mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2024-12-04 03:25:39 +00:00
Move most helper logic from base HostInterface to FrontendCommon
This commit is contained in:
parent
444a09efd4
commit
075380f8e0
File diff suppressed because it is too large
Load diff
|
@ -28,12 +28,6 @@ class HostInterface
|
||||||
friend System;
|
friend System;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum : s32
|
|
||||||
{
|
|
||||||
PER_GAME_SAVE_STATE_SLOTS = 10,
|
|
||||||
GLOBAL_SAVE_STATE_SLOTS = 10
|
|
||||||
};
|
|
||||||
|
|
||||||
enum : u32
|
enum : u32
|
||||||
{
|
{
|
||||||
AUDIO_SAMPLE_RATE = 44100,
|
AUDIO_SAMPLE_RATE = 44100,
|
||||||
|
@ -41,29 +35,6 @@ public:
|
||||||
DEFAULT_AUDIO_BUFFER_SIZE = 2048
|
DEFAULT_AUDIO_BUFFER_SIZE = 2048
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SaveStateInfo
|
|
||||||
{
|
|
||||||
std::string path;
|
|
||||||
u64 timestamp;
|
|
||||||
s32 slot;
|
|
||||||
bool global;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ExtendedSaveStateInfo
|
|
||||||
{
|
|
||||||
std::string path;
|
|
||||||
u64 timestamp;
|
|
||||||
s32 slot;
|
|
||||||
bool global;
|
|
||||||
|
|
||||||
std::string title;
|
|
||||||
std::string game_code;
|
|
||||||
|
|
||||||
u32 screenshot_width;
|
|
||||||
u32 screenshot_height;
|
|
||||||
std::vector<u32> screenshot_data;
|
|
||||||
};
|
|
||||||
|
|
||||||
HostInterface();
|
HostInterface();
|
||||||
virtual ~HostInterface();
|
virtual ~HostInterface();
|
||||||
|
|
||||||
|
@ -76,9 +47,6 @@ public:
|
||||||
/// Returns a settings object which can be modified.
|
/// Returns a settings object which can be modified.
|
||||||
ALWAYS_INLINE Settings& GetSettings() { return m_settings; }
|
ALWAYS_INLINE Settings& GetSettings() { return m_settings; }
|
||||||
|
|
||||||
/// Returns the game list.
|
|
||||||
ALWAYS_INLINE const GameList* GetGameList() const { return m_game_list.get(); }
|
|
||||||
|
|
||||||
/// Access to emulated system.
|
/// Access to emulated system.
|
||||||
ALWAYS_INLINE System* GetSystem() const { return m_system.get(); }
|
ALWAYS_INLINE System* GetSystem() const { return m_system.get(); }
|
||||||
|
|
||||||
|
@ -91,41 +59,12 @@ public:
|
||||||
virtual bool BootSystem(const SystemBootParameters& parameters);
|
virtual bool BootSystem(const SystemBootParameters& parameters);
|
||||||
virtual void PowerOffSystem();
|
virtual void PowerOffSystem();
|
||||||
|
|
||||||
void PauseSystem(bool paused);
|
virtual void ResetSystem();
|
||||||
void ResetSystem();
|
virtual void DestroySystem();
|
||||||
void DestroySystem();
|
|
||||||
|
|
||||||
/// Loads state from the specified filename.
|
/// Loads state from the specified filename.
|
||||||
bool LoadState(const char* filename);
|
bool LoadState(const char* filename);
|
||||||
|
|
||||||
/// Loads the current emulation state from file. Specifying a slot of -1 loads the "resume" game state.
|
|
||||||
bool LoadState(bool global, s32 slot);
|
|
||||||
|
|
||||||
/// Saves the current emulation state to a file. Specifying a slot of -1 saves the "resume" save state.
|
|
||||||
bool SaveState(bool global, s32 slot);
|
|
||||||
|
|
||||||
/// Loads the resume save state for the given game. Optionally boots the game anyway if loading fails.
|
|
||||||
bool ResumeSystemFromState(const char* filename, bool boot_on_failure);
|
|
||||||
|
|
||||||
/// Loads the most recent resume save state. This may be global or per-game.
|
|
||||||
bool ResumeSystemFromMostRecentState();
|
|
||||||
|
|
||||||
/// Saves the resume save state, call when shutting down. Not called automatically on DestroySystem() since that can
|
|
||||||
/// be called as a result of an error.
|
|
||||||
bool SaveResumeSaveState();
|
|
||||||
|
|
||||||
/// Returns true if currently dumping audio.
|
|
||||||
bool IsDumpingAudio() const;
|
|
||||||
|
|
||||||
/// Starts dumping audio to a file. If no file name is provided, one will be generated automatically.
|
|
||||||
bool StartDumpingAudio(const char* filename = nullptr);
|
|
||||||
|
|
||||||
/// Stops dumping audio to file if it has been started.
|
|
||||||
void StopDumpingAudio();
|
|
||||||
|
|
||||||
/// Saves a screenshot to the specified file. IF no file name is provided, one will be generated automatically.
|
|
||||||
bool SaveScreenshot(const char* filename = nullptr, bool full_resolution = true, bool apply_aspect_ratio = true);
|
|
||||||
|
|
||||||
virtual void ReportError(const char* message);
|
virtual void ReportError(const char* message);
|
||||||
virtual void ReportMessage(const char* message);
|
virtual void ReportMessage(const char* message);
|
||||||
virtual bool ConfirmMessage(const char* message);
|
virtual bool ConfirmMessage(const char* message);
|
||||||
|
@ -135,7 +74,7 @@ public:
|
||||||
bool ConfirmFormattedMessage(const char* format, ...);
|
bool ConfirmFormattedMessage(const char* format, ...);
|
||||||
|
|
||||||
/// Adds OSD messages, duration is in seconds.
|
/// Adds OSD messages, duration is in seconds.
|
||||||
void AddOSDMessage(const char* message, float duration = 2.0f);
|
virtual void AddOSDMessage(std::string message, float duration = 2.0f);
|
||||||
void AddFormattedOSDMessage(float duration, const char* format, ...);
|
void AddFormattedOSDMessage(float duration, const char* format, ...);
|
||||||
|
|
||||||
/// Returns the base user directory path.
|
/// Returns the base user directory path.
|
||||||
|
@ -152,19 +91,10 @@ public:
|
||||||
|
|
||||||
/// Displays a loading screen with the logo, rendered with ImGui. Use when executing possibly-time-consuming tasks
|
/// Displays a loading screen with the logo, rendered with ImGui. Use when executing possibly-time-consuming tasks
|
||||||
/// such as compiling shaders when starting up.
|
/// such as compiling shaders when starting up.
|
||||||
void DisplayLoadingScreen(const char* message, int progress_min = -1, int progress_max = -1, int progress_value = -1);
|
virtual void DisplayLoadingScreen(const char* message, int progress_min = -1, int progress_max = -1, int progress_value = -1);
|
||||||
|
|
||||||
/// Returns a list of save states for the specified game code.
|
/// Retrieves information about specified game from game list.
|
||||||
std::vector<SaveStateInfo> GetAvailableSaveStates(const char* game_code) const;
|
virtual void GetGameInfo(const char* path, CDImage* image, std::string* code, std::string* title);
|
||||||
|
|
||||||
/// Returns save state info if present. If game_code is null or empty, assumes global state.
|
|
||||||
std::optional<SaveStateInfo> GetSaveStateInfo(const char* game_code, s32 slot);
|
|
||||||
|
|
||||||
/// Returns save state info if present. If game_code is null or empty, assumes global state.
|
|
||||||
std::optional<ExtendedSaveStateInfo> GetExtendedSaveStateInfo(const char* game_code, s32 slot);
|
|
||||||
|
|
||||||
/// Deletes save states for the specified game code. If resume is set, the resume state is deleted too.
|
|
||||||
void DeleteSaveStates(const char* game_code, bool resume);
|
|
||||||
|
|
||||||
/// Enables the software cursor. Can be called multiple times, but must be matched by a call to DisableSoftwareCursor().
|
/// Enables the software cursor. Can be called multiple times, but must be matched by a call to DisableSoftwareCursor().
|
||||||
void EnableSoftwareCursor();
|
void EnableSoftwareCursor();
|
||||||
|
@ -173,118 +103,59 @@ public:
|
||||||
void DisableSoftwareCursor();
|
void DisableSoftwareCursor();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
enum : u32
|
|
||||||
{
|
|
||||||
SETTINGS_VERSION = 2
|
|
||||||
};
|
|
||||||
|
|
||||||
struct OSDMessage
|
|
||||||
{
|
|
||||||
std::string text;
|
|
||||||
Common::Timer time;
|
|
||||||
float duration;
|
|
||||||
};
|
|
||||||
|
|
||||||
virtual bool AcquireHostDisplay() = 0;
|
virtual bool AcquireHostDisplay() = 0;
|
||||||
virtual void ReleaseHostDisplay() = 0;
|
virtual void ReleaseHostDisplay() = 0;
|
||||||
virtual std::unique_ptr<AudioStream> CreateAudioStream(AudioBackend backend) = 0;
|
virtual std::unique_ptr<AudioStream> CreateAudioStream(AudioBackend backend) = 0;
|
||||||
|
|
||||||
virtual void OnSystemCreated();
|
virtual void OnSystemCreated();
|
||||||
virtual void OnSystemPaused(bool paused);
|
|
||||||
virtual void OnSystemDestroyed();
|
virtual void OnSystemDestroyed();
|
||||||
virtual void OnSystemPerformanceCountersUpdated();
|
virtual void OnSystemPerformanceCountersUpdated();
|
||||||
virtual void OnSystemStateSaved(bool global, s32 slot);
|
virtual void OnSystemStateSaved(bool global, s32 slot);
|
||||||
virtual void OnRunningGameChanged();
|
virtual void OnRunningGameChanged();
|
||||||
virtual void OnControllerTypeChanged(u32 slot);
|
virtual void OnControllerTypeChanged(u32 slot);
|
||||||
virtual void DrawImGuiWindows();
|
|
||||||
|
|
||||||
/// Sets the base path for the user directory. Can be overridden by platform/frontend/command line.
|
/// Restores all settings to defaults.
|
||||||
virtual void SetUserDirectory();
|
virtual void SetDefaultSettings(SettingsInterface& si);
|
||||||
|
|
||||||
|
/// Loads settings to m_settings and any frontend-specific parameters.
|
||||||
|
virtual void LoadSettings(SettingsInterface& si);
|
||||||
|
|
||||||
|
/// Saves current settings variables to ini.
|
||||||
|
virtual void SaveSettings(SettingsInterface& si);
|
||||||
|
|
||||||
|
/// Checks for settings changes, std::move() the old settings away for comparing beforehand.
|
||||||
|
virtual void CheckForSettingsChanges(const Settings& old_settings);
|
||||||
|
|
||||||
|
/// Switches the GPU renderer by saving state, recreating the display window, and restoring state (if needed).
|
||||||
|
virtual void RecreateSystem();
|
||||||
|
|
||||||
/// Sets the user directory to the program directory, i.e. "portable mode".
|
/// Sets the user directory to the program directory, i.e. "portable mode".
|
||||||
void SetUserDirectoryToProgramDirectory();
|
void SetUserDirectoryToProgramDirectory();
|
||||||
|
|
||||||
/// Performs the initial load of settings. Should call CheckSettings() and ApplySettings().
|
|
||||||
virtual void LoadSettings() = 0;
|
|
||||||
|
|
||||||
/// Updates logging settings.
|
|
||||||
virtual void UpdateLogSettings(LOGLEVEL level, const char* filter, bool log_to_console, bool log_to_debug,
|
|
||||||
bool log_to_window, bool log_to_file);
|
|
||||||
|
|
||||||
/// Returns the path of the settings file.
|
|
||||||
std::string GetSettingsFileName() const;
|
|
||||||
|
|
||||||
/// Returns the path to a save state file. Specifying an index of -1 is the "resume" save state.
|
|
||||||
std::string GetGameSaveStateFileName(const char* game_code, s32 slot) const;
|
|
||||||
|
|
||||||
/// Returns the path to a save state file. Specifying an index of -1 is the "resume" save state.
|
|
||||||
std::string GetGlobalSaveStateFileName(s32 slot) const;
|
|
||||||
|
|
||||||
/// Returns the default path to a memory card.
|
/// Returns the default path to a memory card.
|
||||||
std::string GetSharedMemoryCardPath(u32 slot) const;
|
std::string GetSharedMemoryCardPath(u32 slot) const;
|
||||||
|
|
||||||
/// Returns the default path to a memory card for a specific game.
|
/// Returns the default path to a memory card for a specific game.
|
||||||
std::string GetGameMemoryCardPath(const char* game_code, u32 slot) const;
|
std::string GetGameMemoryCardPath(const char* game_code, u32 slot) const;
|
||||||
|
|
||||||
/// Returns the most recent resume save state.
|
|
||||||
std::string GetMostRecentResumeSaveStatePath() const;
|
|
||||||
|
|
||||||
/// Loads the BIOS image for the specified region.
|
/// Loads the BIOS image for the specified region.
|
||||||
std::optional<std::vector<u8>> GetBIOSImage(ConsoleRegion region);
|
std::optional<std::vector<u8>> GetBIOSImage(ConsoleRegion region);
|
||||||
|
|
||||||
/// Ensures the settings is valid and the correct version. If not, resets to defaults.
|
|
||||||
void CheckSettings(SettingsInterface& si);
|
|
||||||
|
|
||||||
/// Restores all settings to defaults.
|
|
||||||
virtual void SetDefaultSettings(SettingsInterface& si);
|
|
||||||
|
|
||||||
/// Loads settings to m_settings and any frontend-specific parameters.
|
|
||||||
virtual void ApplySettings(SettingsInterface& si);
|
|
||||||
|
|
||||||
/// Saves current settings variables to ini.
|
|
||||||
virtual void ExportSettings(SettingsInterface& si);
|
|
||||||
|
|
||||||
/// Applies new settings, updating internal state as needed.
|
|
||||||
virtual void UpdateSettings(SettingsInterface& si);
|
|
||||||
|
|
||||||
/// Quick switch between software and hardware rendering.
|
/// Quick switch between software and hardware rendering.
|
||||||
void ToggleSoftwareRendering();
|
void ToggleSoftwareRendering();
|
||||||
|
|
||||||
/// Adjusts the internal (render) resolution of the hardware backends.
|
/// Adjusts the internal (render) resolution of the hardware backends.
|
||||||
void ModifyResolutionScale(s32 increment);
|
void ModifyResolutionScale(s32 increment);
|
||||||
|
|
||||||
/// Switches the GPU renderer by saving state, recreating the display window, and restoring state (if needed).
|
bool SaveState(const char* filename);
|
||||||
void RecreateSystem();
|
void CreateAudioStream();
|
||||||
|
|
||||||
/// Increases timer resolution when supported by the host OS.
|
|
||||||
void SetTimerResolutionIncreased(bool enabled);
|
|
||||||
|
|
||||||
void UpdateSpeedLimiterState();
|
|
||||||
|
|
||||||
void DrawFPSWindow();
|
|
||||||
void DrawOSDMessages();
|
|
||||||
void DrawDebugWindows();
|
|
||||||
|
|
||||||
HostDisplay* m_display = nullptr;
|
HostDisplay* m_display = nullptr;
|
||||||
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;
|
||||||
std::unique_ptr<GameList> m_game_list;
|
|
||||||
Settings m_settings;
|
Settings m_settings;
|
||||||
std::string m_program_directory;
|
std::string m_program_directory;
|
||||||
std::string m_user_directory;
|
std::string m_user_directory;
|
||||||
|
|
||||||
std::deque<OSDMessage> m_osd_messages;
|
|
||||||
std::mutex m_osd_messages_lock;
|
|
||||||
|
|
||||||
u32 m_software_cursor_use_count = 0;
|
u32 m_software_cursor_use_count = 0;
|
||||||
|
|
||||||
bool m_paused = false;
|
|
||||||
bool m_speed_limiter_temp_disabled = false;
|
|
||||||
bool m_speed_limiter_enabled = false;
|
|
||||||
bool m_timer_resolution_increased = false;
|
|
||||||
|
|
||||||
private:
|
|
||||||
void InitializeUserDirectory();
|
|
||||||
void CreateAudioStream();
|
|
||||||
bool SaveState(const char* filename);
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include "memory_card.h"
|
#include "memory_card.h"
|
||||||
#include "common/byte_stream.h"
|
#include "common/byte_stream.h"
|
||||||
#include "common/file_system.h"
|
#include "common/file_system.h"
|
||||||
|
#include "common/string_util.h"
|
||||||
#include "common/log.h"
|
#include "common/log.h"
|
||||||
#include "common/state_wrapper.h"
|
#include "common/state_wrapper.h"
|
||||||
#include "host_interface.h"
|
#include "host_interface.h"
|
||||||
|
@ -254,7 +255,7 @@ std::unique_ptr<MemoryCard> MemoryCard::Open(System* system, std::string_view fi
|
||||||
message.AppendString(filename.data(), static_cast<u32>(filename.length()));
|
message.AppendString(filename.data(), static_cast<u32>(filename.length()));
|
||||||
message.AppendString("' could not be read, formatting.");
|
message.AppendString("' could not be read, formatting.");
|
||||||
Log_ErrorPrint(message);
|
Log_ErrorPrint(message);
|
||||||
system->GetHostInterface()->AddOSDMessage(message, 5.0f);
|
system->GetHostInterface()->AddOSDMessage(message.GetCharArray(), 5.0f);
|
||||||
mc->Format();
|
mc->Format();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -385,7 +386,7 @@ bool MemoryCard::SaveIfChanged(bool display_osd_message)
|
||||||
if (display_osd_message)
|
if (display_osd_message)
|
||||||
{
|
{
|
||||||
m_system->GetHostInterface()->AddOSDMessage(
|
m_system->GetHostInterface()->AddOSDMessage(
|
||||||
SmallString::FromFormat("Saved memory card to '%s'", m_filename.c_str()));
|
StringUtil::StdStringFromFormat("Saved memory card to '%s'", m_filename.c_str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -73,7 +73,7 @@ void Settings::Load(SettingsInterface& si)
|
||||||
gpu_max_run_ahead = si.GetIntValue("Hacks", "GPUMaxRunAhead", DEFAULT_GPU_MAX_RUN_AHEAD);
|
gpu_max_run_ahead = si.GetIntValue("Hacks", "GPUMaxRunAhead", DEFAULT_GPU_MAX_RUN_AHEAD);
|
||||||
|
|
||||||
bios_path = si.GetStringValue("BIOS", "Path", "bios/scph1001.bin");
|
bios_path = si.GetStringValue("BIOS", "Path", "bios/scph1001.bin");
|
||||||
bios_patch_tty_enable = si.GetBoolValue("BIOS", "PatchTTYEnable", true);
|
bios_patch_tty_enable = si.GetBoolValue("BIOS", "PatchTTYEnable", false);
|
||||||
bios_patch_fast_boot = si.GetBoolValue("BIOS", "PatchFastBoot", false);
|
bios_patch_fast_boot = si.GetBoolValue("BIOS", "PatchFastBoot", false);
|
||||||
|
|
||||||
controller_types[0] = ParseControllerTypeName(si.GetStringValue("Controller1", "Type", "DigitalController").c_str())
|
controller_types[0] = ParseControllerTypeName(si.GetStringValue("Controller1", "Type", "DigitalController").c_str())
|
||||||
|
|
|
@ -1133,26 +1133,7 @@ void System::UpdateRunningGame(const char* path, CDImage* image)
|
||||||
if (path && std::strlen(path) > 0)
|
if (path && std::strlen(path) > 0)
|
||||||
{
|
{
|
||||||
m_running_game_path = path;
|
m_running_game_path = path;
|
||||||
|
m_host_interface->GetGameInfo(path, image, &m_running_game_code, &m_running_game_title);
|
||||||
const GameListEntry* list_entry = m_host_interface->GetGameList()->GetEntryForPath(path);
|
|
||||||
if (list_entry)
|
|
||||||
{
|
|
||||||
m_running_game_code = list_entry->code;
|
|
||||||
m_running_game_title = list_entry->title;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (image)
|
|
||||||
m_running_game_code = GameList::GetGameCodeForImage(image);
|
|
||||||
|
|
||||||
const GameListDatabaseEntry* db_entry =
|
|
||||||
(!m_running_game_code.empty()) ? m_host_interface->GetGameList()->GetDatabaseEntryForCode(m_running_game_code) :
|
|
||||||
nullptr;
|
|
||||||
if (db_entry)
|
|
||||||
m_running_game_title = db_entry->title;
|
|
||||||
else
|
|
||||||
m_running_game_title = GameList::GetTitleForPath(path);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_host_interface->OnRunningGameChanged();
|
m_host_interface->OnRunningGameChanged();
|
||||||
|
|
|
@ -90,6 +90,7 @@ public:
|
||||||
float GetEmulationSpeed() const { return m_speed; }
|
float GetEmulationSpeed() const { return m_speed; }
|
||||||
float GetAverageFrameTime() const { return m_average_frame_time; }
|
float GetAverageFrameTime() const { return m_average_frame_time; }
|
||||||
float GetWorstFrameTime() const { return m_worst_frame_time; }
|
float GetWorstFrameTime() const { return m_worst_frame_time; }
|
||||||
|
float GetThrottleFrequency() const { return m_throttle_frequency; }
|
||||||
|
|
||||||
bool Boot(const SystemBootParameters& params);
|
bool Boot(const SystemBootParameters& params);
|
||||||
void Reset();
|
void Reset();
|
||||||
|
|
|
@ -144,13 +144,15 @@ void QtHostInterface::setDefaultSettings()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QtSettingsInterface si(m_qsettings.get());
|
Settings old_settings(std::move(m_settings));
|
||||||
{
|
{
|
||||||
|
QtSettingsInterface si(m_qsettings.get());
|
||||||
std::lock_guard<std::recursive_mutex> guard(m_qsettings_mutex);
|
std::lock_guard<std::recursive_mutex> guard(m_qsettings_mutex);
|
||||||
SetDefaultSettings(si);
|
SetDefaultSettings(si);
|
||||||
|
CommonHostInterface::LoadSettings(si);
|
||||||
}
|
}
|
||||||
UpdateSettings(si);
|
|
||||||
CommonHostInterface::UpdateInputMap(si);
|
CheckForSettingsChanges(old_settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtHostInterface::applySettings()
|
void QtHostInterface::applySettings()
|
||||||
|
@ -161,15 +163,19 @@ void QtHostInterface::applySettings()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::lock_guard<std::recursive_mutex> guard(m_qsettings_mutex);
|
Settings old_settings(std::move(m_settings));
|
||||||
QtSettingsInterface si(m_qsettings.get());
|
{
|
||||||
UpdateSettings(si);
|
QtSettingsInterface si(m_qsettings.get());
|
||||||
CommonHostInterface::UpdateInputMap(si);
|
std::lock_guard<std::recursive_mutex> guard(m_qsettings_mutex);
|
||||||
|
CommonHostInterface::LoadSettings(si);
|
||||||
|
}
|
||||||
|
|
||||||
|
CheckForSettingsChanges(old_settings);
|
||||||
|
|
||||||
// detect when render-to-main flag changes
|
// detect when render-to-main flag changes
|
||||||
if (m_system)
|
if (m_system)
|
||||||
{
|
{
|
||||||
const bool render_to_main = m_qsettings->value("Main/RenderToMainWindow", true).toBool();
|
const bool render_to_main = getSettingValue("Main/RenderToMainWindow", true).toBool();
|
||||||
if (getHostDisplay() && !m_is_fullscreen && render_to_main != m_is_rendering_to_main)
|
if (getHostDisplay() && !m_is_fullscreen && render_to_main != m_is_rendering_to_main)
|
||||||
{
|
{
|
||||||
m_is_rendering_to_main = render_to_main;
|
m_is_rendering_to_main = render_to_main;
|
||||||
|
@ -224,9 +230,9 @@ void QtHostInterface::resumeSystemFromState(const QString& filename, bool boot_o
|
||||||
|
|
||||||
emit emulationStarting();
|
emit emulationStarting();
|
||||||
if (filename.isEmpty())
|
if (filename.isEmpty())
|
||||||
HostInterface::ResumeSystemFromMostRecentState();
|
ResumeSystemFromMostRecentState();
|
||||||
else
|
else
|
||||||
HostInterface::ResumeSystemFromState(filename.toStdString().c_str(), boot_on_failure);
|
ResumeSystemFromState(filename.toStdString().c_str(), boot_on_failure);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtHostInterface::resumeSystemFromMostRecentState()
|
void QtHostInterface::resumeSystemFromMostRecentState()
|
||||||
|
@ -238,7 +244,7 @@ void QtHostInterface::resumeSystemFromMostRecentState()
|
||||||
}
|
}
|
||||||
|
|
||||||
emit emulationStarting();
|
emit emulationStarting();
|
||||||
HostInterface::ResumeSystemFromMostRecentState();
|
ResumeSystemFromMostRecentState();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtHostInterface::onDisplayWindowKeyEvent(int key, bool pressed)
|
void QtHostInterface::onDisplayWindowKeyEvent(int key, bool pressed)
|
||||||
|
@ -510,8 +516,8 @@ void QtHostInterface::LoadSettings()
|
||||||
}
|
}
|
||||||
|
|
||||||
// load in settings
|
// load in settings
|
||||||
CheckSettings(si);
|
CommonHostInterface::CheckSettings(si);
|
||||||
ApplySettings(si);
|
CommonHostInterface::LoadSettings(si);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtHostInterface::SetDefaultSettings(SettingsInterface& si)
|
void QtHostInterface::SetDefaultSettings(SettingsInterface& si)
|
||||||
|
@ -521,12 +527,6 @@ void QtHostInterface::SetDefaultSettings(SettingsInterface& si)
|
||||||
si.SetBoolValue("Main", "RenderToMainWindow", true);
|
si.SetBoolValue("Main", "RenderToMainWindow", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtHostInterface::ApplySettings(SettingsInterface& si)
|
|
||||||
{
|
|
||||||
std::lock_guard<std::recursive_mutex> lock(m_qsettings_mutex);
|
|
||||||
CommonHostInterface::ApplySettings(si);
|
|
||||||
}
|
|
||||||
|
|
||||||
void QtHostInterface::UpdateInputMap()
|
void QtHostInterface::UpdateInputMap()
|
||||||
{
|
{
|
||||||
updateInputMap();
|
updateInputMap();
|
||||||
|
|
|
@ -158,7 +158,6 @@ protected:
|
||||||
|
|
||||||
void LoadSettings() override;
|
void LoadSettings() override;
|
||||||
void SetDefaultSettings(SettingsInterface& si) override;
|
void SetDefaultSettings(SettingsInterface& si) override;
|
||||||
void ApplySettings(SettingsInterface& si) override;
|
|
||||||
void UpdateInputMap() override;
|
void UpdateInputMap() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -299,7 +299,11 @@ void SDLHostInterface::RunLater(std::function<void()> callback)
|
||||||
void SDLHostInterface::SaveAndUpdateSettings()
|
void SDLHostInterface::SaveAndUpdateSettings()
|
||||||
{
|
{
|
||||||
m_settings_copy.Save(*m_settings_interface.get());
|
m_settings_copy.Save(*m_settings_interface.get());
|
||||||
UpdateSettings(*m_settings_interface.get());
|
|
||||||
|
Settings old_settings(std::move(m_settings));
|
||||||
|
CommonHostInterface::LoadSettings(*m_settings_interface.get());
|
||||||
|
CheckForSettingsChanges(old_settings);
|
||||||
|
|
||||||
m_settings_interface->Save();
|
m_settings_interface->Save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -382,7 +386,7 @@ void SDLHostInterface::LoadSettings()
|
||||||
{
|
{
|
||||||
// Settings need to be loaded prior to creating the window for OpenGL bits.
|
// Settings need to be loaded prior to creating the window for OpenGL bits.
|
||||||
m_settings_interface = std::make_unique<INISettingsInterface>(GetSettingsFileName());
|
m_settings_interface = std::make_unique<INISettingsInterface>(GetSettingsFileName());
|
||||||
ApplySettings(*m_settings_interface.get());
|
CommonHostInterface::LoadSettings(*m_settings_interface.get());
|
||||||
m_settings_copy = m_settings;
|
m_settings_copy = m_settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -22,6 +22,12 @@ class CommonHostInterface : public HostInterface
|
||||||
public:
|
public:
|
||||||
friend ControllerInterface;
|
friend ControllerInterface;
|
||||||
|
|
||||||
|
enum : s32
|
||||||
|
{
|
||||||
|
PER_GAME_SAVE_STATE_SLOTS = 10,
|
||||||
|
GLOBAL_SAVE_STATE_SLOTS = 10
|
||||||
|
};
|
||||||
|
|
||||||
using HostKeyCode = s32;
|
using HostKeyCode = s32;
|
||||||
using HostMouseButton = s32;
|
using HostMouseButton = s32;
|
||||||
|
|
||||||
|
@ -39,6 +45,32 @@ public:
|
||||||
|
|
||||||
using HotkeyInfoList = std::vector<HotkeyInfo>;
|
using HotkeyInfoList = std::vector<HotkeyInfo>;
|
||||||
|
|
||||||
|
struct SaveStateInfo
|
||||||
|
{
|
||||||
|
std::string path;
|
||||||
|
u64 timestamp;
|
||||||
|
s32 slot;
|
||||||
|
bool global;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ExtendedSaveStateInfo
|
||||||
|
{
|
||||||
|
std::string path;
|
||||||
|
u64 timestamp;
|
||||||
|
s32 slot;
|
||||||
|
bool global;
|
||||||
|
|
||||||
|
std::string title;
|
||||||
|
std::string game_code;
|
||||||
|
|
||||||
|
u32 screenshot_width;
|
||||||
|
u32 screenshot_height;
|
||||||
|
std::vector<u32> screenshot_data;
|
||||||
|
};
|
||||||
|
|
||||||
|
using HostInterface::LoadState;
|
||||||
|
using HostInterface::SaveState;
|
||||||
|
|
||||||
/// Returns the name of the frontend.
|
/// Returns the name of the frontend.
|
||||||
virtual const char* GetFrontendName() const = 0;
|
virtual const char* GetFrontendName() const = 0;
|
||||||
|
|
||||||
|
@ -47,6 +79,10 @@ public:
|
||||||
|
|
||||||
virtual bool BootSystem(const SystemBootParameters& parameters) override;
|
virtual bool BootSystem(const SystemBootParameters& parameters) override;
|
||||||
virtual void PowerOffSystem() override;
|
virtual void PowerOffSystem() override;
|
||||||
|
virtual void DestroySystem() override;
|
||||||
|
|
||||||
|
/// Returns the game list.
|
||||||
|
ALWAYS_INLINE const GameList* GetGameList() const { return m_game_list.get(); }
|
||||||
|
|
||||||
/// Returns a list of all available hotkeys.
|
/// Returns a list of all available hotkeys.
|
||||||
ALWAYS_INLINE const HotkeyInfoList& GetHotkeyInfoList() const { return m_hotkeys; }
|
ALWAYS_INLINE const HotkeyInfoList& GetHotkeyInfoList() const { return m_hotkeys; }
|
||||||
|
@ -57,10 +93,75 @@ public:
|
||||||
/// Returns true if running in batch mode, i.e. exit after emulation.
|
/// Returns true if running in batch mode, i.e. exit after emulation.
|
||||||
ALWAYS_INLINE bool InBatchMode() const { return m_batch_mode; }
|
ALWAYS_INLINE bool InBatchMode() const { return m_batch_mode; }
|
||||||
|
|
||||||
|
void PauseSystem(bool paused);
|
||||||
|
|
||||||
/// Parses command line parameters for all frontends.
|
/// Parses command line parameters for all frontends.
|
||||||
bool ParseCommandLineParameters(int argc, char* argv[], std::unique_ptr<SystemBootParameters>* out_boot_params);
|
bool ParseCommandLineParameters(int argc, char* argv[], std::unique_ptr<SystemBootParameters>* out_boot_params);
|
||||||
|
|
||||||
|
/// Loads the current emulation state from file. Specifying a slot of -1 loads the "resume" game state.
|
||||||
|
bool LoadState(bool global, s32 slot);
|
||||||
|
|
||||||
|
/// Saves the current emulation state to a file. Specifying a slot of -1 saves the "resume" save state.
|
||||||
|
bool SaveState(bool global, s32 slot);
|
||||||
|
|
||||||
|
/// Loads the resume save state for the given game. Optionally boots the game anyway if loading fails.
|
||||||
|
bool ResumeSystemFromState(const char* filename, bool boot_on_failure);
|
||||||
|
|
||||||
|
/// Loads the most recent resume save state. This may be global or per-game.
|
||||||
|
bool ResumeSystemFromMostRecentState();
|
||||||
|
|
||||||
|
/// Saves the resume save state, call when shutting down. Not called automatically on DestroySystem() since that can
|
||||||
|
/// be called as a result of an error.
|
||||||
|
bool SaveResumeSaveState();
|
||||||
|
|
||||||
|
/// Returns a list of save states for the specified game code.
|
||||||
|
std::vector<SaveStateInfo> GetAvailableSaveStates(const char* game_code) const;
|
||||||
|
|
||||||
|
/// Returns save state info if present. If game_code is null or empty, assumes global state.
|
||||||
|
std::optional<SaveStateInfo> GetSaveStateInfo(const char* game_code, s32 slot);
|
||||||
|
|
||||||
|
/// Returns save state info if present. If game_code is null or empty, assumes global state.
|
||||||
|
std::optional<ExtendedSaveStateInfo> GetExtendedSaveStateInfo(const char* game_code, s32 slot);
|
||||||
|
|
||||||
|
/// Deletes save states for the specified game code. If resume is set, the resume state is deleted too.
|
||||||
|
void DeleteSaveStates(const char* game_code, bool resume);
|
||||||
|
|
||||||
|
/// Adds OSD messages, duration is in seconds.
|
||||||
|
void AddOSDMessage(std::string message, float duration = 2.0f) override;
|
||||||
|
|
||||||
|
/// Displays a loading screen with the logo, rendered with ImGui. Use when executing possibly-time-consuming tasks
|
||||||
|
/// such as compiling shaders when starting up.
|
||||||
|
void DisplayLoadingScreen(const char* message, int progress_min = -1, int progress_max = -1,
|
||||||
|
int progress_value = -1) override;
|
||||||
|
|
||||||
|
/// Retrieves information about specified game from game list.
|
||||||
|
void GetGameInfo(const char* path, CDImage* image, std::string* code, std::string* title) override;
|
||||||
|
|
||||||
|
/// Returns true if currently dumping audio.
|
||||||
|
bool IsDumpingAudio() const;
|
||||||
|
|
||||||
|
/// Starts dumping audio to a file. If no file name is provided, one will be generated automatically.
|
||||||
|
bool StartDumpingAudio(const char* filename = nullptr);
|
||||||
|
|
||||||
|
/// Stops dumping audio to file if it has been started.
|
||||||
|
void StopDumpingAudio();
|
||||||
|
|
||||||
|
/// Saves a screenshot to the specified file. IF no file name is provided, one will be generated automatically.
|
||||||
|
bool SaveScreenshot(const char* filename = nullptr, bool full_resolution = true, bool apply_aspect_ratio = true);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
enum : u32
|
||||||
|
{
|
||||||
|
SETTINGS_VERSION = 2
|
||||||
|
};
|
||||||
|
|
||||||
|
struct OSDMessage
|
||||||
|
{
|
||||||
|
std::string text;
|
||||||
|
Common::Timer time;
|
||||||
|
float duration;
|
||||||
|
};
|
||||||
|
|
||||||
CommonHostInterface();
|
CommonHostInterface();
|
||||||
~CommonHostInterface();
|
~CommonHostInterface();
|
||||||
|
|
||||||
|
@ -77,14 +178,10 @@ protected:
|
||||||
virtual std::unique_ptr<ControllerInterface> CreateControllerInterface();
|
virtual std::unique_ptr<ControllerInterface> CreateControllerInterface();
|
||||||
|
|
||||||
virtual void OnSystemCreated() override;
|
virtual void OnSystemCreated() override;
|
||||||
virtual void OnSystemPaused(bool paused) override;
|
virtual void OnSystemPaused(bool paused);
|
||||||
virtual void OnSystemDestroyed() override;
|
virtual void OnSystemDestroyed() override;
|
||||||
virtual void OnRunningGameChanged() override;
|
virtual void OnRunningGameChanged() override;
|
||||||
virtual void OnControllerTypeChanged(u32 slot) override;
|
virtual void OnControllerTypeChanged(u32 slot) override;
|
||||||
virtual void DrawImGuiWindows() override;
|
|
||||||
|
|
||||||
virtual void SetDefaultSettings(SettingsInterface& si) override;
|
|
||||||
virtual void ApplySettings(SettingsInterface& si) override;
|
|
||||||
|
|
||||||
virtual std::optional<HostKeyCode> GetHostKeyCode(const std::string_view key_code) const;
|
virtual std::optional<HostKeyCode> GetHostKeyCode(const std::string_view key_code) const;
|
||||||
|
|
||||||
|
@ -118,9 +215,70 @@ protected:
|
||||||
void UpdateControllerRumble();
|
void UpdateControllerRumble();
|
||||||
void StopControllerRumble();
|
void StopControllerRumble();
|
||||||
|
|
||||||
|
/// Returns the path to a save state file. Specifying an index of -1 is the "resume" save state.
|
||||||
|
std::string GetGameSaveStateFileName(const char* game_code, s32 slot) const;
|
||||||
|
|
||||||
|
/// Returns the path to a save state file. Specifying an index of -1 is the "resume" save state.
|
||||||
|
std::string GetGlobalSaveStateFileName(s32 slot) const;
|
||||||
|
|
||||||
|
/// Sets the base path for the user directory. Can be overridden by platform/frontend/command line.
|
||||||
|
virtual void SetUserDirectory();
|
||||||
|
|
||||||
|
/// Performs the initial load of settings. Should call CheckSettings() and LoadSettings(SettingsInterface&).
|
||||||
|
virtual void LoadSettings() = 0;
|
||||||
|
|
||||||
|
/// Updates logging settings.
|
||||||
|
virtual void UpdateLogSettings(LOGLEVEL level, const char* filter, bool log_to_console, bool log_to_debug,
|
||||||
|
bool log_to_window, bool log_to_file);
|
||||||
|
|
||||||
|
/// Returns the path of the settings file.
|
||||||
|
std::string GetSettingsFileName() const;
|
||||||
|
|
||||||
|
/// Returns the most recent resume save state.
|
||||||
|
std::string GetMostRecentResumeSaveStatePath() const;
|
||||||
|
|
||||||
|
/// Ensures the settings is valid and the correct version. If not, resets to defaults.
|
||||||
|
void CheckSettings(SettingsInterface& si);
|
||||||
|
|
||||||
|
/// Restores all settings to defaults.
|
||||||
|
virtual void SetDefaultSettings(SettingsInterface& si);
|
||||||
|
|
||||||
|
/// Loads settings to m_settings and any frontend-specific parameters.
|
||||||
|
virtual void LoadSettings(SettingsInterface& si);
|
||||||
|
|
||||||
|
/// Saves current settings variables to ini.
|
||||||
|
virtual void SaveSettings(SettingsInterface& si);
|
||||||
|
|
||||||
|
/// Checks for settings changes, std::move() the old settings away for comparing beforehand.
|
||||||
|
virtual void CheckForSettingsChanges(const Settings& old_settings);
|
||||||
|
|
||||||
|
/// Increases timer resolution when supported by the host OS.
|
||||||
|
void SetTimerResolutionIncreased(bool enabled);
|
||||||
|
|
||||||
|
void UpdateSpeedLimiterState();
|
||||||
|
|
||||||
|
void RecreateSystem() override;
|
||||||
|
|
||||||
|
virtual void DrawImGuiWindows();
|
||||||
|
|
||||||
|
void DrawFPSWindow();
|
||||||
|
void DrawOSDMessages();
|
||||||
|
void DrawDebugWindows();
|
||||||
|
|
||||||
|
std::unique_ptr<GameList> m_game_list;
|
||||||
|
|
||||||
std::unique_ptr<ControllerInterface> m_controller_interface;
|
std::unique_ptr<ControllerInterface> m_controller_interface;
|
||||||
|
|
||||||
|
std::deque<OSDMessage> m_osd_messages;
|
||||||
|
std::mutex m_osd_messages_lock;
|
||||||
|
|
||||||
|
bool m_paused = false;
|
||||||
|
bool m_speed_limiter_temp_disabled = false;
|
||||||
|
bool m_speed_limiter_enabled = false;
|
||||||
|
bool m_timer_resolution_increased = false;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void InitializeUserDirectory();
|
||||||
void RegisterGeneralHotkeys();
|
void RegisterGeneralHotkeys();
|
||||||
void RegisterGraphicsHotkeys();
|
void RegisterGraphicsHotkeys();
|
||||||
void RegisterSaveStateHotkeys();
|
void RegisterSaveStateHotkeys();
|
||||||
|
|
|
@ -45,9 +45,9 @@ void SaveStateSelectorUI::RefreshList()
|
||||||
const System* system = m_host_interface->GetSystem();
|
const System* system = m_host_interface->GetSystem();
|
||||||
if (system && !system->GetRunningCode().empty())
|
if (system && !system->GetRunningCode().empty())
|
||||||
{
|
{
|
||||||
for (s32 i = 1; i <= HostInterface::GLOBAL_SAVE_STATE_SLOTS; i++)
|
for (s32 i = 1; i <= CommonHostInterface::GLOBAL_SAVE_STATE_SLOTS; i++)
|
||||||
{
|
{
|
||||||
std::optional<HostInterface::ExtendedSaveStateInfo> ssi =
|
std::optional<CommonHostInterface::ExtendedSaveStateInfo> ssi =
|
||||||
m_host_interface->GetExtendedSaveStateInfo(system->GetRunningCode().c_str(), i);
|
m_host_interface->GetExtendedSaveStateInfo(system->GetRunningCode().c_str(), i);
|
||||||
|
|
||||||
ListEntry li;
|
ListEntry li;
|
||||||
|
@ -60,9 +60,10 @@ void SaveStateSelectorUI::RefreshList()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (s32 i = 1; i <= HostInterface::GLOBAL_SAVE_STATE_SLOTS; i++)
|
for (s32 i = 1; i <= CommonHostInterface::GLOBAL_SAVE_STATE_SLOTS; i++)
|
||||||
{
|
{
|
||||||
std::optional<HostInterface::ExtendedSaveStateInfo> ssi = m_host_interface->GetExtendedSaveStateInfo(nullptr, i);
|
std::optional<CommonHostInterface::ExtendedSaveStateInfo> ssi =
|
||||||
|
m_host_interface->GetExtendedSaveStateInfo(nullptr, i);
|
||||||
|
|
||||||
ListEntry li;
|
ListEntry li;
|
||||||
if (ssi)
|
if (ssi)
|
||||||
|
@ -118,7 +119,7 @@ void SaveStateSelectorUI::SelectPreviousSlot()
|
||||||
(m_current_selection == 0) ? (static_cast<u32>(m_slots.size()) - 1u) : (m_current_selection - 1);
|
(m_current_selection == 0) ? (static_cast<u32>(m_slots.size()) - 1u) : (m_current_selection - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SaveStateSelectorUI::InitializeListEntry(ListEntry* li, HostInterface::ExtendedSaveStateInfo* ssi)
|
void SaveStateSelectorUI::InitializeListEntry(ListEntry* li, CommonHostInterface::ExtendedSaveStateInfo* ssi)
|
||||||
{
|
{
|
||||||
li->title = std::move(ssi->title);
|
li->title = std::move(ssi->title);
|
||||||
li->game_code = std::move(ssi->game_code);
|
li->game_code = std::move(ssi->game_code);
|
||||||
|
|
|
@ -48,7 +48,7 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
void InitializePlaceholderListEntry(ListEntry* li, s32 slot, bool global);
|
void InitializePlaceholderListEntry(ListEntry* li, s32 slot, bool global);
|
||||||
void InitializeListEntry(ListEntry* li, HostInterface::ExtendedSaveStateInfo* ssi);
|
void InitializeListEntry(ListEntry* li, CommonHostInterface::ExtendedSaveStateInfo* ssi);
|
||||||
|
|
||||||
CommonHostInterface* m_host_interface;
|
CommonHostInterface* m_host_interface;
|
||||||
std::vector<ListEntry> m_slots;
|
std::vector<ListEntry> m_slots;
|
||||||
|
|
Loading…
Reference in a new issue