add particles.get_origin(...), particles.set_origin(...)

This commit is contained in:
MihailRis 2024-11-05 04:08:55 +03:00
parent a4f7dbf786
commit edb4ce02ca
3 changed files with 41 additions and 0 deletions

View File

@ -113,3 +113,11 @@ void Emitter::stop() {
bool Emitter::isDead() const {
return count == 0;
}
const EmitterOrigin& Emitter::getOrigin() const {
return origin;
}
void Emitter::setOrigin(const EmitterOrigin& origin) {
this->origin = origin;
}

View File

@ -81,4 +81,8 @@ public:
/// @return true if the emitter has spawned all particles
bool isDead() const;
const EmitterOrigin& getOrigin() const;
void setOrigin(const EmitterOrigin& origin);
};

View File

@ -46,8 +46,37 @@ static int l_stop(lua::State* L) {
return 0;
}
static int l_get_origin(lua::State* L) {
u64id_t id = lua::touinteger(L, 1);
if (auto emitter = renderer->particles->getEmitter(id)) {
const auto& origin = emitter->getOrigin();
if (auto pos = std::get_if<glm::vec3>(&origin)) {
return lua::pushvec3(L, *pos);
} else if (auto entityid = std::get_if<entityid_t>(&origin)) {
return lua::pushinteger(L, *entityid);
}
}
return 0;
}
static int l_set_origin(lua::State* L) {
u64id_t id = lua::touinteger(L, 1);
if (auto emitter = renderer->particles->getEmitter(id)) {
EmitterOrigin origin;
if (lua::istable(L, 2)) {
emitter->setOrigin(lua::tovec3(L, 2));
} else {
emitter->setOrigin(static_cast<entityid_t>(lua::tointeger(L, 2)));
}
}
return 0;
}
const luaL_Reg particleslib[] = {
{"emit", lua::wrap<l_emit>},
{"stop", lua::wrap<l_stop>},
{"get_origin", lua::wrap<l_get_origin>},
{"set_origin", lua::wrap<l_set_origin>},
{NULL, NULL}
};