I MADE FUCKIN GAYPADS LED CONTROL MEALNGG

This commit is contained in:
DepressedTWM 2026-06-25 00:44:45 +04:00
parent 6606bb2b4c
commit 2aa9f318a5
4 changed files with 22 additions and 26 deletions

View file

@ -1,8 +1,10 @@
#include <ruby.h> #include <ruby.h>
#include <SDL3/SDL_version.h> #include <SDL3/SDL_version.h>
#include <SDL3/SDL_gamepad.h>
#include <SDL3/SDL_joystick.h>
#include <limits.h> #include <limits.h>
#include "security.h" #include "security.h"
#include "config.h" #include "eventthread.h"
//Просто на C реализуем методы мне в падлу ебаться со статической линковкой и прочим дерьмом. //Просто на C реализуем методы мне в падлу ебаться со статической линковкой и прочим дерьмом.
//Аминь. //Аминь.
@ -32,6 +34,15 @@ static VALUE int_times(VALUE self) {
return self; return self;
} }
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));
}
return Qnil;
}
void SunshineBindingInit(){ void SunshineBindingInit(){
printf("[SunshineBindingInit] Initializing Sunshine binding\n"); printf("[SunshineBindingInit] Initializing Sunshine binding\n");
VALUE module = rb_define_module("Sunshine"); VALUE module = rb_define_module("Sunshine");
@ -40,6 +51,7 @@ void SunshineBindingInit(){
rb_const_set(module, rb_intern("SDLVersion_minor"), INT2NUM(SDL_MINOR_VERSION)); rb_const_set(module, rb_intern("SDLVersion_minor"), INT2NUM(SDL_MINOR_VERSION));
rb_const_set(module, rb_intern("SDLVersion_micro"), INT2NUM(SDL_MICRO_VERSION)); rb_const_set(module, rb_intern("SDLVersion_micro"), INT2NUM(SDL_MICRO_VERSION));
rb_const_set(module, rb_intern("SECURITYSTATE"), rb_str_new_cstr(securitystate)); rb_const_set(module, rb_intern("SECURITYSTATE"), rb_str_new_cstr(securitystate));
rb_define_singleton_method(module, "SetLED", SetLED, 3);
//если методы доступны то просто не перезаписываем их //если методы доступны то просто не перезаписываем их
if (!rb_respond_to(rb_cObject, rb_intern("class"))) { if (!rb_respond_to(rb_cObject, rb_intern("class"))) {
rb_define_method(rb_cObject, "class", rb_obj_class, 0); rb_define_method(rb_cObject, "class", rb_obj_class, 0);

View file

@ -11,30 +11,11 @@ at_exit do
end end
begin begin
p RUBY_VERSION
if $debug
trace = TracePoint.new(:raise) do |tp|
p [tp.lineno, tp.event, tp.raised_exception]
end
trace.enable
0 / 0
#tp = TracePoint.new(:call, :return) do |t|
# case t.event
# when :call
# puts "WRAP START (#{start_code}) -> #{t.defined_class}##{t.method_id}"
# when :return
# puts "WRAP END -> #{t.defined_class}##{t.method_id}"
# end
#end
#tp.enable
end
RPG::Mod.exec_hooks("hooks/Main/start", binding) RPG::Mod.exec_hooks("hooks/Main/start", binding)
$console = Graphics.fullscreen $console = Graphics.fullscreen
Graphics.frame_rate = 60 Graphics.frame_rate = 60
Font.default_size = 20 Font.default_size = 20
Sunshine.SetLED(0, 255, 0)
if defined?(RubyVM::YJIT) if defined?(RubyVM::YJIT)
RubyVM::YJIT.enable RubyVM::YJIT.enable

View file

@ -90,6 +90,8 @@ enum{
}; };
static uint32_t usrIdStart; static uint32_t usrIdStart;
SDL_Gamepad* gc = nullptr;
SDL_Joystick* js = nullptr;
bool EventThread::allocUserEvents(){ bool EventThread::allocUserEvents(){
usrIdStart = SDL_RegisterEvents(EVENT_COUNT); usrIdStart = SDL_RegisterEvents(EVENT_COUNT);
@ -123,7 +125,7 @@ void EventThread::process(RGSSThreadData &rtData){
fps.displayCounter = 0; fps.displayCounter = 0;
fps.acc = 0; fps.acc = 0;
fps.accDiv = 0; fps.accDiv = 0;
if (rtData.config.printFPS) if (rtData.config.printFPS)
fps.sendUpdates.set(); fps.sendUpdates.set();
@ -147,12 +149,12 @@ void EventThread::process(RGSSThreadData &rtData){
for (int i = 0; i < tmpstupidshit; ++i) { for (int i = 0; i < tmpstupidshit; ++i) {
if (SDL_IsGamepad(i)) { if (SDL_IsGamepad(i)) {
//Load as game controller //Load as game controller
SDL_Gamepad *gc = SDL_OpenGamepad(i); gc = SDL_OpenGamepad(i);
int id = SDL_GetJoystickID(SDL_GetGamepadJoystick(gc)); int id = SDL_GetJoystickID(SDL_GetGamepadJoystick(gc));
controllers[id] = gc; controllers[id] = gc;
} else { } else {
//Fall back to joystick //Fall back to joystick
SDL_Joystick *js = SDL_OpenJoystick(i); js = SDL_OpenJoystick(i);
joysticks[SDL_GetJoystickID(js)] = js; joysticks[SDL_GetJoystickID(js)] = js;
} }
} }
@ -166,8 +168,6 @@ void EventThread::process(RGSSThreadData &rtData){
int winW, winH; int winW, winH;
int i; int i;
SDL_Joystick *js;
SDL_Gamepad *gc;
int id; int id;
std::map<int, SDL_Joystick*>::iterator jsit; std::map<int, SDL_Joystick*>::iterator jsit;
std::map<int, SDL_Gamepad*>::iterator gcit; std::map<int, SDL_Gamepad*>::iterator gcit;

View file

@ -44,6 +44,9 @@ union SDL_Event;
#define MAX_FINGERS 4 #define MAX_FINGERS 4
extern SDL_Gamepad* gc;
extern SDL_Joystick* js;
class EventThread{ class EventThread{
public: public:
struct ControllerState{ struct ControllerState{