From 58ecffb6f73f96936bf8c21853570d7da483d0f3 Mon Sep 17 00:00:00 2001 From: divverent Date: Sun, 4 Jul 2010 19:49:03 +0000 Subject: [PATCH] finalize DP_CSQC_BINDMAPS: functions: string(float key[, float bindmap]) getkeybind = #342; float(float key, string bind[, float bindmap]) setkeybind = #630; vector(void) getbindmaps = #631; float(vector bm) setbindmaps(vector bm) = #632; string findkeysforcommand(string command[, float bindmap]) = #610; /* DEPRECATED csqc: #521 */ string keynumtostring(float keynum) = #340; /* menu: #609, DEPRECATED csqc: #520 */ float stringtokeynum(string key) = #341; /* DEPRECATED menu: #614 */ The bindmap argument is OPTIONAL, and maybe should be declared as ... in the definitons. The old alternative builtin numbers are hereby deprecated; they come from esteel's unofficial extension to csqc to provide findkeysforcommand with a different builtin number than the menuqc one, and from menuqc builtins that now are part of the "more official" csqc spec in other builtin number, apart from #609 in menuqc which was documented as part of menuqc before. From: Rudolf Polzer git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@10273 d7cf8633-e32d-0410-b094-e92efae38249 --- clvm_cmds.c | 7 +++-- dpdefs/csprogsdefs.qc | 16 +++++++++++- dpdefs/menudefs.qc | 14 +++++++++- keys.c | 59 +++++++++++++++++++++++++++++++++---------- keys.h | 4 ++- mvm_cmds.c | 10 ++++++-- prvm_cmds.c | 58 ++++++++++++++++++++++++++++++++++++++++-- prvm_cmds.h | 3 +++ svvm_cmds.c | 1 + 9 files changed, 150 insertions(+), 22 deletions(-) diff --git a/clvm_cmds.c b/clvm_cmds.c index bcbcdb54..b314ac92 100644 --- a/clvm_cmds.c +++ b/clvm_cmds.c @@ -4594,7 +4594,7 @@ VM_writetofile, // #606 VM_isfunction, // #607 NULL, // #608 NULL, // #609 -NULL, // #610 +VM_findkeysforcommand, // #610 string findkeysforcommand(string command[, float bindmap]) NULL, // #611 NULL, // #612 VM_parseentitydata, // #613 @@ -4614,7 +4614,10 @@ NULL, // #626 VM_sprintf, // #627 string sprintf(string format, ...) VM_getsurfacenumtriangles, // #628 float(entity e, float s) getsurfacenumpoints (DP_QC_GETSURFACETRIANGLE) VM_getsurfacetriangle, // #629 vector(entity e, float s, float n) getsurfacepoint (DP_QC_GETSURFACETRIANGLE) -NULL, // #630 +VM_setkeybind, // #630 float(float key, string bind[, float bindmap]) setkeybind +VM_getbindmaps, // #631 vector(void) getbindmap +VM_setbindmaps, // #632 float(vector bm) setbindmap +NULL, // #633 }; const int vm_cl_numbuiltins = sizeof(vm_cl_builtins) / sizeof(prvm_builtin_t); diff --git a/dpdefs/csprogsdefs.qc b/dpdefs/csprogsdefs.qc index cb22966d..2c2d0d1a 100644 --- a/dpdefs/csprogsdefs.qc +++ b/dpdefs/csprogsdefs.qc @@ -833,4 +833,18 @@ float stringwidth_menu(string text, float allowColorCodes, vector size) = #468; // r_font_postprocess_shadow_z X : font outline shadow z shift amount, applied during blurring //description: engine support for truetype/freetype fonts //so .AFM+.PFB/.OTF/.TTF files could be stuffed as fontmaps in loadfont() -//(console command version will support them as well) \ No newline at end of file +//(console command version will support them as well) + +//DP_CSQC_BINDMAPS +//idea: daemon, motorsep +//darkplaces implementation: divVerent +//builtin definitions: +string(float key, float bindmap) getkeybind_bindmap = #342; +float(float key, string bind, float bindmap) setkeybind_bindmap = #630; +vector(void) getbindmaps = #631; +float(vector bm) setbindmaps = #632; +string(string command, float bindmap) findkeysforcommand = #610; +// float(string key) stringtokeynum = #341; +// string(float keynum) keynumtostring = #340; +//description: key bind setting/getting including support for switchable +//bindmaps. diff --git a/dpdefs/menudefs.qc b/dpdefs/menudefs.qc index 9216dea3..45e74a14 100644 --- a/dpdefs/menudefs.qc +++ b/dpdefs/menudefs.qc @@ -431,8 +431,20 @@ void callfunction(...) = #605; void writetofile(float fhandle, entity ent) = #606; vector getresolution(float number) = #608; string keynumtostring(float keynum) = #609; -string findkeysforcommand(string command) = #610; float gethostcachevalue(float type) = #611; string gethostcachestring(float type, float hostnr) = #612; +//DP_CSQC_BINDMAPS +//idea: daemon, motorsep +//darkplaces implementation: divVerent +//builtin definitions: +string(float key, float bindmap) getkeybind_bindmap = #342; +float(float key, string bind, float bindmap) setkeybind_bindmap = #630; +vector(void) getbindmaps = #631; +float(vector bm) setbindmaps = #632; +string(string command, float bindmap) findkeysforcommand = #610; +float(string key) stringtokeynum = #341; +// string(float keynum) keynumtostring = #340; +//description: key bind setting/getting including support for switchable +//bindmaps. diff --git a/keys.c b/keys.c index 40ecfde2..18765a16 100644 --- a/keys.c +++ b/keys.c @@ -1085,14 +1085,16 @@ Key_KeynumToString (int keynum) } -void +qboolean Key_SetBinding (int keynum, int bindmap, const char *binding) { char *newbinding; size_t l; if (keynum == -1 || keynum >= MAX_KEYS) - return; + return false; + if ((bindmap < 0) || (bindmap >= MAX_BINDMAPS)) + return false; // free old bindings if (keybindings[bindmap][keynum]) { @@ -1100,13 +1102,35 @@ Key_SetBinding (int keynum, int bindmap, const char *binding) keybindings[bindmap][keynum] = NULL; } if(!binding[0]) // make "" binds be removed --blub - return; + return true; // allocate memory for new binding l = strlen (binding); newbinding = (char *)Z_Malloc (l + 1); memcpy (newbinding, binding, l + 1); newbinding[l] = 0; keybindings[bindmap][keynum] = newbinding; + return true; +} + +void Key_GetBindMap(int *fg, int *bg) +{ + if(fg) + *fg = key_bmap; + if(bg) + *bg = key_bmap2; +} + +qboolean Key_SetBindMap(int fg, int bg) +{ + if(fg >= MAX_BINDMAPS) + return false; + if(bg >= MAX_BINDMAPS) + return false; + if(fg >= 0) + key_bmap = fg; + if(bg >= 0) + key_bmap2 = bg; + return true; } static void @@ -1121,7 +1145,7 @@ Key_In_Unbind_f (void) } m = strtol(Cmd_Argv (1), &errchar, 0); - if ((m < 0) || (m >= 8) || (errchar && *errchar)) { + if ((m < 0) || (m >= MAX_BINDMAPS) || (errchar && *errchar)) { Con_Printf("%s isn't a valid bindmap\n", Cmd_Argv(1)); return; } @@ -1132,7 +1156,8 @@ Key_In_Unbind_f (void) return; } - Key_SetBinding (b, m, ""); + if(!Key_SetBinding (b, m, "")) + Con_Printf("Key_SetBinding failed for unknown reason\n"); } static void @@ -1150,7 +1175,7 @@ Key_In_Bind_f (void) } m = strtol(Cmd_Argv (1), &errchar, 0); - if ((m < 0) || (m >= 8) || (errchar && *errchar)) { + if ((m < 0) || (m >= MAX_BINDMAPS) || (errchar && *errchar)) { Con_Printf("%s isn't a valid bindmap\n", Cmd_Argv(1)); return; } @@ -1176,7 +1201,8 @@ Key_In_Bind_f (void) strlcat (cmd, " ", sizeof (cmd)); } - Key_SetBinding (b, m, cmd); + if(!Key_SetBinding (b, m, cmd)) + Con_Printf("Key_SetBinding failed for unknown reason\n"); } static void @@ -1193,13 +1219,13 @@ Key_In_Bindmap_f (void) } m1 = strtol(Cmd_Argv (1), &errchar, 0); - if ((m1 < 0) || (m1 >= 8) || (errchar && *errchar)) { + if ((m1 < 0) || (m1 >= MAX_BINDMAPS) || (errchar && *errchar)) { Con_Printf("%s isn't a valid bindmap\n", Cmd_Argv(1)); return; } m2 = strtol(Cmd_Argv (2), &errchar, 0); - if ((m2 < 0) || (m2 >= 8) || (errchar && *errchar)) { + if ((m2 < 0) || (m2 >= MAX_BINDMAPS) || (errchar && *errchar)) { Con_Printf("%s isn't a valid bindmap\n", Cmd_Argv(2)); return; } @@ -1224,7 +1250,8 @@ Key_Unbind_f (void) return; } - Key_SetBinding (b, 0, ""); + if(!Key_SetBinding (b, 0, "")) + Con_Printf("Key_SetBinding failed for unknown reason\n"); } static void @@ -1232,7 +1259,7 @@ Key_Unbindall_f (void) { int i, j; - for (j = 0; j < 8; j++) + for (j = 0; j < MAX_BINDMAPS; j++) for (i = 0; i < (int)(sizeof(keybindings[0])/sizeof(keybindings[0][0])); i++) if (keybindings[j][i]) Key_SetBinding (i, j, ""); @@ -1268,7 +1295,7 @@ Key_In_BindList_f (void) if(Cmd_Argc() >= 2) { m = strtol(Cmd_Argv(1), &errchar, 0); - if ((m < 0) || (m >= 8) || (errchar && *errchar)) { + if ((m < 0) || (m >= MAX_BINDMAPS) || (errchar && *errchar)) { Con_Printf("%s isn't a valid bindmap\n", Cmd_Argv(1)); return; } @@ -1320,7 +1347,8 @@ Key_Bind_f (void) strlcat (cmd, " ", sizeof (cmd)); } - Key_SetBinding (b, 0, cmd); + if(!Key_SetBinding (b, 0, cmd)) + Con_Printf("Key_SetBinding failed for unknown reason\n"); } /* @@ -1388,6 +1416,8 @@ const char *Key_GetBind (int key, int bindmap) const char *bind; if (key < 0 || key >= MAX_KEYS) return NULL; + if(bindmap >= MAX_BINDMAPS) + return NULL; if(bindmap >= 0) { bind = keybindings[bindmap][key]; @@ -1410,6 +1440,9 @@ void Key_FindKeysForCommand (const char *command, int *keys, int numkeys, int bi for (j = 0;j < numkeys;j++) keys[j] = -1; + if(bindmap >= MAX_BINDMAPS) + return; + count = 0; for (j = 0; j < MAX_KEYS; ++j) diff --git a/keys.h b/keys.h index cd95805e..c99011dc 100644 --- a/keys.h +++ b/keys.h @@ -345,12 +345,14 @@ void Key_Shutdown(void); void Key_Init_Cvars(void); void Key_Event(int key, int ascii, qboolean down); void Key_ClearStates (void); -void Key_SetBinding (int keynum, int bindmap, const char *binding); void Key_EventQueue_Block(void); void Key_EventQueue_Unblock(void); +qboolean Key_SetBinding (int keynum, int bindmap, const char *binding); const char *Key_GetBind (int key, int bindmap); void Key_FindKeysForCommand (const char *command, int *keys, int numkeys, int bindmap); +qboolean Key_SetBindMap(int fg, int bg); +void Key_GetBindMap(int *fg, int *bg); #endif // __KEYS_H diff --git a/mvm_cmds.c b/mvm_cmds.c index 3bb9a651..b7bbc8b0 100644 --- a/mvm_cmds.c +++ b/mvm_cmds.c @@ -12,6 +12,7 @@ char *vm_m_extensions = "BX_WAL_SUPPORT " "DP_CINEMATIC_DPV " +"DP_CSQC_BINDMAPS " "DP_GFX_FONTS " "DP_GFX_FONTS_FREETYPE " "DP_UTF8 " @@ -1117,8 +1118,8 @@ NULL, // #336 NULL, // #337 NULL, // #338 NULL, // #339 -NULL, // #340 -NULL, // #341 +VM_keynumtostring, // #340 string keynumtostring(float keynum) +VM_stringtokeynum, // #341 float stringtokeynum(string key) VM_getkeybind, // #342 string(float keynum[, float bindmap]) getkeybind (EXT_CSQC) NULL, // #343 NULL, // #344 @@ -1405,6 +1406,11 @@ VM_CL_getextresponse, // #624 string getextresponse(void) VM_netaddress_resolve, // #625 string netaddress_resolve(string, float) VM_M_getgamedirinfo, // #626 string getgamedirinfo(float n, float prop) VM_sprintf, // #627 string sprintf(string format, ...) +NULL, // #628 +NULL, // #629 +VM_setkeybind, // #630 float(float key, string bind[, float bindmap]) setkeybind +VM_getbindmaps, // #631 vector(void) getbindmap +VM_setbindmaps, // #632 float(vector bm) setbindmap NULL }; diff --git a/prvm_cmds.c b/prvm_cmds.c index 666dd52e..9713b10e 100644 --- a/prvm_cmds.c +++ b/prvm_cmds.c @@ -3902,7 +3902,7 @@ void VM_keynumtostring (void) ========= VM_findkeysforcommand -string findkeysforcommand(string command) +string findkeysforcommand(string command, float bindmap) the returned string is an altstring ========= @@ -3954,7 +3954,7 @@ void VM_stringtokeynum (void) ========= VM_getkeybind -string getkeybind(float key) +string getkeybind(float key, float bindmap) ========= */ void VM_getkeybind (void) @@ -3969,6 +3969,60 @@ void VM_getkeybind (void) PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(Key_GetBind((int)PRVM_G_FLOAT(OFS_PARM0), bindmap)); } +/* +========= +VM_setkeybind + +float setkeybind(float key, string cmd, float bindmap) +========= +*/ +void VM_setkeybind (void) +{ + int bindmap; + VM_SAFEPARMCOUNTRANGE(2, 3, VM_CL_setkeybind); + if(prog->argc == 3) + bindmap = bound(-1, PRVM_G_FLOAT(OFS_PARM2), MAX_BINDMAPS-1); + else + bindmap = 0; // consistent to "bind" + + PRVM_G_FLOAT(OFS_RETURN) = 0; + if(Key_SetBinding((int)PRVM_G_FLOAT(OFS_PARM0), bindmap, PRVM_G_STRING(OFS_PARM1))) + PRVM_G_FLOAT(OFS_RETURN) = 1; +} + +/* +========= +VM_getbindmap + +vector getbindmaps() +========= +*/ +void VM_getbindmaps (void) +{ + int fg, bg; + VM_SAFEPARMCOUNT(0, VM_CL_getbindmap); + Key_GetBindMap(&fg, &bg); + PRVM_G_VECTOR(OFS_RETURN)[0] = fg; + PRVM_G_VECTOR(OFS_RETURN)[1] = bg; + PRVM_G_VECTOR(OFS_RETURN)[2] = 0; +} + +/* +========= +VM_setbindmap + +float setbindmaps(vector bindmap) +========= +*/ +void VM_setbindmaps (void) +{ + VM_SAFEPARMCOUNT(1, VM_CL_setbindmap); + PRVM_G_FLOAT(OFS_RETURN) = 0; + if(PRVM_G_VECTOR(OFS_PARM0)[2] == 0) + if(Key_SetBindMap((int)PRVM_G_VECTOR(OFS_PARM0)[0], (int)PRVM_G_VECTOR(OFS_PARM0)[1])) + PRVM_G_FLOAT(OFS_RETURN) = 1; +} + // CL_Video interface functions /* diff --git a/prvm_cmds.h b/prvm_cmds.h index c727b9bf..d47aa613 100644 --- a/prvm_cmds.h +++ b/prvm_cmds.h @@ -369,6 +369,9 @@ void VM_keynumtostring (void); void VM_getkeybind (void); void VM_findkeysforcommand (void); void VM_stringtokeynum (void); +void VM_setkeybind (void); +void VM_getbindmaps (void); +void VM_setbindmaps (void); void VM_cin_open( void ); void VM_cin_close( void ); diff --git a/svvm_cmds.c b/svvm_cmds.c index 5b3a8b19..35cb8bee 100644 --- a/svvm_cmds.c +++ b/svvm_cmds.c @@ -19,6 +19,7 @@ char *vm_sv_extensions = "DP_CON_SET " "DP_CON_SETA " "DP_CON_STARTMAP " +"DP_CSQC_BINDMAPS " "DP_CSQC_ENTITYNOCULL " "DP_CSQC_ENTITYTRANSPARENTSORTING_OFFSET " "DP_CSQC_MULTIFRAME_INTERPOLATION " -- 2.39.2