diff --git a/openrct2.common.props b/openrct2.common.props
index 9c63f8477b..d79ec76ac1 100644
--- a/openrct2.common.props
+++ b/openrct2.common.props
@@ -52,7 +52,7 @@
C4549: 'operator': operator before comma has no effect; did you intend 'operator'?
C4555: expression has no effect; expected expression with side-effect
-->
- __AVX2__;__SSE4_1__;OPENGL_NO_LINK;_CRT_SECURE_NO_WARNINGS;_USE_MATH_DEFINES;SDL_MAIN_HANDLED;_WINSOCK_DEPRECATED_NO_WARNINGS;NOMINMAX;%(PreprocessorDefinitions)
+ __AVX2__;__SSE4_1__;OPENGL_NO_LINK;_CRT_SECURE_NO_WARNINGS;_USE_MATH_DEFINES;SDL_MAIN_HANDLED;_WINSOCK_DEPRECATED_NO_WARNINGS;NOMINMAX;WIN32_LEAN_AND_MEAN%(PreprocessorDefinitions)
ENABLE_SCRIPTING;%(PreprocessorDefinitions)
MultiThreaded
MultiThreadedDLL
diff --git a/src/openrct2-ui/UiContext.Win32.cpp b/src/openrct2-ui/UiContext.Win32.cpp
index 22c9b932a1..e160c2eea9 100644
--- a/src/openrct2-ui/UiContext.Win32.cpp
+++ b/src/openrct2-ui/UiContext.Win32.cpp
@@ -16,7 +16,11 @@
# endif // __MINGW32__
// Windows.h needs to be included first
+// clang-format off
# include
+# include
+# include
+// clang-format on
# undef CreateWindow
// Then the rest
diff --git a/src/openrct2-ui/UiContext.h b/src/openrct2-ui/UiContext.h
index 74d7fde2ec..9dc51b9524 100644
--- a/src/openrct2-ui/UiContext.h
+++ b/src/openrct2-ui/UiContext.h
@@ -17,26 +17,27 @@ struct SDL_Window;
namespace OpenRCT2
{
- interface IContext;
- interface IPlatformEnvironment;
+ struct IContext;
+ struct IPlatformEnvironment;
namespace Ui
{
struct FileDialogDesc;
class InGameConsole;
- interface IUiContext;
+ struct IUiContext;
- interface IPlatformUiContext
+ struct IPlatformUiContext
{
virtual ~IPlatformUiContext() = default;
- virtual void SetWindowIcon(SDL_Window * window) abstract;
+ virtual void SetWindowIcon(SDL_Window* window) abstract;
virtual bool IsSteamOverlayAttached() abstract;
- virtual void ShowMessageBox(SDL_Window * window, const std::string& message) abstract;
+ virtual void ShowMessageBox(SDL_Window* window, const std::string& message) abstract;
virtual void OpenFolder(const std::string& path) abstract;
+
virtual void OpenURL(const std::string& url) abstract;
- virtual std::string ShowFileDialog(SDL_Window * window, const FileDialogDesc& desc) abstract;
- virtual std::string ShowDirectoryDialog(SDL_Window * window, const std::string& title) abstract;
+ virtual std::string ShowFileDialog(SDL_Window* window, const FileDialogDesc& desc) abstract;
+ virtual std::string ShowDirectoryDialog(SDL_Window* window, const std::string& title) abstract;
};
std::unique_ptr CreateUiContext(const std::shared_ptr& env);
diff --git a/src/openrct2-ui/WindowManager.h b/src/openrct2-ui/WindowManager.h
index 16cf0ac9c9..e75d2411de 100644
--- a/src/openrct2-ui/WindowManager.h
+++ b/src/openrct2-ui/WindowManager.h
@@ -13,7 +13,7 @@
namespace OpenRCT2::Ui
{
- interface IWindowManager;
+ struct IWindowManager;
IWindowManager* CreateWindowManager();
} // namespace OpenRCT2::Ui
diff --git a/src/openrct2-ui/audio/AudioContext.h b/src/openrct2-ui/audio/AudioContext.h
index 24c03684a2..0fe4a17def 100644
--- a/src/openrct2-ui/audio/AudioContext.h
+++ b/src/openrct2-ui/audio/AudioContext.h
@@ -21,7 +21,7 @@ using SpeexResamplerState = struct SpeexResamplerState_;
namespace OpenRCT2::Audio
{
struct AudioFormat;
- interface IAudioContext;
+ struct IAudioContext;
#pragma pack(push, 1)
struct WaveFormat
@@ -48,16 +48,16 @@ namespace OpenRCT2::Audio
assert_struct_size(WaveFormatEx, 18);
#pragma pack(pop)
- interface ISDLAudioSource : public IAudioSource
+ struct ISDLAudioSource : public IAudioSource
{
[[nodiscard]] virtual AudioFormat GetFormat() const abstract;
};
- interface ISDLAudioChannel : public IAudioChannel
+ struct ISDLAudioChannel : public IAudioChannel
{
[[nodiscard]] virtual AudioFormat GetFormat() const abstract;
[[nodiscard]] virtual SpeexResamplerState* GetResampler() const abstract;
- virtual void SetResampler(SpeexResamplerState * value) abstract;
+ virtual void SetResampler(SpeexResamplerState* value) abstract;
};
namespace AudioSource
diff --git a/src/openrct2-ui/drawing/engines/DrawingEngineFactory.hpp b/src/openrct2-ui/drawing/engines/DrawingEngineFactory.hpp
index 7bf3859513..d57fd421fc 100644
--- a/src/openrct2-ui/drawing/engines/DrawingEngineFactory.hpp
+++ b/src/openrct2-ui/drawing/engines/DrawingEngineFactory.hpp
@@ -19,7 +19,7 @@ namespace OpenRCT2
{
using namespace OpenRCT2::Drawing;
- interface IUiContext;
+ struct IUiContext;
std::unique_ptr CreateSoftwareDrawingEngine(const std::shared_ptr& uiContext);
std::unique_ptr CreateHardwareDisplayDrawingEngine(const std::shared_ptr& uiContext);
diff --git a/src/openrct2-ui/input/KeyboardShortcuts.h b/src/openrct2-ui/input/KeyboardShortcuts.h
index 74a5e04196..d3d8cee1a5 100644
--- a/src/openrct2-ui/input/KeyboardShortcuts.h
+++ b/src/openrct2-ui/input/KeyboardShortcuts.h
@@ -123,7 +123,7 @@ enum KeyboardShortcut
namespace OpenRCT2
{
- interface IPlatformEnvironment;
+ struct IPlatformEnvironment;
namespace Input
{
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/title/TitleSequencePlayer.h b/src/openrct2-ui/title/TitleSequencePlayer.h
index 15d9f21d29..77699d47fa 100644
--- a/src/openrct2-ui/title/TitleSequencePlayer.h
+++ b/src/openrct2-ui/title/TitleSequencePlayer.h
@@ -12,8 +12,8 @@
#include
#include
-interface ITitleSequencePlayer;
-interface IScenarioRepository;
+struct ITitleSequencePlayer;
+struct IScenarioRepository;
namespace OpenRCT2
{
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-win/openrct2-win.cpp b/src/openrct2-win/openrct2-win.cpp
index 4ba50c15f0..8372e1c682 100644
--- a/src/openrct2-win/openrct2-win.cpp
+++ b/src/openrct2-win/openrct2-win.cpp
@@ -8,7 +8,6 @@
*****************************************************************************/
// Windows.h needs to be included first
-#define WIN32_LEAN_AND_MEAN
#include
// Enable visual styles
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 d517b00476..9111642757 100644
--- a/src/openrct2/Context.h
+++ b/src/openrct2/Context.h
@@ -15,12 +15,15 @@
#include
#include
-interface IObjectManager;
-interface IObjectRepository;
-interface IScenarioRepository;
-interface IStream;
-interface ITrackDesignRepository;
-interface IGameStateSnapshots;
+struct IObjectManager;
+struct IObjectRepository;
+struct IScenarioRepository;
+namespace OpenRCT2
+{
+ struct IStream;
+}
+struct ITrackDesignRepository;
+struct IGameStateSnapshots;
class Intent;
struct rct_window;
@@ -67,17 +70,17 @@ namespace OpenRCT2
{
class GameState;
- interface IPlatformEnvironment;
- interface IReplayManager;
+ struct IPlatformEnvironment;
+ struct IReplayManager;
namespace Audio
{
- interface IAudioContext;
+ struct IAudioContext;
}
namespace Drawing
{
- interface IDrawingEngine;
+ struct IDrawingEngine;
}
namespace Localisation
@@ -92,18 +95,18 @@ namespace OpenRCT2
namespace Ui
{
- interface IUiContext;
+ struct IUiContext;
}
namespace Paint
{
- interface Painter;
+ struct Painter;
}
/**
* Represents an instance of OpenRCT2 and can be used to get various services.
*/
- interface IContext
+ struct IContext
{
virtual ~IContext() = default;
@@ -131,8 +134,8 @@ namespace OpenRCT2
virtual void InitialiseDrawingEngine() abstract;
virtual void DisposeDrawingEngine() abstract;
virtual bool LoadParkFromFile(const std::string& path, bool loadTitleScreenOnFail = false) abstract;
- virtual bool LoadParkFromStream(IStream * stream, const std::string& path, bool loadTitleScreenFirstOnFail = false)
- abstract;
+ virtual bool LoadParkFromStream(
+ IStream* stream, const std::string& path, bool loadTitleScreenFirstOnFail = false) abstract;
virtual void WriteLine(const std::string& s) abstract;
virtual void Finish() abstract;
virtual void Quit() abstract;
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 49038ed612..ecf9ced3b2 100644
--- a/src/openrct2/FileClassifier.h
+++ b/src/openrct2/FileClassifier.h
@@ -25,7 +25,10 @@ enum
#include
-interface IStream;
+namespace OpenRCT2
+{
+ struct 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/GameStateSnapshots.h b/src/openrct2/GameStateSnapshots.h
index 7daa87ec37..e978851a62 100644
--- a/src/openrct2/GameStateSnapshots.h
+++ b/src/openrct2/GameStateSnapshots.h
@@ -60,7 +60,7 @@ struct GameStateCompareData_t
* as it may become invalid at any time when a snapshot is created, rather Link the snapshot
* to a specific tick which can be obtained by that later again assuming its still valid.
*/
-interface IGameStateSnapshots
+struct IGameStateSnapshots
{
virtual ~IGameStateSnapshots() = default;
@@ -77,12 +77,12 @@ interface IGameStateSnapshots
/*
* Links the snapshot to a specific game tick.
*/
- virtual void LinkSnapshot(GameStateSnapshot_t & snapshot, uint32_t tick, uint32_t srand0) = 0;
+ virtual void LinkSnapshot(GameStateSnapshot_t& snapshot, uint32_t tick, uint32_t srand0) = 0;
/*
* This will fill the snapshot with the current game state in a compact form.
*/
- virtual void Capture(GameStateSnapshot_t & snapshot) = 0;
+ virtual void Capture(GameStateSnapshot_t& snapshot) = 0;
/*
* Returns the snapshot for a given tick in the history, nullptr if not found.
@@ -92,7 +92,7 @@ interface IGameStateSnapshots
/*
* Serialisation of GameStateSnapshot_t
*/
- virtual void SerialiseSnapshot(GameStateSnapshot_t & snapshot, DataSerialiser & serialiser) const = 0;
+ virtual void SerialiseSnapshot(GameStateSnapshot_t& snapshot, DataSerialiser& serialiser) const = 0;
/*
* Compares two states resulting GameStateCompareData_t with all mismatches stored.
diff --git a/src/openrct2/ParkImporter.h b/src/openrct2/ParkImporter.h
index ccff5381c9..f887979b63 100644
--- a/src/openrct2/ParkImporter.h
+++ b/src/openrct2/ParkImporter.h
@@ -17,9 +17,13 @@
#include
#include
-interface IObjectManager;
-interface IObjectRepository;
-interface IStream;
+struct IObjectManager;
+struct IObjectRepository;
+namespace OpenRCT2
+{
+ struct IStream;
+}
+
struct scenario_index_entry;
struct ParkLoadResult final
@@ -36,7 +40,7 @@ public:
/**
* Interface to import scenarios and saved games.
*/
-interface IParkImporter
+struct IParkImporter
{
public:
virtual ~IParkImporter() = default;
@@ -45,10 +49,10 @@ 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;
+ virtual bool GetDetails(scenario_index_entry* dst) abstract;
};
namespace ParkImporter
diff --git a/src/openrct2/PlatformEnvironment.h b/src/openrct2/PlatformEnvironment.h
index 15a737fda8..fdd1dcdeb9 100644
--- a/src/openrct2/PlatformEnvironment.h
+++ b/src/openrct2/PlatformEnvironment.h
@@ -72,7 +72,7 @@ namespace OpenRCT2
/**
* Interface for retrieving paths and other environment related things.
*/
- interface IPlatformEnvironment
+ struct IPlatformEnvironment
{
virtual ~IPlatformEnvironment() = default;
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/ReplayManager.h b/src/openrct2/ReplayManager.h
index 1069a58f06..d635147008 100644
--- a/src/openrct2/ReplayManager.h
+++ b/src/openrct2/ReplayManager.h
@@ -32,7 +32,7 @@ namespace OpenRCT2
std::string FilePath;
};
- interface IReplayManager
+ struct IReplayManager
{
public:
enum class RecordType
@@ -56,7 +56,7 @@ namespace OpenRCT2
const std::string& name, uint32_t maxTicks = k_MaxReplayTicks, RecordType rt = RecordType::NORMAL)
= 0;
virtual bool StopRecording(bool discard = false) = 0;
- virtual bool GetCurrentReplayInfo(ReplayRecordInfo & info) const = 0;
+ virtual bool GetCurrentReplayInfo(ReplayRecordInfo& info) const = 0;
virtual bool StartPlayback(const std::string& file) = 0;
virtual bool IsPlaybackStateMismatching() const = 0;
diff --git a/src/openrct2/TrackImporter.h b/src/openrct2/TrackImporter.h
index 22fcd1aba8..677228dc1a 100644
--- a/src/openrct2/TrackImporter.h
+++ b/src/openrct2/TrackImporter.h
@@ -20,13 +20,13 @@
/**
* Interface to import scenarios and saved games.
*/
-interface ITrackImporter
+struct ITrackImporter
{
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/audio/AudioChannel.h b/src/openrct2/audio/AudioChannel.h
index 0470e82263..ec8619f622 100644
--- a/src/openrct2/audio/AudioChannel.h
+++ b/src/openrct2/audio/AudioChannel.h
@@ -14,13 +14,13 @@
namespace OpenRCT2::Audio
{
- interface IAudioSource;
+ struct IAudioSource;
/**
* Represents an audio channel that represents an audio source
* and a number of properties such as volume, pan and loop information.
*/
- interface IAudioChannel
+ struct IAudioChannel
{
virtual ~IAudioChannel() = default;
@@ -62,7 +62,7 @@ namespace OpenRCT2::Audio
virtual bool IsPlaying() const abstract;
- virtual void Play(IAudioSource * source, int32_t loop = 0) abstract;
+ virtual void Play(IAudioSource* source, int32_t loop = 0) abstract;
virtual void UpdateOldVolume() abstract;
virtual size_t Read(void* dst, size_t len) abstract;
diff --git a/src/openrct2/audio/AudioContext.h b/src/openrct2/audio/AudioContext.h
index b54d7e9e6a..5725503af8 100644
--- a/src/openrct2/audio/AudioContext.h
+++ b/src/openrct2/audio/AudioContext.h
@@ -17,14 +17,14 @@
namespace OpenRCT2::Audio
{
- interface IAudioChannel;
- interface IAudioMixer;
- interface IAudioSource;
+ struct IAudioChannel;
+ struct IAudioMixer;
+ struct IAudioSource;
/**
* Audio services for playing music and sound effects.
*/
- interface IAudioContext
+ struct IAudioContext
{
virtual ~IAudioContext() = default;
diff --git a/src/openrct2/audio/AudioMixer.h b/src/openrct2/audio/AudioMixer.h
index a97d071136..1d94d635ef 100644
--- a/src/openrct2/audio/AudioMixer.h
+++ b/src/openrct2/audio/AudioMixer.h
@@ -26,13 +26,13 @@ namespace OpenRCT2::Audio
TitleMusic,
};
- interface IAudioSource;
- interface IAudioChannel;
+ struct IAudioSource;
+ struct IAudioChannel;
/**
* Provides an audio stream by mixing multiple audio channels together.
*/
- interface IAudioMixer
+ struct IAudioMixer
{
virtual ~IAudioMixer() = default;
@@ -40,8 +40,8 @@ namespace OpenRCT2::Audio
virtual void Close() abstract;
virtual void Lock() abstract;
virtual void Unlock() abstract;
- virtual IAudioChannel* Play(IAudioSource * source, int32_t loop, bool deleteondone, bool deletesourceondone) abstract;
- virtual void Stop(IAudioChannel * channel) abstract;
+ virtual IAudioChannel* Play(IAudioSource* source, int32_t loop, bool deleteondone, bool deletesourceondone) abstract;
+ virtual void Stop(IAudioChannel* channel) abstract;
virtual bool LoadMusic(size_t pathid) abstract;
virtual void SetVolume(float volume) abstract;
diff --git a/src/openrct2/audio/AudioSource.h b/src/openrct2/audio/AudioSource.h
index 60df6c06a5..98a5350e44 100644
--- a/src/openrct2/audio/AudioSource.h
+++ b/src/openrct2/audio/AudioSource.h
@@ -17,7 +17,7 @@ namespace OpenRCT2::Audio
/**
* Represents a readable source of audio PCM data.
*/
- interface IAudioSource
+ struct IAudioSource
{
virtual ~IAudioSource() = default;
diff --git a/src/openrct2/common.h b/src/openrct2/common.h
index db41a4caba..dc284a5f3c 100644
--- a/src/openrct2/common.h
+++ b/src/openrct2/common.h
@@ -165,9 +165,6 @@ using rct_string_id = uint16_t;
(x) = nullptr; \
} while (false)
-#ifndef interface
-# define interface struct
-#endif
#define abstract = 0
#if defined(__GNUC__) && (defined(__x86_64__) || defined(__i386__))
diff --git a/src/openrct2/config/ConfigEnum.hpp b/src/openrct2/config/ConfigEnum.hpp
index 04b4398a0e..d598047c8d 100644
--- a/src/openrct2/config/ConfigEnum.hpp
+++ b/src/openrct2/config/ConfigEnum.hpp
@@ -27,7 +27,7 @@ template struct ConfigEnumEntry
}
};
-template interface IConfigEnum
+template struct IConfigEnum
{
virtual ~IConfigEnum() = default;
virtual std::string GetName(T value) const abstract;
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 b8c272b3dc..741c090525 100644
--- a/src/openrct2/config/IniReader.hpp
+++ b/src/openrct2/config/IniReader.hpp
@@ -13,10 +13,14 @@
#include
-interface IStream;
+namespace OpenRCT2
+{
+ struct IStream;
+}
+
template struct IConfigEnum;
-interface IIniReader
+struct IIniReader
{
virtual ~IIniReader() = default;
@@ -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 0329503423..644974f06b 100644
--- a/src/openrct2/config/IniWriter.hpp
+++ b/src/openrct2/config/IniWriter.hpp
@@ -13,10 +13,14 @@
#include
-interface IStream;
+namespace OpenRCT2
+{
+ struct IStream;
+}
+
template struct IConfigEnum;
-interface IIniWriter
+struct IIniWriter
{
virtual ~IIniWriter() = default;
@@ -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/Crypt.CNG.cpp b/src/openrct2/core/Crypt.CNG.cpp
index ca35f4667d..0c5640cf59 100644
--- a/src/openrct2/core/Crypt.CNG.cpp
+++ b/src/openrct2/core/Crypt.CNG.cpp
@@ -21,7 +21,6 @@
// clang-format off
// CNG: Cryptography API: Next Generation (CNG)
// available in Windows Vista onwards.
-#define WIN32_LEAN_AND_MEAN
#include
#include
#include
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/Diagnostics.cpp b/src/openrct2/core/Diagnostics.cpp
index a56b6bcae3..3cc20bad96 100644
--- a/src/openrct2/core/Diagnostics.cpp
+++ b/src/openrct2/core/Diagnostics.cpp
@@ -8,7 +8,6 @@
*****************************************************************************/
#if defined(DEBUG) && defined(_WIN32)
-# define WIN32_LEAN_AND_MEAN
# include
#endif
diff --git a/src/openrct2/core/File.cpp b/src/openrct2/core/File.cpp
index e87bc7c268..7143b671ea 100644
--- a/src/openrct2/core/File.cpp
+++ b/src/openrct2/core/File.cpp
@@ -8,7 +8,6 @@
*****************************************************************************/
#ifdef _WIN32
-# define WIN32_LEAN_AND_MEAN
# include
#else
# include
@@ -88,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/FileScanner.cpp b/src/openrct2/core/FileScanner.cpp
index f1e6fa835e..a0f91feb86 100644
--- a/src/openrct2/core/FileScanner.cpp
+++ b/src/openrct2/core/FileScanner.cpp
@@ -10,7 +10,6 @@
#include "../common.h"
#ifdef _WIN32
-# define WIN32_LEAN_AND_MEAN
# include
#endif
diff --git a/src/openrct2/core/FileScanner.h b/src/openrct2/core/FileScanner.h
index bcde6f2cdb..f3136e48f4 100644
--- a/src/openrct2/core/FileScanner.h
+++ b/src/openrct2/core/FileScanner.h
@@ -21,7 +21,7 @@ struct FileInfo
uint64_t LastModified;
};
-interface IFileScanner
+struct IFileScanner
{
virtual ~IFileScanner() = default;
diff --git a/src/openrct2/core/FileStream.hpp b/src/openrct2/core/FileStream.hpp
index fa0412837f..c683f84401 100644
--- a/src/openrct2/core/FileStream.hpp
+++ b/src/openrct2/core/FileStream.hpp
@@ -29,170 +29,174 @@
# define fseeko _fseeki64
#endif
-enum
+namespace OpenRCT2
{
- FILE_MODE_OPEN,
- FILE_MODE_WRITE,
- FILE_MODE_APPEND,
-};
-
-/**
- * A stream for reading and writing to files.
- */
-class FileStream final : public IStream
-{
-private:
- FILE* _file = nullptr;
- bool _ownsFilePtr = false;
- bool _canRead = false;
- bool _canWrite = false;
- bool _disposed = false;
- uint64_t _fileSize = 0;
-
-public:
- FileStream(const std::string& path, int32_t fileMode)
- : FileStream(path.c_str(), fileMode)
+ enum
{
- }
+ FILE_MODE_OPEN,
+ FILE_MODE_WRITE,
+ FILE_MODE_APPEND,
+ };
- FileStream(const utf8* path, int32_t fileMode)
+ /**
+ * A stream for reading and writing to files.
+ */
+ class FileStream final : public IStream
{
- const char* mode;
- switch (fileMode)
+ private:
+ FILE* _file = nullptr;
+ bool _ownsFilePtr = false;
+ bool _canRead = false;
+ bool _canWrite = false;
+ bool _disposed = false;
+ uint64_t _fileSize = 0;
+
+ public:
+ FileStream(const std::string& path, int32_t fileMode)
+ : FileStream(path.c_str(), fileMode)
{
- case FILE_MODE_OPEN:
- mode = "rb";
- _canRead = true;
- _canWrite = false;
- break;
- case FILE_MODE_WRITE:
- mode = "w+b";
- _canRead = true;
- _canWrite = true;
- break;
- case FILE_MODE_APPEND:
- mode = "a";
- _canRead = false;
- _canWrite = true;
- break;
- default:
- throw;
}
-#ifdef _WIN32
- auto pathW = String::ToWideChar(path);
- auto modeW = String::ToWideChar(mode);
- _file = _wfopen(pathW.c_str(), modeW.c_str());
-#else
- if (fileMode == FILE_MODE_OPEN)
+ FileStream(const utf8* path, int32_t fileMode)
{
- struct stat fileStat;
- // Only allow regular files to be opened as its possible to open directories.
- if (stat(path, &fileStat) == 0 && S_ISREG(fileStat.st_mode))
+ const char* mode;
+ switch (fileMode)
+ {
+ case FILE_MODE_OPEN:
+ mode = "rb";
+ _canRead = true;
+ _canWrite = false;
+ break;
+ case FILE_MODE_WRITE:
+ mode = "w+b";
+ _canRead = true;
+ _canWrite = true;
+ break;
+ case FILE_MODE_APPEND:
+ mode = "a";
+ _canRead = false;
+ _canWrite = true;
+ break;
+ default:
+ throw;
+ }
+
+#ifdef _WIN32
+ auto pathW = String::ToWideChar(path);
+ auto modeW = String::ToWideChar(mode);
+ _file = _wfopen(pathW.c_str(), modeW.c_str());
+#else
+ if (fileMode == FILE_MODE_OPEN)
+ {
+ struct stat fileStat;
+ // Only allow regular files to be opened as its possible to open directories.
+ if (stat(path, &fileStat) == 0 && S_ISREG(fileStat.st_mode))
+ {
+ _file = fopen(path, mode);
+ }
+ }
+ else
{
_file = fopen(path, mode);
}
- }
- else
- {
- _file = fopen(path, mode);
- }
#endif
- if (_file == nullptr)
- {
- throw IOException(String::StdFormat("Unable to open '%s'", path));
+ if (_file == nullptr)
+ {
+ throw IOException(String::StdFormat("Unable to open '%s'", path));
+ }
+
+ Seek(0, STREAM_SEEK_END);
+ _fileSize = GetPosition();
+ Seek(0, STREAM_SEEK_BEGIN);
+
+ _ownsFilePtr = true;
}
- Seek(0, STREAM_SEEK_END);
- _fileSize = GetPosition();
- Seek(0, STREAM_SEEK_BEGIN);
-
- _ownsFilePtr = true;
- }
-
- ~FileStream() override
- {
- if (!_disposed)
+ ~FileStream() override
{
- _disposed = true;
- if (_ownsFilePtr)
+ if (!_disposed)
{
- fclose(_file);
+ _disposed = true;
+ if (_ownsFilePtr)
+ {
+ fclose(_file);
+ }
}
}
- }
- bool CanRead() const override
- {
- return _canRead;
- }
- bool CanWrite() const override
- {
- return _canWrite;
- }
-
- uint64_t GetLength() const override
- {
- return _fileSize;
- }
- uint64_t GetPosition() const override
- {
- return ftello(_file);
- }
-
- void SetPosition(uint64_t position) override
- {
- Seek(position, STREAM_SEEK_BEGIN);
- }
-
- void Seek(int64_t offset, int32_t origin) override
- {
- switch (origin)
+ bool CanRead() const override
{
- case STREAM_SEEK_BEGIN:
- fseeko(_file, offset, SEEK_SET);
- break;
- case STREAM_SEEK_CURRENT:
- fseeko(_file, offset, SEEK_CUR);
- break;
- case STREAM_SEEK_END:
- fseeko(_file, offset, SEEK_END);
- break;
+ return _canRead;
}
- }
-
- void Read(void* buffer, uint64_t length) override
- {
- uint64_t remainingBytes = GetLength() - GetPosition();
- if (length <= remainingBytes)
+ bool CanWrite() const override
{
- if (fread(buffer, static_cast(length), 1, _file) == 1)
+ return _canWrite;
+ }
+
+ uint64_t GetLength() const override
+ {
+ return _fileSize;
+ }
+ uint64_t GetPosition() const override
+ {
+ return ftello(_file);
+ }
+
+ void SetPosition(uint64_t position) override
+ {
+ Seek(position, STREAM_SEEK_BEGIN);
+ }
+
+ void Seek(int64_t offset, int32_t origin) override
+ {
+ switch (origin)
{
- return;
+ case STREAM_SEEK_BEGIN:
+ fseeko(_file, offset, SEEK_SET);
+ break;
+ case STREAM_SEEK_CURRENT:
+ fseeko(_file, offset, SEEK_CUR);
+ break;
+ case STREAM_SEEK_END:
+ fseeko(_file, offset, SEEK_END);
+ break;
}
}
- throw IOException("Attempted to read past end of file.");
- }
- void Write(const void* buffer, uint64_t length) override
- {
- if (fwrite(buffer, static_cast(length), 1, _file) != 1)
+ void Read(void* buffer, uint64_t length) override
{
- throw IOException("Unable to write to file.");
+ uint64_t remainingBytes = GetLength() - GetPosition();
+ if (length <= remainingBytes)
+ {
+ if (fread(buffer, static_cast(length), 1, _file) == 1)
+ {
+ return;
+ }
+ }
+ throw IOException("Attempted to read past end of file.");
}
- uint64_t position = GetPosition();
- _fileSize = std::max(_fileSize, position);
- }
+ void Write(const void* buffer, uint64_t length) override
+ {
+ if (fwrite(buffer, static_cast(length), 1, _file) != 1)
+ {
+ throw IOException("Unable to write to file.");
+ }
- uint64_t TryRead(void* buffer, uint64_t length) override
- {
- size_t readBytes = fread(buffer, 1, static_cast(length), _file);
- return readBytes;
- }
+ uint64_t position = GetPosition();
+ _fileSize = std::max(_fileSize, position);
+ }
- const void* GetData() const override
- {
- return nullptr;
- }
-};
+ uint64_t TryRead(void* buffer, uint64_t length) override
+ {
+ size_t readBytes = fread(buffer, 1, static_cast(length), _file);
+ return readBytes;
+ }
+
+ const void* GetData() const override
+ {
+ return nullptr;
+ }
+ };
+
+} // namespace OpenRCT2
diff --git a/src/openrct2/core/FileWatcher.cpp b/src/openrct2/core/FileWatcher.cpp
index 2d8d6f5839..6be551ac51 100644
--- a/src/openrct2/core/FileWatcher.cpp
+++ b/src/openrct2/core/FileWatcher.cpp
@@ -12,7 +12,6 @@
#include
#ifdef _WIN32
-# define WIN32_LEAN_AND_MEAN
# include
#elif defined(__linux__)
# include
diff --git a/src/openrct2/core/Guard.cpp b/src/openrct2/core/Guard.cpp
index aaaf0f8c6e..95a9790275 100644
--- a/src/openrct2/core/Guard.cpp
+++ b/src/openrct2/core/Guard.cpp
@@ -8,7 +8,6 @@
*****************************************************************************/
#ifdef _WIN32
-# define WIN32_LEAN_AND_MEAN
# include
#endif
diff --git a/src/openrct2/core/Http.WinHttp.cpp b/src/openrct2/core/Http.WinHttp.cpp
index 41c4de4ce0..a84c89d5bb 100644
--- a/src/openrct2/core/Http.WinHttp.cpp
+++ b/src/openrct2/core/Http.WinHttp.cpp
@@ -16,7 +16,6 @@
# include
# include
-# define WIN32_LEAN_AND_MEAN
# include
# include
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..b3d729c4d6 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)
+ struct 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