]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - world.c
edict: Move free and freetime into prvm_edict_t itself
[xonotic/darkplaces.git] / world.c
diff --git a/world.c b/world.c
index 42ed670d05665b3c6d4ee13de09e192fbb2e34c4..39e0102cf63943b243bd7d8ade49681acdb7eb33 100644 (file)
--- a/world.c
+++ b/world.c
@@ -22,6 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #include "quakedef.h"
 #include "clvm_cmds.h"
 #include "cl_collision.h"
+#include "com_list.h"
 
 /*
 
@@ -147,10 +148,10 @@ void World_UnlinkAll(world_t *world)
        // unlink all entities one by one
        grid = &world->areagrid_outside;
        while (grid->list.next != &grid->list)
-               World_UnlinkEdict(PRVM_EDICT_NUM(List_Entry(*grid->list.next, link_t, list)->entitynumber));
+               World_UnlinkEdict(PRVM_EDICT_NUM(List_Entry(grid->list.next, link_t, list)->entitynumber));
        for (i = 0, grid = world->areagrid;i < AREA_GRIDNODES;i++, grid++)
                while (grid->list.next != &grid->list)
-                       World_UnlinkEdict(PRVM_EDICT_NUM(List_Entry(*grid->list.next, link_t, list)->entitynumber));
+                       World_UnlinkEdict(PRVM_EDICT_NUM(List_Entry(grid->list.next, link_t, list)->entitynumber));
 }
 
 /*
@@ -172,7 +173,6 @@ int World_EntitiesInBox(world_t *world, const vec3_t requestmins, const vec3_t r
 {
        prvm_prog_t *prog = world->prog;
        int numlist;
-       llist_t *pos;
        link_t *grid;
        link_t *l;
        prvm_edict_t *ent;
@@ -215,14 +215,13 @@ int World_EntitiesInBox(world_t *world, const vec3_t requestmins, const vec3_t r
        if (world->areagrid_outside.list.next)
        {
                grid = &world->areagrid_outside;
-               List_For_Each(pos, &grid->list)
+               List_For_Each_Entry(l, &grid->list, list)
                {
-                       l = List_Entry(*pos, link_t, list);
                        ent = PRVM_EDICT_NUM(l->entitynumber);
                        if (ent->priv.server->areagridmarknumber != world->areagrid_marknumber)
                        {
                                ent->priv.server->areagridmarknumber = world->areagrid_marknumber;
-                               if (!ent->priv.server->free && BoxesOverlap(paddedmins, paddedmaxs, ent->priv.server->areamins, ent->priv.server->areamaxs))
+                               if (!ent->free && BoxesOverlap(paddedmins, paddedmaxs, ent->priv.server->areamins, ent->priv.server->areamaxs))
                                {
                                        if (numlist < maxlist)
                                                list[numlist] = ent;
@@ -240,14 +239,13 @@ int World_EntitiesInBox(world_t *world, const vec3_t requestmins, const vec3_t r
                {
                        if (grid->list.next)
                        {
-                               List_For_Each(pos, &grid->list)
+                               List_For_Each_Entry(l, &grid->list, list)
                                {
-                                       l = List_Entry(*pos, link_t, list);
                                        ent = PRVM_EDICT_NUM(l->entitynumber);
                                        if (ent->priv.server->areagridmarknumber != world->areagrid_marknumber)
                                        {
                                                ent->priv.server->areagridmarknumber = world->areagrid_marknumber;
-                                               if (!ent->priv.server->free && BoxesOverlap(paddedmins, paddedmaxs, ent->priv.server->areamins, ent->priv.server->areamaxs))
+                                               if (!ent->free && BoxesOverlap(paddedmins, paddedmaxs, ent->priv.server->areamins, ent->priv.server->areamaxs))
                                                {
                                                        if (numlist < maxlist)
                                                                list[numlist] = ent;
@@ -315,7 +313,7 @@ void World_LinkEdict(world_t *world, prvm_edict_t *ent, const vec3_t mins, const
                return;
 
        // don't add free entities
-       if (ent->priv.server->free)
+       if (ent->free)
                return;
 
        VectorCopy(mins, ent->priv.server->areamins);
@@ -1522,7 +1520,7 @@ static void World_Physics_Init(void)
 
 #ifndef LINK_TO_LIBODE
        // Load the DLL
-       if (Sys_LoadLibrary (dllnames, &ode_dll, odefuncs))
+       if (Sys_LoadDependency (dllnames, &ode_dll, odefuncs))
 #endif
        {
                dInitODE();
@@ -1539,7 +1537,7 @@ static void World_Physics_Init(void)
 # else
                        Con_Printf("ODE library not compiled for double precision - incompatible!  Not using ODE physics.\n");
 # endif
-                       Sys_UnloadLibrary(&ode_dll);
+                       Sys_FreeLibrary(&ode_dll);
                        ode_dll = NULL;
                }
                else
@@ -1565,7 +1563,7 @@ static void World_Physics_Shutdown(void)
        {
                dCloseODE();
 #ifndef LINK_TO_LIBODE
-               Sys_UnloadLibrary(&ode_dll);
+               Sys_FreeLibrary(&ode_dll);
                ode_dll = NULL;
 #endif
        }
@@ -1864,7 +1862,7 @@ static void World_Physics_Frame_ForceFromEntity(world_t *world, prvm_edict_t *ed
        if (!forcetype)
                return;
        enemy = PRVM_gameedictedict(ed, enemy);
-       if (enemy <= 0 || enemy >= prog->num_edicts || prog->edicts[enemy].priv.required->free || prog->edicts[enemy].priv.server->ode_body == 0)
+       if (enemy <= 0 || enemy >= prog->num_edicts || prog->edicts[enemy].free || prog->edicts[enemy].priv.server->ode_body == 0)
                return;
        VectorCopy(PRVM_gameedictvector(ed, movedir), movedir);
        VectorCopy(PRVM_gameedictvector(ed, origin), origin);
@@ -1916,9 +1914,9 @@ static void World_Physics_Frame_JointFromEntity(world_t *world, prvm_edict_t *ed
        VectorCopy(PRVM_gameedictvector(ed, movedir), movedir);
        if(movetype == MOVETYPE_PHYSICS)
                jointtype = JOINTTYPE_NONE; // 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)
+       if(enemy <= 0 || enemy >= prog->num_edicts || prog->edicts[enemy].free || prog->edicts[enemy].priv.server->ode_body == 0)
                enemy = 0;
-       if(aiment <= 0 || aiment >= prog->num_edicts || prog->edicts[aiment].priv.required->free || prog->edicts[aiment].priv.server->ode_body == 0)
+       if(aiment <= 0 || aiment >= prog->num_edicts || prog->edicts[aiment].free || prog->edicts[aiment].priv.server->ode_body == 0)
                aiment = 0;
        // see http://www.ode.org/old_list_archives/2006-January/017614.html
        // we want to set ERP? make it fps independent and work like a spring constant
@@ -2927,7 +2925,7 @@ static void nearCallback (void *data, dGeomID o1, dGeomID o2)
                return;
 
        ed1 = (prvm_edict_t *) dGeomGetData(o1);
-       if(ed1 && ed1->priv.server->free)
+       if(ed1 && ed1->free)
                ed1 = NULL;
        if(ed1)
        {
@@ -2938,7 +2936,7 @@ static void nearCallback (void *data, dGeomID o1, dGeomID o2)
        }
 
        ed2 = (prvm_edict_t *) dGeomGetData(o2);
-       if(ed2 && ed2->priv.server->free)
+       if(ed2 && ed2->free)
                ed2 = NULL;
        if(ed2)
        {
@@ -3052,11 +3050,11 @@ void World_Physics_Frame(world_t *world, double frametime, double gravity)
                if (prog)
                {
                        for (i = 0, ed = prog->edicts + i;i < prog->num_edicts;i++, ed++)
-                               if (!prog->edicts[i].priv.required->free)
+                               if (!prog->edicts[i].free)
                                        World_Physics_Frame_BodyFromEntity(world, ed);
                        // oh, and it must be called after all bodies were created
                        for (i = 0, ed = prog->edicts + i;i < prog->num_edicts;i++, ed++)
-                               if (!prog->edicts[i].priv.required->free)
+                               if (!prog->edicts[i].free)
                                        World_Physics_Frame_JointFromEntity(world, ed);
                }
 
@@ -3077,7 +3075,7 @@ void World_Physics_Frame(world_t *world, double frametime, double gravity)
                        {
                                int j;
                                for (j = 0, ed = prog->edicts + j;j < prog->num_edicts;j++, ed++)
-                                       if (!prog->edicts[j].priv.required->free)
+                                       if (!prog->edicts[j].free)
                                                World_Physics_Frame_ForceFromEntity(world, ed);
                        }
                        // run physics (move objects, calculate new velocities)
@@ -3094,7 +3092,7 @@ void World_Physics_Frame(world_t *world, double frametime, double gravity)
                if (prog)
                {
                        for (i = 1, ed = prog->edicts + i;i < prog->num_edicts;i++, ed++)
-                               if (!prog->edicts[i].priv.required->free)
+                               if (!prog->edicts[i].free)
                                        World_Physics_Frame_BodyToEntity(world, ed);
 
                        // print stats
@@ -3106,7 +3104,7 @@ void World_Physics_Frame(world_t *world, double frametime, double gravity)
                                world->physics.ode_activeovjects = 0;
                                for (i = 1, ed = prog->edicts + i;i < prog->num_edicts;i++, ed++)
                                {
-                                       if (prog->edicts[i].priv.required->free)
+                                       if (prog->edicts[i].free)
                                                continue;
                                        body = (dBodyID)prog->edicts[i].priv.server->ode_body;
                                        if (!body)