Skip to content
Permalink
Browse files

Merge pull request #8226 from lioncash/fmt-core

Core/Core: Use fmt where applicable
  • Loading branch information...
stenzek committed Aug 9, 2019
2 parents 8be5ee9 + 1f98188 commit 5c3e9a34c368c2ae775a88d02c53a7ad95396f67
Showing with 30 additions and 29 deletions.
  1. +27 −26 Source/Core/Core/Core.cpp
  2. +3 −3 Source/Core/Core/Core.h
@@ -12,6 +12,8 @@
#include <utility>
#include <variant>

#include <fmt/format.h>

#ifdef _WIN32
#include <windows.h>
#endif
@@ -24,11 +26,10 @@
#include "Common/Event.h"
#include "Common/FileUtil.h"
#include "Common/Flag.h"
#include "Common/Logging/LogManager.h"
#include "Common/Logging/Log.h"
#include "Common/MemoryUtil.h"
#include "Common/MsgHandler.h"
#include "Common/ScopeGuard.h"
#include "Common/StringUtil.h"
#include "Common/Thread.h"
#include "Common/Timer.h"
#include "Common/Version.h"
@@ -144,10 +145,10 @@ void OnFrameEnd()
// Display messages and return values

// 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",
Common::CurrentThreadId(), message.c_str());
return fmt::format("Stop [{} {}]\t{}", main_thread ? "Main Thread" : "Video Thread",
Common::CurrentThreadId(), message);
}

void DisplayMessage(std::string message, int time_in_ms)
@@ -682,7 +683,7 @@ static std::string GenerateScreenshotName()
path += SConfig::GetInstance().GetGameID();

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?
}
@@ -702,15 +703,14 @@ void SaveScreenShot(bool wait_for_completion)
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;

SetState(State::Paused);

std::string filePath = GenerateScreenshotFolderPath() + name + ".png";

g_renderer->SaveScreenshot(filePath, wait_for_completion);
const std::string path = fmt::format("{}{}.png", GenerateScreenshotFolderPath(), name);
g_renderer->SaveScreenshot(path, wait_for_completion);

if (!bPaused)
SetState(State::Running);
@@ -866,23 +866,25 @@ void UpdateTitle()
(VideoInterface::GetTargetRefreshRate() * ElapseTime));

// Settings are shown the same for both extended and summary info
std::string SSettings = StringFromFormat(
"%s %s | %s | %s", PowerPC::GetCPUName(), _CoreParameter.bCPUThread ? "DC" : "SC",
g_video_backend->GetDisplayName().c_str(), _CoreParameter.bDSPHLE ? "HLE" : "LLE");
const std::string SSettings =
fmt::format("{} {} | {} | {}", PowerPC::GetCPUName(), _CoreParameter.bCPUThread ? "DC" : "SC",
g_video_backend->GetDisplayName(), _CoreParameter.bDSPHLE ? "HLE" : "LLE");

std::string SFPS;

if (Movie::IsPlayingInput())
SFPS = StringFromFormat("Input: %u/%u - VI: %u - FPS: %.0f - VPS: %.0f - %.0f%%",
(u32)Movie::GetCurrentInputCount(), (u32)Movie::GetTotalInputCount(),
(u32)Movie::GetCurrentFrame(), FPS, VPS, Speed);
{
SFPS = fmt::format("Input: {}/{} - VI: {} - FPS: {:.0f} - VPS: {:.0f} - {:.0f}%",
Movie::GetCurrentInputCount(), Movie::GetTotalInputCount(),
Movie::GetCurrentFrame(), FPS, VPS, Speed);
}
else if (Movie::IsRecordingInput())
SFPS = StringFromFormat("Input: %u - VI: %u - FPS: %.0f - VPS: %.0f - %.0f%%",
(u32)Movie::GetCurrentInputCount(), (u32)Movie::GetCurrentFrame(), FPS,
VPS, Speed);
{
SFPS = fmt::format("Input: {} - VI: {} - FPS: {:.0f} - VPS: {:.0f} - {:.0f}%",
Movie::GetCurrentInputCount(), Movie::GetCurrentFrame(), FPS, VPS, Speed);
}
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)
{
// Use extended or summary information. The summary information does not print the ticks data,
@@ -902,14 +904,13 @@ void UpdateTitle()
float TicksPercentage =
(float)diff / (float)(SystemTimers::GetTicksPerSecond() / 1000000) * 100;

SFPS += StringFromFormat(" | CPU: ~%i MHz [Real: %i + IdleSkip: %i] / %i MHz (~%3.0f%%)",
(int)(diff), (int)(diff - idleDiff), (int)(idleDiff),
SystemTimers::GetTicksPerSecond() / 1000000, TicksPercentage);
SFPS += fmt::format(" | CPU: ~{} MHz [Real: {} + IdleSkip: {}] / {} MHz (~{:3.0f}%)", diff,
diff - idleDiff, idleDiff, SystemTimers::GetTicksPerSecond() / 1000000,
TicksPercentage);
}
}

std::string message = StringFromFormat("%s | %s | %s", Common::scm_rev_str.c_str(),
SSettings.c_str(), SFPS.c_str());
std::string message = fmt::format("{} | {} | {}", Common::scm_rev_str, SSettings, SFPS);
if (SConfig::GetInstance().m_show_active_title)
{
const std::string& title = SConfig::GetInstance().GetTitleDescription();
@@ -13,7 +13,7 @@
#include <functional>
#include <memory>
#include <string>
#include <vector>
#include <string_view>

#include "Common/CommonTypes.h"

@@ -43,7 +43,7 @@ void Shutdown();
void DeclareAsCPUThread();
void UndeclareAsCPUThread();

std::string StopMessage(bool, const std::string&);
std::string StopMessage(bool main_thread, std::string_view message);

bool IsRunning();
bool IsRunningAndStarted(); // is running and the CPU loop has been entered
@@ -58,7 +58,7 @@ void SetState(State state);
State GetState();

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);

0 comments on commit 5c3e9a3

Please sign in to comment.
You can’t perform that action at this time.