From 63bcb3c3e5b7a19465c62bafbc0bfee83493a966 Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Sat, 29 May 2021 08:07:32 +0100 Subject: [PATCH] Move particle structs to particle files --- src/openrct2/peep/Guest.cpp | 5 +- src/openrct2/ride/Vehicle.cpp | 32 ++------- src/openrct2/world/EntityTweener.h | 3 + src/openrct2/world/Particle.cpp | 105 +++++++++++++++++++++++++++++ src/openrct2/world/Particle.h | 26 +++++++ src/openrct2/world/Sprite.cpp | 82 ---------------------- src/openrct2/world/Sprite.h | 27 -------- 7 files changed, 142 insertions(+), 138 deletions(-) diff --git a/src/openrct2/peep/Guest.cpp b/src/openrct2/peep/Guest.cpp index 6263d7d383..545af5f76b 100644 --- a/src/openrct2/peep/Guest.cpp +++ b/src/openrct2/peep/Guest.cpp @@ -38,6 +38,7 @@ #include "../world/Map.h" #include "../world/MoneyEffect.h" #include "../world/Park.h" +#include "../world/Particle.h" #include "../world/Scenery.h" #include "../world/Sprite.h" #include "../world/Surface.h" @@ -894,8 +895,8 @@ void Guest::Tick128UpdateGuest(int32_t index) { OpenRCT2::Audio::Play3D(OpenRCT2::Audio::SoundId::Crash, { x, y, z }); - sprite_misc_explosion_cloud_create({ x, y, z + 16 }); - sprite_misc_explosion_flare_create({ x, y, z + 16 }); + ExplosionCloud::Create({ x, y, z + 16 }); + ExplosionFlare::Create({ x, y, z + 16 }); Remove(); return; diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index 0be76252fd..40a9917764 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -3600,7 +3600,7 @@ void Vehicle::UpdateCollisionSetup() OpenRCT2::Audio::Play3D(OpenRCT2::Audio::SoundId::Crash, { train->x, train->y, train->z }); - sprite_misc_explosion_cloud_create({ train->x, train->y, train->z }); + ExplosionCloud::Create({ train->x, train->y, train->z }); for (int32_t i = 0; i < 10; i++) { @@ -5358,8 +5358,8 @@ void Vehicle::CrashOnLand() sub_state = 2; OpenRCT2::Audio::Play3D(OpenRCT2::Audio::SoundId::Crash, { x, y, z }); - sprite_misc_explosion_cloud_create({ x, y, z }); - sprite_misc_explosion_flare_create({ x, y, z }); + ExplosionCloud::Create({ x, y, z }); + ExplosionFlare::Create({ x, y, z }); uint8_t numParticles = std::min(sprite_width, static_cast(7)); @@ -5459,7 +5459,7 @@ void Vehicle::UpdateCrash() { 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 }); + ExplosionCloud::Create({ curVehicle->x + xOffset, curVehicle->y + yOffset, curVehicle->z }); } } if (curVehicle->var_C8 + 7281 > 0xFFFF) @@ -7225,28 +7225,6 @@ void Vehicle::UpdateSpinningCar() Invalidate(); } -/** - * - * rct2: 0x006734B2 - */ -static void steam_particle_create(const CoordsXYZ& coords) -{ - auto surfaceElement = map_get_surface_element_at(coords); - if (surfaceElement != nullptr && coords.z > surfaceElement->GetBaseZ()) - { - SteamParticle* steam = CreateEntity(); - if (steam == nullptr) - return; - - steam->sprite_width = 20; - steam->sprite_height_negative = 18; - steam->sprite_height_positive = 16; - steam->frame = 256; - steam->time_to_move = 0; - steam->MoveTo(coords); - } -} - /** * * rct2: 0x006D63D4 @@ -7298,7 +7276,7 @@ void Vehicle::UpdateAdditionalAnimation() }(); int32_t directionIndex = sprite_direction >> 1; auto offset = SteamParticleOffsets[typeIndex][directionIndex]; - steam_particle_create({ x + offset.x, y + offset.y, z + offset.z }); + SteamParticle::Create({ x + offset.x, y + offset.y, z + offset.z }); } } } diff --git a/src/openrct2/world/EntityTweener.h b/src/openrct2/world/EntityTweener.h index 1e3d734185..7e6dfaf843 100644 --- a/src/openrct2/world/EntityTweener.h +++ b/src/openrct2/world/EntityTweener.h @@ -7,7 +7,10 @@ * OpenRCT2 is licensed under the GNU General Public License version 3. *****************************************************************************/ +#pragma once + #include "SpriteBase.h" + #include class EntityTweener diff --git a/src/openrct2/world/Particle.cpp b/src/openrct2/world/Particle.cpp index 965797e4e3..80d94b8765 100644 --- a/src/openrct2/world/Particle.cpp +++ b/src/openrct2/world/Particle.cpp @@ -143,3 +143,108 @@ void CrashSplashParticle::Update() sprite_remove(this); } } + +/** + * + * rct2: 0x006734B2 + */ +void SteamParticle::Create(const CoordsXYZ& coords) +{ + auto surfaceElement = map_get_surface_element_at(coords); + if (surfaceElement != nullptr && coords.z > surfaceElement->GetBaseZ()) + { + SteamParticle* steam = CreateEntity(); + if (steam == nullptr) + return; + + steam->sprite_width = 20; + steam->sprite_height_negative = 18; + steam->sprite_height_positive = 16; + steam->frame = 256; + steam->time_to_move = 0; + steam->MoveTo(coords); + } +} + +/** + * + * rct2: 0x00673200 + */ +void SteamParticle::Update() +{ + // Move up 1 z every 3 ticks (Starts after 4 ticks) + Invalidate(); + time_to_move++; + if (time_to_move >= 4) + { + time_to_move = 1; + MoveTo({ x, y, z + 1 }); + } + frame += 64; + if (frame >= (56 * 64)) + { + sprite_remove(this); + } +} + +/** + * + * rct2: 0x0067363D + */ +void ExplosionCloud::Create(const CoordsXYZ& cloudPos) +{ + auto* entity = CreateEntity(); + if (entity != nullptr) + { + entity->sprite_width = 44; + entity->sprite_height_negative = 32; + entity->sprite_height_positive = 34; + entity->MoveTo(cloudPos + CoordsXYZ{ 0, 0, 4 }); + entity->frame = 0; + } +} + +/** + * + * rct2: 0x00673385 + */ +void ExplosionCloud::Update() +{ + Invalidate(); + frame += 128; + if (frame >= (36 * 128)) + { + sprite_remove(this); + } +} + +/** + * + * rct2: 0x0067366B + */ +void ExplosionFlare::Create(const CoordsXYZ& flarePos) +{ + auto* entity = CreateEntity(); + if (entity != nullptr) + { + entity->sprite_width = 25; + entity->sprite_height_negative = 85; + entity->sprite_height_positive = 8; + entity->MoveTo(flarePos + CoordsXYZ{ 0, 0, 4 }); + entity->frame = 0; + } +} + +/** + * + * rct2: 0x006733B4 + */ +void ExplosionFlare::Update() +{ + Invalidate(); + frame += 64; + if (frame >= (124 * 64)) + { + sprite_remove(this); + } +} diff --git a/src/openrct2/world/Particle.h b/src/openrct2/world/Particle.h index fd764c2ad3..53ba024785 100644 --- a/src/openrct2/world/Particle.h +++ b/src/openrct2/world/Particle.h @@ -39,3 +39,29 @@ struct CrashSplashParticle : MiscEntity void Update(); void Serialise(DataSerialiser& stream); }; + +struct ExplosionFlare : MiscEntity +{ + static constexpr auto cEntityType = EntityType::ExplosionFlare; + static void Create(const CoordsXYZ& flarePos); + void Update(); + void Serialise(DataSerialiser& stream); +}; + +struct ExplosionCloud : MiscEntity +{ + static constexpr auto cEntityType = EntityType::ExplosionCloud; + static void Create(const CoordsXYZ& cloudPos); + void Update(); + void Serialise(DataSerialiser& stream); +}; + +struct SteamParticle : MiscEntity +{ + static constexpr auto cEntityType = EntityType::SteamParticle; + uint16_t time_to_move; + + static void Create(const CoordsXYZ& coords); + void Update(); + void Serialise(DataSerialiser& stream); +}; diff --git a/src/openrct2/world/Sprite.cpp b/src/openrct2/world/Sprite.cpp index 4aad4b1632..94e02ff18c 100644 --- a/src/openrct2/world/Sprite.cpp +++ b/src/openrct2/world/Sprite.cpp @@ -445,88 +445,6 @@ SpriteBase* CreateEntityAt(const uint16_t index, const EntityType type) PrepareNewEntity(entity, type); return entity; } -/** - * - * rct2: 0x00673200 - */ -void SteamParticle::Update() -{ - // Move up 1 z every 3 ticks (Starts after 4 ticks) - Invalidate(); - time_to_move++; - if (time_to_move >= 4) - { - time_to_move = 1; - MoveTo({ x, y, z + 1 }); - } - frame += 64; - if (frame >= (56 * 64)) - { - sprite_remove(this); - } -} - -/** - * - * rct2: 0x0067363D - */ -void sprite_misc_explosion_cloud_create(const CoordsXYZ& cloudPos) -{ - auto* sprite = CreateEntity(); - if (sprite != nullptr) - { - sprite->sprite_width = 44; - sprite->sprite_height_negative = 32; - sprite->sprite_height_positive = 34; - sprite->MoveTo(cloudPos + CoordsXYZ{ 0, 0, 4 }); - sprite->frame = 0; - } -} - -/** - * - * rct2: 0x00673385 - */ -void ExplosionCloud::Update() -{ - Invalidate(); - frame += 128; - if (frame >= (36 * 128)) - { - sprite_remove(this); - } -} - -/** - * - * rct2: 0x0067366B - */ -void sprite_misc_explosion_flare_create(const CoordsXYZ& flarePos) -{ - MiscEntity* sprite = CreateEntity(); - if (sprite != nullptr) - { - sprite->sprite_width = 25; - sprite->sprite_height_negative = 85; - sprite->sprite_height_positive = 8; - sprite->MoveTo(flarePos + CoordsXYZ{ 0, 0, 4 }); - sprite->frame = 0; - } -} - -/** - * - * rct2: 0x006733B4 - */ -void ExplosionFlare::Update() -{ - Invalidate(); - frame += 64; - if (frame >= (124 * 64)) - { - sprite_remove(this); - } -} template void MiscUpdateAllType() { diff --git a/src/openrct2/world/Sprite.h b/src/openrct2/world/Sprite.h index 873bbd6791..d2879ba0ac 100644 --- a/src/openrct2/world/Sprite.h +++ b/src/openrct2/world/Sprite.h @@ -15,31 +15,6 @@ #include -class DataSerialiser; - -struct ExplosionFlare : MiscEntity -{ - static constexpr auto cEntityType = EntityType::ExplosionFlare; - void Update(); - void Serialise(DataSerialiser& stream); -}; - -struct ExplosionCloud : MiscEntity -{ - static constexpr auto cEntityType = EntityType::ExplosionCloud; - void Update(); - void Serialise(DataSerialiser& stream); -}; - -struct SteamParticle : MiscEntity -{ - static constexpr auto cEntityType = EntityType::SteamParticle; - uint16_t time_to_move; - - void Update(); - void Serialise(DataSerialiser& stream); -}; - #pragma pack(push, 1) /** * Sprite structure. @@ -88,8 +63,6 @@ void sprite_misc_update_all(); void sprite_set_coordinates(const CoordsXYZ& spritePos, SpriteBase* sprite); void sprite_remove(SpriteBase* sprite); uint16_t remove_floating_sprites(); -void sprite_misc_explosion_cloud_create(const CoordsXYZ& cloudPos); -void sprite_misc_explosion_flare_create(const CoordsXYZ& flarePos); rct_sprite_checksum sprite_checksum();