mirror of
https://git.sr.ht/~thestr4ng3r/chiaki
synced 2025-08-20 21:43:12 -07:00
Refactor IO class as singleton
This commit is contained in:
parent
a1b081bfce
commit
d31fb46ae8
8 changed files with 462 additions and 379 deletions
|
@ -3,15 +3,14 @@
|
|||
#ifndef CHIAKI_IO_H
|
||||
#define CHIAKI_IO_H
|
||||
|
||||
#include <functional>
|
||||
#include <cstdint>
|
||||
#include <SDL2/SDL.h>
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
|
||||
#include <glad.h> // glad library (OpenGL loader)
|
||||
|
||||
#include <chiaki/session.h>
|
||||
|
||||
|
||||
/*
|
||||
https://github.com/devkitPro/switch-glad/blob/master/include/glad/glad.h
|
||||
https://glad.dav1d.de/#profile=core&language=c&specification=gl&api=gl%3D4.3&extensions=GL_EXT_texture_compression_s3tc&extensions=GL_EXT_texture_filter_anisotropic
|
||||
|
@ -37,8 +36,8 @@ extern "C"
|
|||
#include <libswscale/swscale.h>
|
||||
}
|
||||
|
||||
#include <chiaki/log.h>
|
||||
#include <chiaki/controller.h>
|
||||
#include <chiaki/log.h>
|
||||
|
||||
#include "exception.h"
|
||||
|
||||
|
@ -47,8 +46,11 @@ extern "C"
|
|||
|
||||
class IO
|
||||
{
|
||||
protected:
|
||||
IO();
|
||||
static IO * instance;
|
||||
private:
|
||||
ChiakiLog * log;
|
||||
ChiakiLog *log;
|
||||
int video_width;
|
||||
int video_height;
|
||||
bool quit = false;
|
||||
|
@ -57,15 +59,12 @@ class IO
|
|||
// default nintendo switch res
|
||||
int screen_width = 1280;
|
||||
int screen_height = 720;
|
||||
std::function<bool()> chiaki_event_connected_cb = nullptr;
|
||||
std::function<bool(bool)> chiaki_even_login_pin_request_cb = nullptr;
|
||||
std::function<bool(ChiakiQuitEvent *)> chiaki_event_quit_cb = nullptr;
|
||||
AVCodec * codec;
|
||||
AVCodecContext * codec_context;
|
||||
AVFrame * frame;
|
||||
AVCodec *codec;
|
||||
AVCodecContext *codec_context;
|
||||
AVFrame *frame;
|
||||
SDL_AudioDeviceID sdl_audio_device_id = 0;
|
||||
SDL_Event sdl_event;
|
||||
SDL_Joystick * sdl_joystick_ptr[SDL_JOYSTICK_COUNT] = {0};
|
||||
SDL_Joystick *sdl_joystick_ptr[SDL_JOYSTICK_COUNT] = {0};
|
||||
GLuint vao;
|
||||
GLuint vbo;
|
||||
GLuint tex[PLANES_COUNT];
|
||||
|
@ -73,49 +72,38 @@ class IO
|
|||
GLuint vert;
|
||||
GLuint frag;
|
||||
GLuint prog;
|
||||
private:
|
||||
bool InitAVCodec();
|
||||
bool InitOpenGl();
|
||||
bool InitOpenGlTextures();
|
||||
bool InitOpenGlShader();
|
||||
void OpenGlDraw();
|
||||
#ifdef DEBUG_OPENGL
|
||||
void CheckGLError(const char * func, const char * file, int line);
|
||||
void DumpShaderError(GLuint prog, const char * func, const char * file, int line);
|
||||
void DumpProgramError(GLuint prog, const char * func, const char * file, int line);
|
||||
void CheckGLError(const char *func, const char *file, int line);
|
||||
void DumpShaderError(GLuint prog, const char *func, const char *file, int line);
|
||||
void DumpProgramError(GLuint prog, const char *func, const char *file, int line);
|
||||
#endif
|
||||
GLuint CreateAndCompileShader(GLenum type, const char * source);
|
||||
void SetOpenGlYUVPixels(AVFrame * frame);
|
||||
bool ReadGameKeys(SDL_Event * event, ChiakiControllerState * state);
|
||||
bool ReadGameTouchScreen(ChiakiControllerState * state);
|
||||
GLuint CreateAndCompileShader(GLenum type, const char *source);
|
||||
void SetOpenGlYUVPixels(AVFrame *frame);
|
||||
bool ReadGameKeys(SDL_Event *event, ChiakiControllerState *state);
|
||||
bool ReadGameTouchScreen(ChiakiControllerState *state);
|
||||
|
||||
public:
|
||||
IO(ChiakiLog * log);
|
||||
// singleton configuration
|
||||
IO(const IO&) = delete;
|
||||
void operator=(const IO&) = delete;
|
||||
static IO * GetInstance();
|
||||
|
||||
~IO();
|
||||
void SetMesaConfig();
|
||||
bool VideoCB(uint8_t * buf, size_t buf_size);
|
||||
void SetEventConnectedCallback(std::function<bool()> chiaki_event_connected_cb)
|
||||
{
|
||||
this->chiaki_event_connected_cb = chiaki_event_connected_cb;
|
||||
};
|
||||
void SetEventLoginPinRequestCallback(std::function<bool(bool)> chiaki_even_login_pin_request_cb)
|
||||
{
|
||||
this->chiaki_even_login_pin_request_cb = chiaki_even_login_pin_request_cb;
|
||||
};
|
||||
void SetEventQuitCallback(std::function<bool(ChiakiQuitEvent *)> chiaki_event_quit_cb)
|
||||
{
|
||||
this->chiaki_event_quit_cb = chiaki_event_quit_cb;
|
||||
};
|
||||
bool VideoCB(uint8_t *buf, size_t buf_size);
|
||||
void InitAudioCB(unsigned int channels, unsigned int rate);
|
||||
void AudioCB(int16_t * buf, size_t samples_count);
|
||||
void EventCB(ChiakiEvent *event);
|
||||
void AudioCB(int16_t *buf, size_t samples_count);
|
||||
bool InitVideo(int video_width, int video_height, int screen_width, int screen_height);
|
||||
bool FreeVideo();
|
||||
bool InitJoystick();
|
||||
bool FreeJoystick();
|
||||
bool ReadUserKeyboard(char * buffer, size_t buffer_size);
|
||||
bool MainLoop(ChiakiControllerState * state);
|
||||
bool ReadUserKeyboard(char *buffer, size_t buffer_size);
|
||||
bool MainLoop(ChiakiControllerState *state);
|
||||
};
|
||||
|
||||
#endif //CHIAKI_IO_H
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue