engine/src/system_custom_behaviour.cpp

37 lines
1.0 KiB
C++
Raw Permalink Normal View History

2024-06-02 11:55:04 +00:00
#include "system_custom_behaviour.h"
2023-05-25 17:35:32 +00:00
#include <typeinfo>
2024-06-02 11:55:04 +00:00
#include "component_custom.h"
#include "component_transform.h"
2023-05-25 17:35:32 +00:00
#include "scene.h"
namespace engine {
2024-07-29 17:58:33 +00:00
CustomBehaviourSystem::CustomBehaviourSystem(Scene* scene) : System(scene, {typeid(TransformComponent).hash_code(), typeid(CustomComponent).hash_code()})
{
// constructor here
2023-05-25 17:35:32 +00:00
}
CustomBehaviourSystem::~CustomBehaviourSystem() {}
2024-07-29 17:58:33 +00:00
void CustomBehaviourSystem::onUpdate(float ts)
{
for (Entity entity : m_entities) {
auto c = m_scene->GetComponent<CustomComponent>(entity);
assert(c != nullptr);
assert(c->impl != nullptr);
bool& entity_initialised = m_entity_is_initialised.at(entity);
if (entity_initialised == false) {
c->impl->m_entity = entity;
c->impl->m_scene = m_scene;
c->impl->init();
entity_initialised = true;
}
c->impl->update(ts);
}
2023-05-25 17:35:32 +00:00
}
2024-07-29 17:58:33 +00:00
void CustomBehaviourSystem::onComponentInsert(Entity entity) { m_entity_is_initialised.emplace(entity, false); }
2023-05-27 12:07:25 +00:00
2024-07-29 17:58:33 +00:00
} // namespace engine