Skip to content

Commit

Permalink
game: remove duplication of levelmsg load
Browse files Browse the repository at this point in the history
currently only heretic2 use such game code,
logic with `file_levelmsg` cvar looks unrequired.
  • Loading branch information
0lvin committed Sep 14, 2024
1 parent 4738ba2 commit 0d05d22
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 62 deletions.
5 changes: 4 additions & 1 deletion src/game/ds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2989,8 +2989,11 @@ void CScript::HandlePrint(void)
}
else
{
char message[10];

TextIndex = Text->GetIntValue();
TextValue = level_msgtxt[TextIndex].string;
snprintf(message, sizeof(message), "%d", TextIndex);
TextValue = LocalizationMessage(message, NULL);
}

if (Flags & PRINT_LEVEL)
Expand Down
86 changes: 36 additions & 50 deletions src/game/g_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,67 +173,60 @@ G_CPrintf(edict_t* ent, int printlevel, short stringid)
void
G_BCaption(int printlevel, short stringid)
{
if (stringid > MAX_MESSAGESTRINGS || !level_msgtxt[stringid].string[0])
{
gi.dprintf("%s: Unknow message %d\n", __func__, stringid);
return;
}
char message[10];
int sound_index = 0;

snprintf(message, sizeof(message), "%d", stringid);
gi.bprintf(printlevel, "%s", LocalizationMessage(message, &sound_index));

gi.bprintf(printlevel, "%s", level_msgtxt[stringid].string);
if (level_msgtxt[stringid].wav && level_msgtxt[stringid].wav[0])
if (sound_index)
{
gi.sound(NULL, CHAN_AUTO, gi.soundindex(level_msgtxt[stringid].wav), 1, ATTN_NORM, 0);
gi.sound(NULL, CHAN_AUTO, sound_index, 1, ATTN_NORM, 0);
}
}

void
G_LevelMsgCenterPrintf(edict_t* ent, short stringid)
{
if (stringid > MAX_MESSAGESTRINGS || !level_msgtxt[stringid].string[0])
{
gi.dprintf("%s: Unknow message %d\n", __func__, stringid);
return;
}
char message[10];
int sound_index = 0;

gi.centerprintf(ent, "%s", level_msgtxt[stringid].string);
snprintf(message, sizeof(message), "%d", stringid);
gi.centerprintf(ent, "%s", LocalizationMessage(message, &sound_index));

if (level_msgtxt[stringid].wav && level_msgtxt[stringid].wav[0])
if (sound_index)
{
gi.sound(ent, CHAN_AUTO, gi.soundindex(level_msgtxt[stringid].wav), 1, ATTN_NORM, 0);
gi.sound(ent, CHAN_AUTO, sound_index, 1, ATTN_NORM, 0);
}
}

void
G_CaptionPrintf(edict_t* ent, short stringid)
{
if (stringid > MAX_MESSAGESTRINGS || !level_msgtxt[stringid].string[0])
{
gi.dprintf("%s: Unknow message %d\n", __func__, stringid);
return;
}
char message[10];
int sound_index = 0;

gi.centerprintf(ent, "%s", level_msgtxt[stringid].string);
snprintf(message, sizeof(message), "%d", stringid);
gi.centerprintf(ent, "%s", LocalizationMessage(message, &sound_index));

if (level_msgtxt[stringid].wav && level_msgtxt[stringid].wav[0])
if (sound_index)
{
gi.sound(ent, CHAN_AUTO, gi.soundindex(level_msgtxt[stringid].wav), 1, ATTN_NORM, 0);
gi.sound(ent, CHAN_AUTO, sound_index, 1, ATTN_NORM, 0);
}
}

void
G_BroadcastObituary(int printlevel, short stringid, short client1, short client2)
{
if (stringid > MAX_MESSAGESTRINGS || !level_msgtxt[stringid].string[0])
{
gi.dprintf("%s: Unknow message %d\n", __func__, stringid);
return;
}
char message[10];
int sound_index = 0;

gi.bprintf(printlevel, "%s", level_msgtxt[stringid].string);
snprintf(message, sizeof(message), "%d", stringid);
gi.bprintf(printlevel, "%s", LocalizationMessage(message, &sound_index));

if (level_msgtxt[stringid].wav && level_msgtxt[stringid].wav[0])
if (sound_index)
{
gi.sound(NULL, CHAN_AUTO, gi.soundindex(level_msgtxt[stringid].wav), 1, ATTN_NORM, 0);
gi.sound(NULL, CHAN_AUTO, sound_index, 1, ATTN_NORM, 0);
}
}

