mirror of
https://git.sr.ht/~thestr4ng3r/chiaki
synced 2025-08-14 02:36:51 -07:00
Integrate Setsu in GUI
This commit is contained in:
parent
a688974c89
commit
f3be4ed22a
5 changed files with 124 additions and 6 deletions
|
@ -83,6 +83,10 @@ if(CHIAKI_GUI_ENABLE_SDL_GAMECONTROLLER)
|
|||
target_link_libraries(chiaki SDL2::SDL2)
|
||||
target_compile_definitions(chiaki PRIVATE CHIAKI_GUI_ENABLE_SDL_GAMECONTROLLER)
|
||||
endif()
|
||||
if(CHIAKI_ENABLE_SETSU)
|
||||
target_link_libraries(chiaki setsu)
|
||||
target_compile_definitions(chiaki PRIVATE CHIAKI_GUI_ENABLE_SETSU)
|
||||
endif()
|
||||
|
||||
set_target_properties(chiaki PROPERTIES
|
||||
MACOSX_BUNDLE TRUE
|
||||
|
|
|
@ -21,6 +21,10 @@
|
|||
#include <chiaki/session.h>
|
||||
#include <chiaki/opusdecoder.h>
|
||||
|
||||
#if CHIAKI_GUI_ENABLE_SETSU
|
||||
#include <setsu.h>
|
||||
#endif
|
||||
|
||||
#include "videodecoder.h"
|
||||
#include "exception.h"
|
||||
#include "sessionlog.h"
|
||||
|
@ -69,6 +73,11 @@ class StreamSession : public QObject
|
|||
ChiakiOpusDecoder opus_decoder;
|
||||
|
||||
Controller *controller;
|
||||
#if CHIAKI_GUI_ENABLE_SETSU
|
||||
Setsu *setsu;
|
||||
QMap<QPair<QString, SetsuTrackingId>, uint8_t> setsu_ids;
|
||||
ChiakiControllerState setsu_state;
|
||||
#endif
|
||||
|
||||
ChiakiControllerState keyboard_state;
|
||||
|
||||
|
@ -83,6 +92,9 @@ class StreamSession : public QObject
|
|||
void PushAudioFrame(int16_t *buf, size_t samples_count);
|
||||
void PushVideoSample(uint8_t *buf, size_t buf_size);
|
||||
void Event(ChiakiEvent *event);
|
||||
#if CHIAKI_GUI_ENABLE_SETSU
|
||||
void HandleSetsuEvent(SetsuEvent *event);
|
||||
#endif
|
||||
|
||||
private slots:
|
||||
void InitAudio(unsigned int channels, unsigned int rate);
|
||||
|
|
|
@ -199,7 +199,8 @@ QString Controller::GetName()
|
|||
|
||||
ChiakiControllerState Controller::GetState()
|
||||
{
|
||||
ChiakiControllerState state = {};
|
||||
ChiakiControllerState state;
|
||||
chiaki_controller_state_set_idle(&state);
|
||||
#ifdef CHIAKI_GUI_ENABLE_SDL_GAMECONTROLLER
|
||||
if(!controller)
|
||||
return state;
|
||||
|
|
|
@ -27,6 +27,8 @@
|
|||
#include <cstring>
|
||||
#include <chiaki/session.h>
|
||||
|
||||
#define SETSU_UPDATE_INTERVAL_MS 4
|
||||
|
||||
StreamSessionConnectInfo::StreamSessionConnectInfo(Settings *settings, QString host, QByteArray regist_key, QByteArray morning)
|
||||
{
|
||||
key_map = settings->GetControllerMappingForDecoding();
|
||||
|
@ -44,6 +46,7 @@ static void AudioSettingsCb(uint32_t channels, uint32_t rate, void *user);
|
|||
static void AudioFrameCb(int16_t *buf, size_t samples_count, void *user);
|
||||
static bool VideoSampleCb(uint8_t *buf, size_t buf_size, void *user);
|
||||
static void EventCb(ChiakiEvent *event, void *user);
|
||||
static void SessionSetsuCb(SetsuEvent *event, void *user);
|
||||
|
||||
StreamSession::StreamSession(const StreamSessionConnectInfo &connect_info, QObject *parent)
|
||||
: QObject(parent),
|
||||
|
@ -70,7 +73,7 @@ StreamSession::StreamSession(const StreamSessionConnectInfo &connect_info, QObje
|
|||
throw ChiakiException("Morning invalid");
|
||||
memcpy(chiaki_connect_info.morning, connect_info.morning.constData(), sizeof(chiaki_connect_info.morning));
|
||||
|
||||
memset(&keyboard_state, 0, sizeof(keyboard_state));
|
||||
chiaki_controller_state_set_idle(&keyboard_state);
|
||||
|
||||
ChiakiErrorCode err = chiaki_session_init(&session, &chiaki_connect_info, log.GetChiakiLog());
|
||||
if(err != CHIAKI_ERR_SUCCESS)
|
||||
|
@ -88,6 +91,16 @@ StreamSession::StreamSession(const StreamSessionConnectInfo &connect_info, QObje
|
|||
connect(ControllerManager::GetInstance(), &ControllerManager::AvailableControllersUpdated, this, &StreamSession::UpdateGamepads);
|
||||
#endif
|
||||
|
||||
#if CHIAKI_GUI_ENABLE_SETSU
|
||||
chiaki_controller_state_set_idle(&setsu_state);
|
||||
setsu = setsu_new();
|
||||
auto timer = new QTimer(this);
|
||||
connect(timer, &QTimer::timeout, this, [this]{
|
||||
setsu_poll(setsu, SessionSetsuCb, this);
|
||||
});
|
||||
timer->start(SETSU_UPDATE_INTERVAL_MS);
|
||||
#endif
|
||||
|
||||
key_map = connect_info.key_map;
|
||||
UpdateGamepads();
|
||||
}
|
||||
|
@ -100,6 +113,9 @@ StreamSession::~StreamSession()
|
|||
#if CHIAKI_GUI_ENABLE_SDL_GAMECONTROLLER
|
||||
delete controller;
|
||||
#endif
|
||||
#if CHIAKI_GUI_ENABLE_SETSU
|
||||
setsu_free(setsu);
|
||||
#endif
|
||||
}
|
||||
|
||||
void StreamSession::Start()
|
||||
|
@ -217,13 +233,18 @@ void StreamSession::UpdateGamepads()
|
|||
|
||||
void StreamSession::SendFeedbackState()
|
||||
{
|
||||
ChiakiControllerState state = {};
|
||||
ChiakiControllerState state;
|
||||
chiaki_controller_state_set_idle(&state);
|
||||
|
||||
#if CHIAKI_GUI_ENABLE_SDL_GAMECONTROLLER
|
||||
if(controller)
|
||||
state = controller->GetState();
|
||||
#endif
|
||||
|
||||
#if CHIAKI_GUI_ENABLE_SETSU
|
||||
chiaki_controller_state_or(&state, &state, &setsu_state);
|
||||
#endif
|
||||
|
||||
chiaki_controller_state_or(&state, &state, &keyboard_state);
|
||||
chiaki_session_set_controller_state(&session, &state);
|
||||
}
|
||||
|
@ -275,6 +296,8 @@ void StreamSession::Event(ChiakiEvent *event)
|
|||
{
|
||||
switch(event->type)
|
||||
{
|
||||
case CHIAKI_EVENT_CONNECTED:
|
||||
break;
|
||||
case CHIAKI_EVENT_QUIT:
|
||||
emit SessionQuit(event->quit.reason, event->quit.reason_str ? QString::fromUtf8(event->quit.reason_str) : QString());
|
||||
break;
|
||||
|
@ -284,6 +307,63 @@ void StreamSession::Event(ChiakiEvent *event)
|
|||
}
|
||||
}
|
||||
|
||||
#if CHIAKI_GUI_ENABLE_SETSU
|
||||
void StreamSession::HandleSetsuEvent(SetsuEvent *event)
|
||||
{
|
||||
if(!setsu)
|
||||
return;
|
||||
switch(event->type)
|
||||
{
|
||||
case SETSU_EVENT_DEVICE_ADDED:
|
||||
setsu_connect(setsu, event->path);
|
||||
break;
|
||||
case SETSU_EVENT_DEVICE_REMOVED:
|
||||
for(auto it=setsu_ids.begin(); it!=setsu_ids.end();)
|
||||
{
|
||||
if(it.key().first == event->path)
|
||||
{
|
||||
chiaki_controller_state_stop_touch(&setsu_state, it.value());
|
||||
setsu_ids.erase(it++);
|
||||
}
|
||||
else
|
||||
it++;
|
||||
}
|
||||
SendFeedbackState();
|
||||
break;
|
||||
case SETSU_EVENT_DOWN:
|
||||
break;
|
||||
case SETSU_EVENT_UP:
|
||||
for(auto it=setsu_ids.begin(); it!=setsu_ids.end(); it++)
|
||||
{
|
||||
if(it.key().first == setsu_device_get_path(event->dev) && it.key().second == event->tracking_id)
|
||||
{
|
||||
chiaki_controller_state_stop_touch(&setsu_state, it.value());
|
||||
setsu_ids.erase(it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
SendFeedbackState();
|
||||
break;
|
||||
case SETSU_EVENT_POSITION: {
|
||||
QPair<QString, SetsuTrackingId> k = { setsu_device_get_path(event->dev), event->tracking_id };
|
||||
auto it = setsu_ids.find(k);
|
||||
if(it == setsu_ids.end())
|
||||
{
|
||||
int8_t cid = chiaki_controller_state_start_touch(&setsu_state, event->x, event->y);
|
||||
if(cid >= 0)
|
||||
setsu_ids[k] = (uint8_t)cid;
|
||||
else
|
||||
break;
|
||||
}
|
||||
else
|
||||
chiaki_controller_state_set_touch_pos(&setsu_state, it.value(), event->x, event->y);
|
||||
SendFeedbackState();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
class StreamSessionPrivate
|
||||
{
|
||||
public:
|
||||
|
@ -295,6 +375,9 @@ class StreamSessionPrivate
|
|||
static void PushAudioFrame(StreamSession *session, int16_t *buf, size_t samples_count) { session->PushAudioFrame(buf, samples_count); }
|
||||
static void PushVideoSample(StreamSession *session, uint8_t *buf, size_t buf_size) { session->PushVideoSample(buf, buf_size); }
|
||||
static void Event(StreamSession *session, ChiakiEvent *event) { session->Event(event); }
|
||||
#if CHIAKI_GUI_ENABLE_SETSU
|
||||
static void HandleSetsuEvent(StreamSession *session, SetsuEvent *event) { session->HandleSetsuEvent(event); }
|
||||
#endif
|
||||
};
|
||||
|
||||
static void AudioSettingsCb(uint32_t channels, uint32_t rate, void *user)
|
||||
|
@ -321,3 +404,11 @@ static void EventCb(ChiakiEvent *event, void *user)
|
|||
auto session = reinterpret_cast<StreamSession *>(user);
|
||||
StreamSessionPrivate::Event(session, event);
|
||||
}
|
||||
|
||||
#if CHIAKI_GUI_ENABLE_SETSU
|
||||
static void SessionSetsuCb(SetsuEvent *event, void *user)
|
||||
{
|
||||
auto session = reinterpret_cast<StreamSession *>(user);
|
||||
StreamSessionPrivate::HandleSetsuEvent(session, event);
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -22,10 +22,19 @@
|
|||
CHIAKI_EXPORT void chiaki_controller_state_set_idle(ChiakiControllerState *state)
|
||||
{
|
||||
state->buttons = 0;
|
||||
state->l2_state = 0;
|
||||
state->r2_state = 0;
|
||||
state->left_x = 0;
|
||||
state->left_y = 0;
|
||||
state->right_x = 0;
|
||||
state->right_y = 0;
|
||||
state->touch_id_next = 0;
|
||||
for(size_t i=0; i<CHIAKI_CONTROLLER_TOUCHES_MAX; i++)
|
||||
{
|
||||
state->touches[i].id = -1;
|
||||
state->touches[i].x = 0;
|
||||
state->touches[i].y = 0;
|
||||
}
|
||||
}
|
||||
|
||||
CHIAKI_EXPORT int8_t chiaki_controller_state_start_touch(ChiakiControllerState *state, uint16_t x, uint16_t y)
|
||||
|
@ -38,7 +47,7 @@ CHIAKI_EXPORT int8_t chiaki_controller_state_start_touch(ChiakiControllerState *
|
|||
state->touch_id_next = (state->touch_id_next + 1) & TOUCH_ID_MASK;
|
||||
state->touches[i].x = x;
|
||||
state->touches[i].y = y;
|
||||
break;
|
||||
return state->touches[i].id;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
|
@ -87,13 +96,14 @@ CHIAKI_EXPORT void chiaki_controller_state_or(ChiakiControllerState *out, Chiaki
|
|||
out->touch_id_next = 0;
|
||||
for(size_t i=0; i<CHIAKI_CONTROLLER_TOUCHES_MAX; i++)
|
||||
{
|
||||
ChiakiControllerTouch *touch = a->touches[i].id >= 0 ? &a->touches[i] : b->touches[i].id >= 0 ? &b->touches[i] : NULL;
|
||||
ChiakiControllerTouch *touch = a->touches[i].id >= 0 ? &a->touches[i] : (b->touches[i].id >= 0 ? &b->touches[i] : NULL);
|
||||
if(!touch)
|
||||
{
|
||||
out->touches[i].id = -1;
|
||||
out->touches[i].x = out->touches[i].y = 0;
|
||||
continue;
|
||||
}
|
||||
out->touches[i] = *touch;
|
||||
if(touch != &out->touches[i])
|
||||
out->touches[i] = *touch;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue