summaryrefslogtreecommitdiffstats
path: root/src/GlobalState.cpp
diff options
context:
space:
mode:
authorLaG1924 <12997935+LaG1924@users.noreply.github.com>2019-01-27 06:10:33 +0100
committerLaG1924 <12997935+LaG1924@users.noreply.github.com>2019-01-27 06:10:33 +0100
commite2479261c56c8d1a64b51ad4f084ad3c18505359 (patch)
tree5256688eaec174cebdcf873f5247ece28ec45b9c /src/GlobalState.cpp
parentAdded slow GameState sync (diff)
downloadAltCraft-e2479261c56c8d1a64b51ad4f084ad3c18505359.tar
AltCraft-e2479261c56c8d1a64b51ad4f084ad3c18505359.tar.gz
AltCraft-e2479261c56c8d1a64b51ad4f084ad3c18505359.tar.bz2
AltCraft-e2479261c56c8d1a64b51ad4f084ad3c18505359.tar.lz
AltCraft-e2479261c56c8d1a64b51ad4f084ad3c18505359.tar.xz
AltCraft-e2479261c56c8d1a64b51ad4f084ad3c18505359.tar.zst
AltCraft-e2479261c56c8d1a64b51ad4f084ad3c18505359.zip
Diffstat (limited to 'src/GlobalState.cpp')
-rw-r--r--src/GlobalState.cpp11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/GlobalState.cpp b/src/GlobalState.cpp
index 9675d4b..afa1a56 100644
--- a/src/GlobalState.cpp
+++ b/src/GlobalState.cpp
@@ -9,6 +9,7 @@
//Global game variables
std::unique_ptr<NetworkClient> nc;
std::unique_ptr<GameState> gs;
+std::shared_ptr<GameState> gsReadOnly;
std::unique_ptr<Render> render;
bool isRunning;
bool isPhysRunning;
@@ -16,6 +17,7 @@ EventListener listener;
bool isMoving[5] = { 0,0,0,0,0 };
std::thread threadPhys;
State state;
+std::mutex gsCopyMutex;
void PhysExec();
@@ -194,6 +196,10 @@ void PhysExec() {
listener.HandleAllEvents();
+ gsCopyMutex.lock();
+ gsReadOnly = std::make_shared<GameState>(*gs.get());
+ gsCopyMutex.unlock();
+
timer.Update();
}
}
@@ -212,8 +218,9 @@ void GlobalState::Exec() {
render.reset();
}
-GameState *GlobalState::GetGameState() {
- return gs.get();
+std::shared_ptr<GameState> GlobalState::GetGameState() {
+ std::lock_guard<std::mutex> guard(gsCopyMutex);
+ return gsReadOnly;
}
Render *GlobalState::GetRender() {