Add benchmark bots

This commit is contained in:
tovjemam 2026-01-20 15:56:28 +01:00
parent 2f456fe8ba
commit 0e40d6b92c
3 changed files with 42 additions and 2 deletions

View File

@ -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<Vehicle>("pickup_hd", glm::vec3{1.0f, 0.0f, 0.0f});
vehicle.SetPosition({ static_cast<float>(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)

View File

@ -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*, Vehicle*> player_vehicles_;
std::vector<Vehicle*> bots_;
};
}

View File

@ -30,7 +30,7 @@ public:
net::EntNum GetNewEntnum();
void RegisterEntity(std::unique_ptr<Entity> ent);
void Update(int64_t delta_time);
virtual void Update(int64_t delta_time);
// events
virtual void PlayerJoined(Player& player) {}