]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - clvm_cmds.c
a cosmetic change as suggested by div0:
[xonotic/darkplaces.git] / clvm_cmds.c
index d814234b026ad9d72d06617db24492fa036df148..b0effc637d37691ed2e5ab7ef13175fb16cdedfd 100644 (file)
@@ -127,6 +127,7 @@ void CSQC_RelinkCSQCEntities (void);
 char *Key_GetBind (int key);
 model_t *CSQC_GetModelByIndex(int modelindex);
 model_t *CSQC_GetModelFromEntity(prvm_edict_t *ed);
+void CL_LinkEdict(prvm_edict_t *ed);
 
 
 
@@ -159,6 +160,7 @@ void VM_CL_setorigin (void)
        }
        org = PRVM_G_VECTOR(OFS_PARM1);
        VectorCopy (org, e->fields.client->origin);
+       CL_LinkEdict(e);
 }
 
 // #3 void(entity e, string m) setmodel
@@ -222,6 +224,8 @@ void VM_CL_setsize (void)
        VectorCopy (min, e->fields.client->mins);
        VectorCopy (max, e->fields.client->maxs);
        VectorSubtract (max, min, e->fields.client->size);
+
+       CL_LinkEdict(e);
 }
 
 // #8 void(entity e, float chan, string samp) sound
@@ -568,104 +572,6 @@ void VM_CL_particle (void)
        CL_ParticleEffect(EFFECT_SVC_PARTICLE, count, org, org, dir, dir, NULL, color);
 }
 
