From 7922c44d275f79369a18d546756e740eface3e4f Mon Sep 17 00:00:00 2001 From: rude Date: Thu, 14 Jul 2016 18:07:20 +0200 Subject: [PATCH 01/15] Make CMake build functional on Linux. At least on Ubuntu. --- CMakeLists.txt | 78 +++++++++++++++++++++++++++++++++-- extra/cmake/FindLuaJIT.cmake | 25 +++++++++++ extra/cmake/FindMPG123.cmake | 25 +++++++++++ extra/cmake/FindModPlug.cmake | 25 +++++++++++ extra/cmake/FindSDL2.cmake | 25 +++++++++++ extra/cmake/FindTheora.cmake | 31 ++++++++++++++ extra/cmake/FindVorbis.cmake | 30 ++++++++++++++ 7 files changed, 236 insertions(+), 3 deletions(-) create mode 100644 extra/cmake/FindLuaJIT.cmake create mode 100644 extra/cmake/FindMPG123.cmake create mode 100644 extra/cmake/FindModPlug.cmake create mode 100644 extra/cmake/FindSDL2.cmake create mode 100644 extra/cmake/FindTheora.cmake create mode 100644 extra/cmake/FindVorbis.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 505ce80b3..d226e6123 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,13 +23,17 @@ if(${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_BINARY_DIR}) message(FATAL_ERROR "Prevented in-tree build.") endif() -cmake_minimum_required(VERSION 2.8) +cmake_minimum_required(VERSION 3.1) project(love) set(LOVE_EXE_NAME love) set(LOVE_LIB_NAME liblove) +set(CMAKE_MODULE_PATH "${love_SOURCE_DIR}/extra/cmake" ${CMAKE_MODULE_PATH}) +# Needed for shared libs on Linux. (-fPIC). +set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) + set (CMAKE_CXX_STANDARD 11) if(MSVC) @@ -157,19 +161,87 @@ if(MEGA) # automatically. endif() else() - message(FATAL_ERROR " + if(MSVC) + message(FATAL_ERROR " It is currently only possible to build with megasource on Windows. Please see http://bitbucket.org/rude/megasource ") + endif() + + find_package(Freetype REQUIRED) + find_package(ModPlug REQUIRED) + find_package(OpenAL REQUIRED) + find_package(OpenGL REQUIRED) + find_package(PhysFS REQUIRED) + find_package(SDL2 REQUIRED) + find_package(Theora REQUIRED) + find_package(Vorbis REQUIRED) + + # required for enet + add_definitions(-D HAS_SOCKLEN_T) + + set(LOVE_INCLUDE_DIRS + ${SDL2_INCLUDE_DIR} + ${PHYSFS_INCLUDE_DIR} + ${FREETYPE_INCLUDE_DIRS} + ${VORBIS_INCLUDE_DIR} + ) + + set(LOVE_LINK_LIBRARIES + ${OPENGL_gl_LIBRARY} + ${SDL2_LIBRARY} + ${FREETYPE_LIBRARY} + ${OPENAL_LIBRARY} + ${MODPLUG_LIBRARY} + ${PHYSFS_LIBRARY} + ${THEORA_LIBRARY} + ${THEORADEC_LIBRARY} + ${VORBISFILE_LIBRARY} + ${LOVE_LUA_LIBRARY} + ) + + if(LOVE_MPG123) + find_package(MPG123 REQUIRED) + set(LOVE_LINK_LIBRARIES + ${LOVE_LINK_LIBRARIES} + ${MPG123_LIBRARY} + ) + endif() + + if(LOVE_JIT) + find_package(LuaJIT REQUIRED) + set(LOVE_LUA_LIBRARY ${LUAJIT_LIBRARY}) + set(LOVE_LUA_INCLUDE_DIR ${LUAJIT_INCLUDE_DIR}) + else() + find_package(Lua51 REQUIRED) + set(LOVE_LUA_LIBRARY ${LUA_LIBRARY}) + set(LOVE_LUA_INCLUDE_DIR ${LUA_INCLUDE_DIR}) + endif() + + set(LOVE_INCLUDE_DIRS + ${LOVE_INCLUDE_DIRS} + ${LOVE_LUA_INCLUDE_DIR} + ) + set(LOVE_LINK_LIBRARIES + ${LOVE_LINK_LIBRARIES} + ${LOVE_LUA_LIBRARY} + ) + endif() ### ### No Megasource-specific stuff beyond this point! ### +if(MSVC) + set(DISABLE_WARNING_FLAG -W0) +else() + set(DISABLE_WARNING_FLAG -w) +endif() + function(disable_warnings ARG_TARGET) get_target_property(OLD_FLAGS ${ARG_TARGET} COMPILE_FLAGS) - set(NEW_FLAGS -W0) + set(NEW_FLAGS ${DISABLE_WARNING_FLAG}) if(OLD_FLAGS) set(NEW_FLAGS "${OLD_FLAGS} ${NEW_FLAGS}") endif() diff --git a/extra/cmake/FindLuaJIT.cmake b/extra/cmake/FindLuaJIT.cmake new file mode 100644 index 000000000..a48410195 --- /dev/null +++ b/extra/cmake/FindLuaJIT.cmake @@ -0,0 +1,25 @@ +# Sets the following variables: +# +# LUAJIT_FOUND +# LUAJIT_INCLUDE_DIR +# LUAJIT_LIBRARY + +set(LUAJIT_SEARCH_PATHS + /usr/local + /usr + ) + +find_path(LUAJIT_INCLUDE_DIR + NAMES luajit.h + PATH_SUFFIXES include include/luajit-2.0 + PATHS ${LUAJIT_SEARCH_PATHS}) + +find_library(LUAJIT_LIBRARY + NAMES luajit-5.1 + PATH_SUFFIXES lib + PATHS ${LUAJIT_SEARCH_PATHS}) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(LuaJIT DEFAULT_MSG LUAJIT_LIBRARY LUAJIT_INCLUDE_DIR) + +mark_as_advanced(LUAJIT_INCLUDE_DIR LUAJIT_LIBRARY) diff --git a/extra/cmake/FindMPG123.cmake b/extra/cmake/FindMPG123.cmake new file mode 100644 index 000000000..6cda993b2 --- /dev/null +++ b/extra/cmake/FindMPG123.cmake @@ -0,0 +1,25 @@ +# Sets the following variables: +# +# MPG123_FOUND +# MPG123_INCLUDE_DIR +# MPG123_LIBRARY + +set(MPG123_SEARCH_PATHS + /usr/local + /usr + ) + +find_path(MPG123_INCLUDE_DIR + NAMES mpg123.h + PATH_SUFFIXES include + PATHS ${MPG123_SEARCH_PATHS}) + +find_library(MPG123_LIBRARY + NAMES mpg123 + PATH_SUFFIXES lib + PATHS ${MPG123_SEARCH_PATHS}) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(MPG123 DEFAULT_MSG MPG123_LIBRARY MPG123_INCLUDE_DIR) + +mark_as_advanced(MPG123_INCLUDE_DIR MPG123_LIBRARY) diff --git a/extra/cmake/FindModPlug.cmake b/extra/cmake/FindModPlug.cmake new file mode 100644 index 000000000..16641d3be --- /dev/null +++ b/extra/cmake/FindModPlug.cmake @@ -0,0 +1,25 @@ +# Sets the following variables: +# +# MODPLUG_FOUND +# MODPLUG_INCLUDE_DIR +# MODPLUG_LIBRARY + +set(MODPLUG_SEARCH_PATHS + /usr/local + /usr + ) + +find_path(MODPLUG_INCLUDE_DIR + NAMES libmodplug/modplug.h + PATH_SUFFIXES include + PATHS ${MODPLUG_SEARCH_PATHS}) + +find_library(MODPLUG_LIBRARY + NAMES modplug + PATH_SUFFIXES lib + PATHS ${MODPLUG_SEARCH_PATHS}) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(ModPlug DEFAULT_MSG MODPLUG_LIBRARY MODPLUG_INCLUDE_DIR) + +mark_as_advanced(MODPLUG_INCLUDE_DIR MODPLUG_LIBRARY) diff --git a/extra/cmake/FindSDL2.cmake b/extra/cmake/FindSDL2.cmake new file mode 100644 index 000000000..81de07ffd --- /dev/null +++ b/extra/cmake/FindSDL2.cmake @@ -0,0 +1,25 @@ +# Sets the following variables: +# +# SDL2_FOUND +# SDL2_INCLUDE_DIR +# SDL2_LIBRARY + +set(SDL2_SEARCH_PATHS + /usr/local + /usr + ) + +find_path(SDL2_INCLUDE_DIR + NAMES SDL.h + PATH_SUFFIXES include include/SDL2 + PATHS ${SDL2_SEARCH_PATHS}) + +find_library(SDL2_LIBRARY + NAMES SDL2 + PATH_SUFFIXES lib + PATHS ${SDL2_SEARCH_PATHS}) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(SDL2 DEFAULT_MSG SDL2_LIBRARY SDL2_INCLUDE_DIR) + +mark_as_advanced(SDL2_INCLUDE_DIR SDL2_LIBRARY) diff --git a/extra/cmake/FindTheora.cmake b/extra/cmake/FindTheora.cmake new file mode 100644 index 000000000..4a3804a5b --- /dev/null +++ b/extra/cmake/FindTheora.cmake @@ -0,0 +1,31 @@ +# Sets the following variables: +# +# THEORA_FOUND +# THEORA_INCLUDE_DIR +# THEORA_LIBRARY +# THEORADEC_LIBRARY + +set(THEORA_SEARCH_PATHS + /usr/local + /usr + ) + +find_path(THEORA_INCLUDE_DIR + NAMES theora/codec.h + PATH_SUFFIXES include + PATHS ${THEORA_SEARCH_PATHS}) + +find_library(THEORA_LIBRARY + NAMES theora + PATH_SUFFIXES lib + PATHS ${THEORA_SEARCH_PATHS}) + +find_library(THEORADEC_LIBRARY + NAMES theoradec + PATH_SUFFIXES lib + PATHS ${THEORA_SEARCH_PATHS}) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Theora DEFAULT_MSG THEORA_LIBRARY THEORA_INCLUDE_DIR) + +mark_as_advanced(THEORA_INCLUDE_DIR THEORA_LIBRARY) diff --git a/extra/cmake/FindVorbis.cmake b/extra/cmake/FindVorbis.cmake new file mode 100644 index 000000000..6a263a4c8 --- /dev/null +++ b/extra/cmake/FindVorbis.cmake @@ -0,0 +1,30 @@ +# Sets the following variables: +# +# VORBIS_FOUND +# VORBIS_INCLUDE_DIR +# VORBIS_LIBRARY +# VORBISFILE_LIBRARY + +set(VORBIS_SEARCH_PATHS + /usr/local + /usr + ) + +find_path(VORBIS_INCLUDE_DIR vorbis/vorbisfile.h + PATH_SUFFIXES include + PATHS ${VORBIS_SEARCH_PATHS}) + +find_library(VORBIS_LIBRARY + NAMES vorbis + PATH_SUFFIXES lib + PATHS ${VORBIS_SEARCH_PATHS}) + +find_library(VORBISFILE_LIBRARY + NAMES vorbisfile + PATH_SUFFIXES lib + PATHS ${VORBIS_SEARCH_PATHS}) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Vorbis DEFAULT_MSG VORBIS_LIBRARY VORBISFILE_LIBRARY VORBIS_INCLUDE_DIR) + +mark_as_advanced(VORBIS_INCLUDE_DIR VORBIS_LIBRARY VORBISFILE_LIBRARY) From 877ebbf9c94f5faf37521d12b882b042068c4eaf Mon Sep 17 00:00:00 2001 From: Bart van Strien Date: Fri, 15 Jul 2016 12:20:58 +0200 Subject: [PATCH 02/15] Make WheelJoint/PrismaticJoint:getAxis return a world vector (refs #1176) --- src/modules/physics/box2d/PrismaticJoint.cpp | 6 ++++-- src/modules/physics/box2d/WheelJoint.cpp | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/modules/physics/box2d/PrismaticJoint.cpp b/src/modules/physics/box2d/PrismaticJoint.cpp index 69f182074..e390405e8 100644 --- a/src/modules/physics/box2d/PrismaticJoint.cpp +++ b/src/modules/physics/box2d/PrismaticJoint.cpp @@ -140,8 +140,10 @@ int PrismaticJoint::getLimits(lua_State *L) int PrismaticJoint::getAxis(lua_State *L) { - lua_pushnumber(L, joint->GetLocalAxisA().x); - lua_pushnumber(L, joint->GetLocalAxisA().y); + b2Vec2 axis = joint->GetLocalAxisA(); + getBodyA()->getWorldVector(axis.x, axis.y, axis.x, axis.y); + lua_pushnumber(L, axis.x); + lua_pushnumber(L, axis.y); return 2; } diff --git a/src/modules/physics/box2d/WheelJoint.cpp b/src/modules/physics/box2d/WheelJoint.cpp index bd066c157..2670878cd 100644 --- a/src/modules/physics/box2d/WheelJoint.cpp +++ b/src/modules/physics/box2d/WheelJoint.cpp @@ -115,8 +115,10 @@ float WheelJoint::getSpringDampingRatio() const int WheelJoint::getAxis(lua_State *L) { - lua_pushnumber(L, joint->GetLocalAxisA().x); - lua_pushnumber(L, joint->GetLocalAxisA().y); + b2Vec2 axis = joint->GetLocalAxisA(); + getBodyA()->getWorldVector(axis.x, axis.y, axis.x, axis.y); + lua_pushnumber(L, axis.x); + lua_pushnumber(L, axis.y); return 2; } From 8ea1edbc2a6d3eb56db35151d15c62abdb580f9f Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Sun, 17 Jul 2016 17:44:38 -0300 Subject: [PATCH 03/15] Cause a Lua error instead of silently failing if a vertex buffer memory allocation fails. --- src/modules/graphics/opengl/GLBuffer.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/modules/graphics/opengl/GLBuffer.cpp b/src/modules/graphics/opengl/GLBuffer.cpp index 6658e8fdd..4cee2f34a 100644 --- a/src/modules/graphics/opengl/GLBuffer.cpp +++ b/src/modules/graphics/opengl/GLBuffer.cpp @@ -58,12 +58,10 @@ GLBuffer::GLBuffer(size_t size, const void *data, GLenum target, GLenum usage, u if (data != nullptr) memcpy(memory_map, data, size); - bool ok = load(data != nullptr); - - if (!ok) + if (!load(data != nullptr)) { delete[] memory_map; - throw love::Exception("Could not load VBO."); + throw love::Exception("Could not load vertex buffer (out of VRAM?)"); } } @@ -221,13 +219,16 @@ bool GLBuffer::load(bool restore) GLBuffer::Bind bind(*this); + while (glGetError() != GL_NO_ERROR) + /* Clear the error buffer. */; + // Copy the old buffer only if 'restore' was requested. const GLvoid *src = restore ? memory_map : nullptr; // Note that if 'src' is '0', no data will be copied. glBufferData(getTarget(), (GLsizeiptr) getSize(), src, getUsage()); - return true; + return (glGetError() == GL_NO_ERROR); } void GLBuffer::unload() From d2c2c717e4979dbfc36f6d746e801012b69e71be Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Wed, 20 Jul 2016 19:36:43 -0300 Subject: [PATCH 04/15] =?UTF-8?q?Mac:=20treat=20folders=20with=20the=20.lo?= =?UTF-8?q?ve=20extension=20as=20packages=20that=20can=20be=20double-click?= =?UTF-8?q?ed=20to=20open=20with=20L=C3=96VE=20(resolves=20issue=20#1186).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platform/xcode/macosx/love-macosx.plist | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/platform/xcode/macosx/love-macosx.plist b/platform/xcode/macosx/love-macosx.plist index 191bbf1ab..8cf99c4a7 100644 --- a/platform/xcode/macosx/love-macosx.plist +++ b/platform/xcode/macosx/love-macosx.plist @@ -7,6 +7,10 @@ CFBundleDocumentTypes + CFBundleTypeExtensions + + love + CFBundleTypeIconFile GameIcon CFBundleTypeName @@ -19,6 +23,8 @@ org.love2d.love-game + LSTypeIsPackage + 1 CFBundleTypeName @@ -73,6 +79,7 @@ UTTypeConformsTo com.pkware.zip-archive + com.apple.package UTTypeDescription LÖVE Project From a11c7278c8134032194eeb355f7610551809ad50 Mon Sep 17 00:00:00 2001 From: Leonardo Etcheverry Date: Wed, 20 Jul 2016 21:52:56 -0300 Subject: [PATCH 05/15] Fix FT_Get_Kerning using char codes instead of glyph indices. --- src/modules/font/freetype/TrueTypeRasterizer.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/modules/font/freetype/TrueTypeRasterizer.cpp b/src/modules/font/freetype/TrueTypeRasterizer.cpp index 8fea1b645..1c67ef00f 100644 --- a/src/modules/font/freetype/TrueTypeRasterizer.cpp +++ b/src/modules/font/freetype/TrueTypeRasterizer.cpp @@ -168,7 +168,11 @@ bool TrueTypeRasterizer::hasGlyph(uint32 glyph) const float TrueTypeRasterizer::getKerning(uint32 leftglyph, uint32 rightglyph) const { FT_Vector kerning = {}; - FT_Get_Kerning(face, leftglyph, rightglyph, FT_KERNING_DEFAULT, &kerning); + FT_Get_Kerning(face, + FT_Get_Char_Index(face, leftglyph), + FT_Get_Char_Index(face, rightglyph), + FT_KERNING_DEFAULT, + &kerning); return float(kerning.x >> 6); } From f4999bd2c7d3860e6cc872ca7965001c482e1158 Mon Sep 17 00:00:00 2001 From: Bart van Strien Date: Thu, 28 Jul 2016 17:15:52 +0200 Subject: [PATCH 06/15] Fail gracefully when auto.lua is called on a file not in src/scripts --- src/scripts/auto.lua | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/scripts/auto.lua b/src/scripts/auto.lua index 351ced94d..d4fb77bec 100644 --- a/src/scripts/auto.lua +++ b/src/scripts/auto.lua @@ -108,8 +108,14 @@ end for i, v in ipairs(arg) do --run the auto function for every argument --but do it with pcall, to catch errors - v = v:gsub("%.lua$", ""):gsub("^(.+)/", "") -- normalize input - local ok, err = pcall(auto, v) + local ok, err = true + v = v:gsub("^scripts/", "") + if v:match("/") then + ok, err = false, "not in scripts directory" + else + v = v:gsub("%.lua$", "") -- normalize input + ok, err = pcall(auto, v) + end if not ok then --inform people we've failed print(v .. ": " .. err) From 0a534d47511c9a8f669c74300d6a8f395571d73b Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Thu, 28 Jul 2016 18:08:27 -0300 Subject: [PATCH 07/15] Fixed ChainShape:setPreviousVertex. --- src/modules/physics/box2d/ChainShape.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/physics/box2d/ChainShape.cpp b/src/modules/physics/box2d/ChainShape.cpp index d55e3920d..273d0ac1d 100644 --- a/src/modules/physics/box2d/ChainShape.cpp +++ b/src/modules/physics/box2d/ChainShape.cpp @@ -64,7 +64,7 @@ void ChainShape::setPreviousVertex(float x, float y) } b2Vec2 v(x, y); b2ChainShape *c = (b2ChainShape *)shape; - c->SetNextVertex(Physics::scaleDown(v)); + c->SetPrevVertex(Physics::scaleDown(v)); } EdgeShape *ChainShape::getChildEdge(int index) const From 55cb2fad84f15b830338ea6ebee354760c84994d Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Sun, 31 Jul 2016 11:51:53 -0300 Subject: [PATCH 08/15] Fixture:setCategory and Fixture:setMask now accept a table of categories/masks (resolves issue #1178). --- src/modules/physics/box2d/Fixture.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/modules/physics/box2d/Fixture.cpp b/src/modules/physics/box2d/Fixture.cpp index 49689a4be..d56c5a8ef 100644 --- a/src/modules/physics/box2d/Fixture.cpp +++ b/src/modules/physics/box2d/Fixture.cpp @@ -193,16 +193,28 @@ int Fixture::getMask(lua_State *L) uint16 Fixture::getBits(lua_State *L) { // Get number of args. - int argc = lua_gettop(L); + bool istable = lua_istable(L, 1); + int argc = istable ? (int) luax_objlen(L, 1) : lua_gettop(L); // The new bitset. std::bitset<16> b; - for (int i = 1; i<=argc; i++) + for (int i = 1; i <= argc; i++) { - size_t bpos = (size_t)(lua_tointeger(L, i)-1); + size_t bpos = 0; + + if (istable) + { + lua_rawgeti(L, 1, i); + bpos = (size_t) (lua_tointeger(L, -1) - 1); + lua_pop(L, 1); + } + else + bpos = (size_t) (lua_tointeger(L, i) - 1); + if (bpos >= 16) luaL_error(L, "Values must be in range 1-16."); + b.set(bpos, true); } From 3157e5df7bd2ec1dffe198d3ab041cda009c24ab Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Sun, 31 Jul 2016 14:25:12 -0300 Subject: [PATCH 09/15] Added ChainShape:getNext/PreviousVertex (see issue #1191). Thanks airstruck! --- src/modules/physics/box2d/ChainShape.cpp | 26 ++++++++++++++++ src/modules/physics/box2d/ChainShape.h | 24 +++++++++++++++ src/modules/physics/box2d/wrap_ChainShape.cpp | 30 +++++++++++++++++++ 3 files changed, 80 insertions(+) diff --git a/src/modules/physics/box2d/ChainShape.cpp b/src/modules/physics/box2d/ChainShape.cpp index 273d0ac1d..1521df558 100644 --- a/src/modules/physics/box2d/ChainShape.cpp +++ b/src/modules/physics/box2d/ChainShape.cpp @@ -67,6 +67,32 @@ void ChainShape::setPreviousVertex(float x, float y) c->SetPrevVertex(Physics::scaleDown(v)); } +bool ChainShape::hasNextVertex() const +{ + b2ChainShape *c = (b2ChainShape *)shape; + return c->m_hasNextVertex; +} + +bool ChainShape::hasPreviousVertex() const +{ + b2ChainShape *c = (b2ChainShape *)shape; + return c->m_hasPrevVertex; +} + +b2Vec2 ChainShape::getNextVertex() const +{ + b2ChainShape *c = (b2ChainShape *)shape; + const b2Vec2 &v = c->m_nextVertex; + return Physics::scaleUp(v); +} + +b2Vec2 ChainShape::getPreviousVertex() const +{ + b2ChainShape *c = (b2ChainShape *)shape; + const b2Vec2 &v = c->m_prevVertex; + return Physics::scaleUp(v); +} + EdgeShape *ChainShape::getChildEdge(int index) const { b2ChainShape *c = (b2ChainShape *)shape; diff --git a/src/modules/physics/box2d/ChainShape.h b/src/modules/physics/box2d/ChainShape.h index 9f53ca958..52598686c 100644 --- a/src/modules/physics/box2d/ChainShape.h +++ b/src/modules/physics/box2d/ChainShape.h @@ -63,6 +63,30 @@ public: **/ void setPreviousVertex(float x, float y); + /** + * Returns whether a vertex that follows the last vertex exists. + * @returns True if specified vertex exists, else false. + **/ + bool hasNextVertex() const; + + /** + * Returns whether a vertex that precedes the first vertex exists. + * @returns True if specified vertex exists, else false. + **/ + bool hasPreviousVertex() const; + + /** + * Returns the vertex that follows the last vertex. + * @returns The specified vertex. + **/ + b2Vec2 getNextVertex() const; + + /** + * Returns the vertex that precedes the first vertex. + * @returns The specified vertex. + **/ + b2Vec2 getPreviousVertex() const; + /** * Returns a child EdgeShape. * @param index The index of the child shape. diff --git a/src/modules/physics/box2d/wrap_ChainShape.cpp b/src/modules/physics/box2d/wrap_ChainShape.cpp index 8cf7d8f85..42875059e 100644 --- a/src/modules/physics/box2d/wrap_ChainShape.cpp +++ b/src/modules/physics/box2d/wrap_ChainShape.cpp @@ -82,6 +82,34 @@ int w_ChainShape_getPoint(lua_State *L) return 2; } +int w_ChainShape_getNextVertex(lua_State *L) +{ + ChainShape *c = luax_checkchainshape(L, 1); + if (c->hasNextVertex()) + { + b2Vec2 v; + luax_catchexcept(L, [&](){ v = c->getNextVertex(); }); + lua_pushnumber(L, v.x); + lua_pushnumber(L, v.y); + return 2; + } + return 0; +} + +int w_ChainShape_getPreviousVertex(lua_State *L) +{ + ChainShape *c = luax_checkchainshape(L, 1); + if (c->hasPreviousVertex()) + { + b2Vec2 v; + luax_catchexcept(L, [&](){ v = c->getPreviousVertex(); }); + lua_pushnumber(L, v.x); + lua_pushnumber(L, v.y); + return 2; + } + return 0; +} + int w_ChainShape_getPoints(lua_State *L) { ChainShape *c = luax_checkchainshape(L, 1); @@ -102,6 +130,8 @@ static const luaL_Reg w_ChainShape_functions[] = { { "setNextVertex", w_ChainShape_setNextVertex }, { "setPreviousVertex", w_ChainShape_setPreviousVertex }, + { "getNextVertex", w_ChainShape_getNextVertex }, + { "getPreviousVertex", w_ChainShape_getPreviousVertex }, { "getChildEdge", w_ChainShape_getChildEdge }, { "getVertexCount", w_ChainShape_getVertexCount }, { "getPoint", w_ChainShape_getPoint }, From 2e8f785a01f0039ceb61bd527d9381542a22e4e6 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Sun, 31 Jul 2016 14:40:55 -0300 Subject: [PATCH 10/15] Potentially fix building with megasource on Windows --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d226e6123..7ea4cc8c7 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -239,7 +239,7 @@ else() set(DISABLE_WARNING_FLAG -w) endif() -function(disable_warnings ARG_TARGET) +function(love_disable_warnings ARG_TARGET) get_target_property(OLD_FLAGS ${ARG_TARGET} COMPILE_FLAGS) set(NEW_FLAGS ${DISABLE_WARNING_FLAG}) if(OLD_FLAGS) @@ -1398,7 +1398,7 @@ set(LOVE_3P love_3p_wuff ) -disable_warnings(love_3p_box2d love_3p_enet love_3p_luasocket) +love_disable_warnings(love_3p_box2d love_3p_enet love_3p_luasocket) # # liblove From fc2c79ad5f45ec6fa20a24258150c1f7aff5cd6f Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Mon, 1 Aug 2016 10:15:34 -0300 Subject: [PATCH 11/15] Add EdgeShape:set/getNext/PreviousVertex. ChainShape:setNext/PreviousVertex can now take no arguments to disable ghost vertices. Resolves issue #1191. --- src/modules/physics/box2d/ChainShape.cpp | 42 +++++++++----- src/modules/physics/box2d/ChainShape.h | 24 ++------ src/modules/physics/box2d/EdgeShape.cpp | 58 +++++++++++++++++++ src/modules/physics/box2d/EdgeShape.h | 8 +++ src/modules/physics/box2d/wrap_ChainShape.cpp | 40 ++++++++----- src/modules/physics/box2d/wrap_EdgeShape.cpp | 58 +++++++++++++++++++ 6 files changed, 183 insertions(+), 47 deletions(-) diff --git a/src/modules/physics/box2d/ChainShape.cpp b/src/modules/physics/box2d/ChainShape.cpp index 1521df558..1b77d0cc8 100644 --- a/src/modules/physics/box2d/ChainShape.cpp +++ b/src/modules/physics/box2d/ChainShape.cpp @@ -55,6 +55,12 @@ void ChainShape::setNextVertex(float x, float y) c->SetNextVertex(Physics::scaleDown(v)); } +void ChainShape::setNextVertex() +{ + b2ChainShape *c = (b2ChainShape *)shape; + c->m_hasNextVertex = false; +} + void ChainShape::setPreviousVertex(float x, float y) { if (loop) @@ -67,30 +73,40 @@ void ChainShape::setPreviousVertex(float x, float y) c->SetPrevVertex(Physics::scaleDown(v)); } -bool ChainShape::hasNextVertex() const +void ChainShape::setPreviousVertex() { b2ChainShape *c = (b2ChainShape *)shape; - return c->m_hasNextVertex; + c->m_hasPrevVertex = false; } -bool ChainShape::hasPreviousVertex() const +bool ChainShape::getNextVertex(float &x, float &y) const { b2ChainShape *c = (b2ChainShape *)shape; - return c->m_hasPrevVertex; + + if (c->m_hasNextVertex) + { + b2Vec2 v = Physics::scaleUp(c->m_nextVertex); + x = v.x; + y = v.y; + return true; + } + + return false; } -b2Vec2 ChainShape::getNextVertex() const +bool ChainShape::getPreviousVertex(float &x, float &y) const { b2ChainShape *c = (b2ChainShape *)shape; - const b2Vec2 &v = c->m_nextVertex; - return Physics::scaleUp(v); -} -b2Vec2 ChainShape::getPreviousVertex() const -{ - b2ChainShape *c = (b2ChainShape *)shape; - const b2Vec2 &v = c->m_prevVertex; - return Physics::scaleUp(v); + if (c->m_hasPrevVertex) + { + b2Vec2 v = Physics::scaleUp(c->m_prevVertex); + x = v.x; + y = v.y; + return true; + } + + return false; } EdgeShape *ChainShape::getChildEdge(int index) const diff --git a/src/modules/physics/box2d/ChainShape.h b/src/modules/physics/box2d/ChainShape.h index 52598686c..8b7a18f2f 100644 --- a/src/modules/physics/box2d/ChainShape.h +++ b/src/modules/physics/box2d/ChainShape.h @@ -54,6 +54,7 @@ public: * @param y The y-coordinate of the vertex. **/ void setNextVertex(float x, float y); + void setNextVertex(); /** * Establish connectivity to a vertex that precedes @@ -62,30 +63,17 @@ public: * @param y The y-coordinate of the vertex. **/ void setPreviousVertex(float x, float y); + void setPreviousVertex(); /** - * Returns whether a vertex that follows the last vertex exists. - * @returns True if specified vertex exists, else false. + * Gets the vertex that follows the last vertex. **/ - bool hasNextVertex() const; + bool getNextVertex(float &x, float &y) const; /** - * Returns whether a vertex that precedes the first vertex exists. - * @returns True if specified vertex exists, else false. + * Gets the vertex that precedes the first vertex. **/ - bool hasPreviousVertex() const; - - /** - * Returns the vertex that follows the last vertex. - * @returns The specified vertex. - **/ - b2Vec2 getNextVertex() const; - - /** - * Returns the vertex that precedes the first vertex. - * @returns The specified vertex. - **/ - b2Vec2 getPreviousVertex() const; + bool getPreviousVertex(float &x, float &y) const; /** * Returns a child EdgeShape. diff --git a/src/modules/physics/box2d/EdgeShape.cpp b/src/modules/physics/box2d/EdgeShape.cpp index 47f427c9a..8189b1318 100644 --- a/src/modules/physics/box2d/EdgeShape.cpp +++ b/src/modules/physics/box2d/EdgeShape.cpp @@ -43,6 +43,64 @@ EdgeShape::~EdgeShape() { } +void EdgeShape::setNextVertex(float x, float y) +{ + b2EdgeShape *e = (b2EdgeShape *)shape; + b2Vec2 v(x, y); + e->m_vertex3 = Physics::scaleDown(v); + e->m_hasVertex3 = true; +} + +void EdgeShape::setNextVertex() +{ + b2EdgeShape *e = (b2EdgeShape *)shape; + e->m_hasVertex3 = false; +} + +bool EdgeShape::getNextVertex(float &x, float &y) const +{ + b2EdgeShape *e = (b2EdgeShape *)shape; + + if (e->m_hasVertex3) + { + b2Vec2 v = Physics::scaleUp(e->m_vertex3); + x = v.x; + y = v.y; + return true; + } + + return false; +} + +void EdgeShape::setPreviousVertex(float x, float y) +{ + b2EdgeShape *e = (b2EdgeShape *)shape; + b2Vec2 v(x, y); + e->m_vertex0 = Physics::scaleDown(v); + e->m_hasVertex0 = true; +} + +void EdgeShape::setPreviousVertex() +{ + b2EdgeShape *e = (b2EdgeShape *)shape; + e->m_hasVertex0 = false; +} + +bool EdgeShape::getPreviousVertex(float &x, float &y) const +{ + b2EdgeShape *e = (b2EdgeShape *)shape; + + if (e->m_hasVertex0) + { + b2Vec2 v = Physics::scaleUp(e->m_vertex0); + x = v.x; + y = v.y; + return true; + } + + return false; +} + int EdgeShape::getPoints(lua_State *L) { b2EdgeShape *e = (b2EdgeShape *)shape; diff --git a/src/modules/physics/box2d/EdgeShape.h b/src/modules/physics/box2d/EdgeShape.h index 86fd4e831..3e5184a22 100644 --- a/src/modules/physics/box2d/EdgeShape.h +++ b/src/modules/physics/box2d/EdgeShape.h @@ -47,6 +47,14 @@ public: virtual ~EdgeShape(); + void setNextVertex(float x, float y); + void setNextVertex(); + bool getNextVertex(float &x, float &y) const; + + void setPreviousVertex(float x, float y); + void setPreviousVertex(); + bool getPreviousVertex(float &x, float &y) const; + /** * Returns the transformed points of the edge shape. * This function is useful for debug drawing and such. diff --git a/src/modules/physics/box2d/wrap_ChainShape.cpp b/src/modules/physics/box2d/wrap_ChainShape.cpp index 42875059e..a68e66772 100644 --- a/src/modules/physics/box2d/wrap_ChainShape.cpp +++ b/src/modules/physics/box2d/wrap_ChainShape.cpp @@ -37,18 +37,28 @@ ChainShape *luax_checkchainshape(lua_State *L, int idx) int w_ChainShape_setNextVertex(lua_State *L) { ChainShape *c = luax_checkchainshape(L, 1); - float x = (float)luaL_checknumber(L, 2); - float y = (float)luaL_checknumber(L, 3); - luax_catchexcept(L, [&](){ c->setNextVertex(x, y); }); + if (lua_isnoneornil(L, 2)) + c->setNextVertex(); + else + { + float x = (float)luaL_checknumber(L, 2); + float y = (float)luaL_checknumber(L, 3); + luax_catchexcept(L, [&](){ c->setNextVertex(x, y); }); + } return 0; } int w_ChainShape_setPreviousVertex(lua_State *L) { ChainShape *c = luax_checkchainshape(L, 1); - float x = (float)luaL_checknumber(L, 2); - float y = (float)luaL_checknumber(L, 3); - luax_catchexcept(L, [&](){ c->setPreviousVertex(x, y); }); + if (lua_isnoneornil(L, 2)) + c->setPreviousVertex(); + else + { + float x = (float)luaL_checknumber(L, 2); + float y = (float)luaL_checknumber(L, 3); + luax_catchexcept(L, [&](){ c->setPreviousVertex(x, y); }); + } return 0; } @@ -85,12 +95,11 @@ int w_ChainShape_getPoint(lua_State *L) int w_ChainShape_getNextVertex(lua_State *L) { ChainShape *c = luax_checkchainshape(L, 1); - if (c->hasNextVertex()) + float x, y; + if (c->getNextVertex(x, y)) { - b2Vec2 v; - luax_catchexcept(L, [&](){ v = c->getNextVertex(); }); - lua_pushnumber(L, v.x); - lua_pushnumber(L, v.y); + lua_pushnumber(L, x); + lua_pushnumber(L, y); return 2; } return 0; @@ -99,12 +108,11 @@ int w_ChainShape_getNextVertex(lua_State *L) int w_ChainShape_getPreviousVertex(lua_State *L) { ChainShape *c = luax_checkchainshape(L, 1); - if (c->hasPreviousVertex()) + float x, y; + if (c->getPreviousVertex(x, y)) { - b2Vec2 v; - luax_catchexcept(L, [&](){ v = c->getPreviousVertex(); }); - lua_pushnumber(L, v.x); - lua_pushnumber(L, v.y); + lua_pushnumber(L, x); + lua_pushnumber(L, y); return 2; } return 0; diff --git a/src/modules/physics/box2d/wrap_EdgeShape.cpp b/src/modules/physics/box2d/wrap_EdgeShape.cpp index 4dfceb324..53c8805ce 100644 --- a/src/modules/physics/box2d/wrap_EdgeShape.cpp +++ b/src/modules/physics/box2d/wrap_EdgeShape.cpp @@ -32,6 +32,60 @@ EdgeShape *luax_checkedgeshape(lua_State *L, int idx) return luax_checktype(L, idx, PHYSICS_EDGE_SHAPE_ID); } +int w_EdgeShape_setNextVertex(lua_State *L) +{ + EdgeShape *t = luax_checkedgeshape(L, 1); + if (lua_isnoneornil(L, 2)) + t->setNextVertex(); + else + { + float x = (float)luaL_checknumber(L, 2); + float y = (float)luaL_checknumber(L, 3); + t->setNextVertex(x, y); + } + return 0; +} + +int w_EdgeShape_setPreviousVertex(lua_State *L) +{ + EdgeShape *t = luax_checkedgeshape(L, 1); + if (lua_isnoneornil(L, 2)) + t->setPreviousVertex(); + else + { + float x = (float)luaL_checknumber(L, 2); + float y = (float)luaL_checknumber(L, 3); + t->setPreviousVertex(x, y); + } + return 0; +} + +int w_EdgeShape_getNextVertex(lua_State *L) +{ + EdgeShape *t = luax_checkedgeshape(L, 1); + float x, y; + if (t->getNextVertex(x, y)) + { + lua_pushnumber(L, x); + lua_pushnumber(L, y); + return 2; + } + return 0; +} + +int w_EdgeShape_getPreviousVertex(lua_State *L) +{ + EdgeShape *t = luax_checkedgeshape(L, 1); + float x, y; + if (t->getPreviousVertex(x, y)) + { + lua_pushnumber(L, x); + lua_pushnumber(L, y); + return 2; + } + return 0; +} + int w_EdgeShape_getPoints(lua_State *L) { EdgeShape *t = luax_checkedgeshape(L, 1); @@ -41,6 +95,10 @@ int w_EdgeShape_getPoints(lua_State *L) static const luaL_Reg w_EdgeShape_functions[] = { + { "setNextVertex", w_EdgeShape_setNextVertex }, + { "setPreviousVertex", w_EdgeShape_setPreviousVertex }, + { "getNextVertex", w_EdgeShape_getNextVertex }, + { "getPreviousVertex", w_EdgeShape_getPreviousVertex }, { "getPoints", w_EdgeShape_getPoints }, { 0, 0 } }; From 0ce44e465dad292d41f9746d9c10d6fce79d322b Mon Sep 17 00:00:00 2001 From: Bart van Strien Date: Tue, 2 Aug 2016 13:07:05 +0200 Subject: [PATCH 12/15] Catch possible Box2D exception in Fixture:getBoundingBox() (fixes #1196) --- src/modules/physics/box2d/Fixture.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/modules/physics/box2d/Fixture.cpp b/src/modules/physics/box2d/Fixture.cpp index d56c5a8ef..7f0b31e28 100644 --- a/src/modules/physics/box2d/Fixture.cpp +++ b/src/modules/physics/box2d/Fixture.cpp @@ -284,7 +284,8 @@ int Fixture::rayCast(lua_State *L) const int Fixture::getBoundingBox(lua_State *L) const { int childIndex = (int) luaL_optnumber(L, 1, 1) - 1; // Convert from 1-based index - b2AABB box = fixture->GetAABB(childIndex); + b2AABB box; + luax_catchexcept(L, [&]() { box = fixture->GetAABB(childIndex); }); box = Physics::scaleUp(box); lua_pushnumber(L, box.lowerBound.x); lua_pushnumber(L, box.lowerBound.y); From 57e4ec78e3192aa586f388c50923451b2e6740d7 Mon Sep 17 00:00:00 2001 From: Bart van Strien Date: Tue, 2 Aug 2016 14:26:51 +0200 Subject: [PATCH 13/15] Prevent attaching a MouseJoint to a kinematic body (fixes #1185) It turns out, calling World:update() after attaching a MouseJoint to a kinematic body causes an exception. Normally the wrapper catches the exception, but somehow this exception cannot be caught. Wonderful. --- src/modules/physics/box2d/MouseJoint.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/modules/physics/box2d/MouseJoint.cpp b/src/modules/physics/box2d/MouseJoint.cpp index 08e41d35e..96768e870 100644 --- a/src/modules/physics/box2d/MouseJoint.cpp +++ b/src/modules/physics/box2d/MouseJoint.cpp @@ -36,6 +36,9 @@ MouseJoint::MouseJoint(Body *body1, float x, float y) : Joint(body1) , joint(NULL) { + if (body1->getType() == Body::BODY_KINEMATIC) + throw love::Exception("Cannot attach a MouseJoint to a kinematic body"); + b2MouseJointDef def; def.bodyA = body1->world->getGroundBody(); From 5ae730be9ed00530090fd47fea208a540dbc6274 Mon Sep 17 00:00:00 2001 From: Bart van Strien Date: Tue, 2 Aug 2016 14:33:28 +0200 Subject: [PATCH 14/15] Update changelog --- changes.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/changes.txt b/changes.txt index 1dad9943d..d63a92966 100644 --- a/changes.txt +++ b/changes.txt @@ -8,6 +8,8 @@ Released: N/A * Added Quad:getTextureDimensions. * Added PrismaticJoint:getAxis and WheelJoint:getAxis. * Added 2-point version of love.physics.newRevoluteJoint. + * Added table variants of Fixture:setCategory and Fixture:setMask. + * Added getNextVertex and getPreviousVertex to ChainShape and EdgeShape. * Fixed love on iOS 6. * Fixed os.execute always returning -1 on Linux. @@ -23,6 +25,7 @@ Released: N/A * Fixed large burst of particles when dramatically increasing the emission rate of a ParticleSystem. * Fixed MouseJoint:getBodies unconditionally erroring. * Fixed memory leak in Text:set. + * Fixed incorrect kerning caused by using kerning information for the wrong character in some fonts. * Improved performance of Channel methods by roughly 2x in many cases. From 3e678fc462910d716394a1719a2af8a450664c49 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Fri, 12 Aug 2016 23:44:16 -0300 Subject: [PATCH 15/15] Fix SpriteBatch:setBufferSize to keep old sprite data if it can fit (resolves issue #1204). --- src/modules/graphics/opengl/SpriteBatch.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/modules/graphics/opengl/SpriteBatch.cpp b/src/modules/graphics/opengl/SpriteBatch.cpp index 7c5f4fc6b..6982725e0 100644 --- a/src/modules/graphics/opengl/SpriteBatch.cpp +++ b/src/modules/graphics/opengl/SpriteBatch.cpp @@ -162,14 +162,18 @@ void SpriteBatch::setBufferSize(int newsize) size_t vertex_size = sizeof(Vertex) * 4 * newsize; GLBuffer *new_array_buf = nullptr; + int new_next = std::min(next, newsize); + try { new_array_buf = new GLBuffer(vertex_size, nullptr, array_buf->getTarget(), array_buf->getUsage(), array_buf->getMapFlags()); - // Copy as much of the old data into the new GLBuffer as can fit. GLBuffer::Bind bind(*new_array_buf); - void *new_data = new_array_buf->map(); - memcpy(new_data, old_data, sizeof(Vertex) * 4 * std::min(newsize, size)); + + // Copy as much of the old data into the new GLBuffer as can fit. + size_t copy_size = sizeof(Vertex) * 4 * new_next; + memcpy(new_array_buf->map(), old_data, copy_size); + new_array_buf->setMappedRangeModified(0, copy_size); quad_indices = QuadIndices(newsize); } @@ -185,7 +189,7 @@ void SpriteBatch::setBufferSize(int newsize) array_buf = new_array_buf; size = newsize; - next = std::min(next, newsize); + next = new_next; } int SpriteBatch::getBufferSize() const