]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - prvm_cmds.c
make getsurface* not animate vertices if the model is not animated
[xonotic/darkplaces.git] / prvm_cmds.c
index cb78833cd54fcd65c81a6041679d9028d967acfc..13672c5d8a815667ef6fb079224785bf64755d84 100644 (file)
@@ -187,9 +187,14 @@ void VM_UpdateEdictSkeleton(prvm_edict_t *ed, const dp_model_t *edmodel, const f
                VM_RemoveEdictSkeleton(ed);
                ed->priv.server->skeleton.model = edmodel;
        }
-       if (!ed->priv.server->skeleton.relativetransforms && ed->priv.server->skeleton.model && ed->priv.server->skeleton.model->num_bones)
-               ed->priv.server->skeleton.relativetransforms = Mem_Alloc(prog->progs_mempool, ed->priv.server->skeleton.model->num_bones * sizeof(matrix4x4_t));
-       if (ed->priv.server->skeleton.relativetransforms)
+       if (!ed->priv.server->skeleton.model || !ed->priv.server->skeleton.model->num_bones)
+       {
+               if(ed->priv.server->skeleton.relativetransforms)
+                       Mem_Free(ed->priv.server->skeleton.relativetransforms);
+               ed->priv.server->skeleton.relativetransforms = NULL;
+               return;
+       }
+
        {
                int skeletonindex = -1;
                skeleton_t *skeleton;
@@ -198,30 +203,15 @@ void VM_UpdateEdictSkeleton(prvm_edict_t *ed, const dp_model_t *edmodel, const f
                if (skeletonindex >= 0 && skeletonindex < MAX_EDICTS && (skeleton = prog->skeletons[skeletonindex]) && skeleton->model->num_bones == ed->priv.server->skeleton.model->num_bones)
                {
                        // custom skeleton controlled by the game (FTE_CSQC_SKELETONOBJECTS)
+                       if (!ed->priv.server->skeleton.relativetransforms)
+                               ed->priv.server->skeleton.relativetransforms = (matrix4x4_t *)Mem_Alloc(prog->progs_mempool, ed->priv.server->skeleton.model->num_bones * sizeof(matrix4x4_t));
                        memcpy(ed->priv.server->skeleton.relativetransforms, skeleton->relativetransforms, ed->priv.server->skeleton.model->num_bones * sizeof(matrix4x4_t));
                }
                else
                {
-                       // generated skeleton from frame animation
-                       int blendindex;
-                       int bonenum;
-                       int numbones = ed->priv.server->skeleton.model->num_bones;
-                       const short *framebones6s;
-                       float lerp;
-                       float scale = ed->priv.server->skeleton.model->num_posescale;
-                       matrix4x4_t *relativetransforms = ed->priv.server->skeleton.relativetransforms;
-                       matrix4x4_t matrix;
-                       memset(relativetransforms, 0, numbones * sizeof(matrix4x4_t));
-                       for (blendindex = 0;blendindex < MAX_FRAMEBLENDS && frameblend[blendindex].lerp > 0;blendindex++)
-                       {
-                               lerp = frameblend[blendindex].lerp;
-                               framebones6s = ed->priv.server->skeleton.model->data_poses6s + 6 * frameblend[blendindex].subframe * numbones;
-                               for (bonenum = 0;bonenum < numbones;bonenum++)
-                               {
-                                       Matrix4x4_FromBonePose6s(&matrix, scale, framebones6s + 6 * bonenum);
-                                       Matrix4x4_Accumulate(&ed->priv.server->skeleton.relativetransforms[bonenum], &matrix, lerp);
-                               }
-                       }
+                       if(ed->priv.server->skeleton.relativetransforms)
+                               Mem_Free(ed->priv.server->skeleton.relativetransforms);
+                       ed->priv.server->skeleton.relativetransforms = NULL;
                }
        }
 }
@@ -269,7 +259,7 @@ checkextension(extensionname)
 static qboolean checkextension(const char *name)
 {
        int len;
-       char *e, *start;
+       const char *e, *start;
        len = (int)strlen(name);
 
        for (e = prog->extensionstring;*e;e++)
@@ -3234,7 +3224,7 @@ void VM_precache_pic(void)
        VM_CheckEmptyString (s);
 
        // AK Draw_CachePic is supposed to always return a valid pointer
-       if( Draw_CachePic_Flags(s, CACHEPICFLAG_NOTPERSISTENT)->tex == r_texture_notexture )
+       if( Draw_CachePic_Flags(s, 0)->tex == r_texture_notexture )
                PRVM_G_INT(OFS_RETURN) = OFS_NULL;
 }
 
@@ -3689,7 +3679,7 @@ void VM_drawpic(void)
        if(pos[2] || size[2])
                Con_Printf("VM_drawpic: z value%s from %s discarded\n",(pos[2] && size[2]) ? "s" : " ",((pos[2] && size[2]) ? "pos and size" : (pos[2] ? "pos" : "size")));
 
