]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - world.c
reworked progs loading so that entvars_t and globalvars_t are no longer
[xonotic/darkplaces.git] / world.c
diff --git a/world.c b/world.c
index 9028195730ee26c0d9e903b21c39ddf7e7dcf588..4830996ca77b50073ca69005e277fa51bee82b37 100644 (file)
--- a/world.c
+++ b/world.c
@@ -1725,7 +1725,7 @@ void World_Physics_ApplyCmd(prvm_edict_t *ed, edict_odefunc_t *f)
                dBodyEnable(body);
                dBodyAddForceAtRelPos(body, f->v1[0], f->v1[1], f->v1[2], f->v2[0], f->v2[1], f->v2[2]);
                break;
-       case ODEFUNC_RELTORGUE:
+       case ODEFUNC_RELTORQUE:
                dBodyEnable(body);
                dBodyAddRelTorque(body, f->v1[0], f->v1[1], f->v1[2]);
                break;
@@ -1746,7 +1746,6 @@ static void World_Physics_Frame_BodyToEntity(world_t *world, prvm_edict_t *ed)
        int movetype;
        matrix4x4_t bodymatrix;
        matrix4x4_t entitymatrix;
-       prvm_eval_t *val;
        vec3_t angles;
        vec3_t avelocity;
        vec3_t forward, left, up;
@@ -1756,11 +1755,10 @@ static void World_Physics_Frame_BodyToEntity(world_t *world, prvm_edict_t *ed)
        int jointtype;
        if (!body)
                return;
-       val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.movetype);
-       movetype = (int)val->_float;
+       movetype = (int)PRVM_gameedictfloat(ed, movetype);
        if (movetype != MOVETYPE_PHYSICS)
        {
-               jointtype = 0;val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.jointtype);if (val) jointtype = (int)val->_float;
+               jointtype = (int)PRVM_gameedictfloat(ed, jointtype);
                switch(jointtype)
                {
                        // TODO feed back data from physics
@@ -1817,14 +1815,14 @@ static void World_Physics_Frame_BodyToEntity(world_t *world, prvm_edict_t *ed)
                avelocity[PITCH] *= pitchsign;
        }
 
-       val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.origin);if (val) VectorCopy(origin, val->vector);
-       val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.velocity);if (val) VectorCopy(velocity, val->vector);
-       //val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.axis_forward);if (val) VectorCopy(forward, val->vector);
-       //val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.axis_left);if (val) VectorCopy(left, val->vector);
-       //val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.axis_up);if (val) VectorCopy(up, val->vector);
-       //val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.spinvelocity);if (val) VectorCopy(spinvelocity, val->vector);
-       val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.angles);if (val) VectorCopy(angles, val->vector);
-       val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.avelocity);if (val) VectorCopy(avelocity, val->vector);
+       VectorCopy(origin, PRVM_gameedictvector(ed, origin));
+       VectorCopy(velocity, PRVM_gameedictvector(ed, velocity));
+       //VectorCopy(forward, PRVM_gameedictvector(ed, axis_forward));
+       //VectorCopy(left, PRVM_gameedictvector(ed, axis_left));
+       //VectorCopy(up, PRVM_gameedictvector(ed, axis_up));
+       //VectorCopy(spinvelocity, PRVM_gameedictvector(ed, spinvelocity));
+       VectorCopy(angles, PRVM_gameedictvector(ed, angles));
+       VectorCopy(avelocity, PRVM_gameedictvector(ed, avelocity));
 
        // values for BodyFromEntity to check if the qc modified anything later
        VectorCopy(origin, ed->priv.server->ode_origin);
