diff options
Diffstat (limited to 'include/thread.hpp')
-rw-r--r-- | include/thread.hpp | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/include/thread.hpp b/include/thread.hpp index 3adc43d..0dd20f9 100644 --- a/include/thread.hpp +++ b/include/thread.hpp @@ -12,15 +12,22 @@ class GameThread : public entityx::Receiver<GameThread> { private: + static std::atomic_bool pause; + std::atomic_bool die; std::thread thread; public: GameThread(std::function<void(void)> func) { die.store(false); + pause.store(false); thread = std::thread([&](std::function<void(void)> f) { - while (!die.load()) - f(); + while (!die.load()) { + if (!pause.load()) + f(); + else + std::this_thread::sleep_for(std::chrono::milliseconds(1)); + } }, func); } @@ -31,6 +38,17 @@ public: inline void stop(void) { die.store(true); } + + static inline void pauseAll(void) { + pause.store(true); + std::this_thread::sleep_for(std::chrono::milliseconds(10)); + } + + static inline void resumeAll(void) + { pause.store(false); } + + static inline bool isPaused(void) + { return pause.load(); } }; -#endif // THREAD_HPP_
\ No newline at end of file +#endif // THREAD_HPP_ |