diff --git a/src/openrct2/world/Duck.cpp b/src/openrct2/world/Duck.cpp index 197247f7ee..5a640cf075 100644 --- a/src/openrct2/world/Duck.cpp +++ b/src/openrct2/world/Duck.cpp @@ -334,24 +334,24 @@ void create_duck(const CoordsXY& pos) sprite->duck.frame = 0; } -void duck_update(Duck* duck) +void Duck::Update() { - switch (static_cast(duck->state)) + switch (static_cast(state)) { case DUCK_STATE::FLY_TO_WATER: - duck->UpdateFlyToWater(); + UpdateFlyToWater(); break; case DUCK_STATE::SWIM: - duck->UpdateSwim(); + UpdateSwim(); break; case DUCK_STATE::DRINK: - duck->UpdateDrink(); + UpdateDrink(); break; case DUCK_STATE::DOUBLE_DRINK: - duck->UpdateDoubleDrink(); + UpdateDoubleDrink(); break; case DUCK_STATE::FLY_AWAY: - duck->UpdateFlyAway(); + UpdateFlyAway(); break; } } diff --git a/src/openrct2/world/Particle.cpp b/src/openrct2/world/Particle.cpp index 2c6cf97e82..18f8858245 100644 --- a/src/openrct2/world/Particle.cpp +++ b/src/openrct2/world/Particle.cpp @@ -57,63 +57,61 @@ void crashed_vehicle_particle_create(rct_vehicle_colour colours, const CoordsXYZ * * rct2: 0x00673298 */ -void crashed_vehicle_particle_update(VehicleCrashParticle* particle) +void VehicleCrashParticle::Update() { - particle->Invalidate0(); - particle->time_to_live--; - if (particle->time_to_live == 0) + Invalidate0(); + time_to_live--; + if (time_to_live == 0) { - sprite_remove(particle); + sprite_remove(this); return; } // Apply gravity - particle->acceleration_z -= 5041; + acceleration_z -= 5041; // Apply air resistance - particle->acceleration_x -= (particle->acceleration_x / 256); - particle->acceleration_y -= (particle->acceleration_y / 256); - particle->acceleration_z -= (particle->acceleration_z / 256); + acceleration_x -= (acceleration_x / 256); + acceleration_y -= (acceleration_y / 256); + acceleration_z -= (acceleration_z / 256); // Update velocity and position - int32_t vx = particle->velocity_x + particle->acceleration_x; - int32_t vy = particle->velocity_y + particle->acceleration_y; - int32_t vz = particle->velocity_z + particle->acceleration_z; + int32_t vx = velocity_x + acceleration_x; + int32_t vy = velocity_y + acceleration_y; + int32_t vz = velocity_z + acceleration_z; - int16_t x = particle->x + (vx >> 16); - int16_t y = particle->y + (vy >> 16); - int16_t z = particle->z + (vz >> 16); + CoordsXYZ newLoc = { x + (vx >> 16), y + (vy >> 16), z + (vz >> 16) }; - particle->velocity_x = vx & 0xFFFF; - particle->velocity_y = vy & 0xFFFF; - particle->velocity_z = vz & 0xFFFF; + velocity_x = vx & 0xFFFF; + velocity_y = vy & 0xFFFF; + velocity_z = vz & 0xFFFF; // Check collision with land / water - int16_t landZ = tile_element_height({ x, y }); - int16_t waterZ = tile_element_water_height({ x, y }); + int16_t landZ = tile_element_height(newLoc); + int16_t waterZ = tile_element_water_height(newLoc); - if (waterZ != 0 && particle->z >= waterZ && z <= waterZ) + if (waterZ != 0 && z >= waterZ && newLoc.z <= waterZ) { // Splash - audio_play_sound_at_location(SoundId::Water2, { particle->x, particle->y, waterZ }); - crash_splash_create({ particle->x, particle->y, waterZ }); - sprite_remove(particle); + audio_play_sound_at_location(SoundId::Water2, { x, y, waterZ }); + crash_splash_create({ x, y, waterZ }); + sprite_remove(this); return; } - if (particle->z >= landZ && z <= landZ) + if (z >= landZ && newLoc.z <= landZ) { // Bounce - particle->acceleration_z *= -1; - z = landZ; + acceleration_z *= -1; + newLoc.z = landZ; } - particle->MoveTo({ x, y, z }); - particle->Invalidate0(); + MoveTo(newLoc); + Invalidate0(); - particle->frame += 85; - if (particle->frame >= 3072) + frame += 85; + if (frame >= 3072) { - particle->frame = 0; + frame = 0; } } @@ -140,12 +138,12 @@ void crash_splash_create(const CoordsXYZ& splashPos) * * rct2: 0x0067339D */ -void crash_splash_update(CrashSplashParticle* splash) +void CrashSplashParticle::Update() { - splash->Invalidate2(); - splash->frame += 85; - if (splash->frame >= 7168) + Invalidate2(); + frame += 85; + if (frame >= 7168) { - sprite_remove(splash); + sprite_remove(this); } } diff --git a/src/openrct2/world/Sprite.cpp b/src/openrct2/world/Sprite.cpp index f3e49567f5..7ad6aa9c4a 100644 --- a/src/openrct2/world/Sprite.cpp +++ b/src/openrct2/world/Sprite.cpp @@ -533,21 +533,21 @@ static void move_sprite_to_list(SpriteBase* sprite, EntityListId newListIndex) * * rct2: 0x00673200 */ -static void sprite_steam_particle_update(SteamParticle* steam) +void SteamParticle::Update() { - steam->Invalidate2(); + Invalidate2(); // Move up 1 z every 3 ticks (Starts after 4 ticks) - steam->time_to_move++; - if (steam->time_to_move >= 4) + time_to_move++; + if (time_to_move >= 4) { - steam->time_to_move = 1; - steam->MoveTo({ steam->x, steam->y, steam->z + 1 }); + time_to_move = 1; + MoveTo({ x, y, z + 1 }); } - steam->frame += 64; - if (steam->frame >= (56 * 64)) + frame += 64; + if (frame >= (56 * 64)) { - sprite_remove(steam); + sprite_remove(this); } } @@ -574,13 +574,13 @@ void sprite_misc_explosion_cloud_create(const CoordsXYZ& cloudPos) * * rct2: 0x00673385 */ -static void sprite_misc_explosion_cloud_update(rct_sprite* sprite) +void ExplosionCloud::Update() { - sprite->generic.Invalidate2(); - sprite->generic.frame += 128; - if (sprite->generic.frame >= (36 * 128)) + Invalidate2(); + frame += 128; + if (frame >= (36 * 128)) { - sprite_remove(&sprite->generic); + sprite_remove(this); } } @@ -607,13 +607,13 @@ void sprite_misc_explosion_flare_create(const CoordsXYZ& flarePos) * * rct2: 0x006733B4 */ -static void sprite_misc_explosion_flare_update(rct_sprite* sprite) +void ExplosionFlare::Update() { - sprite->generic.Invalidate2(); - sprite->generic.frame += 64; - if (sprite->generic.frame >= (124 * 64)) + Invalidate2(); + frame += 64; + if (frame >= (124 * 64)) { - sprite_remove(&sprite->generic); + sprite_remove(this); } } @@ -621,37 +621,37 @@ static void sprite_misc_explosion_flare_update(rct_sprite* sprite) * * rct2: 0x006731CD */ -static void sprite_misc_update(rct_sprite* sprite) +static void sprite_misc_update(SpriteBase* sprite) { - switch (sprite->generic.type) + switch (sprite->type) { case SPRITE_MISC_STEAM_PARTICLE: - sprite_steam_particle_update(reinterpret_cast(sprite)); + sprite->As()->Update(); break; case SPRITE_MISC_MONEY_EFFECT: - sprite->money_effect.Update(); + sprite->As()->Update(); break; case SPRITE_MISC_CRASHED_VEHICLE_PARTICLE: - crashed_vehicle_particle_update(reinterpret_cast(sprite)); + sprite->As()->Update(); break; case SPRITE_MISC_EXPLOSION_CLOUD: - sprite_misc_explosion_cloud_update(sprite); + sprite->As()->Update(); break; case SPRITE_MISC_CRASH_SPLASH: - crash_splash_update(reinterpret_cast(sprite)); + sprite->As()->Update(); break; case SPRITE_MISC_EXPLOSION_FLARE: - sprite_misc_explosion_flare_update(sprite); + sprite->As()->Update(); break; case SPRITE_MISC_JUMPING_FOUNTAIN_WATER: case SPRITE_MISC_JUMPING_FOUNTAIN_SNOW: - sprite->jumping_fountain.Update(); + sprite->As()->Update(); break; case SPRITE_MISC_BALLOON: - balloon_update(&sprite->balloon); + sprite->As()->Update(); break; case SPRITE_MISC_DUCK: - duck_update(&sprite->duck); + sprite->As()->Update(); break; } } @@ -664,8 +664,7 @@ void sprite_misc_update_all() { for (auto entity : EntityList(EntityListId::Misc)) { - // TODO: Use more specific Sprite class - sprite_misc_update(reinterpret_cast(entity)); + sprite_misc_update(entity); } } diff --git a/src/openrct2/world/Sprite.h b/src/openrct2/world/Sprite.h index 7837b93d43..748b846bcd 100644 --- a/src/openrct2/world/Sprite.h +++ b/src/openrct2/world/Sprite.h @@ -61,15 +61,18 @@ struct Duck : SpriteGeneric int16_t target_y; uint8_t state; + void Update(); + uint32_t GetFrameImage(int32_t direction) const; + void Invalidate(); + bool IsFlying(); + void Remove(); + +private: void UpdateFlyToWater(); void UpdateSwim(); void UpdateDrink(); void UpdateDoubleDrink(); void UpdateFlyAway(); - uint32_t GetFrameImage(int32_t direction) const; - void Invalidate(); - bool IsFlying(); - void Remove(); }; struct MoneyEffect : SpriteBase @@ -98,23 +101,30 @@ struct VehicleCrashParticle : SpriteGeneric int32_t acceleration_x; int32_t acceleration_y; int32_t acceleration_z; + + void Update(); }; struct ExplosionFlare : SpriteGeneric { + void Update(); }; struct ExplosionCloud : SpriteGeneric { + void Update(); }; struct CrashSplashParticle : SpriteGeneric { + void Update(); }; struct SteamParticle : SpriteGeneric { uint16_t time_to_move; + + void Update(); }; #pragma pack(push, 1)