From 2fa3153a84ba2932542bd3677ee041b70a2a1297 Mon Sep 17 00:00:00 2001 From: terminx Date: Sun, 29 Jun 2008 10:40:37 +0000 Subject: [PATCH] Better keybinding... still needs some work but seems to be functional Example: bind w repeat gamefunc_move_forward bind s repeat gamefunc_move_backward bind a repeat gamefunc_strafe_left bind d repeat gamefunc_strafe_right bind space gamefunc_jump bind leftcontrol repeat gamefunc_crouch bind f12 quit git-svn-id: https://svn.eduke32.com/eduke32@808 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/source/astub.c | 93 ++++++++++----------- polymer/eduke32/source/duke3d.h | 22 ++--- polymer/eduke32/source/game.c | 18 ++-- polymer/eduke32/source/gamedef.c | 1 + polymer/eduke32/source/gameexec.c | 9 +- polymer/eduke32/source/grpscan.c | 10 +-- polymer/eduke32/source/jaudiolib/multivoc.c | 2 +- polymer/eduke32/source/jmact/control.c | 30 ++++++- polymer/eduke32/source/jmact/control.h | 14 ++++ polymer/eduke32/source/osdcmds.c | 26 +++++- polymer/eduke32/source/sounds.c | 46 +++++----- 11 files changed, 159 insertions(+), 112 deletions(-) diff --git a/polymer/eduke32/source/astub.c b/polymer/eduke32/source/astub.c index 312dd91d9..da705670b 100644 --- a/polymer/eduke32/source/astub.c +++ b/polymer/eduke32/source/astub.c @@ -647,7 +647,6 @@ void ExtShowSectorData(short sectnum) //F5 { short statnum=0; int x,x2,y; - int nexti; int i; int secrets=0; int totalactors1=0,totalactors2=0,totalactors3=0,totalactors4=0; @@ -666,56 +665,52 @@ void ExtShowSectorData(short sectnum) //F5 i = headspritestat[statnum]; while (i != -1) { - nexti = nextspritestat[i]; - i = nexti; - + switch (sprite[i].picnum) { - switch (sprite[i].picnum) - { - case RECON: - case DRONE: - case LIZTROOPONTOILET: - case LIZTROOPSTAYPUT: - case LIZTROOPSHOOT: - case LIZTROOPJETPACK: - case LIZTROOPDUCKING: - case LIZTROOPRUNNING: - case LIZTROOP: - case OCTABRAIN: - case OCTABRAINSTAYPUT: - case COMMANDER: - case COMMANDERSTAYPUT: - case EGG: - case PIGCOP: - case PIGCOPSTAYPUT: - case PIGCOPDIVE: - case LIZMAN: - case LIZMANSTAYPUT: - case LIZMANSPITTING: - case LIZMANFEEDING: - case LIZMANJUMP: - case ORGANTIC: - case BOSS1: - case BOSS2: - case BOSS3: - case GREENSLIME: - case ROTATEGUN: - case TANK: - case NEWBEAST: - case BOSS4: - if (sprite[i].lotag<=1) totalactors1++; - if (sprite[i].lotag<=2) totalactors2++; - if (sprite[i].lotag<=3) totalactors3++; - if (sprite[i].lotag<=4) totalactors4++; - break; + case RECON: + case DRONE: + case LIZTROOPONTOILET: + case LIZTROOPSTAYPUT: + case LIZTROOPSHOOT: + case LIZTROOPJETPACK: + case LIZTROOPDUCKING: + case LIZTROOPRUNNING: + case LIZTROOP: + case OCTABRAIN: + case OCTABRAINSTAYPUT: + case COMMANDER: + case COMMANDERSTAYPUT: + case EGG: + case PIGCOP: + case PIGCOPSTAYPUT: + case PIGCOPDIVE: + case LIZMAN: + case LIZMANSTAYPUT: + case LIZMANSPITTING: + case LIZMANFEEDING: + case LIZMANJUMP: + case ORGANTIC: + case BOSS1: + case BOSS2: + case BOSS3: + case GREENSLIME: + case ROTATEGUN: + case TANK: + case NEWBEAST: + case BOSS4: + if (sprite[i].lotag<=1) totalactors1++; + if (sprite[i].lotag<=2) totalactors2++; + if (sprite[i].lotag<=3) totalactors3++; + if (sprite[i].lotag<=4) totalactors4++; + break; - case RESPAWN: - totalrespawn++; + case RESPAWN: + totalrespawn++; - default: - break; - } + default: + break; } + i = nextspritestat[i]; } for (i=0;istr = strdup(buffer); if (CommandPaths) @@ -6655,7 +6650,7 @@ static void addgamepath(const char *buffer) static void addgroup(const char *buffer) { struct strllist *s; - s = (struct strllist *)calloc(1,sizeof(struct strllist)); + s = (struct strllist *)Bcalloc(1,sizeof(struct strllist)); s->str = Bstrdup(buffer); if (Bstrchr(s->str,'.') == 0) Bstrcat(s->str,".grp"); diff --git a/polymer/eduke32/source/duke3d.h b/polymer/eduke32/source/duke3d.h index f556d124e..fa05b06b0 100644 --- a/polymer/eduke32/source/duke3d.h +++ b/polymer/eduke32/source/duke3d.h @@ -311,12 +311,11 @@ typedef struct { typedef struct { int length, num, soundsiz; - char *filename, *ptr; - char *filename1; - short ps,pe,vo; - volatile char lock; - char pr,m; + char *filename, *ptr, *filename1; SOUNDOWNER SoundOwner[4]; + short ps,pe,vo; + char pr,m; + volatile char lock; } sound_t; extern sound_t g_sounds[MAXSOUNDS]; @@ -807,7 +806,8 @@ enum sysstrs { STR_MAPNAME, STR_MAPFILENAME, STR_PLAYERNAME, - STR_VERSION + STR_VERSION, + STR_GAMETYPE }; // store global game definitions @@ -1018,9 +1018,6 @@ extern playerdata_t g_player[MAXPLAYERS]; #include "funct.h" // key bindings stuff -#define MAXSCRIPTFILENAMELENGTH 32 -#define MAXBOUNDKEYS 256 - typedef struct { char *name; int id; @@ -1028,13 +1025,6 @@ typedef struct { extern keydef keynames[]; -typedef struct binding { - char *key; - char name[MAXSCRIPTFILENAMELENGTH]; -} keybind; - -extern keybind boundkeys[MAXBOUNDKEYS]; - #ifdef __cplusplus } #endif diff --git a/polymer/eduke32/source/game.c b/polymer/eduke32/source/game.c index 0a153a83a..d598bbbf1 100644 --- a/polymer/eduke32/source/game.c +++ b/polymer/eduke32/source/game.c @@ -247,8 +247,6 @@ keydef keynames[]= {0,0} }; -keybind boundkeys[MAXBOUNDKEYS]; - enum { T_EOF = -2, @@ -603,6 +601,8 @@ void getpackets(void) sampletimer(); AudioUpdate(); + CONTROL_ProcessBinds(); + if (ALT_IS_PRESSED && KB_KeyPressed(sc_Enter)) { if (setgamemode(!ud.config.ScreenMode,ud.config.ScreenWidth,ud.config.ScreenHeight,ud.config.ScreenBPP)) @@ -7821,12 +7821,6 @@ static void nonsharedkeys(void) int i,ch; int j; - for (i=0;i<256;i++) - if (*boundkeys[i].name&&KB_KeyPressed(i)) - { - load_script(boundkeys[i].name); - KB_ClearKeyDown(i); - } if (ud.recstat == 2) { ControlInfo noshareinfo; @@ -8588,7 +8582,7 @@ static void setup_rancid_net(const char *fn) netparamcount = rancid_players; if (rancid_local_port_string[0] == '-') netparamcount++; - netparam = (char **)calloc(netparamcount, sizeof(char **)); + netparam = (char **)Bcalloc(netparamcount, sizeof(char **)); for (i=0;istr = Bstrdup(buffer); if (Bstrchr(s->str,'.') == 0) Bstrcat(s->str,".grp"); @@ -8952,7 +8946,7 @@ static void addgroup(const char *buffer) static void addgamepath(const char *buffer) { struct strllist *s; - s = (struct strllist *)calloc(1,sizeof(struct strllist)); + s = (struct strllist *)Bcalloc(1,sizeof(struct strllist)); s->str = strdup(buffer); if (CommandPaths) @@ -9117,7 +9111,7 @@ static void checkcommandline(int argc, const char **argv) g_NoSetup = TRUE; firstnet = i; netparamcount = argc - i - 1; - netparam = (char **)calloc(netparamcount, sizeof(char**)); + netparam = (char **)Bcalloc(netparamcount, sizeof(char**)); i++; continue; } diff --git a/polymer/eduke32/source/gamedef.c b/polymer/eduke32/source/gamedef.c index 71c6c11a2..09ef4900e 100644 --- a/polymer/eduke32/source/gamedef.c +++ b/polymer/eduke32/source/gamedef.c @@ -4973,6 +4973,7 @@ static void AddDefaultDefinitions(void) AddDefinition("STR_MAPFILENAME",STR_MAPFILENAME,LABEL_DEFINE); AddDefinition("STR_PLAYERNAME",STR_PLAYERNAME,LABEL_DEFINE); AddDefinition("STR_VERSION",STR_VERSION,LABEL_DEFINE); + AddDefinition("STR_GAMETYPE",STR_GAMETYPE,LABEL_DEFINE); AddDefinition("NO",0,LABEL_DEFINE|LABEL_ACTION|LABEL_AI|LABEL_MOVE); diff --git a/polymer/eduke32/source/gameexec.c b/polymer/eduke32/source/gameexec.c index 5c7ffe28c..241e89387 100644 --- a/polymer/eduke32/source/gameexec.c +++ b/polymer/eduke32/source/gameexec.c @@ -5147,6 +5147,9 @@ static int parse(void) case STR_VERSION: Bstrcpy(fta_quotes[i],HEAD2); break; + case STR_GAMETYPE: + Bstrcpy(fta_quotes[i],gametype_names[ud.coop]); + break; default: OSD_Printf("%s %d unknown str ID %d %d\n",__FILE__,__LINE__,i,j); } @@ -5532,7 +5535,11 @@ static int parse(void) { int32 i=0; insptr++; - if (ud.config.scripthandle < 0) {insptr++;break;} + if (ud.config.scripthandle < 0) + { + insptr++; + break; + } switch (tw) { case CON_SAVEGAMEVAR: diff --git a/polymer/eduke32/source/grpscan.c b/polymer/eduke32/source/grpscan.c index f8ddd80be..dc22dc177 100755 --- a/polymer/eduke32/source/grpscan.c +++ b/polymer/eduke32/source/grpscan.c @@ -52,7 +52,7 @@ static int LoadGroupsCache(void) if (scriptfile_getnumber(script, &fmtime)) break; // modification time if (scriptfile_getnumber(script, &fcrcval)) break; // crc checksum - fg = calloc(1, sizeof(struct grpcache)); + fg = Bcalloc(1, sizeof(struct grpcache)); fg->next = grpcache; grpcache = fg; @@ -110,14 +110,14 @@ int ScanGroups(void) free(fn); if (fg->size == st.st_size && fg->mtime == st.st_mtime) { - grp = (struct grpfile *)calloc(1, sizeof(struct grpfile)); + grp = (struct grpfile *)Bcalloc(1, sizeof(struct grpfile)); grp->name = strdup(sidx->name); grp->crcval = fg->crcval; grp->size = fg->size; grp->next = foundgrps; foundgrps = grp; - fgg = (struct grpcache *)calloc(1, sizeof(struct grpcache)); + fgg = (struct grpcache *)Bcalloc(1, sizeof(struct grpcache)); strcpy(fgg->name, fg->name); fgg->size = fg->size; fgg->mtime = fg->mtime; @@ -149,14 +149,14 @@ int ScanGroups(void) close(fh); initprintf(" Done\n"); - grp = (struct grpfile *)calloc(1, sizeof(struct grpfile)); + grp = (struct grpfile *)Bcalloc(1, sizeof(struct grpfile)); grp->name = strdup(sidx->name); grp->crcval = crcval; grp->size = st.st_size; grp->next = foundgrps; foundgrps = grp; - fgg = (struct grpcache *)calloc(1, sizeof(struct grpcache)); + fgg = (struct grpcache *)Bcalloc(1, sizeof(struct grpcache)); strncpy(fgg->name, sidx->name, BMAX_PATH); fgg->size = st.st_size; fgg->mtime = st.st_mtime; diff --git a/polymer/eduke32/source/jaudiolib/multivoc.c b/polymer/eduke32/source/jaudiolib/multivoc.c index d5457c474..7c3c7e7ed 100644 --- a/polymer/eduke32/source/jaudiolib/multivoc.c +++ b/polymer/eduke32/source/jaudiolib/multivoc.c @@ -2873,7 +2873,7 @@ int MV_Init(int soundcard, int MixRate, int Voices, int numchannels, int sampleb // Allocate mix buffer within 1st megabyte // use calloc to clear the memory for the first playback. - ptr = (char *)calloc(1,TotalBufferSize + 8); // FIXME: temporarily fixes bounds error somewhere... + ptr = (char *)Bcalloc(1,TotalBufferSize + 8); // FIXME: temporarily fixes bounds error somewhere... if (!ptr) { USRHOOKS_FreeMem(MV_Voices); diff --git a/polymer/eduke32/source/jmact/control.c b/polymer/eduke32/source/jmact/control.c index 152b52301..61c6122ac 100644 --- a/polymer/eduke32/source/jmact/control.c +++ b/polymer/eduke32/source/jmact/control.c @@ -159,10 +159,10 @@ boolean CONTROL_KeyboardFunctionPressed(int32 which) if (!CONTROL_Flags[which].used) return false; - if (CONTROL_KeyMapping[which].key1 != KEYUNDEFINED) + if (CONTROL_KeyMapping[which].key1 != KEYUNDEFINED && !boundkeys[CONTROL_KeyMapping[which].key1].name[0]) key1 = KB_KeyDown[ CONTROL_KeyMapping[which].key1 ] ? true : false; - if (CONTROL_KeyMapping[which].key2 != KEYUNDEFINED) + if (CONTROL_KeyMapping[which].key2 != KEYUNDEFINED && !boundkeys[CONTROL_KeyMapping[which].key1].name[0]) key2 = KB_KeyDown[ CONTROL_KeyMapping[which].key2 ] ? true : false; return (key1 | key2); @@ -786,6 +786,27 @@ void CONTROL_ClearButton( int32 whichbutton ) CONTROL_Flags[whichbutton].cleared = true; } +int extinput[CONTROL_NUM_FLAGS]; +keybind boundkeys[MAXBOUNDKEYS]; + +void CONTROL_ProcessBinds(void) +{ + int i; + + for (i=0;i<256;i++) + { + if (boundkeys[i].name[0] && KB_KeyPressed(i)) + { + if (boundkeys[i].repeat || (boundkeys[i].laststate == 0)) + OSD_Dispatch(boundkeys[i].name); +// if (!boundkeys[i].repeat) +// KB_ClearKeyDown(i); + } + boundkeys[i].laststate = KB_KeyPressed(i); + } +} + + void CONTROL_GetInput( ControlInfo *info ) { int32 i, periphs[CONTROL_NUM_FLAGS]; @@ -800,12 +821,15 @@ void CONTROL_GetInput( ControlInfo *info ) CONTROL_ButtonHeldState2 = CONTROL_ButtonState2; CONTROL_ButtonState1 = CONTROL_ButtonState2 = 0; + CONTROL_ProcessBinds(); + for (i=0; iname+9; // skip "gamefunc_" + extinput[CONFIG_FunctionNameToNum(p)] = 1; + return OSDCMD_OK; +} + static int osdcmd_bind(const osdfuncparm_t *parm) { - int i; + int i, j; if (parm->numparms==1&&!Bstrcasecmp(parm->parms[0],"showkeys")) { @@ -973,8 +982,16 @@ static int osdcmd_bind(const osdfuncparm_t *parm) for (i=0;keynames[i].name;i++)if (!Bstrcasecmp(parm->parms[0],keynames[i].name))break; if (!keynames[i].name) return OSDCMD_SHOWHELP; - Bstrncpy(boundkeys[keynames[i].id].name,parm->parms[1], MAXSCRIPTFILENAMELENGTH-1); + j = 1; + if (parm->numparms >= 2 && !Bstrcasecmp(parm->parms[j],"repeat")) + { + boundkeys[keynames[i].id].repeat = 1; + j++; + } + else boundkeys[keynames[i].id].repeat = 0; + Bstrncpy(boundkeys[keynames[i].id].name,parm->parms[j], MAXBINDSTRINGLENGTH-1); boundkeys[keynames[i].id].key=keynames[i].name; + OSD_Printf("key %s repeat %d string %s\n",keynames[i].name,boundkeys[keynames[i].id].repeat, boundkeys[keynames[i].id].name); return OSDCMD_OK; } @@ -1034,6 +1051,11 @@ int registerosdcommands(void) OSD_RegisterFunction("vidmode","vidmode [xdim ydim] [bpp] [fullscreen]: immediately change the video mode",osdcmd_vidmode); OSD_RegisterFunction("bind","bind : executes a command script when gets pressed. Type \"bind showkeys\" for a list of keys.", osdcmd_bind); + for (i=0;i= MAXSOUNDS) return -1; - if (i < 0) - { - sound(num); - return 0; - } + if (i < 0) + { + sound(num); + return 0; + } return xyzsound(num,i,SX,SY,SZ); } void stopspritesound(int num, int i) { UNREFERENCED_PARAMETER(i); - if (num >= 0 && num < MAXSOUNDS) stopsound(num); + if (num >= 0 && num < MAXSOUNDS) stopsound(num); } void stopsound(int num) { - if (num >= 0 && num < MAXSOUNDS) - if (g_sounds[num].num > 0) - { - FX_StopSound(g_sounds[num].SoundOwner[g_sounds[num].num-1].voice); - testcallback(num); - } + if (num >= 0 && num < MAXSOUNDS) + if (g_sounds[num].num > 0) + { + FX_StopSound(g_sounds[num].SoundOwner[g_sounds[num].num-1].voice); + testcallback(num); + } } void stopenvsound(int num,int i) { int j, k; - if (num >= 0 && num < MAXSOUNDS) - if (g_sounds[num].num > 0) - { - k = g_sounds[num].num; - for (j=0;j= 0 && num < MAXSOUNDS) + if (g_sounds[num].num > 0) + { + k = g_sounds[num].num; + for (j=0;j