Skip to content

Commit 12dd65d

Browse files
committed
Various updates
Get server port from env Add benchmark using RocketSim Add ExampleBot toml General system stability improvements to enhance the user’s experience
1 parent 3cef43a commit 12dd65d

File tree

14 files changed

+1003
-137
lines changed

14 files changed

+1003
-137
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
.vscode/
22
build/
3+
4+
ExampleBot/ExampleBot
5+
ExampleBot/ExampleBot.exe
6+
ExampleBot/ExampleBot-Launcher
7+
ExampleBot/ExampleBot-Launcher.exe

CMakeLists.txt

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,70 @@ cmake_minimum_required(VERSION 3.22)
22

33
project(RLBotCPP VERSION 2.0.0)
44

5+
option(RLBOT_CPP_ENABLE_LTO "Enable RLBotCPP link-time optimization" ON)
6+
option(RLBOT_CPP_ENABLE_TRACY "Enable tracy profiler" OFF)
7+
8+
include(CheckIPOSupported)
9+
check_ipo_supported(RESULT LTO_SUPPORTED)
10+
11+
include(FetchContent)
12+
13+
FetchContent_Declare(flatbuffers
14+
GIT_REPOSITORY https://github.com/google/flatbuffers.git
15+
GIT_TAG v24.3.25
16+
)
17+
FetchContent_Populate(flatbuffers)
18+
19+
FetchContent_Declare(flatbuffers_schema
20+
GIT_REPOSITORY https://github.com/RLBot/flatbuffers-schema.git
21+
GIT_TAG a01a99dedbe9f7b58e3f91191dbd20e90c476d84
22+
)
23+
FetchContent_Populate(flatbuffers_schema)
24+
25+
FetchContent_Declare(tracy
26+
GIT_REPOSITORY https://github.com/wolfpld/tracy.git
27+
GIT_TAG v0.11.1
28+
)
29+
FetchContent_Populate(tracy)
30+
31+
if(LINUX)
32+
include(ProcessorCount)
33+
ProcessorCount(NPROC)
34+
35+
FetchContent_Declare(liburing
36+
GIT_REPOSITORY https://github.com/axboe/liburing.git
37+
GIT_TAG liburing-2.7
38+
)
39+
FetchContent_Populate(liburing)
40+
41+
execute_process(
42+
COMMAND ./configure
43+
WORKING_DIRECTORY ${liburing_SOURCE_DIR}
44+
)
45+
46+
execute_process(
47+
COMMAND make -j ${NPROC} library
48+
WORKING_DIRECTORY ${liburing_SOURCE_DIR}
49+
)
50+
endif()
51+
52+
find_program(FLATC flatc REQUIRED NO_DEFAULT_PATH PATHS ${flatbuffers_schema_SOURCE_DIR})
53+
54+
add_custom_command(
55+
OUTPUT
56+
${CMAKE_CURRENT_BINARY_DIR}/rlbot_generated.h
57+
COMMAND
58+
${FLATC} --cpp --gen-object-api --gen-all --cpp-std c++17 ${flatbuffers_schema_SOURCE_DIR}/rlbot.fbs
59+
DEPENDS
60+
${flatbuffers_schema_SOURCE_DIR}/comms.fbs
61+
${flatbuffers_schema_SOURCE_DIR}/gamestate.fbs
62+
${flatbuffers_schema_SOURCE_DIR}/matchstart.fbs
63+
${flatbuffers_schema_SOURCE_DIR}/rlbot.fbs
64+
${flatbuffers_schema_SOURCE_DIR}/rendering.fbs
65+
)
66+
67+
add_custom_target(rlbot-generated DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/rlbot_generated.h)
68+
569
add_subdirectory(library)
70+
add_subdirectory(benchmark)
671
add_subdirectory(ExampleBot)

ExampleBot/CMakeLists.txt

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ cmake_minimum_required(VERSION 3.22)
22

33
project(ExampleBot VERSION 1.0.0)
44

