diff options
| -rw-r--r-- | src/common/memory_util.cpp | 3 | ||||
| -rw-r--r-- | src/common/string_util.cpp | 70 | ||||
| -rw-r--r-- | src/common/string_util.h | 14 | ||||
| -rw-r--r-- | src/common/timer.cpp | 13 | ||||
| -rw-r--r-- | src/core/hle/kernel/svc.cpp | 2 | ||||
| -rw-r--r-- | src/core/hle/service/service.cpp | 5 | ||||
| -rw-r--r-- | src/yuzu/bootmanager.cpp | 6 | ||||
| -rw-r--r-- | src/yuzu_cmd/emu_window/emu_window_sdl2.cpp | 5 |
8 files changed, 19 insertions, 99 deletions
diff --git a/src/common/memory_util.cpp b/src/common/memory_util.cpp index 79b7215d3..4d1ec8fb9 100644 --- a/src/common/memory_util.cpp +++ b/src/common/memory_util.cpp | |||
| @@ -167,8 +167,7 @@ std::string MemUsage() { | |||
| 167 | return "MemUsage Error"; | 167 | return "MemUsage Error"; |
| 168 | 168 | ||
| 169 | if (GetProcessMemoryInfo(hProcess, &pmc, sizeof(pmc))) | 169 | if (GetProcessMemoryInfo(hProcess, &pmc, sizeof(pmc))) |
| 170 | Ret = Common::StringFromFormat( | 170 | Ret = fmt::format("{} K", Common::ThousandSeparate(pmc.WorkingSetSize / 1024, 7)); |
| 171 | "%s K", Common::ThousandSeparate(pmc.WorkingSetSize / 1024, 7).c_str()); | ||
| 172 | 171 | ||
| 173 | CloseHandle(hProcess); | 172 | CloseHandle(hProcess); |
| 174 | return Ret; | 173 | return Ret; |
diff --git a/src/common/string_util.cpp b/src/common/string_util.cpp index 96c52e3ba..1d952874d 100644 --- a/src/common/string_util.cpp +++ b/src/common/string_util.cpp | |||
| @@ -46,76 +46,6 @@ bool AsciiToHex(const char* _szValue, u32& result) { | |||
| 46 | return true; | 46 | return true; |
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | bool CharArrayFromFormatV(char* out, int outsize, const char* format, va_list args) { | ||
| 50 | int writtenCount; | ||
| 51 | |||
| 52 | #ifdef _MSC_VER | ||
| 53 | // You would think *printf are simple, right? Iterate on each character, | ||
| 54 | // if it's a format specifier handle it properly, etc. | ||
| 55 | // | ||
| 56 | // Nooooo. Not according to the C standard. | ||
| 57 | // | ||
| 58 | // According to the C99 standard (7.19.6.1 "The fprintf function") | ||
| 59 | // The format shall be a multibyte character sequence | ||
| 60 | // | ||
| 61 | // Because some character encodings might have '%' signs in the middle of | ||
| 62 | // a multibyte sequence (SJIS for example only specifies that the first | ||
| 63 | // byte of a 2 byte sequence is "high", the second byte can be anything), | ||
| 64 | // printf functions have to decode the multibyte sequences and try their | ||
| 65 | // best to not screw up. | ||
| 66 | // | ||
| 67 | // Unfortunately, on Windows, the locale for most languages is not UTF-8 | ||
| 68 | // as we would need. Notably, for zh_TW, Windows chooses EUC-CN as the | ||
| 69 | // locale, and completely fails when trying to decode UTF-8 as EUC-CN. | ||
| 70 | // | ||
| 71 | // On the other hand, the fix is simple: because we use UTF-8, no such | ||
| 72 | // multibyte handling is required as we can simply assume that no '%' char | ||
| 73 | // will be present in the middle of a multibyte sequence. | ||
| 74 | // | ||
| 75 | // This is why we lookup an ANSI (cp1252) locale here and use _vsnprintf_l. | ||
| 76 | static locale_t c_locale = nullptr; | ||
| 77 | if (!c_locale) | ||
| 78 | c_locale = _create_locale(LC_ALL, ".1252"); | ||
| 79 | writtenCount = _vsnprintf_l(out, outsize, format, c_locale, args); | ||
| 80 | #else | ||
| 81 | writtenCount = vsnprintf(out, outsize, format, args); | ||
| 82 | #endif | ||
| 83 | |||
| 84 | if (writtenCount > 0 && writtenCount < outsize) { | ||
| 85 | out[writtenCount] = '\0'; | ||
| 86 | return true; | ||
| 87 | } else { | ||
| 88 | out[outsize - 1] = '\0'; | ||
| 89 | return false; | ||
| 90 | } | ||
| 91 | } | ||
| 92 | |||
| 93 | std::string StringFromFormat(const char* format, ...) { | ||
| 94 | va_list args; | ||
| 95 | char* buf = nullptr; | ||
| 96 | #ifdef _WIN32 | ||
| 97 | int required = 0; | ||
| 98 | |||
| 99 | va_start(args, format); | ||
| 100 | required = _vscprintf(format, args); | ||
| 101 | buf = new char[required + 1]; | ||
| 102 | CharArrayFromFormatV(buf, required + 1, format, args); | ||
| 103 | va_end(args); | ||
| 104 | |||
| 105 | std::string temp = buf; | ||
| 106 | delete[] buf; | ||
| 107 | #else | ||
| 108 | va_start(args, format); | ||
| 109 | if (vasprintf(&buf, format, args) < 0) | ||
| 110 | NGLOG_ERROR(Common, "Unable to allocate memory for string"); | ||
| 111 | va_end(args); | ||
| 112 | |||
| 113 | std::string temp = buf; | ||
| 114 | free(buf); | ||
| 115 | #endif | ||
| 116 | return temp; | ||
| 117 | } | ||
| 118 | |||
| 119 | // For Debugging. Read out an u8 array. | 49 | // For Debugging. Read out an u8 array. |
| 120 | std::string ArrayToString(const u8* data, size_t size, int line_len, bool spaces) { | 50 | std::string ArrayToString(const u8* data, size_t size, int line_len, bool spaces) { |
| 121 | std::ostringstream oss; | 51 | std::ostringstream oss; |
diff --git a/src/common/string_util.h b/src/common/string_util.h index ec0c31a24..65e4ea5d3 100644 --- a/src/common/string_util.h +++ b/src/common/string_util.h | |||
| @@ -4,7 +4,6 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <cstdarg> | ||
| 8 | #include <cstddef> | 7 | #include <cstddef> |
| 9 | #include <iomanip> | 8 | #include <iomanip> |
| 10 | #include <sstream> | 9 | #include <sstream> |
| @@ -20,19 +19,6 @@ std::string ToLower(std::string str); | |||
| 20 | /// Make a string uppercase | 19 | /// Make a string uppercase |
| 21 | std::string ToUpper(std::string str); | 20 | std::string ToUpper(std::string str); |
| 22 | 21 | ||
| 23 | std::string StringFromFormat(const char* format, ...); | ||
| 24 | // Cheap! | ||
| 25 | bool CharArrayFromFormatV(char* out, int outsize, const char* format, va_list args); | ||
| 26 | |||
| 27 | template <size_t Count> | ||
| 28 | inline void CharArrayFromFormat(char (&out)[Count], const char* format, ...) { | ||
| 29 | va_list args; | ||
| 30 | va_start(args, format); | ||
| 31 | CharArrayFromFormatV(out, Count, format, args); | ||
| 32 | va_end(args); | ||
| 33 | } | ||
| 34 | |||
| 35 | // Good | ||
| 36 | std::string ArrayToString(const u8* data, size_t size, int line_len = 20, bool spaces = true); | 22 | std::string ArrayToString(const u8* data, size_t size, int line_len = 20, bool spaces = true); |
| 37 | 23 | ||
| 38 | std::string StripSpaces(const std::string& s); | 24 | std::string StripSpaces(const std::string& s); |
diff --git a/src/common/timer.cpp b/src/common/timer.cpp index c9803109e..f0c5b1a43 100644 --- a/src/common/timer.cpp +++ b/src/common/timer.cpp | |||
| @@ -2,7 +2,10 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <time.h> | 5 | #include <ctime> |
| 6 | |||
| 7 | #include <fmt/format.h> | ||
| 8 | |||
| 6 | #ifdef _WIN32 | 9 | #ifdef _WIN32 |
| 7 | #include <windows.h> | 10 | #include <windows.h> |
| 8 | // windows.h needs to be included before other windows headers | 11 | // windows.h needs to be included before other windows headers |
| @@ -104,8 +107,8 @@ std::string Timer::GetTimeElapsedFormatted() const { | |||
| 104 | // Hours | 107 | // Hours |
| 105 | u32 Hours = Minutes / 60; | 108 | u32 Hours = Minutes / 60; |
| 106 | 109 | ||
| 107 | std::string TmpStr = StringFromFormat("%02i:%02i:%02i:%03i", Hours, Minutes % 60, Seconds % 60, | 110 | std::string TmpStr = fmt::format("{:02}:{:02}:{:02}:{:03}", Hours, Minutes % 60, Seconds % 60, |
| 108 | Milliseconds % 1000); | 111 | Milliseconds % 1000); |
| 109 | return TmpStr; | 112 | return TmpStr; |
| 110 | } | 113 | } |
| 111 | 114 | ||
| @@ -165,11 +168,11 @@ std::string Timer::GetTimeFormatted() { | |||
| 165 | #ifdef _WIN32 | 168 | #ifdef _WIN32 |
| 166 | struct timeb tp; | 169 | struct timeb tp; |
| 167 | (void)::ftime(&tp); | 170 | (void)::ftime(&tp); |
| 168 | return StringFromFormat("%s:%03i", tmp, tp.millitm); | 171 | return fmt::format("{}:{:03}", tmp, tp.millitm); |
| 169 | #else | 172 | #else |
| 170 | struct timeval t; | 173 | struct timeval t; |
| 171 | (void)gettimeofday(&t, nullptr); | 174 | (void)gettimeofday(&t, nullptr); |
| 172 | return StringFromFormat("%s:%03d", tmp, (int)(t.tv_usec / 1000)); | 175 | return fmt::format("{}:{:03}", tmp, static_cast<int>(t.tv_usec / 1000)); |
| 173 | #endif | 176 | #endif |
| 174 | } | 177 | } |
| 175 | 178 | ||
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index 4df38c977..e2da68227 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp | |||
| @@ -510,7 +510,7 @@ static void ExitProcess() { | |||
| 510 | /// Creates a new thread | 510 | /// Creates a new thread |
| 511 | static ResultCode CreateThread(Handle* out_handle, VAddr entry_point, u64 arg, VAddr stack_top, | 511 | static ResultCode CreateThread(Handle* out_handle, VAddr entry_point, u64 arg, VAddr stack_top, |
| 512 | u32 priority, s32 processor_id) { | 512 | u32 priority, s32 processor_id) { |
| 513 | std::string name = Common::StringFromFormat("unknown-%llx", entry_point); | 513 | std::string name = fmt::format("unknown-{:X}", entry_point); |
| 514 | 514 | ||
| 515 | if (priority > THREADPRIO_LOWEST) { | 515 | if (priority > THREADPRIO_LOWEST) { |
| 516 | return ERR_OUT_OF_RANGE; | 516 | return ERR_OUT_OF_RANGE; |
diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp index 94de21ae1..7a5f08b24 100644 --- a/src/core/hle/service/service.cpp +++ b/src/core/hle/service/service.cpp | |||
| @@ -58,10 +58,9 @@ static std::string MakeFunctionString(const char* name, const char* port_name, | |||
| 58 | // Number of params == bits 0-5 + bits 6-11 | 58 | // Number of params == bits 0-5 + bits 6-11 |
| 59 | int num_params = (cmd_buff[0] & 0x3F) + ((cmd_buff[0] >> 6) & 0x3F); | 59 | int num_params = (cmd_buff[0] & 0x3F) + ((cmd_buff[0] >> 6) & 0x3F); |
| 60 | 60 | ||
| 61 | std::string function_string = | 61 | std::string function_string = fmt::format("function '{}': port={}", name, port_name); |
| 62 | Common::StringFromFormat("function '%s': port=%s", name, port_name); | ||
| 63 | for (int i = 1; i <= num_params; ++i) { | 62 | for (int i = 1; i <= num_params; ++i) { |
| 64 | function_string += Common::StringFromFormat(", cmd_buff[%i]=0x%X", i, cmd_buff[i]); | 63 | function_string += fmt::format(", cmd_buff[{}]={:#X}", i, cmd_buff[i]); |
| 65 | } | 64 | } |
| 66 | return function_string; | 65 | return function_string; |
| 67 | } | 66 | } |
diff --git a/src/yuzu/bootmanager.cpp b/src/yuzu/bootmanager.cpp index 469988d63..5c17cd0d9 100644 --- a/src/yuzu/bootmanager.cpp +++ b/src/yuzu/bootmanager.cpp | |||
| @@ -4,6 +4,8 @@ | |||
| 4 | #include <QScreen> | 4 | #include <QScreen> |
| 5 | #include <QWindow> | 5 | #include <QWindow> |
| 6 | 6 | ||
| 7 | #include <fmt/format.h> | ||
| 8 | |||
| 7 | #include "common/microprofile.h" | 9 | #include "common/microprofile.h" |
| 8 | #include "common/scm_rev.h" | 10 | #include "common/scm_rev.h" |
| 9 | #include "common/string_util.h" | 11 | #include "common/string_util.h" |
| @@ -102,8 +104,8 @@ private: | |||
| 102 | GRenderWindow::GRenderWindow(QWidget* parent, EmuThread* emu_thread) | 104 | GRenderWindow::GRenderWindow(QWidget* parent, EmuThread* emu_thread) |
| 103 | : QWidget(parent), child(nullptr), emu_thread(emu_thread) { | 105 | : QWidget(parent), child(nullptr), emu_thread(emu_thread) { |
| 104 | 106 | ||
| 105 | std::string window_title = Common::StringFromFormat("yuzu %s| %s-%s", Common::g_build_name, | 107 | std::string window_title = fmt::format("yuzu {} | {}-{}", Common::g_build_name, |
| 106 | Common::g_scm_branch, Common::g_scm_desc); | 108 | Common::g_scm_branch, Common::g_scm_desc); |
| 107 | setWindowTitle(QString::fromStdString(window_title)); | 109 | setWindowTitle(QString::fromStdString(window_title)); |
| 108 | 110 | ||
| 109 | InputCommon::Init(); | 111 | InputCommon::Init(); |
diff --git a/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp b/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp index b6ed0c498..e21de6f21 100644 --- a/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp +++ b/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp | |||
| @@ -7,6 +7,7 @@ | |||
| 7 | #include <string> | 7 | #include <string> |
| 8 | #define SDL_MAIN_HANDLED | 8 | #define SDL_MAIN_HANDLED |
| 9 | #include <SDL.h> | 9 | #include <SDL.h> |
| 10 | #include <fmt/format.h> | ||
| 10 | #include <glad/glad.h> | 11 | #include <glad/glad.h> |
| 11 | #include "common/logging/log.h" | 12 | #include "common/logging/log.h" |
| 12 | #include "common/scm_rev.h" | 13 | #include "common/scm_rev.h" |
| @@ -97,8 +98,8 @@ EmuWindow_SDL2::EmuWindow_SDL2(bool fullscreen) { | |||
| 97 | SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); | 98 | SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); |
| 98 | SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 0); | 99 | SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 0); |
| 99 | 100 | ||
| 100 | std::string window_title = Common::StringFromFormat("yuzu %s| %s-%s ", Common::g_build_name, | 101 | std::string window_title = fmt::format("yuzu {} | {}-{}", Common::g_build_name, |
| 101 | Common::g_scm_branch, Common::g_scm_desc); | 102 | Common::g_scm_branch, Common::g_scm_desc); |
| 102 | render_window = | 103 | render_window = |
| 103 | SDL_CreateWindow(window_title.c_str(), | 104 | SDL_CreateWindow(window_title.c_str(), |
| 104 | SDL_WINDOWPOS_UNDEFINED, // x position | 105 | SDL_WINDOWPOS_UNDEFINED, // x position |