-// #49 void(entity ent, float ideal_yaw, float speed_yaw) ChangeYaw
-void VM_CL_changeyaw (void)
-{
-       prvm_edict_t    *ent;
-       float                   ideal, current, move, speed;
-       VM_SAFEPARMCOUNT(3, VM_CL_changeyaw);
-
-       ent = PRVM_G_EDICT(OFS_PARM0);
-       if (ent == prog->edicts)
-       {
-               VM_Warning("changeyaw: can not modify world entity\n");
-               return;
-       }
-       if (ent->priv.server->free)
-       {
-               VM_Warning("changeyaw: can not modify free entity\n");
-               return;
-       }
-       current = ANGLEMOD(ent->fields.client->angles[1]);
-       ideal = PRVM_G_FLOAT(OFS_PARM1);
-       speed = PRVM_G_FLOAT(OFS_PARM2);
-
-       if (current == ideal)
-               return;
-       move = ideal - current;
-       if (ideal > current)
-       {
-               if (move >= 180)
-                       move = move - 360;
-       }
-       else
-       {
-               if (move <= -180)
-                       move = move + 360;
-       }
-       if (move > 0)
-       {
-               if (move > speed)
-                       move = speed;
-       }
-       else
-       {
-               if (move < -speed)
-                       move = -speed;
-       }
-
-       ent->fields.client->angles[1] = ANGLEMOD (current + move);
-}
-
-// #63 void(entity ent, float ideal_pitch, float speed_pitch) changepitch (DP_QC_CHANGEPITCH)
-void VM_CL_changepitch (void)
-{
-       prvm_edict_t            *ent;
-       float                           ideal, current, move, speed;
-       VM_SAFEPARMCOUNT(3, VM_CL_changepitch);
-
-       ent = PRVM_G_EDICT(OFS_PARM0);
-       if (ent == prog->edicts)
-       {
-               VM_Warning("changepitch: can not modify world entity\n");
-               return;
-       }
-       if (ent->priv.server->free)
-       {
-               VM_Warning("changepitch: can not modify free entity\n");
-               return;
-       }
-       current = ANGLEMOD( ent->fields.client->angles[0] );
-       ideal = PRVM_G_FLOAT(OFS_PARM1);
-       speed = PRVM_G_FLOAT(OFS_PARM2);
-
-       if (current == ideal)
-               return;
-       move = ideal - current;
-       if (ideal > current)
-       {
-               if (move >= 180)
-                       move = move - 360;
-       }
-       else
-       {
-               if (move <= -180)
-                       move = move + 360;
-       }
-       if (move > 0)
-       {
-               if (move > speed)
-                       move = speed;
-       }
-       else
-       {
-               if (move < -speed)
-                       move = -speed;
-       }
-
-       ent->fields.client->angles[0] = ANGLEMOD (current + move);
-}
-
 // #64 void(entity e, entity ignore) tracetoss (DP_QC_TRACETOSS)
 void VM_CL_tracetoss (void)
 {
@@ -766,8 +672,6 @@ qboolean csqc_usecsqclistener = false;//[515]: per-frame
 static void CSQC_R_RecalcView (void)
 {
        extern matrix4x4_t viewmodelmatrix;
-       viewmodelmatrix = identitymatrix;
-       r_view.matrix = identitymatrix;
        Matrix4x4_CreateFromQuakeEntity(&r_view.matrix, csqc_origin[0], csqc_origin[1], csqc_origin[2], csqc_angles[0], csqc_angles[1], csqc_angles[2], 1);
        Matrix4x4_CreateFromQuakeEntity(&viewmodelmatrix, csqc_origin[0], csqc_origin[1], csqc_origin[2], csqc_angles[0], csqc_angles[1], csqc_angles[2], cl_viewmodel_scale.value);
 }
@@ -794,7 +698,7 @@ void VM_R_AddEntities (void)
        CSQC_RelinkAllEntities(drawmask);
        CL_RelinkLightFlashes();
 
-       *prog->time = cl.time;
+       prog->globals.client->time = cl.time;
        for(i=1;i<prog->num_edicts;i++)
        {
                ed = &prog->edicts[i];
@@ -915,10 +819,26 @@ void VM_R_SetView (void)
        PRVM_G_FLOAT(OFS_RETURN) = 1;
 }
 
+extern void CL_UpdateNetworkEntity(entity_t *e, int recursionlimit);
 //#304 void() renderscene (EXT_CSQC)
 void VM_R_RenderScene (void) //#134
 {
+       int i;
        VM_SAFEPARMCOUNT(0, VM_R_RenderScene);
+       // we need to update any RENDER_VIEWMODEL entities at this point because
+       // csqc supplies its own view matrix
+       for (i = 1;i < cl.num_entities;i++)
+       {
+               if (cl.entities_active[i])
+               {
+                       entity_t *ent = cl.entities + i;
+                       if ((ent->render.flags & RENDER_VIEWMODEL) || ent->state_current.tagentity)
+                               CL_UpdateNetworkEntity(ent, 32);
+               }
+       }
+       // and of course the engine viewmodel needs updating as well
+       CL_UpdateNetworkEntity(&cl.viewent, 32);
+       // now draw stuff!
        R_RenderView();
 }
 
@@ -1841,11 +1761,11 @@ void VM_CL_setattachment (void)
        if (tagentity == NULL)
                tagentity = prog->edicts;
 
-       v = PRVM_GETEDICTFIELDVALUE(e, csqc_fieldoff_tag_entity);
+       v = PRVM_EDICTFIELDVALUE(e, prog->fieldoffsets.tag_entity);
        if (v)
                v->edict = PRVM_EDICT_TO_PROG(tagentity);
 
-       v = PRVM_GETEDICTFIELDVALUE(e, csqc_fieldoff_tag_index);
+       v = PRVM_EDICTFIELDVALUE(e, prog->fieldoffsets.tag_index);
        if (v)
                v->_float = 0;
        if (tagentity != NULL && tagentity != prog->edicts && tagname && tagname[0])
@@ -1920,13 +1840,13 @@ int CL_GetTagMatrix (matrix4x4_t *out, prvm_edict_t *ent, int tagindex)
        else
                tagmatrix = identitymatrix;
 
-       if ((val = PRVM_GETEDICTFIELDVALUE(ent, csqc_fieldoff_tag_entity)) && val->edict)
+       if ((val = PRVM_EDICTFIELDVALUE(ent, prog->fieldoffsets.tag_entity)) && val->edict)
        { // DP_GFX_QUAKE3MODELTAGS, scan all chain and stop on unattached entity
                attachloop = 0;
                do
                {
                        attachent = PRVM_EDICT_NUM(val->edict); // to this it entity our entity is attached
-                       val = PRVM_GETEDICTFIELDVALUE(ent, csqc_fieldoff_tag_index);
+                       val = PRVM_EDICTFIELDVALUE(ent, prog->fieldoffsets.tag_index);
 
                        model = CSQC_GetModelFromEntity(attachent);
 
@@ -1936,7 +1856,7 @@ int CL_GetTagMatrix (matrix4x4_t *out, prvm_edict_t *ent, int tagindex)
                                attachmatrix = identitymatrix;
 
                        // apply transformation by child entity matrix
-                       val = PRVM_GETEDICTFIELDVALUE(ent, csqc_fieldoff_scale);
+                       val = PRVM_EDICTFIELDVALUE(ent, prog->fieldoffsets.scale);
                        if (val->_float == 0)
                                val->_float = 1;
                        Matrix4x4_CreateFromQuakeEntity(&entitymatrix, ent->fields.client->origin[0], ent->fields.client->origin[1], ent->fields.client->origin[2], -ent->fields.client->angles[0], ent->fields.client->angles[1], ent->fields.client->angles[2], val->_float);
@@ -1952,22 +1872,22 @@ int CL_GetTagMatrix (matrix4x4_t *out, prvm_edict_t *ent, int tagindex)
                        if (attachloop > 255) // prevent runaway looping
                                return 5;
                }
-               while ((val = PRVM_GETEDICTFIELDVALUE(ent, csqc_fieldoff_tag_entity)) && val->edict);
+               while ((val = PRVM_EDICTFIELDVALUE(ent, prog->fieldoffsets.tag_entity)) && val->edict);
        }
 
        // normal or RENDER_VIEWMODEL entity (or main parent entity on attach chain)
-       val = PRVM_GETEDICTFIELDVALUE(ent, csqc_fieldoff_scale);
+       val = PRVM_EDICTFIELDVALUE(ent, prog->fieldoffsets.scale);
        if (val->_float == 0)
                val->_float = 1;
        // Alias models have inverse pitch, bmodels can't have tags, so don't check for modeltype...
        Matrix4x4_CreateFromQuakeEntity(&entitymatrix, ent->fields.client->origin[0], ent->fields.client->origin[1], ent->fields.client->origin[2], -ent->fields.client->angles[0], ent->fields.client->angles[1], ent->fields.client->angles[2], val->_float);
        Matrix4x4_Concat(out, &entitymatrix, &tagmatrix);
 
-       if ((val = PRVM_GETEDICTFIELDVALUE(ent, csqc_fieldoff_renderflags)) && (RF_VIEWMODEL & (int)val->_float))
+       if ((val = PRVM_EDICTFIELDVALUE(ent, prog->fieldoffsets.renderflags)) && (RF_VIEWMODEL & (int)val->_float))
        {// RENDER_VIEWMODEL magic
                Matrix4x4_Copy(&tagmatrix, out);
 
-               val = PRVM_GETEDICTFIELDVALUE(ent, csqc_fieldoff_scale);
+               val = PRVM_EDICTFIELDVALUE(ent, prog->fieldoffsets.scale);
                if (val->_float == 0)
                        val->_float = 1;
 
@@ -2074,7 +1994,7 @@ void VM_WasFreed (void)
        VM_SAFEPARMCOUNT(1, VM_WasFreed);
 
        e = PRVM_G_EDICT(OFS_PARM0);
-       if (!e->priv.required->free || (e->priv.required->free && (e->priv.required->freetime < 2 || (*prog->time - e->priv.required->freetime) > 0.5 )))
+       if (!e->priv.required->free || (e->priv.required->free && (e->priv.required->freetime < 2 || (prog->globals.client->time - e->priv.required->freetime) > 0.5 )))
                PRVM_G_FLOAT(OFS_RETURN) = false;
        else
                PRVM_G_FLOAT(OFS_RETURN) = true;
@@ -2083,18 +2003,15 @@ void VM_WasFreed (void)
 void VM_CL_select_cube (void)
 {
        int             i;
-       int             chain_of;
        float   *mins2, *maxs2;
        prvm_edict_t    *ent, *chain;
        vec3_t  mins1, maxs1;
 
        VM_SAFEPARMCOUNT(2, VM_CL_select_cube);
 
-       // is the same like !(prog->flag & PRVM_FE_CHAIN) - even if the operator precedence is another
-       if(!prog->flag & PRVM_FE_CHAIN)
+       if (prog->fieldoffsets.chain < 0)
                PRVM_ERROR("VM_findchain: %s doesnt have a chain field !\n", PRVM_NAME);
 
-       chain_of = PRVM_ED_FindField("chain")->ofs;
        chain = prog->edicts;
 
        mins2 = PRVM_G_VECTOR(OFS_PARM0);
@@ -2112,7 +2029,7 @@ void VM_CL_select_cube (void)
                        continue;
                if (maxs1[0] < mins2[0] || maxs1[1] < mins2[1] || maxs1[2] < mins2[2])
                        continue;
-               PRVM_E_INT(ent,chain_of) = PRVM_NUM_FOR_EDICT(chain);
+               PRVM_EDICTFIELDVALUE(ent,prog->fieldoffsets.chain)->edict = PRVM_NUM_FOR_EDICT(chain);
                chain = ent;
        }
 
@@ -2122,7 +2039,6 @@ void VM_CL_select_cube (void)
 void VM_CL_select_super (void)
 {
 /*     int             i;
-       int             chain_of;
        float   *v[8];
        prvm_edict_t    *ent, *chain;
        vec3_t  mins1, maxs1;
@@ -2131,11 +2047,9 @@ void VM_CL_select_super (void)
        for(i=0;i<8;i++)
                v[i] = PRVM_G_VECTOR(OFS_PARM0+i*3);
 
-       // is the same like !(prog->flag & PRVM_FE_CHAIN) - even if the operator precedence is another
-       if(!prog->flag & PRVM_FE_CHAIN)
+       if (prog->fieldoffsets.chain < 0)
                PRVM_ERROR("VM_findchain: %s doesnt have a chain field !\n", PRVM_NAME);
 
-       chain_of = PRVM_ED_FindField("chain")->ofs;
        chain = prog->edicts;
 
        mins2 = PRVM_G_VECTOR(OFS_PARM0);
@@ -2153,7 +2067,7 @@ void VM_CL_select_super (void)
                        continue;
                if (maxs1[0] < mins2[0] || maxs1[1] < mins2[1] || maxs1[2] < mins2[2])
                        continue;
-               PRVM_E_INT(ent,chain_of) = PRVM_NUM_FOR_EDICT(chain);
+               PRVM_EDICTFIELDVALUE(ent,prog->fieldoffsets.chain)->edict = PRVM_NUM_FOR_EDICT(chain);
                chain = ent;
        }
 
@@ -2308,7 +2222,7 @@ VM_cvar,                                  // #45 float(string s) cvar
 VM_localcmd,                           // #46 void(string s) localcmd
 VM_nextent,                                    // #47 entity(entity e) nextent
 VM_CL_particle,                                // #48 void(vector o, vector d, float color, float count) particle
-VM_CL_changeyaw,                       // #49 void(entity ent, float ideal_yaw, float speed_yaw) ChangeYaw
+VM_changeyaw,                          // #49 void(entity ent) ChangeYaw
 NULL,                                          // #50
 VM_vectoangles,                                // #51 vector(vector v) vectoangles
 0,                     // #52 void(float to, float f) WriteByte
@@ -2322,7 +2236,7 @@ VM_vectoangles,                           // #51 vector(vector v) vectoangles
 VM_sin,                                                // #60 float(float f) sin (DP_QC_SINCOSSQRTPOW)
 VM_cos,                                                // #61 float(float f) cos (DP_QC_SINCOSSQRTPOW)
 VM_sqrt,                                       // #62 float(float f) sqrt (DP_QC_SINCOSSQRTPOW)
-VM_CL_changepitch,                     // #63 void(entity ent, float ideal_pitch, float speed_pitch) changepitch (DP_QC_CHANGEPITCH)
+VM_changepitch,                                // #63 void(entity ent) changepitch (DP_QC_CHANGEPITCH)
 VM_CL_tracetoss,                       // #64 void(entity e, entity ignore) tracetoss (DP_QC_TRACETOSS)
 VM_etos,                                       // #65 string(entity ent) etos (DP_QC_ETOS)
 NULL,                                          // #66