]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - prvm_cmds.c
menuqc += +VM_getkeybind, // #342 string(float keynum) getkeybind (EXT_CSQC)
[xonotic/darkplaces.git] / prvm_cmds.c
index 6b8fde316ccffe48a9087f2d62c1692aee140a2a..3976608f3e2af8020b6b398915a688f7968424f5 100644 (file)
@@ -3513,16 +3513,16 @@ float loadfont(string fontname, string fontmaps, string sizes, float slot)
 */
 
 dp_font_t *FindFont(const char *title, qboolean allocate_new);
-void LoadFont(qboolean override, const char *name, dp_font_t *fnt);
+void LoadFont(qboolean override, const char *name, dp_font_t *fnt, float scale, float voffset);
 void VM_loadfont(void)
 {
        const char *fontname, *filelist, *sizes, *c, *cm;
        char mainfont[MAX_QPATH];
        int i, numsizes;
-       float sz;
+       float sz, scale, voffset;
        dp_font_t *f;
 
-       VM_SAFEPARMCOUNTRANGE(3,4,VM_loadfont);
+       VM_SAFEPARMCOUNTRANGE(3,6,VM_loadfont);
 
        fontname = PRVM_G_STRING(OFS_PARM0);
        if (!fontname[0])
@@ -3629,8 +3629,20 @@ void VM_loadfont(void)
                numsizes++;
        }
 
+       // additional scale/hoffset parms
+       scale = 1;
+       voffset = 0;
+       if (prog->argc >= 5)
+       {
+               scale = PRVM_G_FLOAT(OFS_PARM4);
+               if (scale <= 0)
+                       scale = 1;
+       }
+       if (prog->argc >= 6)
+               voffset = PRVM_G_FLOAT(OFS_PARM5);
+
        // load
-       LoadFont(true, mainfont, f);
+       LoadFont(true, mainfont, f, scale, voffset);
 
        // return index of loaded font
        PRVM_G_FLOAT(OFS_RETURN) = (f - dp_fonts.f);
@@ -3934,6 +3946,20 @@ void VM_stringtokeynum (void)
        PRVM_G_INT(OFS_RETURN) = Key_StringToKeynum(PRVM_G_STRING(OFS_PARM0));
 }
 
+/*
+=========
+VM_getkeybind
+
+string getkeybind(float key)
+=========
+*/
+const char *Key_GetBind (int key);
+void VM_getkeybind (void)
+{
+       VM_SAFEPARMCOUNT(1, VM_CL_getkeybind);
+       PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(Key_GetBind((int)PRVM_G_FLOAT(OFS_PARM0)));
+}
+
 // CL_Video interface functions
 
 /*
@@ -5944,7 +5970,7 @@ void VM_sprintf(void)
        int width, precision, thisarg, flags;
        char formatbuf[16];
        char *f;
-       qboolean isfloat;
+       int isfloat;
        static int dummyivec[3] = {0, 0, 0};
        static float dummyvec[3] = {0, 0, 0};
 
@@ -5984,6 +6010,7 @@ void VM_sprintf(void)
                                precision = -1;
                                thisarg = -1;
                                flags = 0;
+                               isfloat = -1;
 
                                // is number following?
                                if(*s >= '0' && *s <= '9')
@@ -6106,14 +6133,13 @@ noflags:
                                        }
                                }
 
-                               isfloat = true;
                                for(;;)
                                {
                                        switch(*s)
                                        {
-                                               case 'h': isfloat = true; break;
-                                               case 'l': isfloat = false; break;
-                                               case 'L': isfloat = false; break;
+                                               case 'h': isfloat = 1; break;
+                                               case 'l': isfloat = 0; break;
+                                               case 'L': isfloat = 0; break;
                                                case 'j': break;
                                                case 'z': break;
                                                case 't': break;
@@ -6124,6 +6150,15 @@ noflags:
                                }
 nolength:
 
+                               // now s points to the final directive char and is no longer changed
+                               if(isfloat < 0)
+                               {
+                                       if(*s == 'i')
+                                               isfloat = 0;
+                                       else
+                                               isfloat = 1;
+                               }
+
                                if(thisarg < 0)
                                        thisarg = argpos++;
 
@@ -6337,7 +6372,7 @@ static void applytransform_inverted(const vec3_t in, prvm_edict_t *ed, vec3_t ou
 {
        matrix4x4_t m, n;
        getmatrix(ed, &m);
-       Matrix4x4_Invert_Full(&m, &n);
+       Matrix4x4_Invert_Full(&n, &m);
        Matrix4x4_Transform3x3(&n, in, out);
 }