From cbc6c732183af7654285492f56bf27fcdecd697a Mon Sep 17 00:00:00 2001 From: LaG1924 <12997935+LaG1924@users.noreply.github.com> Date: Sat, 13 Jan 2018 15:35:01 +0500 Subject: Removed GlobalState thread. His tasks assigned to Render thread. --- src/GlobalState.cpp | 46 +++++++++++----------------------------------- 1 file changed, 11 insertions(+), 35 deletions(-) (limited to 'src/GlobalState.cpp') diff --git a/src/GlobalState.cpp b/src/GlobalState.cpp index 57b42ea..a9f3d4e 100644 --- a/src/GlobalState.cpp +++ b/src/GlobalState.cpp @@ -6,12 +6,10 @@ #include "DebugInfo.hpp" #include "Event.hpp" - //Global game variables std::unique_ptr nc; std::unique_ptr gs; std::unique_ptr render; -std::thread threadGs; bool isRunning; bool isPhysRunning; EventListener listener; @@ -64,11 +62,6 @@ void InitEvents() { PUSH_EVENT("Disconnect", data); }); - listener.RegisterHandler("ReceivedPacket", [](const Event& eventData) { - std::shared_ptr packet = eventData.get>(); - gs->UpdatePacket(packet); - }); - /* * GameState Events */ @@ -156,6 +149,11 @@ void PhysExec() { gs->HandleRotation(std::get<0>(data),std::get<1>(data)); }); + listener.RegisterHandler("ReceivedPacket", [](const Event& eventData) { + std::shared_ptr packet = eventData.get>(); + gs->UpdatePacket(packet); + }); + LoopExecutionTimeController timer(std::chrono::milliseconds(8)); while (isPhysRunning) { @@ -182,39 +180,17 @@ void PhysExec() { } } -void GsExec() { - el::Helpers::setThreadName("Game"); - LoopExecutionTimeController timer(std::chrono::milliseconds(16)); - - while (isRunning) { - try { - while (nc && gs) { - listener.HandleAllEvents(); - } - } catch (std::exception &e) { - PUSH_EVENT("NetworkClientException", e.what()); - } - - listener.HandleAllEvents(); - - timer.Update(); - } - if (isPhysRunning) { - isPhysRunning = false; - threadPhys.join(); - } - nc.reset(); - gs.reset(); -} - void GlobalState::Exec() { render = std::make_unique(900, 480, "AltCraft"); isRunning = true; InitEvents(); - threadGs = std::thread(&GsExec); - render->ExecuteRenderLoop(); + GlobalState::SetState(State::MainMenu); + while (isRunning) { + render->Update(); + listener.HandleAllEvents(); + } + PUSH_EVENT("Exit", 0); isRunning = false; - threadGs.join(); render.reset(); } -- cgit v1.2.3