From ec95948b6973f91a43e10cbfde532d03a1077995 Mon Sep 17 00:00:00 2001 From: SNMetamorph <25657591+SNMetamorph@users.noreply.github.com> Date: Mon, 12 Jul 2021 14:43:36 +0400 Subject: [PATCH] engine: server: implemented instant game library loading --- engine/common/host.c | 3 +-- engine/server/server.h | 3 ++- engine/server/sv_game.c | 1 + engine/server/sv_init.c | 8 ++++---- engine/server/sv_main.c | 1 + engine/server/sv_save.c | 1 + 6 files changed, 10 insertions(+), 7 deletions(-) diff --git a/engine/common/host.c b/engine/common/host.c index d014c46e..b183ca3b 100644 --- a/engine/common/host.c +++ b/engine/common/host.c @@ -1131,10 +1131,9 @@ int EXPORT Host_Main( int argc, char **argv, const char *progname, int bChangeGa if( Host_IsDedicated() && GameState->nextstate == STATE_RUNFRAME ) { - Con_Printf( "type 'map ' to run server... (TAB-autocomplete is working too)\n" ); - // execute server.cfg after commandline // so we have a chance to set servercfgfile + Con_Printf( "Type 'map ' to start game... (TAB-autocomplete is working too)\n" ); Cbuf_AddText( va( "exec %s\n", Cvar_VariableString( "servercfgfile" ))); Cbuf_Execute(); } diff --git a/engine/server/server.h b/engine/server/server.h index 4e35c77f..3f4fd518 100644 --- a/engine/server/server.h +++ b/engine/server/server.h @@ -352,6 +352,7 @@ typedef struct typedef struct { qboolean initialized; // sv_init has completed + qboolean game_library_loaded; // is game library loaded in SV_InitGame double timestart; // just for profiling int maxclients; // server max clients @@ -467,7 +468,6 @@ void SV_AddToMaster( netadr_t from, sizebuf_t *msg ); qboolean SV_ProcessUserAgent( netadr_t from, const char *useragent ); void Host_SetServerState( int state ); qboolean SV_IsSimulating( void ); -qboolean SV_InitGame( void ); void SV_FreeClients( void ); void Master_Add( void ); void Master_Heartbeat( void ); @@ -476,6 +476,7 @@ void Master_Packet( void ); // // sv_init.c // +qboolean SV_InitGame( void ); void SV_ActivateServer( int runPhysics ); qboolean SV_SpawnServer( const char *server, const char *startspot, qboolean background ); model_t *SV_ModelHandle( int modelindex ); diff --git a/engine/server/sv_game.c b/engine/server/sv_game.c index ceedd785..7df3751f 100644 --- a/engine/server/sv_game.c +++ b/engine/server/sv_game.c @@ -5028,6 +5028,7 @@ void SV_UnloadProgs( void ) Mod_ResetStudioAPI (); + svs.game_library_loaded = false; COM_FreeLibrary( svgame.hInstance ); Mem_FreePool( &svgame.mempool ); memset( &svgame, 0, sizeof( svgame )); diff --git a/engine/server/sv_init.c b/engine/server/sv_init.c index 4d691074..c08fe2c5 100644 --- a/engine/server/sv_init.c +++ b/engine/server/sv_init.c @@ -668,8 +668,8 @@ qboolean SV_InitGame( void ) { string dllpath; - if( svs.initialized ) - return true; // already initialized ? + if( svs.game_library_loaded ) + return true; // first initialize? COM_ResetLibraryError(); @@ -683,8 +683,7 @@ qboolean SV_InitGame( void ) } // client frames will be allocated in SV_ClientConnect - svs.initialized = true; - + svs.game_library_loaded = true; return true; } @@ -862,6 +861,7 @@ qboolean SV_SpawnServer( const char *mapname, const char *startspot, qboolean ba if( !SV_InitGame( )) return false; + svs.initialized = true; Log_Open(); Log_Printf( "Loading map \"%s\"\n", mapname ); Log_PrintServerVars(); diff --git a/engine/server/sv_main.c b/engine/server/sv_main.c index a748a0fc..bcc433bf 100644 --- a/engine/server/sv_main.c +++ b/engine/server/sv_main.c @@ -959,6 +959,7 @@ void SV_Init( void ) SV_InitFilter(); SV_ClearGameState (); // delete all temporary *.hl files + SV_InitGame(); } /* diff --git a/engine/server/sv_save.c b/engine/server/sv_save.c index 0052ba73..2e754ce1 100644 --- a/engine/server/sv_save.c +++ b/engine/server/sv_save.c @@ -2115,6 +2115,7 @@ qboolean SV_LoadGame( const char *pPath ) if( !SV_InitGame( )) return false; + svs.initialized = true; pFile = FS_Open( pPath, "rb", true ); if( pFile )