feat: modules moved and engine moved to submodule

This commit is contained in:
Jan van der Weide 2025-04-12 18:40:44 +02:00
parent dfb5e645cd
commit c33d2130cc
5136 changed files with 225275 additions and 64485 deletions

View file

@ -380,7 +380,13 @@ AnimationNode::NodeTimeInfo AnimationNodeBlendSpace1D::_process(const AnimationM
Ref<AnimationNodeAnimation> na_c = static_cast<Ref<AnimationNodeAnimation>>(blend_points[cur_closest].node);
Ref<AnimationNodeAnimation> na_n = static_cast<Ref<AnimationNodeAnimation>>(blend_points[new_closest].node);
if (na_c.is_valid() && na_n.is_valid()) {
na_n->process_state = process_state;
na_c->process_state = process_state;
na_n->set_backward(na_c->is_backward());
na_n = nullptr;
na_c = nullptr;
}
// See how much animation remains.
pi.seeked = false;

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef ANIMATION_BLEND_SPACE_1D_H
#define ANIMATION_BLEND_SPACE_1D_H
#pragma once
#include "scene/animation/animation_tree.h"
@ -123,5 +122,3 @@ public:
};
VARIANT_ENUM_CAST(AnimationNodeBlendSpace1D::BlendMode)
#endif // ANIMATION_BLEND_SPACE_1D_H

View file

