From 4edd84910ac8f236228591507525868ee22aa7e1 Mon Sep 17 00:00:00 2001 From: havoc Date: Thu, 1 Jan 2004 02:35:56 +0000 Subject: [PATCH] now runs scripts at startup differently - runs scripts twice, once only executing cvar and exec, then starts video, then runs scripts again git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@3772 d7cf8633-e32d-0410-b094-e92efae38249 --- client.h | 2 -- cmd.c | 34 ++++++++++++--------- cvar.c | 4 ++- host.c | 20 +++++------- host_cmd.c | 89 +++++++++++++++++++++++------------------------------- sv_main.c | 4 +++ todo | 7 +++-- 7 files changed, 76 insertions(+), 84 deletions(-) diff --git a/client.h b/client.h index 578cd684..69fd1195 100644 --- a/client.h +++ b/client.h @@ -659,7 +659,5 @@ extern mempool_t *cl_refdef_mempool; #include "cgamevm.h" -void Host_PerformSpawnServerAndLoadGame(void); - #endif diff --git a/cmd.c b/cmd.c index 24c4c635..47a46928 100644 --- a/cmd.c +++ b/cmd.c @@ -809,30 +809,36 @@ void Cmd_ExecuteString (const char *text, cmd_source_t src) return; // no tokens } -// check functions - for (cmd=cmd_functions ; cmd ; cmd=cmd->next) +// check functions (only after host_initialized) + if (host_initialized || !strcasecmp(cmd_argv[0], "exec")) { - if (!strcasecmp (cmd_argv[0],cmd->name)) + for (cmd=cmd_functions ; cmd ; cmd=cmd->next) { - cmd->function (); - cmd_tokenizebufferpos = oldpos; - return; + if (!strcasecmp (cmd_argv[0],cmd->name)) + { + cmd->function (); + cmd_tokenizebufferpos = oldpos; + return; + } } } -// check alias - for (a=cmd_alias ; a ; a=a->next) +// check alias (only after host_initialized) + if (host_initialized) { - if (!strcasecmp (cmd_argv[0], a->name)) + for (a=cmd_alias ; a ; a=a->next) { - Cbuf_InsertText (a->value); - cmd_tokenizebufferpos = oldpos; - return; + if (!strcasecmp (cmd_argv[0], a->name)) + { + Cbuf_InsertText (a->value); + cmd_tokenizebufferpos = oldpos; + return; + } } } -// check cvars - if (!Cvar_Command ()) +// check cvars (always) + if (!Cvar_Command () && host_initialized) Con_Printf ("Unknown command \"%s\"\n", Cmd_Argv(0)); cmd_tokenizebufferpos = oldpos; diff --git a/cvar.c b/cvar.c index fb7cb18d..db209739 100644 --- a/cvar.c +++ b/cvar.c @@ -315,7 +315,9 @@ qboolean Cvar_Command (void) // perform a variable print or set if (Cmd_Argc() == 1) { - Con_Printf ("\"%s\" is \"%s\"\n", v->name, v->string); + // only print if host_initialized (otherwise it could print twice if this is in a script) + if (host_initialized) + Con_Printf ("\"%s\" is \"%s\"\n", v->name, v->string); return true; } diff --git a/host.c b/host.c index 69e980f1..89e5dab9 100644 --- a/host.c +++ b/host.c @@ -136,8 +136,6 @@ void PRVM_ProcessError(void); static char hosterrorstring1[4096]; static char hosterrorstring2[4096]; static qboolean hosterror = false; -extern char sv_spawnmap[MAX_QPATH]; -extern char sv_loadgame[MAX_OSPATH]; void Host_Error (const char *error, ...) { va_list argptr; @@ -159,10 +157,6 @@ void Host_Error (const char *error, ...) strcpy(hosterrorstring2, hosterrorstring1); - // make sure we don't get in a loading loop - sv_loadgame[0] = 0; - sv_spawnmap[0] = 0; - CL_Parse_DumpPacket(); PR_Crash(); @@ -716,9 +710,6 @@ void _Host_Frame (float time) // process console commands Cbuf_Execute(); - // LordHavoc: map and load are delayed until video is initialized - Host_PerformSpawnServerAndLoadGame(); - // if running the server locally, make intentions now if (cls.state == ca_connected && sv.active) CL_SendCmd(&cmd); @@ -883,10 +874,8 @@ void Host_Init (void) CL_Init(); } - Cbuf_InsertText ("exec quake.rc\n"); - Cbuf_Execute(); - Cbuf_Execute(); - Cbuf_Execute(); + // only cvars are executed when host_initialized == false + Cbuf_InsertText("exec quake.rc\n"); Cbuf_Execute(); host_initialized = true; @@ -899,6 +888,11 @@ void Host_Init (void) SCR_BeginLoadingPlaque(); MR_Init(); } + + // stuff it again so the first host frame will execute it again, this time + // in its entirety + Cbuf_InsertText("exec quake.rc\n"); + Cbuf_Execute(); } diff --git a/host_cmd.c b/host_cmd.c index 528af90a..429af4b4 100644 --- a/host_cmd.c +++ b/host_cmd.c @@ -21,9 +21,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "quakedef.h" int current_skill; -char sv_spawnmap[MAX_QPATH]; -char sv_loadgame[MAX_OSPATH]; - cvar_t sv_cheats = {0, "sv_cheats", "0"}; qboolean allowcheats = false; @@ -272,6 +269,8 @@ command from the console. Active clients are kicked off. */ void Host_Map_f (void) { + char level[MAX_QPATH]; + if (cmd_source != src_command) return; @@ -283,11 +282,12 @@ void Host_Map_f (void) key_dest = key_game; // remove console or menu SCR_BeginLoadingPlaque (); - svs.serverflags = 0; // haven't completed an episode yet - strcpy (sv_spawnmap, Cmd_Argv(1)); - if (host_initialized) - Host_PerformSpawnServerAndLoadGame(); + allowcheats = sv_cheats.integer != 0; + strcpy(level, Cmd_Argv(1)); + SV_SpawnServer(level); + if (sv.active && cls.state == ca_disconnected) + CL_EstablishConnection("local"); } /* @@ -299,6 +299,8 @@ Goes to a new map, taking all clients along */ void Host_Changelevel_f (void) { + char level[MAX_QPATH]; + if (Cmd_Argc() != 2) { Con_Printf ("changelevel : continue game on a new level\n"); @@ -310,9 +312,11 @@ void Host_Changelevel_f (void) return; } SV_SaveSpawnparms (); - strcpy (sv_spawnmap, Cmd_Argv(1)); - if (host_initialized) - Host_PerformSpawnServerAndLoadGame(); + allowcheats = sv_cheats.integer != 0; + strcpy(level, Cmd_Argv(1)); + SV_SpawnServer(level); + if (sv.active && cls.state == ca_disconnected) + CL_EstablishConnection("local"); } /* @@ -324,14 +328,18 @@ Restarts the current server for a dead player */ void Host_Restart_f (void) { + char mapname[MAX_QPATH]; + if (cls.demoplayback || !sv.active) return; if (cmd_source != src_command) return; - strcpy (sv_spawnmap, sv.name); - if (host_initialized) - Host_PerformSpawnServerAndLoadGame(); + allowcheats = sv_cheats.integer != 0; + strcpy(mapname, sv.name); + SV_SpawnServer(mapname); + if (sv.active && cls.state == ca_disconnected) + CL_EstablishConnection("local"); } /* @@ -502,25 +510,9 @@ Host_Loadgame_f =============== */ void Host_Loadgame_f (void) -{ - if (cmd_source != src_command) - return; - - if (Cmd_Argc() != 2) - { - Con_Printf ("load : load a game\n"); - return; - } - - strcpy (sv_loadgame, Cmd_Argv(1)); - FS_DefaultExtension (sv_loadgame, ".sav", sizeof (sv_loadgame)); - - Con_Printf ("Loading game from %s...\n", sv_loadgame); -} - -void Host_PerformLoadGame(char *name) { qfile_t *f; + char filename[MAX_QPATH]; char mapname[MAX_QPATH]; float time, tfloat; char buf[32768]; @@ -532,9 +524,23 @@ void Host_PerformLoadGame(char *name) int version; float spawn_parms[NUM_SPAWN_PARMS]; + if (cmd_source != src_command) + return; + + if (Cmd_Argc() != 2) + { + Con_Printf ("load : load a game\n"); + return; + } + + strcpy (filename, Cmd_Argv(1)); + FS_DefaultExtension (filename, ".sav", sizeof (filename)); + + Con_Printf ("Loading game from %s...\n", filename); + cls.demonum = -1; // stop demo loop in case this fails - f = FS_Open (name, "r", false); + f = FS_Open (filename, "r", false); if (!f) { Con_Printf ("ERROR: couldn't open.\n"); @@ -1572,7 +1578,7 @@ void Host_Startdemos_f (void) if (cls.state == ca_dedicated || COM_CheckParm("-listen")) { - if (!sv.active && !sv_spawnmap[0]) + if (!sv.active) { if (gamemode == GAME_TRANSFUSION) Cbuf_AddText ("map bb1\n"); @@ -1638,25 +1644,6 @@ void Host_Stopdemo_f (void) CL_Disconnect (); } -// LordHavoc: because we don't want to load things before the video starts, -// we have to delay map and game loads until AFTER video is initialized -void Host_PerformSpawnServerAndLoadGame(void) -{ - if (vid_hidden && cls.state != ca_dedicated) - return; - if (sv_loadgame[0]) - Host_PerformLoadGame(sv_loadgame); - else if (sv_spawnmap[0]) - { - allowcheats = sv_cheats.integer != 0; - SV_SpawnServer(sv_spawnmap); - } - sv_loadgame[0] = 0; - sv_spawnmap[0] = 0; - if (sv.active && cls.state == ca_disconnected) - Cbuf_AddText ("connect local"); -} - static void MaxPlayers_f(void) { int n; diff --git a/sv_main.c b/sv_main.c index 832b3b24..afc29be8 100644 --- a/sv_main.c +++ b/sv_main.c @@ -1771,7 +1771,11 @@ void SV_SpawnServer (const char *server) if (sv.active) SV_SendReconnect(); else + { + // make sure cvars have been checked before opening the ports + NetConn_ServerFrame(); NetConn_OpenServerPorts(true); + } // // make cvars consistant diff --git a/todo b/todo index 06748d5f..9d879363 100644 --- a/todo +++ b/todo @@ -35,13 +35,14 @@ -n darkplaces: server is starting before the "port" cvar is set by commandline and scripts? (yummyluv) -n darkplaces: typing ip in join game menu should show 'trying' and 'no response' after a while, or 'no network' if networking is not initialized (yummyluv) -n dpmod: make grapple off-hand (joe hill) +0 darkplaces: add GL_EXT_stencil_two_side support to shadow rendering (fuh) 0 darkplaces: mini scoreboard (the deathmatch overlay) shows player names multiple times in some cases? 4 darkplaces: add qw protocol support (making darkplaces work as a qwcl client) (tell Fuh) 0 darkplaces: add some cl_explosions_ cvars to control settings - start alpha, end alpha, start size, end size, life time (Supajoe, Mercury) 0 darkplaces: "edict -1" and other invalid numbers cause an error, should just complain (Supajoe) 2 darkplaces: add another TE_TELEPORT effect that spawns particles at a model's vertices (Urre) 0 darkplaces: change sky handling to draw sky even if fog is on (Deej, C0burn) -3 darkplaces: redesign startup script handling to simply stop execution until video inits, when it encounters certain commands (instead of delaying those commands) +3 darkplaces: redesign startup script handling to scan scripts for cvars (ignoring commands) and then init video and then run the scripts for real d darkplaces: physics bug: rotating bmodels stop when the player blocks them instead of pushing the player d darkplaces: physics bug: fiends can leap through the player (thanks to Tomaz for massive assistance in tracking down this longstanding bug) -n darkplaces: physics bug: bmodels (doors, etc) hurt player if player pushes against it, and sometimes gets stuck for a frame when falling onto it (Andrew A. Gilevsky) @@ -57,11 +58,11 @@ d darkplaces: add cvar_string builtin (Paul Timofeyev) d darkplaces: add DP_LITSUPPORT extension and document it 0 darkplaces: add DP_SV_ROTATINGBMODEL extension to explain that MOVETYPE_PUSH/SOLID_BSP support rotation in darkplaces and a demonstration of how to use it without qc modifications (Uffe, Supajoe) 0 darkplaces: add Draw2D function to model struct to make it easy to draw models without an entity (Tomaz) -0 darkplaces: add _reflect textures which filter use of skybox as a cubemap reflection (FrikaC) +4 darkplaces: add _reflect textures which filter use of skybox as a cubemap reflection (FrikaC) 0 darkplaces: add a .collision_cancollide QC function call to decide if an entity should collide with another, or pass through it (Uffe) 0 darkplaces: add a clipmask thingy to allow QC to mask off collisions as it wishes (Uffe) -n darkplaces: add a config saving command (Speeds) -0 darkplaces: add a loading screen (gfx/loadback.tga or the loading plaque if that's not found) before loading commences so that people have something to look at when the engine starts... (SeienAbunae) +2 darkplaces: add a loading screen (gfx/loadback.tga or the loading plaque if that's not found) before loading commences so that people have something to look at when the engine starts... (SeienAbunae) -n darkplaces: add a scr_screenshot_jpeg_quality cvar (Electro) 0 darkplaces: add ability to load gfx/particlefont.tga (Vermeulen, frightfan, Error) 0 darkplaces: add automatic binding to whatever address the machine's hostname resolves to (in addition to 0.0.0.0); see original quake code for examples (yummyluv) -- 2.39.2