Skip to content

Commit

Permalink
Update for new custom boost pads api
Browse files Browse the repository at this point in the history
  • Loading branch information
mtheall committed Jun 5, 2024
2 parents b3524da + 0da0546 commit 1e424b0
Show file tree
Hide file tree
Showing 17 changed files with 637 additions and 278 deletions.
114 changes: 105 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,110 @@
cmake_minimum_required (VERSION 3.8)
cmake_minimum_required(VERSION 3.17.0)

project("RocketSim")
project(RocketSim VERSION 2.1.0)

# Add all headers and code files
file(GLOB_RECURSE FILES_ROCKETSIM "${PROJECT_SOURCE_DIR}/src/*.cpp" "${PROJECT_SOURCE_DIR}/src/*.h")
include(GNUInstallDirs)

# Only include bullet headers when using MSVC, otherwise just code files
file(GLOB_RECURSE FILES_BULLET "${PROJECT_SOURCE_DIR}/libsrc/bullet3-3.24/*.cpp" "${PROJECT_SOURCE_DIR}/libsrc/bullet3-3.24/*.h")
include(CheckIPOSupported)
check_ipo_supported(RESULT IPO_SUPPORTED)

add_library(RocketSim ${FILES_ROCKETSIM} ${FILES_BULLET})
file(GLOB_RECURSE ROCKETSIM_BULLET3_SOURCES libsrc/bullet3-3.24/*.cpp)

set_target_properties(RocketSim PROPERTIES LINKER_LANGUAGE CXX)
set_target_properties(RocketSim PROPERTIES CXX_STANDARD 20)
file(GLOB_RECURSE ROCKETSIM_SOURCES src/*.cpp)

add_library(RocketSim-static STATIC)
target_sources(RocketSim-static PRIVATE ${ROCKETSIM_BULLET3_SOURCES} ${ROCKETSIM_SOURCES})

if(NOT NINTENDO_SWITCH AND NOT NINTENDO_3DS)
add_library(RocketSim SHARED)
target_sources(RocketSim PRIVATE ${ROCKETSIM_BULLET3_SOURCES} ${ROCKETSIM_SOURCES})
endif()

foreach(ROCKETSIM_LIBRARY RocketSim RocketSim-static)
if((${ROCKETSIM_LIBRARY} STREQUAL "RocketSim") AND (NINTENDO_SWITCH OR NINTENDO_3DS))
continue()
endif()

if(IPO_SUPPORTED)
set_target_properties(${ROCKETSIM_LIBRARY} PROPERTIES
INTERPROCEDURAL_OPTIMIZATION TRUE
INTERPROCEDURAL_OPTIMIZATION_DEBUG FALSE
INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE
INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO TRUE
INTERPROCEDURAL_OPTIMIZATION_MINSIZEREL TRUE
)
endif()

target_compile_features(${ROCKETSIM_LIBRARY} PRIVATE cxx_std_20)

if(MSVC)
target_compile_options(${ROCKETSIM_LIBRARY} PUBLIC /arch:AVX2)
target_compile_definitions(${ROCKETSIM_LIBRARY} PUBLIC _USE_MATH_DEFINES)
elseif(NOT NINTENDO_SWITCH AND NOT NINTENDO_3DS)
target_compile_options(${ROCKETSIM_LIBRARY} PUBLIC -msse4.1)
#target_compile_options(${ROCKETSIM_LIBRARY} PUBLIC --coverage)
#target_link_options(${ROCKETSIM_LIBRARY} PUBLIC --coverage)
target_compile_options(${ROCKETSIM_LIBRARY} PUBLIC -fno-omit-frame-pointer)
target_link_options(${ROCKETSIM_LIBRARY} PUBLIC -fno-omit-frame-pointer)
target_compile_options(${ROCKETSIM_LIBRARY} PUBLIC -Wno-stringop-overflow -Wno-volatile)
target_link_options(${ROCKETSIM_LIBRARY} PUBLIC -Wno-stringop-overflow -Wno-volatile)
#target_compile_options(${ROCKETSIM_LIBRARY} PUBLIC -Wsuggest-override -Werror)
target_compile_options(${ROCKETSIM_LIBRARY} PUBLIC -Wsuggest-final-types -Wsuggest-final-methods)
endif()

set_target_properties(${ROCKETSIM_LIBRARY} PROPERTIES C_VISIBILITY_PRESET hidden)
set_target_properties(${ROCKETSIM_LIBRARY} PROPERTIES CXX_VISIBILITY_PRESET hidden)

target_include_directories(${ROCKETSIM_LIBRARY} PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/libsrc/bullet3-3.24>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
endforeach()

# only export explicitly
if(NOT NINTENDO_SWITCH AND NOT NINTENDO_3DS)
target_compile_definitions(RocketSim PRIVATE ROCKETSIM_EXPORTS)
endif()
target_compile_definitions(RocketSim-static PUBLIC ROCKETSIM_STATIC)




if(NOT NINTENDO_SWITCH AND NOT NINTENDO_3DS)
###########################
### Example application ###
###########################

#find_package(RocketSim REQUIRED)
find_package(Eigen3 REQUIRED)
add_executable(RocketSimTest)
target_compile_features(RocketSimTest PRIVATE cxx_std_20)

target_sources(RocketSimTest PRIVATE test.cpp)

# choose shared or static lib here
#target_link_libraries(RocketSimTest PRIVATE RocketSim)
target_link_libraries(RocketSimTest PRIVATE RocketSim-static Eigen3::Eigen)

if(IPO_SUPPORTED)
set_target_properties(RocketSimTest PROPERTIES
INTERPROCEDURAL_OPTIMIZATION TRUE
INTERPROCEDURAL_OPTIMIZATION_DEBUG FALSE
INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE
INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO TRUE
INTERPROCEDURAL_OPTIMIZATION_MINSIZEREL TRUE
)
endif()

set_target_properties(RocketSimTest PROPERTIES C_VISIBILITY_PRESET hidden)
set_target_properties(RocketSimTest PROPERTIES CXX_VISIBILITY_PRESET hidden)
endif()

if(NINTENDO_3DS)
add_subdirectory(visualize-3ds)
else()
add_subdirectory(visualize)
#add_subdirectory(visualize-vk)
#add_subdirectory(train_ppo)
#add_subdirectory(train_ppo2)
endif()
7 changes: 4 additions & 3 deletions python-mtheall/Arena.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ auto const hoopsBoostMapping = buildBoostMapping (hoopsIndexMapping);

int getBoostPadIndex (RocketSim::BoostPad const *pad_, std::unordered_map<std::uint64_t, unsigned> const &map_) noexcept
{
auto const it = map_.find (makeKey (pad_->pos.x, pad_->pos.y));
auto const it = map_.find (makeKey (pad_->config.pos.x, pad_->config.pos.y));
if (it == std::end (map_))
return -1;

Expand All @@ -145,7 +145,7 @@ std::unordered_map<std::uint64_t, unsigned> const &getBoostMapping (RocketSim::G

bool ensureBoostPadByIndex (RocketSim::Python::Arena *arena_) noexcept
{
if (arena_->arena->GetArenaConfig ().customBoostPads)
if (arena_->arena->GetArenaConfig ().useCustomBoostPads)
return true;

if (arena_->boostPads->empty ())
Expand Down Expand Up @@ -1790,7 +1790,8 @@ PyObject *Arena::CloneInto (Arena *self_, PyObject *args_, PyObject *kwds_) noex

for (unsigned i = 0; i < padsCount; ++i)
{
if (padsB[i]->pad->isBig != padsA[i]->pad->isBig || padsB[i]->pad->pos != padsA[i]->pad->pos)
if (padsB[i]->pad->config.isBig != padsA[i]->pad->config.isBig ||
padsB[i]->pad->config.pos != padsA[i]->pad->config.pos)
{
PyErr_SetString (PyExc_ValueError, "Boost pad mismatch");
return nullptr;
Expand Down
Loading

0 comments on commit 1e424b0

Please sign in to comment.