From 99a764dbc060c71e4dd3174f4178875b2af9d80b Mon Sep 17 00:00:00 2001 From: toaster Date: Sun, 28 Mar 2021 20:16:47 +0100 Subject: [PATCH 1/4] Loadbar plus. * Resolves #145. * Increased granularity, to seperate out texture loading and sprite loading from other render structure initialisation. * Shows small loading string in DEVELOP builds, to show where we can optimise loading times when we're polishing. * Clean up con_refresh/startup, which got split into two variables in the merge by mistake. --- src/console.c | 39 +++++++++++++++++++++++++++------------ src/console.h | 3 +++ src/d_main.c | 7 +++++++ src/r_data.c | 30 +++--------------------------- src/r_data.h | 3 ++- src/r_main.c | 4 +++- src/r_things.c | 5 +++++ src/v_video.c | 2 +- 8 files changed, 51 insertions(+), 42 deletions(-) diff --git a/src/console.c b/src/console.c index 90fc34ad1..be829b378 100644 --- a/src/console.c +++ b/src/console.c @@ -57,7 +57,6 @@ I_mutex con_mutex; static boolean con_started = false; // console has been initialised boolean con_startup = false; // true at game startup - boolean con_refresh = false; // screen needs refreshing con_loadprogress_t con_startup_loadprogress = 0; // Progress for startup load bar @@ -457,7 +456,6 @@ void CON_Init(void) con_started = true; con_startup = true; - con_refresh = true; // needs explicit screen refresh until we are in the main game loop consoletoggle = false; Unlock_state(); @@ -477,7 +475,6 @@ void CON_Init(void) con_started = true; con_startup = false; - con_refresh = false; // disable explicit screen refresh consoletoggle = true; Unlock_state(); @@ -1497,7 +1494,6 @@ void CONS_Printf(const char *fmt, ...) { va_list argptr; static char *txt = NULL; - boolean refresh; if (txt == NULL) txt = malloc(8192); @@ -1519,16 +1515,8 @@ void CONS_Printf(const char *fmt, ...) // make sure new text is visible con_scrollup = 0; - refresh = con_refresh; Unlock_state(); - - // if not in display loop, force screen update - if (refresh) - { - CON_Drawer(); // here we display the console text - I_FinishUpdate(); // page flip or blit buffer - } } void CONS_Alert(alerttype_t level, const char *fmt, ...) @@ -1892,6 +1880,23 @@ void CON_Drawer(void) Unlock_state(); } +static const char *CON_LoadingStrings[LOADED_ALLDONE] = +{ + "Init Zone Memory...", //LOADED_ZINIT + "Init game timing...", //LOADED_ISTARTUPTIMER + "Loading main assets...", //LOADED_IWAD + "Loading add-ons...", //LOADED_PWAD + "Init graphics subsystem...", //LOADED_ISTARTUPGRAPHICS + "Cache fonts...", //LOADED_HULOADGRAPHICS + "Init miscellaneous...", //LOADED_MINIT + "Cache textures...", //LOADED_INITTEXTUREDATA + "Cache sprites...", //LOADED_INITSPIRTES + "Init rendering daemon...", //LOADED_RINIT + "Init audio subsystem...", //LOADED_SINITSFXCHANNELS + "Cache HUD...", //LOADED_STINIT + "Check game status...", //LOADED_DCHECKNETGAME +}; // see also con_loadprogress_t in console.h + // // Error handling for the loading bar, to ensure it doesn't skip any steps. // @@ -1906,6 +1911,12 @@ void CON_SetLoadingProgress(con_loadprogress_t newStep) } con_startup_loadprogress = newStep; + + if (con_startup_loadprogress < LOADED_ALLDONE) + CONS_Printf("LOADING UPDATE - %s\n", CON_LoadingStrings[con_startup_loadprogress]); + + CON_DrawLoadBar(); // here we display the console text + I_FinishUpdate(); // page flip or blit buffer } // @@ -1928,6 +1939,10 @@ void CON_DrawLoadBar(void) barwidth = (BASEVIDWIDTH * con_startup_loadprogress) / LOADED_ALLDONE; V_DrawFill(0, BASEVIDHEIGHT - barheight, barwidth, barheight, 0); +#ifdef DEVELOP + if (con_startup_loadprogress < LOADED_ALLDONE) + V_DrawCenteredString(BASEVIDWIDTH/2, BASEVIDHEIGHT - (barheight + 8 + 4), 0, CON_LoadingStrings[con_startup_loadprogress]); +#endif Unlock_state(); } diff --git a/src/console.h b/src/console.h index 2ede2d0eb..0dfb2960d 100644 --- a/src/console.h +++ b/src/console.h @@ -31,6 +31,7 @@ extern boolean con_startup; // needs explicit screen refresh until we are in the main game loop extern boolean con_refresh; +// when modifying the below, you must also adjust d_main and console.c typedef enum { LOADED_ZINIT = 1, @@ -40,6 +41,8 @@ typedef enum LOADED_ISTARTUPGRAPHICS, LOADED_HULOADGRAPHICS, LOADED_MINIT, + LOADED_INITTEXTUREDATA, + LOADED_INITSPRITES, LOADED_RINIT, LOADED_SINITSFXCHANNELS, LOADED_STINIT, diff --git a/src/d_main.c b/src/d_main.c index 6943c18cd..62a71bb5e 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -1510,6 +1510,13 @@ void D_SRB2Main(void) M_Init(); CON_SetLoadingProgress(LOADED_MINIT); + R_InitTextureData(); // seperated out from below because it takes ages by itself + CON_SetLoadingProgress(LOADED_INITTEXTUREDATA); + + CONS_Printf("R_InitSprites()...\n"); + R_InitSprites(); // ditto + CON_SetLoadingProgress(LOADED_INITSPRITES); + CONS_Printf("R_Init(): Init SRB2 refresh daemon.\n"); R_Init(); CON_SetLoadingProgress(LOADED_RINIT); diff --git a/src/r_data.c b/src/r_data.c index 5ae986c39..de9d28136 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -262,27 +262,10 @@ static void R_InitExtraColormaps(void) } #endif -// -// R_InitSpriteLumps -// Finds the width and hoffset of all sprites in the wad, so the sprite does not need to be -// cached completely, just for having the header info ready during rendering. -// - -// -// allocate sprite lookup tables -// -static void R_InitSpriteLumps(void) -{ - numspritelumps = 0; - max_spritelumps = 8192; - - Z_Malloc(max_spritelumps*sizeof(*spritecachedinfo), PU_STATIC, &spritecachedinfo); -} - // // R_InitColormaps // -static void R_InitColormaps(void) +void R_InitColormaps(void) { size_t len; lumpnum_t lump; @@ -1180,12 +1163,12 @@ static void R_Init8to16(void) } // -// R_InitData +// R_InitTextureData // // Locates all the lumps that will be used by all views // Must be called after W_Init. // -void R_InitData(void) +void R_InitTextureData(void) { if (highcolor) { @@ -1198,13 +1181,6 @@ void R_InitData(void) CONS_Printf("P_InitPicAnims()...\n"); P_InitPicAnims(); - - CONS_Printf("R_InitSprites()...\n"); - R_InitSpriteLumps(); - R_InitSprites(); - - CONS_Printf("R_InitColormaps()...\n"); - R_InitColormaps(); } // diff --git a/src/r_data.h b/src/r_data.h index 230f72a7c..7f8bdf029 100644 --- a/src/r_data.h +++ b/src/r_data.h @@ -46,7 +46,7 @@ extern CV_PossibleValue_t Color_cons_t[]; extern CV_PossibleValue_t Followercolor_cons_t[]; // follower colours table, not a duplicate because of the "Match" option. // I/O, setting up the stuff. -void R_InitData(void); +void R_InitTextureData(void); void R_PrecacheLevel(void); extern size_t flatmemory, spritememory, texturememory; @@ -58,6 +58,7 @@ extern size_t flatmemory, spritememory, texturememory; // Uncomment to make extra_colormaps order Newest -> Oldest //#define COLORMAPREVERSELIST +void R_InitColormaps(void); void R_ReInitColormaps(UINT16 num, lumpnum_t newencoremap); void R_ClearColormaps(void); extracolormap_t *R_CreateDefaultColormap(boolean lighttable); diff --git a/src/r_main.c b/src/r_main.c index dfee8cc93..aa9cd50ed 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -1084,7 +1084,9 @@ void R_Init(void) { // screensize independent //I_OutputMsg("\nR_InitData"); - R_InitData(); + //R_InitData(); -- split to d_main for its own startup steps since it takes AGES + CONS_Printf("R_InitColormaps()...\n"); + R_InitColormaps(); //I_OutputMsg("\nR_InitViewBorder"); R_InitViewBorder(); diff --git a/src/r_things.c b/src/r_things.c index 0632da143..dc61ac539 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -513,6 +513,11 @@ void R_InitSprites(void) float fa; #endif + // allocate sprite lookup tables + numspritelumps = 0; + max_spritelumps = 8192; + Z_Malloc(max_spritelumps*sizeof(*spritecachedinfo), PU_STATIC, &spritecachedinfo); + for (i = 0; i < MAXVIDWIDTH; i++) negonearray[i] = -1; diff --git a/src/v_video.c b/src/v_video.c index 4f42fc722..0b22378a4 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -1081,7 +1081,7 @@ void V_DrawDiag(INT32 x, INT32 y, INT32 wh, INT32 c) return; #ifdef HWRENDER - if (rendermode != render_soft && !con_startup) + if (rendermode == render_opengl) { HWR_DrawDiag(x, y, wh, c); return; From f7f1202a37a5e98a921d7ad12f8c70ddfee25d39 Mon Sep 17 00:00:00 2001 From: toaster Date: Sun, 28 Mar 2021 20:20:06 +0100 Subject: [PATCH 2/4] woops --- src/console.h | 3 --- src/d_main.c | 1 - 2 files changed, 4 deletions(-) diff --git a/src/console.h b/src/console.h index 0dfb2960d..caeefbb19 100644 --- a/src/console.h +++ b/src/console.h @@ -28,9 +28,6 @@ extern boolean con_recalc; // console being displayed at game startup extern boolean con_startup; -// needs explicit screen refresh until we are in the main game loop -extern boolean con_refresh; - // when modifying the below, you must also adjust d_main and console.c typedef enum { diff --git a/src/d_main.c b/src/d_main.c index 62a71bb5e..11305966e 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -706,7 +706,6 @@ void D_SRB2Loop(void) oldentertics = I_GetTime(); // end of loading screen: CONS_Printf() will no more call FinishUpdate() - con_refresh = false; con_startup = false; // make sure to do a d_display to init mode _before_ load a level From 72defa325f50c59fc7256c72b10347de5b3b7500 Mon Sep 17 00:00:00 2001 From: toaster Date: Mon, 29 Mar 2021 17:02:08 +0100 Subject: [PATCH 3/4] * Add a seperate step for I_STARTUPSKINS - "Load characters" - since it takes a similar length to loading all other types of sprites. * Adjust several loading strings, and left-align their rendering. * Don't call HU_LoadGraphics() again (startup cached ALL FONTS twice). * Adjust when some functions are called during loading to more effectively compartmentalise sections of loading that depend on each other. * LOADED_ISTARTUPGRAPHICS now comes after SCR_Startup, as we can explicitly guarantee the palette has been loaded after that function. * Make sure everything closely related to configurations (gamedata, console stuff, etc) which is not directly dependent on anything else is loaded under LOADED_CONFIG - "Load settings" (formerly LOADED_MINIT). * The `-warp` command line parameter is now checked alongside LOADED_DCHECKNETGAME. * Don't attempt to draw the loading bar before LOADED_ISTARTUPGRAPHICS, as the palette is not loaded, which means you're wasting cycles on a white screen. --- src/console.c | 18 ++++++++------ src/console.h | 5 ++-- src/d_main.c | 67 +++++++++++++++++++++++++++----------------------- src/m_menu.c | 4 +-- src/r_skins.c | 14 +++++++++-- src/r_things.c | 24 ------------------ src/v_video.c | 3 +++ 7 files changed, 67 insertions(+), 68 deletions(-) diff --git a/src/console.c b/src/console.c index be829b378..a4e711090 100644 --- a/src/console.c +++ b/src/console.c @@ -1880,21 +1880,23 @@ void CON_Drawer(void) Unlock_state(); } -static const char *CON_LoadingStrings[LOADED_ALLDONE] = +static const char *CON_LoadingStrings[LOADED_ALLDONE+1] = { - "Init Zone Memory...", //LOADED_ZINIT + "Init zone memory...", //LOADED_ZINIT "Init game timing...", //LOADED_ISTARTUPTIMER "Loading main assets...", //LOADED_IWAD "Loading add-ons...", //LOADED_PWAD "Init graphics subsystem...", //LOADED_ISTARTUPGRAPHICS - "Cache fonts...", //LOADED_HULOADGRAPHICS - "Init miscellaneous...", //LOADED_MINIT + "Cache fonts...", //LOADED_HUINIT + "Load settings...", //LOADED_CONFIG "Cache textures...", //LOADED_INITTEXTUREDATA "Cache sprites...", //LOADED_INITSPIRTES + "Load characters...", //LOADED_INITSKINS "Init rendering daemon...", //LOADED_RINIT "Init audio subsystem...", //LOADED_SINITSFXCHANNELS "Cache HUD...", //LOADED_STINIT "Check game status...", //LOADED_DCHECKNETGAME + "Now starting..." }; // see also con_loadprogress_t in console.h // @@ -1912,9 +1914,11 @@ void CON_SetLoadingProgress(con_loadprogress_t newStep) con_startup_loadprogress = newStep; - if (con_startup_loadprogress < LOADED_ALLDONE) + if (con_startup_loadprogress <= LOADED_ALLDONE) CONS_Printf("LOADING UPDATE - %s\n", CON_LoadingStrings[con_startup_loadprogress]); + if (con_startup_loadprogress < LOADED_ISTARTUPGRAPHICS) // rendering not possible? + return; CON_DrawLoadBar(); // here we display the console text I_FinishUpdate(); // page flip or blit buffer } @@ -1940,8 +1944,8 @@ void CON_DrawLoadBar(void) barwidth = (BASEVIDWIDTH * con_startup_loadprogress) / LOADED_ALLDONE; V_DrawFill(0, BASEVIDHEIGHT - barheight, barwidth, barheight, 0); #ifdef DEVELOP - if (con_startup_loadprogress < LOADED_ALLDONE) - V_DrawCenteredString(BASEVIDWIDTH/2, BASEVIDHEIGHT - (barheight + 8 + 4), 0, CON_LoadingStrings[con_startup_loadprogress]); + if (con_startup_loadprogress <= LOADED_ALLDONE) + V_DrawString(4, BASEVIDHEIGHT - (barheight + 8 + 4), 0, CON_LoadingStrings[con_startup_loadprogress]); #endif Unlock_state(); diff --git a/src/console.h b/src/console.h index caeefbb19..c7a459330 100644 --- a/src/console.h +++ b/src/console.h @@ -36,10 +36,11 @@ typedef enum LOADED_IWAD, LOADED_PWAD, LOADED_ISTARTUPGRAPHICS, - LOADED_HULOADGRAPHICS, - LOADED_MINIT, + LOADED_HUINIT, + LOADED_CONFIG, LOADED_INITTEXTUREDATA, LOADED_INITSPRITES, + LOADED_INITSKINS, LOADED_RINIT, LOADED_SINITSFXCHANNELS, LOADED_STINIT, diff --git a/src/d_main.c b/src/d_main.c index 11305966e..0b0172f96 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -1434,7 +1434,6 @@ void D_SRB2Main(void) CONS_Printf("I_StartupGraphics()...\n"); I_StartupGraphics(); - CON_SetLoadingProgress(LOADED_ISTARTUPGRAPHICS); #ifdef HWRENDER // Lactozilla: Add every hardware mode CVAR and CCMD. @@ -1447,10 +1446,15 @@ void D_SRB2Main(void) // setup loading screen SCR_Startup(); + CON_SetLoadingProgress(LOADED_ISTARTUPGRAPHICS); + + CONS_Printf("HU_Init()...\n"); HU_Init(); CON_Init(); + CON_SetLoadingProgress(LOADED_HUINIT); + memset(timelimits, 0, sizeof(timelimits)); memset(pointlimits, 0, sizeof(pointlimits)); @@ -1463,14 +1467,10 @@ void D_SRB2Main(void) I_RegisterSysCommands(); - CONS_Printf("HU_LoadGraphics()...\n"); - HU_LoadGraphics(); - CON_SetLoadingProgress(LOADED_HULOADGRAPHICS); - //--------------------------------------------------------- CONFIG.CFG M_FirstLoadConfig(); // WARNING : this do a "COM_BufExecute()" - G_LoadGameData(); + M_Init(); #if (defined (__unix__) && !defined (MSDOS)) || defined (UNIXCOMMON) || defined (HAVE_SDL) VID_PrepareModeList(); // Regenerate Modelist according to cv_fullscreen @@ -1479,36 +1479,18 @@ void D_SRB2Main(void) // set user default mode or mode set at cmdline SCR_CheckDefaultMode(); + if (M_CheckParm("-noupload")) + COM_BufAddText("downloading 0\n"); + + G_LoadGameData(); + wipegamestate = gamestate; savedata.lives = 0; // flag this as not-used - //------------------------------------------------ COMMAND LINE PARAMS - - // this must be done after loading gamedata, - // to avoid setting off the corrupted gamedata code in G_LoadGameData if a SOC with custom gamedata is added - // -- Monster Iestyn 20/02/20 - if (M_CheckParm("-warp") && M_IsNextParm()) - { - const char *word = M_GetNextParm(); - pstartmap = G_FindMapByNameOrCode(word, 0); - if (! pstartmap) - I_Error("Cannot find a map remotely named '%s'\n", word); - else - { - if (!M_CheckParm("-server")) - G_SetGameModified(multiplayer, true); - autostart = true; - } - } - - if (M_CheckParm("-noupload")) - COM_BufAddText("downloading 0\n"); - - CONS_Printf("M_Init(): Init miscellaneous info.\n"); - M_Init(); - CON_SetLoadingProgress(LOADED_MINIT); + CON_SetLoadingProgress(LOADED_CONFIG); + CONS_Printf("R_InitTextureData()...\n"); R_InitTextureData(); // seperated out from below because it takes ages by itself CON_SetLoadingProgress(LOADED_INITTEXTUREDATA); @@ -1516,6 +1498,10 @@ void D_SRB2Main(void) R_InitSprites(); // ditto CON_SetLoadingProgress(LOADED_INITSPRITES); + CONS_Printf("R_InitSkins()...\n"); + R_InitSkins(); // ditto + CON_SetLoadingProgress(LOADED_INITSKINS); + CONS_Printf("R_Init(): Init SRB2 refresh daemon.\n"); R_Init(); CON_SetLoadingProgress(LOADED_RINIT); @@ -1562,6 +1548,25 @@ void D_SRB2Main(void) ST_Init(); CON_SetLoadingProgress(LOADED_STINIT); + //------------------------------------------------ COMMAND LINE PARAMS + + // this must be done after loading gamedata, + // to avoid setting off the corrupted gamedata code in G_LoadGameData if a SOC with custom gamedata is added + // -- Monster Iestyn 20/02/20 + if (M_CheckParm("-warp") && M_IsNextParm()) + { + const char *word = M_GetNextParm(); + pstartmap = G_FindMapByNameOrCode(word, 0); + if (! pstartmap) + I_Error("Cannot find a map remotely named '%s'\n", word); + else + { + if (!M_CheckParm("-server")) + G_SetGameModified(multiplayer, true); + autostart = true; + } + } + // Set up splitscreen players before joining! if (!dedicated && (M_CheckParm("-splitscreen") && M_IsNextParm())) { diff --git a/src/m_menu.c b/src/m_menu.c index 28570c699..ef16721b9 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -3466,8 +3466,6 @@ void M_Init(void) { UINT8 i; - COM_AddCommand("manual", Command_Manual_f); - CV_RegisterVar(&cv_nextmap); CV_RegisterVar(&cv_newgametype); CV_RegisterVar(&cv_chooseskin); @@ -3476,6 +3474,8 @@ void M_Init(void) if (dedicated) return; + COM_AddCommand("manual", Command_Manual_f); + // Menu hacks CV_RegisterVar(&cv_dummymenuplayer); CV_RegisterVar(&cv_dummyteam); diff --git a/src/r_skins.c b/src/r_skins.c index 57995b0f5..1e80e18ce 100644 --- a/src/r_skins.c +++ b/src/r_skins.c @@ -133,9 +133,11 @@ static void Sk_SetDefaultValue(skin_t *skin) // void R_InitSkins(void) { -#ifdef SKINVALUES - INT32 i; + size_t i; + // it can be is do before loading config for skin cvar possible value + // (... what the fuck did you just say to me? "it can be is do"?) +#ifdef SKINVALUES for (i = 0; i <= MAXSKINS; i++) { skin_cons_t[i].value = 0; @@ -145,6 +147,14 @@ void R_InitSkins(void) // no default skin! numskins = 0; + + for (i = 0; i < numwadfiles; i++) + { + R_AddSkins((UINT16)i); + R_PatchSkins((UINT16)i); + R_LoadSpriteInfoLumps(i, wadfiles[i]->numlumps); + } + ST_ReloadSkinFaceGraphics(); } UINT32 R_GetSkinAvailabilities(void) diff --git a/src/r_things.c b/src/r_things.c index dc61ac539..aaa272e02 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -546,30 +546,6 @@ void R_InitSprites(void) for (i = 0; i < numwadfiles; i++) R_AddSpriteDefs((UINT16)i); - // - // now check for skins - // - - // it can be is do before loading config for skin cvar possible value - // (... what the fuck did you just say to me? "it can be is do"?) -#ifdef SKINVALUES - for (i = 0; i <= MAXSKINS; i++) - { - skin_cons_t[i].value = 0; - skin_cons_t[i].strvalue = NULL; - } -#endif - - numskins = 0; - - for (i = 0; i < numwadfiles; i++) - { - R_AddSkins((UINT16)i); - R_PatchSkins((UINT16)i); - R_LoadSpriteInfoLumps(i, wadfiles[i]->numlumps); - } - ST_ReloadSkinFaceGraphics(); - // // check if all sprites have frames // diff --git a/src/v_video.c b/src/v_video.c index 0b22378a4..40e1a13f6 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -131,6 +131,9 @@ static boolean InitCube(void) float globalgammamul, globalgammaoffs; boolean doinggamma; + if (con_startup_loadprogress < LOADED_MINIT) + return false; + #define diffcons(cv) (cv.value != atoi(cv.defaultvalue)) doinggamma = diffcons(cv_globalgamma); From 017b472d140ad98923453e7dcbecc6d9c7bb0587 Mon Sep 17 00:00:00 2001 From: toaster Date: Mon, 29 Mar 2021 17:22:48 +0100 Subject: [PATCH 4/4] Fix error for fresh compiles (LOADED_MINIT was renamed into LOADED_CONFIG during dev. of previous commit) --- src/v_video.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/v_video.c b/src/v_video.c index 40e1a13f6..f9f1d84ff 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -131,7 +131,7 @@ static boolean InitCube(void) float globalgammamul, globalgammaoffs; boolean doinggamma; - if (con_startup_loadprogress < LOADED_MINIT) + if (con_startup_loadprogress < LOADED_CONFIG) return false; #define diffcons(cv) (cv.value != atoi(cv.defaultvalue))