mirror of
https://github.com/WinampDesktop/winamp.git
synced 2025-06-17 19:05:46 -04:00
Move most helper logic from base HostInterface to FrontendCommon
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@ -22,6 +22,12 @@ class CommonHostInterface : public HostInterface
|
||||
public:
|
||||
friend ControllerInterface;
|
||||
|
||||
enum : s32
|
||||
{
|
||||
PER_GAME_SAVE_STATE_SLOTS = 10,
|
||||
GLOBAL_SAVE_STATE_SLOTS = 10
|
||||
};
|
||||
|
||||
using HostKeyCode = s32;
|
||||
using HostMouseButton = s32;
|
||||
|
||||
@ -39,6 +45,32 @@ public:
|
||||
|
||||
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.
|
||||
virtual const char* GetFrontendName() const = 0;
|
||||
|
||||
@ -47,6 +79,10 @@ public:
|
||||
|
||||
virtual bool BootSystem(const SystemBootParameters& parameters) 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.
|
||||
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.
|
||||
ALWAYS_INLINE bool InBatchMode() const { return m_batch_mode; }
|
||||
|
||||
void PauseSystem(bool paused);
|
||||
|
||||
/// Parses command line parameters for all frontends.
|
||||
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:
|
||||
enum : u32
|
||||
{
|
||||
SETTINGS_VERSION = 2
|
||||
};
|
||||
|
||||
struct OSDMessage
|
||||
{
|
||||
std::string text;
|
||||
Common::Timer time;
|
||||
float duration;
|
||||
};
|
||||
|
||||
CommonHostInterface();
|
||||
~CommonHostInterface();
|
||||
|
||||
@ -77,14 +178,10 @@ protected:
|
||||
virtual std::unique_ptr<ControllerInterface> CreateControllerInterface();
|
||||
|
||||
virtual void OnSystemCreated() override;
|
||||
virtual void OnSystemPaused(bool paused) override;
|
||||
virtual void OnSystemPaused(bool paused);
|
||||
virtual void OnSystemDestroyed() override;
|
||||
virtual void OnRunningGameChanged() 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;
|
||||
|
||||
@ -118,9 +215,70 @@ protected:
|
||||
void UpdateControllerRumble();
|
||||
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::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:
|
||||
void InitializeUserDirectory();
|
||||
void RegisterGeneralHotkeys();
|
||||
void RegisterGraphicsHotkeys();
|
||||
void RegisterSaveStateHotkeys();
|
||||
|
@ -45,9 +45,9 @@ void SaveStateSelectorUI::RefreshList()
|
||||
const System* system = m_host_interface->GetSystem();
|
||||
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);
|
||||
|
||||
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;
|
||||
if (ssi)
|
||||
@ -118,7 +119,7 @@ void SaveStateSelectorUI::SelectPreviousSlot()
|
||||
(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->game_code = std::move(ssi->game_code);
|
||||
|
@ -48,7 +48,7 @@ private:
|
||||
};
|
||||
|
||||
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;
|
||||
std::vector<ListEntry> m_slots;
|
||||
|
Reference in New Issue
Block a user