diff --git a/src/common/Exception.cpp b/src/common/Exception.cpp index 8b5e5956d..3a2b6d25f 100644 --- a/src/common/Exception.cpp +++ b/src/common/Exception.cpp @@ -23,8 +23,6 @@ #include -using namespace std; - namespace love { diff --git a/src/modules/graphics/opengl/Canvas.cpp b/src/modules/graphics/opengl/Canvas.cpp index 9fb7d0f79..f5b154d06 100644 --- a/src/modules/graphics/opengl/Canvas.cpp +++ b/src/modules/graphics/opengl/Canvas.cpp @@ -645,14 +645,15 @@ love::image::ImageData *Canvas::getImageData(love::image::Image *image) void Canvas::getPixel(unsigned char* pixel_rgba, int x, int y) { - strategy->bindFBO( fbo ); + if (current != this) + strategy->bindFBO(fbo); glReadPixels(x, height - y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel_rgba); - if (current) - strategy->bindFBO( current->fbo ); - else - strategy->bindFBO( 0 ); + if (current && current != this) + strategy->bindFBO(current->fbo); + else if (!current) + strategy->bindFBO(0); } const std::vector &Canvas::getAttachedCanvases() const @@ -692,8 +693,7 @@ bool Canvas::loadVolatile() setFilter(settings.filter); setWrap(settings.wrap); - Color c; - c.r = c.g = c.b = c.a = 0; + Color c(0, 0, 0, 0); clear(c); return true; } diff --git a/src/modules/graphics/opengl/Graphics.cpp b/src/modules/graphics/opengl/Graphics.cpp index 9ffc9cab8..211f1a5ae 100644 --- a/src/modules/graphics/opengl/Graphics.cpp +++ b/src/modules/graphics/opengl/Graphics.cpp @@ -880,7 +880,9 @@ void Graphics::printf(const char *str, float x, float y, float wrap, AlignMode a if (currentFont == 0) return; - using namespace std; + using std::string; + using std::vector; + string text(str); vector lines_to_draw = currentFont->getWrap(text, wrap); diff --git a/src/modules/graphics/opengl/Image.cpp b/src/modules/graphics/opengl/Image.cpp index 532ae4313..ba45adc35 100644 --- a/src/modules/graphics/opengl/Image.cpp +++ b/src/modules/graphics/opengl/Image.cpp @@ -131,21 +131,21 @@ void Image::uploadCompressedMipmaps() bind(); - int numMipmaps = cdata->getNumMipmaps(); + int mipmapcount = cdata->getMipmapCount(); // We have to inform OpenGL if the image doesn't have all mipmap levels. if (GLEE_VERSION_1_2 || GLEE_SGIS_texture_lod) { - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, numMipmaps - 1); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, mipmapcount - 1); } - else if (cdata->getWidth(numMipmaps-1) > 1 || cdata->getHeight(numMipmaps-1) > 1) + else if (cdata->getWidth(mipmapcount-1) > 1 || cdata->getHeight(mipmapcount-1) > 1) { // Telling OpenGL to ignore certain levels isn't always supported. throw love::Exception("Cannot load mipmaps: " "compressed image does not have all required levels."); } - for (int i = 1; i < numMipmaps; i++) + for (int i = 1; i < mipmapcount; i++) { glCompressedTexImage2DARB(GL_TEXTURE_2D, i, diff --git a/src/modules/graphics/opengl/wrap_Canvas.cpp b/src/modules/graphics/opengl/wrap_Canvas.cpp index 8eee30c9a..66396106d 100644 --- a/src/modules/graphics/opengl/wrap_Canvas.cpp +++ b/src/modules/graphics/opengl/wrap_Canvas.cpp @@ -44,8 +44,7 @@ int w_Canvas_renderTo(lua_State *L) } Canvas *canvas = luax_checkcanvas(L, 1); - if (!lua_isfunction(L, 2)) - return luaL_error(L, "Need a function to render to canvas."); + luaL_checktype(L, 2, LUA_TFUNCTION); try { @@ -182,19 +181,19 @@ int w_Canvas_clear(lua_State *L) for (int i = 1; i <= 4; i++) lua_rawgeti(L, 2, i); - c.r = (unsigned char)luaL_checkint(L, -4); - c.g = (unsigned char)luaL_checkint(L, -3); - c.b = (unsigned char)luaL_checkint(L, -2); - c.a = (unsigned char)luaL_optint(L, -1, 255); + c.r = (unsigned char)luaL_checkinteger(L, -4); + c.g = (unsigned char)luaL_checkinteger(L, -3); + c.b = (unsigned char)luaL_checkinteger(L, -2); + c.a = (unsigned char)luaL_optinteger(L, -1, 255); lua_pop(L, 4); } else { - c.r = (unsigned char)luaL_checkint(L, 2); - c.g = (unsigned char)luaL_checkint(L, 3); - c.b = (unsigned char)luaL_checkint(L, 4); - c.a = (unsigned char)luaL_optint(L, 5, 255); + c.r = (unsigned char)luaL_checkinteger(L, 2); + c.g = (unsigned char)luaL_checkinteger(L, 3); + c.b = (unsigned char)luaL_checkinteger(L, 4); + c.a = (unsigned char)luaL_optinteger(L, 5, 255); } canvas->clear(c); diff --git a/src/modules/graphics/opengl/wrap_Graphics.cpp b/src/modules/graphics/opengl/wrap_Graphics.cpp index a12ebacb6..3abc50bf4 100644 --- a/src/modules/graphics/opengl/wrap_Graphics.cpp +++ b/src/modules/graphics/opengl/wrap_Graphics.cpp @@ -241,8 +241,7 @@ int w_getScissor(lua_State *L) int w_newStencil(lua_State *L) { // just return the function - if (!lua_isfunction(L, 1)) - return luaL_typerror(L, 1, "function"); + luaL_checktype(L, 1, LUA_TFUNCTION); lua_settop(L, 1); return 1; } @@ -256,8 +255,7 @@ static int setStencil(lua_State *L, bool invert) return 0; } - if (!lua_isfunction(L, 1)) - return luaL_typerror(L, 1, "mask"); + luaL_checktype(L, 1, LUA_TFUNCTION); instance->defineStencil(); lua_call(L, lua_gettop(L) - 1, 0); // call mask(...) diff --git a/src/modules/image/CompressedData.cpp b/src/modules/image/CompressedData.cpp index 2f55d806c..edabe6889 100644 --- a/src/modules/image/CompressedData.cpp +++ b/src/modules/image/CompressedData.cpp @@ -55,7 +55,7 @@ void *CompressedData::getData() const return 0; } -int CompressedData::getNumMipmaps() const +int CompressedData::getMipmapCount() const { return dataImages.size(); } diff --git a/src/modules/image/CompressedData.h b/src/modules/image/CompressedData.h index 6ffbe6f0c..b9ff93358 100644 --- a/src/modules/image/CompressedData.h +++ b/src/modules/image/CompressedData.h @@ -77,10 +77,10 @@ public: virtual int getSize() const; /** - * Gets the number of mipmaps in this CompressedData. + * Gets the number of mipmaps in this Compressed Image Data. * Includes the base image level. **/ - int getNumMipmaps() const; + int getMipmapCount() const; /** * Gets the size in bytes of a sub-image at the specified mipmap level. diff --git a/src/modules/image/wrap_CompressedData.cpp b/src/modules/image/wrap_CompressedData.cpp index 3035c8043..a65185fba 100644 --- a/src/modules/image/wrap_CompressedData.cpp +++ b/src/modules/image/wrap_CompressedData.cpp @@ -40,7 +40,7 @@ int w_CompressedData_getString(lua_State *L) size_t totalsize = 0; - for (int i = 0; i < t->getNumMipmaps(); i++) + for (int i = 0; i < t->getMipmapCount(); i++) totalsize += t->getSize(i); if (totalsize == 0) @@ -60,7 +60,7 @@ int w_CompressedData_getString(lua_State *L) } size_t curpos = 0; - for (int i = 0; i < t->getNumMipmaps(); i++) + for (int i = 0; i < t->getMipmapCount(); i++) { memcpy(&datastr[curpos], t->getData(i), t->getSize(i)); curpos += t->getSize(i); @@ -79,7 +79,7 @@ int w_CompressedData_getSize(lua_State *L) size_t totalsize = 0; - for (int i = 0; i < t->getNumMipmaps(); i++) + for (int i = 0; i < t->getMipmapCount(); i++) totalsize += t->getSize(i); lua_pushnumber(L, (lua_Number) totalsize); @@ -140,10 +140,10 @@ int w_CompressedData_getDimensions(lua_State *L) return 2; } -int w_CompressedData_getNumMipmaps(lua_State *L) +int w_CompressedData_getMipmapCount(lua_State *L) { CompressedData *t = luax_checkcompresseddata(L, 1); - lua_pushinteger(L, t->getNumMipmaps()); + lua_pushinteger(L, t->getMipmapCount()); return 1; } @@ -172,7 +172,7 @@ static const luaL_Reg functions[] = { "getWidth", w_CompressedData_getWidth }, { "getHeight", w_CompressedData_getHeight }, { "getDimensions", w_CompressedData_getDimensions }, - { "getNumMipmaps", w_CompressedData_getNumMipmaps }, + { "getMipmapCount", w_CompressedData_getMipmapCount }, { "getType", w_CompressedData_getType }, { 0, 0 }, }; diff --git a/src/modules/image/wrap_CompressedData.h b/src/modules/image/wrap_CompressedData.h index 13ec22e46..f31423f72 100644 --- a/src/modules/image/wrap_CompressedData.h +++ b/src/modules/image/wrap_CompressedData.h @@ -36,7 +36,7 @@ int w_CompressedData_getSize(lua_State *L); int w_CompressedData_getWidth(lua_State *L); int w_CompressedData_getHeight(lua_State *L); int w_CompressedData_getDimensions(lua_State *L); -int w_CompressedData_getNumMipmaps(lua_State *L); +int w_CompressedData_getMipmapCount(lua_State *L); int w_CompressedData_getType(lua_State *L); extern "C" int luaopen_compresseddata(lua_State *L); diff --git a/src/modules/image/wrap_ImageData.cpp b/src/modules/image/wrap_ImageData.cpp index 6b5dd40a4..d09c2fc0c 100644 --- a/src/modules/image/wrap_ImageData.cpp +++ b/src/modules/image/wrap_ImageData.cpp @@ -101,8 +101,7 @@ int w_ImageData_mapPixel(lua_State *L) { ImageData *t = luax_checkimagedata(L, 1); - if (!lua_isfunction(L, 2)) - return luaL_error(L, "Function expected"); + luaL_checktype(L, 2, LUA_TFUNCTION); int w = t->getWidth(); int h = t->getHeight(); diff --git a/src/modules/love/love.cpp b/src/modules/love/love.cpp index 657d7b8b7..a82064571 100644 --- a/src/modules/love/love.cpp +++ b/src/modules/love/love.cpp @@ -116,12 +116,12 @@ static const luaL_Reg modules[] = { { "love.image", luaopen_love_image }, { "love.joystick", luaopen_love_joystick }, { "love.keyboard", luaopen_love_keyboard }, + { "love.math", luaopen_love_math }, { "love.mouse", luaopen_love_mouse }, { "love.physics", luaopen_love_physics }, { "love.sound", luaopen_love_sound }, { "love.timer", luaopen_love_timer }, { "love.thread", luaopen_love_thread }, - { "love.math", luaopen_love_math }, { "love.boot", luaopen_love_boot }, { 0, 0 } }; @@ -242,7 +242,8 @@ int w__openConsole(lua_State * L) int luaopen_love_boot(lua_State *L) { if (luaL_loadbuffer(L, (const char *)love::boot_lua, sizeof(love::boot_lua), "boot.lua") == 0) - lua_call(L, 0, 1); + lua_call(L, 0, 1); + return 1; } diff --git a/src/modules/math/MathModule.cpp b/src/modules/math/MathModule.cpp index ef9c39f43..c693519ff 100644 --- a/src/modules/math/MathModule.cpp +++ b/src/modules/math/MathModule.cpp @@ -18,14 +18,17 @@ * 3. This notice may not be removed or altered from any source distribution. **/ +// LOVE #include "MathModule.h" #include "common/math.h" +// STL #include #include #include -using namespace std; +using std::list; +using std::vector; using love::vertex; namespace diff --git a/src/modules/math/MathModule.h b/src/modules/math/MathModule.h index bbacd5c4b..98e98984f 100644 --- a/src/modules/math/MathModule.h +++ b/src/modules/math/MathModule.h @@ -32,7 +32,6 @@ #include "libraries/noise1234/simplexnoise1234.h" // STL -#include #include namespace love