-       DrawQ_Pic(pos[0], pos[1], Draw_CachePic (picname), size[0], size[1], rgb[0], rgb[1], rgb[2], PRVM_G_FLOAT(OFS_PARM4), flag);
+       DrawQ_Pic(pos[0], pos[1], Draw_CachePic_Flags (picname, CACHEPICFLAG_NOTPERSISTENT), size[0], size[1], rgb[0], rgb[1], rgb[2], PRVM_G_FLOAT(OFS_PARM4), flag);
        PRVM_G_FLOAT(OFS_RETURN) = 1;
 }
 /*
@@ -3734,7 +3724,7 @@ void VM_drawrotpic(void)
        if(pos[2] || size[2] || org[2])
                Con_Printf("VM_drawrotpic: z value from pos/size/org discarded\n");
 
-       DrawQ_RotPic(pos[0], pos[1], Draw_CachePic(picname), size[0], size[1], org[0], org[1], PRVM_G_FLOAT(OFS_PARM4), rgb[0], rgb[1], rgb[2], PRVM_G_FLOAT(OFS_PARM6), flag);
+       DrawQ_RotPic(pos[0], pos[1], Draw_CachePic_Flags(picname, CACHEPICFLAG_NOTPERSISTENT), size[0], size[1], org[0], org[1], PRVM_G_FLOAT(OFS_PARM4), rgb[0], rgb[1], rgb[2], PRVM_G_FLOAT(OFS_PARM6), flag);
        PRVM_G_FLOAT(OFS_RETURN) = 1;
 }
 /*
@@ -3782,7 +3772,7 @@ void VM_drawsubpic(void)
        if(pos[2] || size[2])
                Con_Printf("VM_drawsubpic: z value%s from %s discarded\n",(pos[2] && size[2]) ? "s" : " ",((pos[2] && size[2]) ? "pos and size" : (pos[2] ? "pos" : "size")));
 
-       DrawQ_SuperPic(pos[0], pos[1], Draw_CachePic (picname),
+       DrawQ_SuperPic(pos[0], pos[1], Draw_CachePic_Flags (picname, CACHEPICFLAG_NOTPERSISTENT),
                size[0], size[1],
                srcPos[0],              srcPos[1],              rgb[0], rgb[1], rgb[2], alpha,
                srcPos[0] + srcSize[0], srcPos[1],              rgb[0], rgb[1], rgb[2], alpha,
@@ -3902,31 +3892,35 @@ void VM_keynumtostring (void)
 =========
 VM_findkeysforcommand
 
-string findkeysforcommand(string command)
+string findkeysforcommand(string command, float bindmap)
 
 the returned string is an altstring
 =========
 */