@@ -1850,19 +1848,18 @@ static void World_Physics_Frame_JointFromEntity(world_t *world, prvm_edict_t *ed
        int enemy = 0, aiment = 0;
        vec3_t origin, velocity, angles, forward, left, up, movedir;
        vec_t CFM, ERP, FMax, Stop, Vel;
-       prvm_eval_t *val;
        VectorClear(origin);
        VectorClear(velocity);
        VectorClear(angles);
        VectorClear(movedir);
-       val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.movetype);if (val) movetype = (int)val->_float;
-       val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.jointtype);if (val) jointtype = (int)val->_float;
-       val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.enemy);if (val) enemy = val->_int;
-       val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.aiment);if (val) aiment = val->_int;
-       val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.origin);if (val) VectorCopy(val->vector, origin);
-       val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.velocity);if (val) VectorCopy(val->vector, velocity);
-       val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.angles);if (val) VectorCopy(val->vector, angles);
-       val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.movedir);if (val) VectorCopy(val->vector, movedir);
+       movetype = (int)PRVM_gameedictfloat(ed, movetype);
+       jointtype = (int)PRVM_gameedictfloat(ed, jointtype);
+       enemy = PRVM_gameedictedict(ed, enemy);
+       aiment = PRVM_gameedictedict(ed, aiment);
+       VectorCopy(PRVM_gameedictvector(ed, origin), origin);
+       VectorCopy(PRVM_gameedictvector(ed, velocity), velocity);
+       VectorCopy(PRVM_gameedictvector(ed, angles), angles);
+       VectorCopy(PRVM_gameedictvector(ed, movedir), movedir);
        if(movetype == MOVETYPE_PHYSICS)
                jointtype = 0; // can't have both
        if(enemy <= 0 || enemy >= prog->num_edicts || prog->edicts[enemy].priv.required->free || prog->edicts[enemy].priv.server->ode_body == 0)
@@ -2044,7 +2041,6 @@ static void World_Physics_Frame_BodyFromEntity(world_t *world, prvm_edict_t *ed)
        int triangleindex;
        int vertexindex;
        mempool_t *mempool;
-       prvm_eval_t *val;
        qboolean modified = false;
        vec3_t angles;
        vec3_t avelocity;
@@ -2074,9 +2070,9 @@ static void World_Physics_Frame_BodyFromEntity(world_t *world, prvm_edict_t *ed)
 #endif
        VectorClear(entmins);
        VectorClear(entmaxs);
-       val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.solid);if (val) solid = (int)val->_float;
-       val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.movetype);if (val) movetype = (int)val->_float;
-       val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.scale);if (val && val->_float) scale = val->_float;
+       solid = (int)PRVM_gameedictfloat(ed, solid);
+       movetype = (int)PRVM_gameedictfloat(ed, movetype);
+       scale = PRVM_gameedictfloat(ed, scale);if (!scale) scale = 1.0f;
        modelindex = 0;
        if (world == &sv.world)
                mempool = sv_mempool;
@@ -2088,9 +2084,7 @@ static void World_Physics_Frame_BodyFromEntity(world_t *world, prvm_edict_t *ed)
        switch(solid)
        {
        case SOLID_BSP:
-               val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.modelindex);
-               if (val)
-                       modelindex = (int)val->_float;
+               modelindex = (int)PRVM_gameedictfloat(ed, modelindex);
                if (world == &sv.world)
                        model = SV_GetModelByIndex(modelindex);
                else if (world == &cl.world)
@@ -2101,7 +2095,7 @@ static void World_Physics_Frame_BodyFromEntity(world_t *world, prvm_edict_t *ed)
                {
                        VectorScale(model->normalmins, scale, entmins);
                        VectorScale(model->normalmaxs, scale, entmaxs);
-                       val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.mass);if (val) massval = val->_float;
+                       massval = PRVM_gameedictfloat(ed, mass);
                }
                else
                {
@@ -2115,9 +2109,9 @@ static void World_Physics_Frame_BodyFromEntity(world_t *world, prvm_edict_t *ed)
        case SOLID_PHYSICS_BOX:
        case SOLID_PHYSICS_SPHERE:
        case SOLID_PHYSICS_CAPSULE:
-               val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.mins);if (val) VectorCopy(val->vector, entmins);
-               val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.maxs);if (val) VectorCopy(val->vector, entmaxs);
-               val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.mass);if (val) massval = val->_float;
+               VectorCopy(PRVM_gameedictvector(ed, mins), entmins);
+               VectorCopy(PRVM_gameedictvector(ed, maxs), entmaxs);
+               massval = PRVM_gameedictfloat(ed, mass);
                break;
        default:
                if (ed->priv.server->ode_physics)
@@ -2157,7 +2151,7 @@ static void World_Physics_Frame_BodyFromEntity(world_t *world, prvm_edict_t *ed)
                if (massval * geomsize[0] * geomsize[1] * geomsize[2] == 0)
                {
                        if (movetype == MOVETYPE_PHYSICS)
-                               Con_Printf("entity %i (classname %s) .mass * .size_x * .size_y * .size_z == 0\n", PRVM_NUM_FOR_EDICT(ed), PRVM_GetString(PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.classname)->string));
+                               Con_Printf("entity %i (classname %s) .mass * .size_x * .size_y * .size_z == 0\n", PRVM_NUM_FOR_EDICT(ed), PRVM_GetString(PRVM_gameedictstring(ed, classname)));
                        massval = 1.0f;
                        VectorSet(geomsize, 1.0f, 1.0f, 1.0f);
                }
