summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
Diffstat (limited to 'scene')
-rw-r--r--scene/2d/canvas_modulate.cpp2
-rw-r--r--scene/2d/navigation_region_2d.cpp2
-rw-r--r--scene/2d/physics_body_2d.cpp4
-rw-r--r--scene/2d/touch_screen_button.cpp4
-rw-r--r--scene/3d/audio_stream_player_3d.cpp2
-rw-r--r--scene/3d/camera_3d.cpp2
-rw-r--r--scene/3d/gpu_particles_collision_3d.cpp2
-rw-r--r--scene/3d/light_3d.cpp2
-rw-r--r--scene/3d/lightmap_gi.cpp10
-rw-r--r--scene/3d/mesh_instance_3d.cpp4
-rw-r--r--scene/3d/occluder_instance_3d.cpp4
-rw-r--r--scene/3d/physics_body_3d.cpp4
-rw-r--r--scene/3d/skeleton_3d.cpp4
-rw-r--r--scene/3d/soft_body_3d.cpp2
-rw-r--r--scene/3d/voxel_gi.cpp6
-rw-r--r--scene/3d/voxelizer.cpp6
-rw-r--r--scene/3d/world_environment.cpp2
-rw-r--r--scene/3d/xr_nodes.cpp6
-rw-r--r--scene/animation/animation_blend_tree.cpp2
-rw-r--r--scene/animation/animation_node_state_machine.cpp4
-rw-r--r--scene/animation/animation_player.cpp2
-rw-r--r--scene/animation/tween.cpp2113
-rw-r--r--scene/animation/tween.h307
-rw-r--r--scene/debugger/scene_debugger.cpp4
-rw-r--r--scene/gui/button.cpp2
-rw-r--r--scene/gui/code_edit.cpp6
-rw-r--r--scene/gui/color_picker.cpp8
-rw-r--r--scene/gui/graph_node.cpp2
-rw-r--r--scene/gui/item_list.cpp4
-rw-r--r--scene/gui/link_button.cpp2
-rw-r--r--scene/gui/popup_menu.h4
-rw-r--r--scene/gui/rich_text_label.h4
-rw-r--r--scene/gui/shortcut.cpp2
-rw-r--r--scene/gui/spin_box.cpp4
-rw-r--r--scene/gui/tab_container.cpp2
-rw-r--r--scene/gui/tabs.cpp2
-rw-r--r--scene/gui/text_edit.cpp10
-rw-r--r--scene/gui/text_edit.h5
-rw-r--r--scene/gui/tree.cpp4
-rw-r--r--scene/gui/tree.h4
-rw-r--r--scene/main/http_request.cpp2
-rw-r--r--scene/main/instance_placeholder.cpp2
-rw-r--r--scene/main/node.cpp29
-rw-r--r--scene/main/node.h5
-rw-r--r--scene/main/scene_tree.cpp59
-rw-r--r--scene/main/scene_tree.h5
-rw-r--r--scene/main/viewport.cpp20
-rw-r--r--scene/register_scene_types.cpp23
-rw-r--r--scene/resources/audio_stream_sample.cpp2
-rw-r--r--scene/resources/bit_map.cpp8
-rw-r--r--scene/resources/default_theme/default_theme.cpp8
-rw-r--r--scene/resources/font.cpp14
-rw-r--r--scene/resources/material.cpp2
-rw-r--r--scene/resources/mesh.cpp4
-rw-r--r--scene/resources/packed_scene.cpp73
-rw-r--r--scene/resources/packed_scene.h8
-rw-r--r--scene/resources/resource_format_text.cpp12
-rw-r--r--scene/resources/shader.cpp2
-rw-r--r--scene/resources/surface_tool.cpp2
-rw-r--r--scene/resources/texture.cpp24
-rw-r--r--scene/resources/tile_set.cpp2
-rw-r--r--scene/resources/visual_shader.cpp6
62 files changed, 1059 insertions, 1818 deletions
diff --git a/scene/2d/canvas_modulate.cpp b/scene/2d/canvas_modulate.cpp
index 52eabefbcb..4de99959a3 100644
--- a/scene/2d/canvas_modulate.cpp
+++ b/scene/2d/canvas_modulate.cpp
@@ -81,7 +81,7 @@ TypedArray<String> CanvasModulate::get_configuration_warnings() const {
get_tree()->get_nodes_in_group("_canvas_modulate_" + itos(get_canvas().get_id()), &nodes);
if (nodes.size() > 1) {
- warnings.push_back(TTR("Only one visible CanvasModulate is allowed per scene (or set of instanced scenes). The first created one will work, while the rest will be ignored."));
+ warnings.push_back(TTR("Only one visible CanvasModulate is allowed per scene (or set of instantiated scenes). The first created one will work, while the rest will be ignored."));
}
}
diff --git a/scene/2d/navigation_region_2d.cpp b/scene/2d/navigation_region_2d.cpp
index d2caf5bea8..ea639ae3a3 100644
--- a/scene/2d/navigation_region_2d.cpp
+++ b/scene/2d/navigation_region_2d.cpp
@@ -169,7 +169,7 @@ Ref<NavigationMesh> NavigationPolygon::get_mesh() {
MutexLock lock(navmesh_generation);
if (navmesh.is_null()) {
- navmesh.instance();
+ navmesh.instantiate();
Vector<Vector3> verts;
{
verts.resize(get_vertices().size());
diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp
index ce63b25ce0..6c1cdc2129 100644
--- a/scene/2d/physics_body_2d.cpp
+++ b/scene/2d/physics_body_2d.cpp
@@ -64,7 +64,7 @@ Ref<KinematicCollision2D> PhysicsBody2D::_move(const Vector2 &p_motion, bool p_i
if (move_and_collide(p_motion, p_infinite_inertia, result, p_margin, p_exclude_raycast_shapes, p_test_only)) {
if (motion_cache.is_null()) {
- motion_cache.instance();
+ motion_cache.instantiate();
motion_cache->owner = this;
}
@@ -1120,7 +1120,7 @@ Ref<KinematicCollision2D> CharacterBody2D::_get_slide_collision(int p_bounce) {
}
if (slide_colliders[p_bounce].is_null()) {
- slide_colliders.write[p_bounce].instance();
+ slide_colliders.write[p_bounce].instantiate();
slide_colliders.write[p_bounce]->owner = this;
}
diff --git a/scene/2d/touch_screen_button.cpp b/scene/2d/touch_screen_button.cpp
index 4e58984b37..0a6393551c 100644
--- a/scene/2d/touch_screen_button.cpp
+++ b/scene/2d/touch_screen_button.cpp
@@ -288,7 +288,7 @@ void TouchScreenButton::_press(int p_finger_pressed) {
if (action != StringName()) {
Input::get_singleton()->action_press(action);
Ref<InputEventAction> iea;
- iea.instance();
+ iea.instantiate();
iea->set_action(action);
iea->set_pressed(true);
get_viewport()->input(iea, true);
@@ -305,7 +305,7 @@ void TouchScreenButton::_release(bool p_exiting_tree) {
Input::get_singleton()->action_release(action);
if (!p_exiting_tree) {
Ref<InputEventAction> iea;
- iea.instance();
+ iea.instantiate();
iea->set_action(action);
iea->set_pressed(false);
get_viewport()->input(iea, true);
diff --git a/scene/3d/audio_stream_player_3d.cpp b/scene/3d/audio_stream_player_3d.cpp
index 9640043031..e05f37c73c 100644
--- a/scene/3d/audio_stream_player_3d.cpp
+++ b/scene/3d/audio_stream_player_3d.cpp
@@ -997,7 +997,7 @@ void AudioStreamPlayer3D::_bind_methods() {
}
AudioStreamPlayer3D::AudioStreamPlayer3D() {
- velocity_tracker.instance();
+ velocity_tracker.instantiate();
AudioServer::get_singleton()->connect("bus_layout_changed", callable_mp(this, &AudioStreamPlayer3D::_bus_layout_changed));
set_disable_scale(true);
}
diff --git a/scene/3d/camera_3d.cpp b/scene/3d/camera_3d.cpp
index 62bbebe6e7..32006d5e7f 100644
--- a/scene/3d/camera_3d.cpp
+++ b/scene/3d/camera_3d.cpp
@@ -661,7 +661,7 @@ Camera3D::Camera3D() {
set_perspective(75.0, 0.05, 4000.0);
RenderingServer::get_singleton()->camera_set_cull_mask(camera, layers);
//active=false;
- velocity_tracker.instance();
+ velocity_tracker.instantiate();
set_notify_transform(true);
set_disable_scale(true);
}
diff --git a/scene/3d/gpu_particles_collision_3d.cpp b/scene/3d/gpu_particles_collision_3d.cpp
index 322bc60fce..c1e71b9565 100644
--- a/scene/3d/gpu_particles_collision_3d.cpp
+++ b/scene/3d/gpu_particles_collision_3d.cpp
@@ -495,7 +495,7 @@ Ref<Image> GPUParticlesCollisionSDF::bake() {
_compute_sdf(&params);
Ref<Image> ret;
- ret.instance();
+ ret.instantiate();
ret->create(sdf_size.x, sdf_size.y * sdf_size.z, false, Image::FORMAT_RF, data);
ret->convert(Image::FORMAT_RH); //convert to half, save space
ret->set_meta("depth", sdf_size.z); //hack, make sure to add to the docs of this function
diff --git a/scene/3d/light_3d.cpp b/scene/3d/light_3d.cpp
index d45749d36b..37881c3332 100644
--- a/scene/3d/light_3d.cpp
+++ b/scene/3d/light_3d.cpp
@@ -353,7 +353,7 @@ Light3D::Light3D(RenderingServer::LightType p_type) {
}
Light3D::Light3D() {
- ERR_PRINT("Light3D should not be instanced directly; use the DirectionalLight3D, OmniLight3D or SpotLight3D subtypes instead.");
+ ERR_PRINT("Light3D should not be instantiated directly; use the DirectionalLight3D, OmniLight3D or SpotLight3D subtypes instead.");
}
Light3D::~Light3D() {
diff --git a/scene/3d/lightmap_gi.cpp b/scene/3d/lightmap_gi.cpp
index a3f681e53c..74b4269169 100644
--- a/scene/3d/lightmap_gi.cpp
+++ b/scene/3d/lightmap_gi.cpp
@@ -717,7 +717,7 @@ LightmapGI::BakeError LightmapGI::bake(Node *p_from_node, String p_image_data_pa
w_albedo[i + 3] = 255;
}
- md.albedo_on_uv2.instance();
+ md.albedo_on_uv2.instantiate();
md.albedo_on_uv2->create(lightmap_size.width, lightmap_size.height, false, Image::FORMAT_RGBA8, albedom);
}
@@ -940,7 +940,7 @@ LightmapGI::BakeError LightmapGI::bake(Node *p_from_node, String p_image_data_pa
} break;
case ENVIRONMENT_MODE_CUSTOM_COLOR: {
- environment_image.instance();
+ environment_image.instantiate();
environment_image->create(128, 64, false, Image::FORMAT_RGBAF);
Color c = environment_custom_color;
c.r *= environment_custom_energy;
@@ -972,7 +972,7 @@ LightmapGI::BakeError LightmapGI::bake(Node *p_from_node, String p_image_data_pa
}
//we assume they are all the same, so let's create a large one for saving
Ref<Image> large_image;
- large_image.instance();
+ large_image.instantiate();
large_image->create(images[0]->get_width(), images[0]->get_height() * images.size(), false, images[0]->get_format());
@@ -984,7 +984,7 @@ LightmapGI::BakeError LightmapGI::bake(Node *p_from_node, String p_image_data_pa
Ref<ConfigFile> config;
- config.instance();
+ config.instantiate();
if (FileAccess::exists(base_path + ".import")) {
config->load(base_path + ".import");
}
@@ -1017,7 +1017,7 @@ LightmapGI::BakeError LightmapGI::bake(Node *p_from_node, String p_image_data_pa
set_light_data(Ref<LightmapGIData>()); //clear
data->clear();
} else {
- data.instance();
+ data.instantiate();
}
data->set_light_texture(texture);
diff --git a/scene/3d/mesh_instance_3d.cpp b/scene/3d/mesh_instance_3d.cpp
index c495f68890..08dec232ab 100644
--- a/scene/3d/mesh_instance_3d.cpp
+++ b/scene/3d/mesh_instance_3d.cpp
@@ -405,14 +405,14 @@ void MeshInstance3D::create_debug_tangents() {
if (lines.size()) {
Ref<StandardMaterial3D> sm;
- sm.instance();
+ sm.instantiate();
sm->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
sm->set_flag(StandardMaterial3D::FLAG_SRGB_VERTEX_COLOR, true);
sm->set_flag(StandardMaterial3D::FLAG_ALBEDO_FROM_VERTEX_COLOR, true);
Ref<ArrayMesh> am;
- am.instance();
+ am.instantiate();
Array a;
a.resize(Mesh::ARRAY_MAX);
a[Mesh::ARRAY_VERTEX] = lines;
diff --git a/scene/3d/occluder_instance_3d.cpp b/scene/3d/occluder_instance_3d.cpp
index 429e1d4b98..b0b9668fd2 100644
--- a/scene/3d/occluder_instance_3d.cpp
+++ b/scene/3d/occluder_instance_3d.cpp
@@ -114,7 +114,7 @@ Ref<ArrayMesh> Occluder3D::get_debug_mesh() const {
arrays[Mesh::ARRAY_VERTEX] = vertices;
arrays[Mesh::ARRAY_INDEX] = indices;
- debug_mesh.instance();
+ debug_mesh.instantiate();
debug_mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, arrays);
return debug_mesh;
}
@@ -303,7 +303,7 @@ OccluderInstance3D::BakeError OccluderInstance3D::bake(Node *p_from_node, String
if (get_occluder().is_valid()) {
occ = get_occluder();
} else {
- occ.instance();
+ occ.instantiate();
occ->set_path(p_occluder_path);
}
diff --git a/scene/3d/physics_body_3d.cpp b/scene/3d/physics_body_3d.cpp
index 28a0c72fe3..8e10a37afb 100644
--- a/scene/3d/physics_body_3d.cpp
+++ b/scene/3d/physics_body_3d.cpp
@@ -106,7 +106,7 @@ Ref<KinematicCollision3D> PhysicsBody3D::_move(const Vector3 &p_motion, bool p_i
PhysicsServer3D::MotionResult result;
if (move_and_collide(p_motion, p_infinite_inertia, result, p_margin, p_exclude_raycast_shapes, p_test_only)) {
if (motion_cache.is_null()) {
- motion_cache.instance();
+ motion_cache.instantiate();
motion_cache->owner = this;
}
@@ -1168,7 +1168,7 @@ Ref<KinematicCollision3D> CharacterBody3D::_get_slide_collision(int p_bounce) {
}
if (slide_colliders[p_bounce].is_null()) {
- slide_colliders.write[p_bounce].instance();
+ slide_colliders.write[p_bounce].instantiate();
slide_colliders.write[p_bounce]->owner = this;
}
diff --git a/scene/3d/skeleton_3d.cpp b/scene/3d/skeleton_3d.cpp
index f9d613a4bb..fa3b16935c 100644
--- a/scene/3d/skeleton_3d.cpp
+++ b/scene/3d/skeleton_3d.cpp
@@ -797,7 +797,7 @@ Ref<SkinReference> Skeleton3D::register_skin(const Ref<Skin> &p_skin) {
//when skeletons did not support skins. It is also used by gizmo
//to display the skeleton.
- skin.instance();
+ skin.instantiate();
skin->set_bind_count(bones.size());
_update_process_order(); //just in case
@@ -826,7 +826,7 @@ Ref<SkinReference> Skeleton3D::register_skin(const Ref<Skin> &p_skin) {
ERR_FAIL_COND_V(skin.is_null(), Ref<SkinReference>());
Ref<SkinReference> skin_ref;
- skin_ref.instance();
+ skin_ref.instantiate();
skin_ref->skeleton_node = this;
skin_ref->bind_count = 0;
diff --git a/scene/3d/soft_body_3d.cpp b/scene/3d/soft_body_3d.cpp
index df5474d03e..9592fe5849 100644
--- a/scene/3d/soft_body_3d.cpp
+++ b/scene/3d/soft_body_3d.cpp
@@ -465,7 +465,7 @@ void SoftBody3D::become_mesh_owner() {
surface_format |= Mesh::ARRAY_FLAG_USE_DYNAMIC_UPDATE;
Ref<ArrayMesh> soft_mesh;
- soft_mesh.instance();
+ soft_mesh.instantiate();
soft_mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, surface_arrays, surface_blend_arrays, surface_lods, surface_format);
soft_mesh->surface_set_material(0, mesh->surface_get_material(0));
diff --git a/scene/3d/voxel_gi.cpp b/scene/3d/voxel_gi.cpp
index e00be9204c..5558930df8 100644
--- a/scene/3d/voxel_gi.cpp
+++ b/scene/3d/voxel_gi.cpp
@@ -55,7 +55,7 @@ void VoxelGIData::_set_data(const Dictionary &p_data) {
} else if (p_data.has("octree_df_png")) {
Vector<uint8_t> octree_df_png = p_data["octree_df_png"];
Ref<Image> img;
- img.instance();
+ img.instantiate();
Error err = img->load_png_from_buffer(octree_df_png);
ERR_FAIL_COND(err != OK);
ERR_FAIL_COND(img->get_format() != Image::FORMAT_L8);
@@ -76,7 +76,7 @@ Dictionary VoxelGIData::_get_data() const {
d["octree_data"] = get_data_cells();
if (otsize != Vector3i()) {
Ref<Image> img;
- img.instance();
+ img.instantiate();
img->create(otsize.x * otsize.y, otsize.z, false, Image::FORMAT_L8, get_distance_field());
Vector<uint8_t> df_png = img->save_png_to_buffer();
ERR_FAIL_COND_V(df_png.size() == 0, Dictionary());
@@ -467,7 +467,7 @@ void VoxelGI::bake(Node *p_from_node, bool p_create_visual_debug) {
Ref<VoxelGIData> probe_data = get_probe_data();
if (probe_data.is_null()) {
- probe_data.instance();
+ probe_data.instantiate();
}
if (bake_step_function) {
diff --git a/scene/3d/voxelizer.cpp b/scene/3d/voxelizer.cpp
index ee0c3fe9b6..12f055c01d 100644
--- a/scene/3d/voxelizer.cpp
+++ b/scene/3d/voxelizer.cpp
@@ -931,14 +931,14 @@ void Voxelizer::_debug_mesh(int p_idx, int p_level, const AABB &p_aabb, Ref<Mult
Ref<MultiMesh> Voxelizer::create_debug_multimesh() {
Ref<MultiMesh> mm;
- mm.instance();
+ mm.instantiate();
mm->set_transform_format(MultiMesh::TRANSFORM_3D);
mm->set_use_colors(true);
mm->set_instance_count(leaf_voxel_count);
Ref<ArrayMesh> mesh;
- mesh.instance();
+ mesh.instantiate();
{
Array arr;
@@ -985,7 +985,7 @@ Ref<MultiMesh> Voxelizer::create_debug_multimesh() {
{
Ref<StandardMaterial3D> fsm;
- fsm.instance();
+ fsm.instantiate();
fsm->set_flag(StandardMaterial3D::FLAG_SRGB_VERTEX_COLOR, true);
fsm->set_flag(StandardMaterial3D::FLAG_ALBEDO_FROM_VERTEX_COLOR, true);
fsm->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
diff --git a/scene/3d/world_environment.cpp b/scene/3d/world_environment.cpp
index 829ecc5ec2..352bef072f 100644
--- a/scene/3d/world_environment.cpp
+++ b/scene/3d/world_environment.cpp
@@ -145,7 +145,7 @@ TypedArray<String> WorldEnvironment::get_configuration_warnings() const {
}
if (camera_effects.is_valid() && get_viewport()->find_world_3d()->get_camera_effects() != camera_effects) {
- warnings.push_back(TTR("Only one WorldEnvironment is allowed per scene (or set of instanced scenes)."));
+ warnings.push_back(TTR("Only one WorldEnvironment is allowed per scene (or set of instantiated scenes)."));
}
return warnings;
diff --git a/scene/3d/xr_nodes.cpp b/scene/3d/xr_nodes.cpp
index 4f2c816934..a91e712b0b 100644
--- a/scene/3d/xr_nodes.cpp
+++ b/scene/3d/xr_nodes.cpp
@@ -204,7 +204,7 @@ void XRController3D::_notification(int p_what) {
// check button states
for (int i = 0; i < 16; i++) {
bool was_pressed = (button_states & mask) == mask;
- bool is_pressed = Input::get_singleton()->is_joy_button_pressed(joy_id, i);
+ bool is_pressed = Input::get_singleton()->is_joy_button_pressed(joy_id, (JoyButton)i);
if (!was_pressed && is_pressed) {
emit_signal("button_pressed", i);
@@ -304,7 +304,7 @@ bool XRController3D::is_button_pressed(int p_button) const {
return false;
};
- return Input::get_singleton()->is_joy_button_pressed(joy_id, p_button);
+ return Input::get_singleton()->is_joy_button_pressed(joy_id, (JoyButton)p_button);
};
float XRController3D::get_joystick_axis(int p_axis) const {
@@ -313,7 +313,7 @@ float XRController3D::get_joystick_axis(int p_axis) const {
return 0.0;
};
- return Input::get_singleton()->get_joy_axis(joy_id, p_axis);
+ return Input::get_singleton()->get_joy_axis(joy_id, (JoyAxis)p_axis);
};
real_t XRController3D::get_rumble() const {
diff --git a/scene/animation/animation_blend_tree.cpp b/scene/animation/animation_blend_tree.cpp
index 79a1dc1ac0..ad6115fa16 100644
--- a/scene/animation/animation_blend_tree.cpp
+++ b/scene/animation/animation_blend_tree.cpp
@@ -1164,7 +1164,7 @@ void AnimationNodeBlendTree::_bind_methods() {
AnimationNodeBlendTree::AnimationNodeBlendTree() {
Ref<AnimationNodeOutput> output;
- output.instance();
+ output.instantiate();
Node n;
n.node = output;
n.position = Vector2(300, 150);
diff --git a/scene/animation/animation_node_state_machine.cpp b/scene/animation/animation_node_state_machine.cpp
index 65918a2989..f494f5c163 100644
--- a/scene/animation/animation_node_state_machine.cpp
+++ b/scene/animation/animation_node_state_machine.cpp
@@ -496,7 +496,7 @@ void AnimationNodeStateMachinePlayback::_bind_methods() {
}
AnimationNodeStateMachinePlayback::AnimationNodeStateMachinePlayback() {
- set_local_to_scene(true); //only one per instanced scene
+ set_local_to_scene(true); //only one per instantiated scene
}
///////////////////////////////////////////////////////
@@ -520,7 +520,7 @@ void AnimationNodeStateMachine::get_parameter_list(List<PropertyInfo> *r_list) c
Variant AnimationNodeStateMachine::get_parameter_default_value(const StringName &p_parameter) const {
if (p_parameter == playback) {
Ref<AnimationNodeStateMachinePlayback> p;
- p.instance();
+ p.instantiate();
return p;
} else {
return false; //advance condition
diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp
index e3748a4ae1..799c81c2ab 100644
--- a/scene/animation/animation_player.cpp
+++ b/scene/animation/animation_player.cpp
@@ -1511,7 +1511,7 @@ Ref<AnimatedValuesBackup> AnimationPlayer::backup_animated_values(Node *p_root_o
_ensure_node_caches(playback.current.from, p_root_override);
- backup.instance();
+ backup.instantiate();
for (int i = 0; i < playback.current.from->node_cache.size(); i++) {
TrackNodeCache *nc = playback.current.from->node_cache[i];
if (!nc) {
diff --git a/scene/animation/tween.cpp b/scene/animation/tween.cpp
index b4e597f75e..7bf616e602 100644
--- a/scene/animation/tween.cpp
+++ b/scene/animation/tween.cpp
@@ -30,535 +30,407 @@
#include "tween.h"
-void Tween::_add_pending_command(StringName p_key, 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, const Variant &p_arg9, const Variant &p_arg10) {
- // Add a new pending command and reference it
- pending_commands.push_back(PendingCommand());
- PendingCommand &cmd = pending_commands.back()->get();
-
- // Update the command with the target key
- cmd.key = p_key;
-
- // Determine command argument count
- int &count = cmd.args;
- if (p_arg10.get_type() != Variant::NIL) {
- count = 10;
- } else if (p_arg9.get_type() != Variant::NIL) {
- count = 9;
- } else if (p_arg8.get_type() != Variant::NIL) {
- count = 8;
- } else if (p_arg7.get_type() != Variant::NIL) {
- count = 7;
- } else if (p_arg6.get_type() != Variant::NIL) {
- count = 6;
- } else if (p_arg5.get_type() != Variant::NIL) {
- count = 5;
- } else if (p_arg4.get_type() != Variant::NIL) {
- count = 4;
- } else if (p_arg3.get_type() != Variant::NIL) {
- count = 3;
- } else if (p_arg2.get_type() != Variant::NIL) {
- count = 2;
- } else if (p_arg1.get_type() != Variant::NIL) {
- count = 1;
- } else {
- count = 0;
- }
+#include "scene/main/node.h"
- // Add the specified arguments to the command
- if (count > 0) {
- cmd.arg[0] = p_arg1;
- }
- if (count > 1) {
- cmd.arg[1] = p_arg2;
- }
- if (count > 2) {
- cmd.arg[2] = p_arg3;
- }
- if (count > 3) {
- cmd.arg[3] = p_arg4;
- }
- if (count > 4) {
- cmd.arg[4] = p_arg5;
- }
- if (count > 5) {
- cmd.arg[5] = p_arg6;
- }
- if (count > 6) {
- cmd.arg[6] = p_arg7;
- }
- if (count > 7) {
- cmd.arg[7] = p_arg8;
- }
- if (count > 8) {
- cmd.arg[8] = p_arg9;
+void Tweener::set_tween(Ref<Tween> p_tween) {
+ tween = p_tween;
+}
+
+void Tweener::_bind_methods() {
+ ADD_SIGNAL(MethodInfo("finished"));
+}
+
+void Tween::start_tweeners() {
+ if (tweeners.is_empty()) {
+ dead = true;
+ ERR_FAIL_MSG("Tween without commands, aborting.");
}
- if (count > 9) {
- cmd.arg[9] = p_arg10;
+
+ for (List<Ref<Tweener>>::Element *E = tweeners.write[current_step].front(); E; E = E->next()) {
+ E->get()->start();
}
}
-void Tween::_process_pending_commands() {
- // For each pending command...
- for (List<PendingCommand>::Element *E = pending_commands.front(); E; E = E->next()) {
- // Get the command
- PendingCommand &cmd = E->get();
- Callable::CallError err;
-
- // Grab all of the arguments for the command
- Variant *arg[10] = {
- &cmd.arg[0],
- &cmd.arg[1],
- &cmd.arg[2],
- &cmd.arg[3],
- &cmd.arg[4],
- &cmd.arg[5],
- &cmd.arg[6],
- &cmd.arg[7],
- &cmd.arg[8],
- &cmd.arg[9],
- };
-
- // Execute the command (and retrieve any errors)
- this->call(cmd.key, (const Variant **)arg, cmd.args, err);
- }
+Ref<PropertyTweener> Tween::tween_property(Object *p_target, NodePath p_property, Variant p_to, float p_duration) {
+ ERR_FAIL_NULL_V(p_target, nullptr);
+ ERR_FAIL_COND_V_MSG(invalid, nullptr, "Tween was created outside the scene tree, can't use Tweeners.");
+ ERR_FAIL_COND_V_MSG(started, nullptr, "Can't append to a Tween that has started. Use stop() first.");
- // Clear the pending commands
- pending_commands.clear();
+ Ref<PropertyTweener> tweener = memnew(PropertyTweener(p_target, p_property, p_to, p_duration));
+ append(tweener);
+ return tweener;
}
-bool Tween::_set(const StringName &p_name, const Variant &p_value) {
- // Set the correct attribute based on the given name
- String name = p_name;
- if (name == "playback/speed" || name == "speed") { // Backwards compatibility
- set_speed_scale(p_value);
- return true;
+Ref<IntervalTweener> Tween::tween_interval(float p_time) {
+ ERR_FAIL_COND_V_MSG(invalid, nullptr, "Tween was created outside the scene tree, can't use Tweeners.");
+ ERR_FAIL_COND_V_MSG(started, nullptr, "Can't append to a Tween that has started. Use stop() first.");
- } else if (name == "playback/active") {
- set_active(p_value);
- return true;
+ Ref<IntervalTweener> tweener = memnew(IntervalTweener(p_time));
+ append(tweener);
+ return tweener;
+}
- } else if (name == "playback/repeat") {
- set_repeat(p_value);
- return true;
- }
- return false;
+Ref<CallbackTweener> Tween::tween_callback(Callable p_callback) {
+ ERR_FAIL_COND_V_MSG(invalid, nullptr, "Tween was created outside the scene tree, can't use Tweeners.");
+ ERR_FAIL_COND_V_MSG(started, nullptr, "Can't append to a Tween that has started. Use stop() first.");
+
+ Ref<CallbackTweener> tweener = memnew(CallbackTweener(p_callback));
+ append(tweener);
+ return tweener;
}
-bool Tween::_get(const StringName &p_name, Variant &r_ret) const {
- // Get the correct attribute based on the given name
- String name = p_name;
- if (name == "playback/speed") { // Backwards compatibility
- r_ret = speed_scale;
- return true;
+Ref<MethodTweener> Tween::tween_method(Callable p_callback, float p_from, float p_to, float p_duration) {
+ ERR_FAIL_COND_V_MSG(invalid, nullptr, "Tween was created outside the scene tree, can't use Tweeners.");
+ ERR_FAIL_COND_V_MSG(started, nullptr, "Can't append to a Tween that has started. Use stop() first.");
- } else if (name == "playback/active") {
- r_ret = is_active();
- return true;
+ Ref<MethodTweener> tweener = memnew(MethodTweener(p_callback, p_from, p_to, p_duration));
+ append(tweener);
+ return tweener;
+}
- } else if (name == "playback/repeat") {
- r_ret = is_repeat();
- return true;
+Ref<Tween> Tween::append(Ref<Tweener> p_tweener) {
+ ERR_FAIL_COND_V_MSG(invalid, nullptr, "Tween was created outside the scene tree, can't use Tweeners.");
+ ERR_FAIL_COND_V_MSG(started, nullptr, "Can't append to a Tween that has started. Use stop() first.");
+ p_tweener->set_tween(this);
+
+ if (parallel_enabled) {
+ current_step = MAX(current_step, 0);
+ } else {
+ current_step++;
}
- return false;
-}
-
-void Tween::_get_property_list(List<PropertyInfo> *p_list) const {
- // Add the property info for the Tween object
- p_list->push_back(PropertyInfo(Variant::BOOL, "playback/active", PROPERTY_HINT_NONE, ""));
- p_list->push_back(PropertyInfo(Variant::BOOL, "playback/repeat", PROPERTY_HINT_NONE, ""));
- p_list->push_back(PropertyInfo(Variant::FLOAT, "playback/speed", PROPERTY_HINT_RANGE, "-64,64,0.01"));
-}
-
-void Tween::_notification(int p_what) {
- // What notification did we receive?
- switch (p_what) {
- case NOTIFICATION_ENTER_TREE: {
- // Are we not already active?
- if (!is_active()) {
- // Make sure that a previous process state was not saved
- // Only process if "processing" is set
- set_physics_process_internal(false);
- set_process_internal(false);
- }
- } break;
+ parallel_enabled = default_parallel;
- case NOTIFICATION_READY: {
- // Do nothing
- } break;
+ tweeners.resize(current_step + 1);
+ tweeners.write[current_step].push_back(p_tweener);
- case NOTIFICATION_INTERNAL_PROCESS: {
- // Are we processing during physics time?
- if (tween_process_mode == TWEEN_PROCESS_PHYSICS) {
- // Do nothing since we aren't aligned with physics when we should be
- break;
- }
+ return this;
+}
- // Should we update?
- if (is_active()) {
- // Update the tweens
- _tween_process(get_process_delta_time());
- }
- } break;
+void Tween::stop() {
+ started = false;
+ running = false;
+ dead = false;
+}
- case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
- // Are we processing during 'regular' time?
- if (tween_process_mode == TWEEN_PROCESS_IDLE) {
- // Do nothing since we would only process during idle time
- break;
- }
+void Tween::pause() {
+ running = false;
+}
- // Should we update?
- if (is_active()) {
- // Update the tweens
- _tween_process(get_physics_process_delta_time());
- }
- } break;
+void Tween::play() {
+ ERR_FAIL_COND_MSG(invalid, "Tween invalid, can't play.");
+ ERR_FAIL_COND_MSG(dead, "Can't play finished Tween, use stop() first to reset its state.");
+ running = true;
+}
- case NOTIFICATION_EXIT_TREE: {
- // We've left the tree. Stop all tweens
- stop_all();
- } break;
- }
+void Tween::kill() {
+ running = false; // For the sake of is_running().
+ dead = true;
}
-void Tween::_bind_methods() {
- // Bind getters and setters
- ClassDB::bind_method(D_METHOD("is_active"), &Tween::is_active);
- ClassDB::bind_method(D_METHOD("set_active", "active"), &Tween::set_active);
+bool Tween::is_running() {
+ return running;
+}
- ClassDB::bind_method(D_METHOD("is_repeat"), &Tween::is_repeat);
- ClassDB::bind_method(D_METHOD("set_repeat", "repeat"), &Tween::set_repeat);
+void Tween::set_valid(bool p_valid) {
+ invalid = !p_valid;
+}
- ClassDB::bind_method(D_METHOD("set_speed_scale", "speed"), &Tween::set_speed_scale);
- ClassDB::bind_method(D_METHOD("get_speed_scale"), &Tween::get_speed_scale);
-
- ClassDB::bind_method(D_METHOD("set_tween_process_mode", "mode"), &Tween::set_tween_process_mode);
- ClassDB::bind_method(D_METHOD("get_tween_process_mode"), &Tween::get_tween_process_mode);
-
- // Bind the various Tween control methods
- ClassDB::bind_method(D_METHOD("start"), &Tween::start);
- ClassDB::bind_method(D_METHOD("reset", "object", "key"), &Tween::reset, DEFVAL(""));
- ClassDB::bind_method(D_METHOD("reset_all"), &Tween::reset_all);
- ClassDB::bind_method(D_METHOD("stop", "object", "key"), &Tween::stop, DEFVAL(""));
- ClassDB::bind_method(D_METHOD("stop_all"), &Tween::stop_all);
- ClassDB::bind_method(D_METHOD("resume", "object", "key"), &Tween::resume, DEFVAL(""));
- ClassDB::bind_method(D_METHOD("resume_all"), &Tween::resume_all);
- ClassDB::bind_method(D_METHOD("remove", "object", "key"), &Tween::remove, DEFVAL(""));
- ClassDB::bind_method(D_METHOD("_remove_by_uid", "uid"), &Tween::_remove_by_uid);
- ClassDB::bind_method(D_METHOD("remove_all"), &Tween::remove_all);
- ClassDB::bind_method(D_METHOD("seek", "time"), &Tween::seek);
- ClassDB::bind_method(D_METHOD("tell"), &Tween::tell);
- ClassDB::bind_method(D_METHOD("get_runtime"), &Tween::get_runtime);
-
- // 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("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));
- ClassDB::bind_method(D_METHOD("targeting_method", "object", "method", "initial", "initial_method", "final_val", "duration", "trans_type", "ease_type", "delay"), &Tween::targeting_method, DEFVAL(TRANS_LINEAR), DEFVAL(EASE_IN_OUT), DEFVAL(0));
-
- // Add the Tween signals
- ADD_SIGNAL(MethodInfo("tween_started", PropertyInfo(Variant::OBJECT, "object"), PropertyInfo(Variant::NODE_PATH, "key")));
- ADD_SIGNAL(MethodInfo("tween_step", PropertyInfo(Variant::OBJECT, "object"), PropertyInfo(Variant::NODE_PATH, "key"), PropertyInfo(Variant::FLOAT, "elapsed"), PropertyInfo(Variant::OBJECT, "value")));
- ADD_SIGNAL(MethodInfo("tween_completed", PropertyInfo(Variant::OBJECT, "object"), PropertyInfo(Variant::NODE_PATH, "key")));
- ADD_SIGNAL(MethodInfo("tween_all_completed"));
-
- // Add the properties and tie them to the getters and setters
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "repeat"), "set_repeat", "is_repeat");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "playback_process_mode", PROPERTY_HINT_ENUM, "Physics,Idle"), "set_tween_process_mode", "get_tween_process_mode");
- ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "playback_speed", PROPERTY_HINT_RANGE, "-64,64,0.01"), "set_speed_scale", "get_speed_scale");
-
- // Bind Idle vs Physics process
- BIND_ENUM_CONSTANT(TWEEN_PROCESS_PHYSICS);
- BIND_ENUM_CONSTANT(TWEEN_PROCESS_IDLE);
+bool Tween::is_valid() {
+ return invalid;
+}
- // Bind the Transition type constants
- BIND_ENUM_CONSTANT(TRANS_LINEAR);
- BIND_ENUM_CONSTANT(TRANS_SINE);
- BIND_ENUM_CONSTANT(TRANS_QUINT);
- BIND_ENUM_CONSTANT(TRANS_QUART);
- BIND_ENUM_CONSTANT(TRANS_QUAD);
- BIND_ENUM_CONSTANT(TRANS_EXPO);
- BIND_ENUM_CONSTANT(TRANS_ELASTIC);
- BIND_ENUM_CONSTANT(TRANS_CUBIC);
- BIND_ENUM_CONSTANT(TRANS_CIRC);
- BIND_ENUM_CONSTANT(TRANS_BOUNCE);
- BIND_ENUM_CONSTANT(TRANS_BACK);
+Ref<Tween> Tween::bind_node(Node *p_node) {
+ bound_node = p_node->get_instance_id();
+ is_bound = true;
+ return this;
+}
- // Bind the easing constants
- BIND_ENUM_CONSTANT(EASE_IN);
- BIND_ENUM_CONSTANT(EASE_OUT);
- BIND_ENUM_CONSTANT(EASE_IN_OUT);
- BIND_ENUM_CONSTANT(EASE_OUT_IN);
+Ref<Tween> Tween::set_process_mode(TweenProcessMode p_mode) {
+ process_mode = p_mode;
+ return this;
}
-Variant Tween::_get_initial_val(const InterpolateData &p_data) const {
- // What type of data are we interpolating?
- switch (p_data.type) {
- case INTER_PROPERTY:
- case INTER_METHOD:
- case FOLLOW_PROPERTY:
- case FOLLOW_METHOD:
- // Simply use the given initial value
- return p_data.initial_val;
-
- case TARGETING_PROPERTY:
- case TARGETING_METHOD: {
- // Get the object that is being targeted
- Object *object = ObjectDB::get_instance(p_data.target_id);
- ERR_FAIL_COND_V(object == nullptr, p_data.initial_val);
-
- // Are we targeting a property or a method?
- Variant initial_val;
- if (p_data.type == TARGETING_PROPERTY) {
- // Get the property from the target object
- bool valid = false;
- initial_val = object->get_indexed(p_data.target_key, &valid);
- ERR_FAIL_COND_V(!valid, p_data.initial_val);
- } else {
- // Call the method and get the initial value from it
- Callable::CallError error;
- initial_val = object->call(p_data.target_key[0], nullptr, 0, error);
- ERR_FAIL_COND_V(error.error != Callable::CallError::CALL_OK, p_data.initial_val);
- }
- return initial_val;
- }
+Tween::TweenProcessMode Tween::get_process_mode() {
+ return process_mode;
+}
+
+Ref<Tween> Tween::set_pause_mode(TweenPauseMode p_mode) {
+ pause_mode = p_mode;
+ return this;
+}
+
+Tween::TweenPauseMode Tween::get_pause_mode() {
+ return pause_mode;
+}
+
+Ref<Tween> Tween::set_parallel(bool p_parallel) {
+ default_parallel = p_parallel;
+ parallel_enabled = p_parallel;
+ return this;
+}
+
+Ref<Tween> Tween::set_loops(int p_loops) {
+ loops = p_loops;
+ return this;
+}
+
+Ref<Tween> Tween::set_speed_scale(float p_speed) {
+ speed_scale = p_speed;
+ return this;
+}
+
+Ref<Tween> Tween::set_trans(TransitionType p_trans) {
+ default_transition = p_trans;
+ return this;
+}
- case INTER_CALLBACK:
- // Callback does not have a special initial value
- break;
+Tween::TransitionType Tween::get_trans() {
+ return default_transition;
+}
+
+Ref<Tween> Tween::set_ease(EaseType p_ease) {
+ default_ease = p_ease;
+ return this;
+}
+
+Tween::EaseType Tween::get_ease() {
+ return default_ease;
+}
+
+Ref<Tween> Tween::parallel() {
+ parallel_enabled = true;
+ return this;
+}
+
+Ref<Tween> Tween::chain() {
+ parallel_enabled = false;
+ return this;
+}
+
+bool Tween::custom_step(float p_delta) {
+ bool r = running;
+ running = true;
+ bool ret = step(p_delta);
+ running = running && r; // Running might turn false when Tween finished.
+ return ret;
+}
+
+bool Tween::step(float p_delta) {
+ ERR_FAIL_COND_V_MSG(tweeners.is_empty(), false, "Tween started, but has no Tweeners.");
+
+ if (dead) {
+ return false;
}
- // If we've made it here, just return the delta value as the initial value
- return p_data.delta_val;
-}
-
-Variant Tween::_get_final_val(const InterpolateData &p_data) const {
- switch (p_data.type) {
- case FOLLOW_PROPERTY:
- case FOLLOW_METHOD: {
- // Get the object that is being followed
- Object *target = ObjectDB::get_instance(p_data.target_id);
- ERR_FAIL_COND_V(target == nullptr, p_data.initial_val);
-
- // We want to figure out the final value
- Variant final_val;
- if (p_data.type == FOLLOW_PROPERTY) {
- // Read the property as-is
- bool valid = false;
- final_val = target->get_indexed(p_data.target_key, &valid);
- ERR_FAIL_COND_V(!valid, p_data.initial_val);
- } else {
- // We're looking at a method. Call the method on the target object
- Callable::CallError error;
- final_val = target->call(p_data.target_key[0], nullptr, 0, error);
- ERR_FAIL_COND_V(error.error != Callable::CallError::CALL_OK, p_data.initial_val);
- }
- // If we're looking at an INT value, instead convert it to a FLOAT
- // This is better for interpolation
- if (final_val.get_type() == Variant::INT) {
- final_val = final_val.operator real_t();
- }
+ if (!running) {
+ return true;
+ }
- return final_val;
- }
- default: {
- // If we're not following a final value/method, use the final value from the data
- return p_data.final_val;
+ if (is_bound) {
+ Object *bound_instance = ObjectDB::get_instance(bound_node);
+ if (bound_instance) {
+ Node *bound_node = Object::cast_to<Node>(bound_instance);
+ // This can't by anything else than Node, so we can omit checking if casting succeeded.
+ if (!bound_node->is_inside_tree()) {
+ return true;
+ }
+ } else {
+ return false;
}
}
-}
-Variant &Tween::_get_delta_val(InterpolateData &p_data) {
- // What kind of data are we interpolating?
- switch (p_data.type) {
- case INTER_PROPERTY:
- case INTER_METHOD:
- // Simply return the given delta value
- return p_data.delta_val;
-
- case FOLLOW_PROPERTY:
- case FOLLOW_METHOD: {
- // We're following an object, so grab that instance
- Object *target = ObjectDB::get_instance(p_data.target_id);
- ERR_FAIL_COND_V(target == nullptr, p_data.initial_val);
-
- // We want to figure out the final value
- Variant final_val;
- if (p_data.type == FOLLOW_PROPERTY) {
- // Read the property as-is
- bool valid = false;
- final_val = target->get_indexed(p_data.target_key, &valid);
- ERR_FAIL_COND_V(!valid, p_data.initial_val);
- } else {
- // We're looking at a method. Call the method on the target object
- Callable::CallError error;
- final_val = target->call(p_data.target_key[0], nullptr, 0, error);
- ERR_FAIL_COND_V(error.error != Callable::CallError::CALL_OK, p_data.initial_val);
- }
+ if (!started) {
+ current_step = 0;
+ loops_done = 0;
+ start_tweeners();
+ started = true;
+ }
- // If we're looking at an INT value, instead convert it to a FLOAT
- // This is better for interpolation
- if (final_val.get_type() == Variant::INT) {
- final_val = final_val.operator real_t();
- }
+ float rem_delta = p_delta * speed_scale;
+ bool step_active = false;
- // Calculate the delta based on the initial value and the final value
- _calc_delta_val(p_data.initial_val, final_val, p_data.delta_val);
- return p_data.delta_val;
+ while (rem_delta > 0 && running) {
+ float step_delta = rem_delta;
+ step_active = false;
+
+ for (List<Ref<Tweener>>::Element *E = tweeners.write[current_step].front(); E; E = E->next()) {
+ // Modified inside Tweener.step().
+ float temp_delta = rem_delta;
+ // Turns to true if any Tweener returns true (i.e. is still not finished).
+ step_active = E->get()->step(temp_delta) || step_active;
+ step_delta = MIN(temp_delta, rem_delta);
}
- case TARGETING_PROPERTY:
- case TARGETING_METHOD: {
- // Grab the initial value from the data to calculate delta
- Variant initial_val = _get_initial_val(p_data);
+ rem_delta = step_delta;
- // If we're looking at an INT value, instead convert it to a FLOAT
- // This is better for interpolation
- if (initial_val.get_type() == Variant::INT) {
- initial_val = initial_val.operator real_t();
- }
+ if (!step_active) {
+ emit_signal("step_finished", current_step);
+ current_step++;
- // Calculate the delta based on the initial value and the final value
- _calc_delta_val(initial_val, p_data.final_val, p_data.delta_val);
- return p_data.delta_val;
+ if (current_step == tweeners.size()) {
+ loops_done++;
+ if (loops_done == loops) {
+ running = false;
+ dead = true;
+ emit_signal("finished");
+ } else {
+ emit_signal("loop_finished", loops_done);
+ current_step = 0;
+ start_tweeners();
+ }
+ } else {
+ start_tweeners();
+ }
}
+ }
+
+ return true;
+}
- case INTER_CALLBACK:
- // Callbacks have no special delta
- break;
+bool Tween::should_pause() {
+ if (is_bound && pause_mode == TWEEN_PAUSE_BOUND) {
+ Object *bound_instance = ObjectDB::get_instance(bound_node);
+ if (bound_instance) {
+ Node *bound_node = Object::cast_to<Node>(bound_instance);
+ return !bound_node->can_process();
+ }
}
- // If we've made it here, use the initial value as the delta
- return p_data.initial_val;
+
+ return pause_mode != TWEEN_PAUSE_PROCESS;
}
-Variant Tween::_run_equation(InterpolateData &p_data) {
- // Get the initial and delta values from the data
- Variant initial_val = _get_initial_val(p_data);
- Variant &delta_val = _get_delta_val(p_data);
- Variant result;
+Variant Tween::interpolate_variant(Variant p_initial_val, Variant p_delta_val, float p_time, float p_duration, TransitionType p_trans, EaseType p_ease) {
+ ERR_FAIL_INDEX_V(p_trans, TransitionType::TRANS_MAX, Variant());
+ ERR_FAIL_INDEX_V(p_ease, EaseType::EASE_MAX, Variant());
+// Helper macro to run equation on sub-elements of the value (e.g. x and y of Vector2).
#define APPLY_EQUATION(element) \
- r.element = _run_equation(p_data.trans_type, p_data.ease_type, p_data.elapsed - p_data.delay, i.element, d.element, p_data.duration);
+ r.element = run_equation(p_trans, p_ease, p_time, i.element, d.element, p_duration);
- // What type of data are we interpolating?
- switch (initial_val.get_type()) {
- case Variant::BOOL:
- // Run the boolean specific equation (checking if it is at least 0.5)
- result = (_run_equation(p_data.trans_type, p_data.ease_type, p_data.elapsed - p_data.delay, initial_val, delta_val, p_data.duration)) >= 0.5;
- break;
+ switch (p_initial_val.get_type()) {
+ case Variant::BOOL: {
+ return (run_equation(p_trans, p_ease, p_time, p_initial_val, p_delta_val, p_duration)) >= 0.5;
+ }
- case Variant::INT:
- // Run the integer specific equation
- result = (int)_run_equation(p_data.trans_type, p_data.ease_type, p_data.elapsed - p_data.delay, (int)initial_val, (int)delta_val, p_data.duration);
- break;
+ case Variant::INT: {
+ return (int)run_equation(p_trans, p_ease, p_time, (int)p_initial_val, (int)p_delta_val, p_duration);
+ }
- case Variant::FLOAT:
- // Run the FLOAT specific equation
- result = _run_equation(p_data.trans_type, p_data.ease_type, p_data.elapsed - p_data.delay, (real_t)initial_val, (real_t)delta_val, p_data.duration);
- break;
+ case Variant::FLOAT: {
+ return run_equation(p_trans, p_ease, p_time, (real_t)p_initial_val, (real_t)p_delta_val, p_duration);
+ }
case Variant::VECTOR2: {
- // Get vectors for initial and delta values
- Vector2 i = initial_val;
- Vector2 d = delta_val;
+ Vector2 i = p_initial_val;
+ Vector2 d = p_delta_val;
Vector2 r;
- // Execute the equation and mutate the r vector
- // This uses the custom APPLY_EQUATION macro defined above
APPLY_EQUATION(x);
APPLY_EQUATION(y);
- result = r;
- } break;
+ return r;
+ }
+
+ case Variant::VECTOR2I: {
+ Vector2i i = p_initial_val;
+ Vector2i d = p_delta_val;
+ Vector2i r;
+
+ APPLY_EQUATION(x);
+ APPLY_EQUATION(y);
+ return r;
+ }
case Variant::RECT2: {
- // Get the Rect2 for initial and delta value
- Rect2 i = initial_val;
- Rect2 d = delta_val;
+ Rect2 i = p_initial_val;
+ Rect2 d = p_delta_val;
Rect2 r;
- // Execute the equation for the position and size of Rect2
APPLY_EQUATION(position.x);
APPLY_EQUATION(position.y);
APPLY_EQUATION(size.x);
APPLY_EQUATION(size.y);
- result = r;
- } break;
+ return r;
+ }
+
+ case Variant::RECT2I: {
+ Rect2i i = p_initial_val;
+ Rect2i d = p_delta_val;
+ Rect2i r;
+
+ APPLY_EQUATION(position.x);
+ APPLY_EQUATION(position.y);
+ APPLY_EQUATION(size.x);
+ APPLY_EQUATION(size.y);
+ return r;
+ }
case Variant::VECTOR3: {
- // Get vectors for initial and delta values
- Vector3 i = initial_val;
- Vector3 d = delta_val;
+ Vector3 i = p_initial_val;
+ Vector3 d = p_delta_val;
Vector3 r;
- // Execute the equation and mutate the r vector
- // This uses the custom APPLY_EQUATION macro defined above
APPLY_EQUATION(x);
APPLY_EQUATION(y);
APPLY_EQUATION(z);
- result = r;
- } break;
+ return r;
+ }
+
+ case Variant::VECTOR3I: {
+ Vector3i i = p_initial_val;
+ Vector3i d = p_delta_val;
+ Vector3i r;
+
+ APPLY_EQUATION(x);
+ APPLY_EQUATION(y);
+ APPLY_EQUATION(z);
+ return r;
+ }
case Variant::TRANSFORM2D: {
- // Get the transforms for initial and delta values
- Transform2D i = initial_val;
- Transform2D d = delta_val;
+ Transform2D i = p_initial_val;
+ Transform2D d = p_delta_val;
Transform2D r;
- // Execute the equation on the transforms and mutate the r transform
- // This uses the custom APPLY_EQUATION macro defined above
APPLY_EQUATION(elements[0][0]);
APPLY_EQUATION(elements[0][1]);
APPLY_EQUATION(elements[1][0]);
APPLY_EQUATION(elements[1][1]);
APPLY_EQUATION(elements[2][0]);
APPLY_EQUATION(elements[2][1]);
- result = r;
- } break;
+ return r;
+ }
case Variant::QUATERNION: {
- // Get the quaternian for the initial and delta values
- Quaternion i = initial_val;
- Quaternion d = delta_val;
+ Quaternion i = p_initial_val;
+ Quaternion d = p_delta_val;
Quaternion r;
- // Execute the equation on the quaternian values and mutate the r quaternian
- // This uses the custom APPLY_EQUATION macro defined above
APPLY_EQUATION(x);
APPLY_EQUATION(y);
APPLY_EQUATION(z);
APPLY_EQUATION(w);
- result = r;
- } break;
+ return r;
+ }
case Variant::AABB: {
- // Get the AABB's for the initial and delta values
- AABB i = initial_val;
- AABB d = delta_val;
+ AABB i = p_initial_val;
+ AABB d = p_delta_val;
AABB r;
- // Execute the equation for the position and size of the AABB's and mutate the r AABB
- // This uses the custom APPLY_EQUATION macro defined above
APPLY_EQUATION(position.x);
APPLY_EQUATION(position.y);
APPLY_EQUATION(position.z);
APPLY_EQUATION(size.x);
APPLY_EQUATION(size.y);
APPLY_EQUATION(size.z);
- result = r;
- } break;
+ return r;
+ }
case Variant::BASIS: {
- // Get the basis for initial and delta values
- Basis i = initial_val;
- Basis d = delta_val;
+ Basis i = p_initial_val;
+ Basis d = p_delta_val;
Basis r;
- // Execute the equation on all the basis and mutate the r basis
- // This uses the custom APPLY_EQUATION macro defined above
APPLY_EQUATION(elements[0][0]);
APPLY_EQUATION(elements[0][1]);
APPLY_EQUATION(elements[0][2]);
@@ -568,17 +440,14 @@ Variant Tween::_run_equation(InterpolateData &p_data) {
APPLY_EQUATION(elements[2][0]);
APPLY_EQUATION(elements[2][1]);
APPLY_EQUATION(elements[2][2]);
- result = r;
- } break;
+ return r;
+ }
case Variant::TRANSFORM3D: {
- // Get the transforms for the initial and delta values
- Transform3D i = initial_val;
- Transform3D d = delta_val;
+ Transform3D i = p_initial_val;
+ Transform3D d = p_delta_val;
Transform3D r;
- // Execute the equation for each of the transforms and their origin and mutate the r transform
- // This uses the custom APPLY_EQUATION macro defined above
APPLY_EQUATION(basis.elements[0][0]);
APPLY_EQUATION(basis.elements[0][1]);
APPLY_EQUATION(basis.elements[0][2]);
@@ -591,634 +460,67 @@ Variant Tween::_run_equation(InterpolateData &p_data) {
APPLY_EQUATION(origin.x);
APPLY_EQUATION(origin.y);
APPLY_EQUATION(origin.z);
- result = r;
- } break;
+ return r;
+ }
case Variant::COLOR: {
- // Get the Color for initial and delta value
- Color i = initial_val;
- Color d = delta_val;
+ Color i = p_initial_val;
+ Color d = p_delta_val;
Color r;
- // Apply the equation on the Color RGBA, and mutate the r color
- // This uses the custom APPLY_EQUATION macro defined above
APPLY_EQUATION(r);
APPLY_EQUATION(g);
APPLY_EQUATION(b);
APPLY_EQUATION(a);
- result = r;
- } break;
-
- default: {
- // If unknown, just return the initial value
- result = initial_val;
- } break;
- };
-#undef APPLY_EQUATION
- // Return the result that was computed
- return result;
-}
-
-bool Tween::_apply_tween_value(InterpolateData &p_data, Variant &value) {
- // Get the object we want to apply the new value to
- Object *object = ObjectDB::get_instance(p_data.id);
- ERR_FAIL_COND_V(object == nullptr, false);
-
- // What kind of data are we mutating?
- switch (p_data.type) {
- case INTER_PROPERTY:
- case FOLLOW_PROPERTY:
- case TARGETING_PROPERTY: {
- // Simply set the property on the object
- bool valid = false;
- object->set_indexed(p_data.key, value, &valid);
- return valid;
+ return r;
}
- case INTER_METHOD:
- case FOLLOW_METHOD:
- case TARGETING_METHOD: {
- // We want to call the method on the target object
- Callable::CallError error;
-
- // Do we have a non-nil value passed in?
- if (value.get_type() != Variant::NIL) {
- // Pass it as an argument to the function call
- Variant *arg[1] = { &value };
- object->call(p_data.key[0], (const Variant **)arg, 1, error);
- } else {
- // Don't pass any argument
- object->call(p_data.key[0], nullptr, 0, error);
- }
-
- // Did we get an error from the function call?
- return error.error == Callable::CallError::CALL_OK;
+ default: {
+ return p_initial_val;
}
-
- case INTER_CALLBACK:
- // Nothing to apply for a callback
- break;
};
- // No issues found!
- return true;
-}
-
-void Tween::_tween_process(float p_delta) {
- // Process all of the pending commands
- _process_pending_commands();
-
- // If the scale is 0, make no progress on the tweens
- if (speed_scale == 0) {
- return;
- }
-
- // Update the delta and whether we are pending an update
- p_delta *= speed_scale;
- pending_update++;
-
- // Are we repeating the interpolations?
- if (repeat) {
- // For each interpolation...
- bool repeats_finished = true;
- for (List<InterpolateData>::Element *E = interpolates.front(); E; E = E->next()) {
- // Get the data from it
- InterpolateData &data = E->get();
-
- // Is not finished?
- if (!data.finish) {
- // We aren't finished yet, no need to check the rest
- repeats_finished = false;
- break;
- }
- }
-
- // If we are all finished, we can reset all of the tweens
- if (repeats_finished) {
- reset_all();
- }
- }
-
- // Are all of the tweens complete?
- int any_unfinished = 0;
-
- // For each tween we wish to interpolate...
- for (List<InterpolateData>::Element *E = interpolates.front(); E; E = E->next()) {
- // Get the data from it
- InterpolateData &data = E->get();
-
- // Is the data not active or already finished? No need to go any further
- if (!data.active || data.finish) {
- continue;
- }
-
- // Track if we hit one that isn't finished yet
- any_unfinished++;
-
- // Get the target object for this interpolation
- Object *object = ObjectDB::get_instance(data.id);
- if (object == nullptr) {
- continue;
- }
-
- // Are we still delaying this tween?
- bool prev_delaying = data.elapsed <= data.delay;
- data.elapsed += p_delta;
- if (data.elapsed < data.delay) {
- continue;
- } else if (prev_delaying) {
- // We can apply the tween's value to the data and emit that the tween has started
- _apply_tween_value(data, data.initial_val);
- emit_signal("tween_started", object, NodePath(Vector<StringName>(), data.key, false));
- }
-
- // Are we at the end of the tween?
- if (data.elapsed > (data.delay + data.duration)) {
- // Set the elapsed time to the end and mark this one as finished
- data.elapsed = data.delay + data.duration;
- data.finish = true;
- }
-
- // Are we interpolating a callback?
- if (data.type == INTER_CALLBACK) {
- // Is the tween completed?
- if (data.finish) {
- // Are we calling this callback deferred or immediately?
- if (data.call_deferred) {
- // Run the deferred function callback, applying the correct number of arguments
- switch (data.args) {
- case 0:
- object->call_deferred(data.key[0]);
- break;
- case 1:
- object->call_deferred(data.key[0], data.arg[0]);
- break;
- case 2:
- object->call_deferred(data.key[0], data.arg[0], data.arg[1]);
- break;
- case 3:
- object->call_deferred(data.key[0], data.arg[0], data.arg[1], data.arg[2]);
- break;
- case 4:
- object->call_deferred(data.key[0], data.arg[0], data.arg[1], data.arg[2], data.arg[3]);
- break;
- case 5:
- object->call_deferred(data.key[0], data.arg[0], data.arg[1], data.arg[2], data.arg[3], data.arg[4]);
- break;
- }
- } else {
- // Call the function directly with the arguments
- Callable::CallError error;
- Variant *arg[5] = {
- &data.arg[0],
- &data.arg[1],
- &data.arg[2],
- &data.arg[3],
- &data.arg[4],
- };
- object->call(data.key[0], (const Variant **)arg, data.args, error);
- }
- }
- } else {
- // We can apply the value directly
- Variant result = _run_equation(data);
- _apply_tween_value(data, result);
-
- // Emit that the tween has taken a step
- emit_signal("tween_step", object, NodePath(Vector<StringName>(), data.key, false), data.elapsed, result);
- }
-
- // Is the tween now finished?
- if (data.finish) {
- // Set it to the final value directly
- Variant final_val = _get_final_val(data);
- _apply_tween_value(data, final_val);
-
- // Mark the tween as completed and emit the signal
- data.elapsed = 0;
- emit_signal("tween_completed", object, NodePath(Vector<StringName>(), data.key, false));
-
- // If we are not repeating the tween, remove it
- if (!repeat) {
- call_deferred("_remove_by_uid", data.uid);
- any_unfinished--;
- }
- }
- }
- // One less update left to go
- pending_update--;
-
- // If all tweens are completed, we no longer need to be active
- if (any_unfinished == 0) {
- set_active(false);
- emit_signal("tween_all_completed");
- }
-}
-
-void Tween::set_tween_process_mode(TweenProcessMode p_mode) {
- tween_process_mode = p_mode;
-}
-
-Tween::TweenProcessMode Tween::get_tween_process_mode() const {
- return tween_process_mode;
-}
-
-bool Tween::is_active() const {
- return is_processing_internal() || is_physics_processing_internal();
-}
-
-void Tween::set_active(bool p_active) {
- // Do nothing if it's the same active mode that we currently are
- if (is_active() == p_active) {
- return;
- }
-
- // Depending on physics or idle, set processing
- switch (tween_process_mode) {
- case TWEEN_PROCESS_IDLE:
- set_process_internal(p_active);
- break;
- case TWEEN_PROCESS_PHYSICS:
- set_physics_process_internal(p_active);
- break;
- }
-}
-
-bool Tween::is_repeat() const {
- return repeat;
-}
-
-void Tween::set_repeat(bool p_repeat) {
- repeat = p_repeat;
-}
-
-void Tween::set_speed_scale(float p_speed) {
- speed_scale = p_speed;
-}
-
-float Tween::get_speed_scale() const {
- return speed_scale;
-}
-
-void Tween::start() {
- ERR_FAIL_COND_MSG(!is_inside_tree(), "Tween was not added to the SceneTree!");
-
- // Are there any pending updates?
- if (pending_update != 0) {
- // Start the tweens after deferring
- call_deferred("start");
- return;
- }
-
- pending_update++;
- for (List<InterpolateData>::Element *E = interpolates.front(); E; E = E->next()) {
- InterpolateData &data = E->get();
- data.active = true;
- }
- pending_update--;
-
- // We want to be activated
- set_active(true);
-
- // Don't resume from current position if stop_all() function has been used
- if (was_stopped) {
- seek(0);
- }
- was_stopped = false;
-}
-
-void Tween::reset(Object *p_object, StringName p_key) {
- // Find all interpolations that use the same object and target string
- pending_update++;
- for (List<InterpolateData>::Element *E = interpolates.front(); E; E = E->next()) {
- // Get the target object
- InterpolateData &data = E->get();
- Object *object = ObjectDB::get_instance(data.id);
- if (object == nullptr) {
- continue;
- }
-
- // Do we have the correct object and key?
- if (object == p_object && (data.concatenated_key == p_key || p_key == "")) {
- // Reset the tween to the initial state
- data.elapsed = 0;
- data.finish = false;
-
- // Also apply the initial state if there isn't a delay
- if (data.delay == 0) {
- _apply_tween_value(data, data.initial_val);
- }
- }
- }
- pending_update--;
-}
-
-void Tween::reset_all() {
- // Go through all interpolations
- pending_update++;
- for (List<InterpolateData>::Element *E = interpolates.front(); E; E = E->next()) {
- // Get the target data and set it back to the initial state
- InterpolateData &data = E->get();
- data.elapsed = 0;
- data.finish = false;
-
- // If there isn't a delay, apply the value to the object
- if (data.delay == 0) {
- _apply_tween_value(data, data.initial_val);
- }
- }
- pending_update--;
-}
-
-void Tween::stop(Object *p_object, StringName p_key) {
- // Find the tween that has the given target object and string key
- pending_update++;
- for (List<InterpolateData>::Element *E = interpolates.front(); E; E = E->next()) {
- // Get the object the tween is targeting
- InterpolateData &data = E->get();
- Object *object = ObjectDB::get_instance(data.id);
- if (object == nullptr) {
- continue;
- }
-
- // Is this the correct object and does it have the given key?
- if (object == p_object && (data.concatenated_key == p_key || p_key == "")) {
- // Disable the tween
- data.active = false;
- }
- }
- pending_update--;
-}
-
-void Tween::stop_all() {
- // We no longer need to be active since all tweens have been stopped
- set_active(false);
- was_stopped = true;
- // For each interpolation...
- pending_update++;
- for (List<InterpolateData>::Element *E = interpolates.front(); E; E = E->next()) {
- // Simply set it inactive
- InterpolateData &data = E->get();
- data.active = false;
- }
- pending_update--;
-}
-
-void Tween::resume(Object *p_object, StringName p_key) {
- // We need to be activated
- // TODO: What if no tween is found??
- set_active(true);
-
- // Find the tween that uses the given target object and string key
- pending_update++;
- for (List<InterpolateData>::Element *E = interpolates.front(); E; E = E->next()) {
- // Grab the object
- InterpolateData &data = E->get();
- Object *object = ObjectDB::get_instance(data.id);
- if (object == nullptr) {
- continue;
- }
-
- // If the object and string key match, activate it
- if (object == p_object && (data.concatenated_key == p_key || p_key == "")) {
- data.active = true;
- }
- }
- pending_update--;
-}
-
-void Tween::resume_all() {
- // Set ourselves active so we can process tweens
- // TODO: What if there are no tweens? We get set to active for no reason!
- set_active(true);
-
- // For each interpolation...
- pending_update++;
- for (List<InterpolateData>::Element *E = interpolates.front(); E; E = E->next()) {
- // Simply grab it and set it to active
- InterpolateData &data = E->get();
- data.active = true;
- }
- pending_update--;
-}
-
-void Tween::remove(Object *p_object, StringName p_key) {
- // If we are still updating, call this function again later
- if (pending_update != 0) {
- call_deferred("remove", p_object, p_key);
- return;
- }
-
- // For each interpolation...
- List<List<InterpolateData>::Element *> for_removal;
- for (List<InterpolateData>::Element *E = interpolates.front(); E; E = E->next()) {
- // Get the target object
- InterpolateData &data = E->get();
- Object *object = ObjectDB::get_instance(data.id);
- if (object == nullptr) {
- continue;
- }
-
- // If the target object and string key match, queue it for removal
- if (object == p_object && (data.concatenated_key == p_key || p_key == "")) {
- for_removal.push_back(E);
- }
- }
-
- // For each interpolation we wish to remove...
- for (List<List<InterpolateData>::Element *>::Element *E = for_removal.front(); E; E = E->next()) {
- // Erase it
- interpolates.erase(E->get());
- }
-}
-
-void Tween::_remove_by_uid(int uid) {
- // If we are still updating, call this function again later
- if (pending_update != 0) {
- call_deferred("_remove_by_uid", uid);
- return;
- }
-
- // Find the interpolation that matches the given UID
- for (List<InterpolateData>::Element *E = interpolates.front(); E; E = E->next()) {
- if (uid == E->get().uid) {
- // It matches, erase it and stop looking
- E->erase();
- break;
- }
- }
-}
-
-void Tween::_push_interpolate_data(InterpolateData &p_data) {
- pending_update++;
-
- // Add the new interpolation
- p_data.uid = ++uid;
- interpolates.push_back(p_data);
-
- pending_update--;
+#undef APPLY_EQUATION
}
-void Tween::remove_all() {
- // If we are still updating, call this function again later
- if (pending_update != 0) {
- call_deferred("remove_all");
- return;
- }
- // We no longer need to be active
- set_active(false);
-
- // Clear out all interpolations and reset the uid
- interpolates.clear();
- uid = 0;
-}
-
-void Tween::seek(real_t p_time) {
- // Go through each interpolation...
- pending_update++;
- for (List<InterpolateData>::Element *E = interpolates.front(); E; E = E->next()) {
- // Get the target data
- InterpolateData &data = E->get();
-
- // Update the elapsed data to be set to the target time
- data.elapsed = p_time;
-
- // Are we at the end?
- if (data.elapsed < data.delay) {
- // There is still time left to go
- data.finish = false;
- continue;
- } else if (data.elapsed >= (data.delay + data.duration)) {
- // We are past the end of it, set the elapsed time to the end and mark as finished
- data.elapsed = (data.delay + data.duration);
- data.finish = true;
- } else {
- // We are not finished with this interpolation yet
- data.finish = false;
+Variant Tween::calculate_delta_value(Variant p_intial_val, Variant p_final_val) {
+ switch (p_intial_val.get_type()) {
+ case Variant::BOOL: {
+ return (int)p_final_val - (int)p_intial_val;
}
- // If we are a callback, do nothing special
- if (data.type == INTER_CALLBACK) {
- continue;
+ case Variant::RECT2: {
+ Rect2 i = p_intial_val;
+ Rect2 f = p_final_val;
+ return Rect2(f.position - i.position, f.size - i.size);
}
- // Run the equation on the data and apply the value
- Variant result = _run_equation(data);
- _apply_tween_value(data, result);
- }
- pending_update--;
-}
-
-real_t Tween::tell() const {
- // We want to grab the position of the furthest along tween
- pending_update++;
- real_t pos = 0.0;
-
- // For each interpolation...
- for (const List<InterpolateData>::Element *E = interpolates.front(); E; E = E->next()) {
- // Get the data and figure out if its position is further along than the previous ones
- const InterpolateData &data = E->get();
- if (data.elapsed > pos) {
- // Save it if so
- pos = data.elapsed;
+ case Variant::RECT2I: {
+ Rect2i i = p_intial_val;
+ Rect2i f = p_final_val;
+ return Rect2i(f.position - i.position, f.size - i.size);
}
- }
- pending_update--;
- return pos;
-}
-
-real_t Tween::get_runtime() const {
- // If the tween isn't moving, it'll last forever
- if (speed_scale == 0) {
- return INFINITY;
- }
-
- pending_update++;
-
- // For each interpolation...
- real_t runtime = 0.0;
- for (const List<InterpolateData>::Element *E = interpolates.front(); E; E = E->next()) {
- // Get the tween data and see if it's runtime is greater than the previous tweens
- const InterpolateData &data = E->get();
- real_t t = data.delay + data.duration;
- if (t > runtime) {
- // This is the longest running tween
- runtime = t;
- }
- }
- pending_update--;
-
- // Adjust the runtime for the current speed scale
- return runtime / speed_scale;
-}
-
-bool Tween::_calc_delta_val(const Variant &p_initial_val, const Variant &p_final_val, Variant &p_delta_val) {
- // Get the initial, final, and delta values
- const Variant &initial_val = p_initial_val;
- const Variant &final_val = p_final_val;
- Variant &delta_val = p_delta_val;
-
- // What kind of data are we interpolating?
- switch (initial_val.get_type()) {
- case Variant::BOOL:
- // We'll treat booleans just like integers
- case Variant::INT:
- // Compute the integer delta
- delta_val = (int)final_val - (int)initial_val;
- break;
-
- case Variant::FLOAT:
- // Convert to FLOAT and find the delta
- delta_val = (real_t)final_val - (real_t)initial_val;
- break;
-
- case Variant::VECTOR2:
- // Convert to Vectors and find the delta
- delta_val = final_val.operator Vector2() - initial_val.operator Vector2();
- break;
-
- case Variant::RECT2: {
- // Build a new Rect2 and use the new position and sizes to make a delta
- Rect2 i = initial_val;
- Rect2 f = final_val;
- delta_val = Rect2(f.position - i.position, f.size - i.size);
- } break;
-
- case Variant::VECTOR3:
- // Convert to Vectors and find the delta
- delta_val = final_val.operator Vector3() - initial_val.operator Vector3();
- break;
case Variant::TRANSFORM2D: {
- // Build a new transform which is the difference between the initial and final values
- Transform2D i = initial_val;
- Transform2D f = final_val;
- Transform2D d = Transform2D();
- d[0][0] = f.elements[0][0] - i.elements[0][0];
- d[0][1] = f.elements[0][1] - i.elements[0][1];
- d[1][0] = f.elements[1][0] - i.elements[1][0];
- d[1][1] = f.elements[1][1] - i.elements[1][1];
- d[2][0] = f.elements[2][0] - i.elements[2][0];
- d[2][1] = f.elements[2][1] - i.elements[2][1];
- delta_val = d;
- } break;
-
- case Variant::QUATERNION:
- // Convert to quaternianls and find the delta
- delta_val = final_val.operator Quaternion() - initial_val.operator Quaternion();
- break;
+ Transform2D i = p_intial_val;
+ Transform2D f = p_final_val;
+ return Transform2D(f.elements[0][0] - i.elements[0][0],
+ f.elements[0][1] - i.elements[0][1],
+ f.elements[1][0] - i.elements[1][0],
+ f.elements[1][1] - i.elements[1][1],
+ f.elements[2][0] - i.elements[2][0],
+ f.elements[2][1] - i.elements[2][1]);
+ }
case Variant::AABB: {
- // Build a new AABB and use the new position and sizes to make a delta
- AABB i = initial_val;
- AABB f = final_val;
- delta_val = AABB(f.position - i.position, f.size - i.size);
- } break;
+ AABB i = p_intial_val;
+ AABB f = p_final_val;
+ return AABB(f.position - i.position, f.size - i.size);
+ }
case Variant::BASIS: {
- // Build a new basis which is the delta between the initial and final values
- Basis i = initial_val;
- Basis f = final_val;
- delta_val = Basis(f.elements[0][0] - i.elements[0][0],
+ Basis i = p_intial_val;
+ Basis f = p_final_val;
+ return Basis(f.elements[0][0] - i.elements[0][0],
f.elements[0][1] - i.elements[0][1],
f.elements[0][2] - i.elements[0][2],
f.elements[1][0] - i.elements[1][0],
@@ -1227,14 +529,12 @@ bool Tween::_calc_delta_val(const Variant &p_initial_val, const Variant &p_final
f.elements[2][0] - i.elements[2][0],
f.elements[2][1] - i.elements[2][1],
f.elements[2][2] - i.elements[2][2]);
- } break;
+ }
case Variant::TRANSFORM3D: {
- // Build a new transform which is the difference between the initial and final values
- Transform3D i = initial_val;
- Transform3D f = final_val;
- Transform3D d;
- d.set(f.basis.elements[0][0] - i.basis.elements[0][0],
+ Transform3D i = p_intial_val;
+ Transform3D f = p_final_val;
+ return Transform3D(f.basis.elements[0][0] - i.basis.elements[0][0],
f.basis.elements[0][1] - i.basis.elements[0][1],
f.basis.elements[0][2] - i.basis.elements[0][2],
f.basis.elements[1][0] - i.basis.elements[1][0],
@@ -1246,569 +546,342 @@ bool Tween::_calc_delta_val(const Variant &p_initial_val, const Variant &p_final
f.origin.x - i.origin.x,
f.origin.y - i.origin.y,
f.origin.z - i.origin.z);
-
- delta_val = d;
- } break;
-
- case Variant::COLOR: {
- // Make a new color which is the difference between each the color's RGBA attributes
- Color i = initial_val;
- Color f = final_val;
- delta_val = Color(f.r - i.r, f.g - i.g, f.b - i.b, f.a - i.a);
- } break;
+ }
default: {
- static Variant::Type supported_types[] = {
- Variant::BOOL,
- Variant::INT,
- Variant::FLOAT,
- Variant::VECTOR2,
- Variant::RECT2,
- Variant::VECTOR3,
- Variant::TRANSFORM2D,
- Variant::QUATERNION,
- Variant::AABB,
- Variant::BASIS,
- Variant::TRANSFORM3D,
- Variant::COLOR,
- };
-
- int length = *(&supported_types + 1) - supported_types;
- String error_msg = "Invalid parameter type. Supported types are: ";
- for (int i = 0; i < length; i++) {
- if (i != 0) {
- error_msg += ", ";
- }
- error_msg += Variant::get_type_name(supported_types[i]);
- }
- error_msg += ".";
- ERR_PRINT(error_msg);
- return false;
+ return Variant::evaluate(Variant::OP_SUBTRACT, p_final_val, p_intial_val);
}
};
- return true;
}
-void Tween::_build_interpolation(InterpolateType p_interpolation_type, Object *p_object, NodePath *p_property, StringName *p_method, Variant p_initial_val, Variant p_final_val, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay) {
- // TODO: Add initialization+implementation for remaining interpolation types
- // TODO: Fix this method's organization to take advantage of the type
-
- // Make a new interpolation data
- InterpolateData data;
- data.active = true;
- data.type = p_interpolation_type;
- data.finish = false;
- data.elapsed = 0;
+void Tween::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("tween_property", "object", "property", "final_val", "duration"), &Tween::tween_property);
+ ClassDB::bind_method(D_METHOD("tween_interval", "time"), &Tween::tween_interval);
+ ClassDB::bind_method(D_METHOD("tween_callback", "callback"), &Tween::tween_callback);
+ ClassDB::bind_method(D_METHOD("tween_method", "method", "from", "to", "duration"), &Tween::tween_method);
+
+ ClassDB::bind_method(D_METHOD("custom_step", "delta"), &Tween::custom_step);
+ ClassDB::bind_method(D_METHOD("stop"), &Tween::stop);
+ ClassDB::bind_method(D_METHOD("pause"), &Tween::pause);
+ ClassDB::bind_method(D_METHOD("play"), &Tween::play);
+ ClassDB::bind_method(D_METHOD("kill"), &Tween::kill);
+
+ ClassDB::bind_method(D_METHOD("is_running"), &Tween::is_running);
+ ClassDB::bind_method(D_METHOD("is_valid"), &Tween::is_valid);
+ ClassDB::bind_method(D_METHOD("bind_node", "node"), &Tween::bind_node);
+ ClassDB::bind_method(D_METHOD("set_process_mode", "mode"), &Tween::set_process_mode);
+ ClassDB::bind_method(D_METHOD("set_pause_mode", "mode"), &Tween::set_pause_mode);
+
+ ClassDB::bind_method(D_METHOD("set_parallel", "parallel"), &Tween::set_parallel, DEFVAL(true));
+ ClassDB::bind_method(D_METHOD("set_loops", "loops"), &Tween::set_loops, DEFVAL(0));
+ ClassDB::bind_method(D_METHOD("set_speed_scale", "speed"), &Tween::set_speed_scale);
+ ClassDB::bind_method(D_METHOD("set_trans", "trans"), &Tween::set_trans);
+ ClassDB::bind_method(D_METHOD("set_ease", "ease"), &Tween::set_ease);
- // Validate and apply interpolation data
+ ClassDB::bind_method(D_METHOD("parallel"), &Tween::parallel);
+ ClassDB::bind_method(D_METHOD("chain"), &Tween::chain);
- // Give it the object
- ERR_FAIL_COND_MSG(p_object == nullptr, "Invalid object provided to Tween.");
- data.id = p_object->get_instance_id();
+ ClassDB::bind_method(D_METHOD("interpolate_value", "trans_type", "ease_type", "elapsed_time", "initial_value", "delta_value", "duration"), &Tween::interpolate_variant);
- // Validate the initial and final values
- ERR_FAIL_COND_MSG(p_initial_val.get_type() != p_final_val.get_type(), "Initial value type '" + Variant::get_type_name(p_initial_val.get_type()) + "' does not match final value type '" + Variant::get_type_name(p_final_val.get_type()) + "'.");
- data.initial_val = p_initial_val;
- data.final_val = p_final_val;
+ ADD_SIGNAL(MethodInfo("step_finished", PropertyInfo(Variant::INT, "idx")));
+ ADD_SIGNAL(MethodInfo("loop_finished", PropertyInfo(Variant::INT, "loop_count")));
+ ADD_SIGNAL(MethodInfo("finished"));
- // Check the Duration
- ERR_FAIL_COND_MSG(p_duration < 0, "Only non-negative duration values allowed in Tweens.");
- data.duration = p_duration;
+ BIND_ENUM_CONSTANT(TWEEN_PROCESS_PHYSICS);
+ BIND_ENUM_CONSTANT(TWEEN_PROCESS_IDLE);
- // Tween Delay
- ERR_FAIL_COND_MSG(p_delay < 0, "Only non-negative delay values allowed in Tweens.");
- data.delay = p_delay;
+ BIND_ENUM_CONSTANT(TWEEN_PAUSE_BOUND);
+ BIND_ENUM_CONSTANT(TWEEN_PAUSE_STOP);
+ BIND_ENUM_CONSTANT(TWEEN_PAUSE_PROCESS);
- // Transition type
- ERR_FAIL_COND_MSG(p_trans_type < 0 || p_trans_type >= TRANS_COUNT, "Invalid transition type provided to Tween.");
- data.trans_type = p_trans_type;
+ BIND_ENUM_CONSTANT(TRANS_LINEAR);
+ BIND_ENUM_CONSTANT(TRANS_SINE);
+ BIND_ENUM_CONSTANT(TRANS_QUINT);
+ BIND_ENUM_CONSTANT(TRANS_QUART);
+ BIND_ENUM_CONSTANT(TRANS_QUAD);
+ BIND_ENUM_CONSTANT(TRANS_EXPO);
+ BIND_ENUM_CONSTANT(TRANS_ELASTIC);
+ BIND_ENUM_CONSTANT(TRANS_CUBIC);
+ BIND_ENUM_CONSTANT(TRANS_CIRC);
+ BIND_ENUM_CONSTANT(TRANS_BOUNCE);
+ BIND_ENUM_CONSTANT(TRANS_BACK);
- // Easing type
- ERR_FAIL_COND_MSG(p_ease_type < 0 || p_ease_type >= EASE_COUNT, "Invalid easing type provided to Tween.");
- data.ease_type = p_ease_type;
+ BIND_ENUM_CONSTANT(EASE_IN);
+ BIND_ENUM_CONSTANT(EASE_OUT);
+ BIND_ENUM_CONSTANT(EASE_IN_OUT);
+ BIND_ENUM_CONSTANT(EASE_OUT_IN);
+}
- // Is the property defined?
- if (p_property) {
- // Check that the object actually contains the given property
- bool prop_valid = false;
- p_object->get_indexed(p_property->get_subnames(), &prop_valid);
- ERR_FAIL_COND_MSG(!prop_valid, "Tween target object has no property named: " + p_property->get_concatenated_subnames() + ".");
+Ref<PropertyTweener> PropertyTweener::from(Variant p_value) {
+ initial_val = p_value;
+ do_continue = false;
+ return this;
+}
- data.key = p_property->get_subnames();
- data.concatenated_key = p_property->get_concatenated_subnames();
- }
+Ref<PropertyTweener> PropertyTweener::from_current() {
+ do_continue = false;
+ return this;
+}
- // Is the method defined?
- if (p_method) {
- // Does the object even have the requested method?
- ERR_FAIL_COND_MSG(!p_object->has_method(*p_method), "Tween target object has no method named: " + *p_method + ".");
+Ref<PropertyTweener> PropertyTweener::as_relative() {
+ relative = true;
+ return this;
+}
- data.key.push_back(*p_method);
- data.concatenated_key = *p_method;
- }
+Ref<PropertyTweener> PropertyTweener::set_trans(Tween::TransitionType p_trans) {
+ trans_type = p_trans;
+ return this;
+}
- // Is there not a valid delta?
- if (!_calc_delta_val(data.initial_val, data.final_val, data.delta_val)) {
- return;
- }
+Ref<PropertyTweener> PropertyTweener::set_ease(Tween::EaseType p_ease) {
+ ease_type = p_ease;
+ return this;
+}
- // Add this interpolation to the total
- _push_interpolate_data(data);
+Ref<PropertyTweener> PropertyTweener::set_delay(float p_delay) {
+ delay = p_delay;
+ return this;
}
-void Tween::interpolate_property(Object *p_object, NodePath p_property, Variant p_initial_val, Variant p_final_val, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay) {
- // If we are busy updating, call this function again later
- if (pending_update != 0) {
- _add_pending_command("interpolate_property", p_object, p_property, p_initial_val, p_final_val, p_duration, p_trans_type, p_ease_type, p_delay);
+void PropertyTweener::start() {
+ elapsed_time = 0;
+ finished = false;
+
+ Object *target_instance = ObjectDB::get_instance(target);
+ if (!target_instance) {
+ WARN_PRINT("Target object freed before starting, aborting Tweener.");
return;
}
- // Check that the target object is valid
- ERR_FAIL_COND_MSG(p_object == nullptr, vformat("The Tween \"%s\"'s target node is `null`. Is the node reference correct?", get_name()));
-
- // Get the property from the node path
- p_property = p_property.get_as_property_path();
-
- // If no initial value given, grab the initial value from the object
- // TODO: Is this documented? This is very useful and removes a lot of clutter from tweens!
- if (p_initial_val.get_type() == Variant::NIL) {
- p_initial_val = p_object->get_indexed(p_property.get_subnames());
+ if (do_continue) {
+ initial_val = target_instance->get_indexed(property);
}
- // Convert any integers into REALs as they are better for interpolation
- if (p_initial_val.get_type() == Variant::INT) {
- p_initial_val = p_initial_val.operator real_t();
- }
- if (p_final_val.get_type() == Variant::INT) {
- p_final_val = p_final_val.operator real_t();
+ if (relative) {
+ final_val = Variant::evaluate(Variant::Operator::OP_ADD, initial_val, base_final_val);
}
- // Build the interpolation data
- _build_interpolation(INTER_PROPERTY, p_object, &p_property, nullptr, p_initial_val, p_final_val, p_duration, p_trans_type, p_ease_type, p_delay);
+ delta_val = tween->calculate_delta_value(initial_val, final_val);
}
-void Tween::interpolate_method(Object *p_object, StringName p_method, Variant p_initial_val, Variant p_final_val, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay) {
- // If we are busy updating, call this function again later
- if (pending_update != 0) {
- _add_pending_command("interpolate_method", p_object, p_method, p_initial_val, p_final_val, p_duration, p_trans_type, p_ease_type, p_delay);
- return;
+bool PropertyTweener::step(float &r_delta) {
+ if (finished) {
+ // This is needed in case there's a parallel Tweener with longer duration.
+ return false;
}
- // Check that the target object is valid
- ERR_FAIL_COND_MSG(p_object == nullptr, vformat("The Tween \"%s\"'s target node is `null`. Is the node reference correct?", get_name()));
-
- // Convert any integers into REALs as they are better for interpolation
- if (p_initial_val.get_type() == Variant::INT) {
- p_initial_val = p_initial_val.operator real_t();
- }
- if (p_final_val.get_type() == Variant::INT) {
- p_final_val = p_final_val.operator real_t();
+ Object *target_instance = ObjectDB::get_instance(target);
+ if (!target_instance) {
+ return false;
}
+ elapsed_time += r_delta;
- // Build the interpolation data
- _build_interpolation(INTER_METHOD, p_object, nullptr, &p_method, p_initial_val, p_final_val, p_duration, p_trans_type, p_ease_type, p_delay);
-}
-
-void Tween::interpolate_callback(Object *p_object, real_t p_duration, String p_callback, VARIANT_ARG_DECLARE) {
- // If we are already updating, call this function again later
- if (pending_update != 0) {
- _add_pending_command("interpolate_callback", p_object, p_duration, p_callback, p_arg1, p_arg2, p_arg3, p_arg4, p_arg5);
- return;
+ if (elapsed_time < delay) {
+ r_delta = 0;
+ return true;
}
- // Check that the target object is valid
- ERR_FAIL_COND(p_object == nullptr);
-
- // Duration cannot be negative
- ERR_FAIL_COND(p_duration < 0);
-
- // Check whether the object even has the callback
- ERR_FAIL_COND_MSG(!p_object->has_method(p_callback), "Object has no callback named: " + p_callback + ".");
-
- // Build a new InterpolationData
- InterpolateData data;
- data.active = true;
- data.type = INTER_CALLBACK;
- data.finish = false;
- data.call_deferred = false;
- data.elapsed = 0;
-
- // Give the data it's configuration
- data.id = p_object->get_instance_id();
- data.key.push_back(p_callback);
- data.concatenated_key = p_callback;
- data.duration = p_duration;
- data.delay = 0;
-
- // Add arguments to the interpolation
- int args = 0;
- if (p_arg5.get_type() != Variant::NIL) {
- args = 5;
- } else if (p_arg4.get_type() != Variant::NIL) {
- args = 4;
- } else if (p_arg3.get_type() != Variant::NIL) {
- args = 3;
- } else if (p_arg2.get_type() != Variant::NIL) {
- args = 2;
- } else if (p_arg1.get_type() != Variant::NIL) {
- args = 1;
+ float time = MIN(elapsed_time - delay, duration);
+ target_instance->set_indexed(property, tween->interpolate_variant(initial_val, delta_val, time, duration, trans_type, ease_type));
+
+ if (time < duration) {
+ r_delta = 0;
+ return true;
} else {
- args = 0;
+ finished = true;
+ r_delta = elapsed_time - delay - duration;
+ emit_signal("finished");
+ return false;
}
-
- data.args = args;
- data.arg[0] = p_arg1;
- data.arg[1] = p_arg2;
- data.arg[2] = p_arg3;
- data.arg[3] = p_arg4;
- data.arg[4] = p_arg5;
-
- // Add the new interpolation
- _push_interpolate_data(data);
}
-void Tween::interpolate_deferred_callback(Object *p_object, real_t p_duration, String p_callback, VARIANT_ARG_DECLARE) {
- // If we are already updating, call this function again later
- if (pending_update != 0) {
- _add_pending_command("interpolate_deferred_callback", p_object, p_duration, p_callback, p_arg1, p_arg2, p_arg3, p_arg4, p_arg5);
- return;
+void PropertyTweener::set_tween(Ref<Tween> p_tween) {
+ tween = p_tween;
+ if (trans_type == Tween::TRANS_MAX) {
+ trans_type = tween->get_trans();
}
-
- // Check that the target object is valid
- ERR_FAIL_COND(p_object == nullptr);
-
- // No negative durations allowed
- ERR_FAIL_COND(p_duration < 0);
-
- // Confirm the callback exists on the object
- ERR_FAIL_COND_MSG(!p_object->has_method(p_callback), "Object has no callback named: " + p_callback + ".");
-
- // Create a new InterpolateData for the callback
- InterpolateData data;
- data.active = true;
- data.type = INTER_CALLBACK;
- data.finish = false;
- data.call_deferred = true;
- data.elapsed = 0;
-
- // Give the data it's configuration
- data.id = p_object->get_instance_id();
- data.key.push_back(p_callback);
- data.concatenated_key = p_callback;
- data.duration = p_duration;
- data.delay = 0;
-
- // Collect arguments for the callback
- int args = 0;
- if (p_arg5.get_type() != Variant::NIL) {
- args = 5;
- } else if (p_arg4.get_type() != Variant::NIL) {
- args = 4;
- } else if (p_arg3.get_type() != Variant::NIL) {
- args = 3;
- } else if (p_arg2.get_type() != Variant::NIL) {
- args = 2;
- } else if (p_arg1.get_type() != Variant::NIL) {
- args = 1;
- } else {
- args = 0;
+ if (ease_type == Tween::EASE_MAX) {
+ ease_type = tween->get_ease();
}
+}
- data.args = args;
- data.arg[0] = p_arg1;
- data.arg[1] = p_arg2;
- data.arg[2] = p_arg3;
- data.arg[3] = p_arg4;
- data.arg[4] = p_arg5;
+void PropertyTweener::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("from", "value"), &PropertyTweener::from);
+ ClassDB::bind_method(D_METHOD("from_current"), &PropertyTweener::from_current);
+ ClassDB::bind_method(D_METHOD("as_relative"), &PropertyTweener::as_relative);
+ ClassDB::bind_method(D_METHOD("set_trans", "trans"), &PropertyTweener::set_trans);
+ ClassDB::bind_method(D_METHOD("set_ease", "ease"), &PropertyTweener::set_ease);
+ ClassDB::bind_method(D_METHOD("set_delay", "delay"), &PropertyTweener::set_delay);
+}
- // Add the new interpolation
- _push_interpolate_data(data);
+PropertyTweener::PropertyTweener(Object *p_target, NodePath p_property, Variant p_to, float p_duration) {
+ target = p_target->get_instance_id();
+ property = p_property.get_as_property_path().get_subnames();
+ initial_val = p_target->get_indexed(property);
+ base_final_val = p_to;
+ final_val = base_final_val;
+ duration = p_duration;
}
-void Tween::follow_property(Object *p_object, NodePath p_property, Variant p_initial_val, Object *p_target, NodePath p_target_property, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay) {
- // If we are already updating, call this function again later
- if (pending_update != 0) {
- _add_pending_command("follow_property", p_object, p_property, p_initial_val, p_target, p_target_property, p_duration, p_trans_type, p_ease_type, p_delay);
- return;
- }
+PropertyTweener::PropertyTweener() {
+ ERR_FAIL_MSG("Can't create empty PropertyTweener. Use get_tree().tween_property() or tween_property() instead.");
+}
- // Get the two properties from their paths
- p_property = p_property.get_as_property_path();
- p_target_property = p_target_property.get_as_property_path();
+void IntervalTweener::start() {
+ elapsed_time = 0;
+ finished = false;
+}
- // If no initial value is given, grab it from the source object
- // TODO: Is this documented? It's really helpful for decluttering tweens
- if (p_initial_val.get_type() == Variant::NIL) {
- p_initial_val = p_object->get_indexed(p_property.get_subnames());
+bool IntervalTweener::step(float &r_delta) {
+ if (finished) {
+ return false;
}
- // Convert initial INT values to FLOAT as they are better for interpolation
- if (p_initial_val.get_type() == Variant::INT) {
- p_initial_val = p_initial_val.operator real_t();
+ elapsed_time += r_delta;
+
+ if (elapsed_time < duration) {
+ r_delta = 0;
+ return true;
+ } else {
+ finished = true;
+ r_delta = elapsed_time - duration;
+ emit_signal("finished");
+ return false;
}
+}
- // Confirm the source and target objects are valid
- ERR_FAIL_COND(p_object == nullptr);
- ERR_FAIL_COND(p_target == nullptr);
+IntervalTweener::IntervalTweener(float p_time) {
+ duration = p_time;
+}
- // No negative durations
- ERR_FAIL_COND(p_duration < 0);
+IntervalTweener::IntervalTweener() {
+ ERR_FAIL_MSG("Can't create empty IntervalTweener. Use get_tree().tween_interval() instead.");
+}
- // Ensure transition and easing types are valid
- ERR_FAIL_COND(p_trans_type < 0 || p_trans_type >= TRANS_COUNT);
- ERR_FAIL_COND(p_ease_type < 0 || p_ease_type >= EASE_COUNT);
+Ref<CallbackTweener> CallbackTweener::set_delay(float p_delay) {
+ delay = p_delay;
+ return this;
+}
- // No negative delays
- ERR_FAIL_COND(p_delay < 0);
+void CallbackTweener::start() {
+ elapsed_time = 0;
+ finished = false;
+}
- // Confirm the source and target objects have the desired properties
- bool prop_valid = false;
- p_object->get_indexed(p_property.get_subnames(), &prop_valid);
- ERR_FAIL_COND(!prop_valid);
+bool CallbackTweener::step(float &r_delta) {
+ if (finished) {
+ return false;
+ }
- bool target_prop_valid = false;
- Variant target_val = p_target->get_indexed(p_target_property.get_subnames(), &target_prop_valid);
- ERR_FAIL_COND(!target_prop_valid);
+ elapsed_time += r_delta;
+ if (elapsed_time >= delay) {
+ Variant result;
+ Callable::CallError ce;
+ callback.call(nullptr, 0, result, ce);
+ if (ce.error != Callable::CallError::CALL_OK) {
+ ERR_FAIL_V_MSG(false, "Error calling method from CallbackTweener: " + Variant::get_call_error_text(this, callback.get_method(), nullptr, 0, ce));
+ }
- // Convert target INT to FLOAT since it is better for interpolation
- if (target_val.get_type() == Variant::INT) {
- target_val = target_val.operator real_t();
+ finished = true;
+ r_delta = elapsed_time - delay;
+ emit_signal("finished");
+ return false;
}
- // Verify that the target value and initial value are the same type
- ERR_FAIL_COND(target_val.get_type() != p_initial_val.get_type());
-
- // Create a new InterpolateData
- InterpolateData data;
- data.active = true;
- data.type = FOLLOW_PROPERTY;
- data.finish = false;
- data.elapsed = 0;
-
- // Give the InterpolateData it's configuration
- data.id = p_object->get_instance_id();
- data.key = p_property.get_subnames();
- data.concatenated_key = p_property.get_concatenated_subnames();
- data.initial_val = p_initial_val;
- data.target_id = p_target->get_instance_id();
- data.target_key = p_target_property.get_subnames();
- data.duration = p_duration;
- data.trans_type = p_trans_type;
- data.ease_type = p_ease_type;
- data.delay = p_delay;
-
- // Add the interpolation
- _push_interpolate_data(data);
-}
-
-void Tween::follow_method(Object *p_object, StringName p_method, Variant p_initial_val, Object *p_target, StringName p_target_method, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay) {
- // If we are currently updating, call this function again later
- if (pending_update != 0) {
- _add_pending_command("follow_method", p_object, p_method, p_initial_val, p_target, p_target_method, p_duration, p_trans_type, p_ease_type, p_delay);
- return;
- }
- // Convert initial INT values to FLOAT as they are better for interpolation
- if (p_initial_val.get_type() == Variant::INT) {
- p_initial_val = p_initial_val.operator real_t();
- }
+ r_delta = 0;
+ return true;
+}
- // Verify the source and target objects are valid
- ERR_FAIL_COND(p_object == nullptr);
- ERR_FAIL_COND(p_target == nullptr);
+void CallbackTweener::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("set_delay", "delay"), &CallbackTweener::set_delay);
+}
- // No negative durations
- ERR_FAIL_COND(p_duration < 0);
+CallbackTweener::CallbackTweener(Callable p_callback) {
+ callback = p_callback;
+}
- // Ensure that the transition and ease types are valid
- ERR_FAIL_COND(p_trans_type < 0 || p_trans_type >= TRANS_COUNT);
- ERR_FAIL_COND(p_ease_type < 0 || p_ease_type >= EASE_COUNT);
+CallbackTweener::CallbackTweener() {
+ ERR_FAIL_MSG("Can't create empty CallbackTweener. Use get_tree().tween_callback() instead.");
+}
- // No negative delays
- ERR_FAIL_COND(p_delay < 0);
+Ref<MethodTweener> MethodTweener::set_delay(float p_delay) {
+ delay = p_delay;
+ return this;
+}
- // Confirm both objects have the target methods
- ERR_FAIL_COND_MSG(!p_object->has_method(p_method), "Object has no method named: " + p_method + ".");
- ERR_FAIL_COND_MSG(!p_target->has_method(p_target_method), "Target has no method named: " + p_target_method + ".");
+Ref<MethodTweener> MethodTweener::set_trans(Tween::TransitionType p_trans) {
+ trans_type = p_trans;
+ return this;
+}
- // Call the method to get the target value
- Callable::CallError error;
- Variant target_val = p_target->call(p_target_method, nullptr, 0, error);
- ERR_FAIL_COND(error.error != Callable::CallError::CALL_OK);
+Ref<MethodTweener> MethodTweener::set_ease(Tween::EaseType p_ease) {
+ ease_type = p_ease;
+ return this;
+}
- // Convert target INT values to FLOAT as they are better for interpolation
- if (target_val.get_type() == Variant::INT) {
- target_val = target_val.operator real_t();
- }
- ERR_FAIL_COND(target_val.get_type() != p_initial_val.get_type());
-
- // Make the new InterpolateData for the method follow
- InterpolateData data;
- data.active = true;
- data.type = FOLLOW_METHOD;
- data.finish = false;
- data.elapsed = 0;
-
- // Give the data it's configuration
- data.id = p_object->get_instance_id();
- data.key.push_back(p_method);
- data.concatenated_key = p_method;
- data.initial_val = p_initial_val;
- data.target_id = p_target->get_instance_id();
- data.target_key.push_back(p_target_method);
- data.duration = p_duration;
- data.trans_type = p_trans_type;
- data.ease_type = p_ease_type;
- data.delay = p_delay;
-
- // Add the new interpolation
- _push_interpolate_data(data);
-}
-
-void Tween::targeting_property(Object *p_object, NodePath p_property, Object *p_initial, NodePath p_initial_property, Variant p_final_val, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay) {
- // If we are currently updating, call this function again later
- if (pending_update != 0) {
- _add_pending_command("targeting_property", p_object, p_property, p_initial, p_initial_property, p_final_val, p_duration, p_trans_type, p_ease_type, p_delay);
- return;
- }
- // Grab the target property and the target property
- p_property = p_property.get_as_property_path();
- p_initial_property = p_initial_property.get_as_property_path();
+void MethodTweener::start() {
+ elapsed_time = 0;
+ finished = false;
+}
- // Convert the initial INT values to FLOAT as they are better for Interpolation
- if (p_final_val.get_type() == Variant::INT) {
- p_final_val = p_final_val.operator real_t();
+bool MethodTweener::step(float &r_delta) {
+ if (finished) {
+ return false;
}
- // Verify both objects are valid
- ERR_FAIL_COND(p_object == nullptr);
- ERR_FAIL_COND(p_initial == nullptr);
-
- // No negative durations
- ERR_FAIL_COND(p_duration < 0);
-
- // Ensure transition and easing types are valid
- ERR_FAIL_COND(p_trans_type < 0 || p_trans_type >= TRANS_COUNT);
- ERR_FAIL_COND(p_ease_type < 0 || p_ease_type >= EASE_COUNT);
-
- // No negative delays
- ERR_FAIL_COND(p_delay < 0);
-
- // Ensure the initial and target properties exist on their objects
- bool prop_valid = false;
- p_object->get_indexed(p_property.get_subnames(), &prop_valid);
- ERR_FAIL_COND(!prop_valid);
+ elapsed_time += r_delta;
- bool initial_prop_valid = false;
- Variant initial_val = p_initial->get_indexed(p_initial_property.get_subnames(), &initial_prop_valid);
- ERR_FAIL_COND(!initial_prop_valid);
-
- // Convert the initial INT value to FLOAT as it is better for interpolation
- if (initial_val.get_type() == Variant::INT) {
- initial_val = initial_val.operator real_t();
- }
- ERR_FAIL_COND(initial_val.get_type() != p_final_val.get_type());
-
- // Build the InterpolateData object
- InterpolateData data;
- data.active = true;
- data.type = TARGETING_PROPERTY;
- data.finish = false;
- data.elapsed = 0;
-
- // Give the data it's configuration
- data.id = p_object->get_instance_id();
- data.key = p_property.get_subnames();
- data.concatenated_key = p_property.get_concatenated_subnames();
- data.target_id = p_initial->get_instance_id();
- data.target_key = p_initial_property.get_subnames();
- data.initial_val = initial_val;
- data.final_val = p_final_val;
- data.duration = p_duration;
- data.trans_type = p_trans_type;
- data.ease_type = p_ease_type;
- data.delay = p_delay;
-
- // Ensure there is a valid delta
- if (!_calc_delta_val(data.initial_val, data.final_val, data.delta_val)) {
- return;
+ if (elapsed_time < delay) {
+ r_delta = 0;
+ return true;
}
- // Add the interpolation
- _push_interpolate_data(data);
-}
+ float time = MIN(elapsed_time - delay, duration);
+ Variant current_val = tween->interpolate_variant(initial_val, delta_val, time, duration, trans_type, ease_type);
+ const Variant **argptr = (const Variant **)alloca(sizeof(Variant *));
+ argptr[0] = &current_val;
-void Tween::targeting_method(Object *p_object, StringName p_method, Object *p_initial, StringName p_initial_method, Variant p_final_val, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay) {
- // If we are currently updating, call this function again later
- if (pending_update != 0) {
- _add_pending_command("targeting_method", p_object, p_method, p_initial, p_initial_method, p_final_val, p_duration, p_trans_type, p_ease_type, p_delay);
- return;
+ Variant result;
+ Callable::CallError ce;
+ callback.call(argptr, 1, result, ce);
+ if (ce.error != Callable::CallError::CALL_OK) {
+ ERR_FAIL_V_MSG(false, "Error calling method from MethodTweener: " + Variant::get_call_error_text(this, callback.get_method(), argptr, 1, ce));
}
- // Convert final INT values to FLOAT as they are better for interpolation
- if (p_final_val.get_type() == Variant::INT) {
- p_final_val = p_final_val.operator real_t();
+ if (time < duration) {
+ r_delta = 0;
+ return true;
+ } else {
+ finished = true;
+ r_delta = elapsed_time - delay - duration;
+ emit_signal("finished");
+ return false;
}
+}
- // Make sure the given objects are valid
- ERR_FAIL_COND(p_object == nullptr);
- ERR_FAIL_COND(p_initial == nullptr);
-
- // No negative durations
- ERR_FAIL_COND(p_duration < 0);
-
- // Ensure transition and easing types are valid
- ERR_FAIL_COND(p_trans_type < 0 || p_trans_type >= TRANS_COUNT);
- ERR_FAIL_COND(p_ease_type < 0 || p_ease_type >= EASE_COUNT);
-
- // No negative delays
- ERR_FAIL_COND(p_delay < 0);
-
- // Make sure both objects have the given method
- ERR_FAIL_COND_MSG(!p_object->has_method(p_method), "Object has no method named: " + p_method + ".");
- ERR_FAIL_COND_MSG(!p_initial->has_method(p_initial_method), "Initial Object has no method named: " + p_initial_method + ".");
-
- // Call the method to get the initial value
- Callable::CallError error;
- Variant initial_val = p_initial->call(p_initial_method, nullptr, 0, error);
- ERR_FAIL_COND(error.error != Callable::CallError::CALL_OK);
-
- // Convert initial INT values to FLOAT as they aer better for interpolation
- if (initial_val.get_type() == Variant::INT) {
- initial_val = initial_val.operator real_t();
+void MethodTweener::set_tween(Ref<Tween> p_tween) {
+ tween = p_tween;
+ if (trans_type == Tween::TRANS_MAX) {
+ trans_type = tween->get_trans();
}
- ERR_FAIL_COND(initial_val.get_type() != p_final_val.get_type());
-
- // Build the new InterpolateData object
- InterpolateData data;
- data.active = true;
- data.type = TARGETING_METHOD;
- data.finish = false;
- data.elapsed = 0;
-
- // Configure the data
- data.id = p_object->get_instance_id();
- data.key.push_back(p_method);
- data.concatenated_key = p_method;
- data.target_id = p_initial->get_instance_id();
- data.target_key.push_back(p_initial_method);
- data.initial_val = initial_val;
- data.final_val = p_final_val;
- data.duration = p_duration;
- data.trans_type = p_trans_type;
- data.ease_type = p_ease_type;
- data.delay = p_delay;
-
- // Ensure there is a valid delta
- if (!_calc_delta_val(data.initial_val, data.final_val, data.delta_val)) {
- return;
+ if (ease_type == Tween::EASE_MAX) {
+ ease_type = tween->get_ease();
}
+}
- // Add the interpolation
- _push_interpolate_data(data);
+void MethodTweener::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("set_delay", "delay"), &MethodTweener::set_delay);
+ ClassDB::bind_method(D_METHOD("set_trans", "trans"), &MethodTweener::set_trans);
+ ClassDB::bind_method(D_METHOD("set_ease", "ease"), &MethodTweener::set_ease);
}
-Tween::Tween() {
+MethodTweener::MethodTweener(Callable p_callback, float p_from, float p_to, float p_duration) {
+ callback = p_callback;
+ initial_val = p_from;
+ delta_val = tween->calculate_delta_value(p_from, p_to);
+ duration = p_duration;
}
-Tween::~Tween() {
+MethodTweener::MethodTweener() {
+ ERR_FAIL_MSG("Can't create empty MethodTweener. Use get_tree().tween_method() instead.");
}
diff --git a/scene/animation/tween.h b/scene/animation/tween.h
index 142c0c65e0..947cdb7c2d 100644
--- a/scene/animation/tween.h
+++ b/scene/animation/tween.h
@@ -31,10 +31,33 @@
#ifndef TWEEN_H
#define TWEEN_H
-#include "scene/main/node.h"
+#include "core/object/ref_counted.h"
-class Tween : public Node {
- GDCLASS(Tween, Node);
+class Tween;
+class Node;
+
+class Tweener : public RefCounted {
+ GDCLASS(Tweener, RefCounted);
+
+public:
+ virtual void set_tween(Ref<Tween> p_tween);
+ virtual void start() = 0;
+ virtual bool step(float &r_delta) = 0;
+
+protected:
+ static void _bind_methods();
+ Ref<Tween> tween;
+ float elapsed_time = 0;
+ bool finished = false;
+};
+
+class PropertyTweener;
+class IntervalTweener;
+class CallbackTweener;
+class MethodTweener;
+
+class Tween : public RefCounted {
+ GDCLASS(Tween, RefCounted);
public:
enum TweenProcessMode {
@@ -42,6 +65,12 @@ public:
TWEEN_PROCESS_IDLE,
};
+ enum TweenPauseMode {
+ TWEEN_PAUSE_BOUND,
+ TWEEN_PAUSE_STOP,
+ TWEEN_PAUSE_PROCESS,
+ };
+
enum TransitionType {
TRANS_LINEAR,
TRANS_SINE,
@@ -54,8 +83,7 @@ public:
TRANS_CIRC,
TRANS_BOUNCE,
TRANS_BACK,
-
- TRANS_COUNT,
+ TRANS_MAX
};
enum EaseType {
@@ -63,130 +91,187 @@ public:
EASE_OUT,
EASE_IN_OUT,
EASE_OUT_IN,
-
- EASE_COUNT,
+ EASE_MAX
};
private:
- enum InterpolateType {
- INTER_PROPERTY,
- INTER_METHOD,
- FOLLOW_PROPERTY,
- FOLLOW_METHOD,
- TARGETING_PROPERTY,
- TARGETING_METHOD,
- INTER_CALLBACK,
- };
+ TweenProcessMode process_mode = TweenProcessMode::TWEEN_PROCESS_IDLE;
+ TweenPauseMode pause_mode = TweenPauseMode::TWEEN_PAUSE_STOP;
+ TransitionType default_transition = TransitionType::TRANS_LINEAR;
+ EaseType default_ease = EaseType::EASE_IN_OUT;
+ ObjectID bound_node;
- struct InterpolateData {
- bool active = false;
- InterpolateType type = INTER_CALLBACK;
- bool finish = false;
- bool call_deferred = false;
- real_t elapsed = 0.0;
- ObjectID id;
- Vector<StringName> key;
- StringName concatenated_key;
- Variant initial_val;
- Variant delta_val;
- Variant final_val;
- ObjectID target_id;
- Vector<StringName> target_key;
- real_t duration = 0.0;
- TransitionType trans_type = TransitionType::TRANS_BACK;
- EaseType ease_type = EaseType::EASE_COUNT;
- real_t delay = 0.0;
- int args = 0;
- Variant arg[5];
- int uid = 0;
- };
+ Vector<List<Ref<Tweener>>> tweeners;
+ int current_step = -1;
+ int loops = 1;
+ int loops_done = 0;
+ float speed_scale = 1;
- String autoplay;
- TweenProcessMode tween_process_mode = TWEEN_PROCESS_IDLE;
- bool repeat = false;
- float speed_scale = 1.0;
- mutable int pending_update = 0;
- int uid = 0;
- bool was_stopped = false;
+ bool is_bound = false;
+ bool started = false;
+ bool running = true;
+ bool dead = false;
+ bool invalid = true;
+ bool default_parallel = false;
+ bool parallel_enabled = false;
- List<InterpolateData> interpolates;
+ typedef real_t (*interpolater)(real_t t, real_t b, real_t c, real_t d);
+ static interpolater interpolaters[TRANS_MAX][EASE_MAX];
- struct PendingCommand {
- StringName key;
- int args = 0;
- Variant arg[10];
- };
- List<PendingCommand> pending_commands;
+ void start_tweeners();
- void _add_pending_command(StringName p_key, 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(), const Variant &p_arg9 = Variant(), const Variant &p_arg10 = Variant());
- void _process_pending_commands();
+protected:
+ static void _bind_methods();
- typedef real_t (*interpolater)(real_t t, real_t b, real_t c, real_t d);
- static interpolater interpolaters[TRANS_COUNT][EASE_COUNT];
+public:
+ Ref<PropertyTweener> tween_property(Object *p_target, NodePath p_property, Variant p_to, float p_duration);
+ Ref<IntervalTweener> tween_interval(float p_time);
+ Ref<CallbackTweener> tween_callback(Callable p_callback);
+ Ref<MethodTweener> tween_method(Callable p_callback, float p_from, float p_to, float p_duration);
+ Ref<Tween> append(Ref<Tweener> p_tweener);
- real_t _run_equation(TransitionType p_trans_type, EaseType p_ease_type, real_t t, real_t b, real_t c, real_t d);
- Variant &_get_delta_val(InterpolateData &p_data);
- Variant _get_initial_val(const InterpolateData &p_data) const;
- Variant _get_final_val(const InterpolateData &p_data) const;
- Variant _run_equation(InterpolateData &p_data);
- bool _calc_delta_val(const Variant &p_initial_val, const Variant &p_final_val, Variant &p_delta_val);
- bool _apply_tween_value(InterpolateData &p_data, Variant &value);
+ bool custom_step(float p_delta);
+ void stop();
+ void pause();
+ void play();
+ void kill();
- void _tween_process(float p_delta);
- void _remove_by_uid(int uid);
- void _push_interpolate_data(InterpolateData &p_data);
- void _build_interpolation(InterpolateType p_interpolation_type, Object *p_object, NodePath *p_property, StringName *p_method, Variant p_initial_val, Variant p_final_val, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay);
+ bool is_running();
+ void set_valid(bool p_valid);
+ bool is_valid();
-protected:
- bool _set(const StringName &p_name, const Variant &p_value);
- bool _get(const StringName &p_name, Variant &r_ret) const;
- void _get_property_list(List<PropertyInfo> *p_list) const;
- void _notification(int p_what);
+ Ref<Tween> bind_node(Node *p_node);
+ Ref<Tween> set_process_mode(TweenProcessMode p_mode);
+ TweenProcessMode get_process_mode();
+ Ref<Tween> set_pause_mode(TweenPauseMode p_mode);
+ TweenPauseMode get_pause_mode();
- static void _bind_methods();
+ Ref<Tween> set_parallel(bool p_parallel);
+ Ref<Tween> set_loops(int p_loops);
+ Ref<Tween> set_speed_scale(float p_speed);
+ Ref<Tween> set_trans(TransitionType p_trans);
+ TransitionType get_trans();
+ Ref<Tween> set_ease(EaseType p_ease);
+ EaseType get_ease();
-public:
- bool is_active() const;
- void set_active(bool p_active);
-
- bool is_repeat() const;
- void set_repeat(bool p_repeat);
-
- void set_tween_process_mode(TweenProcessMode p_mode);
- TweenProcessMode get_tween_process_mode() const;
-
- void set_speed_scale(float p_speed);
- float get_speed_scale() const;
-
- void start();
- void reset(Object *p_object, StringName p_key);
- void reset_all();
- void stop(Object *p_object, StringName p_key);
- void stop_all();
- void resume(Object *p_object, StringName p_key);
- void resume_all();
- void remove(Object *p_object, StringName p_key);
- void remove_all();
-
- void seek(real_t p_time);
- real_t tell() const;
- real_t get_runtime() const;
-
- void interpolate_property(Object *p_object, NodePath p_property, Variant p_initial_val, Variant p_final_val, real_t p_duration, TransitionType p_trans_type = TRANS_LINEAR, EaseType p_ease_type = EASE_IN_OUT, real_t p_delay = 0);
- void interpolate_method(Object *p_object, StringName p_method, Variant p_initial_val, Variant p_final_val, real_t p_duration, TransitionType p_trans_type = TRANS_LINEAR, EaseType p_ease_type = EASE_IN_OUT, real_t p_delay = 0);
- void interpolate_callback(Object *p_object, real_t p_duration, String p_callback, VARIANT_ARG_DECLARE);
- void interpolate_deferred_callback(Object *p_object, real_t p_duration, String p_callback, VARIANT_ARG_DECLARE);
- void follow_property(Object *p_object, NodePath p_property, Variant p_initial_val, Object *p_target, NodePath p_target_property, real_t p_duration, TransitionType p_trans_type = TRANS_LINEAR, EaseType p_ease_type = EASE_IN_OUT, real_t p_delay = 0);
- void follow_method(Object *p_object, StringName p_method, Variant p_initial_val, Object *p_target, StringName p_target_method, real_t p_duration, TransitionType p_trans_type = TRANS_LINEAR, EaseType p_ease_type = EASE_IN_OUT, real_t p_delay = 0);
- void targeting_property(Object *p_object, NodePath p_property, Object *p_initial, NodePath p_initial_property, Variant p_final_val, real_t p_duration, TransitionType p_trans_type = TRANS_LINEAR, EaseType p_ease_type = EASE_IN_OUT, real_t p_delay = 0);
- void targeting_method(Object *p_object, StringName p_method, Object *p_initial, StringName p_initial_method, Variant p_final_val, real_t p_duration, TransitionType p_trans_type = TRANS_LINEAR, EaseType p_ease_type = EASE_IN_OUT, real_t p_delay = 0);
-
- Tween();
- ~Tween();
+ Ref<Tween> parallel();
+ Ref<Tween> chain();
+
+ real_t run_equation(TransitionType p_trans_type, EaseType p_ease_type, real_t t, real_t b, real_t c, real_t d);
+ Variant interpolate_variant(Variant p_initial_val, Variant p_delta_val, float p_time, float p_duration, Tween::TransitionType p_trans, Tween::EaseType p_ease);
+ Variant calculate_delta_value(Variant p_intial_val, Variant p_final_val);
+
+ bool step(float p_delta);
+ bool should_pause();
+
+ Tween() {}
};
+VARIANT_ENUM_CAST(Tween::TweenPauseMode);
VARIANT_ENUM_CAST(Tween::TweenProcessMode);
VARIANT_ENUM_CAST(Tween::TransitionType);
VARIANT_ENUM_CAST(Tween::EaseType);
+class PropertyTweener : public Tweener {
+ GDCLASS(PropertyTweener, Tweener);
+
+public:
+ Ref<PropertyTweener> from(Variant p_value);
+ Ref<PropertyTweener> from_current();
+ Ref<PropertyTweener> as_relative();
+ Ref<PropertyTweener> set_trans(Tween::TransitionType p_trans);
+ Ref<PropertyTweener> set_ease(Tween::EaseType p_ease);
+ Ref<PropertyTweener> set_delay(float p_delay);
+
+ void set_tween(Ref<Tween> p_tween) override;
+ void start() override;
+ bool step(float &r_delta) override;
+
+ PropertyTweener(Object *p_target, NodePath p_property, Variant p_to, float p_duration);
+ PropertyTweener();
+
+protected:
+ static void _bind_methods();
+
+private:
+ ObjectID target;
+ Vector<StringName> property;
+ Variant initial_val;
+ Variant base_final_val;
+ Variant final_val;
+ Variant delta_val;
+
+ float duration = 0;
+ Tween::TransitionType trans_type = Tween::TRANS_MAX; // This is set inside set_tween();
+ Tween::EaseType ease_type = Tween::EASE_MAX;
+
+ float delay = 0;
+ bool do_continue = true;
+ bool relative = false;
+};
+
+class IntervalTweener : public Tweener {
+ GDCLASS(IntervalTweener, Tweener);
+
+public:
+ void start() override;
+ bool step(float &r_delta) override;
+
+ IntervalTweener(float p_time);
+ IntervalTweener();
+
+private:
+ float duration = 0;
+};
+
+class CallbackTweener : public Tweener {
+ GDCLASS(CallbackTweener, Tweener);
+
+public:
+ Ref<CallbackTweener> set_delay(float p_delay);
+
+ void start() override;
+ bool step(float &r_delta) override;
+
+ CallbackTweener(Callable p_callback);
+ CallbackTweener();
+
+protected:
+ static void _bind_methods();
+
+private:
+ Callable callback;
+ float delay = 0;
+};
+
+class MethodTweener : public Tweener {
+ GDCLASS(MethodTweener, Tweener);
+
+public:
+ Ref<MethodTweener> set_trans(Tween::TransitionType p_trans);
+ Ref<MethodTweener> set_ease(Tween::EaseType p_ease);
+ Ref<MethodTweener> set_delay(float p_delay);
+
+ void set_tween(Ref<Tween> p_tween) override;
+ void start() override;
+ bool step(float &r_delta) override;
+
+ MethodTweener(Callable p_callback, float p_from, float p_to, float p_duration);
+ MethodTweener();
+
+protected:
+ static void _bind_methods();
+
+private:
+ float duration = 0;
+ float delay = 0;
+ Tween::TransitionType trans_type = Tween::TRANS_MAX;
+ Tween::EaseType ease_type = Tween::EASE_MAX;
+
+ Ref<Tween> tween;
+ Variant initial_val;
+ Variant delta_val;
+ Callable callback;
+};
+
#endif
diff --git a/scene/debugger/scene_debugger.cpp b/scene/debugger/scene_debugger.cpp
index 11ce9b2ddc..1bf841be04 100644
--- a/scene/debugger/scene_debugger.cpp
+++ b/scene/debugger/scene_debugger.cpp
@@ -661,7 +661,7 @@ void LiveEditor::_create_node_func(const NodePath &p_parent, const String &p_typ
}
Node *n2 = n->get_node(p_parent);
- Node *no = Object::cast_to<Node>(ClassDB::instance(p_type));
+ Node *no = Object::cast_to<Node>(ClassDB::instantiate(p_type));
if (!no) {
continue;
}
@@ -705,7 +705,7 @@ void LiveEditor::_instance_node_func(const NodePath &p_parent, const String &p_p
}
Node *n2 = n->get_node(p_parent);
- Node *no = ps->instance();
+ Node *no = ps->instantiate();
if (!no) {
continue;
}
diff --git a/scene/gui/button.cpp b/scene/gui/button.cpp
index c0df5271b4..595d712eb8 100644
--- a/scene/gui/button.cpp
+++ b/scene/gui/button.cpp
@@ -543,7 +543,7 @@ void Button::_bind_methods() {
}
Button::Button(const String &p_text) {
- text_buf.instance();
+ text_buf.instantiate();
text_buf->set_flags(TextServer::BREAK_MANDATORY);
set_mouse_filter(MOUSE_FILTER_STOP);
diff --git a/scene/gui/code_edit.cpp b/scene/gui/code_edit.cpp
index 5b720945b8..ff7ea17008 100644
--- a/scene/gui/code_edit.cpp
+++ b/scene/gui/code_edit.cpp
@@ -122,7 +122,7 @@ void CodeEdit::_notification(int p_what) {
ERR_CONTINUE(l < 0 || l >= code_completion_options_count);
Ref<TextLine> tl;
- tl.instance();
+ tl.instantiate();
tl->add_string(code_completion_options[l].display, cache.font, cache.font_size);
int yofs = (row_height - tl->get_size().y) / 2;
@@ -248,6 +248,8 @@ void CodeEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
update();
} break;
+ default:
+ break;
}
return;
}
@@ -615,7 +617,7 @@ bool CodeEdit::is_line_numbers_zero_padded() const {
void CodeEdit::_line_number_draw_callback(int p_line, int p_gutter, const Rect2 &p_region) {
String fc = TS->format_number(String::num(p_line + 1).lpad(line_number_digits, line_number_padding));
Ref<TextLine> tl;
- tl.instance();
+ tl.instantiate();
tl->add_string(fc, cache.font, cache.font_size);
int yofs = p_region.position.y + (get_row_height() - tl->get_size().y) / 2;
Color number_color = get_line_gutter_item_color(p_line, line_number_gutter);
diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp
index f394b9e3a5..049de4c8c5 100644
--- a/scene/gui/color_picker.cpp
+++ b/scene/gui/color_picker.cpp
@@ -88,7 +88,7 @@ Ref<Shader> ColorPicker::wheel_shader;
Ref<Shader> ColorPicker::circle_shader;
void ColorPicker::init_shaders() {
- wheel_shader.instance();
+ wheel_shader.instantiate();
wheel_shader->set_code(
"shader_type canvas_item;"
"void fragment() {"
@@ -107,7 +107,7 @@ void ColorPicker::init_shaders() {
" COLOR = vec4(clamp((abs(fract(((a - TAU) / TAU) + vec3(3.0, 2.0, 1.0) / 3.0) * 6.0 - 3.0) - 1.0), 0.0, 1.0), (b + b2 + b3 + b4) / 4.00);"
"}");
- circle_shader.instance();
+ circle_shader.instantiate();
circle_shader->set_code(
"shader_type canvas_item;"
"uniform float v = 1.0;"
@@ -1213,9 +1213,9 @@ ColorPicker::ColorPicker() :
wheel_edit->set_custom_minimum_size(Size2(get_theme_constant("sv_width"), get_theme_constant("sv_height")));
hb_edit->add_child(wheel_edit);
- wheel_mat.instance();
+ wheel_mat.instantiate();
wheel_mat->set_shader(wheel_shader);
- circle_mat.instance();
+ circle_mat.instantiate();
circle_mat->set_shader(circle_shader);
MarginContainer *wheel_margin(memnew(MarginContainer));
diff --git a/scene/gui/graph_node.cpp b/scene/gui/graph_node.cpp
index 77c502cf8d..93f1fe9e8e 100644
--- a/scene/gui/graph_node.cpp
+++ b/scene/gui/graph_node.cpp
@@ -1021,6 +1021,6 @@ void GraphNode::_bind_methods() {
}
GraphNode::GraphNode() {
- title_buf.instance();
+ title_buf.instantiate();
set_mouse_filter(MOUSE_FILTER_STOP);
}
diff --git a/scene/gui/item_list.cpp b/scene/gui/item_list.cpp
index 150980b2e9..b0d54bf8c9 100644
--- a/scene/gui/item_list.cpp
+++ b/scene/gui/item_list.cpp
@@ -57,7 +57,7 @@ int ItemList::add_item(const String &p_item, const Ref<Texture2D> &p_texture, bo
item.icon_region = Rect2i();
item.icon_modulate = Color(1, 1, 1, 1);
item.text = p_item;
- item.text_buf.instance();
+ item.text_buf.instantiate();
item.selectable = p_selectable;
item.selected = false;
item.disabled = false;
@@ -80,7 +80,7 @@ int ItemList::add_icon_item(const Ref<Texture2D> &p_item, bool p_selectable) {
item.icon_region = Rect2i();
item.icon_modulate = Color(1, 1, 1, 1);
//item.text=p_item;
- item.text_buf.instance();
+ item.text_buf.instantiate();
item.selectable = p_selectable;
item.selected = false;
item.disabled = false;
diff --git a/scene/gui/link_button.cpp b/scene/gui/link_button.cpp
index d45ffde715..ee0618a991 100644
--- a/scene/gui/link_button.cpp
+++ b/scene/gui/link_button.cpp
@@ -301,7 +301,7 @@ void LinkButton::_bind_methods() {
}
LinkButton::LinkButton() {
- text_buf.instance();
+ text_buf.instantiate();
set_focus_mode(FOCUS_NONE);
set_default_cursor_shape(CURSOR_POINTING_HAND);
}
diff --git a/scene/gui/popup_menu.h b/scene/gui/popup_menu.h
index e4cbe984c9..74718395d3 100644
--- a/scene/gui/popup_menu.h
+++ b/scene/gui/popup_menu.h
@@ -80,8 +80,8 @@ class PopupMenu : public Popup {
}
Item() {
- text_buf.instance();
- accel_text_buf.instance();
+ text_buf.instantiate();
+ accel_text_buf.instantiate();
checkable_type = CHECKABLE_TYPE_NONE;
}
};
diff --git a/scene/gui/rich_text_label.h b/scene/gui/rich_text_label.h
index 9bcb9e93c9..999d8b05fd 100644
--- a/scene/gui/rich_text_label.h
+++ b/scene/gui/rich_text_label.h
@@ -102,7 +102,7 @@ private:
int char_offset = 0;
int char_count = 0;
- Line() { text_buf.instance(); }
+ Line() { text_buf.instantiate(); }
};
struct Item {
@@ -325,7 +325,7 @@ private:
ItemCustomFX() {
type = ITEM_CUSTOMFX;
- char_fx_transform.instance();
+ char_fx_transform.instantiate();
}
virtual ~ItemCustomFX() {
diff --git a/scene/gui/shortcut.cpp b/scene/gui/shortcut.cpp
index cbbcf9e069..962c6dcc60 100644
--- a/scene/gui/shortcut.cpp
+++ b/scene/gui/shortcut.cpp
@@ -42,7 +42,7 @@ Ref<InputEvent> Shortcut::get_shortcut() const {
}
bool Shortcut::is_shortcut(const Ref<InputEvent> &p_event) const {
- return shortcut.is_valid() && shortcut->shortcut_match(p_event);
+ return shortcut.is_valid() && shortcut->is_match(p_event, true);
}
String Shortcut::get_as_text() const {
diff --git a/scene/gui/spin_box.cpp b/scene/gui/spin_box.cpp
index 4ac73ae6b5..941dd30057 100644
--- a/scene/gui/spin_box.cpp
+++ b/scene/gui/spin_box.cpp
@@ -52,7 +52,7 @@ void SpinBox::_value_changed(double) {
void SpinBox::_text_submitted(const String &p_string) {
Ref<Expression> expr;
- expr.instance();
+ expr.instantiate();
String num = TS->parse_number(p_string);
// Ignore the prefix and suffix in the expression
@@ -140,6 +140,8 @@ void SpinBox::_gui_input(const Ref<InputEvent> &p_event) {
accept_event();
}
} break;
+ default:
+ break;
}
}
diff --git a/scene/gui/tab_container.cpp b/scene/gui/tab_container.cpp
index acf0641005..133966013b 100644
--- a/scene/gui/tab_container.cpp
+++ b/scene/gui/tab_container.cpp
@@ -586,7 +586,7 @@ void TabContainer::_refresh_texts() {
Control *control = Object::cast_to<Control>(tabs[i]);
String text = control->has_meta("_tab_name") ? String(tr(String(control->get_meta("_tab_name")))) : String(tr(control->get_name()));
Ref<TextLine> name;
- name.instance();
+ name.instantiate();
name->set_direction(rtl ? TextServer::DIRECTION_RTL : TextServer::DIRECTION_LTR);
name->add_string(text, font, font_size, Dictionary(), TranslationServer::get_singleton()->get_tool_locale());
text_buf.push_back(name);
diff --git a/scene/gui/tabs.cpp b/scene/gui/tabs.cpp
index 11096e7976..6f1cff9ec8 100644
--- a/scene/gui/tabs.cpp
+++ b/scene/gui/tabs.cpp
@@ -743,7 +743,7 @@ void Tabs::add_tab(const String &p_str, const Ref<Texture2D> &p_icon) {
Tab t;
t.text = p_str;
t.xl_text = tr(p_str);
- t.text_buf.instance();
+ t.text_buf.instantiate();
t.text_buf->set_direction(is_layout_rtl() ? TextServer::DIRECTION_RTL : TextServer::DIRECTION_LTR);
t.text_buf->add_string(t.xl_text, get_theme_font("font"), get_theme_font_size("font_size"), Dictionary(), TranslationServer::get_singleton()->get_tool_locale());
t.icon = p_icon;
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index 6f78d586f1..b504da2224 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -1114,7 +1114,7 @@ void TextEdit::_notification(int p_what) {
}
Ref<TextLine> tl;
- tl.instance();
+ tl.instantiate();
tl->add_string(text, cache.font, cache.font_size);
int yofs = ofs_y + (row_height - tl->get_size().y) / 2;
@@ -4625,14 +4625,6 @@ Color TextEdit::get_line_background_color(int p_line) {
return text.get_line_background_color(p_line);
}
-void TextEdit::add_keyword(const String &p_keyword) {
- keywords.insert(p_keyword);
-}
-
-void TextEdit::clear_keywords() {
- keywords.clear();
-}
-
void TextEdit::set_auto_indent(bool p_auto_indent) {
auto_indent = p_auto_indent;
}
diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h
index c04d758abb..27577c48d8 100644
--- a/scene/gui/text_edit.h
+++ b/scene/gui/text_edit.h
@@ -96,7 +96,7 @@ private:
bool hidden = false;
Line() {
- data_buf.instance();
+ data_buf.instantiate();
}
};
@@ -744,9 +744,6 @@ public:
void set_insert_mode(bool p_enabled);
bool is_insert_mode() const;
- void add_keyword(const String &p_keyword);
- void clear_keywords();
-
double get_v_scroll() const;
void set_v_scroll(double p_scroll);
diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp
index 26d881955b..b02b4edd8e 100644
--- a/scene/gui/tree.cpp
+++ b/scene/gui/tree.cpp
@@ -2092,7 +2092,7 @@ void Tree::_range_click_timeout() {
click_handled = false;
Ref<InputEventMouseButton> mb;
- mb.instance();
+ mb.instantiate();
propagate_mouse_activated = false; // done from outside, so signal handler can't clear the tree in the middle of emit (which is a common case)
blocked++;
@@ -3161,6 +3161,8 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
}
} break;
+ default:
+ break;
}
}
diff --git a/scene/gui/tree.h b/scene/gui/tree.h
index 0571a605a5..42dd27cb55 100644
--- a/scene/gui/tree.h
+++ b/scene/gui/tree.h
@@ -115,7 +115,7 @@ private:
Ref<Font> custom_font;
Cell() {
- text_buf.instance();
+ text_buf.instantiate();
}
Size2 get_icon_size() const;
@@ -416,7 +416,7 @@ private:
String language;
Control::TextDirection text_direction = Control::TEXT_DIRECTION_INHERITED;
ColumnInfo() {
- text_buf.instance();
+ text_buf.instantiate();
}
};
diff --git a/scene/main/http_request.cpp b/scene/main/http_request.cpp
index 927b114fbc..f3c7d128ba 100644
--- a/scene/main/http_request.cpp
+++ b/scene/main/http_request.cpp
@@ -627,7 +627,7 @@ void HTTPRequest::_bind_methods() {
}
HTTPRequest::HTTPRequest() {
- client.instance();
+ client.instantiate();
timer = memnew(Timer);
timer->set_one_shot(true);
timer->connect("timeout", callable_mp(this, &HTTPRequest::_timeout));
diff --git a/scene/main/instance_placeholder.cpp b/scene/main/instance_placeholder.cpp
index 1661984e30..89dac5f5a8 100644
--- a/scene/main/instance_placeholder.cpp
+++ b/scene/main/instance_placeholder.cpp
@@ -88,7 +88,7 @@ Node *InstancePlaceholder::create_instance(bool p_replace, const Ref<PackedScene
if (!ps.is_valid()) {
return nullptr;
}
- Node *scene = ps->instance();
+ Node *scene = ps->instantiate();
if (!scene) {
return nullptr;
}
diff --git a/scene/main/node.cpp b/scene/main/node.cpp
index e1abea81ef..baf185c847 100644
--- a/scene/main/node.cpp
+++ b/scene/main/node.cpp
@@ -35,6 +35,7 @@
#include "core/object/message_queue.h"
#include "core/string/print_string.h"
#include "instance_placeholder.h"
+#include "scene/animation/tween.h"
#include "scene/debugger/scene_debugger.h"
#include "scene/resources/packed_scene.h"
#include "scene/scene_string_names.h"
@@ -1686,6 +1687,13 @@ int Node::get_index() const {
return data.pos;
}
+Ref<Tween> Node::create_tween() {
+ ERR_FAIL_COND_V_MSG(!data.tree, nullptr, "Can't create Tween when not inside scene tree.");
+ Ref<Tween> tween = get_tree()->create_tween();
+ tween->bind_node(this);
+ return tween;
+}
+
void Node::remove_and_skip() {
ERR_FAIL_COND(!data.parent);
@@ -1805,7 +1813,7 @@ bool Node::get_scene_instance_load_placeholder() const {
Node *Node::_duplicate(int p_flags, Map<const Node *, Node *> *r_duplimap) const {
Node *node = nullptr;
- bool instanced = false;
+ bool instantiated = false;
if (Object::cast_to<InstancePlaceholder>(this)) {
const InstancePlaceholder *ip = Object::cast_to<const InstancePlaceholder>(this);
@@ -1822,13 +1830,13 @@ Node *Node::_duplicate(int p_flags, Map<const Node *, Node *> *r_duplimap) const
ges = PackedScene::GEN_EDIT_STATE_INSTANCE;
}
#endif
- node = res->instance(ges);
+ node = res->instantiate(ges);
ERR_FAIL_COND_V(!node, nullptr);
- instanced = true;
+ instantiated = true;
} else {
- Object *obj = ClassDB::instance(get_class());
+ Object *obj = ClassDB::instantiate(get_class());
ERR_FAIL_COND_V(!obj, nullptr);
node = Object::cast_to<Node>(obj);
if (!node) {
@@ -1848,9 +1856,9 @@ Node *Node::_duplicate(int p_flags, Map<const Node *, Node *> *r_duplimap) const
List<const Node *> node_tree;
node_tree.push_front(this);
- if (instanced) {
- // Since nodes in the instanced hierarchy won't be duplicated explicitly, we need to make an inventory
- // of all the nodes in the tree of the instanced scene in order to transfer the values of the properties
+ if (instantiated) {
+ // Since nodes in the instantiated hierarchy won't be duplicated explicitly, we need to make an inventory
+ // of all the nodes in the tree of the instantiated scene in order to transfer the values of the properties
Vector<const Node *> instance_roots;
instance_roots.push_back(this);
@@ -1858,8 +1866,8 @@ Node *Node::_duplicate(int p_flags, Map<const Node *, Node *> *r_duplimap) const
for (List<const Node *>::Element *N = node_tree.front(); N; N = N->next()) {
for (int i = 0; i < N->get()->get_child_count(); ++i) {
Node *descendant = N->get()->get_child(i);
- // Skip nodes not really belonging to the instanced hierarchy; they'll be processed normally later
- // but remember non-instanced nodes that are hidden below instanced ones
+ // Skip nodes not really belonging to the instantiated hierarchy; they'll be processed normally later
+ // but remember non-instantiated nodes that are hidden below instantiated ones
if (!instance_roots.has(descendant->get_owner())) {
if (descendant->get_parent() && descendant->get_parent() != this && descendant->data.owner != descendant->get_parent()) {
hidden_roots.push_back(descendant);
@@ -1942,7 +1950,7 @@ Node *Node::_duplicate(int p_flags, Map<const Node *, Node *> *r_duplimap) const
if (get_child(i)->data.parent_owned) {
continue;
}
- if (instanced && get_child(i)->data.owner == this) {
+ if (instantiated && get_child(i)->data.owner == this) {
continue; //part of instance
}
@@ -2555,6 +2563,7 @@ void Node::_bind_methods() {
ClassDB::bind_method(D_METHOD("is_physics_processing_internal"), &Node::is_physics_processing_internal);
ClassDB::bind_method(D_METHOD("get_tree"), &Node::get_tree);
+ ClassDB::bind_method(D_METHOD("create_tween"), &Node::create_tween);
ClassDB::bind_method(D_METHOD("duplicate", "flags"), &Node::duplicate, DEFVAL(DUPLICATE_USE_INSTANCING | DUPLICATE_SIGNALS | DUPLICATE_GROUPS | DUPLICATE_SCRIPTS));
ClassDB::bind_method(D_METHOD("replace_by", "node", "keep_groups"), &Node::replace_by, DEFVAL(false));
diff --git a/scene/main/node.h b/scene/main/node.h
index e7b36f351b..0d1685a2be 100644
--- a/scene/main/node.h
+++ b/scene/main/node.h
@@ -41,6 +41,9 @@
class Viewport;
class SceneState;
+class Tween;
+class PropertyTweener;
+
class Node : public Object {
GDCLASS(Node, Object);
OBJ_CATEGORY("Nodes");
@@ -308,6 +311,8 @@ public:
void remove_and_skip();
int get_index() const;
+ Ref<Tween> create_tween();
+
void print_tree();
void print_tree_pretty();
diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp
index 001c857d4c..6c46db7801 100644
--- a/scene/main/scene_tree.cpp
+++ b/scene/main/scene_tree.cpp
@@ -41,6 +41,7 @@
#include "core/os/os.h"
#include "core/string/print_string.h"
#include "node.h"
+#include "scene/animation/tween.h"
#include "scene/debugger/scene_debugger.h"
#include "scene/resources/font.h"
#include "scene/resources/material.h"
@@ -412,6 +413,9 @@ bool SceneTree::physics_process(float p_time) {
_notify_group_pause("physics_process", Node::NOTIFICATION_PHYSICS_PROCESS);
_flush_ugc();
MessageQueue::get_singleton()->flush(); //small little hack
+
+ process_tweens(p_time, true);
+
flush_transform_notifications();
root_lock--;
@@ -476,6 +480,8 @@ bool SceneTree::process(float p_time) {
E = N;
}
+ process_tweens(p_time, false);
+
flush_transform_notifications(); //additional transforms after timers update
_call_idle_callbacks();
@@ -510,6 +516,32 @@ bool SceneTree::process(float p_time) {
return _quit;
}
+void SceneTree::process_tweens(float p_delta, bool p_physics) {
+ // This methods works similarly to how SceneTreeTimers are handled.
+ List<Ref<Tween>>::Element *L = tweens.back();
+
+ for (List<Ref<Tween>>::Element *E = tweens.front(); E;) {
+ List<Ref<Tween>>::Element *N = E->next();
+ // Don't process if paused or process mode doesn't match.
+ if ((paused && E->get()->should_pause()) || (p_physics == (E->get()->get_process_mode() == Tween::TWEEN_PROCESS_IDLE))) {
+ if (E == L) {
+ break;
+ }
+ E = N;
+ continue;
+ }
+
+ if (!E->get()->step(p_delta)) {
+ E->get()->set_valid(false);
+ tweens.erase(E);
+ }
+ if (E == L) {
+ break;
+ }
+ E = N;
+ }
+}
+
void SceneTree::finalize() {
_flush_delete_queue();
@@ -1061,7 +1093,7 @@ Error SceneTree::change_scene(const String &p_path) {
Error SceneTree::change_scene_to(const Ref<PackedScene> &p_scene) {
Node *new_scene = nullptr;
if (p_scene.is_valid()) {
- new_scene = p_scene->instance();
+ new_scene = p_scene->instantiate();
ERR_FAIL_COND_V(!new_scene, ERR_CANT_CREATE);
}
@@ -1082,13 +1114,34 @@ void SceneTree::add_current_scene(Node *p_current) {
Ref<SceneTreeTimer> SceneTree::create_timer(float p_delay_sec, bool p_process_always) {
Ref<SceneTreeTimer> stt;
- stt.instance();
+ stt.instantiate();
stt->set_process_always(p_process_always);
stt->set_time_left(p_delay_sec);
timers.push_back(stt);
return stt;
}
+Ref<Tween> SceneTree::create_tween() {
+ Ref<Tween> tween;
+ tween.instantiate();
+ tween->set_valid(true);
+ tweens.push_back(tween);
+ return tween;
+}
+
+Array SceneTree::get_processed_tweens() {
+ Array ret;
+ ret.resize(tweens.size());
+
+ int i = 0;
+ for (List<Ref<Tween>>::Element *E = tweens.front(); E; E = E->next()) {
+ ret[i] = E->get();
+ i++;
+ }
+
+ return ret;
+}
+
void SceneTree::_network_peer_connected(int p_id) {
emit_signal("network_peer_connected", p_id);
}
@@ -1197,6 +1250,8 @@ void SceneTree::_bind_methods() {
ClassDB::bind_method(D_METHOD("is_paused"), &SceneTree::is_paused);
ClassDB::bind_method(D_METHOD("create_timer", "time_sec", "process_always"), &SceneTree::create_timer, DEFVAL(true));
+ ClassDB::bind_method(D_METHOD("create_tween"), &SceneTree::create_tween);
+ ClassDB::bind_method(D_METHOD("get_processed_tweens"), &SceneTree::get_processed_tweens);
ClassDB::bind_method(D_METHOD("get_node_count"), &SceneTree::get_node_count);
ClassDB::bind_method(D_METHOD("get_frame"), &SceneTree::get_frame);
diff --git a/scene/main/scene_tree.h b/scene/main/scene_tree.h
index 78c4c14e97..0e9ffb0f5f 100644
--- a/scene/main/scene_tree.h
+++ b/scene/main/scene_tree.h
@@ -47,6 +47,7 @@ class Window;
class Material;
class Mesh;
class SceneDebugger;
+class Tween;
class SceneTreeTimer : public RefCounted {
GDCLASS(SceneTreeTimer, RefCounted);
@@ -151,6 +152,7 @@ private:
//void _call_group(uint32_t p_call_flags,const StringName& p_group,const StringName& p_function,const Variant& p_arg1,const Variant& p_arg2);
List<Ref<SceneTreeTimer>> timers;
+ List<Ref<Tween>> tweens;
///network///
@@ -171,6 +173,7 @@ private:
void node_added(Node *p_node);
void node_removed(Node *p_node);
void node_renamed(Node *p_node);
+ void process_tweens(float p_delta, bool p_physics_frame);
Group *add_to_group(const StringName &p_group, Node *p_node);
void remove_from_group(const StringName &p_group, Node *p_node);
@@ -318,6 +321,8 @@ public:
Error reload_current_scene();
Ref<SceneTreeTimer> create_timer(float p_delay_sec, bool p_process_always = true);
+ Ref<Tween> create_tween();
+ Array get_processed_tweens();
//used by Main::start, don't use otherwise
void add_current_scene(Node *p_current);
diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp
index 84a6dbe889..e31135b46a 100644
--- a/scene/main/viewport.cpp
+++ b/scene/main/viewport.cpp
@@ -594,7 +594,7 @@ void Viewport::_process_picking() {
if (!has_mouse_event) {
Ref<InputEventMouseMotion> mm;
- mm.instance();
+ mm.instantiate();
mm->set_device(InputEvent::DEVICE_ID_INTERNAL);
mm->set_global_position(physics_last_mousepos);
@@ -644,9 +644,9 @@ void Viewport::_process_picking() {
physics_last_mouse_state.meta = mb->is_meta_pressed();
if (mb->is_pressed()) {
- physics_last_mouse_state.mouse_mask |= (1 << (mb->get_button_index() - 1));
+ physics_last_mouse_state.mouse_mask |= (MouseButton)(1 << (mb->get_button_index() - 1));
} else {
- physics_last_mouse_state.mouse_mask &= ~(1 << (mb->get_button_index() - 1));
+ physics_last_mouse_state.mouse_mask &= (MouseButton) ~(1 << (mb->get_button_index() - 1));
// If touch mouse raised, assume we don't know last mouse pos until new events come
if (mb->get_device() == InputEvent::DEVICE_ID_TOUCH_MOUSE) {
@@ -2585,10 +2585,10 @@ void Viewport::_drop_mouse_focus() {
for (int i = 0; i < 3; i++) {
if (mask & (1 << i)) {
Ref<InputEventMouseButton> mb;
- mb.instance();
+ mb.instantiate();
mb->set_position(c->get_local_mouse_position());
mb->set_global_position(c->get_local_mouse_position());
- mb->set_button_index(i + 1);
+ mb->set_button_index(MouseButton(i + 1));
mb->set_pressed(false);
c->call(SceneStringNames::get_singleton()->_gui_input, mb);
}
@@ -2661,12 +2661,12 @@ void Viewport::_post_gui_grab_click_focus() {
for (int i = 0; i < 3; i++) {
if (mask & (1 << i)) {
Ref<InputEventMouseButton> mb;
- mb.instance();
+ mb.instantiate();
//send unclick
mb->set_position(click);
- mb->set_button_index(i + 1);
+ mb->set_button_index(MouseButton(i + 1));
mb->set_pressed(false);
gui.mouse_focus->call(SceneStringNames::get_singleton()->_gui_input, mb);
}
@@ -2679,12 +2679,12 @@ void Viewport::_post_gui_grab_click_focus() {
for (int i = 0; i < 3; i++) {
if (mask & (1 << i)) {
Ref<InputEventMouseButton> mb;
- mb.instance();
+ mb.instantiate();
//send click
mb->set_position(click);
- mb->set_button_index(i + 1);
+ mb->set_button_index(MouseButton(i + 1));
mb->set_pressed(true);
gui.mouse_focus->call_deferred(SceneStringNames::get_singleton()->_gui_input, mb);
}
@@ -3698,7 +3698,7 @@ Viewport::Viewport() {
viewport = RenderingServer::get_singleton()->viewport_create();
texture_rid = RenderingServer::get_singleton()->viewport_get_texture(viewport);
- default_texture.instance();
+ default_texture.instantiate();
default_texture->vp = const_cast<Viewport *>(this);
viewport_textures.insert(default_texture.ptr());
default_texture->proxy = RS::get_singleton()->texture_proxy_create(texture_rid);
diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cpp
index 2a97ae3acf..3a2b34c6c8 100644
--- a/scene/register_scene_types.cpp
+++ b/scene/register_scene_types.cpp
@@ -260,33 +260,33 @@ void register_scene_types() {
Node::init_node_hrcr();
- resource_loader_font.instance();
+ resource_loader_font.instantiate();
ResourceLoader::add_resource_format_loader(resource_loader_font);
#ifndef DISABLE_DEPRECATED
- resource_loader_compat_font.instance();
+ resource_loader_compat_font.instantiate();
ResourceLoader::add_resource_format_loader(resource_loader_compat_font);
#endif /* DISABLE_DEPRECATED */
- resource_loader_stream_texture.instance();
+ resource_loader_stream_texture.instantiate();
ResourceLoader::add_resource_format_loader(resource_loader_stream_texture);
- resource_loader_texture_layered.instance();
+ resource_loader_texture_layered.instantiate();
ResourceLoader::add_resource_format_loader(resource_loader_texture_layered);
- resource_loader_texture_3d.instance();
+ resource_loader_texture_3d.instantiate();
ResourceLoader::add_resource_format_loader(resource_loader_texture_3d);
- resource_saver_text.instance();
+ resource_saver_text.instantiate();
ResourceSaver::add_resource_format_saver(resource_saver_text, true);
- resource_loader_text.instance();
+ resource_loader_text.instantiate();
ResourceLoader::add_resource_format_loader(resource_loader_text, true);
- resource_saver_shader.instance();
+ resource_saver_shader.instantiate();
ResourceSaver::add_resource_format_saver(resource_saver_shader, true);
- resource_loader_shader.instance();
+ resource_loader_shader.instantiate();
ResourceLoader::add_resource_format_loader(resource_loader_shader, true);
OS::get_singleton()->yield(); //may take time to init
@@ -407,6 +407,11 @@ void register_scene_types() {
ClassDB::register_class<AnimationPlayer>();
ClassDB::register_class<Tween>();
+ ClassDB::register_virtual_class<Tweener>();
+ ClassDB::register_class<PropertyTweener>();
+ ClassDB::register_class<IntervalTweener>();
+ ClassDB::register_class<CallbackTweener>();
+ ClassDB::register_class<MethodTweener>();
ClassDB::register_class<AnimationTree>();
ClassDB::register_class<AnimationNode>();
diff --git a/scene/resources/audio_stream_sample.cpp b/scene/resources/audio_stream_sample.cpp
index 81062feb46..8ffd2df112 100644
--- a/scene/resources/audio_stream_sample.cpp
+++ b/scene/resources/audio_stream_sample.cpp
@@ -596,7 +596,7 @@ Error AudioStreamSample::save_to_wav(const String &p_path) {
Ref<AudioStreamPlayback> AudioStreamSample::instance_playback() {
Ref<AudioStreamPlaybackSample> sample;
- sample.instance();
+ sample.instantiate();
sample->base = Ref<AudioStreamSample>(this);
return sample;
}
diff --git a/scene/resources/bit_map.cpp b/scene/resources/bit_map.cpp
index 0ffeb8a5bf..de557494c3 100644
--- a/scene/resources/bit_map.cpp
+++ b/scene/resources/bit_map.cpp
@@ -487,7 +487,7 @@ Vector<Vector<Vector2>> BitMap::clip_opaque_to_polygons(const Rect2 &p_rect, flo
Point2i from;
Ref<BitMap> fill;
- fill.instance();
+ fill.instantiate();
fill->create(get_size());
Vector<Vector<Vector2>> polygons;
@@ -525,7 +525,7 @@ void BitMap::grow_mask(int p_pixels, const Rect2 &p_rect) {
Rect2i r = Rect2i(0, 0, width, height).intersection(p_rect);
Ref<BitMap> copy;
- copy.instance();
+ copy.instantiate();
copy->create(get_size());
copy->bitmask = bitmask;
@@ -604,7 +604,7 @@ Array BitMap::_opaque_to_polygons_bind(const Rect2 &p_rect, float p_epsilon) con
void BitMap::resize(const Size2 &p_new_size) {
Ref<BitMap> new_bitmap;
- new_bitmap.instance();
+ new_bitmap.instantiate();
new_bitmap->create(p_new_size);
int lw = MIN(width, p_new_size.width);
int lh = MIN(height, p_new_size.height);
@@ -621,7 +621,7 @@ void BitMap::resize(const Size2 &p_new_size) {
Ref<Image> BitMap::convert_to_image() const {
Ref<Image> image;
- image.instance();
+ image.instantiate();
image->create(width, height, false, Image::FORMAT_L8);
for (int i = 0; i < width; i++) {
diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp
index a4228d48b4..5464a46df4 100644
--- a/scene/resources/default_theme/default_theme.cpp
+++ b/scene/resources/default_theme/default_theme.cpp
@@ -559,7 +559,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const
// ScrollContainer
Ref<StyleBoxEmpty> empty;
- empty.instance();
+ empty.instantiate();
theme->set_stylebox("bg", "ScrollContainer", empty);
// WindowDialog
@@ -979,7 +979,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const
void make_default_theme(bool p_hidpi, Ref<Font> p_font) {
Ref<Theme> t;
- t.instance();
+ t.instantiate();
Ref<StyleBox> default_style;
Ref<Texture2D> default_icon;
@@ -993,10 +993,10 @@ void make_default_theme(bool p_hidpi, Ref<Font> p_font) {
// The default DynamicFont is chosen to have a small file size since it's
// embedded in both editor and export template binaries.
Ref<Font> dynamic_font;
- dynamic_font.instance();
+ dynamic_font.instantiate();
Ref<FontData> dynamic_font_data;
- dynamic_font_data.instance();
+ dynamic_font_data.instantiate();
dynamic_font_data->load_memory(_font_OpenSans_SemiBold, _font_OpenSans_SemiBold_size, "ttf", default_font_size);
dynamic_font->add_data(dynamic_font_data);
diff --git a/scene/resources/font.cpp b/scene/resources/font.cpp
index 6f87c524d8..032171847d 100644
--- a/scene/resources/font.cpp
+++ b/scene/resources/font.cpp
@@ -813,7 +813,7 @@ Size2 Font::get_string_size(const String &p_text, int p_size) const {
if (cache.has(hash)) {
buffer = cache.get(hash);
} else {
- buffer.instance();
+ buffer.instantiate();
int size = p_size <= 0 ? data[0]->get_base_size() : p_size;
buffer->add_string(p_text, Ref<Font>(this), size, Dictionary(), TranslationServer::get_singleton()->get_tool_locale());
cache.insert(hash, buffer);
@@ -838,7 +838,7 @@ Size2 Font::get_multiline_string_size(const String &p_text, float p_width, int p
if (cache_wrap.has(wrp_hash)) {
lines_buffer = cache_wrap.get(wrp_hash);
} else {
- lines_buffer.instance();
+ lines_buffer.instantiate();
int size = p_size <= 0 ? data[0]->get_base_size() : p_size;
lines_buffer->add_string(p_text, Ref<Font>(this), size, Dictionary(), TranslationServer::get_singleton()->get_tool_locale());
lines_buffer->set_width(p_width);
@@ -870,7 +870,7 @@ void Font::draw_string(RID p_canvas_item, const Point2 &p_pos, const String &p_t
if (cache.has(hash)) {
buffer = cache.get(hash);
} else {
- buffer.instance();
+ buffer.instantiate();
int size = p_size <= 0 ? data[0]->get_base_size() : p_size;
buffer->add_string(p_text, Ref<Font>(this), size, Dictionary(), TranslationServer::get_singleton()->get_tool_locale());
cache.insert(hash, buffer);
@@ -905,7 +905,7 @@ void Font::draw_multiline_string(RID p_canvas_item, const Point2 &p_pos, const S
if (cache_wrap.has(wrp_hash)) {
lines_buffer = cache_wrap.get(wrp_hash);
} else {
- lines_buffer.instance();
+ lines_buffer.instantiate();
int size = p_size <= 0 ? data[0]->get_base_size() : p_size;
lines_buffer->add_string(p_text, Ref<Font>(this), size, Dictionary(), TranslationServer::get_singleton()->get_tool_locale());
lines_buffer->set_width(p_width);
@@ -1041,7 +1041,7 @@ RES ResourceFormatLoaderFont::load(const String &p_path, const String &p_origina
}
Ref<FontData> dfont;
- dfont.instance();
+ dfont.instantiate();
dfont->load_resource(p_path);
if (r_error) {
@@ -1096,11 +1096,11 @@ RES ResourceFormatLoaderCompatFont::load(const String &p_path, const String &p_o
}
Ref<FontData> dfont;
- dfont.instance();
+ dfont.instantiate();
dfont->load_resource(p_path);
Ref<Font> font;
- font.instance();
+ font.instantiate();
font->add_data(dfont);
if (r_error) {
diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp
index 2c5634e6ef..7027319554 100644
--- a/scene/resources/material.cpp
+++ b/scene/resources/material.cpp
@@ -2092,7 +2092,7 @@ RID BaseMaterial3D::get_material_rid_for_2d(bool p_shaded, bool p_transparent, b
}
Ref<StandardMaterial3D> material;
- material.instance();
+ material.instantiate();
material->set_shading_mode(p_shaded ? SHADING_MODE_PER_PIXEL : SHADING_MODE_UNSHADED);
material->set_transparency(p_transparent ? (p_opaque_prepass ? TRANSPARENCY_ALPHA_DEPTH_PRE_PASS : (p_cut_alpha ? TRANSPARENCY_ALPHA_SCISSOR : TRANSPARENCY_ALPHA)) : TRANSPARENCY_DISABLED);
diff --git a/scene/resources/mesh.cpp b/scene/resources/mesh.cpp
index 5e8e77c730..cf59c6fa22 100644
--- a/scene/resources/mesh.cpp
+++ b/scene/resources/mesh.cpp
@@ -571,7 +571,7 @@ Vector<Ref<Shape3D>> Mesh::convex_decompose() const {
}
Ref<ConvexPolygonShape3D> shape;
- shape.instance();
+ shape.instantiate();
shape->set_points(convex_points);
ret.push_back(shape);
}
@@ -1537,7 +1537,7 @@ Error ArrayMesh::lightmap_unwrap_cached(const Transform3D &p_base_transform, flo
for (int i = 0; i < lightmap_surfaces.size(); i++) {
Ref<SurfaceTool> st;
- st.instance();
+ st.instantiate();
st->begin(Mesh::PRIMITIVE_TRIANGLES);
st->set_material(lightmap_surfaces[i].material);
surfaces_tools.push_back(st); //stay there
diff --git a/scene/resources/packed_scene.cpp b/scene/resources/packed_scene.cpp
index ab8a4b7934..913f1ca376 100644
--- a/scene/resources/packed_scene.cpp
+++ b/scene/resources/packed_scene.cpp
@@ -41,11 +41,11 @@
#define PACKED_SCENE_VERSION 2
-bool SceneState::can_instance() const {
+bool SceneState::can_instantiate() const {
return nodes.size() > 0;
}
-Node *SceneState::instance(GenEditState p_edit_state) const {
+Node *SceneState::instantiate(GenEditState p_edit_state) const {
// nodes where instancing failed (because something is missing)
List<Node *> stray_instances;
@@ -109,7 +109,7 @@ Node *SceneState::instance(GenEditState p_edit_state) const {
//scene inheritance on root node
Ref<PackedScene> sdata = props[base_scene_idx];
ERR_FAIL_COND_V(!sdata.is_valid(), nullptr);
- node = sdata->instance(p_edit_state == GEN_EDIT_STATE_DISABLED ? PackedScene::GEN_EDIT_STATE_DISABLED : PackedScene::GEN_EDIT_STATE_INSTANCE); //only main gets main edit state
+ node = sdata->instantiate(p_edit_state == GEN_EDIT_STATE_DISABLED ? PackedScene::GEN_EDIT_STATE_DISABLED : PackedScene::GEN_EDIT_STATE_INSTANCE); //only main gets main edit state
ERR_FAIL_COND_V(!node, nullptr);
if (p_edit_state != GEN_EDIT_STATE_DISABLED) {
node->set_scene_inherited_state(sdata->get_state());
@@ -122,7 +122,7 @@ Node *SceneState::instance(GenEditState p_edit_state) const {
if (disable_placeholders) {
Ref<PackedScene> sdata = ResourceLoader::load(path, "PackedScene");
ERR_FAIL_COND_V(!sdata.is_valid(), nullptr);
- node = sdata->instance(p_edit_state == GEN_EDIT_STATE_DISABLED ? PackedScene::GEN_EDIT_STATE_DISABLED : PackedScene::GEN_EDIT_STATE_INSTANCE);
+ node = sdata->instantiate(p_edit_state == GEN_EDIT_STATE_DISABLED ? PackedScene::GEN_EDIT_STATE_DISABLED : PackedScene::GEN_EDIT_STATE_INSTANCE);
ERR_FAIL_COND_V(!node, nullptr);
} else {
InstancePlaceholder *ip = memnew(InstancePlaceholder);
@@ -133,7 +133,7 @@ Node *SceneState::instance(GenEditState p_edit_state) const {
} else {
Ref<PackedScene> sdata = props[n.instance & FLAG_MASK];
ERR_FAIL_COND_V(!sdata.is_valid(), nullptr);
- node = sdata->instance(p_edit_state == GEN_EDIT_STATE_DISABLED ? PackedScene::GEN_EDIT_STATE_DISABLED : PackedScene::GEN_EDIT_STATE_INSTANCE);
+ node = sdata->instantiate(p_edit_state == GEN_EDIT_STATE_DISABLED ? PackedScene::GEN_EDIT_STATE_DISABLED : PackedScene::GEN_EDIT_STATE_INSTANCE);
ERR_FAIL_COND_V(!node, nullptr);
}
@@ -152,7 +152,7 @@ Node *SceneState::instance(GenEditState p_edit_state) const {
if (ClassDB::is_class_enabled(snames[n.type])) {
//node belongs to this scene and must be created
- obj = ClassDB::instance(snames[n.type]);
+ obj = ClassDB::instantiate(snames[n.type]);
}
if (!Object::cast_to<Node>(obj)) {
@@ -180,7 +180,7 @@ Node *SceneState::instance(GenEditState p_edit_state) const {
}
if (node) {
- // may not have found the node (part of instanced scene and removed)
+ // may not have found the node (part of instantiated scene and removed)
// if found all is good, otherwise ignore
//properties
@@ -266,7 +266,7 @@ Node *SceneState::instance(GenEditState p_edit_state) const {
parent->move_child(node, n.index);
}
} else {
- //it may be possible that an instanced scene has changed
+ //it may be possible that an instantiated scene has changed
//and the node has nowhere to go anymore
stray_instances.push_back(node); //can't be added, go to stray list
}
@@ -368,7 +368,7 @@ static int _vm_get_variant(const Variant &p_variant, HashMap<Variant, int, Varia
Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map<StringName, int> &name_map, HashMap<Variant, int, VariantHasher, VariantComparator> &variant_map, Map<Node *, int> &node_map, Map<Node *, int> &nodepath_map) {
// this function handles all the work related to properly packing scenes, be it
- // instanced or inherited.
+ // instantiated or inherited.
// given the complexity of this process, an attempt will be made to properly
// document it. if you fail to understand something, please ask!
@@ -377,7 +377,7 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map
return OK;
}
- // save the child instanced scenes that are chosen as editable, so they can be restored
+ // save the child instantiated scenes that are chosen as editable, so they can be restored
// upon load back
if (p_node != p_owner && p_node->get_filename() != String() && p_owner->is_editable_instance(p_node)) {
editable_instances.push_back(p_owner->get_path_to(p_node));
@@ -386,7 +386,7 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map
NodeData nd;
nd.name = _nm_get_string(p_node->get_name(), name_map);
- nd.instance = -1; //not instanced by default
+ nd.instance = -1; //not instantiated by default
//really convoluted condition, but it basically checks that index is only saved when part of an inherited scene OR the node parent is from the edited scene
if (p_owner->get_scene_inherited_state().is_null() && (p_node == p_owner || (p_node->get_owner() == p_owner && (p_node->get_parent() == p_owner || p_node->get_parent()->get_owner() == p_owner)))) {
@@ -396,18 +396,18 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map
//This (hopefully) happens if the node is a scene root, so its index is irrelevant.
nd.index = -1;
} else {
- //part of an inherited scene, or parent is from an instanced scene
+ //part of an inherited scene, or parent is from an instantiated scene
nd.index = p_node->get_index();
}
- // if this node is part of an instanced scene or sub-instanced scene
+ // if this node is part of an instantiated scene or sub-instantiated scene
// we need to get the corresponding instance states.
// with the instance states, we can query for identical properties/groups
// and only save what has changed
List<PackState> pack_state_stack;
- bool instanced_by_owner = true;
+ bool instantiated_by_owner = true;
{
Node *n = p_node;
@@ -423,11 +423,11 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map
ps.node = node;
ps.state = state;
pack_state_stack.push_back(ps);
- instanced_by_owner = false;
+ instantiated_by_owner = false;
}
}
- if (p_node->get_filename() != String() && p_node->get_owner() == p_owner && instanced_by_owner) {
+ if (p_node->get_filename() != String() && p_node->get_owner() == p_owner && instantiated_by_owner) {
if (p_node->get_scene_instance_load_placeholder()) {
//it's a placeholder, use the placeholder path
nd.instance = _vm_get_variant(p_node->get_filename(), variant_map);
@@ -500,8 +500,8 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map
// }
if (pack_state_stack.size()) {
- // we are on part of an instanced subscene
- // or part of instanced scene.
+ // we are on part of an instantiated subscene
+ // or part of instantiated scene.
// only save what has been changed
// only save changed properties in instance
@@ -571,7 +571,7 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map
}
/*
if (instance_state_node>=0 && instance_state->is_node_in_group(instance_state_node,gi.name))
- continue; //group was instanced, don't add here
+ continue; //group was instantiated, don't add here
*/
bool skip = false;
@@ -594,7 +594,7 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map
// save the right owner
// for the saved scene root this is -1
// for nodes of the saved scene this is 0
- // for nodes of instanced scenes this is >0
+ // for nodes of instantiated scenes this is >0
if (p_node == p_owner) {
//saved scene root
@@ -612,20 +612,20 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map
//this node is not part of an instancing process, so save the type
nd.type = _nm_get_string(p_node->get_class(), name_map);
} else {
- // this node is part of an instanced process, so do not save the type.
- // instead, save that it was instanced
+ // this node is part of an instantiated process, so do not save the type.
+ // instead, save that it was instantiated
nd.type = TYPE_INSTANCED;
}
// determine whether to save this node or not
- // if this node is part of an instanced sub-scene, we can skip storing it if basically
+ // if this node is part of an instantiated sub-scene, we can skip storing it if basically
// no properties changed and no groups were added to it.
// below condition is true for all nodes of the scene being saved, and ones in subscenes
// that hold changes
bool save_node = nd.properties.size() || nd.groups.size(); // some local properties or groups exist
save_node = save_node || p_node == p_owner; // owner is always saved
- save_node = save_node || (p_node->get_owner() == p_owner && instanced_by_owner); //part of scene and not instanced
+ save_node = save_node || (p_node->get_owner() == p_owner && instantiated_by_owner); //part of scene and not instantiated
int idx = nodes.size();
int parent_node = NO_PARENT_SAVED;
@@ -893,6 +893,13 @@ Error SceneState::pack(Node *p_scene) {
node_paths.write[E->get()] = scene->get_path_to(E->key());
}
+ if (Engine::get_singleton()->is_editor_hint()) {
+ // Build node path cache
+ for (Map<Node *, int>::Element *E = node_map.front(); E; E = E->next()) {
+ node_path_cache[scene->get_path_to(E->key())] = E->get();
+ }
+ }
+
return OK;
}
@@ -927,10 +934,12 @@ Ref<SceneState> SceneState::_get_base_scene_state() const {
}
int SceneState::find_node_by_path(const NodePath &p_node) const {
+ ERR_FAIL_COND_V_MSG(node_path_cache.size() == 0, -1, "This operation requires the node cache to have been built.");
+
if (!node_path_cache.has(p_node)) {
if (_get_base_scene_state().is_valid()) {
int idx = _get_base_scene_state()->find_node_by_path(p_node);
- if (idx >= 0) {
+ if (idx != -1) {
int rkey = _find_base_scene_node_remap_key(idx);
if (rkey == -1) {
rkey = nodes.size() + base_scene_node_remap.size();
@@ -946,7 +955,7 @@ int SceneState::find_node_by_path(const NodePath &p_node) const {
if (_get_base_scene_state().is_valid() && !base_scene_node_remap.has(nid)) {
//for nodes that _do_ exist in current scene, still try to look for
- //the node in the instanced scene, as a property may be missing
+ //the node in the instantiated scene, as a property may be missing
//from the local one
int idx = _get_base_scene_state()->find_node_by_path(p_node);
if (idx != -1) {
@@ -1614,16 +1623,16 @@ void PackedScene::clear() {
state->clear();
}
-bool PackedScene::can_instance() const {
- return state->can_instance();
+bool PackedScene::can_instantiate() const {
+ return state->can_instantiate();
}
-Node *PackedScene::instance(GenEditState p_edit_state) const {
+Node *PackedScene::instantiate(GenEditState p_edit_state) const {
#ifndef TOOLS_ENABLED
ERR_FAIL_COND_V_MSG(p_edit_state != GEN_EDIT_STATE_DISABLED, nullptr, "Edit state is only for editors, does not work without tools compiled.");
#endif
- Node *s = state->instance((SceneState::GenEditState)p_edit_state);
+ Node *s = state->instantiate((SceneState::GenEditState)p_edit_state);
if (!s) {
return nullptr;
}
@@ -1671,8 +1680,8 @@ void PackedScene::reset_state() {
}
void PackedScene::_bind_methods() {
ClassDB::bind_method(D_METHOD("pack", "path"), &PackedScene::pack);
- ClassDB::bind_method(D_METHOD("instance", "edit_state"), &PackedScene::instance, DEFVAL(GEN_EDIT_STATE_DISABLED));
- ClassDB::bind_method(D_METHOD("can_instance"), &PackedScene::can_instance);
+ ClassDB::bind_method(D_METHOD("instantiate", "edit_state"), &PackedScene::instantiate, DEFVAL(GEN_EDIT_STATE_DISABLED));
+ ClassDB::bind_method(D_METHOD("can_instantiate"), &PackedScene::can_instantiate);
ClassDB::bind_method(D_METHOD("_set_bundled_scene"), &PackedScene::_set_bundled_scene);
ClassDB::bind_method(D_METHOD("_get_bundled_scene"), &PackedScene::_get_bundled_scene);
ClassDB::bind_method(D_METHOD("get_state"), &PackedScene::get_state);
diff --git a/scene/resources/packed_scene.h b/scene/resources/packed_scene.h
index e85b933439..55708f7914 100644
--- a/scene/resources/packed_scene.h
+++ b/scene/resources/packed_scene.h
@@ -136,8 +136,8 @@ public:
void clear();
- bool can_instance() const;
- Node *instance(GenEditState p_edit_state) const;
+ bool can_instantiate() const;
+ Node *instantiate(GenEditState p_edit_state) const;
//unbuild API
@@ -213,8 +213,8 @@ public:
void clear();
- bool can_instance() const;
- Node *instance(GenEditState p_edit_state = GEN_EDIT_STATE_DISABLED) const;
+ bool can_instantiate() const;
+ Node *instantiate(GenEditState p_edit_state = GEN_EDIT_STATE_DISABLED) const;
void recreate_state();
void replace_state(Ref<SceneState> p_by);
diff --git a/scene/resources/resource_format_text.cpp b/scene/resources/resource_format_text.cpp
index 27f0c50a79..ee61e64ed3 100644
--- a/scene/resources/resource_format_text.cpp
+++ b/scene/resources/resource_format_text.cpp
@@ -65,7 +65,7 @@ Error ResourceLoaderText::_parse_sub_resource_dummy(DummyReadData *p_data, Varia
if (!p_data->resource_map.has(index)) {
Ref<DummyResource> dr;
- dr.instance();
+ dr.instantiate();
dr->set_subindex(index);
p_data->resource_map[index] = dr;
p_data->resource_set.insert(dr);
@@ -183,7 +183,7 @@ Error ResourceLoaderText::_parse_ext_resource(VariantParser::Stream *p_stream, R
Ref<PackedScene> ResourceLoaderText::_parse_node_tag(VariantParser::ResourceParser &parser) {
Ref<PackedScene> packed_scene;
- packed_scene.instance();
+ packed_scene.instantiate();
while (true) {
if (next_tag.name == "node") {
@@ -208,7 +208,7 @@ Ref<PackedScene> ResourceLoaderText::_parse_node_tag(VariantParser::ResourcePars
if (next_tag.fields.has("type")) {
type = packed_scene->get_state()->add_name(next_tag.fields["type"]);
} else {
- type = SceneState::TYPE_INSTANCED; //no type? assume this was instanced
+ type = SceneState::TYPE_INSTANCED; //no type? assume this was instantiated
}
if (next_tag.fields.has("instance")) {
@@ -522,7 +522,7 @@ Error ResourceLoaderText::load() {
} else {
//create
- Object *obj = ClassDB::instance(type);
+ Object *obj = ClassDB::instantiate(type);
if (!obj) {
error_text += "Can't create sub resource of type: " + type;
_printerr();
@@ -604,7 +604,7 @@ Error ResourceLoaderText::load() {
}
if (!resource.is_valid()) {
- Object *obj = ClassDB::instance(res_type);
+ Object *obj = ClassDB::instantiate(res_type);
if (!obj) {
error_text += "Can't create sub resource of type: " + res_type;
_printerr();
@@ -1022,7 +1022,7 @@ Error ResourceLoaderText::save_as_binary(FileAccess *p_f, const String &p_path)
int lindex = dummy_read.external_resources.size();
Ref<DummyResource> dr;
- dr.instance();
+ dr.instantiate();
dr->set_path("res://dummy" + itos(lindex)); //anything is good to detect it for saving as external
dummy_read.external_resources[dr] = lindex;
dummy_read.rev_external_resources[index] = dr;
diff --git a/scene/resources/shader.cpp b/scene/resources/shader.cpp
index cbd44315b7..f19d08dbb1 100644
--- a/scene/resources/shader.cpp
+++ b/scene/resources/shader.cpp
@@ -167,7 +167,7 @@ RES ResourceFormatLoaderShader::load(const String &p_path, const String &p_origi
}
Ref<Shader> shader;
- shader.instance();
+ shader.instantiate();
Vector<uint8_t> buffer = FileAccess::get_file_as_array(p_path);
diff --git a/scene/resources/surface_tool.cpp b/scene/resources/surface_tool.cpp
index fee9f92ad7..9f8c35b668 100644
--- a/scene/resources/surface_tool.cpp
+++ b/scene/resources/surface_tool.cpp
@@ -607,7 +607,7 @@ Ref<ArrayMesh> SurfaceTool::commit(const Ref<ArrayMesh> &p_existing, uint32_t p_
if (p_existing.is_valid()) {
mesh = p_existing;
} else {
- mesh.instance();
+ mesh.instantiate();
}
int varr_len = vertex_array.size();
diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp
index aa85c7116b..b8dd8b1c14 100644
--- a/scene/resources/texture.cpp
+++ b/scene/resources/texture.cpp
@@ -88,7 +88,7 @@ void ImageTexture::reload_from_file() {
}
Ref<Image> img;
- img.instance();
+ img.instantiate();
if (ImageLoader::load_image(path, img) == OK) {
create_from_image(img);
@@ -138,7 +138,7 @@ void ImageTexture::_reload_hook(const RID &p_hook) {
}
Ref<Image> img;
- img.instance();
+ img.instantiate();
Error err = ImageLoader::load_image(path, img);
ERR_FAIL_COND_MSG(err != OK, "Cannot load image from path '" + path + "'.");
@@ -258,7 +258,7 @@ bool ImageTexture::is_pixel_opaque(int p_x, int p_y) const {
decom->decompress();
img = decom;
}
- alpha_cache.instance();
+ alpha_cache.instantiate();
alpha_cache->create_from_image_alpha(img);
}
}
@@ -390,7 +390,7 @@ Ref<Image> StreamTexture2D::load_image_from_file(FileAccess *f, int p_size_limit
//print_line("mipmap read total: " + itos(mipmap_images.size()));
Ref<Image> image;
- image.instance();
+ image.instantiate();
if (mipmap_images.size() == 1) {
//only one image (which will most likely be the case anyway for this format)
@@ -442,7 +442,7 @@ Ref<Image> StreamTexture2D::load_image_from_file(FileAccess *f, int p_size_limit
}
Ref<Image> image;
- image.instance();
+ image.instantiate();
image->create(tw, th, mipmaps - i ? true : false, format, data);
@@ -553,7 +553,7 @@ Error StreamTexture2D::_load_data(const String &p_path, int &r_width, int &r_hei
Error StreamTexture2D::load(const String &p_path) {
int lw, lh;
Ref<Image> image;
- image.instance();
+ image.instantiate();
bool request_3d;
bool request_normal;
@@ -679,7 +679,7 @@ bool StreamTexture2D::is_pixel_opaque(int p_x, int p_y) const {
img = decom;
}
- alpha_cache.instance();
+ alpha_cache.instantiate();
alpha_cache->create_from_image_alpha(img);
}
}
@@ -738,7 +738,7 @@ StreamTexture2D::~StreamTexture2D() {
RES ResourceFormatLoaderStreamTexture2D::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) {
Ref<StreamTexture2D> st;
- st.instance();
+ st.instantiate();
Error err = st->load(p_path);
if (r_error) {
*r_error = err;
@@ -1036,7 +1036,7 @@ StreamTexture3D::~StreamTexture3D() {
RES ResourceFormatLoaderStreamTexture3D::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) {
Ref<StreamTexture3D> st;
- st.instance();
+ st.instantiate();
Error err = st->load(p_path);
if (r_error) {
*r_error = err;
@@ -2257,15 +2257,15 @@ RES ResourceFormatLoaderStreamTextureLayered::load(const String &p_path, const S
Ref<StreamTextureLayered> st;
if (p_path.get_extension().to_lower() == "stexarray") {
Ref<StreamTexture2DArray> s;
- s.instance();
+ s.instantiate();
st = s;
} else if (p_path.get_extension().to_lower() == "scube") {
Ref<StreamCubemap> s;
- s.instance();
+ s.instantiate();
st = s;
} else if (p_path.get_extension().to_lower() == "scubearray") {
Ref<StreamCubemapArray> s;
- s.instance();
+ s.instantiate();
st = s;
} else {
if (r_error) {
diff --git a/scene/resources/tile_set.cpp b/scene/resources/tile_set.cpp
index 0eeea29da4..ef4a53cb0d 100644
--- a/scene/resources/tile_set.cpp
+++ b/scene/resources/tile_set.cpp
@@ -4587,7 +4587,7 @@ void TileSetPluginScenesCollections::update_dirty_quadrants(TileMap *p_tile_map,
if (scenes_collection_source) {
Ref<PackedScene> packed_scene = scenes_collection_source->get_scene_tile_scene(c.alternative_tile);
if (packed_scene.is_valid()) {
- Node *scene = packed_scene->instance();
+ Node *scene = packed_scene->instantiate();
p_tile_map->add_child(scene);
Control *scene_as_control = Object::cast_to<Control>(scene);
Node2D *scene_as_node2d = Object::cast_to<Node2D>(scene);
diff --git a/scene/resources/visual_shader.cpp b/scene/resources/visual_shader.cpp
index 5759948fe6..774c1a5c33 100644
--- a/scene/resources/visual_shader.cpp
+++ b/scene/resources/visual_shader.cpp
@@ -617,7 +617,7 @@ void VisualShader::replace_node(Type p_type, int p_id, const StringName &p_new_c
if (g->nodes[p_id].node->get_class_name() == p_new_class) {
return;
}
- VisualShaderNode *vsn = Object::cast_to<VisualShaderNode>(ClassDB::instance(p_new_class));
+ VisualShaderNode *vsn = Object::cast_to<VisualShaderNode>(ClassDB::instantiate(p_new_class));
vsn->connect("changed", callable_mp(this, &VisualShader::_queue_update));
g->nodes[p_id].node = Ref<VisualShaderNode>(vsn);
@@ -2020,13 +2020,13 @@ VisualShader::VisualShader() {
for (int i = 0; i < TYPE_MAX; i++) {
if (i > (int)TYPE_LIGHT && i < (int)TYPE_SKY) {
Ref<VisualShaderNodeParticleOutput> output;
- output.instance();
+ output.instantiate();
output->shader_type = Type(i);
output->shader_mode = shader_mode;
graph[i].nodes[NODE_ID_OUTPUT].node = output;
} else {
Ref<VisualShaderNodeOutput> output;
- output.instance();
+ output.instantiate();
output->shader_type = Type(i);
output->shader_mode = shader_mode;
graph[i].nodes[NODE_ID_OUTPUT].node = output;