From 83355e35cc02008566b8950b009dcc4366853aa5 Mon Sep 17 00:00:00 2001 From: Matt Date: Thu, 30 Jul 2020 23:01:22 +0200 Subject: [PATCH] Move IStream, MemoryStream, FileStream into OpenRCT2 namespace --- src/openrct2-ui/title/TitleSequencePlayer.cpp | 4 +- src/openrct2-ui/windows/TitleEditor.cpp | 2 +- src/openrct2/Cheats.cpp | 2 +- src/openrct2/Context.h | 5 +- src/openrct2/FileClassifier.cpp | 16 +- src/openrct2/FileClassifier.h | 7 +- src/openrct2/GameStateSnapshots.cpp | 4 +- src/openrct2/ParkImporter.h | 7 +- src/openrct2/ReplayManager.cpp | 10 +- src/openrct2/TrackImporter.h | 2 +- src/openrct2/audio/Audio.cpp | 2 +- src/openrct2/config/IniReader.cpp | 4 +- src/openrct2/config/IniReader.hpp | 8 +- src/openrct2/config/IniWriter.cpp | 6 +- src/openrct2/config/IniWriter.hpp | 8 +- src/openrct2/core/DataSerialiser.h | 9 +- src/openrct2/core/DataSerialiserTraits.h | 140 +++--- src/openrct2/core/File.cpp | 2 +- src/openrct2/core/FileIndex.hpp | 8 +- src/openrct2/core/FileStream.hpp | 8 +- src/openrct2/core/IStream.cpp | 72 +-- src/openrct2/core/IStream.hpp | 341 +++++++------- src/openrct2/core/Json.cpp | 4 +- src/openrct2/core/MemoryStream.cpp | 440 +++++++++--------- src/openrct2/core/MemoryStream.h | 172 +++---- src/openrct2/localisation/LanguagePack.cpp | 2 +- src/openrct2/network/NetworkBase.cpp | 2 +- src/openrct2/network/NetworkBase.h | 6 +- src/openrct2/network/NetworkKey.cpp | 8 +- src/openrct2/network/NetworkKey.h | 13 +- src/openrct2/object/BannerObject.cpp | 6 +- src/openrct2/object/BannerObject.h | 3 +- src/openrct2/object/EntranceObject.cpp | 4 +- src/openrct2/object/EntranceObject.h | 2 +- src/openrct2/object/FootpathItemObject.cpp | 6 +- src/openrct2/object/FootpathItemObject.h | 2 +- src/openrct2/object/FootpathObject.cpp | 6 +- src/openrct2/object/FootpathObject.h | 2 +- src/openrct2/object/ImageTable.cpp | 2 +- src/openrct2/object/ImageTable.h | 7 +- src/openrct2/object/LargeSceneryObject.cpp | 12 +- src/openrct2/object/LargeSceneryObject.h | 4 +- src/openrct2/object/Object.cpp | 2 +- src/openrct2/object/Object.h | 7 +- src/openrct2/object/ObjectFactory.cpp | 8 +- src/openrct2/object/ObjectRepository.cpp | 4 +- src/openrct2/object/ObjectRepository.h | 10 +- src/openrct2/object/RideObject.h | 5 +- src/openrct2/object/SceneryGroupObject.h | 4 +- src/openrct2/object/SmallSceneryObject.cpp | 8 +- src/openrct2/object/SmallSceneryObject.h | 4 +- src/openrct2/object/StringTable.cpp | 2 +- src/openrct2/object/StringTable.h | 7 +- src/openrct2/object/WallObject.cpp | 6 +- src/openrct2/object/WallObject.h | 2 +- src/openrct2/object/WaterObject.cpp | 4 +- src/openrct2/object/WaterObject.h | 2 +- src/openrct2/rct1/T4Importer.cpp | 6 +- src/openrct2/rct12/SawyerChunkReader.cpp | 4 +- src/openrct2/rct12/SawyerChunkReader.h | 9 +- src/openrct2/rct12/SawyerChunkWriter.cpp | 2 +- src/openrct2/rct12/SawyerChunkWriter.h | 9 +- src/openrct2/rct12/SawyerEncoding.cpp | 4 +- src/openrct2/rct12/SawyerEncoding.h | 9 +- src/openrct2/rct2/S6Exporter.cpp | 10 +- src/openrct2/rct2/S6Exporter.h | 12 +- src/openrct2/rct2/S6Importer.cpp | 6 +- src/openrct2/rct2/T6Exporter.cpp | 6 +- src/openrct2/rct2/T6Exporter.h | 7 +- src/openrct2/rct2/T6Importer.cpp | 6 +- src/openrct2/title/TitleSequence.cpp | 17 +- test/tests/IniReaderTest.cpp | 10 +- test/tests/IniWriterTest.cpp | 20 +- test/tests/sawyercoding_test.cpp | 4 +- 74 files changed, 828 insertions(+), 758 deletions(-) diff --git a/src/openrct2-ui/title/TitleSequencePlayer.cpp b/src/openrct2-ui/title/TitleSequencePlayer.cpp index e3a877fc3d..9d6608d568 100644 --- a/src/openrct2-ui/title/TitleSequencePlayer.cpp +++ b/src/openrct2-ui/title/TitleSequencePlayer.cpp @@ -280,7 +280,7 @@ private: TitleSequenceParkHandle* parkHandle = TitleSequenceGetParkHandle(_sequence, saveIndex); if (parkHandle != nullptr) { - loadSuccess = LoadParkFromStream(static_cast(parkHandle->Stream), parkHandle->HintPath); + loadSuccess = LoadParkFromStream(static_cast(parkHandle->Stream), parkHandle->HintPath); TitleSequenceCloseParkHandle(parkHandle); } if (!loadSuccess) @@ -389,7 +389,7 @@ private: * @param stream The stream to read the park data from. * @param hintPath Hint path, the extension is grabbed to determine what importer to use. */ - bool LoadParkFromStream(IStream* stream, const std::string& hintPath) + bool LoadParkFromStream(OpenRCT2::IStream* stream, const std::string& hintPath) { log_verbose("TitleSequencePlayer::LoadParkFromStream(%s)", hintPath.c_str()); bool success = false; diff --git a/src/openrct2-ui/windows/TitleEditor.cpp b/src/openrct2-ui/windows/TitleEditor.cpp index 8df1fff70e..b436999bdb 100644 --- a/src/openrct2-ui/windows/TitleEditor.cpp +++ b/src/openrct2-ui/windows/TitleEditor.cpp @@ -359,7 +359,7 @@ static void window_title_editor_mouseup(rct_window* w, rct_widgetindex widgetInd if (w->selected_list_item >= 0 && w->selected_list_item < static_cast(_editingTitleSequence->NumSaves)) { auto handle = TitleSequenceGetParkHandle(_editingTitleSequence, w->selected_list_item); - auto stream = static_cast(handle->Stream); + auto stream = static_cast(handle->Stream); auto hintPath = String::ToStd(handle->HintPath); bool isScenario = ParkImporter::ExtensionIsScenario(hintPath); try diff --git a/src/openrct2/Cheats.cpp b/src/openrct2/Cheats.cpp index 391986d427..b9e98e40c9 100644 --- a/src/openrct2/Cheats.cpp +++ b/src/openrct2/Cheats.cpp @@ -98,7 +98,7 @@ void CheatsSerialise(DataSerialiser& ds) if (ds.IsSaving()) { - IStream& stream = ds.GetStream(); + OpenRCT2::IStream& stream = ds.GetStream(); // Temporarily write 0, will be updated after every cheat is written. uint64_t countOffset = stream.GetPosition(); diff --git a/src/openrct2/Context.h b/src/openrct2/Context.h index 69d6ebe956..8c2659cb36 100644 --- a/src/openrct2/Context.h +++ b/src/openrct2/Context.h @@ -18,7 +18,10 @@ INTERFACE IObjectManager; INTERFACE IObjectRepository; INTERFACE IScenarioRepository; -INTERFACE IStream; +namespace OpenRCT2 +{ + INTERFACE IStream; +} INTERFACE ITrackDesignRepository; INTERFACE IGameStateSnapshots; diff --git a/src/openrct2/FileClassifier.cpp b/src/openrct2/FileClassifier.cpp index 3f838428e1..77fedaf7d2 100644 --- a/src/openrct2/FileClassifier.cpp +++ b/src/openrct2/FileClassifier.cpp @@ -16,15 +16,15 @@ #include "scenario/Scenario.h" #include "util/SawyerCoding.h" -static bool TryClassifyAsS6(IStream* stream, ClassifiedFileInfo* result); -static bool TryClassifyAsS4(IStream* stream, ClassifiedFileInfo* result); -static bool TryClassifyAsTD4_TD6(IStream* stream, ClassifiedFileInfo* result); +static bool TryClassifyAsS6(OpenRCT2::IStream* stream, ClassifiedFileInfo* result); +static bool TryClassifyAsS4(OpenRCT2::IStream* stream, ClassifiedFileInfo* result); +static bool TryClassifyAsTD4_TD6(OpenRCT2::IStream* stream, ClassifiedFileInfo* result); bool TryClassifyFile(const std::string& path, ClassifiedFileInfo* result) { try { - auto fs = FileStream(path, FILE_MODE_OPEN); + auto fs = OpenRCT2::FileStream(path, OpenRCT2::FILE_MODE_OPEN); return TryClassifyFile(&fs, result); } catch (const std::exception&) @@ -33,7 +33,7 @@ bool TryClassifyFile(const std::string& path, ClassifiedFileInfo* result) } } -bool TryClassifyFile(IStream* stream, ClassifiedFileInfo* result) +bool TryClassifyFile(OpenRCT2::IStream* stream, ClassifiedFileInfo* result) { // TODO Currently track designs get classified as SC4s because they use the // same checksum algorithm. The only way after to tell the difference @@ -61,7 +61,7 @@ bool TryClassifyFile(IStream* stream, ClassifiedFileInfo* result) return false; } -static bool TryClassifyAsS6(IStream* stream, ClassifiedFileInfo* result) +static bool TryClassifyAsS6(OpenRCT2::IStream* stream, ClassifiedFileInfo* result) { bool success = false; uint64_t originalPosition = stream->GetPosition(); @@ -89,7 +89,7 @@ static bool TryClassifyAsS6(IStream* stream, ClassifiedFileInfo* result) return success; } -static bool TryClassifyAsS4(IStream* stream, ClassifiedFileInfo* result) +static bool TryClassifyAsS4(OpenRCT2::IStream* stream, ClassifiedFileInfo* result) { bool success = false; uint64_t originalPosition = stream->GetPosition(); @@ -126,7 +126,7 @@ static bool TryClassifyAsS4(IStream* stream, ClassifiedFileInfo* result) return success; } -static bool TryClassifyAsTD4_TD6(IStream* stream, ClassifiedFileInfo* result) +static bool TryClassifyAsTD4_TD6(OpenRCT2::IStream* stream, ClassifiedFileInfo* result) { bool success = false; uint64_t originalPosition = stream->GetPosition(); diff --git a/src/openrct2/FileClassifier.h b/src/openrct2/FileClassifier.h index a164167836..c8736bb10b 100644 --- a/src/openrct2/FileClassifier.h +++ b/src/openrct2/FileClassifier.h @@ -25,7 +25,10 @@ enum #include -INTERFACE IStream; +namespace OpenRCT2 +{ + INTERFACE IStream; +} enum class FILE_TYPE { @@ -44,6 +47,6 @@ struct ClassifiedFileInfo #define FILE_TYPE_S4_CUTOFF 2 bool TryClassifyFile(const std::string& path, ClassifiedFileInfo* result); -bool TryClassifyFile(IStream* stream, ClassifiedFileInfo* result); +bool TryClassifyFile(OpenRCT2::IStream* stream, ClassifiedFileInfo* result); uint32_t get_file_extension_type(const utf8* path); diff --git a/src/openrct2/GameStateSnapshots.cpp b/src/openrct2/GameStateSnapshots.cpp index d8f3252dbd..7deae158c6 100644 --- a/src/openrct2/GameStateSnapshots.cpp +++ b/src/openrct2/GameStateSnapshots.cpp @@ -28,8 +28,8 @@ struct GameStateSnapshot_t uint32_t tick = InvalidTick; uint32_t srand0 = 0; - MemoryStream storedSprites; - MemoryStream parkParameters; + OpenRCT2::MemoryStream storedSprites; + OpenRCT2::MemoryStream parkParameters; // Must pass a function that can access the sprite. void SerialiseSprites(std::function getEntity, const size_t numSprites, bool saving) diff --git a/src/openrct2/ParkImporter.h b/src/openrct2/ParkImporter.h index b402325adb..6e5707d9b9 100644 --- a/src/openrct2/ParkImporter.h +++ b/src/openrct2/ParkImporter.h @@ -19,7 +19,10 @@ INTERFACE IObjectManager; INTERFACE IObjectRepository; -INTERFACE IStream; +namespace OpenRCT2 +{ + INTERFACE IStream; +} struct scenario_index_entry; struct ParkLoadResult final @@ -45,7 +48,7 @@ public: virtual ParkLoadResult LoadSavedGame(const utf8* path, bool skipObjectCheck = false) abstract; virtual ParkLoadResult LoadScenario(const utf8* path, bool skipObjectCheck = false) abstract; virtual ParkLoadResult LoadFromStream( - IStream * stream, bool isScenario, bool skipObjectCheck = false, const utf8* path = String::Empty) abstract; + OpenRCT2::IStream * stream, bool isScenario, bool skipObjectCheck = false, const utf8* path = String::Empty) abstract; virtual void Import() abstract; virtual bool GetDetails(scenario_index_entry * dst) abstract; diff --git a/src/openrct2/ReplayManager.cpp b/src/openrct2/ReplayManager.cpp index 9c1fc82c18..15945702c1 100644 --- a/src/openrct2/ReplayManager.cpp +++ b/src/openrct2/ReplayManager.cpp @@ -72,7 +72,7 @@ namespace OpenRCT2 uint32_t magic; uint16_t version; uint64_t uncompressedSize; - MemoryStream data; + OpenRCT2::MemoryStream data; }; struct ReplayRecordData @@ -80,9 +80,9 @@ namespace OpenRCT2 uint32_t magic; uint16_t version; std::string networkId; - MemoryStream parkData; - MemoryStream parkParams; - MemoryStream cheatData; + OpenRCT2::MemoryStream parkData; + OpenRCT2::MemoryStream parkParams; + OpenRCT2::MemoryStream cheatData; std::string name; // Name of play std::string filePath; // File path of replay. uint64_t timeRecorded; // Posix Time. @@ -91,7 +91,7 @@ namespace OpenRCT2 std::multiset commands; std::vector> checksums; uint32_t checksumIndex; - MemoryStream gameStateSnapshots; + OpenRCT2::MemoryStream gameStateSnapshots; }; class ReplayManager final : public IReplayManager diff --git a/src/openrct2/TrackImporter.h b/src/openrct2/TrackImporter.h index cbd6194fba..2ce9ef54a7 100644 --- a/src/openrct2/TrackImporter.h +++ b/src/openrct2/TrackImporter.h @@ -26,7 +26,7 @@ public: virtual ~ITrackImporter() = default; virtual bool Load(const utf8* path) abstract; - virtual bool LoadFromStream(IStream * stream) abstract; + virtual bool LoadFromStream(OpenRCT2::IStream * stream) abstract; virtual std::unique_ptr Import() abstract; }; diff --git a/src/openrct2/audio/Audio.cpp b/src/openrct2/audio/Audio.cpp index c0406ae397..dfab7f3d0f 100644 --- a/src/openrct2/audio/Audio.cpp +++ b/src/openrct2/audio/Audio.cpp @@ -341,7 +341,7 @@ void audio_init_ride_sounds_and_info() { try { - auto fs = FileStream(path, FILE_MODE_OPEN); + auto fs = OpenRCT2::FileStream(path, OpenRCT2::FILE_MODE_OPEN); uint32_t head = fs.ReadValue(); if (head == 0x78787878) { diff --git a/src/openrct2/config/IniReader.cpp b/src/openrct2/config/IniReader.cpp index a4c8f580a4..fd34c6f0c0 100644 --- a/src/openrct2/config/IniReader.cpp +++ b/src/openrct2/config/IniReader.cpp @@ -96,7 +96,7 @@ private: std::unordered_map _values; public: - explicit IniReader(IStream* stream) + explicit IniReader(OpenRCT2::IStream* stream) { uint64_t length = stream->GetLength() - stream->GetPosition(); _buffer.resize(length); @@ -437,7 +437,7 @@ utf8* IIniReader::GetCString(const std::string& name, const utf8* defaultValue) return String::Duplicate(szValue.c_str()); } -IIniReader* CreateIniReader(IStream* stream) +IIniReader* CreateIniReader(OpenRCT2::IStream* stream) { return new IniReader(stream); } diff --git a/src/openrct2/config/IniReader.hpp b/src/openrct2/config/IniReader.hpp index 2ae3c8c868..e65ec0a13c 100644 --- a/src/openrct2/config/IniReader.hpp +++ b/src/openrct2/config/IniReader.hpp @@ -13,7 +13,11 @@ #include -INTERFACE IStream; +namespace OpenRCT2 +{ + INTERFACE IStream; +} + template struct IConfigEnum; INTERFACE IIniReader @@ -43,5 +47,5 @@ INTERFACE IIniReader utf8* GetCString(const std::string& name, const utf8* defaultValue) const; }; -IIniReader* CreateIniReader(IStream* stream); +IIniReader* CreateIniReader(OpenRCT2::IStream* stream); IIniReader* CreateDefaultIniReader(); diff --git a/src/openrct2/config/IniWriter.cpp b/src/openrct2/config/IniWriter.cpp index 040cf9d62a..c649c2b947 100644 --- a/src/openrct2/config/IniWriter.cpp +++ b/src/openrct2/config/IniWriter.cpp @@ -18,11 +18,11 @@ class IniWriter final : public IIniWriter { private: - IStream* _stream; + OpenRCT2::IStream* _stream; bool _firstSection = true; public: - explicit IniWriter(IStream* stream) + explicit IniWriter(OpenRCT2::IStream* stream) : _stream(stream) { } @@ -103,7 +103,7 @@ void IIniWriter::WriteString(const std::string& name, const utf8* value) WriteString(name, String::ToStd(value)); } -IIniWriter* CreateIniWriter(IStream* stream) +IIniWriter* CreateIniWriter(OpenRCT2::IStream* stream) { return new IniWriter(stream); } diff --git a/src/openrct2/config/IniWriter.hpp b/src/openrct2/config/IniWriter.hpp index bf10adfbe3..54400fc954 100644 --- a/src/openrct2/config/IniWriter.hpp +++ b/src/openrct2/config/IniWriter.hpp @@ -13,7 +13,11 @@ #include -INTERFACE IStream; +namespace OpenRCT2 +{ + INTERFACE IStream; +} + template struct IConfigEnum; INTERFACE IIniWriter @@ -45,4 +49,4 @@ INTERFACE IIniWriter void WriteString(const std::string& name, const utf8* value); }; -IIniWriter* CreateIniWriter(IStream* stream); +IIniWriter* CreateIniWriter(OpenRCT2::IStream* stream); diff --git a/src/openrct2/core/DataSerialiser.h b/src/openrct2/core/DataSerialiser.h index ed8f04906f..95622961ae 100644 --- a/src/openrct2/core/DataSerialiser.h +++ b/src/openrct2/core/DataSerialiser.h @@ -10,14 +10,15 @@ #pragma once #include "DataSerialiserTraits.h" +#include "MemoryStream.h" #include class DataSerialiser { private: - MemoryStream _stream; - IStream& _activeStream; + OpenRCT2::MemoryStream _stream; + OpenRCT2::IStream& _activeStream; bool _isSaving = false; bool _isLogging = false; @@ -29,7 +30,7 @@ public: { } - DataSerialiser(bool isSaving, IStream& stream, bool isLogging = false) + DataSerialiser(bool isSaving, OpenRCT2::IStream& stream, bool isLogging = false) : _activeStream(stream) , _isSaving(isSaving) , _isLogging(isLogging) @@ -51,7 +52,7 @@ public: return _isLogging; } - IStream& GetStream() + OpenRCT2::IStream& GetStream() { return _activeStream; } diff --git a/src/openrct2/core/DataSerialiserTraits.h b/src/openrct2/core/DataSerialiserTraits.h index 81c76465ce..e3a175183c 100644 --- a/src/openrct2/core/DataSerialiserTraits.h +++ b/src/openrct2/core/DataSerialiserTraits.h @@ -30,25 +30,25 @@ template struct DataSerializerTraits { - static void encode(IStream* stream, const T& v) = delete; - static void decode(IStream* stream, T& val) = delete; - static void log(IStream* stream, const T& val) = delete; + static void encode(OpenRCT2::IStream* stream, const T& v) = delete; + static void decode(OpenRCT2::IStream* stream, T& val) = delete; + static void log(OpenRCT2::IStream* stream, const T& val) = delete; }; template struct DataSerializerTraitsIntegral { - static void encode(IStream* stream, const T& val) + static void encode(OpenRCT2::IStream* stream, const T& val) { T temp = ByteSwapBE(val); stream->Write(&temp); } - static void decode(IStream* stream, T& val) + static void decode(OpenRCT2::IStream* stream, T& val) { T temp; stream->Read(&temp); val = ByteSwapBE(temp); } - static void log(IStream* stream, const T& val) + static void log(OpenRCT2::IStream* stream, const T& val) { std::stringstream ss; ss << std::hex << std::setw(sizeof(T) * 2) << std::setfill('0') << +val; @@ -60,15 +60,15 @@ template struct DataSerializerTraitsIntegral template<> struct DataSerializerTraits { - static void encode(IStream* stream, const bool& val) + static void encode(OpenRCT2::IStream* stream, const bool& val) { stream->Write(&val); } - static void decode(IStream* stream, bool& val) + static void decode(OpenRCT2::IStream* stream, bool& val) { stream->Read(&val); } - static void log(IStream* stream, const bool& val) + static void log(OpenRCT2::IStream* stream, const bool& val) { if (val) stream->Write("true", 4); @@ -111,14 +111,14 @@ template<> struct DataSerializerTraits : public DataSerializerTraitsInt template<> struct DataSerializerTraits { - static void encode(IStream* stream, const std::string& str) + static void encode(OpenRCT2::IStream* stream, const std::string& str) { uint16_t len = static_cast(str.size()); uint16_t swapped = ByteSwapBE(len); stream->Write(&swapped); stream->WriteArray(str.c_str(), len); } - static void decode(IStream* stream, std::string& res) + static void decode(OpenRCT2::IStream* stream, std::string& res) { uint16_t len; stream->Read(&len); @@ -129,7 +129,7 @@ template<> struct DataSerializerTraits Memory::FreeArray(str, len); } - static void log(IStream* stream, const std::string& str) + static void log(OpenRCT2::IStream* stream, const std::string& str) { stream->Write("\"", 1); stream->Write(str.data(), str.size()); @@ -139,19 +139,19 @@ template<> struct DataSerializerTraits template<> struct DataSerializerTraits { - static void encode(IStream* stream, const NetworkPlayerId_t& val) + static void encode(OpenRCT2::IStream* stream, const NetworkPlayerId_t& val) { uint32_t temp = static_cast(val.id); temp = ByteSwapBE(temp); stream->Write(&temp); } - static void decode(IStream* stream, NetworkPlayerId_t& val) + static void decode(OpenRCT2::IStream* stream, NetworkPlayerId_t& val) { uint32_t temp; stream->Read(&temp); val.id = static_cast(ByteSwapBE(temp)); } - static void log(IStream* stream, const NetworkPlayerId_t& val) + static void log(OpenRCT2::IStream* stream, const NetworkPlayerId_t& val) { char playerId[28] = {}; snprintf(playerId, sizeof(playerId), "%u", val.id); @@ -174,19 +174,19 @@ template<> struct DataSerializerTraits template<> struct DataSerializerTraits { - static void encode(IStream* stream, const NetworkRideId_t& val) + static void encode(OpenRCT2::IStream* stream, const NetworkRideId_t& val) { uint32_t temp = static_cast(val.id); temp = ByteSwapBE(temp); stream->Write(&temp); } - static void decode(IStream* stream, NetworkRideId_t& val) + static void decode(OpenRCT2::IStream* stream, NetworkRideId_t& val) { uint32_t temp; stream->Read(&temp); val.id = static_cast(ByteSwapBE(temp)); } - static void log(IStream* stream, const NetworkRideId_t& val) + static void log(OpenRCT2::IStream* stream, const NetworkRideId_t& val) { char rideId[28] = {}; snprintf(rideId, sizeof(rideId), "%u", val.id); @@ -207,17 +207,17 @@ template<> struct DataSerializerTraits template struct DataSerializerTraits> { - static void encode(IStream* stream, const DataSerialiserTag& tag) + static void encode(OpenRCT2::IStream* stream, const DataSerialiserTag& tag) { DataSerializerTraits s; s.encode(stream, tag.Data()); } - static void decode(IStream* stream, DataSerialiserTag& tag) + static void decode(OpenRCT2::IStream* stream, DataSerialiserTag& tag) { DataSerializerTraits s; s.decode(stream, tag.Data()); } - static void log(IStream* stream, const DataSerialiserTag& tag) + static void log(OpenRCT2::IStream* stream, const DataSerialiserTag& tag) { const char* name = tag.Name(); stream->Write(name, strlen(name)); @@ -230,16 +230,16 @@ template struct DataSerializerTraits> } }; -template<> struct DataSerializerTraits +template<> struct DataSerializerTraits { - static void encode(IStream* stream, const MemoryStream& val) + static void encode(OpenRCT2::IStream* stream, const OpenRCT2::MemoryStream& val) { DataSerializerTraits s; s.encode(stream, val.GetLength()); stream->Write(val.GetData(), val.GetLength()); } - static void decode(IStream* stream, MemoryStream& val) + static void decode(OpenRCT2::IStream* stream, OpenRCT2::MemoryStream& val) { DataSerializerTraits s; @@ -251,14 +251,14 @@ template<> struct DataSerializerTraits val.Write(buf.get(), length); } - static void log(IStream* stream, const MemoryStream& tag) + static void log(OpenRCT2::IStream* stream, const OpenRCT2::MemoryStream& tag) { } }; template struct DataSerializerTraitsPODArray { - static void encode(IStream* stream, const _Ty (&val)[_Size]) + static void encode(OpenRCT2::IStream* stream, const _Ty (&val)[_Size]) { uint16_t len = static_cast(_Size); uint16_t swapped = ByteSwapBE(len); @@ -270,7 +270,7 @@ template struct DataSerializerTraitsPODArray s.encode(stream, sub); } } - static void decode(IStream* stream, _Ty (&val)[_Size]) + static void decode(OpenRCT2::IStream* stream, _Ty (&val)[_Size]) { uint16_t len; stream->Read(&len); @@ -285,7 +285,7 @@ template struct DataSerializerTraitsPODArray s.decode(stream, sub); } } - static void log(IStream* stream, const _Ty (&val)[_Size]) + static void log(OpenRCT2::IStream* stream, const _Ty (&val)[_Size]) { stream->Write("{", 1); DataSerializerTraits<_Ty> s; @@ -316,7 +316,7 @@ template struct DataSerializerTraits : public Dat template struct DataSerializerTraits> { - static void encode(IStream* stream, const std::array<_Ty, _Size>& val) + static void encode(OpenRCT2::IStream* stream, const std::array<_Ty, _Size>& val) { uint16_t len = static_cast(_Size); uint16_t swapped = ByteSwapBE(len); @@ -328,7 +328,7 @@ template struct DataSerializerTraits& val) + static void decode(OpenRCT2::IStream* stream, std::array<_Ty, _Size>& val) { uint16_t len; stream->Read(&len); @@ -343,7 +343,7 @@ template struct DataSerializerTraits& val) + static void log(OpenRCT2::IStream* stream, const std::array<_Ty, _Size>& val) { stream->Write("{", 1); DataSerializerTraits<_Ty> s; @@ -358,7 +358,7 @@ template struct DataSerializerTraits struct DataSerializerTraits> { - static void encode(IStream* stream, const std::vector<_Ty>& val) + static void encode(OpenRCT2::IStream* stream, const std::vector<_Ty>& val) { uint16_t len = static_cast(val.size()); uint16_t swapped = ByteSwapBE(len); @@ -370,7 +370,7 @@ template struct DataSerializerTraits> s.encode(stream, sub); } } - static void decode(IStream* stream, std::vector<_Ty>& val) + static void decode(OpenRCT2::IStream* stream, std::vector<_Ty>& val) { uint16_t len; stream->Read(&len); @@ -384,7 +384,7 @@ template struct DataSerializerTraits> val.push_back(sub); } } - static void log(IStream* stream, const std::vector<_Ty>& val) + static void log(OpenRCT2::IStream* stream, const std::vector<_Ty>& val) { stream->Write("{", 1); DataSerializerTraits<_Ty> s; @@ -399,14 +399,14 @@ template struct DataSerializerTraits> template<> struct DataSerializerTraits { - static void encode(IStream* stream, const MapRange& v) + static void encode(OpenRCT2::IStream* stream, const MapRange& v) { stream->WriteValue(ByteSwapBE(v.GetLeft())); stream->WriteValue(ByteSwapBE(v.GetTop())); stream->WriteValue(ByteSwapBE(v.GetRight())); stream->WriteValue(ByteSwapBE(v.GetBottom())); } - static void decode(IStream* stream, MapRange& v) + static void decode(OpenRCT2::IStream* stream, MapRange& v) { auto l = ByteSwapBE(stream->ReadValue()); auto t = ByteSwapBE(stream->ReadValue()); @@ -414,7 +414,7 @@ template<> struct DataSerializerTraits auto b = ByteSwapBE(stream->ReadValue()); v = MapRange(l, t, r, b); } - static void log(IStream* stream, const MapRange& v) + static void log(OpenRCT2::IStream* stream, const MapRange& v) { char coords[128] = {}; snprintf( @@ -427,7 +427,7 @@ template<> struct DataSerializerTraits template<> struct DataSerializerTraits { - static void encode(IStream* stream, const TileElement& tileElement) + static void encode(OpenRCT2::IStream* stream, const TileElement& tileElement) { stream->WriteValue(tileElement.type); stream->WriteValue(tileElement.Flags); @@ -442,7 +442,7 @@ template<> struct DataSerializerTraits stream->WriteValue(tileElement.pad_08[i]); } } - static void decode(IStream* stream, TileElement& tileElement) + static void decode(OpenRCT2::IStream* stream, TileElement& tileElement) { tileElement.type = stream->ReadValue(); tileElement.Flags = stream->ReadValue(); @@ -457,7 +457,7 @@ template<> struct DataSerializerTraits tileElement.pad_08[i] = stream->ReadValue(); } } - static void log(IStream* stream, const TileElement& tileElement) + static void log(OpenRCT2::IStream* stream, const TileElement& tileElement) { char msg[128] = {}; snprintf( @@ -469,18 +469,18 @@ template<> struct DataSerializerTraits template<> struct DataSerializerTraits { - static void encode(IStream* stream, const CoordsXY& coords) + static void encode(OpenRCT2::IStream* stream, const CoordsXY& coords) { stream->WriteValue(ByteSwapBE(coords.x)); stream->WriteValue(ByteSwapBE(coords.y)); } - static void decode(IStream* stream, CoordsXY& coords) + static void decode(OpenRCT2::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) + static void log(OpenRCT2::IStream* stream, const CoordsXY& coords) { char msg[128] = {}; snprintf(msg, sizeof(msg), "CoordsXY(x = %d, y = %d)", coords.x, coords.y); @@ -490,14 +490,14 @@ template<> struct DataSerializerTraits template<> struct DataSerializerTraits { - static void encode(IStream* stream, const CoordsXYZ& coord) + static void encode(OpenRCT2::IStream* stream, const CoordsXYZ& coord) { stream->WriteValue(ByteSwapBE(coord.x)); stream->WriteValue(ByteSwapBE(coord.y)); stream->WriteValue(ByteSwapBE(coord.z)); } - static void decode(IStream* stream, CoordsXYZ& coord) + static void decode(OpenRCT2::IStream* stream, CoordsXYZ& coord) { auto x = ByteSwapBE(stream->ReadValue()); auto y = ByteSwapBE(stream->ReadValue()); @@ -505,7 +505,7 @@ template<> struct DataSerializerTraits coord = CoordsXYZ{ x, y, z }; } - static void log(IStream* stream, const CoordsXYZ& coord) + static void log(OpenRCT2::IStream* stream, const CoordsXYZ& coord) { char msg[128] = {}; snprintf(msg, sizeof(msg), "CoordsXYZ(x = %d, y = %d, z = %d)", coord.x, coord.y, coord.z); @@ -515,7 +515,7 @@ template<> struct DataSerializerTraits template<> struct DataSerializerTraits { - static void encode(IStream* stream, const CoordsXYZD& coord) + static void encode(OpenRCT2::IStream* stream, const CoordsXYZD& coord) { stream->WriteValue(ByteSwapBE(coord.x)); stream->WriteValue(ByteSwapBE(coord.y)); @@ -523,7 +523,7 @@ template<> struct DataSerializerTraits stream->WriteValue(ByteSwapBE(coord.direction)); } - static void decode(IStream* stream, CoordsXYZD& coord) + static void decode(OpenRCT2::IStream* stream, CoordsXYZD& coord) { auto x = ByteSwapBE(stream->ReadValue()); auto y = ByteSwapBE(stream->ReadValue()); @@ -532,7 +532,7 @@ template<> struct DataSerializerTraits coord = CoordsXYZD{ x, y, z, d }; } - static void log(IStream* stream, const CoordsXYZD& coord) + static void log(OpenRCT2::IStream* stream, const CoordsXYZD& coord) { char msg[128] = {}; snprintf( @@ -543,18 +543,18 @@ template<> struct DataSerializerTraits template<> struct DataSerializerTraits { - static void encode(IStream* stream, const NetworkCheatType_t& val) + static void encode(OpenRCT2::IStream* stream, const NetworkCheatType_t& val) { uint32_t temp = ByteSwapBE(val.id); stream->Write(&temp); } - static void decode(IStream* stream, NetworkCheatType_t& val) + static void decode(OpenRCT2::IStream* stream, NetworkCheatType_t& val) { uint32_t temp; stream->Read(&temp); val.id = ByteSwapBE(temp); } - static void log(IStream* stream, const NetworkCheatType_t& val) + static void log(OpenRCT2::IStream* stream, const NetworkCheatType_t& val) { const char* cheatName = CheatsGetName(static_cast(val.id)); stream->Write(cheatName, strlen(cheatName)); @@ -563,13 +563,13 @@ template<> struct DataSerializerTraits template<> struct DataSerializerTraits { - static void encode(IStream* stream, const rct_object_entry& val) + static void encode(OpenRCT2::IStream* stream, const rct_object_entry& val) { uint32_t temp = ByteSwapBE(val.flags); stream->Write(&temp); stream->WriteArray(val.nameWOC, 12); } - static void decode(IStream* stream, rct_object_entry& val) + static void decode(OpenRCT2::IStream* stream, rct_object_entry& val) { uint32_t temp; stream->Read(&temp); @@ -577,7 +577,7 @@ template<> struct DataSerializerTraits const char* str = stream->ReadArray(12); memcpy(val.nameWOC, str, 12); } - static void log(IStream* stream, const rct_object_entry& val) + static void log(OpenRCT2::IStream* stream, const rct_object_entry& val) { stream->WriteArray(val.name, 8); } @@ -585,17 +585,17 @@ template<> struct DataSerializerTraits template<> struct DataSerializerTraits { - static void encode(IStream* stream, const TrackDesignTrackElement& val) + static void encode(OpenRCT2::IStream* stream, const TrackDesignTrackElement& val) { stream->Write(&val.flags); stream->Write(&val.type); } - static void decode(IStream* stream, TrackDesignTrackElement& val) + static void decode(OpenRCT2::IStream* stream, TrackDesignTrackElement& val) { stream->Read(&val.flags); stream->Read(&val.type); } - static void log(IStream* stream, const TrackDesignTrackElement& val) + static void log(OpenRCT2::IStream* stream, const TrackDesignTrackElement& val) { char msg[128] = {}; snprintf(msg, sizeof(msg), "TrackDesignTrackElement(type = %d, flags = %d)", val.type, val.flags); @@ -605,18 +605,18 @@ template<> struct DataSerializerTraits template<> struct DataSerializerTraits { - static void encode(IStream* stream, const TrackDesignMazeElement& val) + static void encode(OpenRCT2::IStream* stream, const TrackDesignMazeElement& val) { uint32_t temp = ByteSwapBE(val.all); stream->Write(&temp); } - static void decode(IStream* stream, TrackDesignMazeElement& val) + static void decode(OpenRCT2::IStream* stream, TrackDesignMazeElement& val) { uint32_t temp; stream->Read(&temp); val.all = ByteSwapBE(temp); } - static void log(IStream* stream, const TrackDesignMazeElement& val) + static void log(OpenRCT2::IStream* stream, const TrackDesignMazeElement& val) { char msg[128] = {}; snprintf(msg, sizeof(msg), "TrackDesignMazeElement(all = %d)", val.all); @@ -626,7 +626,7 @@ template<> struct DataSerializerTraits template<> struct DataSerializerTraits { - static void encode(IStream* stream, const TrackDesignEntranceElement& val) + static void encode(OpenRCT2::IStream* stream, const TrackDesignEntranceElement& val) { stream->Write(&val.x); stream->Write(&val.y); @@ -634,7 +634,7 @@ template<> struct DataSerializerTraits stream->Write(&val.direction); stream->Write(&val.isExit); } - static void decode(IStream* stream, TrackDesignEntranceElement& val) + static void decode(OpenRCT2::IStream* stream, TrackDesignEntranceElement& val) { stream->Read(&val.x); stream->Read(&val.y); @@ -642,7 +642,7 @@ template<> struct DataSerializerTraits stream->Read(&val.direction); stream->Read(&val.isExit); } - static void log(IStream* stream, const TrackDesignEntranceElement& val) + static void log(OpenRCT2::IStream* stream, const TrackDesignEntranceElement& val) { char msg[128] = {}; snprintf( @@ -654,7 +654,7 @@ template<> struct DataSerializerTraits template<> struct DataSerializerTraits { - static void encode(IStream* stream, const TrackDesignSceneryElement& val) + static void encode(OpenRCT2::IStream* stream, const TrackDesignSceneryElement& val) { stream->Write(&val.x); stream->Write(&val.y); @@ -665,7 +665,7 @@ template<> struct DataSerializerTraits DataSerializerTraits s; s.encode(stream, val.scenery_object); } - static void decode(IStream* stream, TrackDesignSceneryElement& val) + static void decode(OpenRCT2::IStream* stream, TrackDesignSceneryElement& val) { stream->Read(&val.x); stream->Read(&val.y); @@ -676,7 +676,7 @@ template<> struct DataSerializerTraits DataSerializerTraits s; s.decode(stream, val.scenery_object); } - static void log(IStream* stream, const TrackDesignSceneryElement& val) + static void log(OpenRCT2::IStream* stream, const TrackDesignSceneryElement& val) { char msg[128] = {}; snprintf( @@ -689,17 +689,17 @@ template<> struct DataSerializerTraits template<> struct DataSerializerTraits { - static void encode(IStream* stream, const rct_vehicle_colour& val) + static void encode(OpenRCT2::IStream* stream, const rct_vehicle_colour& val) { stream->Write(&val.body_colour); stream->Write(&val.trim_colour); } - static void decode(IStream* stream, rct_vehicle_colour& val) + static void decode(OpenRCT2::IStream* stream, rct_vehicle_colour& val) { stream->Read(&val.body_colour); stream->Read(&val.trim_colour); } - static void log(IStream* stream, const rct_vehicle_colour& val) + static void log(OpenRCT2::IStream* stream, const rct_vehicle_colour& val) { char msg[128] = {}; snprintf(msg, sizeof(msg), "rct_vehicle_colour(body_colour = %d, trim_colour = %d)", val.body_colour, val.trim_colour); diff --git a/src/openrct2/core/File.cpp b/src/openrct2/core/File.cpp index 0c6c908792..7143b671ea 100644 --- a/src/openrct2/core/File.cpp +++ b/src/openrct2/core/File.cpp @@ -87,7 +87,7 @@ namespace File void WriteAllBytes(const std::string& path, const void* buffer, size_t length) { - auto fs = FileStream(path, FILE_MODE_WRITE); + auto fs = OpenRCT2::FileStream(path, OpenRCT2::FILE_MODE_WRITE); fs.Write(buffer, length); } diff --git a/src/openrct2/core/FileIndex.hpp b/src/openrct2/core/FileIndex.hpp index 3fce108bbd..6456304fef 100644 --- a/src/openrct2/core/FileIndex.hpp +++ b/src/openrct2/core/FileIndex.hpp @@ -132,12 +132,12 @@ protected: /** * Serialises an index item to the given stream. */ - virtual void Serialise(IStream* stream, const TItem& item) const abstract; + virtual void Serialise(OpenRCT2::IStream* stream, const TItem& item) const abstract; /** * Deserialises an index item from the given stream. */ - virtual TItem Deserialise(IStream* stream) const abstract; + virtual TItem Deserialise(OpenRCT2::IStream* stream) const abstract; private: ScanResult Scan() const @@ -261,7 +261,7 @@ private: try { log_verbose("FileIndex:Loading index: '%s'", _indexPath.c_str()); - auto fs = FileStream(_indexPath, FILE_MODE_OPEN); + auto fs = OpenRCT2::FileStream(_indexPath, OpenRCT2::FILE_MODE_OPEN); // Read header, check if we need to re-scan auto header = fs.ReadValue(); @@ -300,7 +300,7 @@ private: { log_verbose("FileIndex:Writing index: '%s'", _indexPath.c_str()); Path::CreateDirectory(Path::GetDirectory(_indexPath)); - auto fs = FileStream(_indexPath, FILE_MODE_WRITE); + auto fs = OpenRCT2::FileStream(_indexPath, OpenRCT2::FILE_MODE_WRITE); // Write header FileIndexHeader header; diff --git a/src/openrct2/core/FileStream.hpp b/src/openrct2/core/FileStream.hpp index d5144f87eb..c683f84401 100644 --- a/src/openrct2/core/FileStream.hpp +++ b/src/openrct2/core/FileStream.hpp @@ -147,17 +147,17 @@ namespace OpenRCT2 Seek(position, STREAM_SEEK_BEGIN); } - void Seek(int64_t offset, IStream::SeekType origin) override + void Seek(int64_t offset, int32_t origin) override { switch (origin) { - case IStream::SeekType.STREAM_SEEK_BEGIN: + case STREAM_SEEK_BEGIN: fseeko(_file, offset, SEEK_SET); break; - case IStream::SeekType.STREAM_SEEK_CURRENT: + case STREAM_SEEK_CURRENT: fseeko(_file, offset, SEEK_CUR); break; - case IStream::SeekType.STREAM_SEEK_END: + case STREAM_SEEK_END: fseeko(_file, offset, SEEK_END); break; } diff --git a/src/openrct2/core/IStream.cpp b/src/openrct2/core/IStream.cpp index 92d88a9637..85dace3ecb 100644 --- a/src/openrct2/core/IStream.cpp +++ b/src/openrct2/core/IStream.cpp @@ -14,47 +14,51 @@ #include -utf8* IStream::ReadString() +namespace OpenRCT2 { - std::vector result; - - uint8_t ch; - while ((ch = ReadValue()) != 0) + utf8* IStream::ReadString() { - result.push_back(ch); + std::vector result; + + uint8_t ch; + while ((ch = ReadValue()) != 0) + { + result.push_back(ch); + } + result.push_back(0); + + utf8* resultString = Memory::AllocateArray(result.size()); + std::copy(result.begin(), result.end(), resultString); + return resultString; } - result.push_back(0); - utf8* resultString = Memory::AllocateArray(result.size()); - std::copy(result.begin(), result.end(), resultString); - return resultString; -} - -std::string IStream::ReadStdString() -{ - std::string result; - uint8_t ch; - while ((ch = ReadValue()) != 0) + std::string IStream::ReadStdString() { - result.push_back(ch); + std::string result; + uint8_t ch; + while ((ch = ReadValue()) != 0) + { + result.push_back(ch); + } + return result; } - return result; -} -void IStream::WriteString(const utf8* str) -{ - if (str == nullptr) + void IStream::WriteString(const utf8* str) { - WriteValue(0); + if (str == nullptr) + { + WriteValue(0); + } + else + { + size_t numBytes = String::SizeOf(str) + 1; + Write(str, numBytes); + } } - else - { - size_t numBytes = String::SizeOf(str) + 1; - Write(str, numBytes); - } -} -void IStream::WriteString(const std::string& str) -{ - WriteString(str.c_str()); -} + void IStream::WriteString(const std::string& str) + { + WriteString(str.c_str()); + } + +} // namespace OpenRCT2 diff --git a/src/openrct2/core/IStream.hpp b/src/openrct2/core/IStream.hpp index 1de313842a..87a7859fb7 100644 --- a/src/openrct2/core/IStream.hpp +++ b/src/openrct2/core/IStream.hpp @@ -17,193 +17,198 @@ #include #include -enum -{ - STREAM_SEEK_BEGIN, - STREAM_SEEK_CURRENT, - STREAM_SEEK_END -}; - #ifdef __WARN_SUGGEST_FINAL_METHODS__ # pragma GCC diagnostic push # pragma GCC diagnostic ignored "-Wsuggest-final-methods" # pragma GCC diagnostic ignored "-Wsuggest-final-types" #endif -/** - * Represents a stream that can be read or written to. Implemented by types such as FileStream, NetworkStream or MemoryStream. - */ -interface IStream +namespace OpenRCT2 { - /////////////////////////////////////////////////////////////////////////// - // Interface methods - /////////////////////////////////////////////////////////////////////////// - virtual ~IStream() + enum { - } - - virtual bool CanRead() const abstract; - virtual bool CanWrite() const abstract; - - virtual uint64_t GetLength() const abstract; - virtual uint64_t GetPosition() const abstract; - virtual void SetPosition(uint64_t position) abstract; - virtual void Seek(int64_t offset, int32_t origin) abstract; - - virtual void Read(void* buffer, uint64_t length) abstract; - virtual void Write(const void* buffer, uint64_t length) abstract; - - virtual uint64_t TryRead(void* buffer, uint64_t length) abstract; - - virtual const void* GetData() const abstract; - - /////////////////////////////////////////////////////////////////////////// - // Fast path methods, class can override them to use specialised copies. - /////////////////////////////////////////////////////////////////////////// - virtual void Read1(void* buffer) - { - Read(buffer, 1); - } - virtual void Read2(void* buffer) - { - Read(buffer, 2); - } - virtual void Read4(void* buffer) - { - Read(buffer, 4); - } - virtual void Read8(void* buffer) - { - Read(buffer, 8); - } - virtual void Read16(void* buffer) - { - Read(buffer, 16); - } - - virtual void Write1(const void* buffer) - { - Write(buffer, 1); - } - virtual void Write2(const void* buffer) - { - Write(buffer, 2); - } - virtual void Write4(const void* buffer) - { - Write(buffer, 4); - } - virtual void Write8(const void* buffer) - { - Write(buffer, 8); - } - virtual void Write16(const void* buffer) - { - Write(buffer, 16); - } - - /////////////////////////////////////////////////////////////////////////// - // Helper methods - /////////////////////////////////////////////////////////////////////////// - /** - * Reads the size of the given type from the stream directly into the given address. - */ - template void Read(T * value) - { - // Selects the best path at compile time - if constexpr (sizeof(T) == 1) - { - Read1(value); - } - else if constexpr (sizeof(T) == 2) - { - Read2(value); - } - else if constexpr (sizeof(T) == 4) - { - Read4(value); - } - else if constexpr (sizeof(T) == 8) - { - Read8(value); - } - else if constexpr (sizeof(T) == 16) - { - Read16(value); - } - else - { - Read(value, sizeof(T)); - } - } + STREAM_SEEK_BEGIN, + STREAM_SEEK_CURRENT, + STREAM_SEEK_END + }; /** - * Writes the size of the given type to the stream directly from the given address. + * Represents a stream that can be read or written to. Implemented by types such as FileStream, NetworkStream or + * MemoryStream. */ - template void Write(const T* value) + INTERFACE IStream { - // Selects the best path at compile time - if constexpr (sizeof(T) == 1) + /////////////////////////////////////////////////////////////////////////// + // Interface methods + /////////////////////////////////////////////////////////////////////////// + virtual ~IStream() { - Write1(value); } - else if constexpr (sizeof(T) == 2) - { - Write2(value); - } - else if constexpr (sizeof(T) == 4) - { - Write4(value); - } - else if constexpr (sizeof(T) == 8) - { - Write8(value); - } - else if constexpr (sizeof(T) == 16) - { - Write16(value); - } - else - { - Write(value, sizeof(T)); - } - } - /** - * Reads the given type from the stream. Use this only for small types (e.g. int8_t, int64_t, double) - */ - template T ReadValue() - { - T buffer; - Read(&buffer); - return buffer; - } + virtual bool CanRead() const abstract; + virtual bool CanWrite() const abstract; - /** - * Writes the given type to the stream. Use this only for small types (e.g. int8_t, int64_t, double) - */ - template void WriteValue(const T value) - { - Write(&value); - } + virtual uint64_t GetLength() const abstract; + virtual uint64_t GetPosition() const abstract; + virtual void SetPosition(uint64_t position) abstract; + virtual void Seek(int64_t offset, int32_t origin) abstract; - template T* ReadArray(size_t count) - { - T* buffer = Memory::AllocateArray(count); - Read(buffer, sizeof(T) * count); - return buffer; - } + virtual void Read(void* buffer, uint64_t length) abstract; + virtual void Write(const void* buffer, uint64_t length) abstract; - template void WriteArray(T * buffer, size_t count) - { - Write(buffer, sizeof(T) * count); - } + virtual uint64_t TryRead(void* buffer, uint64_t length) abstract; - utf8* ReadString(); - std::string ReadStdString(); - void WriteString(const utf8* str); - void WriteString(const std::string& string); -}; + virtual const void* GetData() const abstract; + + /////////////////////////////////////////////////////////////////////////// + // Fast path methods, class can override them to use specialised copies. + /////////////////////////////////////////////////////////////////////////// + virtual void Read1(void* buffer) + { + Read(buffer, 1); + } + virtual void Read2(void* buffer) + { + Read(buffer, 2); + } + virtual void Read4(void* buffer) + { + Read(buffer, 4); + } + virtual void Read8(void* buffer) + { + Read(buffer, 8); + } + virtual void Read16(void* buffer) + { + Read(buffer, 16); + } + + virtual void Write1(const void* buffer) + { + Write(buffer, 1); + } + virtual void Write2(const void* buffer) + { + Write(buffer, 2); + } + virtual void Write4(const void* buffer) + { + Write(buffer, 4); + } + virtual void Write8(const void* buffer) + { + Write(buffer, 8); + } + virtual void Write16(const void* buffer) + { + Write(buffer, 16); + } + + /////////////////////////////////////////////////////////////////////////// + // Helper methods + /////////////////////////////////////////////////////////////////////////// + /** + * Reads the size of the given type from the stream directly into the given address. + */ + template void Read(T * value) + { + // Selects the best path at compile time + if constexpr (sizeof(T) == 1) + { + Read1(value); + } + else if constexpr (sizeof(T) == 2) + { + Read2(value); + } + else if constexpr (sizeof(T) == 4) + { + Read4(value); + } + else if constexpr (sizeof(T) == 8) + { + Read8(value); + } + else if constexpr (sizeof(T) == 16) + { + Read16(value); + } + else + { + Read(value, sizeof(T)); + } + } + + /** + * Writes the size of the given type to the stream directly from the given address. + */ + template void Write(const T* value) + { + // Selects the best path at compile time + if constexpr (sizeof(T) == 1) + { + Write1(value); + } + else if constexpr (sizeof(T) == 2) + { + Write2(value); + } + else if constexpr (sizeof(T) == 4) + { + Write4(value); + } + else if constexpr (sizeof(T) == 8) + { + Write8(value); + } + else if constexpr (sizeof(T) == 16) + { + Write16(value); + } + else + { + Write(value, sizeof(T)); + } + } + + /** + * Reads the given type from the stream. Use this only for small types (e.g. int8_t, int64_t, double) + */ + template T ReadValue() + { + T buffer; + Read(&buffer); + return buffer; + } + + /** + * Writes the given type to the stream. Use this only for small types (e.g. int8_t, int64_t, double) + */ + template void WriteValue(const T value) + { + Write(&value); + } + + template T* ReadArray(size_t count) + { + T* buffer = Memory::AllocateArray(count); + Read(buffer, sizeof(T) * count); + return buffer; + } + + template void WriteArray(T * buffer, size_t count) + { + Write(buffer, sizeof(T) * count); + } + + utf8* ReadString(); + std::string ReadStdString(); + void WriteString(const utf8* str); + void WriteString(const std::string& string); + }; + +} // namespace OpenRCT2 #ifdef __WARN_SUGGEST_FINAL_METHODS__ # pragma GCC diagnostic pop diff --git a/src/openrct2/core/Json.cpp b/src/openrct2/core/Json.cpp index d556704294..e996d9e420 100644 --- a/src/openrct2/core/Json.cpp +++ b/src/openrct2/core/Json.cpp @@ -18,7 +18,7 @@ namespace Json json_t* ReadFromFile(const utf8* path, size_t maxSize) { json_t* json = nullptr; - auto fs = FileStream(path, FILE_MODE_OPEN); + auto fs = OpenRCT2::FileStream(path, OpenRCT2::FILE_MODE_OPEN); size_t fileLength = static_cast(fs.GetLength()); if (fileLength > maxSize) @@ -48,7 +48,7 @@ namespace Json const char* jsonOutput = json_dumps(json, flags); // Write to file - auto fs = FileStream(path, FILE_MODE_WRITE); + auto fs = OpenRCT2::FileStream(path, OpenRCT2::FILE_MODE_WRITE); size_t jsonOutputSize = String::SizeOf(jsonOutput); fs.Write(jsonOutput, jsonOutputSize); } diff --git a/src/openrct2/core/MemoryStream.cpp b/src/openrct2/core/MemoryStream.cpp index 24f282f22e..326e1232a6 100644 --- a/src/openrct2/core/MemoryStream.cpp +++ b/src/openrct2/core/MemoryStream.cpp @@ -14,243 +14,247 @@ #include #include -MemoryStream::MemoryStream(const MemoryStream& copy) +namespace OpenRCT2 { - _access = copy._access; - _dataCapacity = copy._dataCapacity; - _dataSize = copy._dataSize; - - if (_access & MEMORY_ACCESS::OWNER) + MemoryStream::MemoryStream(const MemoryStream& copy) { - _data = Memory::Allocate(_dataCapacity); - std::memcpy(_data, copy._data, _dataCapacity); - _position = reinterpret_cast(reinterpret_cast(_data) + copy.GetPosition()); - } -} + _access = copy._access; + _dataCapacity = copy._dataCapacity; + _dataSize = copy._dataSize; -MemoryStream::MemoryStream(size_t capacity) -{ - _dataCapacity = capacity; - _data = Memory::Allocate(capacity); - _position = _data; -} - -MemoryStream::MemoryStream(void* data, size_t dataSize, uint8_t access) -{ - _access = access; - _dataCapacity = dataSize; - _dataSize = dataSize; - _data = data; - _position = _data; -} - -MemoryStream::MemoryStream(const void* data, size_t dataSize) - : MemoryStream(const_cast(data), dataSize, MEMORY_ACCESS::READ) -{ -} - -MemoryStream::MemoryStream(MemoryStream&& mv) noexcept -{ - *this = std::move(mv); -} - -MemoryStream::~MemoryStream() -{ - if (_access & MEMORY_ACCESS::OWNER) - { - Memory::Free(_data); - } - _dataCapacity = 0; - _dataSize = 0; - _data = nullptr; -} - -MemoryStream& MemoryStream::operator=(MemoryStream&& mv) noexcept -{ - _access = mv._access; - _dataCapacity = mv._dataCapacity; - _data = mv._data; - _position = mv._position; - - mv._data = nullptr; - mv._position = nullptr; - mv._dataCapacity = 0; - mv._dataSize = 0; - - return *this; -} - -const void* MemoryStream::GetData() const -{ - return _data; -} - -void* MemoryStream::GetDataCopy() const -{ - auto result = Memory::Allocate(_dataSize); - std::memcpy(result, _data, _dataSize); - return result; -} - -void* MemoryStream::TakeData() -{ - _access &= ~MEMORY_ACCESS::OWNER; - return _data; -} - -bool MemoryStream::CanRead() const -{ - return (_access & MEMORY_ACCESS::READ) != 0; -} - -bool MemoryStream::CanWrite() const -{ - return (_access & MEMORY_ACCESS::WRITE) != 0; -} - -uint64_t MemoryStream::GetLength() const -{ - return _dataSize; -} - -uint64_t MemoryStream::GetPosition() const -{ - return static_cast(reinterpret_cast(_position) - reinterpret_cast(_data)); -} - -void MemoryStream::SetPosition(uint64_t position) -{ - Seek(position, STREAM_SEEK_BEGIN); -} - -void MemoryStream::Seek(int64_t offset, int32_t origin) -{ - uint64_t newPosition; - switch (origin) - { - default: - case STREAM_SEEK_BEGIN: - newPosition = offset; - break; - case STREAM_SEEK_CURRENT: - newPosition = GetPosition() + offset; - break; - case STREAM_SEEK_END: - newPosition = _dataSize + offset; - break; + if (_access & MEMORY_ACCESS::OWNER) + { + _data = Memory::Allocate(_dataCapacity); + std::memcpy(_data, copy._data, _dataCapacity); + _position = reinterpret_cast(reinterpret_cast(_data) + copy.GetPosition()); + } } - if (newPosition > _dataSize) + MemoryStream::MemoryStream(size_t capacity) { - throw IOException("New position out of bounds."); - } - _position = reinterpret_cast(reinterpret_cast(_data) + static_cast(newPosition)); -} - -void MemoryStream::Read(void* buffer, uint64_t length) -{ - uint64_t position = GetPosition(); - if (position + length > _dataSize) - { - throw IOException("Attempted to read past end of stream."); + _dataCapacity = capacity; + _data = Memory::Allocate(capacity); + _position = _data; } - std::memcpy(buffer, _position, length); - _position = reinterpret_cast(reinterpret_cast(_position) + length); -} + MemoryStream::MemoryStream(void* data, size_t dataSize, uint8_t access) + { + _access = access; + _dataCapacity = dataSize; + _dataSize = dataSize; + _data = data; + _position = _data; + } -void MemoryStream::Read1(void* buffer) -{ - Read<1>(buffer); -} + MemoryStream::MemoryStream(const void* data, size_t dataSize) + : MemoryStream(const_cast(data), dataSize, MEMORY_ACCESS::READ) + { + } -void MemoryStream::Read2(void* buffer) -{ - Read<2>(buffer); -} + MemoryStream::MemoryStream(MemoryStream&& mv) noexcept + { + *this = std::move(mv); + } -void MemoryStream::Read4(void* buffer) -{ - Read<4>(buffer); -} - -void MemoryStream::Read8(void* buffer) -{ - Read<8>(buffer); -} - -void MemoryStream::Read16(void* buffer) -{ - Read<16>(buffer); -} - -uint64_t MemoryStream::TryRead(void* buffer, uint64_t length) -{ - uint64_t remainingBytes = GetLength() - GetPosition(); - uint64_t bytesToRead = std::min(length, remainingBytes); - Read(buffer, bytesToRead); - return bytesToRead; -} - -void MemoryStream::Write(const void* buffer, uint64_t length) -{ - uint64_t position = GetPosition(); - uint64_t nextPosition = position + length; - if (nextPosition > _dataCapacity) + MemoryStream::~MemoryStream() { if (_access & MEMORY_ACCESS::OWNER) { - EnsureCapacity(static_cast(nextPosition)); - } - else - { - throw IOException("Attempted to write past end of stream."); + Memory::Free(_data); } + _dataCapacity = 0; + _dataSize = 0; + _data = nullptr; } - std::memcpy(_position, buffer, length); - _position = reinterpret_cast(reinterpret_cast(_position) + length); - _dataSize = std::max(_dataSize, static_cast(nextPosition)); -} - -void MemoryStream::Write1(const void* buffer) -{ - Write<1>(buffer); -} - -void MemoryStream::Write2(const void* buffer) -{ - Write<2>(buffer); -} - -void MemoryStream::Write4(const void* buffer) -{ - Write<4>(buffer); -} - -void MemoryStream::Write8(const void* buffer) -{ - Write<8>(buffer); -} - -void MemoryStream::Write16(const void* buffer) -{ - Write<16>(buffer); -} - -void MemoryStream::EnsureCapacity(size_t capacity) -{ - if (_dataCapacity < capacity) + MemoryStream& MemoryStream::operator=(MemoryStream&& mv) noexcept { - size_t newCapacity = std::max(8, _dataCapacity); - while (newCapacity < capacity) + _access = mv._access; + _dataCapacity = mv._dataCapacity; + _data = mv._data; + _position = mv._position; + + mv._data = nullptr; + mv._position = nullptr; + mv._dataCapacity = 0; + mv._dataSize = 0; + + return *this; + } + + const void* MemoryStream::GetData() const + { + return _data; + } + + void* MemoryStream::GetDataCopy() const + { + auto result = Memory::Allocate(_dataSize); + std::memcpy(result, _data, _dataSize); + return result; + } + + void* MemoryStream::TakeData() + { + _access &= ~MEMORY_ACCESS::OWNER; + return _data; + } + + bool MemoryStream::CanRead() const + { + return (_access & MEMORY_ACCESS::READ) != 0; + } + + bool MemoryStream::CanWrite() const + { + return (_access & MEMORY_ACCESS::WRITE) != 0; + } + + uint64_t MemoryStream::GetLength() const + { + return _dataSize; + } + + uint64_t MemoryStream::GetPosition() const + { + return static_cast(reinterpret_cast(_position) - reinterpret_cast(_data)); + } + + void MemoryStream::SetPosition(uint64_t position) + { + Seek(position, STREAM_SEEK_BEGIN); + } + + void MemoryStream::Seek(int64_t offset, int32_t origin) + { + uint64_t newPosition; + switch (origin) { - newCapacity *= 2; + default: + case STREAM_SEEK_BEGIN: + newPosition = offset; + break; + case STREAM_SEEK_CURRENT: + newPosition = GetPosition() + offset; + break; + case STREAM_SEEK_END: + newPosition = _dataSize + offset; + break; } - uint64_t position = GetPosition(); - _dataCapacity = newCapacity; - _data = Memory::Reallocate(_data, _dataCapacity); - _position = reinterpret_cast(reinterpret_cast(_data) + static_cast(position)); + if (newPosition > _dataSize) + { + throw IOException("New position out of bounds."); + } + _position = reinterpret_cast(reinterpret_cast(_data) + static_cast(newPosition)); } -} + + void MemoryStream::Read(void* buffer, uint64_t length) + { + uint64_t position = GetPosition(); + if (position + length > _dataSize) + { + throw IOException("Attempted to read past end of stream."); + } + + std::memcpy(buffer, _position, length); + _position = reinterpret_cast(reinterpret_cast(_position) + length); + } + + void MemoryStream::Read1(void* buffer) + { + Read<1>(buffer); + } + + void MemoryStream::Read2(void* buffer) + { + Read<2>(buffer); + } + + void MemoryStream::Read4(void* buffer) + { + Read<4>(buffer); + } + + void MemoryStream::Read8(void* buffer) + { + Read<8>(buffer); + } + + void MemoryStream::Read16(void* buffer) + { + Read<16>(buffer); + } + + uint64_t MemoryStream::TryRead(void* buffer, uint64_t length) + { + uint64_t remainingBytes = GetLength() - GetPosition(); + uint64_t bytesToRead = std::min(length, remainingBytes); + Read(buffer, bytesToRead); + return bytesToRead; + } + + void MemoryStream::Write(const void* buffer, uint64_t length) + { + uint64_t position = GetPosition(); + uint64_t nextPosition = position + length; + if (nextPosition > _dataCapacity) + { + if (_access & MEMORY_ACCESS::OWNER) + { + EnsureCapacity(static_cast(nextPosition)); + } + else + { + throw IOException("Attempted to write past end of stream."); + } + } + + std::memcpy(_position, buffer, length); + _position = reinterpret_cast(reinterpret_cast(_position) + length); + _dataSize = std::max(_dataSize, static_cast(nextPosition)); + } + + void MemoryStream::Write1(const void* buffer) + { + Write<1>(buffer); + } + + void MemoryStream::Write2(const void* buffer) + { + Write<2>(buffer); + } + + void MemoryStream::Write4(const void* buffer) + { + Write<4>(buffer); + } + + void MemoryStream::Write8(const void* buffer) + { + Write<8>(buffer); + } + + void MemoryStream::Write16(const void* buffer) + { + Write<16>(buffer); + } + + void MemoryStream::EnsureCapacity(size_t capacity) + { + if (_dataCapacity < capacity) + { + size_t newCapacity = std::max(8, _dataCapacity); + while (newCapacity < capacity) + { + newCapacity *= 2; + } + + uint64_t position = GetPosition(); + _dataCapacity = newCapacity; + _data = Memory::Reallocate(_data, _dataCapacity); + _position = reinterpret_cast(reinterpret_cast(_data) + static_cast(position)); + } + } + +} // namespace OpenRCT2 diff --git a/src/openrct2/core/MemoryStream.h b/src/openrct2/core/MemoryStream.h index 2fffaa38f8..0f34e973d9 100644 --- a/src/openrct2/core/MemoryStream.h +++ b/src/openrct2/core/MemoryStream.h @@ -14,100 +14,104 @@ #include -namespace MEMORY_ACCESS +namespace OpenRCT2 { - constexpr uint8_t READ = 1 << 0; - constexpr uint8_t WRITE = 1 << 1; - constexpr uint8_t OWNER = 1 << 2; -}; // namespace MEMORY_ACCESS - -/** - * A stream for reading and writing to a buffer in memory. By default this buffer can grow. - */ -class MemoryStream final : public IStream -{ -private: - uint8_t _access = MEMORY_ACCESS::READ | MEMORY_ACCESS::WRITE | MEMORY_ACCESS::OWNER; - size_t _dataCapacity = 0; - size_t _dataSize = 0; - void* _data = nullptr; - void* _position = nullptr; - -public: - MemoryStream() = default; - MemoryStream(const MemoryStream& copy); - MemoryStream(MemoryStream&& mv) noexcept; - explicit MemoryStream(size_t capacity); - MemoryStream(void* data, size_t dataSize, uint8_t access = MEMORY_ACCESS::READ); - MemoryStream(const void* data, size_t dataSize); - virtual ~MemoryStream(); - - MemoryStream& operator=(MemoryStream&& mv) noexcept; - - const void* GetData() const override; - void* GetDataCopy() const; - void* TakeData(); - - /////////////////////////////////////////////////////////////////////////// - // ISteam methods - /////////////////////////////////////////////////////////////////////////// - bool CanRead() const override; - bool CanWrite() const override; - - uint64_t GetLength() const override; - uint64_t GetPosition() const override; - void SetPosition(uint64_t position) override; - void Seek(int64_t offset, int32_t origin) override; - - void Read(void* buffer, uint64_t length) override; - void Read1(void* buffer) override; - void Read2(void* buffer) override; - void Read4(void* buffer) override; - void Read8(void* buffer) override; - void Read16(void* buffer) override; - - template void Read(void* buffer) + namespace MEMORY_ACCESS { - uint64_t position = GetPosition(); - if (position + N > _dataSize) + constexpr uint8_t READ = 1 << 0; + constexpr uint8_t WRITE = 1 << 1; + constexpr uint8_t OWNER = 1 << 2; + }; // namespace MEMORY_ACCESS + + /** + * A stream for reading and writing to a buffer in memory. By default this buffer can grow. + */ + class MemoryStream final : public IStream + { + private: + uint8_t _access = MEMORY_ACCESS::READ | MEMORY_ACCESS::WRITE | MEMORY_ACCESS::OWNER; + size_t _dataCapacity = 0; + size_t _dataSize = 0; + void* _data = nullptr; + void* _position = nullptr; + + public: + MemoryStream() = default; + MemoryStream(const MemoryStream& copy); + MemoryStream(MemoryStream&& mv) noexcept; + explicit MemoryStream(size_t capacity); + MemoryStream(void* data, size_t dataSize, uint8_t access = MEMORY_ACCESS::READ); + MemoryStream(const void* data, size_t dataSize); + virtual ~MemoryStream(); + + MemoryStream& operator=(MemoryStream&& mv) noexcept; + + const void* GetData() const override; + void* GetDataCopy() const; + void* TakeData(); + + /////////////////////////////////////////////////////////////////////////// + // ISteam methods + /////////////////////////////////////////////////////////////////////////// + bool CanRead() const override; + bool CanWrite() const override; + + uint64_t GetLength() const override; + uint64_t GetPosition() const override; + void SetPosition(uint64_t position) override; + void Seek(int64_t offset, int32_t origin) override; + + void Read(void* buffer, uint64_t length) override; + void Read1(void* buffer) override; + void Read2(void* buffer) override; + void Read4(void* buffer) override; + void Read8(void* buffer) override; + void Read16(void* buffer) override; + + template void Read(void* buffer) { - throw IOException("Attempted to read past end of stream."); + uint64_t position = GetPosition(); + if (position + N > _dataSize) + { + throw IOException("Attempted to read past end of stream."); + } + + std::memcpy(buffer, _position, N); + _position = reinterpret_cast(reinterpret_cast(_position) + N); } - std::memcpy(buffer, _position, N); - _position = reinterpret_cast(reinterpret_cast(_position) + N); - } + void Write(const void* buffer, uint64_t length) override; + void Write1(const void* buffer) override; + void Write2(const void* buffer) override; + void Write4(const void* buffer) override; + void Write8(const void* buffer) override; + void Write16(const void* buffer) override; - void Write(const void* buffer, uint64_t length) override; - void Write1(const void* buffer) override; - void Write2(const void* buffer) override; - void Write4(const void* buffer) override; - void Write8(const void* buffer) override; - void Write16(const void* buffer) override; - - template void Write(const void* buffer) - { - uint64_t position = GetPosition(); - uint64_t nextPosition = position + N; - if (nextPosition > _dataCapacity) + template void Write(const void* buffer) { - if (_access & MEMORY_ACCESS::OWNER) + uint64_t position = GetPosition(); + uint64_t nextPosition = position + N; + if (nextPosition > _dataCapacity) { - EnsureCapacity(static_cast(nextPosition)); - } - else - { - throw IOException("Attempted to write past end of stream."); + if (_access & MEMORY_ACCESS::OWNER) + { + EnsureCapacity(static_cast(nextPosition)); + } + else + { + throw IOException("Attempted to write past end of stream."); + } } + + std::memcpy(_position, buffer, N); + _position = reinterpret_cast(reinterpret_cast(_position) + N); + _dataSize = std::max(_dataSize, static_cast(nextPosition)); } - std::memcpy(_position, buffer, N); - _position = reinterpret_cast(reinterpret_cast(_position) + N); - _dataSize = std::max(_dataSize, static_cast(nextPosition)); - } + uint64_t TryRead(void* buffer, uint64_t length) override; - uint64_t TryRead(void* buffer, uint64_t length) override; + private: + void EnsureCapacity(size_t capacity); + }; -private: - void EnsureCapacity(size_t capacity); -}; +} // namespace OpenRCT2 diff --git a/src/openrct2/localisation/LanguagePack.cpp b/src/openrct2/localisation/LanguagePack.cpp index ec6e758d1e..1d0de908c0 100644 --- a/src/openrct2/localisation/LanguagePack.cpp +++ b/src/openrct2/localisation/LanguagePack.cpp @@ -77,7 +77,7 @@ public: utf8* fileData = nullptr; try { - FileStream fs = FileStream(path, FILE_MODE_OPEN); + OpenRCT2::FileStream fs = OpenRCT2::FileStream(path, OpenRCT2::FILE_MODE_OPEN); size_t fileLength = static_cast(fs.GetLength()); if (fileLength > MAX_LANGUAGE_SIZE) diff --git a/src/openrct2/network/NetworkBase.cpp b/src/openrct2/network/NetworkBase.cpp index c2973b8cf0..4ce1664ecb 100644 --- a/src/openrct2/network/NetworkBase.cpp +++ b/src/openrct2/network/NetworkBase.cpp @@ -1430,7 +1430,7 @@ uint8_t* NetworkBase::save_for_network(size_t& out_size, const std::vector& connection); void UpdateServer(); void ServerClientDisconnected(std::unique_ptr& connection); - bool SaveMap(IStream* stream, const std::vector& objects) const; + bool SaveMap(OpenRCT2::IStream* stream, const std::vector& objects) const; uint8_t* save_for_network(size_t& out_size, const std::vector& objects) const; std::string MakePlayerNameUnique(const std::string& name); @@ -120,7 +120,7 @@ public: // Client bool IsDesynchronised(); NetworkServerState_t GetServerState() const; void ServerClientDisconnected(); - bool LoadMap(IStream* stream); + bool LoadMap(OpenRCT2::IStream* stream); void UpdateClient(); // Packet dispatchers. @@ -218,7 +218,7 @@ private: // Client Data std::string _chatLogPath; std::string _chatLogFilenameFormat = "%Y%m%d-%H%M%S.txt"; std::string _password; - MemoryStream _serverGameState; + OpenRCT2::MemoryStream _serverGameState; NetworkServerState_t _serverState; uint32_t _lastSentHeartbeat = 0; uint32_t last_ping_sent_time = 0; diff --git a/src/openrct2/network/NetworkKey.cpp b/src/openrct2/network/NetworkKey.cpp index 45ba0de798..42d123004d 100644 --- a/src/openrct2/network/NetworkKey.cpp +++ b/src/openrct2/network/NetworkKey.cpp @@ -44,7 +44,7 @@ bool NetworkKey::Generate() } } -bool NetworkKey::LoadPrivate(IStream* stream) +bool NetworkKey::LoadPrivate(OpenRCT2::IStream* stream) { Guard::ArgumentNotNull(stream); @@ -76,7 +76,7 @@ bool NetworkKey::LoadPrivate(IStream* stream) } } -bool NetworkKey::LoadPublic(IStream* stream) +bool NetworkKey::LoadPublic(OpenRCT2::IStream* stream) { Guard::ArgumentNotNull(stream); @@ -108,7 +108,7 @@ bool NetworkKey::LoadPublic(IStream* stream) } } -bool NetworkKey::SavePrivate(IStream* stream) +bool NetworkKey::SavePrivate(OpenRCT2::IStream* stream) { try { @@ -127,7 +127,7 @@ bool NetworkKey::SavePrivate(IStream* stream) } } -bool NetworkKey::SavePublic(IStream* stream) +bool NetworkKey::SavePublic(OpenRCT2::IStream* stream) { try { diff --git a/src/openrct2/network/NetworkKey.h b/src/openrct2/network/NetworkKey.h index d8a584b3de..337f1ee58f 100644 --- a/src/openrct2/network/NetworkKey.h +++ b/src/openrct2/network/NetworkKey.h @@ -18,7 +18,10 @@ # include # include -INTERFACE IStream; +namespace OpenRCT2 +{ + INTERFACE IStream; +} namespace Crypt { @@ -31,10 +34,10 @@ public: NetworkKey(); ~NetworkKey(); bool Generate(); - bool LoadPrivate(IStream* stream); - bool LoadPublic(IStream* stream); - bool SavePrivate(IStream* stream); - bool SavePublic(IStream* stream); + bool LoadPrivate(OpenRCT2::IStream* stream); + bool LoadPublic(OpenRCT2::IStream* stream); + bool SavePrivate(OpenRCT2::IStream* stream); + bool SavePublic(OpenRCT2::IStream* stream); std::string PublicKeyString(); std::string PublicKeyHash(); void Unload(); diff --git a/src/openrct2/object/BannerObject.cpp b/src/openrct2/object/BannerObject.cpp index 7997ab19ce..8290694441 100644 --- a/src/openrct2/object/BannerObject.cpp +++ b/src/openrct2/object/BannerObject.cpp @@ -17,14 +17,14 @@ #include "ObjectJsonHelpers.h" #include "ObjectList.h" -void BannerObject::ReadLegacy(IReadObjectContext* context, IStream* stream) +void BannerObject::ReadLegacy(IReadObjectContext* context, OpenRCT2::IStream* stream) { - stream->Seek(6, STREAM_SEEK_CURRENT); + stream->Seek(6, OpenRCT2::STREAM_SEEK_CURRENT); _legacyType.banner.scrolling_mode = stream->ReadValue(); _legacyType.banner.flags = stream->ReadValue(); _legacyType.banner.price = stream->ReadValue(); _legacyType.banner.scenery_tab_id = OBJECT_ENTRY_INDEX_NULL; - stream->Seek(2, STREAM_SEEK_CURRENT); + stream->Seek(2, OpenRCT2::STREAM_SEEK_CURRENT); GetStringTable().Read(context, stream, OBJ_STRING_ID_NAME); diff --git a/src/openrct2/object/BannerObject.h b/src/openrct2/object/BannerObject.h index 9396aefc01..ea8ad00418 100644 --- a/src/openrct2/object/BannerObject.h +++ b/src/openrct2/object/BannerObject.h @@ -9,6 +9,7 @@ #pragma once +#include "../core/IStream.hpp" #include "../world/Scenery.h" #include "SceneryObject.h" @@ -28,7 +29,7 @@ public: return &_legacyType; } - void ReadLegacy(IReadObjectContext* context, IStream* stream) override; + void ReadLegacy(IReadObjectContext* context, OpenRCT2::IStream* stream) override; void ReadJson(IReadObjectContext* context, const json_t* root) override; void Load() override; void Unload() override; diff --git a/src/openrct2/object/EntranceObject.cpp b/src/openrct2/object/EntranceObject.cpp index 8e04f90e81..c5c82244e6 100644 --- a/src/openrct2/object/EntranceObject.cpp +++ b/src/openrct2/object/EntranceObject.cpp @@ -15,9 +15,9 @@ #include "../localisation/Localisation.h" #include "ObjectJsonHelpers.h" -void EntranceObject::ReadLegacy(IReadObjectContext* context, IStream* stream) +void EntranceObject::ReadLegacy(IReadObjectContext* context, OpenRCT2::IStream* stream) { - stream->Seek(6, STREAM_SEEK_CURRENT); + stream->Seek(6, OpenRCT2::STREAM_SEEK_CURRENT); _legacyType.scrolling_mode = stream->ReadValue(); _legacyType.text_height = stream->ReadValue(); diff --git a/src/openrct2/object/EntranceObject.h b/src/openrct2/object/EntranceObject.h index 149d0f7a8f..4a9c48dda1 100644 --- a/src/openrct2/object/EntranceObject.h +++ b/src/openrct2/object/EntranceObject.h @@ -28,7 +28,7 @@ public: return &_legacyType; } - void ReadLegacy(IReadObjectContext* context, IStream* stream) override; + void ReadLegacy(IReadObjectContext* context, OpenRCT2::IStream* stream) override; void ReadJson(IReadObjectContext* context, const json_t* root) override; void Load() override; void Unload() override; diff --git a/src/openrct2/object/FootpathItemObject.cpp b/src/openrct2/object/FootpathItemObject.cpp index 15c6280eca..65dc72ac0e 100644 --- a/src/openrct2/object/FootpathItemObject.cpp +++ b/src/openrct2/object/FootpathItemObject.cpp @@ -20,15 +20,15 @@ #include -void FootpathItemObject::ReadLegacy(IReadObjectContext* context, IStream* stream) +void FootpathItemObject::ReadLegacy(IReadObjectContext* context, OpenRCT2::IStream* stream) { - stream->Seek(6, STREAM_SEEK_CURRENT); + stream->Seek(6, OpenRCT2::STREAM_SEEK_CURRENT); _legacyType.path_bit.flags = stream->ReadValue(); _legacyType.path_bit.draw_type = stream->ReadValue(); _legacyType.path_bit.tool_id = stream->ReadValue(); _legacyType.path_bit.price = stream->ReadValue(); _legacyType.path_bit.scenery_tab_id = OBJECT_ENTRY_INDEX_NULL; - stream->Seek(2, STREAM_SEEK_CURRENT); + stream->Seek(2, OpenRCT2::STREAM_SEEK_CURRENT); GetStringTable().Read(context, stream, OBJ_STRING_ID_NAME); diff --git a/src/openrct2/object/FootpathItemObject.h b/src/openrct2/object/FootpathItemObject.h index 253ee86857..4e6be3eb6c 100644 --- a/src/openrct2/object/FootpathItemObject.h +++ b/src/openrct2/object/FootpathItemObject.h @@ -28,7 +28,7 @@ public: return &_legacyType; } - void ReadLegacy(IReadObjectContext* context, IStream* stream) override; + void ReadLegacy(IReadObjectContext* context, OpenRCT2::IStream* stream) override; void ReadJson(IReadObjectContext* context, const json_t* root) override; void Load() override; void Unload() override; diff --git a/src/openrct2/object/FootpathObject.cpp b/src/openrct2/object/FootpathObject.cpp index f2cfe28152..8cc976e4ad 100644 --- a/src/openrct2/object/FootpathObject.cpp +++ b/src/openrct2/object/FootpathObject.cpp @@ -15,13 +15,13 @@ #include "../world/Footpath.h" #include "ObjectJsonHelpers.h" -void FootpathObject::ReadLegacy(IReadObjectContext* context, IStream* stream) +void FootpathObject::ReadLegacy(IReadObjectContext* context, OpenRCT2::IStream* stream) { - stream->Seek(10, STREAM_SEEK_CURRENT); + stream->Seek(10, OpenRCT2::STREAM_SEEK_CURRENT); _legacyType.support_type = static_cast(stream->ReadValue()); _legacyType.flags = stream->ReadValue(); _legacyType.scrolling_mode = stream->ReadValue(); - stream->Seek(1, STREAM_SEEK_CURRENT); + stream->Seek(1, OpenRCT2::STREAM_SEEK_CURRENT); GetStringTable().Read(context, stream, OBJ_STRING_ID_NAME); GetImageTable().Read(context, stream); diff --git a/src/openrct2/object/FootpathObject.h b/src/openrct2/object/FootpathObject.h index d91fa206df..88766b2abe 100644 --- a/src/openrct2/object/FootpathObject.h +++ b/src/openrct2/object/FootpathObject.h @@ -46,7 +46,7 @@ public: return &_pathRailingsEntry; } - void ReadLegacy(IReadObjectContext* context, IStream* stream) override; + void ReadLegacy(IReadObjectContext* context, OpenRCT2::IStream* stream) override; void ReadJson(IReadObjectContext* context, const json_t* root) override; void Load() override; void Unload() override; diff --git a/src/openrct2/object/ImageTable.cpp b/src/openrct2/object/ImageTable.cpp index 3b2c4c6379..0deabc25df 100644 --- a/src/openrct2/object/ImageTable.cpp +++ b/src/openrct2/object/ImageTable.cpp @@ -28,7 +28,7 @@ ImageTable::~ImageTable() } } -void ImageTable::Read(IReadObjectContext* context, IStream* stream) +void ImageTable::Read(IReadObjectContext* context, OpenRCT2::IStream* stream) { if (gOpenRCT2NoGraphics) { diff --git a/src/openrct2/object/ImageTable.h b/src/openrct2/object/ImageTable.h index 7e4f55b6fc..2279698719 100644 --- a/src/openrct2/object/ImageTable.h +++ b/src/openrct2/object/ImageTable.h @@ -16,7 +16,10 @@ #include INTERFACE IReadObjectContext; -INTERFACE IStream; +namespace OpenRCT2 +{ + INTERFACE IStream; +} class ImageTable { @@ -30,7 +33,7 @@ public: ImageTable& operator=(const ImageTable&) = delete; ~ImageTable(); - void Read(IReadObjectContext* context, IStream* stream); + void Read(IReadObjectContext* context, OpenRCT2::IStream* stream); const rct_g1_element* GetImages() const { return _entries.data(); diff --git a/src/openrct2/object/LargeSceneryObject.cpp b/src/openrct2/object/LargeSceneryObject.cpp index aea514ff5f..f1d11978dd 100644 --- a/src/openrct2/object/LargeSceneryObject.cpp +++ b/src/openrct2/object/LargeSceneryObject.cpp @@ -23,17 +23,17 @@ #include #include -void LargeSceneryObject::ReadLegacy(IReadObjectContext* context, IStream* stream) +void LargeSceneryObject::ReadLegacy(IReadObjectContext* context, OpenRCT2::IStream* stream) { - stream->Seek(6, STREAM_SEEK_CURRENT); + stream->Seek(6, OpenRCT2::STREAM_SEEK_CURRENT); _legacyType.large_scenery.tool_id = stream->ReadValue(); _legacyType.large_scenery.flags = stream->ReadValue(); _legacyType.large_scenery.price = stream->ReadValue(); _legacyType.large_scenery.removal_price = stream->ReadValue(); - stream->Seek(5, STREAM_SEEK_CURRENT); + stream->Seek(5, OpenRCT2::STREAM_SEEK_CURRENT); _legacyType.large_scenery.scenery_tab_id = OBJECT_ENTRY_INDEX_NULL; _legacyType.large_scenery.scrolling_mode = stream->ReadValue(); - stream->Seek(4, STREAM_SEEK_CURRENT); + stream->Seek(4, OpenRCT2::STREAM_SEEK_CURRENT); GetStringTable().Read(context, stream, OBJ_STRING_ID_NAME); @@ -108,12 +108,12 @@ void LargeSceneryObject::DrawPreview(rct_drawpixelinfo* dpi, int32_t width, int3 gfx_draw_sprite(dpi, imageId, screenCoords, 0); } -std::vector LargeSceneryObject::ReadTiles(IStream* stream) +std::vector LargeSceneryObject::ReadTiles(OpenRCT2::IStream* stream) { auto tiles = std::vector(); while (stream->ReadValue() != 0xFFFF) { - stream->Seek(-2, STREAM_SEEK_CURRENT); + stream->Seek(-2, OpenRCT2::STREAM_SEEK_CURRENT); auto tile = stream->ReadValue(); tiles.push_back(tile); } diff --git a/src/openrct2/object/LargeSceneryObject.h b/src/openrct2/object/LargeSceneryObject.h index 88b64288c9..9b13c034a9 100644 --- a/src/openrct2/object/LargeSceneryObject.h +++ b/src/openrct2/object/LargeSceneryObject.h @@ -34,7 +34,7 @@ public: return &_legacyType; } - void ReadLegacy(IReadObjectContext* context, IStream* stream) override; + void ReadLegacy(IReadObjectContext* context, OpenRCT2::IStream* stream) override; void ReadJson(IReadObjectContext* context, const json_t* root) override; void Load() override; void Unload() override; @@ -42,7 +42,7 @@ public: void DrawPreview(rct_drawpixelinfo* dpi, int32_t width, int32_t height) const override; private: - static std::vector ReadTiles(IStream* stream); + static std::vector ReadTiles(OpenRCT2::IStream* stream); static std::vector ReadJsonTiles(const json_t* jTiles); static std::unique_ptr ReadJson3dFont(const json_t* j3dFont); static std::vector ReadJsonOffsets(const json_t* jOffsets); diff --git a/src/openrct2/object/Object.cpp b/src/openrct2/object/Object.cpp index c1ba1f8c81..c4308840f3 100644 --- a/src/openrct2/object/Object.cpp +++ b/src/openrct2/object/Object.cpp @@ -32,7 +32,7 @@ void* Object::GetLegacyData() throw std::runtime_error("Not supported."); } -void Object::ReadLegacy(IReadObjectContext* context, IStream* stream) +void Object::ReadLegacy(IReadObjectContext* context, OpenRCT2::IStream* stream) { throw std::runtime_error("Not supported."); } diff --git a/src/openrct2/object/Object.h b/src/openrct2/object/Object.h index 24771bd602..d074411183 100644 --- a/src/openrct2/object/Object.h +++ b/src/openrct2/object/Object.h @@ -135,7 +135,10 @@ assert_struct_size(rct_object_filters, 3); #pragma pack(pop) INTERFACE IObjectRepository; -INTERFACE IStream; +namespace OpenRCT2 +{ + INTERFACE IStream; +} struct ObjectRepositoryItem; struct rct_drawpixelinfo; struct json_t; @@ -223,7 +226,7 @@ public: virtual void ReadJson(IReadObjectContext* /*context*/, const json_t* /*root*/) { } - virtual void ReadLegacy(IReadObjectContext* context, IStream* stream); + virtual void ReadLegacy(IReadObjectContext* context, OpenRCT2::IStream* stream); virtual void Load() abstract; virtual void Unload() abstract; diff --git a/src/openrct2/object/ObjectFactory.cpp b/src/openrct2/object/ObjectFactory.cpp index 2ad93ca2a3..5003f1d625 100644 --- a/src/openrct2/object/ObjectFactory.cpp +++ b/src/openrct2/object/ObjectFactory.cpp @@ -179,7 +179,7 @@ namespace ObjectFactory return (result != LookupTable.end()) ? result->second : OBJECT_SOURCE_CUSTOM; } - static void ReadObjectLegacy(Object* object, IReadObjectContext* context, IStream* stream) + static void ReadObjectLegacy(Object* object, IReadObjectContext* context, OpenRCT2::IStream* stream) { try { @@ -203,7 +203,7 @@ namespace ObjectFactory Object* result = nullptr; try { - auto fs = FileStream(path, FILE_MODE_OPEN); + auto fs = OpenRCT2::FileStream(path, OpenRCT2::FILE_MODE_OPEN); auto chunkReader = SawyerChunkReader(&fs); rct_object_entry entry = fs.ReadValue(); @@ -219,7 +219,7 @@ namespace ObjectFactory auto chunk = chunkReader.ReadChunk(); log_verbose(" size: %zu", chunk->GetLength()); - auto chunkStream = MemoryStream(chunk->GetData(), chunk->GetLength()); + auto chunkStream = OpenRCT2::MemoryStream(chunk->GetData(), chunk->GetLength()); auto readContext = ReadObjectContext(objectRepository, objectName, !gOpenRCT2NoGraphics, nullptr); ReadObjectLegacy(result, &readContext, &chunkStream); if (readContext.WasError()) @@ -251,7 +251,7 @@ namespace ObjectFactory object_entry_get_name_fixed(objectName, sizeof(objectName), entry); auto readContext = ReadObjectContext(objectRepository, objectName, !gOpenRCT2NoGraphics, nullptr); - auto chunkStream = MemoryStream(data, dataSize); + auto chunkStream = OpenRCT2::MemoryStream(data, dataSize); ReadObjectLegacy(result, &readContext, &chunkStream); if (readContext.WasError()) diff --git a/src/openrct2/object/ObjectRepository.cpp b/src/openrct2/object/ObjectRepository.cpp index aea733f6ef..58ae87b7ab 100644 --- a/src/openrct2/object/ObjectRepository.cpp +++ b/src/openrct2/object/ObjectRepository.cpp @@ -611,7 +611,7 @@ private: return String::Convert(normalisedName, CODE_PAGE::CP_1252, CODE_PAGE::CP_UTF8); } - void WritePackedObject(IStream* stream, const rct_object_entry* entry) + void WritePackedObject(OpenRCT2::IStream* stream, const rct_object_entry* entry) { const ObjectRepositoryItem* item = FindObject(entry); if (item == nullptr) @@ -620,7 +620,7 @@ private: } // Read object data from file - auto fs = FileStream(item->Path, FILE_MODE_OPEN); + auto fs = OpenRCT2::FileStream(item->Path, OpenRCT2::FILE_MODE_OPEN); auto fileEntry = fs.ReadValue(); if (!object_entry_compare(entry, &fileEntry)) { diff --git a/src/openrct2/object/ObjectRepository.h b/src/openrct2/object/ObjectRepository.h index 3d16f6a70f..658f90b8cd 100644 --- a/src/openrct2/object/ObjectRepository.h +++ b/src/openrct2/object/ObjectRepository.h @@ -16,7 +16,11 @@ #include #include -INTERFACE IStream; +namespace OpenRCT2 +{ + INTERFACE IStream; +} + class Object; namespace OpenRCT2 { @@ -76,8 +80,8 @@ INTERFACE IObjectRepository virtual void AddObject(const rct_object_entry* objectEntry, const void* data, size_t dataSize) abstract; virtual void AddObjectFromFile(const std::string_view& objectName, const void* data, size_t dataSize) abstract; - virtual void ExportPackedObject(IStream * stream) abstract; - virtual void WritePackedObjects(IStream * stream, std::vector & objects) abstract; + virtual void ExportPackedObject(OpenRCT2::IStream * stream) abstract; + virtual void WritePackedObjects(OpenRCT2::IStream * stream, std::vector & objects) abstract; }; std::unique_ptr CreateObjectRepository(const std::shared_ptr& env); diff --git a/src/openrct2/object/RideObject.h b/src/openrct2/object/RideObject.h index 865cb239fb..2448539cbc 100644 --- a/src/openrct2/object/RideObject.h +++ b/src/openrct2/object/RideObject.h @@ -9,6 +9,7 @@ #pragma once +#include "../core/IStream.hpp" #include "../ride/Ride.h" #include "Object.h" @@ -34,7 +35,7 @@ public: } void ReadJson(IReadObjectContext* context, const json_t* root) override; - void ReadLegacy(IReadObjectContext* context, IStream* stream) override; + void ReadLegacy(IReadObjectContext* context, OpenRCT2::IStream* stream) override; void Load() override; void Unload() override; @@ -46,7 +47,7 @@ public: void SetRepositoryItem(ObjectRepositoryItem* item) const override; private: - void ReadLegacyVehicle(IReadObjectContext* context, IStream* stream, rct_ride_entry_vehicle* vehicle); + void ReadLegacyVehicle(IReadObjectContext* context, OpenRCT2::IStream* stream, rct_ride_entry_vehicle* vehicle); void ReadJsonVehicleInfo(IReadObjectContext* context, const json_t* properties); std::vector ReadJsonCars(const json_t* jCars); diff --git a/src/openrct2/object/SceneryGroupObject.h b/src/openrct2/object/SceneryGroupObject.h index c0c60a2db5..ceb1d83d04 100644 --- a/src/openrct2/object/SceneryGroupObject.h +++ b/src/openrct2/object/SceneryGroupObject.h @@ -34,7 +34,7 @@ public: } void ReadJson(IReadObjectContext* context, const json_t* root) override; - void ReadLegacy(IReadObjectContext* context, IStream* stream) override; + void ReadLegacy(IReadObjectContext* context, OpenRCT2::IStream* stream) override; void Load() override; void Unload() override; void UpdateEntryIndexes(); @@ -44,7 +44,7 @@ public: void SetRepositoryItem(ObjectRepositoryItem* item) const override; private: - static std::vector ReadItems(IStream* stream); + static std::vector ReadItems(OpenRCT2::IStream* stream); static uint32_t ReadJsonEntertainerCostumes(const json_t* jCostumes); static uint32_t ParseEntertainerCostume(const std::string& s); static std::vector ReadJsonEntries(const json_t* jEntries); diff --git a/src/openrct2/object/SmallSceneryObject.cpp b/src/openrct2/object/SmallSceneryObject.cpp index e6b37025a7..dd604428a3 100644 --- a/src/openrct2/object/SmallSceneryObject.cpp +++ b/src/openrct2/object/SmallSceneryObject.cpp @@ -23,15 +23,15 @@ #include -void SmallSceneryObject::ReadLegacy(IReadObjectContext* context, IStream* stream) +void SmallSceneryObject::ReadLegacy(IReadObjectContext* context, OpenRCT2::IStream* stream) { - stream->Seek(6, STREAM_SEEK_CURRENT); + stream->Seek(6, OpenRCT2::STREAM_SEEK_CURRENT); _legacyType.small_scenery.flags = stream->ReadValue(); _legacyType.small_scenery.height = stream->ReadValue(); _legacyType.small_scenery.tool_id = stream->ReadValue(); _legacyType.small_scenery.price = stream->ReadValue(); _legacyType.small_scenery.removal_price = stream->ReadValue(); - stream->Seek(4, STREAM_SEEK_CURRENT); + stream->Seek(4, OpenRCT2::STREAM_SEEK_CURRENT); _legacyType.small_scenery.animation_delay = stream->ReadValue(); _legacyType.small_scenery.animation_mask = stream->ReadValue(); _legacyType.small_scenery.num_frames = stream->ReadValue(); @@ -139,7 +139,7 @@ void SmallSceneryObject::DrawPreview(rct_drawpixelinfo* dpi, int32_t width, int3 } } -std::vector SmallSceneryObject::ReadFrameOffsets(IStream* stream) +std::vector SmallSceneryObject::ReadFrameOffsets(OpenRCT2::IStream* stream) { uint8_t frameOffset; auto data = std::vector(); diff --git a/src/openrct2/object/SmallSceneryObject.h b/src/openrct2/object/SmallSceneryObject.h index ce4080cf02..0c6e950f1a 100644 --- a/src/openrct2/object/SmallSceneryObject.h +++ b/src/openrct2/object/SmallSceneryObject.h @@ -31,7 +31,7 @@ public: return &_legacyType; } - void ReadLegacy(IReadObjectContext* context, IStream* stream) override; + void ReadLegacy(IReadObjectContext* context, OpenRCT2::IStream* stream) override; void ReadJson(IReadObjectContext* context, const json_t* root) override; void Load() override; void Unload() override; @@ -39,7 +39,7 @@ public: void DrawPreview(rct_drawpixelinfo* dpi, int32_t width, int32_t height) const override; private: - static std::vector ReadFrameOffsets(IStream* stream); + static std::vector ReadFrameOffsets(OpenRCT2::IStream* stream); static std::vector ReadJsonFrameOffsets(const json_t* jFrameOffsets); void PerformFixes(); rct_object_entry GetScgPiratHeader(); diff --git a/src/openrct2/object/StringTable.cpp b/src/openrct2/object/StringTable.cpp index 6992959174..b51e4f3d92 100644 --- a/src/openrct2/object/StringTable.cpp +++ b/src/openrct2/object/StringTable.cpp @@ -47,7 +47,7 @@ static bool StringIsBlank(const utf8* str) return true; } -void StringTable::Read(IReadObjectContext* context, IStream* stream, uint8_t id) +void StringTable::Read(IReadObjectContext* context, OpenRCT2::IStream* stream, uint8_t id) { try { diff --git a/src/openrct2/object/StringTable.h b/src/openrct2/object/StringTable.h index 642a5e79d8..324cb93d0d 100644 --- a/src/openrct2/object/StringTable.h +++ b/src/openrct2/object/StringTable.h @@ -16,7 +16,10 @@ #include INTERFACE IReadObjectContext; -INTERFACE IStream; +namespace OpenRCT2 +{ + INTERFACE IStream; +} enum OBJ_STRING_ID : uint8_t { @@ -47,7 +50,7 @@ public: StringTable(const StringTable&) = delete; StringTable& operator=(const StringTable&) = delete; - void Read(IReadObjectContext* context, IStream* stream, uint8_t id); + void Read(IReadObjectContext* context, OpenRCT2::IStream* stream, uint8_t id); void Sort(); std::string GetString(uint8_t id) const; std::string GetString(uint8_t language, uint8_t id) const; diff --git a/src/openrct2/object/WallObject.cpp b/src/openrct2/object/WallObject.cpp index aba576cfbb..3d13eee584 100644 --- a/src/openrct2/object/WallObject.cpp +++ b/src/openrct2/object/WallObject.cpp @@ -17,16 +17,16 @@ #include "../world/Banner.h" #include "ObjectJsonHelpers.h" -void WallObject::ReadLegacy(IReadObjectContext* context, IStream* stream) +void WallObject::ReadLegacy(IReadObjectContext* context, OpenRCT2::IStream* stream) { - stream->Seek(6, STREAM_SEEK_CURRENT); + stream->Seek(6, OpenRCT2::STREAM_SEEK_CURRENT); _legacyType.wall.tool_id = stream->ReadValue(); _legacyType.wall.flags = stream->ReadValue(); _legacyType.wall.height = stream->ReadValue(); _legacyType.wall.flags2 = stream->ReadValue(); _legacyType.wall.price = stream->ReadValue(); _legacyType.wall.scenery_tab_id = OBJECT_ENTRY_INDEX_NULL; - stream->Seek(1, STREAM_SEEK_CURRENT); + stream->Seek(1, OpenRCT2::STREAM_SEEK_CURRENT); _legacyType.wall.scrolling_mode = stream->ReadValue(); GetStringTable().Read(context, stream, OBJ_STRING_ID_NAME); diff --git a/src/openrct2/object/WallObject.h b/src/openrct2/object/WallObject.h index c0c9457cfe..403ecd81ca 100644 --- a/src/openrct2/object/WallObject.h +++ b/src/openrct2/object/WallObject.h @@ -28,7 +28,7 @@ public: return &_legacyType; } - void ReadLegacy(IReadObjectContext* context, IStream* stream) override; + void ReadLegacy(IReadObjectContext* context, OpenRCT2::IStream* stream) override; void ReadJson(IReadObjectContext* context, const json_t* root) override; void Load() override; void Unload() override; diff --git a/src/openrct2/object/WaterObject.cpp b/src/openrct2/object/WaterObject.cpp index ba7d269105..926a02a9d9 100644 --- a/src/openrct2/object/WaterObject.cpp +++ b/src/openrct2/object/WaterObject.cpp @@ -20,9 +20,9 @@ #include -void WaterObject::ReadLegacy(IReadObjectContext* context, IStream* stream) +void WaterObject::ReadLegacy(IReadObjectContext* context, OpenRCT2::IStream* stream) { - stream->Seek(14, STREAM_SEEK_CURRENT); + stream->Seek(14, OpenRCT2::STREAM_SEEK_CURRENT); _legacyType.flags = stream->ReadValue(); GetStringTable().Read(context, stream, OBJ_STRING_ID_NAME); diff --git a/src/openrct2/object/WaterObject.h b/src/openrct2/object/WaterObject.h index bca8cc4a7f..b7dcfad231 100644 --- a/src/openrct2/object/WaterObject.h +++ b/src/openrct2/object/WaterObject.h @@ -31,7 +31,7 @@ public: } void ReadJson(IReadObjectContext* context, const json_t* root) override; - void ReadLegacy(IReadObjectContext* context, IStream* stream) override; + void ReadLegacy(IReadObjectContext* context, OpenRCT2::IStream* stream) override; void Load() override; void Unload() override; diff --git a/src/openrct2/rct1/T4Importer.cpp b/src/openrct2/rct1/T4Importer.cpp index 8c9f80ab2a..a460465f2f 100644 --- a/src/openrct2/rct1/T4Importer.cpp +++ b/src/openrct2/rct1/T4Importer.cpp @@ -28,7 +28,7 @@ class TD4Importer final : public ITrackImporter { private: - MemoryStream _stream; + OpenRCT2::MemoryStream _stream; std::string _name; public: @@ -42,7 +42,7 @@ public: if (String::Equals(extension, ".td4", true)) { _name = GetNameFromTrackPath(path); - auto fs = FileStream(path, FILE_MODE_OPEN); + auto fs = OpenRCT2::FileStream(path, OpenRCT2::FILE_MODE_OPEN); return LoadFromStream(&fs); } else @@ -51,7 +51,7 @@ public: } } - bool LoadFromStream(IStream* stream) override + bool LoadFromStream(OpenRCT2::IStream* stream) override { auto checksumType = SawyerEncoding::ValidateTrackChecksum(stream); if (!gConfigGeneral.allow_loading_with_incorrect_checksum && checksumType == RCT12TrackDesignVersion::unknown) diff --git a/src/openrct2/rct12/SawyerChunkReader.cpp b/src/openrct2/rct12/SawyerChunkReader.cpp index d077999dd9..7b0f5b12b0 100644 --- a/src/openrct2/rct12/SawyerChunkReader.cpp +++ b/src/openrct2/rct12/SawyerChunkReader.cpp @@ -41,7 +41,7 @@ public: } }; -SawyerChunkReader::SawyerChunkReader(IStream* stream) +SawyerChunkReader::SawyerChunkReader(OpenRCT2::IStream* stream) : _stream(stream) { } @@ -52,7 +52,7 @@ void SawyerChunkReader::SkipChunk() try { auto header = _stream->ReadValue(); - _stream->Seek(header.length, STREAM_SEEK_CURRENT); + _stream->Seek(header.length, OpenRCT2::STREAM_SEEK_CURRENT); } catch (const std::exception&) { diff --git a/src/openrct2/rct12/SawyerChunkReader.h b/src/openrct2/rct12/SawyerChunkReader.h index 213d2703b3..8c608be9fa 100644 --- a/src/openrct2/rct12/SawyerChunkReader.h +++ b/src/openrct2/rct12/SawyerChunkReader.h @@ -15,7 +15,10 @@ #include -INTERFACE IStream; +namespace OpenRCT2 +{ + INTERFACE IStream; +} /** * Reads sawyer encoding chunks from a data stream. This can be used to read @@ -24,10 +27,10 @@ INTERFACE IStream; class SawyerChunkReader final { private: - IStream* const _stream = nullptr; + OpenRCT2::IStream* const _stream = nullptr; public: - explicit SawyerChunkReader(IStream* stream); + explicit SawyerChunkReader(OpenRCT2::IStream* stream); /** * Skips the next chunk in the stream without decoding or reading its data diff --git a/src/openrct2/rct12/SawyerChunkWriter.cpp b/src/openrct2/rct12/SawyerChunkWriter.cpp index 5ba777edb2..83a7dc944c 100644 --- a/src/openrct2/rct12/SawyerChunkWriter.cpp +++ b/src/openrct2/rct12/SawyerChunkWriter.cpp @@ -15,7 +15,7 @@ // Maximum buffer size to store compressed data, maximum of 16 MiB constexpr size_t MAX_COMPRESSED_CHUNK_SIZE = 16 * 1024 * 1024; -SawyerChunkWriter::SawyerChunkWriter(IStream* stream) +SawyerChunkWriter::SawyerChunkWriter(OpenRCT2::IStream* stream) : _stream(stream) { } diff --git a/src/openrct2/rct12/SawyerChunkWriter.h b/src/openrct2/rct12/SawyerChunkWriter.h index 443be7b8ff..1690087141 100644 --- a/src/openrct2/rct12/SawyerChunkWriter.h +++ b/src/openrct2/rct12/SawyerChunkWriter.h @@ -14,7 +14,10 @@ #include -INTERFACE IStream; +namespace OpenRCT2 +{ + INTERFACE IStream; +} /** * Writes sawyer encoding chunks to a data stream. This can be used to write @@ -23,10 +26,10 @@ INTERFACE IStream; class SawyerChunkWriter final { private: - IStream* const _stream = nullptr; + OpenRCT2::IStream* const _stream = nullptr; public: - explicit SawyerChunkWriter(IStream* stream); + explicit SawyerChunkWriter(OpenRCT2::IStream* stream); /** * Writes a chunk to the stream. diff --git a/src/openrct2/rct12/SawyerEncoding.cpp b/src/openrct2/rct12/SawyerEncoding.cpp index f53e459f9e..e0da9f2c16 100644 --- a/src/openrct2/rct12/SawyerEncoding.cpp +++ b/src/openrct2/rct12/SawyerEncoding.cpp @@ -16,7 +16,7 @@ namespace SawyerEncoding { - bool ValidateChecksum(IStream* stream) + bool ValidateChecksum(OpenRCT2::IStream* stream) { uint64_t initialPosition = stream->GetPosition(); uint64_t dataSize = stream->GetLength() - initialPosition; @@ -60,7 +60,7 @@ namespace SawyerEncoding } // Returns version number - RCT12TrackDesignVersion ValidateTrackChecksum(IStream* stream) + RCT12TrackDesignVersion ValidateTrackChecksum(OpenRCT2::IStream* stream) { uint64_t initialPosition = stream->GetPosition(); uint64_t dataSize = stream->GetLength() - initialPosition; diff --git a/src/openrct2/rct12/SawyerEncoding.h b/src/openrct2/rct12/SawyerEncoding.h index 9c85fd6661..1b98aefb71 100644 --- a/src/openrct2/rct12/SawyerEncoding.h +++ b/src/openrct2/rct12/SawyerEncoding.h @@ -11,12 +11,15 @@ #include "../common.h" -INTERFACE IStream; +namespace OpenRCT2 +{ + INTERFACE IStream; +} enum class RCT12TrackDesignVersion : uint8_t; namespace SawyerEncoding { - bool ValidateChecksum(IStream* stream); - RCT12TrackDesignVersion ValidateTrackChecksum(IStream* stream); + bool ValidateChecksum(OpenRCT2::IStream* stream); + RCT12TrackDesignVersion ValidateTrackChecksum(OpenRCT2::IStream* stream); } // namespace SawyerEncoding diff --git a/src/openrct2/rct2/S6Exporter.cpp b/src/openrct2/rct2/S6Exporter.cpp index 38a6be5928..909ad84bd9 100644 --- a/src/openrct2/rct2/S6Exporter.cpp +++ b/src/openrct2/rct2/S6Exporter.cpp @@ -61,27 +61,27 @@ S6Exporter::S6Exporter() void S6Exporter::SaveGame(const utf8* path) { - auto fs = FileStream(path, FILE_MODE_WRITE); + auto fs = OpenRCT2::FileStream(path, OpenRCT2::FILE_MODE_WRITE); SaveGame(&fs); } -void S6Exporter::SaveGame(IStream* stream) +void S6Exporter::SaveGame(OpenRCT2::IStream* stream) { Save(stream, false); } void S6Exporter::SaveScenario(const utf8* path) { - auto fs = FileStream(path, FILE_MODE_WRITE); + auto fs = OpenRCT2::FileStream(path, OpenRCT2::FILE_MODE_WRITE); SaveScenario(&fs); } -void S6Exporter::SaveScenario(IStream* stream) +void S6Exporter::SaveScenario(OpenRCT2::IStream* stream) { Save(stream, true); } -void S6Exporter::Save(IStream* stream, bool isScenario) +void S6Exporter::Save(OpenRCT2::IStream* stream, bool isScenario) { _s6.header.type = isScenario ? S6_TYPE_SCENARIO : S6_TYPE_SAVEDGAME; _s6.header.classic_flag = 0; diff --git a/src/openrct2/rct2/S6Exporter.h b/src/openrct2/rct2/S6Exporter.h index cecf50efd4..eb97641319 100644 --- a/src/openrct2/rct2/S6Exporter.h +++ b/src/openrct2/rct2/S6Exporter.h @@ -18,7 +18,11 @@ #include #include -INTERFACE IStream; +namespace OpenRCT2 +{ + INTERFACE IStream; +} + struct ObjectRepositoryItem; struct RCT12SpriteBase; struct SpriteBase; @@ -35,9 +39,9 @@ public: S6Exporter(); void SaveGame(const utf8* path); - void SaveGame(IStream* stream); + void SaveGame(OpenRCT2::IStream* stream); void SaveScenario(const utf8* path); - void SaveScenario(IStream* stream); + void SaveScenario(OpenRCT2::IStream* stream); void Export(); void ExportParkName(); void ExportRides(); @@ -54,7 +58,7 @@ private: rct_s6_data _s6{}; std::vector _userStrings; - void Save(IStream* stream, bool isScenario); + void Save(OpenRCT2::IStream* stream, bool isScenario); static uint32_t GetLoanHash(money32 initialCash, money32 bankLoan, uint32_t maxBankLoan); void ExportResearchedRideTypes(); void ExportResearchedRideEntries(); diff --git a/src/openrct2/rct2/S6Importer.cpp b/src/openrct2/rct2/S6Importer.cpp index 12eaee6400..f2a11a9ffa 100644 --- a/src/openrct2/rct2/S6Importer.cpp +++ b/src/openrct2/rct2/S6Importer.cpp @@ -93,7 +93,7 @@ public: ParkLoadResult LoadSavedGame(const utf8* path, bool skipObjectCheck = false) override { - auto fs = FileStream(path, FILE_MODE_OPEN); + auto fs = OpenRCT2::FileStream(path, OpenRCT2::FILE_MODE_OPEN); auto result = LoadFromStream(&fs, false, skipObjectCheck); _s6Path = path; return result; @@ -101,14 +101,14 @@ public: ParkLoadResult LoadScenario(const utf8* path, bool skipObjectCheck = false) override { - auto fs = FileStream(path, FILE_MODE_OPEN); + auto fs = OpenRCT2::FileStream(path, OpenRCT2::FILE_MODE_OPEN); auto result = LoadFromStream(&fs, true, skipObjectCheck); _s6Path = path; return result; } ParkLoadResult LoadFromStream( - IStream* stream, bool isScenario, [[maybe_unused]] bool skipObjectCheck = false, + OpenRCT2::IStream* stream, bool isScenario, [[maybe_unused]] bool skipObjectCheck = false, const utf8* path = String::Empty) override { if (isScenario && !gConfigGeneral.allow_loading_with_incorrect_checksum && !SawyerEncoding::ValidateChecksum(stream)) diff --git a/src/openrct2/rct2/T6Exporter.cpp b/src/openrct2/rct2/T6Exporter.cpp index fce382e832..00a02b1b08 100644 --- a/src/openrct2/rct2/T6Exporter.cpp +++ b/src/openrct2/rct2/T6Exporter.cpp @@ -35,7 +35,7 @@ bool T6Exporter::SaveTrack(const utf8* path) { try { - auto fs = FileStream(path, FILE_MODE_WRITE); + auto fs = OpenRCT2::FileStream(path, OpenRCT2::FILE_MODE_WRITE); return SaveTrack(&fs); } catch (const std::exception& e) @@ -45,9 +45,9 @@ bool T6Exporter::SaveTrack(const utf8* path) } } -bool T6Exporter::SaveTrack(IStream* stream) +bool T6Exporter::SaveTrack(OpenRCT2::IStream* stream) { - MemoryStream tempStream; + OpenRCT2::MemoryStream tempStream; tempStream.WriteValue(_trackDesign->type); tempStream.WriteValue(_trackDesign->vehicle_type); tempStream.WriteValue(_trackDesign->flags); diff --git a/src/openrct2/rct2/T6Exporter.h b/src/openrct2/rct2/T6Exporter.h index c5b6acf5eb..54b137a588 100644 --- a/src/openrct2/rct2/T6Exporter.h +++ b/src/openrct2/rct2/T6Exporter.h @@ -14,7 +14,10 @@ #include -INTERFACE IStream; +namespace OpenRCT2 +{ + INTERFACE IStream; +} /** * Class to export RollerCoaster Tycoon 2 track designs (*.TD6). @@ -25,7 +28,7 @@ public: T6Exporter(TrackDesign* trackDesign); bool SaveTrack(const utf8* path); - bool SaveTrack(IStream* stream); + bool SaveTrack(OpenRCT2::IStream* stream); private: TrackDesign* _trackDesign; diff --git a/src/openrct2/rct2/T6Importer.cpp b/src/openrct2/rct2/T6Importer.cpp index 80f4683d87..324d6a28b8 100644 --- a/src/openrct2/rct2/T6Importer.cpp +++ b/src/openrct2/rct2/T6Importer.cpp @@ -26,7 +26,7 @@ class TD6Importer final : public ITrackImporter { private: - MemoryStream _stream; + OpenRCT2::MemoryStream _stream; std::string _name; public: @@ -40,7 +40,7 @@ public: if (String::Equals(extension, ".td6", true)) { _name = GetNameFromTrackPath(path); - auto fs = FileStream(path, FILE_MODE_OPEN); + auto fs = OpenRCT2::FileStream(path, OpenRCT2::FILE_MODE_OPEN); return LoadFromStream(&fs); } else @@ -49,7 +49,7 @@ public: } } - bool LoadFromStream(IStream* stream) override + bool LoadFromStream(OpenRCT2::IStream* stream) override { if (!gConfigGeneral.allow_loading_with_incorrect_checksum && SawyerEncoding::ValidateTrackChecksum(stream) != RCT12TrackDesignVersion::TD6) diff --git a/src/openrct2/title/TitleSequence.cpp b/src/openrct2/title/TitleSequence.cpp index 8d40e9aa26..304499637f 100644 --- a/src/openrct2/title/TitleSequence.cpp +++ b/src/openrct2/title/TitleSequence.cpp @@ -33,7 +33,7 @@ static std::vector GetSaves(const utf8* path); static std::vector GetSaves(IZipArchive* zip); static std::vector LegacyScriptRead(utf8* script, size_t scriptLength, std::vector saves); -static void LegacyScriptGetLine(IStream* stream, char* parts); +static void LegacyScriptGetLine(OpenRCT2::IStream* stream, char* parts); static std::vector ReadScriptFile(const utf8* path); static std::string LegacyScriptWrite(TitleSequence* seq); @@ -131,7 +131,8 @@ TitleSequenceParkHandle* TitleSequenceGetParkHandle(TitleSequence* seq, size_t i auto data = zip->GetFileData(filename); auto dataForMs = Memory::Allocate(data.size()); std::copy_n(data.data(), data.size(), dataForMs); - auto ms = new MemoryStream(dataForMs, data.size(), MEMORY_ACCESS::READ | MEMORY_ACCESS::OWNER); + auto ms = new OpenRCT2::MemoryStream( + dataForMs, data.size(), OpenRCT2::MEMORY_ACCESS::READ | OpenRCT2::MEMORY_ACCESS::OWNER); handle = Memory::Allocate(); handle->Stream = ms; @@ -148,10 +149,10 @@ TitleSequenceParkHandle* TitleSequenceGetParkHandle(TitleSequence* seq, size_t i String::Set(absolutePath, sizeof(absolutePath), seq->Path); Path::Append(absolutePath, sizeof(absolutePath), filename); - FileStream* fileStream = nullptr; + OpenRCT2::FileStream* fileStream = nullptr; try { - fileStream = new FileStream(absolutePath, FILE_MODE_OPEN); + fileStream = new OpenRCT2::FileStream(absolutePath, OpenRCT2::FILE_MODE_OPEN); } catch (const IOException& exception) { @@ -174,7 +175,7 @@ void TitleSequenceCloseParkHandle(TitleSequenceParkHandle* handle) if (handle != nullptr) { Memory::Free(handle->HintPath); - delete (static_cast(handle->Stream)); + delete (static_cast(handle->Stream)); Memory::Free(handle); } } @@ -386,7 +387,7 @@ static std::vector GetSaves(IZipArchive* zip) static std::vector LegacyScriptRead(utf8* script, size_t scriptLength, std::vector saves) { std::vector commands; - auto fs = MemoryStream(script, scriptLength); + auto fs = OpenRCT2::MemoryStream(script, scriptLength); do { char parts[3 * 128], *token, *part1, *part2; @@ -472,7 +473,7 @@ static std::vector LegacyScriptRead(utf8* script, size_t scriptLen return commands; } -static void LegacyScriptGetLine(IStream* stream, char* parts) +static void LegacyScriptGetLine(OpenRCT2::IStream* stream, char* parts) { for (int32_t i = 0; i < 3; i++) { @@ -543,7 +544,7 @@ static std::vector ReadScriptFile(const utf8* path) std::vector result; try { - auto fs = FileStream(path, FILE_MODE_OPEN); + auto fs = OpenRCT2::FileStream(path, OpenRCT2::FILE_MODE_OPEN); auto size = static_cast(fs.GetLength()); result.resize(size); fs.Read(result.data(), size); diff --git a/test/tests/IniReaderTest.cpp b/test/tests/IniReaderTest.cpp index 93e092a746..0eebf9e50a 100644 --- a/test/tests/IniReaderTest.cpp +++ b/test/tests/IniReaderTest.cpp @@ -29,7 +29,7 @@ static auto Enum_Currency = ConfigEnum({}); TEST_F(IniReaderTest, create_empty) { - MemoryStream ms(0); + OpenRCT2::MemoryStream ms(0); ASSERT_EQ(ms.CanRead(), true); ASSERT_EQ(ms.CanWrite(), true); IIniReader* ir = CreateIniReader(&ms); @@ -46,7 +46,7 @@ TEST_F(IniReaderTest, create_empty) TEST_F(IniReaderTest, read_prepared) { - MemoryStream ms(predefined.c_str(), predefined.size()); + OpenRCT2::MemoryStream ms(predefined.c_str(), predefined.size()); ASSERT_EQ(ms.CanRead(), true); ASSERT_EQ(ms.CanWrite(), false); IIniReader* ir = CreateIniReader(&ms); @@ -76,7 +76,7 @@ TEST_F(IniReaderTest, read_prepared) TEST_F(IniReaderTest, read_duplicate) { - MemoryStream ms(duplicate.c_str(), duplicate.size()); + OpenRCT2::MemoryStream ms(duplicate.c_str(), duplicate.size()); ASSERT_EQ(ms.CanRead(), true); ASSERT_EQ(ms.CanWrite(), false); IIniReader* ir = CreateIniReader(&ms); @@ -102,7 +102,7 @@ TEST_F(IniReaderTest, read_duplicate) TEST_F(IniReaderTest, read_untrimmed) { - MemoryStream ms(untrimmed.c_str(), untrimmed.size()); + OpenRCT2::MemoryStream ms(untrimmed.c_str(), untrimmed.size()); ASSERT_EQ(ms.CanRead(), true); ASSERT_EQ(ms.CanWrite(), false); IIniReader* ir = CreateIniReader(&ms); @@ -120,7 +120,7 @@ TEST_F(IniReaderTest, read_untrimmed) TEST_F(IniReaderTest, read_case_insensitive) { - MemoryStream ms(caseInsensitive.c_str(), caseInsensitive.size()); + OpenRCT2::MemoryStream ms(caseInsensitive.c_str(), caseInsensitive.size()); ASSERT_EQ(ms.CanRead(), true); ASSERT_EQ(ms.CanWrite(), false); IIniReader* ir = CreateIniReader(&ms); diff --git a/test/tests/IniWriterTest.cpp b/test/tests/IniWriterTest.cpp index 76867bc012..acdc46c2af 100644 --- a/test/tests/IniWriterTest.cpp +++ b/test/tests/IniWriterTest.cpp @@ -26,7 +26,7 @@ static auto Enum_Currency = ConfigEnum({ TEST_F(IniWriterTest, create_empty) { - MemoryStream ms(0); + OpenRCT2::MemoryStream ms(0); ASSERT_EQ(ms.CanRead(), true); ASSERT_EQ(ms.CanWrite(), true); IIniWriter* iw = CreateIniWriter(&ms); @@ -36,7 +36,7 @@ TEST_F(IniWriterTest, create_empty) TEST_F(IniWriterTest, create_one_section) { - MemoryStream ms(1000); + OpenRCT2::MemoryStream ms(1000); IIniWriter* iw = CreateIniWriter(&ms); ASSERT_NE(iw, nullptr); iw->WriteSection("OpenRCT2"); @@ -54,7 +54,7 @@ TEST_F(IniWriterTest, create_one_section) TEST_F(IniWriterTest, create_multiple_sections) { - MemoryStream ms(1000); + OpenRCT2::MemoryStream ms(1000); IIniWriter* iw = CreateIniWriter(&ms); ASSERT_NE(iw, nullptr); iw->WriteSection("OpenRCT1"); @@ -78,7 +78,7 @@ TEST_F(IniWriterTest, create_multiple_sections) TEST_F(IniWriterTest, create_loose_bool_entry) { - MemoryStream ms(1000); + OpenRCT2::MemoryStream ms(1000); IIniWriter* iw = CreateIniWriter(&ms); ASSERT_NE(iw, nullptr); iw->WriteBoolean("boolval", true); @@ -96,7 +96,7 @@ TEST_F(IniWriterTest, create_loose_bool_entry) TEST_F(IniWriterTest, create_loose_enum_entry) { - MemoryStream ms(1000); + OpenRCT2::MemoryStream ms(1000); IIniWriter* iw = CreateIniWriter(&ms); ASSERT_NE(iw, nullptr); iw->WriteEnum("by_string", "stringval"); @@ -115,7 +115,7 @@ TEST_F(IniWriterTest, create_loose_enum_entry) TEST_F(IniWriterTest, create_loose_float_entry) { - MemoryStream ms(1000); + OpenRCT2::MemoryStream ms(1000); IIniWriter* iw = CreateIniWriter(&ms); ASSERT_NE(iw, nullptr); iw->WriteFloat("one", 1.); @@ -134,7 +134,7 @@ TEST_F(IniWriterTest, create_loose_float_entry) TEST_F(IniWriterTest, create_loose_int32_t_entry) { - MemoryStream ms(1000); + OpenRCT2::MemoryStream ms(1000); IIniWriter* iw = CreateIniWriter(&ms); ASSERT_NE(iw, nullptr); iw->WriteInt32("one", 1); @@ -159,7 +159,7 @@ TEST_F(IniWriterTest, create_loose_int32_t_entry) TEST_F(IniWriterTest, create_loose_string_entry) { - MemoryStream ms(1000); + OpenRCT2::MemoryStream ms(1000); IIniWriter* iw = CreateIniWriter(&ms); ASSERT_NE(iw, nullptr); iw->WriteString("path", u8"C:'\\some/dir\\here/神鷹暢遊"); @@ -177,7 +177,7 @@ TEST_F(IniWriterTest, create_loose_string_entry) TEST_F(IniWriterTest, create_multiple_section_with_values) { - MemoryStream ms(1000); + OpenRCT2::MemoryStream ms(1000); IIniWriter* iw = CreateIniWriter(&ms); ASSERT_NE(iw, nullptr); iw->WriteSection("bool"); @@ -205,7 +205,7 @@ TEST_F(IniWriterTest, create_multiple_section_with_values) TEST_F(IniWriterTest, create_duplicate_sections) { - MemoryStream ms(1000); + OpenRCT2::MemoryStream ms(1000); IIniWriter* iw = CreateIniWriter(&ms); ASSERT_NE(iw, nullptr); iw->WriteSection("section"); diff --git a/test/tests/sawyercoding_test.cpp b/test/tests/sawyercoding_test.cpp index 7aeea21cb3..c23bd95ce9 100644 --- a/test/tests/sawyercoding_test.cpp +++ b/test/tests/sawyercoding_test.cpp @@ -34,7 +34,7 @@ protected: ASSERT_GT(encodedDataSize, sizeof(sawyercoding_chunk_header)); // Decode - MemoryStream ms(encodedDataBuffer, encodedDataSize); + OpenRCT2::MemoryStream ms(encodedDataBuffer, encodedDataSize); SawyerChunkReader reader(&ms); auto chunk = reader.ReadChunk(); ASSERT_EQ(static_cast(chunk->GetEncoding()), chdr_in.encoding); @@ -51,7 +51,7 @@ protected: auto chdr_in = reinterpret_cast(data); ASSERT_EQ(chdr_in->length, expectedLength); - MemoryStream ms(data, size); + OpenRCT2::MemoryStream ms(data, size); SawyerChunkReader reader(&ms); auto chunk = reader.ReadChunk(); ASSERT_EQ(static_cast(chunk->GetEncoding()), chdr_in->encoding);