diff --git a/src/modules/graphics/opengl/ParticleSystem.cpp b/src/modules/graphics/opengl/ParticleSystem.cpp index 963742f80..4dd116df0 100644 --- a/src/modules/graphics/opengl/ParticleSystem.cpp +++ b/src/modules/graphics/opengl/ParticleSystem.cpp @@ -478,6 +478,20 @@ void ParticleSystem::reset() emitCounter = 0; } +void ParticleSystem::emit(int num) +{ + if (!active) + return; + + for (int i = 0; i < num; i++) + { + if (isFull()) + return; + + add(); + } +} + bool ParticleSystem::isActive() const { return active; diff --git a/src/modules/graphics/opengl/ParticleSystem.h b/src/modules/graphics/opengl/ParticleSystem.h index aa1edacf8..51a653b3a 100644 --- a/src/modules/graphics/opengl/ParticleSystem.h +++ b/src/modules/graphics/opengl/ParticleSystem.h @@ -377,6 +377,12 @@ public: **/ void reset(); + /** + * Instantly emits a number of particles. + * @param num The number of particles to emit. + **/ + void emit(int num); + /** * Returns whether the particle emitter is active. **/ diff --git a/src/modules/graphics/opengl/wrap_ParticleSystem.cpp b/src/modules/graphics/opengl/wrap_ParticleSystem.cpp index f825e7ef7..1287b833d 100644 --- a/src/modules/graphics/opengl/wrap_ParticleSystem.cpp +++ b/src/modules/graphics/opengl/wrap_ParticleSystem.cpp @@ -452,6 +452,14 @@ int w_ParticleSystem_reset(lua_State *L) return 0; } +int w_ParticleSystem_emit(lua_State *L) +{ + ParticleSystem *t = luax_checkparticlesystem(L, 1); + int num = luaL_checkint(L, 2); + t->emit(num); + return 0; +} + int w_ParticleSystem_isActive(lua_State *L) { ParticleSystem *t = luax_checkparticlesystem(L, 1); @@ -518,6 +526,7 @@ static const luaL_Reg functions[] = { "stop", w_ParticleSystem_stop }, { "pause", w_ParticleSystem_pause }, { "reset", w_ParticleSystem_reset }, + { "emit", w_ParticleSystem_emit }, { "isActive", w_ParticleSystem_isActive }, { "isEmpty", w_ParticleSystem_isEmpty }, { "isFull", w_ParticleSystem_isFull }, diff --git a/src/modules/graphics/opengl/wrap_ParticleSystem.h b/src/modules/graphics/opengl/wrap_ParticleSystem.h index 148dcbbc2..f189c7a9a 100644 --- a/src/modules/graphics/opengl/wrap_ParticleSystem.h +++ b/src/modules/graphics/opengl/wrap_ParticleSystem.h @@ -67,6 +67,7 @@ int w_ParticleSystem_start(lua_State *L); int w_ParticleSystem_stop(lua_State *L); int w_ParticleSystem_pause(lua_State *L); int w_ParticleSystem_reset(lua_State *L); +int w_ParticleSystem_emit(lua_State *L); int w_ParticleSystem_isActive(lua_State *L); int w_ParticleSystem_isEmpty(lua_State *L); int w_ParticleSystem_isFull(lua_State *L);