diff --git a/src/openrct2-ui/UiContext.h b/src/openrct2-ui/UiContext.h index 4917703eae..1d84ee0a9a 100644 --- a/src/openrct2-ui/UiContext.h +++ b/src/openrct2-ui/UiContext.h @@ -46,9 +46,9 @@ namespace OpenRCT2 virtual bool HasFilePicker() const abstract; }; - std::unique_ptr CreateUiContext(const std::shared_ptr& env); - IPlatformUiContext* CreatePlatformUiContext(); + [[nodiscard]] std::unique_ptr CreateUiContext(const std::shared_ptr& env); + [[nodiscard]] IPlatformUiContext* CreatePlatformUiContext(); - InGameConsole& GetInGameConsole(); + [[nodiscard]] InGameConsole& GetInGameConsole(); } // namespace Ui } // namespace OpenRCT2 diff --git a/src/openrct2-ui/audio/AudioContext.h b/src/openrct2-ui/audio/AudioContext.h index 7f4a48ebd6..dd175aa7ea 100644 --- a/src/openrct2-ui/audio/AudioContext.h +++ b/src/openrct2-ui/audio/AudioContext.h @@ -79,6 +79,6 @@ namespace OpenRCT2::Audio IAudioMixer* Create(); } - std::unique_ptr CreateAudioContext(); + [[nodiscard]] std::unique_ptr CreateAudioContext(); } // namespace OpenRCT2::Audio diff --git a/src/openrct2-ui/drawing/engines/DrawingEngineFactory.hpp b/src/openrct2-ui/drawing/engines/DrawingEngineFactory.hpp index 47b6868708..e746c966a5 100644 --- a/src/openrct2-ui/drawing/engines/DrawingEngineFactory.hpp +++ b/src/openrct2-ui/drawing/engines/DrawingEngineFactory.hpp @@ -21,16 +21,18 @@ namespace OpenRCT2 struct IUiContext; - std::unique_ptr CreateSoftwareDrawingEngine(const std::shared_ptr& uiContext); - std::unique_ptr CreateHardwareDisplayDrawingEngine(const std::shared_ptr& uiContext); + [[nodiscard]] std::unique_ptr CreateSoftwareDrawingEngine(const std::shared_ptr& uiContext); + [[nodiscard]] std::unique_ptr CreateHardwareDisplayDrawingEngine( + const std::shared_ptr& uiContext); #ifndef DISABLE_OPENGL - std::unique_ptr CreateOpenGLDrawingEngine(const std::shared_ptr& uiContext); + [[nodiscard]] std::unique_ptr CreateOpenGLDrawingEngine(const std::shared_ptr& uiContext); #endif class DrawingEngineFactory final : public IDrawingEngineFactory { public: - std::unique_ptr Create(DrawingEngine type, const std::shared_ptr& uiContext) override + [[nodiscard]] std::unique_ptr Create( + DrawingEngine type, const std::shared_ptr& uiContext) override { switch (type) { diff --git a/src/openrct2-ui/title/TitleSequencePlayer.h b/src/openrct2-ui/title/TitleSequencePlayer.h index 77699d47fa..1d38e714fc 100644 --- a/src/openrct2-ui/title/TitleSequencePlayer.h +++ b/src/openrct2-ui/title/TitleSequencePlayer.h @@ -20,4 +20,4 @@ namespace OpenRCT2 class GameState; } -std::unique_ptr CreateTitleSequencePlayer(OpenRCT2::GameState& gameState); +[[nodiscard]] std::unique_ptr CreateTitleSequencePlayer(OpenRCT2::GameState& gameState); diff --git a/src/openrct2/Context.h b/src/openrct2/Context.h index 967ac662b7..4cac112caf 100644 --- a/src/openrct2/Context.h +++ b/src/openrct2/Context.h @@ -114,10 +114,10 @@ namespace OpenRCT2 { virtual ~IContext() = default; - virtual std::shared_ptr GetAudioContext() abstract; - virtual std::shared_ptr GetUiContext() abstract; + [[nodiscard]] virtual std::shared_ptr GetAudioContext() abstract; + [[nodiscard]] virtual std::shared_ptr GetUiContext() abstract; virtual GameState* GetGameState() abstract; - virtual std::shared_ptr GetPlatformEnvironment() abstract; + [[nodiscard]] virtual std::shared_ptr GetPlatformEnvironment() abstract; virtual Localisation::LocalisationService& GetLocalisationService() abstract; virtual IObjectManager& GetObjectManager() abstract; virtual IObjectRepository& GetObjectRepository() abstract; @@ -156,11 +156,11 @@ namespace OpenRCT2 virtual float GetTimeScale() const abstract; }; - std::unique_ptr CreateContext(); - std::unique_ptr CreateContext( + [[nodiscard]] std::unique_ptr CreateContext(); + [[nodiscard]] std::unique_ptr CreateContext( const std::shared_ptr& env, const std::shared_ptr& audioContext, const std::shared_ptr& uiContext); - IContext* GetContext(); + [[nodiscard]] IContext* GetContext(); } // namespace OpenRCT2 enum diff --git a/src/openrct2/GameStateSnapshots.h b/src/openrct2/GameStateSnapshots.h index f7490c953d..ed3df93176 100644 --- a/src/openrct2/GameStateSnapshots.h +++ b/src/openrct2/GameStateSnapshots.h @@ -110,4 +110,4 @@ struct IGameStateSnapshots virtual std::string GetCompareDataText(const GameStateCompareData_t& cmpData) const = 0; }; -std::unique_ptr CreateGameStateSnapshots(); +[[nodiscard]] std::unique_ptr CreateGameStateSnapshots(); diff --git a/src/openrct2/ParkImporter.h b/src/openrct2/ParkImporter.h index 1edcc8b146..ff2272dd8e 100644 --- a/src/openrct2/ParkImporter.h +++ b/src/openrct2/ParkImporter.h @@ -57,9 +57,9 @@ public: namespace ParkImporter { - std::unique_ptr Create(const std::string& hintPath); - std::unique_ptr CreateS4(); - std::unique_ptr CreateS6(IObjectRepository& objectRepository); + [[nodiscard]] std::unique_ptr Create(const std::string& hintPath); + [[nodiscard]] std::unique_ptr CreateS4(); + [[nodiscard]] std::unique_ptr CreateS6(IObjectRepository& objectRepository); bool ExtensionIsRCT1(const std::string& extension); bool ExtensionIsScenario(const std::string& extension); diff --git a/src/openrct2/PlatformEnvironment.h b/src/openrct2/PlatformEnvironment.h index 91f3a47779..0d539a0024 100644 --- a/src/openrct2/PlatformEnvironment.h +++ b/src/openrct2/PlatformEnvironment.h @@ -84,7 +84,7 @@ namespace OpenRCT2 virtual void SetBasePath(DIRBASE base, const std::string& path) abstract; }; - std::unique_ptr CreatePlatformEnvironment(DIRBASE_VALUES basePaths); - std::unique_ptr CreatePlatformEnvironment(); + [[nodiscard]] std::unique_ptr CreatePlatformEnvironment(DIRBASE_VALUES basePaths); + [[nodiscard]] std::unique_ptr CreatePlatformEnvironment(); } // namespace OpenRCT2 diff --git a/src/openrct2/ReplayManager.h b/src/openrct2/ReplayManager.h index d635147008..895a99fedd 100644 --- a/src/openrct2/ReplayManager.h +++ b/src/openrct2/ReplayManager.h @@ -65,6 +65,6 @@ namespace OpenRCT2 virtual bool NormaliseReplay(const std::string& inputFile, const std::string& outputFile) = 0; }; - std::unique_ptr CreateReplayManager(); + [[nodiscard]] std::unique_ptr CreateReplayManager(); } // namespace OpenRCT2 diff --git a/src/openrct2/TrackImporter.h b/src/openrct2/TrackImporter.h index 677228dc1a..fb5ffee743 100644 --- a/src/openrct2/TrackImporter.h +++ b/src/openrct2/TrackImporter.h @@ -28,14 +28,14 @@ public: virtual bool Load(const utf8* path) abstract; virtual bool LoadFromStream(OpenRCT2::IStream* stream) abstract; - virtual std::unique_ptr Import() abstract; + [[nodiscard]] virtual std::unique_ptr Import() abstract; }; namespace TrackImporter { - std::unique_ptr Create(const std::string& hintPath); - std::unique_ptr CreateTD4(); - std::unique_ptr CreateTD6(); + [[nodiscard]] std::unique_ptr Create(const std::string& hintPath); + [[nodiscard]] std::unique_ptr CreateTD4(); + [[nodiscard]] std::unique_ptr CreateTD6(); bool ExtensionIsRCT1(const std::string& extension); } // namespace TrackImporter diff --git a/src/openrct2/audio/AudioContext.h b/src/openrct2/audio/AudioContext.h index af7ab7bfdb..6b9ee914d2 100644 --- a/src/openrct2/audio/AudioContext.h +++ b/src/openrct2/audio/AudioContext.h @@ -55,6 +55,6 @@ namespace OpenRCT2::Audio virtual void StopVehicleSounds() abstract; }; - std::unique_ptr CreateDummyAudioContext(); + [[nodiscard]] std::unique_ptr CreateDummyAudioContext(); } // namespace OpenRCT2::Audio diff --git a/src/openrct2/config/IniReader.hpp b/src/openrct2/config/IniReader.hpp index 23329091cf..91f847d590 100644 --- a/src/openrct2/config/IniReader.hpp +++ b/src/openrct2/config/IniReader.hpp @@ -48,5 +48,5 @@ struct IIniReader utf8* GetCString(const std::string& name, const utf8* defaultValue) const; }; -std::unique_ptr CreateIniReader(OpenRCT2::IStream* stream); -std::unique_ptr CreateDefaultIniReader(); +[[nodiscard]] std::unique_ptr CreateIniReader(OpenRCT2::IStream* stream); +[[nodiscard]] std::unique_ptr CreateDefaultIniReader(); diff --git a/src/openrct2/config/IniWriter.hpp b/src/openrct2/config/IniWriter.hpp index ab5cd6f501..8f44e51e81 100644 --- a/src/openrct2/config/IniWriter.hpp +++ b/src/openrct2/config/IniWriter.hpp @@ -52,4 +52,4 @@ struct IIniWriter void WriteString(const std::string& name, const utf8* value); }; -std::unique_ptr CreateIniWriter(OpenRCT2::IStream* stream); +[[nodiscard]] std::unique_ptr CreateIniWriter(OpenRCT2::IStream* stream); diff --git a/src/openrct2/core/Crypt.h b/src/openrct2/core/Crypt.h index 468ca65780..18967bd875 100644 --- a/src/openrct2/core/Crypt.h +++ b/src/openrct2/core/Crypt.h @@ -50,10 +50,10 @@ namespace Crypt using Sha256Algorithm = HashAlgorithm<32>; // Factories - std::unique_ptr CreateSHA1(); - std::unique_ptr CreateSHA256(); - std::unique_ptr CreateRSA(); - std::unique_ptr CreateRSAKey(); + [[nodiscard]] std::unique_ptr CreateSHA1(); + [[nodiscard]] std::unique_ptr CreateSHA256(); + [[nodiscard]] std::unique_ptr CreateRSA(); + [[nodiscard]] std::unique_ptr CreateRSAKey(); inline Sha1Algorithm::Result SHA1(const void* data, size_t dataLen) { diff --git a/src/openrct2/core/FileScanner.h b/src/openrct2/core/FileScanner.h index 1e6c63d230..4cc17977bb 100644 --- a/src/openrct2/core/FileScanner.h +++ b/src/openrct2/core/FileScanner.h @@ -51,7 +51,7 @@ namespace Path * @param recurse Whether to scan sub directories or not. * @returns A new FileScanner, this must be deleted when no longer needed. */ - std::unique_ptr ScanDirectory(const std::string& pattern, bool recurse); + [[nodiscard]] std::unique_ptr ScanDirectory(const std::string& pattern, bool recurse); /** * Scans a directory and all sub directories @@ -60,5 +60,5 @@ namespace Path */ void QueryDirectory(QueryDirectoryResult* result, const std::string& pattern); - std::vector GetDirectories(const std::string& path); + [[nodiscard]] std::vector GetDirectories(const std::string& path); } // namespace Path diff --git a/src/openrct2/core/IStream.hpp b/src/openrct2/core/IStream.hpp index 6f751dc77c..815990d8dc 100644 --- a/src/openrct2/core/IStream.hpp +++ b/src/openrct2/core/IStream.hpp @@ -192,7 +192,7 @@ namespace OpenRCT2 Write(&value); } - template std::unique_ptr ReadArray(size_t count) + template[[nodiscard]] std::unique_ptr ReadArray(size_t count) { auto buffer = std::make_unique(count); Read(buffer.get(), sizeof(T) * count); diff --git a/src/openrct2/core/Zip.h b/src/openrct2/core/Zip.h index 01d5e8b17b..43d4beafc5 100644 --- a/src/openrct2/core/Zip.h +++ b/src/openrct2/core/Zip.h @@ -31,11 +31,11 @@ struct IZipArchive { } - virtual size_t GetNumFiles() const abstract; - virtual std::string GetFileName(size_t index) const abstract; - virtual uint64_t GetFileSize(size_t index) const abstract; - virtual std::vector GetFileData(std::string_view path) const abstract; - virtual std::unique_ptr GetFileStream(std::string_view path) const abstract; + [[nodiscard]] virtual size_t GetNumFiles() const abstract; + [[nodiscard]] virtual std::string GetFileName(size_t index) const abstract; + [[nodiscard]] virtual uint64_t GetFileSize(size_t index) const abstract; + [[nodiscard]] virtual std::vector GetFileData(std::string_view path) const abstract; + [[nodiscard]] virtual std::unique_ptr GetFileStream(std::string_view path) const abstract; /** * Creates or overwrites a file within the zip archive to the given data buffer. @@ -47,8 +47,8 @@ struct IZipArchive virtual void DeleteFile(std::string_view path) abstract; virtual void RenameFile(std::string_view path, std::string_view newPath) abstract; - std::optional GetIndexFromPath(std::string_view path) const; - bool Exists(std::string_view path) const; + [[nodiscard]] std::optional GetIndexFromPath(std::string_view path) const; + [[nodiscard]] bool Exists(std::string_view path) const; }; enum class ZIP_ACCESS @@ -59,6 +59,6 @@ enum class ZIP_ACCESS namespace Zip { - std::unique_ptr Open(std::string_view path, ZIP_ACCESS zipAccess); - std::unique_ptr TryOpen(std::string_view path, ZIP_ACCESS zipAccess); + [[nodiscard]] std::unique_ptr Open(std::string_view path, ZIP_ACCESS zipAccess); + [[nodiscard]] std::unique_ptr TryOpen(std::string_view path, ZIP_ACCESS zipAccess); } // namespace Zip diff --git a/src/openrct2/drawing/IDrawingEngine.h b/src/openrct2/drawing/IDrawingEngine.h index 0d679d2467..41c3adb383 100644 --- a/src/openrct2/drawing/IDrawingEngine.h +++ b/src/openrct2/drawing/IDrawingEngine.h @@ -79,7 +79,7 @@ namespace OpenRCT2::Drawing virtual ~IDrawingEngineFactory() { } - virtual std::unique_ptr Create( + [[nodiscard]] virtual std::unique_ptr Create( DrawingEngine type, const std::shared_ptr& uiContext) abstract; }; diff --git a/src/openrct2/network/NetworkServerAdvertiser.h b/src/openrct2/network/NetworkServerAdvertiser.h index b4581ca9f6..e49882d93f 100644 --- a/src/openrct2/network/NetworkServerAdvertiser.h +++ b/src/openrct2/network/NetworkServerAdvertiser.h @@ -30,4 +30,4 @@ struct INetworkServerAdvertiser virtual void Update() abstract; }; -std::unique_ptr CreateServerAdvertiser(uint16_t port); +[[nodiscard]] std::unique_ptr CreateServerAdvertiser(uint16_t port); diff --git a/src/openrct2/network/Socket.h b/src/openrct2/network/Socket.h index 9100d959a9..81b6ea2911 100644 --- a/src/openrct2/network/Socket.h +++ b/src/openrct2/network/Socket.h @@ -60,7 +60,7 @@ public: virtual void Listen(uint16_t port) abstract; virtual void Listen(const std::string& address, uint16_t port) abstract; - virtual std::unique_ptr Accept() abstract; + [[nodiscard]] virtual std::unique_ptr Accept() abstract; virtual void Connect(const std::string& address, uint16_t port) abstract; virtual void ConnectAsync(const std::string& address, uint16_t port) abstract; @@ -98,9 +98,9 @@ public: virtual void Close() abstract; }; -std::unique_ptr CreateTcpSocket(); -std::unique_ptr CreateUdpSocket(); -std::vector> GetBroadcastAddresses(); +[[nodiscard]] std::unique_ptr CreateTcpSocket(); +[[nodiscard]] std::unique_ptr CreateUdpSocket(); +[[nodiscard]] std::vector> GetBroadcastAddresses(); namespace Convert { diff --git a/src/openrct2/network/network.h b/src/openrct2/network/network.h index 2876339f21..9e590caf9c 100644 --- a/src/openrct2/network/network.h +++ b/src/openrct2/network/network.h @@ -47,8 +47,8 @@ void network_shutdown_client(); int32_t network_begin_client(const std::string& host, int32_t port); int32_t network_begin_server(int32_t port, const std::string& address); -int32_t network_get_mode(); -int32_t network_get_status(); +[[nodiscard]] int32_t network_get_mode(); +[[nodiscard]] int32_t network_get_status(); bool network_is_desynchronised(); bool network_check_desynchronisation(); void network_request_gamestate_snapshot(); @@ -58,46 +58,46 @@ void network_update(); void network_process_pending(); void network_flush(); -NetworkAuth network_get_authstatus(); -uint32_t network_get_server_tick(); -uint8_t network_get_current_player_id(); -int32_t network_get_num_players(); -const char* network_get_player_name(uint32_t index); -uint32_t network_get_player_flags(uint32_t index); -int32_t network_get_player_ping(uint32_t index); -int32_t network_get_player_id(uint32_t index); -money32 network_get_player_money_spent(uint32_t index); -std::string network_get_player_ip_address(uint32_t id); -std::string network_get_player_public_key_hash(uint32_t id); +[[nodiscard]] NetworkAuth network_get_authstatus(); +[[nodiscard]] uint32_t network_get_server_tick(); +[[nodiscard]] uint8_t network_get_current_player_id(); +[[nodiscard]] int32_t network_get_num_players(); +[[nodiscard]] const char* network_get_player_name(uint32_t index); +[[nodiscard]] uint32_t network_get_player_flags(uint32_t index); +[[nodiscard]] int32_t network_get_player_ping(uint32_t index); +[[nodiscard]] int32_t network_get_player_id(uint32_t index); +[[nodiscard]] money32 network_get_player_money_spent(uint32_t index); +[[nodiscard]] std::string network_get_player_ip_address(uint32_t id); +[[nodiscard]] std::string network_get_player_public_key_hash(uint32_t id); void network_add_player_money_spent(uint32_t index, money32 cost); -int32_t network_get_player_last_action(uint32_t index, int32_t time); +[[nodiscard]] int32_t network_get_player_last_action(uint32_t index, int32_t time); void network_set_player_last_action(uint32_t index, GameCommand command); -CoordsXYZ network_get_player_last_action_coord(uint32_t index); +[[nodiscard]] CoordsXYZ network_get_player_last_action_coord(uint32_t index); void network_set_player_last_action_coord(uint32_t index, const CoordsXYZ& coord); -uint32_t network_get_player_commands_ran(uint32_t index); -int32_t network_get_player_index(uint32_t id); -uint8_t network_get_player_group(uint32_t index); +[[nodiscard]] uint32_t network_get_player_commands_ran(uint32_t index); +[[nodiscard]] int32_t network_get_player_index(uint32_t id); +[[nodiscard]] uint8_t network_get_player_group(uint32_t index); void network_set_player_group(uint32_t index, uint32_t groupindex); -int32_t network_get_group_index(uint8_t id); -int32_t network_get_current_player_group_index(); -uint8_t network_get_group_id(uint32_t index); -int32_t network_get_num_groups(); -const char* network_get_group_name(uint32_t index); -std::unique_ptr network_set_player_group( +[[nodiscard]] int32_t network_get_group_index(uint8_t id); +[[nodiscard]] int32_t network_get_current_player_group_index(); +[[nodiscard]] uint8_t network_get_group_id(uint32_t index); +[[nodiscard]] int32_t network_get_num_groups(); +[[nodiscard]] const char* network_get_group_name(uint32_t index); +[[nodiscard]] std::unique_ptr network_set_player_group( NetworkPlayerId_t actionPlayerId, NetworkPlayerId_t playerId, uint8_t groupId, bool isExecuting); -std::unique_ptr network_modify_groups( +[[nodiscard]] std::unique_ptr network_modify_groups( NetworkPlayerId_t actionPlayerId, ModifyGroupType type, uint8_t groupId, const std::string& name, uint32_t permissionIndex, PermissionState permissionState, bool isExecuting); -std::unique_ptr network_kick_player(NetworkPlayerId_t playerId, bool isExecuting); -uint8_t network_get_default_group(); -int32_t network_get_num_actions(); -rct_string_id network_get_action_name_string_id(uint32_t index); -int32_t network_can_perform_action(uint32_t groupindex, NetworkPermission index); -int32_t network_can_perform_command(uint32_t groupindex, int32_t index); +[[nodiscard]] std::unique_ptr network_kick_player(NetworkPlayerId_t playerId, bool isExecuting); +[[nodiscard]] uint8_t network_get_default_group(); +[[nodiscard]] int32_t network_get_num_actions(); +[[nodiscard]] rct_string_id network_get_action_name_string_id(uint32_t index); +[[nodiscard]] int32_t network_can_perform_action(uint32_t groupindex, NetworkPermission index); +[[nodiscard]] int32_t network_can_perform_command(uint32_t groupindex, int32_t index); void network_set_pickup_peep(uint8_t playerid, Peep* peep); -Peep* network_get_pickup_peep(uint8_t playerid); +[[nodiscard]] Peep* network_get_pickup_peep(uint8_t playerid); void network_set_pickup_peep_old_x(uint8_t playerid, int32_t x); -int32_t network_get_pickup_peep_old_x(uint8_t playerid); +[[nodiscard]] int32_t network_get_pickup_peep_old_x(uint8_t playerid); void network_send_map(); void network_send_chat(const char* text, const std::vector& playerIds = {}); @@ -110,15 +110,15 @@ void network_set_password(const char* password); void network_print_error(); void network_append_chat_log(const utf8* text); void network_append_server_log(const utf8* text); -const utf8* network_get_server_name(); -const utf8* network_get_server_description(); -const utf8* network_get_server_greeting(); -const utf8* network_get_server_provider_name(); -const utf8* network_get_server_provider_email(); -const utf8* network_get_server_provider_website(); +[[nodiscard]] const utf8* network_get_server_name(); +[[nodiscard]] const utf8* network_get_server_description(); +[[nodiscard]] const utf8* network_get_server_greeting(); +[[nodiscard]] const utf8* network_get_server_provider_name(); +[[nodiscard]] const utf8* network_get_server_provider_email(); +[[nodiscard]] const utf8* network_get_server_provider_website(); -std::string network_get_version(); +[[nodiscard]] std::string network_get_version(); -NetworkStats_t network_get_stats(); -NetworkServerState_t network_get_server_state(); -json_t network_get_server_info_as_json(); +[[nodiscard]] NetworkStats_t network_get_stats(); +[[nodiscard]] NetworkServerState_t network_get_server_state(); +[[nodiscard]] json_t network_get_server_info_as_json(); diff --git a/src/openrct2/object/ImageTable.h b/src/openrct2/object/ImageTable.h index acd6aeea0d..dcad67643f 100644 --- a/src/openrct2/object/ImageTable.h +++ b/src/openrct2/object/ImageTable.h @@ -32,15 +32,17 @@ private: * Container for a G1 image, additional information and RAII. Used by ReadJson */ struct RequiredImage; - static std::vector> ParseImages(IReadObjectContext* context, std::string s); + [[nodiscard]] static std::vector> ParseImages( + IReadObjectContext* context, std::string s); /** * @note root is deliberately left non-const: json_t behaviour changes when const */ - static std::vector> ParseImages(IReadObjectContext* context, json_t& el); - static std::vector> LoadObjectImages( + [[nodiscard]] static std::vector> ParseImages( + IReadObjectContext* context, json_t& el); + [[nodiscard]] static std::vector> LoadObjectImages( IReadObjectContext* context, const std::string& name, const std::vector& range); - static std::vector ParseRange(std::string s); - static std::string FindLegacyObject(const std::string& name); + [[nodiscard]] static std::vector ParseRange(std::string s); + [[nodiscard]] static std::string FindLegacyObject(const std::string& name); public: ImageTable() = default; diff --git a/src/openrct2/object/LargeSceneryObject.h b/src/openrct2/object/LargeSceneryObject.h index a39e387880..d1711336db 100644 --- a/src/openrct2/object/LargeSceneryObject.h +++ b/src/openrct2/object/LargeSceneryObject.h @@ -43,9 +43,9 @@ public: const rct_large_scenery_tile* GetTileForSequence(uint8_t SequenceIndex) const; private: - static std::vector ReadTiles(OpenRCT2::IStream* stream); - static std::vector ReadJsonTiles(json_t& jTiles); - static std::unique_ptr ReadJson3dFont(json_t& j3dFont); - static std::vector ReadJsonOffsets(json_t& jOffsets); - static std::vector ReadJsonGlyphs(json_t& jGlyphs); + [[nodiscard]] static std::vector ReadTiles(OpenRCT2::IStream* stream); + [[nodiscard]] static std::vector ReadJsonTiles(json_t& jTiles); + [[nodiscard]] static std::unique_ptr ReadJson3dFont(json_t& j3dFont); + [[nodiscard]] static std::vector ReadJsonOffsets(json_t& jOffsets); + [[nodiscard]] static std::vector ReadJsonGlyphs(json_t& jGlyphs); }; diff --git a/src/openrct2/object/Object.h b/src/openrct2/object/Object.h index 0f3761986c..4f7ca3f8cf 100644 --- a/src/openrct2/object/Object.h +++ b/src/openrct2/object/Object.h @@ -222,9 +222,9 @@ public: { } - bool IsAvailable() const; - uint64_t GetSize() const; - std::unique_ptr GetStream() const; + [[nodiscard]] bool IsAvailable() const; + [[nodiscard]] uint64_t GetSize() const; + [[nodiscard]] std::unique_ptr GetStream() const; }; struct IReadObjectContext diff --git a/src/openrct2/object/ObjectFactory.h b/src/openrct2/object/ObjectFactory.h index 74ea1787c7..ecbdf9f611 100644 --- a/src/openrct2/object/ObjectFactory.h +++ b/src/openrct2/object/ObjectFactory.h @@ -20,11 +20,12 @@ struct rct_object_entry; namespace ObjectFactory { - std::unique_ptr CreateObjectFromLegacyFile(IObjectRepository& objectRepository, const utf8* path); - std::unique_ptr CreateObjectFromLegacyData( + [[nodiscard]] std::unique_ptr CreateObjectFromLegacyFile(IObjectRepository& objectRepository, const utf8* path); + [[nodiscard]] std::unique_ptr CreateObjectFromLegacyData( IObjectRepository& objectRepository, const rct_object_entry* entry, const void* data, size_t dataSize); - std::unique_ptr CreateObjectFromZipFile(IObjectRepository& objectRepository, std::string_view path); - std::unique_ptr CreateObject(const rct_object_entry& entry); + [[nodiscard]] std::unique_ptr CreateObjectFromZipFile(IObjectRepository& objectRepository, std::string_view path); + [[nodiscard]] std::unique_ptr CreateObject(const rct_object_entry& entry); - std::unique_ptr CreateObjectFromJsonFile(IObjectRepository& objectRepository, const std::string& path); + [[nodiscard]] std::unique_ptr CreateObjectFromJsonFile( + IObjectRepository& objectRepository, const std::string& path); } // namespace ObjectFactory diff --git a/src/openrct2/object/ObjectManager.h b/src/openrct2/object/ObjectManager.h index 37f54cfb05..1dbf7fc2a5 100644 --- a/src/openrct2/object/ObjectManager.h +++ b/src/openrct2/object/ObjectManager.h @@ -43,13 +43,13 @@ struct IObjectManager virtual const std::vector& GetAllRideEntries(uint8_t rideType) abstract; }; -std::unique_ptr CreateObjectManager(IObjectRepository& objectRepository); +[[nodiscard]] std::unique_ptr CreateObjectManager(IObjectRepository& objectRepository); -Object* object_manager_get_loaded_object_by_index(size_t index); -Object* object_manager_get_loaded_object(const ObjectEntryDescriptor& entry); -ObjectEntryIndex object_manager_get_loaded_object_entry_index(const Object* loadedObject); -ObjectEntryIndex object_manager_get_loaded_object_entry_index(const ObjectEntryDescriptor& entry); +[[nodiscard]] Object* object_manager_get_loaded_object_by_index(size_t index); +[[nodiscard]] Object* object_manager_get_loaded_object(const ObjectEntryDescriptor& entry); +[[nodiscard]] ObjectEntryIndex object_manager_get_loaded_object_entry_index(const Object* loadedObject); +[[nodiscard]] ObjectEntryIndex object_manager_get_loaded_object_entry_index(const ObjectEntryDescriptor& entry); Object* object_manager_load_object(const rct_object_entry* entry); void object_manager_unload_objects(const std::vector& entries); void object_manager_unload_all_objects(); -rct_string_id object_manager_get_source_game_string(const ObjectSourceGame sourceGame); +[[nodiscard]] rct_string_id object_manager_get_source_game_string(const ObjectSourceGame sourceGame); diff --git a/src/openrct2/object/ObjectRepository.h b/src/openrct2/object/ObjectRepository.h index bf2af60b25..6fa5555f8d 100644 --- a/src/openrct2/object/ObjectRepository.h +++ b/src/openrct2/object/ObjectRepository.h @@ -55,7 +55,7 @@ struct ObjectRepositoryItem std::vector Entries; } SceneryGroupInfo; - ObjectSourceGame GetFirstSourceGame() const + [[nodiscard]] ObjectSourceGame GetFirstSourceGame() const { if (Sources.empty()) return ObjectSourceGame::Custom; @@ -70,14 +70,14 @@ struct IObjectRepository virtual void LoadOrConstruct(int32_t language) abstract; virtual void Construct(int32_t language) abstract; - virtual size_t GetNumObjects() const abstract; - virtual const ObjectRepositoryItem* GetObjects() const abstract; - virtual const ObjectRepositoryItem* FindObjectLegacy(std::string_view legacyIdentifier) const abstract; - virtual const ObjectRepositoryItem* FindObject(std::string_view identifier) const abstract; - virtual const ObjectRepositoryItem* FindObject(const rct_object_entry* objectEntry) const abstract; - virtual const ObjectRepositoryItem* FindObject(const ObjectEntryDescriptor& oed) const abstract; + [[nodiscard]] virtual size_t GetNumObjects() const abstract; + [[nodiscard]] virtual const ObjectRepositoryItem* GetObjects() const abstract; + [[nodiscard]] virtual const ObjectRepositoryItem* FindObjectLegacy(std::string_view legacyIdentifier) const abstract; + [[nodiscard]] virtual const ObjectRepositoryItem* FindObject(std::string_view identifier) const abstract; + [[nodiscard]] virtual const ObjectRepositoryItem* FindObject(const rct_object_entry* objectEntry) const abstract; + [[nodiscard]] virtual const ObjectRepositoryItem* FindObject(const ObjectEntryDescriptor& oed) const abstract; - virtual std::unique_ptr LoadObject(const ObjectRepositoryItem* ori) abstract; + [[nodiscard]] virtual std::unique_ptr LoadObject(const ObjectRepositoryItem* ori) abstract; virtual void RegisterLoadedObject(const ObjectRepositoryItem* ori, Object* object) abstract; virtual void UnregisterLoadedObject(const ObjectRepositoryItem* ori, Object* object) abstract; @@ -88,12 +88,13 @@ struct IObjectRepository virtual void WritePackedObjects(OpenRCT2::IStream* stream, std::vector& objects) abstract; }; -std::unique_ptr CreateObjectRepository(const std::shared_ptr& env); +[[nodiscard]] std::unique_ptr CreateObjectRepository( + const std::shared_ptr& env); -bool IsObjectCustom(const ObjectRepositoryItem* object); +[[nodiscard]] bool IsObjectCustom(const ObjectRepositoryItem* object); -size_t object_repository_get_items_count(); -const ObjectRepositoryItem* object_repository_get_items(); -const ObjectRepositoryItem* object_repository_find_object_by_entry(const rct_object_entry* entry); -const ObjectRepositoryItem* object_repository_find_object_by_name(const char* name); -std::unique_ptr object_repository_load_object(const rct_object_entry* objectEntry); +[[nodiscard]] size_t object_repository_get_items_count(); +[[nodiscard]] const ObjectRepositoryItem* object_repository_get_items(); +[[nodiscard]] const ObjectRepositoryItem* object_repository_find_object_by_entry(const rct_object_entry* entry); +[[nodiscard]] const ObjectRepositoryItem* object_repository_find_object_by_name(const char* name); +[[nodiscard]] std::unique_ptr object_repository_load_object(const rct_object_entry* objectEntry); diff --git a/src/openrct2/peep/Peep.h b/src/openrct2/peep/Peep.h index 6f4bad1206..eb659b6760 100644 --- a/src/openrct2/peep/Peep.h +++ b/src/openrct2/peep/Peep.h @@ -625,18 +625,18 @@ public: // Peep void UpdateCurrentActionSpriteType(); void SwitchToSpecialSprite(uint8_t special_sprite_id); void StateReset(); - uint8_t GetNextDirection() const; + [[nodiscard]] uint8_t GetNextDirection() const; bool GetNextIsSloped() const; bool GetNextIsSurface() const; void SetNextFlags(uint8_t next_direction, bool is_sloped, bool is_surface); bool CanBePickedUp() const; void Pickup(); void PickupAbort(int32_t old_x); - std::unique_ptr Place(const TileCoordsXYZ& location, bool apply); + [[nodiscard]] std::unique_ptr Place(const TileCoordsXYZ& location, bool apply); void RemoveFromRide(); void FormatActionTo(Formatter&) const; void FormatNameTo(Formatter&) const; - std::string GetName() const; + [[nodiscard]] std::string GetName() const; bool SetName(std::string_view value); bool IsActionWalking() const; bool IsActionIdle() const; @@ -648,16 +648,16 @@ public: // Peep void SetDestination(const CoordsXY& coords); void SetDestination(const CoordsXY& coords, int32_t tolerance); - CoordsXY GetDestination() const; + [[nodiscard]] CoordsXY GetDestination() const; // TODO: Make these private again when done refactoring public: // Peep - bool CheckForPath(); + [[nodiscard]] bool CheckForPath(); void PerformNextAction(uint8_t& pathing_result); void PerformNextAction(uint8_t& pathing_result, TileElement*& tile_result); - int32_t GetZOnSlope(int32_t tile_x, int32_t tile_y); + [[nodiscard]] int32_t GetZOnSlope(int32_t tile_x, int32_t tile_y); void SwitchNextActionSpriteType(); - PeepActionSpriteType GetActionSpriteType(); + [[nodiscard]] PeepActionSpriteType GetActionSpriteType(); private: void UpdateFalling(); diff --git a/src/openrct2/rct12/SawyerChunkReader.h b/src/openrct2/rct12/SawyerChunkReader.h index 0873c8b845..954447325e 100644 --- a/src/openrct2/rct12/SawyerChunkReader.h +++ b/src/openrct2/rct12/SawyerChunkReader.h @@ -57,12 +57,12 @@ public: /** * Reads the next chunk from the stream. */ - std::shared_ptr ReadChunk(); + [[nodiscard]] std::shared_ptr ReadChunk(); /** * As above but for chunks without a header */ - std::shared_ptr ReadChunkTrack(); + [[nodiscard]] std::shared_ptr ReadChunkTrack(); /** * Reads the next chunk from the stream and copies it directly to the diff --git a/src/openrct2/ride/Ride.h b/src/openrct2/ride/Ride.h index 400507c89c..be14e2431a 100644 --- a/src/openrct2/ride/Ride.h +++ b/src/openrct2/ride/Ride.h @@ -450,7 +450,7 @@ public: static void UpdateAll(); static bool NameExists(std::string_view name, ride_id_t excludeRideId = RIDE_ID_NULL); - std::unique_ptr SaveToTrackDesign() const; + [[nodiscard]] std::unique_ptr SaveToTrackDesign() const; uint64_t GetAvailableModes() const; const RideTypeDescriptor& GetRideTypeDescriptor() const; diff --git a/src/openrct2/ride/TrackDesign.h b/src/openrct2/ride/TrackDesign.h index d9b69783ff..d459527365 100644 --- a/src/openrct2/ride/TrackDesign.h +++ b/src/openrct2/ride/TrackDesign.h @@ -199,7 +199,7 @@ extern bool _trackDesignPlaceStateSceneryUnavailable; extern bool gTrackDesignSaveMode; extern ride_id_t gTrackDesignSaveRideIndex; -std::unique_ptr track_design_open(const utf8* path); +[[nodiscard]] std::unique_ptr track_design_open(const utf8* path); void track_design_mirror(TrackDesign* td6); diff --git a/src/openrct2/ride/TrackDesignRepository.h b/src/openrct2/ride/TrackDesignRepository.h index 8e9c1f4085..aeefb83c52 100644 --- a/src/openrct2/ride/TrackDesignRepository.h +++ b/src/openrct2/ride/TrackDesignRepository.h @@ -31,9 +31,9 @@ struct ITrackDesignRepository { virtual ~ITrackDesignRepository() = default; - virtual size_t GetCount() const abstract; - virtual size_t GetCountForObjectEntry(uint8_t rideType, const std::string& entry) const abstract; - virtual std::vector GetItemsForObjectEntry( + [[nodiscard]] virtual size_t GetCount() const abstract; + [[nodiscard]] virtual size_t GetCountForObjectEntry(uint8_t rideType, const std::string& entry) const abstract; + [[nodiscard]] virtual std::vector GetItemsForObjectEntry( uint8_t rideType, const std::string& entry) const abstract; virtual void Scan(int32_t language) abstract; @@ -42,8 +42,9 @@ struct ITrackDesignRepository virtual std::string Install(const std::string& path, const std::string& name) abstract; }; -std::unique_ptr CreateTrackDesignRepository(const std::shared_ptr& env); -std::string GetNameFromTrackPath(const std::string& path); +[[nodiscard]] std::unique_ptr CreateTrackDesignRepository( + const std::shared_ptr& env); +[[nodiscard]] std::string GetNameFromTrackPath(const std::string& path); void track_repository_scan(); bool track_repository_delete(const utf8* path); diff --git a/src/openrct2/scenario/ScenarioRepository.h b/src/openrct2/scenario/ScenarioRepository.h index 0ee807a384..8d6898d464 100644 --- a/src/openrct2/scenario/ScenarioRepository.h +++ b/src/openrct2/scenario/ScenarioRepository.h @@ -74,11 +74,13 @@ struct IScenarioRepository int32_t language, const utf8* scenarioFileName, money64 companyValue, const utf8* name) abstract; }; -std::unique_ptr CreateScenarioRepository(const std::shared_ptr& env); -IScenarioRepository* GetScenarioRepository(); +[[nodiscard]] std::unique_ptr CreateScenarioRepository( + const std::shared_ptr& env); +[[nodiscard]] IScenarioRepository* GetScenarioRepository(); void scenario_repository_scan(); -size_t scenario_repository_get_count(); -const scenario_index_entry* scenario_repository_get_by_index(size_t index); -bool scenario_repository_try_record_highscore(const utf8* scenarioFileName, money64 companyValue, const utf8* name); +[[nodiscard]] size_t scenario_repository_get_count(); +[[nodiscard]] const scenario_index_entry* scenario_repository_get_by_index(size_t index); +[[nodiscard]] bool scenario_repository_try_record_highscore( + const utf8* scenarioFileName, money64 companyValue, const utf8* name); void scenario_translate(scenario_index_entry* scenarioEntry); diff --git a/src/openrct2/scripting/ScriptEngine.h b/src/openrct2/scripting/ScriptEngine.h index 9210a3622c..404e7daffd 100644 --- a/src/openrct2/scripting/ScriptEngine.h +++ b/src/openrct2/scripting/ScriptEngine.h @@ -220,12 +220,12 @@ namespace OpenRCT2::Scripting void AddNetworkPlugin(std::string_view code); - std::unique_ptr QueryOrExecuteCustomGameAction( + [[nodiscard]] std::unique_ptr QueryOrExecuteCustomGameAction( std::string_view id, std::string_view args, bool isExecute); bool RegisterCustomAction( const std::shared_ptr& plugin, std::string_view action, const DukValue& query, const DukValue& execute); void RunGameActionHooks(const GameAction& action, std::unique_ptr& result, bool isExecute); - std::unique_ptr CreateGameAction(const std::string& actionid, const DukValue& args); + [[nodiscard]] std::unique_ptr CreateGameAction(const std::string& actionid, const DukValue& args); void SaveSharedStorage(); @@ -249,8 +249,9 @@ namespace OpenRCT2::Scripting void AutoReloadPlugins(); void ProcessREPL(); void RemoveCustomGameActions(const std::shared_ptr& plugin); - std::unique_ptr DukToGameActionResult(const DukValue& d); - DukValue GameActionResultToDuk(const GameAction& action, const std::unique_ptr& result); + [[nodiscard]] std::unique_ptr DukToGameActionResult(const DukValue& d); + [[nodiscard]] DukValue GameActionResultToDuk( + const GameAction& action, const std::unique_ptr& result); static std::string_view ExpenditureTypeToString(ExpenditureType expenditureType); static ExpenditureType StringToExpenditureType(std::string_view expenditureType); diff --git a/src/openrct2/title/TitleSequence.h b/src/openrct2/title/TitleSequence.h index 447eef9390..62c64d1593 100644 --- a/src/openrct2/title/TitleSequence.h +++ b/src/openrct2/title/TitleSequence.h @@ -78,9 +78,9 @@ enum class TitleScript : uint8_t constexpr const utf8* TITLE_SEQUENCE_EXTENSION = ".parkseq"; constexpr uint8_t SAVE_INDEX_INVALID = UINT8_MAX; -std::unique_ptr CreateTitleSequence(); -std::unique_ptr LoadTitleSequence(const std::string& path); -std::unique_ptr TitleSequenceGetParkHandle(const TitleSequence& seq, size_t index); +[[nodiscard]] std::unique_ptr CreateTitleSequence(); +[[nodiscard]] std::unique_ptr LoadTitleSequence(const std::string& path); +[[nodiscard]] std::unique_ptr TitleSequenceGetParkHandle(const TitleSequence& seq, size_t index); bool TitleSequenceSave(const TitleSequence& seq); bool TitleSequenceAddPark(TitleSequence& seq, const utf8* path, const utf8* name); diff --git a/src/openrct2/ui/UiContext.h b/src/openrct2/ui/UiContext.h index 0f557defef..c2f38d56ac 100644 --- a/src/openrct2/ui/UiContext.h +++ b/src/openrct2/ui/UiContext.h @@ -138,7 +138,7 @@ namespace OpenRCT2 virtual void SetKeysPressed(uint32_t keysym, uint8_t scancode) abstract; // Drawing - virtual std::shared_ptr GetDrawingEngineFactory() abstract; + [[nodiscard]] virtual std::shared_ptr GetDrawingEngineFactory() abstract; virtual void DrawWeatherAnimation( OpenRCT2::Drawing::IWeatherDrawer* weatherDrawer, rct_drawpixelinfo* dpi, OpenRCT2::Drawing::DrawWeatherFunc drawFunc) abstract; @@ -158,6 +158,6 @@ namespace OpenRCT2 virtual ITitleSequencePlayer* GetTitleSequencePlayer() abstract; }; - std::shared_ptr CreateDummyUiContext(); + [[nodiscard]] std::shared_ptr CreateDummyUiContext(); } // namespace Ui } // namespace OpenRCT2 diff --git a/src/openrct2/world/Map.h b/src/openrct2/world/Map.h index ed0bdb7275..9427e13bf9 100644 --- a/src/openrct2/world/Map.h +++ b/src/openrct2/world/Map.h @@ -242,10 +242,10 @@ using CLEAR_FUNC = int32_t (*)(TileElement** tile_element, const CoordsXY& coord int32_t map_place_non_scenery_clear_func(TileElement** tile_element, const CoordsXY& coords, uint8_t flags, money32* price); int32_t map_place_scenery_clear_func(TileElement** tile_element, const CoordsXY& coords, uint8_t flags, money32* price); -std::unique_ptr MapCanConstructWithClearAt( +[[nodiscard]] std::unique_ptr MapCanConstructWithClearAt( const CoordsXYRangedZ& pos, CLEAR_FUNC clearFunc, QuarterTile quarterTile, uint8_t flags, uint8_t crossingMode = CREATE_CROSSING_MODE_NONE, bool isTree = false); -std::unique_ptr MapCanConstructAt(const CoordsXYRangedZ& pos, QuarterTile bl); +[[nodiscard]] std::unique_ptr MapCanConstructAt(const CoordsXYRangedZ& pos, QuarterTile bl); struct tile_element_iterator { diff --git a/test/tests/sawyercoding_test.cpp b/test/tests/sawyercoding_test.cpp index 1a72af0ddb..c449699192 100644 --- a/test/tests/sawyercoding_test.cpp +++ b/test/tests/sawyercoding_test.cpp @@ -118,56 +118,64 @@ TEST_F(SawyerCodingTest, invalid1) { OpenRCT2::MemoryStream ms(invalid1, sizeof(invalid1)); SawyerChunkReader reader(&ms); - EXPECT_THROW(reader.ReadChunk(), SawyerChunkException); + std::shared_ptr ptr; + EXPECT_THROW(ptr = reader.ReadChunk(), SawyerChunkException); } TEST_F(SawyerCodingTest, invalid2) { OpenRCT2::MemoryStream ms(invalid2, sizeof(invalid2)); SawyerChunkReader reader(&ms); - EXPECT_THROW(reader.ReadChunk(), SawyerChunkException); + std::shared_ptr ptr; + EXPECT_THROW(ptr = reader.ReadChunk(), SawyerChunkException); } TEST_F(SawyerCodingTest, invalid3) { OpenRCT2::MemoryStream ms(invalid3, sizeof(invalid3)); SawyerChunkReader reader(&ms); - EXPECT_THROW(reader.ReadChunk(), SawyerChunkException); + std::shared_ptr ptr; + EXPECT_THROW(ptr = reader.ReadChunk(), SawyerChunkException); } TEST_F(SawyerCodingTest, invalid4) { OpenRCT2::MemoryStream ms(invalid4, sizeof(invalid4)); SawyerChunkReader reader(&ms); - EXPECT_THROW(reader.ReadChunk(), SawyerChunkException); + std::shared_ptr ptr; + EXPECT_THROW(ptr = reader.ReadChunk(), SawyerChunkException); } TEST_F(SawyerCodingTest, invalid5) { OpenRCT2::MemoryStream ms(invalid5, sizeof(invalid5)); SawyerChunkReader reader(&ms); - EXPECT_THROW(reader.ReadChunk(), SawyerChunkException); + std::shared_ptr ptr; + EXPECT_THROW(ptr = reader.ReadChunk(), SawyerChunkException); } TEST_F(SawyerCodingTest, invalid6) { OpenRCT2::MemoryStream ms(invalid6, sizeof(invalid6)); SawyerChunkReader reader(&ms); - EXPECT_THROW(reader.ReadChunk(), SawyerChunkException); + std::shared_ptr ptr; + EXPECT_THROW(ptr = reader.ReadChunk(), SawyerChunkException); } TEST_F(SawyerCodingTest, invalid7) { OpenRCT2::MemoryStream ms(invalid7, sizeof(invalid7)); SawyerChunkReader reader(&ms); - EXPECT_THROW(reader.ReadChunk(), SawyerChunkException); + std::shared_ptr ptr; + EXPECT_THROW(ptr = reader.ReadChunk(), SawyerChunkException); } TEST_F(SawyerCodingTest, empty) { OpenRCT2::MemoryStream ms(empty, 0); SawyerChunkReader reader(&ms); - EXPECT_THROW(reader.ReadChunk(), IOException); + std::shared_ptr ptr; + EXPECT_THROW(ptr = reader.ReadChunk(), IOException); } // 1024 bytes of random data