1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-15 11:03:00 +01:00

Use entity list rather than MAX_ENTITIES loop (#14384)

* Use entity list rather than MAX_ENTITIES loop

* Use guest for variable names
This commit is contained in:
Duncan
2021-03-25 08:08:26 +00:00
committed by GitHub
parent 040a3eb144
commit 1be7457e30
3 changed files with 31 additions and 41 deletions

View File

@@ -34,6 +34,7 @@
#include "util/Util.h"
#include "windows/Intent.h"
#include "world/Climate.h"
#include "world/EntityList.h"
#include "world/Entrance.h"
#include "world/Footpath.h"
#include "world/Park.h"
@@ -310,13 +311,13 @@ namespace Editor
ride_init_all();
//
for (int32_t i = 0; i < MAX_ENTITIES; i++)
for (auto* guest : EntityList<Guest>())
{
auto peep = GetEntity<Peep>(i);
if (peep != nullptr)
{
peep->SetName({});
}
guest->SetName({});
}
for (auto* staff : EntityList<Staff>())
{
staff->SetName({});
}
reset_sprite_list();

View File

@@ -1580,49 +1580,43 @@ static int32_t cc_mp_desync(InteractiveConsole& console, const arguments_t& argv
desyncType = atoi(argv[0].c_str());
}
std::vector<Peep*> peeps;
std::vector<Guest*> guests;
for (int i = 0; i < MAX_ENTITIES; i++)
for (auto* guest : EntityList<Guest>())
{
auto* sprite = GetEntity(i);
if (sprite == nullptr || sprite->Type == EntityType::Null)
continue;
auto peep = sprite->As<Peep>();
if (peep != nullptr)
peeps.push_back(peep);
guests.push_back(guest);
}
switch (desyncType)
{
case 0: // Peep t-shirts.
case 0: // Guest t-shirts.
{
if (peeps.empty())
if (guests.empty())
{
console.WriteFormatLine("No peeps");
console.WriteFormatLine("No guests");
}
else
{
auto* peep = peeps[0];
if (peeps.size() > 1)
peep = peeps[util_rand() % peeps.size() - 1];
peep->TshirtColour = util_rand() & 0xFF;
peep->Invalidate();
auto* guest = guests[0];
if (guests.size() > 1)
guest = guests[util_rand() % guests.size() - 1];
guest->TshirtColour = util_rand() & 0xFF;
guest->Invalidate();
}
break;
}
case 1: // Remove random peep.
case 1: // Remove random guest.
{
if (peeps.empty())
if (guests.empty())
{
console.WriteFormatLine("No peep removed");
console.WriteFormatLine("No guest removed");
}
else
{
auto* peep = peeps[0];
if (peeps.size() > 1)
peep = peeps[util_rand() % peeps.size() - 1];
peep->Remove();
auto* guest = guests[0];
if (guests.size() > 1)
guest = guests[util_rand() % guests.size() - 1];
guest->Remove();
}
break;
}
@@ -1810,7 +1804,7 @@ static constexpr const console_command console_command_table[] = {
{ "replay_start", cc_replay_start, "Starts a replay", "replay_start <name>"},
{ "replay_stop", cc_replay_stop, "Stops the replay", "replay_stop"},
{ "replay_normalise", cc_replay_normalise, "Normalises the replay to remove all gaps", "replay_normalise <input file> <output file>"},
{ "mp_desync", cc_mp_desync, "Forces a multiplayer desync", "cc_mp_desync [desync_type, 0 = Random t-shirt color on random peep, 1 = Remove random peep ]"},
{ "mp_desync", cc_mp_desync, "Forces a multiplayer desync", "cc_mp_desync [desync_type, 0 = Random t-shirt color on random guest, 1 = Remove random guest ]"},
};
// clang-format on

View File

@@ -1360,13 +1360,9 @@ private:
ImportPeep(peep, srcPeep);
}
}
for (size_t i = 0; i < MAX_ENTITIES; i++)
for (auto* vehicle : EntityList<Vehicle>())
{
auto vehicle = GetEntity<Vehicle>(i);
if (vehicle != nullptr)
{
FixVehiclePeepLinks(vehicle, spriteIndexMap);
}
FixVehiclePeepLinks(vehicle, spriteIndexMap);
}
for (auto& ride : GetRideManager())
@@ -1374,12 +1370,11 @@ private:
FixRidePeepLinks(&ride, spriteIndexMap);
}
for (auto peep : EntityList<Guest>())
{
for (auto peep : EntityList<Guest>())
{
FixPeepNextInQueue(peep, spriteIndexMap);
}
FixPeepNextInQueue(peep, spriteIndexMap);
}
// Fix the news items in advance
for (auto i = 0; i < News::MaxItems; i++)
{