From a1001c5fddf502fb6939d63cbcf2d4e85ccf7539 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 19 Jul 2020 00:26:36 +0200 Subject: [PATCH] - changed startnewgame to handle the screen jobs asynchronously. --- source/games/duke/src/ccmds.cpp | 3 +- source/games/duke/src/funct.h | 3 +- source/games/duke/src/premap.cpp | 51 ++++++++++++++++++-------------- 3 files changed, 32 insertions(+), 25 deletions(-) diff --git a/source/games/duke/src/ccmds.cpp b/source/games/duke/src/ccmds.cpp index 7535946c1..54746f534 100644 --- a/source/games/duke/src/ccmds.cpp +++ b/source/games/duke/src/ccmds.cpp @@ -55,7 +55,8 @@ static void dowarp(MapRecord *map) if (ps[myconnectindex].gm & MODE_GAME) { - newgame(map, ud.m_player_skill); + ready2send = 0; + donewgame(map, ud.m_player_skill); ps[myconnectindex].gm = MODE_RESTART; } else startnewgame(map, ud.m_player_skill); diff --git a/source/games/duke/src/funct.h b/source/games/duke/src/funct.h index 553228dfd..1fb5d51ea 100644 --- a/source/games/duke/src/funct.h +++ b/source/games/duke/src/funct.h @@ -225,7 +225,8 @@ void e4intro(CompletionFunc completion); void clearfrags(void); int exitlevel(); int enterlevel(MapRecord* mi, int gm); -void newgame(MapRecord* mi, int sk); +void newgame(MapRecord* mi, int sk, CompletionFunc completion); +void donewgame(MapRecord* map, int sk); void startnewgame(MapRecord* map, int skill); void setlocalplayerinput(player_struct *pp); void PlayerColorChanged(void); diff --git a/source/games/duke/src/premap.cpp b/source/games/duke/src/premap.cpp index a661eb030..50a0be5e3 100644 --- a/source/games/duke/src/premap.cpp +++ b/source/games/duke/src/premap.cpp @@ -771,7 +771,7 @@ void resettimevars(void) // //--------------------------------------------------------------------------- -static void donewgame(MapRecord* map, int sk) +void donewgame(MapRecord* map, int sk) { auto p = &ps[0]; show_shareware = 26 * 34; @@ -837,29 +837,33 @@ static void donewgame(MapRecord* map, int sk) } } -void newgame(MapRecord* map, int sk) +void newgame(MapRecord* map, int sk, CompletionFunc completion) { handleevents(); ready2send = 0; - auto completion = [=](bool) + auto completion1 = [=](bool res) { if (!isRR() && map->levelNumber == levelnum(3, 0) && (ud.multimode < 2)) { - e4intro([=](bool) { donewgame(map, sk); }); + e4intro([=](bool) { donewgame(map, sk); if (completion) completion(res); }); + } + else + { + donewgame(map, sk); + if (completion) completion(res); } - else donewgame(map, sk); }; if (ud.m_recstat != 2 && ud.last_level >= 0 && ud.multimode > 1 && ud.coop != 1) - dobonus(1, completion); + dobonus(1, completion1); #if 0 // this is one lousy hack job that's hopefully not needed anymore. else if (isRR() && !isRRRA() && map->levelNumber == levelnum(0, 6)) - dobonus(0, completion); + dobonus(0, completion1); #endif - else completion(false); + else completion1(false); } //--------------------------------------------------------------------------- @@ -1029,21 +1033,22 @@ int enterlevel(MapRecord *mi, int gamemode) void startnewgame(MapRecord* map, int skill) { - newgame(map, skill); - - if (enterlevel(map, MODE_GAME)) - { - ps[myconnectindex].gm = 0; - startmainmenu(); - } - else - { - ud.showweapons = cl_showweapon; - setlocalplayerinput(&ps[myconnectindex]); - PlayerColorChanged(); - inputState.ClearAllInput(); - gamestate = GS_LEVEL; - } + newgame(map, skill, [=](bool) + { + if (enterlevel(map, MODE_GAME)) + { + ps[myconnectindex].gm = 0; + startmainmenu(); + } + else + { + ud.showweapons = cl_showweapon; + setlocalplayerinput(&ps[myconnectindex]); + PlayerColorChanged(); + inputState.ClearAllInput(); + gamestate = GS_LEVEL; + } + }); } //---------------------------------------------------------------------------