diff --git a/lib/ivis_opengl/gfx_api_gl.cpp b/lib/ivis_opengl/gfx_api_gl.cpp index 29587f3524c..4e56396bd1a 100644 --- a/lib/ivis_opengl/gfx_api_gl.cpp +++ b/lib/ivis_opengl/gfx_api_gl.cpp @@ -3075,7 +3075,7 @@ bool gl_context::getScreenshot(std::function)> c return false; } - auto image = std::unique_ptr(new iV_Image()); + auto image = std::make_unique(); auto width = m_viewport[2]; auto height = m_viewport[3]; bool allocateResult = image->allocate(width, height, channelsPerPixel); // RGB diff --git a/lib/ivis_opengl/gfx_api_image_basis_priv.cpp b/lib/ivis_opengl/gfx_api_image_basis_priv.cpp index 86cfee7a150..2f990efeab5 100644 --- a/lib/ivis_opengl/gfx_api_image_basis_priv.cpp +++ b/lib/ivis_opengl/gfx_api_image_basis_priv.cpp @@ -409,7 +409,7 @@ static std::vector> loadiVImagesFromFile_Basis_Dat ASSERT_OR_RETURN({}, format == basist::transcoder_texture_format::cTFRGBA32, "Unsupported uncompressed format: %u", (unsigned)format); numBlocksOrPixels = level_info.m_orig_width * level_info.m_orig_height; - uncompressedOutput = std::unique_ptr(new iV_Image()); + uncompressedOutput = std::make_unique(); if (!uncompressedOutput->allocate(level_info.m_orig_width, level_info.m_orig_height, 4, false)) // hard-coded for RGBA32 for now { debug(LOG_ERROR, "Failed to allocate memory for uncompressed image buffer"); @@ -421,7 +421,7 @@ static std::vector> loadiVImagesFromFile_Basis_Dat numBlocksOrPixels = level_info.m_total_blocks; uint32_t outputSize = numBlocksOrPixels * bytes_per_block_or_pixel; - compressedOutput = std::unique_ptr(new iV_CompressedImage()); + compressedOutput = std::make_unique(); if (!compressedOutput->allocate(internalFormat, outputSize, level_info.m_width, level_info.m_height, level_info.m_orig_width, level_info.m_orig_height, false)) { debug(LOG_ERROR, "Failed to allocate memory for buffer"); diff --git a/lib/ivis_opengl/gfx_api_image_compress_priv.cpp b/lib/ivis_opengl/gfx_api_image_compress_priv.cpp index 6418f8b49c0..9a67d0f543c 100644 --- a/lib/ivis_opengl/gfx_api_image_compress_priv.cpp +++ b/lib/ivis_opengl/gfx_api_image_compress_priv.cpp @@ -286,7 +286,7 @@ static std::unique_ptr compressImageEtcPak(const iV_Image& i size_t outputSize = gfx_api::format_memory_size(desiredFormat, originalWidth, originalHeight); - std::unique_ptr compressedOutput = std::unique_ptr(new iV_CompressedImage()); + std::unique_ptr compressedOutput = std::make_unique(); if (!compressedOutput->allocate(desiredFormat, outputSize, alignedWidth, alignedHeight, originalWidth, originalHeight, false)) { debug(LOG_ERROR, "Failed to allocate memory for buffer"); diff --git a/lib/ivis_opengl/textdraw.cpp b/lib/ivis_opengl/textdraw.cpp index cf9096a118f..64cbfb118a0 100644 --- a/lib/ivis_opengl/textdraw.cpp +++ b/lib/ivis_opengl/textdraw.cpp @@ -1067,13 +1067,13 @@ static bool inline initializeCJKFontsIfNeeded() uint32_t horizDPI = static_cast(DEFAULT_DPI * _horizScaleFactor); uint32_t vertDPI = static_cast(DEFAULT_DPI * _vertScaleFactor); try { - cjkFonts->regular = std::unique_ptr(new FTFace(getGlobalFTlib().lib, CJK_FONT_PATH, 12 * 64, horizDPI, vertDPI, 400)); - cjkFonts->regularBold = std::unique_ptr(new FTFace(getGlobalFTlib().lib, CJK_FONT_PATH, 12 * 64, horizDPI, vertDPI, 700)); - cjkFonts->bold = std::unique_ptr(new FTFace(getGlobalFTlib().lib, CJK_FONT_PATH, 21 * 64, horizDPI, vertDPI, 400)); - cjkFonts->medium = std::unique_ptr(new FTFace(getGlobalFTlib().lib, CJK_FONT_PATH, 16 * 64, horizDPI, vertDPI, 400)); - cjkFonts->mediumBold = std::unique_ptr(new FTFace(getGlobalFTlib().lib, CJK_FONT_PATH, 16 * 64, horizDPI, vertDPI, 700)); - cjkFonts->small = std::unique_ptr(new FTFace(getGlobalFTlib().lib, CJK_FONT_PATH, 9 * 64, horizDPI, vertDPI, 400)); - cjkFonts->smallBold = std::unique_ptr(new FTFace(getGlobalFTlib().lib, CJK_FONT_PATH, 9 * 64, horizDPI, vertDPI, 700)); + cjkFonts->regular = std::make_unique(getGlobalFTlib().lib, CJK_FONT_PATH, 12 * 64, horizDPI, vertDPI, 400); + cjkFonts->regularBold = std::make_unique(getGlobalFTlib().lib, CJK_FONT_PATH, 12 * 64, horizDPI, vertDPI, 700); + cjkFonts->bold = std::make_unique(getGlobalFTlib().lib, CJK_FONT_PATH, 21 * 64, horizDPI, vertDPI, 400); + cjkFonts->medium = std::make_unique(getGlobalFTlib().lib, CJK_FONT_PATH, 16 * 64, horizDPI, vertDPI, 400); + cjkFonts->mediumBold = std::make_unique(getGlobalFTlib().lib, CJK_FONT_PATH, 16 * 64, horizDPI, vertDPI, 700); + cjkFonts->small = std::make_unique(getGlobalFTlib().lib, CJK_FONT_PATH, 9 * 64, horizDPI, vertDPI, 400); + cjkFonts->smallBold = std::make_unique(getGlobalFTlib().lib, CJK_FONT_PATH, 9 * 64, horizDPI, vertDPI, 700); } catch (const std::exception &e) { debug(LOG_ERROR, "Failed to load font:\n%s", e.what()); @@ -1175,13 +1175,13 @@ void iV_TextInit(unsigned int horizScalePercentage, unsigned int vertScalePercen } try { - baseFonts->regular = std::unique_ptr(new FTFace(getGlobalFTlib().lib, "fonts/DejaVuSans.ttf", 12 * 64, horizDPI, vertDPI)); - baseFonts->regularBold = std::unique_ptr(new FTFace(getGlobalFTlib().lib, "fonts/DejaVuSans-Bold.ttf", 12 * 64, horizDPI, vertDPI)); - baseFonts->bold = std::unique_ptr(new FTFace(getGlobalFTlib().lib, "fonts/DejaVuSans-Bold.ttf", 21 * 64, horizDPI, vertDPI)); - baseFonts->medium = std::unique_ptr(new FTFace(getGlobalFTlib().lib, "fonts/DejaVuSans.ttf", 16 * 64, horizDPI, vertDPI)); - baseFonts->mediumBold = std::unique_ptr(new FTFace(getGlobalFTlib().lib, "fonts/DejaVuSans-Bold.ttf", 16 * 64, horizDPI, vertDPI)); - baseFonts->small = std::unique_ptr(new FTFace(getGlobalFTlib().lib, "fonts/DejaVuSans.ttf", 9 * 64, horizDPI, vertDPI)); - baseFonts->smallBold = std::unique_ptr(new FTFace(getGlobalFTlib().lib, "fonts/DejaVuSans-Bold.ttf", 9 * 64, horizDPI, vertDPI)); + baseFonts->regular = std::make_unique(getGlobalFTlib().lib, "fonts/DejaVuSans.ttf", 12 * 64, horizDPI, vertDPI); + baseFonts->regularBold = std::make_unique(getGlobalFTlib().lib, "fonts/DejaVuSans-Bold.ttf", 12 * 64, horizDPI, vertDPI); + baseFonts->bold = std::make_unique(getGlobalFTlib().lib, "fonts/DejaVuSans-Bold.ttf", 21 * 64, horizDPI, vertDPI); + baseFonts->medium = std::make_unique(getGlobalFTlib().lib, "fonts/DejaVuSans.ttf", 16 * 64, horizDPI, vertDPI); + baseFonts->mediumBold = std::make_unique(getGlobalFTlib().lib, "fonts/DejaVuSans-Bold.ttf", 16 * 64, horizDPI, vertDPI); + baseFonts->small = std::make_unique(getGlobalFTlib().lib, "fonts/DejaVuSans.ttf", 9 * 64, horizDPI, vertDPI); + baseFonts->smallBold = std::make_unique(getGlobalFTlib().lib, "fonts/DejaVuSans-Bold.ttf", 9 * 64, horizDPI, vertDPI); } catch (const std::exception &e) { // Log lots of details: diff --git a/lib/netplay/netplay.h b/lib/netplay/netplay.h index d7fd9c07ec9..eb9f264c4c5 100644 --- a/lib/netplay/netplay.h +++ b/lib/netplay/netplay.h @@ -552,7 +552,7 @@ struct PlayerReference void disconnect() { - detached = std::unique_ptr(new PLAYER(NetPlay.players[index])); + detached = std::make_unique(NetPlay.players[index]); detached->wzFiles = std::make_shared>(); } diff --git a/lib/netplay/netreplay.cpp b/lib/netplay/netreplay.cpp index d88a0fb2b74..c1fcb7f6623 100644 --- a/lib/netplay/netreplay.cpp +++ b/lib/netplay/netreplay.cpp @@ -189,7 +189,7 @@ bool NETreplaySaveStart(std::string const& subdir, ReplayOptionsHandler const &o latestWriteBuffer.reserve(minBufferSizeToQueue); if (desiredBufferSize != std::numeric_limits::max()) { - saveThread = std::unique_ptr(new wz::thread(replaySaveThreadFunc, replaySaveHandle)); + saveThread = std::make_unique(replaySaveThreadFunc, replaySaveHandle); } else { @@ -415,7 +415,7 @@ bool NETreplayLoadNetMessage(std::unique_ptr &message, uint8_t &play return false; } - message = std::unique_ptr(new NetMessage(type)); + message = std::make_unique(type); message->data.resize(len); size_t messageRead = WZ_PHYSFS_readBytes(replayLoadHandle, message->data.data(), message->data.size()); if (messageRead != message->data.size()) diff --git a/lib/netplay/nettypes.cpp b/lib/netplay/nettypes.cpp index 5b7d7543878..3309ad8d4b2 100644 --- a/lib/netplay/nettypes.cpp +++ b/lib/netplay/nettypes.cpp @@ -1064,7 +1064,7 @@ bool NETloadReplay(std::string const &filename, ReplayOptionsHandler& optionsHan return false; } // Add special REPLAY_ENDED message to the end of the host's gameQueue - newMessage = std::unique_ptr(new NetMessage(REPLAY_ENDED)); + newMessage = std::make_unique(REPLAY_ENDED); gameQueues[NetPlay.hostPlayer]->pushMessage(*newMessage); NETreplayLoadStop(); bIsReplay = true; diff --git a/lib/sdl/gfx_api_sdl.cpp b/lib/sdl/gfx_api_sdl.cpp index 12296d7d58a..7e77ef3a9dd 100644 --- a/lib/sdl/gfx_api_sdl.cpp +++ b/lib/sdl/gfx_api_sdl.cpp @@ -32,13 +32,13 @@ SDL_gfx_api_Impl_Factory::SDL_gfx_api_Impl_Factory(SDL_Window* _window, SDL_gfx_ std::unique_ptr SDL_gfx_api_Impl_Factory::createNullBackendImpl() const { - return std::unique_ptr(new sdl_Null_Impl()); + return std::make_unique(); } std::unique_ptr SDL_gfx_api_Impl_Factory::createOpenGLBackendImpl() const { ASSERT_OR_RETURN(nullptr, window != nullptr, "Invalid SDL_Window*"); - return std::unique_ptr(new sdl_OpenGL_Impl(window, config.useOpenGLES, config.useOpenGLESLibrary)); + return std::make_unique(window, config.useOpenGLES, config.useOpenGLESLibrary); } #if defined(WZ_VULKAN_ENABLED) @@ -46,7 +46,7 @@ std::unique_ptr SDL_gfx_api_Impl_Factory::createVu { ASSERT_OR_RETURN(nullptr, window != nullptr, "Invalid SDL_Window*"); #if defined(HAVE_SDL_VULKAN_H) - return std::unique_ptr(new sdl_Vulkan_Impl(window, config.allowImplicitLayers)); + return std::make_unique(window, config.allowImplicitLayers); #else // !defined(HAVE_SDL_VULKAN_H) SDL_version compiled_version; SDL_VERSION(&compiled_version); diff --git a/lib/sound/oggvorbis.cpp b/lib/sound/oggvorbis.cpp index 8b0a04092b0..b98d07bd94c 100644 --- a/lib/sound/oggvorbis.cpp +++ b/lib/sound/oggvorbis.cpp @@ -145,7 +145,7 @@ WZVorbisDecoder* WZVorbisDecoder::fromFilename(const char* fileName) debug(LOG_ERROR, "sound_LoadTrackFromFile: PHYSFS_openRead(\"%s\") failed with error: %s\n", fileName, WZ_PHYSFS_getLastError()); return nullptr; } - std::unique_ptr ovf = std::unique_ptr(new OggVorbis_File()); + std::unique_ptr ovf = std::make_unique(); // https://xiph.org/vorbis/doc/vorbisfile/ov_open_callbacks.html const int error = ov_open_callbacks(fileHandle, ovf.get(), nullptr, 0, wz_oggVorbis_callbacks); if (error != 0) diff --git a/lib/widget/paragraph.cpp b/lib/widget/paragraph.cpp index fc2ce580679..51a0c995fe4 100644 --- a/lib/widget/paragraph.cpp +++ b/lib/widget/paragraph.cpp @@ -480,14 +480,14 @@ std::vector> Paragraph::calculateLinesLayout() void Paragraph::addText(std::string const &text) { layoutDirty = true; - elements.push_back(std::unique_ptr(new ParagraphTextElement(text, textStyle))); + elements.push_back(std::make_unique(text, textStyle)); } void Paragraph::addWidget(const std::shared_ptr &widget, int32_t aboveBase) { layoutDirty = true; attach(widget); - elements.push_back(std::unique_ptr(new ParagraphWidgetElement(widget, aboveBase))); + elements.push_back(std::make_unique(widget, aboveBase)); } void Paragraph::geometryChanged() diff --git a/lib/widget/paragraph.h b/lib/widget/paragraph.h index 3754b4e49c6..4a571a49c09 100644 --- a/lib/widget/paragraph.h +++ b/lib/widget/paragraph.h @@ -72,7 +72,7 @@ class WzCachedText { if (!cachedText) { - cachedText = std::unique_ptr(new WzText(text, font)); + cachedText = std::make_unique(text, font); } cacheExpireAt = realTime + (cacheDurationMs * GAME_TICKS_PER_SEC) / 1000; diff --git a/lib/wzmaplib/CMakeLists.txt b/lib/wzmaplib/CMakeLists.txt index 58781180a8e..838dfbe8844 100644 --- a/lib/wzmaplib/CMakeLists.txt +++ b/lib/wzmaplib/CMakeLists.txt @@ -45,7 +45,7 @@ set_target_properties(wzmaplib PROPERTIES VERSION "${WZMAPLIB_VERSION_STRING}") set_target_properties(wzmaplib PROPERTIES - CXX_STANDARD 11 + CXX_STANDARD 14 CXX_STANDARD_REQUIRED YES CXX_EXTENSIONS NO ) @@ -170,7 +170,7 @@ if (libzip_FOUND AND libzip_LINK_TEST) set_property(TARGET ZipIOProvider PROPERTY FOLDER "lib") set_target_properties(ZipIOProvider PROPERTIES - CXX_STANDARD 11 + CXX_STANDARD 14 CXX_STANDARD_REQUIRED YES CXX_EXTENSIONS NO ) diff --git a/lib/wzmaplib/include/wzmaplib/map.h b/lib/wzmaplib/include/wzmaplib/map.h index b2b8a8f54c7..5551981cc82 100644 --- a/lib/wzmaplib/include/wzmaplib/map.h +++ b/lib/wzmaplib/include/wzmaplib/map.h @@ -128,7 +128,7 @@ std::string to_string(MapType mapType); class Map { private: - Map(const std::string& mapFolderPath, MapType mapType, uint32_t mapMaxPlayers, std::shared_ptr logger, std::shared_ptr mapIO = std::shared_ptr(new StdIOProvider())); + Map(const std::string& mapFolderPath, MapType mapType, uint32_t mapMaxPlayers, std::shared_ptr logger, std::shared_ptr mapIO = std::make_shared()); public: // Construct an empty Map, for modification @@ -138,10 +138,10 @@ class Map // - seed (a seed used for random script-based maps generation) // - a logger // - a WzMap::IOProvider - static std::shared_ptr loadFromPath(const std::string& mapFolderPath, MapType mapType, uint32_t mapMaxPlayers, uint32_t seed, std::shared_ptr logger = nullptr, std::shared_ptr mapIO = std::shared_ptr(new StdIOProvider())); + static std::shared_ptr loadFromPath(const std::string& mapFolderPath, MapType mapType, uint32_t mapMaxPlayers, uint32_t seed, std::shared_ptr logger = nullptr, std::shared_ptr mapIO = std::make_shared()); // Export a map to a specified folder path in a specified output format (version) - static bool exportMapToPath(Map& map, const std::string& mapFolderPath, MapType mapType, uint32_t mapMaxPlayers, OutputFormat format, std::shared_ptr logger = nullptr, std::shared_ptr mapIO = std::shared_ptr(new StdIOProvider())); + static bool exportMapToPath(Map& map, const std::string& mapFolderPath, MapType mapType, uint32_t mapMaxPlayers, OutputFormat format, std::shared_ptr logger = nullptr, std::shared_ptr mapIO = std::make_shared()); // High-level data loading functions diff --git a/lib/wzmaplib/include/wzmaplib/map_package.h b/lib/wzmaplib/include/wzmaplib/map_package.h index 78f9ddc11f7..1700d0c9b74 100644 --- a/lib/wzmaplib/include/wzmaplib/map_package.h +++ b/lib/wzmaplib/include/wzmaplib/map_package.h @@ -115,7 +115,7 @@ class MapPackage // The default StdIOProvider will assume pathToMapPackage is a path to an extracted map package (i.e. standard filesystem I/O) // // To load from an archive (.zip/.wz), create a custom implementation of WzMap::IOProvider that supports compressed archive files that you initialize with the path to the zip. An example of this (which uses libzip) is available in `plugins/ZipIOProvider`. You would then set `pathToMapPackage` to be the root path inside the zip. (In the case of plugins\ZipIOProvider, literally "/" or ""). - static std::unique_ptr loadPackage(const std::string& pathToMapPackage, std::shared_ptr logger = nullptr, std::shared_ptr mapIO = std::shared_ptr(new StdIOProvider())); + static std::unique_ptr loadPackage(const std::string& pathToMapPackage, std::shared_ptr logger = nullptr, std::shared_ptr mapIO = std::make_shared()); // Construct a new MapPackage object (which can then be exported) MapPackage(const LevelDetails& levelDetails, MapType mapType, std::shared_ptr map); @@ -123,7 +123,7 @@ class MapPackage // Export the currently-loaded map package to a specified path in a specified format // Can convert both the LevelFormat and the WzMap::OutputFormat bool exportMapPackageFiles(std::string basePath, LevelFormat levelFormat, WzMap::OutputFormat mapOutputFormat, - optional mapFolderRelativePathOverride = nullopt, bool copyAdditionalFilesFromOriginalLoadedPackage = false, std::shared_ptr logger = nullptr, std::shared_ptr exportIO = std::shared_ptr(new StdIOProvider())); + optional mapFolderRelativePathOverride = nullopt, bool copyAdditionalFilesFromOriginalLoadedPackage = false, std::shared_ptr logger = nullptr, std::shared_ptr exportIO = std::make_shared()); // High-level data loading functions diff --git a/lib/wzmaplib/src/map_package.cpp b/lib/wzmaplib/src/map_package.cpp index 1e1f415983d..dfa303ab0bb 100644 --- a/lib/wzmaplib/src/map_package.cpp +++ b/lib/wzmaplib/src/map_package.cpp @@ -1115,7 +1115,7 @@ MapPackage::MapPackage() // The default StdIOProvider will assume pathToMapPackage is a path to an extracted map package (i.e. standard filesystem I/O) // // To load from an archive (.zip/.wz), create a custom implementation of WzMap::IOProvider that supports compressed archive files that you initialize with the path to the zip. An example of this (which uses libzip) is available in `plugins/ZipIOProvider`. You would then set `pathToMapPackage` to be the root path inside the zip. (In the case of plugins\ZipIOProvider, literally `/`). -std::unique_ptr MapPackage::loadPackage(const std::string& pathToMapPackage, std::shared_ptr logger /*= nullptr*/, std::shared_ptr pMapIO /*= std::shared_ptr(new StdIOProvider())*/) +std::unique_ptr MapPackage::loadPackage(const std::string& pathToMapPackage, std::shared_ptr logger /*= nullptr*/, std::shared_ptr pMapIO /*= std::make_shared()*/) { LoggingProtocol* pCustomLogger = logger.get(); if (!pMapIO) @@ -1287,7 +1287,7 @@ static bool copyFile_IOProviders(const std::string& readPath, const std::string& // Export the currently-loaded map package to a specified path in a specified format // Can convert both the LevelFormat and the WzMap::OutputFormat bool MapPackage::exportMapPackageFiles(std::string basePath, LevelFormat levelFormat, WzMap::OutputFormat mapOutputFormat, - optional mapFolderRelativePathOverride /*= nullopt*/, bool copyAdditionalFilesFromOriginalLoadedPackage /*= false*/, std::shared_ptr logger /*= nullptr*/, std::shared_ptr exportIO /*= std::shared_ptr(new StdIOProvider())*/) + optional mapFolderRelativePathOverride /*= nullopt*/, bool copyAdditionalFilesFromOriginalLoadedPackage /*= false*/, std::shared_ptr logger /*= nullptr*/, std::shared_ptr exportIO /*= std::make_shared()*/) { LoggingProtocol* pCustomLogger = logger.get(); if (!exportIO) diff --git a/lib/wzmaplib/src/map_preview.cpp b/lib/wzmaplib/src/map_preview.cpp index cbc9de05cda..7b433402b30 100644 --- a/lib/wzmaplib/src/map_preview.cpp +++ b/lib/wzmaplib/src/map_preview.cpp @@ -239,7 +239,7 @@ bool plotStructurePreviewWzMap(Map &wzMap, const MapPreviewColorScheme& colorSch MapPlayerColorProvider* pPlayerColorProvider = colorScheme.playerColorProvider.get(); if (!pPlayerColorProvider) { - defaultPlayerColorProvider = std::unique_ptr(new MapPlayerColorProvider()); + defaultPlayerColorProvider = std::make_unique(); pPlayerColorProvider = defaultPlayerColorProvider.get(); } @@ -295,7 +295,7 @@ std::unique_ptr generate2DMapPreview(Map& wzMap, const MapPrevi const TilesetColorScheme& clrSch = colorScheme.tilesetColors; - std::unique_ptr result = std::unique_ptr(new MapPreviewImage()); + std::unique_ptr result = std::make_unique(); result->width = mapData->width; result->height = mapData->height; result->channels = 3; diff --git a/src/activity.cpp b/src/activity.cpp index 0774f6baefe..96fd3ccba29 100644 --- a/src/activity.cpp +++ b/src/activity.cpp @@ -220,12 +220,12 @@ class ActivityDatabase : public ActivityDBProtocol // Caller is expected to handle thrown exceptions ActivityDatabase(const std::string& activityDatabasePath) { - db = std::unique_ptr(new SQLite::Database(activityDatabasePath, SQLite::OPEN_READWRITE | SQLite::OPEN_CREATE)); + db = std::make_unique(activityDatabasePath, SQLite::OPEN_READWRITE | SQLite::OPEN_CREATE); db->exec("PRAGMA journal_mode=WAL"); createTables(); - query_findValueByName = std::unique_ptr(new SQLite::Statement(*db, "SELECT value FROM general_kv_storage WHERE name = ?")); - query_insertValueForName = std::unique_ptr(new SQLite::Statement(*db, "INSERT OR IGNORE INTO general_kv_storage(name, value) VALUES(?, ?)")); - query_updateValueForName = std::unique_ptr(new SQLite::Statement(*db, "UPDATE general_kv_storage SET value = ? WHERE name = ?")); + query_findValueByName = std::make_unique(*db, "SELECT value FROM general_kv_storage WHERE name = ?"); + query_insertValueForName = std::make_unique(*db, "INSERT OR IGNORE INTO general_kv_storage(name, value) VALUES(?, ?)"); + query_updateValueForName = std::make_unique(*db, "UPDATE general_kv_storage SET value = ? WHERE name = ?"); } public: // Must be thread-safe diff --git a/src/display.cpp b/src/display.cpp index c56553ca369..cb01ea8bab7 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -123,8 +123,8 @@ static UDWORD currentFrame; static UDWORD StartOfLastFrame; static SDWORD rotX; static SDWORD rotY; -std::unique_ptr rotationHorizontalTracker = std::unique_ptr(new ValueTracker()); -std::unique_ptr rotationVerticalTracker = std::unique_ptr(new ValueTracker()); +std::unique_ptr rotationHorizontalTracker = std::make_unique(); +std::unique_ptr rotationVerticalTracker = std::make_unique(); static uint32_t scrollRefTime; static float scrollSpeedLeftRight; //use two directions and add them because its simple static float scrollStepLeftRight; @@ -648,8 +648,8 @@ static void HandleDrag() UDWORD panMouseX; // Mouse Y coordinate at start of panning. UDWORD panMouseY; -std::unique_ptr panXTracker = std::unique_ptr(new ValueTracker()); -std::unique_ptr panZTracker = std::unique_ptr(new ValueTracker()); +std::unique_ptr panXTracker = std::make_unique(); +std::unique_ptr panZTracker = std::make_unique(); bool panActive; //don't want to do any of these whilst in the Intelligence Screen diff --git a/src/display3d.cpp b/src/display3d.cpp index 562f0ddb9f1..859b9a2db33 100644 --- a/src/display3d.cpp +++ b/src/display3d.cpp @@ -2065,11 +2065,11 @@ static void renderBuildOrder(uint8_t droidPlayer, DroidOrder const &order, STRUC } } -std::unique_ptr playerBlueprint = std::unique_ptr(new Blueprint()); -std::unique_ptr playerBlueprintX = std::unique_ptr(new ValueTracker()); -std::unique_ptr playerBlueprintY = std::unique_ptr(new ValueTracker()); -std::unique_ptr playerBlueprintZ = std::unique_ptr(new ValueTracker()); -std::unique_ptr playerBlueprintDirection = std::unique_ptr(new ValueTracker()); +std::unique_ptr playerBlueprint = std::make_unique(); +std::unique_ptr playerBlueprintX = std::make_unique(); +std::unique_ptr playerBlueprintY = std::make_unique(); +std::unique_ptr playerBlueprintZ = std::make_unique(); +std::unique_ptr playerBlueprintDirection = std::make_unique(); void displayBlueprints(const glm::mat4 &viewMatrix, const glm::mat4 &perspectiveViewMatrix) { diff --git a/src/game.cpp b/src/game.cpp index ff4b0a2fb4f..47a660be357 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -7059,7 +7059,7 @@ bool loadSaveTemplate(const char *pFileName) ini.beginArray("templates"); while (ini.remainingArrayItems() > 0) { - addTemplate(player, std::unique_ptr(new DROID_TEMPLATE(loadTemplate()))); + addTemplate(player, std::make_unique(loadTemplate())); } ini.endArray(); ini.endGroup(); diff --git a/src/init.cpp b/src/init.cpp index 49020cf6a30..73e2ff29555 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -273,7 +273,7 @@ static void cleanSearchPath() void registerSearchPath(const std::string& newPath, unsigned int priority) { ASSERT_OR_RETURN(, !newPath.empty(), "Calling registerSearchPath with empty path, priority %u", priority); - std::unique_ptr tmpSearchPath = std::unique_ptr(new wzSearchPath()); + std::unique_ptr tmpSearchPath = std::make_unique(); tmpSearchPath->path = newPath; if (!strEndsWith(tmpSearchPath->path, PHYSFS_getDirSeparator())) { diff --git a/src/map.cpp b/src/map.cpp index 4cc885f3b7c..55ee96934b3 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -261,7 +261,7 @@ static void init_tileNames(MAP_TILESET type) numTile_names = numlines; //increment the pointer to the start of the next record pFileData = strchr(pFileData, '\n') + 1; - Tile_names = std::unique_ptr(new char[numlines * MAX_STR_LENGTH]()); + Tile_names = std::make_unique(numlines * MAX_STR_LENGTH); for (i = 0; i < numlines; i++) { @@ -673,8 +673,8 @@ static void SetDecals(const char *filename, const char *decal_type) //increment the pointer to the start of the next record pFileData = strchr(pFileData, '\n') + 1; // value initialization sets everything to false. - mapDecals = std::unique_ptr(new bool[MAX_TERRAIN_TILES]()); - + mapDecals = std::make_unique(MAX_TERRAIN_TILES); + for (i = 0; i < numlines; i++) { tiledecal = -1; @@ -1011,7 +1011,7 @@ bool mapLoadFromWzMapData(std::shared_ptr loadedMap) ASSERT(psMapTiles == nullptr, "Map has not been cleared before calling mapLoad()!"); /* Allocate the memory for the map */ - psMapTiles = std::unique_ptr(new MAPTILE[width * height]()); + psMapTiles = std::make_unique(static_cast(width) * height); ASSERT(psMapTiles != nullptr, "Out of memory"); mapWidth = width; @@ -1104,12 +1104,12 @@ static bool afterMapLoad() /* Allocate aux maps */ ASSERT(mapWidth >= 0 && mapHeight >= 0, "Invalid mapWidth or mapHeight (%d x %d)", mapWidth, mapHeight); const size_t mapSize = static_cast(mapWidth) * static_cast(mapHeight); - psBlockMap[AUX_MAP] = std::unique_ptr(new uint8_t[mapSize]()); - psBlockMap[AUX_ASTARMAP] = std::unique_ptr(new uint8_t[mapSize]()); - psBlockMap[AUX_DANGERMAP] = std::unique_ptr(new uint8_t[mapSize]()); + psBlockMap[AUX_MAP] = std::make_unique(mapSize); + psBlockMap[AUX_ASTARMAP] = std::make_unique(mapSize); + psBlockMap[AUX_DANGERMAP] = std::make_unique(mapSize); for (int x = 0; x < MAX_PLAYERS + AUX_MAX; ++x) { - psAuxMap[x] = std::unique_ptr (new uint8_t[mapSize]()); + psAuxMap[x] = std::make_unique (mapSize); } // Set our blocking bits diff --git a/src/multiint.cpp b/src/multiint.cpp index de7e0cad812..6bbea0894f7 100644 --- a/src/multiint.cpp +++ b/src/multiint.cpp @@ -754,7 +754,7 @@ void loadMapPreview(bool hideInterface) previewColorScheme.hqColor = PIELIGHT_to_MapPreviewColor(WZCOL_MAP_PREVIEW_HQ); previewColorScheme.oilResourceColor = PIELIGHT_to_MapPreviewColor(WZCOL_MAP_PREVIEW_OIL); previewColorScheme.oilBarrelColor = PIELIGHT_to_MapPreviewColor(WZCOL_MAP_PREVIEW_BARREL); - previewColorScheme.playerColorProvider = std::unique_ptr(new WzLobbyPreviewPlayerColorProvider()); + previewColorScheme.playerColorProvider = std::make_unique(); switch (guessMapTilesetType(psLevel)) { case MAP_TILESET::ARIZONA: diff --git a/src/multistat.cpp b/src/multistat.cpp index 4334320c1f5..90191472cfc 100644 --- a/src/multistat.cpp +++ b/src/multistat.cpp @@ -821,15 +821,15 @@ class KnownPlayersDB { // Caller is expected to handle thrown exceptions KnownPlayersDB(const std::string& knownPlayersDBPath) { - db = std::unique_ptr(new SQLite::Database(knownPlayersDBPath, SQLite::OPEN_READWRITE | SQLite::OPEN_CREATE)); + db = std::make_unique(knownPlayersDBPath, SQLite::OPEN_READWRITE | SQLite::OPEN_CREATE); db->exec("PRAGMA journal_mode=WAL"); createKnownPlayersDBTables(); - query_findPlayerIdentityByName = std::unique_ptr(new SQLite::Statement(*db, "SELECT local_id, name, pk FROM known_players WHERE name = ?")); - query_insertNewKnownPlayer = std::unique_ptr(new SQLite::Statement(*db, "INSERT OR IGNORE INTO known_players(name, pk) VALUES(?, ?)")); - query_updateKnownPlayerKey = std::unique_ptr(new SQLite::Statement(*db, "UPDATE known_players SET pk = ? WHERE name = ?")); - query_findPlayerOptionsByPK = std::unique_ptr(new SQLite::Statement(*db, "SELECT name, muted, banned FROM player_options WHERE pk = ?")); - query_insertNewPlayerOptions = std::unique_ptr(new SQLite::Statement(*db, "INSERT OR IGNORE INTO player_options(pk, name, muted, banned) VALUES(?, ?, ?, ?)")); - query_updatePlayerOptionsMuted = std::unique_ptr(new SQLite::Statement(*db, "UPDATE player_options SET muted = ? WHERE pk = ? AND name = ?")); + query_findPlayerIdentityByName = std::make_unique(*db, "SELECT local_id, name, pk FROM known_players WHERE name = ?"); + query_insertNewKnownPlayer = std::make_unique(*db, "INSERT OR IGNORE INTO known_players(name, pk) VALUES(?, ?)"); + query_updateKnownPlayerKey = std::make_unique(*db, "UPDATE known_players SET pk = ? WHERE name = ?"); + query_findPlayerOptionsByPK = std::make_unique(*db, "SELECT name, muted, banned FROM player_options WHERE pk = ?"); + query_insertNewPlayerOptions = std::make_unique(*db, "INSERT OR IGNORE INTO player_options(pk, name, muted, banned) VALUES(?, ?, ?, ?)"); + query_updatePlayerOptionsMuted = std::make_unique(*db, "UPDATE player_options SET muted = ? WHERE pk = ? AND name = ?"); } public: @@ -1054,7 +1054,7 @@ void initKnownPlayers() ASSERT_OR_RETURN(, pWriteDir, "PHYSFS_getWriteDir returned null"); std::string knownPlayersDBPath = std::string(pWriteDir) + "/" + "knownPlayers.db"; try { - knownPlayersDB = std::unique_ptr(new KnownPlayersDB(knownPlayersDBPath)); + knownPlayersDB = std::make_unique(knownPlayersDBPath); } catch (std::exception& e) { // error loading SQLite database diff --git a/src/notifications.cpp b/src/notifications.cpp index fe3c111f5ce..6be4650cc56 100644 --- a/src/notifications.cpp +++ b/src/notifications.cpp @@ -1305,7 +1305,7 @@ void addNotification(const WZ_Notification& notification, const WZ_Notification_ } // Add the notification to the notification system's queue - notificationQueue.push_back(std::unique_ptr(new WZ_Queued_Notification(notification, WZ_Notification_Status(realTime), trigger))); + notificationQueue.push_back(std::make_unique(notification, WZ_Notification_Status(realTime), trigger)); } bool removeNotificationPreferencesIf(const std::function& matchIdentifierFunc) diff --git a/src/quickjs_backend.cpp b/src/quickjs_backend.cpp index 8e57f6dd29e..ab49257f1c8 100644 --- a/src/quickjs_backend.cpp +++ b/src/quickjs_backend.cpp @@ -2430,7 +2430,7 @@ static uniqueTimerID SetQuickJSTimer(JSContext *ctx, int player, const std::stri } , player, ms, funcName, psObj, type // additionalParams - , std::unique_ptr(new quickjs_timer_additionaldata(stringArg))); + , std::make_unique(stringArg)); } //-- ## setTimer(functionName, milliseconds[, object]) @@ -2845,7 +2845,7 @@ std::tuple> quickjs_scripting_in std::for_each(args.begin(), args.end(), [pContext](JSValue& val) { JS_FreeValue(pContext, val); }); } // additionalParams - , std::unique_ptr(new quickjs_timer_additionaldata(stringArg)) + , std::make_unique(stringArg) }; } diff --git a/src/template.cpp b/src/template.cpp index ff62130a991..0288f7ba47f 100644 --- a/src/template.cpp +++ b/src/template.cpp @@ -558,7 +558,7 @@ bool loadDroidTemplates(const char *filename) DROID_TEMPLATE *copyTemplate(int player, DROID_TEMPLATE *psTemplate) { - auto dup = std::unique_ptr(new DROID_TEMPLATE(*psTemplate)); + auto dup = std::make_unique(*psTemplate); return addTemplate(player, std::move(dup)); } diff --git a/src/terrain.cpp b/src/terrain.cpp index aa041434e26..d3efa5bebe7 100644 --- a/src/terrain.cpp +++ b/src/terrain.cpp @@ -945,7 +945,7 @@ void loadWaterTextures(int maxTerrainTextureSize, optional maxTerrainAuxTex })) { waterTexturesHigh.tex_nm = gfx_api::context::get().loadTextureArrayFromFiles(waterTextureFilenames_nm, gfx_api::texture_type::normal_map, maxTerrainAuxTextureSize, maxTerrainAuxTextureSize, [](int width, int height, int channels) -> std::unique_ptr { - std::unique_ptr pDefaultNormalMap = std::unique_ptr(new iV_Image); + std::unique_ptr pDefaultNormalMap = std::make_unique(); pDefaultNormalMap->allocate(width, height, channels, true); // default normal map: (0,0,1) unsigned char* pBmpWrite = pDefaultNormalMap->bmp_w(); @@ -967,7 +967,7 @@ void loadWaterTextures(int maxTerrainTextureSize, optional maxTerrainAuxTex })) { waterTexturesHigh.tex_sm = gfx_api::context::get().loadTextureArrayFromFiles(waterTextureFilenames_sm, gfx_api::texture_type::specular_map, maxTerrainAuxTextureSize, maxTerrainAuxTextureSize, [](int width, int height, int channels) -> std::unique_ptr { - std::unique_ptr pDefaultSpecularMap = std::unique_ptr(new iV_Image); + std::unique_ptr pDefaultSpecularMap = std::make_unique(); // default specular map: 0 pDefaultSpecularMap->allocate(width, height, channels, true); return pDefaultSpecularMap; @@ -1036,7 +1036,7 @@ void loadTerrainTextures_SinglePass(MAP_TILESET mapTileset) })) { groundNormalArr = gfx_api::context::get().loadTextureArrayFromFiles(groundTextureFilenames_nm, gfx_api::texture_type::normal_map, maxTerrainAuxTextureSize, maxTerrainAuxTextureSize, [](int width, int height, int channels) -> std::unique_ptr { - std::unique_ptr pDefaultNormalMap = std::unique_ptr(new iV_Image); + std::unique_ptr pDefaultNormalMap = std::make_unique(); pDefaultNormalMap->allocate(width, height, channels, true); // default normal map: (0,0,1) unsigned char* pBmpWrite = pDefaultNormalMap->bmp_w(); @@ -1058,7 +1058,7 @@ void loadTerrainTextures_SinglePass(MAP_TILESET mapTileset) })) { groundSpecularArr = gfx_api::context::get().loadTextureArrayFromFiles(groundTextureFilenames_spec, gfx_api::texture_type::specular_map, maxTerrainAuxTextureSize, maxTerrainAuxTextureSize, [](int width, int height, int channels) -> std::unique_ptr { - std::unique_ptr pDefaultSpecularMap = std::unique_ptr(new iV_Image); + std::unique_ptr pDefaultSpecularMap = std::make_unique(); // default specular map: 0 pDefaultSpecularMap->allocate(width, height, channels, true); return pDefaultSpecularMap; @@ -1070,7 +1070,7 @@ void loadTerrainTextures_SinglePass(MAP_TILESET mapTileset) })) { groundHeightArr = gfx_api::context::get().loadTextureArrayFromFiles(groundTextureFilenames_height, gfx_api::texture_type::height_map, maxTerrainAuxTextureSize, maxTerrainAuxTextureSize, [](int width, int height, int channels) -> std::unique_ptr { - std::unique_ptr pDefaultHeightMap = std::unique_ptr(new iV_Image); + std::unique_ptr pDefaultHeightMap = std::make_unique(); // default height map: 0 pDefaultHeightMap->allocate(width, height, channels, true); return pDefaultHeightMap; @@ -1517,7 +1517,7 @@ bool initTerrain() lightmapValues.ModelUVLightmap = lightmapValues.lightMatrix * glm::transpose(glm::mat4(lightmapValues.paramsXLight, lightmapValues.paramsYLight, glm::vec4(0,0,1,0), glm::vec4(0,0,0,1))); // Prepare the lightmap pixmap and texture - lightmapPixmap = std::unique_ptr(new iV_Image()); + lightmapPixmap = std::make_unique(); unsigned int lightmapChannels = 4; // always use 4-channel (RGBA) if (lightmapPixmap == nullptr || !lightmapPixmap->allocate(lightmapWidth, lightmapHeight, lightmapChannels, true)) @@ -1703,12 +1703,12 @@ static void cullTerrain() static void drawDepthOnly(const glm::mat4 &ModelViewProjection, const glm::vec4 ¶msXLight, const glm::vec4 ¶msYLight, bool withOffset) { const auto &renderState = getCurrentRenderState(); - + // bind the vertex buffer gfx_api::TerrainDepth::get().bind(); gfx_api::TerrainDepth::get().bind_textures(lightmap_texture); gfx_api::TerrainDepth::get().bind_vertex_buffers(geometryVBO); - gfx_api::TerrainDepth::get().bind_constants({ ModelViewProjection, paramsXLight, paramsYLight, glm::vec4(0.f), glm::vec4(0.f), glm::mat4(1.f), glm::mat4(1.f), + gfx_api::TerrainDepth::get().bind_constants({ ModelViewProjection, paramsXLight, paramsYLight, glm::vec4(0.f), glm::vec4(0.f), glm::mat4(1.f), glm::mat4(1.f), glm::vec4(0.f), renderState.fogEnabled, renderState.fogBegin, renderState.fogEnd, 0, 0 }); gfx_api::context::get().bind_index_buffer(*geometryIndexVBO, gfx_api::index_type::u32); diff --git a/src/texture.cpp b/src/texture.cpp index 3eda70d52f6..5638ce147bd 100644 --- a/src/texture.cpp +++ b/src/texture.cpp @@ -377,7 +377,7 @@ bool texLoad(const char *fileName) if (has_nm) { decalNormalArr = gfx_api::context::get().loadTextureArrayFromFiles(tile_nm_filepaths, gfx_api::texture_type::normal_map, mipmap_max, mipmap_max, [](int width, int height, int channels) -> std::unique_ptr { - std::unique_ptr pDefaultNormalMap = std::unique_ptr(new iV_Image); + std::unique_ptr pDefaultNormalMap = std::make_unique(); pDefaultNormalMap->allocate(width, height, channels, true); // default normal map: (0,0,1) unsigned char* pBmpWrite = pDefaultNormalMap->bmp_w(); @@ -397,7 +397,7 @@ bool texLoad(const char *fileName) if (has_sm) { decalSpecularArr = gfx_api::context::get().loadTextureArrayFromFiles(tile_sm_filepaths, gfx_api::texture_type::specular_map, mipmap_max, mipmap_max, [](int width, int height, int channels) -> std::unique_ptr { - std::unique_ptr pDefaultSpecularMap = std::unique_ptr(new iV_Image); + std::unique_ptr pDefaultSpecularMap = std::make_unique(); // default specular map: 0 pDefaultSpecularMap->allocate(width, height, channels, true); return pDefaultSpecularMap; @@ -407,7 +407,7 @@ bool texLoad(const char *fileName) if (has_hm) { decalHeightArr = gfx_api::context::get().loadTextureArrayFromFiles(tile_hm_filepaths, gfx_api::texture_type::height_map, mipmap_max, mipmap_max, [](int width, int height, int channels) -> std::unique_ptr { - std::unique_ptr pDefaultHeightMap = std::unique_ptr(new iV_Image); + std::unique_ptr pDefaultHeightMap = std::make_unique(); // default height map: 0 pDefaultHeightMap->allocate(width, height, channels, true); return pDefaultHeightMap; diff --git a/src/wzapi.cpp b/src/wzapi.cpp index fe40ed60b7f..7fbccf0d0cd 100644 --- a/src/wzapi.cpp +++ b/src/wzapi.cpp @@ -1732,7 +1732,7 @@ static int get_first_available_component(int player, int capacity, const wzapi:: static std::unique_ptr makeTemplate(int player, const std::string &templateName, const wzapi::string_or_string_list& _body, const wzapi::string_or_string_list& _propulsion, const wzapi::va_list& _turrets, int capacity, bool strict) { - std::unique_ptr psTemplate = std::unique_ptr(new DROID_TEMPLATE); + std::unique_ptr psTemplate = std::make_unique(); size_t numTurrets = _turrets.va_list.size(); int result;