Properly parse and cache ubersounds, and don't cache resources that must be always loaded to avoid filling up sound indexes

This commit is contained in:
smallmodel 2024-10-29 21:02:16 +01:00 committed by GitHub
parent becf9f5d8c
commit d3212c55a0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 196 additions and 91 deletions

View file

@ -977,6 +977,7 @@ qboolean G_Command_ProcessFile(const char *filename, qboolean quiet)
const char *bufstart;
const char *token;
int numTokens = 0;
char tempName[65];
if (gi.FS_ReadFile(filename, (void **)&buffer, quiet) == -1) {
return qfalse;
@ -988,6 +989,9 @@ qboolean G_Command_ProcessFile(const char *filename, qboolean quiet)
bufstart = buffer;
Com_sprintf(tempName, sizeof(tempName), "m%s", filename);
gi.LoadResource(tempName);
while (1) {
// grab each line as we go
token = COM_ParseExt(&buffer, qtrue);
@ -1024,6 +1028,9 @@ qboolean G_Command_ProcessFile(const char *filename, qboolean quiet)
gi.FS_FreeFile((void *)bufstart);
Com_sprintf(tempName, sizeof(tempName), "o%s", filename);
gi.LoadResource(tempName);
return qtrue;
}

View file

@ -440,24 +440,27 @@ static int bLoadForMap(char *psMapsBuffer, const char *name)
return false;
}
void ScriptMaster::RegisterAliasInternal(Event *ev, bool bCache)
void ScriptMaster::RegisterAliasAndCache(Event *ev)
{
int i;
char parameters[MAX_STRING_CHARS];
char *psMapsBuffer;
int subtitle;
bool bAlwaysLoaded = false;
int i;
char parameters[MAX_STRING_CHARS];
char *psMapsBuffer;
bool bAlwaysLoaded = false;
if (ev->NumArgs() < 2) {
return;
}
// Get the parameters for this alias command
parameters[0] = 0;
subtitle = 0;
psMapsBuffer = NULL;
for (i = 3; i <= ev->NumArgs(); i++) {
str s;
// MOHAA doesn't check that
// Added in OPM
// MOHAA doesn't check that
if (ev->IsListenerAt(i)) {
Listener *l = ev->GetListener(i);
@ -470,44 +473,97 @@ void ScriptMaster::RegisterAliasInternal(Event *ev, bool bCache)
s = ev->GetString(i);
}
if (subtitle) {
if (!s.icmp("maps")) {
i++;
psMapsBuffer = (char *)ev->GetToken(i).c_str();
continue;
}
if (!s.icmp("always")) {
bAlwaysLoaded = true;
continue;
}
strcat(parameters, s);
strcat(parameters, " ");
}
if (bAlwaysLoaded) {
gi.GlobalAlias_Add(ev->GetString(1), ev->GetString(2), parameters);
}
if (bLoadForMap(psMapsBuffer, ev->GetString(1))) {
if (!bAlwaysLoaded) {
gi.GlobalAlias_Add(ev->GetString(1), ev->GetString(2), parameters);
}
CacheResource(ev->GetString(2));
}
}
void ScriptMaster::RegisterAlias(Event *ev)
{
int i;
char parameters[MAX_STRING_CHARS];
char *psMapsBuffer;
qboolean subtitle;
bool bAlwaysLoaded = false;
if (ev->NumArgs() < 2) {
return;
}
// Get the parameters for this alias command
parameters[0] = 0;
subtitle = 0;
psMapsBuffer = NULL;
for (i = 3; i <= ev->NumArgs(); i++) {
str s;
// Added in OPM
// MOHAA doesn't check that
if (ev->IsListenerAt(i)) {
Listener *l = ev->GetListener(i);
if (l && l == Director.CurrentThread()) {
s = "local";
} else {
s = ev->GetString(i);
}
} else {
s = ev->GetString(i);
}
if (!s.icmp("maps")) {
i++;
psMapsBuffer = (char *)ev->GetToken(i).c_str();
continue;
}
if (!s.icmp("always")) {
bAlwaysLoaded = true;
} else if (subtitle) {
strcat(parameters, "\"");
strcat(parameters, s);
strcat(parameters, "\" ");
subtitle = 0;
} else if (!s.icmp("maps")) {
i++;
psMapsBuffer = (char *)ev->GetToken(i).c_str();
} else if (!s.icmp("always")) {
bAlwaysLoaded = true;
} else {
subtitle = s.icmp("subtitle") == 0;
strcat(parameters, s);
strcat(parameters, " ");
}
strcat(parameters, " ");
}
if (bAlwaysLoaded || bLoadForMap(psMapsBuffer, ev->GetString(1))) {
gi.GlobalAlias_Add(ev->GetString(1), ev->GetString(2), parameters);
if (bCache) {
CacheResource(ev->GetString(2));
}
}
}
void ScriptMaster::RegisterAliasAndCache(Event *ev)
{
RegisterAliasInternal(ev, true);
}
void ScriptMaster::RegisterAlias(Event *ev)
{
RegisterAliasInternal(ev);
}
void ScriptMaster::Cache(Event *ev)
{
#ifdef GAME_DLL

View file

@ -82,7 +82,6 @@ protected:
void Cache(Event *ev);
void RegisterAliasAndCache(Event *ev);
void RegisterAlias(Event *ev);
void RegisterAliasInternal(Event *ev, bool bCache = false);
public:
CLASS_PROTOTYPE(ScriptMaster);