1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-23 23:04:36 +01:00

Change loop for searching free staff id from O(N^2) to O(N*log(N))

This commit is contained in:
ζeh Matt
2023-02-28 05:09:15 +02:00
parent 291a778720
commit 16cc1d3eb9

View File

@@ -26,6 +26,8 @@
#include "../world/Entrance.h"
#include "../world/Park.h"
#include <set>
/* rct2: 0x009929FC */
static constexpr const PeepSpriteType spriteTypes[] = {
PeepSpriteType::Handyman,
@@ -142,25 +144,20 @@ GameActions::Result StaffHireNewAction::QueryExecute(bool execute) const
newPeep->StaffOrders = _staffOrders;
// We search for the first available Id for a given staff type
uint32_t newStaffId = 0;
for (;;)
std::set<uint32_t> usedStaffIds;
for (auto searchPeep : EntityList<Staff>())
{
bool found = false;
++newStaffId;
for (auto searchPeep : EntityList<Staff>())
{
if (static_cast<uint8_t>(searchPeep->AssignedStaffType) != _staffType)
continue;
if (static_cast<uint8_t>(searchPeep->AssignedStaffType) != _staffType)
continue;
if (searchPeep->PeepId == newStaffId)
{
found = true;
break;
}
}
usedStaffIds.insert(searchPeep->PeepId);
}
if (!found)
break;
uint32_t newStaffId = 1;
while (usedStaffIds.find(newStaffId) != usedStaffIds.end())
{
newStaffId++;
}
newPeep->PeepId = newStaffId;