Core/Core: Use fmt where applicable
Continues the migration over to using fmt. Given fmt is also compatible with std::string and std::string_view, we can convert some parameters over to std::string_view, such as the message parameter for StopMessage() and the name parameter for an overload of SaveScreenShot()
This commit is contained in:
parent
29ba53f6c3
commit
1f98188277
|
@ -12,6 +12,8 @@
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <variant>
|
#include <variant>
|
||||||
|
|
||||||
|
#include <fmt/format.h>
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -23,11 +25,10 @@
|
||||||
#include "Common/CommonTypes.h"
|
#include "Common/CommonTypes.h"
|
||||||
#include "Common/FileUtil.h"
|
#include "Common/FileUtil.h"
|
||||||
#include "Common/Flag.h"
|
#include "Common/Flag.h"
|
||||||
#include "Common/Logging/LogManager.h"
|
#include "Common/Logging/Log.h"
|
||||||
#include "Common/MemoryUtil.h"
|
#include "Common/MemoryUtil.h"
|
||||||
#include "Common/MsgHandler.h"
|
#include "Common/MsgHandler.h"
|
||||||
#include "Common/ScopeGuard.h"
|
#include "Common/ScopeGuard.h"
|
||||||
#include "Common/StringUtil.h"
|
|
||||||
#include "Common/Thread.h"
|
#include "Common/Thread.h"
|
||||||
#include "Common/Timer.h"
|
#include "Common/Timer.h"
|
||||||
#include "Common/Version.h"
|
#include "Common/Version.h"
|
||||||
|
@ -142,10 +143,10 @@ void OnFrameEnd()
|
||||||
// Display messages and return values
|
// Display messages and return values
|
||||||
|
|
||||||
// Formatted stop message
|
// Formatted stop message
|
||||||
std::string StopMessage(bool main_thread, const std::string& message)
|
std::string StopMessage(bool main_thread, std::string_view message)
|
||||||
{
|
{
|
||||||
return StringFromFormat("Stop [%s %i]\t%s", main_thread ? "Main Thread" : "Video Thread",
|
return fmt::format("Stop [{} {}]\t{}", main_thread ? "Main Thread" : "Video Thread",
|
||||||
Common::CurrentThreadId(), message.c_str());
|
Common::CurrentThreadId(), message);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DisplayMessage(const std::string& message, int time_in_ms)
|
void DisplayMessage(const std::string& message, int time_in_ms)
|
||||||
|
@ -679,7 +680,7 @@ static std::string GenerateScreenshotName()
|
||||||
path += SConfig::GetInstance().GetGameID();
|
path += SConfig::GetInstance().GetGameID();
|
||||||
|
|
||||||
std::string name;
|
std::string name;
|
||||||
for (int i = 1; File::Exists(name = StringFromFormat("%s-%d.png", path.c_str(), i)); ++i)
|
for (int i = 1; File::Exists(name = fmt::format("{}-{}.png", path, i)); ++i)
|
||||||
{
|
{
|
||||||
// TODO?
|
// TODO?
|
||||||
}
|
}
|
||||||
|
@ -699,15 +700,14 @@ void SaveScreenShot(bool wait_for_completion)
|
||||||
SetState(State::Running);
|
SetState(State::Running);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SaveScreenShot(const std::string& name, bool wait_for_completion)
|
void SaveScreenShot(std::string_view name, bool wait_for_completion)
|
||||||
{
|
{
|
||||||
const bool bPaused = GetState() == State::Paused;
|
const bool bPaused = GetState() == State::Paused;
|
||||||
|
|
||||||
SetState(State::Paused);
|
SetState(State::Paused);
|
||||||
|
|
||||||
std::string filePath = GenerateScreenshotFolderPath() + name + ".png";
|
const std::string path = fmt::format("{}{}.png", GenerateScreenshotFolderPath(), name);
|
||||||
|
g_renderer->SaveScreenshot(path, wait_for_completion);
|
||||||
g_renderer->SaveScreenshot(filePath, wait_for_completion);
|
|
||||||
|
|
||||||
if (!bPaused)
|
if (!bPaused)
|
||||||
SetState(State::Running);
|
SetState(State::Running);
|
||||||
|
@ -824,23 +824,25 @@ void UpdateTitle()
|
||||||
(VideoInterface::GetTargetRefreshRate() * ElapseTime));
|
(VideoInterface::GetTargetRefreshRate() * ElapseTime));
|
||||||
|
|
||||||
// Settings are shown the same for both extended and summary info
|
// Settings are shown the same for both extended and summary info
|
||||||
std::string SSettings = StringFromFormat(
|
const std::string SSettings =
|
||||||
"%s %s | %s | %s", PowerPC::GetCPUName(), _CoreParameter.bCPUThread ? "DC" : "SC",
|
fmt::format("{} {} | {} | {}", PowerPC::GetCPUName(), _CoreParameter.bCPUThread ? "DC" : "SC",
|
||||||
g_video_backend->GetDisplayName().c_str(), _CoreParameter.bDSPHLE ? "HLE" : "LLE");
|
g_video_backend->GetDisplayName(), _CoreParameter.bDSPHLE ? "HLE" : "LLE");
|
||||||
|
|
||||||
std::string SFPS;
|
std::string SFPS;
|
||||||
|
|
||||||
if (Movie::IsPlayingInput())
|
if (Movie::IsPlayingInput())
|
||||||
SFPS = StringFromFormat("Input: %u/%u - VI: %u - FPS: %.0f - VPS: %.0f - %.0f%%",
|
{
|
||||||
(u32)Movie::GetCurrentInputCount(), (u32)Movie::GetTotalInputCount(),
|
SFPS = fmt::format("Input: {}/{} - VI: {} - FPS: {:.0f} - VPS: {:.0f} - {:.0f}%",
|
||||||
(u32)Movie::GetCurrentFrame(), FPS, VPS, Speed);
|
Movie::GetCurrentInputCount(), Movie::GetTotalInputCount(),
|
||||||
|
Movie::GetCurrentFrame(), FPS, VPS, Speed);
|
||||||
|
}
|
||||||
else if (Movie::IsRecordingInput())
|
else if (Movie::IsRecordingInput())
|
||||||
SFPS = StringFromFormat("Input: %u - VI: %u - FPS: %.0f - VPS: %.0f - %.0f%%",
|
{
|
||||||
(u32)Movie::GetCurrentInputCount(), (u32)Movie::GetCurrentFrame(), FPS,
|
SFPS = fmt::format("Input: {} - VI: {} - FPS: {:.0f} - VPS: {:.0f} - {:.0f}%",
|
||||||
VPS, Speed);
|
Movie::GetCurrentInputCount(), Movie::GetCurrentFrame(), FPS, VPS, Speed);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SFPS = StringFromFormat("FPS: %.0f - VPS: %.0f - %.0f%%", FPS, VPS, Speed);
|
SFPS = fmt::format("FPS: {:.0f} - VPS: {:.0f} - {:.0f}%", FPS, VPS, Speed);
|
||||||
if (SConfig::GetInstance().m_InterfaceExtendedFPSInfo)
|
if (SConfig::GetInstance().m_InterfaceExtendedFPSInfo)
|
||||||
{
|
{
|
||||||
// Use extended or summary information. The summary information does not print the ticks data,
|
// Use extended or summary information. The summary information does not print the ticks data,
|
||||||
|
@ -860,14 +862,13 @@ void UpdateTitle()
|
||||||
float TicksPercentage =
|
float TicksPercentage =
|
||||||
(float)diff / (float)(SystemTimers::GetTicksPerSecond() / 1000000) * 100;
|
(float)diff / (float)(SystemTimers::GetTicksPerSecond() / 1000000) * 100;
|
||||||
|
|
||||||
SFPS += StringFromFormat(" | CPU: ~%i MHz [Real: %i + IdleSkip: %i] / %i MHz (~%3.0f%%)",
|
SFPS += fmt::format(" | CPU: ~{} MHz [Real: {} + IdleSkip: {}] / {} MHz (~{:3.0f}%)", diff,
|
||||||
(int)(diff), (int)(diff - idleDiff), (int)(idleDiff),
|
diff - idleDiff, idleDiff, SystemTimers::GetTicksPerSecond() / 1000000,
|
||||||
SystemTimers::GetTicksPerSecond() / 1000000, TicksPercentage);
|
TicksPercentage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string message = StringFromFormat("%s | %s | %s", Common::scm_rev_str.c_str(),
|
std::string message = fmt::format("{} | {} | {}", Common::scm_rev_str, SSettings, SFPS);
|
||||||
SSettings.c_str(), SFPS.c_str());
|
|
||||||
if (SConfig::GetInstance().m_show_active_title)
|
if (SConfig::GetInstance().m_show_active_title)
|
||||||
{
|
{
|
||||||
const std::string& title = SConfig::GetInstance().GetTitleDescription();
|
const std::string& title = SConfig::GetInstance().GetTitleDescription();
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <string_view>
|
||||||
|
|
||||||
#include "Common/CommonTypes.h"
|
#include "Common/CommonTypes.h"
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ void Shutdown();
|
||||||
void DeclareAsCPUThread();
|
void DeclareAsCPUThread();
|
||||||
void UndeclareAsCPUThread();
|
void UndeclareAsCPUThread();
|
||||||
|
|
||||||
std::string StopMessage(bool, const std::string&);
|
std::string StopMessage(bool main_thread, std::string_view message);
|
||||||
|
|
||||||
bool IsRunning();
|
bool IsRunning();
|
||||||
bool IsRunningAndStarted(); // is running and the CPU loop has been entered
|
bool IsRunningAndStarted(); // is running and the CPU loop has been entered
|
||||||
|
@ -58,7 +58,7 @@ void SetState(State state);
|
||||||
State GetState();
|
State GetState();
|
||||||
|
|
||||||
void SaveScreenShot(bool wait_for_completion = false);
|
void SaveScreenShot(bool wait_for_completion = false);
|
||||||
void SaveScreenShot(const std::string& name, bool wait_for_completion = false);
|
void SaveScreenShot(std::string_view name, bool wait_for_completion = false);
|
||||||
|
|
||||||
void Callback_WiimoteInterruptChannel(int number, u16 channel_id, const u8* data, u32 size);
|
void Callback_WiimoteInterruptChannel(int number, u16 channel_id, const u8* data, u32 size);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue