Added a Initialize function for systems.
This commit is contained in:
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user