engine/src/system_custom_behaviour.cpp

39 lines
1.2 KiB
C++
Raw Normal View History

2023-05-25 17:35:32 +00:00
#include "systems/custom_behaviour.h"
#include <typeinfo>
#include "components/custom.h"
#include "components/transform.h"
#include "scene.h"
namespace engine {
CustomBehaviourSystem::CustomBehaviourSystem(Scene* scene)
: System(scene, {typeid(TransformComponent).hash_code(),
typeid(CustomComponent).hash_code()}) {
// constructor here
}
CustomBehaviourSystem::~CustomBehaviourSystem() {}
void CustomBehaviourSystem::OnUpdate(float ts) {
2023-09-19 07:40:45 +00:00
for (Entity entity : entities_) {
2023-05-25 17:35:32 +00:00
auto c = scene_->GetComponent<CustomComponent>(entity);
assert(c != nullptr);
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();
entity_initialised = true;
}
2024-06-01 22:03:39 +00:00
c->on_update(ts);
2023-05-25 17:35:32 +00:00
}
}
2023-09-19 07:40:45 +00:00
void CustomBehaviourSystem::OnComponentInsert(Entity entity)
2023-05-27 12:07:25 +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