Browse Source

Merged default into minor

--HG--
branch : minor
Alex Szpakowski 10 years ago
parent
commit
8dba668ce9
32 changed files with 348 additions and 22 deletions
  1. 103 3
      license.txt
  2. 6 6
      platform/macosx/love.xcodeproj/project.pbxproj
  3. 1 1
      src/libraries/ddsparse/ddsparse.cpp
  4. 1 1
      src/libraries/ddsparse/ddsparse.h
  5. 17 3
      src/modules/graphics/opengl/Image.cpp
  6. 4 0
      src/modules/image/CompressedData.cpp
  7. 4 0
      src/modules/image/CompressedData.h
  8. 8 2
      src/modules/image/magpie/ddsHandler.cpp
  9. 8 0
      src/modules/joystick/sdl/JoystickModule.cpp
  10. 9 5
      src/modules/joystick/wrap_JoystickModule.cpp
  11. 27 0
      src/modules/physics/box2d/Body.cpp
  12. 5 0
      src/modules/physics/box2d/Body.h
  13. 27 0
      src/modules/physics/box2d/GearJoint.cpp
  14. 3 0
      src/modules/physics/box2d/GearJoint.h
  15. 28 0
      src/modules/physics/box2d/Joint.cpp
  16. 3 1
      src/modules/physics/box2d/Joint.h
  17. 10 0
      src/modules/physics/box2d/wrap_Body.cpp
  18. 1 0
      src/modules/physics/box2d/wrap_Body.h
  19. 1 0
      src/modules/physics/box2d/wrap_DistanceJoint.cpp
  20. 1 0
      src/modules/physics/box2d/wrap_FrictionJoint.cpp
  21. 18 0
      src/modules/physics/box2d/wrap_GearJoint.cpp
  22. 1 0
      src/modules/physics/box2d/wrap_GearJoint.h
  23. 52 0
      src/modules/physics/box2d/wrap_Joint.cpp
  24. 2 0
      src/modules/physics/box2d/wrap_Joint.h
  25. 1 0
      src/modules/physics/box2d/wrap_MotorJoint.cpp
  26. 1 0
      src/modules/physics/box2d/wrap_MouseJoint.cpp
  27. 1 0
      src/modules/physics/box2d/wrap_PrismaticJoint.cpp
  28. 1 0
      src/modules/physics/box2d/wrap_PulleyJoint.cpp
  29. 1 0
      src/modules/physics/box2d/wrap_RevoluteJoint.cpp
  30. 1 0
      src/modules/physics/box2d/wrap_RopeJoint.cpp
  31. 1 0
      src/modules/physics/box2d/wrap_WeldJoint.cpp
  32. 1 0
      src/modules/physics/box2d/wrap_WheelJoint.cpp

+ 103 - 3
license.txt

@@ -1,4 +1,6 @@
-Copyright (c) 2006-2014 LOVE Development Team
+This software uses LÖVE:
+
+LÖVE is Copyright (c) 2006-2014 LOVE Development Team
 
 This software is provided 'as-is', without any express or implied
 warranty. In no event will the authors be held liable for any damages
@@ -19,11 +21,109 @@ misrepresented as being the original software.
 3. This notice may not be removed or altered from any source
 distribution.
 
+---------
+
+This software uses LuaJIT:
+
+LuaJIT is Copyright (c) 2005-2014 Mike Pall
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+
+---------
+
+This software uses ENet:
+
+Copyright (c) 2002-2014 Lee Salzman
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+
+---------
+
+This software uses lua-enet:
+
+Copyright (C) 2011 by Leaf Corcoran
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+
+---------
+
+This software uses UTF8-CPP:
+
+Copyright 2006 Nemanja Trifunovic
+
+Permission is hereby granted, free of charge, to any person or organization
+obtaining a copy of the software and accompanying documentation covered by
+this license (the "Software") to use, reproduce, display, distribute,
+execute, and transmit the Software, and to prepare derivative works of the
+Software, and to permit third-parties to whom the Software is furnished to
+do so, all subject to the following:
+
+The copyright notices in the Software and this entire statement, including
+the above license grant, this restriction and the following disclaimer,
+must be included in all copies of the Software, in whole or in part, and
+all derivative works of the Software, unless such copies or derivative
+works are solely in the form of machine-executable object code generated by
+a source language processor.
 
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS IN THE SOFTWARE.
 
