Don't reload all files if removing an unimportant one

This commit is contained in:
Lactozilla 2023-07-28 17:15:14 -03:00
parent 12599c6272
commit 2876a02466
14 changed files with 62 additions and 66 deletions

View file

@ -3884,8 +3884,6 @@ static void Got_AddPlayer(UINT8 **p, INT32 playernum)
// wake up the status bar
ST_Start();
// wake up the heads up text
HU_Start();
if (camera.chase && !splitscreenplayer)
P_ResetCamera(newplayer, &camera);

View file

@ -1761,6 +1761,8 @@ void D_SRB2Main(void)
// Reload all files.
void D_ReloadFiles(void)
{
game_reloading = true;
// Set the initial state
G_InitialState();
@ -1777,7 +1779,6 @@ void D_ReloadFiles(void)
Patch_FreeTag(PU_PATCH_LOWPRIORITY);
Patch_FreeTag(PU_PATCH_ROTATED);
Patch_FreeTag(PU_SPRITE);
Patch_FreeTag(PU_HUDGFX);
// Load SOC and Lua.
for (INT32 i = 0; i < numwadfiles; i++)
@ -1795,23 +1796,18 @@ void D_ReloadFiles(void)
P_InitPicAnims();
// Flush and reload HUD graphics
ST_UnloadGraphics();
HU_LoadGraphics();
ST_LoadGraphics();
ST_ReloadSkinFaceGraphics();
game_reloading = false;
}
void D_RestartGame(boolean remove_all_addons)
{
// Remove all addons
W_ClearCachedData();
W_UnloadAddons(remove_all_addons);
// Reload all files
game_reloading = true;
D_ReloadFiles();
game_reloading = false;
}
const char *D_Home(void)

View file

@ -4349,15 +4349,13 @@ void G_InitialState(void)
// Delete all skins.
R_DelSkins();
// Stop all sound effects.
S_StopSounds();
S_ClearSfx();
for (INT32 i = 0; i < NUMSFX; i++)
// Clear all added sound effects.
for (INT32 i = sfx_freeslot0; i <= sfx_lastskinsoundslot; i++)
{
if (S_sfx[i].lumpnum != LUMPERROR)
{
S_RemoveSoundFx(i);
S_sfx[i].lumpnum = LUMPERROR;
S_sfx[i].priority = 0;
I_FreeSfx(&S_sfx[i]);
}
}

View file

@ -75,11 +75,9 @@ patch_t *ttlnum[10]; // act numbers (0-9)
patch_t *ntb_font[NT_FONTSIZE];
patch_t *nto_font[NT_FONTSIZE];
static player_t *plr;
boolean chat_on; // entering a chat message?
static char w_chat[HU_MAXMSGLEN + 1];
static size_t c_input = 0; // let's try to make the chat input less shitty.
static boolean headsupactive = false;
boolean hu_showscores; // draw rankings
static char hu_tick;
@ -341,24 +339,6 @@ void HU_Init(void)
luahuddrawlist_scores = LUA_HUD_CreateDrawList();
}
static inline void HU_Stop(void)
{
headsupactive = false;
}
//
// Reset Heads up when consoleplayer spawns
//
void HU_Start(void)
{
if (headsupactive)
HU_Stop();
plr = &players[consoleplayer];
headsupactive = true;
}
//======================================================================
// EXECUTION
//======================================================================

View file

@ -104,9 +104,6 @@ void HU_Init(void);
void HU_LoadGraphics(void);
// reset heads up when consoleplayer respawns.
void HU_Start(void);
boolean HU_Responder(event_t *ev);
void HU_Ticker(void);
void HU_Drawer(void);

View file

@ -11676,8 +11676,6 @@ void P_AfterPlayerSpawn(INT32 playernum)
{
// wake up the status bar
ST_Start();
// wake up the heads up text
HU_Start();
}
p->drawangle = mobj->angle;

View file

@ -7846,7 +7846,7 @@ boolean P_LoadLevel(boolean fromnetsave, boolean reloadinggamestate)
// As oddly named as this is, this handles music only.
// We should be fine starting it here.
// Don't do this during titlemap, because the menu code handles music by itself.
S_Start();
S_PlayMapMusic(false);
}
levelfadecol = (ranspecialwipe) ? 0 : 31;

View file