@@ -2168,7 +2162,7 @@ static void World_Physics_Frame_BodyFromEntity(world_t *world, prvm_edict_t *ed)
                        ed->priv.server->ode_offsetmatrix = identitymatrix;
                        if (!model)
                        {
-                               Con_Printf("entity %i (classname %s) has no model\n", PRVM_NUM_FOR_EDICT(ed), PRVM_GetString(PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.classname)->string));
+                               Con_Printf("entity %i (classname %s) has no model\n", PRVM_NUM_FOR_EDICT(ed), PRVM_GetString(PRVM_gameedictstring(ed, classname)));
                                goto treatasbox;
                        }
                        // add an optimized mesh to the model containing only the SUPERCONTENTS_SOLID surfaces
@@ -2176,7 +2170,7 @@ static void World_Physics_Frame_BodyFromEntity(world_t *world, prvm_edict_t *ed)
                                Mod_CreateCollisionMesh(model);
                        if (!model->brush.collisionmesh || !model->brush.collisionmesh->numtriangles)
                        {
-                               Con_Printf("entity %i (classname %s) has no geometry\n", PRVM_NUM_FOR_EDICT(ed), PRVM_GetString(PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.classname)->string));
+                               Con_Printf("entity %i (classname %s) has no geometry\n", PRVM_NUM_FOR_EDICT(ed), PRVM_GetString(PRVM_gameedictstring(ed, classname)));
                                goto treatasbox;
                        }
                        // ODE requires persistent mesh storage, so we need to copy out
@@ -2294,16 +2288,16 @@ treatasbox:
        VectorClear(angles);
        VectorClear(avelocity);
        gravity = true;
-       val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.origin);if (val) VectorCopy(val->vector, origin);
-       val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.velocity);if (val) VectorCopy(val->vector, velocity);
-       //val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.axis_forward);if (val) VectorCopy(val->vector, forward);
-       //val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.axis_left);if (val) VectorCopy(val->vector, left);
-       //val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.axis_up);if (val) VectorCopy(val->vector, up);
-       //val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.spinvelocity);if (val) VectorCopy(val->vector, spinvelocity);
-       val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.angles);if (val) VectorCopy(val->vector, angles);
-       val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.avelocity);if (val) VectorCopy(val->vector, avelocity);
-       val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.gravity);if (val) { if(val->_float != 0.0f && val->_float < 0.5f) gravity = false; }
-       if(ed == prog->edicts)
+       VectorCopy(PRVM_gameedictvector(ed, origin), origin);
+       VectorCopy(PRVM_gameedictvector(ed, velocity), velocity);
+       //VectorCopy(PRVM_gameedictvector(ed, axis_forward), forward);
+       //VectorCopy(PRVM_gameedictvector(ed, axis_left), left);
+       //VectorCopy(PRVM_gameedictvector(ed, axis_up), up);
+       //VectorCopy(PRVM_gameedictvector(ed, spinvelocity), spinvelocity);
+       VectorCopy(PRVM_gameedictvector(ed, angles), angles);
+       VectorCopy(PRVM_gameedictvector(ed, avelocity), avelocity);
+       if (PRVM_gameedictfloat(ed, gravity) != 0.0f && PRVM_gameedictfloat(ed, gravity) < 0.5f) gravity = false;
+       if (ed == prog->edicts)
                gravity = false;
 
        // compatibility for legacy entities
