From 090a4540b7b708f9c8acf8edac4f56888188bc6d Mon Sep 17 00:00:00 2001 From: David Snopek Date: Wed, 8 Oct 2025 16:37:43 -0500 Subject: [PATCH] Use `RequiredParam` and `RequiredResult` in a handful of places in order to test --- core/core_bind.cpp | 2 +- core/core_bind.h | 2 +- core/io/resource_saver.cpp | 4 +-- core/io/resource_saver.h | 2 +- scene/animation/tween.cpp | 56 +++++++++++++++++++------------------- scene/animation/tween.h | 56 +++++++++++++++++++------------------- scene/main/node.cpp | 6 ++-- scene/main/node.h | 4 +-- scene/main/scene_tree.cpp | 2 +- scene/main/scene_tree.h | 2 +- 10 files changed, 68 insertions(+), 68 deletions(-) diff --git a/core/core_bind.cpp b/core/core_bind.cpp index 9930ac8aba5..86f27a13398 100644 --- a/core/core_bind.cpp +++ b/core/core_bind.cpp @@ -165,7 +165,7 @@ void ResourceLoader::_bind_methods() { ////// ResourceSaver ////// -Error ResourceSaver::save(const Ref &p_resource, const String &p_path, BitField p_flags) { +Error ResourceSaver::save(RequiredParam p_resource, const String &p_path, BitField p_flags) { return ::ResourceSaver::save(p_resource, p_path, p_flags); } diff --git a/core/core_bind.h b/core/core_bind.h index be109db6687..9848393e1dd 100644 --- a/core/core_bind.h +++ b/core/core_bind.h @@ -109,7 +109,7 @@ public: static ResourceSaver *get_singleton() { return singleton; } - Error save(const Ref &p_resource, const String &p_path, BitField p_flags); + Error save(RequiredParam p_resource, const String &p_path, BitField p_flags); Error set_uid(const String &p_path, ResourceUID::ID p_uid); Vector get_recognized_extensions(const Ref &p_resource); void add_resource_format_saver(Ref p_format_saver, bool p_at_front); diff --git a/core/io/resource_saver.cpp b/core/io/resource_saver.cpp index 8456a5819a3..be58564a1ff 100644 --- a/core/io/resource_saver.cpp +++ b/core/io/resource_saver.cpp @@ -97,8 +97,8 @@ void ResourceFormatSaver::_bind_methods() { GDVIRTUAL_BIND(_recognize_path, "resource", "path"); } -Error ResourceSaver::save(const Ref &p_resource, const String &p_path, uint32_t p_flags) { - ERR_FAIL_COND_V_MSG(p_resource.is_null(), ERR_INVALID_PARAMETER, vformat("Can't save empty resource to path '%s'.", p_path)); +Error ResourceSaver::save(RequiredParam rp_resource, const String &p_path, uint32_t p_flags) { + EXTRACT_PARAM_OR_FAIL_V_MSG(p_resource, rp_resource, ERR_INVALID_PARAMETER, vformat("Can't save empty resource to path '%s'.", p_path)); String path = p_path; if (path.is_empty()) { path = p_resource->get_path(); diff --git a/core/io/resource_saver.h b/core/io/resource_saver.h index 5602a3a422f..3ecf2b6bd0b 100644 --- a/core/io/resource_saver.h +++ b/core/io/resource_saver.h @@ -83,7 +83,7 @@ public: FLAG_REPLACE_SUBRESOURCE_PATHS = 64, }; - static Error save(const Ref &p_resource, const String &p_path = "", uint32_t p_flags = (uint32_t)FLAG_NONE); + static Error save(RequiredParam p_resource, const String &p_path = "", uint32_t p_flags = (uint32_t)FLAG_NONE); static void get_recognized_extensions(const Ref &p_resource, List *p_extensions); static void add_resource_format_saver(Ref p_format_saver, bool p_at_front = false); static void remove_resource_format_saver(Ref p_format_saver); diff --git a/scene/animation/tween.cpp b/scene/animation/tween.cpp index 42abf97f874..08c27247116 100644 --- a/scene/animation/tween.cpp +++ b/scene/animation/tween.cpp @@ -95,7 +95,7 @@ void Tween::_stop_internal(bool p_reset) { } } -Ref Tween::tween_property(const Object *p_target, const NodePath &p_property, Variant p_to, double p_duration) { +RequiredResult Tween::tween_property(const Object *p_target, const NodePath &p_property, Variant p_to, double p_duration) { ERR_FAIL_NULL_V(p_target, nullptr); CHECK_VALID(); @@ -118,7 +118,7 @@ Ref Tween::tween_property(const Object *p_target, const NodePat return tweener; } -Ref Tween::tween_interval(double p_time) { +RequiredResult Tween::tween_interval(double p_time) { CHECK_VALID(); Ref tweener; @@ -127,7 +127,7 @@ Ref Tween::tween_interval(double p_time) { return tweener; } -Ref Tween::tween_callback(const Callable &p_callback) { +RequiredResult Tween::tween_callback(const Callable &p_callback) { CHECK_VALID(); Ref tweener; @@ -136,7 +136,7 @@ Ref Tween::tween_callback(const Callable &p_callback) { return tweener; } -Ref Tween::tween_method(const Callable &p_callback, const Variant p_from, Variant p_to, double p_duration) { +RequiredResult Tween::tween_method(const Callable &p_callback, const Variant p_from, Variant p_to, double p_duration) { CHECK_VALID(); if (!Animation::validate_type_match(p_from, p_to)) { @@ -149,7 +149,7 @@ Ref Tween::tween_method(const Callable &p_callback, const Variant return tweener; } -Ref Tween::tween_subtween(const Ref &p_subtween) { +RequiredResult Tween::tween_subtween(const Ref &p_subtween) { CHECK_VALID(); // Ensure that the subtween being added is not null. @@ -221,7 +221,7 @@ void Tween::clear() { tweeners.clear(); } -Ref Tween::bind_node(const Node *p_node) { +RequiredResult Tween::bind_node(const Node *p_node) { ERR_FAIL_NULL_V(p_node, this); bound_node = p_node->get_instance_id(); @@ -229,7 +229,7 @@ Ref Tween::bind_node(const Node *p_node) { return this; } -Ref Tween::set_process_mode(TweenProcessMode p_mode) { +RequiredResult Tween::set_process_mode(TweenProcessMode p_mode) { process_mode = p_mode; return this; } @@ -238,7 +238,7 @@ Tween::TweenProcessMode Tween::get_process_mode() const { return process_mode; } -Ref Tween::set_pause_mode(TweenPauseMode p_mode) { +RequiredResult Tween::set_pause_mode(TweenPauseMode p_mode) { pause_mode = p_mode; return this; } @@ -247,7 +247,7 @@ Tween::TweenPauseMode Tween::get_pause_mode() const { return pause_mode; } -Ref Tween::set_ignore_time_scale(bool p_ignore) { +RequiredResult Tween::set_ignore_time_scale(bool p_ignore) { ignore_time_scale = p_ignore; return this; } @@ -256,13 +256,13 @@ bool Tween::is_ignoring_time_scale() const { return ignore_time_scale; } -Ref Tween::set_parallel(bool p_parallel) { +RequiredResult Tween::set_parallel(bool p_parallel) { default_parallel = p_parallel; parallel_enabled = p_parallel; return this; } -Ref Tween::set_loops(int p_loops) { +RequiredResult Tween::set_loops(int p_loops) { loops = p_loops; return this; } @@ -275,12 +275,12 @@ int Tween::get_loops_left() const { } } -Ref Tween::set_speed_scale(float p_speed) { +RequiredResult Tween::set_speed_scale(float p_speed) { speed_scale = p_speed; return this; } -Ref Tween::set_trans(TransitionType p_trans) { +RequiredResult Tween::set_trans(TransitionType p_trans) { default_transition = p_trans; return this; } @@ -289,7 +289,7 @@ Tween::TransitionType Tween::get_trans() const { return default_transition; } -Ref Tween::set_ease(EaseType p_ease) { +RequiredResult Tween::set_ease(EaseType p_ease) { default_ease = p_ease; return this; } @@ -298,12 +298,12 @@ Tween::EaseType Tween::get_ease() const { return default_ease; } -Ref Tween::parallel() { +RequiredResult Tween::parallel() { parallel_enabled = true; return this; } -Ref Tween::chain() { +RequiredResult Tween::chain() { parallel_enabled = false; return this; } @@ -554,7 +554,7 @@ double PropertyTweener::_get_custom_interpolated_value(const Variant &p_value) { return result; } -Ref PropertyTweener::from(const Variant &p_value) { +RequiredResult PropertyTweener::from(const Variant &p_value) { Ref tween = _get_tween(); ERR_FAIL_COND_V(tween.is_null(), nullptr); @@ -568,32 +568,32 @@ Ref PropertyTweener::from(const Variant &p_value) { return this; } -Ref PropertyTweener::from_current() { +RequiredResult PropertyTweener::from_current() { do_continue = false; return this; } -Ref PropertyTweener::as_relative() { +RequiredResult PropertyTweener::as_relative() { relative = true; return this; } -Ref PropertyTweener::set_trans(Tween::TransitionType p_trans) { +RequiredResult PropertyTweener::set_trans(Tween::TransitionType p_trans) { trans_type = p_trans; return this; } -Ref PropertyTweener::set_ease(Tween::EaseType p_ease) { +RequiredResult PropertyTweener::set_ease(Tween::EaseType p_ease) { ease_type = p_ease; return this; } -Ref PropertyTweener::set_custom_interpolator(const Callable &p_method) { +RequiredResult PropertyTweener::set_custom_interpolator(const Callable &p_method) { custom_method = p_method; return this; } -Ref PropertyTweener::set_delay(double p_delay) { +RequiredResult PropertyTweener::set_delay(double p_delay) { delay = p_delay; return this; } @@ -731,7 +731,7 @@ IntervalTweener::IntervalTweener() { ERR_FAIL_MSG("IntervalTweener can't be created directly. Use the tween_interval() method in Tween."); } -Ref CallbackTweener::set_delay(double p_delay) { +RequiredResult CallbackTweener::set_delay(double p_delay) { delay = p_delay; return this; } @@ -781,17 +781,17 @@ CallbackTweener::CallbackTweener() { ERR_FAIL_MSG("CallbackTweener can't be created directly. Use the tween_callback() method in Tween."); } -Ref MethodTweener::set_delay(double p_delay) { +RequiredResult MethodTweener::set_delay(double p_delay) { delay = p_delay; return this; } -Ref MethodTweener::set_trans(Tween::TransitionType p_trans) { +RequiredResult MethodTweener::set_trans(Tween::TransitionType p_trans) { trans_type = p_trans; return this; } -Ref MethodTweener::set_ease(Tween::EaseType p_ease) { +RequiredResult MethodTweener::set_ease(Tween::EaseType p_ease) { ease_type = p_ease; return this; } @@ -912,7 +912,7 @@ bool SubtweenTweener::step(double &r_delta) { return true; } -Ref SubtweenTweener::set_delay(double p_delay) { +RequiredResult SubtweenTweener::set_delay(double p_delay) { delay = p_delay; return this; } diff --git a/scene/animation/tween.h b/scene/animation/tween.h index ab1d7da6ae7..e4f77990139 100644 --- a/scene/animation/tween.h +++ b/scene/animation/tween.h @@ -143,11 +143,11 @@ protected: virtual String _to_string() override; public: - Ref tween_property(const Object *p_target, const NodePath &p_property, Variant p_to, double p_duration); - Ref tween_interval(double p_time); - Ref tween_callback(const Callable &p_callback); - Ref tween_method(const Callable &p_callback, const Variant p_from, Variant p_to, double p_duration); - Ref tween_subtween(const Ref &p_subtween); + RequiredResult tween_property(const Object *p_target, const NodePath &p_property, Variant p_to, double p_duration); + RequiredResult tween_interval(double p_time); + RequiredResult tween_callback(const Callable &p_callback); + RequiredResult tween_method(const Callable &p_callback, const Variant p_from, Variant p_to, double p_duration); + RequiredResult tween_subtween(const Ref &p_subtween); void append(Ref p_tweener); bool custom_step(double p_delta); @@ -160,25 +160,25 @@ public: bool is_valid(); void clear(); - Ref bind_node(const Node *p_node); - Ref set_process_mode(TweenProcessMode p_mode); + RequiredResult bind_node(const Node *p_node); + RequiredResult set_process_mode(TweenProcessMode p_mode); TweenProcessMode get_process_mode() const; - Ref set_pause_mode(TweenPauseMode p_mode); + RequiredResult set_pause_mode(TweenPauseMode p_mode); TweenPauseMode get_pause_mode() const; - Ref set_ignore_time_scale(bool p_ignore = true); + RequiredResult set_ignore_time_scale(bool p_ignore = true); bool is_ignoring_time_scale() const; - Ref set_parallel(bool p_parallel); - Ref set_loops(int p_loops); + RequiredResult set_parallel(bool p_parallel); + RequiredResult set_loops(int p_loops); int get_loops_left() const; - Ref set_speed_scale(float p_speed); - Ref set_trans(TransitionType p_trans); + RequiredResult set_speed_scale(float p_speed); + RequiredResult set_trans(TransitionType p_trans); TransitionType get_trans() const; - Ref set_ease(EaseType p_ease); + RequiredResult set_ease(EaseType p_ease); EaseType get_ease() const; - Ref parallel(); - Ref chain(); + RequiredResult parallel(); + RequiredResult chain(); static real_t run_equation(TransitionType p_trans_type, EaseType p_ease_type, real_t t, real_t b, real_t c, real_t d); static Variant interpolate_variant(const Variant &p_initial_val, const Variant &p_delta_val, double p_time, double p_duration, Tween::TransitionType p_trans, Tween::EaseType p_ease); @@ -203,13 +203,13 @@ class PropertyTweener : public Tweener { double _get_custom_interpolated_value(const Variant &p_value); public: - Ref from(const Variant &p_value); - Ref from_current(); - Ref as_relative(); - Ref set_trans(Tween::TransitionType p_trans); - Ref set_ease(Tween::EaseType p_ease); - Ref set_custom_interpolator(const Callable &p_method); - Ref set_delay(double p_delay); + RequiredResult from(const Variant &p_value); + RequiredResult from_current(); + RequiredResult as_relative(); + RequiredResult set_trans(Tween::TransitionType p_trans); + RequiredResult set_ease(Tween::EaseType p_ease); + RequiredResult set_custom_interpolator(const Callable &p_method); + RequiredResult set_delay(double p_delay); void set_tween(const Ref &p_tween) override; void start() override; @@ -259,7 +259,7 @@ class CallbackTweener : public Tweener { GDCLASS(CallbackTweener, Tweener); public: - Ref set_delay(double p_delay); + RequiredResult set_delay(double p_delay); bool step(double &r_delta) override; @@ -280,9 +280,9 @@ class MethodTweener : public Tweener { GDCLASS(MethodTweener, Tweener); public: - Ref set_trans(Tween::TransitionType p_trans); - Ref set_ease(Tween::EaseType p_ease); - Ref set_delay(double p_delay); + RequiredResult set_trans(Tween::TransitionType p_trans); + RequiredResult set_ease(Tween::EaseType p_ease); + RequiredResult set_delay(double p_delay); void set_tween(const Ref &p_tween) override; bool step(double &r_delta) override; @@ -315,7 +315,7 @@ public: void start() override; bool step(double &r_delta) override; - Ref set_delay(double p_delay); + RequiredResult set_delay(double p_delay); SubtweenTweener(const Ref &p_subtween); SubtweenTweener(); diff --git a/scene/main/node.cpp b/scene/main/node.cpp index bc98af836d0..15f33f31dac 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -1696,11 +1696,11 @@ void Node::_add_child_nocheck(Node *p_child, const StringName &p_name, InternalM emit_signal(SNAME("child_order_changed")); } -void Node::add_child(Node *p_child, bool p_force_readable_name, InternalMode p_internal) { +void Node::add_child(RequiredParam rp_child, bool p_force_readable_name, InternalMode p_internal) { ERR_FAIL_COND_MSG(data.tree && !Thread::is_main_thread(), "Adding children to a node inside the SceneTree is only allowed from the main thread. Use call_deferred(\"add_child\",node)."); ERR_THREAD_GUARD - ERR_FAIL_NULL(p_child); + EXTRACT_PARAM_OR_FAIL(p_child, rp_child); ERR_FAIL_COND_MSG(p_child == this, vformat("Can't add child '%s' to itself.", p_child->get_name())); // adding to itself! ERR_FAIL_COND_MSG(p_child->data.parent, vformat("Can't add child '%s' to '%s', already has a parent '%s'.", p_child->get_name(), get_name(), p_child->data.parent->get_name())); //Fail if node has a parent #ifdef DEBUG_ENABLED @@ -2635,7 +2635,7 @@ void Node::_propagate_replace_owner(Node *p_owner, Node *p_by_owner) { data.blocked--; } -Ref Node::create_tween() { +RequiredResult Node::create_tween() { ERR_THREAD_GUARD_V(Ref()); SceneTree *tree = data.tree; diff --git a/scene/main/node.h b/scene/main/node.h index 0e74ed6ecdd..a8c0b24c620 100644 --- a/scene/main/node.h +++ b/scene/main/node.h @@ -512,7 +512,7 @@ public: InternalMode get_internal_mode() const; - void add_child(Node *p_child, bool p_force_readable_name = false, InternalMode p_internal = INTERNAL_MODE_DISABLED); + void add_child(RequiredParam rp_child, bool p_force_readable_name = false, InternalMode p_internal = INTERNAL_MODE_DISABLED); void add_sibling(Node *p_sibling, bool p_force_readable_name = false); void remove_child(Node *p_child); @@ -608,7 +608,7 @@ public: } } - Ref create_tween(); + RequiredResult create_tween(); void print_tree(); void print_tree_pretty(); diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp index 8d8e070ad65..03f6ce2d025 100644 --- a/scene/main/scene_tree.cpp +++ b/scene/main/scene_tree.cpp @@ -1751,7 +1751,7 @@ Ref SceneTree::create_timer(double p_delay_sec, bool p_process_a return stt; } -Ref SceneTree::create_tween() { +RequiredResult SceneTree::create_tween() { _THREAD_SAFE_METHOD_ Ref tween; tween.instantiate(this); diff --git a/scene/main/scene_tree.h b/scene/main/scene_tree.h index 38f7b5c8467..5db45ddcf96 100644 --- a/scene/main/scene_tree.h +++ b/scene/main/scene_tree.h @@ -429,7 +429,7 @@ public: void unload_current_scene(); Ref create_timer(double p_delay_sec, bool p_process_always = true, bool p_process_in_physics = false, bool p_ignore_time_scale = false); - Ref create_tween(); + RequiredResult create_tween(); void remove_tween(const Ref &p_tween); TypedArray get_processed_tweens();