Loading...
Searching...
No Matches
Entity.cpp
Go to the documentation of this file.
1//
2// Created by denzel on 21/08/2025.
3//
4#include "hellfire/ecs/ScriptComponent.h"
5#include "Entity.h"
6#include "hellfire/ecs/TransformComponent.h"
7
8#include <glm/detail/type_mat.hpp>
9
10namespace hellfire {
12 return script_components_;
13 }
14
15
16 void Entity::initialize_scripts() const {
17 for (auto *script: script_components_) {
18 script->init();
19 }
20 }
21
22 void Entity::update_scripts(const float delta_time) const {
23 for (auto *script: script_components_) {
24 if (script->is_enabled()) {
25 script->update(delta_time);
26 }
27 }
28 }
29
30 void Entity::cleanup_scripts() const {
31 for (auto *script: script_components_) {
32 script->remove();
33 }
34 }
35
36 void Entity::broadcast_event(const std::string &event_name, void *data) const {
37 for (auto *script: script_components_) {
38 script->trigger_event(event_name, data);
39 }
40 }
41
43 auto *comp = get_component<TransformComponent>();
44 if (!comp) {
45 std::clog << "Warning: Entity '" << get_name()
46 << "' missing TransformComponent, auto-creating\n";
47 comp = add_component<TransformComponent>();
48 }
49 return comp;
50 }
51
52 const TransformComponent *Entity::transform() const { return get_component<TransformComponent>(); }
53}
const std::string & get_name() const
Definition Entity.h:46
const TransformComponent * transform() const
Definition Entity.cpp:52
TransformComponent * transform()
Definition Entity.cpp:42
const std::vector< ScriptComponent * > & get_script_components() const
Definition Entity.cpp:11
void initialize_scripts() const
Definition Entity.cpp:16
void cleanup_scripts() const
Definition Entity.cpp:30
std::vector< ScriptComponent * > script_components_
Definition Entity.h:88
void broadcast_event(const std::string &event_name, void *data=nullptr) const
Definition Entity.cpp:36