From 44cd8c3150821610fb10d56d5d17bb3270b105f4 Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Fri, 8 Feb 2019 08:55:46 +0000 Subject: [PATCH] Refactor. Add CoordsXY to data serialiser --- src/openrct2/actions/LandSetHeightAction.hpp | 36 ++++++++++---------- src/openrct2/core/DataSerialiserTraits.h | 22 ++++++++++++ 2 files changed, 40 insertions(+), 18 deletions(-) diff --git a/src/openrct2/actions/LandSetHeightAction.hpp b/src/openrct2/actions/LandSetHeightAction.hpp index 2bc0e40f77..47b7135ee5 100644 --- a/src/openrct2/actions/LandSetHeightAction.hpp +++ b/src/openrct2/actions/LandSetHeightAction.hpp @@ -23,23 +23,6 @@ #include "../world/Surface.h" #include "GameAction.h" -/** - * - * rct2: 0x00663CB9 - */ -static int32_t map_set_land_height_clear_func( - TileElement** tile_element, [[maybe_unused]] int32_t x, [[maybe_unused]] int32_t y, [[maybe_unused]] uint8_t flags, - [[maybe_unused]] money32* price) -{ - if ((*tile_element)->GetType() == TILE_ELEMENT_TYPE_SURFACE) - return 0; - - if ((*tile_element)->GetType() == TILE_ELEMENT_TYPE_SMALL_SCENERY) - return 0; - - return 1; -} - DEFINE_GAME_ACTION(LandSetHeightAction, GAME_COMMAND_SET_LAND_HEIGHT, GameActionResult) { private: @@ -67,7 +50,7 @@ public: { GameAction::Serialise(stream); - stream << DS_TAG(_coords.x) << DS_TAG(_coords.y) << DS_TAG(_height) << DS_TAG(_style); + stream << DS_TAG(_coords) << DS_TAG(_height) << DS_TAG(_style); } GameActionResult::Ptr Query() const override @@ -382,4 +365,21 @@ private: map_invalidate_tile_full(_coords.x, _coords.y); } + + /** + * + * rct2: 0x00663CB9 + */ + static int32_t map_set_land_height_clear_func( + TileElement * *tile_element, [[maybe_unused]] int32_t x, [[maybe_unused]] int32_t y, [[maybe_unused]] uint8_t flags, + [[maybe_unused]] money32 * price) + { + if ((*tile_element)->GetType() == TILE_ELEMENT_TYPE_SURFACE) + return 0; + + if ((*tile_element)->GetType() == TILE_ELEMENT_TYPE_SMALL_SCENERY) + return 0; + + return 1; + } }; diff --git a/src/openrct2/core/DataSerialiserTraits.h b/src/openrct2/core/DataSerialiserTraits.h index c496398259..67071f48cd 100644 --- a/src/openrct2/core/DataSerialiserTraits.h +++ b/src/openrct2/core/DataSerialiserTraits.h @@ -321,3 +321,25 @@ template<> struct DataSerializerTraits stream->Write(coords, strlen(coords)); } }; + +template<> struct DataSerializerTraits +{ + static void encode(IStream* stream, const CoordsXY& coords) + { + stream->WriteValue(ByteSwapBE(coords.x)); + stream->WriteValue(ByteSwapBE(coords.y)); + } + static void decode(IStream* stream, CoordsXY& coords) + { + auto x = ByteSwapBE(stream->ReadValue()); + auto y = ByteSwapBE(stream->ReadValue()); + coords = CoordsXY(x, y); + } + static void log(IStream* stream, const CoordsXY& coords) + { + char msg[128] = {}; + snprintf(msg, sizeof(msg), "CoordsXY(x = %d, y = %d)", coords.x, coords.y); + + stream->Write(msg, strlen(msg)); + } +};