Add benchmark bots
This commit is contained in:
parent
2f456fe8ba
commit
0e40d6b92c
@ -6,6 +6,44 @@
|
|||||||
game::OpenWorld::OpenWorld() : World("openworld")
|
game::OpenWorld::OpenWorld() : World("openworld")
|
||||||
{
|
{
|
||||||
srand(time(NULL));
|
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)
|
void game::OpenWorld::PlayerJoined(Player& player)
|
||||||
|
|||||||
@ -11,6 +11,8 @@ class OpenWorld : public World
|
|||||||
public:
|
public:
|
||||||
OpenWorld();
|
OpenWorld();
|
||||||
|
|
||||||
|
virtual void Update(int64_t delta_time) override;
|
||||||
|
|
||||||
virtual void PlayerJoined(Player& player) override;
|
virtual void PlayerJoined(Player& player) override;
|
||||||
virtual void PlayerInput(Player& player, PlayerInputType type, bool enabled) override;
|
virtual void PlayerInput(Player& player, PlayerInputType type, bool enabled) override;
|
||||||
virtual void PlayerLeft(Player& player) override;
|
virtual void PlayerLeft(Player& player) override;
|
||||||
@ -21,7 +23,7 @@ private:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
std::map<Player*, Vehicle*> player_vehicles_;
|
std::map<Player*, Vehicle*> player_vehicles_;
|
||||||
|
std::vector<Vehicle*> bots_;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -30,7 +30,7 @@ public:
|
|||||||
net::EntNum GetNewEntnum();
|
net::EntNum GetNewEntnum();
|
||||||
void RegisterEntity(std::unique_ptr<Entity> ent);
|
void RegisterEntity(std::unique_ptr<Entity> ent);
|
||||||
|
|
||||||
void Update(int64_t delta_time);
|
virtual void Update(int64_t delta_time);
|
||||||
|
|
||||||
// events
|
// events
|
||||||
virtual void PlayerJoined(Player& player) {}
|
virtual void PlayerJoined(Player& player) {}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user