TSR_ECS/src/tsr/entity.cpp
2023-12-25 18:48:16 +01:00

34 lines
937 B
C++

#include "entity.hpp"
using namespace TSR;
entt::entity EntitySystem::Spawn(const Transform& trans) {
auto& reg = Game::Registry();
auto ent = reg.create();
auto& comp = reg.emplace<TransformComponent>(ent);
comp.trans = trans;
return ent;
}
void EntitySystem::Despawn(entt::entity ent) {
Game::Registry().destroy(ent);
}
void EntitySystem::RegisterLuaFunctions() {
LuaAPI::RegisterFunction("ent_spawn", [](float x, float y, float z, float pitch, float yaw, float roll, float sx, float sy, float sz) {
Transform trans;
trans.pos.x = x;
trans.pos.y = y;
trans.pos.z = z;
trans.rot = glm::quat(glm::vec3(pitch, yaw, roll));
trans.scl.x = sx;
trans.scl.y = sy;
trans.scl.z = sz;
return EntitySystem::Spawn(trans);
});
LuaAPI::RegisterFunction("ent_despawn", [](entt::entity ent) {
EntitySystem::Despawn(ent);
});
}