From a3e9ea97a8ae35a3945ccce28cc9976feaf36d2c Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 18 Jul 2020 23:50:46 +0200 Subject: [PATCH] - merged the two main loops into one. Yet to do: Run the screen jobs from the main loop as well. --- source/games/duke/src/funct.h | 1 + source/games/duke/src/gameloop.cpp | 93 +++++++++++++++++------------- source/games/duke/src/premap.cpp | 14 ++++- 3 files changed, 65 insertions(+), 43 deletions(-) diff --git a/source/games/duke/src/funct.h b/source/games/duke/src/funct.h index 92bb46e52..553228dfd 100644 --- a/source/games/duke/src/funct.h +++ b/source/games/duke/src/funct.h @@ -235,5 +235,6 @@ void calcviewpitch(player_struct* p, double factor); void sethorizon(int snum, int sb_snum, double factor, bool frominput = false); bool movementBlocked(int snum); void GetInput(); +void startmainmenu(); END_DUKE_NS diff --git a/source/games/duke/src/gameloop.cpp b/source/games/duke/src/gameloop.cpp index 98e3e7e6c..6dc35de35 100644 --- a/source/games/duke/src/gameloop.cpp +++ b/source/games/duke/src/gameloop.cpp @@ -28,6 +28,7 @@ Modifications for JonoF's port by Jonathon Fowler (jf@jonof.id.au) #include "ns.h" // Must come before everything else! +#include "gamestate.h" #include "duke3d.h" #include "sbar.h" #include "baselayer.h" @@ -376,63 +377,73 @@ bool GameTicker() // //--------------------------------------------------------------------------- +void startmainmenu() +{ + M_StartControlPanel(false); + M_SetMenu(NAME_Mainmenu); + FX_StopAllSounds(); + gamestate = GS_DEMOSCREEN; +} + +//--------------------------------------------------------------------------- +// +// +// +//--------------------------------------------------------------------------- + void app_loop() { + gamestate = GS_STARTUP; while (true) { - totalclock = 0; - ototalclock = 0; - lockclock = 0; - - ps[myconnectindex].ftq = 0; - - //if (ud.warp_on == 0) + handleevents(); + switch (gamestate) { -#if 0 // fixme once the game loop has been done. - if ((ud.multimode > 1) && startupMap.IsNotEmpty()) + default: + case GS_STARTUP: + totalclock = 0; + ototalclock = 0; + lockclock = 0; + + ps[myconnectindex].ftq = 0; + + if (userConfig.CommandMap.IsNotEmpty()) { - auto maprecord = FindMap(startupMap); - ud.m_respawn_monsters = ud.m_player_skill == 4; - - for (int i = 0; i != -1; i = connectpoint2[i]) + auto maprecord = FindMapByName(userConfig.CommandMap); + userConfig.CommandMap = ""; + if (maprecord) { - resetweapons(i); - resetinventory(i); - } + ud.m_respawn_monsters = ud.m_player_skill == 4; - StartGame(maprecord); + for (int i = 0; i != -1; i = connectpoint2[i]) + { + resetweapons(i); + resetinventory(i); + } + startnewgame(maprecord, /*userConfig.skill*/2); + } } else -#endif { - fi.ShowLogo([](bool) {}); + fi.ShowLogo([](bool) { startmainmenu(); }); } + break; - M_StartControlPanel(false); - M_SetMenu(NAME_Mainmenu); - FX_StopAllSounds(); + case GS_DEMOSCREEN: + drawbackground(); + break; + + case GS_LEVEL: + if (GameTicker()) gamestate = GS_STARTUP; + break; + + case GS_INTERMISSION: + // todo: run screen jobs here + break; - while (menuactive != MENU_Off) - { - handleevents(); - drawbackground(); - videoNextPage(); - } } - - ud.showweapons = cl_showweapon; - setlocalplayerinput(&ps[myconnectindex]); - PlayerColorChanged(); - inputState.ClearAllInput(); - - bool res; - do - { - handleevents(); - res = GameTicker(); - videoNextPage(); - } while (!res); + videoNextPage(); } } diff --git a/source/games/duke/src/premap.cpp b/source/games/duke/src/premap.cpp index 0025a3a0e..a661eb030 100644 --- a/source/games/duke/src/premap.cpp +++ b/source/games/duke/src/premap.cpp @@ -32,6 +32,8 @@ Prepared for public release: 03/21/2003 - Charlie Wiederhold, 3D Realms #include "mapinfo.h" #include "secrets.h" #include "statistics.h" +#include "gamestate.h" +#include "sbar.h" BEGIN_DUKE_NS @@ -755,6 +757,7 @@ void resettimevars(void) { totalclock = 0; cloudtotalclock = 0; + levelTextTime = 85; ototalclock = 0; lockclock = 0; ready2send = 1; @@ -1031,8 +1034,15 @@ void startnewgame(MapRecord* map, int skill) if (enterlevel(map, MODE_GAME)) { ps[myconnectindex].gm = 0; - M_StartControlPanel(false); - M_SetMenu(NAME_Mainmenu); + startmainmenu(); + } + else + { + ud.showweapons = cl_showweapon; + setlocalplayerinput(&ps[myconnectindex]); + PlayerColorChanged(); + inputState.ClearAllInput(); + gamestate = GS_LEVEL; } }