From 2b540b9da1b04d07311d4add1945acb84c85b98a Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Thu, 27 Jul 2017 16:54:58 +0200 Subject: [PATCH] Remove direct access to small scenery's colour_1 and _2 fields --- src/openrct2/paint/map_element/scenery.c | 34 +++++++++++++++-------- src/openrct2/rct1/S4Importer.cpp | 7 ++--- src/openrct2/ride/track_design_save.c | 8 +++--- src/openrct2/windows/top_toolbar.c | 4 +-- src/openrct2/world/SmallScenery.cpp | 13 ++++----- src/openrct2/world/map.h | 5 ++++ src/openrct2/world/mapgen.c | 2 +- src/openrct2/world/scenery.c | 35 ++++++++++++++++++++++++ src/openrct2/world/scenery.h | 7 +++++ 9 files changed, 86 insertions(+), 29 deletions(-) diff --git a/src/openrct2/paint/map_element/scenery.c b/src/openrct2/paint/map_element/scenery.c index d2a50d8a1b..c66eb90f24 100644 --- a/src/openrct2/paint/map_element/scenery.c +++ b/src/openrct2/paint/map_element/scenery.c @@ -117,10 +117,16 @@ void scenery_paint(uint8 direction, sint32 height, rct_map_element* mapElement) baseImageid += 4; } } - if (entry->small_scenery.flags & SMALL_SCENERY_FLAG_HAS_PRIMARY_COLOUR) { - baseImageid |= ((mapElement->properties.scenery.colour_1 & 0x1F) << 19) | IMAGE_TYPE_REMAP; - if (entry->small_scenery.flags & SMALL_SCENERY_FLAG_HAS_SECONDARY_COLOUR) { - baseImageid |= ((mapElement->properties.scenery.colour_2 & 0x1F) << 24) | IMAGE_TYPE_REMAP_2_PLUS; + if (entry->small_scenery.flags & SMALL_SCENERY_FLAG_HAS_PRIMARY_COLOUR) + { + if (entry->small_scenery.flags & SMALL_SCENERY_FLAG_HAS_SECONDARY_COLOUR) + { + baseImageid |= SPRITE_ID_PALETTE_COLOUR_3(scenery_small_get_primary_colour(mapElement), + scenery_small_get_secondary_colour(mapElement)); + } + else + { + baseImageid |= SPRITE_ID_PALETTE_COLOUR_1(scenery_small_get_primary_colour(mapElement)); } } if (dword_F64EB0 != 0) { @@ -134,7 +140,7 @@ void scenery_paint(uint8 direction, sint32 height, rct_map_element* mapElement) if (dword_F64EB0 == 0) { // Draw translucent overlay: // TODO: Name palette entries - sint32 image_id = (baseImageid & 0x7FFFF) + (GlassPaletteIds[(mapElement->properties.scenery.colour_1 & 0x1F)] << 19) + 0x40000004; + sint32 image_id = (baseImageid & 0x7FFFF) + (GlassPaletteIds[scenery_small_get_primary_colour(mapElement)] << 19) + 0x40000004; sub_98199C(image_id, x_offset, y_offset, boxlength.x, boxlength.y, boxlength.z - 1, height, boxoffset.x, boxoffset.y, boxoffset.z, rotation); } } @@ -235,10 +241,15 @@ void scenery_paint(uint8 direction, sint32 height, rct_map_element* mapElement) if (entry->small_scenery.flags & (SMALL_SCENERY_FLAG_VISIBLE_WHEN_ZOOMED | SMALL_SCENERY_FLAG17)) { image_id += 4; } - if (entry->small_scenery.flags & SMALL_SCENERY_FLAG_HAS_PRIMARY_COLOUR) { - image_id |= ((mapElement->properties.scenery.colour_1 & 0x1F) << 19) | IMAGE_TYPE_REMAP; + if (entry->small_scenery.flags & SMALL_SCENERY_FLAG_HAS_PRIMARY_COLOUR) + { if (entry->small_scenery.flags & SMALL_SCENERY_FLAG_HAS_SECONDARY_COLOUR) { - image_id |= ((mapElement->properties.scenery.colour_2 & 0x1F) << 24) | IMAGE_TYPE_REMAP_2_PLUS; + image_id |= SPRITE_ID_PALETTE_COLOUR_3(scenery_small_get_primary_colour(mapElement), + scenery_small_get_secondary_colour(mapElement)); + } + else + { + image_id |= SPRITE_ID_PALETTE_COLOUR_1(scenery_small_get_primary_colour(mapElement)); } } if (dword_F64EB0 != 0) { @@ -254,7 +265,7 @@ void scenery_paint(uint8 direction, sint32 height, rct_map_element* mapElement) } } // 6E0556: Draw supports: - if (mapElement->properties.scenery.colour_1 & 0x20) { + if (scenery_small_get_supports_needed(mapElement)) { if (!(entry->small_scenery.flags & SMALL_SCENERY_FLAG_NO_SUPPORTS)) { sint32 ax = 0; sint32 supportHeight = height; @@ -263,8 +274,9 @@ void scenery_paint(uint8 direction, sint32 height, rct_map_element* mapElement) ax = 49; } uint32 supportImageColourFlags = IMAGE_TYPE_REMAP; - if (entry->small_scenery.flags & SMALL_SCENERY_FLAG_PAINT_SUPPORTS) { - supportImageColourFlags = ((mapElement->properties.scenery.colour_1 & 0x1F) << 19) | IMAGE_TYPE_REMAP; + if (entry->small_scenery.flags & SMALL_SCENERY_FLAG_PAINT_SUPPORTS) + { + supportImageColourFlags = SPRITE_ID_PALETTE_COLOUR_1(scenery_small_get_primary_colour(mapElement)); } if (dword_F64EB0 != 0) { supportImageColourFlags = dword_F64EB0; diff --git a/src/openrct2/rct1/S4Importer.cpp b/src/openrct2/rct1/S4Importer.cpp index 8908f0b250..1351e00fb3 100644 --- a/src/openrct2/rct1/S4Importer.cpp +++ b/src/openrct2/rct1/S4Importer.cpp @@ -2198,9 +2198,8 @@ private: { switch (map_element_get_type(mapElement)) { case MAP_ELEMENT_TYPE_SCENERY: - colour = RCT1::GetColour(mapElement->properties.scenery.colour_1 & 0x1F); - mapElement->properties.scenery.colour_1 &= 0xE0; - mapElement->properties.scenery.colour_1 |= colour; + colour = RCT1::GetColour(scenery_small_get_primary_colour(mapElement)); + scenery_small_set_primary_colour(mapElement, colour); // Copied from [rct2: 0x006A2956] switch (mapElement->properties.scenery.type) { @@ -2209,7 +2208,7 @@ private: case 168: // TGE3 (Geometric Sculpture) case 170: // TGE4 (Geometric Sculpture) case 171: // TGE5 (Geometric Sculpture) - mapElement->properties.scenery.colour_2 = COLOUR_WHITE; + scenery_small_set_secondary_colour(mapElement, COLOUR_WHITE); break; } break; diff --git a/src/openrct2/ride/track_design_save.c b/src/openrct2/ride/track_design_save.c index ebcff4cee9..26629c9f64 100644 --- a/src/openrct2/ride/track_design_save.c +++ b/src/openrct2/ride/track_design_save.c @@ -286,8 +286,8 @@ static void track_design_save_add_scenery(sint32 x, sint32 y, rct_map_element *m flags |= mapElement->type & 3; flags |= (mapElement->type & 0xC0) >> 4; - uint8 primaryColour = mapElement->properties.scenery.colour_1 & 0x1F; - uint8 secondaryColour = mapElement->properties.scenery.colour_2 & 0x1F; + uint8 primaryColour = scenery_small_get_primary_colour(mapElement); + uint8 secondaryColour = scenery_small_get_secondary_colour(mapElement); track_design_save_push_map_element(x, y, mapElement); track_design_save_push_map_element_desc(entry, x, y, mapElement->base_height, flags, primaryColour, secondaryColour); @@ -469,8 +469,8 @@ static void track_design_save_remove_scenery(sint32 x, sint32 y, rct_map_element flags |= mapElement->type & 3; flags |= (mapElement->type & 0xC0) >> 4; - uint8 primaryColour = mapElement->properties.scenery.colour_1 & 0x1F; - uint8 secondaryColour = mapElement->properties.scenery.colour_2 & 0x1F; + uint8 primaryColour = scenery_small_get_primary_colour(mapElement); + uint8 secondaryColour = scenery_small_get_secondary_colour(mapElement); track_design_save_pop_map_element(x, y, mapElement); track_design_save_pop_map_element_desc(entry, x, y, mapElement->base_height, flags, primaryColour, secondaryColour); diff --git a/src/openrct2/windows/top_toolbar.c b/src/openrct2/windows/top_toolbar.c index 8b01c10d86..bb75f79c09 100644 --- a/src/openrct2/windows/top_toolbar.c +++ b/src/openrct2/windows/top_toolbar.c @@ -1045,8 +1045,8 @@ static void scenery_eyedropper_tool_down(sint16 x, sint16 y, rct_widgetindex wid sint32 sceneryId = get_scenery_id_from_entry_index(OBJECT_TYPE_SMALL_SCENERY, entryIndex); if (sceneryId != -1 && window_scenery_set_selected_item(sceneryId)) { gWindowSceneryRotation = map_element_get_direction_with_offset(mapElement, get_current_rotation()); - gWindowSceneryPrimaryColour = mapElement->properties.scenery.colour_1 & 0x1F; - gWindowScenerySecondaryColour = mapElement->properties.scenery.colour_2 & 0x1F; + gWindowSceneryPrimaryColour = scenery_small_get_primary_colour(mapElement); + gWindowScenerySecondaryColour = scenery_small_get_secondary_colour(mapElement); gWindowSceneryEyedropperEnabled = false; } } diff --git a/src/openrct2/world/SmallScenery.cpp b/src/openrct2/world/SmallScenery.cpp index 8c45e56c92..1669088c7e 100644 --- a/src/openrct2/world/SmallScenery.cpp +++ b/src/openrct2/world/SmallScenery.cpp @@ -149,10 +149,9 @@ static money32 SmallScenerySetColour(sint16 x, sint16 y, sint8 baseHeight, uint8 if (flags & GAME_COMMAND_FLAG_APPLY) { - mapElement->properties.scenery.colour_1 &= 0xE0; - mapElement->properties.scenery.colour_1 |= primaryColour; - mapElement->properties.scenery.colour_2 &= 0xE0; - mapElement->properties.scenery.colour_2 |= secondaryColour; + scenery_small_set_primary_colour(mapElement, primaryColour); + scenery_small_set_secondary_colour(mapElement, secondaryColour); + map_invalidate_tile_full(x, y); } @@ -414,13 +413,13 @@ static money32 SmallSceneryPlace(sint16 x, newElement->type = type; newElement->properties.scenery.type = sceneryType; newElement->properties.scenery.age = 0; - newElement->properties.scenery.colour_1 = primaryColour; - newElement->properties.scenery.colour_2 = secondaryColour; + scenery_small_set_primary_colour(newElement, primaryColour); + scenery_small_set_secondary_colour(newElement, secondaryColour); newElement->clearance_height = newElement->base_height + ((sceneryEntry->small_scenery.height + 7) / 8); if (supportsRequired) { - newElement->properties.scenery.colour_1 |= 0x20; + scenery_small_set_supports_needed(newElement); } if (flags & GAME_COMMAND_FLAG_GHOST) diff --git a/src/openrct2/world/map.h b/src/openrct2/world/map.h index 3949c9181d..bac15d97ba 100644 --- a/src/openrct2/world/map.h +++ b/src/openrct2/world/map.h @@ -253,6 +253,11 @@ enum MAP_ELEM_TRACK_SEQUENCE_GREEN_LIGHT = (1 << 7), }; +enum +{ + MAP_ELEM_SMALL_SCENERY_COLOUR_FLAG_NEEDS_SUPPORTS = (1 << 5), +}; + #define MAP_ELEMENT_QUADRANT_MASK 0xC0 #define MAP_ELEMENT_TYPE_MASK 0x3C #define MAP_ELEMENT_DIRECTION_MASK 0x03 diff --git a/src/openrct2/world/mapgen.c b/src/openrct2/world/mapgen.c index c117c5f111..2846b99837 100644 --- a/src/openrct2/world/mapgen.c +++ b/src/openrct2/world/mapgen.c @@ -257,7 +257,7 @@ static void mapgen_place_tree(sint32 type, sint32 x, sint32 y) mapElement->type = MAP_ELEMENT_TYPE_SCENERY | (util_rand() & 3); mapElement->properties.scenery.type = type; mapElement->properties.scenery.age = 0; - mapElement->properties.scenery.colour_1 = COLOUR_YELLOW; + scenery_small_set_primary_colour(mapElement, COLOUR_YELLOW); } /** diff --git a/src/openrct2/world/scenery.c b/src/openrct2/world/scenery.c index 3210f814ec..5fb38f7108 100644 --- a/src/openrct2/world/scenery.c +++ b/src/openrct2/world/scenery.c @@ -317,3 +317,38 @@ sint32 get_scenery_id_from_entry_index(uint8 objectType, sint32 entryIndex) default: return -1; } } + +sint32 scenery_small_get_primary_colour(const rct_map_element *mapElement) +{ + return (mapElement->properties.scenery.colour_1 & 0x1F); +} + +sint32 scenery_small_get_secondary_colour(const rct_map_element *mapElement) +{ + return (mapElement->properties.scenery.colour_2 & 0x1F); +} + +void scenery_small_set_primary_colour(rct_map_element *mapElement, uint32 colour) +{ + assert(colour <= 31); + mapElement->properties.scenery.colour_1 &= ~0x1F; + mapElement->properties.scenery.colour_1 |= colour; + +} + +void scenery_small_set_secondary_colour(rct_map_element *mapElement, uint32 colour) +{ + assert(colour <= 31); + mapElement->properties.scenery.colour_2 &= ~0x1F; + mapElement->properties.scenery.colour_2 |= colour; +} + +bool scenery_small_get_supports_needed(const rct_map_element *mapElement) +{ + return (bool)(mapElement->properties.scenery.colour_1 & MAP_ELEM_SMALL_SCENERY_COLOUR_FLAG_NEEDS_SUPPORTS); +} + +void scenery_small_set_supports_needed(rct_map_element *mapElement) +{ + mapElement->properties.scenery.colour_1 |= MAP_ELEM_SMALL_SCENERY_COLOUR_FLAG_NEEDS_SUPPORTS; +} diff --git a/src/openrct2/world/scenery.h b/src/openrct2/world/scenery.h index c745b4b877..5a6dc6df03 100644 --- a/src/openrct2/world/scenery.h +++ b/src/openrct2/world/scenery.h @@ -295,4 +295,11 @@ rct_scenery_set_entry *get_scenery_group_entry(sint32 entryIndex); sint32 get_scenery_id_from_entry_index(uint8 objectType, sint32 entryIndex); +sint32 scenery_small_get_primary_colour(const rct_map_element *mapElement); +sint32 scenery_small_get_secondary_colour(const rct_map_element *mapElement); +void scenery_small_set_primary_colour(rct_map_element *mapElement, uint32 colour); +void scenery_small_set_secondary_colour(rct_map_element *mapElement, uint32 colour); +bool scenery_small_get_supports_needed(const rct_map_element *mapElement); +void scenery_small_set_supports_needed(rct_map_element *mapElement); + #endif