HostInterface: Move performance counters to base class
This commit is contained in:
parent
abfa531648
commit
0a6b913536
|
@ -24,7 +24,7 @@ static std::string GetRelativePath(const std::string& path, const char* new_file
|
||||||
const char* last = std::strrchr(path.c_str(), '/');
|
const char* last = std::strrchr(path.c_str(), '/');
|
||||||
if (!last)
|
if (!last)
|
||||||
return new_filename;
|
return new_filename;
|
||||||
|
|
||||||
std::string new_path(path.c_str(), last - path.c_str() + 1);
|
std::string new_path(path.c_str(), last - path.c_str() + 1);
|
||||||
new_path += new_filename;
|
new_path += new_filename;
|
||||||
return new_path;
|
return new_path;
|
||||||
|
@ -41,7 +41,6 @@ static std::string GetRelativePath(const std::string& path, const char* new_file
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
HostInterface::HostInterface()
|
HostInterface::HostInterface()
|
||||||
{
|
{
|
||||||
m_settings.SetDefaults();
|
m_settings.SetDefaults();
|
||||||
|
@ -72,10 +71,18 @@ bool HostInterface::BootSystem(const char* filename, const char* state_filename)
|
||||||
|
|
||||||
if (state_filename && !LoadState(state_filename))
|
if (state_filename && !LoadState(state_filename))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void HostInterface::ResetSystem()
|
||||||
|
{
|
||||||
|
m_system->Reset();
|
||||||
|
ResetPerformanceCounters();
|
||||||
|
AddOSDMessage("System reset.");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void HostInterface::DestroySystem()
|
void HostInterface::DestroySystem()
|
||||||
{
|
{
|
||||||
m_system.reset();
|
m_system.reset();
|
||||||
|
@ -246,3 +253,42 @@ void HostInterface::UpdateSpeedLimiterState()
|
||||||
m_throttle_timer.Reset();
|
m_throttle_timer.Reset();
|
||||||
m_last_throttle_time = 0;
|
m_last_throttle_time = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void HostInterface::UpdatePerformanceCounters()
|
||||||
|
{
|
||||||
|
if (!m_system)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// update fps counter
|
||||||
|
const double time = m_fps_timer.GetTimeSeconds();
|
||||||
|
if (time >= 0.25f)
|
||||||
|
{
|
||||||
|
m_vps = static_cast<float>(static_cast<double>(m_system->GetFrameNumber() - m_last_frame_number) / time);
|
||||||
|
m_last_frame_number = m_system->GetFrameNumber();
|
||||||
|
m_fps =
|
||||||
|
static_cast<float>(static_cast<double>(m_system->GetInternalFrameNumber() - m_last_internal_frame_number) / time);
|
||||||
|
m_last_internal_frame_number = m_system->GetInternalFrameNumber();
|
||||||
|
m_speed = static_cast<float>(static_cast<double>(m_system->GetGlobalTickCounter() - m_last_global_tick_counter) /
|
||||||
|
(static_cast<double>(MASTER_CLOCK) * time)) *
|
||||||
|
100.0f;
|
||||||
|
m_last_global_tick_counter = m_system->GetGlobalTickCounter();
|
||||||
|
m_fps_timer.Reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void HostInterface::ResetPerformanceCounters()
|
||||||
|
{
|
||||||
|
if (m_system)
|
||||||
|
{
|
||||||
|
m_last_frame_number = m_system->GetFrameNumber();
|
||||||
|
m_last_internal_frame_number = m_system->GetInternalFrameNumber();
|
||||||
|
m_last_global_tick_counter = m_system->GetGlobalTickCounter();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_last_frame_number = 0;
|
||||||
|
m_last_internal_frame_number = 0;
|
||||||
|
m_last_global_tick_counter = 0;
|
||||||
|
}
|
||||||
|
m_fps_timer.Reset();
|
||||||
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@ public:
|
||||||
|
|
||||||
bool CreateSystem();
|
bool CreateSystem();
|
||||||
bool BootSystem(const char* filename, const char* state_filename);
|
bool BootSystem(const char* filename, const char* state_filename);
|
||||||
|
void ResetSystem();
|
||||||
void DestroySystem();
|
void DestroySystem();
|
||||||
|
|
||||||
virtual void ReportError(const char* message);
|
virtual void ReportError(const char* message);
|
||||||
|
@ -57,6 +58,9 @@ protected:
|
||||||
|
|
||||||
void UpdateSpeedLimiterState();
|
void UpdateSpeedLimiterState();
|
||||||
|
|
||||||
|
void UpdatePerformanceCounters();
|
||||||
|
void ResetPerformanceCounters();
|
||||||
|
|
||||||
std::unique_ptr<HostDisplay> m_display;
|
std::unique_ptr<HostDisplay> m_display;
|
||||||
std::unique_ptr<AudioStream> m_audio_stream;
|
std::unique_ptr<AudioStream> m_audio_stream;
|
||||||
std::unique_ptr<System> m_system;
|
std::unique_ptr<System> m_system;
|
||||||
|
@ -67,6 +71,14 @@ protected:
|
||||||
Timer m_throttle_timer;
|
Timer m_throttle_timer;
|
||||||
Timer m_speed_lost_time_timestamp;
|
Timer m_speed_lost_time_timestamp;
|
||||||
|
|
||||||
|
float m_vps = 0.0f;
|
||||||
|
float m_fps = 0.0f;
|
||||||
|
float m_speed = 0.0f;
|
||||||
|
u32 m_last_frame_number = 0;
|
||||||
|
u32 m_last_internal_frame_number = 0;
|
||||||
|
u32 m_last_global_tick_counter = 0;
|
||||||
|
Timer m_fps_timer;
|
||||||
|
|
||||||
bool m_paused = false;
|
bool m_paused = false;
|
||||||
bool m_speed_limiter_temp_disabled = false;
|
bool m_speed_limiter_temp_disabled = false;
|
||||||
bool m_speed_limiter_enabled = false;
|
bool m_speed_limiter_enabled = false;
|
||||||
|
|
|
@ -166,23 +166,6 @@ void SDLHostInterface::ConnectControllers()
|
||||||
m_system->SetController(0, m_controller);
|
m_system->SetController(0, m_controller);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SDLHostInterface::ResetPerformanceCounters()
|
|
||||||
{
|
|
||||||
if (m_system)
|
|
||||||
{
|
|
||||||
m_last_frame_number = m_system->GetFrameNumber();
|
|
||||||
m_last_internal_frame_number = m_system->GetInternalFrameNumber();
|
|
||||||
m_last_global_tick_counter = m_system->GetGlobalTickCounter();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_last_frame_number = 0;
|
|
||||||
m_last_internal_frame_number = 0;
|
|
||||||
m_last_global_tick_counter = 0;
|
|
||||||
}
|
|
||||||
m_fps_timer.Reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
void SDLHostInterface::QueueSwitchGPURenderer()
|
void SDLHostInterface::QueueSwitchGPURenderer()
|
||||||
{
|
{
|
||||||
SDL_Event ev = {};
|
SDL_Event ev = {};
|
||||||
|
@ -685,7 +668,7 @@ void SDLHostInterface::DrawMainMenuBar()
|
||||||
DoPowerOff();
|
DoPowerOff();
|
||||||
|
|
||||||
if (ImGui::MenuItem("Reset", nullptr, false, system_enabled))
|
if (ImGui::MenuItem("Reset", nullptr, false, system_enabled))
|
||||||
DoReset();
|
ResetSystem();
|
||||||
|
|
||||||
if (ImGui::MenuItem("Pause", nullptr, m_paused, system_enabled))
|
if (ImGui::MenuItem("Pause", nullptr, m_paused, system_enabled))
|
||||||
DoTogglePause();
|
DoTogglePause();
|
||||||
|
@ -1343,13 +1326,6 @@ void SDLHostInterface::DrawOSDMessages()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SDLHostInterface::DoReset()
|
|
||||||
{
|
|
||||||
m_system->Reset();
|
|
||||||
ResetPerformanceCounters();
|
|
||||||
AddOSDMessage("System reset.");
|
|
||||||
}
|
|
||||||
|
|
||||||
void SDLHostInterface::DoPowerOff()
|
void SDLHostInterface::DoPowerOff()
|
||||||
{
|
{
|
||||||
Assert(m_system);
|
Assert(m_system);
|
||||||
|
@ -1555,25 +1531,7 @@ void SDLHostInterface::Run()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_system)
|
UpdatePerformanceCounters();
|
||||||
{
|
|
||||||
// update fps counter
|
|
||||||
const double time = m_fps_timer.GetTimeSeconds();
|
|
||||||
if (time >= 0.25f)
|
|
||||||
{
|
|
||||||
m_vps = static_cast<float>(static_cast<double>(m_system->GetFrameNumber() - m_last_frame_number) / time);
|
|
||||||
m_last_frame_number = m_system->GetFrameNumber();
|
|
||||||
m_fps = static_cast<float>(
|
|
||||||
static_cast<double>(m_system->GetInternalFrameNumber() - m_last_internal_frame_number) / time);
|
|
||||||
m_last_internal_frame_number = m_system->GetInternalFrameNumber();
|
|
||||||
m_speed =
|
|
||||||
static_cast<float>(static_cast<double>(m_system->GetGlobalTickCounter() - m_last_global_tick_counter) /
|
|
||||||
(static_cast<double>(MASTER_CLOCK) * time)) *
|
|
||||||
100.0f;
|
|
||||||
m_last_global_tick_counter = m_system->GetGlobalTickCounter();
|
|
||||||
m_fps_timer.Reset();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save state on exit so it can be resumed
|
// Save state on exit so it can be resumed
|
||||||
|
|
|
@ -70,14 +70,12 @@ private:
|
||||||
|
|
||||||
void SaveSettings();
|
void SaveSettings();
|
||||||
|
|
||||||
void ResetPerformanceCounters();
|
|
||||||
void QueueSwitchGPURenderer();
|
void QueueSwitchGPURenderer();
|
||||||
void SwitchGPURenderer();
|
void SwitchGPURenderer();
|
||||||
void UpdateFullscreen();
|
void UpdateFullscreen();
|
||||||
|
|
||||||
// We only pass mouse input through if it's grabbed
|
// We only pass mouse input through if it's grabbed
|
||||||
void DrawImGui();
|
void DrawImGui();
|
||||||
void DoReset();
|
|
||||||
void DoPowerOff();
|
void DoPowerOff();
|
||||||
void DoResume();
|
void DoResume();
|
||||||
void DoStartDisc();
|
void DoStartDisc();
|
||||||
|
@ -119,14 +117,6 @@ private:
|
||||||
|
|
||||||
u32 m_switch_gpu_renderer_event_id = 0;
|
u32 m_switch_gpu_renderer_event_id = 0;
|
||||||
|
|
||||||
float m_vps = 0.0f;
|
|
||||||
float m_fps = 0.0f;
|
|
||||||
float m_speed = 0.0f;
|
|
||||||
u32 m_last_frame_number = 0;
|
|
||||||
u32 m_last_internal_frame_number = 0;
|
|
||||||
u32 m_last_global_tick_counter = 0;
|
|
||||||
Timer m_fps_timer;
|
|
||||||
|
|
||||||
bool m_quit_request = false;
|
bool m_quit_request = false;
|
||||||
bool m_frame_step_request = false;
|
bool m_frame_step_request = false;
|
||||||
bool m_focus_main_menu_bar = false;
|
bool m_focus_main_menu_bar = false;
|
||||||
|
|
Loading…
Reference in New Issue