feat: multiple components per entity support
This commit is contained in:
@@ -90,12 +90,15 @@ entityid_t Entities::spawn(
|
||||
create_trigger_callback<scripting::on_trigger_exit>(this)
|
||||
};
|
||||
}
|
||||
auto& scripting = registry.emplace<Scripting>(
|
||||
entity, entity_funcs_set {}, nullptr);
|
||||
auto& scripting = registry.emplace<ScriptComponents>(entity);
|
||||
entities[id] = entity;
|
||||
registry.emplace<rigging::Rig>(entity, rig->instance());
|
||||
scripting.env = scripting::on_entity_spawn(
|
||||
def, id, scripting.funcsset, std::move(args));
|
||||
for (auto& componentName : def.components) {
|
||||
auto component = std::make_unique<UserComponent>(
|
||||
componentName, entity_funcs_set {}, nullptr);
|
||||
scripting.components.emplace_back(std::move(component));
|
||||
}
|
||||
scripting::on_entity_spawn(def, id, scripting.components, std::move(args));
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "../data/dynamic.hpp"
|
||||
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <glm/glm.hpp>
|
||||
#define GLM_ENABLE_EXPERIMENTAL
|
||||
@@ -65,9 +66,23 @@ struct Rigidbody {
|
||||
std::vector<Trigger> triggers;
|
||||
};
|
||||
|
||||
struct Scripting {
|
||||
struct UserComponent {
|
||||
std::string name;
|
||||
entity_funcs_set funcsset;
|
||||
scriptenv env;
|
||||
|
||||
UserComponent(const std::string& name, entity_funcs_set funcsset, scriptenv env)
|
||||
: name(name), funcsset(funcsset), env(env) {}
|
||||
};
|
||||
|
||||
struct ScriptComponents {
|
||||
std::vector<std::unique_ptr<UserComponent>> components;
|
||||
|
||||
ScriptComponents() = default;
|
||||
|
||||
ScriptComponents(ScriptComponents&& other)
|
||||
: components(std::move(other.components)) {
|
||||
}
|
||||
};
|
||||
|
||||
class Level;
|
||||
@@ -116,8 +131,8 @@ public:
|
||||
return registry.get<Rigidbody>(entity);
|
||||
}
|
||||
|
||||
Scripting& getScripting() const {
|
||||
return registry.get<Scripting>(entity);
|
||||
ScriptComponents& getScripting() const {
|
||||
return registry.get<ScriptComponents>(entity);
|
||||
}
|
||||
|
||||
rigging::Rig& getModeltree() const;
|
||||
|
||||
@@ -15,8 +15,9 @@ namespace rigging {
|
||||
struct EntityDef {
|
||||
/// @brief Entity string id (with prefix included)
|
||||
std::string const name;
|
||||
|
||||
std::vector<std::string> components;
|
||||
|
||||
std::string scriptName = name.substr(name.find(':')+1);
|
||||
glm::vec3 hitbox {0.5f};
|
||||
std::vector<std::pair<size_t, AABB>> boxTriggers {};
|
||||
std::vector<std::pair<size_t, float>> radialTriggers {};
|
||||
|
||||
Reference in New Issue
Block a user