@ -367,7 +367,7 @@ void AnimationNodeBlendSpace2D::_update_triangles() {
Vector2 AnimationNodeBlendSpace2D::get_closest_point(const Vector2 &p_point) {
_update_triangles();
if (triangles.size() == 0) {
if (triangles.is_empty()) {
return Vector2();
}
@ -385,11 +385,9 @@ Vector2 AnimationNodeBlendSpace2D::get_closest_point(const Vector2 &p_point) {
}
for (int j = 0; j < 3; j++) {
Vector2 s[2] = {
points[j],
points[(j + 1) % 3]
};
Vector2 closest_point = Geometry2D::get_closest_point_to_segment(p_point, s);
const Vector2 segment_a = points[j];
const Vector2 segment_b = points[(j + 1) % 3];
Vector2 closest_point = Geometry2D::get_closest_point_to_segment(p_point, segment_a, segment_b);
if (first || closest_point.distance_to(p_point) < best_point.distance_to(p_point)) {
best_point = closest_point;
first = false;
@ -481,22 +479,20 @@ AnimationNode::NodeTimeInfo AnimationNodeBlendSpace2D::_process(const AnimationM
}
for (int j = 0; j < 3; j++) {
Vector2 s[2] = {
points[j],
points[(j + 1) % 3]
};
Vector2 closest2 = Geometry2D::get_closest_point_to_segment(blend_pos, s);
const Vector2 segment_a = points[j];
const Vector2 segment_b = points[(j + 1) % 3];
Vector2 closest2 = Geometry2D::get_closest_point_to_segment(blend_pos, segment_a, segment_b);
if (first || closest2.distance_to(blend_pos) < best_point.distance_to(blend_pos)) {
best_point = closest2;
blend_triangle = i;
first = false;
float d = s[0].distance_to(s[1]);
const real_t d = segment_a.distance_to(segment_b);
if (d == 0.0) {
blend_weights[j] = 1.0;
blend_weights[(j + 1) % 3] = 0.0;
blend_weights[(j + 2) % 3] = 0.0;
} else {
float c = s[0].distance_to(closest2) / d;
const real_t c = segment_a.distance_to(closest2) / d;
blend_weights[j] = 1.0 - c;
blend_weights[(j + 1) % 3] = c;
@ -557,7 +553,13 @@ AnimationNode::NodeTimeInfo AnimationNodeBlendSpace2D::_process(const AnimationM
Ref<AnimationNodeAnimation> na_c = static_cast<Ref<AnimationNodeAnimation>>(blend_points[cur_closest].node);
Ref<AnimationNodeAnimation> na_n = static_cast<Ref<AnimationNodeAnimation>>(blend_points[new_closest].node);
if (na_c.is_valid() && na_n.is_valid()) {
na_n->process_state = process_state;
na_c->process_state = process_state;
na_n->set_backward(na_c->is_backward());
na_n = nullptr;
na_c = nullptr;
}
// See how much animation remains.
pi.seeked = false;

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef ANIMATION_BLEND_SPACE_2D_H
#define ANIMATION_BLEND_SPACE_2D_H
#pragma once
#include "scene/animation/animation_tree.h"
@ -149,5 +148,3 @@ public:
};
VARIANT_ENUM_CAST(AnimationNodeBlendSpace2D::BlendMode)
#endif // ANIMATION_BLEND_SPACE_2D_H

View file

@ -907,7 +907,7 @@ AnimationNode::NodeTimeInfo AnimationNodeBlend3::_process(const AnimationMixer::
AnimationMixer::PlaybackInfo pi = p_playback_info;
pi.weight = MAX(0, -amount);
NodeTimeInfo nti0 = blend_input(0, pi, FILTER_IGNORE, sync, p_test_only);
pi.weight = 1.0 - ABS(amount);
pi.weight = 1.0 - Math::abs(amount);
NodeTimeInfo nti1 = blend_input(1, pi, FILTER_IGNORE, sync, p_test_only);
pi.weight = MAX(0, amount);
NodeTimeInfo nti2 = blend_input(2, pi, FILTER_IGNORE, sync, p_test_only);

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef ANIMATION_BLEND_TREE_H
#define ANIMATION_BLEND_TREE_H
#pragma once
#include "scene/animation/animation_tree.h"
@ -485,5 +484,3 @@ public:
};
VARIANT_ENUM_CAST(AnimationNodeBlendTree::ConnectionError)
#endif // ANIMATION_BLEND_TREE_H

View file

@ -77,11 +77,9 @@ bool AnimationMixer::_set(const StringName &p_name, const Variant &p_value) {
while (animation_libraries.size()) {
remove_animation_library(animation_libraries[0].name);
}
List<Variant> keys;
d.get_key_list(&keys);
for (const Variant &K : keys) {
Ref<AnimationLibrary> lib = d[K];
add_animation_library(K, lib);
for (const KeyValue<Variant, Variant> &kv : d) {
Ref<AnimationLibrary> lib = kv.value;
add_animation_library(kv.key, lib);
}
emit_signal(SNAME("animation_libraries_updated"));
@ -999,7 +997,7 @@ Variant AnimationMixer::_post_process_key_value(const Ref<Animation> &p_anim, in
switch (p_anim->track_get_type(p_track)) {
case Animation::TYPE_POSITION_3D: {
if (p_object_sub_idx >= 0) {
Skeleton3D *skel = Object::cast_to<Skeleton3D>(ObjectDB::get_instance(p_object_id));
Skeleton3D *skel = ObjectDB::get_instance<Skeleton3D>(p_object_id);
if (skel) {
return Vector3(p_value) * skel->get_motion_scale();
}
@ -1591,17 +1589,17 @@ void AnimationMixer::_blend_process(double p_delta, bool p_update_only) {
float rot_a = t->value;
float rot_b = value;
float rot_init = t->init_value;
rot_a = Math::fposmod(rot_a, (float)Math_TAU);
rot_b = Math::fposmod(rot_b, (float)Math_TAU);
rot_init = Math::fposmod(rot_init, (float)Math_TAU);
if (rot_init < Math_PI) {
rot_a = rot_a > rot_init + Math_PI ? rot_a - Math_TAU : rot_a;
rot_b = rot_b > rot_init + Math_PI ? rot_b - Math_TAU : rot_b;
rot_a = Math::fposmod(rot_a, (float)Math::TAU);
rot_b = Math::fposmod(rot_b, (float)Math::TAU);
rot_init = Math::fposmod(rot_init, (float)Math::TAU);
if (rot_init < Math::PI) {
rot_a = rot_a > rot_init + Math::PI ? rot_a - Math::TAU : rot_a;
rot_b = rot_b > rot_init + Math::PI ? rot_b - Math::TAU : rot_b;
} else {
rot_a = rot_a < rot_init - Math_PI ? rot_a + Math_TAU : rot_a;
rot_b = rot_b < rot_init - Math_PI ? rot_b + Math_TAU : rot_b;
rot_a = rot_a < rot_init - Math::PI ? rot_a + Math::TAU : rot_a;
rot_b = rot_b < rot_init - Math::PI ? rot_b + Math::TAU : rot_b;
}
t->value = Math::fposmod(rot_a + (rot_b - rot_init) * (float)blend, (float)Math_TAU);
t->value = Math::fposmod(rot_a + (rot_b - rot_init) * (float)blend, (float)Math::TAU);
} else {
value = Animation::cast_to_blendwise(value);
if (t->init_value.is_array()) {
@ -1869,7 +1867,7 @@ void AnimationMixer::_blend_apply() {
root_motion_rotation_accumulator = t->rot;
root_motion_scale_accumulator = t->scale;
} else if (t->skeleton_id.is_valid() && t->bone_idx >= 0) {
Skeleton3D *t_skeleton = Object::cast_to<Skeleton3D>(ObjectDB::get_instance(t->skeleton_id));
Skeleton3D *t_skeleton = ObjectDB::get_instance<Skeleton3D>(t->skeleton_id);
if (!t_skeleton) {
return;
}
@ -1884,7 +1882,7 @@ void AnimationMixer::_blend_apply() {
}
} else if (!t->skeleton_id.is_valid()) {
Node3D *t_node_3d = Object::cast_to<Node3D>(ObjectDB::get_instance(t->object_id));
Node3D *t_node_3d = ObjectDB::get_instance<Node3D>(t->object_id);
if (!t_node_3d) {
return;
}
@ -1904,7 +1902,7 @@ void AnimationMixer::_blend_apply() {
#ifndef _3D_DISABLED
TrackCacheBlendShape *t = static_cast<TrackCacheBlendShape *>(track);
MeshInstance3D *t_mesh_3d = Object::cast_to<MeshInstance3D>(ObjectDB::get_instance(t->object_id));
MeshInstance3D *t_mesh_3d = ObjectDB::get_instance<MeshInstance3D>(t->object_id);
if (t_mesh_3d) {
t_mesh_3d->set_blend_shape_value(t->shape_index, t->value);
}
@ -2000,7 +1998,7 @@ void AnimationMixer::_blend_apply() {
for (uint32_t erase_idx = 0; erase_idx < erase_streams.size(); erase_idx++) {
map.erase(erase_streams[erase_idx]);
}
if (map.size() == 0) {
if (map.is_empty()) {
erase_maps.push_back(L.key);
}
}
@ -2133,7 +2131,7 @@ void AnimationMixer::_build_backup_track_cache() {
if (t->root_motion) {
// Do nothing.
} else if (t->skeleton_id.is_valid() && t->bone_idx >= 0) {
Skeleton3D *t_skeleton = Object::cast_to<Skeleton3D>(ObjectDB::get_instance(t->skeleton_id));
Skeleton3D *t_skeleton = ObjectDB::get_instance<Skeleton3D>(t->skeleton_id);
if (!t_skeleton) {
return;
}
@ -2147,7 +2145,7 @@ void AnimationMixer::_build_backup_track_cache() {
t->scale = t_skeleton->get_bone_pose_scale(t->bone_idx);
}
} else if (!t->skeleton_id.is_valid()) {
Node3D *t_node_3d = Object::cast_to<Node3D>(ObjectDB::get_instance(t->object_id));
Node3D *t_node_3d = ObjectDB::get_instance<Node3D>(t->object_id);
if (!t_node_3d) {
return;
}
@ -2166,7 +2164,7 @@ void AnimationMixer::_build_backup_track_cache() {
case Animation::TYPE_BLEND_SHAPE: {
#ifndef _3D_DISABLED
TrackCacheBlendShape *t = static_cast<TrackCacheBlendShape *>(track);
MeshInstance3D *t_mesh_3d = Object::cast_to<MeshInstance3D>(ObjectDB::get_instance(t->object_id));
MeshInstance3D *t_mesh_3d = ObjectDB::get_instance<MeshInstance3D>(t->object_id);
if (t_mesh_3d) {
t->value = t_mesh_3d->get_blend_shape_value(t->shape_index);
}

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef ANIMATION_MIXER_H
#define ANIMATION_MIXER_H
#pragma once
#include "core/templates/a_hash_map.h"
#include "scene/animation/tween.h"
@ -509,5 +508,3 @@ public:
VARIANT_ENUM_CAST(AnimationMixer::AnimationCallbackModeProcess);
VARIANT_ENUM_CAST(AnimationMixer::AnimationCallbackModeMethod);
VARIANT_ENUM_CAST(AnimationMixer::AnimationCallbackModeDiscrete);
#endif // ANIMATION_MIXER_H

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef ANIMATION_NODE_EXTENSION_H
#define ANIMATION_NODE_EXTENSION_H
#pragma once
#include "scene/animation/animation_tree.h"
@ -51,5 +50,3 @@ private:
static AnimationNode::NodeTimeInfo _array_to_node_time_info(const PackedFloat32Array &p_array);
static PackedFloat64Array _playback_info_to_array(const AnimationMixer::PlaybackInfo &p_playback_info);
};
#endif // ANIMATION_NODE_EXTENSION_H

View file

@ -563,7 +563,7 @@ bool AnimationNodeStateMachinePlayback::_make_travel_path(AnimationTree *p_tree,
// Begin astar.
while (!found_route) {
if (open_list.size() == 0) {
if (open_list.is_empty()) {
break; // No path found.
}

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef ANIMATION_NODE_STATE_MACHINE_H
#define ANIMATION_NODE_STATE_MACHINE_H
#pragma once
#include "core/math/expression.h"
#include "scene/animation/animation_tree.h"
@ -348,5 +347,3 @@ public:
AnimationNodeStateMachinePlayback();
};
#endif // ANIMATION_NODE_STATE_MACHINE_H

View file

@ -256,8 +256,7 @@ void AnimationPlayer::_process_playback_data(PlaybackData &cd, double p_delta, f
float AnimationPlayer::get_current_blend_amount() {
Playback &c = playback;
float blend = 1.0;
for (List<Blend>::Element *E = c.blend.front(); E; E = E->next()) {
Blend &b = E->get();
for (const Blend &b : c.blend) {
blend = blend - b.blend_left;
}
return MAX(0, blend);

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef ANIMATION_PLAYER_H
#define ANIMATION_PLAYER_H
#pragma once
#include "animation_mixer.h"
#include "scene/resources/animation.h"
@ -246,5 +245,3 @@ public:
VARIANT_ENUM_CAST(AnimationPlayer::AnimationProcessCallback);
VARIANT_ENUM_CAST(AnimationPlayer::AnimationMethodCallMode);
#endif // DISABLE_DEPRECATED
#endif // ANIMATION_PLAYER_H

View file

@ -121,12 +121,10 @@ AnimationNode::NodeTimeInfo AnimationNode::get_node_time_info() const {
void AnimationNode::get_child_nodes(List<ChildNode> *r_child_nodes) {
Dictionary cn;
if (GDVIRTUAL_CALL(_get_child_nodes, cn)) {
List<Variant> keys;
cn.get_key_list(&keys);
for (const Variant &E : keys) {
for (const KeyValue<Variant, Variant> &kv : cn) {
ChildNode child;
child.name = E;
child.node = cn[E];
child.name = kv.key;
child.node = kv.value;
r_child_nodes->push_back(child);
}
}

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef ANIMATION_TREE_H
#define ANIMATION_TREE_H
#pragma once
#include "animation_mixer.h"
#include "scene/resources/animation.h"
@ -362,5 +361,3 @@ public:
#ifndef DISABLE_DEPRECATED
VARIANT_ENUM_CAST(AnimationTree::AnimationProcessCallback);
#endif // DISABLE_DEPRECATED
#endif // ANIMATION_TREE_H

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef EASING_EQUATIONS_H
#define EASING_EQUATIONS_H
#pragma once
/*
* Derived from Robert Penner's easing equations: http://robertpenner.com/easing/
@ -55,23 +54,23 @@
* SOFTWARE.
*/
namespace linear {
namespace Linear {
static real_t in(real_t t, real_t b, real_t c, real_t d) {
return c * t / d + b;
}
}; // namespace linear
}; // namespace Linear
namespace sine {
namespace Sine {
static real_t in(real_t t, real_t b, real_t c, real_t d) {
return -c * cos(t / d * (Math_PI / 2)) + c + b;
return -c * cos(t / d * (Math::PI / 2)) + c + b;
}
static real_t out(real_t t, real_t b, real_t c, real_t d) {
return c * sin(t / d * (Math_PI / 2)) + b;
return c * sin(t / d * (Math::PI / 2)) + b;
}
static real_t in_out(real_t t, real_t b, real_t c, real_t d) {
return -c / 2 * (cos(Math_PI * t / d) - 1) + b;
return -c / 2 * (cos(Math::PI * t / d) - 1) + b;
}
static real_t out_in(real_t t, real_t b, real_t c, real_t d) {
@ -81,9 +80,9 @@ static real_t out_in(real_t t, real_t b, real_t c, real_t d) {
real_t h = c / 2;
return in(t * 2 - d, b + h, h, d);
}
}; // namespace sine
}; // namespace Sine
namespace quint {
namespace Quint {
static real_t in(real_t t, real_t b, real_t c, real_t d) {
return c * pow(t / d, 5) + b;
}
@ -108,9 +107,9 @@ static real_t out_in(real_t t, real_t b, real_t c, real_t d) {
real_t h = c / 2;
return in(t * 2 - d, b + h, h, d);
}
}; // namespace quint
}; // namespace Quint
namespace quart {
namespace Quart {
static real_t in(real_t t, real_t b, real_t c, real_t d) {
return c * pow(t / d, 4) + b;
}
@ -135,9 +134,9 @@ static real_t out_in(real_t t, real_t b, real_t c, real_t d) {
real_t h = c / 2;
return in(t * 2 - d, b + h, h, d);
}
}; // namespace quart
}; // namespace Quart
namespace quad {
namespace Quad {
static real_t in(real_t t, real_t b, real_t c, real_t d) {
return c * pow(t / d, 2) + b;
}
@ -163,9 +162,9 @@ static real_t out_in(real_t t, real_t b, real_t c, real_t d) {
real_t h = c / 2;
return in(t * 2 - d, b + h, h, d);
}
}; // namespace quad
}; // namespace Quad
namespace expo {
namespace Expo {
static real_t in(real_t t, real_t b, real_t c, real_t d) {
if (t == 0) {
return b;
@ -204,9 +203,9 @@ static real_t out_in(real_t t, real_t b, real_t c, real_t d) {
real_t h = c / 2;
return in(t * 2 - d, b + h, h, d);
}
}; // namespace expo
}; // namespace Expo
namespace elastic {
namespace Elastic {
static real_t in(real_t t, real_t b, real_t c, real_t d) {
if (t == 0) {
return b;
@ -222,7 +221,7 @@ static real_t in(real_t t, real_t b, real_t c, real_t d) {
float a = c * pow(2, 10 * t);
float s = p / 4;
return -(a * sin((t * d - s) * (2 * Math_PI) / p)) + b;
return -(a * sin((t * d - s) * (2 * Math::PI) / p)) + b;
}
static real_t out(real_t t, real_t b, real_t c, real_t d) {
@ -238,7 +237,7 @@ static real_t out(real_t t, real_t b, real_t c, real_t d) {
float p = d * 0.3f;
float s = p / 4;
return (c * pow(2, -10 * t) * sin((t * d - s) * (2 * Math_PI) / p) + c + b);
return (c * pow(2, -10 * t) * sin((t * d - s) * (2 * Math::PI) / p) + c + b);
}
static real_t in_out(real_t t, real_t b, real_t c, real_t d) {
@ -257,12 +256,12 @@ static real_t in_out(real_t t, real_t b, real_t c, real_t d) {
if (t < 1) {
t -= 1;
a *= pow(2, 10 * t);
return -0.5f * (a * sin((t * d - s) * (2 * Math_PI) / p)) + b;
return -0.5f * (a * sin((t * d - s) * (2 * Math::PI) / p)) + b;
}
t -= 1;
a *= pow(2, -10 * t);
return a * sin((t * d - s) * (2 * Math_PI) / p) * 0.5f + c + b;
return a * sin((t * d - s) * (2 * Math::PI) / p) * 0.5f + c + b;
}
static real_t out_in(real_t t, real_t b, real_t c, real_t d) {
@ -272,9 +271,9 @@ static real_t out_in(real_t t, real_t b, real_t c, real_t d) {
real_t h = c / 2;
return in(t * 2 - d, b + h, h, d);
}
}; // namespace elastic
}; // namespace Elastic
namespace cubic {
namespace Cubic {
static real_t in(real_t t, real_t b, real_t c, real_t d) {
t /= d;
return c * t * t * t + b;
@ -302,9 +301,9 @@ static real_t out_in(real_t t, real_t b, real_t c, real_t d) {
real_t h = c / 2;
return in(t * 2 - d, b + h, h, d);
}
}; // namespace cubic
}; // namespace Cubic
namespace circ {
namespace Circ {
static real_t in(real_t t, real_t b, real_t c, real_t d) {
t /= d;
return -c * (sqrt(1 - t * t) - 1) + b;
@ -332,9 +331,9 @@ static real_t out_in(real_t t, real_t b, real_t c, real_t d) {
real_t h = c / 2;
return in(t * 2 - d, b + h, h, d);
}
}; // namespace circ
}; // namespace Circ
namespace bounce {
namespace Bounce {
static real_t out(real_t t, real_t b, real_t c, real_t d) {
t /= d;
@ -375,9 +374,9 @@ static real_t out_in(real_t t, real_t b, real_t c, real_t d) {
real_t h = c / 2;
return in(t * 2 - d, b + h, h, d);
}
}; // namespace bounce
}; // namespace Bounce
namespace back {
namespace Back {
static real_t in(real_t t, real_t b, real_t c, real_t d) {
float s = 1.70158f;
t /= d;
@ -411,13 +410,13 @@ static real_t out_in(real_t t, real_t b, real_t c, real_t d) {
real_t h = c / 2;
return in(t * 2 - d, b + h, h, d);
}
}; // namespace back
}; // namespace Back
namespace spring {
namespace Spring {
static real_t out(real_t t, real_t b, real_t c, real_t d) {
t /= d;
real_t s = 1.0 - t;
t = (sin(t * Math_PI * (0.2 + 2.5 * t * t * t)) * pow(s, 2.2) + t) * (1.0 + (1.2 * s));
t = (sin(t * Math::PI * (0.2 + 2.5 * t * t * t)) * pow(s, 2.2) + t) * (1.0 + (1.2 * s));
return c * t + b;
}
@ -440,6 +439,4 @@ static real_t out_in(real_t t, real_t b, real_t c, real_t d) {
real_t h = c / 2;
return in(t * 2 - d, b + h, h, d);
}
}; // namespace spring
#endif // EASING_EQUATIONS_H
}; // namespace Spring

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef ROOT_MOTION_VIEW_H
#define ROOT_MOTION_VIEW_H
#pragma once
#include "scene/3d/visual_instance_3d.h"
#include "scene/resources/immediate_mesh.h"
@ -75,5 +74,3 @@ public:
RootMotionView();
~RootMotionView();
};
#endif // ROOT_MOTION_VIEW_H

View file

@ -39,18 +39,18 @@
ERR_FAIL_COND_V_MSG(started, nullptr, "Can't append to a Tween that has started. Use stop() first.");
Tween::interpolater Tween::interpolaters[Tween::TRANS_MAX][Tween::EASE_MAX] = {
{ &linear::in, &linear::in, &linear::in, &linear::in }, // Linear is the same for each easing.
{ &sine::in, &sine::out, &sine::in_out, &sine::out_in },
{ &quint::in, &quint::out, &quint::in_out, &quint::out_in },
{ &quart::in, &quart::out, &quart::in_out, &quart::out_in },
{ &quad::in, &quad::out, &quad::in_out, &quad::out_in },
{ &expo::in, &expo::out, &expo::in_out, &expo::out_in },
{ &elastic::in, &elastic::out, &elastic::in_out, &elastic::out_in },
{ &cubic::in, &cubic::out, &cubic::in_out, &cubic::out_in },
{ &circ::in, &circ::out, &circ::in_out, &circ::out_in },
{ &bounce::in, &bounce::out, &bounce::in_out, &bounce::out_in },
{ &back::in, &back::out, &back::in_out, &back::out_in },
{ &spring::in, &spring::out, &spring::in_out, &spring::out_in },
{ &Linear::in, &Linear::in, &Linear::in, &Linear::in }, // Linear is the same for each easing.
{ &Sine::in, &Sine::out, &Sine::in_out, &Sine::out_in },
{ &Quint::in, &Quint::out, &Quint::in_out, &Quint::out_in },
{ &Quart::in, &Quart::out, &Quart::in_out, &Quart::out_in },
{ &Quad::in, &Quad::out, &Quad::in_out, &Quad::out_in },
{ &Expo::in, &Expo::out, &Expo::in_out, &Expo::out_in },
{ &Elastic::in, &Elastic::out, &Elastic::in_out, &Elastic::out_in },
{ &Cubic::in, &Cubic::out, &Cubic::in_out, &Cubic::out_in },
{ &Circ::in, &Circ::out, &Circ::in_out, &Circ::out_in },
{ &Bounce::in, &Bounce::out, &Bounce::in_out, &Bounce::out_in },
{ &Back::in, &Back::out, &Back::in_out, &Back::out_in },
{ &Spring::in, &Spring::out, &Spring::in_out, &Spring::out_in },
};
void Tweener::set_tween(const Ref<Tween> &p_tween) {
@ -63,7 +63,7 @@ void Tweener::start() {
}
Ref<Tween> Tweener::_get_tween() {
return Ref<Tween>(ObjectDB::get_instance(tween_id));
return ObjectDB::get_ref<Tween>(tween_id);
}
void Tweener::_finish() {
@ -212,6 +212,7 @@ void Tween::play() {
void Tween::kill() {
running = false; // For the sake of is_running().
valid = false;
dead = true;
}
@ -432,7 +433,7 @@ bool Tween::can_process(bool p_tree_paused) const {
Node *Tween::get_bound_node() const {
if (is_bound) {
return Object::cast_to<Node>(ObjectDB::get_instance(bound_node));
return ObjectDB::get_instance<Node>(bound_node);
} else {
return nullptr;
}
@ -542,6 +543,20 @@ Tween::Tween(SceneTree *p_parent_tree) {
valid = true;
}
double PropertyTweener::_get_custom_interpolated_value(const Variant &p_value) {
const Variant *argptr = &p_value;
Variant result;
Callable::CallError ce;
custom_method.callp(&argptr, 1, result, ce);
if (ce.error != Callable::CallError::CALL_OK) {
ERR_FAIL_V_MSG(false, "Error calling custom method from PropertyTweener: " + Variant::get_callable_error_text(custom_method, &argptr, 1, ce) + ".");
} else if (result.get_type() != Variant::FLOAT) {
ERR_FAIL_V_MSG(false, vformat("Wrong return type in PropertyTweener custom method. Expected float, got %s.", Variant::get_type_name(result.get_type())));
}
return result;
}
Ref<PropertyTweener> PropertyTweener::from(const Variant &p_value) {
Ref<Tween> tween = _get_tween();
ERR_FAIL_COND_V(tween.is_null(), nullptr);
@ -638,17 +653,7 @@ bool PropertyTweener::step(double &r_delta) {
if (time < duration) {
if (custom_method.is_valid()) {
const Variant t = tween->interpolate_variant(0.0, 1.0, time, duration, trans_type, ease_type);
const Variant *argptr = &t;
Variant result;
Callable::CallError ce;
custom_method.callp(&argptr, 1, result, ce);
if (ce.error != Callable::CallError::CALL_OK) {
ERR_FAIL_V_MSG(false, "Error calling custom method from PropertyTweener: " + Variant::get_callable_error_text(custom_method, &argptr, 1, ce) + ".");
} else if (result.get_type() != Variant::FLOAT) {
ERR_FAIL_V_MSG(false, vformat("Wrong return type in PropertyTweener custom method. Expected float, got %s.", Variant::get_type_name(result.get_type())));
}
double result = _get_custom_interpolated_value(t);
target_instance->set_indexed(property, Animation::interpolate_variant(initial_val, final_val, result));
} else {
target_instance->set_indexed(property, tween->interpolate_variant(initial_val, delta_val, time, duration, trans_type, ease_type));
@ -656,7 +661,12 @@ bool PropertyTweener::step(double &r_delta) {
r_delta = 0;
return true;
} else {
target_instance->set_indexed(property, final_val);
if (custom_method.is_valid()) {
double final_t = _get_custom_interpolated_value(1.0);
target_instance->set_indexed(property, Animation::interpolate_variant(initial_val, final_val, final_t));
} else {
target_instance->set_indexed(property, final_val);
}
r_delta = elapsed_time - delay - duration;
_finish();
return false;

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef TWEEN_H
#define TWEEN_H
#pragma once
#include "core/object/ref_counted.h"
@ -201,6 +200,8 @@ VARIANT_ENUM_CAST(Tween::EaseType);
class PropertyTweener : public Tweener {
GDCLASS(PropertyTweener, Tweener);
double _get_custom_interpolated_value(const Variant &p_value);
public:
Ref<PropertyTweener> from(const Variant &p_value);
Ref<PropertyTweener> from_current();
@ -325,5 +326,3 @@ protected:
private:
double delay = 0;
};
#endif // TWEEN_H