From 533e9379267fcb69117a69349156d6e0809db1c7 Mon Sep 17 00:00:00 2001 From: Michael Steenbeek Date: Mon, 17 Sep 2018 14:10:05 +0200 Subject: [PATCH 1/7] Create slope and colour functions for WallElement --- src/openrct2/world/TileElement.cpp | 5 --- src/openrct2/world/TileElement.h | 18 ++++++++++- src/openrct2/world/Wall.cpp | 50 ++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 6 deletions(-) diff --git a/src/openrct2/world/TileElement.cpp b/src/openrct2/world/TileElement.cpp index 62ec8c6dd9..5d35b4d67f 100644 --- a/src/openrct2/world/TileElement.cpp +++ b/src/openrct2/world/TileElement.cpp @@ -54,11 +54,6 @@ bool TileElementBase::IsGhost() const return (this->flags & TILE_ELEMENT_FLAG_GHOST) != 0; } -uint8_t WallElement::GetSlope() const -{ - return (this->type & TILE_ELEMENT_QUADRANT_MASK) >> 6; -} - bool tile_element_is_underground(rct_tile_element* tileElement) { do diff --git a/src/openrct2/world/TileElement.h b/src/openrct2/world/TileElement.h index 87a55b6577..96d06d1160 100644 --- a/src/openrct2/world/TileElement.h +++ b/src/openrct2/world/TileElement.h @@ -297,10 +297,26 @@ assert_struct_size(LargeSceneryElement, 8); struct WallElement : TileElementBase { - rct_tile_element_wall_properties temp; +//private: + uint8_t entryIndex; // 4 + union + { + uint8_t colour_3; // 5 + BannerIndex banner_index; // 5 + }; + uint8_t colour_1; // 6 0b_2221_1111 2 = colour_2 (uses flags for rest of colour2), 1 = colour_1 + uint8_t animation; // 7 0b_dfff_ft00 d = direction, f = frame num, t = across track flag (not used) public: uint8_t GetSlope() const; + void SetSlope(uint8_t newslope); + + colour_t GetPrimaryColour() const; + void SetPrimaryColour(colour_t newColour); + colour_t GetSecondaryColour() const; + void SetSecondaryColour(colour_t newColour); + colour_t GetTertiaryColour() const; + void SetTertiaryColour(colour_t newColour); }; assert_struct_size(WallElement, 8); diff --git a/src/openrct2/world/Wall.cpp b/src/openrct2/world/Wall.cpp index 7f58052342..008e7f4cbb 100644 --- a/src/openrct2/world/Wall.cpp +++ b/src/openrct2/world/Wall.cpp @@ -749,3 +749,53 @@ void game_command_set_wall_colour( *eax & 0xFFFF, *ecx & 0xFFFF, (*edx >> 8) & 0xFF, *edx & 0xFF, (*ebx >> 8) & 0xFF, *ebp & 0xFF, (*ebp >> 8) & 0xFF, *ebx & 0xFF); } + +uint8_t WallElement::GetSlope() const +{ + return (type & TILE_ELEMENT_QUADRANT_MASK) >> 6; +} + +void WallElement::SetSlope(uint8_t newSlope) +{ + type &= ~TILE_ELEMENT_QUADRANT_MASK; + type |= (newSlope << 6); +} + +colour_t WallElement::GetPrimaryColour() const +{ + return colour_1 & TILE_ELEMENT_COLOUR_MASK; +} + +colour_t WallElement::GetSecondaryColour() const +{ + uint8_t secondaryColour = (colour_1 & ~TILE_ELEMENT_COLOUR_MASK) >> 5; + secondaryColour |= (flags & 0x60) >> 2; + return secondaryColour; +} + +colour_t WallElement::GetTertiaryColour() const +{ + return colour_3 & TILE_ELEMENT_COLOUR_MASK; +} + +void WallElement::SetPrimaryColour(colour_t newColour) +{ + assert(newColour <= 31); + colour_1 &= ~TILE_ELEMENT_COLOUR_MASK; + colour_1 |= newColour; +} + +void WallElement::SetSecondaryColour(colour_t newColour) +{ + colour_1 &= TILE_ELEMENT_COLOUR_MASK; + colour_1 |= (newColour & 0x7) << 5; + flags &= ~0x60; + flags |= (newColour & 0x18) << 2; +} + +void WallElement::SetTertiaryColour(colour_t newColour) +{ + assert(newColour <= 31); + colour_3 &= ~TILE_ELEMENT_COLOUR_MASK; + colour_3 |= newColour; +} \ No newline at end of file From dcabdeb8058e41aadf4a5b4e1c5a99d6ae9ce332 Mon Sep 17 00:00:00 2001 From: Michael Steenbeek Date: Mon, 17 Sep 2018 14:22:17 +0200 Subject: [PATCH 2/7] Move wall colour functions over to the struct methods --- src/openrct2-ui/windows/Sign.cpp | 4 +- src/openrct2-ui/windows/TopToolbar.cpp | 6 +-- .../paint/tile_element/Paint.Wall.cpp | 8 +-- src/openrct2/ride/TrackDesignSave.cpp | 8 +-- src/openrct2/world/Map.cpp | 4 +- src/openrct2/world/Wall.cpp | 51 +++---------------- src/openrct2/world/Wall.h | 6 --- 7 files changed, 21 insertions(+), 66 deletions(-) diff --git a/src/openrct2-ui/windows/Sign.cpp b/src/openrct2-ui/windows/Sign.cpp index 20bd35662c..6d05f66b22 100644 --- a/src/openrct2-ui/windows/Sign.cpp +++ b/src/openrct2-ui/windows/Sign.cpp @@ -423,8 +423,8 @@ rct_window* window_sign_small_open(rct_windownumber number) int32_t view_z = tile_element->base_height << 3; w->frame_no = view_z; - w->list_information_type = wall_get_primary_colour(tile_element); - w->var_492 = wall_get_secondary_colour(tile_element); + w->list_information_type = tile_element->AsWall()->GetPrimaryColour(); + w->var_492 = tile_element->AsWall()->GetSecondaryColour(); w->var_48C = tile_element->properties.wall.type; view_x += 16; diff --git a/src/openrct2-ui/windows/TopToolbar.cpp b/src/openrct2-ui/windows/TopToolbar.cpp index 58b23967f8..950d0e6c9a 100644 --- a/src/openrct2-ui/windows/TopToolbar.cpp +++ b/src/openrct2-ui/windows/TopToolbar.cpp @@ -1087,9 +1087,9 @@ static void scenery_eyedropper_tool_down(int16_t x, int16_t y, rct_widgetindex w int32_t sceneryId = get_scenery_id_from_entry_index(OBJECT_TYPE_WALLS, entryIndex); if (sceneryId != -1 && window_scenery_set_selected_item(sceneryId)) { - gWindowSceneryPrimaryColour = wall_get_primary_colour(tileElement); - gWindowScenerySecondaryColour = wall_get_secondary_colour(tileElement); - gWindowSceneryTertiaryColour = wall_get_tertiary_colour(tileElement); + gWindowSceneryPrimaryColour = tileElement->AsWall()->GetPrimaryColour(); + gWindowScenerySecondaryColour = tileElement->AsWall()->GetSecondaryColour(); + gWindowSceneryTertiaryColour = tileElement->AsWall()->GetTertiaryColour(); gWindowSceneryEyedropperEnabled = false; } } diff --git a/src/openrct2/paint/tile_element/Paint.Wall.cpp b/src/openrct2/paint/tile_element/Paint.Wall.cpp index 2738dd9b9b..1eed64340f 100644 --- a/src/openrct2/paint/tile_element/Paint.Wall.cpp +++ b/src/openrct2/paint/tile_element/Paint.Wall.cpp @@ -170,20 +170,20 @@ void fence_paint(paint_session* session, uint8_t direction, int32_t height, cons frameNum = (gCurrentTicks & 7) * 2; } - int32_t primaryColour = wall_get_primary_colour(tile_element); + int32_t primaryColour = tile_element->AsWall()->GetPrimaryColour(); uint32_t imageColourFlags = primaryColour << 19 | IMAGE_TYPE_REMAP; uint32_t dword_141F718 = imageColourFlags + 0x23800006; if (sceneryEntry->wall.flags & WALL_SCENERY_HAS_SECONDARY_COLOUR) { - uint8_t secondaryColour = wall_get_secondary_colour(tile_element); + uint8_t secondaryColour = tile_element->AsWall()->GetSecondaryColour(); imageColourFlags |= secondaryColour << 24 | IMAGE_TYPE_REMAP_2_PLUS; } uint32_t tertiaryColour = 0; if (sceneryEntry->wall.flags & WALL_SCENERY_HAS_TERNARY_COLOUR) { - tertiaryColour = wall_get_tertiary_colour(tile_element); + tertiaryColour = tile_element->AsWall()->GetTertiaryColour(); imageColourFlags &= 0x0DFFFFFFF; } @@ -413,7 +413,7 @@ void fence_paint(paint_session* session, uint8_t direction, int32_t height, cons set_format_arg(0, uint32_t, 0); set_format_arg(4, uint32_t, 0); - uint8_t secondaryColour = wall_get_secondary_colour(tile_element); + uint8_t secondaryColour = tile_element->AsWall()->GetSecondaryColour(); if (dword_141F710 != 0) { diff --git a/src/openrct2/ride/TrackDesignSave.cpp b/src/openrct2/ride/TrackDesignSave.cpp index 1cce540877..9f8f00df2c 100644 --- a/src/openrct2/ride/TrackDesignSave.cpp +++ b/src/openrct2/ride/TrackDesignSave.cpp @@ -359,10 +359,10 @@ static void track_design_save_add_wall(int32_t x, int32_t y, rct_tile_element* t uint8_t flags = 0; flags |= tileElement->type & 3; - flags |= wall_get_tertiary_colour(tileElement) << 2; + flags |= tileElement->AsWall()->GetTertiaryColour() << 2; - uint8_t secondaryColour = wall_get_secondary_colour(tileElement); - uint8_t primaryColour = wall_get_primary_colour(tileElement); + uint8_t secondaryColour = tileElement->AsWall()->GetSecondaryColour(); + uint8_t primaryColour = tileElement->AsWall()->GetPrimaryColour(); track_design_save_push_tile_element(x, y, tileElement); track_design_save_push_tile_element_desc(entry, x, y, tileElement->base_height, flags, primaryColour, secondaryColour); @@ -547,7 +547,7 @@ static void track_design_save_remove_wall(int32_t x, int32_t y, rct_tile_element uint8_t flags = 0; flags |= tileElement->type & 3; - flags |= wall_get_tertiary_colour(tileElement) << 2; + flags |= tileElement->AsWall()->GetTertiaryColour() << 2; track_design_save_pop_tile_element(x, y, tileElement); track_design_save_pop_tile_element_desc(entry, x, y, tileElement->base_height, flags); diff --git a/src/openrct2/world/Map.cpp b/src/openrct2/world/Map.cpp index 67e2d90151..26c6e005cb 100644 --- a/src/openrct2/world/Map.cpp +++ b/src/openrct2/world/Map.cpp @@ -4408,8 +4408,8 @@ void game_command_set_sign_style( *ebx = 0; return; } - wall_set_primary_colour(tileElement, mainColour); - wall_set_secondary_colour(tileElement, textColour); + tileElement->AsWall()->SetPrimaryColour(mainColour); + tileElement->AsWall()->SetSecondaryColour(textColour); map_invalidate_tile(x, y, tileElement->base_height * 8, tileElement->clearance_height * 8); } diff --git a/src/openrct2/world/Wall.cpp b/src/openrct2/world/Wall.cpp index 008e7f4cbb..69019a8234 100644 --- a/src/openrct2/world/Wall.cpp +++ b/src/openrct2/world/Wall.cpp @@ -515,8 +515,8 @@ static money32 WallPlace( tileElement->type = edgeSlope | edge | TILE_ELEMENT_TYPE_WALL; - wall_set_primary_colour(tileElement, primaryColour); - wall_set_secondary_colour(tileElement, secondaryColour); + tileElement->AsWall()->SetPrimaryColour(primaryColour); + tileElement->AsWall()->SetSecondaryColour(secondaryColour); if (wallAcrossTrack) { @@ -531,7 +531,7 @@ static money32 WallPlace( if (wallEntry->wall.flags & WALL_SCENERY_HAS_TERNARY_COLOUR) { - wall_set_tertiary_colour(tileElement, tertiaryColour); + tileElement->AsWall()->SetTertiaryColour(tertiaryColour); } if (flags & GAME_COMMAND_FLAG_GHOST) @@ -583,12 +583,12 @@ static money32 WallSetColour( if (flags & GAME_COMMAND_FLAG_APPLY) { rct_scenery_entry* scenery_entry = get_wall_entry(wallElement->properties.wall.type); - wall_set_primary_colour(wallElement, primaryColour); - wall_set_secondary_colour(wallElement, secondaryColour); + wallElement->AsWall()->SetPrimaryColour(primaryColour); + wallElement->AsWall()->SetSecondaryColour(secondaryColour); if (scenery_entry->wall.flags & WALL_SCENERY_HAS_TERNARY_COLOUR) { - wall_set_tertiary_colour(wallElement, tertiaryColour); + wallElement->AsWall()->SetTertiaryColour(tertiaryColour); } map_invalidate_tile_zoom1(x, y, z, z + 72); } @@ -607,45 +607,6 @@ void wall_set_animation_frame(rct_tile_element* wallElement, uint8_t frameNum) wallElement->properties.wall.animation |= (frameNum & 0xF) << 3; } -colour_t wall_get_primary_colour(const rct_tile_element* tileElement) -{ - return tileElement->properties.wall.colour_1 & TILE_ELEMENT_COLOUR_MASK; -} - -colour_t wall_get_secondary_colour(const rct_tile_element* wallElement) -{ - uint8_t secondaryColour = (wallElement->properties.wall.colour_1 & ~TILE_ELEMENT_COLOUR_MASK) >> 5; - secondaryColour |= (wallElement->flags & 0x60) >> 2; - return secondaryColour; -} - -colour_t wall_get_tertiary_colour(const rct_tile_element* tileElement) -{ - return tileElement->properties.wall.colour_3 & TILE_ELEMENT_COLOUR_MASK; -} - -void wall_set_primary_colour(rct_tile_element* tileElement, colour_t colour) -{ - assert(colour <= 31); - tileElement->properties.wall.colour_1 &= ~TILE_ELEMENT_COLOUR_MASK; - tileElement->properties.wall.colour_1 |= colour; -} - -void wall_set_secondary_colour(rct_tile_element* wallElement, colour_t secondaryColour) -{ - wallElement->properties.wall.colour_1 &= TILE_ELEMENT_COLOUR_MASK; - wallElement->properties.wall.colour_1 |= (secondaryColour & 0x7) << 5; - wallElement->flags &= ~0x60; - wallElement->flags |= (secondaryColour & 0x18) << 2; -} - -void wall_set_tertiary_colour(rct_tile_element* tileElement, colour_t colour) -{ - assert(colour <= 31); - tileElement->properties.wall.colour_3 &= ~TILE_ELEMENT_COLOUR_MASK; - tileElement->properties.wall.colour_3 |= colour; -} - /** * * rct2: 0x006E588E diff --git a/src/openrct2/world/Wall.h b/src/openrct2/world/Wall.h index 29b352148f..4232395034 100644 --- a/src/openrct2/world/Wall.h +++ b/src/openrct2/world/Wall.h @@ -20,12 +20,6 @@ enum WALL_ANIMATION_FLAG_ALL_FLAGS = WALL_ANIMATION_FLAG_ACROSS_TRACK | WALL_ANIMATION_FLAG_DIRECTION_BACKWARD }; -colour_t wall_get_primary_colour(const rct_tile_element* tileElement); -colour_t wall_get_secondary_colour(const rct_tile_element* wallElement); -colour_t wall_get_tertiary_colour(const rct_tile_element* tileElement); -void wall_set_primary_colour(rct_tile_element* tileElement, colour_t colour); -void wall_set_secondary_colour(rct_tile_element* wallElement, colour_t secondaryColour); -void wall_set_tertiary_colour(rct_tile_element* tileElement, colour_t colour); uint8_t wall_get_animation_frame(const rct_tile_element* fenceElement); void wall_set_animation_frame(rct_tile_element* wallElement, uint8_t frameNum); From 345e03d41be36ca1983f3fd79bd3c87ea2c80a87 Mon Sep 17 00:00:00 2001 From: Michael Steenbeek Date: Mon, 17 Sep 2018 14:48:27 +0200 Subject: [PATCH 3/7] 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); From 508276b0817e5141e3300fef2b58778ebd734364 Mon Sep 17 00:00:00 2001 From: Michael Steenbeek Date: Mon, 17 Sep 2018 15:18:07 +0200 Subject: [PATCH 4/7] Remove lots of direct access to ->type fields --- src/openrct2-ui/windows/TileInspector.cpp | 4 ++-- src/openrct2/actions/FootpathRemoveAction.hpp | 2 +- .../paint/tile_element/Paint.SmallScenery.cpp | 2 +- src/openrct2/paint/tile_element/Paint.Wall.cpp | 16 ++++++++-------- src/openrct2/rct1/S4Importer.cpp | 10 ++++++---- src/openrct2/ride/TrackDesign.cpp | 2 +- src/openrct2/ride/Vehicle.cpp | 2 +- src/openrct2/world/SmallScenery.cpp | 15 ++++++++++----- src/openrct2/world/TileElement.h | 1 + src/openrct2/world/TileInspector.cpp | 14 +++++--------- src/openrct2/world/Wall.cpp | 6 ++++-- 11 files changed, 40 insertions(+), 34 deletions(-) diff --git a/src/openrct2-ui/windows/TileInspector.cpp b/src/openrct2-ui/windows/TileInspector.cpp index cf02c56638..1226257bb5 100644 --- a/src/openrct2-ui/windows/TileInspector.cpp +++ b/src/openrct2-ui/windows/TileInspector.cpp @@ -730,7 +730,7 @@ static void window_tile_inspector_entrance_make_usable(int32_t elementIndex) static void window_tile_inspector_wall_set_slope(int32_t elementIndex, int32_t slopeValue) { // Make sure only the correct bits are set - openrct2_assert((slopeValue & 0xC0) == slopeValue, "slopeValue doesn't match its mask"); + openrct2_assert((slopeValue & 3) == slopeValue, "slopeValue doesn't match its mask"); game_do_command( TILE_INSPECTOR_WALL_SET_SLOPE, GAME_COMMAND_FLAG_APPLY, windowTileInspectorTileX | (windowTileInspectorTileY << 8), @@ -1189,7 +1189,7 @@ static void window_tile_inspector_dropdown(rct_window* w, rct_widgetindex widget switch (widgetIndex) { case WIDX_WALL_DROPDOWN_SLOPE_BUTTON: - window_tile_inspector_wall_set_slope(windowTileInspectorSelectedIndex, dropdownIndex << 6); + window_tile_inspector_wall_set_slope(windowTileInspectorSelectedIndex, dropdownIndex); break; } break; diff --git a/src/openrct2/actions/FootpathRemoveAction.hpp b/src/openrct2/actions/FootpathRemoveAction.hpp index 64646d7786..02650b54e8 100644 --- a/src/openrct2/actions/FootpathRemoveAction.hpp +++ b/src/openrct2/actions/FootpathRemoveAction.hpp @@ -109,7 +109,7 @@ private: { while (!(tileElement++)->IsLastForTile()) { - if (tileElement->type != TILE_ELEMENT_TYPE_PATH && !tileElement->IsGhost()) + if (tileElement->GetType() != TILE_ELEMENT_TYPE_PATH && !tileElement->IsGhost()) { continue; } diff --git a/src/openrct2/paint/tile_element/Paint.SmallScenery.cpp b/src/openrct2/paint/tile_element/Paint.SmallScenery.cpp index 77160e8057..5d9515c1cd 100644 --- a/src/openrct2/paint/tile_element/Paint.SmallScenery.cpp +++ b/src/openrct2/paint/tile_element/Paint.SmallScenery.cpp @@ -288,7 +288,7 @@ void scenery_paint(paint_session* session, uint8_t direction, int32_t height, co { // 6E01F8: frame += ((session->SpritePosition.x / 4) + (session->SpritePosition.y / 4)); - frame += (tileElement->type & 0xC0) / 16; + frame += tileElement->AsSmallScenery()->GetSceneryQuadrant() << 2; } // 6E0222: uint16_t delay = entry->small_scenery.animation_delay & 0xFF; diff --git a/src/openrct2/paint/tile_element/Paint.Wall.cpp b/src/openrct2/paint/tile_element/Paint.Wall.cpp index 5cf671f1b5..b55ad42ec2 100644 --- a/src/openrct2/paint/tile_element/Paint.Wall.cpp +++ b/src/openrct2/paint/tile_element/Paint.Wall.cpp @@ -300,11 +300,11 @@ void fence_paint(paint_session* session, uint8_t direction, int32_t height, cons switch (direction) { case 0: - if (tile_element->type & 0x80) + if (tile_element->AsWall()->GetSlope() == 2) { imageOffset = 3; } - else if (tile_element->type & 0x40) + else if (tile_element->AsWall()->GetSlope() == 1) { imageOffset = 5; } @@ -319,11 +319,11 @@ void fence_paint(paint_session* session, uint8_t direction, int32_t height, cons break; case 1: - if (tile_element->type & 0x80) + if (tile_element->AsWall()->GetSlope() == 2) { imageOffset = 2; } - else if (tile_element->type & 0x40) + else if (tile_element->AsWall()->GetSlope() == 1) { imageOffset = 4; } @@ -353,11 +353,11 @@ void fence_paint(paint_session* session, uint8_t direction, int32_t height, cons break; case 2: - if (tile_element->type & 0x80) + if (tile_element->AsWall()->GetSlope() == 2) { imageOffset = 5; } - else if (tile_element->type & 0x40) + else if (tile_element->AsWall()->GetSlope() == 1) { imageOffset = 3; } @@ -377,11 +377,11 @@ void fence_paint(paint_session* session, uint8_t direction, int32_t height, cons break; case 3: - if (tile_element->type & 0x80) + if (tile_element->AsWall()->GetSlope() == 2) { imageOffset = 4; } - else if (tile_element->type & 0x40) + else if (tile_element->AsWall()->GetSlope() == 1) { imageOffset = 2; } diff --git a/src/openrct2/rct1/S4Importer.cpp b/src/openrct2/rct1/S4Importer.cpp index 89eeac1f76..fd883ecc9f 100644 --- a/src/openrct2/rct1/S4Importer.cpp +++ b/src/openrct2/rct1/S4Importer.cpp @@ -2404,10 +2404,11 @@ private: // Fill the rest of the row with blank tiles for (int32_t y = 0; y < RCT1_MAX_MAP_SIZE; y++) { - nextFreeTileElement->type = TILE_ELEMENT_TYPE_SURFACE; + memset(nextFreeTileElement, 0, sizeof(rct_tile_element)); + nextFreeTileElement->SetType(TILE_ELEMENT_TYPE_SURFACE); nextFreeTileElement->flags = TILE_ELEMENT_FLAG_LAST_TILE; nextFreeTileElement->base_height = 2; - nextFreeTileElement->clearance_height = 0; + nextFreeTileElement->clearance_height = 2; nextFreeTileElement->AsSurface()->SetSlope(TILE_ELEMENT_SLOPE_FLAT); nextFreeTileElement->AsSurface()->SetSurfaceStyle(TERRAIN_GRASS); nextFreeTileElement->AsSurface()->SetEdgeStyle(TERRAIN_EDGE_ROCK); @@ -2420,10 +2421,11 @@ private: // 128 extra rows left to fill with blank tiles for (int32_t y = 0; y < 128 * 256; y++) { - nextFreeTileElement->type = TILE_ELEMENT_TYPE_SURFACE; + memset(nextFreeTileElement, 0, sizeof(rct_tile_element)); + nextFreeTileElement->SetType(TILE_ELEMENT_TYPE_SURFACE); nextFreeTileElement->flags = TILE_ELEMENT_FLAG_LAST_TILE; nextFreeTileElement->base_height = 2; - nextFreeTileElement->clearance_height = 0; + nextFreeTileElement->clearance_height = 2; nextFreeTileElement->AsSurface()->SetSlope(TILE_ELEMENT_SLOPE_FLAT); nextFreeTileElement->AsSurface()->SetSurfaceStyle(TERRAIN_GRASS); nextFreeTileElement->AsSurface()->SetEdgeStyle(TERRAIN_EDGE_ROCK); diff --git a/src/openrct2/ride/TrackDesign.cpp b/src/openrct2/ride/TrackDesign.cpp index 2a009750ec..5b19330a23 100644 --- a/src/openrct2/ride/TrackDesign.cpp +++ b/src/openrct2/ride/TrackDesign.cpp @@ -2327,7 +2327,7 @@ static void track_design_preview_clear_map() { rct_tile_element* tile_element = &gTileElements[i]; memset(tile_element, 0, sizeof(rct_tile_element)); - tile_element->type = TILE_ELEMENT_TYPE_SURFACE; + tile_element->SetType(TILE_ELEMENT_TYPE_SURFACE); tile_element->flags = TILE_ELEMENT_FLAG_LAST_TILE; tile_element->base_height = 2; tile_element->clearance_height = 0; diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index 5a43c530fc..b93df28ca2 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -2846,7 +2846,7 @@ static bool vehicle_can_depart_synchronised(rct_vehicle* vehicle) * is found we allow for space between that and the next. */ - int32_t direction = (tileElement->type + 1) & 3; + int32_t direction = tileElement->GetDirectionWithOffset(1); int32_t spaceBetween; int32_t maxCheckDistance = RIDE_ADJACENCY_CHECK_DISTANCE; diff --git a/src/openrct2/world/SmallScenery.cpp b/src/openrct2/world/SmallScenery.cpp index 2fff1f9c8c..c8e9b2e061 100644 --- a/src/openrct2/world/SmallScenery.cpp +++ b/src/openrct2/world/SmallScenery.cpp @@ -76,7 +76,7 @@ static money32 SmallSceneryRemove( { if (tileElement->GetType() != TILE_ELEMENT_TYPE_SMALL_SCENERY) continue; - if ((tileElement->type >> 6) != quadrant) + if ((tileElement->AsSmallScenery()->GetSceneryQuadrant()) != quadrant) continue; if (tileElement->base_height != baseHeight) continue; @@ -382,11 +382,10 @@ static money32 SmallSceneryPlace( rct_tile_element* newElement = tile_element_insert(x / 32, y / 32, zLow, collisionQuadrants); assert(newElement != nullptr); gSceneryTileElement = newElement; - uint8_t type = quadrant << 6; - type |= TILE_ELEMENT_TYPE_SMALL_SCENERY; - type |= rotation; - newElement->type = type; SmallSceneryElement* sceneryElement = newElement->AsSmallScenery(); + newElement->SetType(TILE_ELEMENT_TYPE_SMALL_SCENERY); + newElement->AsSmallScenery()->SetSceneryQuadrant(quadrant); + newElement->SetDirection(rotation); sceneryElement->SetEntryIndex(sceneryType); sceneryElement->SetAge(0); sceneryElement->SetPrimaryColour(primaryColour); @@ -530,6 +529,12 @@ uint8_t SmallSceneryElement::GetSceneryQuadrant() const return (this->type & TILE_ELEMENT_QUADRANT_MASK) >> 6; } +void SmallSceneryElement::SetSceneryQuadrant(uint8_t newQuadrant) +{ + type &= ~TILE_ELEMENT_QUADRANT_MASK; + type |= (newQuadrant << 6); +} + uint8_t SmallSceneryElement::GetEntryIndex() const { return this->entryIndex; diff --git a/src/openrct2/world/TileElement.h b/src/openrct2/world/TileElement.h index ce2e79fad6..34c15a8464 100644 --- a/src/openrct2/world/TileElement.h +++ b/src/openrct2/world/TileElement.h @@ -263,6 +263,7 @@ public: void SetAge(uint8_t newAge); void IncreaseAge(int32_t x, int32_t y); uint8_t GetSceneryQuadrant() const; + void SetSceneryQuadrant(uint8_t newQuadrant); colour_t GetPrimaryColour() const; void SetPrimaryColour(colour_t colour); colour_t GetSecondaryColour() const; diff --git a/src/openrct2/world/TileInspector.cpp b/src/openrct2/world/TileInspector.cpp index 3775aa0e62..d58a9fe170 100644 --- a/src/openrct2/world/TileInspector.cpp +++ b/src/openrct2/world/TileInspector.cpp @@ -92,7 +92,7 @@ int32_t tile_inspector_insert_corrupt_at(int32_t x, int32_t y, int16_t elementIn log_warning("Failed to insert corrupt element."); return MONEY32_UNDEFINED; } - corruptElement->type = TILE_ELEMENT_TYPE_CORRUPT; + corruptElement->SetType(TILE_ELEMENT_TYPE_CORRUPT); // Set the base height to be the same as the selected element rct_tile_element* const selectedElement = map_get_nth_element_at(x, y, elementIndex + 1); @@ -238,8 +238,7 @@ int32_t tile_inspector_rotate_element_at(int32_t x, int32_t y, int32_t elementIn { // Update element rotation newRotation = tileElement->GetDirectionWithOffset(1); - tileElement->type &= ~TILE_ELEMENT_DIRECTION_MASK; - tileElement->type |= newRotation; + tileElement->SetDirection(newRotation); // Update ride's known entrance/exit rotation Ride* ride = get_ride(tileElement->properties.entrance.ride_index); @@ -264,8 +263,7 @@ int32_t tile_inspector_rotate_element_at(int32_t x, int32_t y, int32_t elementIn case TILE_ELEMENT_TYPE_SMALL_SCENERY: case TILE_ELEMENT_TYPE_WALL: newRotation = tileElement->GetDirectionWithOffset(1); - tileElement->type &= ~TILE_ELEMENT_DIRECTION_MASK; - tileElement->type |= newRotation; + tileElement->SetDirection(newRotation); break; case TILE_ELEMENT_TYPE_BANNER: { @@ -708,8 +706,7 @@ int32_t tile_inspector_wall_set_slope(int32_t x, int32_t y, int32_t elementIndex if (flags & GAME_COMMAND_FLAG_APPLY) { // Set new slope value - wallElement->type &= ~0xC0; - wallElement->type |= slopeValue; + wallElement->AsWall()->SetSlope(slopeValue); map_invalidate_tile_full(x << 5, y << 5); @@ -994,8 +991,7 @@ int32_t tile_inspector_scenery_set_quarter_location( if (flags & GAME_COMMAND_FLAG_APPLY) { // Set quadrant index - tileElement->type &= ~TILE_ELEMENT_QUADRANT_MASK; - tileElement->type |= quarterIndex << 6; + tileElement->AsSmallScenery()->SetSceneryQuadrant(quarterIndex); // Update collision tileElement->flags &= 0xF0; diff --git a/src/openrct2/world/Wall.cpp b/src/openrct2/world/Wall.cpp index db57c71faf..a1c348390c 100644 --- a/src/openrct2/world/Wall.cpp +++ b/src/openrct2/world/Wall.cpp @@ -512,8 +512,10 @@ static money32 WallPlace( map_animation_create(MAP_ANIMATION_TYPE_WALL, position.x, position.y, position.z / 8); tileElement->clearance_height = clearanceHeight; - - tileElement->type = edgeSlope | edge | TILE_ELEMENT_TYPE_WALL; + tileElement->SetType(TILE_ELEMENT_TYPE_WALL); + tileElement->SetDirection(edge); + // TODO: Normalise the edge slope code. + tileElement->AsWall()->SetSlope(edgeSlope >> 6); tileElement->AsWall()->SetPrimaryColour(primaryColour); tileElement->AsWall()->SetSecondaryColour(secondaryColour); From 6062960390e062dc292bb80905463afae904f87f Mon Sep 17 00:00:00 2001 From: Michael Steenbeek Date: Mon, 17 Sep 2018 15:42:34 +0200 Subject: [PATCH 5/7] Port remaining wall stuff to struct methods --- .../interface/ViewportInteraction.cpp | 8 +-- src/openrct2-ui/windows/Sign.cpp | 10 ++-- src/openrct2-ui/windows/TileInspector.cpp | 8 +-- src/openrct2-ui/windows/TopToolbar.cpp | 4 +- src/openrct2/EditorObjectSelectionSession.cpp | 2 +- .../paint/tile_element/Paint.Wall.cpp | 7 ++- src/openrct2/peep/Guest.cpp | 12 ++-- src/openrct2/ride/TrackDesignSave.cpp | 4 +- src/openrct2/ride/Vehicle.cpp | 13 +++-- src/openrct2/world/Map.cpp | 6 +- src/openrct2/world/MapAnimation.cpp | 4 +- src/openrct2/world/TileElement.cpp | 6 +- src/openrct2/world/TileElement.h | 26 ++++----- src/openrct2/world/Wall.cpp | 57 +++++++++++++++++-- 14 files changed, 108 insertions(+), 59 deletions(-) diff --git a/src/openrct2-ui/interface/ViewportInteraction.cpp b/src/openrct2-ui/interface/ViewportInteraction.cpp index 94035d17e7..0723bbabb8 100644 --- a/src/openrct2-ui/interface/ViewportInteraction.cpp +++ b/src/openrct2-ui/interface/ViewportInteraction.cpp @@ -306,7 +306,7 @@ int32_t viewport_interaction_get_item_right(int32_t x, int32_t y, viewport_inter return info->type; case VIEWPORT_INTERACTION_ITEM_WALL: - sceneryEntry = get_wall_entry(tileElement->properties.wall.type); + sceneryEntry = tileElement->AsWall()->GetEntry(); if (sceneryEntry->wall.scrolling_mode != 255) { set_map_tooltip_format_arg(0, rct_string_id, STR_MAP_TOOLTIP_STRINGID_CLICK_TO_MODIFY); @@ -383,7 +383,7 @@ int32_t viewport_interaction_get_item_right(int32_t x, int32_t y, viewport_inter return info->type; case VIEWPORT_INTERACTION_ITEM_WALL: - sceneryEntry = get_wall_entry(tileElement->properties.wall.type); + sceneryEntry = tileElement->AsWall()->GetEntry(); set_map_tooltip_format_arg(0, rct_string_id, STR_MAP_TOOLTIP_STRINGID_CLICK_TO_REMOVE); set_map_tooltip_format_arg(2, rct_string_id, sceneryEntry->name); return info->type; @@ -540,10 +540,10 @@ void viewport_interaction_remove_park_entrance(rct_tile_element* tileElement, in */ static void viewport_interaction_remove_park_wall(rct_tile_element* tileElement, int32_t x, int32_t y) { - rct_scenery_entry* sceneryEntry = get_wall_entry(tileElement->properties.wall.type); + rct_scenery_entry* sceneryEntry = tileElement->AsWall()->GetEntry(); if (sceneryEntry->wall.scrolling_mode != 0xFF) { - context_open_detail_window(WD_SIGN_SMALL, tileElement->properties.wall.banner_index); + context_open_detail_window(WD_SIGN_SMALL, tileElement->AsWall()->GetBannerIndex()); } else { diff --git a/src/openrct2-ui/windows/Sign.cpp b/src/openrct2-ui/windows/Sign.cpp index 6d05f66b22..5e246be401 100644 --- a/src/openrct2-ui/windows/Sign.cpp +++ b/src/openrct2-ui/windows/Sign.cpp @@ -410,10 +410,10 @@ rct_window* window_sign_small_open(rct_windownumber number) { if (tile_element->GetType() == TILE_ELEMENT_TYPE_WALL) { - rct_scenery_entry* scenery_entry = get_wall_entry(tile_element->properties.wall.type); + rct_scenery_entry* scenery_entry = tile_element->AsWall()->GetEntry(); if (scenery_entry->wall.scrolling_mode != 0xFF) { - if (tile_element->properties.wall.banner_index == w->number) + if (tile_element->AsWall()->GetBannerIndex() == w->number) break; } } @@ -425,7 +425,7 @@ rct_window* window_sign_small_open(rct_windownumber number) w->list_information_type = tile_element->AsWall()->GetPrimaryColour(); w->var_492 = tile_element->AsWall()->GetSecondaryColour(); - w->var_48C = tile_element->properties.wall.type; + w->var_48C = tile_element->AsWall()->GetEntryIndex(); view_x += 16; view_y += 16; @@ -468,10 +468,10 @@ static void window_sign_small_mouseup(rct_window* w, rct_widgetindex widgetIndex { if (tile_element->GetType() == TILE_ELEMENT_TYPE_WALL) { - rct_scenery_entry* scenery_entry = get_wall_entry(tile_element->properties.wall.type); + rct_scenery_entry* scenery_entry = tile_element->AsWall()->GetEntry(); if (scenery_entry->wall.scrolling_mode != 0xFF) { - if (tile_element->properties.wall.banner_index == w->number) + if (tile_element->AsWall()->GetBannerIndex() == w->number) break; } } diff --git a/src/openrct2-ui/windows/TileInspector.cpp b/src/openrct2-ui/windows/TileInspector.cpp index 1226257bb5..0d9e17a897 100644 --- a/src/openrct2-ui/windows/TileInspector.cpp +++ b/src/openrct2-ui/windows/TileInspector.cpp @@ -1623,7 +1623,7 @@ static void window_tile_inspector_invalidate(rct_window* w) w->widgets[WIDX_WALL_DROPDOWN_SLOPE].text = WallSlopeStringIds[tileElement->AsWall()->GetSlope()]; w->widgets[WIDX_WALL_DROPDOWN_SLOPE_BUTTON].top = GBBT(propertiesAnchor, 1) + 4; w->widgets[WIDX_WALL_DROPDOWN_SLOPE_BUTTON].bottom = GBBB(propertiesAnchor, 1) - 4; - const uint8_t wallType = tileElement->properties.wall.type; + const uint8_t wallType = tileElement->AsWall()->GetEntryIndex(); const rct_wall_scenery_entry wallEntry = get_wall_entry(wallType)->wall; const bool canBeSloped = !(wallEntry.flags & WALL_SCENERY_CANT_BUILD_ON_SLOPE); // Wall slope dropdown @@ -1978,7 +1978,7 @@ static void window_tile_inspector_paint(rct_window* w, rct_drawpixelinfo* dpi) { // Details // Type - int16_t wallType = tileElement->properties.wall.type; + int16_t wallType = tileElement->AsWall()->GetEntryIndex(); gfx_draw_string_left(dpi, STR_TILE_INSPECTOR_WALL_TYPE, &wallType, COLOUR_DARK_GREEN, x, y); // Banner info @@ -1987,7 +1987,7 @@ static void window_tile_inspector_paint(rct_window* w, rct_drawpixelinfo* dpi) { gfx_draw_string_left( dpi, STR_TILE_INSPECTOR_ENTRY_BANNER_TEXT, - &gBanners[tileElement->properties.wall.banner_index].string_idx, COLOUR_DARK_GREEN, x, y + 11); + &gBanners[tileElement->AsWall()->GetBannerIndex()].string_idx, COLOUR_DARK_GREEN, x, y + 11); } else { @@ -2158,7 +2158,7 @@ static void window_tile_inspector_scrollpaint(rct_window* w, rct_drawpixelinfo* case TILE_ELEMENT_TYPE_WALL: snprintf( buffer, sizeof(buffer), "%s (%s)", language_get_string(STR_TILE_INSPECTOR_WALL), - language_get_string(get_wall_entry(tileElement->properties.wall.type)->name)); + language_get_string(tileElement->AsWall()->GetEntry()->name)); typeName = buffer; break; case TILE_ELEMENT_TYPE_LARGE_SCENERY: diff --git a/src/openrct2-ui/windows/TopToolbar.cpp b/src/openrct2-ui/windows/TopToolbar.cpp index 950d0e6c9a..eb4bdf6b9c 100644 --- a/src/openrct2-ui/windows/TopToolbar.cpp +++ b/src/openrct2-ui/windows/TopToolbar.cpp @@ -1001,7 +1001,7 @@ static void repaint_scenery_tool_down(int16_t x, int16_t y, rct_widgetindex widg } case VIEWPORT_INTERACTION_ITEM_WALL: { - rct_scenery_entry* scenery_entry = get_wall_entry(tile_element->properties.wall.type); + rct_scenery_entry* scenery_entry = tile_element->AsWall()->GetEntry(); // If can't repaint if (!(scenery_entry->wall.flags & (WALL_SCENERY_HAS_PRIMARY_COLOUR | WALL_SCENERY_HAS_GLASS))) @@ -1080,7 +1080,7 @@ static void scenery_eyedropper_tool_down(int16_t x, int16_t y, rct_widgetindex w } case VIEWPORT_INTERACTION_ITEM_WALL: { - int32_t entryIndex = tileElement->properties.wall.type; + int32_t entryIndex = tileElement->AsWall()->GetEntryIndex(); rct_scenery_entry* sceneryEntry = get_wall_entry(entryIndex); if (sceneryEntry != nullptr) { diff --git a/src/openrct2/EditorObjectSelectionSession.cpp b/src/openrct2/EditorObjectSelectionSession.cpp index 688b1fc85d..fd0ec9c1c0 100644 --- a/src/openrct2/EditorObjectSelectionSession.cpp +++ b/src/openrct2/EditorObjectSelectionSession.cpp @@ -161,7 +161,7 @@ void setup_in_use_selection_flags() Editor::SetSelectedObject(OBJECT_TYPE_PATHS, type, OBJECT_SELECTION_FLAG_SELECTED); break; case TILE_ELEMENT_TYPE_WALL: - type = iter.element->properties.wall.type; + type = iter.element->AsWall()->GetEntryIndex(); assert(type < object_entry_group_counts[OBJECT_TYPE_WALLS]); Editor::SetSelectedObject(OBJECT_TYPE_WALLS, type, OBJECT_SELECTION_FLAG_SELECTED); break; diff --git a/src/openrct2/paint/tile_element/Paint.Wall.cpp b/src/openrct2/paint/tile_element/Paint.Wall.cpp index b55ad42ec2..0a83a93c3f 100644 --- a/src/openrct2/paint/tile_element/Paint.Wall.cpp +++ b/src/openrct2/paint/tile_element/Paint.Wall.cpp @@ -158,7 +158,7 @@ void fence_paint(paint_session* session, uint8_t direction, int32_t height, cons { session->InteractionType = VIEWPORT_INTERACTION_ITEM_WALL; - rct_scenery_entry* sceneryEntry = get_wall_entry(tile_element->properties.wall.type); + rct_scenery_entry* sceneryEntry = tile_element->AsWall()->GetEntry(); if (sceneryEntry == nullptr) { return; @@ -214,7 +214,8 @@ void fence_paint(paint_session* session, uint8_t direction, int32_t height, cons LocationXYZ16 boundsR1, boundsR1_, boundsR2, boundsR2_, boundsL1, boundsL1_; uint8_t animationFrame = tile_element->AsWall()->GetAnimationFrame(); // Add the direction as well - animationFrame |= (tile_element->properties.wall.animation & WALL_ANIMATION_FLAG_DIRECTION_BACKWARD) >> 3; + if (tile_element->AsWall()->AnimationIsBackwards()) + animationFrame |= (1 << 4); uint32_t imageId; switch (direction) { @@ -429,7 +430,7 @@ void fence_paint(paint_session* session, uint8_t direction, int32_t height, cons uint16_t scrollingMode = sceneryEntry->wall.scrolling_mode + ((direction + 1) & 0x3); - uint8_t bannerIndex = tile_element->properties.wall.banner_index; + uint8_t bannerIndex = tile_element->AsWall()->GetBannerIndex(); rct_banner* banner = &gBanners[bannerIndex]; set_format_arg(0, rct_string_id, banner->string_idx); diff --git a/src/openrct2/peep/Guest.cpp b/src/openrct2/peep/Guest.cpp index 02f235c394..5f98271193 100644 --- a/src/openrct2/peep/Guest.cpp +++ b/src/openrct2/peep/Guest.cpp @@ -6299,7 +6299,7 @@ static bool peep_find_ride_to_look_at(rct_peep* peep, uint8_t edge, uint8_t* rid continue; if (tileElement->GetDirection() != edge) continue; - auto wallEntry = get_wall_entry(tileElement->properties.wall.type); + auto wallEntry = tileElement->AsWall()->GetEntry(); if (wallEntry == nullptr || (wallEntry->wall.flags2 & WALL_SCENERY_2_IS_OPAQUE)) continue; if (peep->next_z + 4 <= tileElement->base_height) @@ -6333,7 +6333,7 @@ static bool peep_find_ride_to_look_at(rct_peep* peep, uint8_t edge, uint8_t* rid continue; if (tileElement->GetDirectionWithOffset(2) != edge) continue; - auto wallEntry = get_wall_entry(tileElement->properties.wall.type); + auto wallEntry = tileElement->AsWall()->GetEntry(); if (wallEntry == nullptr || (wallEntry->wall.flags2 & WALL_SCENERY_2_IS_OPAQUE)) continue; // TODO: Check whether this shouldn't be <=, as the other loops use. If so, also extract as loop A. @@ -6411,7 +6411,7 @@ static bool peep_find_ride_to_look_at(rct_peep* peep, uint8_t edge, uint8_t* rid if (tileElement->GetType() == TILE_ELEMENT_TYPE_WALL) { - auto wallEntry = get_wall_entry(tileElement->properties.wall.type); + auto wallEntry = tileElement->AsWall()->GetEntry(); if (wallEntry == nullptr || (wallEntry->wall.flags2 & WALL_SCENERY_2_IS_OPAQUE)) { continue; @@ -6445,7 +6445,7 @@ static bool peep_find_ride_to_look_at(rct_peep* peep, uint8_t edge, uint8_t* rid continue; if (tileElement->GetDirectionWithOffset(2) != edge) continue; - auto wallEntry = get_wall_entry(tileElement->properties.wall.type); + auto wallEntry = tileElement->AsWall()->GetEntry(); if (wallEntry == nullptr || (wallEntry->wall.flags2 & WALL_SCENERY_2_IS_OPAQUE)) continue; if (peep->next_z + 6 <= tileElement->base_height) @@ -6522,7 +6522,7 @@ static bool peep_find_ride_to_look_at(rct_peep* peep, uint8_t edge, uint8_t* rid if (tileElement->GetType() == TILE_ELEMENT_TYPE_WALL) { - auto wallEntry = get_wall_entry(tileElement->properties.wall.type); + auto wallEntry = tileElement->AsWall()->GetEntry(); if (wallEntry == nullptr || (wallEntry->wall.flags2 & WALL_SCENERY_2_IS_OPAQUE)) { continue; @@ -6556,7 +6556,7 @@ static bool peep_find_ride_to_look_at(rct_peep* peep, uint8_t edge, uint8_t* rid continue; if (tileElement->GetDirectionWithOffset(2) != edge) continue; - auto wallEntry = get_wall_entry(tileElement->properties.wall.type); + auto wallEntry = tileElement->AsWall()->GetEntry(); if (wallEntry == nullptr || (wallEntry->wall.flags2 & WALL_SCENERY_2_IS_OPAQUE)) continue; if (peep->next_z + 8 <= tileElement->base_height) diff --git a/src/openrct2/ride/TrackDesignSave.cpp b/src/openrct2/ride/TrackDesignSave.cpp index 9f8f00df2c..3c060a3a88 100644 --- a/src/openrct2/ride/TrackDesignSave.cpp +++ b/src/openrct2/ride/TrackDesignSave.cpp @@ -354,7 +354,7 @@ static void track_design_save_add_large_scenery(int32_t x, int32_t y, rct_tile_e static void track_design_save_add_wall(int32_t x, int32_t y, rct_tile_element* tileElement) { - int32_t entryType = tileElement->properties.wall.type; + int32_t entryType = tileElement->AsWall()->GetEntryIndex(); auto entry = object_entry_get_entry(OBJECT_TYPE_WALLS, entryType); uint8_t flags = 0; @@ -542,7 +542,7 @@ static void track_design_save_remove_large_scenery(int32_t x, int32_t y, rct_til static void track_design_save_remove_wall(int32_t x, int32_t y, rct_tile_element* tileElement) { - int32_t entryType = tileElement->properties.wall.type; + int32_t entryType = tileElement->AsWall()->GetEntryIndex(); auto entry = object_entry_get_entry(OBJECT_TYPE_WALLS, entryType); uint8_t flags = 0; diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index b93df28ca2..2db3b8a3ea 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -7397,7 +7397,7 @@ static void vehicle_update_additional_animation(rct_vehicle* vehicle) */ static void vehicle_play_scenery_door_open_sound(rct_vehicle* vehicle, rct_tile_element* tileElement) { - rct_scenery_entry* wallEntry = get_wall_entry(tileElement->properties.wall.type); + rct_scenery_entry* wallEntry = tileElement->AsWall()->GetEntry(); int32_t doorSoundType = wall_entry_get_door_sound(wallEntry); if (doorSoundType != 0) { @@ -7415,7 +7415,7 @@ static void vehicle_play_scenery_door_open_sound(rct_vehicle* vehicle, rct_tile_ */ static void vehicle_play_scenery_door_close_sound(rct_vehicle* vehicle, rct_tile_element* tileElement) { - rct_scenery_entry* wallEntry = get_wall_entry(tileElement->properties.wall.type); + rct_scenery_entry* wallEntry = tileElement->AsWall()->GetEntry(); int32_t doorSoundType = wall_entry_get_door_sound(wallEntry); if (doorSoundType != 0) { @@ -7453,14 +7453,15 @@ 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); + // FIXME: Likely an implementation typo, should probably be true! + tileElement->AsWall()->SetAnimationIsBackwards(false); 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); + tileElement->AsWall()->SetAnimationIsBackwards(false); tileElement->AsWall()->SetAnimationFrame(6); vehicle_play_scenery_door_close_sound(vehicle, tileElement); } @@ -7533,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; + tileElement->AsWall()->SetAnimationIsBackwards(true); 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); + tileElement->AsWall()->SetAnimationIsBackwards(false); tileElement->AsWall()->SetAnimationFrame(6); vehicle_play_scenery_door_close_sound(vehicle, tileElement); } diff --git a/src/openrct2/world/Map.cpp b/src/openrct2/world/Map.cpp index 26c6e005cb..8855c14322 100644 --- a/src/openrct2/world/Map.cpp +++ b/src/openrct2/world/Map.cpp @@ -3442,7 +3442,7 @@ void map_obstruction_set_error_text(rct_tile_element* tileElement) } break; case TILE_ELEMENT_TYPE_WALL: - sceneryEntry = get_wall_entry(tileElement->properties.wall.type); + sceneryEntry = tileElement->AsWall()->GetEntry(); errorStringId = STR_X_IN_THE_WAY; set_format_arg(0, rct_string_id, sceneryEntry->name); break; @@ -4388,10 +4388,10 @@ void game_command_set_sign_style( if (tileElement->GetType() != TILE_ELEMENT_TYPE_WALL) continue; - rct_scenery_entry* scenery_entry = get_wall_entry(tileElement->properties.wall.type); + rct_scenery_entry* scenery_entry = tileElement->AsWall()->GetEntry(); if (scenery_entry->wall.scrolling_mode == 0xFF) continue; - if (tileElement->properties.wall.banner_index != bannerId) + if (tileElement->AsWall()->GetBannerIndex() != bannerId) continue; wall_found = true; break; diff --git a/src/openrct2/world/MapAnimation.cpp b/src/openrct2/world/MapAnimation.cpp index 75042f06f5..6d7c2cca3e 100644 --- a/src/openrct2/world/MapAnimation.cpp +++ b/src/openrct2/world/MapAnimation.cpp @@ -492,7 +492,7 @@ static bool map_animation_invalidate_wall_door(int32_t x, int32_t y, int32_t bas if (tileElement->GetType() != TILE_ELEMENT_TYPE_WALL) continue; - sceneryEntry = get_wall_entry(tileElement->properties.wall.type); + sceneryEntry = tileElement->AsWall()->GetEntry(); if (!(sceneryEntry->wall.flags & WALL_SCENERY_IS_DOOR)) continue; @@ -552,7 +552,7 @@ static bool map_animation_invalidate_wall(int32_t x, int32_t y, int32_t baseZ) if (tileElement->GetType() != TILE_ELEMENT_TYPE_WALL) continue; - sceneryEntry = get_wall_entry(tileElement->properties.wall.type); + sceneryEntry = tileElement->AsWall()->GetEntry(); if (!(sceneryEntry->wall.flags2 & WALL_SCENERY_2_ANIMATED) && sceneryEntry->wall.scrolling_mode == 255) continue; diff --git a/src/openrct2/world/TileElement.cpp b/src/openrct2/world/TileElement.cpp index 5d35b4d67f..3d9e074513 100644 --- a/src/openrct2/world/TileElement.cpp +++ b/src/openrct2/world/TileElement.cpp @@ -78,11 +78,11 @@ BannerIndex tile_element_get_banner_index(rct_tile_element* tileElement) return tileElement->AsLargeScenery()->GetBannerIndex(); case TILE_ELEMENT_TYPE_WALL: - sceneryEntry = get_wall_entry(tileElement->properties.wall.type); + sceneryEntry = tileElement->AsWall()->GetEntry(); if (sceneryEntry == nullptr || sceneryEntry->wall.scrolling_mode == 0xFF) return BANNER_INDEX_NULL; - return tileElement->properties.wall.banner_index; + return tileElement->AsWall()->GetBannerIndex(); case TILE_ELEMENT_TYPE_BANNER: return tileElement->properties.banner.index; default: @@ -95,7 +95,7 @@ void tile_element_set_banner_index(rct_tile_element* tileElement, BannerIndex ba switch (tileElement->GetType()) { case TILE_ELEMENT_TYPE_WALL: - tileElement->properties.wall.banner_index = bannerIndex; + tileElement->AsWall()->SetBannerIndex(bannerIndex); break; case TILE_ELEMENT_TYPE_LARGE_SCENERY: tileElement->AsLargeScenery()->SetBannerIndex(bannerIndex); diff --git a/src/openrct2/world/TileElement.h b/src/openrct2/world/TileElement.h index 34c15a8464..60c7c72c52 100644 --- a/src/openrct2/world/TileElement.h +++ b/src/openrct2/world/TileElement.h @@ -64,19 +64,6 @@ struct rct_tile_element_entrance_properties }; assert_struct_size(rct_tile_element_entrance_properties, 4); -struct rct_tile_element_wall_properties -{ - uint8_t type; // 4 - union - { - uint8_t colour_3; // 5 - BannerIndex banner_index; // 5 - }; - uint8_t colour_1; // 6 0b_2221_1111 2 = colour_2 (uses flags for rest of colour2), 1 = colour_1 - uint8_t animation; // 7 0b_dfff_ft00 d = direction, f = frame num, t = across track flag (not used) -}; -assert_struct_size(rct_tile_element_wall_properties, 4); - struct rct_tile_element_banner_properties { BannerIndex index; // 4 @@ -91,7 +78,6 @@ union rct_tile_element_properties rct_tile_element_path_properties path; rct_tile_element_track_properties track; rct_tile_element_entrance_properties entrance; - rct_tile_element_wall_properties wall; rct_tile_element_banner_properties banner; }; assert_struct_size(rct_tile_element_properties, 4); @@ -309,6 +295,10 @@ struct WallElement : TileElementBase uint8_t animation; // 7 0b_dfff_ft00 d = direction, f = frame num, t = across track flag (not used) public: + uint8_t GetEntryIndex() const; + void SetEntryIndex(uint8_t newIndex); + rct_scenery_entry* GetEntry() const; + uint8_t GetSlope() const; void SetSlope(uint8_t newslope); @@ -322,6 +312,14 @@ public: uint8_t GetAnimationFrame() const; void SetAnimationFrame(uint8_t frameNum); + BannerIndex GetBannerIndex() const; + void SetBannerIndex(BannerIndex newIndex); + + bool IsAcrossTrack() const; + void SetAcrossTrack(bool acrossTrack); + bool AnimationIsBackwards() const; + void SetAnimationIsBackwards(bool isBackwards); + int32_t GetRCT1WallType(int32_t edge) const; colour_t GetRCT1WallColour() const; }; diff --git a/src/openrct2/world/Wall.cpp b/src/openrct2/world/Wall.cpp index a1c348390c..56d9ea74f6 100644 --- a/src/openrct2/world/Wall.cpp +++ b/src/openrct2/world/Wall.cpp @@ -522,13 +522,13 @@ static money32 WallPlace( if (wallAcrossTrack) { - tileElement->properties.wall.animation |= WALL_ANIMATION_FLAG_ACROSS_TRACK; + tileElement->AsWall()->SetAcrossTrack(true); } - tileElement->properties.wall.type = wallType; + tileElement->AsWall()->SetEntryIndex(wallType); if (bannerIndex != 0xFF) { - tileElement->properties.wall.banner_index = bannerIndex; + tileElement->AsWall()->SetBannerIndex(bannerIndex); } if (wallEntry->wall.flags & WALL_SCENERY_HAS_TERNARY_COLOUR) @@ -584,7 +584,7 @@ static money32 WallSetColour( if (flags & GAME_COMMAND_FLAG_APPLY) { - rct_scenery_entry* scenery_entry = get_wall_entry(wallElement->properties.wall.type); + rct_scenery_entry* scenery_entry = wallElement->AsWall()->GetEntry(); wallElement->AsWall()->SetPrimaryColour(primaryColour); wallElement->AsWall()->SetSecondaryColour(secondaryColour); @@ -761,4 +761,53 @@ void WallElement::SetAnimationFrame(uint8_t frameNum) { animation &= WALL_ANIMATION_FLAG_ALL_FLAGS; animation |= (frameNum & 0xF) << 3; +} + +uint8_t WallElement::GetEntryIndex() const +{ + return entryIndex; +} + +rct_scenery_entry* WallElement::GetEntry() const +{ + return get_wall_entry(entryIndex); +} + +void WallElement::SetEntryIndex(uint8_t newIndex) +{ + entryIndex = newIndex; +} + +BannerIndex WallElement::GetBannerIndex() const +{ + return banner_index; +} + +void WallElement::SetBannerIndex(BannerIndex newIndex) +{ + banner_index = newIndex; +} + +bool WallElement::IsAcrossTrack() const +{ + return (animation & WALL_ANIMATION_FLAG_ACROSS_TRACK) != 0; +} + +void WallElement::SetAcrossTrack(bool acrossTrack) +{ + animation &= ~WALL_ANIMATION_FLAG_ACROSS_TRACK; + if (acrossTrack) + animation |= WALL_ANIMATION_FLAG_ACROSS_TRACK; +} + +bool WallElement::AnimationIsBackwards() const +{ + return (animation & WALL_ANIMATION_FLAG_DIRECTION_BACKWARD) != 0; +} + +void WallElement::SetAnimationIsBackwards(bool isBackwards) +{ + animation &= ~WALL_ANIMATION_FLAG_DIRECTION_BACKWARD; + if (isBackwards) + animation |= WALL_ANIMATION_FLAG_DIRECTION_BACKWARD; } \ No newline at end of file From f1c98a4475cd2a3795bd0fcaafe9583e946bbef2 Mon Sep 17 00:00:00 2001 From: Michael Steenbeek Date: Mon, 17 Sep 2018 16:12:11 +0200 Subject: [PATCH 6/7] Make fields private --- src/openrct2/world/TileElement.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/openrct2/world/TileElement.h b/src/openrct2/world/TileElement.h index 60c7c72c52..ca144847da 100644 --- a/src/openrct2/world/TileElement.h +++ b/src/openrct2/world/TileElement.h @@ -284,7 +284,7 @@ assert_struct_size(LargeSceneryElement, 8); struct WallElement : TileElementBase { -//private: +private: uint8_t entryIndex; // 4 union { From c8063a3c38cd350b3e4642d30a15ea8eac499d5a Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Mon, 17 Sep 2018 20:03:56 +0200 Subject: [PATCH 7/7] Fix scenery doors closing the wrong --- src/openrct2/ride/Vehicle.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index 2db3b8a3ea..71ed31744c 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -7453,7 +7453,6 @@ static void vehicle_update_scenery_door(rct_vehicle* vehicle) if (vehicle->next_vehicle_on_train != SPRITE_INDEX_NULL) { - // FIXME: Likely an implementation typo, should probably be true! tileElement->AsWall()->SetAnimationIsBackwards(false); tileElement->AsWall()->SetAnimationFrame(1); map_animation_create(MAP_ANIMATION_TYPE_WALL_DOOR, x, y, z); @@ -7541,7 +7540,7 @@ static void vehicle_update_handle_scenery_door(rct_vehicle* vehicle) } else { - tileElement->AsWall()->SetAnimationIsBackwards(false); + tileElement->AsWall()->SetAnimationIsBackwards(true); tileElement->AsWall()->SetAnimationFrame(6); vehicle_play_scenery_door_close_sound(vehicle, tileElement); }