2019-09-12 14:18:13 +00:00
|
|
|
#pragma once
|
2020-01-10 03:31:12 +00:00
|
|
|
#include "common/timer.h"
|
2019-11-03 14:39:48 +00:00
|
|
|
#include "settings.h"
|
2019-11-16 10:12:03 +00:00
|
|
|
#include "types.h"
|
|
|
|
#include <chrono>
|
2019-12-01 11:33:56 +00:00
|
|
|
#include <deque>
|
2019-09-14 10:28:47 +00:00
|
|
|
#include <memory>
|
2019-12-01 11:33:56 +00:00
|
|
|
#include <mutex>
|
2019-11-16 05:27:57 +00:00
|
|
|
#include <optional>
|
2019-12-01 11:33:56 +00:00
|
|
|
#include <string>
|
2019-11-16 05:27:57 +00:00
|
|
|
#include <vector>
|
2019-09-12 14:18:13 +00:00
|
|
|
|
2019-10-10 16:20:21 +00:00
|
|
|
class AudioStream;
|
2020-01-24 04:50:46 +00:00
|
|
|
class CDImage;
|
2019-11-03 14:39:48 +00:00
|
|
|
class HostDisplay;
|
2020-01-24 04:50:46 +00:00
|
|
|
class GameList;
|
2019-09-12 14:18:13 +00:00
|
|
|
|
2019-09-14 10:28:47 +00:00
|
|
|
class System;
|
|
|
|
|
2019-09-12 14:18:13 +00:00
|
|
|
class HostInterface
|
|
|
|
{
|
2020-01-24 04:50:46 +00:00
|
|
|
friend System;
|
|
|
|
|
2019-09-12 14:18:13 +00:00
|
|
|
public:
|
2019-09-14 10:28:47 +00:00
|
|
|
HostInterface();
|
|
|
|
virtual ~HostInterface();
|
|
|
|
|
2019-11-07 15:07:39 +00:00
|
|
|
/// Access to host display.
|
|
|
|
ALWAYS_INLINE HostDisplay* GetDisplay() const { return m_display.get(); }
|
|
|
|
|
|
|
|
/// Access to host audio stream.
|
2019-10-10 16:20:21 +00:00
|
|
|
AudioStream* GetAudioStream() const { return m_audio_stream.get(); }
|
|
|
|
|
2019-11-07 15:07:39 +00:00
|
|
|
/// Returns a settings object which can be modified.
|
|
|
|
Settings& GetSettings() { return m_settings; }
|
|
|
|
|
2020-01-24 04:50:46 +00:00
|
|
|
/// Returns the game list.
|
|
|
|
const GameList* GetGameList() const { return m_game_list.get(); }
|
|
|
|
|
2019-11-16 10:12:03 +00:00
|
|
|
/// Adjusts the throttle frequency, i.e. how many times we should sleep per second.
|
|
|
|
void SetThrottleFrequency(double frequency) { m_throttle_period = static_cast<s64>(1000000000.0 / frequency); }
|
|
|
|
|
2019-11-16 05:27:57 +00:00
|
|
|
bool CreateSystem();
|
|
|
|
bool BootSystem(const char* filename, const char* state_filename);
|
2019-12-01 11:29:09 +00:00
|
|
|
void ResetSystem();
|
2019-11-16 05:27:57 +00:00
|
|
|
void DestroySystem();
|
2019-11-07 15:07:39 +00:00
|
|
|
|
2019-11-16 05:27:57 +00:00
|
|
|
virtual void ReportError(const char* message);
|
|
|
|
virtual void ReportMessage(const char* message);
|
2019-09-12 14:18:13 +00:00
|
|
|
|
2020-01-10 03:31:12 +00:00
|
|
|
void ReportFormattedError(const char* format, ...);
|
|
|
|
void ReportFormattedMessage(const char* format, ...);
|
|
|
|
|
2019-12-01 11:33:56 +00:00
|
|
|
/// Adds OSD messages, duration is in seconds.
|
|
|
|
void AddOSDMessage(const char* message, float duration = 2.0f);
|
2020-01-10 03:31:12 +00:00
|
|
|
void AddFormattedOSDMessage(float duration, const char* format, ...);
|
2019-09-14 10:28:47 +00:00
|
|
|
|
2019-11-16 05:27:57 +00:00
|
|
|
/// Loads the BIOS image for the specified region.
|
|
|
|
virtual std::optional<std::vector<u8>> GetBIOSImage(ConsoleRegion region);
|
|
|
|
|
2019-09-14 10:28:47 +00:00
|
|
|
bool LoadState(const char* filename);
|
|
|
|
bool SaveState(const char* filename);
|
|
|
|
|
2020-01-24 04:51:00 +00:00
|
|
|
/// Returns the base user directory path.
|
|
|
|
const std::string& GetUserDirectory() const { return m_user_directory; }
|
|
|
|
|
|
|
|
/// Returns a path relative to the user directory.
|
2020-01-24 04:51:03 +00:00
|
|
|
std::string GetUserDirectoryRelativePath(const char* format, ...) const;
|
2020-01-24 04:51:00 +00:00
|
|
|
|
2019-09-30 04:22:30 +00:00
|
|
|
protected:
|
2019-11-16 10:12:03 +00:00
|
|
|
using ThrottleClock = std::chrono::steady_clock;
|
|
|
|
|
2020-01-07 04:17:41 +00:00
|
|
|
enum : u32
|
|
|
|
{
|
|
|
|
AUDIO_SAMPLE_RATE = 44100,
|
|
|
|
AUDIO_CHANNELS = 2,
|
|
|
|
AUDIO_BUFFER_SIZE = 2048,
|
|
|
|
AUDIO_BUFFERS = 2
|
|
|
|
};
|
|
|
|
|
2019-12-01 11:33:56 +00:00
|
|
|
struct OSDMessage
|
|
|
|
{
|
|
|
|
std::string text;
|
2020-01-10 03:31:12 +00:00
|
|
|
Common::Timer time;
|
2019-12-01 11:33:56 +00:00
|
|
|
float duration;
|
|
|
|
};
|
|
|
|
|
2020-01-24 04:49:47 +00:00
|
|
|
virtual void OnPerformanceCountersUpdated();
|
2020-01-24 04:51:05 +00:00
|
|
|
virtual void OnRunningGameChanged();
|
2020-01-24 04:49:47 +00:00
|
|
|
|
2020-01-24 04:51:00 +00:00
|
|
|
void SetUserDirectory();
|
|
|
|
|
2020-01-24 04:51:03 +00:00
|
|
|
/// Returns the path of the settings file.
|
|
|
|
std::string GetSettingsFileName() const;
|
|
|
|
|
2020-01-24 04:49:47 +00:00
|
|
|
void RunFrame();
|
|
|
|
|
2019-11-16 10:12:03 +00:00
|
|
|
/// Throttles the system, i.e. sleeps until it's time to execute the next frame.
|
|
|
|
void Throttle();
|
|
|
|
|
|
|
|
void UpdateSpeedLimiterState();
|
2019-11-07 15:07:39 +00:00
|
|
|
|
2020-01-02 09:14:06 +00:00
|
|
|
void DrawFPSWindow();
|
2019-12-01 11:33:56 +00:00
|
|
|
void DrawOSDMessages();
|
2020-01-02 09:14:06 +00:00
|
|
|
void DrawDebugWindows();
|
2019-12-01 11:33:56 +00:00
|
|
|
void ClearImGuiFocus();
|
|
|
|
|
2019-12-01 11:29:09 +00:00
|
|
|
void UpdatePerformanceCounters();
|
|
|
|
void ResetPerformanceCounters();
|
|
|
|
|
2019-11-07 15:07:39 +00:00
|
|
|
std::unique_ptr<HostDisplay> m_display;
|
2019-10-10 16:20:21 +00:00
|
|
|
std::unique_ptr<AudioStream> m_audio_stream;
|
2019-09-14 10:28:47 +00:00
|
|
|
std::unique_ptr<System> m_system;
|
2020-01-24 04:50:46 +00:00
|
|
|
std::unique_ptr<GameList> m_game_list;
|
2019-11-03 14:39:48 +00:00
|
|
|
Settings m_settings;
|
2020-01-24 04:51:00 +00:00
|
|
|
std::string m_user_directory;
|
2019-11-07 15:07:39 +00:00
|
|
|
|
2019-11-16 10:12:03 +00:00
|
|
|
u64 m_last_throttle_time = 0;
|
|
|
|
s64 m_throttle_period = INT64_C(1000000000) / 60;
|
2020-01-10 03:31:12 +00:00
|
|
|
Common::Timer m_throttle_timer;
|
|
|
|
Common::Timer m_speed_lost_time_timestamp;
|
2019-11-16 10:12:03 +00:00
|
|
|
|
2020-01-24 04:49:47 +00:00
|
|
|
bool m_paused = false;
|
|
|
|
bool m_speed_limiter_temp_disabled = false;
|
|
|
|
bool m_speed_limiter_enabled = false;
|
|
|
|
|
|
|
|
float m_average_frame_time_accumulator = 0.0f;
|
|
|
|
float m_worst_frame_time_accumulator = 0.0f;
|
|
|
|
|
2019-12-01 11:29:09 +00:00
|
|
|
float m_vps = 0.0f;
|
|
|
|
float m_fps = 0.0f;
|
|
|
|
float m_speed = 0.0f;
|
2020-01-24 04:49:47 +00:00
|
|
|
float m_worst_frame_time = 0.0f;
|
|
|
|
float m_average_frame_time = 0.0f;
|
2019-12-01 11:29:09 +00:00
|
|
|
u32 m_last_frame_number = 0;
|
|
|
|
u32 m_last_internal_frame_number = 0;
|
|
|
|
u32 m_last_global_tick_counter = 0;
|
2020-01-10 03:31:12 +00:00
|
|
|
Common::Timer m_fps_timer;
|
2020-01-24 04:49:47 +00:00
|
|
|
Common::Timer m_frame_timer;
|
2019-12-01 11:29:09 +00:00
|
|
|
|
2019-12-01 11:33:56 +00:00
|
|
|
std::deque<OSDMessage> m_osd_messages;
|
|
|
|
std::mutex m_osd_messages_lock;
|
2019-09-12 14:18:13 +00:00
|
|
|
};
|