From 1bc6242caac5261dfd74be55027aa033f7a297a4 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 4 Apr 2022 22:28:16 +0200 Subject: Streamlined game loops --- StarsEx/Game.cpp | 33 ++++++++------------------------- StarsEx/Game.h | 2 +- StarsEx/GameWinDX9.cpp | 3 +-- StarsEx/StarServer.cpp | 22 ---------------------- StarsEx/StarServer.h | 1 - StarsEx/Starshatter.cpp | 37 ------------------------------------- StarsEx/Starshatter.h | 1 - 7 files changed, 10 insertions(+), 89 deletions(-) (limited to 'StarsEx') diff --git a/StarsEx/Game.cpp b/StarsEx/Game.cpp index 4fda01e..41375f9 100644 --- a/StarsEx/Game.cpp +++ b/StarsEx/Game.cpp @@ -136,37 +136,20 @@ Game::Pause(bool f) // +--------------------------------------------------------------------+ -bool +void Game::GameLoop() { - bool wait_for_windows_events = true; - - if (active && !paused) { - if (!server) { - // Route Events to EventTargets - EventDispatch* ed = EventDispatch::GetInstance(); - if (ed) - ed->Dispatch(); - } - - UpdateWorld(); - GameState(); - - if (!server) { - UpdateScreen(); - } - - wait_for_windows_events = false; + if (active) { + auto dispatch = EventDispatch::GetInstance(); + if (dispatch) + dispatch->Dispatch(); } - else if (active && paused) { - if (GetKey()=='P') - Pause(false); - } - + UpdateWorld(); + GameState(); + UpdateScreen(); Clock::GetInstance()->Step(); frame_number++; Mouse::w = 0; - return wait_for_windows_events; } // +--------------------------------------------------------------------+ diff --git a/StarsEx/Game.h b/StarsEx/Game.h index cf62744..6f5936e 100644 --- a/StarsEx/Game.h +++ b/StarsEx/Game.h @@ -70,7 +70,7 @@ public: bool Server() { return server; } bool ShowMouse() { return show_mouse; } - virtual bool GameLoop(); + virtual void GameLoop(); virtual void UpdateWorld(); virtual void GameState(); virtual void UpdateScreen(); diff --git a/StarsEx/GameWinDX9.cpp b/StarsEx/GameWinDX9.cpp index 2e1aabc..6e779c7 100644 --- a/StarsEx/GameWinDX9.cpp +++ b/StarsEx/GameWinDX9.cpp @@ -583,8 +583,7 @@ GameWinDX9::Run() DispatchMessage(&msg); } else { - if (GameLoop()) - WaitMessage(); + GameLoop(); } } return exit_code ? exit_code : msg.wParam; diff --git a/StarsEx/StarServer.cpp b/StarsEx/StarServer.cpp index 2d24bde..fa0743d 100644 --- a/StarsEx/StarServer.cpp +++ b/StarsEx/StarServer.cpp @@ -291,28 +291,6 @@ StarServer::InstantiateMission() // +--------------------------------------------------------------------+ -bool -StarServer::GameLoop() -{ - if (active && paused) { - UpdateWorld(); - GameState(); - } - - else if (!active) { - UpdateWorld(); - GameState(); - Sleep(10); - } - - Game::GameLoop(); - return false; // must return false to keep processing - // true tells the outer loop to sleep until a - // windows event is available -} - -// +--------------------------------------------------------------------+ - void StarServer::UpdateWorld() { diff --git a/StarsEx/StarServer.h b/StarsEx/StarServer.h index 3e8a722..fa4828d 100644 --- a/StarsEx/StarServer.h +++ b/StarsEx/StarServer.h @@ -51,7 +51,6 @@ public: protected: - virtual bool GameLoop(); virtual void UpdateWorld(); virtual void InstantiateMission(); diff --git a/StarsEx/Starshatter.cpp b/StarsEx/Starshatter.cpp index 415a04b..cc36461 100644 --- a/StarsEx/Starshatter.cpp +++ b/StarsEx/Starshatter.cpp @@ -789,43 +789,6 @@ Starshatter::KeyDown(int action) const // +--------------------------------------------------------------------+ -bool -Starshatter::GameLoop() -{ - cam_dir = CameraDirector::GetInstance(); - - if (active && paused) { - // Route Events to EventTargets - EventDispatch* ed = EventDispatch::GetInstance(); - if (ed) - ed->Dispatch(); - - UpdateWorld(); - GameState(); - UpdateScreen(); - - /*** - static DWORD vmf_time = 0; - - if (real_time() - vmf_time > 5000) { - vmf_time = real_time(); - DWORD vmf = video->VidMemFree() / (1024 * 1024); - ::Print("\n###### %02d:%02d - Video Memory Free: %d MB\n\n", - vmf_time / 60000, - vmf_time / 1000, - vmf); - } - ***/ - } - - Game::GameLoop(); - return false; // must return false to keep processing - // true tells the outer loop to sleep until a - // windows event is available -} - -// +--------------------------------------------------------------------+ - void Starshatter::UpdateWorld() { diff --git a/StarsEx/Starshatter.h b/StarsEx/Starshatter.h index ed800fc..75f5d0d 100644 --- a/StarsEx/Starshatter.h +++ b/StarsEx/Starshatter.h @@ -128,7 +128,6 @@ protected: virtual void DoChatMode(); virtual void DoGameKeys(); - virtual bool GameLoop(); virtual void UpdateWorld(); virtual void InstantiateMission(); virtual bool ResizeVideo(); -- cgit v1.1