Merge default into minor

--HG--
branch : minor
This commit is contained in:
Bart van Strien
2016-07-14 18:42:42 +02:00
19 changed files with 257 additions and 85 deletions
+161 -69
View File
@@ -27,16 +27,11 @@ cmake_minimum_required(VERSION 2.8)
project(love) project(love)
if(NOT MEGA)
message(FATAL_ERROR "
It is currently only possible to build with megasource on Windows.
Please see http://bitbucket.org/rude/megasource
")
endif()
set(LOVE_EXE_NAME love) set(LOVE_EXE_NAME love)
set(LOVE_LIB_NAME liblove) set(LOVE_LIB_NAME liblove)
set (CMAKE_CXX_STANDARD 11)
if(MSVC) if(MSVC)
set(LOVE_CONSOLE_EXE_NAME lovec) set(LOVE_CONSOLE_EXE_NAME lovec)
endif() endif()
@@ -53,6 +48,9 @@ option(LOVE_JIT "Use LuaJIT" TRUE)
option(LOVE_MPG123 "Use mpg123" TRUE) option(LOVE_MPG123 "Use mpg123" TRUE)
if(LOVE_JIT) if(LOVE_JIT)
if(APPLE)
message(FATAL_ERROR "JIT not supported yet on Mac. Please use -DLOVE_JIT=0.")
endif()
message(STATUS "LuaJIT: Enabled") message(STATUS "LuaJIT: Enabled")
else() else()
message(STATUS "LuaJIT: Disabled") message(STATUS "LuaJIT: Disabled")
@@ -66,17 +64,118 @@ message(STATUS "Target platform: ${LOVE_TARGET_PLATFORM}")
find_package(OpenGL) find_package(OpenGL)
if(${LOVE_JIT}) if(MEGA)
set(MEGA_LUA ${MEGA_LUAJIT_LIB}) # LOVE_MSVC_DLLS contains runtime DLLs that should be bundled with the love
set(MEGA_EXTRA_INCLUDE ${MEGA_LUAJIT_INCLUDE}) # binary (in e.g. the installer). Example: msvcp140.dll.
set(MEGA_EXTRA_DLLS ${MEGA_LUAJIT_DLL}) set(LOVE_MSVC_DLLS ${MEGA_MSVC_DLLS})
set(MEGA_EXTRA_DEPENDECIES luajit)
# LOVE_INCLUDE_DIRS contains the search directories for #include. It's mostly
# not needed for MEGA builds, since almost all the libraries (except LuaJIT)
# are CMake targets, causing include paths to be added automatically.
set(LOVE_INCLUDE_DIRS)
if(APPLE)
# Some files do #include <SDL2/SDL.h>, but building with megasource
# requires #include <SDL.h>.
add_definitions(-DLOVE_MACOSX_SDL_DIRECT_INCLUDE)
endif ()
# SDL2 links with some DirectX libraries, and we apparently also
# pull those libraries in for linkage because we link with SDL2.
set(LOVE_LINK_DIRS ${SDL_LINK_DIR})
set(LOVE_LINK_LIBRARIES
${OPENGL_gl_LIBRARY}
${MEGA_FREETYPE}
${MEGA_LIBOGG}
${MEGA_LIBVORBISFILE}
${MEGA_LIBVORBIS}
${MEGA_LIBTHEORA}
${MEGA_MODPLUG}
${MEGA_OPENAL}
${MEGA_PHYSFS}
${MEGA_SDL2MAIN}
${MEGA_SDL2}
${MEGA_ZLIB}
)
# These DLLs are moved next to the love binary in a post-build step to
# love runnable from inside Visual Studio.
#
# LOVE_MOVE_DLLS can contain CMake targets, in which case the target's
# output is assumed to be a DLL, or it can contain paths to actual files.
# We detect whether or not each item is a target, and take the appropriate
# action.
set(LOVE_MOVE_DLLS
${MEGA_SDL2}
${MEGA_OPENAL}
)
if(LOVE_MPG123)
set(LOVE_LINK_LIBRARIES
${LOVE_LINK_LIBRARIES}
${MEGA_MPEG123}
)
set(LOVE_MOVE_DLLS
${LOVE_MOVE_DLLS}
${MEGA_MPEG123}
)
endif()
if(LOVE_JIT)
set(LOVE_LUA_LIBRARY ${MEGA_LUAJIT_LIB})
# LOVE_EXTRA_DLLS are non-runtime DLLs which should be bundled with the
# love binary in installers, etc. It's only needed for external
# (non-CMake) targets, i.e. LuaJIT.
set(LOVE_EXTRA_DLLS ${MEGA_LUAJIT_DLL})
set(LOVE_EXTRA_DEPENDECIES luajit)
set(LOVE_INCLUDE_DIRS
${LOVE_INCLUDE_DIRS}
${MEGA_LUAJIT_INCLUDE}
)
set(LOVE_LINK_LIBRARIES
${LOVE_LINK_LIBRARIES}
${LOVE_LUA_LIBRARY}
)
set(LOVE_MOVE_DLLS
${LOVE_MOVE_DLLS}
${MEGA_LUAJIT_DLL}
)
else()
set(LOVE_LUA_LIBRARY ${MEGA_LUA51})
set(LOVE_LINK_LIBRARIES
${LOVE_LINK_LIBRARIES}
${LOVE_LUA_LIBRARY}
)
set(LOVE_MOVE_DLLS
${LOVE_MOVE_DLLS}
${LOVE_LUA_LIBRARY}
)
# MEGA_LUA51 is a CMake target, so includes are handled
# automatically.
endif()
else() else()
set(MEGA_LUA ${MEGA_LUA51}) message(FATAL_ERROR "
# MEGA_LUA51 is a CMake target, so includes are handled It is currently only possible to build with megasource on Windows.
# automatically. Please see http://bitbucket.org/rude/megasource
")
endif() endif()
###
### No Megasource-specific stuff beyond this point!
###
function(disable_warnings ARG_TARGET)
get_target_property(OLD_FLAGS ${ARG_TARGET} COMPILE_FLAGS)
set(NEW_FLAGS -W0)
if(OLD_FLAGS)
set(NEW_FLAGS "${OLD_FLAGS} ${NEW_FLAGS}")
endif()
set_target_properties(${ARG_TARGET} PROPERTIES COMPILE_FLAGS ${NEW_FLAGS})
endfunction()
# #
# common # common
# #
@@ -121,6 +220,12 @@ set(LOVE_SRC_COMMON
src/common/wrap_Data.h src/common/wrap_Data.h
) )
if (APPLE)
set(LOVE_SRC_COMMON ${LOVE_SRC_COMMON}
src/common/macosx.mm
)
endif()
source_group("common" FILES ${LOVE_SRC_COMMON}) source_group("common" FILES ${LOVE_SRC_COMMON})
# #
@@ -1034,7 +1139,7 @@ set(LOVE_SRC_3P_ENET
) )
add_library(love_3p_enet ${LOVE_SRC_3P_ENET}) add_library(love_3p_enet ${LOVE_SRC_3P_ENET})
target_link_libraries(love_3p_enet ${MEGA_LUA}) target_link_libraries(love_3p_enet ${LOVE_LUA_LIBRARY})
target_include_directories(love_3p_enet PUBLIC src/libraries/enet/libenet/include) target_include_directories(love_3p_enet PUBLIC src/libraries/enet/libenet/include)
# #
@@ -1112,6 +1217,12 @@ if(MSVC)
src/libraries/luasocket/libluasocket/wsocket.c src/libraries/luasocket/libluasocket/wsocket.c
src/libraries/luasocket/libluasocket/wsocket.h src/libraries/luasocket/libluasocket/wsocket.h
) )
else()
set(LOVE_SRC_3P_LUASOCKET_LIBLUASOCKET
${LOVE_SRC_3P_LUASOCKET_LIBLUASOCKET}
src/libraries/luasocket/libluasocket/usocket.c
src/libraries/luasocket/libluasocket/usocket.h
)
endif() endif()
set(LOVE_SRC_3P_LUASOCKET set(LOVE_SRC_3P_LUASOCKET
@@ -1120,7 +1231,7 @@ set(LOVE_SRC_3P_LUASOCKET
) )
add_library(love_3p_luasocket ${LOVE_SRC_3P_LUASOCKET}) add_library(love_3p_luasocket ${LOVE_SRC_3P_LUASOCKET})
target_link_libraries(love_3p_luasocket ${MEGA_LUA}) target_link_libraries(love_3p_luasocket ${LOVE_LUA_LIBRARY})
# #
# Lua 5.3's UTF-8 library # Lua 5.3's UTF-8 library
@@ -1133,7 +1244,7 @@ set(LOVE_SRC_3P_LUAUTF8
) )
add_library(love_3p_luautf8 ${LOVE_SRC_3P_LUAUTF8}) add_library(love_3p_luautf8 ${LOVE_SRC_3P_LUAUTF8})
target_link_libraries(love_3p_luautf8 ${MEGA_LUA}) target_link_libraries(love_3p_luautf8 ${LOVE_LUA_LIBRARY})
# #
# lz4 # lz4
@@ -1264,40 +1375,10 @@ include_directories(
src src
src/libraries src/libraries
src/modules src/modules
${MEGA_EXTRA_INCLUDE} ${LOVE_INCLUDE_DIRS}
) )
# SDL2 links with some DirectX libraries, and we apparently also link_directories(${LOVE_LINK_DIRS})
# pull those libraries in for linkage because we link with SDL2.
link_directories(${SDL_LINK_DIR})
set(LOVE_MEGA_3P
${MEGA_FREETYPE}
${MEGA_LIBOGG}
${MEGA_LIBVORBISFILE}
${MEGA_LIBVORBIS}
${MEGA_LIBTHEORA}
${MEGA_LUA}
${MEGA_MODPLUG}
${MEGA_OPENAL}
${MEGA_PHYSFS}
${MEGA_SDL2MAIN}
${MEGA_SDL2}
${MEGA_ZLIB}
)
if(LOVE_MPG123)
set(LOVE_MEGA_3P
${LOVE_MEGA_3P}
${MEGA_MPEG123}
)
endif()
set(LOVE_LINK_LIBRARIES
${OPENGL_gl_LIBRARY}
${LOVE_MEGA_3P}
)
set(LOVE_RC) set(LOVE_RC)
@@ -1316,8 +1397,8 @@ endif()
add_library(${LOVE_LIB_NAME} SHARED ${LOVE_LIB_SRC} ${LOVE_RC}) add_library(${LOVE_LIB_NAME} SHARED ${LOVE_LIB_SRC} ${LOVE_RC})
target_link_libraries(${LOVE_LIB_NAME} ${LOVE_LINK_LIBRARIES} ${LOVE_3P}) target_link_libraries(${LOVE_LIB_NAME} ${LOVE_LINK_LIBRARIES} ${LOVE_3P})
if(MEGA_EXTRA_DEPENDECIES) if(LOVE_EXTRA_DEPENDECIES)
add_dependencies(${LOVE_LIB_NAME} ${MEGA_EXTRA_DEPENDECIES}) add_dependencies(${LOVE_LIB_NAME} ${LOVE_EXTRA_DEPENDECIES})
endif() endif()
if(MSVC) if(MSVC)
@@ -1336,20 +1417,31 @@ if(MSVC)
target_link_libraries(${LOVE_CONSOLE_EXE_NAME} ${LOVE_LIB_NAME}) target_link_libraries(${LOVE_CONSOLE_EXE_NAME} ${LOVE_LIB_NAME})
endif() endif()
function(post_step_move_dll ARG_POST_TARGET ARG_TARGET_OR_FILE)
if(TARGET ${ARG_TARGET_OR_FILE})
add_custom_command(TARGET ${ARG_POST_TARGET} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
$<TARGET_FILE:${ARG_TARGET_OR_FILE}>
${CMAKE_CURRENT_BINARY_DIR}/$<CONFIGURATION>/$<TARGET_FILE_NAME:${ARG_TARGET_OR_FILE}>)
else()
get_filename_component(TEMP_FILENAME ${ARG_TARGET_OR_FILE} NAME)
add_custom_command(TARGET ${ARG_POST_TARGET} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${ARG_TARGET_OR_FILE}
${CMAKE_CURRENT_BINARY_DIR}/$<CONFIGURATION>/${TEMP_FILENAME})
endif()
endfunction()
# Add post build steps to move the DLLs next to the binary. Otherwise # Add post build steps to move the DLLs next to the binary. Otherwise
# running/debugging the binary will not work from inside VS. # running/debugging the binary will not work from inside VS.
if(LOVE_MPG123) if(LOVE_MOVE_DLLS)
add_move_dll(love ${MEGA_MPEG123}) foreach(DLL ${LOVE_MOVE_DLLS})
post_step_move_dll(love ${DLL})
endforeach()
endif() endif()
add_move_dll(love ${MEGA_SDL2}) if (NOT MSVC)
add_move_dll(love ${MEGA_OPENAL}) return()
if(LOVE_JIT)
add_move_file(love ${MEGA_LUAJIT_DLL})
else()
add_move_dll(love ${MEGA_LUA51})
endif() endif()
################################### ###################################
@@ -1380,21 +1472,21 @@ message(STATUS "Version: ${LOVE_VERSION_STR}")
install(TARGETS ${LOVE_EXE_NAME} ${LOVE_CONSOLE_EXE_NAME} ${LOVE_LIB_NAME} RUNTIME DESTINATION .) install(TARGETS ${LOVE_EXE_NAME} ${LOVE_CONSOLE_EXE_NAME} ${LOVE_LIB_NAME} RUNTIME DESTINATION .)
# Extra DLLs. # Extra DLLs.
if(MEGA_EXTRA_DLLS) if(LOVE_EXTRA_DLLS)
foreach(DLL ${MEGA_EXTRA_DLLS}) foreach(DLL ${LOVE_EXTRA_DLLS})
get_filename_component(DLL_NAME ${DLL} NAME) get_filename_component(DLL_NAME ${DLL} NAME)
message(STATUS "Extra DLL: ${DLL_NAME}") message(STATUS "Extra DLL: ${DLL_NAME}")
endforeach() endforeach()
install(FILES ${MEGA_EXTRA_DLLS} DESTINATION .) install(FILES ${LOVE_EXTRA_DLLS} DESTINATION .)
endif() endif()
# Dynamic runtime libs. # Dynamic runtime libs.
if(MEGA_MSVC_DLLS) if(LOVE_MSVC_DLLS)
foreach(DLL ${MEGA_MSVC_DLLS}) foreach(DLL ${LOVE_MSVC_DLLS})
get_filename_component(DLL_NAME ${DLL} NAME) get_filename_component(DLL_NAME ${DLL} NAME)
message(STATUS "Runtime DLL: ${DLL_NAME}") message(STATUS "Runtime DLL: ${DLL_NAME}")
endforeach() endforeach()
install(FILES ${MEGA_MSVC_DLLS} DESTINATION .) install(FILES ${LOVE_MSVC_DLLS} DESTINATION .)
endif() endif()
# Copy a text file from CMAKE_CURRENT_SOURCE_DIR to CMAKE_CURRENT_BINARY_DIR. # Copy a text file from CMAKE_CURRENT_SOURCE_DIR to CMAKE_CURRENT_BINARY_DIR.
@@ -1435,7 +1527,7 @@ set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/readme.md")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/license.txt") set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/license.txt")
set(CPACK_NSIS_EXECUTABLES_DIRECTORY .) set(CPACK_NSIS_EXECUTABLES_DIRECTORY .)
set(CPACK_NSIS_PACKAGE_NAME "LOVE") set(CPACK_NSIS_PACKAGE_NAME "LÖVE")
set(CPACK_NSIS_DISPLAY_NAME "LOVE ${LOVE_VERSION_STR}") set(CPACK_NSIS_DISPLAY_NAME "LOVE ${LOVE_VERSION_STR}")
set(CPACK_NSIS_MODIFY_PATH OFF) set(CPACK_NSIS_MODIFY_PATH OFF)
@@ -1456,7 +1548,7 @@ set(NSIS_MUI_ICON "${CMAKE_CURRENT_SOURCE_DIR}/extra/nsis\\\\love.ico")
set(NSIS_MUI_UNICON "${CMAKE_CURRENT_SOURCE_DIR}/extra/nsis\\\\love.ico") set(NSIS_MUI_UNICON "${CMAKE_CURRENT_SOURCE_DIR}/extra/nsis\\\\love.ico")
set(CPACK_NSIS_INSTALLER_MUI_ICON_CODE " set(CPACK_NSIS_INSTALLER_MUI_ICON_CODE "
!define MUI_WELCOMEPAGE_TITLE \\\"LOVE ${LOVE_VERSION_STR} Setup\\\" !define MUI_WELCOMEPAGE_TITLE \\\"LÖVE ${LOVE_VERSION_STR} Setup\\\"
!define MUI_WELCOMEFINISHPAGE_BITMAP \\\"${NSIS_LEFT_BMP}\\\" !define MUI_WELCOMEFINISHPAGE_BITMAP \\\"${NSIS_LEFT_BMP}\\\"
!define MUI_HEADERIMAGE_BITMAP \\\"${NSIS_TOP_BMP}\\\" !define MUI_HEADERIMAGE_BITMAP \\\"${NSIS_TOP_BMP}\\\"
!define MUI_ICON \\\"${NSIS_MUI_ICON}\\\" !define MUI_ICON \\\"${NSIS_MUI_ICON}\\\"
+4
View File
@@ -31,6 +31,8 @@ Released: N/A
* Added lovec.exe in Windows. It is the same as love.exe but built with the Console subsystem, so it always uses or provides a console. * Added lovec.exe in Windows. It is the same as love.exe but built with the Console subsystem, so it always uses or provides a console.
* Added 'shaderswitches' field to the table returned by love.graphics.getStats. * Added 'shaderswitches' field to the table returned by love.graphics.getStats.
* Added Quad:getTextureDimensions. * Added Quad:getTextureDimensions.
* Added PrismaticJoint:getAxis and WheelJoint:getAxis.
* Added 2-point version of love.physics.newRevoluteJoint.
* Fixed love on iOS 6. * Fixed love on iOS 6.
* Fixed os.execute always returning -1 on Linux. * Fixed os.execute always returning -1 on Linux.
@@ -44,6 +46,8 @@ Released: N/A
* Fixed the default shader improperly applying gamma correction to per-vertex colors when gamma correction is requested but not supported on OpenGL ES. * Fixed the default shader improperly applying gamma correction to per-vertex colors when gamma correction is requested but not supported on OpenGL ES.
* Fixed text coloring breaking because of an empty string. * Fixed text coloring breaking because of an empty string.
* Fixed large burst of particles when dramatically increasing the emission rate of a ParticleSystem. * 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.
* Improved performance of Channel methods by roughly 2x in many cases. * Improved performance of Channel methods by roughly 2x in many cases.
+1 -1
View File
@@ -11,7 +11,7 @@ init:
install: install:
# We need to install NSIS to create the packaged installer executable. # We need to install NSIS to create the packaged installer executable.
- choco install nsis -y - choco install nsis-unicode -y
# Move all woking directory items except `appveyor.yml` to `love` subdirectory. # Move all woking directory items except `appveyor.yml` to `love` subdirectory.
- md love - md love
+5 -1
View File
@@ -25,7 +25,11 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
#include <SDL2/SDL.h> #ifdef LOVE_MACOSX_SDL_DIRECT_INCLUDE
# include <SDL.h>
#else
# include <SDL2/SDL.h>
#endif
namespace love namespace love
{ {
+1
View File
@@ -129,6 +129,7 @@ void Text::addTextData(const TextData &t)
{ {
voffset = 0; voffset = 0;
draw_commands.clear(); draw_commands.clear();
text_data.clear();
} }
uploadVertices(vertices, voffset); uploadVertices(vertices, voffset);
+2 -2
View File
@@ -84,8 +84,8 @@ public:
**/ **/
Type getType() const; Type getType() const;
Body *getBodyA() const; virtual Body *getBodyA() const;
Body *getBodyB() const; virtual Body *getBodyB() const;
/** /**
* Gets the anchor positions of the Joint in world * Gets the anchor positions of the Joint in world
+10
View File
@@ -91,6 +91,16 @@ float MouseJoint::getDampingRatio() const
return joint->GetDampingRatio(); return joint->GetDampingRatio();
} }
Body *MouseJoint::getBodyA() const
{
return Joint::getBodyB();
}
Body *MouseJoint::getBodyB() const
{
return nullptr;
}
} // box2d } // box2d
} // physics } // physics
} // love } // love
+3
View File
@@ -95,6 +95,9 @@ public:
**/ **/
float getDampingRatio() const; float getDampingRatio() const;
virtual Body *getBodyA() const;
virtual Body *getBodyB() const;
private: private:
// The Box2D MouseJoint object. // The Box2D MouseJoint object.
b2MouseJoint *joint; b2MouseJoint *joint;
+2 -2
View File
@@ -223,9 +223,9 @@ MouseJoint *Physics::newMouseJoint(Body *body, float x, float y)
return new MouseJoint(body, x, y); return new MouseJoint(body, x, y);
} }
RevoluteJoint *Physics::newRevoluteJoint(Body *body1, Body *body2, float x, float y, bool collideConnected) RevoluteJoint *Physics::newRevoluteJoint(Body *body1, Body *body2, float xA, float yA, float xB, float yB, bool collideConnected)
{ {
return new RevoluteJoint(body1, body2, x, y, collideConnected); return new RevoluteJoint(body1, body2, xA, yA, xB, yB, collideConnected);
} }
PrismaticJoint *Physics::newPrismaticJoint(Body *body1, Body *body2, float xA, float yA, float xB, float yB, float ax, float ay, bool collideConnected) PrismaticJoint *Physics::newPrismaticJoint(Body *body1, Body *body2, float xA, float yA, float xB, float yB, float ax, float ay, bool collideConnected)
+5 -3
View File
@@ -171,11 +171,13 @@ public:
/** /**
* Creates a new RevoluteJoint connecting body1 with body2. * Creates a new RevoluteJoint connecting body1 with body2.
* @param x Anchor along the x-axis. (World coordinates) * @param xA Anchor for body 1 along the x-axis. (World coordinates)
* @param y Anchor along the y-axis. (World coordinates) * @param yA Anchor for body 1 along the y-axis. (World coordinates)
* @param xB Anchor for body 2 along the x-axis. (World coordinates)
* @param yB Anchor for body 2 along the y-axis. (World coordinates)
* @param collideConnected Whether the connected bodies should collide with each other. Defaults to false. * @param collideConnected Whether the connected bodies should collide with each other. Defaults to false.
**/ **/
RevoluteJoint *newRevoluteJoint(Body *body1, Body *body2, float x, float y, bool collideConnected); RevoluteJoint *newRevoluteJoint(Body *body1, Body *body2, float xA, float yA, float xB, float yB, bool collideConnected);
/** /**
* Creates a new PrismaticJoint connecting body1 with body2. * Creates a new PrismaticJoint connecting body1 with body2.
@@ -138,6 +138,12 @@ int PrismaticJoint::getLimits(lua_State *L)
return 2; return 2;
} }
int PrismaticJoint::getAxis(lua_State *L)
{
lua_pushnumber(L, joint->GetLocalAxisA().x);
lua_pushnumber(L, joint->GetLocalAxisA().y);
return 2;
}
} // box2d } // box2d
} // physics } // physics
@@ -134,6 +134,13 @@ public:
**/ **/
int getLimits(lua_State *L); int getLimits(lua_State *L);
/**
* Gets the axis unit vector, relative to body1.
* @returns The X component of the axis unit vector.
* @returns The Y component of the axis unit vector.
**/
int getAxis(lua_State *L);
private: private:
// The Box2D prismatic joint object. // The Box2D prismatic joint object.
+3 -2
View File
@@ -34,12 +34,13 @@ namespace physics
namespace box2d namespace box2d
{ {
RevoluteJoint::RevoluteJoint(Body *body1, Body *body2, float x, float y, bool collideConnected) RevoluteJoint::RevoluteJoint(Body *body1, Body *body2, float xA, float yA, float xB, float yB, bool collideConnected)
: Joint(body1, body2) : Joint(body1, body2)
, joint(NULL) , joint(NULL)
{ {
b2RevoluteJointDef def; b2RevoluteJointDef def;
def.Initialize(body1->body, body2->body, Physics::scaleDown(b2Vec2(x,y))); def.Initialize(body1->body, body2->body, Physics::scaleDown(b2Vec2(xA,yA)));
def.localAnchorB = body2->body->GetLocalPoint(Physics::scaleDown(b2Vec2(xB, yB)));
def.collideConnected = collideConnected; def.collideConnected = collideConnected;
joint = (b2RevoluteJoint *)createJoint(&def); joint = (b2RevoluteJoint *)createJoint(&def);
} }
+1 -1
View File
@@ -42,7 +42,7 @@ public:
/** /**
* Creates a new RevoluteJoint connecting body1 and body2. * Creates a new RevoluteJoint connecting body1 and body2.
**/ **/
RevoluteJoint(Body *body1, Body *body2, float x, float y, bool collideConnected); RevoluteJoint(Body *body1, Body *body2, float xA, float yA, float xB, float yB, bool collideConnected);
virtual ~RevoluteJoint(); virtual ~RevoluteJoint();
+6
View File
@@ -113,6 +113,12 @@ float WheelJoint::getSpringDampingRatio() const
return joint->GetSpringDampingRatio(); return joint->GetSpringDampingRatio();
} }
int WheelJoint::getAxis(lua_State *L)
{
lua_pushnumber(L, joint->GetLocalAxisA().x);
lua_pushnumber(L, joint->GetLocalAxisA().y);
return 2;
}
} // box2d } // box2d
} // physics } // physics
+7
View File
@@ -114,6 +114,13 @@ public:
**/ **/
float getSpringDampingRatio() const; float getSpringDampingRatio() const;
/**
* Gets the axis unit vector, relative to body1.
* @returns The X component of the axis unit vector.
* @returns The Y component of the axis unit vector.
**/
int getAxis(lua_State *L);
private: private:
// The Box2D wheel joint object. // The Box2D wheel joint object.
+17 -4
View File
@@ -215,12 +215,25 @@ int w_newRevoluteJoint(lua_State *L)
{ {
Body *body1 = luax_checkbody(L, 1); Body *body1 = luax_checkbody(L, 1);
Body *body2 = luax_checkbody(L, 2); Body *body2 = luax_checkbody(L, 2);
float x = (float)luaL_checknumber(L, 3); float xA = (float)luaL_checknumber(L, 3);
float y = (float)luaL_checknumber(L, 4); float yA = (float)luaL_checknumber(L, 4);
bool collideConnected = luax_optboolean(L, 5, false); float xB, yB;
bool collideConnected;
if (lua_gettop(L) >= 6)
{
xB = (float)luaL_checknumber(L, 5);
yB = (float)luaL_checknumber(L, 6);
collideConnected = luax_optboolean(L, 7, false);
}
else
{
xB = xA;
yB = yA;
collideConnected = luax_optboolean(L, 5, false);
}
RevoluteJoint *j; RevoluteJoint *j;
luax_catchexcept(L, [&]() { luax_catchexcept(L, [&]() {
j = instance()->newRevoluteJoint(body1, body2, x, y, collideConnected); j = instance()->newRevoluteJoint(body1, body2, xA, yA, xB, yB, collideConnected);
}); });
luax_pushtype(L, PHYSICS_REVOLUTE_JOINT_ID, j); luax_pushtype(L, PHYSICS_REVOLUTE_JOINT_ID, j);
j->release(); j->release();
@@ -164,6 +164,13 @@ int w_PrismaticJoint_getLimits(lua_State *L)
return t->getLimits(L); return t->getLimits(L);
} }
int w_PrismaticJoint_getAxis(lua_State *L)
{
PrismaticJoint *t = luax_checkprismaticjoint(L, 1);
lua_remove(L, 1);
return t->getAxis(L);
}
static const luaL_Reg w_PrismaticJoint_functions[] = static const luaL_Reg w_PrismaticJoint_functions[] =
{ {
{ "getJointTranslation", w_PrismaticJoint_getJointTranslation }, { "getJointTranslation", w_PrismaticJoint_getJointTranslation },
@@ -183,6 +190,7 @@ static const luaL_Reg w_PrismaticJoint_functions[] =
{ "getLowerLimit", w_PrismaticJoint_getLowerLimit }, { "getLowerLimit", w_PrismaticJoint_getLowerLimit },
{ "getUpperLimit", w_PrismaticJoint_getUpperLimit }, { "getUpperLimit", w_PrismaticJoint_getUpperLimit },
{ "getLimits", w_PrismaticJoint_getLimits }, { "getLimits", w_PrismaticJoint_getLimits },
{ "getAxis", w_PrismaticJoint_getAxis },
{ 0, 0 } { 0, 0 }
}; };
@@ -132,6 +132,13 @@ int w_WheelJoint_getSpringDampingRatio(lua_State *L)
return 1; return 1;
} }
int w_WheelJoint_getAxis(lua_State *L)
{
WheelJoint *t = luax_checkwheeljoint(L, 1);
lua_remove(L, 1);
return t->getAxis(L);
}
static const luaL_Reg w_WheelJoint_functions[] = static const luaL_Reg w_WheelJoint_functions[] =
{ {
{ "getJointTranslation", w_WheelJoint_getJointTranslation }, { "getJointTranslation", w_WheelJoint_getJointTranslation },
@@ -147,6 +154,7 @@ static const luaL_Reg w_WheelJoint_functions[] =
{ "getSpringFrequency", w_WheelJoint_getSpringFrequency }, { "getSpringFrequency", w_WheelJoint_getSpringFrequency },
{ "setSpringDampingRatio", w_WheelJoint_setSpringDampingRatio }, { "setSpringDampingRatio", w_WheelJoint_setSpringDampingRatio },
{ "getSpringDampingRatio", w_WheelJoint_getSpringDampingRatio }, { "getSpringDampingRatio", w_WheelJoint_getSpringDampingRatio },
{ "getAxis", w_WheelJoint_getAxis },
{ 0, 0 } { 0, 0 }
}; };