Kaynağa Gözat

Fix warnings in MSVC 2010.

rude 14 yıl önce
ebeveyn
işleme
e1d1ebb2f1

+ 6 - 1
src/common/math.h

@@ -66,7 +66,7 @@ struct vertex
 	float x, y;
 	float s, t;
 };
-	
+
 inline int next_p2(int x)
 {
 	x += (x == 0);
@@ -75,6 +75,11 @@ inline int next_p2(int x)
 	return ++x;
 }
 
+inline float next_p2(float x)
+{
+	return static_cast<float>(next_p2(static_cast<int>(x)));
+}
+
 } // love
 
 #endif // LOVE_MATH_H

+ 22 - 0
src/common/runtime.h

@@ -273,6 +273,28 @@ namespace love
 
 	Type luax_type(lua_State * L, int idx);
 
+	/**
+	 * Convert the value at the specified index to an Lua number, and then
+	 * convert to a float.
+	 *
+	 * @param L The Lua state.
+	 * @param idx The index on the stack.
+	 */
+	inline float luax_tofloat(lua_State *L, int idx)
+	{
+		return static_cast<float>(lua_tonumber(L, idx));
+	}
+
+	/**
+	 * Like luax_tofloat, but checks that the value is a number.
+	 *
+	 * @see luax_tofloat
+	 */
+	inline float luax_checkfloat(lua_State *L, int idx)
+	{
+		return static_cast<float>(luaL_checknumber(L, idx));
+	}
+
 	/**
 	* Converts the value at idx to the specified type without checking that
 	* this conversion is valid. If the type has been previously verified with

+ 1 - 1
src/modules/filesystem/physfs/wrap_Filesystem.cpp

@@ -56,7 +56,7 @@ namespace physfs
 	{
 		// no error checking needed, everything, even nothing
 		// can be converted to a boolean
-		instance->setRelease(lua_toboolean(L, 1));
+		instance->setRelease(luax_toboolean(L, 1));
 		return 0;
 	}
 

+ 5 - 9
src/modules/graphics/opengl/Graphics.cpp

@@ -78,14 +78,10 @@ namespace opengl
 	DisplayState Graphics::saveState()
 	{
 		DisplayState s;
-		//create a table in which to store the color data in float format, before converting it
-		float color[4];
-		//get the color
-		glGetFloatv(GL_CURRENT_COLOR, color);
-		s.color.set( (color[0]*255.0f), (color[1]*255.0f), (color[2]*255.0f), (color[3]*255.0f) );
-		//get the background color
-		glGetFloatv(GL_COLOR_CLEAR_VALUE, color);
-		s.backgroundColor.set( color[0]*255.0f, color[1]*255.0f, color[2]*255.0f, color[3]*255.0f );
+
+		s.color = getColor();
+		s.backgroundColor = getBackgroundColor();
+
 		//store modes here
 		GLint mode;
 		//get blend mode
@@ -276,7 +272,7 @@ namespace opengl
 		currentMode.colorDepth = 32;
 		currentMode.fsaa = fsaa;
 		currentMode.fullscreen = fullscreen;
-		currentMode.vsync = real_vsync;
+		currentMode.vsync = (real_vsync != 0);
 
 		// Reload all volatile objects.
 		if(!Volatile::loadAll())

+ 1 - 1
src/modules/graphics/opengl/ParticleSystem.cpp

@@ -114,7 +114,7 @@ namespace opengl
 		pLast->tangentialAcceleration = (rand() / (float(RAND_MAX)+1)) * (max - min) + min;
 
 		pLast->sizeOffset       = (rand() / (float(RAND_MAX)+1)) * sizeVariation; // time offset for size change
-		pLast->sizeIntervalSize = (1.0 - (rand() / (float(RAND_MAX)+1)) * sizeVariation) - pLast->sizeOffset;
+		pLast->sizeIntervalSize = (1.0f - (rand() / (float(RAND_MAX)+1)) * sizeVariation) - pLast->sizeOffset;
 		pLast->size = sizes[(size_t)(pLast->sizeOffset - .5f) * (sizes.size() - 1)];
 
 		min = rotationMin;

+ 4 - 4
src/modules/graphics/opengl/wrap_Graphics.cpp

@@ -926,12 +926,12 @@ namespace opengl
 			for (int i = 0; i < args; ++i) {
 				lua_pushnumber(L, i + 1);
 				lua_rawget(L, 1);
-				coords[i] = lua_tonumber(L, -1);
+				coords[i] = luax_tofloat(L, -1);
 				lua_pop(L, 1);
 			}
 		} else {
 			for (int i = 0; i < args; ++i)
-				coords[i] = lua_tonumber(L, i + 1);
+				coords[i] = luax_tofloat(L, i + 1);
 		}
 
 		instance->polyline(coords, args);
@@ -1050,12 +1050,12 @@ namespace opengl
 			for (int i = 0; i < args; ++i) {
 				lua_pushnumber(L, i + 1);
 				lua_rawget(L, 2);
-				coords[i] = lua_tonumber(L, -1);
+				coords[i] = luax_tofloat(L, -1);
 				lua_pop(L, 1);
 			}
 		} else {
 			for (int i = 0; i < args; ++i)
-				coords[i] = lua_tonumber(L, i + 2);
+				coords[i] = luax_tofloat(L, i + 2);
 		}
 
 		// make a closed loop

+ 2 - 2
src/modules/graphics/opengl/wrap_ParticleSystem.cpp

@@ -148,11 +148,11 @@ namespace opengl
 		ParticleSystem * t = luax_checkparticlesystem(L, 1);
 		size_t nSizes = lua_gettop(L) - 1;
 		if (nSizes == 1) {
-			t->setSize(luaL_checknumber(L, 2));
+			t->setSize(luax_checkfloat(L, 2));
 		} else {
 			std::vector<float> sizes(nSizes);
 			for (size_t i = 0; i < nSizes; ++i)
-				sizes[i] = luaL_checknumber(L, 1 + i + 1);
+				sizes[i] = luax_checkfloat(L, 1 + i + 1);
 
 			t->setSize(sizes);
 		}

+ 1 - 1
src/modules/sound/lullaby/Mpg123Decoder.cpp

@@ -164,7 +164,7 @@ namespace lullaby
 
 	bool Mpg123Decoder::seek(float s)
 	{
-		off_t offset = s * sampleRate;
+		off_t offset = static_cast<off_t>(s * static_cast<float>(sampleRate));
 
 		if(offset < 0)
 			return false;