24#include <SDL3/SDL_stdinc.h>
28#include <glm/vec3.hpp>
55 bool init(
const std::string& host, Uint16 port,
int botId);
72 void start(
const std::atomic<bool>& stopFlag);
90 [[nodiscard]]
bool isReady()
const {
return ready_.load(std::memory_order_relaxed); }
94 void runLoop(
const std::atomic<bool>& stopFlag);
101 std::optional<registry_serialization::Loader>
147 std::uint32_t snapshotTick,
const std::uint8_t* bytes, Uint32 size, Uint64 captureNs, std::uint32_t& ackedTick);
216 std::uint32_t shotInputTick,
217 const glm::vec3& origin,
218 const glm::vec3& direction,
219 std::uint16_t intendedTargetClientId,
220 const glm::vec3& intendedTargetPos,
221 float intendedTargetDist,
223 std::uint16_t botHitClientId,
224 const glm::vec3& botHitPos,
TCP client for connecting to the game server.
Shared ECS registry type alias for the game engine.
entt::registry Registry
Shared ECS registry type alias.
Definition Registry.hpp:11
std::optional< registry_serialization::Loader > snapshotLoader_
Incremental snapshot loader; created on first snapshot apply.
Definition Bot.hpp:102
void setSimulatedLossPercent(int percent)
Apply a simulated UDP packet-loss percentage to the bot's UDP path.
Definition Bot.cpp:293
void join()
Block until the worker thread exits.
Definition Bot.cpp:359
std::FILE * obsCsv_
Definition Bot.hpp:175
void writeShotIntent(std::uint16_t shooterClientId, std::uint32_t shotInputTick, const glm::vec3 &origin, const glm::vec3 &direction, std::uint16_t intendedTargetClientId, const glm::vec3 &intendedTargetPos, float intendedTargetDist, bool botRayHit, std::uint16_t botHitClientId, const glm::vec3 &botHitPos, float botHitDist)
Append a shot-intent row.
Definition Bot.cpp:139
bool initialized_
True once init() succeeded; gates run().
Definition Bot.hpp:105
Registry registry_
Snapshot apply target — never read.
Definition Bot.hpp:97
void writeObservationLog()
Walk the registry for view<Position, ClientId>, write one row per replicated player entity to the bot...
Definition Bot.cpp:72
~Bot()
Definition Bot.cpp:41
int botId_
Log prefix.
Definition Bot.hpp:104
std::FILE * shotsCsv_
Definition Bot.hpp:196
std::thread thread_
Worker thread; joined in dtor or join().
Definition Bot.hpp:98
static constexpr int k_tickHz
Default tick rate; matches the server's physics tick rate.
Definition Bot.hpp:41
void setSimulatedLatencyMs(int totalMs)
Apply a simulated round-trip latency on the bot's UDP path.
Definition Bot.cpp:288
bool localPlayerReady_
Set true once the bot maps the server-assigned local player.
Definition Bot.hpp:138
bool prevShootingForLog_
Rising-edge detector for fire log.
Definition Bot.hpp:197
bool isReady() const
PR-1: true once the bot's worker has logged at least one finished tick.
Definition Bot.hpp:90
uint32_t predictTick_
Monotonic tick counter, stamped onto each input.
Definition Bot.hpp:100
void runLoop(const std::atomic< bool > &stopFlag)
Worker-thread main loop: send input + poll, sleep to next tick.
Definition Bot.cpp:375
std::optional< entt::entity > getLocalPlayerEntity() const
Return the bot's local-registry player entity, or nullopt before the first snapshot maps it.
Definition Bot.cpp:253
void closeObservationLog() noexcept
Flush + close the CSV if open. Safe to call from dtor.
Definition Bot.cpp:105
void openObservationLog()
Open the CSV if GROUP2_BOT_OBS_CSV_PREFIX is set.
Definition Bot.cpp:53
bool applyIncomingSnapshot(std::uint32_t snapshotTick, const std::uint8_t *bytes, Uint32 size, Uint64 captureNs, std::uint32_t &ackedTick)
Deserialize a snapshot and update the bot's registry; maps the local entity on first apply.
Definition Bot.cpp:217
Bot & operator=(const Bot &)=delete
bool init(const std::string &host, Uint16 port, int botId)
Connect to the server.
Definition Bot.cpp:260
std::atomic< bool > ready_
PR-1 (server-perf): set true after the first successful poll inside runLoop.
Definition Bot.hpp:110
InputRingBuffer inputRing_
Definition Bot.hpp:132
void openShotsLog()
Open the shot-intent log if GROUP2_BOT_SHOTS_CSV_PREFIX is set.
Definition Bot.cpp:115
Bot & operator=(Bot &&)=delete
std::optional< entt::entity > mappedLocalPlayerEntity_
Local-registry entity for this bot's player, once mapped.
Definition Bot.hpp:103
float getCurrentRttMs() const
PR-1 (server-perf): current smoothed RTT in ms.
Definition Bot.cpp:365
void start(const std::atomic< bool > &stopFlag)
Spawn the worker thread.
Definition Bot.cpp:298
Client client_
Underlying TCP client (TCP today; UDP after Phase 3).
Definition Bot.hpp:96
InputSnapshot input_
Reused per-tick input scratch.
Definition Bot.hpp:99
void closeShotsLog() noexcept
Flush + close the shot log if open. Safe from dtor.
Definition Bot.cpp:180
void setupLocalPlayerCallback()
PR-23: set up the snapshot callback that emplaces LocalPlayer + InputSnapshot + PreviousPosition + Pl...
Definition Bot.cpp:206
TCP stream client — sends input to the server and receives state updates.
Definition Client.hpp:69