From 345e03d41be36ca1983f3fd79bd3c87ea2c80a87 Mon Sep 17 00:00:00 2001 From: Michael Steenbeek Date: Mon, 17 Sep 2018 14:48:27 +0200 Subject: [PATCH] Move animation frame and rct1 wall functions to methods --- .../paint/tile_element/Paint.Wall.cpp | 2 +- src/openrct2/rct1/S4Importer.cpp | 18 +++++++-------- src/openrct2/ride/Vehicle.cpp | 8 +++---- src/openrct2/world/MapAnimation.cpp | 4 ++-- src/openrct2/world/TileElement.h | 6 +++++ src/openrct2/world/Wall.cpp | 22 +++++++++---------- src/openrct2/world/Wall.h | 3 --- 7 files changed, 32 insertions(+), 31 deletions(-) diff --git a/src/openrct2/paint/tile_element/Paint.Wall.cpp b/src/openrct2/paint/tile_element/Paint.Wall.cpp index 1eed64340f..5cf671f1b5 100644 --- a/src/openrct2/paint/tile_element/Paint.Wall.cpp +++ b/src/openrct2/paint/tile_element/Paint.Wall.cpp @@ -212,7 +212,7 @@ void fence_paint(paint_session* session, uint8_t direction, int32_t height, cons { LocationXYZ16 offset; LocationXYZ16 boundsR1, boundsR1_, boundsR2, boundsR2_, boundsL1, boundsL1_; - uint8_t animationFrame = wall_get_animation_frame(tile_element); + uint8_t animationFrame = tile_element->AsWall()->GetAnimationFrame(); // Add the direction as well animationFrame |= (tile_element->properties.wall.animation & WALL_ANIMATION_FLAG_DIRECTION_BACKWARD) >> 3; uint32_t imageId; diff --git a/src/openrct2/rct1/S4Importer.cpp b/src/openrct2/rct1/S4Importer.cpp index 346eaf544c..89eeac1f76 100644 --- a/src/openrct2/rct1/S4Importer.cpp +++ b/src/openrct2/rct1/S4Importer.cpp @@ -61,8 +61,6 @@ using namespace OpenRCT2; static uint8_t GetPathType(rct_tile_element* tileElement); -static int32_t GetWallType(rct_tile_element* tileElement, int32_t edge); -static uint8_t GetWallColour(rct_tile_element* tileElement); class EntryList { @@ -499,7 +497,7 @@ private: { for (int32_t edge = 0; edge < 4; edge++) { - int32_t type = GetWallType(tileElement, edge); + int32_t type = tileElement->AsWall()->GetRCT1WallType(edge); if (type != -1) { @@ -2573,11 +2571,11 @@ private: for (int32_t edge = 0; edge < 4; edge++) { - int32_t type = GetWallType(&originalTileElement, edge); + int32_t type = originalTileElement.AsWall()->GetRCT1WallType(edge); if (type != -1) { - int32_t colourA = RCT1::GetColour(GetWallColour(&originalTileElement)); + int32_t colourA = RCT1::GetColour(originalTileElement.AsWall()->GetRCT1WallColour()); int32_t colourB = 0; int32_t colourC = 0; ConvertWall(&type, &colourA, &colourB); @@ -2895,10 +2893,10 @@ static uint8_t GetPathType(rct_tile_element* tileElement) return pathType; } -static int32_t GetWallType(rct_tile_element* tileElement, int32_t edge) +int32_t WallElement::GetRCT1WallType(int32_t edge) const { - uint8_t var_05 = tileElement->properties.wall.colour_3; - uint16_t var_06 = tileElement->properties.wall.colour_1 | (tileElement->properties.wall.animation << 8); + uint8_t var_05 = colour_3; + uint16_t var_06 = colour_1 | (animation << 8); int32_t typeA = (var_05 >> (edge * 2)) & 3; int32_t typeB = (var_06 >> (edge * 4)) & 0x0F; @@ -2913,7 +2911,7 @@ static int32_t GetWallType(rct_tile_element* tileElement, int32_t edge) } } -static uint8_t GetWallColour(rct_tile_element* tileElement) +colour_t WallElement::GetRCT1WallColour() const { - return ((tileElement->type & 0xC0) >> 3) | ((tileElement->properties.wall.type & 0xE0) >> 5); + return ((type & 0xC0) >> 3) | ((entryIndex & 0xE0) >> 5); } diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index 89cb2a19dd..5a43c530fc 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -7454,14 +7454,14 @@ static void vehicle_update_scenery_door(rct_vehicle* vehicle) if (vehicle->next_vehicle_on_train != SPRITE_INDEX_NULL) { tileElement->properties.wall.animation &= ~(WALL_ANIMATION_FLAG_DIRECTION_BACKWARD); - wall_set_animation_frame(tileElement, 1); + tileElement->AsWall()->SetAnimationFrame(1); map_animation_create(MAP_ANIMATION_TYPE_WALL_DOOR, x, y, z); vehicle_play_scenery_door_open_sound(vehicle, tileElement); } else { tileElement->properties.wall.animation &= ~(WALL_ANIMATION_FLAG_DIRECTION_BACKWARD); - wall_set_animation_frame(tileElement, 6); + tileElement->AsWall()->SetAnimationFrame(6); vehicle_play_scenery_door_close_sound(vehicle, tileElement); } } @@ -7534,14 +7534,14 @@ static void vehicle_update_handle_scenery_door(rct_vehicle* vehicle) if (vehicle->next_vehicle_on_train != SPRITE_INDEX_NULL) { tileElement->properties.wall.animation |= WALL_ANIMATION_FLAG_DIRECTION_BACKWARD; - wall_set_animation_frame(tileElement, 1); + tileElement->AsWall()->SetAnimationFrame(1); map_animation_create(MAP_ANIMATION_TYPE_WALL_DOOR, x, y, z); vehicle_play_scenery_door_open_sound(vehicle, tileElement); } else { tileElement->properties.wall.animation &= ~(WALL_ANIMATION_FLAG_DIRECTION_BACKWARD); - wall_set_animation_frame(tileElement, 6); + tileElement->AsWall()->SetAnimationFrame(6); vehicle_play_scenery_door_close_sound(vehicle, tileElement); } } diff --git a/src/openrct2/world/MapAnimation.cpp b/src/openrct2/world/MapAnimation.cpp index 76953b018a..75042f06f5 100644 --- a/src/openrct2/world/MapAnimation.cpp +++ b/src/openrct2/world/MapAnimation.cpp @@ -503,7 +503,7 @@ static bool map_animation_invalidate_wall_door(int32_t x, int32_t y, int32_t bas bool invalidate = false; - uint8_t currentFrame = wall_get_animation_frame(tileElement); + uint8_t currentFrame = tileElement->AsWall()->GetAnimationFrame(); if (currentFrame != 0) { if (currentFrame == 15) @@ -523,7 +523,7 @@ static bool map_animation_invalidate_wall_door(int32_t x, int32_t y, int32_t bas } } } - wall_set_animation_frame(tileElement, currentFrame); + tileElement->AsWall()->SetAnimationFrame(currentFrame); if (invalidate) { int32_t z = tileElement->base_height * 8; diff --git a/src/openrct2/world/TileElement.h b/src/openrct2/world/TileElement.h index 96d06d1160..ce2e79fad6 100644 --- a/src/openrct2/world/TileElement.h +++ b/src/openrct2/world/TileElement.h @@ -317,6 +317,12 @@ public: void SetSecondaryColour(colour_t newColour); colour_t GetTertiaryColour() const; void SetTertiaryColour(colour_t newColour); + + uint8_t GetAnimationFrame() const; + void SetAnimationFrame(uint8_t frameNum); + + int32_t GetRCT1WallType(int32_t edge) const; + colour_t GetRCT1WallColour() const; }; assert_struct_size(WallElement, 8); diff --git a/src/openrct2/world/Wall.cpp b/src/openrct2/world/Wall.cpp index 69019a8234..db57c71faf 100644 --- a/src/openrct2/world/Wall.cpp +++ b/src/openrct2/world/Wall.cpp @@ -596,17 +596,6 @@ static money32 WallSetColour( return 0; } -uint8_t wall_get_animation_frame(const rct_tile_element* wallElement) -{ - return (wallElement->properties.wall.animation >> 3) & 0xF; -} - -void wall_set_animation_frame(rct_tile_element* wallElement, uint8_t frameNum) -{ - wallElement->properties.wall.animation &= WALL_ANIMATION_FLAG_ALL_FLAGS; - wallElement->properties.wall.animation |= (frameNum & 0xF) << 3; -} - /** * * rct2: 0x006E588E @@ -759,4 +748,15 @@ void WallElement::SetTertiaryColour(colour_t newColour) assert(newColour <= 31); colour_3 &= ~TILE_ELEMENT_COLOUR_MASK; colour_3 |= newColour; +} + +uint8_t WallElement::GetAnimationFrame() const +{ + return (animation >> 3) & 0xF; +} + +void WallElement::SetAnimationFrame(uint8_t frameNum) +{ + animation &= WALL_ANIMATION_FLAG_ALL_FLAGS; + animation |= (frameNum & 0xF) << 3; } \ No newline at end of file diff --git a/src/openrct2/world/Wall.h b/src/openrct2/world/Wall.h index 4232395034..3b80c5baa0 100644 --- a/src/openrct2/world/Wall.h +++ b/src/openrct2/world/Wall.h @@ -20,7 +20,4 @@ enum WALL_ANIMATION_FLAG_ALL_FLAGS = WALL_ANIMATION_FLAG_ACROSS_TRACK | WALL_ANIMATION_FLAG_DIRECTION_BACKWARD }; -uint8_t wall_get_animation_frame(const rct_tile_element* fenceElement); -void wall_set_animation_frame(rct_tile_element* wallElement, uint8_t frameNum); - money32 wall_remove(int16_t x, int16_t y, uint8_t baseHeight, uint8_t direction, uint8_t flags);