diff --git a/core/object.h b/core/object.h index b46ab496ae0..c7123f63deb 100644 --- a/core/object.h +++ b/core/object.h @@ -43,13 +43,13 @@ #include -#define VARIANT_ARG_LIST const Variant &p_arg1 = Variant(), const Variant &p_arg2 = Variant(), const Variant &p_arg3 = Variant(), const Variant &p_arg4 = Variant(), const Variant &p_arg5 = Variant() -#define VARIANT_ARG_PASS p_arg1, p_arg2, p_arg3, p_arg4, p_arg5 -#define VARIANT_ARG_DECLARE const Variant &p_arg1, const Variant &p_arg2, const Variant &p_arg3, const Variant &p_arg4, const Variant &p_arg5 -#define VARIANT_ARG_MAX 5 -#define VARIANT_ARGPTRS const Variant *argptr[5] = { &p_arg1, &p_arg2, &p_arg3, &p_arg4, &p_arg5 }; -#define VARIANT_ARGPTRS_PASS *argptr[0], *argptr[1], *argptr[2], *argptr[3], *argptr[4] -#define VARIANT_ARGS_FROM_ARRAY(m_arr) m_arr[0], m_arr[1], m_arr[2], m_arr[3], m_arr[4] +#define VARIANT_ARG_LIST const Variant &p_arg1 = Variant(), const Variant &p_arg2 = Variant(), const Variant &p_arg3 = Variant(), const Variant &p_arg4 = Variant(), const Variant &p_arg5 = Variant(), const Variant &p_arg6 = Variant(), const Variant &p_arg7 = Variant(), const Variant &p_arg8 = Variant() +#define VARIANT_ARG_PASS p_arg1, p_arg2, p_arg3, p_arg4, p_arg5, p_arg6, p_arg7, p_arg8 +#define VARIANT_ARG_DECLARE const Variant &p_arg1, const Variant &p_arg2, const Variant &p_arg3, const Variant &p_arg4, const Variant &p_arg5, const Variant &p_arg6, const Variant &p_arg7, const Variant &p_arg8 +#define VARIANT_ARG_MAX 8 +#define VARIANT_ARGPTRS const Variant *argptr[8] = { &p_arg1, &p_arg2, &p_arg3, &p_arg4, &p_arg5, &p_arg6, &p_arg7, &p_arg8 }; +#define VARIANT_ARGPTRS_PASS *argptr[0], *argptr[1], *argptr[2], *argptr[3], *argptr[4], *argptr[5], *argptr[6], *argptr[7] +#define VARIANT_ARGS_FROM_ARRAY(m_arr) m_arr[0], m_arr[1], m_arr[2], m_arr[3], m_arr[4], m_arr[5], m_arr[6], m_arr[7] /** @author Juan Linietsky diff --git a/core/undo_redo.cpp b/core/undo_redo.cpp index c9e1211ea55..8765bc26162 100644 --- a/core/undo_redo.cpp +++ b/core/undo_redo.cpp @@ -445,7 +445,8 @@ Variant UndoRedo::_add_do_method(const Variant **p_args, int p_argcount, Variant v[i] = *p_args[i + 2]; } - add_do_method(object, method, v[0], v[1], v[2], v[3], v[4]); + static_assert(VARIANT_ARG_MAX == 8, "This code needs to be updated if VARIANT_ARG_MAX != 8"); + add_do_method(object, method, v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7]); return Variant(); } @@ -481,7 +482,8 @@ Variant UndoRedo::_add_undo_method(const Variant **p_args, int p_argcount, Varia v[i] = *p_args[i + 2]; } - add_undo_method(object, method, v[0], v[1], v[2], v[3], v[4]); + static_assert(VARIANT_ARG_MAX == 8, "This code needs to be updated if VARIANT_ARG_MAX != 8"); + add_undo_method(object, method, v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7]); return Variant(); } diff --git a/core/variant.h b/core/variant.h index fbe5954ba2e..71d9b43b78a 100644 --- a/core/variant.h +++ b/core/variant.h @@ -379,7 +379,7 @@ public: void call_ptr(const StringName &p_method, const Variant **p_args, int p_argcount, Variant *r_ret, CallError &r_error); Variant call(const StringName &p_method, const Variant **p_args, int p_argcount, CallError &r_error); - Variant call(const StringName &p_method, const Variant &p_arg1 = Variant(), const Variant &p_arg2 = Variant(), const Variant &p_arg3 = Variant(), const Variant &p_arg4 = Variant(), const Variant &p_arg5 = Variant()); + Variant call(const StringName &p_method, const Variant &p_arg1 = Variant(), const Variant &p_arg2 = Variant(), const Variant &p_arg3 = Variant(), const Variant &p_arg4 = Variant(), const Variant &p_arg5 = Variant(), const Variant &p_arg6 = Variant(), const Variant &p_arg7 = Variant(), const Variant &p_arg8 = Variant()); static String get_call_error_text(Object *p_base, const StringName &p_method, const Variant **p_argptrs, int p_argcount, const Variant::CallError &ce); diff --git a/doc/classes/Tween.xml b/doc/classes/Tween.xml index 43de07f4bef..7bcc9cfae86 100644 --- a/doc/classes/Tween.xml +++ b/doc/classes/Tween.xml @@ -70,6 +70,9 @@ + + + Calls [code]callback[/code] of [code]object[/code] after [code]duration[/code]. [code]arg1[/code]-[code]arg5[/code] are arguments to be passed to the callback. @@ -84,6 +87,9 @@ + + + Calls [code]callback[/code] of [code]object[/code] after [code]duration[/code] on the main thread (similar to [method Object.call_deferred]). [code]arg1[/code]-[code]arg5[/code] are arguments to be passed to the callback. diff --git a/editor/animation_track_editor.cpp b/editor/animation_track_editor.cpp index 357d2942ff6..a2d3fe29b1d 100644 --- a/editor/animation_track_editor.cpp +++ b/editor/animation_track_editor.cpp @@ -556,7 +556,8 @@ public: } break; case Animation::TYPE_METHOD: { p_list->push_back(PropertyInfo(Variant::STRING, "name")); - p_list->push_back(PropertyInfo(Variant::INT, "arg_count", PROPERTY_HINT_RANGE, "0,5,1")); + static_assert(VARIANT_ARG_MAX == 8, "PROPERTY_HINT_RANGE needs to be updated if VARIANT_ARG_MAX != 8"); + p_list->push_back(PropertyInfo(Variant::INT, "arg_count", PROPERTY_HINT_RANGE, "0,8,1")); Dictionary d = animation->track_get_key_value(track, key); ERR_FAIL_COND(!d.has("args")); @@ -1205,7 +1206,8 @@ public: } break; case Animation::TYPE_METHOD: { p_list->push_back(PropertyInfo(Variant::STRING, "name")); - p_list->push_back(PropertyInfo(Variant::INT, "arg_count", PROPERTY_HINT_RANGE, "0,5,1")); + static_assert(VARIANT_ARG_MAX == 8, "PROPERTY_HINT_RANGE needs to be updated if VARIANT_ARG_MAX != 8"); + p_list->push_back(PropertyInfo(Variant::INT, "arg_count", PROPERTY_HINT_RANGE, "0,8,1")); Dictionary d = animation->track_get_key_value(first_track, first_key); ERR_FAIL_COND(!d.has("args")); diff --git a/platform/android/java_godot_lib_jni.cpp b/platform/android/java_godot_lib_jni.cpp index 67ebac2c66a..8a46ea145a1 100644 --- a/platform/android/java_godot_lib_jni.cpp +++ b/platform/android/java_godot_lib_jni.cpp @@ -486,7 +486,8 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_calldeferred(JNIEnv * env->DeleteLocalRef(obj); }; - obj->call_deferred(str_method, args[0], args[1], args[2], args[3], args[4]); + static_assert(VARIANT_ARG_MAX == 8, "This code needs to be updated if VARIANT_ARG_MAX != 8"); + obj->call_deferred(str_method, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7]); // something env->PopLocalFrame(NULL); } diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp index b301c802fc1..99845ab5cb2 100644 --- a/scene/animation/animation_player.cpp +++ b/scene/animation/animation_player.cpp @@ -552,6 +552,7 @@ void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, float } #endif + static_assert(VARIANT_ARG_MAX == 8, "This code needs to be updated if VARIANT_ARG_MAX != 8"); if (can_call) { if (method_call_mode == ANIMATION_METHOD_CALL_DEFERRED) { MessageQueue::get_singleton()->push_call( @@ -561,7 +562,10 @@ void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, float s >= 2 ? params[1] : Variant(), s >= 3 ? params[2] : Variant(), s >= 4 ? params[3] : Variant(), - s >= 5 ? params[4] : Variant()); + s >= 5 ? params[4] : Variant(), + s >= 6 ? params[5] : Variant(), + s >= 7 ? params[6] : Variant(), + s >= 8 ? params[7] : Variant()); } else { nc->node->call( method, @@ -569,7 +573,10 @@ void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, float s >= 2 ? params[1] : Variant(), s >= 3 ? params[2] : Variant(), s >= 4 ? params[3] : Variant(), - s >= 5 ? params[4] : Variant()); + s >= 5 ? params[4] : Variant(), + s >= 6 ? params[5] : Variant(), + s >= 7 ? params[6] : Variant(), + s >= 8 ? params[7] : Variant()); } } } diff --git a/scene/animation/animation_tree.cpp b/scene/animation/animation_tree.cpp index e7de36cecf6..d2f4cd37f24 100644 --- a/scene/animation/animation_tree.cpp +++ b/scene/animation/animation_tree.cpp @@ -981,6 +981,7 @@ void AnimationTree::_process_graph(float p_delta) { int s = params.size(); + static_assert(VARIANT_ARG_MAX == 8, "This code needs to be updated if VARIANT_ARG_MAX != 8"); ERR_CONTINUE(s > VARIANT_ARG_MAX); if (can_call) { t->object->call_deferred( @@ -989,7 +990,10 @@ void AnimationTree::_process_graph(float p_delta) { s >= 2 ? params[1] : Variant(), s >= 3 ? params[2] : Variant(), s >= 4 ? params[3] : Variant(), - s >= 5 ? params[4] : Variant()); + s >= 5 ? params[4] : Variant(), + s >= 6 ? params[5] : Variant(), + s >= 7 ? params[6] : Variant(), + s >= 8 ? params[7] : Variant()); } } diff --git a/scene/animation/tween.cpp b/scene/animation/tween.cpp index cb6d5e1624c..cdd10b6e16a 100644 --- a/scene/animation/tween.cpp +++ b/scene/animation/tween.cpp @@ -255,8 +255,8 @@ void Tween::_bind_methods() { // Bind interpolation and follow methods ClassDB::bind_method(D_METHOD("interpolate_property", "object", "property", "initial_val", "final_val", "duration", "trans_type", "ease_type", "delay"), &Tween::interpolate_property, DEFVAL(TRANS_LINEAR), DEFVAL(EASE_IN_OUT), DEFVAL(0)); ClassDB::bind_method(D_METHOD("interpolate_method", "object", "method", "initial_val", "final_val", "duration", "trans_type", "ease_type", "delay"), &Tween::interpolate_method, DEFVAL(TRANS_LINEAR), DEFVAL(EASE_IN_OUT), DEFVAL(0)); - ClassDB::bind_method(D_METHOD("interpolate_callback", "object", "duration", "callback", "arg1", "arg2", "arg3", "arg4", "arg5"), &Tween::interpolate_callback, DEFVAL(Variant()), DEFVAL(Variant()), DEFVAL(Variant()), DEFVAL(Variant()), DEFVAL(Variant())); - ClassDB::bind_method(D_METHOD("interpolate_deferred_callback", "object", "duration", "callback", "arg1", "arg2", "arg3", "arg4", "arg5"), &Tween::interpolate_deferred_callback, DEFVAL(Variant()), DEFVAL(Variant()), DEFVAL(Variant()), DEFVAL(Variant()), DEFVAL(Variant())); + ClassDB::bind_method(D_METHOD("interpolate_callback", "object", "duration", "callback", "arg1", "arg2", "arg3", "arg4", "arg5", "arg6", "arg7", "arg8"), &Tween::interpolate_callback, DEFVAL(Variant()), DEFVAL(Variant()), DEFVAL(Variant()), DEFVAL(Variant()), DEFVAL(Variant()), DEFVAL(Variant()), DEFVAL(Variant()), DEFVAL(Variant())); + ClassDB::bind_method(D_METHOD("interpolate_deferred_callback", "object", "duration", "callback", "arg1", "arg2", "arg3", "arg4", "arg5", "arg6", "arg7", "arg8"), &Tween::interpolate_deferred_callback, DEFVAL(Variant()), DEFVAL(Variant()), DEFVAL(Variant()), DEFVAL(Variant()), DEFVAL(Variant()), DEFVAL(Variant()), DEFVAL(Variant()), DEFVAL(Variant())); ClassDB::bind_method(D_METHOD("follow_property", "object", "property", "initial_val", "target", "target_property", "duration", "trans_type", "ease_type", "delay"), &Tween::follow_property, DEFVAL(TRANS_LINEAR), DEFVAL(EASE_IN_OUT), DEFVAL(0)); ClassDB::bind_method(D_METHOD("follow_method", "object", "method", "initial_val", "target", "target_method", "duration", "trans_type", "ease_type", "delay"), &Tween::follow_method, DEFVAL(TRANS_LINEAR), DEFVAL(EASE_IN_OUT), DEFVAL(0)); ClassDB::bind_method(D_METHOD("targeting_property", "object", "property", "initial", "initial_val", "final_val", "duration", "trans_type", "ease_type", "delay"), &Tween::targeting_property, DEFVAL(TRANS_LINEAR), DEFVAL(EASE_IN_OUT), DEFVAL(0)); @@ -744,6 +744,8 @@ void Tween::_tween_process(float p_delta) { if (data.type == INTER_CALLBACK) { // Is the tween completed? if (data.finish) { + static_assert(VARIANT_ARG_MAX == 8, "This code needs to be updated if VARIANT_ARG_MAX != 8"); + // Are we calling this callback deferred or immediately? if (data.call_deferred) { // Run the deferred function callback, applying the correct number of arguments @@ -766,16 +768,28 @@ void Tween::_tween_process(float p_delta) { case 5: object->call_deferred(data.key[0], data.arg[0], data.arg[1], data.arg[2], data.arg[3], data.arg[4]); break; + case 6: + object->call_deferred(data.key[0], data.arg[0], data.arg[1], data.arg[2], data.arg[3], data.arg[4], data.arg[5]); + break; + case 7: + object->call_deferred(data.key[0], data.arg[0], data.arg[1], data.arg[2], data.arg[3], data.arg[4], data.arg[5], data.arg[6]); + break; + case 8: + object->call_deferred(data.key[0], data.arg[0], data.arg[1], data.arg[2], data.arg[3], data.arg[4], data.arg[5], data.arg[6], data.arg[7]); + break; } } else { // Call the function directly with the arguments Variant::CallError error; - Variant *arg[5] = { + Variant *arg[VARIANT_ARG_MAX] = { &data.arg[0], &data.arg[1], &data.arg[2], &data.arg[3], &data.arg[4], + &data.arg[5], + &data.arg[6], + &data.arg[7], }; object->call(data.key[0], (const Variant **)arg, data.args, error); } @@ -1519,8 +1533,15 @@ bool Tween::interpolate_deferred_callback(Object *p_object, real_t p_duration, S data.delay = 0; // Collect arguments for the callback + static_assert(VARIANT_ARG_MAX == 8, "This code needs to be updated if VARIANT_ARG_MAX != 8"); int args = 0; - if (p_arg5.get_type() != Variant::NIL) { + if (p_arg8.get_type() != Variant::NIL) { + args = 8; + } else if (p_arg7.get_type() != Variant::NIL) { + args = 7; + } else if (p_arg6.get_type() != Variant::NIL) { + args = 6; + } else if (p_arg5.get_type() != Variant::NIL) { args = 5; } else if (p_arg4.get_type() != Variant::NIL) { args = 4; @@ -1540,6 +1561,9 @@ bool Tween::interpolate_deferred_callback(Object *p_object, real_t p_duration, S data.arg[2] = p_arg3; data.arg[3] = p_arg4; data.arg[4] = p_arg5; + data.arg[5] = p_arg6; + data.arg[6] = p_arg7; + data.arg[7] = p_arg8; // Add the new interpolation _push_interpolate_data(data); diff --git a/scene/animation/tween.h b/scene/animation/tween.h index 82017387698..23da0ef3f57 100644 --- a/scene/animation/tween.h +++ b/scene/animation/tween.h @@ -98,7 +98,7 @@ private: EaseType ease_type; real_t delay; int args; - Variant arg[5]; + Variant arg[VARIANT_ARG_MAX]; int uid; InterpolateData() { active = false; diff --git a/scene/debugger/script_debugger_remote.cpp b/scene/debugger/script_debugger_remote.cpp index abc3b802314..c1889a6280f 100644 --- a/scene/debugger/script_debugger_remote.cpp +++ b/scene/debugger/script_debugger_remote.cpp @@ -517,10 +517,10 @@ bool ScriptDebuggerRemote::_parse_live_edit(const Array &p_command) { scene_tree->_live_edit_res_set_func(p_command[1], p_command[2], p_command[3]); } else if (cmdstr == "live_node_call") { - scene_tree->_live_edit_node_call_func(p_command[1], p_command[2], p_command[3], p_command[4], p_command[5], p_command[6], p_command[7]); + scene_tree->_live_edit_node_call_func(p_command[1], p_command[2], p_command[3], p_command[4], p_command[5], p_command[6], p_command[7], p_command[8], p_command[9], p_command[10]); } else if (cmdstr == "live_res_call") { - scene_tree->_live_edit_res_call_func(p_command[1], p_command[2], p_command[3], p_command[4], p_command[5], p_command[6], p_command[7]); + scene_tree->_live_edit_res_call_func(p_command[1], p_command[2], p_command[3], p_command[4], p_command[5], p_command[6], p_command[7], p_command[8], p_command[9], p_command[10]); } else if (cmdstr == "live_create_node") { scene_tree->_live_edit_create_node_func(p_command[1], p_command[2], p_command[3]); diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp index 94b513ba1b6..70e2410a5df 100644 --- a/scene/main/scene_tree.cpp +++ b/scene/main/scene_tree.cpp @@ -200,7 +200,8 @@ void SceneTree::_flush_ugc() { v[i] = E->get()[i]; } - call_group_flags(GROUP_CALL_REALTIME, E->key().group, E->key().call, v[0], v[1], v[2], v[3], v[4]); + static_assert(VARIANT_ARG_MAX == 8, "This code needs to be updated if VARIANT_ARG_MAX != 8"); + call_group_flags(GROUP_CALL_REALTIME, E->key().group, E->key().call, v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7]); unique_group_calls.erase(E); } @@ -1099,11 +1100,12 @@ Variant SceneTree::_call_group_flags(const Variant **p_args, int p_argcount, Var StringName method = *p_args[2]; Variant v[VARIANT_ARG_MAX]; - for (int i = 0; i < MIN(p_argcount - 3, 5); i++) { + for (int i = 0; i < MIN(p_argcount - 3, VARIANT_ARG_MAX); i++) { v[i] = *p_args[i + 3]; } - call_group_flags(flags, group, method, v[0], v[1], v[2], v[3], v[4]); + static_assert(VARIANT_ARG_MAX == 8, "This code needs to be updated if VARIANT_ARG_MAX != 8"); + call_group_flags(flags, group, method, v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7]); return Variant(); }