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 {
|
|
|
|
|
|
|
|
CustomBehaviourSystem::CustomBehaviourSystem(Scene* scene)
|
|
|
|
: System(scene, {typeid(TransformComponent).hash_code(),
|
|
|
|
typeid(CustomComponent).hash_code()}) {
|
|
|
|
// constructor here
|
|
|
|
}
|
|
|
|
|
|
|
|
CustomBehaviourSystem::~CustomBehaviourSystem() {}
|
|
|
|
|
2024-06-04 18:01:49 +00:00
|
|
|
void CustomBehaviourSystem::onUpdate(float ts) {
|
|
|
|
for (Entity entity : m_entities) {
|
|
|
|
auto c = m_scene->GetComponent<CustomComponent>(entity);
|
2023-05-25 17:35:32 +00:00
|
|
|
assert(c != nullptr);
|
2023-08-01 15:13:33 +00:00
|
|
|
bool& entity_initialised = entity_is_initialised_.at(entity);
|
|
|
|
if (entity_initialised == false) {
|
2024-06-01 22:03:39 +00:00
|
|
|
if (c->on_init == nullptr) throw std::runtime_error("CustomComponent::on_init not set! Entity: " + std::to_string(entity));
|
|
|
|
if (c->on_update == nullptr) throw std::runtime_error("CustomComponent::on_update not set! Entity: " + std::to_string(entity));
|
|
|
|
c->on_init();
|
2023-08-01 15:13:33 +00:00
|
|
|
entity_initialised = true;
|
|
|
|
}
|
2024-06-01 22:03:39 +00:00
|
|
|
c->on_update(ts);
|
2023-05-25 17:35:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-04 18:01:49 +00:00
|
|
|
void CustomBehaviourSystem::onComponentInsert(Entity entity)
|
2023-05-27 12:07:25 +00:00
|
|
|
{
|
2023-08-01 15:13:33 +00:00
|
|
|
entity_is_initialised_.emplace(entity, false);
|
2023-05-27 12:07:25 +00:00
|
|
|
}
|
|
|
|
|
2023-05-25 17:35:32 +00:00
|
|
|
} // namespace engine
|