From 30376085cf858613957c755698e616deabce1456 Mon Sep 17 00:00:00 2001 From: Matt Date: Thu, 30 Jul 2020 22:18:23 +0200 Subject: [PATCH] Include missing headers --- src/openrct2-ui/UiContext.Win32.cpp | 4 + src/openrct2-ui/UiContext.h | 8 +- src/openrct2-ui/WindowManager.h | 2 +- src/openrct2-ui/audio/AudioContext.h | 6 +- .../drawing/engines/DrawingEngineFactory.hpp | 2 +- src/openrct2-ui/input/KeyboardShortcuts.h | 2 +- src/openrct2-ui/title/TitleSequencePlayer.h | 4 +- src/openrct2-win/openrct2-win.cpp | 1 - src/openrct2/Context.h | 26 +- src/openrct2/FileClassifier.h | 2 +- src/openrct2/GameStateSnapshots.h | 2 +- src/openrct2/ParkImporter.h | 8 +- src/openrct2/PlatformEnvironment.h | 2 +- src/openrct2/ReplayManager.h | 2 +- src/openrct2/TrackImporter.h | 2 +- src/openrct2/audio/AudioChannel.h | 4 +- src/openrct2/audio/AudioContext.h | 8 +- src/openrct2/audio/AudioMixer.h | 6 +- src/openrct2/audio/AudioSource.h | 2 +- src/openrct2/common.h | 4 +- src/openrct2/config/ConfigEnum.hpp | 2 +- src/openrct2/config/IniReader.hpp | 4 +- src/openrct2/config/IniWriter.hpp | 4 +- src/openrct2/core/Crypt.CNG.cpp | 1 - src/openrct2/core/File.cpp | 1 - src/openrct2/core/FileScanner.cpp | 1 - src/openrct2/core/FileScanner.h | 2 +- src/openrct2/core/FileStream.hpp | 276 +++++++++--------- src/openrct2/core/FileWatcher.cpp | 1 - src/openrct2/core/Guard.cpp | 1 - src/openrct2/core/Http.WinHttp.cpp | 1 - src/openrct2/core/Registration.hpp | 2 +- src/openrct2/core/String.cpp | 4 - src/openrct2/core/StringReader.hpp | 2 +- src/openrct2/core/Zip.h | 2 +- src/openrct2/drawing/Drawing.h | 4 +- src/openrct2/drawing/IDrawingContext.h | 4 +- src/openrct2/drawing/IDrawingEngine.h | 10 +- src/openrct2/drawing/Rain.h | 2 +- src/openrct2/drawing/X8DrawingEngine.h | 2 +- src/openrct2/localisation/LanguagePack.h | 2 +- .../localisation/LocalisationService.h | 6 +- src/openrct2/network/NetworkKey.h | 2 +- .../network/NetworkServerAdvertiser.h | 2 +- src/openrct2/network/Socket.h | 6 +- src/openrct2/network/network.h | 2 +- src/openrct2/object/ImageTable.h | 4 +- src/openrct2/object/Object.h | 6 +- src/openrct2/object/ObjectFactory.cpp | 2 +- src/openrct2/object/ObjectFactory.h | 2 +- src/openrct2/object/ObjectManager.h | 4 +- src/openrct2/object/ObjectRepository.h | 6 +- src/openrct2/object/StringTable.h | 4 +- src/openrct2/paint/Painter.h | 6 +- src/openrct2/platform/Platform.Win32.cpp | 2 +- src/openrct2/platform/Shared.cpp | 1 - src/openrct2/platform/Windows.cpp | 3 + src/openrct2/rct12/SawyerChunkReader.h | 2 +- src/openrct2/rct12/SawyerChunkWriter.h | 2 +- src/openrct2/rct12/SawyerEncoding.h | 2 +- src/openrct2/rct2/S6Exporter.h | 2 +- src/openrct2/rct2/T6Exporter.h | 2 +- src/openrct2/ride/Ride.h | 2 +- src/openrct2/ride/TrackDesignRepository.h | 4 +- src/openrct2/scenario/ScenarioRepository.h | 4 +- src/openrct2/scripting/ScriptEngine.h | 2 +- src/openrct2/title/TitleScreen.h | 2 +- src/openrct2/title/TitleSequencePlayer.h | 2 +- src/openrct2/ui/UiContext.h | 10 +- src/openrct2/ui/WindowManager.h | 2 +- 70 files changed, 260 insertions(+), 261 deletions(-) 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..7728ae9b15 100644 --- a/src/openrct2-ui/UiContext.h +++ b/src/openrct2-ui/UiContext.h @@ -17,16 +17,16 @@ struct SDL_Window; namespace OpenRCT2 { - interface IContext; - interface IPlatformEnvironment; + INTERFACE IContext; + INTERFACE IPlatformEnvironment; namespace Ui { struct FileDialogDesc; class InGameConsole; - interface IUiContext; + INTERFACE IUiContext; - interface IPlatformUiContext + INTERFACE IPlatformUiContext { virtual ~IPlatformUiContext() = default; virtual void SetWindowIcon(SDL_Window * window) abstract; diff --git a/src/openrct2-ui/WindowManager.h b/src/openrct2-ui/WindowManager.h index 16cf0ac9c9..5bb0f36fe8 100644 --- a/src/openrct2-ui/WindowManager.h +++ b/src/openrct2-ui/WindowManager.h @@ -13,7 +13,7 @@ namespace OpenRCT2::Ui { - interface IWindowManager; + INTERFACE IWindowManager; IWindowManager* CreateWindowManager(); } // namespace OpenRCT2::Ui diff --git a/src/openrct2-ui/audio/AudioContext.h b/src/openrct2-ui/audio/AudioContext.h index 24c03684a2..03ad0ece07 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; + INTERFACE IAudioContext; #pragma pack(push, 1) struct WaveFormat @@ -48,12 +48,12 @@ namespace OpenRCT2::Audio assert_struct_size(WaveFormatEx, 18); #pragma pack(pop) - interface ISDLAudioSource : public IAudioSource + INTERFACE ISDLAudioSource : public IAudioSource { [[nodiscard]] virtual AudioFormat GetFormat() const abstract; }; - interface ISDLAudioChannel : public IAudioChannel + INTERFACE ISDLAudioChannel : public IAudioChannel { [[nodiscard]] virtual AudioFormat GetFormat() const abstract; [[nodiscard]] virtual SpeexResamplerState* GetResampler() const abstract; diff --git a/src/openrct2-ui/drawing/engines/DrawingEngineFactory.hpp b/src/openrct2-ui/drawing/engines/DrawingEngineFactory.hpp index 7bf3859513..c40c745bd9 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; + INTERFACE 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..ca7cacbf66 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; + INTERFACE IPlatformEnvironment; namespace Input { diff --git a/src/openrct2-ui/title/TitleSequencePlayer.h b/src/openrct2-ui/title/TitleSequencePlayer.h index 15d9f21d29..5585b1018e 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; +INTERFACE ITitleSequencePlayer; +INTERFACE IScenarioRepository; namespace OpenRCT2 { 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/Context.h b/src/openrct2/Context.h index d517b00476..69d6ebe956 100644 --- a/src/openrct2/Context.h +++ b/src/openrct2/Context.h @@ -15,12 +15,12 @@ #include #include -interface IObjectManager; -interface IObjectRepository; -interface IScenarioRepository; -interface IStream; -interface ITrackDesignRepository; -interface IGameStateSnapshots; +INTERFACE IObjectManager; +INTERFACE IObjectRepository; +INTERFACE IScenarioRepository; +INTERFACE IStream; +INTERFACE ITrackDesignRepository; +INTERFACE IGameStateSnapshots; class Intent; struct rct_window; @@ -67,17 +67,17 @@ namespace OpenRCT2 { class GameState; - interface IPlatformEnvironment; - interface IReplayManager; + INTERFACE IPlatformEnvironment; + INTERFACE IReplayManager; namespace Audio { - interface IAudioContext; + INTERFACE IAudioContext; } namespace Drawing { - interface IDrawingEngine; + INTERFACE IDrawingEngine; } namespace Localisation @@ -92,18 +92,18 @@ namespace OpenRCT2 namespace Ui { - interface IUiContext; + INTERFACE IUiContext; } namespace Paint { - interface Painter; + INTERFACE Painter; } /** * Represents an instance of OpenRCT2 and can be used to get various services. */ - interface IContext + INTERFACE IContext { virtual ~IContext() = default; diff --git a/src/openrct2/FileClassifier.h b/src/openrct2/FileClassifier.h index 49038ed612..a164167836 100644 --- a/src/openrct2/FileClassifier.h +++ b/src/openrct2/FileClassifier.h @@ -25,7 +25,7 @@ enum #include -interface IStream; +INTERFACE IStream; enum class FILE_TYPE { diff --git a/src/openrct2/GameStateSnapshots.h b/src/openrct2/GameStateSnapshots.h index 7daa87ec37..1b27801c3c 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 +INTERFACE IGameStateSnapshots { virtual ~IGameStateSnapshots() = default; diff --git a/src/openrct2/ParkImporter.h b/src/openrct2/ParkImporter.h index ccff5381c9..b402325adb 100644 --- a/src/openrct2/ParkImporter.h +++ b/src/openrct2/ParkImporter.h @@ -17,9 +17,9 @@ #include #include -interface IObjectManager; -interface IObjectRepository; -interface IStream; +INTERFACE IObjectManager; +INTERFACE IObjectRepository; +INTERFACE IStream; struct scenario_index_entry; struct ParkLoadResult final @@ -36,7 +36,7 @@ public: /** * Interface to import scenarios and saved games. */ -interface IParkImporter +INTERFACE IParkImporter { public: virtual ~IParkImporter() = default; diff --git a/src/openrct2/PlatformEnvironment.h b/src/openrct2/PlatformEnvironment.h index 15a737fda8..6a84f00c65 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 + INTERFACE IPlatformEnvironment { virtual ~IPlatformEnvironment() = default; diff --git a/src/openrct2/ReplayManager.h b/src/openrct2/ReplayManager.h index 1069a58f06..f7fa785dd9 100644 --- a/src/openrct2/ReplayManager.h +++ b/src/openrct2/ReplayManager.h @@ -32,7 +32,7 @@ namespace OpenRCT2 std::string FilePath; }; - interface IReplayManager + INTERFACE IReplayManager { public: enum class RecordType diff --git a/src/openrct2/TrackImporter.h b/src/openrct2/TrackImporter.h index 22fcd1aba8..cbd6194fba 100644 --- a/src/openrct2/TrackImporter.h +++ b/src/openrct2/TrackImporter.h @@ -20,7 +20,7 @@ /** * Interface to import scenarios and saved games. */ -interface ITrackImporter +INTERFACE ITrackImporter { public: virtual ~ITrackImporter() = default; diff --git a/src/openrct2/audio/AudioChannel.h b/src/openrct2/audio/AudioChannel.h index 0470e82263..02e7517634 100644 --- a/src/openrct2/audio/AudioChannel.h +++ b/src/openrct2/audio/AudioChannel.h @@ -14,13 +14,13 @@ namespace OpenRCT2::Audio { - interface IAudioSource; + INTERFACE IAudioSource; /** * Represents an audio channel that represents an audio source * and a number of properties such as volume, pan and loop information. */ - interface IAudioChannel + INTERFACE IAudioChannel { virtual ~IAudioChannel() = default; diff --git a/src/openrct2/audio/AudioContext.h b/src/openrct2/audio/AudioContext.h index b54d7e9e6a..114a166045 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; + INTERFACE IAudioChannel; + INTERFACE IAudioMixer; + INTERFACE IAudioSource; /** * Audio services for playing music and sound effects. */ - interface IAudioContext + INTERFACE IAudioContext { virtual ~IAudioContext() = default; diff --git a/src/openrct2/audio/AudioMixer.h b/src/openrct2/audio/AudioMixer.h index a97d071136..0e36533c26 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; + INTERFACE IAudioSource; + INTERFACE IAudioChannel; /** * Provides an audio stream by mixing multiple audio channels together. */ - interface IAudioMixer + INTERFACE IAudioMixer { virtual ~IAudioMixer() = default; diff --git a/src/openrct2/audio/AudioSource.h b/src/openrct2/audio/AudioSource.h index 60df6c06a5..5c6b860edc 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 + INTERFACE IAudioSource { virtual ~IAudioSource() = default; diff --git a/src/openrct2/common.h b/src/openrct2/common.h index db41a4caba..ed6ec9a048 100644 --- a/src/openrct2/common.h +++ b/src/openrct2/common.h @@ -165,8 +165,8 @@ using rct_string_id = uint16_t; (x) = nullptr; \ } while (false) -#ifndef interface -# define interface struct +#ifndef INTERFACE +# define INTERFACE struct #endif #define abstract = 0 diff --git a/src/openrct2/config/ConfigEnum.hpp b/src/openrct2/config/ConfigEnum.hpp index 04b4398a0e..96fc4289e0 100644 --- a/src/openrct2/config/ConfigEnum.hpp +++ b/src/openrct2/config/ConfigEnum.hpp @@ -27,7 +27,7 @@ template struct ConfigEnumEntry } }; -template interface IConfigEnum +template INTERFACE IConfigEnum { virtual ~IConfigEnum() = default; virtual std::string GetName(T value) const abstract; diff --git a/src/openrct2/config/IniReader.hpp b/src/openrct2/config/IniReader.hpp index b8c272b3dc..2ae3c8c868 100644 --- a/src/openrct2/config/IniReader.hpp +++ b/src/openrct2/config/IniReader.hpp @@ -13,10 +13,10 @@ #include -interface IStream; +INTERFACE IStream; template struct IConfigEnum; -interface IIniReader +INTERFACE IIniReader { virtual ~IIniReader() = default; diff --git a/src/openrct2/config/IniWriter.hpp b/src/openrct2/config/IniWriter.hpp index 0329503423..bf10adfbe3 100644 --- a/src/openrct2/config/IniWriter.hpp +++ b/src/openrct2/config/IniWriter.hpp @@ -13,10 +13,10 @@ #include -interface IStream; +INTERFACE IStream; template struct IConfigEnum; -interface IIniWriter +INTERFACE IIniWriter { virtual ~IIniWriter() = default; 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/File.cpp b/src/openrct2/core/File.cpp index e87bc7c268..0c6c908792 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 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..62268e0eec 100644 --- a/src/openrct2/core/FileScanner.h +++ b/src/openrct2/core/FileScanner.h @@ -21,7 +21,7 @@ struct FileInfo uint64_t LastModified; }; -interface IFileScanner +INTERFACE IFileScanner { virtual ~IFileScanner() = default; diff --git a/src/openrct2/core/FileStream.hpp b/src/openrct2/core/FileStream.hpp index fa0412837f..d5144f87eb 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, IStream::SeekType origin) override + { + switch (origin) { - return; + case IStream::SeekType.STREAM_SEEK_BEGIN: + fseeko(_file, offset, SEEK_SET); + break; + case IStream::SeekType.STREAM_SEEK_CURRENT: + fseeko(_file, offset, SEEK_CUR); + break; + case IStream::SeekType.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/Registration.hpp b/src/openrct2/core/Registration.hpp index 59a2874404..97da307ef5 100644 --- a/src/openrct2/core/Registration.hpp +++ b/src/openrct2/core/Registration.hpp @@ -17,7 +17,7 @@ namespace OpenRCT2 * Represents a registration of some service which when deleted will be * unregistered. */ - interface IRegistration + INTERFACE IRegistration { virtual ~IRegistration() = default; }; diff --git a/src/openrct2/core/String.cpp b/src/openrct2/core/String.cpp index aacd1c4ac1..8a3e95e132 100644 --- a/src/openrct2/core/String.cpp +++ b/src/openrct2/core/String.cpp @@ -24,10 +24,6 @@ #endif #ifdef _WIN32 -# ifndef NOMINMAX -# define NOMINMAX -# endif -# define WIN32_LEAN_AND_MEAN # include #endif diff --git a/src/openrct2/core/StringReader.hpp b/src/openrct2/core/StringReader.hpp index ec2b9ec22e..d2d71e648c 100644 --- a/src/openrct2/core/StringReader.hpp +++ b/src/openrct2/core/StringReader.hpp @@ -14,7 +14,7 @@ #include "../util/Util.h" #include "String.hpp" -interface IStringReader +INTERFACE IStringReader { virtual ~IStringReader() = default; diff --git a/src/openrct2/core/Zip.h b/src/openrct2/core/Zip.h index 94e12c7e2b..327ba3e008 100644 --- a/src/openrct2/core/Zip.h +++ b/src/openrct2/core/Zip.h @@ -18,7 +18,7 @@ /** * Represents a zip file. */ -interface IZipArchive +INTERFACE IZipArchive { virtual ~IZipArchive() { diff --git a/src/openrct2/drawing/Drawing.h b/src/openrct2/drawing/Drawing.h index 2cbfa09f03..02f7910516 100644 --- a/src/openrct2/drawing/Drawing.h +++ b/src/openrct2/drawing/Drawing.h @@ -22,12 +22,12 @@ struct ScreenLine; struct ScreenRect; namespace OpenRCT2 { - interface IPlatformEnvironment; + INTERFACE IPlatformEnvironment; } namespace OpenRCT2::Drawing { - interface IDrawingEngine; + INTERFACE IDrawingEngine; } struct PaletteBGRA diff --git a/src/openrct2/drawing/IDrawingContext.h b/src/openrct2/drawing/IDrawingContext.h index d950f718f7..50feaa997b 100644 --- a/src/openrct2/drawing/IDrawingContext.h +++ b/src/openrct2/drawing/IDrawingContext.h @@ -14,9 +14,9 @@ namespace OpenRCT2::Drawing { - interface IDrawingEngine; + INTERFACE IDrawingEngine; - interface IDrawingContext + INTERFACE IDrawingContext { virtual ~IDrawingContext() { diff --git a/src/openrct2/drawing/IDrawingEngine.h b/src/openrct2/drawing/IDrawingEngine.h index 0c3c7f4aff..e811faec91 100644 --- a/src/openrct2/drawing/IDrawingEngine.h +++ b/src/openrct2/drawing/IDrawingEngine.h @@ -38,15 +38,15 @@ struct GamePalette; namespace OpenRCT2::Ui { - interface IUiContext; + INTERFACE IUiContext; } // namespace OpenRCT2::Ui namespace OpenRCT2::Drawing { enum class DRAWING_ENGINE_TYPE; - interface IDrawingContext; + INTERFACE IDrawingContext; - interface IDrawingEngine + INTERFACE IDrawingEngine { virtual ~IDrawingEngine() { @@ -75,7 +75,7 @@ namespace OpenRCT2::Drawing virtual void InvalidateImage(uint32_t image) abstract; }; - interface IDrawingEngineFactory + INTERFACE IDrawingEngineFactory { virtual ~IDrawingEngineFactory() { @@ -84,7 +84,7 @@ namespace OpenRCT2::Drawing DRAWING_ENGINE_TYPE type, const std::shared_ptr& uiContext) abstract; }; - interface IRainDrawer + INTERFACE IRainDrawer { virtual ~IRainDrawer() { diff --git a/src/openrct2/drawing/Rain.h b/src/openrct2/drawing/Rain.h index c4ea8684cf..9758d7c7d3 100644 --- a/src/openrct2/drawing/Rain.h +++ b/src/openrct2/drawing/Rain.h @@ -15,7 +15,7 @@ struct rct_drawpixelinfo; namespace OpenRCT2::Drawing { - interface IRainDrawer; + INTERFACE IRainDrawer; } // clang-format off diff --git a/src/openrct2/drawing/X8DrawingEngine.h b/src/openrct2/drawing/X8DrawingEngine.h index b913a50937..16353fbd0f 100644 --- a/src/openrct2/drawing/X8DrawingEngine.h +++ b/src/openrct2/drawing/X8DrawingEngine.h @@ -17,7 +17,7 @@ namespace OpenRCT2 { namespace Ui { - interface IUiContext; + INTERFACE IUiContext; } // namespace Ui namespace Drawing diff --git a/src/openrct2/localisation/LanguagePack.h b/src/openrct2/localisation/LanguagePack.h index 29db0cd165..26619d577a 100644 --- a/src/openrct2/localisation/LanguagePack.h +++ b/src/openrct2/localisation/LanguagePack.h @@ -14,7 +14,7 @@ #include #include -interface ILanguagePack +INTERFACE ILanguagePack { virtual ~ILanguagePack() = default; diff --git a/src/openrct2/localisation/LocalisationService.h b/src/openrct2/localisation/LocalisationService.h index 6bab2be10b..ffceaf6b82 100644 --- a/src/openrct2/localisation/LocalisationService.h +++ b/src/openrct2/localisation/LocalisationService.h @@ -17,12 +17,12 @@ #include #include -interface ILanguagePack; -interface IObjectManager; +INTERFACE ILanguagePack; +INTERFACE IObjectManager; namespace OpenRCT2 { - interface IPlatformEnvironment; + INTERFACE IPlatformEnvironment; } namespace OpenRCT2::Localisation diff --git a/src/openrct2/network/NetworkKey.h b/src/openrct2/network/NetworkKey.h index c083b42812..d8a584b3de 100644 --- a/src/openrct2/network/NetworkKey.h +++ b/src/openrct2/network/NetworkKey.h @@ -18,7 +18,7 @@ # include # include -interface IStream; +INTERFACE IStream; namespace Crypt { diff --git a/src/openrct2/network/NetworkServerAdvertiser.h b/src/openrct2/network/NetworkServerAdvertiser.h index 98a0ad7622..9153b8bad5 100644 --- a/src/openrct2/network/NetworkServerAdvertiser.h +++ b/src/openrct2/network/NetworkServerAdvertiser.h @@ -20,7 +20,7 @@ enum class ADVERTISE_STATUS REGISTERED, }; -interface INetworkServerAdvertiser +INTERFACE INetworkServerAdvertiser { virtual ~INetworkServerAdvertiser() { diff --git a/src/openrct2/network/Socket.h b/src/openrct2/network/Socket.h index 7cb8270d0a..102aab0038 100644 --- a/src/openrct2/network/Socket.h +++ b/src/openrct2/network/Socket.h @@ -35,7 +35,7 @@ enum NETWORK_READPACKET /** * Represents an address and port. */ -interface INetworkEndpoint +INTERFACE INetworkEndpoint { virtual ~INetworkEndpoint() { @@ -47,7 +47,7 @@ interface INetworkEndpoint /** * Represents a TCP socket / connection or listener. */ -interface ITcpSocket +INTERFACE ITcpSocket { public: virtual ~ITcpSocket() = default; @@ -74,7 +74,7 @@ public: /** * Represents a UDP socket / listener. */ -interface IUdpSocket +INTERFACE IUdpSocket { public: virtual ~IUdpSocket() = default; diff --git a/src/openrct2/network/network.h b/src/openrct2/network/network.h index 7c937a2614..16e9eb8238 100644 --- a/src/openrct2/network/network.h +++ b/src/openrct2/network/network.h @@ -32,7 +32,7 @@ enum class PermissionState : uint8_t; namespace OpenRCT2 { - interface IPlatformEnvironment; + INTERFACE IPlatformEnvironment; } void network_set_env(const std::shared_ptr& env); diff --git a/src/openrct2/object/ImageTable.h b/src/openrct2/object/ImageTable.h index efa20fc193..7e4f55b6fc 100644 --- a/src/openrct2/object/ImageTable.h +++ b/src/openrct2/object/ImageTable.h @@ -15,8 +15,8 @@ #include #include -interface IReadObjectContext; -interface IStream; +INTERFACE IReadObjectContext; +INTERFACE IStream; class ImageTable { diff --git a/src/openrct2/object/Object.h b/src/openrct2/object/Object.h index 463ab909ed..24771bd602 100644 --- a/src/openrct2/object/Object.h +++ b/src/openrct2/object/Object.h @@ -134,13 +134,13 @@ struct rct_object_filters assert_struct_size(rct_object_filters, 3); #pragma pack(pop) -interface IObjectRepository; -interface IStream; +INTERFACE IObjectRepository; +INTERFACE IStream; struct ObjectRepositoryItem; struct rct_drawpixelinfo; struct json_t; -interface IReadObjectContext +INTERFACE IReadObjectContext { virtual ~IReadObjectContext() = default; diff --git a/src/openrct2/object/ObjectFactory.cpp b/src/openrct2/object/ObjectFactory.cpp index 9160462542..2ad93ca2a3 100644 --- a/src/openrct2/object/ObjectFactory.cpp +++ b/src/openrct2/object/ObjectFactory.cpp @@ -40,7 +40,7 @@ #include #include -interface IFileDataRetriever +INTERFACE IFileDataRetriever { virtual ~IFileDataRetriever() = default; virtual std::vector GetData(const std::string_view& path) const abstract; diff --git a/src/openrct2/object/ObjectFactory.h b/src/openrct2/object/ObjectFactory.h index ac8e8c23f6..2e060f0158 100644 --- a/src/openrct2/object/ObjectFactory.h +++ b/src/openrct2/object/ObjectFactory.h @@ -13,7 +13,7 @@ #include -interface IObjectRepository; +INTERFACE IObjectRepository; class Object; struct rct_object_entry; diff --git a/src/openrct2/object/ObjectManager.h b/src/openrct2/object/ObjectManager.h index f9be574a4a..7a2461c539 100644 --- a/src/openrct2/object/ObjectManager.h +++ b/src/openrct2/object/ObjectManager.h @@ -14,11 +14,11 @@ #include -interface IObjectRepository; +INTERFACE IObjectRepository; class Object; struct ObjectRepositoryItem; -interface IObjectManager +INTERFACE IObjectManager { virtual ~IObjectManager() { diff --git a/src/openrct2/object/ObjectRepository.h b/src/openrct2/object/ObjectRepository.h index 2dc1665a0c..3d16f6a70f 100644 --- a/src/openrct2/object/ObjectRepository.h +++ b/src/openrct2/object/ObjectRepository.h @@ -16,11 +16,11 @@ #include #include -interface IStream; +INTERFACE IStream; class Object; namespace OpenRCT2 { - interface IPlatformEnvironment; + INTERFACE IPlatformEnvironment; } namespace OpenRCT2::Localisation @@ -58,7 +58,7 @@ struct ObjectRepositoryItem } }; -interface IObjectRepository +INTERFACE IObjectRepository { virtual ~IObjectRepository() = default; diff --git a/src/openrct2/object/StringTable.h b/src/openrct2/object/StringTable.h index dff9da5c4c..642a5e79d8 100644 --- a/src/openrct2/object/StringTable.h +++ b/src/openrct2/object/StringTable.h @@ -15,8 +15,8 @@ #include #include -interface IReadObjectContext; -interface IStream; +INTERFACE IReadObjectContext; +INTERFACE IStream; enum OBJ_STRING_ID : uint8_t { diff --git a/src/openrct2/paint/Painter.h b/src/openrct2/paint/Painter.h index 663435034b..9ec14caefd 100644 --- a/src/openrct2/paint/Painter.h +++ b/src/openrct2/paint/Painter.h @@ -22,17 +22,17 @@ namespace OpenRCT2 { namespace Drawing { - interface IDrawingEngine; + INTERFACE IDrawingEngine; } // namespace Drawing namespace Ui { - interface IUiContext; + INTERFACE IUiContext; } // namespace Ui namespace Paint { - interface Painter final + INTERFACE Painter final { private: std::shared_ptr const _uiContext; diff --git a/src/openrct2/platform/Platform.Win32.cpp b/src/openrct2/platform/Platform.Win32.cpp index b5b97b8add..73b1159504 100644 --- a/src/openrct2/platform/Platform.Win32.cpp +++ b/src/openrct2/platform/Platform.Win32.cpp @@ -225,7 +225,7 @@ namespace Platform auto hModule = GetModuleHandleA("ntdll.dll"); if (hModule != nullptr) { - using RtlGetVersionPtr = NTSTATUS(WINAPI*)(PRTL_OSVERSIONINFOW); + using RtlGetVersionPtr = long(WINAPI*)(PRTL_OSVERSIONINFOW); # if defined(__GNUC__) && __GNUC__ >= 8 # pragma GCC diagnostic push # pragma GCC diagnostic ignored "-Wcast-function-type" diff --git a/src/openrct2/platform/Shared.cpp b/src/openrct2/platform/Shared.cpp index db2989c9da..8b74012d07 100644 --- a/src/openrct2/platform/Shared.cpp +++ b/src/openrct2/platform/Shared.cpp @@ -10,7 +10,6 @@ #include "../common.h" #ifdef _WIN32 -# define WIN32_LEAN_AND_MEAN # include #else # include diff --git a/src/openrct2/platform/Windows.cpp b/src/openrct2/platform/Windows.cpp index eb00d27d0c..2bc9bdbe64 100644 --- a/src/openrct2/platform/Windows.cpp +++ b/src/openrct2/platform/Windows.cpp @@ -16,7 +16,10 @@ #ifdef _WIN32 // Windows.h needs to be included first +// clang-format off # include +# include +// clang-format on // Then the rest # include "../OpenRCT2.h" diff --git a/src/openrct2/rct12/SawyerChunkReader.h b/src/openrct2/rct12/SawyerChunkReader.h index f66a92ec04..213d2703b3 100644 --- a/src/openrct2/rct12/SawyerChunkReader.h +++ b/src/openrct2/rct12/SawyerChunkReader.h @@ -15,7 +15,7 @@ #include -interface IStream; +INTERFACE IStream; /** * Reads sawyer encoding chunks from a data stream. This can be used to read diff --git a/src/openrct2/rct12/SawyerChunkWriter.h b/src/openrct2/rct12/SawyerChunkWriter.h index 54db05c581..443be7b8ff 100644 --- a/src/openrct2/rct12/SawyerChunkWriter.h +++ b/src/openrct2/rct12/SawyerChunkWriter.h @@ -14,7 +14,7 @@ #include -interface IStream; +INTERFACE IStream; /** * Writes sawyer encoding chunks to a data stream. This can be used to write diff --git a/src/openrct2/rct12/SawyerEncoding.h b/src/openrct2/rct12/SawyerEncoding.h index 8a10f996f6..9c85fd6661 100644 --- a/src/openrct2/rct12/SawyerEncoding.h +++ b/src/openrct2/rct12/SawyerEncoding.h @@ -11,7 +11,7 @@ #include "../common.h" -interface IStream; +INTERFACE IStream; enum class RCT12TrackDesignVersion : uint8_t; diff --git a/src/openrct2/rct2/S6Exporter.h b/src/openrct2/rct2/S6Exporter.h index 68940d6620..cecf50efd4 100644 --- a/src/openrct2/rct2/S6Exporter.h +++ b/src/openrct2/rct2/S6Exporter.h @@ -18,7 +18,7 @@ #include #include -interface IStream; +INTERFACE IStream; struct ObjectRepositoryItem; struct RCT12SpriteBase; struct SpriteBase; diff --git a/src/openrct2/rct2/T6Exporter.h b/src/openrct2/rct2/T6Exporter.h index d1b9d9db9c..c5b6acf5eb 100644 --- a/src/openrct2/rct2/T6Exporter.h +++ b/src/openrct2/rct2/T6Exporter.h @@ -14,7 +14,7 @@ #include -interface IStream; +INTERFACE IStream; /** * Class to export RollerCoaster Tycoon 2 track designs (*.TD6). diff --git a/src/openrct2/ride/Ride.h b/src/openrct2/ride/Ride.h index 2df2e406cf..00f46c61d3 100644 --- a/src/openrct2/ride/Ride.h +++ b/src/openrct2/ride/Ride.h @@ -21,7 +21,7 @@ #include #include -interface IObjectManager; +INTERFACE IObjectManager; class Formatter; class StationObject; struct Peep; diff --git a/src/openrct2/ride/TrackDesignRepository.h b/src/openrct2/ride/TrackDesignRepository.h index a529a084cb..582523ce72 100644 --- a/src/openrct2/ride/TrackDesignRepository.h +++ b/src/openrct2/ride/TrackDesignRepository.h @@ -24,10 +24,10 @@ struct track_design_file_ref namespace OpenRCT2 { - interface IPlatformEnvironment; + INTERFACE IPlatformEnvironment; } -interface ITrackDesignRepository +INTERFACE ITrackDesignRepository { virtual ~ITrackDesignRepository() = default; diff --git a/src/openrct2/scenario/ScenarioRepository.h b/src/openrct2/scenario/ScenarioRepository.h index bc4c443493..b9a20309de 100644 --- a/src/openrct2/scenario/ScenarioRepository.h +++ b/src/openrct2/scenario/ScenarioRepository.h @@ -48,10 +48,10 @@ struct scenario_index_entry namespace OpenRCT2 { - interface IPlatformEnvironment; + INTERFACE IPlatformEnvironment; } -interface IScenarioRepository +INTERFACE IScenarioRepository { virtual ~IScenarioRepository() = default; diff --git a/src/openrct2/scripting/ScriptEngine.h b/src/openrct2/scripting/ScriptEngine.h index 8ee0257afc..e688904d25 100644 --- a/src/openrct2/scripting/ScriptEngine.h +++ b/src/openrct2/scripting/ScriptEngine.h @@ -37,7 +37,7 @@ class InteractiveConsole; namespace OpenRCT2 { - interface IPlatformEnvironment; + INTERFACE IPlatformEnvironment; } namespace OpenRCT2::Scripting diff --git a/src/openrct2/title/TitleScreen.h b/src/openrct2/title/TitleScreen.h index d697f92a3b..a2e2c730aa 100644 --- a/src/openrct2/title/TitleScreen.h +++ b/src/openrct2/title/TitleScreen.h @@ -12,7 +12,7 @@ #include "../common.h" #include "../drawing/Drawing.h" -interface ITitleSequencePlayer; +INTERFACE ITitleSequencePlayer; namespace OpenRCT2 { diff --git a/src/openrct2/title/TitleSequencePlayer.h b/src/openrct2/title/TitleSequencePlayer.h index 59b20b81cb..209b9c3da1 100644 --- a/src/openrct2/title/TitleSequencePlayer.h +++ b/src/openrct2/title/TitleSequencePlayer.h @@ -11,7 +11,7 @@ #include "../common.h" -interface ITitleSequencePlayer +INTERFACE ITitleSequencePlayer { virtual ~ITitleSequencePlayer() = default; diff --git a/src/openrct2/ui/UiContext.h b/src/openrct2/ui/UiContext.h index 3c0bf90845..2aa46e4bc4 100644 --- a/src/openrct2/ui/UiContext.h +++ b/src/openrct2/ui/UiContext.h @@ -19,21 +19,21 @@ struct ScreenCoordsXY; struct rct_drawpixelinfo; -interface ITitleSequencePlayer; +INTERFACE ITitleSequencePlayer; namespace OpenRCT2 { namespace Drawing { - interface IDrawingEngineFactory; - interface IRainDrawer; + INTERFACE IDrawingEngineFactory; + INTERFACE IRainDrawer; using DrawRainFunc = void (*)( OpenRCT2::Drawing::IRainDrawer* rainDrawer, int32_t left, int32_t top, int32_t width, int32_t height); } // namespace Drawing namespace Ui { - interface IWindowManager; + INTERFACE IWindowManager; enum class FULLSCREEN_MODE { @@ -87,7 +87,7 @@ namespace OpenRCT2 /** * Represents the window or screen that OpenRCT2 is presented on. */ - interface IUiContext + INTERFACE IUiContext { virtual ~IUiContext() = default; diff --git a/src/openrct2/ui/WindowManager.h b/src/openrct2/ui/WindowManager.h index 0243b1e2cd..f187e0568e 100644 --- a/src/openrct2/ui/WindowManager.h +++ b/src/openrct2/ui/WindowManager.h @@ -20,7 +20,7 @@ namespace OpenRCT2::Ui /** * Manager of in-game windows and widgets. */ - interface IWindowManager + INTERFACE IWindowManager { virtual ~IWindowManager() = default; virtual void Init() abstract;