Duckstation/src/duckstation/sdl_host_interface.h

128 lines
3.3 KiB
C
Raw Normal View History

2019-09-09 07:01:26 +00:00
#pragma once
2019-09-12 14:18:13 +00:00
#include "YBaseLib/String.h"
#include "YBaseLib/Timer.h"
#include "common/gl/program.h"
#include "common/gl/texture.h"
2019-10-04 03:54:09 +00:00
#include "core/host_interface.h"
#include "core/host_display.h"
2019-09-12 14:18:13 +00:00
#include <SDL.h>
2019-09-09 07:01:26 +00:00
#include <array>
#include <deque>
2019-10-23 11:39:48 +00:00
#include <map>
#include <memory>
#include <mutex>
2019-09-09 07:01:26 +00:00
class System;
class DigitalController;
2019-09-29 15:07:38 +00:00
class MemoryCard;
2019-10-10 16:20:21 +00:00
class AudioStream;
2019-09-09 07:01:26 +00:00
class SDLHostInterface : public HostInterface
2019-09-09 07:01:26 +00:00
{
public:
SDLHostInterface();
~SDLHostInterface();
2019-09-09 07:01:26 +00:00
static std::unique_ptr<SDLHostInterface> Create(const char* filename = nullptr, const char* exp1_filename = nullptr,
const char* save_state_filename = nullptr);
2019-09-09 07:01:26 +00:00
2019-09-14 10:28:47 +00:00
static TinyString GetSaveStateFilename(u32 index);
2019-09-12 14:18:13 +00:00
void ReportMessage(const char* message) override;
2019-09-09 07:01:26 +00:00
2019-09-12 14:18:13 +00:00
// Adds OSD messages, duration is in seconds.
void AddOSDMessage(const char* message, float duration = 2.0f) override;
2019-09-09 07:01:26 +00:00
void Run();
2019-09-12 14:18:13 +00:00
private:
static constexpr u32 NUM_QUICK_SAVE_STATES = 10;
static constexpr char RESUME_SAVESTATE_FILENAME[] = "savestate_resume.bin";
2019-09-09 07:01:26 +00:00
struct OSDMessage
{
String text;
Timer time;
float duration;
};
bool HasSystem() const { return static_cast<bool>(m_system); }
#ifdef WIN32
bool UseOpenGLRenderer() const { return m_settings.gpu_renderer == Settings::GPURenderer::HardwareOpenGL; }
#else
bool UseOpenGLRenderer() const { return true; }
#endif
2019-09-12 14:18:13 +00:00
bool CreateSDLWindow();
bool CreateDisplay();
2019-11-07 15:07:39 +00:00
void CreateImGuiContext();
2019-10-10 16:20:21 +00:00
bool CreateAudioStream();
2019-09-12 14:18:13 +00:00
2019-10-23 11:39:48 +00:00
void OpenGameControllers();
void CloseGameControllers();
2019-11-07 15:07:39 +00:00
void SaveSettings();
bool InitializeSystem(const char* filename = nullptr, const char* exp1_filename = nullptr);
void ConnectDevices();
void ResetPerformanceCounters();
2019-11-07 13:52:19 +00:00
void SwitchGPURenderer();
2019-09-09 07:01:26 +00:00
// We only pass mouse input through if it's grabbed
bool IsWindowFullscreen() const;
void DrawImGui();
void DoReset();
2019-10-20 11:18:11 +00:00
void DoPowerOff();
void DoResume();
void DoStartDisc();
void DoStartBIOS();
void DoChangeDisc();
2019-09-09 07:01:26 +00:00
void DoLoadState(u32 index);
void DoSaveState(u32 index);
2019-10-27 11:22:33 +00:00
void DoTogglePause();
void DoFrameStep();
void DoToggleSoftwareRendering();
void DoModifyInternalResolution(s32 increment);
2019-09-09 07:01:26 +00:00
2019-10-23 11:39:48 +00:00
void HandleSDLEvent(const SDL_Event* event);
void HandleSDLKeyEvent(const SDL_Event* event);
void ClearImGuiFocus();
void DrawMainMenuBar();
2019-11-07 15:07:39 +00:00
void DrawQuickSettingsMenu();
void DrawDebugMenu();
void DrawPoweredOffWindow();
2019-11-07 13:52:19 +00:00
void DrawSettingsWindow();
2019-10-20 11:18:11 +00:00
void DrawAboutWindow();
void DrawOSDMessages();
void DrawDebugWindows();
2019-11-07 13:52:19 +00:00
bool DrawFileChooser(const char* label, std::string* path, const char* filter = nullptr);
2019-09-09 07:01:26 +00:00
2019-09-12 14:18:13 +00:00
SDL_Window* m_window = nullptr;
std::unique_ptr<HostDisplayTexture> m_app_icon_texture;
2019-09-09 07:01:26 +00:00
2019-11-07 15:07:39 +00:00
std::string m_settings_filename;
2019-09-09 07:01:26 +00:00
std::deque<OSDMessage> m_osd_messages;
std::mutex m_osd_messages_lock;
2019-10-23 11:39:48 +00:00
std::map<int, SDL_GameController*> m_sdl_controllers;
std::shared_ptr<DigitalController> m_controller;
2019-09-26 11:44:02 +00:00
float m_vps = 0.0f;
2019-09-26 11:44:02 +00:00
float m_fps = 0.0f;
float m_speed = 0.0f;
u32 m_last_frame_number = 0;
u32 m_last_internal_frame_number = 0;
2019-10-04 10:48:29 +00:00
u32 m_last_global_tick_counter = 0;
2019-09-26 11:44:02 +00:00
Timer m_fps_timer;
2019-10-20 11:18:11 +00:00
2019-10-27 11:22:33 +00:00
bool m_quit_request = false;
bool m_frame_step_request = false;
bool m_focus_main_menu_bar = false;
2019-11-07 13:52:19 +00:00
bool m_settings_window_open = false;
2019-10-20 11:18:11 +00:00
bool m_about_window_open = false;
2019-09-09 07:01:26 +00:00
};