Refactor IO class as singleton

This commit is contained in:
h0neybadger 2020-12-27 15:57:19 +01:00 committed by Florian Märkl
commit d31fb46ae8
No known key found for this signature in database
GPG key ID: 125BC8A5A6A1E857
8 changed files with 462 additions and 379 deletions

View file

@ -11,13 +11,13 @@
#include <borealis.hpp>
#include <thread>
#include <map>
#include <thread>
#include "host.h"
#include "settings.h"
#include "discoverymanager.h"
#include "host.h"
#include "io.h"
#include "settings.h"
class HostInterface : public brls::List
{
@ -26,19 +26,19 @@ class HostInterface : public brls::List
Host *host;
Settings *settings;
bool connected = false;
public:
HostInterface(IO * io, Host * host, Settings * settings);
HostInterface(Host *host);
~HostInterface();
static void Register(IO * io, Host * host,
Settings * settings, std::function<void()> success_cb = nullptr);
static void Register(Host *host, std::function<void()> success_cb = nullptr);
void Register();
void Wakeup(brls::View *view);
void Connect(brls::View *view);
void ConnectSession();
void Disconnect();
bool Stream();
bool CloseStream(ChiakiQuitEvent * quit);
void Stream();
void CloseStream(ChiakiQuitEvent *quit);
};
class MainApplication
@ -57,9 +57,9 @@ class MainApplication
bool BuildConfigurationMenu(brls::List *, Host *host = nullptr);
void BuildAddHostConfigurationMenu(brls::List *);
public:
MainApplication(DiscoveryManager * discoverymanager, IO * io);
public:
MainApplication(DiscoveryManager *discoverymanager);
~MainApplication();
bool Load();
};
@ -80,11 +80,10 @@ class PSRemotePlay : public brls::View
// int fps = 0;
public:
PSRemotePlay(IO * io, Host * host);
PSRemotePlay(Host *host);
~PSRemotePlay();
void draw(NVGcontext *vg, int x, int y, unsigned width, unsigned height, brls::Style *style, brls::FrameContext *ctx) override;
};
#endif // CHIAKI_GUI_H

View file

@ -22,8 +22,8 @@ static void Discovery(ChiakiDiscoveryHost *, void *);
static void InitAudioCB(unsigned int channels, unsigned int rate, void *user);
static bool VideoCB(uint8_t *buf, size_t buf_size, void *user);
static void AudioCB(int16_t *buf, size_t samples_count, void *user);
static void RegistEventCB(ChiakiRegistEvent * event, void * user);
static void EventCB(ChiakiEvent *event, void *user);
static void RegistEventCB(ChiakiRegistEvent *event, void *user);
enum RegistError
{
@ -52,6 +52,9 @@ class Host
std::function<void()> chiaki_regist_event_type_finished_canceled = nullptr;
std::function<void()> chiaki_regist_event_type_finished_failed = nullptr;
std::function<void()> chiaki_regist_event_type_finished_success = nullptr;
std::function<void()> chiaki_event_connected_cb = nullptr;
std::function<void(bool)> chiaki_even_login_pin_request_cb = nullptr;
std::function<void(ChiakiQuitEvent *)> chiaki_event_quit_cb = nullptr;
// internal state
bool discovered = false;
@ -95,6 +98,7 @@ class Host
void StartSession();
void SendFeedbackState(ChiakiControllerState *);
void RegistCB(ChiakiRegistEvent *);
void ConnectionEventCB(ChiakiEvent *);
bool GetVideoResolution(int *ret_width, int *ret_height);
std::string GetHostName();
std::string GetHostAddr();
@ -104,6 +108,9 @@ class Host
void SetRegistEventTypeFinishedCanceled(std::function<void()> chiaki_regist_event_type_finished_canceled);
void SetRegistEventTypeFinishedFailed(std::function<void()> chiaki_regist_event_type_finished_failed);
void SetRegistEventTypeFinishedSuccess(std::function<void()> chiaki_regist_event_type_finished_success);
void SetEventConnectedCallback(std::function<void()> chiaki_event_connected_cb);
void SetEventLoginPinRequestCallback(std::function<void(bool)> chiaki_even_login_pin_request_cb);
void SetEventQuitCallback(std::function<void(ChiakiQuitEvent *)> chiaki_event_quit_cb);
bool IsRegistered();
bool IsDiscovered();
bool IsReady();

View file

@ -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,6 +46,9 @@ extern "C"
class IO
{
protected:
IO();
static IO * instance;
private:
ChiakiLog *log;
int video_width;
@ -57,9 +59,6 @@ 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;
@ -73,7 +72,6 @@ class IO
GLuint vert;
GLuint frag;
GLuint prog;
private:
bool InitAVCodec();
bool InitOpenGl();
bool InitOpenGlTextures();
@ -88,26 +86,18 @@ class IO
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;
};
void InitAudioCB(unsigned int channels, unsigned int rate);
void AudioCB(int16_t *buf, size_t samples_count);
void EventCB(ChiakiEvent *event);
bool InitVideo(int video_width, int video_height, int screen_width, int screen_height);
bool FreeVideo();
bool InitJoystick();
@ -117,5 +107,3 @@ class IO
};
#endif //CHIAKI_IO_H