-#define NUMKEYS 5 // TODO: merge the constant in keys.c with this one somewhen
-
+#define FKFC_NUMKEYS 5
 void M_FindKeysForCommand(const char *command, int *keys);
 void VM_findkeysforcommand(void)
 {
        const char *cmd;
        char ret[VM_STRINGTEMP_LENGTH];
-       int keys[NUMKEYS];
+       int keys[FKFC_NUMKEYS];
        int i;
+       int bindmap;
 
-       VM_SAFEPARMCOUNT(1, VM_findkeysforcommand);
+       VM_SAFEPARMCOUNTRANGE(1, 2, VM_findkeysforcommand);
 
        cmd = PRVM_G_STRING(OFS_PARM0);
+       if(prog->argc == 2)
+               bindmap = bound(-1, PRVM_G_FLOAT(OFS_PARM1), MAX_BINDMAPS-1);
+       else
+               bindmap = 0; // consistent to "bind"
 
        VM_CheckEmptyString(cmd);
 
-       M_FindKeysForCommand(cmd, keys);
+       Key_FindKeysForCommand(cmd, keys, FKFC_NUMKEYS, bindmap);
 
        ret[0] = 0;
-       for(i = 0; i < NUMKEYS; i++)
+       for(i = 0; i < FKFC_NUMKEYS; i++)
                strlcat(ret, va(" \'%i\'", keys[i]), sizeof(ret));
 
        PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(ret);
@@ -3943,7 +3937,80 @@ void VM_stringtokeynum (void)
 {
        VM_SAFEPARMCOUNT( 1, VM_keynumtostring );
 
-       PRVM_G_INT(OFS_RETURN) = Key_StringToKeynum(PRVM_G_STRING(OFS_PARM0));
+       PRVM_G_FLOAT(OFS_RETURN) = Key_StringToKeynum(PRVM_G_STRING(OFS_PARM0));
+}
+
+/*
+=========
+VM_getkeybind
+
+string getkeybind(float key, float bindmap)
+=========
+*/
+void VM_getkeybind (void)
+{
+       int bindmap;
+       VM_SAFEPARMCOUNTRANGE(1, 2, VM_CL_getkeybind);
+       if(prog->argc == 2)
+               bindmap = bound(-1, PRVM_G_FLOAT(OFS_PARM1), MAX_BINDMAPS-1);
+       else
+               bindmap = 0; // consistent to "bind"
+
+       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
@@ -5956,7 +6023,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};
 
@@ -5996,6 +6063,7 @@ void VM_sprintf(void)
                                precision = -1;
                                thisarg = -1;
                                flags = 0;
+                               isfloat = -1;
 
                                // is number following?
                                if(*s >= '0' && *s <= '9')
@@ -6118,14 +6186,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;
@@ -6136,6 +6203,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++;
 
@@ -6267,7 +6343,7 @@ void animatemodel(dp_model_t *model, prvm_edict_t *ed)
        skeleton_t *skeleton;
        int skeletonindex = -1;
        qboolean need = false;
-       if(!model->AnimateVertices)
+       if(!(model->surfmesh.isanimated && model->AnimateVertices))
        {
                animatemodel_cache.data_vertex3f = model->surfmesh.data_vertex3f;
                animatemodel_cache.data_svector3f = model->surfmesh.data_svector3f;
@@ -6280,13 +6356,13 @@ void animatemodel(dp_model_t *model, prvm_edict_t *ed)
        need |= (animatemodel_cache.model != model);
        VM_GenerateFrameGroupBlend(ed->priv.server->framegroupblend, ed);
        VM_FrameBlendFromFrameGroupBlend(ed->priv.server->frameblend, ed->priv.server->framegroupblend, model);
-       need |= (memcmp(&animatemodel_cache.frameblend, &ed->priv.server->frameblend, sizeof(ed->priv.server->frameblend)));
+       need |= (memcmp(&animatemodel_cache.frameblend, &ed->priv.server->frameblend, sizeof(ed->priv.server->frameblend))) != 0;
        if ((val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.skeletonindex))) skeletonindex = (int)val->_float - 1;
        if (!(skeletonindex >= 0 && skeletonindex < MAX_EDICTS && (skeleton = prog->skeletons[skeletonindex]) && skeleton->model->num_bones == ed->priv.server->skeleton.model->num_bones))
                skeleton = NULL;
        need |= (animatemodel_cache.skeleton_p != skeleton);
        if(skeleton)
-               need |= (memcmp(&animatemodel_cache.skeleton, skeleton, sizeof(ed->priv.server->skeleton)));
+               need |= (memcmp(&animatemodel_cache.skeleton, skeleton, sizeof(ed->priv.server->skeleton))) != 0;
        if(!need)
                return;
        if(model->surfmesh.num_vertices > animatemodel_cache.max_vertices)
@@ -6296,10 +6372,10 @@ void animatemodel(dp_model_t *model, prvm_edict_t *ed)
                if(animatemodel_cache.buf_svector3f) Mem_Free(animatemodel_cache.buf_svector3f);
                if(animatemodel_cache.buf_tvector3f) Mem_Free(animatemodel_cache.buf_tvector3f);
                if(animatemodel_cache.buf_normal3f) Mem_Free(animatemodel_cache.buf_normal3f);
-               animatemodel_cache.buf_vertex3f = Mem_Alloc(prog->progs_mempool, sizeof(float[3]) * animatemodel_cache.max_vertices);
-               animatemodel_cache.buf_svector3f = Mem_Alloc(prog->progs_mempool, sizeof(float[3]) * animatemodel_cache.max_vertices);
-               animatemodel_cache.buf_tvector3f = Mem_Alloc(prog->progs_mempool, sizeof(float[3]) * animatemodel_cache.max_vertices);
-               animatemodel_cache.buf_normal3f = Mem_Alloc(prog->progs_mempool, sizeof(float[3]) * animatemodel_cache.max_vertices);
+               animatemodel_cache.buf_vertex3f = (float *)Mem_Alloc(prog->progs_mempool, sizeof(float[3]) * animatemodel_cache.max_vertices);
+               animatemodel_cache.buf_svector3f = (float *)Mem_Alloc(prog->progs_mempool, sizeof(float[3]) * animatemodel_cache.max_vertices);
+               animatemodel_cache.buf_tvector3f = (float *)Mem_Alloc(prog->progs_mempool, sizeof(float[3]) * animatemodel_cache.max_vertices);
+               animatemodel_cache.buf_normal3f = (float *)Mem_Alloc(prog->progs_mempool, sizeof(float[3]) * animatemodel_cache.max_vertices);
        }
        animatemodel_cache.data_vertex3f = animatemodel_cache.buf_vertex3f;
        animatemodel_cache.data_svector3f = animatemodel_cache.buf_svector3f;
@@ -6349,7 +6425,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);
 }