1. rude
  2. love

Commits

Alex Szpakowski  committed b3b9a2e

Renamed CompressedData:getNumMipmaps to CompressedData:getMipmapCount; Improved type-checking error messages for some functions which expect function arguments

  • Participants
  • Parent commits 69cd35a
  • Branches default

Comments (0)

Files changed (14)

File src/common/Exception.cpp

View file
 
 #include <iostream>
 
-using namespace std;
-
 namespace love
 {
 

File src/modules/graphics/opengl/Canvas.cpp

View file
 
 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 *> &Canvas::getAttachedCanvases() const
 
 	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;
 }

File src/modules/graphics/opengl/Graphics.cpp

View file
 	if (currentFont == 0)
 		return;
 
-	using namespace std;
+	using std::string;
+	using std::vector;
+
 	string text(str);
 	vector<string> lines_to_draw = currentFont->getWrap(text, wrap);
 

File src/modules/graphics/opengl/Image.cpp

View file
 
 	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,

File src/modules/graphics/opengl/wrap_Canvas.cpp

View file
 	}
 
 	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
 	{
 		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);
 

File src/modules/graphics/opengl/wrap_Graphics.cpp

View file
 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;
 }
 		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(...)

File src/modules/image/CompressedData.cpp

View file
 		return 0;
 }
 
-int CompressedData::getNumMipmaps() const
+int CompressedData::getMipmapCount() const
 {
 	return dataImages.size();
 }

File src/modules/image/CompressedData.h

View file
 	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.

File src/modules/image/wrap_CompressedData.cpp

View file
 
 	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)
 	}
 
 	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);
 
 	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);
 	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;
 }
 
 	{ "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 },
 };

File src/modules/image/wrap_CompressedData.h

View file
 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);
 

File src/modules/image/wrap_ImageData.cpp

View file
 {
 	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();

File src/modules/love/love.cpp

View file
 	{ "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 }
 };
 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;
 }
 

File src/modules/math/MathModule.cpp

View file
  * 3. This notice may not be removed or altered from any source distribution.
  **/
 
+// LOVE
 #include "MathModule.h"
 #include "common/math.h"
 
+// STL
 #include <cmath>
 #include <list>
 #include <iostream>
 
-using namespace std;
+using std::list;
+using std::vector;
 using love::vertex;
 
 namespace

File src/modules/math/MathModule.h

View file
 #include "libraries/noise1234/simplexnoise1234.h"
 
 // STL
-#include <limits>
 #include <vector>
 
 namespace love