瀏覽代碼

Added SpriteBatch:isEmpty() and SpriteBatch:isFull()

Alex Szpakowski 12 年之前
父節點
當前提交
d3cdb7d609

+ 10 - 0
src/modules/graphics/opengl/SpriteBatch.cpp

@@ -190,6 +190,16 @@ void SpriteBatch::setColor()
 	color = 0;
 	color = 0;
 }
 }
 
 
+bool SpriteBatch::isEmpty() const
+{
+	return next == 0;
+}
+
+bool SpriteBatch::isFull() const
+{
+	return next >= size;
+}
+
 void SpriteBatch::draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const
 void SpriteBatch::draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const
 {
 {
 	const int color_offset = 0;
 	const int color_offset = 0;

+ 10 - 0
src/modules/graphics/opengl/SpriteBatch.h

@@ -86,6 +86,16 @@ public:
 	 */
 	 */
 	void setColor();
 	void setColor();
 
 
+	/**
+	 * Returns whether the SpriteBatch is empty of sprites or not.
+	 **/
+	bool isEmpty() const;
+
+	/**
+	 * Returns whether the amount of sprites has reached the buffer limit or not.
+	 **/
+	bool isFull() const;
+
 	// Implements Drawable.
 	// Implements Drawable.
 	void draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const;
 	void draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const;
 
 

+ 16 - 0
src/modules/graphics/opengl/wrap_SpriteBatch.cpp

@@ -184,6 +184,20 @@ int w_SpriteBatch_setColor(lua_State *L)
 	return 0;
 	return 0;
 }
 }
 
 
+int w_SpriteBatch_isEmpty(lua_State *L)
+{
+	SpriteBatch *t = luax_checkspritebatch(L, 1);
+	luax_pushboolean(L, t->isEmpty());
+	return 1;
+}
+
+int w_SpriteBatch_isFull(lua_State *L)
+{
+	SpriteBatch *t = luax_checkspritebatch(L, 1);
+	luax_pushboolean(L, t->isFull());
+	return 1;
+}
+
 static const luaL_Reg functions[] =
 static const luaL_Reg functions[] =
 {
 {
 	{ "add", w_SpriteBatch_add },
 	{ "add", w_SpriteBatch_add },
@@ -196,6 +210,8 @@ static const luaL_Reg functions[] =
 	{ "setImage", w_SpriteBatch_setImage },
 	{ "setImage", w_SpriteBatch_setImage },
 	{ "getImage", w_SpriteBatch_getImage },
 	{ "getImage", w_SpriteBatch_getImage },
 	{ "setColor", w_SpriteBatch_setColor },
 	{ "setColor", w_SpriteBatch_setColor },
+	{ "isEmpty", w_SpriteBatch_isEmpty },
+	{ "isFull", w_SpriteBatch_isFull },
 	{ 0, 0 }
 	{ 0, 0 }
 };
 };
 
 

+ 5 - 2
src/modules/graphics/opengl/wrap_SpriteBatch.h

@@ -37,10 +37,13 @@ int w_SpriteBatch_addq(lua_State *L);
 int w_SpriteBatch_set(lua_State *L);
 int w_SpriteBatch_set(lua_State *L);
 int w_SpriteBatch_setq(lua_State *L);
 int w_SpriteBatch_setq(lua_State *L);
 int w_SpriteBatch_clear(lua_State *L);
 int w_SpriteBatch_clear(lua_State *L);
-int w_SpriteBatch_lock(lua_State *L);
-int w_SpriteBatch_unlock(lua_State *L);
+int w_SpriteBatch_bind(lua_State *L);
+int w_SpriteBatch_unbind(lua_State *L);
 int w_SpriteBatch_setImage(lua_State *L);
 int w_SpriteBatch_setImage(lua_State *L);
 int w_SpriteBatch_getImage(lua_State *L);
 int w_SpriteBatch_getImage(lua_State *L);
+int w_SpriteBatch_setColor(lua_State *L);
+int w_SpriteBatch_isEmpty(lua_State *L);
+int w_SpriteBatch_isFull(lua_State *L);
 
 
 extern "C" int luaopen_spritebatch(lua_State *L);
 extern "C" int luaopen_spritebatch(lua_State *L);