diff options
-rw-r--r-- | core/ustring.cpp | 3 | ||||
-rw-r--r-- | core/ustring.h | 20 | ||||
-rw-r--r-- | editor/plugins/animation_blend_tree_editor_plugin.cpp | 1 | ||||
-rw-r--r-- | main/input_default.cpp | 8 | ||||
-rw-r--r-- | main/tests/test_string.cpp | 28 | ||||
-rw-r--r-- | modules/gdscript/gdscript_editor.cpp | 8 | ||||
-rw-r--r-- | scene/2d/camera_2d.cpp | 1 |
7 files changed, 61 insertions, 8 deletions
diff --git a/core/ustring.cpp b/core/ustring.cpp index 75fe36dd37..311aa52d40 100644 --- a/core/ustring.cpp +++ b/core/ustring.cpp @@ -58,6 +58,9 @@ #define IS_DIGIT(m_d) ((m_d) >= '0' && (m_d) <= '9') #define IS_HEX_DIGIT(m_d) (((m_d) >= '0' && (m_d) <= '9') || ((m_d) >= 'a' && (m_d) <= 'f') || ((m_d) >= 'A' && (m_d) <= 'F')) +const char CharString::_null = 0; +const CharType String::_null = 0; + bool is_symbol(CharType c) { return c != '_' && ((c >= '!' && c <= '/') || (c >= ':' && c <= '@') || (c >= '[' && c <= '`') || (c >= '{' && c <= '~') || c == '\t' || c == ' '); } diff --git a/core/ustring.h b/core/ustring.h index b6cfb81e70..1773e94b0e 100644 --- a/core/ustring.h +++ b/core/ustring.h @@ -47,6 +47,7 @@ class CharProxy { const int _index; CowData<T> &_cowdata; + static const T _null = 0; _FORCE_INLINE_ CharProxy(const int &p_index, CowData<T> &cowdata) : _index(p_index), @@ -54,6 +55,9 @@ class CharProxy { public: _FORCE_INLINE_ operator T() const { + if (unlikely(_index == _cowdata.size())) + return _null; + return _cowdata.get(_index); } @@ -73,6 +77,7 @@ public: class CharString { CowData<char> _cowdata; + static const char _null; public: _FORCE_INLINE_ char *ptrw() { return _cowdata.ptrw(); } @@ -83,7 +88,12 @@ public: _FORCE_INLINE_ char get(int p_index) { return _cowdata.get(p_index); } _FORCE_INLINE_ const char get(int p_index) const { return _cowdata.get(p_index); } _FORCE_INLINE_ void set(int p_index, const char &p_elem) { _cowdata.set(p_index, p_elem); } - _FORCE_INLINE_ const char &operator[](int p_index) const { return _cowdata.get(p_index); } + _FORCE_INLINE_ const char &operator[](int p_index) const { + if (unlikely(p_index == _cowdata.size())) + return _null; + + return _cowdata.get(p_index); + } _FORCE_INLINE_ CharProxy<char> operator[](int p_index) { return CharProxy<char>(p_index, _cowdata); } _FORCE_INLINE_ CharString() {} @@ -112,6 +122,7 @@ struct StrRange { class String { CowData<CharType> _cowdata; + static const CharType _null; void copy_from(const char *p_cstr); void copy_from(const CharType *p_cstr, const int p_clip_to = -1); @@ -138,7 +149,12 @@ public: _FORCE_INLINE_ int size() const { return _cowdata.size(); } Error resize(int p_size) { return _cowdata.resize(p_size); } - _FORCE_INLINE_ const CharType &operator[](int p_index) const { return _cowdata.get(p_index); } + _FORCE_INLINE_ const CharType &operator[](int p_index) const { + if (unlikely(p_index == _cowdata.size())) + return _null; + + return _cowdata.get(p_index); + } _FORCE_INLINE_ CharProxy<CharType> operator[](int p_index) { return CharProxy<CharType>(p_index, _cowdata); } bool operator==(const String &p_str) const; diff --git a/editor/plugins/animation_blend_tree_editor_plugin.cpp b/editor/plugins/animation_blend_tree_editor_plugin.cpp index 9a07bf93c0..a5b730dffd 100644 --- a/editor/plugins/animation_blend_tree_editor_plugin.cpp +++ b/editor/plugins/animation_blend_tree_editor_plugin.cpp @@ -134,7 +134,6 @@ void AnimationNodeBlendTreeEditor::_update_graph() { node->set_offset(blend_tree->get_node_position(E->get()) * EDSCALE); node->set_title(agnode->get_caption()); - node->set_human_readable_collision_renaming(false); node->set_name(E->get()); int base = 0; diff --git a/main/input_default.cpp b/main/input_default.cpp index 2b7bc3f671..18b4649f4d 100644 --- a/main/input_default.cpp +++ b/main/input_default.cpp @@ -1084,7 +1084,7 @@ Array InputDefault::get_connected_joypads() { return ret; } -static const char *_buttons[] = { +static const char *_buttons[JOY_BUTTON_MAX] = { "Face Button Bottom", "Face Button Right", "Face Button Left", @@ -1103,7 +1103,7 @@ static const char *_buttons[] = { "DPAD Right" }; -static const char *_axes[] = { +static const char *_axes[JOY_AXIS_MAX] = { "Left Stick X", "Left Stick Y", "Right Stick X", @@ -1111,7 +1111,9 @@ static const char *_axes[] = { "", "", "L2", - "R2" + "R2", + "", + "" }; String InputDefault::get_joy_button_string(int p_button) { diff --git a/main/tests/test_string.cpp b/main/tests/test_string.cpp index ddc36e807c..b4aeb4d215 100644 --- a/main/tests/test_string.cpp +++ b/main/tests/test_string.cpp @@ -942,6 +942,33 @@ bool test_30() { OS::get_singleton()->print("Capitalize %ls: %ls, %s\n", input.c_str(), output.c_str(), success ? "OK" : "FAIL"); return state; +} + +bool test_31() { + bool state = true; + bool success; + + String a = ""; + success = a[0] == 0; + OS::get_singleton()->print("Is 0 String[0]:, %s\n", success ? "OK" : "FAIL"); + if (!success) state = false; + + String b = "Godot"; + success = b[b.size()] == 0; + OS::get_singleton()->print("Is 0 String[size()]:, %s\n", success ? "OK" : "FAIL"); + if (!success) state = false; + + const String c = ""; + success = c[0] == 0; + OS::get_singleton()->print("Is 0 const String[0]:, %s\n", success ? "OK" : "FAIL"); + if (!success) state = false; + + const String d = "Godot"; + success = d[d.size()] == 0; + OS::get_singleton()->print("Is 0 const String[size()]:, %s\n", success ? "OK" : "FAIL"); + if (!success) state = false; + + return state; }; typedef bool (*TestFunc)(void); @@ -978,6 +1005,7 @@ TestFunc test_funcs[] = { test_28, test_29, test_30, + test_31, 0 }; diff --git a/modules/gdscript/gdscript_editor.cpp b/modules/gdscript/gdscript_editor.cpp index 6f06d518e5..56540b1269 100644 --- a/modules/gdscript/gdscript_editor.cpp +++ b/modules/gdscript/gdscript_editor.cpp @@ -2442,9 +2442,13 @@ Error GDScriptLanguage::complete_code(const String &p_code, const String &p_base context._class = parser.get_completion_class(); context.block = parser.get_completion_block(); context.function = parser.get_completion_function(); - context.base = p_owner; - context.base_path = p_base_path; context.line = parser.get_completion_line(); + + if (!context._class) { + context.base = p_owner; + context.base_path = p_base_path; + } + bool is_function = false; switch (parser.get_completion_type()) { diff --git a/scene/2d/camera_2d.cpp b/scene/2d/camera_2d.cpp index 97accbda3e..aeee301e6e 100644 --- a/scene/2d/camera_2d.cpp +++ b/scene/2d/camera_2d.cpp @@ -410,6 +410,7 @@ void Camera2D::make_current() { } else { get_tree()->call_group_flags(SceneTree::GROUP_CALL_REALTIME, group_name, "_make_current", this); } + _update_scroll(); } void Camera2D::clear_current() { |