FrontendCommon: Move input binding and some other logic from Qt to common

This commit is contained in:
Connor McLaughlin
2020-02-28 17:00:09 +10:00
parent ccbe6f0c42
commit f35970fcac
18 changed files with 639 additions and 440 deletions

View File

@ -53,7 +53,6 @@ HostInterface::HostInterface()
{
SetUserDirectory();
CreateUserDirectorySubdirectories();
SetDefaultSettings();
m_game_list = std::make_unique<GameList>();
m_game_list->SetCacheFilename(GetGameListCacheFileName());
m_game_list->SetDatabaseFilename(GetGameListDatabaseFileName());
@ -135,6 +134,17 @@ void HostInterface::ResetSystem()
AddOSDMessage("System reset.");
}
void HostInterface::PowerOffSystem()
{
if (!m_system)
return;
if (m_settings.save_state_on_exit)
SaveResumeSaveState();
DestroySystem();
}
void HostInterface::DestroySystem()
{
if (!m_system)
@ -493,7 +503,11 @@ bool HostInterface::SaveState(bool global, s32 slot)
}
std::string save_path = global ? GetGlobalSaveStateFileName(slot) : GetGameSaveStateFileName(code.c_str(), slot);
return SaveState(save_path.c_str());
if (!SaveState(save_path.c_str()))
return false;
OnSystemStateSaved(global, slot);
return true;
}
bool HostInterface::ResumeSystemFromState(const char* filename, bool boot_on_failure)
@ -584,6 +598,8 @@ void HostInterface::OnSystemDestroyed()
void HostInterface::OnSystemPerformanceCountersUpdated() {}
void HostInterface::OnSystemStateSaved(bool global, s32 slot) {}
void HostInterface::OnRunningGameChanged() {}
void HostInterface::OnControllerTypeChanged(u32 slot) {}
@ -725,7 +741,7 @@ std::vector<HostInterface::SaveStateInfo> HostInterface::GetAvailableSaveStates(
std::vector<SaveStateInfo> si;
std::string path;
auto add_path = [&si](const std::string& path, s32 slot, bool global) {
auto add_path = [&si](std::string path, s32 slot, bool global) {
FILESYSTEM_STAT_DATA sd;
if (!FileSystem::StatFile(path.c_str(), &sd))
return;
@ -766,42 +782,67 @@ std::string HostInterface::GetMostRecentResumeSaveStatePath() const
return std::move(most_recent->FileName);
}
void HostInterface::SetDefaultSettings()
void HostInterface::CheckSettings(SettingsInterface& si)
{
m_settings.region = ConsoleRegion::Auto;
m_settings.cpu_execution_mode = CPUExecutionMode::Interpreter;
const int settings_version = si.GetIntValue("Main", "SettingsVersion", -1);
if (settings_version == SETTINGS_VERSION)
return;
m_settings.emulation_speed = 1.0f;
m_settings.speed_limiter_enabled = true;
m_settings.increase_timer_resolution = true;
m_settings.start_paused = false;
m_settings.save_state_on_exit = true;
m_settings.confim_power_off = true;
// TODO: we probably should delete all the sections in the ini...
Log_WarningPrintf("Settings version %d does not match expected version %d, resetting", settings_version,
SETTINGS_VERSION);
si.Clear();
si.SetIntValue("Main", "SettingsVersion", SETTINGS_VERSION);
SetDefaultSettings(si);
}
m_settings.gpu_renderer = Settings::DEFAULT_GPU_RENDERER;
m_settings.gpu_resolution_scale = 1;
m_settings.gpu_true_color = true;
m_settings.gpu_texture_filtering = false;
m_settings.gpu_force_progressive_scan = true;
m_settings.gpu_use_debug_device = false;
m_settings.display_linear_filtering = true;
m_settings.display_fullscreen = false;
m_settings.video_sync_enabled = true;
void HostInterface::SetDefaultSettings(SettingsInterface& si)
{
si.SetStringValue("Console", "Region", Settings::GetConsoleRegionName(ConsoleRegion::Auto));
m_settings.cdrom_read_thread = true;
si.SetFloatValue("Main", "EmulationSpeed", 1.0f);
si.SetBoolValue("Main", "SpeedLimiterEnabled", true);
si.SetBoolValue("Main", "IncreaseTimerResolution", true);
si.SetBoolValue("Main", "StartPaused", false);
si.SetBoolValue("Main", "SaveStateOnExit", true);
si.SetBoolValue("Main", "ConfirmPowerOff", true);
m_settings.audio_backend = AudioBackend::Cubeb;
m_settings.audio_sync_enabled = true;
si.SetStringValue("CPU", "ExecutionMode", Settings::GetCPUExecutionModeName(CPUExecutionMode::Interpreter));
m_settings.bios_path = "bios/scph1001.bin";
m_settings.bios_patch_tty_enable = false;
m_settings.bios_patch_fast_boot = false;
si.SetStringValue("GPU", "Renderer", Settings::GetRendererName(Settings::DEFAULT_GPU_RENDERER));
si.SetIntValue("GPU", "ResolutionScale", 1);
si.SetBoolValue("GPU", "TrueColor", true);
si.SetBoolValue("GPU", "TextureFiltering", false);
si.SetBoolValue("GPU", "ForceProgressiveScan", true);
si.SetBoolValue("GPU", "UseDebugDevice", false);
m_settings.controller_types[0] = ControllerType::DigitalController;
m_settings.controller_types[1] = ControllerType::None;
si.SetBoolValue("Display", "LinearFiltering", true);
si.SetBoolValue("Display", "Fullscreen", false);
si.SetBoolValue("Display", "VSync", true);
m_settings.memory_card_paths[0] = "memcards/shared_card_1.mcd";
m_settings.memory_card_paths[1].clear();
si.SetBoolValue("CDROM", "ReadThread", true);
si.SetStringValue("Audio", "Backend", Settings::GetAudioBackendName(AudioBackend::Cubeb));
si.SetBoolValue("Audio", "Sync", true);
si.SetStringValue("BIOS", "Path", "bios/scph1001.bin");
si.SetBoolValue("BIOS", "PatchTTYEnable", false);
si.SetBoolValue("BIOS", "PatchFastBoot", false);
si.SetStringValue("Controller1", "Type", Settings::GetControllerTypeName(ControllerType::DigitalController));
si.SetStringValue("Controller2", "Type", Settings::GetControllerTypeName(ControllerType::None));
si.SetStringValue("MemoryCards", "Card1Path", "memcards/shared_card_1.mcd");
si.SetStringValue("MemoryCards", "Card2Path", "");
si.SetBoolValue("Debug", "ShowVRAM", false);
si.SetBoolValue("Debug", "DumpCPUToVRAMCopies", false);
si.SetBoolValue("Debug", "DumpVRAMToCPUCopies", false);
si.SetBoolValue("Debug", "ShowGPUState", false);
si.SetBoolValue("Debug", "ShowCDROMState", false);
si.SetBoolValue("Debug", "ShowSPUState", false);
si.SetBoolValue("Debug", "ShowTimersState", false);
si.SetBoolValue("Debug", "ShowMDECState", false);
}
void HostInterface::UpdateSettings(const std::function<void()>& apply_callback)

View File

@ -46,15 +46,17 @@ public:
bool BootSystemFromBIOS();
void PauseSystem(bool paused);
void ResetSystem();
void PowerOffSystem();
void DestroySystem();
/// Loads state from the specified 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);
bool LoadState(const char* filename);
/// Saves the current emulation state to a file. Specifying a slot of -1 saves the "resume" save state.
bool SaveState(bool global, s32 slot);
bool SaveState(const char* filename);
/// 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);
@ -91,12 +93,13 @@ public:
protected:
enum : u32
{
SETTINGS_VERSION = 2,
AUDIO_SAMPLE_RATE = 44100,
AUDIO_CHANNELS = 2,
AUDIO_BUFFER_SIZE = 2048,
AUDIO_BUFFERS = 2,
PER_GAME_SAVE_STATE_SLOTS = 10,
GLOBAL_SAVE_STATE_SLOTS = 10
GLOBAL_SAVE_STATE_SLOTS = 10,
};
struct OSDMessage
@ -122,6 +125,7 @@ protected:
virtual void OnSystemPaused(bool paused);
virtual void OnSystemDestroyed();
virtual void OnSystemPerformanceCountersUpdated();
virtual void OnSystemStateSaved(bool global, s32 slot);
virtual void OnRunningGameChanged();
virtual void OnControllerTypeChanged(u32 slot);
@ -160,8 +164,11 @@ protected:
/// Loads the BIOS image for the specified 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.
void SetDefaultSettings();
virtual void SetDefaultSettings(SettingsInterface& si);
/// Applies new settings, updating internal state as needed. apply_callback should call m_settings.Load() after
/// locking any required mutexes.
@ -202,4 +209,5 @@ protected:
private:
void CreateAudioStream();
bool SaveState(const char* filename);
};

View File

@ -9,12 +9,12 @@ void Settings::Load(SettingsInterface& si)
region =
ParseConsoleRegionName(si.GetStringValue("Console", "Region", "NTSC-U").c_str()).value_or(ConsoleRegion::NTSC_U);
emulation_speed = si.GetFloatValue("General", "EmulationSpeed", 1.0f);
speed_limiter_enabled = si.GetBoolValue("General", "SpeedLimiterEnabled", true);
increase_timer_resolution = si.GetBoolValue("General", "IncreaseTimerResolution", true);
start_paused = si.GetBoolValue("General", "StartPaused", false);
save_state_on_exit = si.GetBoolValue("General", "SaveStateOnExit", true);
confim_power_off = si.GetBoolValue("General", "ConfirmPowerOff", true);
emulation_speed = si.GetFloatValue("Main", "EmulationSpeed", 1.0f);
speed_limiter_enabled = si.GetBoolValue("Main", "SpeedLimiterEnabled", true);
increase_timer_resolution = si.GetBoolValue("Main", "IncreaseTimerResolution", true);
start_paused = si.GetBoolValue("Mainal", "StartPaused", false);
save_state_on_exit = si.GetBoolValue("Main", "SaveStateOnExit", true);
confim_power_off = si.GetBoolValue("Main", "ConfirmPowerOff", true);
cpu_execution_mode = ParseCPUExecutionMode(si.GetStringValue("CPU", "ExecutionMode", "Interpreter").c_str())
.value_or(CPUExecutionMode::Interpreter);
@ -63,12 +63,12 @@ void Settings::Save(SettingsInterface& si) const
{
si.SetStringValue("Console", "Region", GetConsoleRegionName(region));
si.SetFloatValue("General", "EmulationSpeed", emulation_speed);
si.SetBoolValue("General", "SpeedLimiterEnabled", speed_limiter_enabled);
si.SetBoolValue("General", "IncreaseTimerResolution", increase_timer_resolution);
si.SetBoolValue("General", "StartPaused", start_paused);
si.SetBoolValue("General", "SaveStateOnExit", save_state_on_exit);
si.SetBoolValue("General", "ConfirmPowerOff", confim_power_off);
si.SetFloatValue("Main", "EmulationSpeed", emulation_speed);
si.SetBoolValue("Main", "SpeedLimiterEnabled", speed_limiter_enabled);
si.SetBoolValue("Main", "IncreaseTimerResolution", increase_timer_resolution);
si.SetBoolValue("Main", "StartPaused", start_paused);
si.SetBoolValue("Main", "SaveStateOnExit", save_state_on_exit);
si.SetBoolValue("Main", "ConfirmPowerOff", confim_power_off);
si.SetStringValue("CPU", "ExecutionMode", GetCPUExecutionModeName(cpu_execution_mode));

View File

@ -9,6 +9,8 @@
class SettingsInterface
{
public:
virtual void Clear() = 0;
virtual int GetIntValue(const char* section, const char* key, int default_value = 0) = 0;
virtual float GetFloatValue(const char* section, const char* key, float default_value = 0.0f) = 0;
virtual bool GetBoolValue(const char* section, const char* key, bool default_value = false) = 0;