Merge pull request #111707 from Nintorch/joypad-features

Support adding advanced joypad features
This commit is contained in:
Thaddeus Crews
2025-11-11 16:07:56 -06:00
9 changed files with 560 additions and 3 deletions

View File

@ -986,6 +986,15 @@ void Input::set_joy_axis(int p_device, JoyAxis p_axis, float p_value) {
_joy_axis[c] = p_value;
}
void Input::set_joy_features(int p_device, JoypadFeatures *p_features) {
Joypad *joypad = joy_names.getptr(p_device);
if (!joypad) {
return;
}
joypad->features = p_features;
_update_joypad_features(p_device);
}
void Input::start_joy_vibration(int p_device, float p_weak_magnitude, float p_strong_magnitude, float p_duration) {
_THREAD_SAFE_METHOD_
if (p_weak_magnitude < 0.f || p_weak_magnitude > 1.f || p_strong_magnitude < 0.f || p_strong_magnitude > 1.f) {
@ -1478,6 +1487,15 @@ void Input::_update_action_cache(const StringName &p_action_name, ActionState &r
}
}
void Input::_update_joypad_features(int p_device) {
Joypad *joypad = joy_names.getptr(p_device);
if (!joypad || joypad->features == nullptr) {
return;
}
// Do something based on the features. For example, we can save the information about
// the joypad having motion sensors, LED light, etc.
}
Input::JoyEvent Input::_get_mapped_button_event(const JoyDeviceMapping &mapping, JoyButton p_button) {
JoyEvent event;

View File

@ -79,6 +79,15 @@ public:
CURSOR_MAX
};
class JoypadFeatures {
public:
virtual ~JoypadFeatures() {}
// None at the moment, but later we can add new features like:
// virtual bool has_joy_accelerometer() const { return false; }
// virtual bool set_joy_accelerometer_enabled(bool p_enable) { return false; }
};
static constexpr int32_t JOYPADS_MAX = 16;
typedef void (*EventDispatchFunc)(const Ref<InputEvent> &p_event);
@ -174,6 +183,7 @@ private:
int mapping = -1;
int hat_current = 0;
Dictionary info;
Input::JoypadFeatures *features = nullptr;
};
VelocityTrack mouse_velocity_track;
@ -253,6 +263,7 @@ private:
void _button_event(int p_device, JoyButton p_index, bool p_pressed);
void _axis_event(int p_device, JoyAxis p_axis, float p_value);
void _update_action_cache(const StringName &p_action_name, ActionState &r_action_state);
void _update_joypad_features(int p_device);
void _parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_emulated);
@ -346,6 +357,8 @@ public:
void set_gyroscope(const Vector3 &p_gyroscope);
void set_joy_axis(int p_device, JoyAxis p_axis, float p_value);
void set_joy_features(int p_device, JoypadFeatures *p_features);
void start_joy_vibration(int p_device, float p_weak_magnitude, float p_strong_magnitude, float p_duration = 0);
void stop_joy_vibration(int p_device);
void vibrate_handheld(int p_duration_ms = 500, float p_amplitude = -1.0);