summaryrefslogtreecommitdiffstats
path: root/src/GlobalState.cpp
diff options
context:
space:
mode:
authorLaG1924 <12997935+LaG1924@users.noreply.github.com>2018-01-13 11:35:01 +0100
committerLaG1924 <12997935+LaG1924@users.noreply.github.com>2018-01-13 11:35:57 +0100
commitcbc6c732183af7654285492f56bf27fcdecd697a (patch)
tree436a2eacb47c2a1f9d8f6a1e407e95d07e70a6c4 /src/GlobalState.cpp
parentReplaced all usages of NC to new implementation (diff)
downloadAltCraft-cbc6c732183af7654285492f56bf27fcdecd697a.tar
AltCraft-cbc6c732183af7654285492f56bf27fcdecd697a.tar.gz
AltCraft-cbc6c732183af7654285492f56bf27fcdecd697a.tar.bz2
AltCraft-cbc6c732183af7654285492f56bf27fcdecd697a.tar.lz
AltCraft-cbc6c732183af7654285492f56bf27fcdecd697a.tar.xz
AltCraft-cbc6c732183af7654285492f56bf27fcdecd697a.tar.zst
AltCraft-cbc6c732183af7654285492f56bf27fcdecd697a.zip
Diffstat (limited to '')
-rw-r--r--src/GlobalState.cpp46
1 files changed, 11 insertions, 35 deletions
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<NetworkClient> nc;
std::unique_ptr<GameState> gs;
std::unique_ptr<Render> 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> packet = eventData.get<std::shared_ptr<Packet>>();
- 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> packet = eventData.get<std::shared_ptr<Packet>>();
+ 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<Render>(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();
}