From b6ce5ce4a5e8240e1630afd94f2147ff77531537 Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Sat, 25 Nov 2017 09:26:35 +0000 Subject: [PATCH] Simplify fountain code. Name sprite fields. Fix warning Fountain jumping code has been sped up slightly so that the code can be simplified and not require rolling over a unsigned int. Also removed setting direction of the fountain as the field was not used. --- src/openrct2/paint/sprite/misc.c | 2 +- src/openrct2/paint/sprite/sprite.h | 1 + src/openrct2/rct1/S4Importer.cpp | 4 ++-- src/openrct2/world/Fountain.cpp | 23 +++++++++++++---------- src/openrct2/world/Particle.cpp | 5 +---- src/openrct2/world/sprite.h | 14 ++++---------- 6 files changed, 22 insertions(+), 27 deletions(-) diff --git a/src/openrct2/paint/sprite/misc.c b/src/openrct2/paint/sprite/misc.c index f670b8f50b..08124d1a24 100644 --- a/src/openrct2/paint/sprite/misc.c +++ b/src/openrct2/paint/sprite/misc.c @@ -121,7 +121,7 @@ void misc_paint(paint_session * session, rct_sprite *misc, sint32 imageDirection } uint32 baseImageId = (jumpingFountain.misc_identifier == SPRITE_MISC_JUMPING_FOUNTAIN_SNOW) ? 23037 : 22973; - uint32 imageId = baseImageId + ebx * 16 + jumpingFountain.var_26b; + uint32 imageId = baseImageId + ebx * 16 + jumpingFountain.frame; if (al & 1) { switch (ebx) { case 0: diff --git a/src/openrct2/paint/sprite/sprite.h b/src/openrct2/paint/sprite/sprite.h index 8b0d26b71a..b2515a3ce3 100644 --- a/src/openrct2/paint/sprite/sprite.h +++ b/src/openrct2/paint/sprite/sprite.h @@ -32,6 +32,7 @@ extern "C" { void litter_paint(paint_session * session, rct_litter *litter, sint32 imageDirection); void peep_paint(paint_session * session, rct_peep *peep, sint32 imageDirection); + extern const uint32 vehicle_particle_base_sprites[5]; #ifdef __cplusplus } #endif diff --git a/src/openrct2/rct1/S4Importer.cpp b/src/openrct2/rct1/S4Importer.cpp index fb1b35485a..8ce37ec9c2 100644 --- a/src/openrct2/rct1/S4Importer.cpp +++ b/src/openrct2/rct1/S4Importer.cpp @@ -1662,8 +1662,8 @@ private: { dst->fountain_flags = src->fountain_flags; dst->iteration = src->iteration; - dst->var_26a = src->var_26a; - dst->var_26b = src->var_26b; + dst->num_ticks_alive = src->num_ticks_alive; + dst->frame = src->frame; } void ImportBalloon(rct_balloon * dst, rct_balloon * src) diff --git a/src/openrct2/world/Fountain.cpp b/src/openrct2/world/Fountain.cpp index b699d768c5..b04c4e67c0 100644 --- a/src/openrct2/world/Fountain.cpp +++ b/src/openrct2/world/Fountain.cpp @@ -183,7 +183,6 @@ extern "C" if (jumpingFountain != nullptr) { jumpingFountain->iteration = iteration; - jumpingFountain->var_2E = direction; jumpingFountain->fountain_flags = flags; jumpingFountain->sprite_direction = direction << 3; jumpingFountain->sprite_width = 33; @@ -194,42 +193,46 @@ extern "C" jumpingFountain->misc_identifier = type == JUMPING_FOUNTAIN_TYPE_SNOW ? SPRITE_MISC_JUMPING_FOUNTAIN_SNOW : SPRITE_MISC_JUMPING_FOUNTAIN_WATER; - jumpingFountain->var_26 = 0; + jumpingFountain->num_ticks_alive = 0; + jumpingFountain->frame = 0; } } void jumping_fountain_update(rct_jumping_fountain * jumpingFountain) { - sint32 original_var_26a = jumpingFountain->var_26a; - jumpingFountain->var_26a += 160; - if (original_var_26a <= 255 - 160) + jumpingFountain->num_ticks_alive++; + // Originaly this would not update the frame on the following + // ticks: 1, 3, 6, 9, 11, 14, 17, 19, 22, 25 + // This change was to simplefy the code base. There is a small increase + // in speed of the fountain jump because of this change. + if ((jumpingFountain->num_ticks_alive % 3) == 0) { return; } invalidate_sprite_0((rct_sprite *)jumpingFountain); - jumpingFountain->var_26b++; + jumpingFountain->frame++; switch (jumpingFountain->misc_identifier) { case SPRITE_MISC_JUMPING_FOUNTAIN_WATER: - if (jumpingFountain->var_26b == 11 && (jumpingFountain->fountain_flags & FOUNTAIN_FLAG::FAST)) + if (jumpingFountain->frame == 11 && (jumpingFountain->fountain_flags & FOUNTAIN_FLAG::FAST)) { jumping_fountain_continue(jumpingFountain); } - if (jumpingFountain->var_26b == 16 && !(jumpingFountain->fountain_flags & FOUNTAIN_FLAG::FAST)) + if (jumpingFountain->frame == 16 && !(jumpingFountain->fountain_flags & FOUNTAIN_FLAG::FAST)) { jumping_fountain_continue(jumpingFountain); } break; case SPRITE_MISC_JUMPING_FOUNTAIN_SNOW: - if (jumpingFountain->var_26b == 16) + if (jumpingFountain->frame == 16) { jumping_fountain_continue(jumpingFountain); } break; } - if (jumpingFountain->var_26b == 16) + if (jumpingFountain->frame == 16) { sprite_remove((rct_sprite*)jumpingFountain); } diff --git a/src/openrct2/world/Particle.cpp b/src/openrct2/world/Particle.cpp index 2fa2656bd9..9b4d458aa9 100644 --- a/src/openrct2/world/Particle.cpp +++ b/src/openrct2/world/Particle.cpp @@ -17,12 +17,9 @@ #include "../audio/audio.h" #include "../core/Util.hpp" #include "../scenario/scenario.h" +#include "../paint/sprite/sprite.h" #include "sprite.h" -extern "C" { - extern const uint32 vehicle_particle_base_sprites[5]; -} - /** * * rct2: 0x006735A1 diff --git a/src/openrct2/world/sprite.h b/src/openrct2/world/sprite.h index 1a8dd53338..b30f4b2328 100644 --- a/src/openrct2/world/sprite.h +++ b/src/openrct2/world/sprite.h @@ -175,7 +175,7 @@ typedef struct rct_jumping_fountain { uint8 linked_list_type_offset; // 0x08 Valid values are SPRITE_LINKEDLIST_OFFSET_... uint8 sprite_height_negative; uint16 sprite_index; // 0x0A - uint16 flags; // 0x0C + uint16 flags; // 0x0C sint16 x; // 0x0E sint16 y; // 0x10 sint16 z; // 0x12 @@ -184,15 +184,9 @@ typedef struct rct_jumping_fountain { uint8 pad_16[0x8]; uint8 sprite_direction; // 0x1E uint8 pad_1F[0x7]; - union { - uint16 var_26; - struct { - uint8 var_26a; - uint8 var_26b; - }; - }; - uint8 pad_28[0x6]; - uint8 var_2E; + uint8 num_ticks_alive; // 0x26 + uint8 frame; // 0x27 + uint8 pad_28[0x7]; // 0x28 Originally var_2E was set to direction but it was unused. uint8 fountain_flags; // 0x2F sint16 target_x; // 0x30 sint16 target_y; // 0x32