]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
replaced World_Clear with World_SetSize and World_UnlinkAll
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 4 Feb 2008 11:24:42 +0000 (11:24 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 4 Feb 2008 11:24:42 +0000 (11:24 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@8070 d7cf8633-e32d-0410-b094-e92efae38249

cl_parse.c
csprogs.c
sv_main.c
world.c
world.h

index 8c05fe3ab0c7d4447c010259e10fe28690ea69fa..14de82c8d1d53dc9a26c8292b1859966e8f0b2fb 100644 (file)
@@ -387,6 +387,8 @@ void CL_ParseEntityLump(char *entdata)
 
 extern void CL_Locs_Reload_f(void);
 extern void CL_VM_Init (void);
+static const vec3_t defaultmins = {-4096, -4096, -4096};
+static const vec3_t defaultmaxs = {4096, 4096, 4096};
 static void CL_SetupWorldModel(void)
 {
        // update the world model
@@ -395,16 +397,9 @@ static void CL_SetupWorldModel(void)
 
        // set up csqc world for collision culling
        if (cl.worldmodel)
-       {
-               VectorCopy(cl.worldmodel->normalmins, cl.world.areagrid_mins);
-               VectorCopy(cl.worldmodel->normalmaxs, cl.world.areagrid_maxs);
-       }
+               World_SetSize(&cl.world, cl.worldmodel->normalmins, cl.worldmodel->normalmaxs);
        else
-       {
-               VectorSet(cl.world.areagrid_mins, -4096, -4096, -4096);
-               VectorSet(cl.world.areagrid_maxs, 4096, 4096, 4096);
-       }
-       World_Clear(&cl.world);
+               World_SetSize(&cl.world, defaultmins, defaultmaxs);
 
        // load or reload .loc file for team chat messages
        CL_Locs_Reload_f();
index c6b38b152094497e001053ee59e549f2fdda894b..7748ccf0d2b9f4552b7d7e9d60df223780bf1d14 100644 (file)
--- a/csprogs.c
+++ b/csprogs.c
@@ -592,17 +592,8 @@ void CSQC_ReadEntities (void)
 
 void CL_VM_CB_BeginIncreaseEdicts(void)
 {
-       int i;
-       prvm_edict_t *ent;
-
        // links don't survive the transition, so unlink everything
-       for (i = 0, ent = prog->edicts;i < prog->max_edicts;i++, ent++)
-       {
-               if (!ent->priv.server->free)
-                       World_UnlinkEdict(prog->edicts + i);
-               memset(&ent->priv.server->areagrid, 0, sizeof(ent->priv.server->areagrid));
-       }
-       World_Clear(&cl.world);
+       World_UnlinkAll(&cl.world);
 }
 
 void CL_VM_CB_EndIncreaseEdicts(void)
index aee839684f545fe84a8c5af8b2ed539cc3ef7d6a..08a362665455b5f028fc08493b021600897adb48 100644 (file)
--- a/sv_main.c
+++ b/sv_main.c
@@ -2606,9 +2606,7 @@ void SV_SpawnServer (const char *server)
 //
 // clear world interaction links
 //
-       VectorCopy(sv.worldmodel->normalmins, sv.world.areagrid_mins);
-       VectorCopy(sv.worldmodel->normalmaxs, sv.world.areagrid_maxs);
-       World_Clear(&sv.world);
+       World_SetSize(&sv.world, sv.worldmodel->normalmins, sv.worldmodel->normalmaxs);
 
        strlcpy(sv.sound_precache[0], "", sizeof(sv.sound_precache[0]));
 
@@ -2726,17 +2724,8 @@ void SV_SpawnServer (const char *server)
 
 static void SV_VM_CB_BeginIncreaseEdicts(void)
 {
-       int i;
-       prvm_edict_t *ent;
-
        // links don't survive the transition, so unlink everything
-       for (i = 0, ent = prog->edicts;i < prog->max_edicts;i++, ent++)
-       {
-               if (!ent->priv.server->free)
-                       World_UnlinkEdict(prog->edicts + i);
-               memset(&ent->priv.server->areagrid, 0, sizeof(ent->priv.server->areagrid));
-       }
-       World_Clear(&sv.world);
+       World_UnlinkAll(&sv.world);
 }
 
 static void SV_VM_CB_EndIncreaseEdicts(void)
diff --git a/world.c b/world.c
index b178bad212bed4025cc0b2ffd4d02a02c7703a89..f332f0399c52ea5f221237d4c383708bae3ae2fa 100644 (file)
--- a/world.c
+++ b/world.c
@@ -76,11 +76,11 @@ void World_PrintAreaStats(world_t *world, const char *worldname)
 
 /*
 ===============
-World_Clear
+World_SetSize
 
 ===============
 */
-void World_Clear(world_t *world)
+void World_SetSize(world_t *world, const vec3_t mins, const vec3_t maxs)
 {
        int i;
        // the areagrid_marknumber is not allowed to be 0
@@ -105,9 +105,28 @@ void World_Clear(world_t *world)
        World_ClearLink(&world->areagrid_outside);
        for (i = 0;i < AREA_GRIDNODES;i++)
                World_ClearLink(&world->areagrid[i]);
-       Con_DPrintf("areagrid settings: divisions %ix%ix1 : box %f %f %f : %f %f %f size %f %f %f grid %f %f %f (mingrid %f)\n", AREA_GRID, AREA_GRID, world->areagrid_mins[0], world->areagrid_mins[1], world->areagrid_mins[2], world->areagrid_maxs[0], world->areagrid_maxs[1], world->areagrid_maxs[2], world->areagrid_size[0], world->areagrid_size[1], world->areagrid_size[2], 1.0f / world->areagrid_scale[0], 1.0f / world->areagrid_scale[1], 1.0f / world->areagrid_scale[2], sv_areagrid_mingridsize.value);
+       if (developer.integer >= 10)
+               Con_Printf("areagrid settings: divisions %ix%ix1 : box %f %f %f : %f %f %f size %f %f %f grid %f %f %f (mingrid %f)\n", AREA_GRID, AREA_GRID, world->areagrid_mins[0], world->areagrid_mins[1], world->areagrid_mins[2], world->areagrid_maxs[0], world->areagrid_maxs[1], world->areagrid_maxs[2], world->areagrid_size[0], world->areagrid_size[1], world->areagrid_size[2], 1.0f / world->areagrid_scale[0], 1.0f / world->areagrid_scale[1], 1.0f / world->areagrid_scale[2], sv_areagrid_mingridsize.value);
 }
 
+/*
+===============
+World_UnlinkAll
+
+===============
+*/
+void World_UnlinkAll(world_t *world)
+{
+       int i;
+       link_t *grid;
+       // unlink all entities one by one
+       grid = &world->areagrid_outside;
+       while (grid->next != grid)
+               World_UnlinkEdict(PRVM_EDICT_NUM(grid->next->entitynumber));
+       for (i = 0, grid = world->areagrid;i < AREA_GRIDNODES;i++, grid++)
+               while (grid->next != grid)
+                       World_UnlinkEdict(PRVM_EDICT_NUM(grid->next->entitynumber));
+}
 
 /*
 ===============
diff --git a/world.h b/world.h
index cbe9747ffb0b638307dec3283b917bf85ecdac40..1d16b74882c553172ce165d7f308eb185b43b36f 100644 (file)
--- a/world.h
+++ b/world.h
@@ -66,7 +66,9 @@ void World_InsertLinkBefore(link_t *l, link_t *before, int entitynumber);
 void World_Init(void);
 
 // called after the world model has been loaded, before linking any entities
-void World_Clear(world_t *world);
+void World_SetSize(world_t *world, const vec3_t mins, const vec3_t maxs);
+// unlinks all entities (used before reallocation of edicts)
+void World_UnlinkAll(world_t *world);
 
 void World_PrintAreaStats(world_t *world, const char *worldname);