5-
include(CheckIPOSupported)
6-
check_ipo_supported(RESULT ENABLE_LTO)
7-
85
###########################################################################
96
add_executable(${PROJECT_NAME})
107

@@ -16,15 +13,19 @@ target_sources(${PROJECT_NAME} PRIVATE
1613
main.cpp
1714
)
1815

19-
if(ENABLE_LTO)
16+
if(LTO_SUPPORTED)
2017
set_target_properties(${PROJECT_NAME} PROPERTIES
21-
INTERPROCEDURAL_OPTIMIZATION TRUE
18+
INTERPROCEDURAL_OPTIMIZATION $<BOOL:${RLBOT_CPP_ENABLE_LTO}>
2219
INTERPROCEDURAL_OPTIMIZATION_DEBUG FALSE
2320
)
2421
endif()
2522

2623
target_link_libraries(${PROJECT_NAME} PRIVATE RLBotCPP-static)
2724

25+
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
26+
COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:${PROJECT_NAME}> ${CMAKE_CURRENT_SOURCE_DIR}
27+
)
28+
2829
###########################################################################
2930
add_executable(${PROJECT_NAME}-Launcher)
3031

@@ -36,11 +37,13 @@ target_sources(${PROJECT_NAME}-Launcher PRIVATE
3637

3738
target_link_libraries(${PROJECT_NAME}-Launcher PRIVATE RLBotCPP-static)
3839

39-
if(ENABLE_LTO)
40+
if(LTO_SUPPORTED)
4041
set_target_properties(${PROJECT_NAME}-Launcher PROPERTIES
41-
INTERPROCEDURAL_OPTIMIZATION TRUE
42+
INTERPROCEDURAL_OPTIMIZATION $<BOOL:${RLBOT_CPP_ENABLE_LTO}>
4243
INTERPROCEDURAL_OPTIMIZATION_DEBUG FALSE
4344
)
4445
endif()
4546

46-
47+
add_custom_command(TARGET ${PROJECT_NAME}-Launcher POST_BUILD
48+
COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:${PROJECT_NAME}-Launcher> ${CMAKE_CURRENT_SOURCE_DIR}
49+
)

ExampleBot/ExampleBot.bot.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[settings]
2+
name = "ExampleBotCPP"
3+
loadout_file = ""
4+
root_dir = ""
5+
run_command = "ExampleBot.exe"
6+
run_command_linux = "./ExampleBot"
7+
agent_id = "RLBotCPP/ExampleBot"
8+
hivemind = true
9+
10+
[details]
11+
description = "Made possible by RLBot"
12+
fun_fact = "This is a test bot"
13+
source_link = "https://github.com/mtheall/RLBotCPP"
14+
developer = "BotMaker"
15+
language = "C++"
16+
tags = []

ExampleBot/launcher.cpp

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,27 @@
11
#include <rlbot/BotManager.h>
22

33
#include <cstdio>
4+
#include <cstdlib>
5+
6+
#ifdef _WIN32
7+
#include <direct.h>
8+
#else
9+
#include <unistd.h>
10+
#endif
411

512
#define USE_HIVEMIND true
613

714
int main (int argc_, char *argv_[])
815
{
16+
// MSVC and glibc support dynamically allocated cwd
17+
// If you use a different libc this won't work!
18+
auto const cwd = ::getcwd (nullptr, 0);
19+
if (!cwd)
20+
{
21+
std::fprintf (stderr, "Failed to get current directory\n");
22+
return EXIT_FAILURE;
23+
}
24+
925
if (argc_ <= 2)
1026
{
1127
std::fprintf (stderr, "Usage: %s <addr> <port>\n", argv_[0]);
@@ -17,6 +33,7 @@ int main (int argc_, char *argv_[])
1733

1834
/// map names at https://github.com/VirxEC/python-interface/blob/master/rlbot/utils/maps.py
1935
rlbot::flat::MatchSettingsT ms{};
36+
ms.auto_start_bots = true;
2037
ms.game_map_upk = "Stadium_P";
2138
ms.game_mode = rlbot::flat::GameMode::Soccer;
2239
ms.skip_replays = true;
@@ -25,17 +42,25 @@ int main (int argc_, char *argv_[])
2542
ms.enable_rendering = true;
2643
ms.enable_state_setting = true;
2744

28-
for (unsigned i = 0; i < 1; ++i)
45+
for (unsigned i = 0; i < 4; ++i)
2946
{
3047
auto player = std::make_unique<rlbot::flat::PlayerConfigurationT> ();
3148
player->variety.Set (rlbot::flat::RLBotT{});
3249
player->team = i % 2;
50+
player->root_dir = cwd;
51+
#ifdef _WIN32
52+
player->run_command = "ExampleBot.exe";
53+
#else
54+
player->run_command = "./ExampleBot";
55+
#endif
3356
player->name = "ExampleBot";
3457
player->agent_id = "RLBotCPP/ExampleBot";
3558
player->hivemind = USE_HIVEMIND;
3659
ms.player_configurations.emplace_back (std::move (player));
3760
}
3861

62+
std::free (cwd);
63+
3964
if (!rlbot::BotManagerBase::startMatch (host, port, ms))
4065
return EXIT_FAILURE;
4166

ExampleBot/main.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,29 @@ int main (int argc_, char *argv_[])
2525
{
2626
TracyNoop;
2727

28-
if (argc_ <= 2)
29-
{
30-
std::fprintf (stderr, "Usage: %s <addr> <port>\n", argv_[0]);
31-
return EXIT_FAILURE;
32-
}
33-
3428
auto const agentId = std::getenv ("RLBOT_AGENT_ID");
3529
if (!agentId || std::strlen (agentId) == 0)
3630
{
3731
std::fprintf (stderr, "Missing environment variable RLBOT_AGENT_ID\n");
3832
return EXIT_FAILURE;
3933
}
4034

41-
auto const host = argv_[1];
42-
auto const port = argv_[2];
35+
auto const serverPort = [] () -> char const * {
36+
auto const env = std::getenv ("RLBOT_SERVER_PORT");
37+
if (env)
38+
return env;
39+
return "23234";
40+
}();
41+
42+
auto const host = argc_ > 1 ? argv_[1] : "127.0.0.1";
43+
auto const port = argc_ > 2 ? argv_[2] : serverPort;
4344

4445
rlbot::BotManager<ExampleBot> manager;
4546
if (!manager.run (host, port, agentId, true))
47+
{
48+
std::fprintf (stderr, "Usage: %s [addr] [port]\n", argv_[0]);
4649
return EXIT_FAILURE;
50+
}
4751
}
4852

4953
#ifdef TRACY_ENABLE

benchmark/CMakeLists.txt

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
cmake_minimum_required(VERSION 3.22)
2+
3+
project(RLBotCPP-Benchmark VERSION 1.0.0)
4+
5+
FetchContent_Declare(RocketSim
6+
GIT_REPOSITORY https://github.com/ZealanL/RocketSim.git
7+
GIT_TAG 9b36a351d86fcb15fd69154c7943821658b16b09
8+
)
9+
FetchContent_MakeAvailable(RocketSim)
10+
11+
###########################################################################
12+
add_executable(${PROJECT_NAME})
13+
14+
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_20)
15+
16+
target_sources(${PROJECT_NAME} PRIVATE
17+
../library/Log.cpp
18+
../library/Log.h
19+
../library/Message.cpp
20+
../library/Message.h
21+
../library/Pool.cpp
22+
../library/Pool.h
23+
$<$<BOOL:${WIN32}>:../library/WsaData.cpp>
24+
$<$<BOOL:${WIN32}>:../library/WsaData.h>
25+
26+
main.cpp
27+
Simulator.cpp
28+
Simulator.h
29+
)
30+
31+
target_link_libraries(${PROJECT_NAME} PRIVATE RLBotCPP-static RocketSim)
32+
33+
target_include_directories(${PROJECT_NAME} SYSTEM PRIVATE
34+
../library
35+
${RocketSim_SOURCE_DIR}/src
36+
)
37+
38+
add_dependencies(${PROJECT_NAME} rlbot-generated)
39+
target_include_directories(${PROJECT_NAME} SYSTEM PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/..)
40+
41+
if(WIN32)
42+
target_link_libraries(${PROJECT_NAME} PRIVATE wsock32 ws2_32)
43+
target_compile_definitions(${PROJECT_NAME}
44+
PRIVATE
45+
_CRT_SECURE_NO_WARNINGS
46+
_WIN32_WINNT=_WIN32_WINNT_WINBLUE
47+
)
48+
endif()
49+
50+
if(MSVC)
51+
# standard definitions to enable
52+
target_compile_definitions(${PROJECT_NAME} PRIVATE
53+
NOMINMAX # no min/max macros
54+
_CRT_SECURE_NO_DEPRECATE # don't deprecate functions in favor of _s versions
55+
WIN32_LEAN_AND_MEAN # minimal headers
56+
)
57+
58+
# standard compile options
59+
target_compile_options(${PROJECT_NAME} PRIVATE
60+
/utf-8 # utf-8
61+
/EHsc # fix up exception handling model
62+
/W3 # level 3 warnings
63+
/WX # warnings as errors
64+
/wd4251 # 'identifier' : class 'type' needs to have dll-interface
65+
/wd4267 # conversion integer type to smaller type
66+
/Zc:preprocessor # use c preprocessor
67+
)
68+
else()
69+
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
70+
# work around gcc _Pragma problem
71+
target_compile_options(${PROJECT_NAME} PRIVATE
72+
-no-integrated-cpp
73+
)
74+
elseif(("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") AND ("${CMAKE_CXX_COMPILER_FRONTEND_VARIANT}" STREQUAL "GNU"))
75+
# make clang a little more like gcc's set of warnings
76+
target_compile_options(${PROJECT_NAME} PRIVATE
77+
-Wno-unused-const-variable
78+
-Wno-deprecated-anon-enum-enum-conversion
79+
-Winconsistent-missing-override
80+
-Wno-error=inconsistent-missing-override
81+
-Winconsistent-missing-destructor-override
82+
)
83+
endif()
84+
85+
# standard warnings to enable
86+
target_compile_options(${PROJECT_NAME} PRIVATE
87+
-Wall
88+
-Wextra
89+
-Wno-unknown-pragmas
90+
-Wno-error=deprecated-declarations
91+
-Wsuggest-override
92+
-Wno-error=suggest-override
93+
-Wzero-as-null-pointer-constant
94+
-Wno-error=zero-as-null-pointer-constant
95+
-Wno-missing-field-initializers
96+
)
97+
endif()
98+
99+
if(RLBOT_CPP_ENABLE_TRACY)
100+
target_compile_definitions(${PROJECT_NAME} PUBLIC TRACY_ENABLE)
101+
target_sources(${PROJECT_NAME} PRIVATE ${tracy_SOURCE_DIR}/public/TracyClient.cpp)
102+
endif()
103+
104+
target_compile_definitions(${PROJECT_NAME} PUBLIC
105+
FLATBUFFERS_USE_STD_OPTIONAL=1
106+
FLATBUFFERS_USE_STD_SPAN=1
107+
)
108+
109+
if(LTO_SUPPORTED)
110+
set_target_properties(${PROJECT_NAME} PROPERTIES
111+
INTERPROCEDURAL_OPTIMIZATION $<BOOL:${RLBOT_CPP_ENABLE_LTO}>
112+
INTERPROCEDURAL_OPTIMIZATION_DEBUG FALSE
113+
)
114+
endif()
115+

0 commit comments

Comments
 (0)