Putting the ECS to work
Due to the part this paradigm plays in the overall structure of our application, we want the system manager and entity manager classes to be accessible to the majority of our code base. Having these objects be part of the shared context is the best way to do so:
struct SharedContext{ SharedContext(): ... m_systemManager(nullptr), m_entityManager(nullptr), ...{} ... SystemManager* m_systemManager; EntityManager* m_entityManager; ... };
Adjusting the shared context means we have two extra classes to keep track of in Game.h
:
class Game{ ... private: ... SystemManager m_systemManager; EntityManager m_entityManager; ... };
These classes have to be properly initialized, which is done in Game.cpp
:
Game::Game(): m_window("Chapter 8", sf::Vector2u(800,600)), m_entityManager(&m_systemManager, &m_textureManager), m_stateManager(&m_context) { ... m_systemManager.SetEntityManager(&m_entityManager...