summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/config/engine.cpp11
-rw-r--r--core/config/engine.h5
-rw-r--r--core/config/project_settings.cpp4
-rw-r--r--core/config/project_settings.h3
-rw-r--r--core/core_bind.cpp4
-rw-r--r--core/core_bind.h7
-rw-r--r--core/core_constants.cpp45
-rw-r--r--core/crypto/aes_context.cpp1
-rw-r--r--core/crypto/aes_context.h2
-rw-r--r--core/crypto/crypto_core.h8
-rw-r--r--core/crypto/hashing_context.h2
-rw-r--r--core/debugger/debugger_marshalls.cpp2
-rw-r--r--core/debugger/debugger_marshalls.h2
-rw-r--r--core/input/input.cpp165
-rw-r--r--core/input/input.h12
-rw-r--r--core/input/input_event.cpp91
-rw-r--r--core/input/input_event.h78
-rw-r--r--core/input/input_map.cpp26
-rw-r--r--core/input/input_map.h7
-rw-r--r--core/io/file_access_encrypted.h4
-rw-r--r--core/io/file_access_memory.h4
-rw-r--r--core/io/file_access_zip.cpp1
-rw-r--r--core/io/http_client.cpp59
-rw-r--r--core/io/http_client.h4
-rw-r--r--core/io/image.cpp13
-rw-r--r--core/io/image.h6
-rw-r--r--core/io/ip.h2
-rw-r--r--core/io/ip_address.cpp1
-rw-r--r--core/io/json.h1
-rw-r--r--core/io/multiplayer_api.h1
-rw-r--r--core/io/packed_data_container.h2
-rw-r--r--core/io/pck_packer.h8
-rw-r--r--core/io/resource.cpp14
-rw-r--r--core/io/resource_format_binary.cpp2
-rw-r--r--core/io/resource_loader.cpp2
-rw-r--r--core/io/resource_saver.cpp2
-rw-r--r--core/io/resource_saver.h1
-rw-r--r--core/io/stream_peer_tcp.h1
-rw-r--r--core/math/a_star.h16
-rw-r--r--core/math/expression.h22
-rw-r--r--core/math/geometry_3d.cpp2
-rw-r--r--core/math/math_defs.h5
-rw-r--r--core/math/math_fieldwise.cpp10
-rw-r--r--core/math/octree.h1
-rw-r--r--core/math/quick_hull.h10
-rw-r--r--core/object/callable_method_pointer.h3
-rw-r--r--core/object/method_bind.h18
-rw-r--r--core/object/object.cpp3
-rw-r--r--core/object/object.h2
-rw-r--r--core/object/reference.h4
-rw-r--r--core/object/script_language.h1
-rw-r--r--core/os/dir_access.h1
-rw-r--r--core/os/file_access.cpp4
-rw-r--r--core/os/file_access.h1
-rw-r--r--core/os/keyboard.cpp1
-rw-r--r--core/os/keyboard.h3
-rw-r--r--core/os/os.h1
-rw-r--r--core/os/pool_allocator.h1
-rw-r--r--core/os/thread.h1
-rw-r--r--core/string/string_name.h1
-rw-r--r--core/string/ustring.cpp1
-rw-r--r--core/string/ustring.h1
-rw-r--r--core/templates/hash_map.h2
-rw-r--r--core/templates/list.h6
-rw-r--r--core/templates/safe_refcount.h2
-rw-r--r--core/templates/set.h2
-rw-r--r--core/templates/sort_array.h1
-rw-r--r--core/templates/thread_work_pool.h4
-rw-r--r--core/variant/array.cpp2
-rw-r--r--core/variant/binder_common.h26
-rw-r--r--core/variant/callable.h6
-rw-r--r--core/variant/method_ptrcall.h26
-rw-r--r--core/variant/typed_array.h4
-rw-r--r--core/variant/variant.h6
-rw-r--r--core/variant/variant_call.cpp51
-rw-r--r--core/variant/variant_internal.h255
-rw-r--r--core/variant/variant_op.cpp223
-rw-r--r--core/variant/variant_parser.h1
-rw-r--r--core/variant/variant_setget.cpp106
-rw-r--r--core/variant/variant_utility.cpp85
80 files changed, 691 insertions, 833 deletions
diff --git a/core/config/engine.cpp b/core/config/engine.cpp
index b0037ffb37..26f8cdf840 100644
--- a/core/config/engine.cpp
+++ b/core/config/engine.cpp
@@ -219,3 +219,14 @@ 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
+ Reference *ref = Object::cast_to<Reference>(p_ptr);
+ if (ref && !ref->is_referenced()) {
+ WARN_PRINT("You must use Ref<> to ensure the lifetime of a Reference object intended to be used as a singleton.");
+ }
+#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/config/project_settings.cpp b/core/config/project_settings.cpp
index aa954ed300..8b8aff3e9e 100644
--- a/core/config/project_settings.cpp
+++ b/core/config/project_settings.cpp
@@ -524,10 +524,6 @@ bool ProjectSettings::has_setting(String p_var) const {
return props.has(p_var);
}
-void ProjectSettings::set_registering_order(bool p_enable) {
- registering_order = p_enable;
-}
-
Error ProjectSettings::_load_settings_binary(const String &p_path) {
Error err;
FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err);
diff --git a/core/config/project_settings.h b/core/config/project_settings.h
index a8c9adc587..5a16248c76 100644
--- a/core/config/project_settings.h
+++ b/core/config/project_settings.h
@@ -76,7 +76,6 @@ protected:
}
};
- bool registering_order = true;
int last_order = NO_BUILTIN_ORDER_BASE;
int last_builtin_order = 0;
Map<StringName, VariantContainer> props;
@@ -160,8 +159,6 @@ public:
bool is_using_datapack() const;
- void set_registering_order(bool p_enable);
-
bool has_custom_feature(const String &p_feature) const;
Map<StringName, AutoloadInfo> get_autoload_list() const;
diff --git a/core/core_bind.cpp b/core/core_bind.cpp
index f3bdea1eec..259d899d39 100644
--- a/core/core_bind.cpp
+++ b/core/core_bind.cpp
@@ -542,9 +542,9 @@ void _OS::dump_memory_to_file(const String &p_file) {
struct _OSCoreBindImg {
String path;
Size2 size;
- int fmt;
+ int fmt = 0;
ObjectID id;
- int vram;
+ int vram = 0;
bool operator<(const _OSCoreBindImg &p_img) const { return vram == p_img.vram ? id < p_img.id : vram > p_img.vram; }
};
diff --git a/core/core_bind.h b/core/core_bind.h
index 7794750387..f3a77a4fa6 100644
--- a/core/core_bind.h
+++ b/core/core_bind.h
@@ -83,7 +83,6 @@ protected:
public:
enum SaverFlags {
-
FLAG_RELATIVE_PATHS = 1,
FLAG_BUNDLE_RESOURCES = 2,
FLAG_CHANGE_PATH = 4,
@@ -361,7 +360,6 @@ protected:
public:
enum ModeFlags {
-
READ = 1,
WRITE = 2,
READ_WRITE = 3,
@@ -494,8 +492,8 @@ public:
virtual ~_Directory();
private:
- bool _list_skip_navigational;
- bool _list_skip_hidden;
+ bool _list_skip_navigational = false;
+ bool _list_skip_hidden = false;
};
class _Marshalls : public Object {
@@ -561,7 +559,6 @@ protected:
public:
enum Priority {
-
PRIORITY_LOW,
PRIORITY_NORMAL,
PRIORITY_HIGH,
diff --git a/core/core_constants.cpp b/core/core_constants.cpp
index 4229436e84..57ea10c074 100644
--- a/core/core_constants.cpp
+++ b/core/core_constants.cpp
@@ -38,10 +38,10 @@
struct _CoreConstant {
#ifdef DEBUG_METHODS_ENABLED
StringName enum_name;
- bool ignore_value_in_docs;
+ bool ignore_value_in_docs = false;
#endif
const char *name;
- int value;
+ int value = 0;
_CoreConstant() {}
@@ -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/crypto/aes_context.cpp b/core/crypto/aes_context.cpp
index 8ef1f4f1d4..608f3c912c 100644
--- a/core/crypto/aes_context.cpp
+++ b/core/crypto/aes_context.cpp
@@ -112,5 +112,4 @@ void AESContext::_bind_methods() {
}
AESContext::AESContext() {
- mode = MODE_MAX;
}
diff --git a/core/crypto/aes_context.h b/core/crypto/aes_context.h
index c23c504a72..557bde1f04 100644
--- a/core/crypto/aes_context.h
+++ b/core/crypto/aes_context.h
@@ -47,7 +47,7 @@ public:
};
private:
- Mode mode;
+ Mode mode = MODE_MAX;
CryptoCore::AESContext ctx;
PackedByteArray iv;
diff --git a/core/crypto/crypto_core.h b/core/crypto/crypto_core.h
index 57ba469f8d..c2ec6febe3 100644
--- a/core/crypto/crypto_core.h
+++ b/core/crypto/crypto_core.h
@@ -37,7 +37,7 @@ class CryptoCore {
public:
class MD5Context {
private:
- void *ctx; // To include, or not to include...
+ void *ctx = nullptr; // To include, or not to include...
public:
MD5Context();
@@ -50,7 +50,7 @@ public:
class SHA1Context {
private:
- void *ctx; // To include, or not to include...
+ void *ctx = nullptr; // To include, or not to include...
public:
SHA1Context();
@@ -63,7 +63,7 @@ public:
class SHA256Context {
private:
- void *ctx; // To include, or not to include...
+ void *ctx = nullptr; // To include, or not to include...
public:
SHA256Context();
@@ -76,7 +76,7 @@ public:
class AESContext {
private:
- void *ctx; // To include, or not to include...
+ void *ctx = nullptr; // To include, or not to include...
public:
AESContext();
diff --git a/core/crypto/hashing_context.h b/core/crypto/hashing_context.h
index 40d075afa9..7cd55ba267 100644
--- a/core/crypto/hashing_context.h
+++ b/core/crypto/hashing_context.h
@@ -45,7 +45,7 @@ public:
private:
void *ctx = nullptr;
- HashType type;
+ HashType type = HASH_MD5;
protected:
static void _bind_methods();
diff --git a/core/debugger/debugger_marshalls.cpp b/core/debugger/debugger_marshalls.cpp
index 3f949b0ae1..03de832b5e 100644
--- a/core/debugger/debugger_marshalls.cpp
+++ b/core/debugger/debugger_marshalls.cpp
@@ -171,7 +171,7 @@ bool DebuggerMarshalls::ServersProfilerFrame::deserialize(const Array &p_arr) {
}
servers.push_back(si);
}
- CHECK_SIZE(p_arr, idx + 3, "ServersProfilerFrame");
+ CHECK_SIZE(p_arr, idx + 1, "ServersProfilerFrame");
int func_size = p_arr[idx];
idx += 1;
CHECK_SIZE(p_arr, idx + func_size, "ServersProfilerFrame");
diff --git a/core/debugger/debugger_marshalls.h b/core/debugger/debugger_marshalls.h
index f5a1a891bf..0c13790d60 100644
--- a/core/debugger/debugger_marshalls.h
+++ b/core/debugger/debugger_marshalls.h
@@ -148,7 +148,7 @@ struct DebuggerMarshalls {
// Visual Profiler
struct VisualProfilerFrame {
- uint64_t frame_number;
+ uint64_t frame_number = 0;
Vector<RS::FrameProfileArea> areas;
Array serialize();
diff --git a/core/input/input.cpp b/core/input/input.cpp
index ee66bf94cb..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;
@@ -149,6 +95,9 @@ void Input::_bind_methods() {
ClassDB::bind_method(D_METHOD("is_action_just_pressed", "action"), &Input::is_action_just_pressed);
ClassDB::bind_method(D_METHOD("is_action_just_released", "action"), &Input::is_action_just_released);
ClassDB::bind_method(D_METHOD("get_action_strength", "action"), &Input::get_action_strength);
+ ClassDB::bind_method(D_METHOD("get_action_raw_strength", "action"), &Input::get_action_strength);
+ ClassDB::bind_method(D_METHOD("get_axis", "negative_action", "positive_action"), &Input::get_axis);
+ ClassDB::bind_method(D_METHOD("get_vector", "negative_x", "positive_x", "negative_y", "positive_y", "deadzone"), &Input::get_vector, DEFVAL(-1.0f));
ClassDB::bind_method(D_METHOD("add_joy_mapping", "mapping", "update_existing"), &Input::add_joy_mapping, DEFVAL(false));
ClassDB::bind_method(D_METHOD("remove_joy_mapping", "guid"), &Input::remove_joy_mapping);
ClassDB::bind_method(D_METHOD("joy_connection_changed", "device", "connected", "name", "guid"), &Input::joy_connection_changed);
@@ -159,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));
@@ -215,7 +160,9 @@ void Input::get_argument_options(const StringName &p_function, int p_idx, List<S
const String quote_style = EDITOR_DEF("text_editor/completion/use_single_quotes", 0) ? "'" : "\"";
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")) {
+ 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" || pf == "get_axis" || pf == "get_vector")) {
List<PropertyInfo> pinfo;
ProjectSettings::get_singleton()->get_property_list(&pinfo);
@@ -326,6 +273,46 @@ float Input::get_action_strength(const StringName &p_action) const {
return E->get().strength;
}
+float Input::get_action_raw_strength(const StringName &p_action) const {
+ const Map<StringName, Action>::Element *E = action_state.find(p_action);
+ if (!E) {
+ return 0.0f;
+ }
+
+ return E->get().raw_strength;
+}
+
+float Input::get_axis(const StringName &p_negative_action, const StringName &p_positive_action) const {
+ return get_action_strength(p_positive_action) - get_action_strength(p_negative_action);
+}
+
+Vector2 Input::get_vector(const StringName &p_negative_x, const StringName &p_positive_x, const StringName &p_negative_y, const StringName &p_positive_y, float p_deadzone) const {
+ Vector2 vector = Vector2(
+ get_action_raw_strength(p_positive_x) - get_action_raw_strength(p_negative_x),
+ get_action_raw_strength(p_positive_y) - get_action_raw_strength(p_negative_y));
+
+ if (p_deadzone < 0.0f) {
+ // If the deadzone isn't specified, get it from the average of the actions.
+ p_deadzone = (InputMap::get_singleton()->action_get_deadzone(p_positive_x) +
+ InputMap::get_singleton()->action_get_deadzone(p_negative_x) +
+ InputMap::get_singleton()->action_get_deadzone(p_positive_y) +
+ InputMap::get_singleton()->action_get_deadzone(p_negative_y)) /
+ 4;
+ }
+
+ // Circular length limiting and deadzone.
+ float length = vector.length();
+ if (length <= p_deadzone) {
+ return Vector2();
+ } else if (length > 1.0f) {
+ return vector / length;
+ } else {
+ // Inverse lerp length to map (p_deadzone, 1) to (0, 1).
+ return vector * (Math::inverse_lerp(p_deadzone, 1.0f, length) / length);
+ }
+ return vector;
+}
+
float Input::get_joy_axis(int p_device, int p_axis) const {
_THREAD_SAFE_METHOD_
int c = _combine_device(p_axis, p_device);
@@ -603,10 +590,12 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em
action.physics_frame = Engine::get_singleton()->get_physics_frames();
action.idle_frame = Engine::get_singleton()->get_idle_frames();
action.pressed = p_event->is_action_pressed(E->key());
- action.strength = 0.f;
+ action.strength = 0.0f;
+ action.raw_strength = 0.0f;
action_state[E->key()] = action;
}
action_state[E->key()].strength = p_event->get_action_strength(E->key());
+ action_state[E->key()].raw_strength = p_event->get_action_raw_strength(E->key());
}
}
@@ -890,14 +879,6 @@ void Input::joy_axis(int p_device, int p_axis, const JoyAxis &p_value) {
return;
}
- 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;
- }
-
//when changing direction quickly, insert fake event to release pending inputmap actions
float last = joy.last_axis[p_axis];
if (p_value.min == 0 && (last < 0.25 || last > 0.75) && (last - 0.5) * (p_value.value - 0.5) < 0) {
@@ -1187,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) {
@@ -1261,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;
@@ -1362,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) {
@@ -1385,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 98bbff6441..1b2df49ac0 100644
--- a/core/input/input.h
+++ b/core/input/input.h
@@ -117,6 +117,7 @@ private:
uint64_t idle_frame;
bool pressed;
float strength;
+ float raw_strength;
};
Map<StringName, Action> action_state;
@@ -146,7 +147,6 @@ private:
bool connected = false;
bool last_buttons[JOY_BUTTON_MAX] = { false };
float last_axis[JOY_AXIS_MAX] = { 0.0f };
- float filter = 0.01f;
int last_hat = HAT_MASK_CENTER;
int mapping = -1;
int hat_current = 0;
@@ -223,7 +223,6 @@ private:
JoyAxisList _get_output_axis(String output);
void _button_event(int p_device, int p_index, bool p_pressed);
void _axis_event(int p_device, int p_axis, float p_value);
- float _handle_deadzone(int p_device, int p_axis, float p_value);
void _parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_emulated);
@@ -266,6 +265,10 @@ public:
bool is_action_just_pressed(const StringName &p_action) const;
bool is_action_just_released(const StringName &p_action) const;
float get_action_strength(const StringName &p_action) const;
+ float get_action_raw_strength(const StringName &p_action) const;
+
+ float get_axis(const StringName &p_negative_action, const StringName &p_positive_action) const;
+ Vector2 get_vector(const StringName &p_negative_x, const StringName &p_positive_x, const StringName &p_negative_y, const StringName &p_positive_y, float p_deadzone = -1.0f) const;
float get_joy_axis(int p_device, int p_axis) const;
String get_joy_name(int p_idx);
@@ -327,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 6ba082f86f..41bc5e84b0 100644
--- a/core/input/input_event.cpp
+++ b/core/input/input_event.cpp
@@ -61,12 +61,17 @@ bool InputEvent::is_action_released(const StringName &p_action) const {
}
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);
+ bool valid = InputMap::get_singleton()->event_get_action_status(Ref<InputEvent>((InputEvent *)this), p_action, nullptr, &strength);
return valid ? strength : 0.0f;
}
+float InputEvent::get_action_raw_strength(const StringName &p_action) const {
+ float raw_strength;
+ bool valid = InputMap::get_singleton()->event_get_action_status(Ref<InputEvent>((InputEvent *)this), p_action, nullptr, nullptr, &raw_strength);
+ return valid ? raw_strength : 0.0f;
+}
+
bool InputEvent::is_pressed() const {
return false;
}
@@ -83,7 +88,7 @@ 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 {
+bool InputEvent::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const {
return false;
}
@@ -138,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;
}
@@ -186,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);
@@ -201,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");
@@ -208,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) {
@@ -307,7 +346,7 @@ String InputEventKey::as_text() const {
return kc;
}
-bool InputEventKey::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const {
+bool InputEventKey::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const {
Ref<InputEventKey> key = p_event;
if (key.is_null()) {
return false;
@@ -329,8 +368,12 @@ bool InputEventKey::action_match(const Ref<InputEvent> &p_event, bool *p_pressed
if (p_pressed != nullptr) {
*p_pressed = key->is_pressed();
}
+ float strength = (p_pressed != nullptr && *p_pressed) ? 1.0f : 0.0f;
if (p_strength != nullptr) {
- *p_strength = (p_pressed != nullptr && *p_pressed) ? 1.0f : 0.0f;
+ *p_strength = strength;
+ }
+ if (p_raw_strength != nullptr) {
+ *p_raw_strength = strength;
}
}
return match;
@@ -470,7 +513,7 @@ Ref<InputEvent> InputEventMouseButton::xformed_by(const Transform2D &p_xform, co
return mb;
}
-bool InputEventMouseButton::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const {
+bool InputEventMouseButton::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const {
Ref<InputEventMouseButton> mb = p_event;
if (mb.is_null()) {
return false;
@@ -481,8 +524,12 @@ bool InputEventMouseButton::action_match(const Ref<InputEvent> &p_event, bool *p
if (p_pressed != nullptr) {
*p_pressed = mb->is_pressed();
}
+ float strength = (p_pressed != nullptr && *p_pressed) ? 1.0f : 0.0f;
if (p_strength != nullptr) {
- *p_strength = (p_pressed != nullptr && *p_pressed) ? 1.0f : 0.0f;
+ *p_strength = strength;
+ }
+ if (p_raw_strength != nullptr) {
+ *p_raw_strength = strength;
}
}
@@ -713,7 +760,7 @@ 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 {
+bool InputEventJoypadMotion::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const {
Ref<InputEventJoypadMotion> jm = p_event;
if (jm.is_null()) {
return false;
@@ -721,8 +768,9 @@ bool InputEventJoypadMotion::action_match(const Ref<InputEvent> &p_event, bool *
bool match = (axis == jm->axis); // Matches even if not in the same direction, but returns a "not pressed" event.
if (match) {
+ float jm_abs_axis_value = Math::abs(jm->get_axis_value());
bool same_direction = (((axis_value < 0) == (jm->axis_value < 0)) || jm->axis_value == 0);
- bool pressed = same_direction ? Math::abs(jm->get_axis_value()) >= p_deadzone : false;
+ bool pressed = same_direction && jm_abs_axis_value >= p_deadzone;
if (p_pressed != nullptr) {
*p_pressed = pressed;
}
@@ -731,12 +779,19 @@ bool InputEventJoypadMotion::action_match(const Ref<InputEvent> &p_event, bool *
if (p_deadzone == 1.0f) {
*p_strength = 1.0f;
} else {
- *p_strength = CLAMP(Math::inverse_lerp(p_deadzone, 1.0f, Math::abs(jm->get_axis_value())), 0.0f, 1.0f);
+ *p_strength = CLAMP(Math::inverse_lerp(p_deadzone, 1.0f, jm_abs_axis_value), 0.0f, 1.0f);
}
} else {
*p_strength = 0.0f;
}
}
+ if (p_raw_strength != nullptr) {
+ if (same_direction) { // NOT pressed, because we want to ignore the deadzone.
+ *p_raw_strength = jm_abs_axis_value;
+ } else {
+ *p_raw_strength = 0.0f;
+ }
+ }
}
return match;
}
@@ -782,7 +837,7 @@ 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 {
+bool InputEventJoypadButton::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const {
Ref<InputEventJoypadButton> jb = p_event;
if (jb.is_null()) {
return false;
@@ -793,8 +848,12 @@ bool InputEventJoypadButton::action_match(const Ref<InputEvent> &p_event, bool *
if (p_pressed != nullptr) {
*p_pressed = jb->is_pressed();
}
+ float strength = (p_pressed != nullptr && *p_pressed) ? 1.0f : 0.0f;
if (p_strength != nullptr) {
- *p_strength = (p_pressed != nullptr && *p_pressed) ? 1.0f : 0.0f;
+ *p_strength = strength;
+ }
+ if (p_raw_strength != nullptr) {
+ *p_raw_strength = strength;
}
}
@@ -997,7 +1056,7 @@ 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 {
+bool InputEventAction::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const {
Ref<InputEventAction> act = p_event;
if (act.is_null()) {
return false;
@@ -1008,8 +1067,12 @@ bool InputEventAction::action_match(const Ref<InputEvent> &p_event, bool *p_pres
if (p_pressed != nullptr) {
*p_pressed = act->pressed;
}
+ float strength = (p_pressed != nullptr && *p_pressed) ? 1.0f : 0.0f;
if (p_strength != nullptr) {
- *p_strength = (p_pressed != nullptr && *p_pressed) ? 1.0f : 0.0f;
+ *p_strength = strength;
+ }
+ if (p_raw_strength != nullptr) {
+ *p_raw_strength = strength;
}
}
return match;
diff --git a/core/input/input_event.h b/core/input/input_event.h
index 8b58cf08c2..0eae3a2bbe 100644
--- a/core/input/input_event.h
+++ b/core/input/input_event.h
@@ -60,10 +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,
@@ -79,64 +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 {
@@ -173,6 +126,7 @@ public:
bool is_action_pressed(const StringName &p_action, bool p_allow_echo = false) const;
bool is_action_released(const StringName &p_action) const;
float get_action_strength(const StringName &p_action) const;
+ float get_action_raw_strength(const StringName &p_action) const;
// To be removed someday, since they do not make sense for all events
virtual bool is_pressed() const;
@@ -182,7 +136,7 @@ public:
virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const;
- virtual bool action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const;
+ virtual bool action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const;
virtual bool shortcut_match(const Ref<InputEvent> &p_event) const;
virtual bool is_action_type() const;
@@ -209,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
@@ -228,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;
@@ -283,7 +243,7 @@ public:
uint32_t get_keycode_with_modifiers() const;
uint32_t get_physical_keycode_with_modifiers() const;
- virtual bool action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const override;
+ virtual bool action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const override;
virtual bool shortcut_match(const Ref<InputEvent> &p_event) const override;
virtual bool is_action_type() const override { return true; }
@@ -342,7 +302,7 @@ public:
bool is_doubleclick() const;
virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const override;
- virtual bool action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const override;
+ virtual bool action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const override;
virtual bool is_action_type() const override { return true; }
virtual String as_text() const override;
@@ -399,7 +359,7 @@ public:
virtual bool is_pressed() const override;
- virtual bool action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const override;
+ virtual bool action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const override;
virtual bool is_action_type() const override { return true; }
virtual String as_text() const override;
@@ -426,7 +386,7 @@ public:
void set_pressure(float p_pressure);
float get_pressure() const;
- virtual bool action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const override;
+ virtual bool action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const override;
virtual bool shortcut_match(const Ref<InputEvent> &p_event) const override;
virtual bool is_action_type() const override { return true; }
@@ -511,7 +471,7 @@ public:
virtual bool is_action(const StringName &p_action) const;
- virtual bool action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const override;
+ virtual bool action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const override;
virtual bool shortcut_match(const Ref<InputEvent> &p_event) const override;
virtual bool is_action_type() const override { return true; }
diff --git a/core/input/input_map.cpp b/core/input/input_map.cpp
index ba1de3c58d..979809c7af 100644
--- a/core/input/input_map.cpp
+++ b/core/input/input_map.cpp
@@ -31,6 +31,7 @@
#include "input_map.h"
#include "core/config/project_settings.h"
+#include "core/input/input.h"
#include "core/os/keyboard.h"
InputMap *InputMap::singleton = nullptr;
@@ -50,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) {
@@ -94,7 +95,7 @@ List<StringName> InputMap::get_actions() const {
return actions;
}
-List<Ref<InputEvent>>::Element *InputMap::_find_event(Action &p_action, const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength) const {
+List<Ref<InputEvent>>::Element *InputMap::_find_event(Action &p_action, const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float *p_raw_strength) const {
ERR_FAIL_COND_V(!p_event.is_valid(), nullptr);
for (List<Ref<InputEvent>>::Element *E = p_action.inputs.front(); E; E = E->next()) {
@@ -105,7 +106,7 @@ List<Ref<InputEvent>>::Element *InputMap::_find_event(Action &p_action, const Re
int device = e->get_device();
if (device == ALL_DEVICES || device == p_event->get_device()) {
- if (e->action_match(p_event, p_pressed, p_strength, p_action.deadzone)) {
+ if (e->action_match(p_event, p_pressed, p_strength, p_raw_strength, p_action.deadzone)) {
return E;
}
}
@@ -118,6 +119,12 @@ bool InputMap::has_action(const StringName &p_action) const {
return input_map.has(p_action);
}
+float InputMap::action_get_deadzone(const StringName &p_action) {
+ ERR_FAIL_COND_V_MSG(!input_map.has(p_action), 0.0f, "Request for nonexistent InputMap action '" + String(p_action) + "'.");
+
+ return input_map[p_action].deadzone;
+}
+
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) + "'.");
@@ -145,6 +152,9 @@ void InputMap::action_erase_event(const StringName &p_action, const Ref<InputEve
List<Ref<InputEvent>>::Element *E = _find_event(input_map[p_action], p_event);
if (E) {
input_map[p_action].inputs.erase(E);
+ if (Input::get_singleton()->is_action_pressed(p_action)) {
+ Input::get_singleton()->action_release(p_action);
+ }
}
}
@@ -179,7 +189,7 @@ bool InputMap::event_is_action(const Ref<InputEvent> &p_event, const StringName
return event_get_action_status(p_event, p_action);
}
-bool InputMap::event_get_action_status(const Ref<InputEvent> &p_event, const StringName &p_action, bool *p_pressed, float *p_strength) const {
+bool InputMap::event_get_action_status(const Ref<InputEvent> &p_event, const StringName &p_action, bool *p_pressed, float *p_strength, float *p_raw_strength) const {
Map<StringName, Action>::Element *E = input_map.find(p_action);
ERR_FAIL_COND_V_MSG(!E, false, "Request for nonexistent InputMap action '" + String(p_action) + "'.");
@@ -196,7 +206,8 @@ bool InputMap::event_get_action_status(const Ref<InputEvent> &p_event, const Str
bool pressed;
float strength;
- List<Ref<InputEvent>>::Element *event = _find_event(E->get(), p_event, &pressed, &strength);
+ float raw_strength;
+ List<Ref<InputEvent>>::Element *event = _find_event(E->get(), p_event, &pressed, &strength, &raw_strength);
if (event != nullptr) {
if (p_pressed != nullptr) {
*p_pressed = pressed;
@@ -204,6 +215,9 @@ bool InputMap::event_get_action_status(const Ref<InputEvent> &p_event, const Str
if (p_strength != nullptr) {
*p_strength = strength;
}
+ if (p_raw_strength != nullptr) {
+ *p_raw_strength = raw_strength;
+ }
return true;
} else {
return false;
@@ -214,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 35c65d0881..948d78ebdd 100644
--- a/core/input/input_map.h
+++ b/core/input/input_map.h
@@ -54,7 +54,7 @@ private:
mutable Map<StringName, Action> input_map;
- List<Ref<InputEvent>>::Element *_find_event(Action &p_action, const Ref<InputEvent> &p_event, bool *p_pressed = nullptr, float *p_strength = nullptr) const;
+ List<Ref<InputEvent>>::Element *_find_event(Action &p_action, const Ref<InputEvent> &p_event, bool *p_pressed = nullptr, float *p_strength = nullptr, float *p_raw_strength = nullptr) const;
Array _action_get_events(const StringName &p_action);
Array _get_actions();
@@ -70,6 +70,7 @@ public:
void add_action(const StringName &p_action, float p_deadzone = 0.5);
void erase_action(const StringName &p_action);
+ float action_get_deadzone(const StringName &p_action);
void action_set_deadzone(const StringName &p_action, float p_deadzone);
void action_add_event(const StringName &p_action, const Ref<InputEvent> &p_event);
bool action_has_event(const StringName &p_action, const Ref<InputEvent> &p_event);
@@ -78,10 +79,10 @@ public:
const List<Ref<InputEvent>> *action_get_events(const StringName &p_action);
bool event_is_action(const Ref<InputEvent> &p_event, const StringName &p_action) const;
- bool event_get_action_status(const Ref<InputEvent> &p_event, const StringName &p_action, bool *p_pressed = nullptr, float *p_strength = nullptr) const;
+ 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/file_access_encrypted.h b/core/io/file_access_encrypted.h
index fddc6842f3..c760933038 100644
--- a/core/io/file_access_encrypted.h
+++ b/core/io/file_access_encrypted.h
@@ -47,8 +47,8 @@ private:
Vector<uint8_t> key;
bool writing = false;
FileAccess *file = nullptr;
- size_t base;
- size_t length;
+ size_t base = 0;
+ size_t length = 0;
Vector<uint8_t> data;
mutable int pos = 0;
mutable bool eofed = false;
diff --git a/core/io/file_access_memory.h b/core/io/file_access_memory.h
index 1a9bd3fbbb..47012b4e83 100644
--- a/core/io/file_access_memory.h
+++ b/core/io/file_access_memory.h
@@ -35,8 +35,8 @@
class FileAccessMemory : public FileAccess {
uint8_t *data = nullptr;
- int length;
- mutable int pos;
+ int length = 0;
+ mutable int pos = 0;
static FileAccess *create();
diff --git a/core/io/file_access_zip.cpp b/core/io/file_access_zip.cpp
index ce402fe8ed..1163c409bc 100644
--- a/core/io/file_access_zip.cpp
+++ b/core/io/file_access_zip.cpp
@@ -102,7 +102,6 @@ static voidpf godot_alloc(voidpf opaque, uInt items, uInt size) {
static void godot_free(voidpf opaque, voidpf address) {
memfree(address);
}
-
} // extern "C"
void ZipArchive::close_handle(unzFile p_file) const {
diff --git a/core/io/http_client.cpp b/core/io/http_client.cpp
index a25413b21b..768fcdbb14 100644
--- a/core/io/http_client.cpp
+++ b/core/io/http_client.cpp
@@ -109,24 +109,41 @@ Ref<StreamPeer> HTTPClient::get_connection() const {
return connection;
}
+static bool _check_request_url(HTTPClient::Method p_method, const String &p_url) {
+ switch (p_method) {
+ case HTTPClient::METHOD_CONNECT: {
+ // Authority in host:port format, as in RFC7231
+ int pos = p_url.find_char(':');
+ return 0 < pos && pos < p_url.length() - 1;
+ }
+ case HTTPClient::METHOD_OPTIONS: {
+ if (p_url == "*") {
+ return true;
+ }
+ [[fallthrough]];
+ }
+ default:
+ // Absolute path or absolute URL
+ return p_url.begins_with("/") || p_url.begins_with("http://") || p_url.begins_with("https://");
+ }
+}
+
Error HTTPClient::request_raw(Method p_method, const String &p_url, const Vector<String> &p_headers, const Vector<uint8_t> &p_body) {
ERR_FAIL_INDEX_V(p_method, METHOD_MAX, ERR_INVALID_PARAMETER);
- ERR_FAIL_COND_V(!p_url.begins_with("/"), ERR_INVALID_PARAMETER);
+ ERR_FAIL_COND_V(!_check_request_url(p_method, p_url), ERR_INVALID_PARAMETER);
ERR_FAIL_COND_V(status != STATUS_CONNECTED, ERR_INVALID_PARAMETER);
ERR_FAIL_COND_V(connection.is_null(), ERR_INVALID_DATA);
String request = String(_methods[p_method]) + " " + p_url + " HTTP/1.1\r\n";
- if ((ssl && conn_port == PORT_HTTPS) || (!ssl && conn_port == PORT_HTTP)) {
- // Don't append the standard ports
- request += "Host: " + conn_host + "\r\n";
- } else {
- request += "Host: " + conn_host + ":" + itos(conn_port) + "\r\n";
- }
+ bool add_host = true;
bool add_clen = p_body.size() > 0;
bool add_uagent = true;
bool add_accept = true;
for (int i = 0; i < p_headers.size(); i++) {
request += p_headers[i] + "\r\n";
+ if (add_host && p_headers[i].findn("Host:") == 0) {
+ add_host = false;
+ }
if (add_clen && p_headers[i].findn("Content-Length:") == 0) {
add_clen = false;
}
@@ -137,6 +154,14 @@ Error HTTPClient::request_raw(Method p_method, const String &p_url, const Vector
add_accept = false;
}
}
+ if (add_host) {
+ if ((ssl && conn_port == PORT_HTTPS) || (!ssl && conn_port == PORT_HTTP)) {
+ // Don't append the standard ports
+ request += "Host: " + conn_host + "\r\n";
+ } else {
+ request += "Host: " + conn_host + ":" + itos(conn_port) + "\r\n";
+ }
+ }
if (add_clen) {
request += "Content-Length: " + itos(p_body.size()) + "\r\n";
// Should it add utf8 encoding?
@@ -178,22 +203,20 @@ Error HTTPClient::request_raw(Method p_method, const String &p_url, const Vector
Error HTTPClient::request(Method p_method, const String &p_url, const Vector<String> &p_headers, const String &p_body) {
ERR_FAIL_INDEX_V(p_method, METHOD_MAX, ERR_INVALID_PARAMETER);
- ERR_FAIL_COND_V(!p_url.begins_with("/"), ERR_INVALID_PARAMETER);
+ ERR_FAIL_COND_V(!_check_request_url(p_method, p_url), ERR_INVALID_PARAMETER);
ERR_FAIL_COND_V(status != STATUS_CONNECTED, ERR_INVALID_PARAMETER);
ERR_FAIL_COND_V(connection.is_null(), ERR_INVALID_DATA);
String request = String(_methods[p_method]) + " " + p_url + " HTTP/1.1\r\n";
- if ((ssl && conn_port == PORT_HTTPS) || (!ssl && conn_port == PORT_HTTP)) {
- // Don't append the standard ports
- request += "Host: " + conn_host + "\r\n";
- } else {
- request += "Host: " + conn_host + ":" + itos(conn_port) + "\r\n";
- }
+ bool add_host = true;
bool add_uagent = true;
bool add_accept = true;
bool add_clen = p_body.length() > 0;
for (int i = 0; i < p_headers.size(); i++) {
request += p_headers[i] + "\r\n";
+ if (add_host && p_headers[i].findn("Host:") == 0) {
+ add_host = false;
+ }
if (add_clen && p_headers[i].findn("Content-Length:") == 0) {
add_clen = false;
}
@@ -204,6 +227,14 @@ Error HTTPClient::request(Method p_method, const String &p_url, const Vector<Str
add_accept = false;
}
}
+ if (add_host) {
+ if ((ssl && conn_port == PORT_HTTPS) || (!ssl && conn_port == PORT_HTTP)) {
+ // Don't append the standard ports
+ request += "Host: " + conn_host + "\r\n";
+ } else {
+ request += "Host: " + conn_host + ":" + itos(conn_port) + "\r\n";
+ }
+ }
if (add_clen) {
request += "Content-Length: " + itos(p_body.utf8().length()) + "\r\n";
// Should it add utf8 encoding?
diff --git a/core/io/http_client.h b/core/io/http_client.h
index ece7e1924b..3d9fe321ba 100644
--- a/core/io/http_client.h
+++ b/core/io/http_client.h
@@ -41,7 +41,6 @@ class HTTPClient : public Reference {
public:
enum ResponseCode {
-
// 1xx informational
RESPONSE_CONTINUE = 100,
RESPONSE_SWITCHING_PROTOCOLS = 101,
@@ -116,7 +115,6 @@ public:
};
enum Method {
-
METHOD_GET,
METHOD_HEAD,
METHOD_POST,
@@ -131,7 +129,6 @@ public:
};
enum Status {
-
STATUS_DISCONNECTED,
STATUS_RESOLVING, // Resolving hostname (if passed a hostname)
STATUS_CANT_RESOLVE,
@@ -150,7 +147,6 @@ private:
static const int HOST_MIN_LEN = 4;
enum Port {
-
PORT_HTTP = 80,
PORT_HTTPS = 443,
diff --git a/core/io/image.cpp b/core/io/image.cpp
index 005fd481e8..6dde25af32 100644
--- a/core/io/image.cpp
+++ b/core/io/image.cpp
@@ -80,7 +80,6 @@ const char *Image::format_names[Image::FORMAT_MAX] = {
"ETC2_RGB8A1",
"ETC2_RA_AS_RG",
"FORMAT_DXT5_RA_AS_RG",
-
};
SavePNGFunc Image::save_png_func = nullptr;
@@ -2767,8 +2766,8 @@ Dictionary Image::_get_data() const {
return d;
}
-Color Image::get_pixelv(const Point2 &p_src) const {
- return get_pixel(p_src.x, p_src.y);
+Color Image::get_pixelv(const Point2i &p_point) const {
+ return get_pixel(p_point.x, p_point.y);
}
Color Image::_get_color_at_ofs(const uint8_t *ptr, uint32_t ofs) const {
@@ -2977,8 +2976,8 @@ Color Image::get_pixel(int p_x, int p_y) const {
return _get_color_at_ofs(data.ptr(), ofs);
}
-void Image::set_pixelv(const Point2 &p_dst, const Color &p_color) {
- set_pixel(p_dst.x, p_dst.y, p_color);
+void Image::set_pixelv(const Point2i &p_point, const Color &p_color) {
+ set_pixel(p_point.x, p_point.y, p_color);
}
void Image::set_pixel(int p_x, int p_y, const Color &p_color) {
@@ -3133,9 +3132,9 @@ void Image::_bind_methods() {
ClassDB::bind_method(D_METHOD("_set_data", "data"), &Image::_set_data);
ClassDB::bind_method(D_METHOD("_get_data"), &Image::_get_data);
- ClassDB::bind_method(D_METHOD("get_pixelv", "src"), &Image::get_pixelv);
+ ClassDB::bind_method(D_METHOD("get_pixelv", "point"), &Image::get_pixelv);
ClassDB::bind_method(D_METHOD("get_pixel", "x", "y"), &Image::get_pixel);
- ClassDB::bind_method(D_METHOD("set_pixelv", "dst", "color"), &Image::set_pixelv);
+ ClassDB::bind_method(D_METHOD("set_pixelv", "point", "color"), &Image::set_pixelv);
ClassDB::bind_method(D_METHOD("set_pixel", "x", "y", "color"), &Image::set_pixel);
ClassDB::bind_method(D_METHOD("load_png_from_buffer", "buffer"), &Image::load_png_from_buffer);
diff --git a/core/io/image.h b/core/io/image.h
index fecb90cab0..c4c84589e5 100644
--- a/core/io/image.h
+++ b/core/io/image.h
@@ -66,7 +66,6 @@ public:
};
enum Format {
-
FORMAT_L8, //luminance
FORMAT_LA8, //luminance-alpha
FORMAT_R8,
@@ -111,7 +110,6 @@ public:
static const char *format_names[FORMAT_MAX];
enum Interpolation {
-
INTERPOLATE_NEAREST,
INTERPOLATE_BILINEAR,
INTERPOLATE_CUBIC,
@@ -389,9 +387,9 @@ public:
UsedChannels detect_used_channels(CompressSource p_source = COMPRESS_SOURCE_GENERIC);
void optimize_channels();
- Color get_pixelv(const Point2 &p_src) const;
+ Color get_pixelv(const Point2i &p_point) const;
Color get_pixel(int p_x, int p_y) const;
- void set_pixelv(const Point2 &p_dst, const Color &p_color);
+ void set_pixelv(const Point2i &p_point, const Color &p_color);
void set_pixel(int p_x, int p_y, const Color &p_color);
void set_as_black();
diff --git a/core/io/ip.h b/core/io/ip.h
index d434d02f9b..32572b8eb2 100644
--- a/core/io/ip.h
+++ b/core/io/ip.h
@@ -42,7 +42,6 @@ class IP : public Object {
public:
enum ResolverStatus {
-
RESOLVER_STATUS_NONE,
RESOLVER_STATUS_WAITING,
RESOLVER_STATUS_DONE,
@@ -50,7 +49,6 @@ public:
};
enum Type {
-
TYPE_NONE = 0,
TYPE_IPV4 = 1,
TYPE_IPV6 = 2,
diff --git a/core/io/ip_address.cpp b/core/io/ip_address.cpp
index d0fb63b958..7d730e5ae8 100644
--- a/core/io/ip_address.cpp
+++ b/core/io/ip_address.cpp
@@ -31,7 +31,6 @@
#include "ip_address.h"
/*
IP_Address::operator Variant() const {
-
return operator String();
}*/
diff --git a/core/io/json.h b/core/io/json.h
index 2854d956ec..431b252e55 100644
--- a/core/io/json.h
+++ b/core/io/json.h
@@ -49,7 +49,6 @@ class JSON {
};
enum Expecting {
-
EXPECT_OBJECT,
EXPECT_OBJECT_KEY,
EXPECT_COLON,
diff --git a/core/io/multiplayer_api.h b/core/io/multiplayer_api.h
index e0ce1c8ca4..5b30c2e680 100644
--- a/core/io/multiplayer_api.h
+++ b/core/io/multiplayer_api.h
@@ -102,7 +102,6 @@ public:
};
enum RPCMode {
-
RPC_MODE_DISABLED, // No rpc for this method, calls to this will be blocked (default)
RPC_MODE_REMOTE, // Using rpc() on it will call method / set property in all remote peers
RPC_MODE_MASTER, // Using rpc() on it will call method on wherever the master is, be it local or remote
diff --git a/core/io/packed_data_container.h b/core/io/packed_data_container.h
index b784abcd16..3899c14bb4 100644
--- a/core/io/packed_data_container.h
+++ b/core/io/packed_data_container.h
@@ -84,7 +84,7 @@ class PackedDataContainerRef : public Reference {
GDCLASS(PackedDataContainerRef, Reference);
friend class PackedDataContainer;
- uint32_t offset;
+ uint32_t offset = 0;
Ref<PackedDataContainer> from;
protected:
diff --git a/core/io/pck_packer.h b/core/io/pck_packer.h
index c1026c2499..56be1b52df 100644
--- a/core/io/pck_packer.h
+++ b/core/io/pck_packer.h
@@ -39,7 +39,7 @@ class PCKPacker : public Reference {
GDCLASS(PCKPacker, Reference);
FileAccess *file = nullptr;
- int alignment;
+ int alignment = 0;
uint64_t ofs = 0;
Vector<uint8_t> key;
@@ -50,9 +50,9 @@ class PCKPacker : public Reference {
struct File {
String path;
String src_path;
- uint64_t ofs;
- uint64_t size;
- bool encrypted;
+ uint64_t ofs = 0;
+ uint64_t size = 0;
+ bool encrypted = false;
Vector<uint8_t> md5;
};
Vector<File> files;
diff --git a/core/io/resource.cpp b/core/io/resource.cpp
index 5b249f7af3..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) {
@@ -209,8 +207,8 @@ Ref<Resource> Resource::duplicate(bool p_subresources) const {
List<PropertyInfo> plist;
get_property_list(&plist);
- Resource *r = (Resource *)ClassDB::instance(get_class());
- ERR_FAIL_COND_V(!r, Ref<Resource>());
+ Ref<Resource> r = (Resource *)ClassDB::instance(get_class());
+ ERR_FAIL_COND_V(r.is_null(), Ref<Resource>());
for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) {
if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) {
@@ -230,7 +228,7 @@ Ref<Resource> Resource::duplicate(bool p_subresources) const {
}
}
- return Ref<Resource>(r);
+ return r;
}
void Resource::_set_path(const String &p_path) {
diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp
index c67e68e4fc..aeb859aabd 100644
--- a/core/io/resource_format_binary.cpp
+++ b/core/io/resource_format_binary.cpp
@@ -41,7 +41,6 @@
#define print_bl(m_what) (void)(m_what)
enum {
-
//numbering must be different from variant, in case new variant types are added (variant must be always contiguous for jumptable optimization)
VARIANT_NIL = 1,
VARIANT_BOOL = 2,
@@ -90,7 +89,6 @@ enum {
FORMAT_VERSION = 3,
FORMAT_VERSION_CAN_RENAME_DEPS = 1,
FORMAT_VERSION_NO_NODEPATH_PROPERTY = 3,
-
};
void ResourceLoaderBinary::_advance_padding(uint32_t p_len) {
diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp
index 9991ee405e..a8ca6a817e 100644
--- a/core/io/resource_loader.cpp
+++ b/core/io/resource_loader.cpp
@@ -1057,7 +1057,7 @@ bool ResourceLoader::add_custom_resource_format_loader(String script_path) {
ERR_FAIL_COND_V_MSG(obj == nullptr, false, "Cannot instance script as custom resource loader, expected 'ResourceFormatLoader' inheritance, got: " + String(ibt) + ".");
- ResourceFormatLoader *crl = Object::cast_to<ResourceFormatLoader>(obj);
+ Ref<ResourceFormatLoader> crl = Object::cast_to<ResourceFormatLoader>(obj);
crl->set_script(s);
ResourceLoader::add_resource_format_loader(crl);
diff --git a/core/io/resource_saver.cpp b/core/io/resource_saver.cpp
index 2eac2a6b4d..6ded27d82f 100644
--- a/core/io/resource_saver.cpp
+++ b/core/io/resource_saver.cpp
@@ -214,7 +214,7 @@ bool ResourceSaver::add_custom_resource_format_saver(String script_path) {
ERR_FAIL_COND_V_MSG(obj == nullptr, false, "Cannot instance script as custom resource saver, expected 'ResourceFormatSaver' inheritance, got: " + String(ibt) + ".");
- ResourceFormatSaver *crl = Object::cast_to<ResourceFormatSaver>(obj);
+ Ref<ResourceFormatSaver> crl = Object::cast_to<ResourceFormatSaver>(obj);
crl->set_script(s);
ResourceSaver::add_resource_format_saver(crl);
diff --git a/core/io/resource_saver.h b/core/io/resource_saver.h
index 2e2950af53..c724c4a6e5 100644
--- a/core/io/resource_saver.h
+++ b/core/io/resource_saver.h
@@ -63,7 +63,6 @@ class ResourceSaver {
public:
enum SaverFlags {
-
FLAG_RELATIVE_PATHS = 1,
FLAG_BUNDLE_RESOURCES = 2,
FLAG_CHANGE_PATH = 4,
diff --git a/core/io/stream_peer_tcp.h b/core/io/stream_peer_tcp.h
index 45205866b4..173f92e2b6 100644
--- a/core/io/stream_peer_tcp.h
+++ b/core/io/stream_peer_tcp.h
@@ -42,7 +42,6 @@ class StreamPeerTCP : public StreamPeer {
public:
enum Status {
-
STATUS_NONE,
STATUS_CONNECTING,
STATUS_CONNECTED,
diff --git a/core/math/a_star.h b/core/math/a_star.h
index a6fa771b30..7cfa73f2c2 100644
--- a/core/math/a_star.h
+++ b/core/math/a_star.h
@@ -47,20 +47,20 @@ class AStar : public Reference {
struct Point {
Point() {}
- int id;
+ int id = 0;
Vector3 pos;
- real_t weight_scale;
- bool enabled;
+ real_t weight_scale = 0;
+ bool enabled = false;
OAHashMap<int, Point *> neighbours = 4u;
OAHashMap<int, Point *> unlinked_neighbours = 4u;
// Used for pathfinding.
- Point *prev_point;
- real_t g_score;
- real_t f_score;
- uint64_t open_pass;
- uint64_t closed_pass;
+ Point *prev_point = nullptr;
+ real_t g_score = 0;
+ real_t f_score = 0;
+ uint64_t open_pass = 0;
+ uint64_t closed_pass = 0;
};
struct SortPoints {
diff --git a/core/math/expression.h b/core/math/expression.h
index d9cedb8c2c..6b34bc6ae8 100644
--- a/core/math/expression.h
+++ b/core/math/expression.h
@@ -133,7 +133,7 @@ private:
ENode *next = nullptr;
- Type type;
+ Type type = TYPE_INPUT;
ENode() {}
virtual ~ENode() {
@@ -144,7 +144,7 @@ private:
};
struct ExpressionNode {
- bool is_op;
+ bool is_op = false;
union {
Variant::Operator op;
ENode *node;
@@ -154,23 +154,23 @@ private:
ENode *_parse_expression();
struct InputNode : public ENode {
- int index;
+ int index = 0;
InputNode() {
type = TYPE_INPUT;
}
};
struct ConstantNode : public ENode {
- Variant value;
+ Variant value = Variant::NIL;
ConstantNode() {
type = TYPE_CONSTANT;
}
};
struct OperatorNode : public ENode {
- Variant::Operator op;
+ Variant::Operator op = Variant::Operator::OP_ADD;
- ENode *nodes[2];
+ ENode *nodes[2] = { nullptr, nullptr };
OperatorNode() {
type = TYPE_OPERATOR;
@@ -184,8 +184,8 @@ private:
};
struct IndexNode : public ENode {
- ENode *base;
- ENode *index;
+ ENode *base = nullptr;
+ ENode *index = nullptr;
IndexNode() {
type = TYPE_INDEX;
@@ -193,7 +193,7 @@ private:
};
struct NamedIndexNode : public ENode {
- ENode *base;
+ ENode *base = nullptr;
StringName name;
NamedIndexNode() {
@@ -202,7 +202,7 @@ private:
};
struct ConstructorNode : public ENode {
- Variant::Type data_type;
+ Variant::Type data_type = Variant::Type::NIL;
Vector<ENode *> arguments;
ConstructorNode() {
@@ -211,7 +211,7 @@ private:
};
struct CallNode : public ENode {
- ENode *base;
+ ENode *base = nullptr;
StringName method;
Vector<ENode *> arguments;
diff --git a/core/math/geometry_3d.cpp b/core/math/geometry_3d.cpp
index 56353de783..ccb6648561 100644
--- a/core/math/geometry_3d.cpp
+++ b/core/math/geometry_3d.cpp
@@ -241,7 +241,6 @@ Vector<Vector<Face3>> Geometry3D::separate_objects(Vector<Face3> p_array) {
/*** GEOMETRY WRAPPER ***/
enum _CellFlags {
-
_CELL_SOLID = 1,
_CELL_EXTERIOR = 2,
_CELL_STEP_MASK = 0x1C,
@@ -262,7 +261,6 @@ enum _CellFlags {
_CELL_PREV_Z_POS = 5 << 5,
_CELL_PREV_Z_NEG = 6 << 5,
_CELL_PREV_FIRST = 7 << 5,
-
};
static inline void _plot_face(uint8_t ***p_cell_status, int x, int y, int z, int len_x, int len_y, int len_z, const Vector3 &voxelsize, const Face3 &p_face) {
diff --git a/core/math/math_defs.h b/core/math/math_defs.h
index 4928c96abd..5192722839 100644
--- a/core/math/math_defs.h
+++ b/core/math/math_defs.h
@@ -66,27 +66,23 @@ enum ClockDirection {
};
enum Orientation {
-
HORIZONTAL,
VERTICAL
};
enum HAlign {
-
HALIGN_LEFT,
HALIGN_CENTER,
HALIGN_RIGHT
};
enum VAlign {
-
VALIGN_TOP,
VALIGN_CENTER,
VALIGN_BOTTOM
};
enum Margin {
-
MARGIN_LEFT,
MARGIN_TOP,
MARGIN_RIGHT,
@@ -94,7 +90,6 @@ enum Margin {
};
enum Corner {
-
CORNER_TOP_LEFT,
CORNER_TOP_RIGHT,
CORNER_BOTTOM_RIGHT,
diff --git a/core/math/math_fieldwise.cpp b/core/math/math_fieldwise.cpp
index ef2a0c5339..221c6812c1 100644
--- a/core/math/math_fieldwise.cpp
+++ b/core/math/math_fieldwise.cpp
@@ -47,9 +47,7 @@ Variant fieldwise_assign(const Variant &p_target, const Variant &p_source, const
/* clang-format off */
switch (p_source.get_type()) {
-
case Variant::VECTOR2: {
-
SETUP_TYPE(Vector2)
/**/ TRY_TRANSFER_FIELD("x", x)
@@ -59,7 +57,6 @@ Variant fieldwise_assign(const Variant &p_target, const Variant &p_source, const
}
case Variant::RECT2: {
-
SETUP_TYPE(Rect2)
/**/ TRY_TRANSFER_FIELD("x", position.x)
@@ -71,7 +68,6 @@ Variant fieldwise_assign(const Variant &p_target, const Variant &p_source, const
}
case Variant::VECTOR3: {
-
SETUP_TYPE(Vector3)
/**/ TRY_TRANSFER_FIELD("x", x)
@@ -82,7 +78,6 @@ Variant fieldwise_assign(const Variant &p_target, const Variant &p_source, const
}
case Variant::PLANE: {
-
SETUP_TYPE(Plane)
/**/ TRY_TRANSFER_FIELD("x", normal.x)
@@ -94,7 +89,6 @@ Variant fieldwise_assign(const Variant &p_target, const Variant &p_source, const
}
case Variant::QUAT: {
-
SETUP_TYPE(Quat)
/**/ TRY_TRANSFER_FIELD("x", x)
@@ -106,7 +100,6 @@ Variant fieldwise_assign(const Variant &p_target, const Variant &p_source, const
}
case Variant::AABB: {
-
SETUP_TYPE(AABB)
/**/ TRY_TRANSFER_FIELD("px", position.x)
@@ -120,7 +113,6 @@ Variant fieldwise_assign(const Variant &p_target, const Variant &p_source, const
}
case Variant::TRANSFORM2D: {
-
SETUP_TYPE(Transform2D)
/**/ TRY_TRANSFER_FIELD("xx", elements[0][0])
@@ -134,7 +126,6 @@ Variant fieldwise_assign(const Variant &p_target, const Variant &p_source, const
}
case Variant::BASIS: {
-
SETUP_TYPE(Basis)
/**/ TRY_TRANSFER_FIELD("xx", elements[0][0])
@@ -151,7 +142,6 @@ Variant fieldwise_assign(const Variant &p_target, const Variant &p_source, const
}
case Variant::TRANSFORM: {
-
SETUP_TYPE(Transform)
/**/ TRY_TRANSFER_FIELD("xx", basis.elements[0][0])
diff --git a/core/math/octree.h b/core/math/octree.h
index 40201f99b1..be1e7d6a61 100644
--- a/core/math/octree.h
+++ b/core/math/octree.h
@@ -379,7 +379,6 @@ void Octree<T, use_pairs, AL>::_insert_element(Element *p_element, Octant *p_oct
if (p_octant->aabb.size.x / OCTREE_DIVISOR < element_size) {
//if (p_octant->aabb.size.x*0.5 < element_size) {
-
/* at smallest possible size for the element */
typename Element::OctantOwner owner;
owner.octant = p_octant;
diff --git a/core/math/quick_hull.h b/core/math/quick_hull.h
index 80f32e191b..024325c4fc 100644
--- a/core/math/quick_hull.h
+++ b/core/math/quick_hull.h
@@ -41,7 +41,7 @@ public:
struct Edge {
union {
uint32_t vertices[2];
- uint64_t id;
+ uint64_t id = 0;
};
bool operator<(const Edge &p_edge) const {
@@ -60,7 +60,7 @@ public:
struct Face {
Plane plane;
- uint32_t vertices[3];
+ uint32_t vertices[3] = { 0 };
Vector<int> points_over;
bool operator<(const Face &p_face) const {
@@ -70,11 +70,13 @@ public:
private:
struct FaceConnect {
- List<Face>::Element *left, *right = nullptr;
+ List<Face>::Element *left = nullptr;
+ List<Face>::Element *right = nullptr;
FaceConnect() {}
};
struct RetFaceConnect {
- List<Geometry3D::MeshData::Face>::Element *left, *right = nullptr;
+ List<Geometry3D::MeshData::Face>::Element *left = nullptr;
+ List<Geometry3D::MeshData::Face>::Element *right = nullptr;
RetFaceConnect() {}
};
diff --git a/core/object/callable_method_pointer.h b/core/object/callable_method_pointer.h
index ee6da6a8db..68990dcb72 100644
--- a/core/object/callable_method_pointer.h
+++ b/core/object/callable_method_pointer.h
@@ -114,7 +114,6 @@ Callable create_custom_callable_function_pointer(T *p_instance,
const char *p_func_text,
#endif
void (T::*p_method)(P...)) {
-
typedef CallableCustomMethodPointer<T, P...> CCMP; // Messes with memnew otherwise.
CCMP *ccmp = memnew(CCMP(p_instance, p_method));
#ifdef DEBUG_METHODS_ENABLED
@@ -170,7 +169,6 @@ Callable create_custom_callable_function_pointer(T *p_instance,
const char *p_func_text,
#endif
R (T::*p_method)(P...)) {
-
typedef CallableCustomMethodPointerRet<T, R, P...> CCMP; // Messes with memnew otherwise.
CCMP *ccmp = memnew(CCMP(p_instance, p_method));
#ifdef DEBUG_METHODS_ENABLED
@@ -226,7 +224,6 @@ Callable create_custom_callable_function_pointer(T *p_instance,
const char *p_func_text,
#endif
R (T::*p_method)(P...) const) {
-
typedef CallableCustomMethodPointerRetC<T, R, P...> CCMP; // Messes with memnew otherwise.
CCMP *ccmp = memnew(CCMP(p_instance, p_method));
#ifdef DEBUG_METHODS_ENABLED
diff --git a/core/object/method_bind.h b/core/object/method_bind.h
index ab4ba90b94..bd308c9630 100644
--- a/core/object/method_bind.h
+++ b/core/object/method_bind.h
@@ -34,7 +34,6 @@
#include "core/variant/binder_common.h"
enum MethodFlags {
-
METHOD_FLAG_NORMAL = 1,
METHOD_FLAG_EDITOR = 2,
METHOD_FLAG_NOSCRIPT = 4,
@@ -124,10 +123,7 @@ public:
_FORCE_INLINE_ int get_argument_count() const { return argument_count; };
virtual Variant call(Object *p_object, const Variant **p_args, int p_arg_count, Callable::CallError &r_error) = 0;
-
-#ifdef PTRCALL_ENABLED
virtual void ptrcall(Object *p_object, const void **p_args, void *r_ret) = 0;
-#endif
StringName get_name() const;
void set_name(const StringName &p_name);
@@ -206,11 +202,9 @@ public:
#endif
}
-#ifdef PTRCALL_ENABLED
virtual void ptrcall(Object *p_object, const void **p_args, void *r_ret) {
- ERR_FAIL(); //can't call
- } //todo
-#endif
+ ERR_FAIL(); // Can't call.
+ }
void set_method(NativeCall p_method) { call_method = p_method; }
virtual bool is_const() const { return false; }
@@ -290,7 +284,6 @@ public:
return Variant();
}
-#ifdef PTRCALL_ENABLED
virtual void ptrcall(Object *p_object, const void **p_args, void *r_ret) {
#ifdef TYPED_METHOD_BIND
call_with_ptr_args<T, P...>(static_cast<T *>(p_object), method, p_args);
@@ -298,7 +291,6 @@ public:
call_with_ptr_args<MB_T, P...>((MB_T *)(p_object), method, p_args);
#endif
}
-#endif
MethodBindT(void (MB_T::*p_method)(P...)) {
method = p_method;
@@ -371,7 +363,6 @@ public:
return Variant();
}
-#ifdef PTRCALL_ENABLED
virtual void ptrcall(Object *p_object, const void **p_args, void *r_ret) {
#ifdef TYPED_METHOD_BIND
call_with_ptr_argsc<T, P...>(static_cast<T *>(p_object), method, p_args);
@@ -379,7 +370,6 @@ public:
call_with_ptr_argsc<MB_T, P...>((MB_T *)(p_object), method, p_args);
#endif
}
-#endif
MethodBindTC(void (MB_T::*p_method)(P...) const) {
method = p_method;
@@ -463,7 +453,6 @@ public:
return ret;
}
-#ifdef PTRCALL_ENABLED
virtual void ptrcall(Object *p_object, const void **p_args, void *r_ret) {
#ifdef TYPED_METHOD_BIND
call_with_ptr_args_ret<T, R, P...>(static_cast<T *>(p_object), method, p_args, r_ret);
@@ -471,7 +460,6 @@ public:
call_with_ptr_args_ret<MB_T, R, P...>((MB_T *)(p_object), method, p_args, r_ret);
#endif
}
-#endif
MethodBindTR(R (MB_T::*p_method)(P...)) {
method = p_method;
@@ -556,7 +544,6 @@ public:
return ret;
}
-#ifdef PTRCALL_ENABLED
virtual void ptrcall(Object *p_object, const void **p_args, void *r_ret) {
#ifdef TYPED_METHOD_BIND
call_with_ptr_args_retc<T, R, P...>(static_cast<T *>(p_object), method, p_args, r_ret);
@@ -564,7 +551,6 @@ public:
call_with_ptr_args_retc<MB_T, R, P...>((MB_T *)(p_object), method, p_args, r_ret);
#endif
}
-#endif
MethodBindTRC(R (MB_T::*p_method)(P...) const) {
method = p_method;
diff --git a/core/object/object.cpp b/core/object/object.cpp
index c3f49856ca..96a41d6852 100644
--- a/core/object/object.cpp
+++ b/core/object/object.cpp
@@ -597,9 +597,6 @@ void Object::get_property_list(List<PropertyInfo> *p_list, bool p_reversed) cons
_get_property_listv(p_list, p_reversed);
if (!is_class("Script")) { // can still be set, but this is for userfriendlyness
-#ifdef TOOLS_ENABLED
- p_list->push_back(PropertyInfo(Variant::NIL, "Script", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_GROUP));
-#endif
p_list->push_back(PropertyInfo(Variant::OBJECT, "script", PROPERTY_HINT_RESOURCE_TYPE, "Script", PROPERTY_USAGE_DEFAULT));
}
if (!metadata.empty()) {
diff --git a/core/object/object.h b/core/object/object.h
index c79745cf74..0bcfa42e3d 100644
--- a/core/object/object.h
+++ b/core/object/object.h
@@ -98,7 +98,6 @@ enum PropertyHint {
};
enum PropertyUsageFlags {
-
PROPERTY_USAGE_STORAGE = 1,
PROPERTY_USAGE_EDITOR = 2,
PROPERTY_USAGE_NETWORK = 4,
@@ -406,7 +405,6 @@ class ScriptInstance;
class Object {
public:
enum ConnectFlags {
-
CONNECT_DEFERRED = 1,
CONNECT_PERSIST = 2, // hint for scene to save this connection
CONNECT_ONESHOT = 4,
diff --git a/core/object/reference.h b/core/object/reference.h
index 575f1cd914..0eb127f362 100644
--- a/core/object/reference.h
+++ b/core/object/reference.h
@@ -252,8 +252,6 @@ public:
WeakRef() {}
};
-#ifdef PTRCALL_ENABLED
-
template <class T>
struct PtrToArg<Ref<T>> {
_FORCE_INLINE_ static Ref<T> convert(const void *p_ptr) {
@@ -272,8 +270,6 @@ struct PtrToArg<const Ref<T> &> {
}
};
-#endif // PTRCALL_ENABLED
-
#ifdef DEBUG_METHODS_ENABLED
template <class T>
diff --git a/core/object/script_language.h b/core/object/script_language.h
index 447216f14f..3fd56c2f15 100644
--- a/core/object/script_language.h
+++ b/core/object/script_language.h
@@ -57,7 +57,6 @@ struct SortNetData {
class ScriptServer {
enum {
-
MAX_LANGUAGES = 16
};
diff --git a/core/os/dir_access.h b/core/os/dir_access.h
index 0f4fa9b250..17f84d3c52 100644
--- a/core/os/dir_access.h
+++ b/core/os/dir_access.h
@@ -57,7 +57,6 @@ protected:
String _get_root_string() const;
String fix_path(String p_path) const;
- bool next_is_dir;
template <class T>
static DirAccess *_create_builtin() {
diff --git a/core/os/file_access.cpp b/core/os/file_access.cpp
index fd3c6f8806..b962f61e1f 100644
--- a/core/os/file_access.cpp
+++ b/core/os/file_access.cpp
@@ -254,8 +254,8 @@ class CharBuffer {
Vector<char> vector;
char stack_buffer[256];
- char *buffer;
- int capacity;
+ char *buffer = nullptr;
+ int capacity = 0;
int written = 0;
bool grow() {
diff --git a/core/os/file_access.h b/core/os/file_access.h
index 39b977a4d9..777c82bbd7 100644
--- a/core/os/file_access.h
+++ b/core/os/file_access.h
@@ -81,7 +81,6 @@ public:
virtual void _set_access_type(AccessType p_access);
enum ModeFlags {
-
READ = 1,
WRITE = 2,
READ_WRITE = 3,
diff --git a/core/os/keyboard.cpp b/core/os/keyboard.cpp
index d088151a6d..ef341987dc 100644
--- a/core/os/keyboard.cpp
+++ b/core/os/keyboard.cpp
@@ -38,7 +38,6 @@ struct _KeyCodeText {
};
static const _KeyCodeText _keycodes[] = {
-
/* clang-format off */
{KEY_ESCAPE ,"Escape"},
{KEY_TAB ,"Tab"},
diff --git a/core/os/keyboard.h b/core/os/keyboard.h
index 92664aff8f..67c60a2dbe 100644
--- a/core/os/keyboard.h
+++ b/core/os/keyboard.h
@@ -294,11 +294,9 @@ enum KeyList {
KEY_DIVISION = 0x00F7,
KEY_YDIAERESIS = 0x00FF,
-
};
enum KeyModifierMask {
-
KEY_CODE_MASK = ((1 << 25) - 1), ///< Apply this mask to any keycode to remove modifiers.
KEY_MODIFIER_MASK = (0xFF << 24), ///< Apply this mask to isolate modifiers.
KEY_MASK_SHIFT = (1 << 25),
@@ -314,7 +312,6 @@ enum KeyModifierMask {
KEY_MASK_KPAD = (1 << 29),
KEY_MASK_GROUP_SWITCH = (1 << 30)
// bit 31 can't be used because variant uses regular 32 bits int as datatype
-
};
String keycode_get_string(uint32_t p_code);
diff --git a/core/os/os.h b/core/os/os.h
index a1e75b5ee9..40104b479b 100644
--- a/core/os/os.h
+++ b/core/os/os.h
@@ -77,7 +77,6 @@ public:
typedef bool (*HasServerFeatureCallback)(const String &p_feature);
enum RenderThreadMode {
-
RENDER_THREAD_UNSAFE,
RENDER_THREAD_SAFE,
RENDER_SEPARATE_THREAD
diff --git a/core/os/pool_allocator.h b/core/os/pool_allocator.h
index 7d77af6266..c67b4d7fa2 100644
--- a/core/os/pool_allocator.h
+++ b/core/os/pool_allocator.h
@@ -43,7 +43,6 @@
*/
enum {
-
POOL_ALLOCATOR_INVALID_ID = -1 ///< default invalid value. use INVALID_ID( id ) to test
};
diff --git a/core/os/thread.h b/core/os/thread.h
index d68476e683..b87ec84313 100644
--- a/core/os/thread.h
+++ b/core/os/thread.h
@@ -39,7 +39,6 @@ typedef void (*ThreadCreateCallback)(void *p_userdata);
class Thread {
public:
enum Priority {
-
PRIORITY_LOW,
PRIORITY_NORMAL,
PRIORITY_HIGH
diff --git a/core/string/string_name.h b/core/string/string_name.h
index e6b46506c3..320f63bf68 100644
--- a/core/string/string_name.h
+++ b/core/string/string_name.h
@@ -44,7 +44,6 @@ struct StaticCString {
class StringName {
enum {
-
STRING_TABLE_BITS = 12,
STRING_TABLE_LEN = 1 << STRING_TABLE_BITS,
STRING_TABLE_MASK = STRING_TABLE_LEN - 1
diff --git a/core/string/ustring.cpp b/core/string/ustring.cpp
index b5758bddf3..213578485e 100644
--- a/core/string/ustring.cpp
+++ b/core/string/ustring.cpp
@@ -3864,7 +3864,6 @@ String String::xml_escape(bool p_escape_quotes) const {
}
/*
for (int i=1;i<32;i++) {
-
char chr[2]={i,0};
str=str.replace(chr,"&#"+String::num(i)+";");
}*/
diff --git a/core/string/ustring.h b/core/string/ustring.h
index b46733ab66..bfae16fe64 100644
--- a/core/string/ustring.h
+++ b/core/string/ustring.h
@@ -198,7 +198,6 @@ class String {
public:
enum {
-
npos = -1 ///<for "some" compatibility with std::string (npos is a huge value in std::string)
};
diff --git a/core/templates/hash_map.h b/core/templates/hash_map.h
index f6b889015a..e1ba381595 100644
--- a/core/templates/hash_map.h
+++ b/core/templates/hash_map.h
@@ -73,7 +73,7 @@ public:
private:
friend class HashMap;
- uint32_t hash;
+ uint32_t hash = 0;
Element *next = nullptr;
Element() {}
Pair pair;
diff --git a/core/templates/list.h b/core/templates/list.h
index d745066e4c..8e14aaa90d 100644
--- a/core/templates/list.h
+++ b/core/templates/list.h
@@ -137,9 +137,9 @@ public:
private:
struct _Data {
- Element *first;
- Element *last;
- int size_cache;
+ Element *first = nullptr;
+ Element *last = nullptr;
+ int size_cache = 0;
bool erase(const Element *p_I) {
ERR_FAIL_COND_V(!p_I, false);
diff --git a/core/templates/safe_refcount.h b/core/templates/safe_refcount.h
index dc4e62354a..6b08b876f8 100644
--- a/core/templates/safe_refcount.h
+++ b/core/templates/safe_refcount.h
@@ -165,7 +165,7 @@ uint64_t atomic_exchange_if_greater(volatile uint64_t *pw, volatile uint64_t val
#endif
struct SafeRefCount {
- uint32_t count;
+ uint32_t count = 0;
public:
// destroy() is called when weak_count_ drops to zero.
diff --git a/core/templates/set.h b/core/templates/set.h
index 1bc0a3f41e..d0ac71a710 100644
--- a/core/templates/set.h
+++ b/core/templates/set.h
@@ -80,7 +80,7 @@ public:
private:
struct _Data {
Element *_root = nullptr;
- Element *_nil;
+ Element *_nil = nullptr;
int size_cache = 0;
_FORCE_INLINE_ _Data() {
diff --git a/core/templates/sort_array.h b/core/templates/sort_array.h
index a4326ac565..ece5e72e51 100644
--- a/core/templates/sort_array.h
+++ b/core/templates/sort_array.h
@@ -54,7 +54,6 @@ struct _DefaultComparator {
template <class T, class Comparator = _DefaultComparator<T>, bool Validate = SORT_ARRAY_VALIDATE_ENABLED>
class SortArray {
enum {
-
INTROSORT_THRESHOLD = 16
};
diff --git a/core/templates/thread_work_pool.h b/core/templates/thread_work_pool.h
index 661060aa3f..e083cdcb24 100644
--- a/core/templates/thread_work_pool.h
+++ b/core/templates/thread_work_pool.h
@@ -41,8 +41,8 @@ class ThreadWorkPool {
std::atomic<uint32_t> index;
struct BaseWork {
- std::atomic<uint32_t> *index;
- uint32_t max_elements;
+ std::atomic<uint32_t> *index = nullptr;
+ uint32_t max_elements = 0;
virtual void work() = 0;
virtual ~BaseWork() = default;
};
diff --git a/core/variant/array.cpp b/core/variant/array.cpp
index 79bc01b89c..5043868b1d 100644
--- a/core/variant/array.cpp
+++ b/core/variant/array.cpp
@@ -371,7 +371,7 @@ void Array::sort() {
}
struct _ArrayVariantSortCustom {
- Object *obj;
+ Object *obj = nullptr;
StringName func;
_FORCE_INLINE_ bool operator()(const Variant &p_l, const Variant &p_r) const {
diff --git a/core/variant/binder_common.h b/core/variant/binder_common.h
index 2e38ce5b06..e950709526 100644
--- a/core/variant/binder_common.h
+++ b/core/variant/binder_common.h
@@ -63,8 +63,6 @@ struct VariantCaster<const T &> {
}
};
-#ifdef PTRCALL_ENABLED
-
#define VARIANT_ENUM_CAST(m_enum) \
MAKE_ENUM_TYPE_INFO(m_enum) \
template <> \
@@ -83,19 +81,6 @@ struct VariantCaster<const T &> {
} \
};
-#else
-
-#define VARIANT_ENUM_CAST(m_enum) \
- MAKE_ENUM_TYPE_INFO(m_enum) \
- template <> \
- struct VariantCaster<m_enum> { \
- static _FORCE_INLINE_ m_enum cast(const Variant &p_variant) { \
- return (m_enum)p_variant.operator int(); \
- } \
- };
-
-#endif
-
// Object enum casts must go here
VARIANT_ENUM_CAST(Object::ConnectFlags);
@@ -118,7 +103,7 @@ struct VariantCaster<char32_t> {
return (char32_t)p_variant.operator int();
}
};
-#ifdef PTRCALL_ENABLED
+
template <>
struct PtrToArg<char32_t> {
_FORCE_INLINE_ static char32_t convert(const void *p_ptr) {
@@ -128,7 +113,6 @@ struct PtrToArg<char32_t> {
*(int *)p_ptr = p_val;
}
};
-#endif
template <typename T>
struct VariantObjectClassChecker {
@@ -228,8 +212,6 @@ void call_with_variant_argsc_helper(T *p_instance, void (T::*p_method)(P...) con
(void)(p_args); //avoid warning
}
-#ifdef PTRCALL_ENABLED
-
template <class T, class... P, size_t... Is>
void call_with_ptr_args_helper(T *p_instance, void (T::*p_method)(P...), const void **p_args, IndexSequence<Is...>) {
(p_instance->*p_method)(PtrToArg<P>::convert(p_args[Is])...);
@@ -255,8 +237,6 @@ void call_with_ptr_args_static_retc_helper(T *p_instance, R (*p_method)(T *, P..
PtrToArg<R>::encode(p_method(p_instance, PtrToArg<P>::convert(p_args[Is])...), r_ret);
}
-#endif // PTRCALL_ENABLED
-
template <class T, class... P, size_t... Is>
void call_with_validated_variant_args_helper(T *p_instance, void (T::*p_method)(P...), const Variant **p_args, IndexSequence<Is...>) {
(p_instance->*p_method)((VariantInternalAccessor<typename GetSimpleTypeT<P>::type_t>::get(p_args[Is]))...);
@@ -450,8 +430,6 @@ void call_with_variant_args_retc_dv(T *p_instance, R (T::*p_method)(P...) const,
call_with_variant_args_retc_helper(p_instance, p_method, args, r_ret, r_error, BuildIndexSequence<sizeof...(P)>{});
}
-#ifdef PTRCALL_ENABLED
-
template <class T, class... P>
void call_with_ptr_args(T *p_instance, void (T::*p_method)(P...), const void **p_args) {
call_with_ptr_args_helper<T, P...>(p_instance, p_method, p_args, BuildIndexSequence<sizeof...(P)>{});
@@ -477,8 +455,6 @@ void call_with_ptr_args_static_retc(T *p_instance, R (*p_method)(T *, P...), con
call_with_ptr_args_static_retc_helper<T, R, P...>(p_instance, p_method, p_args, r_ret, BuildIndexSequence<sizeof...(P)>{});
}
-#endif // PTRCALL_ENABLED
-
template <class T, class... P>
void call_with_validated_variant_args(Variant *base, void (T::*p_method)(P...), const Variant **p_args) {
call_with_validated_variant_args_helper<T, P...>(VariantGetInternalPtr<T>::get_ptr(base), p_method, p_args, BuildIndexSequence<sizeof...(P)>{});
diff --git a/core/variant/callable.h b/core/variant/callable.h
index 40621fbde3..9334ae3581 100644
--- a/core/variant/callable.h
+++ b/core/variant/callable.h
@@ -62,9 +62,9 @@ public:
CALL_ERROR_TOO_FEW_ARGUMENTS, // expected is number of arguments
CALL_ERROR_INSTANCE_IS_NULL,
};
- Error error;
- int argument;
- int expected;
+ Error error = Error::CALL_OK;
+ int argument = 0;
+ int expected = 0;
};
void call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, CallError &r_call_error) const;
diff --git a/core/variant/method_ptrcall.h b/core/variant/method_ptrcall.h
index 936de145f8..40fa3543dc 100644
--- a/core/variant/method_ptrcall.h
+++ b/core/variant/method_ptrcall.h
@@ -36,11 +36,8 @@
#include "core/typedefs.h"
#include "core/variant/variant.h"
-#ifdef PTRCALL_ENABLED
-
template <class T>
-struct PtrToArg {
-};
+struct PtrToArg {};
#define MAKE_PTRARG(m_type) \
template <> \
@@ -146,7 +143,7 @@ MAKE_PTRARG(PackedVector3Array);
MAKE_PTRARG(PackedColorArray);
MAKE_PTRARG_BY_REFERENCE(Variant);
-//this is for Object
+// This is for Object.
template <class T>
struct PtrToArg<T *> {
@@ -170,7 +167,7 @@ struct PtrToArg<const T *> {
}
};
-//this is for ObjectID
+// This is for ObjectID.
template <>
struct PtrToArg<ObjectID> {
@@ -183,7 +180,7 @@ struct PtrToArg<ObjectID> {
}
};
-//this is for the special cases used by Variant
+// This is for the special cases used by Variant.
#define MAKE_VECARG(m_type) \
template <> \
@@ -274,18 +271,11 @@ struct PtrToArg<ObjectID> {
return ret; \
} \
}
-/*
-MAKE_VECARG(String);
-MAKE_VECARG(uint8_t);
-MAKE_VECARG(int);
-MAKE_VECARG(float);
-MAKE_VECARG(Vector2);
-MAKE_VECARG(Vector3);
-MAKE_VECARG(Color);
-*/
+
MAKE_VECARG_ALT(String, StringName);
-//for stuff that gets converted to Array vectors
+// For stuff that gets converted to Array vectors.
+
#define MAKE_VECARR(m_type) \
template <> \
struct PtrToArg<Vector<m_type>> { \
@@ -429,6 +419,7 @@ struct PtrToArg<Vector<Face3>> {
}
}
};
+
template <>
struct PtrToArg<const Vector<Face3> &> {
_FORCE_INLINE_ static Vector<Face3> convert(const void *p_ptr) {
@@ -450,4 +441,3 @@ struct PtrToArg<const Vector<Face3> &> {
};
#endif // METHOD_PTRCALL_H
-#endif
diff --git a/core/variant/typed_array.h b/core/variant/typed_array.h
index ff42cb687e..2f11f22ff8 100644
--- a/core/variant/typed_array.h
+++ b/core/variant/typed_array.h
@@ -120,8 +120,6 @@ MAKE_TYPED_ARRAY(Vector<Vector2>, Variant::PACKED_VECTOR2_ARRAY)
MAKE_TYPED_ARRAY(Vector<Vector3>, Variant::PACKED_VECTOR3_ARRAY)
MAKE_TYPED_ARRAY(Vector<Color>, Variant::PACKED_COLOR_ARRAY)
-#ifdef PTRCALL_ENABLED
-
template <class T>
struct PtrToArg<TypedArray<T>> {
_FORCE_INLINE_ static TypedArray<T> convert(const void *p_ptr) {
@@ -140,8 +138,6 @@ struct PtrToArg<const TypedArray<T> &> {
}
};
-#endif // PTRCALL_ENABLED
-
#ifdef DEBUG_METHODS_ENABLED
template <class T>
diff --git a/core/variant/variant.h b/core/variant/variant.h
index 1a684eeea0..d87078b5da 100644
--- a/core/variant/variant.h
+++ b/core/variant/variant.h
@@ -128,7 +128,7 @@ private:
struct ObjData {
ObjectID id;
- Object *obj;
+ Object *obj = nullptr;
};
/* array helpers */
@@ -370,7 +370,6 @@ public:
#ifdef NEED_LONG_INT
Variant(signed long p_long); // real one
Variant(unsigned long p_long);
-//Variant(long unsigned int p_long);
#endif
Variant(signed short p_short); // real one
Variant(unsigned short p_short);
@@ -426,7 +425,6 @@ public:
// If this changes the table in variant_op must be updated
enum Operator {
-
//comparison
OP_EQUAL,
OP_NOT_EQUAL,
@@ -472,10 +470,8 @@ public:
static Variant::Type get_operator_return_type(Operator p_operator, Type p_type_a, Type p_type_b);
typedef void (*ValidatedOperatorEvaluator)(const Variant *left, const Variant *right, Variant *r_ret);
static ValidatedOperatorEvaluator get_validated_operator_evaluator(Operator p_operator, Type p_type_a, Type p_type_b);
-#ifdef PTRCALL_ENABLED
typedef void (*PTROperatorEvaluator)(const void *left, const void *right, void *r_ret);
static PTROperatorEvaluator get_ptr_operator_evaluator(Operator p_operator, Type p_type_a, Type p_type_b);
-#endif
void zero();
Variant duplicate(bool deep = false) const;
diff --git a/core/variant/variant_call.cpp b/core/variant/variant_call.cpp
index 4cb8457ccd..13514b7b9f 100644
--- a/core/variant/variant_call.cpp
+++ b/core/variant/variant_call.cpp
@@ -42,27 +42,6 @@
typedef void (*VariantFunc)(Variant &r_ret, Variant &p_self, const Variant **p_args);
typedef void (*VariantConstructFunc)(Variant &r_ret, const Variant **p_args);
-template <class T>
-struct TypeAdjust {
- _FORCE_INLINE_ static void adjust(Variant *r_ret) {
- VariantTypeChanger<typename GetSimpleTypeT<T>::type_t>::change(r_ret);
- }
-};
-
-template <> //do nothing for variant
-struct TypeAdjust<Variant> {
- _FORCE_INLINE_ static void adjust(Variant *r_ret) {
- }
-};
-
-template <> //do nothing for variant
-struct TypeAdjust<Object *> {
- _FORCE_INLINE_ static void adjust(Variant *r_ret) {
- VariantInternal::clear(r_ret);
- *r_ret = (Object *)nullptr;
- }
-};
-
template <class R, class T, class... P>
static _FORCE_INLINE_ void vc_method_call(R (T::*method)(P...), Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, const Vector<Variant> &p_defvals, Callable::CallError &r_error) {
call_with_variant_args_ret_dv(VariantGetInternalPtr<T>::get_ptr(base), method, p_args, p_argcount, r_ret, r_error, p_defvals);
@@ -123,6 +102,31 @@ static _FORCE_INLINE_ void vc_ptrcall(void (T::*method)(P...) const, void *p_bas
}
template <class R, class T, class... P>
+static _FORCE_INLINE_ void vc_change_return_type(R (T::*method)(P...), Variant *v) {
+ VariantTypeAdjust<R>::adjust(v);
+}
+
+template <class R, class T, class... P>
+static _FORCE_INLINE_ void vc_change_return_type(R (T::*method)(P...) const, Variant *v) {
+ VariantTypeAdjust<R>::adjust(v);
+}
+
+template <class T, class... P>
+static _FORCE_INLINE_ void vc_change_return_type(void (T::*method)(P...), Variant *v) {
+ VariantInternal::clear(v);
+}
+
+template <class T, class... P>
+static _FORCE_INLINE_ void vc_change_return_type(void (T::*method)(P...) const, Variant *v) {
+ VariantInternal::clear(v);
+}
+
+template <class R, class... P>
+static _FORCE_INLINE_ void vc_change_return_type(R (*method)(P...), Variant *v) {
+ VariantTypeAdjust<R>::adjust(v);
+}
+
+template <class R, class T, class... P>
static _FORCE_INLINE_ int vc_get_argument_count(R (T::*method)(P...)) {
return sizeof...(P);
}
@@ -258,7 +262,7 @@ static _FORCE_INLINE_ Variant::Type vc_get_base_type(void (T::*method)(P...) con
vc_method_call(m_method_ptr, base, p_args, p_argcount, r_ret, p_defvals, r_error); \
} \
static void validated_call(Variant *base, const Variant **p_args, int p_argcount, Variant *r_ret) { \
- TypeAdjust<m_class>::adjust(r_ret); \
+ vc_change_return_type(m_method_ptr, r_ret); \
vc_validated_call(m_method_ptr, base, p_args, r_ret); \
} \
static void ptrcall(void *p_base, const void **p_args, void *r_ret, int p_argcount) { \
@@ -301,7 +305,7 @@ static _FORCE_INLINE_ void vc_ptrcall(R (*method)(T *, P...), void *p_base, cons
call_with_variant_args_retc_static_helper_dv(VariantGetInternalPtr<m_class>::get_ptr(base), m_method_ptr, p_args, p_argcount, r_ret, p_defvals, r_error); \
} \
static void validated_call(Variant *base, const Variant **p_args, int p_argcount, Variant *r_ret) { \
- TypeAdjust<m_class>::adjust(r_ret); \
+ vc_change_return_type(m_method_ptr, r_ret); \
call_with_validated_variant_args_static_retc(base, m_method_ptr, p_args, r_ret); \
} \
static void ptrcall(void *p_base, const void **p_args, void *r_ret, int p_argcount) { \
@@ -607,7 +611,6 @@ void Variant::call(const StringName &p_method, const Variant **p_args, int p_arg
r_ret = _get_obj().obj->call(p_method, p_args, p_argcount, r_error);
//else if (type==Variant::METHOD) {
-
} else {
r_error.error = Callable::CallError::CALL_OK;
diff --git a/core/variant/variant_internal.h b/core/variant/variant_internal.h
index 3ac7f32dec..bf7e46eed7 100644
--- a/core/variant/variant_internal.h
+++ b/core/variant/variant_internal.h
@@ -38,7 +38,82 @@
class VariantInternal {
public:
// Set type.
- _FORCE_INLINE_ static void initialize(Variant *v, Variant::Type p_type) { v->type = p_type; }
+ _FORCE_INLINE_ static void initialize(Variant *v, Variant::Type p_type) {
+ v->clear();
+ v->type = p_type;
+
+ switch (p_type) {
+ case Variant::AABB:
+ init_aabb(v);
+ break;
+ case Variant::TRANSFORM2D:
+ init_transform2d(v);
+ break;
+ case Variant::TRANSFORM:
+ init_transform(v);
+ break;
+ case Variant::STRING:
+ init_string(v);
+ break;
+ case Variant::STRING_NAME:
+ init_string_name(v);
+ break;
+ case Variant::NODE_PATH:
+ init_node_path(v);
+ break;
+ case Variant::CALLABLE:
+ init_callable(v);
+ break;
+ case Variant::SIGNAL:
+ init_signal(v);
+ break;
+ case Variant::DICTIONARY:
+ init_dictionary(v);
+ break;
+ case Variant::ARRAY:
+ init_array(v);
+ break;
+ case Variant::PACKED_BYTE_ARRAY:
+ init_byte_array(v);
+ break;
+ case Variant::PACKED_INT32_ARRAY:
+ init_int32_array(v);
+ break;
+ case Variant::PACKED_INT64_ARRAY:
+ init_int64_array(v);
+ break;
+ case Variant::PACKED_FLOAT32_ARRAY:
+ init_float32_array(v);
+ break;
+ case Variant::PACKED_FLOAT64_ARRAY:
+ init_float64_array(v);
+ break;
+ case Variant::PACKED_STRING_ARRAY:
+ init_string_array(v);
+ break;
+ case Variant::PACKED_VECTOR2_ARRAY:
+ init_vector2_array(v);
+ break;
+ case Variant::PACKED_VECTOR3_ARRAY:
+ init_vector3_array(v);
+ break;
+ case Variant::PACKED_COLOR_ARRAY:
+ init_color_array(v);
+ break;
+ default:
+ break;
+ }
+ }
+
+ _FORCE_INLINE_ static void set_object(Variant *v, Object *obj) {
+ if (obj) {
+ v->_get_obj().obj = obj;
+ v->_get_obj().id = obj->get_instance_id();
+ } else {
+ v->_get_obj().obj = nullptr;
+ v->_get_obj().id = ObjectID();
+ }
+ }
// Atomic types.
_FORCE_INLINE_ static bool *get_bool(Variant *v) { return &v->_data._bool; }
@@ -216,6 +291,162 @@ public:
v->_get_obj().obj = nullptr;
v->_get_obj().id = ObjectID();
}
+
+ _FORCE_INLINE_ static void *get_opaque_pointer(Variant *v) {
+ switch (v->type) {
+ case Variant::NIL:
+ return nullptr;
+ case Variant::BOOL:
+ return get_bool(v);
+ case Variant::INT:
+ return get_int(v);
+ case Variant::FLOAT:
+ return get_float(v);
+ case Variant::STRING:
+ return get_string(v);
+ case Variant::VECTOR2:
+ return get_vector2(v);
+ case Variant::VECTOR2I:
+ return get_vector2i(v);
+ case Variant::VECTOR3:
+ return get_vector3(v);
+ case Variant::VECTOR3I:
+ return get_vector3i(v);
+ case Variant::RECT2:
+ return get_rect2(v);
+ case Variant::RECT2I:
+ return get_rect2i(v);
+ case Variant::TRANSFORM:
+ return get_transform(v);
+ case Variant::TRANSFORM2D:
+ return get_transform2d(v);
+ case Variant::QUAT:
+ return get_quat(v);
+ case Variant::PLANE:
+ return get_plane(v);
+ case Variant::BASIS:
+ return get_basis(v);
+ case Variant::AABB:
+ return get_aabb(v);
+ case Variant::COLOR:
+ return get_color(v);
+ case Variant::STRING_NAME:
+ return get_string_name(v);
+ case Variant::NODE_PATH:
+ return get_node_path(v);
+ case Variant::RID:
+ return get_rid(v);
+ case Variant::CALLABLE:
+ return get_callable(v);
+ case Variant::SIGNAL:
+ return get_signal(v);
+ case Variant::DICTIONARY:
+ return get_dictionary(v);
+ case Variant::ARRAY:
+ return get_array(v);
+ case Variant::PACKED_BYTE_ARRAY:
+ return get_byte_array(v);
+ case Variant::PACKED_INT32_ARRAY:
+ return get_int32_array(v);
+ case Variant::PACKED_INT64_ARRAY:
+ return get_int64_array(v);
+ case Variant::PACKED_FLOAT32_ARRAY:
+ return get_float32_array(v);
+ case Variant::PACKED_FLOAT64_ARRAY:
+ return get_float64_array(v);
+ case Variant::PACKED_STRING_ARRAY:
+ return get_string_array(v);
+ case Variant::PACKED_VECTOR2_ARRAY:
+ return get_vector2_array(v);
+ case Variant::PACKED_VECTOR3_ARRAY:
+ return get_vector3_array(v);
+ case Variant::PACKED_COLOR_ARRAY:
+ return get_color_array(v);
+ case Variant::OBJECT:
+ return v->_get_obj().obj;
+ case Variant::VARIANT_MAX:
+ ERR_FAIL_V(nullptr);
+ }
+ ERR_FAIL_V(nullptr);
+ }
+
+ _FORCE_INLINE_ static const void *get_opaque_pointer(const Variant *v) {
+ switch (v->type) {
+ case Variant::NIL:
+ return nullptr;
+ case Variant::BOOL:
+ return get_bool(v);
+ case Variant::INT:
+ return get_int(v);
+ case Variant::FLOAT:
+ return get_float(v);
+ case Variant::STRING:
+ return get_string(v);
+ case Variant::VECTOR2:
+ return get_vector2(v);
+ case Variant::VECTOR2I:
+ return get_vector2i(v);
+ case Variant::VECTOR3:
+ return get_vector3(v);
+ case Variant::VECTOR3I:
+ return get_vector3i(v);
+ case Variant::RECT2:
+ return get_rect2(v);
+ case Variant::RECT2I:
+ return get_rect2i(v);
+ case Variant::TRANSFORM:
+ return get_transform(v);
+ case Variant::TRANSFORM2D:
+ return get_transform2d(v);
+ case Variant::QUAT:
+ return get_quat(v);
+ case Variant::PLANE:
+ return get_plane(v);
+ case Variant::BASIS:
+ return get_basis(v);
+ case Variant::AABB:
+ return get_aabb(v);
+ case Variant::COLOR:
+ return get_color(v);
+ case Variant::STRING_NAME:
+ return get_string_name(v);
+ case Variant::NODE_PATH:
+ return get_node_path(v);
+ case Variant::RID:
+ return get_rid(v);
+ case Variant::CALLABLE:
+ return get_callable(v);
+ case Variant::SIGNAL:
+ return get_signal(v);
+ case Variant::DICTIONARY:
+ return get_dictionary(v);
+ case Variant::ARRAY:
+ return get_array(v);
+ case Variant::PACKED_BYTE_ARRAY:
+ return get_byte_array(v);
+ case Variant::PACKED_INT32_ARRAY:
+ return get_int32_array(v);
+ case Variant::PACKED_INT64_ARRAY:
+ return get_int64_array(v);
+ case Variant::PACKED_FLOAT32_ARRAY:
+ return get_float32_array(v);
+ case Variant::PACKED_FLOAT64_ARRAY:
+ return get_float64_array(v);
+ case Variant::PACKED_STRING_ARRAY:
+ return get_string_array(v);
+ case Variant::PACKED_VECTOR2_ARRAY:
+ return get_vector2_array(v);
+ case Variant::PACKED_VECTOR3_ARRAY:
+ return get_vector3_array(v);
+ case Variant::PACKED_COLOR_ARRAY:
+ return get_color_array(v);
+ case Variant::OBJECT:
+ return v->_get_obj().obj;
+ case Variant::VARIANT_MAX:
+ ERR_FAIL_V(nullptr);
+ }
+ ERR_FAIL_V(nullptr);
+ }
};
template <class T>
@@ -1128,4 +1359,26 @@ struct VariantTypeChanger {
}
};
+template <class T>
+struct VariantTypeAdjust {
+ _FORCE_INLINE_ static void adjust(Variant *r_ret) {
+ VariantTypeChanger<typename GetSimpleTypeT<T>::type_t>::change(r_ret);
+ }
+};
+
+template <>
+struct VariantTypeAdjust<Variant> {
+ _FORCE_INLINE_ static void adjust(Variant *r_ret) {
+ // Do nothing for variant.
+ }
+};
+
+template <>
+struct VariantTypeAdjust<Object *> {
+ _FORCE_INLINE_ static void adjust(Variant *r_ret) {
+ VariantInternal::clear(r_ret);
+ *r_ret = (Object *)nullptr;
+ }
+};
+
#endif // VARIANT_INTERNAL_H
diff --git a/core/variant/variant_op.cpp b/core/variant/variant_op.cpp
index 8e55c1d6cd..07b024ecb4 100644
--- a/core/variant/variant_op.cpp
+++ b/core/variant/variant_op.cpp
@@ -47,11 +47,9 @@ public:
VariantTypeChanger<R>::change(r_ret);
*VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) + *VariantGetInternalPtr<B>::get_ptr(right);
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<R>::encode(PtrToArg<A>::convert(left) + PtrToArg<B>::convert(right), r_ret);
}
-#endif
static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; }
};
@@ -68,11 +66,9 @@ public:
VariantTypeChanger<R>::change(r_ret);
*VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) - *VariantGetInternalPtr<B>::get_ptr(right);
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<R>::encode(PtrToArg<A>::convert(left) - PtrToArg<B>::convert(right), r_ret);
}
-#endif
static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; }
};
@@ -89,11 +85,9 @@ public:
VariantTypeChanger<R>::change(r_ret);
*VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) * *VariantGetInternalPtr<B>::get_ptr(right);
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<R>::encode(PtrToArg<A>::convert(left) * PtrToArg<B>::convert(right), r_ret);
}
-#endif
static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; }
};
@@ -110,11 +104,9 @@ public:
VariantTypeChanger<R>::change(r_ret);
*VariantGetInternalPtr<R>::get_ptr(r_ret) = VariantGetInternalPtr<A>::get_ptr(left)->xform(*VariantGetInternalPtr<B>::get_ptr(right));
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<R>::encode(PtrToArg<A>::convert(left).xform(PtrToArg<B>::convert(right)), r_ret);
}
-#endif
static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; }
};
@@ -131,11 +123,9 @@ public:
VariantTypeChanger<R>::change(r_ret);
*VariantGetInternalPtr<R>::get_ptr(r_ret) = VariantGetInternalPtr<B>::get_ptr(right)->xform_inv(*VariantGetInternalPtr<A>::get_ptr(left));
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<R>::encode(PtrToArg<B>::convert(right).xform_inv(PtrToArg<A>::convert(left)), r_ret);
}
-#endif
static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; }
};
@@ -152,11 +142,9 @@ public:
VariantTypeChanger<R>::change(r_ret);
*VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) / *VariantGetInternalPtr<B>::get_ptr(right);
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<R>::encode(PtrToArg<A>::convert(left) / PtrToArg<B>::convert(right), r_ret);
}
-#endif
static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; }
};
@@ -178,11 +166,9 @@ public:
VariantTypeChanger<R>::change(r_ret);
*VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) / *VariantGetInternalPtr<B>::get_ptr(right);
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<R>::encode(PtrToArg<A>::convert(left) / PtrToArg<B>::convert(right), r_ret);
}
-#endif
static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; }
};
@@ -199,11 +185,9 @@ public:
VariantTypeChanger<R>::change(r_ret);
*VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) % *VariantGetInternalPtr<B>::get_ptr(right);
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<R>::encode(PtrToArg<A>::convert(left) % PtrToArg<B>::convert(right), r_ret);
}
-#endif
static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; }
};
@@ -225,11 +209,9 @@ public:
VariantTypeChanger<R>::change(r_ret);
*VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) % *VariantGetInternalPtr<B>::get_ptr(right);
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<R>::encode(PtrToArg<A>::convert(left) % PtrToArg<B>::convert(right), r_ret);
}
-#endif
static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; }
};
@@ -245,11 +227,9 @@ public:
VariantTypeChanger<R>::change(r_ret);
*VariantGetInternalPtr<R>::get_ptr(r_ret) = -*VariantGetInternalPtr<A>::get_ptr(left);
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<R>::encode(-PtrToArg<A>::convert(left), r_ret);
}
-#endif
static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; }
};
@@ -265,11 +245,9 @@ public:
VariantTypeChanger<R>::change(r_ret);
*VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left);
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<R>::encode(PtrToArg<A>::convert(left), r_ret);
}
-#endif
static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; }
};
@@ -286,11 +264,9 @@ public:
VariantTypeChanger<R>::change(r_ret);
*VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) << *VariantGetInternalPtr<B>::get_ptr(right);
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<R>::encode(PtrToArg<A>::convert(left) << PtrToArg<B>::convert(right), r_ret);
}
-#endif
static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; }
};
@@ -307,11 +283,9 @@ public:
VariantTypeChanger<R>::change(r_ret);
*VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) >> *VariantGetInternalPtr<B>::get_ptr(right);
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<R>::encode(PtrToArg<A>::convert(left) >> PtrToArg<B>::convert(right), r_ret);
}
-#endif
static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; }
};
@@ -328,11 +302,9 @@ public:
VariantTypeChanger<R>::change(r_ret);
*VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) | *VariantGetInternalPtr<B>::get_ptr(right);
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<R>::encode(PtrToArg<A>::convert(left) | PtrToArg<B>::convert(right), r_ret);
}
-#endif
static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; }
};
@@ -348,11 +320,9 @@ public:
static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
*VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) & *VariantGetInternalPtr<B>::get_ptr(right);
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<R>::encode(PtrToArg<A>::convert(left) & PtrToArg<B>::convert(right), r_ret);
}
-#endif
static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; }
};
@@ -369,11 +339,9 @@ public:
VariantTypeChanger<R>::change(r_ret);
*VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) ^ *VariantGetInternalPtr<B>::get_ptr(right);
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<R>::encode(PtrToArg<A>::convert(left) ^ PtrToArg<B>::convert(right), r_ret);
}
-#endif
static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; }
};
@@ -389,11 +357,9 @@ public:
VariantTypeChanger<R>::change(r_ret);
*VariantGetInternalPtr<R>::get_ptr(r_ret) = ~*VariantGetInternalPtr<A>::get_ptr(left);
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<R>::encode(~PtrToArg<A>::convert(left), r_ret);
}
-#endif
static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; }
};
@@ -410,14 +376,12 @@ public:
VariantTypeChanger<bool>::change(r_ret);
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) == *VariantGetInternalPtr<B>::get_ptr(right);
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<bool>::encode(PtrToArg<A>::convert(left) == PtrToArg<B>::convert(right), r_ret);
}
-#endif
static Variant::Type get_return_type() { return Variant::BOOL; }
};
-//equalobject
+
class OperatorEvaluatorEqualObject {
public:
static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) {
@@ -432,11 +396,9 @@ public:
VariantTypeChanger<bool>::change(r_ret);
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = a == b;
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<bool>::encode(PtrToArg<Object *>::convert(left) == PtrToArg<Object *>::convert(right), r_ret);
}
-#endif
static Variant::Type get_return_type() { return Variant::BOOL; }
};
@@ -452,11 +414,9 @@ public:
VariantTypeChanger<bool>::change(r_ret);
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = a == nullptr;
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<bool>::encode(PtrToArg<Object *>::convert(left) == nullptr, r_ret);
}
-#endif
static Variant::Type get_return_type() { return Variant::BOOL; }
};
@@ -472,11 +432,9 @@ public:
VariantTypeChanger<bool>::change(r_ret);
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = nullptr == b;
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<bool>::encode(nullptr == PtrToArg<Object *>::convert(right), r_ret);
}
-#endif
static Variant::Type get_return_type() { return Variant::BOOL; }
};
@@ -493,11 +451,9 @@ public:
VariantTypeChanger<bool>::change(r_ret);
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) != *VariantGetInternalPtr<B>::get_ptr(right);
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<bool>::encode(PtrToArg<A>::convert(left) != PtrToArg<B>::convert(right), r_ret);
}
-#endif
static Variant::Type get_return_type() { return Variant::BOOL; }
};
@@ -515,11 +471,9 @@ public:
VariantTypeChanger<bool>::change(r_ret);
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = a != b;
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<bool>::encode(PtrToArg<Object *>::convert(left) != PtrToArg<Object *>::convert(right), r_ret);
}
-#endif
static Variant::Type get_return_type() { return Variant::BOOL; }
};
@@ -535,11 +489,9 @@ public:
VariantTypeChanger<bool>::change(r_ret);
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = a != nullptr;
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<bool>::encode(PtrToArg<Object *>::convert(left) != nullptr, r_ret);
}
-#endif
static Variant::Type get_return_type() { return Variant::BOOL; }
};
@@ -555,11 +507,9 @@ public:
VariantTypeChanger<bool>::change(r_ret);
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = nullptr != b;
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<bool>::encode(nullptr != PtrToArg<Object *>::convert(right), r_ret);
}
-#endif
static Variant::Type get_return_type() { return Variant::BOOL; }
};
@@ -576,11 +526,9 @@ public:
VariantTypeChanger<bool>::change(r_ret);
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) < *VariantGetInternalPtr<B>::get_ptr(right);
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<bool>::encode(PtrToArg<A>::convert(left) < PtrToArg<B>::convert(right), r_ret);
}
-#endif
static Variant::Type get_return_type() { return Variant::BOOL; }
};
@@ -597,11 +545,9 @@ public:
VariantTypeChanger<bool>::change(r_ret);
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) <= *VariantGetInternalPtr<B>::get_ptr(right);
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<bool>::encode(PtrToArg<A>::convert(left) <= PtrToArg<B>::convert(right), r_ret);
}
-#endif
static Variant::Type get_return_type() { return Variant::BOOL; }
};
@@ -618,11 +564,9 @@ public:
VariantTypeChanger<bool>::change(r_ret);
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) > *VariantGetInternalPtr<B>::get_ptr(right);
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<bool>::encode(PtrToArg<A>::convert(left) > PtrToArg<B>::convert(right), r_ret);
}
-#endif
static Variant::Type get_return_type() { return Variant::BOOL; }
};
@@ -639,11 +583,9 @@ public:
VariantTypeChanger<bool>::change(r_ret);
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) >= *VariantGetInternalPtr<B>::get_ptr(right);
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<bool>::encode(PtrToArg<A>::convert(left) >= PtrToArg<B>::convert(right), r_ret);
}
-#endif
static Variant::Type get_return_type() { return Variant::BOOL; }
};
@@ -660,12 +602,9 @@ public:
VariantTypeChanger<bool>::change(r_ret);
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) && *VariantGetInternalPtr<B>::get_ptr(right);
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<bool>::encode(PtrToArg<A>::convert(left) && PtrToArg<B>::convert(right), r_ret);
}
-#endif
-
static Variant::Type get_return_type() { return Variant::BOOL; }
};
@@ -682,11 +621,9 @@ public:
VariantTypeChanger<bool>::change(r_ret);
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) || *VariantGetInternalPtr<B>::get_ptr(right);
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<bool>::encode(PtrToArg<A>::convert(left) || PtrToArg<B>::convert(right), r_ret);
}
-#endif
static Variant::Type get_return_type() { return Variant::BOOL; }
};
@@ -697,7 +634,6 @@ public:
_FORCE_INLINE_ static bool xor_op(const A &a, const B &b) {
return ((a) || (b)) && !((a) && (b));
}
-
static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) {
const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left);
const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right);
@@ -708,12 +644,9 @@ public:
VariantTypeChanger<bool>::change(r_ret);
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = xor_op(*VariantGetInternalPtr<A>::get_ptr(left), *VariantGetInternalPtr<B>::get_ptr(right));
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<bool>::encode(xor_op(PtrToArg<A>::convert(left), PtrToArg<B>::convert(right)), r_ret);
}
-#endif
-
static Variant::Type get_return_type() { return Variant::BOOL; }
};
@@ -729,11 +662,9 @@ public:
VariantTypeChanger<bool>::change(r_ret);
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = !*VariantGetInternalPtr<A>::get_ptr(left);
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<bool>::encode(!PtrToArg<A>::convert(left));
}
-#endif
static Variant::Type get_return_type() { return Variant::BOOL; }
};
@@ -764,14 +695,11 @@ public:
VariantTypeChanger<Array>::change(r_ret);
_add_arrays(*VariantGetInternalPtr<Array>::get_ptr(r_ret), *VariantGetInternalPtr<Array>::get_ptr(left), *VariantGetInternalPtr<Array>::get_ptr(right));
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
Array ret;
_add_arrays(ret, PtrToArg<Array>::convert(left), PtrToArg<Array>::convert(right));
PtrToArg<Array>::encode(ret, r_ret);
}
-#endif
-
static Variant::Type get_return_type() { return Variant::ARRAY; }
};
@@ -791,14 +719,11 @@ public:
*VariantGetInternalPtr<Vector<T>>::get_ptr(r_ret) = *VariantGetInternalPtr<Vector<T>>::get_ptr(left);
VariantGetInternalPtr<Vector<T>>::get_ptr(r_ret)->append_array(*VariantGetInternalPtr<Vector<T>>::get_ptr(right));
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
Vector<T> sum = PtrToArg<Vector<T>>::convert(left);
sum.append_array(PtrToArg<Vector<T>>::convert(right));
PtrToArg<Vector<T>>::encode(sum, r_ret);
}
-#endif
-
static Variant::Type get_return_type() { return GetTypeInfo<Vector<T>>::VARIANT_TYPE; }
};
@@ -819,16 +744,13 @@ public:
*r_ret = do_mod(a, &r_valid);
r_valid = true;
}
-
static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
VariantTypeChanger<String>::change(r_ret);
*VariantGetInternalPtr<String>::get_ptr(r_ret) = do_mod(*VariantGetInternalPtr<String>::get_ptr(left), nullptr);
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<String>::encode(do_mod(PtrToArg<String>::convert(left), nullptr), r_ret);
}
-#endif
static Variant::Type get_return_type() { return Variant::STRING; }
};
@@ -846,16 +768,13 @@ public:
*r_ret = do_mod(a, *VariantGetInternalPtr<Array>::get_ptr(&p_right), &r_valid);
r_valid = true;
}
-
static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
VariantTypeChanger<String>::change(r_ret);
*VariantGetInternalPtr<String>::get_ptr(r_ret) = do_mod(*VariantGetInternalPtr<String>::get_ptr(left), *VariantGetInternalPtr<Array>::get_ptr(right), nullptr);
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<String>::encode(do_mod(PtrToArg<String>::convert(left), PtrToArg<Array>::convert(right), nullptr), r_ret);
}
-#endif
static Variant::Type get_return_type() { return Variant::STRING; }
};
@@ -876,16 +795,13 @@ public:
*r_ret = do_mod(a, p_right.get_validated_object(), &r_valid);
r_valid = true;
}
-
static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
VariantTypeChanger<String>::change(r_ret);
*VariantGetInternalPtr<String>::get_ptr(r_ret) = do_mod(*VariantGetInternalPtr<String>::get_ptr(left), right->get_validated_object(), nullptr);
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<String>::encode(do_mod(PtrToArg<String>::convert(left), PtrToArg<Object *>::convert(right), nullptr), r_ret);
}
-#endif
static Variant::Type get_return_type() { return Variant::STRING; }
};
@@ -906,16 +822,13 @@ public:
*r_ret = do_mod(a, *VariantGetInternalPtr<T>::get_ptr(&p_right), &r_valid);
r_valid = true;
}
-
static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
VariantTypeChanger<String>::change(r_ret);
*VariantGetInternalPtr<String>::get_ptr(r_ret) = do_mod(*VariantGetInternalPtr<String>::get_ptr(left), *VariantGetInternalPtr<T>::get_ptr(right), nullptr);
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<String>::encode(do_mod(PtrToArg<String>::convert(left), PtrToArg<T>::convert(right), nullptr), r_ret);
}
-#endif
static Variant::Type get_return_type() { return Variant::STRING; }
};
@@ -926,16 +839,13 @@ public:
*r_ret = true;
r_valid = true;
}
-
static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
VariantTypeChanger<bool>::change(r_ret);
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = true;
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<bool>::encode(true, r_ret);
}
-#endif
static Variant::Type get_return_type() { return Variant::BOOL; }
};
@@ -946,16 +856,13 @@ public:
*r_ret = false;
r_valid = true;
}
-
static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
VariantTypeChanger<bool>::change(r_ret);
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = false;
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<bool>::encode(false, r_ret);
}
-#endif
static Variant::Type get_return_type() { return Variant::BOOL; }
};
@@ -964,9 +871,11 @@ public:
_FORCE_INLINE_ static bool _operate_or(bool p_left, bool p_right) {
return p_left || p_right;
}
+
_FORCE_INLINE_ static bool _operate_and(bool p_left, bool p_right) {
return p_left && p_right;
}
+
_FORCE_INLINE_ static bool _operate_xor(bool p_left, bool p_right) {
return (p_left || p_right) && !(p_left && p_right);
}
@@ -991,29 +900,6 @@ _FORCE_INLINE_ static bool _operate_get_object(const Variant *p_ptr) {
return p_ptr->get_validated_object() != nullptr;
}
-#ifndef PTRCALL_ENABLED
-
-#define OP_EVALUATOR(m_class_name, m_left, m_right, m_op) \
- class m_class_name { \
- public: \
- static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { \
- *r_ret = m_op(_operate_get_##m_left(&p_left), _operate_get_##m_right(&p_right)); \
- r_valid = true; \
- } \
- \
- static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { \
- VariantTypeChanger<bool>::change(r_ret); \
- *VariantGetInternalPtr<bool>::get_ptr(r_ret) = m_op(_operate_get_##m_left(left), _operate_get_##m_right(right)); \
- } \
- \
- static Variant::Type \
- get_return_type() { \
- return Variant::BOOL; \
- } \
- };
-
-#else
-
_FORCE_INLINE_ static bool _operate_get_ptr_nil(const void *p_ptr) {
return false;
}
@@ -1056,11 +942,9 @@ _FORCE_INLINE_ static bool _operate_get_ptr_object(const void *p_ptr) {
} \
};
-#endif
-
// OR
-//nil
+// nil
OP_EVALUATOR(OperatorEvaluatorNilXBoolOr, nil, bool, _operate_or)
OP_EVALUATOR(OperatorEvaluatorBoolXNilOr, bool, nil, _operate_or)
@@ -1073,7 +957,7 @@ OP_EVALUATOR(OperatorEvaluatorFloatXNilOr, float, nil, _operate_or)
OP_EVALUATOR(OperatorEvaluatorObjectXNilOr, object, nil, _operate_or)
OP_EVALUATOR(OperatorEvaluatorNilXObjectOr, nil, object, _operate_or)
-//bool
+// bool
OP_EVALUATOR(OperatorEvaluatorBoolXBoolOr, bool, bool, _operate_or)
OP_EVALUATOR(OperatorEvaluatorBoolXIntOr, bool, int, _operate_or)
@@ -1085,8 +969,7 @@ OP_EVALUATOR(OperatorEvaluatorFloatXBoolOr, float, bool, _operate_or)
OP_EVALUATOR(OperatorEvaluatorBoolXObjectOr, bool, object, _operate_or)
OP_EVALUATOR(OperatorEvaluatorObjectXBoolOr, object, bool, _operate_or)
-//int
-
+// int
OP_EVALUATOR(OperatorEvaluatorIntXIntOr, int, int, _operate_or)
OP_EVALUATOR(OperatorEvaluatorIntXFloatOr, int, float, _operate_or)
@@ -1095,20 +978,18 @@ OP_EVALUATOR(OperatorEvaluatorFloatXIntOr, float, int, _operate_or)
OP_EVALUATOR(OperatorEvaluatorIntXObjectOr, int, object, _operate_or)
OP_EVALUATOR(OperatorEvaluatorObjectXIntOr, object, int, _operate_or)
-//float
-
+// float
OP_EVALUATOR(OperatorEvaluatorFloatXFloatOr, float, float, _operate_or)
OP_EVALUATOR(OperatorEvaluatorFloatXObjectOr, float, object, _operate_or)
OP_EVALUATOR(OperatorEvaluatorObjectXFloatOr, object, float, _operate_or)
-//object
-
+// object
OP_EVALUATOR(OperatorEvaluatorObjectXObjectOr, object, object, _operate_or)
// AND
-//nil
+// nil
OP_EVALUATOR(OperatorEvaluatorNilXBoolAnd, nil, bool, _operate_and)
OP_EVALUATOR(OperatorEvaluatorBoolXNilAnd, bool, nil, _operate_and)
@@ -1121,7 +1002,7 @@ OP_EVALUATOR(OperatorEvaluatorFloatXNilAnd, float, nil, _operate_and)
OP_EVALUATOR(OperatorEvaluatorObjectXNilAnd, object, nil, _operate_and)
OP_EVALUATOR(OperatorEvaluatorNilXObjectAnd, nil, object, _operate_and)
-//bool
+// bool
OP_EVALUATOR(OperatorEvaluatorBoolXBoolAnd, bool, bool, _operate_and)
OP_EVALUATOR(OperatorEvaluatorBoolXIntAnd, bool, int, _operate_and)
@@ -1133,8 +1014,7 @@ OP_EVALUATOR(OperatorEvaluatorFloatXBoolAnd, float, bool, _operate_and)
OP_EVALUATOR(OperatorEvaluatorBoolXObjectAnd, bool, object, _operate_and)
OP_EVALUATOR(OperatorEvaluatorObjectXBoolAnd, object, bool, _operate_and)
-//int
-
+// int
OP_EVALUATOR(OperatorEvaluatorIntXIntAnd, int, int, _operate_and)
OP_EVALUATOR(OperatorEvaluatorIntXFloatAnd, int, float, _operate_and)
@@ -1143,20 +1023,18 @@ OP_EVALUATOR(OperatorEvaluatorFloatXIntAnd, float, int, _operate_and)
OP_EVALUATOR(OperatorEvaluatorIntXObjectAnd, int, object, _operate_and)
OP_EVALUATOR(OperatorEvaluatorObjectXIntAnd, object, int, _operate_and)
-//float
-
+// float
OP_EVALUATOR(OperatorEvaluatorFloatXFloatAnd, float, float, _operate_and)
OP_EVALUATOR(OperatorEvaluatorFloatXObjectAnd, float, object, _operate_and)
OP_EVALUATOR(OperatorEvaluatorObjectXFloatAnd, object, float, _operate_and)
-//object
-
+// object
OP_EVALUATOR(OperatorEvaluatorObjectXObjectAnd, object, object, _operate_and)
// XOR
-//nil
+// nil
OP_EVALUATOR(OperatorEvaluatorNilXBoolXor, nil, bool, _operate_xor)
OP_EVALUATOR(OperatorEvaluatorBoolXNilXor, bool, nil, _operate_xor)
@@ -1169,7 +1047,7 @@ OP_EVALUATOR(OperatorEvaluatorFloatXNilXor, float, nil, _operate_xor)
OP_EVALUATOR(OperatorEvaluatorObjectXNilXor, object, nil, _operate_xor)
OP_EVALUATOR(OperatorEvaluatorNilXObjectXor, nil, object, _operate_xor)
-//bool
+// bool
OP_EVALUATOR(OperatorEvaluatorBoolXBoolXor, bool, bool, _operate_xor)
OP_EVALUATOR(OperatorEvaluatorBoolXIntXor, bool, int, _operate_xor)
@@ -1181,8 +1059,7 @@ OP_EVALUATOR(OperatorEvaluatorFloatXBoolXor, float, bool, _operate_xor)
OP_EVALUATOR(OperatorEvaluatorBoolXObjectXor, bool, object, _operate_xor)
OP_EVALUATOR(OperatorEvaluatorObjectXBoolXor, object, bool, _operate_xor)
-//int
-
+// int
OP_EVALUATOR(OperatorEvaluatorIntXIntXor, int, int, _operate_xor)
OP_EVALUATOR(OperatorEvaluatorIntXFloatXor, int, float, _operate_xor)
@@ -1191,15 +1068,13 @@ OP_EVALUATOR(OperatorEvaluatorFloatXIntXor, float, int, _operate_xor)
OP_EVALUATOR(OperatorEvaluatorIntXObjectXor, int, object, _operate_xor)
OP_EVALUATOR(OperatorEvaluatorObjectXIntXor, object, int, _operate_xor)
-//float
-
+// float
OP_EVALUATOR(OperatorEvaluatorFloatXFloatXor, float, float, _operate_xor)
OP_EVALUATOR(OperatorEvaluatorFloatXObjectXor, float, object, _operate_xor)
OP_EVALUATOR(OperatorEvaluatorObjectXFloatXor, object, float, _operate_xor)
-//object
-
+// object
OP_EVALUATOR(OperatorEvaluatorObjectXObjectXor, object, object, _operate_xor)
class OperatorEvaluatorNotBool {
@@ -1208,17 +1083,13 @@ public:
*r_ret = !*VariantGetInternalPtr<bool>::get_ptr(&p_left);
r_valid = true;
}
-
static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
VariantTypeChanger<bool>::change(r_ret);
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = !*VariantGetInternalPtr<bool>::get_ptr(left);
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<bool>::encode(!PtrToArg<bool>::convert(left), r_ret);
}
-#endif
-
static Variant::Type get_return_type() { return Variant::BOOL; }
};
@@ -1228,17 +1099,13 @@ public:
*r_ret = !*VariantGetInternalPtr<int64_t>::get_ptr(&p_left);
r_valid = true;
}
-
static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
VariantTypeChanger<bool>::change(r_ret);
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = !*VariantGetInternalPtr<int64_t>::get_ptr(left);
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<bool>::encode(!PtrToArg<int64_t>::convert(left), r_ret);
}
-#endif
-
static Variant::Type get_return_type() { return Variant::BOOL; }
};
@@ -1248,17 +1115,13 @@ public:
*r_ret = !*VariantGetInternalPtr<double>::get_ptr(&p_left);
r_valid = true;
}
-
static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
VariantTypeChanger<bool>::change(r_ret);
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = !*VariantGetInternalPtr<double>::get_ptr(left);
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<bool>::encode(!PtrToArg<double>::convert(left), r_ret);
}
-#endif
-
static Variant::Type get_return_type() { return Variant::BOOL; }
};
@@ -1268,17 +1131,13 @@ public:
*r_ret = p_left.get_validated_object() == nullptr;
r_valid = true;
}
-
static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
VariantTypeChanger<bool>::change(r_ret);
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = left->get_validated_object() == nullptr;
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<bool>::encode(PtrToArg<Object *>::convert(left) == nullptr, r_ret);
}
-#endif
-
static Variant::Type get_return_type() { return Variant::BOOL; }
};
@@ -1293,18 +1152,15 @@ public:
*r_ret = str_b.find(str_a) != -1;
r_valid = true;
}
-
static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
const String &str_a = *VariantGetInternalPtr<String>::get_ptr(left);
const String &str_b = *VariantGetInternalPtr<String>::get_ptr(right);
VariantTypeChanger<bool>::change(r_ret);
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = str_b.find(str_a) != -1;
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<bool>::encode(PtrToArg<String>::convert(right).find(PtrToArg<String>::convert(left)) != -1, r_ret);
}
-#endif
static Variant::Type get_return_type() { return Variant::BOOL; }
};
@@ -1318,18 +1174,15 @@ public:
*r_ret = b.find(a) != -1;
r_valid = true;
}
-
static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
const A &a = *VariantGetInternalPtr<A>::get_ptr(left);
const B &b = *VariantGetInternalPtr<B>::get_ptr(right);
VariantTypeChanger<bool>::change(r_ret);
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = b.find(a) != -1;
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<bool>::encode(PtrToArg<B>::convert(right).find(PtrToArg<A>::convert(left)) != -1, r_ret);
}
-#endif
static Variant::Type get_return_type() { return Variant::BOOL; }
};
@@ -1340,17 +1193,14 @@ public:
*r_ret = b.find(Variant()) != -1;
r_valid = true;
}
-
static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
const Array &b = *VariantGetInternalPtr<Array>::get_ptr(right);
VariantTypeChanger<bool>::change(r_ret);
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = b.find(Variant()) != -1;
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<bool>::encode(PtrToArg<Array>::convert(right).find(Variant()) != -1, r_ret);
}
-#endif
static Variant::Type get_return_type() { return Variant::BOOL; }
};
@@ -1361,17 +1211,14 @@ public:
*r_ret = b.find(p_left) != -1;
r_valid = true;
}
-
static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
const Array &b = *VariantGetInternalPtr<Array>::get_ptr(right);
VariantTypeChanger<bool>::change(r_ret);
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = b.find(*left) != -1;
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<bool>::encode(PtrToArg<Array>::convert(right).find(PtrToArg<Object *>::convert(left)) != -1, r_ret);
}
-#endif
static Variant::Type get_return_type() { return Variant::BOOL; }
};
@@ -1385,18 +1232,15 @@ public:
*r_ret = b.has(a);
r_valid = true;
}
-
static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
const Dictionary &b = *VariantGetInternalPtr<Dictionary>::get_ptr(right);
const A &a = *VariantGetInternalPtr<A>::get_ptr(left);
VariantTypeChanger<bool>::change(r_ret);
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = b.has(a);
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<bool>::encode(PtrToArg<Dictionary>::convert(right).has(PtrToArg<A>::convert(left)), r_ret);
}
-#endif
static Variant::Type get_return_type() { return Variant::BOOL; }
};
@@ -1408,17 +1252,14 @@ public:
*r_ret = b.has(Variant());
r_valid = true;
}
-
static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
const Dictionary &b = *VariantGetInternalPtr<Dictionary>::get_ptr(right);
VariantTypeChanger<bool>::change(r_ret);
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = b.has(Variant());
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<bool>::encode(PtrToArg<Dictionary>::convert(right).has(Variant()), r_ret);
}
-#endif
static Variant::Type get_return_type() { return Variant::BOOL; }
};
@@ -1430,17 +1271,14 @@ public:
*r_ret = b.has(p_left);
r_valid = true;
}
-
static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
const Dictionary &b = *VariantGetInternalPtr<Dictionary>::get_ptr(right);
VariantTypeChanger<bool>::change(r_ret);
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = b.has(*left);
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<bool>::encode(PtrToArg<Dictionary>::convert(right).has(PtrToArg<Object *>::convert(left)), r_ret);
}
-#endif
static Variant::Type get_return_type() { return Variant::BOOL; }
};
@@ -1459,7 +1297,6 @@ public:
b->get(a, &r_valid);
*r_ret = r_valid;
}
-
static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
Object *l = right->get_validated_object();
ERR_FAIL_COND(l == nullptr);
@@ -1470,13 +1307,11 @@ public:
VariantTypeChanger<bool>::change(r_ret);
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = valid;
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
bool valid;
PtrToArg<Object *>::convert(right)->get(PtrToArg<String>::convert(left), &valid);
PtrToArg<bool>::encode(valid, r_ret);
}
-#endif
static Variant::Type get_return_type() { return Variant::BOOL; }
};
@@ -1495,7 +1330,6 @@ public:
b->get(a, &r_valid);
*r_ret = r_valid;
}
-
static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
Object *l = right->get_validated_object();
ERR_FAIL_COND(l == nullptr);
@@ -1506,13 +1340,11 @@ public:
VariantTypeChanger<bool>::change(r_ret);
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = valid;
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
bool valid;
PtrToArg<Object *>::convert(right)->get(PtrToArg<StringName>::convert(left), &valid);
PtrToArg<bool>::encode(valid, r_ret);
}
-#endif
static Variant::Type get_return_type() { return Variant::BOOL; }
};
@@ -1521,27 +1353,21 @@ typedef void (*VariantEvaluatorFunction)(const Variant &p_left, const Variant &p
static Variant::Type operator_return_type_table[Variant::OP_MAX][Variant::VARIANT_MAX][Variant::VARIANT_MAX];
static VariantEvaluatorFunction operator_evaluator_table[Variant::OP_MAX][Variant::VARIANT_MAX][Variant::VARIANT_MAX];
static Variant::ValidatedOperatorEvaluator validated_operator_evaluator_table[Variant::OP_MAX][Variant::VARIANT_MAX][Variant::VARIANT_MAX];
-#ifdef PTRCALL_ENABLED
static Variant::PTROperatorEvaluator ptr_operator_evaluator_table[Variant::OP_MAX][Variant::VARIANT_MAX][Variant::VARIANT_MAX];
-#endif
template <class T>
void register_op(Variant::Operator p_op, Variant::Type p_type_a, Variant::Type p_type_b) {
operator_return_type_table[p_op][p_type_a][p_type_b] = T::get_return_type();
operator_evaluator_table[p_op][p_type_a][p_type_b] = T::evaluate;
validated_operator_evaluator_table[p_op][p_type_a][p_type_b] = T::validated_evaluate;
-#ifdef PTRCALL_ENABLED
ptr_operator_evaluator_table[p_op][p_type_a][p_type_b] = T::ptr_evaluate;
-#endif
}
void Variant::_register_variant_operators() {
zeromem(operator_return_type_table, sizeof(operator_return_type_table));
zeromem(operator_evaluator_table, sizeof(operator_evaluator_table));
zeromem(validated_operator_evaluator_table, sizeof(validated_operator_evaluator_table));
-#ifdef PTRCALL_ENABLED
zeromem(ptr_operator_evaluator_table, sizeof(ptr_operator_evaluator_table));
-#endif
register_op<OperatorEvaluatorAdd<int64_t, int64_t, int64_t>>(Variant::OP_ADD, Variant::INT, Variant::INT);
register_op<OperatorEvaluatorAdd<double, int64_t, double>>(Variant::OP_ADD, Variant::INT, Variant::FLOAT);
@@ -1896,7 +1722,7 @@ void Variant::_register_variant_operators() {
register_op<OperatorEvaluatorAlwaysFalse<Variant::OP_OR, Variant::NIL, Variant::NIL>>(Variant::OP_OR, Variant::NIL, Variant::NIL);
- //OR
+ // OR
register_op<OperatorEvaluatorNilXBoolOr>(Variant::OP_OR, Variant::NIL, Variant::BOOL);
register_op<OperatorEvaluatorBoolXNilOr>(Variant::OP_OR, Variant::BOOL, Variant::NIL);
register_op<OperatorEvaluatorNilXIntOr>(Variant::OP_OR, Variant::NIL, Variant::INT);
@@ -1924,7 +1750,8 @@ void Variant::_register_variant_operators() {
register_op<OperatorEvaluatorFloatXObjectOr>(Variant::OP_OR, Variant::FLOAT, Variant::OBJECT);
register_op<OperatorEvaluatorObjectXFloatOr>(Variant::OP_OR, Variant::OBJECT, Variant::FLOAT);
register_op<OperatorEvaluatorObjectXObjectOr>(Variant::OP_OR, Variant::OBJECT, Variant::OBJECT);
- //AND
+
+ // AND
register_op<OperatorEvaluatorNilXBoolAnd>(Variant::OP_AND, Variant::NIL, Variant::BOOL);
register_op<OperatorEvaluatorBoolXNilAnd>(Variant::OP_AND, Variant::BOOL, Variant::NIL);
register_op<OperatorEvaluatorNilXIntAnd>(Variant::OP_AND, Variant::NIL, Variant::INT);
@@ -1952,7 +1779,8 @@ void Variant::_register_variant_operators() {
register_op<OperatorEvaluatorFloatXObjectAnd>(Variant::OP_AND, Variant::FLOAT, Variant::OBJECT);
register_op<OperatorEvaluatorObjectXFloatAnd>(Variant::OP_AND, Variant::OBJECT, Variant::FLOAT);
register_op<OperatorEvaluatorObjectXObjectAnd>(Variant::OP_AND, Variant::OBJECT, Variant::OBJECT);
- //XOR
+
+ // XOR
register_op<OperatorEvaluatorNilXBoolXor>(Variant::OP_XOR, Variant::NIL, Variant::BOOL);
register_op<OperatorEvaluatorBoolXNilXor>(Variant::OP_XOR, Variant::BOOL, Variant::NIL);
register_op<OperatorEvaluatorNilXIntXor>(Variant::OP_XOR, Variant::NIL, Variant::INT);
@@ -2124,7 +1952,7 @@ Variant::ValidatedOperatorEvaluator Variant::get_validated_operator_evaluator(Op
ERR_FAIL_INDEX_V(p_type_b, Variant::VARIANT_MAX, nullptr);
return validated_operator_evaluator_table[p_operator][p_type_a][p_type_b];
}
-#ifdef PTRCALL_ENABLED
+
Variant::PTROperatorEvaluator Variant::get_ptr_operator_evaluator(Operator p_operator, Type p_type_a, Type p_type_b) {
ERR_FAIL_INDEX_V(p_operator, Variant::OP_MAX, nullptr);
ERR_FAIL_INDEX_V(p_type_a, Variant::VARIANT_MAX, nullptr);
@@ -2132,8 +1960,6 @@ Variant::PTROperatorEvaluator Variant::get_ptr_operator_evaluator(Operator p_ope
return ptr_operator_evaluator_table[p_operator][p_type_a][p_type_b];
}
-#endif
-
static const char *_op_names[Variant::OP_MAX] = {
"==",
"!=",
@@ -2159,7 +1985,6 @@ static const char *_op_names[Variant::OP_MAX] = {
"xor",
"not",
"in"
-
};
String Variant::get_operator_name(Operator p_op) {
diff --git a/core/variant/variant_parser.h b/core/variant/variant_parser.h
index 59d18a8b9f..cf1941a40e 100644
--- a/core/variant/variant_parser.h
+++ b/core/variant/variant_parser.h
@@ -100,7 +100,6 @@ public:
};
enum Expecting {
-
EXPECT_OBJECT,
EXPECT_OBJECT_KEY,
EXPECT_COLON,
diff --git a/core/variant/variant_setget.cpp b/core/variant/variant_setget.cpp
index 05fe2b80d9..f6a2c11830 100644
--- a/core/variant/variant_setget.cpp
+++ b/core/variant/variant_setget.cpp
@@ -41,9 +41,7 @@
#define SETGET_STRUCT(m_base_type, m_member_type, m_member) \
struct VariantSetGet_##m_base_type##_##m_member { \
static void get(const Variant *base, Variant *member) { \
- *member = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_member; \
- } \
- static void validated_get(const Variant *base, Variant *member) { \
+ VariantTypeAdjust<m_member_type>::adjust(member); \
*VariantGetInternalPtr<m_member_type>::get_ptr(member) = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_member; \
} \
static void ptr_get(const void *base, void *member) { \
@@ -71,9 +69,7 @@
#define SETGET_NUMBER_STRUCT(m_base_type, m_member_type, m_member) \
struct VariantSetGet_##m_base_type##_##m_member { \
static void get(const Variant *base, Variant *member) { \
- *member = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_member; \
- } \
- static void validated_get(const Variant *base, Variant *member) { \
+ VariantTypeAdjust<m_member_type>::adjust(member); \
*VariantGetInternalPtr<m_member_type>::get_ptr(member) = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_member; \
} \
static void ptr_get(const void *base, void *member) { \
@@ -104,9 +100,7 @@
#define SETGET_STRUCT_CUSTOM(m_base_type, m_member_type, m_member, m_custom) \
struct VariantSetGet_##m_base_type##_##m_member { \
static void get(const Variant *base, Variant *member) { \
- *member = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_custom; \
- } \
- static void validated_get(const Variant *base, Variant *member) { \
+ VariantTypeAdjust<m_member_type>::adjust(member); \
*VariantGetInternalPtr<m_member_type>::get_ptr(member) = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_custom; \
} \
static void ptr_get(const void *base, void *member) { \
@@ -134,9 +128,7 @@
#define SETGET_NUMBER_STRUCT_CUSTOM(m_base_type, m_member_type, m_member, m_custom) \
struct VariantSetGet_##m_base_type##_##m_member { \
static void get(const Variant *base, Variant *member) { \
- *member = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_custom; \
- } \
- static void validated_get(const Variant *base, Variant *member) { \
+ VariantTypeAdjust<m_member_type>::adjust(member); \
*VariantGetInternalPtr<m_member_type>::get_ptr(member) = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_custom; \
} \
static void ptr_get(const void *base, void *member) { \
@@ -167,9 +159,7 @@
#define SETGET_STRUCT_FUNC(m_base_type, m_member_type, m_member, m_setter, m_getter) \
struct VariantSetGet_##m_base_type##_##m_member { \
static void get(const Variant *base, Variant *member) { \
- *member = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_getter(); \
- } \
- static void validated_get(const Variant *base, Variant *member) { \
+ VariantTypeAdjust<m_member_type>::adjust(member); \
*VariantGetInternalPtr<m_member_type>::get_ptr(member) = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_getter(); \
} \
static void ptr_get(const void *base, void *member) { \
@@ -197,9 +187,7 @@
#define SETGET_NUMBER_STRUCT_FUNC(m_base_type, m_member_type, m_member, m_setter, m_getter) \
struct VariantSetGet_##m_base_type##_##m_member { \
static void get(const Variant *base, Variant *member) { \
- *member = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_getter(); \
- } \
- static void validated_get(const Variant *base, Variant *member) { \
+ VariantTypeAdjust<m_member_type>::adjust(member); \
*VariantGetInternalPtr<m_member_type>::get_ptr(member) = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_getter(); \
} \
static void ptr_get(const void *base, void *member) { \
@@ -230,9 +218,7 @@
#define SETGET_STRUCT_FUNC_INDEX(m_base_type, m_member_type, m_member, m_setter, m_getter, m_index) \
struct VariantSetGet_##m_base_type##_##m_member { \
static void get(const Variant *base, Variant *member) { \
- *member = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_getter(m_index); \
- } \
- static void validated_get(const Variant *base, Variant *member) { \
+ VariantTypeAdjust<m_member_type>::adjust(member); \
*VariantGetInternalPtr<m_member_type>::get_ptr(member) = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_getter(m_index); \
} \
static void ptr_get(const void *base, void *member) { \
@@ -340,7 +326,7 @@ static void register_member(Variant::Type p_type, const StringName &p_member) {
sgi.ptr_setter = T::ptr_set;
sgi.getter = T::get;
- sgi.validated_getter = T::validated_get;
+ sgi.validated_getter = T::get;
sgi.ptr_getter = T::ptr_get;
sgi.member_type = T::get_type();
@@ -605,18 +591,7 @@ Variant Variant::get_named(const StringName &p_member, bool &r_valid) const {
oob = true; \
return; \
} \
- *value = (*VariantGetInternalPtr<m_base_type>::get_ptr(base))[index]; \
- oob = false; \
- } \
- static void validated_get(const Variant *base, int64_t index, Variant *value, bool &oob) { \
- int64_t size = VariantGetInternalPtr<m_base_type>::get_ptr(base)->size(); \
- if (index < 0) { \
- index += size; \
- } \
- if (index < 0 || index >= size) { \
- oob = true; \
- return; \
- } \
+ VariantTypeAdjust<m_elem_type>::adjust(value); \
*VariantGetInternalPtr<m_elem_type>::get_ptr(value) = (*VariantGetInternalPtr<m_base_type>::get_ptr(base))[index]; \
oob = false; \
} \
@@ -682,18 +657,7 @@ Variant Variant::get_named(const StringName &p_member, bool &r_valid) const {
oob = true; \
return; \
} \
- *value = (*VariantGetInternalPtr<m_base_type>::get_ptr(base))[index]; \
- oob = false; \
- } \
- static void validated_get(const Variant *base, int64_t index, Variant *value, bool &oob) { \
- int64_t size = VariantGetInternalPtr<m_base_type>::get_ptr(base)->size(); \
- if (index < 0) { \
- index += size; \
- } \
- if (index < 0 || index >= size) { \
- oob = true; \
- return; \
- } \
+ VariantTypeAdjust<m_elem_type>::adjust(value); \
*VariantGetInternalPtr<m_elem_type>::get_ptr(value) = (*VariantGetInternalPtr<m_base_type>::get_ptr(base))[index]; \
oob = false; \
} \
@@ -760,14 +724,7 @@ Variant Variant::get_named(const StringName &p_member, bool &r_valid) const {
oob = true; \
return; \
} \
- *value = (*VariantGetInternalPtr<m_base_type>::get_ptr(base))[index]; \
- oob = false; \
- } \
- static void validated_get(const Variant *base, int64_t index, Variant *value, bool &oob) { \
- if (index < 0 || index >= m_max) { \
- oob = true; \
- return; \
- } \
+ VariantTypeAdjust<m_elem_type>::adjust(value); \
*VariantGetInternalPtr<m_elem_type>::get_ptr(value) = (*VariantGetInternalPtr<m_base_type>::get_ptr(base))[index]; \
oob = false; \
} \
@@ -822,14 +779,7 @@ Variant Variant::get_named(const StringName &p_member, bool &r_valid) const {
oob = true; \
return; \
} \
- *value = (*VariantGetInternalPtr<m_base_type>::get_ptr(base))m_accessor[index]; \
- oob = false; \
- } \
- static void validated_get(const Variant *base, int64_t index, Variant *value, bool &oob) { \
- if (index < 0 || index >= m_max) { \
- oob = true; \
- return; \
- } \
+ VariantTypeAdjust<m_elem_type>::adjust(value); \
*VariantGetInternalPtr<m_elem_type>::get_ptr(value) = (*VariantGetInternalPtr<m_base_type>::get_ptr(base))m_accessor[index]; \
oob = false; \
} \
@@ -878,14 +828,7 @@ Variant Variant::get_named(const StringName &p_member, bool &r_valid) const {
oob = true; \
return; \
} \
- *value = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_get(index); \
- oob = false; \
- } \
- static void validated_get(const Variant *base, int64_t index, Variant *value, bool &oob) { \
- if (index < 0 || index >= m_max) { \
- oob = true; \
- return; \
- } \
+ VariantTypeAdjust<m_elem_type>::adjust(value); \
*VariantGetInternalPtr<m_elem_type>::get_ptr(value) = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_get(index); \
oob = false; \
} \
@@ -941,18 +884,6 @@ Variant Variant::get_named(const StringName &p_member, bool &r_valid) const {
*value = (*VariantGetInternalPtr<m_base_type>::get_ptr(base))[index]; \
oob = false; \
} \
- static void validated_get(const Variant *base, int64_t index, Variant *value, bool &oob) { \
- int64_t size = VariantGetInternalPtr<m_base_type>::get_ptr(base)->size(); \
- if (index < 0) { \
- index += size; \
- } \
- if (index < 0 || index >= size) { \
- oob = true; \
- return; \
- } \
- *value = (*VariantGetInternalPtr<m_base_type>::get_ptr(base))[index]; \
- oob = false; \
- } \
static void ptr_get(const void *base, int64_t index, void *member) { \
/* avoid ptrconvert for performance*/ \
const m_base_type &v = *reinterpret_cast<const m_base_type *>(base); \
@@ -1010,15 +941,6 @@ Variant Variant::get_named(const StringName &p_member, bool &r_valid) const {
*value = *ptr; \
oob = false; \
} \
- static void validated_get(const Variant *base, int64_t index, Variant *value, bool &oob) { \
- const Variant *ptr = VariantGetInternalPtr<m_base_type>::get_ptr(base)->getptr(index); \
- if (!ptr) { \
- oob = true; \
- return; \
- } \
- *value = *ptr; \
- oob = false; \
- } \
static void ptr_get(const void *base, int64_t index, void *member) { \
/* avoid ptrconvert for performance*/ \
const m_base_type &v = *reinterpret_cast<const m_base_type *>(base); \
@@ -1094,7 +1016,7 @@ static void register_indexed_member(Variant::Type p_type) {
sgi.ptr_setter = T::ptr_set;
sgi.getter = T::get;
- sgi.validated_getter = T::validated_get;
+ sgi.validated_getter = T::get;
sgi.ptr_getter = T::ptr_get;
sgi.index_type = T::get_index_type();
diff --git a/core/variant/variant_utility.cpp b/core/variant/variant_utility.cpp
index 91a1b0262c..d54e223a99 100644
--- a/core/variant/variant_utility.cpp
+++ b/core/variant/variant_utility.cpp
@@ -40,12 +40,15 @@
struct VariantUtilityFunctions {
// Math
+
static inline double sin(double arg) {
return Math::sin(arg);
}
+
static inline double cos(double arg) {
return Math::cos(arg);
}
+
static inline double tan(double arg) {
return Math::tan(arg);
}
@@ -53,9 +56,11 @@ struct VariantUtilityFunctions {
static inline double sinh(double arg) {
return Math::sinh(arg);
}
+
static inline double cosh(double arg) {
return Math::cosh(arg);
}
+
static inline double tanh(double arg) {
return Math::tanh(arg);
}
@@ -63,9 +68,11 @@ struct VariantUtilityFunctions {
static inline double asin(double arg) {
return Math::asin(arg);
}
+
static inline double acos(double arg) {
return Math::acos(arg);
}
+
static inline double atan(double arg) {
return Math::atan(arg);
}
@@ -173,6 +180,7 @@ struct VariantUtilityFunctions {
static inline double pow(double x, double y) {
return Math::pow(x, y);
}
+
static inline double log(double x) {
return Math::log(x);
}
@@ -181,24 +189,24 @@ struct VariantUtilityFunctions {
return Math::exp(x);
}
- static inline double is_nan(double x) {
+ static inline bool is_nan(double x) {
return Math::is_nan(x);
}
- static inline double is_inf(double x) {
+ static inline bool is_inf(double x) {
return Math::is_inf(x);
}
- static inline double is_equal_approx(double x, double y) {
+ static inline bool is_equal_approx(double x, double y) {
return Math::is_equal_approx(x, y);
}
- static inline double is_zero_approx(double x) {
+ static inline bool is_zero_approx(double x) {
return Math::is_zero_approx(x);
}
- static inline double ease(float x, float c) {
- return Math::ease(x, c);
+ static inline double ease(float x, float curve) {
+ return Math::ease(x, curve);
}
static inline int step_decimals(float step) {
@@ -268,6 +276,7 @@ struct VariantUtilityFunctions {
static inline int64_t wrapi(int64_t value, int64_t min, int64_t max) {
return Math::wrapi(value, min, max);
}
+
static inline double wrapf(double value, double min, double max) {
return Math::wrapf(value, min, max);
}
@@ -528,7 +537,7 @@ struct VariantUtilityFunctions {
str += p_args[i]->operator String();
}
- print_error(str);
+ print_line(str);
r_error.error = Callable::CallError::CALL_OK;
}
@@ -545,7 +554,7 @@ struct VariantUtilityFunctions {
str += p_args[i]->operator String();
}
- print_error(str);
+ print_line(str);
r_error.error = Callable::CallError::CALL_OK;
}
@@ -695,9 +704,9 @@ struct VariantUtilityFunctions {
return p_arr.hash();
}
- static inline Variant instance_from_id(int64_t p_id) {
+ static inline Object *instance_from_id(int64_t p_id) {
ObjectID id = ObjectID((uint64_t)p_id);
- Variant ret = ObjectDB::get_instance(id);
+ Object *ret = ObjectDB::get_instance(id);
return ret;
}
@@ -829,22 +838,18 @@ static _FORCE_INLINE_ Variant::Type get_ret_type_helper(void (*p_func)(P...)) {
static void call(Variant *r_ret, const Variant **p_args, int p_argcount, Callable::CallError &r_error) { \
call_helperr(VariantUtilityFunctions::m_func, r_ret, p_args, r_error); \
} \
- \
static void validated_call(Variant *r_ret, const Variant **p_args, int p_argcount) { \
validated_call_helperr(VariantUtilityFunctions::m_func, r_ret, p_args); \
} \
static void ptrcall(void *ret, const void **p_args, int p_argcount) { \
ptr_call_helperr(VariantUtilityFunctions::m_func, ret, p_args); \
} \
- \
static int get_argument_count() { \
return get_arg_count_helperr(VariantUtilityFunctions::m_func); \
} \
- \
static Variant::Type get_argument_type(int p_arg) { \
return get_arg_type_helperr(VariantUtilityFunctions::m_func, p_arg); \
} \
- \
static Variant::Type get_return_type() { \
return get_ret_type_helperr(VariantUtilityFunctions::m_func); \
} \
@@ -863,7 +868,6 @@ static _FORCE_INLINE_ Variant::Type get_ret_type_helper(void (*p_func)(P...)) {
r_error.error = Callable::CallError::CALL_OK; \
*r_ret = VariantUtilityFunctions::m_func(*p_args[0], r_error); \
} \
- \
static void validated_call(Variant *r_ret, const Variant **p_args, int p_argcount) { \
Callable::CallError ce; \
*r_ret = VariantUtilityFunctions::m_func(*p_args[0], ce); \
@@ -872,15 +876,12 @@ static _FORCE_INLINE_ Variant::Type get_ret_type_helper(void (*p_func)(P...)) {
Callable::CallError ce; \
PtrToArg<Variant>::encode(VariantUtilityFunctions::m_func(PtrToArg<Variant>::convert(p_args[0]), ce), ret); \
} \
- \
static int get_argument_count() { \
return 1; \
} \
- \
static Variant::Type get_argument_type(int p_arg) { \
return Variant::NIL; \
} \
- \
static Variant::Type get_return_type() { \
return Variant::NIL; \
} \
@@ -899,7 +900,6 @@ static _FORCE_INLINE_ Variant::Type get_ret_type_helper(void (*p_func)(P...)) {
r_error.error = Callable::CallError::CALL_OK; \
*r_ret = VariantUtilityFunctions::m_func(*p_args[0], *p_args[1], *p_args[2], r_error); \
} \
- \
static void validated_call(Variant *r_ret, const Variant **p_args, int p_argcount) { \
Callable::CallError ce; \
*r_ret = VariantUtilityFunctions::m_func(*p_args[0], *p_args[1], *p_args[2], ce); \
@@ -910,15 +910,12 @@ static _FORCE_INLINE_ Variant::Type get_ret_type_helper(void (*p_func)(P...)) {
r = VariantUtilityFunctions::m_func(PtrToArg<Variant>::convert(p_args[0]), PtrToArg<Variant>::convert(p_args[1]), PtrToArg<Variant>::convert(p_args[2]), ce); \
PtrToArg<Variant>::encode(r, ret); \
} \
- \
static int get_argument_count() { \
return 3; \
} \
- \
static Variant::Type get_argument_type(int p_arg) { \
return Variant::NIL; \
} \
- \
static Variant::Type get_return_type() { \
return Variant::NIL; \
} \
@@ -937,7 +934,6 @@ static _FORCE_INLINE_ Variant::Type get_ret_type_helper(void (*p_func)(P...)) {
r_error.error = Callable::CallError::CALL_OK; \
*r_ret = VariantUtilityFunctions::m_func(p_args, p_argcount, r_error); \
} \
- \
static void validated_call(Variant *r_ret, const Variant **p_args, int p_argcount) { \
Callable::CallError c; \
*r_ret = VariantUtilityFunctions::m_func(p_args, p_argcount, c); \
@@ -955,15 +951,12 @@ static _FORCE_INLINE_ Variant::Type get_ret_type_helper(void (*p_func)(P...)) {
validated_call(&r, (const Variant **)argsp.ptr(), p_argcount); \
PtrToArg<Variant>::encode(r, ret); \
} \
- \
static int get_argument_count() { \
return 2; \
} \
- \
static Variant::Type get_argument_type(int p_arg) { \
return Variant::NIL; \
} \
- \
static Variant::Type get_return_type() { \
return Variant::NIL; \
} \
@@ -986,7 +979,6 @@ static _FORCE_INLINE_ Variant::Type get_ret_type_helper(void (*p_func)(P...)) {
r_error.error = Callable::CallError::CALL_OK; \
*r_ret = VariantUtilityFunctions::m_func(p_args, p_argcount, r_error); \
} \
- \
static void validated_call(Variant *r_ret, const Variant **p_args, int p_argcount) { \
Callable::CallError c; \
*r_ret = VariantUtilityFunctions::m_func(p_args, p_argcount, c); \
@@ -1004,15 +996,12 @@ static _FORCE_INLINE_ Variant::Type get_ret_type_helper(void (*p_func)(P...)) {
validated_call(&r, (const Variant **)argsp.ptr(), p_argcount); \
PtrToArg<String>::encode(r.operator String(), ret); \
} \
- \
static int get_argument_count() { \
return 1; \
} \
- \
static Variant::Type get_argument_type(int p_arg) { \
return Variant::NIL; \
} \
- \
static Variant::Type get_return_type() { \
return Variant::STRING; \
} \
@@ -1035,7 +1024,6 @@ static _FORCE_INLINE_ Variant::Type get_ret_type_helper(void (*p_func)(P...)) {
r_error.error = Callable::CallError::CALL_OK; \
VariantUtilityFunctions::m_func(p_args, p_argcount, r_error); \
} \
- \
static void validated_call(Variant *r_ret, const Variant **p_args, int p_argcount) { \
Callable::CallError c; \
VariantUtilityFunctions::m_func(p_args, p_argcount, c); \
@@ -1052,15 +1040,12 @@ static _FORCE_INLINE_ Variant::Type get_ret_type_helper(void (*p_func)(P...)) {
Variant r; \
validated_call(&r, (const Variant **)argsp.ptr(), p_argcount); \
} \
- \
static int get_argument_count() { \
return 1; \
} \
- \
static Variant::Type get_argument_type(int p_arg) { \
return Variant::NIL; \
} \
- \
static Variant::Type get_return_type() { \
return Variant::NIL; \
} \
@@ -1082,22 +1067,18 @@ static _FORCE_INLINE_ Variant::Type get_ret_type_helper(void (*p_func)(P...)) {
static void call(Variant *r_ret, const Variant **p_args, int p_argcount, Callable::CallError &r_error) { \
call_helper(VariantUtilityFunctions::m_func, p_args, r_error); \
} \
- \
static void validated_call(Variant *r_ret, const Variant **p_args, int p_argcount) { \
validated_call_helper(VariantUtilityFunctions::m_func, p_args); \
} \
static void ptrcall(void *ret, const void **p_args, int p_argcount) { \
ptr_call_helper(VariantUtilityFunctions::m_func, p_args); \
} \
- \
static int get_argument_count() { \
return get_arg_count_helper(VariantUtilityFunctions::m_func); \
} \
- \
static Variant::Type get_argument_type(int p_arg) { \
return get_arg_type_helper(VariantUtilityFunctions::m_func, p_arg); \
} \
- \
static Variant::Type get_return_type() { \
return get_ret_type_helper(VariantUtilityFunctions::m_func); \
} \
@@ -1187,7 +1168,7 @@ void Variant::_register_variant_utility_functions() {
FUNCBINDR(signf, sarray("x"), Variant::UTILITY_FUNC_TYPE_MATH);
FUNCBINDR(signi, sarray("x"), Variant::UTILITY_FUNC_TYPE_MATH);
- FUNCBINDR(pow, sarray("x", "y"), Variant::UTILITY_FUNC_TYPE_MATH);
+ FUNCBINDR(pow, sarray("base", "exp"), Variant::UTILITY_FUNC_TYPE_MATH);
FUNCBINDR(log, sarray("x"), Variant::UTILITY_FUNC_TYPE_MATH);
FUNCBINDR(exp, sarray("x"), Variant::UTILITY_FUNC_TYPE_MATH);
@@ -1197,17 +1178,17 @@ void Variant::_register_variant_utility_functions() {
FUNCBINDR(is_equal_approx, sarray("a", "b"), Variant::UTILITY_FUNC_TYPE_MATH);
FUNCBINDR(is_zero_approx, sarray("x"), Variant::UTILITY_FUNC_TYPE_MATH);
- FUNCBINDR(ease, sarray("x", "c"), Variant::UTILITY_FUNC_TYPE_MATH);
+ FUNCBINDR(ease, sarray("x", "curve"), Variant::UTILITY_FUNC_TYPE_MATH);
FUNCBINDR(step_decimals, sarray("x"), Variant::UTILITY_FUNC_TYPE_MATH);
FUNCBINDR(range_step_decimals, sarray("x"), Variant::UTILITY_FUNC_TYPE_MATH);
- FUNCBINDR(stepify, sarray("x", "y"), Variant::UTILITY_FUNC_TYPE_MATH);
+ FUNCBINDR(stepify, sarray("x", "step"), Variant::UTILITY_FUNC_TYPE_MATH);
- FUNCBINDR(lerp, sarray("from", "to", "c"), Variant::UTILITY_FUNC_TYPE_MATH);
- FUNCBINDR(lerp_angle, sarray("from", "to", "c"), Variant::UTILITY_FUNC_TYPE_MATH);
- FUNCBINDR(inverse_lerp, sarray("from", "to", "c"), Variant::UTILITY_FUNC_TYPE_MATH);
+ FUNCBINDR(lerp, sarray("from", "to", "weight"), Variant::UTILITY_FUNC_TYPE_MATH);
+ FUNCBINDR(lerp_angle, sarray("from", "to", "weight"), Variant::UTILITY_FUNC_TYPE_MATH);
+ FUNCBINDR(inverse_lerp, sarray("from", "to", "weight"), Variant::UTILITY_FUNC_TYPE_MATH);
FUNCBINDR(range_lerp, sarray("value", "istart", "istop", "ostart", "ostop"), Variant::UTILITY_FUNC_TYPE_MATH);
- FUNCBINDR(smoothstep, sarray("from", "to", "c"), Variant::UTILITY_FUNC_TYPE_MATH);
+ FUNCBINDR(smoothstep, sarray("from", "to", "x"), Variant::UTILITY_FUNC_TYPE_MATH);
FUNCBINDR(move_toward, sarray("from", "to", "delta"), Variant::UTILITY_FUNC_TYPE_MATH);
FUNCBINDR(dectime, sarray("value", "amount", "step"), Variant::UTILITY_FUNC_TYPE_MATH);
@@ -1238,7 +1219,7 @@ void Variant::_register_variant_utility_functions() {
FUNCBINDR(nearest_po2, sarray("value"), Variant::UTILITY_FUNC_TYPE_MATH);
- //Random
+ // Random
FUNCBIND(randomize, sarray(), Variant::UTILITY_FUNC_TYPE_RANDOM);
FUNCBINDR(randi, sarray(), Variant::UTILITY_FUNC_TYPE_RANDOM);
@@ -1249,7 +1230,8 @@ void Variant::_register_variant_utility_functions() {
FUNCBINDR(rand_from_seed, sarray("seed"), Variant::UTILITY_FUNC_TYPE_RANDOM);
// Utility
- FUNCBINDVR(weakref, sarray("from"), Variant::UTILITY_FUNC_TYPE_GENERAL);
+
+ FUNCBINDVR(weakref, sarray("obj"), Variant::UTILITY_FUNC_TYPE_GENERAL);
FUNCBINDR(_typeof, sarray("variable"), Variant::UTILITY_FUNC_TYPE_GENERAL);
FUNCBINDVARARGS(str, sarray(), Variant::UTILITY_FUNC_TYPE_GENERAL);
FUNCBINDVARARGV(print, sarray(), Variant::UTILITY_FUNC_TYPE_GENERAL);
@@ -1271,10 +1253,11 @@ void Variant::_register_variant_utility_functions() {
FUNCBINDR(hash, sarray("variable"), Variant::UTILITY_FUNC_TYPE_GENERAL);
- FUNCBINDR(instance_from_id, sarray("id"), Variant::UTILITY_FUNC_TYPE_GENERAL);
+ FUNCBINDR(instance_from_id, sarray("instance_id"), Variant::UTILITY_FUNC_TYPE_GENERAL);
FUNCBINDR(is_instance_id_valid, sarray("id"), Variant::UTILITY_FUNC_TYPE_GENERAL);
FUNCBINDR(is_instance_valid, sarray("instance"), Variant::UTILITY_FUNC_TYPE_GENERAL);
}
+
void Variant::_unregister_variant_utility_functions() {
utility_function_table.clear();
utility_function_name_table.clear();
@@ -1318,6 +1301,7 @@ Variant::ValidatedUtilityFunction Variant::get_validated_utility_function(const
return bfi->validated_call_utility;
}
+
Variant::PTRUtilityFunction Variant::get_ptr_utility_function(const StringName &p_name) {
const VariantUtilityFunctionInfo *bfi = utility_function_table.lookup_ptr(p_name);
if (!bfi) {
@@ -1344,6 +1328,7 @@ int Variant::get_utility_function_argument_count(const StringName &p_name) {
return bfi->argcount;
}
+
Variant::Type Variant::get_utility_function_argument_type(const StringName &p_name, int p_arg) {
const VariantUtilityFunctionInfo *bfi = utility_function_table.lookup_ptr(p_name);
if (!bfi) {
@@ -1352,6 +1337,7 @@ Variant::Type Variant::get_utility_function_argument_type(const StringName &p_na
return bfi->get_arg_type(p_arg);
}
+
String Variant::get_utility_function_argument_name(const StringName &p_name, int p_arg) {
const VariantUtilityFunctionInfo *bfi = utility_function_table.lookup_ptr(p_name);
if (!bfi) {
@@ -1361,6 +1347,7 @@ String Variant::get_utility_function_argument_name(const StringName &p_name, int
ERR_FAIL_INDEX_V(p_arg, bfi->argnames.size(), String());
return bfi->argnames[p_arg];
}
+
bool Variant::has_utility_function_return_value(const StringName &p_name) {
const VariantUtilityFunctionInfo *bfi = utility_function_table.lookup_ptr(p_name);
if (!bfi) {
@@ -1368,6 +1355,7 @@ bool Variant::has_utility_function_return_value(const StringName &p_name) {
}
return bfi->returns_value;
}
+
Variant::Type Variant::get_utility_function_return_type(const StringName &p_name) {
const VariantUtilityFunctionInfo *bfi = utility_function_table.lookup_ptr(p_name);
if (!bfi) {
@@ -1376,6 +1364,7 @@ Variant::Type Variant::get_utility_function_return_type(const StringName &p_name
return bfi->return_type;
}
+
bool Variant::is_utility_function_vararg(const StringName &p_name) {
const VariantUtilityFunctionInfo *bfi = utility_function_table.lookup_ptr(p_name);
if (!bfi) {