diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/config/engine.cpp | 10 | ||||
-rw-r--r-- | core/config/engine.h | 5 | ||||
-rw-r--r-- | core/core_constants.cpp | 41 | ||||
-rw-r--r-- | core/input/input.cpp | 106 | ||||
-rw-r--r-- | core/input/input.h | 5 | ||||
-rw-r--r-- | core/input/input_event.cpp | 34 | ||||
-rw-r--r-- | core/input/input_event.h | 63 | ||||
-rw-r--r-- | core/input/input_map.cpp | 4 | ||||
-rw-r--r-- | core/input/input_map.h | 2 | ||||
-rw-r--r-- | core/io/resource.cpp | 8 |
10 files changed, 77 insertions, 201 deletions
diff --git a/core/config/engine.cpp b/core/config/engine.cpp index b0037ffb37..8e2ab094b0 100644 --- a/core/config/engine.cpp +++ b/core/config/engine.cpp @@ -219,3 +219,13 @@ Engine *Engine::get_singleton() { Engine::Engine() { singleton = this; } + +Engine::Singleton::Singleton(const StringName &p_name, Object *p_ptr) : + name(p_name), + ptr(p_ptr) { +#ifdef DEBUG_ENABLED + if (Object::cast_to<Reference>(p_ptr)) { + ERR_PRINT("A class intended to be used as a singleton must *not* inherit from Reference."); + } +#endif +} diff --git a/core/config/engine.h b/core/config/engine.h index 1d3d963b39..0d9aa02f28 100644 --- a/core/config/engine.h +++ b/core/config/engine.h @@ -41,10 +41,7 @@ public: struct Singleton { StringName name; Object *ptr; - Singleton(const StringName &p_name = StringName(), Object *p_ptr = nullptr) : - name(p_name), - ptr(p_ptr) { - } + Singleton(const StringName &p_name = StringName(), Object *p_ptr = nullptr); }; private: diff --git a/core/core_constants.cpp b/core/core_constants.cpp index 4229436e84..64bfff1c58 100644 --- a/core/core_constants.cpp +++ b/core/core_constants.cpp @@ -409,7 +409,7 @@ void register_global_constants() { BIND_CORE_ENUM_CONSTANT(BUTTON_MASK_XBUTTON2); // Joypad buttons - BIND_CORE_ENUM_CONSTANT(JOY_INVALID_BUTTON); + BIND_CORE_ENUM_CONSTANT(JOY_BUTTON_INVALID); BIND_CORE_ENUM_CONSTANT(JOY_BUTTON_A); BIND_CORE_ENUM_CONSTANT(JOY_BUTTON_B); BIND_CORE_ENUM_CONSTANT(JOY_BUTTON_X); @@ -425,51 +425,18 @@ void register_global_constants() { BIND_CORE_ENUM_CONSTANT(JOY_BUTTON_DPAD_DOWN); BIND_CORE_ENUM_CONSTANT(JOY_BUTTON_DPAD_LEFT); BIND_CORE_ENUM_CONSTANT(JOY_BUTTON_DPAD_RIGHT); - BIND_CORE_ENUM_CONSTANT(JOY_SDL_BUTTONS); - BIND_CORE_ENUM_CONSTANT(JOY_SONY_X); - BIND_CORE_ENUM_CONSTANT(JOY_SONY_CROSS); - BIND_CORE_ENUM_CONSTANT(JOY_SONY_CIRCLE); - BIND_CORE_ENUM_CONSTANT(JOY_SONY_SQUARE); - BIND_CORE_ENUM_CONSTANT(JOY_SONY_TRIANGLE); - BIND_CORE_ENUM_CONSTANT(JOY_SONY_SELECT); - BIND_CORE_ENUM_CONSTANT(JOY_SONY_START); - BIND_CORE_ENUM_CONSTANT(JOY_SONY_PS); - BIND_CORE_ENUM_CONSTANT(JOY_SONY_L1); - BIND_CORE_ENUM_CONSTANT(JOY_SONY_R1); - BIND_CORE_ENUM_CONSTANT(JOY_SONY_L3); - BIND_CORE_ENUM_CONSTANT(JOY_SONY_R3); - BIND_CORE_ENUM_CONSTANT(JOY_XBOX_A); - BIND_CORE_ENUM_CONSTANT(JOY_XBOX_B); - BIND_CORE_ENUM_CONSTANT(JOY_XBOX_X); - BIND_CORE_ENUM_CONSTANT(JOY_XBOX_Y); - BIND_CORE_ENUM_CONSTANT(JOY_XBOX_BACK); - BIND_CORE_ENUM_CONSTANT(JOY_XBOX_START); - BIND_CORE_ENUM_CONSTANT(JOY_XBOX_HOME); - BIND_CORE_ENUM_CONSTANT(JOY_XBOX_LS); - BIND_CORE_ENUM_CONSTANT(JOY_XBOX_RS); - BIND_CORE_ENUM_CONSTANT(JOY_XBOX_LB); - BIND_CORE_ENUM_CONSTANT(JOY_XBOX_RB); + BIND_CORE_ENUM_CONSTANT(JOY_BUTTON_SDL_MAX); BIND_CORE_ENUM_CONSTANT(JOY_BUTTON_MAX); // Joypad axes - BIND_CORE_ENUM_CONSTANT(JOY_INVALID_AXIS); + BIND_CORE_ENUM_CONSTANT(JOY_AXIS_INVALID); BIND_CORE_ENUM_CONSTANT(JOY_AXIS_LEFT_X); BIND_CORE_ENUM_CONSTANT(JOY_AXIS_LEFT_Y); BIND_CORE_ENUM_CONSTANT(JOY_AXIS_RIGHT_X); BIND_CORE_ENUM_CONSTANT(JOY_AXIS_RIGHT_Y); BIND_CORE_ENUM_CONSTANT(JOY_AXIS_TRIGGER_LEFT); BIND_CORE_ENUM_CONSTANT(JOY_AXIS_TRIGGER_RIGHT); - BIND_CORE_ENUM_CONSTANT(JOY_SDL_AXES); - BIND_CORE_ENUM_CONSTANT(JOY_AXIS_0_X); - BIND_CORE_ENUM_CONSTANT(JOY_AXIS_0_Y); - BIND_CORE_ENUM_CONSTANT(JOY_AXIS_1_X); - BIND_CORE_ENUM_CONSTANT(JOY_AXIS_1_Y); - BIND_CORE_ENUM_CONSTANT(JOY_AXIS_2_X); - BIND_CORE_ENUM_CONSTANT(JOY_AXIS_2_Y); - BIND_CORE_ENUM_CONSTANT(JOY_AXIS_3_X); - BIND_CORE_ENUM_CONSTANT(JOY_AXIS_3_Y); - BIND_CORE_ENUM_CONSTANT(JOY_AXIS_4_X); - BIND_CORE_ENUM_CONSTANT(JOY_AXIS_4_Y); + BIND_CORE_ENUM_CONSTANT(JOY_AXIS_SDL_MAX); BIND_CORE_ENUM_CONSTANT(JOY_AXIS_MAX); // midi diff --git a/core/input/input.cpp b/core/input/input.cpp index aa64ac09a7..00a7e63a73 100644 --- a/core/input/input.cpp +++ b/core/input/input.cpp @@ -39,7 +39,7 @@ #include "editor/editor_settings.h" #endif -static const char *_joy_buttons[JOY_SDL_BUTTONS + 1] = { +static const char *_joy_buttons[JOY_BUTTON_SDL_MAX] = { "a", "b", "x", @@ -55,69 +55,15 @@ static const char *_joy_buttons[JOY_SDL_BUTTONS + 1] = { "dpdown", "dpleft", "dpright", - nullptr }; -static const char *_joy_button_names[JOY_BUTTON_MAX] = { - "Face Bottom", - "Face Right", - "Face Left", - "Face Top", - "Select", - "Guide", - "Start", - "Left Stick", - "Right Stick", - "Left Shoulder", - "Right Shoulder", - "D-Pad Up", - "D-Pad Down", - "D-Pad Left", - "D-Pad Right", - "Button 15", - "Button 16", - "Button 17", - "Button 18", - "Button 19", - "Button 20", - "Button 21", - "Button 22", - "Button 23", - "Button 24", - "Button 25", - "Button 26", - "Button 27", - "Button 28", - "Button 29", - "Button 30", - "Button 31", - "Button 32", - "Button 33", - "Button 34", - "Button 35" -}; - -static const char *_joy_axes[JOY_SDL_AXES + 1] = { +static const char *_joy_axes[JOY_AXIS_SDL_MAX] = { "leftx", "lefty", "rightx", "righty", "lefttrigger", "righttrigger", - nullptr -}; - -static const char *_joy_axis_names[JOY_AXIS_MAX] = { - "Left Stick X", - "Left Stick Y", - "Right Stick X", - "Right Stick Y", - "Left Trigger", - "Right Trigger", - "Joystick 3 Stick X", - "Joystick 3 Stick Y", - "Joystick 4 Stick X", - "Joystick 4 Stick Y" }; Input *Input::singleton = nullptr; @@ -162,10 +108,6 @@ void Input::_bind_methods() { ClassDB::bind_method(D_METHOD("get_connected_joypads"), &Input::get_connected_joypads); ClassDB::bind_method(D_METHOD("get_joy_vibration_strength", "device"), &Input::get_joy_vibration_strength); ClassDB::bind_method(D_METHOD("get_joy_vibration_duration", "device"), &Input::get_joy_vibration_duration); - ClassDB::bind_method(D_METHOD("get_joy_button_string", "button_index"), &Input::get_joy_button_string); - ClassDB::bind_method(D_METHOD("get_joy_button_index_from_string", "button"), &Input::get_joy_button_index_from_string); - ClassDB::bind_method(D_METHOD("get_joy_axis_string", "axis_index"), &Input::get_joy_axis_string); - ClassDB::bind_method(D_METHOD("get_joy_axis_index_from_string", "axis"), &Input::get_joy_axis_index_from_string); ClassDB::bind_method(D_METHOD("start_joy_vibration", "device", "weak_magnitude", "strong_magnitude", "duration"), &Input::start_joy_vibration, DEFVAL(0)); ClassDB::bind_method(D_METHOD("stop_joy_vibration", "device"), &Input::stop_joy_vibration); ClassDB::bind_method(D_METHOD("vibrate_handheld", "duration_ms"), &Input::vibrate_handheld, DEFVAL(500)); @@ -1226,21 +1168,21 @@ 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++) { + for (int i = 0; i < JOY_BUTTON_SDL_MAX; i++) { if (output == _joy_buttons[i]) { return JoyButtonList(i); } } - return JoyButtonList::JOY_INVALID_BUTTON; + return JoyButtonList::JOY_BUTTON_INVALID; } JoyAxisList Input::_get_output_axis(String output) { - for (int i = 0; _joy_axes[i]; i++) { + for (int i = 0; i < JOY_AXIS_SDL_MAX; i++) { if (output == _joy_axes[i]) { return JoyAxisList(i); } } - return JoyAxisList::JOY_INVALID_AXIS; + return JoyAxisList::JOY_AXIS_INVALID; } void Input::parse_mapping(String p_mapping) { @@ -1300,16 +1242,16 @@ void Input::parse_mapping(String p_mapping) { JoyButtonList output_button = _get_output_button(output); JoyAxisList output_axis = _get_output_axis(output); - ERR_CONTINUE_MSG(output_button == JOY_INVALID_BUTTON && output_axis == JOY_INVALID_AXIS, + ERR_CONTINUE_MSG(output_button == JOY_BUTTON_INVALID && output_axis == JOY_AXIS_INVALID, String(entry[idx] + "\nUnrecognised output string: " + output)); - ERR_CONTINUE_MSG(output_button != JOY_INVALID_BUTTON && output_axis != JOY_INVALID_AXIS, + ERR_CONTINUE_MSG(output_button != JOY_BUTTON_INVALID && output_axis != JOY_AXIS_INVALID, String("BUG: Output string matched both button and axis: " + output)); JoyBinding binding; - if (output_button != JOY_INVALID_BUTTON) { + if (output_button != JOY_BUTTON_INVALID) { binding.outputType = TYPE_BUTTON; binding.output.button = output_button; - } else if (output_axis != JOY_INVALID_AXIS) { + } else if (output_axis != JOY_AXIS_INVALID) { binding.outputType = TYPE_AXIS; binding.output.axis.axis = output_axis; binding.output.axis.range = output_range; @@ -1401,20 +1343,6 @@ Array Input::get_connected_joypads() { return ret; } -String Input::get_joy_button_string(int p_button) { - ERR_FAIL_INDEX_V(p_button, JOY_BUTTON_MAX, "Invalid button"); - return _joy_button_names[p_button]; -} - -int Input::get_joy_button_index_from_string(String p_button) { - for (int i = 0; i < JOY_BUTTON_MAX; i++) { - if (p_button == _joy_button_names[i]) { - return i; - } - } - ERR_FAIL_V(JOY_INVALID_BUTTON); -} - int Input::get_unused_joy_id() { for (int i = 0; i < JOYPADS_MAX; i++) { if (!joy_names.has(i) || !joy_names[i].connected) { @@ -1424,20 +1352,6 @@ int Input::get_unused_joy_id() { return -1; } -String Input::get_joy_axis_string(int p_axis) { - ERR_FAIL_INDEX_V(p_axis, JOY_AXIS_MAX, "Invalid axis"); - return _joy_axis_names[p_axis]; -} - -int Input::get_joy_axis_index_from_string(String p_axis) { - for (int i = 0; i < JOY_AXIS_MAX; i++) { - if (p_axis == _joy_axis_names[i]) { - return i; - } - } - ERR_FAIL_V(JOY_INVALID_AXIS); -} - Input::Input() { singleton = this; diff --git a/core/input/input.h b/core/input/input.h index 46e9d24bf2..1b2df49ac0 100644 --- a/core/input/input.h +++ b/core/input/input.h @@ -330,11 +330,6 @@ public: void add_joy_mapping(String p_mapping, bool p_update_existing = false); void remove_joy_mapping(String p_guid); - String get_joy_button_string(int p_button); - String get_joy_axis_string(int p_axis); - int get_joy_axis_index_from_string(String p_axis); - int get_joy_button_index_from_string(String p_button); - int get_unused_joy_id(); bool is_joy_known(int p_device); diff --git a/core/input/input_event.cpp b/core/input/input_event.cpp index 31ce1bb892..41bc5e84b0 100644 --- a/core/input/input_event.cpp +++ b/core/input/input_event.cpp @@ -143,6 +143,14 @@ int64_t InputEventFromWindow::get_window_id() const { /////////////////////////////////// +void InputEventWithModifiers::set_store_command(bool p_enabled) { + store_command = p_enabled; +} + +bool InputEventWithModifiers::is_storing_command() const { + return store_command; +} + void InputEventWithModifiers::set_shift(bool p_enabled) { shift = p_enabled; } @@ -191,6 +199,9 @@ void InputEventWithModifiers::set_modifiers_from_event(const InputEventWithModif } void InputEventWithModifiers::_bind_methods() { + ClassDB::bind_method(D_METHOD("set_store_command", "enable"), &InputEventWithModifiers::set_store_command); + ClassDB::bind_method(D_METHOD("is_storing_command"), &InputEventWithModifiers::is_storing_command); + ClassDB::bind_method(D_METHOD("set_alt", "enable"), &InputEventWithModifiers::set_alt); ClassDB::bind_method(D_METHOD("get_alt"), &InputEventWithModifiers::get_alt); @@ -206,6 +217,7 @@ void InputEventWithModifiers::_bind_methods() { ClassDB::bind_method(D_METHOD("set_command", "enable"), &InputEventWithModifiers::set_command); ClassDB::bind_method(D_METHOD("get_command"), &InputEventWithModifiers::get_command); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "store_command"), "set_store_command", "is_storing_command"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "alt"), "set_alt", "get_alt"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "shift"), "set_shift", "get_shift"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "control"), "set_control", "get_control"); @@ -213,6 +225,28 @@ void InputEventWithModifiers::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "command"), "set_command", "get_command"); } +void InputEventWithModifiers::_validate_property(PropertyInfo &property) const { + if (store_command) { + // If we only want to Store "Command". +#ifdef APPLE_STYLE_KEYS + // Don't store "Meta" on Mac. + if (property.name == "meta") { + property.usage ^= PROPERTY_USAGE_STORAGE; + } +#else + // Don't store "Control". + if (property.name == "control") { + property.usage ^= PROPERTY_USAGE_STORAGE; + } +#endif + } else { + // We don't want to store command, only control or meta (on mac). + if (property.name == "command") { + property.usage ^= PROPERTY_USAGE_STORAGE; + } + } +} + /////////////////////////////////// void InputEventKey::set_pressed(bool p_pressed) { diff --git a/core/input/input_event.h b/core/input/input_event.h index dc86bddf8e..0eae3a2bbe 100644 --- a/core/input/input_event.h +++ b/core/input/input_event.h @@ -60,9 +60,7 @@ enum ButtonList { }; enum JoyButtonList { - JOY_INVALID_BUTTON = -1, - - // SDL Buttons + JOY_BUTTON_INVALID = -1, JOY_BUTTON_A = 0, JOY_BUTTON_B = 1, JOY_BUTTON_X = 2, @@ -78,63 +76,20 @@ enum JoyButtonList { JOY_BUTTON_DPAD_DOWN = 12, JOY_BUTTON_DPAD_LEFT = 13, JOY_BUTTON_DPAD_RIGHT = 14, - JOY_SDL_BUTTONS = 15, - - // Sony Buttons - JOY_SONY_X = JOY_BUTTON_A, - JOY_SONY_CROSS = JOY_BUTTON_A, - JOY_SONY_CIRCLE = JOY_BUTTON_B, - JOY_SONY_SQUARE = JOY_BUTTON_X, - JOY_SONY_TRIANGLE = JOY_BUTTON_Y, - JOY_SONY_SELECT = JOY_BUTTON_BACK, - JOY_SONY_START = JOY_BUTTON_START, - JOY_SONY_PS = JOY_BUTTON_GUIDE, - JOY_SONY_L1 = JOY_BUTTON_LEFT_SHOULDER, - JOY_SONY_R1 = JOY_BUTTON_RIGHT_SHOULDER, - JOY_SONY_L3 = JOY_BUTTON_LEFT_STICK, - JOY_SONY_R3 = JOY_BUTTON_RIGHT_STICK, - - // Xbox Buttons - JOY_XBOX_A = JOY_BUTTON_A, - JOY_XBOX_B = JOY_BUTTON_B, - JOY_XBOX_X = JOY_BUTTON_X, - JOY_XBOX_Y = JOY_BUTTON_Y, - JOY_XBOX_BACK = JOY_BUTTON_BACK, - JOY_XBOX_START = JOY_BUTTON_START, - JOY_XBOX_HOME = JOY_BUTTON_GUIDE, - JOY_XBOX_LS = JOY_BUTTON_LEFT_STICK, - JOY_XBOX_RS = JOY_BUTTON_RIGHT_STICK, - JOY_XBOX_LB = JOY_BUTTON_LEFT_SHOULDER, - JOY_XBOX_RB = JOY_BUTTON_RIGHT_SHOULDER, - - JOY_BUTTON_MAX = 36 // Apparently Android supports up to 36 buttons. + JOY_BUTTON_SDL_MAX = 15, + JOY_BUTTON_MAX = 36, // Android supports up to 36 buttons. }; enum JoyAxisList { - JOY_INVALID_AXIS = -1, - - // SDL Axes + JOY_AXIS_INVALID = -1, JOY_AXIS_LEFT_X = 0, JOY_AXIS_LEFT_Y = 1, JOY_AXIS_RIGHT_X = 2, JOY_AXIS_RIGHT_Y = 3, JOY_AXIS_TRIGGER_LEFT = 4, JOY_AXIS_TRIGGER_RIGHT = 5, - JOY_SDL_AXES = 6, - - // Joystick axes. - JOY_AXIS_0_X = 0, - JOY_AXIS_0_Y = 1, - JOY_AXIS_1_X = 2, - JOY_AXIS_1_Y = 3, - JOY_AXIS_2_X = 4, - JOY_AXIS_2_Y = 5, - JOY_AXIS_3_X = 6, - JOY_AXIS_3_Y = 7, - JOY_AXIS_4_X = 8, - JOY_AXIS_4_Y = 9, - - JOY_AXIS_MAX = 10 // OpenVR supports up to 5 Joysticks making a total of 10 axes. + JOY_AXIS_SDL_MAX = 6, + JOY_AXIS_MAX = 10, // OpenVR supports up to 5 Joysticks making a total of 10 axes. }; enum MidiMessageList { @@ -208,6 +163,8 @@ public: class InputEventWithModifiers : public InputEventFromWindow { GDCLASS(InputEventWithModifiers, InputEventFromWindow); + bool store_command = true; + bool shift = false; bool alt = false; #ifdef APPLE_STYLE_KEYS @@ -227,8 +184,12 @@ class InputEventWithModifiers : public InputEventFromWindow { protected: static void _bind_methods(); + virtual void _validate_property(PropertyInfo &property) const override; public: + void set_store_command(bool p_enabled); + bool is_storing_command() const; + void set_shift(bool p_enabled); bool get_shift() const; diff --git a/core/input/input_map.cpp b/core/input/input_map.cpp index 9fd5476f51..979809c7af 100644 --- a/core/input/input_map.cpp +++ b/core/input/input_map.cpp @@ -51,7 +51,7 @@ void InputMap::_bind_methods() { ClassDB::bind_method(D_METHOD("action_erase_events", "action"), &InputMap::action_erase_events); ClassDB::bind_method(D_METHOD("action_get_events", "action"), &InputMap::_action_get_events); ClassDB::bind_method(D_METHOD("event_is_action", "event", "action"), &InputMap::event_is_action); - ClassDB::bind_method(D_METHOD("load_from_globals"), &InputMap::load_from_globals); + ClassDB::bind_method(D_METHOD("load_from_project_settings"), &InputMap::load_from_project_settings); } void InputMap::add_action(const StringName &p_action, float p_deadzone) { @@ -228,7 +228,7 @@ const Map<StringName, InputMap::Action> &InputMap::get_action_map() const { return input_map; } -void InputMap::load_from_globals() { +void InputMap::load_from_project_settings() { input_map.clear(); List<PropertyInfo> pinfo; diff --git a/core/input/input_map.h b/core/input/input_map.h index 019a1056fb..948d78ebdd 100644 --- a/core/input/input_map.h +++ b/core/input/input_map.h @@ -82,7 +82,7 @@ public: bool event_get_action_status(const Ref<InputEvent> &p_event, const StringName &p_action, bool *p_pressed = nullptr, float *p_strength = nullptr, float *p_raw_strength = nullptr) const; const Map<StringName, Action> &get_action_map() const; - void load_from_globals(); + void load_from_project_settings(); void load_default(); InputMap(); diff --git a/core/io/resource.cpp b/core/io/resource.cpp index 08f5021889..58ab9a8cde 100644 --- a/core/io/resource.cpp +++ b/core/io/resource.cpp @@ -147,8 +147,8 @@ Ref<Resource> Resource::duplicate_for_local_scene(Node *p_for_scene, Map<Ref<Res List<PropertyInfo> plist; get_property_list(&plist); - Resource *r = Object::cast_to<Resource>(ClassDB::instance(get_class())); - ERR_FAIL_COND_V(!r, Ref<Resource>()); + Ref<Resource> r = Object::cast_to<Resource>(ClassDB::instance(get_class())); + ERR_FAIL_COND_V(r.is_null(), Ref<Resource>()); r->local_scene = p_for_scene; @@ -175,9 +175,7 @@ Ref<Resource> Resource::duplicate_for_local_scene(Node *p_for_scene, Map<Ref<Res r->set(E->get().name, p); } - RES res = Ref<Resource>(r); - - return res; + return r; } void Resource::configure_for_local_scene(Node *p_for_scene, Map<Ref<Resource>, Ref<Resource>> &remap_cache) { |