mirror of
https://github.com/love2d/love.git
synced 2026-08-21 21:15:09 +02:00
Merge default into minor
--HG-- branch : minor
This commit is contained in:
+159
-67
@@ -27,16 +27,11 @@ cmake_minimum_required(VERSION 2.8)
|
||||
|
||||
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_LIB_NAME liblove)
|
||||
|
||||
set (CMAKE_CXX_STANDARD 11)
|
||||
|
||||
if(MSVC)
|
||||
set(LOVE_CONSOLE_EXE_NAME lovec)
|
||||
endif()
|
||||
@@ -53,6 +48,9 @@ option(LOVE_JIT "Use LuaJIT" TRUE)
|
||||
option(LOVE_MPG123 "Use mpg123" TRUE)
|
||||
|
||||
if(LOVE_JIT)
|
||||
if(APPLE)
|
||||
message(FATAL_ERROR "JIT not supported yet on Mac. Please use -DLOVE_JIT=0.")
|
||||
endif()
|
||||
message(STATUS "LuaJIT: Enabled")
|
||||
else()
|
||||
message(STATUS "LuaJIT: Disabled")
|
||||
@@ -66,16 +64,117 @@ message(STATUS "Target platform: ${LOVE_TARGET_PLATFORM}")
|
||||
|
||||
find_package(OpenGL)
|
||||
|
||||
if(${LOVE_JIT})
|
||||
set(MEGA_LUA ${MEGA_LUAJIT_LIB})
|
||||
set(MEGA_EXTRA_INCLUDE ${MEGA_LUAJIT_INCLUDE})
|
||||
set(MEGA_EXTRA_DLLS ${MEGA_LUAJIT_DLL})
|
||||
set(MEGA_EXTRA_DEPENDECIES luajit)
|
||||
if(MEGA)
|
||||
# LOVE_MSVC_DLLS contains runtime DLLs that should be bundled with the love
|
||||
# binary (in e.g. the installer). Example: msvcp140.dll.
|
||||
set(LOVE_MSVC_DLLS ${MEGA_MSVC_DLLS})
|
||||
|
||||
# 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(MEGA_LUA ${MEGA_LUA51})
|
||||
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()
|
||||
message(FATAL_ERROR "
|
||||
It is currently only possible to build with megasource on Windows.
|
||||
Please see http://bitbucket.org/rude/megasource
|
||||
")
|
||||
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
|
||||
@@ -121,6 +220,12 @@ set(LOVE_SRC_COMMON
|
||||
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})
|
||||
|
||||
#
|
||||
@@ -1034,7 +1139,7 @@ set(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)
|
||||
|
||||
#
|
||||
@@ -1112,6 +1217,12 @@ if(MSVC)
|
||||
src/libraries/luasocket/libluasocket/wsocket.c
|
||||
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()
|
||||
|
||||
set(LOVE_SRC_3P_LUASOCKET
|
||||
@@ -1120,7 +1231,7 @@ set(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
|
||||
@@ -1133,7 +1244,7 @@ set(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
|
||||
@@ -1264,40 +1375,10 @@ include_directories(
|
||||
src
|
||||
src/libraries
|
||||
src/modules
|
||||
${MEGA_EXTRA_INCLUDE}
|
||||
${LOVE_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
# SDL2 links with some DirectX libraries, and we apparently also
|
||||
# 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}
|
||||
)
|
||||
link_directories(${LOVE_LINK_DIRS})
|
||||
|
||||
set(LOVE_RC)
|
||||
|
||||
@@ -1316,8 +1397,8 @@ endif()
|
||||
add_library(${LOVE_LIB_NAME} SHARED ${LOVE_LIB_SRC} ${LOVE_RC})
|
||||
target_link_libraries(${LOVE_LIB_NAME} ${LOVE_LINK_LIBRARIES} ${LOVE_3P})
|
||||
|
||||
if(MEGA_EXTRA_DEPENDECIES)
|
||||
add_dependencies(${LOVE_LIB_NAME} ${MEGA_EXTRA_DEPENDECIES})
|
||||
if(LOVE_EXTRA_DEPENDECIES)
|
||||
add_dependencies(${LOVE_LIB_NAME} ${LOVE_EXTRA_DEPENDECIES})
|
||||
endif()
|
||||
|
||||
if(MSVC)
|
||||
@@ -1336,20 +1417,31 @@ if(MSVC)
|
||||
target_link_libraries(${LOVE_CONSOLE_EXE_NAME} ${LOVE_LIB_NAME})
|
||||
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
|
||||
# running/debugging the binary will not work from inside VS.
|
||||
if(LOVE_MPG123)
|
||||
add_move_dll(love ${MEGA_MPEG123})
|
||||
if(LOVE_MOVE_DLLS)
|
||||
foreach(DLL ${LOVE_MOVE_DLLS})
|
||||
post_step_move_dll(love ${DLL})
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
add_move_dll(love ${MEGA_SDL2})
|
||||
add_move_dll(love ${MEGA_OPENAL})
|
||||
|
||||
if(LOVE_JIT)
|
||||
add_move_file(love ${MEGA_LUAJIT_DLL})
|
||||
else()
|
||||
add_move_dll(love ${MEGA_LUA51})
|
||||
if (NOT MSVC)
|
||||
return()
|
||||
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 .)
|
||||
|
||||
# Extra DLLs.
|
||||
if(MEGA_EXTRA_DLLS)
|
||||
foreach(DLL ${MEGA_EXTRA_DLLS})
|
||||
if(LOVE_EXTRA_DLLS)
|
||||
foreach(DLL ${LOVE_EXTRA_DLLS})
|
||||
get_filename_component(DLL_NAME ${DLL} NAME)
|
||||
message(STATUS "Extra DLL: ${DLL_NAME}")
|
||||
endforeach()
|
||||
install(FILES ${MEGA_EXTRA_DLLS} DESTINATION .)
|
||||
install(FILES ${LOVE_EXTRA_DLLS} DESTINATION .)
|
||||
endif()
|
||||
|
||||
# Dynamic runtime libs.
|
||||
if(MEGA_MSVC_DLLS)
|
||||
foreach(DLL ${MEGA_MSVC_DLLS})
|
||||
if(LOVE_MSVC_DLLS)
|
||||
foreach(DLL ${LOVE_MSVC_DLLS})
|
||||
get_filename_component(DLL_NAME ${DLL} NAME)
|
||||
message(STATUS "Runtime DLL: ${DLL_NAME}")
|
||||
endforeach()
|
||||
install(FILES ${MEGA_MSVC_DLLS} DESTINATION .)
|
||||
install(FILES ${LOVE_MSVC_DLLS} DESTINATION .)
|
||||
endif()
|
||||
|
||||
# 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_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_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(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_HEADERIMAGE_BITMAP \\\"${NSIS_TOP_BMP}\\\"
|
||||
!define MUI_ICON \\\"${NSIS_MUI_ICON}\\\"
|
||||
|
||||
@@ -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 'shaderswitches' field to the table returned by love.graphics.getStats.
|
||||
* Added Quad:getTextureDimensions.
|
||||
* Added PrismaticJoint:getAxis and WheelJoint:getAxis.
|
||||
* Added 2-point version of love.physics.newRevoluteJoint.
|
||||
|
||||
* Fixed love on iOS 6.
|
||||
* 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 text coloring breaking because of an empty string.
|
||||
* 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.
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ init:
|
||||
|
||||
install:
|
||||
# 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.
|
||||
- md love
|
||||
|
||||
@@ -25,7 +25,11 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
#ifdef LOVE_MACOSX_SDL_DIRECT_INCLUDE
|
||||
# include <SDL.h>
|
||||
#else
|
||||
# include <SDL2/SDL.h>
|
||||
#endif
|
||||
|
||||
namespace love
|
||||
{
|
||||
|
||||
@@ -129,6 +129,7 @@ void Text::addTextData(const TextData &t)
|
||||
{
|
||||
voffset = 0;
|
||||
draw_commands.clear();
|
||||
text_data.clear();
|
||||
}
|
||||
|
||||
uploadVertices(vertices, voffset);
|
||||
|
||||
@@ -84,8 +84,8 @@ public:
|
||||
**/
|
||||
Type getType() const;
|
||||
|
||||
Body *getBodyA() const;
|
||||
Body *getBodyB() const;
|
||||
virtual Body *getBodyA() const;
|
||||
virtual Body *getBodyB() const;
|
||||
|
||||
/**
|
||||
* Gets the anchor positions of the Joint in world
|
||||
|
||||
@@ -91,6 +91,16 @@ float MouseJoint::getDampingRatio() const
|
||||
return joint->GetDampingRatio();
|
||||
}
|
||||
|
||||
Body *MouseJoint::getBodyA() const
|
||||
{
|
||||
return Joint::getBodyB();
|
||||
}
|
||||
|
||||
Body *MouseJoint::getBodyB() const
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
@@ -95,6 +95,9 @@ public:
|
||||
**/
|
||||
float getDampingRatio() const;
|
||||
|
||||
virtual Body *getBodyA() const;
|
||||
virtual Body *getBodyB() const;
|
||||
|
||||
private:
|
||||
// The Box2D MouseJoint object.
|
||||
b2MouseJoint *joint;
|
||||
|
||||
@@ -223,9 +223,9 @@ MouseJoint *Physics::newMouseJoint(Body *body, float x, float 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)
|
||||
|
||||
@@ -171,11 +171,13 @@ public:
|
||||
|
||||
/**
|
||||
* Creates a new RevoluteJoint connecting body1 with body2.
|
||||
* @param x Anchor along the x-axis. (World coordinates)
|
||||
* @param y Anchor along the y-axis. (World coordinates)
|
||||
* @param xA Anchor for body 1 along the x-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.
|
||||
**/
|
||||
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.
|
||||
|
||||
@@ -138,6 +138,12 @@ int PrismaticJoint::getLimits(lua_State *L)
|
||||
return 2;
|
||||
}
|
||||
|
||||
int PrismaticJoint::getAxis(lua_State *L)
|
||||
{
|
||||
lua_pushnumber(L, joint->GetLocalAxisA().x);
|
||||
lua_pushnumber(L, joint->GetLocalAxisA().y);
|
||||
return 2;
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
|
||||
@@ -134,6 +134,13 @@ public:
|
||||
**/
|
||||
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:
|
||||
|
||||
// The Box2D prismatic joint object.
|
||||
|
||||
@@ -34,12 +34,13 @@ namespace physics
|
||||
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(NULL)
|
||||
{
|
||||
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;
|
||||
joint = (b2RevoluteJoint *)createJoint(&def);
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ public:
|
||||
/**
|
||||
* 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();
|
||||
|
||||
|
||||
@@ -113,6 +113,12 @@ float WheelJoint::getSpringDampingRatio() const
|
||||
return joint->GetSpringDampingRatio();
|
||||
}
|
||||
|
||||
int WheelJoint::getAxis(lua_State *L)
|
||||
{
|
||||
lua_pushnumber(L, joint->GetLocalAxisA().x);
|
||||
lua_pushnumber(L, joint->GetLocalAxisA().y);
|
||||
return 2;
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
|
||||
@@ -114,6 +114,13 @@ public:
|
||||
**/
|
||||
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:
|
||||
|
||||
// The Box2D wheel joint object.
|
||||
|
||||
@@ -215,12 +215,25 @@ int w_newRevoluteJoint(lua_State *L)
|
||||
{
|
||||
Body *body1 = luax_checkbody(L, 1);
|
||||
Body *body2 = luax_checkbody(L, 2);
|
||||
float x = (float)luaL_checknumber(L, 3);
|
||||
float y = (float)luaL_checknumber(L, 4);
|
||||
bool collideConnected = luax_optboolean(L, 5, false);
|
||||
float xA = (float)luaL_checknumber(L, 3);
|
||||
float yA = (float)luaL_checknumber(L, 4);
|
||||
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;
|
||||
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);
|
||||
j->release();
|
||||
|
||||
@@ -164,6 +164,13 @@ int w_PrismaticJoint_getLimits(lua_State *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[] =
|
||||
{
|
||||
{ "getJointTranslation", w_PrismaticJoint_getJointTranslation },
|
||||
@@ -183,6 +190,7 @@ static const luaL_Reg w_PrismaticJoint_functions[] =
|
||||
{ "getLowerLimit", w_PrismaticJoint_getLowerLimit },
|
||||
{ "getUpperLimit", w_PrismaticJoint_getUpperLimit },
|
||||
{ "getLimits", w_PrismaticJoint_getLimits },
|
||||
{ "getAxis", w_PrismaticJoint_getAxis },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
|
||||
@@ -132,6 +132,13 @@ int w_WheelJoint_getSpringDampingRatio(lua_State *L)
|
||||
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[] =
|
||||
{
|
||||
{ "getJointTranslation", w_WheelJoint_getJointTranslation },
|
||||
@@ -147,6 +154,7 @@ static const luaL_Reg w_WheelJoint_functions[] =
|
||||
{ "getSpringFrequency", w_WheelJoint_getSpringFrequency },
|
||||
{ "setSpringDampingRatio", w_WheelJoint_setSpringDampingRatio },
|
||||
{ "getSpringDampingRatio", w_WheelJoint_getSpringDampingRatio },
|
||||
{ "getAxis", w_WheelJoint_getAxis },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user