From b52a2b0d9a2addb1e0308add4cb1f5ce30448c6f Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 9 Sep 2020 22:42:01 +0200 Subject: [PATCH] - set up the loadscreen code. This isn't active, though, because load times are so short these days that all this results in is an irritating screen flash before the level starts. It may be activated later when hires assets are in use. Fixes #10 (or not...? ;) ) --- source/blood/src/endgame.cpp | 20 ++++++++---------- source/games/duke/src/2d_d.cpp | 20 ++++++++---------- source/games/duke/src/2d_r.cpp | 19 +++++++---------- source/games/duke/src/funct.h | 2 +- source/games/duke/src/gameloop.cpp | 15 +++++++++++-- source/games/duke/src/premap.cpp | 34 +++++++++--------------------- 6 files changed, 50 insertions(+), 60 deletions(-) diff --git a/source/blood/src/endgame.cpp b/source/blood/src/endgame.cpp index ba5b18d01..8a0f69079 100644 --- a/source/blood/src/endgame.cpp +++ b/source/blood/src/endgame.cpp @@ -280,12 +280,11 @@ void EndGameLoadSaveConstruct(void) class DBloodLoadScreen : public DScreenJob { - std::function callback; const char* pzLoadingScreenText1; MapRecord* rec; public: - DBloodLoadScreen(const char* caption, MapRecord* maprec, std::function callback_) : DScreenJob(fadein | fadeout), callback(callback_), rec(maprec) + DBloodLoadScreen(const char* caption, MapRecord* maprec) : DScreenJob(), rec(maprec) { if (gGameOptions.nGameType == 0) pzLoadingScreenText1 = GStrings("TXTB_LLEVEL"); else pzLoadingScreenText1 = GStrings(FStringf("TXTB_NETGT%d", gGameOptions.nGameType)); @@ -298,16 +297,15 @@ public: DrawMenuCaption(pzLoadingScreenText1); viewDrawText(1, rec->DisplayName(), 160, 50, -128, 0, 1, 1); viewDrawText(3, GStrings("TXTB_PLSWAIT"), 160, 134, -128, 0, 1, 1); - - // Initiate the level load once the page has been faded in completely. - if (callback && GetFadeState() == visible) - { - callback(); - callback = nullptr; - } - if (clock > 5'000'000'000) return 0; // make sure the screen stays long enough to be seen. - return skiprequest ? -1 : 1; + return 0; } }; +void loadscreen(MapRecord* rec, CompletionFunc func) +{ + JobDesc job = { Create(rec) }; + RunScreenJob(&job, 1, func); +} + + END_BLD_NS diff --git a/source/games/duke/src/2d_d.cpp b/source/games/duke/src/2d_d.cpp index 2d965f1f3..75d45244e 100644 --- a/source/games/duke/src/2d_d.cpp +++ b/source/games/duke/src/2d_d.cpp @@ -1053,30 +1053,28 @@ void e4intro(const CompletionFunc& completion) class DDukeLoadScreen : public DScreenJob { - std::function callback; MapRecord* rec; public: - DDukeLoadScreen(MapRecord *maprec, std::function callback_) : DScreenJob(fadein|fadeout), callback(callback_), rec(maprec) {} + DDukeLoadScreen(MapRecord *maprec) : DScreenJob(0), rec(maprec) {} int Frame(uint64_t clock, bool skiprequest) { + twod->ClearScreen(); DrawTexture(twod, tileGetTexture(LOADSCREEN), 0, 0, DTA_FullscreenEx, FSMode_ScaleToFit43, DTA_LegacyRenderStyle, STYLE_Normal, TAG_DONE); BigText(160, 90, (rec->flags & MI_USERMAP)? GStrings("TXT_LOADUM") : GStrings("TXT_LOADING")); BigText(160, 114, rec->DisplayName()); - - // Initiate the level load once the page has been faded in completely. - if (callback && GetFadeState() == visible) - { - callback(); - callback = nullptr; - } - if (clock > 5'000'000'000) return 0; // make sure the screen stays long enough to be seen. - return skiprequest? -1 : 1; + return 0; } }; +void loadscreen_d(MapRecord *rec, CompletionFunc func) +{ + JobDesc job = { Create(rec) }; + RunScreenJob(&job, 1, func); +} + void PrintPaused_d() { BigText(160, 100, GStrings("Game Paused")); diff --git a/source/games/duke/src/2d_r.cpp b/source/games/duke/src/2d_r.cpp index 6c304cba4..c26ebd48d 100644 --- a/source/games/duke/src/2d_r.cpp +++ b/source/games/duke/src/2d_r.cpp @@ -611,11 +611,10 @@ void dobonus_r(int bonusonly, const CompletionFunc& completion) class DRRLoadScreen : public DScreenJob { - std::function callback; MapRecord* rec; public: - DRRLoadScreen(MapRecord* maprec, std::function callback_) : DScreenJob(fadein | fadeout), callback(callback_), rec(maprec) {} + DRRLoadScreen(MapRecord* maprec) : DScreenJob(0), rec(maprec) {} int Frame(uint64_t clock, bool skiprequest) { @@ -624,18 +623,16 @@ public: int y = isRRRA()? 140 : 90; BigText(160, y, (rec->flags & MI_USERMAP) ? GStrings("TXT_ENTRUM") : GStrings("TXT_ENTERIN"), 0); BigText(160, y+24, rec->DisplayName(), 0); - - // Initiate the level load once the page has been faded in completely. - if (callback && GetFadeState() == visible) - { - callback(); - callback = nullptr; - } - if (clock > 5'000'000'000) return 0; // make sure the screen stays long enough to be seen. - return skiprequest? -1 : 1; + return 0; } }; +void loadscreen_r(MapRecord* rec, CompletionFunc func) +{ + JobDesc job = { Create(rec) }; + RunScreenJob(&job, 1, func); +} + void PrintPaused_r() { BigText(160, 100, GStrings("Game Paused"), 0); diff --git a/source/games/duke/src/funct.h b/source/games/duke/src/funct.h index 295194dc8..691a89360 100644 --- a/source/games/duke/src/funct.h +++ b/source/games/duke/src/funct.h @@ -221,7 +221,7 @@ void prelevel_d(int g); void prelevel_r(int g); void e4intro(const CompletionFunc& completion); void exitlevel(MapRecord *next); -int enterlevel(MapRecord* mi, int gm); +void enterlevel(MapRecord* mi, int gm); void donewgame(MapRecord* map, int sk); void startnewgame(MapRecord* map, int skill); void setlocalplayerinput(player_struct *pp); diff --git a/source/games/duke/src/gameloop.cpp b/source/games/duke/src/gameloop.cpp index 7df82aa33..028ae3dc3 100644 --- a/source/games/duke/src/gameloop.cpp +++ b/source/games/duke/src/gameloop.cpp @@ -158,12 +158,23 @@ void GameInterface::Render() // // //--------------------------------------------------------------------------- +void loadscreen_d(MapRecord* rec, CompletionFunc func); +void loadscreen_r(MapRecord* rec, CompletionFunc func); void GameInterface::NextLevel(MapRecord* map, int skill) { if (skill != -1) ud.player_skill = skill + 1; - int res = enterlevel(map, 0); - if (res) gameaction = ga_startup; + +#if 0 + // Loading is so fast on modern system so that this only serves as an irritant, not an asset. + auto loadscreen = isRR() ? loadscreen_r : loadscreen_d; + loadscreen_d(map, [=](bool) + { + enterlevel(map, 0); + gameaction = ga_level; + }); +#endif + enterlevel(map, 0); } //--------------------------------------------------------------------------- diff --git a/source/games/duke/src/premap.cpp b/source/games/duke/src/premap.cpp index bba0d8227..5d4b45b3d 100644 --- a/source/games/duke/src/premap.cpp +++ b/source/games/duke/src/premap.cpp @@ -861,14 +861,12 @@ static int LoadTheMap(MapRecord *mi, struct player_struct *p, int gamemode) int16_t lbang; if (VOLUMEONE && (mi->flags & MI_USERMAP)) { - Printf(TEXTCOLOR_RED "Cannot load user maps with shareware version!\n"); - return 1; + I_Error("Cannot load user maps with shareware version!\n"); } if (engineLoadBoard(mi->fileName, VOLUMEONE, &p->pos, &lbang, &p->cursectnum) < 0) { - Printf(TEXTCOLOR_RED "Map \"%s\" not found or invalid map version!\n", mi->fileName.GetChars()); - return 1; + I_Error("Map \"%s\" not found or invalid map version!\n", mi->fileName.GetChars()); } currentLevel = mi; SECRET_SetMapName(mi->DisplayName(), mi->name); @@ -926,7 +924,7 @@ static void clearfrags(void) // //--------------------------------------------------------------------------- -int enterlevel(MapRecord *mi, int gamemode) +void enterlevel(MapRecord *mi, int gamemode) { // flushpackets(); // waitforeverybody(); @@ -947,12 +945,7 @@ int enterlevel(MapRecord *mi, int gamemode) auto p = &ps[0]; - - /* - G_DoLoadScreen(msg, -1); // this should be done outside of this function later. - */ - int res = LoadTheMap(mi, p, gamemode); - if (res != 0) return res; + LoadTheMap(mi, p, gamemode); // Try this first so that it can disable the CD player if no tracks are found. if (isRR()) @@ -990,7 +983,6 @@ int enterlevel(MapRecord *mi, int gamemode) clearfrags(); resettimevars(); // Here we go setLevelStarted(mi); - return 0; } //--------------------------------------------------------------------------- @@ -1010,18 +1002,12 @@ void startnewgame(MapRecord* map, int skill) newgame(map, skill, [=](bool) { - if (enterlevel(map, 0)) - { - gameaction = ga_mainmenu; - } - else - { - ud.showweapons = cl_showweapon; - setlocalplayerinput(&ps[myconnectindex]); - PlayerColorChanged(); - inputState.ClearAllInput(); - gameaction = ga_level; - } + enterlevel(map, 0); + ud.showweapons = cl_showweapon; + setlocalplayerinput(&ps[myconnectindex]); + PlayerColorChanged(); + inputState.ClearAllInput(); + gameaction = ga_level; }); }