Use new class

This commit is contained in:
duncanspumpkin committed 2020-06-16 20:27:40 +01:00
1 parent 225ae3a0a9
commit c45a0536eb
11 files changed
+31 -71

No files matched your search

+4 -6
View File
@@ -1106,13 +1106,11 @@ static void window_map_paint_peep_overlay(rct_drawpixelinfo* dpi)
*/
static void window_map_paint_train_overlay(rct_drawpixelinfo* dpi)
{
Vehicle *train, *vehicle;
uint16_t train_index, vehicle_index;
for (train_index = gSpriteListHead[SPRITE_LIST_TRAIN_HEAD]; train_index != SPRITE_INDEX_NULL; train_index = train->next)
auto list = EntityList<Vehicle>(SPRITE_LIST_TRAIN_HEAD);
for (auto train : list)
{
train = GET_VEHICLE(train_index);
for (vehicle_index = train_index; vehicle_index != SPRITE_INDEX_NULL; vehicle_index = vehicle->next_vehicle_on_train)
Vehicle* vehicle = nullptr;
for (auto vehicle_index = train->sprite_index; vehicle_index != SPRITE_INDEX_NULL; vehicle_index = vehicle->next_vehicle_on_train)
{
vehicle = GET_VEHICLE(vehicle_index);
if (vehicle->x == LOCATION_NULL)
+4 -6
View File
@@ -427,10 +427,9 @@ private:
void RemoveLitter() const
{
for (uint16_t spriteIndex = gSpriteListHead[SPRITE_LIST_LITTER]; spriteIndex != SPRITE_INDEX_NULL;)
auto list = EntityList<Litter>(SPRITE_LIST_LITTER);
for (auto litter : list)
{
auto litter = GetEntity<Litter>(spriteIndex);
spriteIndex = litter->next;
sprite_remove(litter);
}
@@ -696,10 +695,9 @@ private:
// Do not use the FOR_ALL_PEEPS macro for this as next sprite index
// will be fetched on a deleted peep.
for (spriteIndex = gSpriteListHead[SPRITE_LIST_PEEP]; spriteIndex != SPRITE_INDEX_NULL;)
auto list = EntityList<Peep>(SPRITE_LIST_PEEP);
for (auto peep : list)
{
auto peep = GET_PEEP(spriteIndex);
spriteIndex = peep->next;
if (peep->AssignedPeepType == PEEP_TYPE_GUEST)
{
peep->Remove();
+1 -4
View File
@@ -3006,11 +3006,8 @@ static PeepThoughtType peep_assess_surroundings(int16_t centre_x, int16_t centre
}
}
for (uint16_t sprite_idx = gSpriteListHead[SPRITE_LIST_LITTER]; sprite_idx != SPRITE_INDEX_NULL;)
for (auto litter : EntityList<Litter>(SPRITE_LIST_LITTER))
{
auto litter = GetEntity<Litter>(sprite_idx);
sprite_idx = litter->next;
int16_t dist_x = abs(litter->x - centre_x);
int16_t dist_y = abs(litter->y - centre_y);
if (std::max(dist_x, dist_y) <= 160)
+3 -8
View File
@@ -402,20 +402,15 @@ int32_t peep_get_staff_count()
*/
void peep_update_all()
{
int32_t i = 0;
uint16_t spriteIndex;
Peep* peep;
if (gScreenFlags & SCREEN_FLAGS_EDITOR)
return;
int32_t i = 0;
// Do not use the FOR_ALL_PEEPS macro for this as next sprite index
// will be fetched on a delted peep if peep leaves the park.
for (spriteIndex = gSpriteListHead[SPRITE_LIST_PEEP]; spriteIndex != SPRITE_INDEX_NULL;)
auto list = EntityList<Peep>(SPRITE_LIST_PEEP);
for (auto peep : list)
{
peep = GET_PEEP(spriteIndex);
spriteIndex = peep->next;
if (static_cast<uint32_t>(i & 0x7F) != (gCurrentTicks & 0x7F))
{
peep->Update();
+1 -1
View File
@@ -990,7 +990,7 @@ enum
/**
* Helper macro loop for enumerating through all the peeps. To avoid needing a end loop counterpart, statements are
* applied in tautology if statements.
* applied in tautology if statements. TODO REMOVE
*/
#define FOR_ALL_PEEPS(sprite_index, peep) \
for ((sprite_index) = gSpriteListHead[SPRITE_LIST_PEEP]; (sprite_index) != SPRITE_INDEX_NULL; (sprite_index) = peep->next) \
+2 -4
View File
@@ -443,11 +443,9 @@ static uint8_t staff_handyman_direction_to_nearest_litter(Peep* peep)
{
uint16_t nearestLitterDist = 0xFFFF;
Litter* nearestLitter = nullptr;
for (uint16_t litterIndex = gSpriteListHead[SPRITE_LIST_LITTER]; litterIndex != SPRITE_INDEX_NULL;)
auto list = EntityList<Litter>(SPRITE_LIST_LITTER);
for (auto litter : list)
{
auto litter = GetEntity<Litter>(litterIndex);
litterIndex = litter->next;
uint16_t distance = abs(litter->x - peep->x) + abs(litter->y - peep->y) + abs(litter->z - peep->z) * 4;
if (distance < nearestLitterDist)
+2 -11
View File
@@ -1321,10 +1321,8 @@ void vehicle_sounds_update()
vehicle_sounds_update_window_setup();
for (uint16_t i = gSpriteListHead[SPRITE_LIST_TRAIN_HEAD]; i != SPRITE_INDEX_NULL;)
for (auto vehicle : EntityList<Vehicle>(SPRITE_LIST_TRAIN_HEAD))
{
auto vehicle = GetEntity<Vehicle>(i);
i = vehicle->next;
vehicle->UpdateSoundParams(vehicleSoundParamsList);
}
@@ -1395,21 +1393,14 @@ void vehicle_sounds_update()
*/
void vehicle_update_all()
{
uint16_t sprite_index;
Vehicle* vehicle;
if (gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR)
return;
if ((gScreenFlags & SCREEN_FLAGS_TRACK_DESIGNER) && gS6Info.editor_step != EDITOR_STEP_ROLLERCOASTER_DESIGNER)
return;
sprite_index = gSpriteListHead[SPRITE_LIST_TRAIN_HEAD];
while (sprite_index != SPRITE_INDEX_NULL)
for (auto vehicle : EntityList<Vehicle>(SPRITE_LIST_TRAIN_HEAD))
{
vehicle = GET_VEHICLE(sprite_index);
sprite_index = vehicle->next;
vehicle->Update();
}
}
+2 -5
View File
@@ -131,12 +131,9 @@ namespace OpenRCT2::Scripting
}
std::vector<DukValue> result;
for (auto spriteId = gSpriteListHead[targetList]; spriteId != SPRITE_INDEX_NULL;)
auto list = EntityList(targetList);
for (auto sprite : list)
{
auto sprite = GetEntity(spriteId);
spriteId = sprite->next;
// Only the misc list checks the type property
if (targetList != SPRITE_LIST_MISC || sprite->type == targetType)
{
+3 -8
View File
@@ -363,15 +363,10 @@ void duck_press(Duck* duck)
void duck_remove_all()
{
for (uint16_t spriteIndex = gSpriteListHead[SPRITE_LIST_MISC]; spriteIndex != SPRITE_INDEX_NULL;)
auto list = EntityList<Duck>(SPRITE_LIST_MISC);
for (auto duck : list)
{
auto sprite = GetEntity(spriteIndex);
spriteIndex = sprite->next;
if (sprite->type == SPRITE_MISC_DUCK)
{
sprite->Invalidate1();
sprite_remove(sprite);
}
duck->Remove();
}
}
+2 -4
View File
@@ -470,11 +470,9 @@ int32_t Park::CalculateParkRating() const
// Litter
{
int32_t litterCount = 0;
for (uint16_t spriteIndex = gSpriteListHead[SPRITE_LIST_LITTER]; spriteIndex != SPRITE_INDEX_NULL;)
auto list = EntityList<Litter>(SPRITE_LIST_LITTER);
for (auto litter : list)
{
auto litter = GetEntity<Litter>(spriteIndex);
spriteIndex = litter->next;
// Ignore recently dropped litter
if (litter->creationTick - gScenarioTicks >= 7680)
{
+7 -14
View File
@@ -358,11 +358,8 @@ static void sprite_reset(SpriteBase* sprite)
*/
void sprite_clear_all_unused()
{
for (uint16_t spriteIndex = gSpriteListHead[SPRITE_LIST_FREE]; spriteIndex != SPRITE_INDEX_NULL;)
for (auto sprite : EntityList(SPRITE_LIST_FREE))
{
auto sprite = GetEntity(spriteIndex);
spriteIndex = sprite->next;
sprite_reset(sprite);
sprite->linked_list_index = SPRITE_LIST_FREE;
@@ -631,11 +628,10 @@ static void sprite_misc_update(rct_sprite* sprite)
*/
void sprite_misc_update_all()
{
for (auto spriteIndex = gSpriteListHead[SPRITE_LIST_MISC]; spriteIndex != SPRITE_INDEX_NULL;)
for (auto entity : EntityList(SPRITE_LIST_MISC))
{
auto sprite = GetEntity(spriteIndex);
spriteIndex = sprite->next;
sprite_misc_update(reinterpret_cast<rct_sprite*>(sprite));
// TODO: Use more specific Sprite class
sprite_misc_update(reinterpret_cast<rct_sprite*>(entity));
}
}
@@ -806,10 +802,8 @@ void litter_create(int32_t x, int32_t y, int32_t z, int32_t direction, int32_t t
{
Litter* newestLitter = nullptr;
uint32_t newestLitterCreationTick = 0;
for (uint16_t spriteIndex = gSpriteListHead[SPRITE_LIST_LITTER]; spriteIndex != SPRITE_INDEX_NULL;)
for (auto litter : EntityList<Litter>(SPRITE_LIST_LITTER))
{
Litter* litter = GetEntity<Litter>(spriteIndex);
spriteIndex = litter->next;
if (newestLitterCreationTick <= litter->creationTick)
{
newestLitterCreationTick = litter->creationTick;
@@ -1066,10 +1060,9 @@ static SpriteBase* find_sprite_quadrant_cycle(uint16_t sprite_idx)
static bool index_is_in_list(uint16_t index, enum SPRITE_LIST sl)
{
for (uint16_t sprite_index = gSpriteListHead[sl]; sprite_index != SPRITE_INDEX_NULL;
sprite_index = GetEntity(sprite_index)->next)
for (auto entity : EntityList(sl))
{
if (sprite_index == index)
if (entity->sprite_index == index)
{
return true;
}