Properly handle and delete unused non visible entity sounds to free up sound indexes

This commit is contained in:
smallmodel 2024-10-18 23:01:27 +02:00
parent 1a3122bef3
commit 5136aa4886
No known key found for this signature in database
GPG key ID: 9F2D623CEDF08512
6 changed files with 108 additions and 62 deletions

View file

@ -532,6 +532,12 @@ typedef struct gameExport_s {
void (*SetFrameNumber)(int frameNumber);
void (*SoundCallback)(int entNum, soundChannel_t channelNumber, const char *name);
//
// Added in OPM
//
int (*pvssoundindex)(const char* name, int streamed);
//
// global variables shared between game and server
//

View file

@ -481,6 +481,9 @@ int SV_NumClients(void);
void SV_ChangeMaxClients( void );
void SV_SpawnServer( const char *server, qboolean loadgame, qboolean restart, qboolean bTransition );
// Added in OPM
int SV_PVSSoundIndex(const char* name, qboolean streamed);
void SV_HandleNonPVSSound();
//

View file

@ -1802,6 +1802,9 @@ void SV_InitGameProgs( void ) {
import.SanitizeName = Com_SanitizeName;
import.fsDebug = fs_debug;
// Added in OPM
import.soundindex = SV_PVSSoundIndex;
ge = Sys_GetGameAPI( &import );
if( !ge ) {

View file

@ -1172,3 +1172,95 @@ void SV_Shutdown( const char *finalmsg ) {
CL_Disconnect();
}
//
// Added in OPM
//
/*
===============
SV_PVSSoundIndex
===============
*/
int SV_PVSSoundIndex( const char *name, qboolean streamed )
{
int index = SV_SoundIndex(name, streamed);
svs.nonpvs_sound_cache[index].inUse = qtrue;
svs.nonpvs_sound_cache[index].deleteTime = svs.time + 1000;
return index;
}
/*
=======================
SV_CacheNonPVSSound
=======================
*/
void SV_CacheNonPVSSound(void)
{
gentity_t* ent;
nonpvs_sound_t* npvs;
int i, j;
for (i = 0; i < sv.num_entities; i++) {
ent = SV_GentityNum(i);
for (j = 0; j < ent->r.num_nonpvs_sounds; j++) {
npvs = &ent->r.nonpvs_sounds[j];
if (npvs->index) {
svs.nonpvs_sound_cache[npvs->index].inUse = qtrue;
svs.nonpvs_sound_cache[npvs->index].deleteTime = svs.time + 1000;
}
}
}
}
/*
=======================
SV_CleanupNonPVSSound
=======================
*/
void SV_CleanupNonPVSSound(void)
{
nonpvs_sound_cache_t* cache;
int i, j, k, l;
for (i = 1; i < MAX_SOUNDS; i++) {
cache = &svs.nonpvs_sound_cache[i];
if (!sv.configstrings[CS_SOUNDS + i]) {
continue;
}
if (!cache->inUse) {
continue;
}
if (svs.time >= cache->deleteTime) {
SV_SetConfigstring(CS_SOUNDS + i, NULL);
cache->inUse = qfalse;
}
}
}
/*
===============
SV_HandleNonPVSSound
===============
*/
void SV_HandleNonPVSSound()
{
gentity_t *ent;
int i;
SV_CacheNonPVSSound();
for (i = 0; i < sv.num_entities; i++) {
ent = SV_GentityNum(i);
ent->r.num_nonpvs_sounds = 0;
}
// Free up sound indices
SV_CleanupNonPVSSound();
}

View file

@ -1121,6 +1121,10 @@ void SV_Frame( int msec ) {
// process all gamespy queries
SV_ProcessGamespyQueries();
// Added in OPM
// Handle non-pvs sounds
SV_HandleNonPVSSound();
svs.lastTime = svs.time;
}

View file

@ -1257,58 +1257,6 @@ void SV_SendClientSnapshot( client_t *client ) {
SV_SendMessageToClient( &msg, client );
}
/*
=======================
SV_CacheNonPVSSound
=======================
*/
void SV_CacheNonPVSSound(void)
{
gentity_t* ent;
nonpvs_sound_t* npvs;
int i, j;
for (i = 0; i < sv.num_entities; i++) {
ent = SV_GentityNum(i);
for (j = 0; j < ent->r.num_nonpvs_sounds; j++) {
npvs = &ent->r.nonpvs_sounds[j];
if (npvs->index) {
svs.nonpvs_sound_cache[npvs->index].inUse = qtrue;
svs.nonpvs_sound_cache[npvs->index].deleteTime = svs.time + 1000;
}
}
}
}
/*
=======================
SV_CleanupNonPVSSound
=======================
*/
void SV_CleanupNonPVSSound(void)
{
nonpvs_sound_cache_t* cache;
int i, j, k, l;
for (i = 1; i < MAX_SOUNDS; i++) {
cache = &svs.nonpvs_sound_cache[i];
if (!sv.configstrings[i]) {
continue;
}
if (!cache->inUse) {
continue;
}
if (svs.time >= cache->deleteTime) {
SV_SetConfigstring(CS_SOUNDS + i, NULL);
cache->inUse = qfalse;
}
}
}
/*
=======================
SV_SendClientMessages
@ -1321,8 +1269,6 @@ void SV_SendClientMessages(void)
client_t *c;
gentity_t *ent;
SV_CacheNonPVSSound();
// send a message to each connected client
for(i=0; i < sv_maxclients->integer; i++)
{
@ -1365,14 +1311,6 @@ void SV_SendClientMessages(void)
c->lastSnapshotTime = svs.time;
c->rateDelayed = qfalse;
}
for (i = 0; i < sv.num_entities; i++) {
ent = SV_GentityNum(i);
ent->r.num_nonpvs_sounds = 0;
}
// Free up sound indices
SV_CleanupNonPVSSound();
}
qboolean SV_IsValidSnapshotClient(client_t* client) {