From c2026725b55e3025eb7f6f76a3a4fa1687a15988 Mon Sep 17 00:00:00 2001 From: havoc Date: Fri, 22 Feb 2008 05:30:33 +0000 Subject: [PATCH] set csqc world.mins and world.maxs (reworked World_SetSize to make this easier) moved the qc SV_Shutdown in Host_ShutdownServer to before clients are kicked off added qc SV_Shutdown call in SV_SpawnServer (before the progs reset) fixed a bug with failed changelevel (which was unloading world) git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@8122 d7cf8633-e32d-0410-b094-e92efae38249 --- cl_parse.c | 4 ++-- csprogs.c | 4 +++- host.c | 6 +++--- sv_main.c | 33 ++++++++++++++++++++++++++------- world.c | 7 ++++++- world.h | 7 ++++++- 6 files changed, 46 insertions(+), 15 deletions(-) diff --git a/cl_parse.c b/cl_parse.c index 7fd83d30..46c3c64b 100644 --- a/cl_parse.c +++ b/cl_parse.c @@ -397,9 +397,9 @@ static void CL_SetupWorldModel(void) // set up csqc world for collision culling if (cl.worldmodel) - World_SetSize(&cl.world, cl.worldmodel->normalmins, cl.worldmodel->normalmaxs); + World_SetSize(&cl.world, cl.worldmodel->name, cl.worldmodel->normalmins, cl.worldmodel->normalmaxs); else - World_SetSize(&cl.world, defaultmins, defaultmaxs); + 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 7748ccf0..670ec099 100644 --- a/csprogs.c +++ b/csprogs.c @@ -756,13 +756,15 @@ void CL_VM_Init (void) // set time prog->globals.client->time = cl.time; - prog->globals.client->mapname = PRVM_SetEngineString(cl.worldmodel->name); + prog->globals.client->mapname = cl.worldmodel ? PRVM_SetEngineString(cl.worldmodel->name) : PRVM_SetEngineString(""); prog->globals.client->player_localentnum = cl.playerentity; // set map description (use world entity 0) val = PRVM_EDICTFIELDVALUE(prog->edicts, prog->fieldoffsets.message); if(val) val->string = PRVM_SetEngineString(cl.levelname); + VectorCopy(cl.world.mins, prog->edicts->fields.client->mins); + VectorCopy(cl.world.maxs, prog->edicts->fields.client->maxs); // call the prog init PRVM_ExecuteProgram(prog->funcoffsets.CSQC_Init, "QC function CSQC_Init is missing"); diff --git a/host.c b/host.c index c3c0b64a..0bafb91a 100644 --- a/host.c +++ b/host.c @@ -528,9 +528,6 @@ void Host_ShutdownServer(void) // make sure all the clients know we're disconnecting SV_VM_Begin(); - for (i = 0, host_client = svs.clients;i < svs.maxclients;i++, host_client++) - if (host_client->active) - SV_DropClient(false); // server shutdown if(prog->loaded) if(prog->funcoffsets.SV_Shutdown) { @@ -538,6 +535,9 @@ void Host_ShutdownServer(void) prog->funcoffsets.SV_Shutdown = 0; // prevent it from getting called again PRVM_ExecuteProgram(s,"SV_Shutdown() required"); } + for (i = 0, host_client = svs.clients;i < svs.maxclients;i++, host_client++) + if (host_client->active) + SV_DropClient(false); // server shutdown SV_VM_End(); NetConn_CloseServerPorts(); diff --git a/sv_main.c b/sv_main.c index 08a36266..99096341 100644 --- a/sv_main.c +++ b/sv_main.c @@ -798,7 +798,7 @@ void SV_SendServerinfo (client_t *client) client->clientcamera = PRVM_NUM_FOR_EDICT(client->edict); MSG_WriteByte (&client->netconnection->message, svc_setview); MSG_WriteShort (&client->netconnection->message, client->clientcamera); - + MSG_WriteByte (&client->netconnection->message, svc_signonnum); MSG_WriteByte (&client->netconnection->message, 1); @@ -2484,13 +2484,32 @@ void SV_SpawnServer (const char *server) Con_DPrintf("SpawnServer: %s\n", server); + dpsnprintf (modelname, sizeof(modelname), "maps/%s.bsp", server); + + if (!FS_FileExists(modelname)) + { + Con_Printf("SpawnServer: no map file named %s\n", modelname); + return; + } + if (cls.state != ca_dedicated) { SCR_BeginLoadingPlaque(); S_StopAllSounds(); } - dpsnprintf (modelname, sizeof(modelname), "maps/%s.bsp", server); + if(sv.active) + { + SV_VM_Begin(); + if(prog->funcoffsets.SV_Shutdown) + { + func_t s = prog->funcoffsets.SV_Shutdown; + prog->funcoffsets.SV_Shutdown = 0; // prevent it from getting called again + PRVM_ExecuteProgram(s,"SV_Shutdown() required"); + } + SV_VM_End(); + } + worldmodel = Mod_ForName(modelname, false, true, true); if (!worldmodel || !worldmodel->TraceBox) { @@ -2606,7 +2625,7 @@ void SV_SpawnServer (const char *server) // // clear world interaction links // - World_SetSize(&sv.world, sv.worldmodel->normalmins, sv.worldmodel->normalmaxs); + World_SetSize(&sv.world, sv.worldmodel->name, sv.worldmodel->normalmins, sv.worldmodel->normalmaxs); strlcpy(sv.sound_precache[0], "", sizeof(sv.sound_precache[0])); @@ -2629,10 +2648,10 @@ void SV_SpawnServer (const char *server) ent->fields.server->modelindex = 1; // world model ent->fields.server->solid = SOLID_BSP; ent->fields.server->movetype = MOVETYPE_PUSH; - VectorCopy(sv.worldmodel->normalmins, ent->fields.server->mins); - VectorCopy(sv.worldmodel->normalmaxs, ent->fields.server->maxs); - VectorCopy(sv.worldmodel->normalmins, ent->fields.server->absmin); - VectorCopy(sv.worldmodel->normalmaxs, ent->fields.server->absmax); + VectorCopy(sv.world.mins, ent->fields.server->mins); + VectorCopy(sv.world.maxs, ent->fields.server->maxs); + VectorCopy(sv.world.mins, ent->fields.server->absmin); + VectorCopy(sv.world.maxs, ent->fields.server->absmax); if (coop.value) prog->globals.server->coop = coop.integer; diff --git a/world.c b/world.c index f332f039..a9192494 100644 --- a/world.c +++ b/world.c @@ -80,9 +80,14 @@ World_SetSize =============== */ -void World_SetSize(world_t *world, const vec3_t mins, const vec3_t maxs) +void World_SetSize(world_t *world, const char *filename, const vec3_t mins, const vec3_t maxs) { int i; + + strlcpy(world->filename, filename, sizeof(world->filename)); + VectorCopy(mins, world->mins); + VectorCopy(maxs, world->maxs); + // the areagrid_marknumber is not allowed to be 0 if (world->areagrid_marknumber < 1) world->areagrid_marknumber = 1; diff --git a/world.h b/world.h index 1d16b748..216e67c9 100644 --- a/world.h +++ b/world.h @@ -41,6 +41,11 @@ typedef struct link_s typedef struct world_s { + // convenient fields + char filename[MAX_QPATH]; + vec3_t mins; + vec3_t maxs; + int areagrid_stats_calls; int areagrid_stats_nodechecks; int areagrid_stats_entitychecks; @@ -66,7 +71,7 @@ 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_SetSize(world_t *world, const vec3_t mins, const vec3_t maxs); +void World_SetSize(world_t *world, const char *filename, const vec3_t mins, const vec3_t maxs); // unlinks all entities (used before reallocation of edicts) void World_UnlinkAll(world_t *world); -- 2.39.2