add particles.get_origin(...), particles.set_origin(...)
This commit is contained in:
parent
a4f7dbf786
commit
edb4ce02ca
@ -113,3 +113,11 @@ void Emitter::stop() {
|
|||||||
bool Emitter::isDead() const {
|
bool Emitter::isDead() const {
|
||||||
return count == 0;
|
return count == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const EmitterOrigin& Emitter::getOrigin() const {
|
||||||
|
return origin;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Emitter::setOrigin(const EmitterOrigin& origin) {
|
||||||
|
this->origin = origin;
|
||||||
|
}
|
||||||
|
|||||||
@ -81,4 +81,8 @@ public:
|
|||||||
|
|
||||||
/// @return true if the emitter has spawned all particles
|
/// @return true if the emitter has spawned all particles
|
||||||
bool isDead() const;
|
bool isDead() const;
|
||||||
|
|
||||||
|
const EmitterOrigin& getOrigin() const;
|
||||||
|
|
||||||
|
void setOrigin(const EmitterOrigin& origin);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -46,8 +46,37 @@ static int l_stop(lua::State* L) {
|
|||||||
return 0;
|
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[] = {
|
const luaL_Reg particleslib[] = {
|
||||||
{"emit", lua::wrap<l_emit>},
|
{"emit", lua::wrap<l_emit>},
|
||||||
{"stop", lua::wrap<l_stop>},
|
{"stop", lua::wrap<l_stop>},
|
||||||
|
{"get_origin", lua::wrap<l_get_origin>},
|
||||||
|
{"set_origin", lua::wrap<l_set_origin>},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user