Add telemetry system: protobuf over Unix socket

- TelemetrySocket: non-blocking Unix domain socket writer (fire-and-forget)
- TelemetryEmitter: high-level event emitter with protobuf serialization
- Hooks into: World::update (snapshots), World::onGo (race start),
  ServerLobby (race finish, player join/leave),
  LinearWorld::newLap (laps, kart finish),
  NetworkItemManager (item collection, switch),
  Flyable (projectile hits)
- CMake: finds protobuf, generates C++ from proto schema, links libprotobuf
- Configurable via STK_TELEMETRY_SOCKET env (disabled if unset)
- Snapshot rate configurable via STK_TELEMETRY_SNAPSHOT_HZ (default 10)
This commit is contained in:
Benjamin
2026-06-11 20:29:04 +02:00
parent eebbfac15f
commit 4a962014a2
11 changed files with 1058 additions and 0 deletions
+30
View File
@@ -530,6 +530,35 @@ endif()
# Provides list of source and header files (STK_SOURCES and STK_HEADERS)
include(sources.cmake)
# --- Telemetry (protobuf) ---------------------------------------------------
# Generate C++ code from the telemetry proto file. Only needed for server builds;
# the telemetry emitter is compiled in unconditionally but is a runtime no-op
# unless STK_TELEMETRY_SOCKET is set.
find_package(Protobuf REQUIRED)
set(TELEMETRY_PROTO "${CMAKE_CURRENT_SOURCE_DIR}/../proto/telemetry.proto")
# If building inside Docker, the proto file is copied to the source tree.
if(NOT EXISTS "${TELEMETRY_PROTO}")
set(TELEMETRY_PROTO "${CMAKE_CURRENT_SOURCE_DIR}/proto/telemetry.proto")
endif()
set(TELEMETRY_PROTO_OUT "${CMAKE_CURRENT_BINARY_DIR}/telemetry_proto")
file(MAKE_DIRECTORY ${TELEMETRY_PROTO_OUT})
set(TELEMETRY_PB_CC "${TELEMETRY_PROTO_OUT}/telemetry.pb.cc")
set(TELEMETRY_PB_H "${TELEMETRY_PROTO_OUT}/telemetry.pb.h")
add_custom_command(
OUTPUT ${TELEMETRY_PB_CC} ${TELEMETRY_PB_H}
COMMAND protobuf::protoc
--cpp_out=${TELEMETRY_PROTO_OUT}
--proto_path=${CMAKE_CURRENT_SOURCE_DIR}/../proto
--proto_path=${CMAKE_CURRENT_SOURCE_DIR}/proto
telemetry.proto
DEPENDS ${TELEMETRY_PROTO}
COMMENT "Generating telemetry protobuf C++"
)
set(STK_SOURCES ${STK_SOURCES} ${TELEMETRY_PB_CC})
set(STK_HEADERS ${STK_HEADERS} ${TELEMETRY_PB_H})
include_directories(${TELEMETRY_PROTO_OUT})
include_directories(${Protobuf_INCLUDE_DIRS})
if (USE_APPLE_NETWORK_LIBRARIES)
add_definitions(-DAPPLE_NETWORK_LIBRARIES)
set(STK_SOURCES
@@ -703,6 +732,7 @@ target_link_libraries(supertuxkart
stkirrlicht
${Angelscript_LIBRARIES}
${MCPP_LIBRARY}
${Protobuf_LIBRARIES}
)
if (USE_APPLE_NETWORK_LIBRARIES)