Browse Source

Added ParticleSystem:emit(num) (issue #577)

Alex Szpakowski 12 years ago
parent
commit
7b8884965e

+ 14 - 0
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;

+ 6 - 0
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.
 	 **/

+ 9 - 0
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 },

+ 1 - 0
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);