#pragma once #include #include #include #include #include namespace Game::State { class GameState { public: static GameState& getInstance() { static GameState instance; return instance; } // Execute work while holding the GameState mutex to keep access thread-safe. template void withEntitiesLocked(Fn&& fn) { std::scoped_lock lock(mMutex); fn(mEntities); } // Update entity at index, by REFERENCE. Object::Entity* getAtIndex(size_t at); // Add an entity to the gamestate. void addEntity(std::unique_ptr entity); private: mutable std::mutex mMutex; // Shared mutex for thread safety std::vector> mEntities; }; }