Ensure move_sprite_to_list only used in sprite.cpp

After an entity is created it should never need to call this function. This will be important in later changes when the lists are changed to vectors
This commit is contained in:
duncanspumpkin 2020-04-27 19:01:40 +01:00
parent 5b07a76f05
commit 63549dee57
6 changed files with 36 additions and 37 deletions

View File

@ -158,8 +158,6 @@ private:
}
else
{
move_sprite_to_list(newPeep, SPRITE_LIST_PEEP);
newPeep->sprite_identifier = 1;
newPeep->window_invalidate_flags = 0;
newPeep->action = PEEP_ACTION_NONE_2;

View File

@ -1122,17 +1122,14 @@ private:
rct1_vehicle* srcVehicle = &_s4.sprites[i].vehicle;
if (srcVehicle->x != LOCATION_NULL)
{
Vehicle* vehicle = reinterpret_cast<Vehicle*>(create_sprite(SPRITE_IDENTIFIER_VEHICLE));
// If vehicle is the first car on a train add to train list
auto llt = srcVehicle->type == VEHICLE_TYPE_HEAD ? SPRITE_LIST_TRAIN_HEAD : SPRITE_LIST_VEHICLE;
Vehicle* vehicle = reinterpret_cast<Vehicle*>(create_sprite(SPRITE_IDENTIFIER_VEHICLE, llt));
spriteIndexMap[i] = vehicle->sprite_index;
vehicles.push_back(vehicle);
ImportVehicle(vehicle, srcVehicle);
// If vehicle is the first car on a train add to train list
if (vehicle->IsHead())
{
move_sprite_to_list(vehicle, SPRITE_LIST_TRAIN_HEAD);
}
}
}
}

View File