--------
+---------
 
-LÖVE uses the following LGPL libraries:
+This software uses the following LGPL libraries:
 
  - libmpg123
      Website: http://www.mpg123.de/

+ 6 - 6
platform/macosx/love.xcodeproj/project.pbxproj

@@ -14,17 +14,17 @@
 		A9255F58104324E100BA1496 /* Ogg.framework in Copy Frameworks */ = {isa = PBXBuildFile; fileRef = A9255F51104324D700BA1496 /* Ogg.framework */; };
 		A93E6E5510420B57007D418B /* Lua.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A93E6E5310420B57007D418B /* Lua.framework */; };
 		A93E6EED10420BA8007D418B /* love.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A93E6A3410420AC0007D418B /* love.cpp */; };
-		A9D307F2106635D3004FEDF8 /* physfs.framework in Copy Frameworks */ = {isa = PBXBuildFile; fileRef = A9D307E9106635C3004FEDF8 /* physfs.framework */; };
+		A9D307F2106635D3004FEDF8 /* physfs.framework in Copy Frameworks */ = {isa = PBXBuildFile; fileRef = A9D307E9106635C3004FEDF8 /* physfs.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };
 		A9DEC1C11046EFA70049C70C /* Love.icns in Resources */ = {isa = PBXBuildFile; fileRef = A9DEC1BF1046EFA60049C70C /* Love.icns */; };
 		A9DEC1C21046EFA70049C70C /* LoveDocument.icns in Resources */ = {isa = PBXBuildFile; fileRef = A9DEC1C01046EFA70049C70C /* LoveDocument.icns */; };
-		A9F169AC109E825000FC83D1 /* mpg123.framework in Copy Frameworks */ = {isa = PBXBuildFile; fileRef = A9F169A6109E824900FC83D1 /* mpg123.framework */; };
-		A9F169AD109E825000FC83D1 /* libmodplug.framework in Copy Frameworks */ = {isa = PBXBuildFile; fileRef = A9F16926109E7BAD00FC83D1 /* libmodplug.framework */; };
+		A9F169AC109E825000FC83D1 /* mpg123.framework in Copy Frameworks */ = {isa = PBXBuildFile; fileRef = A9F169A6109E824900FC83D1 /* mpg123.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };
+		A9F169AD109E825000FC83D1 /* libmodplug.framework in Copy Frameworks */ = {isa = PBXBuildFile; fileRef = A9F16926109E7BAD00FC83D1 /* libmodplug.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };
 		FA08F69616C766E000F007B5 /* love.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FA08F69116C765A200F007B5 /* love.framework */; };
 		FA08F69716C766E700F007B5 /* love.framework in Copy Frameworks */ = {isa = PBXBuildFile; fileRef = FA08F69116C765A200F007B5 /* love.framework */; };
 		FA77A36518F1172600D23AE9 /* jpeg-turbo.framework in Copy Frameworks */ = {isa = PBXBuildFile; fileRef = FA77A36418F1172600D23AE9 /* jpeg-turbo.framework */; };
 		FA9B4A0A16E1579F00074F42 /* SDL2.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FA9B4A0916E1579F00074F42 /* SDL2.framework */; };
-		FA9B4A0B16E157B500074F42 /* SDL2.framework in Copy Frameworks */ = {isa = PBXBuildFile; fileRef = FA9B4A0916E1579F00074F42 /* SDL2.framework */; };
-		FAAFF04716CB120000CCDE45 /* OpenAL-Soft.framework in Copy Frameworks */ = {isa = PBXBuildFile; fileRef = FAAFF04616CB120000CCDE45 /* OpenAL-Soft.framework */; };
+		FA9B4A0B16E157B500074F42 /* SDL2.framework in Copy Frameworks */ = {isa = PBXBuildFile; fileRef = FA9B4A0916E1579F00074F42 /* SDL2.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };
+		FAAFF04716CB120000CCDE45 /* OpenAL-Soft.framework in Copy Frameworks */ = {isa = PBXBuildFile; fileRef = FAAFF04616CB120000CCDE45 /* OpenAL-Soft.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };
 		FAC1A449196F5DC600125284 /* license.txt in Resources */ = {isa = PBXBuildFile; fileRef = FAC1A448196F5DC600125284 /* license.txt */; };
 		FAC8E8D416F3C468004DADF3 /* OSX.mm in Sources */ = {isa = PBXBuildFile; fileRef = FAC8E8D316F3C468004DADF3 /* OSX.mm */; };
 /* End PBXBuildFile section */
@@ -201,7 +201,7 @@
 		29B97313FDCFA39411CA2CEA /* Project object */ = {
 			isa = PBXProject;
 			attributes = {
-				LastUpgradeCheck = 0510;
+				LastUpgradeCheck = 0610;
 			};
 			buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "love" */;
 			compatibilityVersion = "Xcode 3.2";

+ 1 - 1
src/libraries/ddsparse/ddsparse.cpp

@@ -116,7 +116,7 @@ static Format parseDX10Format(DXGIFormat fmt)
 		f = FORMAT_BC6H;
 		break;
 	case DXGI_FORMAT_BC6H_SF16:
-		f = FORAMT_BC6Hs;
+		f = FORMAT_BC6Hs;
 		break;
 	case DXGI_FORMAT_BC7_TYPELESS:
 	case DXGI_FORMAT_BC7_UNORM:

+ 1 - 1
src/libraries/ddsparse/ddsparse.h

@@ -45,7 +45,7 @@ enum Format
 	FORMAT_BC5,
 	FORMAT_BC5s,
 	FORMAT_BC6H,
-	FORAMT_BC6Hs,
+	FORMAT_BC6Hs,
 	FORMAT_BC7,
 	FORMAT_BC7srgb, // sRGB color space.
 	FORMAT_UNKNOWN

+ 17 - 3
src/modules/graphics/opengl/Image.cpp

@@ -491,6 +491,17 @@ GLenum Image::getCompressedFormat(image::CompressedData::Format cformat) const
 		return GL_COMPRESSED_RG_RGTC2;
 	case image::CompressedData::FORMAT_BC5s:
 		return GL_COMPRESSED_SIGNED_RG_RGTC2;
+	case image::CompressedData::FORMAT_BC6H:
+		return GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT;
+	case image::CompressedData::FORMAT_BC6Hs:
+		return GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT;
+	case image::CompressedData::FORMAT_BC7:
+		if (flags.sRGB)
+			return GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM;
+		else
+			return GL_COMPRESSED_RGBA_BPTC_UNORM;
+	case image::CompressedData::FORMAT_BC7SRGB:
+		return GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM;
 	default:
 		if (flags.sRGB)
 			return GL_SRGB8_ALPHA8;
@@ -519,11 +530,14 @@ bool Image::hasCompressedTextureSupport(image::CompressedData::Format format)
 	case image::CompressedData::FORMAT_BC5:
 	case image::CompressedData::FORMAT_BC5s:
 		return (GLAD_VERSION_3_0 || GLAD_ARB_texture_compression_rgtc || GLAD_EXT_texture_compression_rgtc);
+	case image::CompressedData::FORMAT_BC6H:
+	case image::CompressedData::FORMAT_BC6Hs:
+	case image::CompressedData::FORMAT_BC7:
+	case image::CompressedData::FORMAT_BC7SRGB:
+		return GLAD_VERSION_4_2 || GLAD_ARB_texture_compression_bptc;
 	default:
-		break;
+		return false;
 	}
-
-	return false;
 }
 
 bool Image::hasSRGBSupport()

+ 4 - 0
src/modules/image/CompressedData.cpp

@@ -110,6 +110,10 @@ StringMap<CompressedData::Format, CompressedData::FORMAT_MAX_ENUM>::Entry Compre
 	{"bc4s", CompressedData::FORMAT_BC4s},
 	{"bc5", CompressedData::FORMAT_BC5},
 	{"bc5s", CompressedData::FORMAT_BC5s},
+	{"bc6h", CompressedData::FORMAT_BC6H},
+	{"bc6hs", CompressedData::FORMAT_BC6Hs},
+	{"bc7", CompressedData::FORMAT_BC7},
+	{"bc7srgb", CompressedData::FORMAT_BC7SRGB},
 };
 
 StringMap<CompressedData::Format, CompressedData::FORMAT_MAX_ENUM> CompressedData::formats(CompressedData::formatEntries, sizeof(CompressedData::formatEntries));

+ 4 - 0
src/modules/image/CompressedData.h

@@ -54,6 +54,10 @@ public:
 		FORMAT_BC4s,
 		FORMAT_BC5,
 		FORMAT_BC5s,
+		FORMAT_BC6H,
+		FORMAT_BC6Hs,
+		FORMAT_BC7,
+		FORMAT_BC7SRGB,
 		FORMAT_MAX_ENUM
 	};
 

