This commit is contained in:
DepressedTWM 2026-07-06 23:31:50 +04:00
commit b74589b5c8
6 changed files with 50 additions and 74 deletions

View file

@ -28,8 +28,10 @@
#include "keybindings-binding.h"
#include <SDL3/SDL_error.h>
#include <SDL3/SDL_keyboard.h>
#include <SDL3/SDL_gamepad.h>
#include <cstdio>
#include <vector>
RB_METHOD(inputUpdate){
@ -279,10 +281,11 @@ static VALUE setBinding(VALUE self, VALUE rb_arr, VALUE rb_target){
static VALUE setLED(VALUE self, VALUE r, VALUE g, VALUE b) {
if (gc != nullptr) {
SDL_SetGamepadLED(gc, NUM2INT(r), NUM2INT(g), NUM2INT(b));
} else if (js != nullptr) {
SDL_SetJoystickLED(js, NUM2INT(r), NUM2INT(g), NUM2INT(b));
if (!SDL_SetGamepadLED(gc, NUM2INT(r), NUM2INT(g), NUM2INT(b))) {
printf("failed to set gamepad led for gamepad %s: %s\n", SDL_GetGamepadName(gc), SDL_GetError());
}
}
return Qnil;
}
@ -291,10 +294,12 @@ static VALUE rumble(VALUE self, VALUE low_frequency_rumble, VALUE high_frequency
Uint16 high_freq = NUM2DBL(high_frequency_rumble) * 65535;
if (gc != nullptr) {
SDL_RumbleGamepad(gc, low_freq, high_freq, NUM2INT(duration_ms));
} else if (js != nullptr) {
SDL_RumbleJoystick(js, low_freq, high_freq, NUM2INT(duration_ms));
printf("low freq: %d, high freq: %d, duration: %d", low_freq, high_freq, NUM2INT(duration_ms));
if (!SDL_RumbleGamepad(gc, low_freq, high_freq, NUM2INT(duration_ms))) {
printf("failed to rumble gamepad %s: %s\n", SDL_GetGamepadName(gc), SDL_GetError());
}
}
return Qnil;
}

View file

@ -52,3 +52,5 @@ Optimizations for steamshim
crash() function update
*NIX support patches
Start house reworked
removed SDL joystick support
fixed SECCOMP blocking UDEV sockets

View file

@ -15,7 +15,7 @@ begin
Graphics.frame_rate = 60
Font.default_size = 20
#debug shit
Input.set_led(0, 255, 0)
Input.set_led(255, 150, 30)
# Load persistent data
Persistent.load

View file

@ -21,10 +21,13 @@
#include "eventthread.h"
#include <SDL3/SDL_error.h>
#include <SDL3/SDL_events.h>
#include <SDL3/SDL_joystick.h>
#include <SDL3/SDL_gamepad.h>
#include <SDL3/SDL_log.h>
#include <SDL3/SDL_messagebox.h>
#include <SDL3/SDL_properties.h>
#include <SDL3/SDL_timer.h>
#include <SDL3/SDL_thread.h>
#include <SDL3/SDL_touch.h>
@ -39,6 +42,7 @@
#include <SDL3/SDL_stdinc.h>
#include <cstdio>
#include <map>
#include <iostream>
@ -90,7 +94,6 @@ enum{
static uint32_t usrIdStart;
SDL_Gamepad* gc = nullptr;
SDL_Joystick* js = nullptr;
bool EventThread::allocUserEvents(){
usrIdStart = SDL_RegisterEvents(EVENT_COUNT);
@ -139,22 +142,24 @@ void EventThread::process(RGSSThreadData &rtData){
bool terminate = false;
std::map<int, SDL_Gamepad*> controllers;
std::map<int, SDL_Joystick*> joysticks;
std::map<int, SDL_Gamepad*> gamepads;
int tmpstupidshit;
SDL_GetJoysticks(&tmpstupidshit);
int count = 0;
int jId = 0;
SDL_JoystickID *ids = SDL_GetGamepads(&count);
for (int i = 0; i < tmpstupidshit; ++i) {
if (SDL_IsGamepad(i)) {
//Load as game controller
gc = SDL_OpenGamepad(i);
int id = SDL_GetJoystickID(SDL_GetGamepadJoystick(gc));
controllers[id] = gc;
} else {
//Fall back to joystick
js = SDL_OpenJoystick(i);
joysticks[SDL_GetJoystickID(js)] = js;
for(int i = 0; i < count; i++) {
SDL_Gamepad* gamepd = SDL_OpenGamepad(ids[i]);
if (gc == nullptr) {
gc = gamepd;
jId = ids[i];
}
printf("Gamepad connected: %s", SDL_GetGamepadName(gc));
if (i > 0) {
SDL_CloseGamepad(gamepd);
}
}
@ -168,7 +173,6 @@ void EventThread::process(RGSSThreadData &rtData){
int i;
int id;
std::map<int, SDL_Joystick*>::iterator jsit;
std::map<int, SDL_Gamepad*>::iterator gcit;
SDL_GetWindowSize(win, &winW, &winH); // SDL_GL_GetDrawableSize(win, &winW, &winH);
@ -179,7 +183,6 @@ void EventThread::process(RGSSThreadData &rtData){
break;
}
/* Preselect and discard unwanted events here */
switch (event.type){
case SDL_EVENT_MOUSE_BUTTON_DOWN :
case SDL_EVENT_MOUSE_BUTTON_UP :
@ -345,51 +348,15 @@ void EventThread::process(RGSSThreadData &rtData){
break;
case SDL_EVENT_GAMEPAD_ADDED:
gc = SDL_OpenGamepad(event.jdevice.which);
gc = SDL_OpenGamepad(event.gdevice.which);
id = SDL_GetJoystickID(SDL_GetGamepadJoystick(gc));
controllers[id] = gc;
gamepads[id] = gc;
break;
case SDL_EVENT_GAMEPAD_REMOVED:
gcit = controllers.find(event.jdevice.which);
gcit = gamepads.find(event.gdevice.which);
SDL_CloseGamepad(gcit->second);
controllers.erase(gcit);
break;
case SDL_EVENT_JOYSTICK_BUTTON_DOWN :
if (joysticks.find(event.jbutton.which) != joysticks.end())
joyState.buttons[event.jbutton.button] = true;
break;
case SDL_EVENT_JOYSTICK_BUTTON_UP :
if (joysticks.find(event.jbutton.which) != joysticks.end())
joyState.buttons[event.jbutton.button] = false;
break;
case SDL_EVENT_JOYSTICK_HAT_MOTION :
if (joysticks.find(event.jbutton.which) != joysticks.end())
joyState.hats[event.jhat.hat] = event.jhat.value;
break;
case SDL_EVENT_JOYSTICK_AXIS_MOTION :
if (joysticks.find(event.jbutton.which) != joysticks.end())
joyState.axes[event.jaxis.axis] = event.jaxis.value;
break;
case SDL_EVENT_JOYSTICK_ADDED :
if (SDL_IsGamepad(event.jdevice.which))
break;
js = SDL_OpenJoystick(event.jdevice.which);
joysticks[SDL_GetJoystickID(js)] = js;
break;
case SDL_EVENT_JOYSTICK_REMOVED :
jsit = joysticks.find(event.jdevice.which);
if (jsit != joysticks.end()) {
SDL_CloseJoystick(jsit->second);
joysticks.erase(jsit);
resetInputStates();
}
gamepads.erase(gcit);
break;
case SDL_EVENT_MOUSE_BUTTON_DOWN :
@ -491,10 +458,8 @@ void EventThread::process(RGSSThreadData &rtData){
/* Just in case */
rtData.syncPoint.resumeThreads();
for (gcit = controllers.begin(); gcit != controllers.end(); ++gcit)
for (gcit = gamepads.begin(); gcit != gamepads.end(); ++gcit)
SDL_CloseGamepad(gcit->second);
for (jsit = joysticks.begin(); jsit != joysticks.end(); ++jsit)
SDL_CloseJoystick(jsit->second);
}
bool EventThread::eventFilter(void *data, SDL_Event *event){

View file

@ -45,7 +45,6 @@ union SDL_Event;
#define MAX_FINGERS 4
extern SDL_Gamepad* gc;
extern SDL_Joystick* js;
class EventThread{
public:

View file

@ -38,11 +38,16 @@ void SecurityManagerInit(){
//Extra rules
//Deny all network connections
if(seccomp_rule_add(ctx, SCMP_ACT_ERRNO(EPERM), SCMP_SYS(socket), 1, SCMP_CMP(0, SCMP_CMP_NE, AF_UNIX))){
Debug() << "seccomp_rule_add failed for extra rules";
if(seccomp_rule_add(ctx, SCMP_ACT_ERRNO(EPERM), SCMP_SYS(socket), 1, SCMP_CMP(0, SCMP_CMP_EQ, AF_INET))){
Debug() << "seccomp_rule_add failed for extra rules (socket AF_INET)";
}
if(seccomp_rule_add(ctx, SCMP_ACT_ERRNO(EPERM), SCMP_SYS(socket), 1, SCMP_CMP(0, SCMP_CMP_EQ, AF_INET6))){
Debug() << "seccomp_rule_add failed for extra rules (socket AF_INET6)";
}
if(seccomp_rule_add(ctx, SCMP_ACT_ERRNO(EPERM), SCMP_SYS(socketpair), 1, SCMP_CMP(0, SCMP_CMP_NE, AF_UNIX))){
Debug() << "seccomp_rule_add failed for extra rules";
Debug() << "seccomp_rule_add failed for extra rules (socketpair)";
}