#pragma once #include "IState.h" #include #include #include template class IStateController { public: virtual ~IStateController() = default; void ChangeState(unsigned stateId) { auto it = m_pStates.find(stateId); if (it == m_pStates.end()) { // Handle error: State with the provided ID doesn't exist. std::cout << "Error: State with the provided ID doesn't exist." << std::endl; return; } if (m_pCurrentState) { m_pCurrentState->Exit(static_cast(this)); } m_pCurrentState = it->second; m_pCurrentState->Enter(static_cast(this)); } void UpdateState(float deltaTime) { if (m_pCurrentState) { m_pCurrentState->Update(static_cast(this), deltaTime); } } protected: std::map>> m_pStates; std::shared_ptr> m_pCurrentState; };