From 030686dc6b95ffe25c1bacd3bf7c30b3842e9173 Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Sun, 21 Jun 2020 13:35:43 -0300 Subject: [PATCH 01/12] Make crashed_vehicle_particle_create use CoordsXYZ --- src/openrct2/ride/Vehicle.cpp | 6 +++--- src/openrct2/world/Particle.cpp | 4 ++-- src/openrct2/world/Sprite.h | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index f7bc0db324..b1fd6b1b34 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -3574,7 +3574,7 @@ void Vehicle::UpdateCollisionSetup() for (int32_t i = 0; i < 10; i++) { - crashed_vehicle_particle_create(train->colours, train->x, train->y, train->z); + crashed_vehicle_particle_create(train->colours, { train->x, train->y, train->z }); } train->flags |= SPRITE_FLAGS_IS_CRASHED_VEHICLE_SPRITE; @@ -5300,7 +5300,7 @@ void Vehicle::CrashOnLand() uint8_t numParticles = std::min(sprite_width, static_cast(7)); while (numParticles-- != 0) - crashed_vehicle_particle_create(colours, x, y, z); + crashed_vehicle_particle_create(colours, { x, y, z }); flags |= SPRITE_FLAGS_IS_CRASHED_VEHICLE_SPRITE; animation_frame = 0; @@ -5364,7 +5364,7 @@ void Vehicle::CrashOnWater() crash_splash_create(x - 4, y + 8, z); for (int32_t i = 0; i < 10; ++i) - crashed_vehicle_particle_create(colours, x - 4, y + 8, z); + crashed_vehicle_particle_create(colours, { x - 4, y + 8, z }); flags |= SPRITE_FLAGS_IS_CRASHED_VEHICLE_SPRITE; animation_frame = 0; diff --git a/src/openrct2/world/Particle.cpp b/src/openrct2/world/Particle.cpp index b13693552c..22c0a23a0e 100644 --- a/src/openrct2/world/Particle.cpp +++ b/src/openrct2/world/Particle.cpp @@ -27,7 +27,7 @@ template<> bool SpriteBase::Is() const * * rct2: 0x006735A1 */ -void crashed_vehicle_particle_create(rct_vehicle_colour colours, int32_t x, int32_t y, int32_t z) +void crashed_vehicle_particle_create(rct_vehicle_colour colours, const CoordsXYZ& vehiclePos) { VehicleCrashParticle* sprite = &create_sprite(SPRITE_IDENTIFIER_MISC)->crashed_vehicle_particle; if (sprite != nullptr) @@ -38,7 +38,7 @@ void crashed_vehicle_particle_create(rct_vehicle_colour colours, int32_t x, int3 sprite->sprite_height_negative = 8; sprite->sprite_height_positive = 8; sprite->sprite_identifier = SPRITE_IDENTIFIER_MISC; - sprite->MoveTo({ x, y, z }); + sprite->MoveTo(vehiclePos); sprite->type = SPRITE_MISC_CRASHED_VEHICLE_PARTICLE; sprite->frame = (scenario_rand() & 0xFF) * 12; diff --git a/src/openrct2/world/Sprite.h b/src/openrct2/world/Sprite.h index 14088e2306..c23fe318b4 100644 --- a/src/openrct2/world/Sprite.h +++ b/src/openrct2/world/Sprite.h @@ -249,7 +249,7 @@ uint32_t duck_get_frame_image(const Duck* duck, int32_t direction); /////////////////////////////////////////////////////////////// // Crash particles /////////////////////////////////////////////////////////////// -void crashed_vehicle_particle_create(rct_vehicle_colour colours, int32_t x, int32_t y, int32_t z); +void crashed_vehicle_particle_create(rct_vehicle_colour colours, const CoordsXYZ& vehiclePos); void crashed_vehicle_particle_update(VehicleCrashParticle* particle); void crash_splash_create(int32_t x, int32_t y, int32_t z); void crash_splash_update(CrashSplashParticle* splash); From 15bad3898d56ea5060d91b4e7852641c02a77aba Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Sun, 21 Jun 2020 13:41:11 -0300 Subject: [PATCH 02/12] Make crash_splash_create use CoordsXYZ --- src/openrct2/ride/Vehicle.cpp | 10 +++++----- src/openrct2/world/Particle.cpp | 6 +++--- src/openrct2/world/Sprite.h | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index b1fd6b1b34..8979b9361b 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -5357,11 +5357,11 @@ void Vehicle::CrashOnWater() sub_state = 2; audio_play_sound_at_location(SoundId::Water1, { x, y, z }); - crash_splash_create(x, y, z); - crash_splash_create(x - 8, y - 9, z); - crash_splash_create(x + 11, y - 9, z); - crash_splash_create(x + 11, y + 8, z); - crash_splash_create(x - 4, y + 8, z); + crash_splash_create({ x, y, z }); + crash_splash_create({ x - 8, y - 9, z }); + crash_splash_create({ x + 11, y - 9, z }); + crash_splash_create({ x + 11, y + 8, z }); + crash_splash_create({ x - 4, y + 8, z }); for (int32_t i = 0; i < 10; ++i) crashed_vehicle_particle_create(colours, { x - 4, y + 8, z }); diff --git a/src/openrct2/world/Particle.cpp b/src/openrct2/world/Particle.cpp index 22c0a23a0e..2c6cf97e82 100644 --- a/src/openrct2/world/Particle.cpp +++ b/src/openrct2/world/Particle.cpp @@ -96,7 +96,7 @@ void crashed_vehicle_particle_update(VehicleCrashParticle* particle) { // Splash audio_play_sound_at_location(SoundId::Water2, { particle->x, particle->y, waterZ }); - crash_splash_create(particle->x, particle->y, waterZ); + crash_splash_create({ particle->x, particle->y, waterZ }); sprite_remove(particle); return; } @@ -121,7 +121,7 @@ void crashed_vehicle_particle_update(VehicleCrashParticle* particle) * * rct2: 0x00673699 */ -void crash_splash_create(int32_t x, int32_t y, int32_t z) +void crash_splash_create(const CoordsXYZ& splashPos) { SpriteGeneric* sprite = &create_sprite(SPRITE_IDENTIFIER_MISC)->generic; if (sprite != nullptr) @@ -130,7 +130,7 @@ void crash_splash_create(int32_t x, int32_t y, int32_t z) sprite->sprite_height_negative = 51; sprite->sprite_height_positive = 16; sprite->sprite_identifier = SPRITE_IDENTIFIER_MISC; - sprite->MoveTo({ x, y, z + 3 }); + sprite->MoveTo(splashPos + CoordsXYZ{ 0, 0, 3 }); sprite->type = SPRITE_MISC_CRASH_SPLASH; sprite->frame = 0; } diff --git a/src/openrct2/world/Sprite.h b/src/openrct2/world/Sprite.h index c23fe318b4..e39671528a 100644 --- a/src/openrct2/world/Sprite.h +++ b/src/openrct2/world/Sprite.h @@ -251,7 +251,7 @@ uint32_t duck_get_frame_image(const Duck* duck, int32_t direction); /////////////////////////////////////////////////////////////// void crashed_vehicle_particle_create(rct_vehicle_colour colours, const CoordsXYZ& vehiclePos); void crashed_vehicle_particle_update(VehicleCrashParticle* particle); -void crash_splash_create(int32_t x, int32_t y, int32_t z); +void crash_splash_create(const CoordsXYZ& splashPos); void crash_splash_update(CrashSplashParticle* splash); rct_sprite_checksum sprite_checksum(); From d5c7063214a0f3389b3b6b9b0d57ef056fc0a53c Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Sun, 21 Jun 2020 13:43:42 -0300 Subject: [PATCH 03/12] Make create_balloon use CoordsXYZ --- src/openrct2/peep/Guest.cpp | 2 +- src/openrct2/peep/Peep.cpp | 2 +- src/openrct2/world/Balloon.cpp | 4 ++-- src/openrct2/world/Sprite.h | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/openrct2/peep/Guest.cpp b/src/openrct2/peep/Guest.cpp index 19f3021e90..d4a14d49e8 100644 --- a/src/openrct2/peep/Guest.cpp +++ b/src/openrct2/peep/Guest.cpp @@ -6831,7 +6831,7 @@ void Guest::UpdateSpriteType() isBalloonPopped = true; audio_play_sound_at_location(SoundId::BalloonPop, { x, y, z }); } - create_balloon(x, y, z + 9, BalloonColour, isBalloonPopped); + create_balloon({ x, y, z + 9 }, BalloonColour, isBalloonPopped); } ItemStandardFlags &= ~PEEP_ITEM_BALLOON; WindowInvalidateFlags |= PEEP_INVALIDATE_PEEP_INVENTORY; diff --git a/src/openrct2/peep/Peep.cpp b/src/openrct2/peep/Peep.cpp index 4b9eb8b489..a39171e295 100644 --- a/src/openrct2/peep/Peep.cpp +++ b/src/openrct2/peep/Peep.cpp @@ -3362,7 +3362,7 @@ static void peep_release_balloon(Guest* peep, int16_t spawn_height) if (peep->SpriteType == PEEP_SPRITE_TYPE_BALLOON && peep->x != LOCATION_NULL) { - create_balloon(peep->x, peep->y, spawn_height, peep->BalloonColour, false); + create_balloon({ peep->x, peep->y, spawn_height }, peep->BalloonColour, false); peep->WindowInvalidateFlags |= PEEP_INVALIDATE_PEEP_INVENTORY; peep->UpdateSpriteType(); } diff --git a/src/openrct2/world/Balloon.cpp b/src/openrct2/world/Balloon.cpp index 86b618e160..b4eace93c8 100644 --- a/src/openrct2/world/Balloon.cpp +++ b/src/openrct2/world/Balloon.cpp @@ -79,7 +79,7 @@ void Balloon::Pop() audio_play_sound_at_location(SoundId::BalloonPop, { x, y, z }); } -void create_balloon(int32_t x, int32_t y, int32_t z, int32_t colour, bool isPopped) +void create_balloon(const CoordsXYZ& balloonPos, int32_t colour, bool isPopped) { rct_sprite* sprite = create_sprite(SPRITE_IDENTIFIER_MISC); if (sprite != nullptr) @@ -88,7 +88,7 @@ void create_balloon(int32_t x, int32_t y, int32_t z, int32_t colour, bool isPopp sprite->balloon.sprite_height_negative = 22; sprite->balloon.sprite_height_positive = 11; sprite->balloon.sprite_identifier = SPRITE_IDENTIFIER_MISC; - sprite->balloon.MoveTo({ x, y, z }); + sprite->balloon.MoveTo(balloonPos); sprite->balloon.type = SPRITE_MISC_BALLOON; sprite->balloon.time_to_move = 0; sprite->balloon.frame = 0; diff --git a/src/openrct2/world/Sprite.h b/src/openrct2/world/Sprite.h index e39671528a..841605a45b 100644 --- a/src/openrct2/world/Sprite.h +++ b/src/openrct2/world/Sprite.h @@ -234,7 +234,7 @@ void sprite_position_tween_reset(); /////////////////////////////////////////////////////////////// // Balloon /////////////////////////////////////////////////////////////// -void create_balloon(int32_t x, int32_t y, int32_t z, int32_t colour, bool isPopped); +void create_balloon(const CoordsXYZ& balloonPos, int32_t colour, bool isPopped); void balloon_update(Balloon* balloon); /////////////////////////////////////////////////////////////// From ae1e9b75edabdd9336ddfa5cbc5999f293b6e6e9 Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Sun, 21 Jun 2020 13:50:54 -0300 Subject: [PATCH 04/12] Make sprite_set_coordinates use CoordsXYZ --- src/openrct2/world/Sprite.cpp | 21 +++++++++++---------- src/openrct2/world/Sprite.h | 2 +- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/openrct2/world/Sprite.cpp b/src/openrct2/world/Sprite.cpp index 0bbc1709cc..5134d6fa7a 100644 --- a/src/openrct2/world/Sprite.cpp +++ b/src/openrct2/world/Sprite.cpp @@ -715,22 +715,21 @@ void SpriteBase::MoveTo(const CoordsXYZ& newLocation) } else { - sprite_set_coordinates(loc.x, loc.y, loc.z, this); + sprite_set_coordinates(loc, this); } } -void sprite_set_coordinates(int16_t x, int16_t y, int16_t z, SpriteBase* sprite) +void sprite_set_coordinates(const CoordsXYZ& spritePos, SpriteBase* sprite) { - CoordsXYZ coords3d = { x, y, z }; - auto screenCoords = translate_3d_to_2d_with_z(get_current_rotation(), coords3d); + auto screenCoords = translate_3d_to_2d_with_z(get_current_rotation(), spritePos); sprite->sprite_left = screenCoords.x - sprite->sprite_width; sprite->sprite_right = screenCoords.x + sprite->sprite_width; sprite->sprite_top = screenCoords.y - sprite->sprite_height_negative; sprite->sprite_bottom = screenCoords.y + sprite->sprite_height_positive; - sprite->x = x; - sprite->y = y; - sprite->z = z; + sprite->x = spritePos.x; + sprite->y = spritePos.y; + sprite->z = spritePos.z; } /** @@ -938,8 +937,10 @@ void sprite_position_tween_all(float alpha) continue; } sprite_set_coordinates( - std::round(posB.x * alpha + posA.x * inv), std::round(posB.y * alpha + posA.y * inv), - std::round(posB.z * alpha + posA.z * inv), sprite); + { static_cast(std::round(posB.x * alpha + posA.x * inv)), + static_cast(std::round(posB.y * alpha + posA.y * inv)), + static_cast(std::round(posB.z * alpha + posA.z * inv)) }, + sprite); sprite->Invalidate2(); } } @@ -958,7 +959,7 @@ void sprite_position_tween_restore() sprite->Invalidate2(); auto pos = _spritelocations2[i]; - sprite_set_coordinates(pos.x, pos.y, pos.z, sprite); + sprite_set_coordinates(pos, sprite); } } } diff --git a/src/openrct2/world/Sprite.h b/src/openrct2/world/Sprite.h index 841605a45b..c6669a8d9b 100644 --- a/src/openrct2/world/Sprite.h +++ b/src/openrct2/world/Sprite.h @@ -217,7 +217,7 @@ void reset_sprite_list(); void reset_sprite_spatial_index(); void sprite_clear_all_unused(); void sprite_misc_update_all(); -void sprite_set_coordinates(int16_t x, int16_t y, int16_t z, SpriteBase* sprite); +void sprite_set_coordinates(const CoordsXYZ& spritePos, SpriteBase* sprite); void sprite_remove(SpriteBase* sprite); void litter_create(int32_t x, int32_t y, int32_t z, int32_t direction, int32_t type); void litter_remove_at(int32_t x, int32_t y, int32_t z); From 2e31a7d64d11835c926aeeb016b092b3783ee5f6 Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Sun, 21 Jun 2020 13:58:13 -0300 Subject: [PATCH 05/12] Make sprite_misc_explosion_cloud_create use CoordsXYZ --- src/openrct2/peep/Guest.cpp | 2 +- src/openrct2/ride/Vehicle.cpp | 10 +++++----- src/openrct2/world/Sprite.cpp | 4 ++-- src/openrct2/world/Sprite.h | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/openrct2/peep/Guest.cpp b/src/openrct2/peep/Guest.cpp index d4a14d49e8..a04eef3357 100644 --- a/src/openrct2/peep/Guest.cpp +++ b/src/openrct2/peep/Guest.cpp @@ -714,7 +714,7 @@ void Guest::Tick128UpdateGuest(int32_t index) { audio_play_sound_at_location(SoundId::Crash, { x, y, z }); - sprite_misc_explosion_cloud_create(x, y, z + 16); + sprite_misc_explosion_cloud_create({ x, y, z + 16 }); sprite_misc_explosion_flare_create(x, y, z + 16); Remove(); diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index 8979b9361b..e30dc71811 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -3570,7 +3570,7 @@ void Vehicle::UpdateCollisionSetup() audio_play_sound_at_location(SoundId::Crash, { train->x, train->y, train->z }); - sprite_misc_explosion_cloud_create(train->x, train->y, train->z); + sprite_misc_explosion_cloud_create({ train->x, train->y, train->z }); for (int32_t i = 0; i < 10; i++) { @@ -5294,7 +5294,7 @@ void Vehicle::CrashOnLand() sub_state = 2; audio_play_sound_at_location(SoundId::Crash, { x, y, z }); - sprite_misc_explosion_cloud_create(x, y, z); + sprite_misc_explosion_cloud_create({ x, y, z }); sprite_misc_explosion_flare_create(x, y, z); uint8_t numParticles = std::min(sprite_width, static_cast(7)); @@ -5397,9 +5397,9 @@ void Vehicle::UpdateCrash() curVehicle->crash_z++; if ((scenario_rand() & 0xFFFF) <= 0x1555) { - auto xOffset = (scenario_rand() & 2) - 1; - auto yOffset = (scenario_rand() & 2) - 1; - sprite_misc_explosion_cloud_create(curVehicle->x + xOffset, curVehicle->y + yOffset, curVehicle->z); + int32_t xOffset = (scenario_rand() & 2) - 1; + int32_t yOffset = (scenario_rand() & 2) - 1; + sprite_misc_explosion_cloud_create({ curVehicle->x + xOffset, curVehicle->y + yOffset, curVehicle->z }); } } if (curVehicle->var_C8 + 7281 > 0xFFFF) diff --git a/src/openrct2/world/Sprite.cpp b/src/openrct2/world/Sprite.cpp index 5134d6fa7a..b4f785563f 100644 --- a/src/openrct2/world/Sprite.cpp +++ b/src/openrct2/world/Sprite.cpp @@ -521,7 +521,7 @@ static void sprite_steam_particle_update(SteamParticle* steam) * * rct2: 0x0067363D */ -void sprite_misc_explosion_cloud_create(int32_t x, int32_t y, int32_t z) +void sprite_misc_explosion_cloud_create(const CoordsXYZ& cloudPos) { SpriteGeneric* sprite = &create_sprite(SPRITE_IDENTIFIER_MISC)->generic; if (sprite != nullptr) @@ -530,7 +530,7 @@ void sprite_misc_explosion_cloud_create(int32_t x, int32_t y, int32_t z) sprite->sprite_height_negative = 32; sprite->sprite_height_positive = 34; sprite->sprite_identifier = SPRITE_IDENTIFIER_MISC; - sprite->MoveTo({ x, y, z + 4 }); + sprite->MoveTo(cloudPos + CoordsXYZ{ 0, 0, 4 }); sprite->type = SPRITE_MISC_EXPLOSION_CLOUD; sprite->frame = 0; } diff --git a/src/openrct2/world/Sprite.h b/src/openrct2/world/Sprite.h index c6669a8d9b..1ffcf1c4e9 100644 --- a/src/openrct2/world/Sprite.h +++ b/src/openrct2/world/Sprite.h @@ -222,7 +222,7 @@ void sprite_remove(SpriteBase* sprite); void litter_create(int32_t x, int32_t y, int32_t z, int32_t direction, int32_t type); void litter_remove_at(int32_t x, int32_t y, int32_t z); uint16_t remove_floating_sprites(); -void sprite_misc_explosion_cloud_create(int32_t x, int32_t y, int32_t z); +void sprite_misc_explosion_cloud_create(const CoordsXYZ& cloudPos); void sprite_misc_explosion_flare_create(int32_t x, int32_t y, int32_t z); uint16_t sprite_get_first_in_quadrant(int32_t x, int32_t y); void sprite_position_tween_store_a(); From f329644dd53fbca52b803f82f81b2f121f47ac4a Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Sun, 21 Jun 2020 14:00:37 -0300 Subject: [PATCH 06/12] Make sprite_misc_explosion_flare_create use CoordsXYZ --- src/openrct2/peep/Guest.cpp | 2 +- src/openrct2/ride/Vehicle.cpp | 2 +- src/openrct2/world/Sprite.cpp | 4 ++-- src/openrct2/world/Sprite.h | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/openrct2/peep/Guest.cpp b/src/openrct2/peep/Guest.cpp index a04eef3357..ce6e706867 100644 --- a/src/openrct2/peep/Guest.cpp +++ b/src/openrct2/peep/Guest.cpp @@ -715,7 +715,7 @@ void Guest::Tick128UpdateGuest(int32_t index) audio_play_sound_at_location(SoundId::Crash, { x, y, z }); sprite_misc_explosion_cloud_create({ x, y, z + 16 }); - sprite_misc_explosion_flare_create(x, y, z + 16); + sprite_misc_explosion_flare_create({ x, y, z + 16 }); Remove(); return; diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index e30dc71811..8abca3861d 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -5295,7 +5295,7 @@ void Vehicle::CrashOnLand() audio_play_sound_at_location(SoundId::Crash, { x, y, z }); sprite_misc_explosion_cloud_create({ x, y, z }); - sprite_misc_explosion_flare_create(x, y, z); + sprite_misc_explosion_flare_create({ x, y, z }); uint8_t numParticles = std::min(sprite_width, static_cast(7)); diff --git a/src/openrct2/world/Sprite.cpp b/src/openrct2/world/Sprite.cpp index b4f785563f..b2d6b989c7 100644 --- a/src/openrct2/world/Sprite.cpp +++ b/src/openrct2/world/Sprite.cpp @@ -554,7 +554,7 @@ static void sprite_misc_explosion_cloud_update(rct_sprite* sprite) * * rct2: 0x0067366B */ -void sprite_misc_explosion_flare_create(int32_t x, int32_t y, int32_t z) +void sprite_misc_explosion_flare_create(const CoordsXYZ& flarePos) { SpriteGeneric* sprite = &create_sprite(SPRITE_IDENTIFIER_MISC)->generic; if (sprite != nullptr) @@ -563,7 +563,7 @@ void sprite_misc_explosion_flare_create(int32_t x, int32_t y, int32_t z) sprite->sprite_height_negative = 85; sprite->sprite_height_positive = 8; sprite->sprite_identifier = SPRITE_IDENTIFIER_MISC; - sprite->MoveTo({ x, y, z + 4 }); + sprite->MoveTo(flarePos + CoordsXYZ{ 0, 0, 4 }); sprite->type = SPRITE_MISC_EXPLOSION_FLARE; sprite->frame = 0; } diff --git a/src/openrct2/world/Sprite.h b/src/openrct2/world/Sprite.h index 1ffcf1c4e9..3d63c51c63 100644 --- a/src/openrct2/world/Sprite.h +++ b/src/openrct2/world/Sprite.h @@ -223,7 +223,7 @@ void litter_create(int32_t x, int32_t y, int32_t z, int32_t direction, int32_t t void litter_remove_at(int32_t x, int32_t y, int32_t z); uint16_t remove_floating_sprites(); void sprite_misc_explosion_cloud_create(const CoordsXYZ& cloudPos); -void sprite_misc_explosion_flare_create(int32_t x, int32_t y, int32_t z); +void sprite_misc_explosion_flare_create(const CoordsXYZ& flarePos); uint16_t sprite_get_first_in_quadrant(int32_t x, int32_t y); void sprite_position_tween_store_a(); void sprite_position_tween_store_b(); From e24de95b825a917b4761dd080ac8f5d617be018c Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Sun, 21 Jun 2020 14:03:35 -0300 Subject: [PATCH 07/12] Make sprite_get_first_in_quadrant use CoordsXY --- src/openrct2/world/Sprite.cpp | 4 ++-- src/openrct2/world/Sprite.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/openrct2/world/Sprite.cpp b/src/openrct2/world/Sprite.cpp index b2d6b989c7..15d1d73068 100644 --- a/src/openrct2/world/Sprite.cpp +++ b/src/openrct2/world/Sprite.cpp @@ -122,9 +122,9 @@ SpriteBase* GetEntity(size_t sprite_idx) return GetEntity(sprite_idx); } -uint16_t sprite_get_first_in_quadrant(int32_t x, int32_t y) +uint16_t sprite_get_first_in_quadrant(const CoordsXY& spritePos) { - return gSpriteSpatialIndex[GetSpatialIndexOffset(x, y)]; + return gSpriteSpatialIndex[GetSpatialIndexOffset(spritePos.x, spritePos.y)]; } static void invalidate_sprite_max_zoom(SpriteBase* sprite, int32_t maxZoom) diff --git a/src/openrct2/world/Sprite.h b/src/openrct2/world/Sprite.h index 3d63c51c63..4688d85015 100644 --- a/src/openrct2/world/Sprite.h +++ b/src/openrct2/world/Sprite.h @@ -224,7 +224,7 @@ void litter_remove_at(int32_t x, int32_t y, int32_t z); uint16_t remove_floating_sprites(); void sprite_misc_explosion_cloud_create(const CoordsXYZ& cloudPos); void sprite_misc_explosion_flare_create(const CoordsXYZ& flarePos); -uint16_t sprite_get_first_in_quadrant(int32_t x, int32_t y); +uint16_t sprite_get_first_in_quadrant(const CoordsXY& spritePos); void sprite_position_tween_store_a(); void sprite_position_tween_store_b(); void sprite_position_tween_all(float nudge); @@ -326,7 +326,7 @@ private: public: EntityTileList(const CoordsXY& loc) - : FirstEntity(sprite_get_first_in_quadrant(loc.x, loc.y)) + : FirstEntity(sprite_get_first_in_quadrant(loc)) { } From 7622ca513e9eacee35a470fa184333863515169f Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Sun, 21 Jun 2020 14:06:56 -0300 Subject: [PATCH 08/12] Make litter_remove_at use CoordsXYZ --- src/openrct2/peep/Staff.cpp | 2 +- src/openrct2/world/Sprite.cpp | 8 ++++---- src/openrct2/world/Sprite.h | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/openrct2/peep/Staff.cpp b/src/openrct2/peep/Staff.cpp index 704c49cc4c..0be73aa635 100644 --- a/src/openrct2/peep/Staff.cpp +++ b/src/openrct2/peep/Staff.cpp @@ -1386,7 +1386,7 @@ void Staff::UpdateSweeping() if (Action == PEEP_ACTION_STAFF_SWEEP && ActionFrame == 8) { // Remove sick at this location - litter_remove_at(x, y, z); + litter_remove_at({ x, y, z }); StaffLitterSwept++; WindowInvalidateFlags |= PEEP_INVALIDATE_STAFF_STATS; } diff --git a/src/openrct2/world/Sprite.cpp b/src/openrct2/world/Sprite.cpp index 15d1d73068..df04024f5d 100644 --- a/src/openrct2/world/Sprite.cpp +++ b/src/openrct2/world/Sprite.cpp @@ -836,13 +836,13 @@ void litter_create(int32_t x, int32_t y, int32_t z, int32_t direction, int32_t t * * rct2: 0x006738E1 */ -void litter_remove_at(int32_t x, int32_t y, int32_t z) +void litter_remove_at(const CoordsXYZ& litterPos) { - for (auto litter : EntityTileList({ x, y })) + for (auto litter : EntityTileList(litterPos)) { - if (abs(litter->z - z) <= 16) + if (abs(litter->z - litterPos.z) <= 16) { - if (abs(litter->x - x) <= 8 && abs(litter->y - y) <= 8) + if (abs(litter->x - litterPos.x) <= 8 && abs(litter->y - litterPos.y) <= 8) { litter->Invalidate0(); sprite_remove(litter); diff --git a/src/openrct2/world/Sprite.h b/src/openrct2/world/Sprite.h index 4688d85015..2943b040e1 100644 --- a/src/openrct2/world/Sprite.h +++ b/src/openrct2/world/Sprite.h @@ -220,7 +220,7 @@ void sprite_misc_update_all(); void sprite_set_coordinates(const CoordsXYZ& spritePos, SpriteBase* sprite); void sprite_remove(SpriteBase* sprite); void litter_create(int32_t x, int32_t y, int32_t z, int32_t direction, int32_t type); -void litter_remove_at(int32_t x, int32_t y, int32_t z); +void litter_remove_at(const CoordsXYZ& litterPos); uint16_t remove_floating_sprites(); void sprite_misc_explosion_cloud_create(const CoordsXYZ& cloudPos); void sprite_misc_explosion_flare_create(const CoordsXYZ& flarePos); From 40a7dfbb2406cae6d3740822cd8b4d4bc0900981 Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Sun, 21 Jun 2020 14:13:22 -0300 Subject: [PATCH 09/12] Make litter_create use CoordsXYZD --- src/openrct2/peep/Guest.cpp | 12 ++++++------ src/openrct2/peep/Peep.cpp | 2 +- src/openrct2/world/Sprite.cpp | 13 +++++++------ src/openrct2/world/Sprite.h | 2 +- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/openrct2/peep/Guest.cpp b/src/openrct2/peep/Guest.cpp index ce6e706867..afc5da8c3a 100644 --- a/src/openrct2/peep/Guest.cpp +++ b/src/openrct2/peep/Guest.cpp @@ -5314,9 +5314,9 @@ void Guest::UpdateWalking() int32_t litterType = litter_types[scenario_rand() & 0x3]; int32_t litterX = x + (scenario_rand() & 0x7) - 3; int32_t litterY = y + (scenario_rand() & 0x7) - 3; - int32_t litterDirection = (scenario_rand() & 0x3); + Direction litterDirection = (scenario_rand() & 0x3); - litter_create(litterX, litterY, z, litterDirection, litterType); + litter_create({ litterX, litterY, z, litterDirection }, litterType); } } } @@ -5352,9 +5352,9 @@ void Guest::UpdateWalking() int32_t litterX = x + (scenario_rand() & 0x7) - 3; int32_t litterY = y + (scenario_rand() & 0x7) - 3; - int32_t litterDirection = (scenario_rand() & 0x3); + Direction litterDirection = (scenario_rand() & 0x3); - litter_create(litterX, litterY, z, litterDirection, litterType); + litter_create({ litterX, litterY, z, litterDirection }, litterType); } } @@ -5917,7 +5917,7 @@ void Guest::UpdateUsingBin() int32_t litterX = x + (scenario_rand() & 7) - 3; int32_t litterY = y + (scenario_rand() & 7) - 3; - litter_create(litterX, litterY, z, scenario_rand() & 3, litterType); + litter_create({ litterX, litterY, z, static_cast(scenario_rand() & 3) }, litterType); ItemStandardFlags &= ~(1 << cur_container); WindowInvalidateFlags |= PEEP_INVALIDATE_PEEP_INVENTORY; @@ -5951,7 +5951,7 @@ void Guest::UpdateUsingBin() int32_t litterX = x + (scenario_rand() & 7) - 3; int32_t litterY = y + (scenario_rand() & 7) - 3; - litter_create(litterX, litterY, z, scenario_rand() & 3, litterType); + litter_create({ litterX, litterY, z, static_cast(scenario_rand() & 3) }, litterType); ItemExtraFlags &= ~(1 << cur_container); WindowInvalidateFlags |= PEEP_INVALIDATE_PEEP_INVENTORY; diff --git a/src/openrct2/peep/Peep.cpp b/src/openrct2/peep/Peep.cpp index a39171e295..5beb991eb2 100644 --- a/src/openrct2/peep/Peep.cpp +++ b/src/openrct2/peep/Peep.cpp @@ -653,7 +653,7 @@ std::optional Peep::UpdateAction(int16_t& xy_distance) WindowInvalidateFlags |= PEEP_INVALIDATE_PEEP_2; // Create sick at location - litter_create(x, y, z, sprite_direction, (sprite_index & 1) ? LITTER_TYPE_SICK_ALT : LITTER_TYPE_SICK); + litter_create({ x, y, z, sprite_direction }, (sprite_index & 1) ? LITTER_TYPE_SICK_ALT : LITTER_TYPE_SICK); SoundId coughs[4] = { SoundId::Cough1, SoundId::Cough2, SoundId::Cough3, SoundId::Cough4 }; auto soundId = coughs[scenario_rand() & 3]; diff --git a/src/openrct2/world/Sprite.cpp b/src/openrct2/world/Sprite.cpp index df04024f5d..97957d4d50 100644 --- a/src/openrct2/world/Sprite.cpp +++ b/src/openrct2/world/Sprite.cpp @@ -786,15 +786,16 @@ static bool litter_can_be_at(int32_t x, int32_t y, int32_t z) * * rct2: 0x0067375D */ -void litter_create(int32_t x, int32_t y, int32_t z, int32_t direction, int32_t type) +void litter_create(const CoordsXYZD& litterPos, int32_t type) { if (gCheatsDisableLittering) return; - x += CoordsDirectionDelta[direction >> 3].x / 8; - y += CoordsDirectionDelta[direction >> 3].y / 8; + auto offsetLitterPos = litterPos + + CoordsXY{ CoordsDirectionDelta[litterPos.direction >> 3].x / 8, + CoordsDirectionDelta[litterPos.direction >> 3].y / 8 }; - if (!litter_can_be_at(x, y, z)) + if (!litter_can_be_at(offsetLitterPos.x, offsetLitterPos.y, offsetLitterPos.z)) return; if (gSpriteListCount[SPRITE_LIST_LITTER] >= 500) @@ -821,13 +822,13 @@ void litter_create(int32_t x, int32_t y, int32_t z, int32_t direction, int32_t t if (litter == nullptr) return; - litter->sprite_direction = direction; + litter->sprite_direction = offsetLitterPos.direction; litter->sprite_width = 6; litter->sprite_height_negative = 6; litter->sprite_height_positive = 3; litter->sprite_identifier = SPRITE_IDENTIFIER_LITTER; litter->type = type; - litter->MoveTo({ x, y, z }); + litter->MoveTo(offsetLitterPos); litter->Invalidate0(); litter->creationTick = gScenarioTicks; } diff --git a/src/openrct2/world/Sprite.h b/src/openrct2/world/Sprite.h index 2943b040e1..815e885736 100644 --- a/src/openrct2/world/Sprite.h +++ b/src/openrct2/world/Sprite.h @@ -219,7 +219,7 @@ void sprite_clear_all_unused(); void sprite_misc_update_all(); void sprite_set_coordinates(const CoordsXYZ& spritePos, SpriteBase* sprite); void sprite_remove(SpriteBase* sprite); -void litter_create(int32_t x, int32_t y, int32_t z, int32_t direction, int32_t type); +void litter_create(const CoordsXYZD& litterPos, int32_t type); void litter_remove_at(const CoordsXYZ& litterPos); uint16_t remove_floating_sprites(); void sprite_misc_explosion_cloud_create(const CoordsXYZ& cloudPos); From 3c75481d8a298b015f491256de9d34e85296197a Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Sun, 21 Jun 2020 14:14:44 -0300 Subject: [PATCH 10/12] Make litter_can_be_at use CoordsXYZ --- src/openrct2/world/Sprite.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/openrct2/world/Sprite.cpp b/src/openrct2/world/Sprite.cpp index 97957d4d50..b6a8735a2a 100644 --- a/src/openrct2/world/Sprite.cpp +++ b/src/openrct2/world/Sprite.cpp @@ -758,14 +758,14 @@ void sprite_remove(SpriteBase* sprite) *spriteIndex = sprite->next_in_quadrant; } -static bool litter_can_be_at(int32_t x, int32_t y, int32_t z) +static bool litter_can_be_at(const CoordsXYZ& mapPos) { TileElement* tileElement; - if (!map_is_location_owned({ x, y, z })) + if (!map_is_location_owned(mapPos)) return false; - tileElement = map_get_first_element_at({ x, y }); + tileElement = map_get_first_element_at(mapPos); if (tileElement == nullptr) return false; do @@ -774,7 +774,7 @@ static bool litter_can_be_at(int32_t x, int32_t y, int32_t z) continue; int32_t pathZ = tileElement->GetBaseZ(); - if (pathZ < z || pathZ >= z + 32) + if (pathZ < mapPos.z || pathZ >= mapPos.z + 32) continue; return !tile_element_is_underground(tileElement); @@ -795,7 +795,7 @@ void litter_create(const CoordsXYZD& litterPos, int32_t type) + CoordsXY{ CoordsDirectionDelta[litterPos.direction >> 3].x / 8, CoordsDirectionDelta[litterPos.direction >> 3].y / 8 }; - if (!litter_can_be_at(offsetLitterPos.x, offsetLitterPos.y, offsetLitterPos.z)) + if (!litter_can_be_at(offsetLitterPos)) return; if (gSpriteListCount[SPRITE_LIST_LITTER] >= 500) From f6dae982a6774d7129ad74e5bbe0691f3db59239 Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Sun, 21 Jun 2020 14:18:00 -0300 Subject: [PATCH 11/12] Make MoneyEffect::CreateAt use CoordsXYZ --- src/openrct2/peep/Guest.cpp | 2 +- src/openrct2/world/MoneyEffect.cpp | 6 +++--- src/openrct2/world/Sprite.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/openrct2/peep/Guest.cpp b/src/openrct2/peep/Guest.cpp index afc5da8c3a..410a2ba406 100644 --- a/src/openrct2/peep/Guest.cpp +++ b/src/openrct2/peep/Guest.cpp @@ -2357,7 +2357,7 @@ void Guest::SpendMoney(money16& peep_expend_type, money32 amount, ExpenditureTyp // needing to be synchronised if (network_get_mode() == NETWORK_MODE_NONE && !gOpenRCT2Headless) { - MoneyEffect::CreateAt(amount, x, y, z, true); + MoneyEffect::CreateAt(amount, { x, y, z }, true); } } diff --git a/src/openrct2/world/MoneyEffect.cpp b/src/openrct2/world/MoneyEffect.cpp index 0f723d6b52..355ae5ce11 100644 --- a/src/openrct2/world/MoneyEffect.cpp +++ b/src/openrct2/world/MoneyEffect.cpp @@ -27,7 +27,7 @@ template<> bool SpriteBase::Is() const * * rct2: 0x0067351F */ -void MoneyEffect::CreateAt(money32 value, int32_t x, int32_t y, int32_t z, bool vertical) +void MoneyEffect::CreateAt(money32 value, const CoordsXYZ& effectPos, bool vertical) { if (value == MONEY(0, 00)) return; @@ -42,7 +42,7 @@ void MoneyEffect::CreateAt(money32 value, int32_t x, int32_t y, int32_t z, bool moneyEffect->sprite_height_negative = 20; moneyEffect->sprite_height_positive = 30; moneyEffect->sprite_identifier = SPRITE_IDENTIFIER_MISC; - moneyEffect->MoveTo({ x, y, z }); + moneyEffect->MoveTo(effectPos); moneyEffect->type = SPRITE_MISC_MONEY_EFFECT; moneyEffect->NumMovements = 0; moneyEffect->MoveDelay = 0; @@ -89,7 +89,7 @@ void MoneyEffect::Create(money32 value, CoordsXYZ loc) loc = { *mapPositionXY, tile_element_height(*mapPositionXY) }; } loc.z += 10; - CreateAt(-value, loc.x, loc.y, loc.z, false); + CreateAt(-value, loc, false); } /** diff --git a/src/openrct2/world/Sprite.h b/src/openrct2/world/Sprite.h index 815e885736..b8145a8cf7 100644 --- a/src/openrct2/world/Sprite.h +++ b/src/openrct2/world/Sprite.h @@ -81,7 +81,7 @@ struct MoneyEffect : SpriteBase int16_t OffsetX; uint16_t Wiggle; - static void CreateAt(money32 value, int32_t x, int32_t y, int32_t z, bool vertical); + static void CreateAt(money32 value, const CoordsXYZ& effectPos, bool vertical); static void Create(money32 value, CoordsXYZ loc); void Update(); std::pair GetStringId() const; From ad529c7f6c185d69ff651021855412f8b771aecc Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Sun, 21 Jun 2020 14:22:17 -0300 Subject: [PATCH 12/12] Use const ref on MoneyEffect::Create --- src/openrct2/world/MoneyEffect.cpp | 9 +++++---- src/openrct2/world/Sprite.h | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/openrct2/world/MoneyEffect.cpp b/src/openrct2/world/MoneyEffect.cpp index 355ae5ce11..e0b44744ba 100644 --- a/src/openrct2/world/MoneyEffect.cpp +++ b/src/openrct2/world/MoneyEffect.cpp @@ -64,8 +64,9 @@ void MoneyEffect::CreateAt(money32 value, const CoordsXYZ& effectPos, bool verti * * rct2: 0x0069C5D0 */ -void MoneyEffect::Create(money32 value, CoordsXYZ loc) +void MoneyEffect::Create(money32 value, const CoordsXYZ& loc) { + auto offsetLoc = loc; if (loc.isNull()) { // If game actions return no valid location of the action we can not use the screen @@ -86,10 +87,10 @@ void MoneyEffect::Create(money32 value, CoordsXYZ loc) if (!mapPositionXY) return; - loc = { *mapPositionXY, tile_element_height(*mapPositionXY) }; + offsetLoc = { *mapPositionXY, tile_element_height(*mapPositionXY) }; } - loc.z += 10; - CreateAt(-value, loc, false); + offsetLoc.z += 10; + CreateAt(-value, offsetLoc, false); } /** diff --git a/src/openrct2/world/Sprite.h b/src/openrct2/world/Sprite.h index b8145a8cf7..043fc87964 100644 --- a/src/openrct2/world/Sprite.h +++ b/src/openrct2/world/Sprite.h @@ -82,7 +82,7 @@ struct MoneyEffect : SpriteBase uint16_t Wiggle; static void CreateAt(money32 value, const CoordsXYZ& effectPos, bool vertical); - static void Create(money32 value, CoordsXYZ loc); + static void Create(money32 value, const CoordsXYZ& loc); void Update(); std::pair GetStringId() const; };