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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user