Expand Down Expand Up @@ -271,32 +264,26 @@ G_TraceBoundingForm(FormMove_t* formMove)

void G_MsgVarCenterPrintf(edict_t* ent, short msg, int vari)
{
if (msg > MAX_MESSAGESTRINGS || !level_msgtxt[msg].string[0])
{
gi.dprintf("%s: Unknow message %d\n", __func__, msg);
return;
}
char message[10];
int sound_index = 0;

gi.centerprintf(ent, "%s", level_msgtxt[msg].string);
snprintf(message, sizeof(message), "%d", msg);
gi.centerprintf(ent, "%s", LocalizationMessage(message, &sound_index));

if (level_msgtxt[msg].wav && level_msgtxt[msg].wav[0])
if (sound_index)
{
gi.sound(ent, CHAN_AUTO, gi.soundindex(level_msgtxt[msg].wav), 1, ATTN_NORM, 0);
gi.sound(ent, CHAN_AUTO, sound_index, 1, ATTN_NORM, 0);
}
}

void G_MsgDualCenterPrintf(edict_t* ent, short msg1, short msg2)
{
if (msg1 > MAX_MESSAGESTRINGS || msg2 > MAX_MESSAGESTRINGS ||
!level_msgtxt[msg1].string[0] ||
!level_msgtxt[msg2].string[0])
{
gi.dprintf("%s: Unknow message %d -> %d\n", __func__, msg1, msg2);
return;
}
char message[10];

gi.centerprintf(ent, "%s", level_msgtxt[msg1].string);
gi.centerprintf(ent, "%s", level_msgtxt[msg2].string);
snprintf(message, sizeof(message), "%d", msg1);
gi.centerprintf(ent, "%s", LocalizationMessage(message, NULL));
snprintf(message, sizeof(message), "%d", msg2);
gi.centerprintf(ent, "%s", LocalizationMessage(message, NULL));
}

qboolean G_ResizeBoundingForm(edict_t* self, struct FormMove_s* formMove)
Expand Down Expand Up @@ -356,7 +343,6 @@ ShutdownGame(void)
game.entitiesSpawned = false;

gi.FS_FreeFile(game_msgbuf);
gi.FS_FreeFile(level_msgbuf);

gi.FreeTags(TAG_LEVEL);
gi.FreeTags(TAG_GAME);
Expand Down
2 changes: 1 addition & 1 deletion src/game/g_spawnf.c
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ void SP_worldspawn (edict_t *ent)
if (ent->message && ent->message[0])
{
gi.configstring (CS_LEVEL_NUMBER, ent->message );
gi.configstring (CS_NAME, level_msgtxt[atoi(ent->message)].string);
gi.configstring (CS_NAME, LocalizationMessage(ent->message, NULL));
strncpy (level.level_name, ent->message, sizeof(level.level_name));
gi.dprintf("Unique Level Index : %d\n", atoi(ent->message));
}
Expand Down
2 changes: 0 additions & 2 deletions src/game/header/local.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,7 @@ typedef struct

// jmarshall: this wasn't extern in the original code,
// this is now correct, wondering if this will cause knock ons?
extern unsigned *level_msgbuf;
extern unsigned *game_msgbuf;
extern trig_message_t level_msgtxt[];
extern trig_message_t game_msgtxt[];


Expand Down
9 changes: 1 addition & 8 deletions src/game/savegame/savegame.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,7 @@ static field_t clientfields[] =
{NULL, 0, F_INT}
};

trig_message_t level_msgtxt[MAX_MESSAGESTRINGS];
trig_message_t game_msgtxt[MAX_MESSAGESTRINGS];
unsigned *level_msgbuf;
unsigned *game_msgbuf;


Expand Down Expand Up @@ -382,15 +380,10 @@ static void Load_FileStrings(char *buffer, trig_message_t *msgtxt, int length)

static void Load_Strings(void)
{
cvar_t *levelmsg_name, *gamemsg_name;
cvar_t *gamemsg_name;
char *buffer;
int length;

levelmsg_name = gi.cvar("file_levelmsg", "levelmsg.txt", 0);
length = LoadTextFile (levelmsg_name->string, &buffer);
level_msgbuf = (unsigned *) buffer;
Load_FileStrings(buffer, level_msgtxt, length);

gamemsg_name = gi.cvar("file_gamemsg", "gamemsg.txt", 1);
length = LoadTextFile (gamemsg_name->string, &buffer);
game_msgbuf = (unsigned *) buffer;
Expand Down

0 comments on commit 0d05d22

Please sign in to comment.