Skip to content

Commit

Permalink
Add hot reloading support for collision code
Browse files Browse the repository at this point in the history
  • Loading branch information
ChillerDragon committed May 26, 2024
1 parent d42fd36 commit ccc8d67
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 5 deletions.
48 changes: 45 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ if(TARGET_OS STREQUAL "android")
find_package(Android)
endif()
find_package(ZLIB)
find_package(Crypto)
# find_package(Crypto)
find_package(Curl)
if(CLIENT AND VIDEORECORDER)
find_package(FFMPEG)
Expand Down Expand Up @@ -2621,7 +2621,7 @@ if(SERVER)
)

# twbl start
set(TWBL_ROOT src/external/TeeworldsBotLib)
set(TWBL_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/src/external/TeeworldsBotLib)
add_subdirectory(${TWBL_ROOT})
include_directories(${TWBL_ROOT}/src)
FILE(GLOB TWBL_SRC
Expand All @@ -2631,8 +2631,50 @@ if(SERVER)
${TWBL_ROOT}/src/bots/*.h
)

add_library(twbl_bottick SHARED ${TWBL_SRC})
add_library(twbl_bottick_lite SHARED ${TWBL_SRC})
set(SERVER_SRC ${SERVER_SRC} ${TWBL_SRC})
# set(SERVER_SRC ${SERVER_SRC}
# ${TWBL_ROOT}/src/shared/hotreload.cpp
# ${TWBL_ROOT}/src/shared/hotreload.h
# ${TWBL_ROOT}/src/shared/types.h
# ${TWBL_ROOT}/src/bots/base.cpp
# ${TWBL_ROOT}/src/bots/base.h
# )


add_library(twbl_bottick SHARED
${SERVER_SRC}
${TWBL_SRC}
${ANTIBOT_SRC}
${GAME_GENERATED_SHARED}
src/base/hash_ctxt.h
src/engine/external/md5/md5.h)

# add_library(md5 EXCLUDE_FROM_ALL OBJECT ${DEP_MD5_SRC})
target_link_libraries(twbl_bottick
PRIVATE
${CRYPTO_LIBRARIES}
${DEP_MD5_SRC}
PUBLIC
ssl
)

target_include_directories(twbl_bottick SYSTEM PRIVATE ${CRYPTO_INCLUDE_DIRS})

target_compile_definitions(twbl_bottick PRIVATE TWBL_SHARED_OBJECT=1)

target_include_directories(twbl_bottick PRIVATE src)
target_include_directories(twbl_bottick PRIVATE ${PROJECT_BINARY_DIR}/src)
target_include_directories(twbl_bottick PRIVATE src/rust-bridge)
add_cxx_compiler_flag_if_supported(OUR_FLAGS_LINK -rdynamic)
add_cxx_compiler_flag_if_supported(OUT_FLAGS_LINK -fno-gnu-unique)
add_cxx_compiler_flag_if_supported(OUT_FLAGS_LINK -fPIC)
add_cxx_compiler_flag_if_supported(OUT_FLAGS -fno-gnu-unique)
add_cxx_compiler_flag_if_supported(OUT_FLAGS -fPIC)
target_compile_options(twbl_bottick PUBLIC -fPIC)

# set_own_rpath(game-server)

# twbl end

# Target
Expand Down
1 change: 1 addition & 0 deletions src/engine/shared/config_variables.h
Original file line number Diff line number Diff line change
Expand Up @@ -680,3 +680,4 @@ MACRO_CONFIG_INT(ClVideoRecorderFPS, cl_video_recorder_fps, 60, 1, 1000, CFGFLAG
/*
* Add config variables for mods below this comment to avoid merge conflicts.
*/

10 changes: 9 additions & 1 deletion src/game/server/entities/character.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
/* If you are missing that file, acquire a complete release at teeworlds.com. */
#include "character.h"
#include "base/system.h"
#include "laser.h"
#include "pickup.h"
#include "projectile.h"

#include <antibot/antibot_data.h>

#include <dlfcn.h>
#include <engine/antibot.h>
#include <engine/shared/config.h>

Expand Down Expand Up @@ -770,10 +772,16 @@ void CCharacter::Tick()
if(pHandle)
{
BotTick(&State, &Bot);
dlclose(pHandle);
int Err = dlclose(pHandle);
if(Err) {
dbg_msg("twbl", "failed to close err=%d", Err);
}
dlerror();
}
else
Twbl_SampleTick(&State, &Bot);

BotTick = nullptr;

m_SavedInput.m_Direction = Bot.m_Direction;

Expand Down

0 comments on commit ccc8d67

Please sign in to comment.