Skip to content

Commit 41516df

Browse files
committed
Update twbl
1 parent fb65b04 commit 41516df

File tree

4 files changed

+38
-14
lines changed

4 files changed

+38
-14
lines changed

CMakeLists.txt

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2815,22 +2815,30 @@ if(SERVER)
28152815
set(TWBL_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/src/external/TeeworldsBotLib)
28162816
include_directories(${TWBL_ROOT}/src)
28172817
FILE(GLOB TWBL_SRC
2818-
${TWBL_ROOT}/src/shared/*.cpp
2819-
${TWBL_ROOT}/src/shared/*.h
2818+
${TWBL_ROOT}/src/twbl/*/*.cpp
2819+
${TWBL_ROOT}/src/twbl/*/*.h
2820+
${TWBL_ROOT}/src/twbl/*.cpp
2821+
${TWBL_ROOT}/src/twbl/*.h
2822+
${TWBL_ROOT}/src/bots/*/*.cpp
2823+
${TWBL_ROOT}/src/bots/*/*.h
28202824
${TWBL_ROOT}/src/bots/*.cpp
28212825
${TWBL_ROOT}/src/bots/*.h
2826+
${TWBL_ROOT}/src/engines/*/*.cpp
2827+
${TWBL_ROOT}/src/engines/*/*.h
2828+
${TWBL_ROOT}/src/engines/*.cpp
2829+
${TWBL_ROOT}/src/engines/*.h
2830+
${TWBL_ROOT}/src/server/*.cpp
2831+
${TWBL_ROOT}/src/server/*.h
28222832
)
28232833

2824-
add_library(twbl_bottick_lite SHARED ${TWBL_SRC})
2825-
target_compile_options(twbl_bottick_lite PRIVATE -std=gnu++20)
2826-
28272834
set(SERVER_SRC ${SERVER_SRC} ${TWBL_SRC})
28282835
add_library(twbl_bottick SHARED
28292836
${GAME_SHARED}
28302837
${TWBL_SRC}
28312838
${GAME_GENERATED_SHARED})
28322839

28332840
target_compile_options(twbl_bottick PRIVATE -std=gnu++20)
2841+
target_compile_options(twbl_bottick PRIVATE -Wno-deprecated-enum-float-conversion) # c++20 arithmetic between floating-point type and enumeration type
28342842
target_compile_definitions(twbl_bottick PRIVATE TWBL_SHARED_OBJECT=1)
28352843

28362844
target_include_directories(twbl_bottick PRIVATE src)

src/external/TeeworldsBotLib

Submodule TeeworldsBotLib updated 51 files

src/game/server/entities/character.cpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "laser.h"
55
#include "pickup.h"
66
#include "projectile.h"
7+
#include "twbl/state.h"
78

89
#include <antibot/antibot_data.h>
910

@@ -21,10 +22,10 @@
2122
#include <game/server/score.h>
2223
#include <game/server/teams.h>
2324

24-
#include <bots/sample.h>
25+
#include <bots/sample/sample.h>
2526
#include <server/set_state.h>
26-
#include <shared/hotreload.h>
27-
#include <shared/types.h>
27+
#include <twbl/hotreload.h>
28+
#include <twbl/types.h>
2829

2930
MACRO_ALLOC_POOL_ID_IMPL(CCharacter, MAX_CLIENTS)
3031

@@ -776,21 +777,28 @@ void CCharacter::Tick()
776777
{
777778
if(GetPlayer()->GetCid() > 60)
778779
{
779-
CServerBotStateOut Bot;
780780
CServerBotStateIn State;
781+
CServerBotStateOut Bot;
781782

782783
TWBL::SetState(this, &State);
784+
State.m_GameTick = GameServer()->Server()->Tick();
783785
State.m_pCollision = Collision();
784786
State.m_ppPlayers = GameServer()->m_apPlayers;
787+
State.m_pCallbackCtx = &GameServer()->m_TwblCallbackCtx;
788+
789+
// nicer would be a member variable and not calling Init every tick
790+
static TWBL::CHotreloader s_Hotreloader;
791+
s_Hotreloader.Init("./libtwbl_bottick.so", "Follow");
785792

786-
static TWBL::CHotreloader Hotreloader("./libtwbl_bottick.so", "Follow");
787793
FTwbl_BotTick BotTick;
788-
void *pHandle = Hotreloader.LoadTick(&BotTick);
794+
void *pHandle = s_Hotreloader.LoadTick(&BotTick);
795+
796+
CTwblPersistentState *pPersistentState = &GameServer()->m_aTwblPersistentState[GetPlayer()->GetCid()];
789797

790798
if(pHandle)
791-
BotTick(&State, &Bot);
799+
BotTick(&State, &Bot, pPersistentState, sizeof(*pPersistentState));
792800
else
793-
Twbl_SampleTick(&State, &Bot);
801+
Twbl_SampleTick(&State, &Bot, pPersistentState, sizeof(*pPersistentState));
794802

795803
BotTick = nullptr;
796804
TWBL_SET_INPUT(m_SavedInput, Bot);

src/game/server/gamecontext.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
#include <game/mapbugs.h>
1313
#include <game/voting.h>
1414

15+
// twbl
16+
#include <server/ddnet_callback_ctx.h>
17+
#include <twbl/state.h>
18+
19+
#include "engine/shared/protocol.h"
1520
#include "eventhandler.h"
1621
#include "gameworld.h"
1722
#include "teehistorian.h"
@@ -624,6 +629,9 @@ class CGameContext : public IGameServer
624629
void OnSetAuthed(int ClientId, int Level) override;
625630

626631
void ResetTuning();
632+
633+
TWBL::CDDNetCallbackCtx m_TwblCallbackCtx;
634+
CTwblPersistentState m_aTwblPersistentState[MAX_CLIENTS];
627635
};
628636

629637
static inline bool CheckClientId(int ClientId)

0 commit comments

Comments
 (0)