+ 8 - 2
src/modules/image/magpie/ddsHandler.cpp

@@ -117,11 +117,17 @@ CompressedData::Format ddsHandler::convertFormat(dds::Format ddsformat)
 		return CompressedData::FORMAT_BC5;
 	case dds::FORMAT_BC5s:
 		return CompressedData::FORMAT_BC5s;
+	case dds::FORMAT_BC6H:
+		return CompressedData::FORMAT_BC6H;
+	case dds::FORMAT_BC6Hs:
+		return CompressedData::FORMAT_BC6Hs;
+	case dds::FORMAT_BC7:
+		return CompressedData::FORMAT_BC7;
+	case dds::FORMAT_BC7srgb:
+		return CompressedData::FORMAT_BC7SRGB;
 	default:
 		return CompressedData::FORMAT_UNKNOWN;
 	}
-
-	return CompressedData::FORMAT_UNKNOWN;
 }
 
 } // magpie

+ 8 - 0
src/modules/joystick/sdl/JoystickModule.cpp

@@ -489,6 +489,10 @@ void JoystickModule::loadGamepadMappings(const std::string &mappings)
 		if (mapping.empty())
 			continue;
 
+		// Lines starting with "#" are comments.
+		if (mapping[0] == '#')
+			continue;
+
 		// Strip out and compare any "platform:XYZ," in the mapping.
 		size_t pstartpos = mapping.find("platform:");
 		if (pstartpos != std::string::npos)