@ -2431,7 +2431,7 @@ boolean S_FadeOutStopMusic(UINT32 ms)
// Kills playing sounds at start of level,
// determines music if any, changes music.
//
void S_StartEx(boolean reset)
void S_PlayMapMusic(boolean reset)
{
if (mapmusflags & MUSIC_RELOADRESET)
{

View file

@ -125,8 +125,7 @@ void S_InitSfxChannels(INT32 sfxVolume);
//
void S_StopSounds(void);
void S_ClearSfx(void);
void S_StartEx(boolean reset);
#define S_Start() S_StartEx(false)
void S_PlayMapMusic(boolean reset);
//
// Basically a W_GetNumForName that adds "ds" at the beginning of the string. Returns a lumpnum.

View file

@ -151,7 +151,7 @@ static void Midiplayer_Onchange(void)
Mix_Timidity_addToPathList(cv_miditimiditypath.string);
if (restart)
S_StartEx(true);
S_PlayMapMusic(true);
}
static void MidiSoundfontPath_Onchange(void)
@ -189,7 +189,7 @@ static void MidiSoundfontPath_Onchange(void)
if (!Mix_SetSoundFonts(cv_midisoundfontpath.string))
CONS_Alert(CONS_ERROR, "Sound font error: %s", Mix_GetError());
else
S_StartEx(true);
S_PlayMapMusic(true);
}
}
}

View file

@ -915,7 +915,7 @@ void S_RemoveSoundFx(sfxenum_t id)
&& S_sfx[id].priority != 0)
{
S_sfx[id].lumpnum = LUMPERROR;
I_FreeSfx(&S_sfx[id]);
S_sfx[id].priority = 0;
I_FreeSfx(&S_sfx[id]);
}
}

View file

@ -403,16 +403,6 @@ void ST_UnLoadFaceGraphics(INT32 skinnum)
W_UnlockCachedPatch(superprefix[skinnum]);
}
static inline void ST_InitData(void)
{
// 'link' the statusbar display to a player, which could be
// another player than consoleplayer, for example, when you
// change the view in a multiplayer demo with F12.
stplyr = &players[displayplayer];
st_palette = -1;
}
static inline void ST_Stop(void)
{
if (st_stopped)
@ -428,7 +418,12 @@ void ST_Start(void)
if (!st_stopped)
ST_Stop();
ST_InitData();
// 'link' the statusbar display to a player, which could be
// another player than consoleplayer, for example, when you
// change the view in a multiplayer demo with F12.
stplyr = &players[displayplayer];
st_palette = -1;
st_stopped = false;
}

View file

@ -64,6 +64,8 @@
#include "i_time.h"
#include "i_system.h"
#include "i_video.h" // rendermode
#include "st_stuff.h"
#include "hu_stuff.h"
#include "md5.h"
#include "lua_script.h"
#ifdef SCANTHINGS
@ -1237,12 +1239,26 @@ void W_LoadFileScripts(UINT16 wadfilenum, boolean mainfile)
}
}
/** Unloads a file.
*/
void W_UnloadWadFile(UINT16 num)
{
boolean is_important = wadfiles[num]->important;
if (is_important)
G_SaveGameData(clientGamedata);
// Clear all added sound effects for this file
for (INT32 i = sfx_freeslot0; i <= sfx_lastskinsoundslot; i++)
{
if (S_sfx[i].lumpnum != LUMPERROR && WADFILENUM(S_sfx[i].lumpnum) == num)
{
S_sfx[i].lumpnum = LUMPERROR;
S_sfx[i].priority = 0;
I_FreeSfx(&S_sfx[i]);
}
}
W_ClearCachedData();
W_UnloadFile(wadfiles[num]);
wadfiles[num] = NULL;
@ -1251,18 +1267,34 @@ void W_UnloadWadFile(UINT16 num)
for (UINT16 i = num; i < numwadfiles; i++)
wadfiles[i] = wadfiles[i + 1];
game_reloading = true;
if (!is_important)
{
HU_LoadGraphics();
ST_LoadGraphics();
ST_ReloadSkinFaceGraphics();
S_PlayMapMusic(true);
return;
}
D_ReloadFiles();
G_LoadGameData(clientGamedata);
M_CopyGameData(serverGamedata, clientGamedata);
game_reloading = false;
G_AfterFileDeletion();
}
void W_ClearCachedData(void)
{
// Stop all sounds, stop current music
S_StopSounds();
S_ClearSfx();
S_StopMusic();
// Unload HUD graphics
ST_UnloadGraphics();
}
void W_UnloadAddons(boolean remove_all_addons)
{
for (UINT16 i = mainwads + 1; i < numwadfiles;)

View file

@ -182,6 +182,9 @@ void W_UnloadWadFile(UINT16 num);
// Unloads all addons.
void W_UnloadAddons(boolean remove_all_addons);
// Call before W_UnloadAddons or W_UnloadWadFile
void W_ClearCachedData(void);
const char *W_CheckNameForNumPwad(UINT16 wad, UINT16 lump);
const char *W_CheckNameForNum(lumpnum_t lumpnum);