View file

@ -1,7 +1,7 @@
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL
#include <chiaki/log.h>
#include "gui.h"
#include <chiaki/log.h>
#define SCREEN_W 1280
#define SCREEN_H 720
@ -11,8 +11,7 @@ using namespace brls::i18n::literals; // for _i18n
#define DIALOG(dialog, r) \
brls::Dialog *d_##dialog = new brls::Dialog(r); \
brls::GenericEvent::Callback cb_##dialog = [d_##dialog](brls::View* view) \
{ \
brls::GenericEvent::Callback cb_##dialog = [d_##dialog](brls::View *view) { \
d_##dialog->close(); \
}; \
d_##dialog->addButton("Ok", cb_##dialog); \
@ -20,10 +19,12 @@ using namespace brls::i18n::literals; // for _i18n
d_##dialog->open(); \
brls::Logger::info("Dialog: {0}", r);
HostInterface::HostInterface(IO * io, Host * host, Settings * settings)
: io(io), host(host), settings(settings)
HostInterface::HostInterface(Host *host)
: host(host)
{
this->settings = Settings::GetInstance();
this->io = IO::GetInstance();
brls::ListItem *connect = new brls::ListItem("Connect");
connect->getClickEvent()->subscribe(std::bind(&HostInterface::Connect, this, std::placeholders::_1));
this->addView(connect);
@ -37,6 +38,10 @@ HostInterface::HostInterface(IO * io, Host * host, Settings * settings)
"Host configuration", true);
this->addView(info);
// push opengl chiaki stream
// when the host is connected
this->host->SetEventConnectedCallback(std::bind(&HostInterface::Stream, this));
this->host->SetEventQuitCallback(std::bind(&HostInterface::CloseStream, this, std::placeholders::_1));
}
HostInterface::~HostInterface()
@ -44,8 +49,11 @@ HostInterface::~HostInterface()
Disconnect();
}
void HostInterface::Register(IO * io, Host * host, Settings * settings, std::function<void()> success_cb)
void HostInterface::Register(Host *host, std::function<void()> success_cb)
{
Settings *settings = Settings::GetInstance();
IO *io = IO::GetInstance();
// user must provide psn id for registration
std::string account_id = settings->GetPSNAccountID(host);
std::string online_id = settings->GetPSNOnlineID(host);
@ -65,8 +73,7 @@ void HostInterface::Register(IO * io, Host * host, Settings * settings, std::fun
}
// add HostConnected function to regist_event_type_finished_success
auto event_type_finished_success_cb = [settings, success_cb]()
{
auto event_type_finished_success_cb = [settings, success_cb]() {
// save RP keys
settings->WriteFile();
if(success_cb != nullptr)
@ -82,8 +89,7 @@ void HostInterface::Register(IO * io, Host * host, Settings * settings, std::fun
};
host->SetRegistEventTypeFinishedSuccess(event_type_finished_success_cb);
auto event_type_finished_failed_cb = []()
{
auto event_type_finished_failed_cb = []() {
// unlock user inputs
brls::Application::unblockInputs();
brls::Application::notify("Registration failed");
@ -92,8 +98,7 @@ void HostInterface::Register(IO * io, Host * host, Settings * settings, std::fun
// the host is not registered yet
brls::Dialog *peprpc = new brls::Dialog("Please enter your PlayStation registration PIN code");
brls::GenericEvent::Callback cb_peprpc = [host, io, peprpc](brls::View* view)
{
brls::GenericEvent::Callback cb_peprpc = [host, io, peprpc](brls::View *view) {
bool pin_provided = false;
char pin_input[9] = {0};
std::string error_message;
@ -133,8 +138,7 @@ void HostInterface::Register(IO * io, Host * host, Settings * settings, std::fun
void HostInterface::Register()
{
// use Connect just after the registration to save user inputs
HostInterface::Register(this->io, this->host,
this->settings, std::bind(&HostInterface::ConnectSession, this));
HostInterface::Register(this->host, std::bind(&HostInterface::ConnectSession, this));
}
void HostInterface::Wakeup(brls::View *view)
@ -194,11 +198,6 @@ void HostInterface::ConnectSession()
// user inputs are restored with the CloseStream
brls::Application::blockInputs();
// push opengl chiaki stream
// when the host is connected
this->io->SetEventConnectedCallback(std::bind(&HostInterface::Stream, this));
this->io->SetEventQuitCallback(std::bind(&HostInterface::CloseStream, this, std::placeholders::_1));
// connect host sesssion
this->host->InitSession(this->io);
this->host->StartSession();
@ -212,10 +211,11 @@ void HostInterface::Disconnect()
this->host->StopSession();
this->connected = false;
}
this->host->FiniSession();
}
bool HostInterface::Stream()
void HostInterface::Stream()
{
this->connected = true;
// https://github.com/natinusala/borealis/issues/59
@ -226,11 +226,10 @@ bool HostInterface::Stream()
// brls::Application::setDisplayFramerate(true);
// push raw opengl stream over borealis
brls::Application::pushView(new PSRemotePlay(this->io, this->host));
return true;
brls::Application::pushView(new PSRemotePlay(this->host));
}
bool HostInterface::CloseStream(ChiakiQuitEvent * quit)
void HostInterface::CloseStream(ChiakiQuitEvent *quit)
{
// session QUIT call back
brls::Application::unblockInputs();
@ -244,14 +243,14 @@ bool HostInterface::CloseStream(ChiakiQuitEvent * quit)
*/
brls::Application::notify(chiaki_quit_reason_string(quit->reason));
Disconnect();
return false;
}
MainApplication::MainApplication(DiscoveryManager * discoverymanager, IO * io)
: discoverymanager(discoverymanager), io(io)
MainApplication::MainApplication(DiscoveryManager *discoverymanager)
: discoverymanager(discoverymanager)
{
this->settings = Settings::GetInstance();
this->log = this->settings->GetLogger();
this->io = IO::GetInstance();
}
MainApplication::~MainApplication()
@ -312,10 +311,9 @@ bool MainApplication::Load()
for(auto it = hosts->begin(); it != hosts->end(); it++)
{
// add host to the gui only if the host is registered or discovered
if(this->host_menuitems.find(&it->second) == this->host_menuitems.end()
&& (it->second.HasRPkey() == true || it->second.IsDiscovered() == true))
if(this->host_menuitems.find(&it->second) == this->host_menuitems.end() && (it->second.HasRPkey() == true || it->second.IsDiscovered() == true))
{
HostInterface * new_host = new HostInterface(this->io, &it->second, this->settings);
HostInterface *new_host = new HostInterface(&it->second);
this->host_menuitems[&it->second] = new_host;
// create host if udefined
BuildConfigurationMenu(new_host, &it->second);
@ -331,8 +329,7 @@ bool MainApplication::BuildConfigurationMenu(brls::List * ls, Host * host)
std::string psn_account_id_string = this->settings->GetPSNAccountID(host);
brls::ListItem *psn_account_id = new brls::ListItem("PSN Account ID", "PS5 or PS4 v7.0 and greater (base64 account_id)");
psn_account_id->setValue(psn_account_id_string.c_str());
auto psn_account_id_cb = [this, host, psn_account_id](brls::View * view)
{
auto psn_account_id_cb = [this, host, psn_account_id](brls::View *view) {
char account_id[CHIAKI_PSN_ACCOUNT_ID_SIZE * 2] = {0};
bool input = this->io->ReadUserKeyboard(account_id, sizeof(account_id));
if(input)
@ -351,8 +348,7 @@ bool MainApplication::BuildConfigurationMenu(brls::List * ls, Host * host)
std::string psn_online_id_string = this->settings->GetPSNOnlineID(host);
brls::ListItem *psn_online_id = new brls::ListItem("PSN Online ID");
psn_online_id->setValue(psn_online_id_string.c_str());
auto psn_online_id_cb = [this, host, psn_online_id](brls::View * view)
{
auto psn_online_id_cb = [this, host, psn_online_id](brls::View *view) {
char online_id[256] = {0};
bool input = this->io->ReadUserKeyboard(online_id, sizeof(online_id));
if(input)
@ -386,8 +382,7 @@ bool MainApplication::BuildConfigurationMenu(brls::List * ls, Host * host)
brls::SelectListItem *resolution = new brls::SelectListItem(
"Resolution", {"720p", "540p", "360p"}, value);
auto resolution_cb = [this, host](int result)
{
auto resolution_cb = [this, host](int result) {
ChiakiVideoResolutionPreset value = CHIAKI_VIDEO_RESOLUTION_PRESET_720p;
switch(result)
{
@ -421,8 +416,7 @@ bool MainApplication::BuildConfigurationMenu(brls::List * ls, Host * host)
brls::SelectListItem *fps = new brls::SelectListItem(
"FPS", {"60", "30"}, value);
auto fps_cb = [this, host](int result)
{
auto fps_cb = [this, host](int result) {
ChiakiVideoFPSPreset value = CHIAKI_VIDEO_FPS_PRESET_60;
switch(result)
{
@ -471,7 +465,6 @@ bool MainApplication::BuildConfigurationMenu(brls::List * ls, Host * host)
brls::ListItem *host_rp_key_type = new brls::ListItem("RP Key type");
host_rp_key_type->setValue(host_rp_key_type_string.c_str());
ls->addView(host_rp_key_type);
}
return true;
@ -484,8 +477,7 @@ void MainApplication::BuildAddHostConfigurationMenu(brls::List * add_host)
// "Add Host configuration", true);
brls::ListItem *display_name = new brls::ListItem("Display name");
auto display_name_cb = [this, display_name](brls::View * view)
{
auto display_name_cb = [this, display_name](brls::View *view) {
char name[16] = {0};
bool input = this->io->ReadUserKeyboard(name, sizeof(name));
if(input)
@ -500,8 +492,7 @@ void MainApplication::BuildAddHostConfigurationMenu(brls::List * add_host)
add_host->addView(display_name);
brls::ListItem *address = new brls::ListItem("Remote IP/name");
auto address_cb = [this, address](brls::View * view)
{
auto address_cb = [this, address](brls::View *view) {
char addr[256] = {0};
bool input = this->io->ReadUserKeyboard(addr, sizeof(addr));
if(input)
@ -515,15 +506,13 @@ void MainApplication::BuildAddHostConfigurationMenu(brls::List * add_host)
address->getClickEvent()->subscribe(address_cb);
add_host->addView(address);
// TODO
// brls::ListItem* port = new brls::ListItem("Remote session port", "tcp/udp 9295");
// brls::ListItem* port = new brls::ListItem("Remote stream port", "udp 9296");
// brls::ListItem* port = new brls::ListItem("Remote Senkusha port", "udp 9297");
brls::SelectListItem *ps_version = new brls::SelectListItem("PlayStation Version",
{"PS5", "PS4 > 8", "7 < PS4 < 8", "PS4 < 7"});
auto ps_version_cb = [this, ps_version](int result)
{
auto ps_version_cb = [this, ps_version](int result) {
switch(result)
{
case 0:
@ -548,8 +537,7 @@ void MainApplication::BuildAddHostConfigurationMenu(brls::List * add_host)
add_host->addView(ps_version);
brls::ListItem *register_host = new brls::ListItem("Register");
auto register_host_cb = [this](brls::View * view)
{
auto register_host_cb = [this](brls::View *view) {
bool err = false;
if(this->remote_display_name.length() <= 0)
{
@ -576,16 +564,18 @@ void MainApplication::BuildAddHostConfigurationMenu(brls::List * add_host)
host->SetHostAddr(this->remote_addr);
host->SetChiakiTarget(this->remote_ps_version);
HostInterface::Register(this->io, host, this->settings);
HostInterface::Register(host);
};
register_host->getClickEvent()->subscribe(register_host_cb);
add_host->addView(register_host);
}
PSRemotePlay::PSRemotePlay(IO * io, Host * host)
: io(io), host(host)
PSRemotePlay::PSRemotePlay(Host *host)
: host(host)
{
this->io = IO::GetInstance();
// store joycon/touchpad keys
for(int x = 0; x < CHIAKI_CONTROLLER_TOUCHES_MAX; x++)
// start touchpad as "untouched"
@ -622,4 +612,3 @@ void PSRemotePlay::draw(NVGcontext* vg, int x, int y, unsigned width, unsigned h
PSRemotePlay::~PSRemotePlay()
{
}

View file

@ -27,8 +27,8 @@ static void AudioCB(int16_t * buf, size_t samples_count, void * user)
static void EventCB(ChiakiEvent *event, void *user)
{
IO * io = (IO *)user;
io->EventCB(event);
Host *host = (Host *)user;
host->ConnectionEventCB(event);
}
static void RegistEventCB(ChiakiRegistEvent *event, void *user)
@ -158,7 +158,7 @@ int Host::InitSession(IO * user)
chiaki_opus_decoder_get_sink(&this->opus_decoder, &audio_sink);
chiaki_session_set_audio_sink(&(this->session), &audio_sink);
chiaki_session_set_video_sample_cb(&(this->session), VideoCB, user);
chiaki_session_set_event_cb(&(this->session), EventCB, user);
chiaki_session_set_event_cb(&(this->session), EventCB, this);
return 0;
}
@ -166,6 +166,7 @@ int Host::FiniSession()
{
if(this->session_init)
{
this->session_init = false;
chiaki_session_join(&this->session);
chiaki_session_fini(&this->session);
chiaki_opus_decoder_fini(&this->opus_decoder);
@ -194,6 +195,28 @@ void Host::SendFeedbackState(ChiakiControllerState * state)
chiaki_session_set_controller_state(&this->session, state);
}
void Host::ConnectionEventCB(ChiakiEvent *event)
{
switch(event->type)
{
case CHIAKI_EVENT_CONNECTED:
CHIAKI_LOGI(this->log, "EventCB CHIAKI_EVENT_CONNECTED");
if(this->chiaki_event_connected_cb != nullptr)
this->chiaki_event_connected_cb();
break;
case CHIAKI_EVENT_LOGIN_PIN_REQUEST:
CHIAKI_LOGI(this->log, "EventCB CHIAKI_EVENT_LOGIN_PIN_REQUEST");
if(this->chiaki_even_login_pin_request_cb != nullptr)
this->chiaki_even_login_pin_request_cb(event->login_pin_request.pin_incorrect);
break;
case CHIAKI_EVENT_QUIT:
CHIAKI_LOGI(this->log, "EventCB CHIAKI_EVENT_QUIT");
if(this->chiaki_event_quit_cb != nullptr)
this->chiaki_event_quit_cb(&event->quit);
break;
}
}
void Host::RegistCB(ChiakiRegistEvent *event)
{
// Chiaki callback fuction
@ -314,6 +337,21 @@ void Host::SetRegistEventTypeFinishedSuccess(std::function<void()> chiaki_regist
this->chiaki_regist_event_type_finished_success = chiaki_regist_event_type_finished_success;
}
void Host::SetEventConnectedCallback(std::function<void()> chiaki_event_connected_cb)
{
this->chiaki_event_connected_cb = chiaki_event_connected_cb;
}
void Host::SetEventLoginPinRequestCallback(std::function<void(bool)> chiaki_even_login_pin_request_cb)
{
this->chiaki_even_login_pin_request_cb = chiaki_even_login_pin_request_cb;
}
void Host::SetEventQuitCallback(std::function<void(ChiakiQuitEvent *)> chiaki_event_quit_cb)
{
this->chiaki_event_quit_cb = chiaki_event_quit_cb;
}
bool Host::IsRegistered()
{
return this->registered;

View file

@ -7,6 +7,7 @@
#endif
#include "io.h"
#include "settings.h"
// https://github.com/torvalds/linux/blob/41ba50b0572e90ed3d24fe4def54567e9050bc47/drivers/hid/hid-sony.c#L2742
#define DS4_TRACKPAD_MAX_X 1920
@ -60,12 +61,23 @@ static const float vert_pos[] = {
0.0f, 0.0f,
0.0f, 1.0f,
1.0f, 0.0f,
1.0f, 1.0f
};
1.0f, 1.0f};
IO::IO(ChiakiLog * log)
: log(log)
IO *IO::instance = nullptr;
IO *IO::GetInstance()
{
if(instance == nullptr)
{
instance = new IO;
}
return instance;
}
IO::IO()
{
Settings *settings = Settings::GetInstance();
this->log = settings->GetLogger();
}
IO::~IO()
@ -99,7 +111,11 @@ void IO::SetMesaConfig()
}
#ifdef DEBUG_OPENGL
#define D(x){ (x); CheckGLError(__func__, __FILE__, __LINE__); }
#define D(x) \
{ \
(x); \
CheckGLError(__func__, __FILE__, __LINE__); \
}
void IO::CheckGLError(const char *func, const char *file, int line)
{
GLenum err;
@ -115,36 +131,50 @@ void IO::CheckGLError(const char* func, const char* file, int line)
}
}
#define DS(x){ DumpShaderError(x, __func__, __FILE__, __LINE__); }
#define DS(x) \
{ \
DumpShaderError(x, __func__, __FILE__, __LINE__); \
}
void IO::DumpShaderError(GLuint shader, const char *func, const char *file, int line)
{
GLchar str[512 + 1];
GLsizei len = 0;
glGetShaderInfoLog(shader, 512, &len, str);
if (len > 512) len = 512;
if(len > 512)
len = 512;
str[len] = '\0';
CHIAKI_LOGE(this->log, "glGetShaderInfoLog: %s function: %s from %s line %d", str, func, file, line);
}
#define DP(x){ DumpProgramError(x, __func__, __FILE__, __LINE__); }
#define DP(x) \
{ \
DumpProgramError(x, __func__, __FILE__, __LINE__); \
}
void IO::DumpProgramError(GLuint prog, const char *func, const char *file, int line)
{
GLchar str[512 + 1];
GLsizei len = 0;
glGetProgramInfoLog(prog, 512, &len, str);
if (len > 512) len = 512;
if(len > 512)
len = 512;
str[len] = '\0';
CHIAKI_LOGE(this->log, "glGetProgramInfoLog: %s function: %s from %s line %d", str, func, file, line);
}
#else
// do nothing
#define D(x){ (x); }
#define DS(x){ }
#define DP(x){ }
#define D(x) \
{ \
(x); \
}
#define DS(x) \
{ \
}
#define DP(x) \
{ \
}
#endif
bool IO::VideoCB(uint8_t *buf, size_t buf_size)
{
// callback function to decode video buffer
@ -204,7 +234,6 @@ send_packet:
return true;
}
void IO::InitAudioCB(unsigned int channels, unsigned int rate)
{
SDL_AudioSpec want, have, test;
@ -289,33 +318,6 @@ bool IO::InitVideo(int video_width, int video_height, int screen_width, int scre
return true;
}
void IO::EventCB(ChiakiEvent *event)
{
switch(event->type)
{
case CHIAKI_EVENT_CONNECTED:
CHIAKI_LOGI(this->log, "EventCB CHIAKI_EVENT_CONNECTED");
if(this->chiaki_event_connected_cb != nullptr)
this->quit = !this->chiaki_event_connected_cb();
else
this->quit = false;
break;
case CHIAKI_EVENT_LOGIN_PIN_REQUEST:
CHIAKI_LOGI(this->log, "EventCB CHIAKI_EVENT_LOGIN_PIN_REQUEST");
if(this->chiaki_even_login_pin_request_cb != nullptr)
this->quit = !this->chiaki_even_login_pin_request_cb(event->login_pin_request.pin_incorrect);
break;
case CHIAKI_EVENT_QUIT:
CHIAKI_LOGI(this->log, "EventCB CHIAKI_EVENT_QUIT");
if(this->chiaki_event_quit_cb != nullptr)
this->quit = !this->chiaki_event_quit_cb(&event->quit);
else
this->quit = true;
break;
}
}
bool IO::FreeVideo()
{
bool ret = true;
@ -403,8 +405,7 @@ bool IO::ReadGameTouchScreen(ChiakiControllerState *state)
uint16_t y = touch.py * (DS4_TRACKPAD_MAX_Y / SWITCH_TOUCHSCREEN_MAX_Y);
// use nintendo switch border's 5% to
if(x <= (SWITCH_TOUCHSCREEN_MAX_X * 0.05) || x >= (SWITCH_TOUCHSCREEN_MAX_X * 0.95)
|| y <= (SWITCH_TOUCHSCREEN_MAX_Y * 0.05) || y >= (SWITCH_TOUCHSCREEN_MAX_Y * 0.95))
if(x <= (SWITCH_TOUCHSCREEN_MAX_X * 0.05) || x >= (SWITCH_TOUCHSCREEN_MAX_X * 0.95) || y <= (SWITCH_TOUCHSCREEN_MAX_Y * 0.05) || y >= (SWITCH_TOUCHSCREEN_MAX_Y * 0.95))
{
state->buttons |= CHIAKI_CONTROLLER_BUTTON_TOUCHPAD; // touchscreen
// printf("CHIAKI_CONTROLLER_BUTTON_TOUCHPAD\n");
@ -479,24 +480,56 @@ bool IO::ReadGameKeys(SDL_Event *event, ChiakiControllerState *state)
// event->jbutton.which, event->jbutton.button);
switch(event->jbutton.button)
{
case 0: state->buttons |= CHIAKI_CONTROLLER_BUTTON_MOON; break; // KEY_A
case 1: state->buttons |= CHIAKI_CONTROLLER_BUTTON_CROSS; break; // KEY_B
case 2: state->buttons |= CHIAKI_CONTROLLER_BUTTON_PYRAMID; break; // KEY_X
case 3: state->buttons |= CHIAKI_CONTROLLER_BUTTON_BOX; break; // KEY_Y
case 12: state->buttons |= CHIAKI_CONTROLLER_BUTTON_DPAD_LEFT; break; // KEY_DLEFT
case 14: state->buttons |= CHIAKI_CONTROLLER_BUTTON_DPAD_RIGHT; break; // KEY_DRIGHT
case 13: state->buttons |= CHIAKI_CONTROLLER_BUTTON_DPAD_UP; break; // KEY_DUP
case 15: state->buttons |= CHIAKI_CONTROLLER_BUTTON_DPAD_DOWN; break; // KEY_DDOWN
case 6: state->buttons |= CHIAKI_CONTROLLER_BUTTON_L1; break; // KEY_L
case 7: state->buttons |= CHIAKI_CONTROLLER_BUTTON_R1; break; // KEY_R
case 8: state->l2_state = 0xff; break; // KEY_ZL
case 9: state->r2_state = 0xff; break; // KEY_ZR
case 4: state->buttons |= CHIAKI_CONTROLLER_BUTTON_L3; break; // KEY_LSTICK
case 5: state->buttons |= CHIAKI_CONTROLLER_BUTTON_R3; break; // KEY_RSTICK
case 10: state->buttons |= CHIAKI_CONTROLLER_BUTTON_OPTIONS; break; // KEY_PLUS
case 0:
state->buttons |= CHIAKI_CONTROLLER_BUTTON_MOON;
break; // KEY_A
case 1:
state->buttons |= CHIAKI_CONTROLLER_BUTTON_CROSS;
break; // KEY_B
case 2:
state->buttons |= CHIAKI_CONTROLLER_BUTTON_PYRAMID;
break; // KEY_X
case 3:
state->buttons |= CHIAKI_CONTROLLER_BUTTON_BOX;
break; // KEY_Y
case 12:
state->buttons |= CHIAKI_CONTROLLER_BUTTON_DPAD_LEFT;
break; // KEY_DLEFT
case 14:
state->buttons |= CHIAKI_CONTROLLER_BUTTON_DPAD_RIGHT;
break; // KEY_DRIGHT
case 13:
state->buttons |= CHIAKI_CONTROLLER_BUTTON_DPAD_UP;
break; // KEY_DUP
case 15:
state->buttons |= CHIAKI_CONTROLLER_BUTTON_DPAD_DOWN;
break; // KEY_DDOWN
case 6:
state->buttons |= CHIAKI_CONTROLLER_BUTTON_L1;
break; // KEY_L
case 7:
state->buttons |= CHIAKI_CONTROLLER_BUTTON_R1;
break; // KEY_R
case 8:
state->l2_state = 0xff;
break; // KEY_ZL
case 9:
state->r2_state = 0xff;
break; // KEY_ZR
case 4:
state->buttons |= CHIAKI_CONTROLLER_BUTTON_L3;
break; // KEY_LSTICK
case 5:
state->buttons |= CHIAKI_CONTROLLER_BUTTON_R3;
break; // KEY_RSTICK
case 10:
state->buttons |= CHIAKI_CONTROLLER_BUTTON_OPTIONS;
break; // KEY_PLUS
// FIXME
// case 11: state->buttons |= CHIAKI_CONTROLLER_BUTTON_SHARE; break; // KEY_MINUS
case 11: state->buttons |= CHIAKI_CONTROLLER_BUTTON_PS; break; // KEY_MINUS
case 11:
state->buttons |= CHIAKI_CONTROLLER_BUTTON_PS;
break; // KEY_MINUS
default:
ret = false;
}
@ -506,23 +539,55 @@ bool IO::ReadGameKeys(SDL_Event *event, ChiakiControllerState *state)
// event->jbutton.which, event->jbutton.button);
switch(event->jbutton.button)
{
case 0: state->buttons ^= CHIAKI_CONTROLLER_BUTTON_MOON; break; // KEY_A
case 1: state->buttons ^= CHIAKI_CONTROLLER_BUTTON_CROSS; break; // KEY_B
case 2: state->buttons ^= CHIAKI_CONTROLLER_BUTTON_PYRAMID; break; // KEY_X
case 3: state->buttons ^= CHIAKI_CONTROLLER_BUTTON_BOX; break; // KEY_Y
case 12: state->buttons ^= CHIAKI_CONTROLLER_BUTTON_DPAD_LEFT; break; // KEY_DLEFT
case 14: state->buttons ^= CHIAKI_CONTROLLER_BUTTON_DPAD_RIGHT; break; // KEY_DRIGHT
case 13: state->buttons ^= CHIAKI_CONTROLLER_BUTTON_DPAD_UP; break; // KEY_DUP
case 15: state->buttons ^= CHIAKI_CONTROLLER_BUTTON_DPAD_DOWN; break; // KEY_DDOWN
case 6: state->buttons ^= CHIAKI_CONTROLLER_BUTTON_L1; break; // KEY_L
case 7: state->buttons ^= CHIAKI_CONTROLLER_BUTTON_R1; break; // KEY_R
case 8: state->l2_state = 0x00; break; // KEY_ZL
case 9: state->r2_state = 0x00; break; // KEY_ZR
case 4: state->buttons ^= CHIAKI_CONTROLLER_BUTTON_L3; break; // KEY_LSTICK
case 5: state->buttons ^= CHIAKI_CONTROLLER_BUTTON_R3; break; // KEY_RSTICK
case 10: state->buttons ^= CHIAKI_CONTROLLER_BUTTON_OPTIONS; break; // KEY_PLUS
case 0:
state->buttons ^= CHIAKI_CONTROLLER_BUTTON_MOON;
break; // KEY_A
case 1:
state->buttons ^= CHIAKI_CONTROLLER_BUTTON_CROSS;
break; // KEY_B
case 2:
state->buttons ^= CHIAKI_CONTROLLER_BUTTON_PYRAMID;
break; // KEY_X
case 3:
state->buttons ^= CHIAKI_CONTROLLER_BUTTON_BOX;
break; // KEY_Y
case 12:
state->buttons ^= CHIAKI_CONTROLLER_BUTTON_DPAD_LEFT;
break; // KEY_DLEFT
case 14:
state->buttons ^= CHIAKI_CONTROLLER_BUTTON_DPAD_RIGHT;
break; // KEY_DRIGHT
case 13:
state->buttons ^= CHIAKI_CONTROLLER_BUTTON_DPAD_UP;
break; // KEY_DUP
case 15:
state->buttons ^= CHIAKI_CONTROLLER_BUTTON_DPAD_DOWN;
break; // KEY_DDOWN
case 6:
state->buttons ^= CHIAKI_CONTROLLER_BUTTON_L1;
break; // KEY_L
case 7:
state->buttons ^= CHIAKI_CONTROLLER_BUTTON_R1;
break; // KEY_R
case 8:
state->l2_state = 0x00;
break; // KEY_ZL
case 9:
state->r2_state = 0x00;
break; // KEY_ZR
case 4:
state->buttons ^= CHIAKI_CONTROLLER_BUTTON_L3;
break; // KEY_LSTICK
case 5:
state->buttons ^= CHIAKI_CONTROLLER_BUTTON_R3;
break; // KEY_RSTICK
case 10:
state->buttons ^= CHIAKI_CONTROLLER_BUTTON_OPTIONS;
break; // KEY_PLUS
//case 11: state->buttons ^= CHIAKI_CONTROLLER_BUTTON_SHARE; break; // KEY_MINUS
case 11: state->buttons ^= CHIAKI_CONTROLLER_BUTTON_PS; break; // KEY_MINUS
case 11:
state->buttons ^= CHIAKI_CONTROLLER_BUTTON_PS;
break; // KEY_MINUS
default:
ret = false;
}
@ -798,4 +863,3 @@ bool IO::MainLoop(ChiakiControllerState * state)
return !this->quit;
}

View file

@ -134,9 +134,8 @@ int main(int argc, char * argv[])
}
// build sdl OpenGl and AV decoders graphical interface
IO io = IO(log); // open Input Output class
DiscoveryManager discoverymanager = DiscoveryManager();
MainApplication app = MainApplication(&discoverymanager, &io);
MainApplication app = MainApplication(&discoverymanager);
app.Load();
CHIAKI_LOGI(log, "Quit applet");

View file

@ -6,11 +6,10 @@
Settings::Settings()
{
#if defined(__SWITCH__) && !defined(CHIAKI_ENABLE_SWITCH_NXLINK)
// null log for switch version
chiaki_log_init(&this->log, CHIAKI_LOG_ALL ^ CHIAKI_LOG_VERBOSE, chiaki_log_cb_print, NULL);
#if defined(__SWITCH__)
chiaki_log_init(&this->log, CHIAKI_LOG_ALL ^ CHIAKI_LOG_VERBOSE ^ CHIAKI_LOG_DEBUG, chiaki_log_cb_print, NULL);
#else
chiaki_log_init(&this->log, CHIAKI_LOG_ALL ^ CHIAKI_LOG_VERBOSE, chiaki_log_cb_print, NULL);
chiaki_log_init(&this->log, CHIAKI_LOG_ALL, chiaki_log_cb_print, NULL);
#endif
}