diff --git a/conanfile.py b/conanfile.py index ae2e91f83..4392cc0b8 100644 --- a/conanfile.py +++ b/conanfile.py @@ -17,7 +17,7 @@ class StormEngine(ConanFile): # dependencies used in deploy binaries # conan-center - requires = ["zlib/1.2.13", "spdlog/1.9.2", "fast_float/3.4.0", "mimalloc/2.0.3", "sentry-native/0.5.0", + requires = ["zlib/1.2.13", "spdlog/1.12.0", "fast_float/5.2.0", "mimalloc/2.1.2", "sentry-native/0.6.5", # storm.jfrog.io "directx/9.0@storm/prebuilt", "fmod/2.02.05@storm/prebuilt"] # aux dependencies (e.g. for tests) @@ -64,10 +64,7 @@ def imports(self): self.__install_lib("steam_api64.dll") self.__install_bin("mimalloc-redirect.dll") - if self.settings.build_type == "Debug": - self.__install_bin("mimalloc-debug.dll") - else: - self.__install_bin("mimalloc.dll") + self.__install_bin("mimalloc.dll") else: # not Windows if self.settings.build_type == "Debug": diff --git a/src/apps/engine/src/main.cpp b/src/apps/engine/src/main.cpp index f3e0d9b4d..a308afc53 100644 --- a/src/apps/engine/src/main.cpp +++ b/src/apps/engine/src/main.cpp @@ -55,29 +55,6 @@ void RunFrameWithOverflowCheck() #define RunFrameWithOverflowCheck RunFrame #endif -void mimalloc_fun(const char *msg, void *arg) -{ - static std::filesystem::path mimalloc_log_path; - if (mimalloc_log_path.empty()) - { - mimalloc_log_path = fs::GetLogsPath() / "mimalloc.log"; - std::error_code ec; - remove(mimalloc_log_path, ec); - } - - FILE *mimalloc_log = -#ifdef _MSC_VER - _wfopen(mimalloc_log_path.c_str(), L"a+b"); -#else - fopen(mimalloc_log_path.c_str(), "a+b"); -#endif - if (mimalloc_log != nullptr) - { - fputs(msg, mimalloc_log); - fclose(mimalloc_log); - } -} - } // namespace void HandleWindowEvent(const storm::OSWindow::Event &event) @@ -129,19 +106,6 @@ int main(int argc, char *argv[]) return EXIT_SUCCESS; } #endif - mi_register_output(mimalloc_fun, nullptr); - mi_option_set(mi_option_show_errors, 1); - mi_option_set(mi_option_show_stats, 0); - mi_option_set(mi_option_eager_commit, 1); - mi_option_set(mi_option_eager_region_commit, 1); - mi_option_set(mi_option_large_os_pages, 1); - mi_option_set(mi_option_page_reset, 0); - mi_option_set(mi_option_segment_reset, 0); - mi_option_set(mi_option_reserve_huge_os_pages, 1); - mi_option_set(mi_option_segment_cache, 16); -#ifdef _DEBUG - mi_option_set(mi_option_verbose, 4); -#endif SDL_InitSubSystem(SDL_INIT_EVENTS | SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER); @@ -255,12 +219,6 @@ int main(int argc, char *argv[]) { std::this_thread::sleep_for(std::chrono::milliseconds(50)); } - - if (core.Controls && core.Controls->GetDebugAsyncKeyState(VK_F1) && core.Controls->GetDebugAsyncKeyState(VK_SHIFT)) - { - mi_stats_print_out(mimalloc_fun, nullptr); - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - } } // Release diff --git a/src/libs/core/src/data.cpp b/src/libs/core/src/data.cpp index 533d065bd..df593e5ff 100644 --- a/src/libs/core/src/data.cpp +++ b/src/libs/core/src/data.cpp @@ -1684,7 +1684,7 @@ bool DATA::Plus(DATA *pV) Set(sValue + std::to_string(pV->lValue)); break; case VAR_FLOAT: - Set(sValue + fmt::format("{}", pV->fValue)); + Set(sValue + std::format("{}", pV->fValue)); break; case VAR_STRING: Set(sValue + pV->sValue); diff --git a/src/libs/core/src/message.cpp b/src/libs/core/src/message.cpp index e06537730..f627540fd 100644 --- a/src/libs/core/src/message.cpp +++ b/src/libs/core/src/message.cpp @@ -4,7 +4,7 @@ #include -#include +#include void MESSAGE::Move2Start() { @@ -208,6 +208,6 @@ storm::MessageParam MESSAGE::GetParamValue(const char c, va_list&args) return std::string(ptr); } default: - throw std::runtime_error(fmt::format("Unknown message format: '{}'", c)); + throw std::runtime_error(std::format("Unknown message format: '{}'", c)); } } diff --git a/src/libs/diagnostics/src/spdlog_sinks/file_helper.cpp b/src/libs/diagnostics/src/spdlog_sinks/file_helper.cpp deleted file mode 100644 index f602b71f5..000000000 --- a/src/libs/diagnostics/src/spdlog_sinks/file_helper.cpp +++ /dev/null @@ -1,146 +0,0 @@ -#include "file_helper.hpp" - -#include -#include - -#include -#include -#include -#include -#include -#include - -namespace storm::logging::details -{ -using namespace spdlog; -using namespace spdlog::details; - -SPDLOG_INLINE file_helper::~file_helper() -{ - close(); -} - -SPDLOG_INLINE void file_helper::open(const filename_t &fname, bool truncate) -{ - close(); - filename_ = fname; - - auto *mode = SPDLOG_FILENAME_T("ab"); - auto *trunc_mode = SPDLOG_FILENAME_T("wb"); - - for (int tries = 0; tries < open_tries_; ++tries) - { - // create containing folder if not exists already. - os::create_dir(os::dir_name(fname)); - if (truncate) - { - // Truncate by opening-and-closing a tmp file in "wb" mode, always - // opening the actual log-we-write-to in "ab" mode, since that - // interacts more politely with eternal processes that might - // rotate/truncate the file underneath us. - std::FILE *tmp; - if (os::fopen_s(&tmp, fname, trunc_mode)) - { - continue; - } - std::fclose(tmp); - } - if (!os::fopen_s(&fd_, fname, mode)) - { - return; - } - - details::os::sleep_for_millis(open_interval_); - } - - throw_spdlog_ex("Failed opening file " + os::filename_to_str(filename_) + " for writing", errno); -} - -SPDLOG_INLINE void file_helper::reopen(bool truncate) -{ - if (filename_.empty()) - { - throw_spdlog_ex("Failed re opening file - was not opened before"); - } - this->open(filename_, truncate); -} - -SPDLOG_INLINE void file_helper::flush() -{ - std::fflush(fd_); -} - -SPDLOG_INLINE void file_helper::close() -{ - if (fd_ != nullptr) - { - std::fclose(fd_); - fd_ = nullptr; - } -} - -SPDLOG_INLINE void file_helper::write(const memory_buf_t &buf) -{ - size_t msg_size = buf.size(); - auto data = buf.data(); - if (std::fwrite(data, 1, msg_size, fd_) != msg_size) - { - throw_spdlog_ex("Failed writing to file " + os::filename_to_str(filename_), errno); - } -} - -SPDLOG_INLINE size_t file_helper::size() const -{ - if (fd_ == nullptr) - { - throw_spdlog_ex("Cannot use size() on closed file " + os::filename_to_str(filename_)); - } - return os::filesize(fd_); -} - -SPDLOG_INLINE const filename_t &file_helper::filename() const -{ - return filename_; -} - -std::FILE *file_helper::getfd() const -{ - return fd_; -} - -// -// return file path and its extension: -// -// "mylog.txt" => ("mylog", ".txt") -// "mylog" => ("mylog", "") -// "mylog." => ("mylog.", "") -// "/dir1/dir2/mylog.txt" => ("/dir1/dir2/mylog", ".txt") -// -// the starting dot in filenames is ignored (hidden files): -// -// ".mylog" => (".mylog". "") -// "my_folder/.mylog" => ("my_folder/.mylog", "") -// "my_folder/.mylog.txt" => ("my_folder/.mylog", ".txt") -SPDLOG_INLINE std::tuple file_helper::split_by_extension(const filename_t &fname) -{ - auto ext_index = fname.rfind('.'); - - // no valid extension found - return whole path and empty string as - // extension - if (ext_index == filename_t::npos || ext_index == 0 || ext_index == fname.size() - 1) - { - return std::make_tuple(fname, filename_t()); - } - - // treat cases like "/etc/rc.d/somelogfile or "/abc/.hiddenfile" - auto folder_index = fname.find_last_of(details::os::folder_seps_filename); - if (folder_index != filename_t::npos && folder_index >= ext_index - 1) - { - return std::make_tuple(fname, filename_t()); - } - - // finally - return a valid base and extension tuple - return std::make_tuple(fname.substr(0, ext_index), fname.substr(ext_index)); -} - -} // namespace storm::logging::details diff --git a/src/libs/diagnostics/src/spdlog_sinks/file_helper.hpp b/src/libs/diagnostics/src/spdlog_sinks/file_helper.hpp deleted file mode 100644 index 6f3d6ff8e..000000000 --- a/src/libs/diagnostics/src/spdlog_sinks/file_helper.hpp +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#include -#include - -namespace storm::logging::details -{ -// Helper class for file sinks. -// When failing to open a file, retry several times(5) with a delay interval(10 ms). -// Throw spdlog_ex exception on errors. - -class SPDLOG_API file_helper -{ - public: - explicit file_helper() = default; - - file_helper(const file_helper &) = delete; - file_helper &operator=(const file_helper &) = delete; - ~file_helper(); - - void open(const spdlog::filename_t &fname, bool truncate = false); - void reopen(bool truncate); - void flush(); - void close(); - void write(const spdlog::memory_buf_t &buf); - size_t size() const; - const spdlog::filename_t &filename() const; - - std::FILE *getfd() const; - - // - // return file path and its extension: - // - // "mylog.txt" => ("mylog", ".txt") - // "mylog" => ("mylog", "") - // "mylog." => ("mylog.", "") - // "/dir1/dir2/mylog.txt" => ("/dir1/dir2/mylog", ".txt") - // - // the starting dot in filenames is ignored (hidden files): - // - // ".mylog" => (".mylog". "") - // "my_folder/.mylog" => ("my_folder/.mylog", "") - // "my_folder/.mylog.txt" => ("my_folder/.mylog", ".txt") - static std::tuple split_by_extension(const spdlog::filename_t &fname); - - private: - const int open_tries_ = 5; - const int open_interval_ = 10; - std::FILE *fd_{nullptr}; - spdlog::filename_t filename_; -}; -} // namespace storm::logging::details \ No newline at end of file diff --git a/src/libs/diagnostics/src/spdlog_sinks/syncable_sink.cpp b/src/libs/diagnostics/src/spdlog_sinks/syncable_sink.cpp index 9c1902ab1..63166bdee 100644 --- a/src/libs/diagnostics/src/spdlog_sinks/syncable_sink.cpp +++ b/src/libs/diagnostics/src/spdlog_sinks/syncable_sink.cpp @@ -44,17 +44,9 @@ void storm::logging::sinks::syncable_sink::set_formatter(std::unique_ptr(_get_osfhandle(_fileno(file_helper_.getfd())))); - if (!success) - { - OutputDebugStringA(std::format("failed to flush:{} ({})", file_helper_.filename(), GetLastError()).c_str()); - } -#else - fsync(fileno(file_helper_.getfd())); -#endif + file_helper_.sync(); } void storm::logging::sinks::syncable_sink::terminate_immediately() diff --git a/src/libs/diagnostics/src/spdlog_sinks/syncable_sink.hpp b/src/libs/diagnostics/src/spdlog_sinks/syncable_sink.hpp index f21a667f9..d2246f288 100644 --- a/src/libs/diagnostics/src/spdlog_sinks/syncable_sink.hpp +++ b/src/libs/diagnostics/src/spdlog_sinks/syncable_sink.hpp @@ -3,11 +3,7 @@ #include #include #include - -// TODO: write own helper or patch spdlog to retrieve fd (protected or getter) -// this is basically spdlog::details::file_helper with additional getfd method -// this may break down after spdlog update -#include "file_helper.hpp" +#include namespace storm::logging::sinks { @@ -28,12 +24,12 @@ class syncable_sink final : public spdlog::sinks::sink void set_pattern(const std::string &pattern) override; void set_formatter(std::unique_ptr sink_formatter) override; - void sync() const; + void sync(); void terminate_immediately(); protected: std::unique_ptr formatter_; - details::file_helper file_helper_; + spdlog::details::file_helper file_helper_; }; } // namespace storm::spdlog_sinks diff --git a/src/libs/dialog/src/legacy_dialog.cpp b/src/libs/dialog/src/legacy_dialog.cpp index aeca7521c..6d348a54f 100644 --- a/src/libs/dialog/src/legacy_dialog.cpp +++ b/src/libs/dialog/src/legacy_dialog.cpp @@ -288,7 +288,7 @@ uint64_t LegacyDialog::ProcessMessage(MESSAGE &msg) const auto last_name_attr = core.Entity_GetAttribute(charId, "lastname"); const std::string_view name = name_attr ? name_attr : ""; const std::string_view last_name = last_name_attr ? last_name_attr : ""; - characterName_ = fmt::format("{} {}", name, last_name); + characterName_ = std::format("{} {}", name, last_name); std::transform(characterName_.begin(), characterName_.end(), characterName_.begin(), ::toupper); break; } @@ -480,7 +480,7 @@ void LegacyDialog::SetAction(std::string action) void LegacyDialog::UpdateHeadModel(const std::string &headModelPath) { - const std::string newHeadModelPath = fmt::format("Heads/{}", headModelPath); + const std::string newHeadModelPath = std::format("Heads/{}", headModelPath); if (headModelPath_ != newHeadModelPath) { diff --git a/src/libs/geometry/src/geom_static.cpp b/src/libs/geometry/src/geom_static.cpp index 78df7b6d5..95dcc1547 100644 --- a/src/libs/geometry/src/geom_static.cpp +++ b/src/libs/geometry/src/geom_static.cpp @@ -12,7 +12,7 @@ Import library main file #include #include -#include +#include #include #include "../../util/include/string_compare.hpp" @@ -210,7 +210,7 @@ GEOM::GEOM(const char *fname, const char *lightname, GEOM_SERVICE &_srv, int32_t }); if (!valid) { - throw std::runtime_error(fmt::format("Detected invalid collision data while loading file '{}'", fname)); + throw std::runtime_error(std::format("Detected invalid collision data while loading file '{}'", fname)); } } } diff --git a/src/libs/location/src/lights.cpp b/src/libs/location/src/lights.cpp index f624bb9c6..1578477ee 100644 --- a/src/libs/location/src/lights.cpp +++ b/src/libs/location/src/lights.cpp @@ -637,7 +637,7 @@ void Lights::PrintDebugInfo() rs->ExtPrint(FONT_DEFAULT, D3DCOLOR_ARGB(255, 255, 255, 255), 0x00000000, PR_ALIGN_CENTER, false, scale, 0, 0, - static_cast(vrt.x), static_cast(vrt.y), fmt::format("{}", d).c_str()); + static_cast(vrt.x), static_cast(vrt.y), std::format("{}", d).c_str()); // print idx auto color = D3DCOLOR_ARGB(255, 233, 30, 30); @@ -651,7 +651,7 @@ void Lights::PrintDebugInfo() } rs->ExtPrint(FONT_DEFAULT, color, 0x00000000, PR_ALIGN_CENTER, false, scale, 0, 0, static_cast(vrt.x), static_cast(vrt.y), - fmt::format("{}", i).c_str()); + std::format("{}", i).c_str()); rs->SetTransform(D3DTS_VIEW, view); diff --git a/src/libs/model/src/node.cpp b/src/libs/model/src/node.cpp index c8b8d7d38..edb16491e 100644 --- a/src/libs/model/src/node.cpp +++ b/src/libs/model/src/node.cpp @@ -189,12 +189,12 @@ bool NODER::Init(const char *lightPath, const char *pname, const char *oname, co if (pname == nullptr) { - throw std::runtime_error(fmt::format("NODER::Init: got nullptr model name")); + throw std::runtime_error(std::format("NODER::Init: got nullptr model name")); } sys_modelName_base = pname; if (oname && oname[0]) - sys_modelName_full = fmt::format("{}_{}", sys_modelName_base, oname); + sys_modelName_full = std::format("{}_{}", sys_modelName_base, oname); else sys_modelName_full = sys_modelName_base; @@ -308,7 +308,7 @@ void NODER::RestoreGeometry() gs->SetTexturePath(ttPath); delete[] ttPath; if (!geo) - throw std::runtime_error(fmt::format("Cannot restore geometry {}", sys_modelName_full)); + throw std::runtime_error(std::format("Cannot restore geometry {}", sys_modelName_full)); isReleased = false; for (int32_t i = 0; i < next.size(); i++) @@ -586,7 +586,7 @@ void NODER::SetMaxViewDist(float fDist) void NODER::SubstituteGeometry(const std::string &new_model) { - sys_modelName_full = fmt::format("{}_{}", sys_modelName_base, new_model); + sys_modelName_full = std::format("{}_{}", sys_modelName_base, new_model); ReleaseGeometry(); RestoreGeometry(); } diff --git a/src/libs/renderer/src/font.cpp b/src/libs/renderer/src/font.cpp index 18b5325b0..ce88aec27 100644 --- a/src/libs/renderer/src/font.cpp +++ b/src/libs/renderer/src/font.cpp @@ -3,7 +3,7 @@ #include "storm/config.hpp" #include "utf8.h" -#include +#include namespace { @@ -208,7 +208,7 @@ int32_t FONT::GetStringWidth(const std::string_view &text, std::optional if (Codepoint > USED_CODES) { core.Trace("Invalid codepoint: %d", Codepoint); if constexpr(storm::kIsDebug) { - throw std::runtime_error(fmt::format("Invalid codepoint: {}", Codepoint)); + throw std::runtime_error(std::format("Invalid codepoint: {}", Codepoint)); } continue; } @@ -252,7 +252,7 @@ int32_t FONT::UpdateVertexBuffer(int32_t x, int32_t y, char *data_PTR, int utf8l if (Codepoint > USED_CODES) { core.Trace("Invalid codepoint: %d", Codepoint); if constexpr(storm::kIsDebug) { - throw std::runtime_error(fmt::format("Invalid codepoint: {}", Codepoint)); + throw std::runtime_error(std::format("Invalid codepoint: {}", Codepoint)); } continue; } diff --git a/src/libs/renderer/src/s_device.cpp b/src/libs/renderer/src/s_device.cpp index c814bb1d2..e4eae5f49 100644 --- a/src/libs/renderer/src/s_device.cpp +++ b/src/libs/renderer/src/s_device.cpp @@ -14,8 +14,6 @@ #include #include -#include - #ifdef _WIN32 #include #include @@ -3278,8 +3276,8 @@ void DX9RENDER::MakeScreenShot() core.Trace("Failed to make screenshot"); return; } - - const auto screenshot_base_filename = fmt::format("{:%Y-%m-%d_%H-%M-%S}", fmt::localtime(std::time(nullptr))); + + const auto screenshot_base_filename = std::format("{:%Y-%m-%d_%H-%M-%S}", std::chrono::system_clock::now()); auto screenshot_path = fs::GetScreenshotsPath() / screenshot_base_filename; screenshot_path.replace_extension(screenshotExt); for(size_t i = 0; exists(screenshot_path); ++i) diff --git a/src/libs/sea_ai/src/ai_ship_cannon_controller.cpp b/src/libs/sea_ai/src/ai_ship_cannon_controller.cpp index dc92b39df..dfcfce4db 100644 --- a/src/libs/sea_ai/src/ai_ship_cannon_controller.cpp +++ b/src/libs/sea_ai/src/ai_ship_cannon_controller.cpp @@ -626,7 +626,7 @@ void AIShipCannonController::Realize(float fDeltaTime) std::string buf; for (const auto &bort : aShipBorts) { - buf += fmt::format("{:.3f} ", GetBortHeightAngle(bort)); + buf += std::format("{:.3f} ", GetBortHeightAngle(bort)); } AIHelper::pRS->Print(200, 20, buf.c_str()); } diff --git a/src/libs/util/include/storm_assert.h b/src/libs/util/include/storm_assert.h index 6354c21c8..249ca37cd 100644 --- a/src/libs/util/include/storm_assert.h +++ b/src/libs/util/include/storm_assert.h @@ -4,7 +4,7 @@ #include "debug-trap.h" #else #include -#include +#include #endif inline void __Storm_Assert__(bool expression, const char *file, int32_t line, const char *str) @@ -14,7 +14,8 @@ inline void __Storm_Assert__(bool expression, const char *file, int32_t line, co #ifdef EX_OFF psnip_trap(); #else - throw std::runtime_error(fmt::format("Assert failed in {} line {}, expression string {}", file, line, str ? str : "")); + throw std::runtime_error( + std::format("Assert failed in {} line {}, expression string {}", file, line, str ? str : "")); #endif } } diff --git a/src/libs/xinterface/src/aviplayer/aviplayer.cpp b/src/libs/xinterface/src/aviplayer/aviplayer.cpp index d44d3753d..9de4344d1 100644 --- a/src/libs/xinterface/src/aviplayer/aviplayer.cpp +++ b/src/libs/xinterface/src/aviplayer/aviplayer.cpp @@ -163,7 +163,7 @@ uint64_t CAviPlayer::ProcessMessage(MESSAGE &message) { case MSG_SET_VIDEO_PLAY: { const std::string ¶m = message.String(); - const std::string vidName = fmt::format("{}\\{}", VIDEO_DIRECTORY, param); + const std::string vidName = std::format("{}\\{}", VIDEO_DIRECTORY, param); filename = vidName; if (!PlayMedia(vidName.c_str())) {