Duckstation/src/core/host_interface.h

74 lines
2 KiB
C
Raw Normal View History

2019-09-12 14:18:13 +00:00
#pragma once
#include "YBaseLib/Timer.h"
#include "settings.h"
#include "types.h"
#include <chrono>
2019-09-14 10:28:47 +00:00
#include <memory>
#include <optional>
#include <vector>
2019-09-12 14:18:13 +00:00
2019-10-10 16:20:21 +00:00
class AudioStream;
class HostDisplay;
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
{
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; }
/// 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); }
bool CreateSystem();
bool BootSystem(const char* filename, const char* state_filename);
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
// Adds OSD messages, duration is in seconds.
virtual void AddOSDMessage(const char* message, float duration = 2.0f) = 0;
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);
protected:
using ThrottleClock = std::chrono::steady_clock;
/// Connects controllers. TODO: Clean this up later...
virtual void ConnectControllers();
/// 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
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;
Settings m_settings;
2019-11-07 15:07:39 +00:00
u64 m_last_throttle_time = 0;
s64 m_throttle_period = INT64_C(1000000000) / 60;
Timer m_throttle_timer;
Timer m_speed_lost_time_timestamp;
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;
2019-09-12 14:18:13 +00:00
};