From e1d1ebb2f15f167a383643ffa2bfa1ed3ea77f78 Mon Sep 17 00:00:00 2001 From: rude Date: Sun, 24 Jul 2011 18:32:11 +0200 Subject: [PATCH] Fix warnings in MSVC 2010. --- src/common/math.h | 7 +++++- src/common/runtime.h | 22 +++++++++++++++++++ .../filesystem/physfs/wrap_Filesystem.cpp | 2 +- src/modules/graphics/opengl/Graphics.cpp | 14 +++++------- .../graphics/opengl/ParticleSystem.cpp | 2 +- src/modules/graphics/opengl/wrap_Graphics.cpp | 8 +++---- .../graphics/opengl/wrap_ParticleSystem.cpp | 4 ++-- src/modules/sound/lullaby/Mpg123Decoder.cpp | 2 +- 8 files changed, 42 insertions(+), 19 deletions(-) diff --git a/src/common/math.h b/src/common/math.h index ae8e4aaa5..2ec22db5c 100644 --- a/src/common/math.h +++ b/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(next_p2(static_cast(x))); +} + } // love #endif // LOVE_MATH_H diff --git a/src/common/runtime.h b/src/common/runtime.h index 4c973031c..1543758b2 100644 --- a/src/common/runtime.h +++ b/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(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(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 diff --git a/src/modules/filesystem/physfs/wrap_Filesystem.cpp b/src/modules/filesystem/physfs/wrap_Filesystem.cpp index d8a6932f2..dfbfc0a8e 100644 --- a/src/modules/filesystem/physfs/wrap_Filesystem.cpp +++ b/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; } diff --git a/src/modules/graphics/opengl/Graphics.cpp b/src/modules/graphics/opengl/Graphics.cpp index ae10e7674..527c96708 100644 --- a/src/modules/graphics/opengl/Graphics.cpp +++ b/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()) diff --git a/src/modules/graphics/opengl/ParticleSystem.cpp b/src/modules/graphics/opengl/ParticleSystem.cpp index fb6c61cb3..2d8a5fe6a 100644 --- a/src/modules/graphics/opengl/ParticleSystem.cpp +++ b/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; diff --git a/src/modules/graphics/opengl/wrap_Graphics.cpp b/src/modules/graphics/opengl/wrap_Graphics.cpp index 416373cc4..683775d06 100644 --- a/src/modules/graphics/opengl/wrap_Graphics.cpp +++ b/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 diff --git a/src/modules/graphics/opengl/wrap_ParticleSystem.cpp b/src/modules/graphics/opengl/wrap_ParticleSystem.cpp index 8c6383cf3..1f4b7275c 100644 --- a/src/modules/graphics/opengl/wrap_ParticleSystem.cpp +++ b/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 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); } diff --git a/src/modules/sound/lullaby/Mpg123Decoder.cpp b/src/modules/sound/lullaby/Mpg123Decoder.cpp index 928e168c5..b62a5f272 100644 --- a/src/modules/sound/lullaby/Mpg123Decoder.cpp +++ b/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(s * static_cast(sampleRate)); if(offset < 0) return false;