From 0e40d6b92c4905e5e519e86086f4cc1e87f7f4d3 Mon Sep 17 00:00:00 2001 From: tovjemam Date: Tue, 20 Jan 2026 15:56:28 +0100 Subject: [PATCH] Add benchmark bots --- src/game/openworld.cpp | 38 ++++++++++++++++++++++++++++++++++++++ src/game/openworld.hpp | 4 +++- src/game/world.hpp | 2 +- 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/src/game/openworld.cpp b/src/game/openworld.cpp index f17b641..d89755a 100644 --- a/src/game/openworld.cpp +++ b/src/game/openworld.cpp @@ -6,6 +6,44 @@ game::OpenWorld::OpenWorld() : World("openworld") { srand(time(NULL)); + + // spawn test vehicles + for (size_t i = 0; i < 150; ++i) + { + auto& vehicle = Spawn("pickup_hd", glm::vec3{1.0f, 0.0f, 0.0f}); + vehicle.SetPosition({ static_cast(i * 3), 150.0f, 5.0f }); + vehicle.SetInput(VIN_FORWARD, true); + bots_.push_back(&vehicle); + } +} + +void game::OpenWorld::Update(int64_t delta_time) +{ + World::Update(delta_time); + + for (auto bot : bots_) + { + bot->SetInput(VIN_FORWARD, true); + + if (rand() % 1000 < 10) + { + bool turn_left = rand() % 2; + bot->SetInput(VIN_LEFT, turn_left); + bot->SetInput(VIN_RIGHT, !turn_left); + } + else + { + bot->SetInput(VIN_LEFT, false); + bot->SetInput(VIN_RIGHT, false); + } + + auto pos = bot->GetPosition(); + if (glm::distance(pos, glm::vec3(0.0f, 0.0f, 0.0f)) > 1000.0f || pos.z < -20.0f) + { + bot->SetPosition({ rand() % 30 * 3 + 100.0f, 200.0f, 10.0f }); + } + + } } void game::OpenWorld::PlayerJoined(Player& player) diff --git a/src/game/openworld.hpp b/src/game/openworld.hpp index 0c3e60f..2d3f3f4 100644 --- a/src/game/openworld.hpp +++ b/src/game/openworld.hpp @@ -11,6 +11,8 @@ class OpenWorld : public World public: OpenWorld(); + virtual void Update(int64_t delta_time) override; + virtual void PlayerJoined(Player& player) override; virtual void PlayerInput(Player& player, PlayerInputType type, bool enabled) override; virtual void PlayerLeft(Player& player) override; @@ -21,7 +23,7 @@ private: private: std::map player_vehicles_; - + std::vector bots_; }; } \ No newline at end of file diff --git a/src/game/world.hpp b/src/game/world.hpp index d8350ee..3643820 100644 --- a/src/game/world.hpp +++ b/src/game/world.hpp @@ -30,7 +30,7 @@ public: net::EntNum GetNewEntnum(); void RegisterEntity(std::unique_ptr ent); - void Update(int64_t delta_time); + virtual void Update(int64_t delta_time); // events virtual void PlayerJoined(Player& player) {}