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"
|
2019-11-03 05:22:37 +00:00
|
|
|
#include "common/gl/program.h"
|
|
|
|
#include "common/gl/texture.h"
|
2019-11-03 14:39:48 +00:00
|
|
|
#include "core/host_display.h"
|
2019-12-14 14:17:43 +00:00
|
|
|
#include "core/host_interface.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>
|
2019-09-20 06:47:41 +00:00
|
|
|
#include <memory>
|
2019-10-20 14:38:04 +00:00
|
|
|
#include <mutex>
|
2019-09-09 07:01:26 +00:00
|
|
|
|
|
|
|
class System;
|
2019-10-10 16:20:21 +00:00
|
|
|
class AudioStream;
|
2019-09-09 07:01:26 +00:00
|
|
|
|
2019-12-14 14:17:43 +00:00
|
|
|
class Controller;
|
|
|
|
|
2019-11-16 05:27:57 +00:00
|
|
|
class SDLHostInterface final : public HostInterface
|
2019-09-09 07:01:26 +00:00
|
|
|
{
|
|
|
|
public:
|
2019-11-03 14:39:48 +00:00
|
|
|
SDLHostInterface();
|
|
|
|
~SDLHostInterface();
|
2019-09-09 07:01:26 +00:00
|
|
|
|
2019-11-03 14:39:48 +00:00
|
|
|
static std::unique_ptr<SDLHostInterface> Create(const char* filename = nullptr, const char* exp1_filename = nullptr,
|
2019-12-14 14:17:43 +00:00
|
|
|
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-11-16 05:27:57 +00:00
|
|
|
void ReportError(const char* message) override;
|
2019-09-12 14:18:13 +00:00
|
|
|
void ReportMessage(const char* message) override;
|
2019-09-09 07:01:26 +00:00
|
|
|
|
|
|
|
void Run();
|
|
|
|
|
2019-09-12 14:18:13 +00:00
|
|
|
private:
|
2019-12-14 14:17:43 +00:00
|
|
|
enum class KeyboardControllerAction
|
|
|
|
{
|
|
|
|
Up,
|
|
|
|
Down,
|
|
|
|
Left,
|
|
|
|
Right,
|
|
|
|
Triangle,
|
|
|
|
Cross,
|
|
|
|
Square,
|
|
|
|
Circle,
|
|
|
|
L1,
|
|
|
|
R1,
|
|
|
|
L2,
|
|
|
|
R2,
|
|
|
|
Start,
|
|
|
|
Select,
|
|
|
|
Count
|
|
|
|
};
|
|
|
|
|
|
|
|
using KeyboardControllerActionMap = std::array<s32, static_cast<int>(KeyboardControllerAction::Count)>;
|
|
|
|
|
2019-12-15 13:24:34 +00:00
|
|
|
struct ControllerData
|
|
|
|
{
|
|
|
|
SDL_GameController* controller;
|
|
|
|
SDL_Haptic* haptic;
|
|
|
|
u32 controller_index;
|
|
|
|
float last_rumble_strength;
|
|
|
|
};
|
|
|
|
|
2019-10-20 14:38:04 +00:00
|
|
|
static constexpr u32 NUM_QUICK_SAVE_STATES = 10;
|
2019-10-31 13:02:52 +00:00
|
|
|
static constexpr char RESUME_SAVESTATE_FILENAME[] = "savestate_resume.bin";
|
2019-10-20 14:38:04 +00:00
|
|
|
|
|
|
|
bool HasSystem() const { return static_cast<bool>(m_system); }
|
|
|
|
|
2019-11-03 15:57:08 +00:00
|
|
|
#ifdef WIN32
|
2019-11-16 05:27:57 +00:00
|
|
|
bool UseOpenGLRenderer() const { return m_settings.gpu_renderer == GPURenderer::HardwareOpenGL; }
|
2019-11-03 14:39:48 +00:00
|
|
|
#else
|
|
|
|
bool UseOpenGLRenderer() const { return true; }
|
|
|
|
#endif
|
|
|
|
|
2019-09-12 14:18:13 +00:00
|
|
|
bool CreateSDLWindow();
|
2019-11-17 09:37:10 +00:00
|
|
|
void DestroySDLWindow();
|
2019-11-03 14:39:48 +00:00
|
|
|
bool CreateDisplay();
|
2019-11-17 09:37:10 +00:00
|
|
|
void DestroyDisplay();
|
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-11-07 15:07:39 +00:00
|
|
|
void SaveSettings();
|
|
|
|
|
2019-11-17 09:37:10 +00:00
|
|
|
void QueueSwitchGPURenderer();
|
2019-11-07 13:52:19 +00:00
|
|
|
void SwitchGPURenderer();
|
2019-11-15 04:57:27 +00:00
|
|
|
void UpdateFullscreen();
|
2019-12-14 14:17:43 +00:00
|
|
|
void UpdateControllerMapping();
|
2019-10-20 14:38:04 +00:00
|
|
|
|
2019-09-09 07:01:26 +00:00
|
|
|
// We only pass mouse input through if it's grabbed
|
2019-10-04 12:27:18 +00:00
|
|
|
void DrawImGui();
|
2019-10-20 11:18:11 +00:00
|
|
|
void DoPowerOff();
|
2019-10-20 10:37:21 +00:00
|
|
|
void DoResume();
|
|
|
|
void DoStartDisc();
|
|
|
|
void DoStartBIOS();
|
2019-10-28 07:34:59 +00:00
|
|
|
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();
|
2019-10-27 11:35:13 +00:00
|
|
|
void DoFrameStep();
|
2019-10-27 11:52:10 +00:00
|
|
|
void DoToggleSoftwareRendering();
|
2019-11-15 04:57:27 +00:00
|
|
|
void DoToggleFullscreen();
|
2019-10-27 14:48:43 +00:00
|
|
|
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);
|
2019-10-27 03:44:48 +00:00
|
|
|
|
2019-12-14 14:17:43 +00:00
|
|
|
void UpdateKeyboardControllerMapping();
|
|
|
|
bool HandleSDLKeyEventForController(const SDL_Event* event);
|
|
|
|
|
2019-12-15 13:24:34 +00:00
|
|
|
bool OpenGameController(int index);
|
|
|
|
bool CloseGameController(int index);
|
|
|
|
void CloseGameControllers();
|
2019-12-14 14:17:43 +00:00
|
|
|
void UpdateControllerControllerMapping();
|
|
|
|
void HandleSDLControllerAxisEventForController(const SDL_Event* event);
|
|
|
|
void HandleSDLControllerButtonEventForController(const SDL_Event* event);
|
2019-12-15 13:24:34 +00:00
|
|
|
void UpdateControllerRumble();
|
2019-12-14 14:17:43 +00:00
|
|
|
|
2019-10-04 12:27:18 +00:00
|
|
|
void DrawMainMenuBar();
|
2019-11-07 15:07:39 +00:00
|
|
|
void DrawQuickSettingsMenu();
|
|
|
|
void DrawDebugMenu();
|
2019-10-20 10:37:21 +00:00
|
|
|
void DrawPoweredOffWindow();
|
2019-11-07 13:52:19 +00:00
|
|
|
void DrawSettingsWindow();
|
2019-10-20 11:18:11 +00:00
|
|
|
void DrawAboutWindow();
|
2019-10-26 02:55:56 +00:00
|
|
|
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;
|
2019-11-03 14:39:48 +00:00
|
|
|
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-12-14 14:17:43 +00:00
|
|
|
KeyboardControllerActionMap m_keyboard_button_mapping;
|
|
|
|
|
2019-12-15 13:24:34 +00:00
|
|
|
std::map<int, ControllerData> m_sdl_controllers;
|
2019-12-14 14:31:07 +00:00
|
|
|
std::array<s32, SDL_CONTROLLER_AXIS_MAX> m_controller_axis_mapping;
|
2019-12-14 14:17:43 +00:00
|
|
|
std::array<s32, SDL_CONTROLLER_BUTTON_MAX> m_controller_button_mapping;
|
2019-10-23 11:39:48 +00:00
|
|
|
|
2019-11-17 09:37:10 +00:00
|
|
|
u32 m_switch_gpu_renderer_event_id = 0;
|
|
|
|
|
2019-10-27 11:22:33 +00:00
|
|
|
bool m_quit_request = false;
|
2019-10-27 11:35:13 +00:00
|
|
|
bool m_frame_step_request = false;
|
2019-10-26 15:05:43 +00:00
|
|
|
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
|
|
|
};
|