Duckstation/src/core/host_interface.h

148 lines
4.2 KiB
C
Raw Normal View History

2019-09-12 14:18:13 +00:00
#pragma once
2020-01-10 03:31:12 +00:00
#include "common/timer.h"
#include "settings.h"
#include "types.h"
#include <chrono>
#include <deque>
#include <functional>
2019-09-14 10:28:47 +00:00
#include <memory>
#include <mutex>
#include <optional>
#include <string>
#include <vector>
2019-09-12 14:18:13 +00:00
2019-10-10 16:20:21 +00:00
class AudioStream;
class CDImage;
class HostDisplay;
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
{
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; }
/// Returns the game list.
const GameList* GetGameList() const { return m_game_list.get(); }
bool CreateSystem();
bool BootSystem(const char* filename, const char* state_filename);
void ResetSystem();
void DestroySystem();
2019-11-07 15:07:39 +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, ...);
/// 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
/// 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);
/// Returns the base user directory path.
const std::string& GetUserDirectory() const { return m_user_directory; }
/// Returns a path relative to the user directory.
std::string GetUserDirectoryRelativePath(const char* format, ...) const;
protected:
2020-01-07 04:17:41 +00:00
enum : u32
{
AUDIO_SAMPLE_RATE = 44100,
AUDIO_CHANNELS = 2,
AUDIO_BUFFER_SIZE = 2048,
AUDIO_BUFFERS = 2
};
struct OSDMessage
{
std::string text;
2020-01-10 03:31:12 +00:00
Common::Timer time;
float duration;
};
virtual void SwitchGPURenderer();
virtual void OnSystemPerformanceCountersUpdated();
virtual void OnRunningGameChanged();
void SetUserDirectory();
/// Ensures all subdirectories of the user directory are created.
void CreateUserDirectorySubdirectories();
/// Returns the path of the settings file.
std::string GetSettingsFileName() const;
/// Returns the path of the game list cache file.
std::string GetGameListCacheFileName() const;
/// Returns the path of the game database cache file.
std::string GetGameListDatabaseFileName() 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);
/// Returns the path to a save state file. Specifying an index of -1 is the "resume" save state.
std::string GetGlobalSaveStateFileName(s32 slot);
/// Returns the default path to a memory card.
std::string GetSharedMemoryCardPath(u32 slot);
/// Returns the default path to a memory card for a specific game.
std::string GetGameMemoryCardPath(const char* game_code, u32 slot);
/// Restores all settings to defaults.
void SetDefaultSettings();
/// Applies new settings, updating internal state as needed. apply_callback should call m_settings.Load() after
/// locking any required mutexes.
void UpdateSettings(const std::function<void()>& apply_callback);
/// Quick switch between software and hardware rendering.
void ToggleSoftwareRendering();
/// Adjusts the internal (render) resolution of the hardware backends.
void ModifyResolutionScale(s32 increment);
void UpdateSpeedLimiterState();
2019-11-07 15:07:39 +00:00
void DrawFPSWindow();
void DrawOSDMessages();
void DrawDebugWindows();
void ClearImGuiFocus();
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;
std::unique_ptr<GameList> m_game_list;
Settings m_settings;
std::string m_user_directory;
2019-11-07 15:07:39 +00:00
bool m_paused = false;
bool m_speed_limiter_temp_disabled = false;
bool m_speed_limiter_enabled = false;
std::deque<OSDMessage> m_osd_messages;
std::mutex m_osd_messages_lock;
2019-09-12 14:18:13 +00:00
};