@ -23,13 +23,13 @@
Vehicle* cable_lift_segment_create(
Ride& ride, int32_t x, int32_t y, int32_t z, int32_t direction, uint16_t var_44, int32_t remaining_distance, bool head)
{
Vehicle* current = &(create_sprite(SPRITE_IDENTIFIER_VEHICLE)->vehicle);
Vehicle* current = &(
create_sprite(SPRITE_IDENTIFIER_VEHICLE, head ? SPRITE_LIST_TRAIN_HEAD : SPRITE_LIST_VEHICLE)->vehicle);
current->sprite_identifier = SPRITE_IDENTIFIER_VEHICLE;
current->ride = ride.id;
current->ride_subtype = RIDE_ENTRY_INDEX_NULL;
if (head)
{
move_sprite_to_list(current, SPRITE_LIST_TRAIN_HEAD);
ride.cable_lift = current->sprite_index;
}
current->type = head ? VEHICLE_TYPE_HEAD : VEHICLE_TYPE_TAIL;

View File

@ -4324,7 +4324,8 @@ static Vehicle* vehicle_create_car(
return nullptr;
auto vehicleEntry = &rideEntry->vehicles[vehicleEntryIndex];
auto vehicle = &create_sprite(SPRITE_IDENTIFIER_VEHICLE)->vehicle;
auto vehicle = &create_sprite(SPRITE_IDENTIFIER_VEHICLE, carIndex == 0 ? SPRITE_LIST_TRAIN_HEAD : SPRITE_LIST_VEHICLE)
->vehicle;
if (vehicle == nullptr)
return nullptr;
@ -4568,8 +4569,6 @@ static void vehicle_create_trains(ride_id_t rideIndex, int32_t x, int32_t y, int
}
lastTrain = train;
// Add train to ride vehicle list
move_sprite_to_list(train.head, SPRITE_LIST_TRAIN_HEAD);
for (int32_t i = 0; i <= MAX_VEHICLES_PER_RIDE; i++)
{
if (ride->vehicles[i] == SPRITE_INDEX_NULL)

View File

@ -50,6 +50,7 @@ static CoordsXYZ _spritelocations1[MAX_SPRITES];
static CoordsXYZ _spritelocations2[MAX_SPRITES];
static size_t GetSpatialIndexOffset(int32_t x, int32_t y);
static void move_sprite_to_list(SpriteBase* sprite, SPRITE_LIST newListIndex);
std::string rct_sprite_checksum::ToString() const
{
@ -358,7 +359,7 @@ static void SpriteSpatialInsert(SpriteBase* sprite, const CoordsXY& newLoc);
static constexpr uint16_t MAX_MISC_SPRITES = 300;
rct_sprite* create_sprite(SPRITE_IDENTIFIER spriteIdentifier)
rct_sprite* create_sprite(SPRITE_IDENTIFIER spriteIdentifier, SPRITE_LIST linkedListIndex)
{
if (gSpriteListCount[SPRITE_LIST_FREE] == 0)
{
@ -366,26 +367,6 @@ rct_sprite* create_sprite(SPRITE_IDENTIFIER spriteIdentifier)
return nullptr;
}
SPRITE_LIST linkedListIndex;
switch (spriteIdentifier)
{
case SPRITE_IDENTIFIER_VEHICLE:
linkedListIndex = SPRITE_LIST_VEHICLE;
break;
case SPRITE_IDENTIFIER_PEEP:
linkedListIndex = SPRITE_LIST_PEEP;
break;
case SPRITE_IDENTIFIER_MISC:
linkedListIndex = SPRITE_LIST_MISC;
break;
case SPRITE_IDENTIFIER_LITTER:
linkedListIndex = SPRITE_LIST_LITTER;
break;
default:
Guard::Assert(false, "Invalid sprite identifier: 0x%02X", spriteIdentifier);
return nullptr;
}
if (linkedListIndex == SPRITE_LIST_MISC)
{
// Misc sprites are commonly used for effects, if there are less than MAX_MISC_SPRITES
@ -420,12 +401,36 @@ rct_sprite* create_sprite(SPRITE_IDENTIFIER spriteIdentifier)
return reinterpret_cast<rct_sprite*>(sprite);
}
rct_sprite* create_sprite(SPRITE_IDENTIFIER spriteIdentifier)
{
SPRITE_LIST linkedListIndex = SPRITE_LIST_FREE;
switch (spriteIdentifier)
{
case SPRITE_IDENTIFIER_VEHICLE:
linkedListIndex = SPRITE_LIST_VEHICLE;
break;
case SPRITE_IDENTIFIER_PEEP:
linkedListIndex = SPRITE_LIST_PEEP;
break;
case SPRITE_IDENTIFIER_MISC:
linkedListIndex = SPRITE_LIST_MISC;
break;
case SPRITE_IDENTIFIER_LITTER:
linkedListIndex = SPRITE_LIST_LITTER;
break;
default:
Guard::Assert(false, "Invalid sprite identifier: 0x%02X", spriteIdentifier);
return nullptr;
}
return create_sprite(spriteIdentifier, linkedListIndex);
}
/*
* rct2: 0x0069ED0B
* This function moves a sprite to the specified sprite linked list.
* The game uses this list to categorise sprites by type.
*/
void move_sprite_to_list(SpriteBase* sprite, SPRITE_LIST newListIndex)
static void move_sprite_to_list(SpriteBase* sprite, SPRITE_LIST newListIndex)
{
int32_t oldListIndex = sprite->linked_list_index;

View File

@ -204,10 +204,10 @@ extern uint16_t gSpriteSpatialIndex[SPATIAL_INDEX_SIZE];
extern const rct_string_id litterNames[12];
rct_sprite* create_sprite(SPRITE_IDENTIFIER spriteIdentifier);
rct_sprite* create_sprite(SPRITE_IDENTIFIER spriteIdentifier, SPRITE_LIST linkedListIndex);
void reset_sprite_list();
void reset_sprite_spatial_index();
void sprite_clear_all_unused();
void move_sprite_to_list(SpriteBase* sprite, SPRITE_LIST newList);
void sprite_misc_update_all();
void sprite_move(int16_t x, int16_t y, int16_t z, SpriteBase* sprite);
void sprite_set_coordinates(int16_t x, int16_t y, int16_t z, SpriteBase* sprite);