@@ -499,7 +503,11 @@ void JoystickModule::loadGamepadMappings(const std::string &mappings)
 			std::string platform = mapping.substr(pstartpos, pendpos - pstartpos);
 
 			if (platform.compare(SDL_GetPlatform()) != 0)
+			{
+				// Ignore the mapping but still acknowledge that it is one.
+				success = true;
 				continue;
+			}
 
 			pstartpos -= strlen("platform:");
 			mapping.erase(pstartpos, pendpos - pstartpos + 1);

+ 9 - 5
src/modules/joystick/wrap_JoystickModule.cpp

@@ -179,13 +179,17 @@ int w_getGamepadMapping(lua_State *L)
 
 int w_loadGamepadMappings(lua_State *L)
 {
-	lua_pushvalue(L, 1);
-	luax_convobj(L, -1, "filesystem", "isFile");
-	bool isfile = luax_toboolean(L, -1);
-	lua_pop(L, 1);
-
+	bool isfile = true;
 	std::string mappings;
 
+	if (lua_isstring(L, 1))
+	{
+		lua_pushvalue(L, 1);
+		luax_convobj(L, -1, "filesystem", "isFile");
+		isfile = luax_toboolean(L, -1);
+		lua_pop(L, 1);
+	}
+
 	if (isfile)
 	{
 		love::filesystem::FileData *fd = love::filesystem::luax_getfiledata(L, 1);

+ 27 - 0
src/modules/physics/box2d/Body.cpp

@@ -28,6 +28,9 @@
 #include "World.h"
 #include "Physics.h"
 
+// Needed for luax_pushjoint.
+#include "wrap_Joint.h"
+
 namespace love
 {
 namespace physics
@@ -440,6 +443,30 @@ int Body::getFixtureList(lua_State *L) const
 	return 1;
 }
 
+int Body::getJointList(lua_State *L) const
+{
+	lua_newtable(L);
+	const b2JointEdge *je = body->GetJointList();
+	int i = 1;
+
+	do
+	{
+		if (!je)
+			break;
+
+		Joint *joint = (Joint *) Memoizer::find(je->joint);
+		if (!joint)
+			throw love::Exception("A joint has escaped Memoizer!");
+
+		luax_pushjoint(L, joint);
+		lua_rawseti(L, -2, i);
+		i++;
+	}
+	while ((je = je->next));
+
+	return 1;
+}
+
 int Body::getContactList(lua_State *L) const
 {
 	lua_newtable(L);

+ 5 - 0
src/modules/physics/box2d/Body.h

@@ -393,6 +393,11 @@ public:
 	 **/
 	int getFixtureList(lua_State *L) const;
 
+	/**
+	 * Get an array of all Joints attached to this Body.
+	 **/
+	int getJointList(lua_State *L) const;
+
 	/**
 	 * Get an array of all active Contacts attached to this Body.
 	 * This list changes during World:update and you may miss some collisions

+ 27 - 0
src/modules/physics/box2d/GearJoint.cpp

@@ -23,6 +23,7 @@
 // Module
 #include "Body.h"
 #include "World.h"
+#include "common/Memoizer.h"
 
 namespace love
 {
@@ -60,6 +61,32 @@ float GearJoint::getRatio() const
 	return joint->GetRatio();
 }
 
+Joint *GearJoint::getJointA() const
+{
+	b2Joint *b2joint = joint->GetJoint1();
+	if (b2joint == nullptr)
+		return nullptr;
+
+	Joint *j = (Joint *) Memoizer::find(b2joint);
+	if (j == nullptr)
+		throw love::Exception("A joint has escaped Memoizer!");
+
+	return j;
+}
+
+Joint *GearJoint::getJointB() const
+{
+	b2Joint *b2joint = joint->GetJoint2();
+	if (b2joint == nullptr)
+		return nullptr;
+
+	Joint *j = (Joint *) Memoizer::find(b2joint);
+	if (j == nullptr)
+		throw love::Exception("A joint has escaped Memoizer!");
+
+	return j;
+}
+
 } // box2d
 } // physics
 } // love

+ 3 - 0
src/modules/physics/box2d/GearJoint.h

@@ -64,6 +64,9 @@ public:
 	 **/
 	float getRatio() const;
 
+	Joint *getJointA() const;
+	Joint *getJointB() const;
+
 private:
 	// The Box2D GearJoint object.
 	b2GearJoint *joint;

+ 28 - 0
src/modules/physics/box2d/Joint.cpp

@@ -90,11 +90,39 @@ Joint::Type Joint::getType() const
 		return JOINT_WHEEL;
 	case e_ropeJoint:
 		return JOINT_ROPE;
+	case e_motorJoint:
+		return JOINT_MOTOR;
 	default:
 		return JOINT_INVALID;
 	}
 }
 
+Body *Joint::getBodyA() const
+{
+	b2Body *b2body = joint->GetBodyA();
+	if (b2body == nullptr)
+		return nullptr;
+
+	Body *body = (Body *) Memoizer::find(b2body);
+	if (body == nullptr)
+		throw love::Exception("A body has escaped Memoizer!");
+
+	return body;
+}
+
+Body *Joint::getBodyB() const
+{
+	b2Body *b2body = joint->GetBodyB();
+	if (b2body == nullptr)
+		return nullptr;
+
+	Body *body = (Body *) Memoizer::find(b2body);
+	if (body == nullptr)
+		throw love::Exception("A body has escaped Memoizer!");
+
+	return body;
+}
+
 bool Joint::isValid() const
 {
 	return joint != 0;

+ 3 - 1
src/modules/physics/box2d/Joint.h

@@ -79,12 +79,14 @@ public:
 	 **/
 	bool isValid() const;
 
-
 	/**
 	 * Gets the type of joint.
 	 **/
 	Type getType() const;
 
+	Body *getBodyA() const;
+	Body *getBodyB() const;
+
 	/**
 	 * Gets the anchor positions of the Joint in world
 	 * coordinates. This is useful for debugdrawing the joint.

+ 10 - 0
src/modules/physics/box2d/wrap_Body.cpp

@@ -539,6 +539,15 @@ int w_Body_getFixtureList(lua_State *L)
 	return n;
 }
 
+int w_Body_getJointList(lua_State *L)
+{
+	Body *t = luax_checkbody(L, 1);
+	lua_remove(L, 1);
+	int n = 0;
+	luax_catchexcept(L, [&](){ n = t->getJointList(L); });
+	return n;
+}
+
 int w_Body_getContactList(lua_State *L)
 {
 	Body *t = luax_checkbody(L, 1);
@@ -623,6 +632,7 @@ static const luaL_Reg functions[] =
 	{ "isFixedRotation", w_Body_isFixedRotation },
 	{ "getWorld", w_Body_getWorld },
 	{ "getFixtureList", w_Body_getFixtureList },
+	{ "getJointList", w_Body_getJointList },
 	{ "getContactList", w_Body_getContactList },
 	{ "destroy", w_Body_destroy },
 	{ "setUserData", w_Body_setUserData },

+ 1 - 0
src/modules/physics/box2d/wrap_Body.h

@@ -85,6 +85,7 @@ int w_Body_setFixedRotation(lua_State *L);
 int w_Body_isFixedRotation(lua_State *L);
 int w_Body_getWorld(lua_State *L);
 int w_Body_getFixtureList(lua_State *L);
+int w_Body_getJointList(lua_State *L);
 int w_Body_getContactList(lua_State *L);
 int w_Body_destroy(lua_State *L);
 int w_Body_setUserData(lua_State *L);

+ 1 - 0
src/modules/physics/box2d/wrap_DistanceJoint.cpp

@@ -90,6 +90,7 @@ static const luaL_Reg functions[] =
 	{ "getDampingRatio", w_DistanceJoint_getDampingRatio },
 	// From Joint.
 	{ "getType", w_Joint_getType },
+	{ "getBodies", w_Joint_getBodies },
 	{ "getAnchors", w_Joint_getAnchors },
 	{ "getReactionForce", w_Joint_getReactionForce },
 	{ "getReactionTorque", w_Joint_getReactionTorque },

+ 1 - 0
src/modules/physics/box2d/wrap_FrictionJoint.cpp

@@ -74,6 +74,7 @@ static const luaL_Reg functions[] =
 	{ "getMaxTorque", w_FrictionJoint_getMaxTorque },
 	// From Joint.
 	{ "getType", w_Joint_getType },
+	{ "getBodies", w_Joint_getBodies },
 	{ "getAnchors", w_Joint_getAnchors },
 	{ "getReactionForce", w_Joint_getReactionForce },
 	{ "getReactionTorque", w_Joint_getReactionTorque },

+ 18 - 0
src/modules/physics/box2d/wrap_GearJoint.cpp

@@ -51,12 +51,30 @@ int w_GearJoint_getRatio(lua_State *L)
 	return 1;
 }
 
+int w_GearJoint_getJoints(lua_State *L)
+{
+	GearJoint *t = luax_checkgearjoint(L, 1);
+	Joint *j1 = nullptr;
+	Joint *j2 = nullptr;
+
+	luax_catchexcept(L, [&]() {
+		j1 = t->getJointA();
+		j2 = t->getJointB();
+	});
+
+	luax_pushjoint(L, j1);
+	luax_pushjoint(L, j2);
+	return 2;
+}
+
 static const luaL_Reg functions[] =
 {
 	{ "setRatio", w_GearJoint_setRatio },
 	{ "getRatio", w_GearJoint_getRatio },
+	{ "getJoints", w_GearJoint_getJoints },
 	// From Joint.
 	{ "getType", w_Joint_getType },
+	{ "getBodies", w_Joint_getBodies },
 	{ "getAnchors", w_Joint_getAnchors },
 	{ "getReactionForce", w_Joint_getReactionForce },
 	{ "getReactionTorque", w_Joint_getReactionTorque },

+ 1 - 0
src/modules/physics/box2d/wrap_GearJoint.h

@@ -36,6 +36,7 @@ namespace box2d
 GearJoint *luax_checkgearjoint(lua_State *L, int idx);
 int w_GearJoint_setRatio(lua_State *L);
 int w_GearJoint_getRatio(lua_State *L);
+int w_GearJoint_getJoints(lua_State *L);
 extern "C" int luaopen_gearjoint(lua_State *L);
 
 } // box2d

+ 52 - 0
src/modules/physics/box2d/wrap_Joint.cpp

@@ -21,6 +21,7 @@
 // LOVE
 #include "wrap_Joint.h"
 #include "common/StringMap.h"
+#include "Body.h"
 
 namespace love
 {
@@ -29,6 +30,40 @@ namespace physics
 namespace box2d
 {
 
+void luax_pushjoint(lua_State *L, Joint *j)
+{
+	if (j == nullptr)
+		return lua_pushnil(L);
+
+	switch (j->getType())
+	{
+	case Joint::JOINT_DISTANCE:
+		return luax_pushtype(L, "DistanceJoint", PHYSICS_DISTANCE_JOINT_T, j);
+	case Joint::JOINT_REVOLUTE:
+		return luax_pushtype(L, "RevoluteJoint", PHYSICS_REVOLUTE_JOINT_T, j);
+	case Joint::JOINT_PRISMATIC:
+		return luax_pushtype(L, "PrismaticJoint", PHYSICS_PRISMATIC_JOINT_T, j);
+	case Joint::JOINT_MOUSE:
+		return luax_pushtype(L, "MouseJoint", PHYSICS_MOUSE_JOINT_T, j);
+	case Joint::JOINT_PULLEY:
+		return luax_pushtype(L, "PulleyJoint", PHYSICS_PULLEY_JOINT_T, j);
+	case Joint::JOINT_GEAR:
+		return luax_pushtype(L, "GearJoint", PHYSICS_GEAR_JOINT_T, j);
+	case Joint::JOINT_FRICTION:
+		return luax_pushtype(L, "FrictionJoint", PHYSICS_FRICTION_JOINT_T, j);
+	case Joint::JOINT_WELD:
+		return luax_pushtype(L, "WeldJoint", PHYSICS_WELD_JOINT_T, j);
+	case Joint::JOINT_WHEEL:
+		return luax_pushtype(L, "WheelJoint", PHYSICS_WHEEL_JOINT_T, j);
+	case Joint::JOINT_ROPE:
+		return luax_pushtype(L, "RopeJoint", PHYSICS_ROPE_JOINT_T, j);
+	case Joint::JOINT_MOTOR:
+		return luax_pushtype(L, "MotorJoint", PHYSICS_MOTOR_JOINT_T, j);
+	default:
+		return lua_pushnil(L);
+	}
+}
+
 Joint *luax_checkjoint(lua_State *L, int idx)
 {
 	Joint *t = luax_checktype<Joint>(L, idx, "Joint", PHYSICS_JOINT_T);
@@ -46,6 +81,22 @@ int w_Joint_getType(lua_State *L)
 	return 1;
 }
 
+int w_Joint_getBodies(lua_State *L)
+{
+	Joint *t = luax_checkjoint(L, 1);
+	Body *b1 = nullptr;
+	Body *b2 = nullptr;
+
+	luax_catchexcept(L, [&]() {
+		b1 = t->getBodyA();
+		b2 = t->getBodyB();
+	});
+
+	luax_pushtype(L, "Body", PHYSICS_BODY_T, b1);
+	luax_pushtype(L, "Body", PHYSICS_BODY_T, b2);
+	return 2;
+}
+
 int w_Joint_getAnchors(lua_State *L)
 {
 	Joint *t = luax_checkjoint(L, 1);
@@ -99,6 +150,7 @@ int w_Joint_destroy(lua_State *L)
 static const luaL_Reg functions[] =
 {
 	{ "getType", w_Joint_getType },
+	{ "getBodies", w_Joint_getBodies },
 	{ "getAnchors", w_Joint_getAnchors },
 	{ "getReactionForce", w_Joint_getReactionForce },
 	{ "getReactionTorque", w_Joint_getReactionTorque },

+ 2 - 0
src/modules/physics/box2d/wrap_Joint.h

@@ -32,8 +32,10 @@ namespace physics
 namespace box2d
 {
 
+void luax_pushjoint(lua_State *L, Joint *j);
 Joint *luax_checkjoint(lua_State *L, int idx);
 int w_Joint_getType(lua_State *L);
+int w_Joint_getBodies(lua_State *L);
 int w_Joint_getAnchors(lua_State *L);
 int w_Joint_getReactionForce(lua_State *L);
 int w_Joint_getReactionTorque(lua_State *L);

+ 1 - 0
src/modules/physics/box2d/wrap_MotorJoint.cpp

@@ -124,6 +124,7 @@ static const luaL_Reg functions[] =
 	{ "getCorrectionFactor", w_MotorJoint_getCorrectionFactor },
 	// From Joint.
 	{ "getType", w_Joint_getType },
+	{ "getBodies", w_Joint_getBodies },
 	{ "getAnchors", w_Joint_getAnchors },
 	{ "getReactionForce", w_Joint_getReactionForce },
 	{ "getReactionTorque", w_Joint_getReactionTorque },

+ 1 - 0
src/modules/physics/box2d/wrap_MouseJoint.cpp

@@ -108,6 +108,7 @@ static const luaL_Reg functions[] =
 	{ "getDampingRatio", w_MouseJoint_getDampingRatio },
 	// From Joint.
 	{ "getType", w_Joint_getType },
+	{ "getBodies", w_Joint_getBodies },
 	{ "getAnchors", w_Joint_getAnchors },
 	{ "getReactionForce", w_Joint_getReactionForce },
 	{ "getReactionTorque", w_Joint_getReactionTorque },

+ 1 - 0
src/modules/physics/box2d/wrap_PrismaticJoint.cpp

@@ -185,6 +185,7 @@ static const luaL_Reg functions[] =
 	{ "getLimits", w_PrismaticJoint_getLimits },
 	// From Joint.
 	{ "getType", w_Joint_getType },
+	{ "getBodies", w_Joint_getBodies },
 	{ "getAnchors", w_Joint_getAnchors },
 	{ "getReactionForce", w_Joint_getReactionForce },
 	{ "getReactionTorque", w_Joint_getReactionTorque },

+ 1 - 0
src/modules/physics/box2d/wrap_PulleyJoint.cpp

@@ -71,6 +71,7 @@ static const luaL_Reg functions[] =
 	{ "getRatio", w_PulleyJoint_getRatio },
 	// From Joint.
 	{ "getType", w_Joint_getType },
+	{ "getBodies", w_Joint_getBodies },
 	{ "getAnchors", w_Joint_getAnchors },
 	{ "getReactionForce", w_Joint_getReactionForce },
 	{ "getReactionTorque", w_Joint_getReactionTorque },

+ 1 - 0
src/modules/physics/box2d/wrap_RevoluteJoint.cpp

@@ -185,6 +185,7 @@ static const luaL_Reg functions[] =
 	{ "getLimits", w_RevoluteJoint_getLimits },
 	// From Joint.
 	{ "getType", w_Joint_getType },
+	{ "getBodies", w_Joint_getBodies },
 	{ "getAnchors", w_Joint_getAnchors },
 	{ "getReactionForce", w_Joint_getReactionForce },
 	{ "getReactionTorque", w_Joint_getReactionTorque },

+ 1 - 0
src/modules/physics/box2d/wrap_RopeJoint.cpp

@@ -47,6 +47,7 @@ static const luaL_Reg functions[] =
 	{ "getMaxLength", w_RopeJoint_getMaxLength },
 	// From Joint.
 	{ "getType", w_Joint_getType },
+	{ "getBodies", w_Joint_getBodies },
 	{ "getAnchors", w_Joint_getAnchors },
 	{ "getReactionForce", w_Joint_getReactionForce },
 	{ "getReactionTorque", w_Joint_getReactionTorque },

+ 1 - 0
src/modules/physics/box2d/wrap_WeldJoint.cpp

@@ -73,6 +73,7 @@ static const luaL_Reg functions[] =
 	{ "getDampingRatio", w_WeldJoint_getDampingRatio },
 	// From Joint.
 	{ "getType", w_Joint_getType },
+	{ "getBodies", w_Joint_getBodies },
 	{ "getAnchors", w_Joint_getAnchors },
 	{ "getReactionForce", w_Joint_getReactionForce },
 	{ "getReactionTorque", w_Joint_getReactionTorque },

+ 1 - 0
src/modules/physics/box2d/wrap_WheelJoint.cpp

@@ -149,6 +149,7 @@ static const luaL_Reg functions[] =
 	{ "getSpringDampingRatio", w_WheelJoint_getSpringDampingRatio },
 	// From Joint.
 	{ "getType", w_Joint_getType },
+	{ "getBodies", w_Joint_getBodies },
 	{ "getAnchors", w_Joint_getAnchors },
 	{ "getReactionForce", w_Joint_getReactionForce },
 	{ "getReactionTorque", w_Joint_getReactionTorque },