gamepads haptic moved from Sunshine module to Input module
This commit is contained in:
parent
9f439b38b8
commit
27731db838
|
|
@ -277,7 +277,26 @@ static VALUE setBinding(VALUE self, VALUE rb_arr, VALUE rb_target){
|
||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
static VALUE rumble(VALUE self, VALUE low_frequency_rumble, VALUE high_frequency_rumble, VALUE duration_ms) {
|
||||||
|
Uint16 low_freq = NUM2DBL(low_frequency_rumble) * 65535;
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
return Qnil;
|
||||||
|
}
|
||||||
|
|
||||||
struct{
|
struct{
|
||||||
const char *str;
|
const char *str;
|
||||||
|
|
@ -349,7 +368,11 @@ void inputBindingInit(){
|
||||||
_rb_define_module_function(module, "c_axis_from_name", getGamepadAxisFromName);
|
_rb_define_module_function(module, "c_axis_from_name", getGamepadAxisFromName);
|
||||||
rb_const_set(module, rb_intern("GAMEPAD_AXIS_COUNT"), SDL_GamepadAxis::SDL_GAMEPAD_AXIS_COUNT - 1);
|
rb_const_set(module, rb_intern("GAMEPAD_AXIS_COUNT"), SDL_GamepadAxis::SDL_GAMEPAD_AXIS_COUNT - 1);
|
||||||
|
|
||||||
rb_define_module_function(module, "set_binding", RUBY_METHOD_FUNC(setBinding), 2);
|
rb_define_module_function(module, "set_binding", setBinding, 2);
|
||||||
|
|
||||||
|
// haptic
|
||||||
|
rb_define_singleton_method(module, "set_led", setLED, 3);
|
||||||
|
rb_define_singleton_method(module, "vibrate", rumble, 3);
|
||||||
|
|
||||||
// mouse
|
// mouse
|
||||||
_rb_define_module_function(module, "mouse_x", inputMouseX);
|
_rb_define_module_function(module, "mouse_x", inputMouseX);
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
#include <SDL3/SDL_log.h>
|
|
||||||
#include <ruby.h>
|
#include <ruby.h>
|
||||||
#include <SDL3/SDL_version.h>
|
#include <SDL3/SDL_version.h>
|
||||||
#include <SDL3/SDL_gamepad.h>
|
#include <SDL3/SDL_gamepad.h>
|
||||||
|
|
@ -39,27 +38,6 @@ 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
static VALUE Rumble(VALUE self, VALUE low_frequency_rumble, VALUE high_frequency_rumble, VALUE duration_ms) {
|
|
||||||
Uint16 low_freq = NUM2DBL(low_frequency_rumble) * 65535;
|
|
||||||
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));
|
|
||||||
}
|
|
||||||
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");
|
||||||
|
|
@ -68,8 +46,6 @@ 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);
|
|
||||||
rb_define_singleton_method(module, "Vibrate", Rumble, 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);
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ begin
|
||||||
$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)
|
Input.set_led(0, 255, 0)
|
||||||
|
|
||||||
if defined?(RubyVM::YJIT)
|
if defined?(RubyVM::YJIT)
|
||||||
RubyVM::YJIT.enable
|
RubyVM::YJIT.enable
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue