From 1e8c9e18c30bef6c755a5b50b20e0f5bcde3e5b9 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Wed, 27 Aug 2014 00:58:42 -0300 Subject: [PATCH 1/5] Fixed love.joystick.setGamepadMapping: the generated SDL controller mapping string is no longer invalid, and joystick hats are now properly converted to the SDL representation. --- src/modules/joystick/sdl/JoystickModule.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/modules/joystick/sdl/JoystickModule.cpp b/src/modules/joystick/sdl/JoystickModule.cpp index 4ec6deb00..e9b96255a 100644 --- a/src/modules/joystick/sdl/JoystickModule.cpp +++ b/src/modules/joystick/sdl/JoystickModule.cpp @@ -218,8 +218,8 @@ bool JoystickModule::setGamepadMapping(const std::string &guid, Joystick::Gamepa joyinputstream << "b" << joyinput.button; break; case Joystick::INPUT_TYPE_HAT: - if (joyinput.hat.value >= 0 && Joystick::getConstant(joyinput.hat.value, sdlhat)) - joyinputstream << "h" << joyinput.hat.value << "." << int(sdlhat); + if (joyinput.hat.index >= 0 && Joystick::getConstant(joyinput.hat.value, sdlhat)) + joyinputstream << "h" << joyinput.hat.index << "." << int(sdlhat); break; default: break; @@ -297,7 +297,7 @@ Joystick::JoystickInput JoystickModule::getGamepadMapping(const std::string &gui if (findpos == std::string::npos) return jinput; - size_t endpos = mapstr.find_first_of(',', findpos); + size_t endpos = mapstr.find_first_of(',', findpos + 1); if (endpos == std::string::npos) { // Assume end-of-string if we can't find the next comma. @@ -364,19 +364,19 @@ Joystick::JoystickInput JoystickModule::JoystickInputFromString(const std::strin { case 'a': jinput.type = Joystick::INPUT_TYPE_AXIS; - jinput.axis = atoi(bindvalues.c_str()); + jinput.axis = (int) strtol(bindvalues.c_str(), nullptr, 10); break; case 'b': jinput.type = Joystick::INPUT_TYPE_BUTTON; - jinput.button = atoi(bindvalues.c_str()); + jinput.button = (int) strtol(bindvalues.c_str(), nullptr, 10); break; case 'h': // Hat string syntax is "index.value". if (bindvalues.length() < 3) break; jinput.type = Joystick::INPUT_TYPE_HAT; - jinput.hat.index = atoi(bindvalues.substr(0, 1).c_str()); - sdlhat = (Uint8) atoi(bindvalues.substr(2, 1).c_str()); + jinput.hat.index = (int) strtol(bindvalues.substr(0, 1).c_str(), nullptr, 10); + sdlhat = (Uint8) strtol(bindvalues.substr(2).c_str(), nullptr, 10); if (!Joystick::getConstant(sdlhat, jinput.hat.value)) { // Return an invalid value if we can't find the hat constant. @@ -405,10 +405,14 @@ void JoystickModule::removeBindFromMapString(std::string &mapstr, const std::str if (joybindpos == std::string::npos) return; - // Find the start of the entire bind. + // Find the start of the entire bind by looking for the separator between + // the end of one section of the map string and the start of this section. size_t bindstart = mapstr.rfind(',', joybindpos); if (bindstart != std::string::npos && bindstart < mapstr.length() - 1) { + // The start of the bind is directly after the separator. + bindstart++; + size_t bindend = mapstr.find(',', bindstart + 1); if (bindend == std::string::npos) bindend = mapstr.length() - 1; From e26abb417ee33233004dbe9bb2c3937c5ddae8c5 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Wed, 27 Aug 2014 01:04:58 -0300 Subject: [PATCH 2/5] Fixed indentation. --- src/modules/joystick/sdl/JoystickModule.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/modules/joystick/sdl/JoystickModule.cpp b/src/modules/joystick/sdl/JoystickModule.cpp index e9b96255a..a6af78703 100644 --- a/src/modules/joystick/sdl/JoystickModule.cpp +++ b/src/modules/joystick/sdl/JoystickModule.cpp @@ -405,13 +405,13 @@ void JoystickModule::removeBindFromMapString(std::string &mapstr, const std::str if (joybindpos == std::string::npos) return; - // Find the start of the entire bind by looking for the separator between - // the end of one section of the map string and the start of this section. + // Find the start of the entire bind by looking for the separator between + // the end of one section of the map string and the start of this section. size_t bindstart = mapstr.rfind(',', joybindpos); if (bindstart != std::string::npos && bindstart < mapstr.length() - 1) { - // The start of the bind is directly after the separator. - bindstart++; + // The start of the bind is directly after the separator. + bindstart++; size_t bindend = mapstr.find(',', bindstart + 1); if (bindend == std::string::npos) From 40c6821048f5ebd6ea5ebc46f7dcb2b7822d8c05 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Thu, 28 Aug 2014 00:48:32 -0300 Subject: [PATCH 3/5] Removed some dead code and fixed luax_pushtype when the object argument is null. --- src/common/runtime.cpp | 3 ++ src/modules/graphics/opengl/OpenGL.cpp | 52 -------------------------- src/modules/graphics/opengl/OpenGL.h | 5 --- src/modules/image/magpie/ddsHandler.h | 2 +- 4 files changed, 4 insertions(+), 58 deletions(-) diff --git a/src/common/runtime.cpp b/src/common/runtime.cpp index 6e4c34130..34b9719eb 100644 --- a/src/common/runtime.cpp +++ b/src/common/runtime.cpp @@ -398,7 +398,10 @@ void luax_rawnewtype(lua_State *L, const char *name, bits flags, love::Object *o void luax_pushtype(lua_State *L, const char *name, bits flags, love::Object *object) { if (object == nullptr) + { lua_pushnil(L); + return; + } // Fetch the registry table of instantiated types. luax_getregistry(L, REGISTRY_TYPES); diff --git a/src/modules/graphics/opengl/OpenGL.cpp b/src/modules/graphics/opengl/OpenGL.cpp index ec13d9b4f..86dc51204 100644 --- a/src/modules/graphics/opengl/OpenGL.cpp +++ b/src/modules/graphics/opengl/OpenGL.cpp @@ -579,58 +579,6 @@ float OpenGL::setTextureFilter(graphics::Texture::Filter &f) return f.anisotropy; } -graphics::Texture::Filter OpenGL::getTextureFilter() -{ - GLint gmin, gmag; - glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, &gmin); - glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, &gmag); - - Texture::Filter f; - - switch (gmin) - { - case GL_NEAREST: - f.min = Texture::FILTER_NEAREST; - f.mipmap = Texture::FILTER_NONE; - break; - case GL_NEAREST_MIPMAP_NEAREST: - f.min = f.mipmap = Texture::FILTER_NEAREST; - break; - case GL_NEAREST_MIPMAP_LINEAR: - f.min = Texture::FILTER_NEAREST; - f.mipmap = Texture::FILTER_LINEAR; - break; - case GL_LINEAR_MIPMAP_NEAREST: - f.min = Texture::FILTER_LINEAR; - f.mipmap = Texture::FILTER_NEAREST; - break; - case GL_LINEAR_MIPMAP_LINEAR: - f.min = f.mipmap = Texture::FILTER_LINEAR; - break; - case GL_LINEAR: - default: - f.min = Texture::FILTER_LINEAR; - f.mipmap = Texture::FILTER_NONE; - break; - } - - switch (gmag) - { - case GL_NEAREST: - f.mag = Texture::FILTER_NEAREST; - break; - case GL_LINEAR: - default: - f.mag = Texture::FILTER_LINEAR; - break; - } - - if (GLEE_EXT_texture_filter_anisotropic) - glGetTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, &f.anisotropy); - - return f; -} - void OpenGL::setTextureWrap(const graphics::Texture::Wrap &w) { GLint gs, gt; diff --git a/src/modules/graphics/opengl/OpenGL.h b/src/modules/graphics/opengl/OpenGL.h index 9d9ad6497..416199d78 100644 --- a/src/modules/graphics/opengl/OpenGL.h +++ b/src/modules/graphics/opengl/OpenGL.h @@ -264,11 +264,6 @@ public: **/ float setTextureFilter(graphics::Texture::Filter &f); - /** - * Returns the texture filter mode for the currently bound texture. - **/ - graphics::Texture::Filter getTextureFilter(); - /** * Sets the texture wrap mode for the currently bound texture. **/ diff --git a/src/modules/image/magpie/ddsHandler.h b/src/modules/image/magpie/ddsHandler.h index f8d711801..414a3b923 100644 --- a/src/modules/image/magpie/ddsHandler.h +++ b/src/modules/image/magpie/ddsHandler.h @@ -58,7 +58,7 @@ public: * a single block of memory containing all the images. * * @param[in] filedata The data to parse. - * @param[out] image The list of sub-images generated. Byte data is a pointer + * @param[out] images The list of sub-images generated. Byte data is a pointer * to the returned data. * @param[out] dataSize The total size in bytes of the returned data. * @param[out] format The format of the Compressed Data. From ab9954272a46f92430e379a44a59aa9a110fa9c0 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Thu, 28 Aug 2014 20:39:49 -0300 Subject: [PATCH 4/5] Updated the initialization code to trigger a real Lua error if love.conf has an error in it. --- src/scripts/boot.lua | 15 +++++++++------ src/scripts/boot.lua.h | 27 +++++++++++++++++++-------- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/src/scripts/boot.lua b/src/scripts/boot.lua index da4928f41..90d8d14ad 100644 --- a/src/scripts/boot.lua +++ b/src/scripts/boot.lua @@ -341,12 +341,11 @@ function love.init() -- Yes, conf.lua might not exist, but there are other ways of making -- love.conf appear, so we should check for it anyway. + local confok, conferr if love.conf then - local ok, err = pcall(love.conf, c) - if not ok then - print(err) - -- continue - end + confok, conferr = pcall(love.conf, c) + -- If love.conf errors, we'll trigger the error after loading modules so + -- the error message can be displayed in the window. end if love.arg.options.console.set then @@ -385,6 +384,10 @@ function love.init() love.createhandlers() end + if not confok and conferr then + error(conferr) + end + -- Setup window here. if c.window and c.modules.window then assert(love.window.setMode(c.window.width, c.window.height, @@ -1565,7 +1568,7 @@ function love.errhand(msg) local font = love.graphics.setNewFont(math.floor(14 * love.window.getPixelScale())) local sRGB = select(3, love.window.getMode()).srgb - if sRGB then + if sRGB and love.math then love.graphics.setBackgroundColor(love.math.gammaToLinear(89, 157, 220)) else love.graphics.setBackgroundColor(89, 157, 220) diff --git a/src/scripts/boot.lua.h b/src/scripts/boot.lua.h index 29880a85e..ea01b84db 100644 --- a/src/scripts/boot.lua.h +++ b/src/scripts/boot.lua.h @@ -614,14 +614,20 @@ const unsigned char boot_lua[] = 0x61, 0x72, 0x2c, 0x20, 0x73, 0x6f, 0x20, 0x77, 0x65, 0x20, 0x73, 0x68, 0x6f, 0x75, 0x6c, 0x64, 0x20, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x69, 0x74, 0x20, 0x61, 0x6e, 0x79, 0x77, 0x61, 0x79, 0x2e, 0x0a, + 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x63, 0x6f, 0x6e, 0x66, 0x6f, 0x6b, 0x2c, 0x20, 0x63, 0x6f, 0x6e, + 0x66, 0x65, 0x72, 0x72, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, - 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6f, 0x6b, 0x2c, 0x20, 0x65, 0x72, 0x72, 0x20, 0x3d, 0x20, - 0x70, 0x63, 0x61, 0x6c, 0x6c, 0x28, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x2c, 0x20, 0x63, - 0x29, 0x0a, - 0x09, 0x09, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x6f, 0x6b, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, - 0x09, 0x09, 0x09, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, 0x65, 0x72, 0x72, 0x29, 0x0a, - 0x09, 0x09, 0x09, 0x2d, 0x2d, 0x20, 0x63, 0x6f, 0x6e, 0x74, 0x69, 0x6e, 0x75, 0x65, 0x0a, - 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, + 0x09, 0x09, 0x63, 0x6f, 0x6e, 0x66, 0x6f, 0x6b, 0x2c, 0x20, 0x63, 0x6f, 0x6e, 0x66, 0x65, 0x72, 0x72, 0x20, + 0x3d, 0x20, 0x70, 0x63, 0x61, 0x6c, 0x6c, 0x28, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x2c, + 0x20, 0x63, 0x29, 0x0a, + 0x09, 0x09, 0x2d, 0x2d, 0x20, 0x49, 0x66, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x20, + 0x65, 0x72, 0x72, 0x6f, 0x72, 0x73, 0x2c, 0x20, 0x77, 0x65, 0x27, 0x6c, 0x6c, 0x20, 0x74, 0x72, 0x69, 0x67, + 0x67, 0x65, 0x72, 0x20, 0x74, 0x68, 0x65, 0x20, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x20, 0x61, 0x66, 0x74, 0x65, + 0x72, 0x20, 0x6c, 0x6f, 0x61, 0x64, 0x69, 0x6e, 0x67, 0x20, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x73, 0x20, + 0x73, 0x6f, 0x0a, + 0x09, 0x09, 0x2d, 0x2d, 0x20, 0x74, 0x68, 0x65, 0x20, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x20, 0x6d, 0x65, 0x73, + 0x73, 0x61, 0x67, 0x65, 0x20, 0x63, 0x61, 0x6e, 0x20, 0x62, 0x65, 0x20, 0x64, 0x69, 0x73, 0x70, 0x6c, 0x61, + 0x79, 0x65, 0x64, 0x20, 0x69, 0x6e, 0x20, 0x74, 0x68, 0x65, 0x20, 0x77, 0x69, 0x6e, 0x64, 0x6f, 0x77, 0x2e, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x61, 0x72, 0x67, 0x2e, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x63, 0x6f, 0x6e, 0x73, 0x6f, 0x6c, 0x65, 0x2e, 0x73, 0x65, 0x74, 0x20, 0x74, 0x68, 0x65, @@ -666,6 +672,10 @@ const unsigned char boot_lua[] = 0x09, 0x09, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x68, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x73, 0x28, 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, + 0x09, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x63, 0x6f, 0x6e, 0x66, 0x6f, 0x6b, 0x20, 0x61, 0x6e, 0x64, + 0x20, 0x63, 0x6f, 0x6e, 0x66, 0x65, 0x72, 0x72, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, + 0x09, 0x09, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x28, 0x63, 0x6f, 0x6e, 0x66, 0x65, 0x72, 0x72, 0x29, 0x0a, + 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x2d, 0x2d, 0x20, 0x53, 0x65, 0x74, 0x75, 0x70, 0x20, 0x77, 0x69, 0x6e, 0x64, 0x6f, 0x77, 0x20, 0x68, 0x65, 0x72, 0x65, 0x2e, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x63, 0x2e, 0x77, 0x69, 0x6e, 0x64, 0x6f, 0x77, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x63, @@ -5289,7 +5299,8 @@ const unsigned char boot_lua[] = 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x73, 0x52, 0x47, 0x42, 0x20, 0x3d, 0x20, 0x73, 0x65, 0x6c, 0x65, 0x63, 0x74, 0x28, 0x33, 0x2c, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x77, 0x69, 0x6e, 0x64, 0x6f, 0x77, 0x2e, 0x67, 0x65, 0x74, 0x4d, 0x6f, 0x64, 0x65, 0x28, 0x29, 0x29, 0x2e, 0x73, 0x72, 0x67, 0x62, 0x0a, - 0x09, 0x69, 0x66, 0x20, 0x73, 0x52, 0x47, 0x42, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, + 0x09, 0x69, 0x66, 0x20, 0x73, 0x52, 0x47, 0x42, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, + 0x6d, 0x61, 0x74, 0x68, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x67, 0x72, 0x61, 0x70, 0x68, 0x69, 0x63, 0x73, 0x2e, 0x73, 0x65, 0x74, 0x42, 0x61, 0x63, 0x6b, 0x67, 0x72, 0x6f, 0x75, 0x6e, 0x64, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x6d, 0x61, 0x74, 0x68, 0x2e, 0x67, 0x61, 0x6d, 0x6d, 0x61, 0x54, 0x6f, 0x4c, 0x69, From 68b2c9e8516b387150d4ba12fb525e334764c8e5 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Fri, 29 Aug 2014 01:31:16 -0300 Subject: [PATCH 5/5] The default filter mode is now included in the state affected by love.graphics.push("all"). --- src/modules/graphics/opengl/Graphics.cpp | 20 ++++++++++++++++++++ src/modules/graphics/opengl/Graphics.h | 7 +++++++ 2 files changed, 27 insertions(+) diff --git a/src/modules/graphics/opengl/Graphics.cpp b/src/modules/graphics/opengl/Graphics.cpp index 1c1c5b2d9..f44d2b7e6 100644 --- a/src/modules/graphics/opengl/Graphics.cpp +++ b/src/modules/graphics/opengl/Graphics.cpp @@ -101,6 +101,9 @@ void Graphics::restoreState(const DisplayState &s) setColorMask(s.colorMask); setWireframe(s.wireframe); + + setDefaultFilter(s.defaultFilter); + setDefaultMipmapFilter(s.defaultMipmapFilter, s.defaultMipmapSharpness); } void Graphics::restoreStateChecked(const DisplayState &s) @@ -158,6 +161,9 @@ void Graphics::restoreStateChecked(const DisplayState &s) if (s.wireframe != cur.wireframe) setWireframe(s.wireframe); + + setDefaultFilter(s.defaultFilter); + setDefaultMipmapFilter(s.defaultMipmapFilter, s.defaultMipmapSharpness); } void Graphics::setViewportSize(int width, int height) @@ -785,6 +791,7 @@ Graphics::BlendMode Graphics::getBlendMode() const void Graphics::setDefaultFilter(const Texture::Filter &f) { Texture::setDefaultFilter(f); + states.back().defaultFilter = f; } const Texture::Filter &Graphics::getDefaultFilter() const @@ -796,6 +803,9 @@ void Graphics::setDefaultMipmapFilter(Texture::FilterMode filter, float sharpnes { Image::setDefaultMipmapFilter(filter); Image::setDefaultMipmapSharpness(sharpness); + + states.back().defaultMipmapFilter = filter; + states.back().defaultMipmapSharpness = sharpness; } void Graphics::getDefaultMipmapFilter(Texture::FilterMode *filter, float *sharpness) const @@ -1334,6 +1344,9 @@ Graphics::DisplayState::DisplayState() , font(nullptr) , shader(nullptr) , wireframe(false) + , defaultFilter() + , defaultMipmapFilter(Texture::FILTER_NONE) + , defaultMipmapSharpness(0.0f) { // We should just directly initialize the array in the initializer list, but // that feature of C++11 is broken in Visual Studio 2013... @@ -1355,6 +1368,9 @@ Graphics::DisplayState::DisplayState(const DisplayState &other) , shader(other.shader) , canvases(other.canvases) , wireframe(other.wireframe) + , defaultFilter(other.defaultFilter) + , defaultMipmapFilter(other.defaultMipmapFilter) + , defaultMipmapSharpness(other.defaultMipmapSharpness) { for (int i = 0; i < 4; i++) colorMask[i] = other.colorMask[i]; @@ -1386,6 +1402,10 @@ Graphics::DisplayState &Graphics::DisplayState::operator = (const DisplayState & wireframe = other.wireframe; + defaultFilter = other.defaultFilter; + defaultMipmapFilter = other.defaultMipmapFilter; + defaultMipmapSharpness = other.defaultMipmapSharpness; + return *this; } diff --git a/src/modules/graphics/opengl/Graphics.h b/src/modules/graphics/opengl/Graphics.h index e3e24b3f6..647c6ba98 100644 --- a/src/modules/graphics/opengl/Graphics.h +++ b/src/modules/graphics/opengl/Graphics.h @@ -475,6 +475,13 @@ private: bool wireframe; + // Default filter. + Texture::Filter defaultFilter; + + // Default mipmap filter and sharpness. + Texture::FilterMode defaultMipmapFilter; + float defaultMipmapSharpness; + DisplayState(); DisplayState(const DisplayState &other); ~DisplayState();