8#include "core/reflect.h"
11#include "system/script/behavior.h"
12#include "system/script/behavior_registry.h"
14namespace Vkm::Engine {
37 std::vector<std::unique_ptr<Behavior>> behaviors;
50EntityId findEntityWithBehaviorNamed(
Scene& scene, std::string_view typeName);
57void reportUnregisteredBehavior(
const char* typeName);
90T& addBehavior(Scene& scene, EntityId entity) {
91 const char* name = Reflect::Traits<T>::NAME;
92 if (!BehaviorRegistry::get().contains(name)) reportUnregisteredBehavior(name);
94 auto instance = std::make_unique<T>();
95 T& behavior = *instance;
96 ScriptComponent* script = scene.tryGet<ScriptComponent>(entity);
97 if (!script) script = &scene.add(entity, ScriptComponent{});
98 script->behaviors.push_back(std::move(instance));
Central registry managing entities and an open set of component types.
Definition scene.h:29
Names one entity of one Scene, for as long as that slot holds it.
Definition entity.h:23
The reflection trait, specialised per type by VKM_REFLECT_BEGIN / VKM_F / VKM_REFLECT_END.
Definition reflect.h:41
ECS component attaching owned, polymorphic Behaviors to an entity.
Definition script_component.h:36
std::vector< UnknownBehavior > unknown
Behaviors held as text because no type of that name is registered.
Definition script_component.h:40
A behavior whose type the registry does not know, kept verbatim.
Definition script_component.h:22
size_t index
Position in the list read from; list order is run order, so it must survive a save.
Definition script_component.h:27
std::string properties
Its property object, as JSON text, untouched.
Definition script_component.h:24