Entity update + components

This commit is contained in:
2026-03-24 09:00:23 +01:00
parent 0c0e7c41af
commit 8f2a4e9ecb
11 changed files with 197 additions and 7 deletions

View File

@@ -50,6 +50,13 @@ namespace Game {
static GameStateEnum getCurrentGameState() { return mCurrentGameState; }
static void setCurrentGameState(GameStateEnum newState) { mCurrentGameState = newState; }
template<typename T>
static bool instantiateEntity(std::unique_ptr<T> entity);
template<typename T>
static T* getEntityByName(const std::string& name);
template<typename T>
static void destroyEntity(T* entity);
private:
int mTargetUpdatesPerSecond = TARGET_UPDATE_RATE;
clock::time_point mLastUpdate;
@@ -114,4 +121,26 @@ namespace Game {
return T{};
}
template<typename T>
bool GameManager::instantiateEntity(std::unique_ptr<T> entity) {
static_assert(std::is_base_of_v<Object::Entity, T>, "T must derive from Object::Entity");
State::GameState::getInstance().addEntity(std::move(entity));
return true;
}
template<typename T>
T* GameManager::getEntityByName(const std::string& name) {
static_assert(std::is_base_of_v<Object::Entity, T>, "T must derive from Object::Entity");
Object::Entity* entity = State::GameState::getInstance().getEntityByName(name);
return dynamic_cast<T*>(entity);
}
template<typename T>
void GameManager::destroyEntity(T* entity) {
static_assert(std::is_base_of_v<Object::Entity, T>, "T must derive from Object::Entity");
if (entity) {
State::GameState::getInstance().removeEntity(entity->getName());
}
}
}