@@ -2352,9 +2346,9 @@ treatasbox:
                if (IS_NAN(test))
                {
                        modified = true;
-                       //Con_Printf("Fixing NAN values on entity %i : .classname = \"%s\" .origin = '%f %f %f' .velocity = '%f %f %f' .axis_forward = '%f %f %f' .axis_left = '%f %f %f' .axis_up = %f %f %f' .spinvelocity = '%f %f %f'\n", PRVM_NUM_FOR_EDICT(ed), PRVM_GetString(PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.classname)->string), origin[0], origin[1], origin[2], velocity[0], velocity[1], velocity[2], forward[0], forward[1], forward[2], left[0], left[1], left[2], up[0], up[1], up[2], spinvelocity[0], spinvelocity[1], spinvelocity[2]);
+                       //Con_Printf("Fixing NAN values on entity %i : .classname = \"%s\" .origin = '%f %f %f' .velocity = '%f %f %f' .axis_forward = '%f %f %f' .axis_left = '%f %f %f' .axis_up = %f %f %f' .spinvelocity = '%f %f %f'\n", PRVM_NUM_FOR_EDICT(ed), PRVM_GetString(PRVM_gameedictstring(ed, classname)), origin[0], origin[1], origin[2], velocity[0], velocity[1], velocity[2], forward[0], forward[1], forward[2], left[0], left[1], left[2], up[0], up[1], up[2], spinvelocity[0], spinvelocity[1], spinvelocity[2]);
                        if (physics_ode_trick_fixnan.integer >= 2)
-                               Con_Printf("Fixing NAN values on entity %i : .classname = \"%s\" .origin = '%f %f %f' .velocity = '%f %f %f' .angles = '%f %f %f' .avelocity = '%f %f %f'\n", PRVM_NUM_FOR_EDICT(ed), PRVM_GetString(PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.classname)->string), origin[0], origin[1], origin[2], velocity[0], velocity[1], velocity[2], angles[0], angles[1], angles[2], avelocity[0], avelocity[1], avelocity[2]);
+                               Con_Printf("Fixing NAN values on entity %i : .classname = \"%s\" .origin = '%f %f %f' .velocity = '%f %f %f' .angles = '%f %f %f' .avelocity = '%f %f %f'\n", PRVM_NUM_FOR_EDICT(ed), PRVM_GetString(PRVM_gameedictstring(ed, classname)), origin[0], origin[1], origin[2], velocity[0], velocity[1], velocity[2], angles[0], angles[1], angles[2], avelocity[0], avelocity[1], avelocity[2]);
                        test = VectorLength2(origin);
                        if (IS_NAN(test))
                                VectorClear(origin);
@@ -2506,7 +2500,6 @@ static void nearCallback (void *data, dGeomID o1, dGeomID o2)
        dJointID c;
        int i;
        int numcontacts;
-       prvm_eval_t *val;
        float bouncefactor1 = 0.0f;
        float bouncestop1 = 60.0f / 800.0f;
        float bouncefactor2 = 0.0f;
@@ -2541,13 +2534,10 @@ static void nearCallback (void *data, dGeomID o1, dGeomID o2)
                ed1 = NULL;
        if(ed1)
        {
-               val = PRVM_EDICTFIELDVALUE(ed1, prog->fieldoffsets.bouncefactor);
-               if (val!=0 && val->_float)
-                       bouncefactor1 = val->_float;
-
-               val = PRVM_EDICTFIELDVALUE(ed1, prog->fieldoffsets.bouncestop);
-               if (val!=0 && val->_float)
-                       bouncestop1 = val->_float;
+               bouncefactor1 = PRVM_gameedictfloat(ed1, bouncefactor);
+               bouncestop1 = PRVM_gameedictfloat(ed1, bouncestop);
+               if (!bouncestop1)
+                       bouncestop1 = 60.0f / 800.0f;
        }
 
        ed2 = (prvm_edict_t *) dGeomGetData(o2);
@@ -2555,22 +2545,19 @@ static void nearCallback (void *data, dGeomID o1, dGeomID o2)
                ed2 = NULL;
        if(ed2)
        {
-               val = PRVM_EDICTFIELDVALUE(ed2, prog->fieldoffsets.bouncefactor);
-               if (val!=0 && val->_float)
-                       bouncefactor2 = val->_float;
-
-               val = PRVM_EDICTFIELDVALUE(ed2, prog->fieldoffsets.bouncestop);
-               if (val!=0 && val->_float)
-                       bouncestop2 = val->_float;
+               bouncefactor2 = PRVM_gameedictfloat(ed2, bouncefactor);
+               bouncestop2 = PRVM_gameedictfloat(ed2, bouncestop);
+               if (!bouncestop2)
+                       bouncestop2 = 60.0f / 800.0f;
        }
 
        if(!strcmp(prog->name, "server"))
        {
-               if(ed1 && ed1->fields.server->touch)
+               if(ed1 && PRVM_serveredictfunction(ed1, touch))
                {
                        SV_LinkEdict_TouchAreaGrid_Call(ed1, ed2 ? ed2 : prog->edicts);
                }
-               if(ed2 && ed2->fields.server->touch)
+               if(ed2 && PRVM_serveredictfunction(ed2, touch))
                {
                        SV_LinkEdict_TouchAreaGrid_Call(ed2, ed1 ? ed1 : prog->edicts);
                }