summaryrefslogtreecommitdiffstats
path: root/src/GlobalState.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-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() {