Added a Initialize function for systems.

This commit is contained in:
stiffly
2015-12-11 14:03:00 +01:00
parent 80f028edf2
commit 0b60979c7b
6 changed files with 20 additions and 5 deletions
+2 -2
View File
@@ -15,10 +15,10 @@ public:
, m_ComponentType(componentType)
{ }
virtual void Initialize();
virtual void Initialize() { }
virtual void Update(World* world, ComponentWrapper& component, double dt) = 0;
private:
protected:
std::string m_ComponentType;
EventBroker* m_EventBroker;
};
+10
View File
@@ -21,6 +21,16 @@ public:
}
}
void Initialize()
{
for (auto& pair : m_Systems) {
auto& systems = pair.second;
for (auto& system : systems) {
system->Initialize();
}
}
}
template <typename T, typename... Arguments>
void AddSystem(Arguments... args)
{
+1 -2
View File
@@ -17,13 +17,12 @@ public:
: System(eventBroker, "Player")
{ }
void Initialize();
virtual void Initialize();
virtual void Update(World* world, ComponentWrapper& player, double dt) override;
private:
float m_Speed;
glm::vec3 m_Direction;
EventBroker* m_EventBroker;
EventRelay<PlayerSystem, Events::KeyDown> m_EKeyDown;
bool OnKeyDown(const Events::KeyDown &event);
+2
View File
@@ -8,6 +8,8 @@ public:
: System(eventBroker, "RaptorCopter")
{ }
virtual void Initialize() { }
virtual void Update(World* world, ComponentWrapper& raptorCopter, double dt) override
{
ComponentWrapper& transform = world->GetComponent(raptorCopter.EntityID, "Transform");
+4
View File
@@ -47,9 +47,13 @@ Game::Game(int argc, char* argv[])
m_SystemPipeline->AddSystem<RaptorCopterSystem>();
m_SystemPipeline->AddSystem<PlayerSystem>();
m_LastTime = glfwGetTime();
testIntialize();
m_SystemPipeline->Initialize();
}
Game::~Game()
+1 -1
View File
@@ -16,7 +16,7 @@ void PlayerSystem::Update(World * world, ComponentWrapper & player, double dt)
bool PlayerSystem::OnKeyDown(const Events::KeyDown & event)
{
if (event.KeyCode == GLFW_KEY_P) {
if (event.KeyCode == GLFW_KEY_UP) {
m_Direction.z == -1;
}
if (event.KeyCode == GLFW_KEY_LEFT) {