add "triggers" entity property

This commit is contained in:
MihailRis
2024-06-30 23:14:02 +03:00
parent 1f257d2db2
commit 15496070e0
7 changed files with 28 additions and 5 deletions
+5 -4
View File
@@ -36,8 +36,9 @@ entityid_t Entities::spawn(EntityDef& def, glm::vec3 pos) {
auto id = nextID++;
registry.emplace<EntityId>(entity, static_cast<entityid_t>(id), def);
registry.emplace<Transform>(entity, pos, size, glm::mat3(1.0f));
registry.emplace<Rigidbody>(entity, true, Hitbox {pos, def.hitbox}, std::vector<Trigger>{
{true, id, AABB {glm::vec3{-0.2f, -0.2f, -0.2f}, glm::vec3{0.2f, 0.2f, 0.2f}}, {}, {}, {},
auto& body = registry.emplace<Rigidbody>(entity, true, Hitbox {pos, def.hitbox}, std::vector<Trigger>{});
for (auto& box : def.triggers) {
body.triggers.emplace_back(Trigger{true, id, box, AABB{}, {}, {},
[=](auto entityid, auto index, auto otherid) {
if (auto entity = get(entityid)) {
if (entity->isValid()) {
@@ -50,8 +51,8 @@ entityid_t Entities::spawn(EntityDef& def, glm::vec3 pos) {
scripting::on_trigger_exit(*entity, index, otherid);
}
}
}}
});
}});
}
auto& scripting = registry.emplace<Scripting>(entity, entity_funcs_set {}, nullptr);
entities[id] = entity;
scripting.env = scripting::on_entity_spawn(def, id, scripting.funcsset);