diff --git a/src/modules/graphics/opengl/SpriteBatch.cpp b/src/modules/graphics/opengl/SpriteBatch.cpp index fc2bfc6ad..e80c4b491 100644 --- a/src/modules/graphics/opengl/SpriteBatch.cpp +++ b/src/modules/graphics/opengl/SpriteBatch.cpp @@ -20,9 +20,6 @@ #include "SpriteBatch.h" -// STD -#include // std::find - // OpenGL #include "OpenGL.h" @@ -97,25 +94,9 @@ SpriteBatch::~SpriteBatch() int SpriteBatch::add(float x, float y, float a, float sx, float sy, float ox, float oy, float kx, float ky, int index /*= -1*/) { // Only do this if there's a free slot. - if ((index == -1 && next >= size && gaps.size() == 0) || index < -1 || index >= size) + if ((index == -1 && next >= size) || index < -1 || index >= size) return -1; - // Determine where in the vertex buffer to insert into, using the gap list - // if possible. - int realindex; - if (index == -1 && gaps.size() > 0) - { - realindex = gaps.front(); - gaps.pop_front(); - } - else - { - realindex = (index == -1) ? next : index; - std::deque::iterator it = std::find(gaps.begin(), gaps.end(), realindex); - if (it != gaps.end()) - gaps.erase(it); // This index is no longer a gap. - } - // Needed for colors. memcpy(sprite, image->getVertices(), sizeof(vertex)*4); @@ -128,37 +109,21 @@ int SpriteBatch::add(float x, float y, float a, float sx, float sy, float ox, fl setColorv(sprite, *color); - addv(sprite, realindex); + addv(sprite, (index == -1) ? next : index); // Increment counter. - if (index == -1 && realindex == next) + if (index == -1) return next++; - return realindex; + return index; } int SpriteBatch::addq(Quad *quad, float x, float y, float a, float sx, float sy, float ox, float oy, float kx, float ky, int index /*= -1*/) { // Only do this if there's a free slot. - if ((index == -1 && next >= size && gaps.size() == 0) || index < -1 || index >= next) + if ((index == -1 && next >= size) || index < -1 || index >= next) return -1; - // Determine where in the vertex buffer to insert into, using the gap list - // if possible. - int realindex; - if (index == -1 && gaps.size() > 0) - { - realindex = gaps.front(); - gaps.pop_front(); - } - else - { - realindex = (index == -1) ? next : index; - std::deque::iterator it = std::find(gaps.begin(), gaps.end(), realindex); - if (it != gaps.end()) - gaps.erase(it); // This index is no longer a gap. - } - // Needed for colors. memcpy(sprite, quad->getVertices(), sizeof(vertex)*4); @@ -170,53 +135,19 @@ int SpriteBatch::addq(Quad *quad, float x, float y, float a, float sx, float sy, if (color) setColorv(sprite, *color); - addv(sprite, realindex); + addv(sprite, (index == -1) ? next : index); // Increment counter. - if (index == -1 && realindex == next) + if (index == -1) return next++; - return realindex; -} - -void SpriteBatch::remove(int index) -{ - if (index < 0 || index >= next || next <= 0) - return; - - // If this is the last index in the sprite list, decrease the total sprite - // count instead of adding a dummy sprite. - if (index == next - 1) - { - int spritecount = index; - - // Remove all consecutive gaps at the end of the sprite list. - std::deque::iterator it; - while ((it = std::find(gaps.begin(), gaps.end(), --spritecount)) != gaps.end()) - gaps.erase(it); - - next = spritecount + 1; - return; - } - else if (std::find(gaps.begin(), gaps.end(), index) != gaps.end()) - return; // Don't add the same index to the gap list twice. - - - // OpenGL won't render any primitive whose vertices are all identical. - for (int i = 0; i < 4; i++) - sprite[i].x = sprite[i].y = 0; - - // Replace the existing sprite at this index with the dummy sprite. - addv(sprite, index); - - gaps.push_back(index); + return index; } void SpriteBatch::clear() { // Reset the position of the next index. next = 0; - gaps.clear(); } void *SpriteBatch::lock() diff --git a/src/modules/graphics/opengl/SpriteBatch.h b/src/modules/graphics/opengl/SpriteBatch.h index 43055dab1..5cf71b928 100644 --- a/src/modules/graphics/opengl/SpriteBatch.h +++ b/src/modules/graphics/opengl/SpriteBatch.h @@ -23,7 +23,6 @@ // C #include -#include // LOVE #include "common/math.h" @@ -64,7 +63,6 @@ public: int add(float x, float y, float a, float sx, float sy, float ox, float oy, float kx, float ky, int index = -1); int addq(Quad *quad, float x, float y, float a, float sx, float sy, float ox, float oy, float kx, float ky, int index = -1); - void remove(int index); void clear(); void *lock(); @@ -127,10 +125,6 @@ private: VertexBuffer *array_buf; VertexIndex *element_buf; - // List of gaps in the SpriteBatch. Checked when adding sprites, and added - // to when removing them. - std::deque gaps; - }; // SpriteBatch } // opengl diff --git a/src/modules/graphics/opengl/wrap_SpriteBatch.cpp b/src/modules/graphics/opengl/wrap_SpriteBatch.cpp index f29619991..6d9f501c1 100644 --- a/src/modules/graphics/opengl/wrap_SpriteBatch.cpp +++ b/src/modules/graphics/opengl/wrap_SpriteBatch.cpp @@ -101,14 +101,6 @@ int w_SpriteBatch_setq(lua_State *L) return 0; } -int w_SpriteBatch_remove(lua_State *L) -{ - SpriteBatch *t = luax_checkspritebatch(L, 1); - int id = luaL_checkinteger(L, 2); - t->remove(id); - return 0; -} - int w_SpriteBatch_clear(lua_State *L) { SpriteBatch *t = luax_checkspritebatch(L, 1); @@ -198,7 +190,6 @@ static const luaL_Reg functions[] = { "addq", w_SpriteBatch_addq }, { "set", w_SpriteBatch_set }, { "setq", w_SpriteBatch_setq }, - { "remove", w_SpriteBatch_remove }, { "clear", w_SpriteBatch_clear }, { "bind", w_SpriteBatch_bind }, { "unbind", w_SpriteBatch_unbind }, diff --git a/src/modules/graphics/opengl/wrap_SpriteBatch.h b/src/modules/graphics/opengl/wrap_SpriteBatch.h index ca397d715..aa737dcc9 100644 --- a/src/modules/graphics/opengl/wrap_SpriteBatch.h +++ b/src/modules/graphics/opengl/wrap_SpriteBatch.h @@ -36,7 +36,6 @@ int w_SpriteBatch_add(lua_State *L); int w_SpriteBatch_addq(lua_State *L); int w_SpriteBatch_set(lua_State *L); int w_SpriteBatch_setq(lua_State *L); -int w_SpriteBatch_remove(lua_State *L); int w_SpriteBatch_clear(lua_State *L); int w_SpriteBatch_lock(lua_State *L); int w_SpriteBatch_unlock(lua_State *L);