From 8ce2f78e1818d01c6fb0dd73998d4a07e1078617 Mon Sep 17 00:00:00 2001 From: havoc Date: Mon, 4 Feb 2008 11:24:42 +0000 Subject: [PATCH] replaced World_Clear with World_SetSize and World_UnlinkAll git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@8070 d7cf8633-e32d-0410-b094-e92efae38249 --- cl_parse.c | 13 ++++--------- csprogs.c | 11 +---------- sv_main.c | 15 ++------------- world.c | 25 ++++++++++++++++++++++--- world.h | 4 +++- 5 files changed, 32 insertions(+), 36 deletions(-) diff --git a/cl_parse.c b/cl_parse.c index 8c05fe3a..14de82c8 100644 --- a/cl_parse.c +++ b/cl_parse.c @@ -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(); diff --git a/csprogs.c b/csprogs.c index c6b38b15..7748ccf0 100644 --- 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) diff --git a/sv_main.c b/sv_main.c index aee83968..08a36266 100644 --- 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 b178bad2..f332f039 100644 --- 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 cbe9747f..1d16b748 100644 --- 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); -- 2.39.2