Fix #9198: Move vehicle invalidate to member function

To further improve the readability of the codebase the vehicle_invalidate function is now a member function of rct_vehicle.
This commit is contained in:
nexgenration 2019-05-11 08:20:34 -04:00 committed by Duncan
parent b51f6a4d90
commit ebefe5721b
2 changed files with 46 additions and 45 deletions

View File

@ -839,9 +839,9 @@ rct_vehicle* try_get_vehicle(uint16_t spriteIndex)
return &sprite->vehicle; return &sprite->vehicle;
} }
static void vehicle_invalidate(rct_vehicle* vehicle) void rct_vehicle::Invalidate()
{ {
invalidate_sprite_2((rct_sprite*)vehicle); invalidate_sprite_2((rct_sprite*)this);
} }
static int32_t get_train_mass(rct_vehicle* first_vehicle) static int32_t get_train_mass(rct_vehicle* first_vehicle)
@ -1392,7 +1392,7 @@ static bool vehicle_close_restraints(rct_vehicle* vehicle)
continue; continue;
} }
} }
vehicle_invalidate(vehicle); vehicle->Invalidate();
restraintsClosed = false; restraintsClosed = false;
} while ((vehicle_id = vehicle->next_vehicle_on_train) != SPRITE_INDEX_NULL); } while ((vehicle_id = vehicle->next_vehicle_on_train) != SPRITE_INDEX_NULL);
@ -1449,7 +1449,7 @@ static bool vehicle_open_restraints(rct_vehicle* vehicle)
vehicle->spin_sprite += value; vehicle->spin_sprite += value;
vehicle->spin_speed -= value; vehicle->spin_speed -= value;
vehicle_invalidate(vehicle); vehicle->Invalidate();
continue; continue;
} }
} }
@ -1460,7 +1460,7 @@ static bool vehicle_open_restraints(rct_vehicle* vehicle)
vehicle->var_C8 = vehicle->var_C8 + 0x3333 - 0xFFFF; vehicle->var_C8 = vehicle->var_C8 + 0x3333 - 0xFFFF;
vehicle->animation_frame++; vehicle->animation_frame++;
vehicle->animation_frame &= 7; vehicle->animation_frame &= 7;
vehicle_invalidate(vehicle); vehicle->Invalidate();
} }
else else
{ {
@ -1500,7 +1500,7 @@ static bool vehicle_open_restraints(rct_vehicle* vehicle)
} }
vehicle->restraints_position += 20; vehicle->restraints_position += 20;
} }
vehicle_invalidate(vehicle); vehicle->Invalidate();
restraintsOpen = false; restraintsOpen = false;
} while ((vehicle_id = vehicle->next_vehicle_on_train) != SPRITE_INDEX_NULL); } while ((vehicle_id = vehicle->next_vehicle_on_train) != SPRITE_INDEX_NULL);
@ -2259,7 +2259,7 @@ static void vehicle_update_waiting_for_passengers(rct_vehicle* vehicle)
vehicle->sub_state = 1; vehicle->sub_state = 1;
vehicle->time_waiting = 0; vehicle->time_waiting = 0;
vehicle_invalidate(vehicle); vehicle->Invalidate();
return; return;
} }
else if (vehicle->sub_state == 1) else if (vehicle->sub_state == 1)
@ -2451,7 +2451,7 @@ static void vehicle_update_dodgems_mode(rct_vehicle* vehicle)
if (vehicleEntry->flags & VEHICLE_ENTRY_FLAG_DODGEM_INUSE_LIGHTS && vehicle->animation_frame != 1) if (vehicleEntry->flags & VEHICLE_ENTRY_FLAG_DODGEM_INUSE_LIGHTS && vehicle->animation_frame != 1)
{ {
vehicle->animation_frame = 1; vehicle->animation_frame = 1;
vehicle_invalidate(vehicle); vehicle->Invalidate();
} }
vehicle_update_motion_dodgems(vehicle); vehicle_update_motion_dodgems(vehicle);
@ -2467,7 +2467,7 @@ static void vehicle_update_dodgems_mode(rct_vehicle* vehicle)
// Mark the dodgem as not in use. // Mark the dodgem as not in use.
vehicle->animation_frame = 0; vehicle->animation_frame = 0;
vehicle_invalidate(vehicle); vehicle->Invalidate();
vehicle->velocity = 0; vehicle->velocity = 0;
vehicle->acceleration = 0; vehicle->acceleration = 0;
vehicle->status = VEHICLE_STATUS_UNLOADING_PASSENGERS; vehicle->status = VEHICLE_STATUS_UNLOADING_PASSENGERS;
@ -3417,7 +3417,7 @@ static void vehicle_update_departing(rct_vehicle* vehicle)
if (!vehicle_current_tower_element_is_top(vehicle)) if (!vehicle_current_tower_element_is_top(vehicle))
{ {
if (ride->mode == RIDE_MODE_FREEFALL_DROP) if (ride->mode == RIDE_MODE_FREEFALL_DROP)
vehicle_invalidate(vehicle); vehicle->Invalidate();
return; return;
} }
@ -3681,7 +3681,7 @@ static void vehicle_update_travelling(rct_vehicle* vehicle)
vehicle->animation_frame++; vehicle->animation_frame++;
vehicle->velocity = 0; vehicle->velocity = 0;
vehicle->acceleration = 0; vehicle->acceleration = 0;
vehicle_invalidate(vehicle); vehicle->Invalidate();
return; return;
} }
@ -4321,7 +4321,7 @@ static void vehicle_update_motion_boat_hire(rct_vehicle* vehicle)
unk_F64E20.x = vehicle->x; unk_F64E20.x = vehicle->x;
unk_F64E20.y = vehicle->y; unk_F64E20.y = vehicle->y;
unk_F64E20.z = vehicle->z; unk_F64E20.z = vehicle->z;
vehicle_invalidate(vehicle); vehicle->Invalidate();
for (;;) for (;;)
{ {
@ -4545,7 +4545,7 @@ static void vehicle_update_motion_boat_hire(rct_vehicle* vehicle)
} }
sprite_move(unk_F64E20.x, unk_F64E20.y, unk_F64E20.z, (rct_sprite*)vehicle); sprite_move(unk_F64E20.x, unk_F64E20.y, unk_F64E20.z, (rct_sprite*)vehicle);
vehicle_invalidate(vehicle); vehicle->Invalidate();
} }
// loc_6DAAC9: // loc_6DAAC9:
@ -4719,7 +4719,7 @@ static void vehicle_update_swinging(rct_vehicle* vehicle)
{ {
// Used to know which sprite to draw // Used to know which sprite to draw
vehicle->vehicle_sprite_type = (uint8_t)spriteType; vehicle->vehicle_sprite_type = (uint8_t)spriteType;
vehicle_invalidate(vehicle); vehicle->Invalidate();
} }
return; return;
} }
@ -4804,7 +4804,7 @@ static void vehicle_update_ferris_wheel_rotating(rct_vehicle* vehicle)
if (rotation == vehicle->sub_state) if (rotation == vehicle->sub_state)
vehicle->var_CE++; vehicle->var_CE++;
vehicle_invalidate(vehicle); vehicle->Invalidate();
uint8_t subState = vehicle->sub_state; uint8_t subState = vehicle->sub_state;
if (ride->mode == RIDE_MODE_FORWARD_ROTATION) if (ride->mode == RIDE_MODE_FORWARD_ROTATION)
@ -4867,7 +4867,7 @@ static void vehicle_update_simulator_operating(rct_vehicle* vehicle)
if (al == vehicle->vehicle_sprite_type) if (al == vehicle->vehicle_sprite_type)
return; return;
vehicle->vehicle_sprite_type = al; vehicle->vehicle_sprite_type = al;
vehicle_invalidate(vehicle); vehicle->Invalidate();
return; return;
} }
@ -4921,7 +4921,7 @@ static void vehicle_update_rotating(rct_vehicle* vehicle)
if (sprite == vehicle->vehicle_sprite_type) if (sprite == vehicle->vehicle_sprite_type)
return; return;
vehicle->vehicle_sprite_type = sprite; vehicle->vehicle_sprite_type = sprite;
vehicle_invalidate(vehicle); vehicle->Invalidate();
return; return;
} }
@ -4985,7 +4985,7 @@ static void vehicle_update_space_rings_operating(rct_vehicle* vehicle)
if (spriteType != vehicle->vehicle_sprite_type) if (spriteType != vehicle->vehicle_sprite_type)
{ {
vehicle->vehicle_sprite_type = spriteType; vehicle->vehicle_sprite_type = spriteType;
vehicle_invalidate(vehicle); vehicle->Invalidate();
} }
} }
else else
@ -5011,7 +5011,7 @@ static void vehicle_update_haunted_house_operating(rct_vehicle* vehicle)
if (gCurrentTicks & 1) if (gCurrentTicks & 1)
{ {
vehicle->vehicle_sprite_type++; vehicle->vehicle_sprite_type++;
vehicle_invalidate(vehicle); vehicle->Invalidate();
if (vehicle->vehicle_sprite_type == 19) if (vehicle->vehicle_sprite_type == 19)
vehicle->vehicle_sprite_type = 0; vehicle->vehicle_sprite_type = 0;
@ -5035,7 +5035,7 @@ static void vehicle_update_haunted_house_operating(rct_vehicle* vehicle)
break; break;
case 75: case 75:
vehicle->vehicle_sprite_type = 1; vehicle->vehicle_sprite_type = 1;
vehicle_invalidate(vehicle); vehicle->Invalidate();
break; break;
case 400: case 400:
audio_play_sound_at_location(SOUND_HAUNTED_HOUSE_SCREAM_1, vehicle->x, vehicle->y, vehicle->z); audio_play_sound_at_location(SOUND_HAUNTED_HOUSE_SCREAM_1, vehicle->x, vehicle->y, vehicle->z);
@ -5045,7 +5045,7 @@ static void vehicle_update_haunted_house_operating(rct_vehicle* vehicle)
break; break;
case 775: case 775:
vehicle->vehicle_sprite_type = 1; vehicle->vehicle_sprite_type = 1;
vehicle_invalidate(vehicle); vehicle->Invalidate();
break; break;
case 1100: case 1100:
audio_play_sound_at_location(SOUND_HAUNTED_HOUSE_SCREAM_2, vehicle->x, vehicle->y, vehicle->z); audio_play_sound_at_location(SOUND_HAUNTED_HOUSE_SCREAM_2, vehicle->x, vehicle->y, vehicle->z);
@ -5092,13 +5092,13 @@ static void vehicle_update_top_spin_operating(rct_vehicle* vehicle)
if (rotation != vehicle->vehicle_sprite_type) if (rotation != vehicle->vehicle_sprite_type)
{ {
vehicle->vehicle_sprite_type = rotation; vehicle->vehicle_sprite_type = rotation;
vehicle_invalidate(vehicle); vehicle->Invalidate();
} }
rotation = sprite_map[vehicle->current_time].bank_rotation; rotation = sprite_map[vehicle->current_time].bank_rotation;
if (rotation != vehicle->bank_rotation) if (rotation != vehicle->bank_rotation)
{ {
vehicle->bank_rotation = rotation; vehicle->bank_rotation = rotation;
vehicle_invalidate(vehicle); vehicle->Invalidate();
} }
return; return;
} }
@ -5313,7 +5313,7 @@ static void vehicle_crash_on_land(rct_vehicle* vehicle)
vehicle->sprite_height_positive = 5; vehicle->sprite_height_positive = 5;
sprite_move(vehicle->x, vehicle->y, vehicle->z, (rct_sprite*)vehicle); sprite_move(vehicle->x, vehicle->y, vehicle->z, (rct_sprite*)vehicle);
vehicle_invalidate(vehicle); vehicle->Invalidate();
vehicle->crash_z = 0; vehicle->crash_z = 0;
} }
@ -5368,7 +5368,7 @@ static void vehicle_crash_on_water(rct_vehicle* vehicle)
vehicle->sprite_height_positive = 5; vehicle->sprite_height_positive = 5;
sprite_move(vehicle->x, vehicle->y, vehicle->z, (rct_sprite*)vehicle); sprite_move(vehicle->x, vehicle->y, vehicle->z, (rct_sprite*)vehicle);
vehicle_invalidate(vehicle); vehicle->Invalidate();
vehicle->crash_z = -1; vehicle->crash_z = -1;
} }
@ -6291,7 +6291,7 @@ static int32_t vehicle_update_motion_dodgems(rct_vehicle* vehicle)
vehicle->sprite_direction -= 2; vehicle->sprite_direction -= 2;
} }
vehicle->sprite_direction &= 0x1E; vehicle->sprite_direction &= 0x1E;
vehicle_invalidate(vehicle); vehicle->Invalidate();
} }
else if ((scenario_rand() & 0xFFFF) <= 2849) else if ((scenario_rand() & 0xFFFF) <= 2849)
{ {
@ -6300,7 +6300,7 @@ static int32_t vehicle_update_motion_dodgems(rct_vehicle* vehicle)
else else
vehicle->sprite_direction += 2; vehicle->sprite_direction += 2;
vehicle->sprite_direction &= 0x1E; vehicle->sprite_direction &= 0x1E;
vehicle_invalidate(vehicle); vehicle->Invalidate();
} }
} }
@ -6320,9 +6320,9 @@ static int32_t vehicle_update_motion_dodgems(rct_vehicle* vehicle)
if (!vehicle_update_dodgems_collision(vehicle, location.x, location.y, &collideSprite)) if (!vehicle_update_dodgems_collision(vehicle, location.x, location.y, &collideSprite))
{ {
vehicle_invalidate(vehicle); vehicle->Invalidate();
sprite_move(location.x, location.y, location.z, (rct_sprite*)vehicle); sprite_move(location.x, location.y, location.z, (rct_sprite*)vehicle);
vehicle_invalidate(vehicle); vehicle->Invalidate();
} }
} }
@ -6335,7 +6335,7 @@ static int32_t vehicle_update_motion_dodgems(rct_vehicle* vehicle)
unk_F64E20.y = vehicle->y; unk_F64E20.y = vehicle->y;
unk_F64E20.z = vehicle->z; unk_F64E20.z = vehicle->z;
vehicle_invalidate(vehicle); vehicle->Invalidate();
while (true) while (true)
{ {
@ -6390,7 +6390,7 @@ static int32_t vehicle_update_motion_dodgems(rct_vehicle* vehicle)
} }
sprite_move(unk_F64E20.x, unk_F64E20.y, unk_F64E20.z, (rct_sprite*)vehicle); sprite_move(unk_F64E20.x, unk_F64E20.y, unk_F64E20.z, (rct_sprite*)vehicle);
vehicle_invalidate(vehicle); vehicle->Invalidate();
} }
int32_t eax = vehicle->velocity / 2; int32_t eax = vehicle->velocity / 2;
@ -7051,7 +7051,7 @@ static void vehicle_update_swinging_car(rct_vehicle* vehicle)
if (swingSprite != vehicle->swing_sprite) if (swingSprite != vehicle->swing_sprite)
{ {
vehicle->swing_sprite = swingSprite; vehicle->swing_sprite = swingSprite;
vehicle_invalidate(vehicle); vehicle->Invalidate();
} }
} }
@ -7210,7 +7210,7 @@ static void vehicle_update_spinning_car(rct_vehicle* vehicle)
vehicle->spin_sprite += spinSpeed >> 8; vehicle->spin_sprite += spinSpeed >> 8;
// Note this actually increases the spin speed if going right! // Note this actually increases the spin speed if going right!
vehicle->spin_speed -= spinSpeed >> vehicleEntry->spinning_friction; vehicle->spin_speed -= spinSpeed >> vehicleEntry->spinning_friction;
vehicle_invalidate(vehicle); vehicle->Invalidate();
} }
/** /**
@ -7285,7 +7285,7 @@ static void vehicle_update_additional_animation(rct_vehicle* vehicle)
vehicle->z + SteamParticleOffsets[index].z); vehicle->z + SteamParticleOffsets[index].z);
} }
} }
vehicle_invalidate(vehicle); vehicle->Invalidate();
} }
break; break;
case VEHICLE_ENTRY_ANIMATION_SWAN: // loc_6D6424 case VEHICLE_ENTRY_ANIMATION_SWAN: // loc_6D6424
@ -7294,7 +7294,7 @@ static void vehicle_update_additional_animation(rct_vehicle* vehicle)
if (vehicle->animation_frame != al) if (vehicle->animation_frame != al)
{ {
vehicle->animation_frame = al; vehicle->animation_frame = al;
vehicle_invalidate(vehicle); vehicle->Invalidate();
} }
break; break;
case VEHICLE_ENTRY_ANIMATION_CANOES: // loc_6D6482 case VEHICLE_ENTRY_ANIMATION_CANOES: // loc_6D6482
@ -7304,7 +7304,7 @@ static void vehicle_update_additional_animation(rct_vehicle* vehicle)
if (vehicle->animation_frame != ah) if (vehicle->animation_frame != ah)
{ {
vehicle->animation_frame = ah; vehicle->animation_frame = ah;
vehicle_invalidate(vehicle); vehicle->Invalidate();
} }
break; break;
case VEHICLE_ENTRY_ANIMATION_ROW_BOATS: // loc_6D64F7 case VEHICLE_ENTRY_ANIMATION_ROW_BOATS: // loc_6D64F7
@ -7314,7 +7314,7 @@ static void vehicle_update_additional_animation(rct_vehicle* vehicle)
if (vehicle->animation_frame != ah) if (vehicle->animation_frame != ah)
{ {
vehicle->animation_frame = ah; vehicle->animation_frame = ah;
vehicle_invalidate(vehicle); vehicle->Invalidate();
} }
break; break;
case VEHICLE_ENTRY_ANIMATION_WATER_TRICYCLES: // loc_6D6453 case VEHICLE_ENTRY_ANIMATION_WATER_TRICYCLES: // loc_6D6453
@ -7323,7 +7323,7 @@ static void vehicle_update_additional_animation(rct_vehicle* vehicle)
if (vehicle->animation_frame != al) if (vehicle->animation_frame != al)
{ {
vehicle->animation_frame = al; vehicle->animation_frame = al;
vehicle_invalidate(vehicle); vehicle->Invalidate();
} }
break; break;
case VEHICLE_ENTRY_ANIMATION_OBSERVATION_TOWER: // loc_6D65C3 case VEHICLE_ENTRY_ANIMATION_OBSERVATION_TOWER: // loc_6D65C3
@ -7336,7 +7336,7 @@ static void vehicle_update_additional_animation(rct_vehicle* vehicle)
vehicle->var_C8 += 0x3333; vehicle->var_C8 += 0x3333;
vehicle->animation_frame += 1; vehicle->animation_frame += 1;
vehicle->animation_frame &= 7; vehicle->animation_frame &= 7;
vehicle_invalidate(vehicle); vehicle->Invalidate();
} }
break; break;
case VEHICLE_ENTRY_ANIMATION_HELICARS: // loc_6D63F5 case VEHICLE_ENTRY_ANIMATION_HELICARS: // loc_6D63F5
@ -7345,7 +7345,7 @@ static void vehicle_update_additional_animation(rct_vehicle* vehicle)
if (vehicle->animation_frame != al) if (vehicle->animation_frame != al)
{ {
vehicle->animation_frame = al; vehicle->animation_frame = al;
vehicle_invalidate(vehicle); vehicle->Invalidate();
} }
break; break;
case VEHICLE_ENTRY_ANIMATION_MONORAIL_CYCLES: // loc_6D64B6 case VEHICLE_ENTRY_ANIMATION_MONORAIL_CYCLES: // loc_6D64B6
@ -7357,7 +7357,7 @@ static void vehicle_update_additional_animation(rct_vehicle* vehicle)
if (vehicle->animation_frame != ah) if (vehicle->animation_frame != ah)
{ {
vehicle->animation_frame = ah; vehicle->animation_frame = ah;
vehicle_invalidate(vehicle); vehicle->Invalidate();
} }
} }
break; break;
@ -7379,7 +7379,7 @@ static void vehicle_update_additional_animation(rct_vehicle* vehicle)
vehicle->seat_rotation++; vehicle->seat_rotation++;
vehicle->animation_frame = (vehicle->seat_rotation - 4) & 7; vehicle->animation_frame = (vehicle->seat_rotation - 4) & 7;
vehicle_invalidate(vehicle); vehicle->Invalidate();
} }
} }
break; break;
@ -8727,7 +8727,7 @@ loc_6DC40E:
unk_F64E20.x = vehicle->x; unk_F64E20.x = vehicle->x;
unk_F64E20.y = vehicle->y; unk_F64E20.y = vehicle->y;
unk_F64E20.z = vehicle->z; unk_F64E20.z = vehicle->z;
vehicle_invalidate(vehicle); vehicle->Invalidate();
loc_6DC462: loc_6DC462:
if (vehicle->var_D3 == 0) if (vehicle->var_D3 == 0)
@ -9071,7 +9071,7 @@ loc_6DCA7A:
unk_F64E20.x = vehicle->x; unk_F64E20.x = vehicle->x;
unk_F64E20.y = vehicle->y; unk_F64E20.y = vehicle->y;
unk_F64E20.z = vehicle->z; unk_F64E20.z = vehicle->z;
vehicle_invalidate(vehicle); vehicle->Invalidate();
loc_6DCA9A: loc_6DCA9A:
regs.ax = vehicle->track_progress - 1; regs.ax = vehicle->track_progress - 1;
@ -9236,7 +9236,7 @@ loc_6DCD6B:
loc_6DCDE4: loc_6DCDE4:
sprite_move(unk_F64E20.x, unk_F64E20.y, unk_F64E20.z, (rct_sprite*)vehicle); sprite_move(unk_F64E20.x, unk_F64E20.y, unk_F64E20.z, (rct_sprite*)vehicle);
vehicle_invalidate(vehicle); vehicle->Invalidate();
loc_6DCE02: loc_6DCE02:
vehicle->acceleration /= _vehicleUnkF64E10; vehicle->acceleration /= _vehicleUnkF64E10;

View File

@ -234,6 +234,7 @@ struct rct_vehicle : rct_sprite_common
rct_vehicle* GetHead(); rct_vehicle* GetHead();
const rct_vehicle* GetHead() const; const rct_vehicle* GetHead() const;
const rct_vehicle* GetCar(size_t carIndex) const; const rct_vehicle* GetCar(size_t carIndex) const;
void Invalidate();
}; };
struct train_ref struct train_ref