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(), '/');
|
||||
if (!last)
|
||||
return new_filename;
|
||||
|
||||
|
||||
std::string new_path(path.c_str(), last - path.c_str() + 1);
|
||||
new_path += new_filename;
|
||||
return new_path;
|
||||
|
@ -41,7 +41,6 @@ static std::string GetRelativePath(const std::string& path, const char* new_file
|
|||
|
||||
#endif
|
||||
|
||||
|
||||
HostInterface::HostInterface()
|
||||
{
|
||||
m_settings.SetDefaults();
|
||||
|
@ -72,10 +71,18 @@ bool HostInterface::BootSystem(const char* filename, const char* state_filename)
|
|||
|
||||
if (state_filename && !LoadState(state_filename))
|
||||
return false;
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void HostInterface::ResetSystem()
|
||||
{
|
||||
m_system->Reset();
|
||||
ResetPerformanceCounters();
|
||||
AddOSDMessage("System reset.");
|
||||
}
|
||||
|
||||
|
||||
void HostInterface::DestroySystem()
|
||||
{
|
||||
m_system.reset();
|
||||
|
@ -246,3 +253,42 @@ void HostInterface::UpdateSpeedLimiterState()
|
|||
m_throttle_timer.Reset();
|
||||
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 BootSystem(const char* filename, const char* state_filename);
|
||||
void ResetSystem();
|
||||
void DestroySystem();
|
||||
|
||||
virtual void ReportError(const char* message);
|
||||
|
@ -57,6 +58,9 @@ protected:
|
|||
|
||||
void UpdateSpeedLimiterState();
|
||||
|
||||
void UpdatePerformanceCounters();
|
||||
void ResetPerformanceCounters();
|
||||
|
||||
std::unique_ptr<HostDisplay> m_display;
|
||||
std::unique_ptr<AudioStream> m_audio_stream;
|
||||
std::unique_ptr<System> m_system;
|
||||
|
@ -67,6 +71,14 @@ protected:
|
|||
Timer m_throttle_timer;
|
||||
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_speed_limiter_temp_disabled = false;
|
||||
bool m_speed_limiter_enabled = false;
|
||||
|
|
|
@ -166,23 +166,6 @@ void SDLHostInterface::ConnectControllers()
|
|||
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()
|
||||
{
|
||||
SDL_Event ev = {};
|
||||
|
@ -685,7 +668,7 @@ void SDLHostInterface::DrawMainMenuBar()
|
|||
DoPowerOff();
|
||||
|
||||
if (ImGui::MenuItem("Reset", nullptr, false, system_enabled))
|
||||
DoReset();
|
||||
ResetSystem();
|
||||
|
||||
if (ImGui::MenuItem("Pause", nullptr, m_paused, system_enabled))
|
||||
DoTogglePause();
|
||||
|
@ -1343,13 +1326,6 @@ void SDLHostInterface::DrawOSDMessages()
|
|||
}
|
||||
}
|
||||
|
||||
void SDLHostInterface::DoReset()
|
||||
{
|
||||
m_system->Reset();
|
||||
ResetPerformanceCounters();
|
||||
AddOSDMessage("System reset.");
|
||||
}
|
||||
|
||||
void SDLHostInterface::DoPowerOff()
|
||||
{
|
||||
Assert(m_system);
|
||||
|
@ -1555,25 +1531,7 @@ void SDLHostInterface::Run()
|
|||
}
|
||||
}
|
||||
|
||||
if (m_system)
|
||||
{
|
||||
// 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();
|
||||
}
|
||||
}
|
||||
UpdatePerformanceCounters();
|
||||
}
|
||||
|
||||
// Save state on exit so it can be resumed
|
||||
|
|
|
@ -70,14 +70,12 @@ private:
|
|||
|
||||
void SaveSettings();
|
||||
|
||||
void ResetPerformanceCounters();
|
||||
void QueueSwitchGPURenderer();
|
||||
void SwitchGPURenderer();
|
||||
void UpdateFullscreen();
|
||||
|
||||
// We only pass mouse input through if it's grabbed
|
||||
void DrawImGui();
|
||||
void DoReset();
|
||||
void DoPowerOff();
|
||||
void DoResume();
|
||||
void DoStartDisc();
|
||||
|
@ -119,14 +117,6 @@ private:
|
|||
|
||||
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_frame_step_request = false;
|
||||
bool m_focus_main_menu_bar = false;
|
||||
|
|
Loading…
Reference in New Issue