diff options
Diffstat (limited to 'core/input')
-rw-r--r-- | core/input/input.cpp | 77 | ||||
-rw-r--r-- | core/input/input.h | 1 | ||||
-rw-r--r-- | core/input/input_event.cpp | 140 | ||||
-rw-r--r-- | core/input/input_event.h | 11 | ||||
-rw-r--r-- | core/input/input_map.cpp | 20 | ||||
-rw-r--r-- | core/input/input_map.h | 1 |
6 files changed, 0 insertions, 250 deletions
diff --git a/core/input/input.cpp b/core/input/input.cpp index 38a71994d8..a9921f791a 100644 --- a/core/input/input.cpp +++ b/core/input/input.cpp @@ -129,7 +129,6 @@ Input::CursorShape (*Input::get_current_cursor_shape_func)() = nullptr; void (*Input::set_custom_mouse_cursor_func)(const RES &, Input::CursorShape, const Vector2 &) = nullptr; Input *Input::get_singleton() { - return singleton; } @@ -139,12 +138,10 @@ void Input::set_mouse_mode(MouseMode p_mode) { } Input::MouseMode Input::get_mouse_mode() const { - return get_mouse_mode_func(); } void Input::_bind_methods() { - ClassDB::bind_method(D_METHOD("is_key_pressed", "keycode"), &Input::is_key_pressed); ClassDB::bind_method(D_METHOD("is_mouse_button_pressed", "button"), &Input::is_mouse_button_pressed); ClassDB::bind_method(D_METHOD("is_joy_button_pressed", "device", "button"), &Input::is_joy_button_pressed); @@ -219,7 +216,6 @@ void Input::get_argument_options(const StringName &p_function, int p_idx, List<S String pf = p_function; if (p_idx == 0 && (pf == "is_action_pressed" || pf == "action_press" || pf == "action_release" || pf == "is_action_just_pressed" || pf == "is_action_just_released" || pf == "get_action_strength")) { - List<PropertyInfo> pinfo; ProjectSettings::get_singleton()->get_property_list(&pinfo); @@ -237,7 +233,6 @@ void Input::get_argument_options(const StringName &p_function, int p_idx, List<S } void Input::SpeedTrack::update(const Vector2 &p_delta_p) { - uint64_t tick = OS::get_singleton()->get_ticks_usec(); uint32_t tdiff = tick - last_tick; float delta_t = tdiff / 1000000.0; @@ -250,7 +245,6 @@ void Input::SpeedTrack::update(const Vector2 &p_delta_p) { accum_t = max_ref_frame * 10; while (accum_t >= min_ref_frame) { - float slice_t = min_ref_frame / accum_t; Vector2 slice = accum * slice_t; accum = accum - slice; @@ -267,42 +261,35 @@ void Input::SpeedTrack::reset() { } Input::SpeedTrack::SpeedTrack() { - min_ref_frame = 0.1; max_ref_frame = 0.3; reset(); } bool Input::is_key_pressed(int p_keycode) const { - _THREAD_SAFE_METHOD_ return keys_pressed.has(p_keycode); } bool Input::is_mouse_button_pressed(int p_button) const { - _THREAD_SAFE_METHOD_ return (mouse_button_mask & (1 << (p_button - 1))) != 0; } static int _combine_device(int p_value, int p_device) { - return p_value | (p_device << 20); } bool Input::is_joy_button_pressed(int p_device, int p_button) const { - _THREAD_SAFE_METHOD_ return joy_buttons_pressed.has(_combine_device(p_button, p_device)); } bool Input::is_action_pressed(const StringName &p_action) const { - return action_state.has(p_action) && action_state[p_action].pressed; } bool Input::is_action_just_pressed(const StringName &p_action) const { - const Map<StringName, Action>::Element *E = action_state.find(p_action); if (!E) return false; @@ -315,7 +302,6 @@ bool Input::is_action_just_pressed(const StringName &p_action) const { } bool Input::is_action_just_released(const StringName &p_action) const { - const Map<StringName, Action>::Element *E = action_state.find(p_action); if (!E) return false; @@ -336,7 +322,6 @@ float Input::get_action_strength(const StringName &p_action) const { } float Input::get_joy_axis(int p_device, int p_axis) const { - _THREAD_SAFE_METHOD_ int c = _combine_device(p_axis, p_device); if (_joy_axis.has(c)) { @@ -347,7 +332,6 @@ float Input::get_joy_axis(int p_device, int p_axis) const { } String Input::get_joy_name(int p_idx) { - _THREAD_SAFE_METHOD_ return joy_names[p_idx].name; }; @@ -377,7 +361,6 @@ float Input::get_joy_vibration_duration(int p_device) { } static String _hex_str(uint8_t p_byte) { - static const char *dict = "0123456789abcdef"; char ret[3]; ret[2] = 0; @@ -389,14 +372,12 @@ static String _hex_str(uint8_t p_byte) { }; void Input::joy_connection_changed(int p_idx, bool p_connected, String p_name, String p_guid) { - _THREAD_SAFE_METHOD_ Joypad js; js.name = p_connected ? p_name : ""; js.uid = p_connected ? p_guid : ""; if (p_connected) { - String uidname = p_guid; if (p_guid == "") { int uidlen = MIN(p_name.length(), 16); @@ -430,36 +411,30 @@ void Input::joy_connection_changed(int p_idx, bool p_connected, String p_name, S }; Vector3 Input::get_gravity() const { - _THREAD_SAFE_METHOD_ return gravity; } Vector3 Input::get_accelerometer() const { - _THREAD_SAFE_METHOD_ return accelerometer; } Vector3 Input::get_magnetometer() const { - _THREAD_SAFE_METHOD_ return magnetometer; } Vector3 Input::get_gyroscope() const { - _THREAD_SAFE_METHOD_ return gyroscope; } void Input::parse_input_event(const Ref<InputEvent> &p_event) { - _parse_input_event_impl(p_event, false); } void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_emulated) { - // Notes on mouse-touch emulation: // - Emulated mouse events are parsed, that is, re-routed to this method, so they make the same effects // as true mouse events. The only difference is the situation is flagged as emulated so they are not @@ -480,7 +455,6 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em Ref<InputEventMouseButton> mb = p_event; if (mb.is_valid()) { - if (mb->is_pressed()) { mouse_button_mask |= (1 << (mb->get_button_index() - 1)); } else { @@ -504,7 +478,6 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em Ref<InputEventMouseMotion> mm = p_event; if (mm.is_valid()) { - Point2 pos = mm->get_global_position(); if (mouse_pos != pos) { set_mouse_position(pos); @@ -525,7 +498,6 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em Ref<InputEventScreenTouch> st = p_event; if (st.is_valid()) { - if (st->is_pressed()) { SpeedTrack &track = touch_speed_track[st->get_index()]; track.reset(); @@ -536,7 +508,6 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em } if (emulate_mouse_from_touch) { - bool translate = false; if (st->is_pressed()) { if (mouse_from_touch_index == -1) { @@ -573,13 +544,11 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em Ref<InputEventScreenDrag> sd = p_event; if (sd.is_valid()) { - SpeedTrack &track = touch_speed_track[sd->get_index()]; track.update(sd->get_relative()); sd->set_speed(track.speed); if (emulate_mouse_from_touch && sd->get_index() == mouse_from_touch_index) { - Ref<InputEventMouseMotion> motion_event; motion_event.instance(); @@ -597,7 +566,6 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em Ref<InputEventJoypadButton> jb = p_event; if (jb.is_valid()) { - int c = _combine_device(jb->get_button_index(), jb->get_device()); if (jb->is_pressed()) @@ -615,7 +583,6 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em Ref<InputEventGesture> ge = p_event; if (ge.is_valid()) { - if (event_dispatch_function) { event_dispatch_function(ge); } @@ -623,7 +590,6 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em for (const Map<StringName, InputMap::Action>::Element *E = InputMap::get_singleton()->get_action_map().front(); E; E = E->next()) { if (InputMap::get_singleton()->event_is_action(p_event, E->key())) { - // Save the action's state if (!p_event->is_echo() && is_action_pressed(E->key()) != p_event->is_action_pressed(E->key())) { Action action; @@ -642,7 +608,6 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em } void Input::set_joy_axis(int p_device, int p_axis, float p_value) { - _THREAD_SAFE_METHOD_ int c = _combine_device(p_axis, p_device); _joy_axis[c] = p_value; @@ -676,50 +641,42 @@ void Input::vibrate_handheld(int p_duration_ms) { } void Input::set_gravity(const Vector3 &p_gravity) { - _THREAD_SAFE_METHOD_ gravity = p_gravity; } void Input::set_accelerometer(const Vector3 &p_accel) { - _THREAD_SAFE_METHOD_ accelerometer = p_accel; } void Input::set_magnetometer(const Vector3 &p_magnetometer) { - _THREAD_SAFE_METHOD_ magnetometer = p_magnetometer; } void Input::set_gyroscope(const Vector3 &p_gyroscope) { - _THREAD_SAFE_METHOD_ gyroscope = p_gyroscope; } void Input::set_mouse_position(const Point2 &p_posf) { - mouse_speed_track.update(p_posf - mouse_pos); mouse_pos = p_posf; } Point2 Input::get_mouse_position() const { - return mouse_pos; } Point2 Input::get_last_mouse_speed() const { - return mouse_speed_track.speed; } int Input::get_mouse_button_mask() const { - return mouse_button_mask; // do not trust OS implementation, should remove it - OS::get_singleton()->get_mouse_button_state(); } @@ -728,7 +685,6 @@ void Input::warp_mouse_position(const Vector2 &p_to) { } Point2i Input::warp_mouse_motion(const Ref<InputEventMouseMotion> &p_motion, const Rect2 &p_rect) { - // The relative distance reported for the next event after a warp is in the boundaries of the // size of the rect on that axis, but it may be greater, in which case there's not problem as fmod() // will warp it, but if the pointer has moved in the opposite direction between the pointer relocation @@ -757,7 +713,6 @@ void Input::iteration(float p_step) { } void Input::action_press(const StringName &p_action, float p_strength) { - Action action; action.physics_frame = Engine::get_singleton()->get_physics_frames(); @@ -769,7 +724,6 @@ void Input::action_press(const StringName &p_action, float p_strength) { } void Input::action_release(const StringName &p_action) { - Action action; action.physics_frame = Engine::get_singleton()->get_physics_frames(); @@ -781,19 +735,16 @@ void Input::action_release(const StringName &p_action) { } void Input::set_emulate_touch_from_mouse(bool p_emulate) { - emulate_touch_from_mouse = p_emulate; } bool Input::is_emulating_touch_from_mouse() const { - return emulate_touch_from_mouse; } // Calling this whenever the game window is focused helps unstucking the "touch mouse" // if the OS or its abstraction class hasn't properly reported that touch pointers raised void Input::ensure_touch_mouse_raised() { - if (mouse_from_touch_index != -1) { mouse_from_touch_index = -1; @@ -812,22 +763,18 @@ void Input::ensure_touch_mouse_raised() { } void Input::set_emulate_mouse_from_touch(bool p_emulate) { - emulate_mouse_from_touch = p_emulate; } bool Input::is_emulating_mouse_from_touch() const { - return emulate_mouse_from_touch; } Input::CursorShape Input::get_default_cursor_shape() const { - return default_shape; } void Input::set_default_cursor_shape(CursorShape p_shape) { - if (default_shape == p_shape) return; @@ -842,7 +789,6 @@ void Input::set_default_cursor_shape(CursorShape p_shape) { } Input::CursorShape Input::get_current_cursor_shape() const { - return get_current_cursor_shape_func(); } @@ -867,7 +813,6 @@ void Input::accumulate_input_event(const Ref<InputEvent> &p_event) { accumulated_events.push_back(p_event); } void Input::flush_accumulated_events() { - while (accumulated_events.front()) { parse_input_event(accumulated_events.front()->get()); accumulated_events.pop_front(); @@ -875,12 +820,10 @@ void Input::flush_accumulated_events() { } void Input::set_use_accumulated_input(bool p_enable) { - use_accumulated_input = p_enable; } void Input::release_pressed_events() { - flush_accumulated_events(); // this is needed to release actions strengths keys_pressed.clear(); @@ -898,7 +841,6 @@ void Input::set_event_dispatch_function(EventDispatchFunc p_function) { } void Input::joy_button(int p_device, int p_button, bool p_pressed) { - _THREAD_SAFE_METHOD_; Joypad &joy = joy_names[p_device]; //printf("got button %i, mapping is %i\n", p_button, joy.mapping); @@ -925,7 +867,6 @@ void Input::joy_button(int p_device, int p_button, bool p_pressed) { } void Input::joy_axis(int p_device, int p_axis, const JoyAxis &p_value) { - _THREAD_SAFE_METHOD_; ERR_FAIL_INDEX(p_axis, JOY_AXIS_MAX); @@ -937,13 +878,10 @@ void Input::joy_axis(int p_device, int p_axis, const JoyAxis &p_value) { } if (p_value.value > joy.last_axis[p_axis]) { - if (p_value.value < joy.last_axis[p_axis] + joy.filter) { - return; } } else if (p_value.value > joy.last_axis[p_axis] - joy.filter) { - return; } @@ -972,7 +910,6 @@ void Input::joy_axis(int p_device, int p_axis, const JoyAxis &p_value) { JoyEvent map = _get_mapped_axis_event(map_db[joy.mapping], p_axis, p_value); if (map.type == TYPE_BUTTON) { - if (map.index == JOY_BUTTON_DPAD_UP || map.index == JOY_BUTTON_DPAD_DOWN) { bool pressed = p_value.value != 0.0f; int button = p_value.value < 0 ? JOY_BUTTON_DPAD_UP : JOY_BUTTON_DPAD_DOWN; @@ -1023,7 +960,6 @@ void Input::joy_axis(int p_device, int p_axis, const JoyAxis &p_value) { } if (map.type == TYPE_AXIS) { - _axis_event(p_device, map.index, map.value); return; } @@ -1031,7 +967,6 @@ void Input::joy_axis(int p_device, int p_axis, const JoyAxis &p_value) { } void Input::joy_hat(int p_device, int p_val) { - _THREAD_SAFE_METHOD_; const Joypad &joy = joy_names[p_device]; @@ -1077,7 +1012,6 @@ void Input::joy_hat(int p_device, int p_val) { } void Input::_button_event(int p_device, int p_index, bool p_pressed) { - Ref<InputEventJoypadButton> ievent; ievent.instance(); ievent->set_device(p_device); @@ -1088,7 +1022,6 @@ void Input::_button_event(int p_device, int p_index, bool p_pressed) { } void Input::_axis_event(int p_device, int p_axis, float p_value) { - Ref<InputEventJoypadMotion> ievent; ievent.instance(); ievent->set_device(p_device); @@ -1099,7 +1032,6 @@ void Input::_axis_event(int p_device, int p_axis, float p_value) { }; Input::JoyEvent Input::_get_mapped_button_event(const JoyDeviceMapping &mapping, int p_button) { - JoyEvent event; event.type = TYPE_MAX; @@ -1123,7 +1055,6 @@ Input::JoyEvent Input::_get_mapped_button_event(const JoyDeviceMapping &mapping, } Input::JoyEvent Input::_get_mapped_axis_event(const JoyDeviceMapping &mapping, int p_axis, const JoyAxis &p_value) { - JoyEvent event; event.type = TYPE_MAX; @@ -1180,11 +1111,9 @@ Input::JoyEvent Input::_get_mapped_axis_event(const JoyDeviceMapping &mapping, i } void Input::_get_mapped_hat_events(const JoyDeviceMapping &mapping, int p_hat, JoyEvent r_events[]) { - for (int i = 0; i < mapping.bindings.size(); i++) { const JoyBinding binding = mapping.bindings[i]; if (binding.inputType == TYPE_HAT && binding.input.hat.hat == p_hat) { - int index; switch (binding.input.hat.hat_mask) { case HAT_MASK_UP: @@ -1220,7 +1149,6 @@ void Input::_get_mapped_hat_events(const JoyDeviceMapping &mapping, int p_hat, J } JoyButtonList Input::_get_output_button(String output) { - for (int i = 0; _joy_buttons[i]; i++) { if (output == _joy_buttons[i]) return JoyButtonList(i); @@ -1229,7 +1157,6 @@ JoyButtonList Input::_get_output_button(String output) { } JoyAxisList Input::_get_output_axis(String output) { - for (int i = 0; _joy_axes[i]; i++) { if (output == _joy_axes[i]) return JoyAxisList(i); @@ -1238,7 +1165,6 @@ JoyAxisList Input::_get_output_axis(String output) { } void Input::parse_mapping(String p_mapping) { - _THREAD_SAFE_METHOD_; JoyDeviceMapping mapping; @@ -1255,7 +1181,6 @@ void Input::parse_mapping(String p_mapping) { int idx = 1; while (++idx < entry.size()) { - if (entry[idx] == "") continue; @@ -1361,7 +1286,6 @@ void Input::remove_joy_mapping(String p_guid) { } void Input::set_fallback_mapping(String p_guid) { - for (int i = 0; i < map_db.size(); i++) { if (map_db[i].uid == p_guid) { fallback_mapping = i; @@ -1431,7 +1355,6 @@ int Input::get_joy_axis_index_from_string(String p_axis) { } Input::Input() { - singleton = this; // Parse default mappings. diff --git a/core/input/input.h b/core/input/input.h index f3150a8127..91e3b83b95 100644 --- a/core/input/input.h +++ b/core/input/input.h @@ -128,7 +128,6 @@ private: int mouse_from_touch_index = -1; struct SpeedTrack { - uint64_t last_tick; Vector2 speed; Vector2 accum; diff --git a/core/input/input_event.cpp b/core/input/input_event.cpp index 9d3f8f9424..094ed0bc56 100644 --- a/core/input/input_event.cpp +++ b/core/input/input_event.cpp @@ -45,26 +45,22 @@ int InputEvent::get_device() const { } bool InputEvent::is_action(const StringName &p_action) const { - return InputMap::get_singleton()->event_is_action(Ref<InputEvent>((InputEvent *)this), p_action); } bool InputEvent::is_action_pressed(const StringName &p_action, bool p_allow_echo) const { - bool pressed; bool valid = InputMap::get_singleton()->event_get_action_status(Ref<InputEvent>((InputEvent *)this), p_action, &pressed); return valid && pressed && (p_allow_echo || !is_echo()); } bool InputEvent::is_action_released(const StringName &p_action) const { - bool pressed; bool valid = InputMap::get_singleton()->event_get_action_status(Ref<InputEvent>((InputEvent *)this), p_action, &pressed); return valid && !pressed; } float InputEvent::get_action_strength(const StringName &p_action) const { - bool pressed; float strength; bool valid = InputMap::get_singleton()->event_get_action_status(Ref<InputEvent>((InputEvent *)this), p_action, &pressed, &strength); @@ -72,42 +68,34 @@ float InputEvent::get_action_strength(const StringName &p_action) const { } bool InputEvent::is_pressed() const { - return false; } bool InputEvent::is_echo() const { - return false; } Ref<InputEvent> InputEvent::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const { - return Ref<InputEvent>((InputEvent *)this); } String InputEvent::as_text() const { - return String(); } bool InputEvent::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const { - return false; } bool InputEvent::shortcut_match(const Ref<InputEvent> &p_event) const { - return false; } bool InputEvent::is_action_type() const { - return false; } void InputEvent::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_device", "device"), &InputEvent::set_device); ClassDB::bind_method(D_METHOD("get_device"), &InputEvent::get_device); @@ -135,7 +123,6 @@ void InputEvent::_bind_methods() { /////////////////////////////////// void InputEventFromWindow::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_window_id", "id"), &InputEventFromWindow::set_window_id); ClassDB::bind_method(D_METHOD("get_window_id"), &InputEventFromWindow::get_window_id); ADD_PROPERTY(PropertyInfo(Variant::INT, "window_id"), "set_window_id", "get_window_id"); @@ -151,53 +138,42 @@ int64_t InputEventFromWindow::get_window_id() const { /////////////////////////////////// void InputEventWithModifiers::set_shift(bool p_enabled) { - shift = p_enabled; } bool InputEventWithModifiers::get_shift() const { - return shift; } void InputEventWithModifiers::set_alt(bool p_enabled) { - alt = p_enabled; } bool InputEventWithModifiers::get_alt() const { - return alt; } void InputEventWithModifiers::set_control(bool p_enabled) { - control = p_enabled; } bool InputEventWithModifiers::get_control() const { - return control; } void InputEventWithModifiers::set_metakey(bool p_enabled) { - meta = p_enabled; } bool InputEventWithModifiers::get_metakey() const { - return meta; } void InputEventWithModifiers::set_command(bool p_enabled) { - command = p_enabled; } bool InputEventWithModifiers::get_command() const { - return command; } void InputEventWithModifiers::set_modifiers_from_event(const InputEventWithModifiers *event) { - set_alt(event->get_alt()); set_shift(event->get_shift()); set_control(event->get_control()); @@ -205,7 +181,6 @@ void InputEventWithModifiers::set_modifiers_from_event(const InputEventWithModif } void InputEventWithModifiers::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_alt", "enable"), &InputEventWithModifiers::set_alt); ClassDB::bind_method(D_METHOD("get_alt"), &InputEventWithModifiers::get_alt); @@ -231,57 +206,46 @@ void InputEventWithModifiers::_bind_methods() { /////////////////////////////////// void InputEventKey::set_pressed(bool p_pressed) { - pressed = p_pressed; } bool InputEventKey::is_pressed() const { - return pressed; } void InputEventKey::set_keycode(uint32_t p_keycode) { - keycode = p_keycode; } uint32_t InputEventKey::get_keycode() const { - return keycode; } void InputEventKey::set_physical_keycode(uint32_t p_keycode) { - physical_keycode = p_keycode; } uint32_t InputEventKey::get_physical_keycode() const { - return physical_keycode; } void InputEventKey::set_unicode(uint32_t p_unicode) { - unicode = p_unicode; } uint32_t InputEventKey::get_unicode() const { - return unicode; } void InputEventKey::set_echo(bool p_enable) { - echo = p_enable; } bool InputEventKey::is_echo() const { - return echo; } uint32_t InputEventKey::get_keycode_with_modifiers() const { - uint32_t sc = keycode; if (get_control()) sc |= KEY_MASK_CTRL; @@ -296,7 +260,6 @@ uint32_t InputEventKey::get_keycode_with_modifiers() const { } uint32_t InputEventKey::get_physical_keycode_with_modifiers() const { - uint32_t sc = physical_keycode; if (get_control()) sc |= KEY_MASK_CTRL; @@ -311,7 +274,6 @@ uint32_t InputEventKey::get_physical_keycode_with_modifiers() const { } String InputEventKey::as_text() const { - String kc = keycode_get_string(keycode); if (kc == String()) return kc; @@ -332,7 +294,6 @@ String InputEventKey::as_text() const { } bool InputEventKey::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const { - Ref<InputEventKey> key = p_event; if (key.is_null()) return false; @@ -359,7 +320,6 @@ bool InputEventKey::action_match(const Ref<InputEvent> &p_event, bool *p_pressed } bool InputEventKey::shortcut_match(const Ref<InputEvent> &p_event) const { - Ref<InputEventKey> key = p_event; if (key.is_null()) return false; @@ -371,7 +331,6 @@ bool InputEventKey::shortcut_match(const Ref<InputEvent> &p_event) const { } void InputEventKey::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_pressed", "pressed"), &InputEventKey::set_pressed); ClassDB::bind_method(D_METHOD("set_keycode", "keycode"), &InputEventKey::set_keycode); @@ -398,34 +357,27 @@ void InputEventKey::_bind_methods() { /////////////////////////////////// void InputEventMouse::set_button_mask(int p_mask) { - button_mask = p_mask; } int InputEventMouse::get_button_mask() const { - return button_mask; } void InputEventMouse::set_position(const Vector2 &p_pos) { - pos = p_pos; } Vector2 InputEventMouse::get_position() const { - return pos; } void InputEventMouse::set_global_position(const Vector2 &p_global_pos) { - global_pos = p_global_pos; } Vector2 InputEventMouse::get_global_position() const { - return global_pos; } void InputEventMouse::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_button_mask", "button_mask"), &InputEventMouse::set_button_mask); ClassDB::bind_method(D_METHOD("get_button_mask"), &InputEventMouse::get_button_mask); @@ -443,44 +395,35 @@ void InputEventMouse::_bind_methods() { /////////////////////////////////// void InputEventMouseButton::set_factor(float p_factor) { - factor = p_factor; } float InputEventMouseButton::get_factor() const { - return factor; } void InputEventMouseButton::set_button_index(int p_index) { - button_index = p_index; } int InputEventMouseButton::get_button_index() const { - return button_index; } void InputEventMouseButton::set_pressed(bool p_pressed) { - pressed = p_pressed; } bool InputEventMouseButton::is_pressed() const { - return pressed; } void InputEventMouseButton::set_doubleclick(bool p_doubleclick) { - doubleclick = p_doubleclick; } bool InputEventMouseButton::is_doubleclick() const { - return doubleclick; } Ref<InputEvent> InputEventMouseButton::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const { - Vector2 g = get_global_position(); Vector2 l = p_xform.xform(get_position() + p_local_ofs); @@ -504,7 +447,6 @@ Ref<InputEvent> InputEventMouseButton::xformed_by(const Transform2D &p_xform, co } bool InputEventMouseButton::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const { - Ref<InputEventMouseButton> mb = p_event; if (mb.is_null()) return false; @@ -521,7 +463,6 @@ bool InputEventMouseButton::action_match(const Ref<InputEvent> &p_event, bool *p } String InputEventMouseButton::as_text() const { - String button_index_string = ""; switch (get_button_index()) { case BUTTON_LEFT: @@ -559,7 +500,6 @@ String InputEventMouseButton::as_text() const { } void InputEventMouseButton::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_factor", "factor"), &InputEventMouseButton::set_factor); ClassDB::bind_method(D_METHOD("get_factor"), &InputEventMouseButton::get_factor); @@ -581,47 +521,38 @@ void InputEventMouseButton::_bind_methods() { /////////////////////////////////// void InputEventMouseMotion::set_tilt(const Vector2 &p_tilt) { - tilt = p_tilt; } Vector2 InputEventMouseMotion::get_tilt() const { - return tilt; } void InputEventMouseMotion::set_pressure(float p_pressure) { - pressure = p_pressure; } float InputEventMouseMotion::get_pressure() const { - return pressure; } void InputEventMouseMotion::set_relative(const Vector2 &p_relative) { - relative = p_relative; } Vector2 InputEventMouseMotion::get_relative() const { - return relative; } void InputEventMouseMotion::set_speed(const Vector2 &p_speed) { - speed = p_speed; } Vector2 InputEventMouseMotion::get_speed() const { - return speed; } Ref<InputEvent> InputEventMouseMotion::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const { - Vector2 g = get_global_position(); Vector2 l = p_xform.xform(get_position() + p_local_ofs); Vector2 r = p_xform.basis_xform(get_relative()); @@ -648,7 +579,6 @@ Ref<InputEvent> InputEventMouseMotion::xformed_by(const Transform2D &p_xform, co } String InputEventMouseMotion::as_text() const { - String button_mask_string = ""; switch (get_button_mask()) { case BUTTON_MASK_LEFT: @@ -674,7 +604,6 @@ String InputEventMouseMotion::as_text() const { } bool InputEventMouseMotion::accumulate(const Ref<InputEvent> &p_event) { - Ref<InputEventMouseMotion> motion = p_event; if (motion.is_null()) return false; @@ -716,7 +645,6 @@ bool InputEventMouseMotion::accumulate(const Ref<InputEvent> &p_event) { } void InputEventMouseMotion::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_tilt", "tilt"), &InputEventMouseMotion::set_tilt); ClassDB::bind_method(D_METHOD("get_tilt"), &InputEventMouseMotion::get_tilt); @@ -738,32 +666,26 @@ void InputEventMouseMotion::_bind_methods() { /////////////////////////////////// void InputEventJoypadMotion::set_axis(int p_axis) { - axis = p_axis; } int InputEventJoypadMotion::get_axis() const { - return axis; } void InputEventJoypadMotion::set_axis_value(float p_value) { - axis_value = p_value; } float InputEventJoypadMotion::get_axis_value() const { - return axis_value; } bool InputEventJoypadMotion::is_pressed() const { - return Math::abs(axis_value) >= 0.5f; } bool InputEventJoypadMotion::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const { - Ref<InputEventJoypadMotion> jm = p_event; if (jm.is_null()) return false; @@ -790,12 +712,10 @@ bool InputEventJoypadMotion::action_match(const Ref<InputEvent> &p_event, bool * } String InputEventJoypadMotion::as_text() const { - return "InputEventJoypadMotion : axis=" + itos(axis) + ", axis_value=" + String(Variant(axis_value)); } void InputEventJoypadMotion::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_axis", "axis"), &InputEventJoypadMotion::set_axis); ClassDB::bind_method(D_METHOD("get_axis"), &InputEventJoypadMotion::get_axis); @@ -809,35 +729,28 @@ void InputEventJoypadMotion::_bind_methods() { /////////////////////////////////// void InputEventJoypadButton::set_button_index(int p_index) { - button_index = p_index; } int InputEventJoypadButton::get_button_index() const { - return button_index; } void InputEventJoypadButton::set_pressed(bool p_pressed) { - pressed = p_pressed; } bool InputEventJoypadButton::is_pressed() const { - return pressed; } void InputEventJoypadButton::set_pressure(float p_pressure) { - pressure = p_pressure; } float InputEventJoypadButton::get_pressure() const { - return pressure; } bool InputEventJoypadButton::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const { - Ref<InputEventJoypadButton> jb = p_event; if (jb.is_null()) return false; @@ -854,7 +767,6 @@ bool InputEventJoypadButton::action_match(const Ref<InputEvent> &p_event, bool * } bool InputEventJoypadButton::shortcut_match(const Ref<InputEvent> &p_event) const { - Ref<InputEventJoypadButton> button = p_event; if (button.is_null()) return false; @@ -863,12 +775,10 @@ bool InputEventJoypadButton::shortcut_match(const Ref<InputEvent> &p_event) cons } String InputEventJoypadButton::as_text() const { - return "InputEventJoypadButton : button_index=" + itos(button_index) + ", pressed=" + (pressed ? "true" : "false") + ", pressure=" + String(Variant(pressure)); } void InputEventJoypadButton::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_button_index", "button_index"), &InputEventJoypadButton::set_button_index); ClassDB::bind_method(D_METHOD("get_button_index"), &InputEventJoypadButton::get_button_index); @@ -886,34 +796,27 @@ void InputEventJoypadButton::_bind_methods() { /////////////////////////////////// void InputEventScreenTouch::set_index(int p_index) { - index = p_index; } int InputEventScreenTouch::get_index() const { - return index; } void InputEventScreenTouch::set_position(const Vector2 &p_pos) { - pos = p_pos; } Vector2 InputEventScreenTouch::get_position() const { - return pos; } void InputEventScreenTouch::set_pressed(bool p_pressed) { - pressed = p_pressed; } bool InputEventScreenTouch::is_pressed() const { - return pressed; } Ref<InputEvent> InputEventScreenTouch::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const { - Ref<InputEventScreenTouch> st; st.instance(); st->set_device(get_device()); @@ -926,12 +829,10 @@ Ref<InputEvent> InputEventScreenTouch::xformed_by(const Transform2D &p_xform, co } String InputEventScreenTouch::as_text() const { - return "InputEventScreenTouch : index=" + itos(index) + ", pressed=" + (pressed ? "true" : "false") + ", position=(" + String(get_position()) + ")"; } void InputEventScreenTouch::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_index", "index"), &InputEventScreenTouch::set_index); ClassDB::bind_method(D_METHOD("get_index"), &InputEventScreenTouch::get_index); @@ -949,44 +850,35 @@ void InputEventScreenTouch::_bind_methods() { /////////////////////////////////// void InputEventScreenDrag::set_index(int p_index) { - index = p_index; } int InputEventScreenDrag::get_index() const { - return index; } void InputEventScreenDrag::set_position(const Vector2 &p_pos) { - pos = p_pos; } Vector2 InputEventScreenDrag::get_position() const { - return pos; } void InputEventScreenDrag::set_relative(const Vector2 &p_relative) { - relative = p_relative; } Vector2 InputEventScreenDrag::get_relative() const { - return relative; } void InputEventScreenDrag::set_speed(const Vector2 &p_speed) { - speed = p_speed; } Vector2 InputEventScreenDrag::get_speed() const { - return speed; } Ref<InputEvent> InputEventScreenDrag::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const { - Ref<InputEventScreenDrag> sd; sd.instance(); @@ -1003,12 +895,10 @@ Ref<InputEvent> InputEventScreenDrag::xformed_by(const Transform2D &p_xform, con } String InputEventScreenDrag::as_text() const { - return "InputEventScreenDrag : index=" + itos(index) + ", position=(" + String(get_position()) + "), relative=(" + String(get_relative()) + "), speed=(" + String(get_speed()) + ")"; } void InputEventScreenDrag::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_index", "index"), &InputEventScreenDrag::set_index); ClassDB::bind_method(D_METHOD("get_index"), &InputEventScreenDrag::get_index); @@ -1030,20 +920,16 @@ void InputEventScreenDrag::_bind_methods() { /////////////////////////////////// void InputEventAction::set_action(const StringName &p_action) { - action = p_action; } StringName InputEventAction::get_action() const { - return action; } void InputEventAction::set_pressed(bool p_pressed) { - pressed = p_pressed; } bool InputEventAction::is_pressed() const { - return pressed; } @@ -1063,12 +949,10 @@ bool InputEventAction::shortcut_match(const Ref<InputEvent> &p_event) const { } bool InputEventAction::is_action(const StringName &p_action) const { - return action == p_action; } bool InputEventAction::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const { - Ref<InputEventAction> act = p_event; if (act.is_null()) return false; @@ -1084,12 +968,10 @@ bool InputEventAction::action_match(const Ref<InputEvent> &p_event, bool *p_pres } String InputEventAction::as_text() const { - return "InputEventAction : action=" + action + ", pressed=(" + (pressed ? "true" : "false"); } void InputEventAction::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_action", "action"), &InputEventAction::set_action); ClassDB::bind_method(D_METHOD("get_action"), &InputEventAction::get_action); @@ -1109,12 +991,10 @@ void InputEventAction::_bind_methods() { /////////////////////////////////// void InputEventGesture::set_position(const Vector2 &p_pos) { - pos = p_pos; } void InputEventGesture::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_position", "position"), &InputEventGesture::set_position); ClassDB::bind_method(D_METHOD("get_position"), &InputEventGesture::get_position); @@ -1122,24 +1002,20 @@ void InputEventGesture::_bind_methods() { } Vector2 InputEventGesture::get_position() const { - return pos; } /////////////////////////////////// void InputEventMagnifyGesture::set_factor(real_t p_factor) { - factor = p_factor; } real_t InputEventMagnifyGesture::get_factor() const { - return factor; } Ref<InputEvent> InputEventMagnifyGesture::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const { - Ref<InputEventMagnifyGesture> ev; ev.instance(); @@ -1155,12 +1031,10 @@ Ref<InputEvent> InputEventMagnifyGesture::xformed_by(const Transform2D &p_xform, } String InputEventMagnifyGesture::as_text() const { - return "InputEventMagnifyGesture : factor=" + rtos(get_factor()) + ", position=(" + String(get_position()) + ")"; } void InputEventMagnifyGesture::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_factor", "factor"), &InputEventMagnifyGesture::set_factor); ClassDB::bind_method(D_METHOD("get_factor"), &InputEventMagnifyGesture::get_factor); @@ -1170,7 +1044,6 @@ void InputEventMagnifyGesture::_bind_methods() { /////////////////////////////////// void InputEventPanGesture::set_delta(const Vector2 &p_delta) { - delta = p_delta; } @@ -1179,7 +1052,6 @@ Vector2 InputEventPanGesture::get_delta() const { } Ref<InputEvent> InputEventPanGesture::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const { - Ref<InputEventPanGesture> ev; ev.instance(); @@ -1195,12 +1067,10 @@ Ref<InputEvent> InputEventPanGesture::xformed_by(const Transform2D &p_xform, con } String InputEventPanGesture::as_text() const { - return "InputEventPanGesture : delta=(" + String(get_delta()) + "), position=(" + String(get_position()) + ")"; } void InputEventPanGesture::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_delta", "delta"), &InputEventPanGesture::set_delta); ClassDB::bind_method(D_METHOD("get_delta"), &InputEventPanGesture::get_delta); @@ -1210,7 +1080,6 @@ void InputEventPanGesture::_bind_methods() { /////////////////////////////////// void InputEventMIDI::set_channel(const int p_channel) { - channel = p_channel; } @@ -1219,7 +1088,6 @@ int InputEventMIDI::get_channel() const { } void InputEventMIDI::set_message(const int p_message) { - message = p_message; } @@ -1228,7 +1096,6 @@ int InputEventMIDI::get_message() const { } void InputEventMIDI::set_pitch(const int p_pitch) { - pitch = p_pitch; } @@ -1237,7 +1104,6 @@ int InputEventMIDI::get_pitch() const { } void InputEventMIDI::set_velocity(const int p_velocity) { - velocity = p_velocity; } @@ -1246,7 +1112,6 @@ int InputEventMIDI::get_velocity() const { } void InputEventMIDI::set_instrument(const int p_instrument) { - instrument = p_instrument; } @@ -1255,7 +1120,6 @@ int InputEventMIDI::get_instrument() const { } void InputEventMIDI::set_pressure(const int p_pressure) { - pressure = p_pressure; } @@ -1264,7 +1128,6 @@ int InputEventMIDI::get_pressure() const { } void InputEventMIDI::set_controller_number(const int p_controller_number) { - controller_number = p_controller_number; } @@ -1273,7 +1136,6 @@ int InputEventMIDI::get_controller_number() const { } void InputEventMIDI::set_controller_value(const int p_controller_value) { - controller_value = p_controller_value; } @@ -1282,12 +1144,10 @@ int InputEventMIDI::get_controller_value() const { } String InputEventMIDI::as_text() const { - return "InputEventMIDI : channel=(" + itos(get_channel()) + "), message=(" + itos(get_message()) + ")"; } void InputEventMIDI::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_channel", "channel"), &InputEventMIDI::set_channel); ClassDB::bind_method(D_METHOD("get_channel"), &InputEventMIDI::get_channel); ClassDB::bind_method(D_METHOD("set_message", "message"), &InputEventMIDI::set_message); diff --git a/core/input/input_event.h b/core/input/input_event.h index 18792076f5..dd1cc11982 100644 --- a/core/input/input_event.h +++ b/core/input/input_event.h @@ -192,7 +192,6 @@ public: }; class InputEventFromWindow : public InputEvent { - GDCLASS(InputEventFromWindow, InputEvent); int64_t window_id = 0; @@ -252,7 +251,6 @@ public: }; class InputEventKey : public InputEventWithModifiers { - GDCLASS(InputEventKey, InputEventWithModifiers); bool pressed = false; /// otherwise release @@ -296,7 +294,6 @@ public: }; class InputEventMouse : public InputEventWithModifiers { - GDCLASS(InputEventMouse, InputEventWithModifiers); int button_mask = 0; @@ -321,7 +318,6 @@ public: }; class InputEventMouseButton : public InputEventMouse { - GDCLASS(InputEventMouseButton, InputEventMouse); float factor = 1; @@ -355,7 +351,6 @@ public: }; class InputEventMouseMotion : public InputEventMouse { - GDCLASS(InputEventMouseMotion, InputEventMouse); Vector2 tilt; @@ -388,7 +383,6 @@ public: }; class InputEventJoypadMotion : public InputEvent { - GDCLASS(InputEventJoypadMotion, InputEvent); int axis = 0; ///< Joypad axis float axis_value = 0; ///< -1 to 1 @@ -467,7 +461,6 @@ public: }; class InputEventScreenDrag : public InputEventFromWindow { - GDCLASS(InputEventScreenDrag, InputEventFromWindow); int index = 0; Vector2 pos; @@ -497,7 +490,6 @@ public: }; class InputEventAction : public InputEvent { - GDCLASS(InputEventAction, InputEvent); StringName action; @@ -529,7 +521,6 @@ public: }; class InputEventGesture : public InputEventWithModifiers { - GDCLASS(InputEventGesture, InputEventWithModifiers); Vector2 pos; @@ -543,7 +534,6 @@ public: }; class InputEventMagnifyGesture : public InputEventGesture { - GDCLASS(InputEventMagnifyGesture, InputEventGesture); real_t factor = 1.0; @@ -561,7 +551,6 @@ public: }; class InputEventPanGesture : public InputEventGesture { - GDCLASS(InputEventPanGesture, InputEventGesture); Vector2 delta; diff --git a/core/input/input_map.cpp b/core/input/input_map.cpp index 6b6acf062d..d341b5ba4c 100644 --- a/core/input/input_map.cpp +++ b/core/input/input_map.cpp @@ -38,7 +38,6 @@ InputMap *InputMap::singleton = nullptr; int InputMap::ALL_DEVICES = -1; void InputMap::_bind_methods() { - ClassDB::bind_method(D_METHOD("has_action", "action"), &InputMap::has_action); ClassDB::bind_method(D_METHOD("get_actions"), &InputMap::_get_actions); ClassDB::bind_method(D_METHOD("add_action", "action", "deadzone"), &InputMap::add_action, DEFVAL(0.5f)); @@ -55,7 +54,6 @@ void InputMap::_bind_methods() { } void InputMap::add_action(const StringName &p_action, float p_deadzone) { - ERR_FAIL_COND_MSG(input_map.has(p_action), "InputMap already has action '" + String(p_action) + "'."); input_map[p_action] = Action(); static int last_id = 1; @@ -65,20 +63,17 @@ void InputMap::add_action(const StringName &p_action, float p_deadzone) { } void InputMap::erase_action(const StringName &p_action) { - ERR_FAIL_COND_MSG(!input_map.has(p_action), "Request for nonexistent InputMap action '" + String(p_action) + "'."); input_map.erase(p_action); } Array InputMap::_get_actions() { - Array ret; List<StringName> actions = get_actions(); if (actions.empty()) return ret; for (const List<StringName>::Element *E = actions.front(); E; E = E->next()) { - ret.push_back(E->get()); } @@ -86,7 +81,6 @@ Array InputMap::_get_actions() { } List<StringName> InputMap::get_actions() const { - List<StringName> actions = List<StringName>(); if (input_map.empty()) { return actions; @@ -100,9 +94,7 @@ List<StringName> InputMap::get_actions() const { } List<Ref<InputEvent>>::Element *InputMap::_find_event(Action &p_action, const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength) const { - for (List<Ref<InputEvent>>::Element *E = p_action.inputs.front(); E; E = E->next()) { - const Ref<InputEvent> e = E->get(); //if (e.type != Ref<InputEvent>::KEY && e.device != p_event.device) -- unsure about the KEY comparison, why is this here? @@ -120,19 +112,16 @@ List<Ref<InputEvent>>::Element *InputMap::_find_event(Action &p_action, const Re } bool InputMap::has_action(const StringName &p_action) const { - return input_map.has(p_action); } void InputMap::action_set_deadzone(const StringName &p_action, float p_deadzone) { - ERR_FAIL_COND_MSG(!input_map.has(p_action), "Request for nonexistent InputMap action '" + String(p_action) + "'."); input_map[p_action].deadzone = p_deadzone; } void InputMap::action_add_event(const StringName &p_action, const Ref<InputEvent> &p_event) { - ERR_FAIL_COND_MSG(p_event.is_null(), "It's not a reference to a valid InputEvent object."); ERR_FAIL_COND_MSG(!input_map.has(p_action), "Request for nonexistent InputMap action '" + String(p_action) + "'."); if (_find_event(input_map[p_action], p_event)) @@ -142,13 +131,11 @@ void InputMap::action_add_event(const StringName &p_action, const Ref<InputEvent } bool InputMap::action_has_event(const StringName &p_action, const Ref<InputEvent> &p_event) { - ERR_FAIL_COND_V_MSG(!input_map.has(p_action), false, "Request for nonexistent InputMap action '" + String(p_action) + "'."); return (_find_event(input_map[p_action], p_event) != nullptr); } void InputMap::action_erase_event(const StringName &p_action, const Ref<InputEvent> &p_event) { - ERR_FAIL_COND_MSG(!input_map.has(p_action), "Request for nonexistent InputMap action '" + String(p_action) + "'."); List<Ref<InputEvent>>::Element *E = _find_event(input_map[p_action], p_event); @@ -157,19 +144,16 @@ void InputMap::action_erase_event(const StringName &p_action, const Ref<InputEve } void InputMap::action_erase_events(const StringName &p_action) { - ERR_FAIL_COND_MSG(!input_map.has(p_action), "Request for nonexistent InputMap action '" + String(p_action) + "'."); input_map[p_action].inputs.clear(); } Array InputMap::_get_action_list(const StringName &p_action) { - Array ret; const List<Ref<InputEvent>> *al = get_action_list(p_action); if (al) { for (const List<Ref<InputEvent>>::Element *E = al->front(); E; E = E->next()) { - ret.push_back(E->get()); } } @@ -178,7 +162,6 @@ Array InputMap::_get_action_list(const StringName &p_action) { } const List<Ref<InputEvent>> *InputMap::get_action_list(const StringName &p_action) { - const Map<StringName, Action>::Element *E = input_map.find(p_action); if (!E) return nullptr; @@ -222,7 +205,6 @@ const Map<StringName, InputMap::Action> &InputMap::get_action_map() const { } void InputMap::load_from_globals() { - input_map.clear(); List<PropertyInfo> pinfo; @@ -251,7 +233,6 @@ void InputMap::load_from_globals() { } void InputMap::load_default() { - Ref<InputEventKey> key; add_action("ui_accept"); @@ -332,7 +313,6 @@ void InputMap::load_default() { } InputMap::InputMap() { - ERR_FAIL_COND_MSG(singleton, "Singleton in InputMap already exist."); singleton = this; } diff --git a/core/input/input_map.h b/core/input/input_map.h index e03bc5fd4f..3abc224ccf 100644 --- a/core/input/input_map.h +++ b/core/input/input_map.h @@ -35,7 +35,6 @@ #include "core/object.h" class InputMap : public Object { - GDCLASS(InputMap, Object); public: |