From e11635d15c43789b6b7382d912b6c4abc08504b3 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Thu, 3 Oct 2024 19:33:51 +0300 Subject: [PATCH] engine: server: slight refactoring, hide client calls under XASH_DEDICATED, remove useless dedicated stub --- engine/common/dedicated.c | 5 ---- engine/server/sv_game.c | 7 ++++-- engine/server/sv_save.c | 49 ++++++++++++++++++--------------------- 3 files changed, 28 insertions(+), 33 deletions(-) diff --git a/engine/common/dedicated.c b/engine/common/dedicated.c index 9d57e89f..62bd98a9 100644 --- a/engine/common/dedicated.c +++ b/engine/common/dedicated.c @@ -134,11 +134,6 @@ void GAME_EXPORT S_StopSound(int entnum, int channel, const char *soundname) } -int S_GetCurrentStaticSounds( soundlist_t *pout, int size ) -{ - return 0; -} - int GAME_EXPORT CL_GetMaxClients( void ) { return 0; diff --git a/engine/server/sv_game.c b/engine/server/sv_game.c index 9ae68af9..518869fe 100644 --- a/engine/server/sv_game.c +++ b/engine/server/sv_game.c @@ -643,12 +643,16 @@ Write ambient sounds into demo */ void SV_RestartAmbientSounds( void ) { + // TODO: we don't know sounds state on remote server + // as it's used only for demos, maybe this could be implemented on client side? +#if !XASH_DEDICATED soundlist_t soundInfo[256]; string curtrack, looptrack; int i, nSounds; int position; - if( !SV_Active( )) return; + if( !SV_Active( ) || Host_IsDedicated( )) + return; nSounds = S_GetCurrentStaticSounds( soundInfo, 256 ); @@ -663,7 +667,6 @@ void SV_RestartAmbientSounds( void ) SV_StartSound( SV_PEntityOfEntIndex( si->entnum, true ), CHAN_STATIC, si->name, si->volume, si->attenuation, 0, si->pitch ); } -#if !XASH_DEDICATED // TODO: ??? // restart soundtrack if( S_StreamGetCurrentState( curtrack, sizeof( curtrack ), looptrack, sizeof( looptrack ), &position )) { diff --git a/engine/server/sv_save.c b/engine/server/sv_save.c index 473c9f51..6e642155 100644 --- a/engine/server/sv_save.c +++ b/engine/server/sv_save.c @@ -1170,41 +1170,36 @@ static void SaveClientState( SAVERESTOREDATA *pSaveData, const char *level, int char name[MAX_QPATH]; int i, id, version; char *pTokenData; - decallist_t *decalList; - SAVE_CLIENT header; + decallist_t *decalList = NULL; + SAVE_CLIENT header = { 0 }; file_t *pFile; // clearing the saving buffer to reuse SaveClear( pSaveData ); - memset( &header, 0, sizeof( header )); - - // g-cont. add space for studiodecals if present - decalList = (decallist_t *)Z_Calloc( sizeof( decallist_t ) * MAX_RENDER_DECALS * 2 ); + header.entityCount = sv.num_static_entities; // initialize client header #if !XASH_DEDICATED - if( !Host_IsDedicated() ) + if( !Host_IsDedicated( )) { - header.decalCount = ref.dllFuncs.R_CreateDecalList( decalList ); - } - else -#endif // XASH_DEDICATED - { - // we probably running a dedicated server - header.decalCount = 0; - } - header.entityCount = sv.num_static_entities; + // g-cont. add space for studiodecals if present + decalList = (decallist_t *)Mem_Calloc( host.mempool, sizeof( decallist_t ) * MAX_RENDER_DECALS * 2 ); - if( !changelevel ) - { - // sounds won't going across transition - header.soundCount = S_GetCurrentDynamicSounds( soundInfo, MAX_CHANNELS ); -#if !XASH_DEDICATED - // music not reqiured to save position: it's just continue playing on a next level - S_StreamGetCurrentState( header.introTrack, sizeof( header.introTrack ), header.mainTrack, sizeof( header.mainTrack ), &header.trackPosition ); -#endif + header.decalCount = ref.dllFuncs.R_CreateDecalList( decalList ); + + if( !changelevel ) // sounds won't going across transition + { + header.soundCount = S_GetCurrentDynamicSounds( soundInfo, MAX_CHANNELS ); + + // music not reqiured to save position: it's just continue playing on a next level + S_StreamGetCurrentState( + header.introTrack, sizeof( header.introTrack ), + header.mainTrack, sizeof( header.mainTrack ), + &header.trackPosition ); + } } +#endif // XASH_DEDICATED // save viewentity to allow camera works after save\restore if( SV_IsValidEdict( cl->pViewEntity ) && cl->pViewEntity != cl->edict ) @@ -1217,7 +1212,7 @@ static void SaveClientState( SAVERESTOREDATA *pSaveData, const char *level, int svgame.dllFuncs.pfnSaveWriteFields( pSaveData, "ClientHeader", &header, gSaveClient, ARRAYSIZE( gSaveClient )); // store decals - for( i = 0; i < header.decalCount; i++ ) + for( i = 0; decalList != NULL && i < header.decalCount; i++ ) { // NOTE: apply landmark offset only for brush entities without origin brushes if( pSaveData->fUseLandmark && FBitSet( decalList[i].flags, FDECAL_USE_LANDMARK )) @@ -1225,7 +1220,9 @@ static void SaveClientState( SAVERESTOREDATA *pSaveData, const char *level, int svgame.dllFuncs.pfnSaveWriteFields( pSaveData, "DECALLIST", &decalList[i], gDecalEntry, ARRAYSIZE( gDecalEntry )); } - Z_Free( decalList ); + + if( decalList ) + Mem_Free( decalList ); // write client entities for( i = 0; i < header.entityCount; i++ )