diff --git a/binding-mri/sunshine-binding.cpp b/binding-mri/sunshine-binding.cpp index d056461..b6b4749 100644 --- a/binding-mri/sunshine-binding.cpp +++ b/binding-mri/sunshine-binding.cpp @@ -1,8 +1,10 @@ #include #include +#include +#include #include #include "security.h" -#include "config.h" +#include "eventthread.h" //Просто на C реализуем методы мне в падлу ебаться со статической линковкой и прочим дерьмом. //Аминь. @@ -32,6 +34,15 @@ static VALUE int_times(VALUE 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(){ printf("[SunshineBindingInit] Initializing Sunshine binding\n"); 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_micro"), INT2NUM(SDL_MICRO_VERSION)); 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"))) { rb_define_method(rb_cObject, "class", rb_obj_class, 0); diff --git a/scripts/Main.rb b/scripts/Main.rb index e9f5d5b..f244da2 100644 --- a/scripts/Main.rb +++ b/scripts/Main.rb @@ -11,30 +11,11 @@ at_exit do end 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) $console = Graphics.fullscreen Graphics.frame_rate = 60 Font.default_size = 20 + Sunshine.SetLED(0, 255, 0) if defined?(RubyVM::YJIT) RubyVM::YJIT.enable diff --git a/src/eventthread.cpp b/src/eventthread.cpp index 4e5f689..7685729 100644 --- a/src/eventthread.cpp +++ b/src/eventthread.cpp @@ -90,6 +90,8 @@ enum{ }; static uint32_t usrIdStart; +SDL_Gamepad* gc = nullptr; +SDL_Joystick* js = nullptr; bool EventThread::allocUserEvents(){ usrIdStart = SDL_RegisterEvents(EVENT_COUNT); @@ -123,7 +125,7 @@ void EventThread::process(RGSSThreadData &rtData){ fps.displayCounter = 0; fps.acc = 0; fps.accDiv = 0; - + if (rtData.config.printFPS) fps.sendUpdates.set(); @@ -147,12 +149,12 @@ void EventThread::process(RGSSThreadData &rtData){ for (int i = 0; i < tmpstupidshit; ++i) { if (SDL_IsGamepad(i)) { //Load as game controller - SDL_Gamepad *gc = SDL_OpenGamepad(i); + gc = SDL_OpenGamepad(i); int id = SDL_GetJoystickID(SDL_GetGamepadJoystick(gc)); controllers[id] = gc; } else { //Fall back to joystick - SDL_Joystick *js = SDL_OpenJoystick(i); + js = SDL_OpenJoystick(i); joysticks[SDL_GetJoystickID(js)] = js; } } @@ -166,8 +168,6 @@ void EventThread::process(RGSSThreadData &rtData){ int winW, winH; int i; - SDL_Joystick *js; - SDL_Gamepad *gc; int id; std::map::iterator jsit; std::map::iterator gcit; diff --git a/src/eventthread.h b/src/eventthread.h index d0d42c1..6f9efb6 100644 --- a/src/eventthread.h +++ b/src/eventthread.h @@ -44,6 +44,9 @@ union SDL_Event; #define MAX_FINGERS 4 +extern SDL_Gamepad* gc; +extern SDL_Joystick* js; + class EventThread{ public: struct ControllerState{