Duckstation/src/duckstation/sdl_interface.h

123 lines
3.2 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"
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
2019-09-12 14:18:13 +00:00
class SDLInterface : public HostInterface
2019-09-09 07:01:26 +00:00
{
public:
2019-09-12 14:18:13 +00:00
SDLInterface();
2019-09-09 07:01:26 +00:00
~SDLInterface();
static std::unique_ptr<SDLInterface> 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);
void SetDisplayTexture(GL::Texture* texture, u32 offset_x, u32 offset_y, u32 width, u32 height,
float aspect_ratio) override;
2019-09-09 07:01:26 +00:00
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;
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); }
2019-09-12 14:18:13 +00:00
bool CreateSDLWindow();
bool CreateGLContext();
bool CreateImGuiContext();
bool CreateGLResources();
2019-10-10 16:20:21 +00:00
bool CreateAudioStream();
void UpdateAudioVisualSync();
2019-09-12 14:18:13 +00:00
2019-10-23 11:39:48 +00:00
void OpenGameControllers();
void CloseGameControllers();
bool InitializeSystem(const char* filename = nullptr, const char* exp1_filename = nullptr);
void ConnectDevices();
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();
2019-09-09 07:01:26 +00:00
void DoLoadState(u32 index);
void DoSaveState(u32 index);
2019-10-23 11:39:48 +00:00
void HandleSDLEvent(const SDL_Event* event);
void HandleSDLKeyEvent(const SDL_Event* event);
2019-09-09 07:01:26 +00:00
bool PassEventToImGui(const SDL_Event* event);
void Render();
2019-09-12 14:18:13 +00:00
void RenderDisplay();
void DrawMainMenuBar();
void DrawPoweredOffWindow();
2019-10-20 11:18:11 +00:00
void DrawAboutWindow();
void DrawOSDMessages();
2019-09-09 07:01:26 +00:00
2019-09-12 14:18:13 +00:00
SDL_Window* m_window = nullptr;
SDL_GLContext m_gl_context = nullptr;
int m_window_width = 0;
int m_window_height = 0;
2019-09-09 07:01:26 +00:00
std::unique_ptr<GL::Texture> m_app_icon_texture = nullptr;
2019-09-12 14:18:13 +00:00
GL::Program m_display_program;
GLuint m_display_vao = 0;
GL::Texture* m_display_texture = nullptr;
u32 m_display_texture_offset_x = 0;
u32 m_display_texture_offset_y = 0;
u32 m_display_texture_width = 0;
u32 m_display_texture_height = 0;
float m_display_aspect_ratio = 1.0f;
2019-09-12 14:18:13 +00:00
bool m_display_texture_changed = false;
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-29 15:07:38 +00:00
std::shared_ptr<MemoryCard> m_memory_card;
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
bool m_about_window_open = false;
bool m_speed_limiter_enabled = true;
bool m_speed_limiter_temp_disabled = false;
2019-09-09 07:01:26 +00:00
};