]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
finalize DP_CSQC_BINDMAPS:
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 4 Jul 2010 19:49:03 +0000 (19:49 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 4 Jul 2010 19:49:03 +0000 (19:49 +0000)
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 <divverent@alientrap.org>

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@10273 d7cf8633-e32d-0410-b094-e92efae38249

clvm_cmds.c
dpdefs/csprogsdefs.qc
dpdefs/menudefs.qc
keys.c
keys.h
mvm_cmds.c
prvm_cmds.c
prvm_cmds.h
svvm_cmds.c

index bcbcdb54d7e08cd47f68c8322de6a9a13dd4a32b..b314ac925da285b9110946817a08414eb4c9c7c4 100644 (file)
@@ -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);
index cb22966dae7e63558d3bcdb19c4bff0cd13046c1..2c2d0d1ab1545647bc453d27613dcf854ecc6ea4 100644 (file)
@@ -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;
+//<already in EXT_CSQC> float(string key) stringtokeynum = #341;
+//<already in EXT_CSQC> string(float keynum) keynumtostring = #340;
+//description: key bind setting/getting including support for switchable
+//bindmaps.
index 9216dea39dbb42fdac8e353ed0b8480c4b6df3cb..45e74a14993c493317d6500e3d699fcc8f626a77 100644 (file)
@@ -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;
+//<also allowed builtin number to match EXT_CSQC> string(float keynum) keynumtostring = #340;
+//description: key bind setting/getting including support for switchable
+//bindmaps.
diff --git a/keys.c b/keys.c
index 40ecfde2e25c3ccb6420fdf98e2bda0b1f9ac177..18765a167e2c0c6c050dd6e915502c858ac1d654 100644 (file)
--- 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 cd95805e921e0bdd6c2b818302f9c4646a4adcca..c99011dca7505b678b15ed38931ae50a6d5d5981 100644 (file)
--- 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
 
index 3bb9a651a9770f04682382ed32376e12438f411a..b7bbc8b0f5350df77913f5ff88f2f70582420564 100644 (file)
@@ -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
 };
 
index 666dd52e636452606e0309f16adc287a93cda698..9713b10e44f06d0cbfe9f27c655e8420e440f139 100644 (file)
@@ -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
 
 /*
index c727b9bfc138ff1b4f00d75c911dff90950f697d..d47aa613639e8dc7b80b203bfff7ad1f2fc8b765 100644 (file)
@@ -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 );
index 5b3a8b190565857498ddb0b60d41865677be9cc2..35cb8beed1a93bd463875344772d14e7ad04847d 100644 (file)
@@ -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 "