summaryrefslogtreecommitdiff
path: root/scene/animation
diff options
context:
space:
mode:
Diffstat (limited to 'scene/animation')
-rw-r--r--scene/animation/animation_cache.cpp206
-rw-r--r--scene/animation/animation_cache.h29
-rw-r--r--scene/animation/animation_player.cpp911
-rw-r--r--scene/animation/animation_player.h162
-rw-r--r--scene/animation/animation_tree_player.cpp1485
-rw-r--r--scene/animation/animation_tree_player.h286
-rw-r--r--scene/animation/tween.cpp1038
-rw-r--r--scene/animation/tween.h167
-rw-r--r--scene/animation/tween_interpolaters.cpp450
9 files changed, 2088 insertions, 2646 deletions
diff --git a/scene/animation/animation_cache.cpp b/scene/animation/animation_cache.cpp
index 960356d9cf..93fbde519e 100644
--- a/scene/animation/animation_cache.cpp
+++ b/scene/animation/animation_cache.cpp
@@ -28,8 +28,6 @@
/*************************************************************************/
#include "animation_cache.h"
-
-
void AnimationCache::_node_exit_tree(Node *p_node) {
//it is one shot, so it disconnects upon arrival
@@ -38,47 +36,41 @@ void AnimationCache::_node_exit_tree(Node *p_node) {
connected_nodes.erase(p_node);
- for(int i=0;i<path_cache.size();i++) {
-
+ for (int i = 0; i < path_cache.size(); i++) {
- if (path_cache[i].node!=p_node)
+ if (path_cache[i].node != p_node)
continue;
- path_cache[i].valid=false; //invalidate path cache
+ path_cache[i].valid = false; //invalidate path cache
}
-
}
void AnimationCache::_animation_changed() {
-
_clear_cache();
}
void AnimationCache::_clear_cache() {
- while(connected_nodes.size()) {
+ while (connected_nodes.size()) {
- connected_nodes.front()->get()->disconnect("tree_exited",this,"_node_exit_tree");
+ connected_nodes.front()->get()->disconnect("tree_exited", this, "_node_exit_tree");
connected_nodes.erase(connected_nodes.front());
}
path_cache.clear();
- cache_valid=false;
- cache_dirty=true;
+ cache_valid = false;
+ cache_dirty = true;
}
-
void AnimationCache::_update_cache() {
- cache_valid=false;
+ cache_valid = false;
ERR_FAIL_COND(!root);
ERR_FAIL_COND(!root->is_inside_tree());
ERR_FAIL_COND(animation.is_null());
- for(int i=0;i<animation->get_track_count();i++) {
-
-
+ for (int i = 0; i < animation->get_track_count(); i++) {
NodePath np = animation->track_get_path(i);
@@ -86,146 +78,127 @@ void AnimationCache::_update_cache() {
if (!node) {
path_cache.push_back(Path());
- ERR_EXPLAIN("Invalid Track Path in Animation: "+np);
+ ERR_EXPLAIN("Invalid Track Path in Animation: " + np);
ERR_CONTINUE(!node);
}
-
Path path;
Ref<Resource> res;
if (np.get_subname_count()) {
-
- if (animation->track_get_type(i)==Animation::TYPE_TRANSFORM) {
+ if (animation->track_get_type(i) == Animation::TYPE_TRANSFORM) {
path_cache.push_back(Path());
- ERR_EXPLAIN("Transform tracks can't have a subpath: "+np);
- ERR_CONTINUE(animation->track_get_type(i)==Animation::TYPE_TRANSFORM);
-
+ ERR_EXPLAIN("Transform tracks can't have a subpath: " + np);
+ ERR_CONTINUE(animation->track_get_type(i) == Animation::TYPE_TRANSFORM);
}
RES res;
- for(int j=0;j<np.get_subname_count();j++) {
- res = j==0 ? node->get(np.get_subname(j)) : res->get(np.get_subname(j));
+ for (int j = 0; j < np.get_subname_count(); j++) {
+ res = j == 0 ? node->get(np.get_subname(j)) : res->get(np.get_subname(j));
if (res.is_null())
break;
-
}
if (res.is_null()) {
path_cache.push_back(Path());
- ERR_EXPLAIN("Invalid Track SubPath in Animation: "+np);
+ ERR_EXPLAIN("Invalid Track SubPath in Animation: " + np);
ERR_CONTINUE(res.is_null());
}
- path.resource=res;
- path.object=res.ptr();
+ path.resource = res;
+ path.object = res.ptr();
} else {
-
- if (animation->track_get_type(i)==Animation::TYPE_TRANSFORM) {
+ if (animation->track_get_type(i) == Animation::TYPE_TRANSFORM) {
StringName property = np.get_property();
String ps = property;
-
Spatial *sp = node->cast_to<Spatial>();
if (!sp) {
path_cache.push_back(Path());
- ERR_EXPLAIN("Transform track not of type Spatial: "+np);
+ ERR_EXPLAIN("Transform track not of type Spatial: " + np);
ERR_CONTINUE(!sp);
}
- if (ps!="") {
+ if (ps != "") {
Skeleton *sk = node->cast_to<Skeleton>();
if (!sk) {
path_cache.push_back(Path());
- ERR_EXPLAIN("Property defined in Transform track, but not a Skeleton!: "+np);
+ ERR_EXPLAIN("Property defined in Transform track, but not a Skeleton!: " + np);
ERR_CONTINUE(!sk);
}
int idx = sk->find_bone(ps);
- if (idx==-1) {
+ if (idx == -1) {
path_cache.push_back(Path());
- ERR_EXPLAIN("Property defined in Transform track, but not a Skeleton Bone!: "+np);
- ERR_CONTINUE(idx==-1);
-
+ ERR_EXPLAIN("Property defined in Transform track, but not a Skeleton Bone!: " + np);
+ ERR_CONTINUE(idx == -1);
}
- path.bone_idx=idx;
- path.skeleton=sk;
-
+ path.bone_idx = idx;
+ path.skeleton = sk;
}
- path.spatial=sp;
-
+ path.spatial = sp;
}
- path.node=node;
- path.object=node;
-
+ path.node = node;
+ path.object = node;
}
- if (animation->track_get_type(i)==Animation::TYPE_VALUE) {
+ if (animation->track_get_type(i) == Animation::TYPE_VALUE) {
- if (np.get_property().operator String()=="") {
+ if (np.get_property().operator String() == "") {
path_cache.push_back(Path());
- ERR_EXPLAIN("Value Track lacks property: "+np);
- ERR_CONTINUE(np.get_property().operator String()=="");
-
+ ERR_EXPLAIN("Value Track lacks property: " + np);
+ ERR_CONTINUE(np.get_property().operator String() == "");
}
- path.property=np.get_property();
+ path.property = np.get_property();
- } else if (animation->track_get_type(i)==Animation::TYPE_METHOD) {
+ } else if (animation->track_get_type(i) == Animation::TYPE_METHOD) {
- if (np.get_property().operator String()!="") {
+ if (np.get_property().operator String() != "") {
path_cache.push_back(Path());
- ERR_EXPLAIN("Method Track has property: "+np);
- ERR_CONTINUE(np.get_property().operator String()!="");
-
+ ERR_EXPLAIN("Method Track has property: " + np);
+ ERR_CONTINUE(np.get_property().operator String() != "");
}
-
}
-
- path.valid=true;
+ path.valid = true;
path_cache.push_back(path);
if (!connected_nodes.has(path.node)) {
connected_nodes.insert(path.node);
- path.node->connect("tree_exited",this,"_node_exit_tree",Node::make_binds(path.node),CONNECT_ONESHOT);
+ path.node->connect("tree_exited", this, "_node_exit_tree", Node::make_binds(path.node), CONNECT_ONESHOT);
}
-
-
-
}
-
-
- cache_dirty=false;
- cache_valid=true;
+ cache_dirty = false;
+ cache_valid = true;
}
-void AnimationCache::set_track_transform(int p_idx,const Transform& p_transform) {
+void AnimationCache::set_track_transform(int p_idx, const Transform &p_transform) {
if (cache_dirty)
_update_cache();
ERR_FAIL_COND(!cache_valid);
- ERR_FAIL_INDEX(p_idx,path_cache.size());
+ ERR_FAIL_INDEX(p_idx, path_cache.size());
Path &p = path_cache[p_idx];
if (!p.valid)
return;
@@ -234,47 +207,42 @@ void AnimationCache::set_track_transform(int p_idx,const Transform& p_transform)
ERR_FAIL_COND(!p.spatial);
if (p.skeleton) {
- p.skeleton->set_bone_pose(p.bone_idx,p_transform);
+ p.skeleton->set_bone_pose(p.bone_idx, p_transform);
} else {
p.spatial->set_transform(p_transform);
}
-
}
-void AnimationCache::set_track_value(int p_idx,const Variant& p_value) {
+void AnimationCache::set_track_value(int p_idx, const Variant &p_value) {
if (cache_dirty)
_update_cache();
ERR_FAIL_COND(!cache_valid);
- ERR_FAIL_INDEX(p_idx,path_cache.size());
+ ERR_FAIL_INDEX(p_idx, path_cache.size());
Path &p = path_cache[p_idx];
if (!p.valid)
return;
ERR_FAIL_COND(!p.object);
- p.object->set(p.property,p_value);
+ p.object->set(p.property, p_value);
}
-
-void AnimationCache::call_track(int p_idx,const StringName& p_method,const Variant** p_args,int p_argcount,Variant::CallError &r_error) {
+void AnimationCache::call_track(int p_idx, const StringName &p_method, const Variant **p_args, int p_argcount, Variant::CallError &r_error) {
if (cache_dirty)
_update_cache();
-
ERR_FAIL_COND(!cache_valid);
- ERR_FAIL_INDEX(p_idx,path_cache.size());
+ ERR_FAIL_INDEX(p_idx, path_cache.size());
Path &p = path_cache[p_idx];
if (!p.valid)
return;
ERR_FAIL_COND(!p.object);
- p.object->call(p_method,p_args,p_argcount,r_error);
-
+ p.object->call(p_method, p_args, p_argcount, r_error);
}
-
void AnimationCache::set_all(float p_time, float p_delta) {
if (cache_dirty)
@@ -283,104 +251,100 @@ void AnimationCache::set_all(float p_time, float p_delta) {
ERR_FAIL_COND(!cache_valid);
int tc = animation->get_track_count();
- for(int i=0;i<tc;i++) {
+ for (int i = 0; i < tc; i++) {
- switch(animation->track_get_type(i)) {
+ switch (animation->track_get_type(i)) {
case Animation::TYPE_TRANSFORM: {
- Vector3 loc,scale;
+ Vector3 loc, scale;
Quat rot;
- animation->transform_track_interpolate(i,p_time,&loc,&rot,&scale);
- Transform tr( Basis(rot), loc );
+ animation->transform_track_interpolate(i, p_time, &loc, &rot, &scale);
+ Transform tr(Basis(rot), loc);
tr.basis.scale(scale);
- set_track_transform(i,tr);
-
+ set_track_transform(i, tr);
} break;
case Animation::TYPE_VALUE: {
- if (animation->value_track_get_update_mode(i)==Animation::UPDATE_CONTINUOUS || (animation->value_track_get_update_mode(i)==Animation::UPDATE_DISCRETE && p_delta==0)) {
- Variant v = animation->value_track_interpolate(i,p_time);
- set_track_value(i,v);
+ if (animation->value_track_get_update_mode(i) == Animation::UPDATE_CONTINUOUS || (animation->value_track_get_update_mode(i) == Animation::UPDATE_DISCRETE && p_delta == 0)) {
+ Variant v = animation->value_track_interpolate(i, p_time);
+ set_track_value(i, v);
} else {
List<int> indices;
- animation->value_track_get_key_indices(i,p_time,p_delta,&indices);
+ animation->value_track_get_key_indices(i, p_time, p_delta, &indices);
- for(List<int>::Element *E=indices.front();E;E=E->next()) {
+ for (List<int>::Element *E = indices.front(); E; E = E->next()) {
- Variant v = animation->track_get_key_value(i,E->get());
- set_track_value(i,v);
+ Variant v = animation->track_get_key_value(i, E->get());
+ set_track_value(i, v);
}
-
}
} break;
case Animation::TYPE_METHOD: {
List<int> indices;
- animation->method_track_get_key_indices(i,p_time,p_delta,&indices);
+ animation->method_track_get_key_indices(i, p_time, p_delta, &indices);
- for(List<int>::Element *E=indices.front();E;E=E->next()) {
+ for (List<int>::Element *E = indices.front(); E; E = E->next()) {
- Vector<Variant> args = animation->method_track_get_params(i,E->get());
- StringName name = animation->method_track_get_name(i,E->get());
+ Vector<Variant> args = animation->method_track_get_params(i, E->get());
+ StringName name = animation->method_track_get_name(i, E->get());
Variant::CallError err;
if (!args.size()) {
- call_track(i,name,NULL,0,err);
+ call_track(i, name, NULL, 0, err);
} else {
- Vector<Variant*> argptrs;
+ Vector<Variant *> argptrs;
argptrs.resize(args.size());
- for(int j=0;j<args.size();j++) {
+ for (int j = 0; j < args.size(); j++) {
- argptrs[j]=&args[j];
+ argptrs[j] = &args[j];
}
- call_track(i,name,(const Variant**)&argptrs[0],args.size(),err);
+ call_track(i, name, (const Variant **)&argptrs[0], args.size(), err);
}
-
}
} break;
default: {}
}
}
-
}
-void AnimationCache::set_animation(const Ref<Animation>& p_animation) {
+void AnimationCache::set_animation(const Ref<Animation> &p_animation) {
_clear_cache();
if (animation.is_valid())
- animation->disconnect("changed",this,"_animation_changed");
+ animation->disconnect("changed", this, "_animation_changed");
- animation=p_animation;
+ animation = p_animation;
if (animation.is_valid())
- animation->connect("changed",this,"_animation_changed");
+ animation->connect("changed", this, "_animation_changed");
}
void AnimationCache::_bind_methods() {
- ClassDB::bind_method(D_METHOD("_node_exit_tree"),&AnimationCache::_node_exit_tree);
- ClassDB::bind_method(D_METHOD("_animation_changed"),&AnimationCache::_animation_changed);
+ ClassDB::bind_method(D_METHOD("_node_exit_tree"), &AnimationCache::_node_exit_tree);
+ ClassDB::bind_method(D_METHOD("_animation_changed"), &AnimationCache::_animation_changed);
}
-void AnimationCache::set_root(Node* p_root) {
+void AnimationCache::set_root(Node *p_root) {
_clear_cache();
- root=p_root;
+ root = p_root;
}
AnimationCache::AnimationCache() {
- root=NULL;
- cache_dirty=true;
- cache_valid=false;
+ root = NULL;
+ cache_dirty = true;
+ cache_valid = false;
}
diff --git a/scene/animation/animation_cache.h b/scene/animation/animation_cache.h
index 75e004c811..1668c62519 100644
--- a/scene/animation/animation_cache.h
+++ b/scene/animation/animation_cache.h
@@ -29,12 +29,12 @@
#ifndef ANIMATION_CACHE_H
#define ANIMATION_CACHE_H
-#include "scene/resources/animation.h"
#include "scene/3d/skeleton.h"
+#include "scene/resources/animation.h"
class AnimationCache : public Object {
- GDCLASS(AnimationCache,Object);
+ GDCLASS(AnimationCache, Object);
struct Path {
@@ -47,10 +47,17 @@ class AnimationCache : public Object {
int bone_idx;
StringName property;
bool valid;
- Path() { object=NULL; skeleton=NULL; node=NULL; bone_idx=-1; valid=false; spatial=NULL; }
+ Path() {
+ object = NULL;
+ skeleton = NULL;
+ node = NULL;
+ bone_idx = -1;
+ valid = false;
+ spatial = NULL;
+ }
};
- Set<Node*> connected_nodes;
+ Set<Node *> connected_nodes;
Vector<Path> path_cache;
Node *root;
@@ -65,19 +72,17 @@ class AnimationCache : public Object {
void _animation_changed();
protected:
-
static void _bind_methods();
public:
+ void set_track_transform(int p_idx, const Transform &p_transform);
+ void set_track_value(int p_idx, const Variant &p_value);
+ void call_track(int p_idx, const StringName &p_method, const Variant **p_args, int p_argcount, Variant::CallError &r_error);
- void set_track_transform(int p_idx,const Transform& p_transform);
- void set_track_value(int p_idx,const Variant& p_value);
- void call_track(int p_idx,const StringName& p_method,const Variant** p_args,int p_argcount,Variant::CallError &r_error);
-
- void set_all(float p_time, float p_delta=0);
+ void set_all(float p_time, float p_delta = 0);
- void set_animation(const Ref<Animation>& p_animation);
- void set_root(Node* p_root);
+ void set_animation(const Ref<Animation> &p_animation);
+ void set_root(Node *p_root);
AnimationCache();
};
diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp
index e9f1904fe9..dc9aa1758a 100644
--- a/scene/animation/animation_player.cpp
+++ b/scene/animation/animation_player.cpp
@@ -31,111 +31,104 @@
#include "message_queue.h"
#include "scene/scene_string_names.h"
-bool AnimationPlayer::_set(const StringName& p_name, const Variant& p_value) {
+bool AnimationPlayer::_set(const StringName &p_name, const Variant &p_value) {
- String name=p_name;
+ String name = p_name;
- if (p_name==SceneStringNames::get_singleton()->playback_speed || p_name==SceneStringNames::get_singleton()->speed) { //bw compatibility
+ if (p_name == SceneStringNames::get_singleton()->playback_speed || p_name == SceneStringNames::get_singleton()->speed) { //bw compatibility
set_speed_scale(p_value);
- } else if (p_name==SceneStringNames::get_singleton()->playback_active) {
+ } else if (p_name == SceneStringNames::get_singleton()->playback_active) {
set_active(p_value);
} else if (name.begins_with("playback/play")) {
- String which=p_value;
+ String which = p_value;
-
- if (which=="[stop]")
+ if (which == "[stop]")
stop();
else
play(which);
} else if (name.begins_with("anims/")) {
+ String which = name.get_slicec('/', 1);
- String which=name.get_slicec('/',1);
-
- add_animation(which,p_value);
+ add_animation(which, p_value);
} else if (name.begins_with("next/")) {
+ String which = name.get_slicec('/', 1);
+ animation_set_next(which, p_value);
- String which=name.get_slicec('/',1);
- animation_set_next(which,p_value);
-
- } else if (p_name==SceneStringNames::get_singleton()->blend_times) {
+ } else if (p_name == SceneStringNames::get_singleton()->blend_times) {
- Array array=p_value;
+ Array array = p_value;
int len = array.size();
- ERR_FAIL_COND_V(len%3,false);
+ ERR_FAIL_COND_V(len % 3, false);
+ for (int i = 0; i < len / 3; i++) {
- for(int i=0;i<len/3;i++) {
+ StringName from = array[i * 3 + 0];
+ StringName to = array[i * 3 + 1];
+ float time = array[i * 3 + 2];
- StringName from = array[i*3+0];
- StringName to = array[i*3+1];
- float time = array[i*3+2];
-
- set_blend_time(from,to,time);
+ set_blend_time(from, to, time);
}
- } else if (p_name==SceneStringNames::get_singleton()->autoplay) {
- autoplay=p_value;
+ } else if (p_name == SceneStringNames::get_singleton()->autoplay) {
+ autoplay = p_value;
} else
return false;
return true;
-
}
-bool AnimationPlayer::_get(const StringName& p_name,Variant &r_ret) const {
+bool AnimationPlayer::_get(const StringName &p_name, Variant &r_ret) const {
- String name=p_name;
+ String name = p_name;
- if (name=="playback/speed") { //bw compatibility
+ if (name == "playback/speed") { //bw compatibility
- r_ret=speed_scale;
- } else if (name=="playback/active") {
+ r_ret = speed_scale;
+ } else if (name == "playback/active") {
- r_ret=is_active();
- } else if (name=="playback/play") {
+ r_ret = is_active();
+ } else if (name == "playback/play") {
if (is_active() && is_playing())
- r_ret=playback.assigned;
+ r_ret = playback.assigned;
else
- r_ret="[stop]";
+ r_ret = "[stop]";
} else if (name.begins_with("anims/")) {
- String which=name.get_slicec('/',1);
+ String which = name.get_slicec('/', 1);
- r_ret= get_animation(which).get_ref_ptr();
+ r_ret = get_animation(which).get_ref_ptr();
} else if (name.begins_with("next/")) {
- String which=name.get_slicec('/',1);
+ String which = name.get_slicec('/', 1);
- r_ret= animation_get_next(which);
+ r_ret = animation_get_next(which);
-
- } else if (name=="blend_times") {
+ } else if (name == "blend_times") {
Vector<BlendKey> keys;
- for(Map<BlendKey, float >::Element *E=blend_times.front();E;E=E->next()) {
+ for (Map<BlendKey, float>::Element *E = blend_times.front(); E; E = E->next()) {
keys.ordered_insert(E->key());
}
Array array;
- for(int i=0;i<keys.size();i++) {
+ for (int i = 0; i < keys.size(); i++) {
array.push_back(keys[i].from);
array.push_back(keys[i].to);
array.push_back(blend_times[keys[i]]);
}
- r_ret=array;
- } else if (name=="autoplay") {
- r_ret=autoplay;
-
+ r_ret = array;
+ } else if (name == "autoplay") {
+ r_ret = autoplay;
} else
return false;
@@ -143,26 +136,23 @@ bool AnimationPlayer::_get(const StringName& p_name,Variant &r_ret) const {
return true;
}
-void AnimationPlayer::_get_property_list( List<PropertyInfo> *p_list) const {
-
-
-
+void AnimationPlayer::_get_property_list(List<PropertyInfo> *p_list) const {
List<String> names;
List<PropertyInfo> anim_names;
- for( Map<StringName, AnimationData>::Element *E=animation_set.front();E;E=E->next()) {
+ for (Map<StringName, AnimationData>::Element *E = animation_set.front(); E; E = E->next()) {
- anim_names.push_back( PropertyInfo( Variant::OBJECT, "anims/"+String(E->key()), PROPERTY_HINT_RESOURCE_TYPE, "Animation",PROPERTY_USAGE_NOEDITOR) );
- if (E->get().next!=StringName())
- anim_names.push_back( PropertyInfo( Variant::STRING, "next/"+String(E->key()), PROPERTY_HINT_NONE, "",PROPERTY_USAGE_NOEDITOR) );
+ anim_names.push_back(PropertyInfo(Variant::OBJECT, "anims/" + String(E->key()), PROPERTY_HINT_RESOURCE_TYPE, "Animation", PROPERTY_USAGE_NOEDITOR));
+ if (E->get().next != StringName())
+ anim_names.push_back(PropertyInfo(Variant::STRING, "next/" + String(E->key()), PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR));
names.push_back(E->key());
}
anim_names.sort();
- for( List<PropertyInfo>::Element *E=anim_names.front();E;E=E->next()) {
+ for (List<PropertyInfo>::Element *E = anim_names.front(); E; E = E->next()) {
p_list->push_back(E->get());
}
@@ -170,34 +160,30 @@ void AnimationPlayer::_get_property_list( List<PropertyInfo> *p_list) const {
names.sort();
names.push_front("[stop]");
String hint;
- for(List<String>::Element *E=names.front();E;E=E->next()) {
+ for (List<String>::Element *E = names.front(); E; E = E->next()) {
- if (E!=names.front())
- hint+=",";
- hint+=E->get();
+ if (E != names.front())
+ hint += ",";
+ hint += E->get();
}
- p_list->push_back( PropertyInfo( Variant::STRING, "playback/play", PROPERTY_HINT_ENUM, hint,PROPERTY_USAGE_EDITOR|PROPERTY_USAGE_ANIMATE_AS_TRIGGER) );
- p_list->push_back( PropertyInfo( Variant::BOOL, "playback/active", PROPERTY_HINT_NONE,"" ) );
- p_list->push_back( PropertyInfo( Variant::REAL, "playback/speed", PROPERTY_HINT_RANGE, "-64,64,0.01") );
-
+ p_list->push_back(PropertyInfo(Variant::STRING, "playback/play", PROPERTY_HINT_ENUM, hint, PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_ANIMATE_AS_TRIGGER));
+ p_list->push_back(PropertyInfo(Variant::BOOL, "playback/active", PROPERTY_HINT_NONE, ""));
+ p_list->push_back(PropertyInfo(Variant::REAL, "playback/speed", PROPERTY_HINT_RANGE, "-64,64,0.01"));
}
-
-
- p_list->push_back( PropertyInfo( Variant::ARRAY, "blend_times", PROPERTY_HINT_NONE, "",PROPERTY_USAGE_NOEDITOR) );
- p_list->push_back( PropertyInfo( Variant::STRING, "autoplay", PROPERTY_HINT_NONE, "",PROPERTY_USAGE_NOEDITOR) );
-
+ p_list->push_back(PropertyInfo(Variant::ARRAY, "blend_times", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR));
+ p_list->push_back(PropertyInfo(Variant::STRING, "autoplay", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR));
}
void AnimationPlayer::advance(float p_time) {
- _animation_process( p_time );
+ _animation_process(p_time);
}
void AnimationPlayer::_notification(int p_what) {
- switch(p_what) {
+ switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
@@ -218,19 +204,19 @@ void AnimationPlayer::_notification(int p_what) {
}
} break;
case NOTIFICATION_INTERNAL_PROCESS: {
- if (animation_process_mode==ANIMATION_PROCESS_FIXED)
+ if (animation_process_mode == ANIMATION_PROCESS_FIXED)
break;
if (processing)
- _animation_process( get_process_delta_time() );
+ _animation_process(get_process_delta_time());
} break;
case NOTIFICATION_INTERNAL_FIXED_PROCESS: {
- if (animation_process_mode==ANIMATION_PROCESS_IDLE)
+ if (animation_process_mode == ANIMATION_PROCESS_IDLE)
break;
if (processing)
- _animation_process( get_fixed_process_delta_time() );
+ _animation_process(get_fixed_process_delta_time());
} break;
case NOTIFICATION_EXIT_TREE: {
@@ -240,174 +226,164 @@ void AnimationPlayer::_notification(int p_what) {
}
}
-void AnimationPlayer::_generate_node_caches(AnimationData* p_anim) {
+void AnimationPlayer::_generate_node_caches(AnimationData *p_anim) {
Node *parent = get_node(root);
ERR_FAIL_COND(!parent);
- Animation *a=p_anim->animation.operator->();
+ Animation *a = p_anim->animation.operator->();
- p_anim->node_cache.resize( a->get_track_count() );
+ p_anim->node_cache.resize(a->get_track_count());
- for (int i=0;i<a->get_track_count();i++) {
+ for (int i = 0; i < a->get_track_count(); i++) {
- p_anim->node_cache[i]=NULL;
+ p_anim->node_cache[i] = NULL;
RES resource;
- Node *child = parent->get_node_and_resource(a->track_get_path(i),resource);
+ Node *child = parent->get_node_and_resource(a->track_get_path(i), resource);
if (!child) {
- ERR_EXPLAIN("On Animation: '"+p_anim->name+"', couldn't resolve track: '"+String(a->track_get_path(i))+"'");
+ ERR_EXPLAIN("On Animation: '" + p_anim->name + "', couldn't resolve track: '" + String(a->track_get_path(i)) + "'");
}
ERR_CONTINUE(!child); // couldn't find the child node
- uint32_t id=resource.is_valid()?resource->get_instance_ID():child->get_instance_ID();
- int bone_idx=-1;
+ uint32_t id = resource.is_valid() ? resource->get_instance_ID() : child->get_instance_ID();
+ int bone_idx = -1;
if (a->track_get_path(i).get_property() && child->cast_to<Skeleton>()) {
- bone_idx = child->cast_to<Skeleton>()->find_bone( a->track_get_path(i).get_property() );
- if (bone_idx==-1) {
+ bone_idx = child->cast_to<Skeleton>()->find_bone(a->track_get_path(i).get_property());
+ if (bone_idx == -1) {
continue;
}
}
{
- if (!child->is_connected("tree_exited",this,"_node_removed"))
- child->connect("tree_exited",this,"_node_removed",make_binds(child),CONNECT_ONESHOT);
+ if (!child->is_connected("tree_exited", this, "_node_removed"))
+ child->connect("tree_exited", this, "_node_removed", make_binds(child), CONNECT_ONESHOT);
}
TrackNodeCacheKey key;
- key.id=id;
- key.bone_idx=bone_idx;
-
+ key.id = id;
+ key.bone_idx = bone_idx;
if (node_cache_map.has(key)) {
- p_anim->node_cache[i]=&node_cache_map[key];
+ p_anim->node_cache[i] = &node_cache_map[key];
} else {
+ node_cache_map[key] = TrackNodeCache();
- node_cache_map[key]=TrackNodeCache();
-
- p_anim->node_cache[i]=&node_cache_map[key];
- p_anim->node_cache[i]->path=a->track_get_path(i);
- p_anim->node_cache[i]->node=child;
- p_anim->node_cache[i]->resource=resource;
- p_anim->node_cache[i]->node_2d=child->cast_to<Node2D>();
- if (a->track_get_type(i)==Animation::TYPE_TRANSFORM) {
+ p_anim->node_cache[i] = &node_cache_map[key];
+ p_anim->node_cache[i]->path = a->track_get_path(i);
+ p_anim->node_cache[i]->node = child;
+ p_anim->node_cache[i]->resource = resource;
+ p_anim->node_cache[i]->node_2d = child->cast_to<Node2D>();
+ if (a->track_get_type(i) == Animation::TYPE_TRANSFORM) {
// special cases and caches for transform tracks
// cache spatial
- p_anim->node_cache[i]->spatial=child->cast_to<Spatial>();
+ p_anim->node_cache[i]->spatial = child->cast_to<Spatial>();
// cache skeleton
- p_anim->node_cache[i]->skeleton=child->cast_to<Skeleton>();
+ p_anim->node_cache[i]->skeleton = child->cast_to<Skeleton>();
if (p_anim->node_cache[i]->skeleton) {
- StringName bone_name=a->track_get_path(i).get_property();
- if (bone_name.operator String()!="") {
+ StringName bone_name = a->track_get_path(i).get_property();
+ if (bone_name.operator String() != "") {
- p_anim->node_cache[i]->bone_idx=p_anim->node_cache[i]->skeleton->find_bone(bone_name);
- if (p_anim->node_cache[i]->bone_idx<0) {
+ p_anim->node_cache[i]->bone_idx = p_anim->node_cache[i]->skeleton->find_bone(bone_name);
+ if (p_anim->node_cache[i]->bone_idx < 0) {
// broken track (nonexistent bone)
- p_anim->node_cache[i]->skeleton=NULL;
- p_anim->node_cache[i]->spatial=NULL;
+ p_anim->node_cache[i]->skeleton = NULL;
+ p_anim->node_cache[i]->spatial = NULL;
printf("bone is %ls\n", String(bone_name).c_str());
- ERR_CONTINUE( p_anim->node_cache[i]->bone_idx<0 );
+ ERR_CONTINUE(p_anim->node_cache[i]->bone_idx < 0);
} else {
}
} else {
// no property, just use spatialnode
- p_anim->node_cache[i]->skeleton=NULL;
+ p_anim->node_cache[i]->skeleton = NULL;
}
-
}
}
}
- if (a->track_get_type(i)==Animation::TYPE_VALUE) {
+ if (a->track_get_type(i) == Animation::TYPE_VALUE) {
StringName property = a->track_get_path(i).get_property();
if (!p_anim->node_cache[i]->property_anim.has(property)) {
TrackNodeCache::PropertyAnim pa;
- pa.prop=property;
- pa.object=resource.is_valid()?(Object*)resource.ptr():(Object*)child;
- pa.special=SP_NONE;
- pa.owner=p_anim->node_cache[i];
+ pa.prop = property;
+ pa.object = resource.is_valid() ? (Object *)resource.ptr() : (Object *)child;
+ pa.special = SP_NONE;
+ pa.owner = p_anim->node_cache[i];
if (false && p_anim->node_cache[i]->node_2d) {
- if (pa.prop==SceneStringNames::get_singleton()->transform_pos)
- pa.special=SP_NODE2D_POS;
- else if (pa.prop==SceneStringNames::get_singleton()->transform_rot)
- pa.special=SP_NODE2D_ROT;
- else if (pa.prop==SceneStringNames::get_singleton()->transform_scale)
- pa.special=SP_NODE2D_SCALE;
+ if (pa.prop == SceneStringNames::get_singleton()->transform_pos)
+ pa.special = SP_NODE2D_POS;
+ else if (pa.prop == SceneStringNames::get_singleton()->transform_rot)
+ pa.special = SP_NODE2D_ROT;
+ else if (pa.prop == SceneStringNames::get_singleton()->transform_scale)
+ pa.special = SP_NODE2D_SCALE;
}
- p_anim->node_cache[i]->property_anim[property]=pa;
+ p_anim->node_cache[i]->property_anim[property] = pa;
}
}
}
}
-
-void AnimationPlayer::_animation_process_animation(AnimationData* p_anim,float p_time, float p_delta,float p_interp, bool p_allow_discrete) {
+void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, float p_time, float p_delta, float p_interp, bool p_allow_discrete) {
if (p_anim->node_cache.size() != p_anim->animation->get_track_count()) {
// animation hasn't been "node-cached"
_generate_node_caches(p_anim);
}
+ ERR_FAIL_COND(p_anim->node_cache.size() != p_anim->animation->get_track_count());
- ERR_FAIL_COND( p_anim->node_cache.size() != p_anim->animation->get_track_count() );
-
-
- Animation *a=p_anim->animation.operator->();
+ Animation *a = p_anim->animation.operator->();
bool can_call = is_inside_tree() && !get_tree()->is_editor_hint();
- for (int i=0;i<a->get_track_count();i++) {
+ for (int i = 0; i < a->get_track_count(); i++) {
- TrackNodeCache *nc=p_anim->node_cache[i];
+ TrackNodeCache *nc = p_anim->node_cache[i];
if (!nc) // no node cache for this track, skip it
continue;
- if (a->track_get_key_count(i)==0)
+ if (a->track_get_key_count(i) == 0)
continue; // do nothing if track is empty
- switch(a->track_get_type(i)) {
+ switch (a->track_get_type(i)) {
case Animation::TYPE_TRANSFORM: {
if (!nc->spatial)
continue;
-
Vector3 loc;
Quat rot;
Vector3 scale;
-
- Error err = a->transform_track_interpolate(i,p_time,&loc,&rot,&scale);
+ Error err = a->transform_track_interpolate(i, p_time, &loc, &rot, &scale);
//ERR_CONTINUE(err!=OK); //used for testing, should be removed
-
- if (err!=OK)
+ if (err != OK)
continue;
- if (nc->accum_pass!=accum_pass) {
- ERR_CONTINUE( cache_update_size >= NODE_CACHE_UPDATE_MAX );
- cache_update[cache_update_size++]=nc;
- nc->accum_pass=accum_pass;
- nc->loc_accum=loc;
- nc->rot_accum=rot;
- nc->scale_accum=scale;
+ if (nc->accum_pass != accum_pass) {
+ ERR_CONTINUE(cache_update_size >= NODE_CACHE_UPDATE_MAX);
+ cache_update[cache_update_size++] = nc;
+ nc->accum_pass = accum_pass;
+ nc->loc_accum = loc;
+ nc->rot_accum = rot;
+ nc->scale_accum = scale;
} else {
- nc->loc_accum=nc->loc_accum.linear_interpolate(loc,p_interp);
- nc->rot_accum=nc->rot_accum.slerp(rot,p_interp);
- nc->scale_accum=nc->scale_accum.linear_interpolate(scale,p_interp);
-
+ nc->loc_accum = nc->loc_accum.linear_interpolate(loc, p_interp);
+ nc->rot_accum = nc->rot_accum.slerp(rot, p_interp);
+ nc->scale_accum = nc->scale_accum.linear_interpolate(scale, p_interp);
}
} break;
@@ -418,82 +394,76 @@ void AnimationPlayer::_animation_process_animation(AnimationData* p_anim,float p
//StringName property=a->track_get_path(i).get_property();
- Map<StringName,TrackNodeCache::PropertyAnim>::Element *E=nc->property_anim.find(a->track_get_path(i).get_property());
+ Map<StringName, TrackNodeCache::PropertyAnim>::Element *E = nc->property_anim.find(a->track_get_path(i).get_property());
ERR_CONTINUE(!E); //should it continue, or create a new one?
TrackNodeCache::PropertyAnim *pa = &E->get();
+ if (a->value_track_get_update_mode(i) == Animation::UPDATE_CONTINUOUS || (p_delta == 0 && a->value_track_get_update_mode(i) == Animation::UPDATE_DISCRETE)) { //delta == 0 means seek
- if (a->value_track_get_update_mode(i)==Animation::UPDATE_CONTINUOUS || (p_delta==0 && a->value_track_get_update_mode(i)==Animation::UPDATE_DISCRETE)) { //delta == 0 means seek
-
-
- Variant value=a->value_track_interpolate(i,p_time);
+ Variant value = a->value_track_interpolate(i, p_time);
//thanks to trigger mode, this should be solved now..
/*
if (p_delta==0 && value.get_type()==Variant::STRING)
continue; // doing this with strings is messy, should find another way
*/
- if (pa->accum_pass!=accum_pass) {
- ERR_CONTINUE( cache_update_prop_size >= NODE_CACHE_UPDATE_MAX );
- cache_update_prop[cache_update_prop_size++]=pa;
- pa->value_accum=value;
- pa->accum_pass=accum_pass;
+ if (pa->accum_pass != accum_pass) {
+ ERR_CONTINUE(cache_update_prop_size >= NODE_CACHE_UPDATE_MAX);
+ cache_update_prop[cache_update_prop_size++] = pa;
+ pa->value_accum = value;
+ pa->accum_pass = accum_pass;
} else {
- Variant::interpolate(pa->value_accum,value,p_interp,pa->value_accum);
+ Variant::interpolate(pa->value_accum, value, p_interp, pa->value_accum);
}
-
- } else if (p_allow_discrete && p_delta!=0) {
+ } else if (p_allow_discrete && p_delta != 0) {
List<int> indices;
- a->value_track_get_key_indices(i,p_time,p_delta,&indices);
-
+ a->value_track_get_key_indices(i, p_time, p_delta, &indices);
- for(List<int>::Element *F=indices.front();F;F=F->next()) {
+ for (List<int>::Element *F = indices.front(); F; F = F->next()) {
- Variant value=a->track_get_key_value(i,F->get());
- switch(pa->special) {
+ Variant value = a->track_get_key_value(i, F->get());
+ switch (pa->special) {
case SP_NONE: {
bool valid;
- pa->object->set(pa->prop,value,&valid); //you are not speshul
+ pa->object->set(pa->prop, value, &valid); //you are not speshul
#ifdef DEBUG_ENABLED
if (!valid) {
- ERR_PRINTS("Failed setting track value '"+String(pa->owner->path)+"'. Check if property exists or the type of key is valid");
+ ERR_PRINTS("Failed setting track value '" + String(pa->owner->path) + "'. Check if property exists or the type of key is valid");
}
#endif
} break;
case SP_NODE2D_POS: {
#ifdef DEBUG_ENABLED
- if (value.get_type()!=Variant::VECTOR2) {
- ERR_PRINTS("Position key at time "+rtos(p_time)+" in Animation Track '"+String(pa->owner->path)+"' not of type Vector2()");
+ if (value.get_type() != Variant::VECTOR2) {
+ ERR_PRINTS("Position key at time " + rtos(p_time) + " in Animation Track '" + String(pa->owner->path) + "' not of type Vector2()");
}
#endif
- static_cast<Node2D*>(pa->object)->set_position(value);
+ static_cast<Node2D *>(pa->object)->set_position(value);
} break;
case SP_NODE2D_ROT: {
#ifdef DEBUG_ENABLED
if (value.is_num()) {
- ERR_PRINTS("Rotation key at time "+rtos(p_time)+" in Animation Track '"+String(pa->owner->path)+"' not numerical");
+ ERR_PRINTS("Rotation key at time " + rtos(p_time) + " in Animation Track '" + String(pa->owner->path) + "' not numerical");
}
#endif
- static_cast<Node2D*>(pa->object)->set_rotation(Math::deg2rad((double)value));
+ static_cast<Node2D *>(pa->object)->set_rotation(Math::deg2rad((double)value));
} break;
case SP_NODE2D_SCALE: {
#ifdef DEBUG_ENABLED
- if (value.get_type()!=Variant::VECTOR2) {
- ERR_PRINTS("Scale key at time "+rtos(p_time)+" in Animation Track '"+String(pa->owner->path)+"' not of type Vector2()");
+ if (value.get_type() != Variant::VECTOR2) {
+ ERR_PRINTS("Scale key at time " + rtos(p_time) + " in Animation Track '" + String(pa->owner->path) + "' not of type Vector2()");
}
#endif
- static_cast<Node2D*>(pa->object)->set_scale(value);
+ static_cast<Node2D *>(pa->object)->set_scale(value);
} break;
}
-
}
-
}
} break;
@@ -501,154 +471,142 @@ void AnimationPlayer::_animation_process_animation(AnimationData* p_anim,float p
if (!nc->node)
continue;
- if (p_delta==0)
+ if (p_delta == 0)
continue;
if (!p_allow_discrete)
break;
List<int> indices;
- a->method_track_get_key_indices(i,p_time,p_delta,&indices);
+ a->method_track_get_key_indices(i, p_time, p_delta, &indices);
- for(List<int>::Element *E=indices.front();E;E=E->next()) {
+ for (List<int>::Element *E = indices.front(); E; E = E->next()) {
- StringName method=a->method_track_get_name(i,E->get());
- Vector<Variant> params=a->method_track_get_params(i,E->get());
+ StringName method = a->method_track_get_name(i, E->get());
+ Vector<Variant> params = a->method_track_get_params(i, E->get());
- int s=params.size();
+ int s = params.size();
- ERR_CONTINUE( s > VARIANT_ARG_MAX );
+ ERR_CONTINUE(s > VARIANT_ARG_MAX);
if (can_call) {
MessageQueue::get_singleton()->push_call(
- nc->node,
- method,
- s>=1 ? params[0] : Variant(),
- s>=2 ? params[1] : Variant(),
- s>=3 ? params[2] : Variant(),
- s>=4 ? params[3] : Variant(),
- s>=5 ? params[4] : Variant()
- );
+ nc->node,
+ method,
+ s >= 1 ? params[0] : Variant(),
+ s >= 2 ? params[1] : Variant(),
+ s >= 3 ? params[2] : Variant(),
+ s >= 4 ? params[3] : Variant(),
+ s >= 5 ? params[4] : Variant());
}
}
-
} break;
}
}
}
-void AnimationPlayer::_animation_process_data(PlaybackData &cd,float p_delta,float p_blend) {
+void AnimationPlayer::_animation_process_data(PlaybackData &cd, float p_delta, float p_blend) {
- float delta=p_delta*speed_scale*cd.speed_scale;
- bool backwards=delta<0;
- float next_pos=cd.pos+delta;
+ float delta = p_delta * speed_scale * cd.speed_scale;
+ bool backwards = delta < 0;
+ float next_pos = cd.pos + delta;
- float len=cd.from->animation->get_length();
- bool loop=cd.from->animation->has_loop();
+ float len = cd.from->animation->get_length();
+ bool loop = cd.from->animation->has_loop();
if (!loop) {
- if (next_pos<0)
- next_pos=0;
- else if (next_pos>len)
- next_pos=len;
+ if (next_pos < 0)
+ next_pos = 0;
+ else if (next_pos > len)
+ next_pos = len;
// fix delta
- delta=next_pos-cd.pos;
+ delta = next_pos - cd.pos;
if (&cd == &playback.current) {
- if (!backwards && cd.pos < len && next_pos==len /*&& playback.blend.empty()*/) {
+ if (!backwards && cd.pos < len && next_pos == len /*&& playback.blend.empty()*/) {
//playback finished
- end_notify=true;
+ end_notify = true;
}
- if (backwards && cd.pos > 0 && next_pos==0 /*&& playback.blend.empty()*/) {
+ if (backwards && cd.pos > 0 && next_pos == 0 /*&& playback.blend.empty()*/) {
//playback finished
- end_notify=true;
+ end_notify = true;
}
-
}
} else {
- next_pos=Math::fposmod(next_pos,len);
-
+ next_pos = Math::fposmod(next_pos, len);
}
- cd.pos=next_pos;
-
- _animation_process_animation(cd.from,cd.pos,delta,p_blend,&cd == &playback.current);
-
-
+ cd.pos = next_pos;
+ _animation_process_animation(cd.from, cd.pos, delta, p_blend, &cd == &playback.current);
}
void AnimationPlayer::_animation_process2(float p_delta) {
-
- Playback &c=playback;
+ Playback &c = playback;
accum_pass++;
- _animation_process_data(c.current,p_delta,1.0f);
+ _animation_process_data(c.current, p_delta, 1.0f);
List<Blend>::Element *prev = NULL;
- for (List<Blend>::Element *E=c.blend.back();E;E=prev) {
+ for (List<Blend>::Element *E = c.blend.back(); E; E = prev) {
- Blend& b=E->get();
- float blend=b.blend_left/b.blend_time;
- _animation_process_data(b.data,p_delta,blend);
+ Blend &b = E->get();
+ float blend = b.blend_left / b.blend_time;
+ _animation_process_data(b.data, p_delta, blend);
- b.blend_left-=Math::absf(speed_scale*p_delta);
+ b.blend_left -= Math::absf(speed_scale * p_delta);
prev = E->prev();
- if (b.blend_left<0) {
+ if (b.blend_left < 0) {
c.blend.erase(E);
}
}
-
-
}
void AnimationPlayer::_animation_update_transforms() {
+ for (int i = 0; i < cache_update_size; i++) {
- for (int i=0;i<cache_update_size;i++) {
+ TrackNodeCache *nc = cache_update[i];
- TrackNodeCache *nc=cache_update[i];
-
- ERR_CONTINUE( nc->accum_pass!=accum_pass );
+ ERR_CONTINUE(nc->accum_pass != accum_pass);
if (nc->spatial) {
Transform t;
- t.origin=nc->loc_accum;
- t.basis=nc->rot_accum;
- t.basis.scale( nc->scale_accum );
+ t.origin = nc->loc_accum;
+ t.basis = nc->rot_accum;
+ t.basis.scale(nc->scale_accum);
- if (nc->skeleton && nc->bone_idx>=0) {
+ if (nc->skeleton && nc->bone_idx >= 0) {
- nc->skeleton->set_bone_pose( nc->bone_idx, t );
+ nc->skeleton->set_bone_pose(nc->bone_idx, t);
} else if (nc->spatial) {
nc->spatial->set_transform(t);
}
}
-
}
- cache_update_size=0;
+ cache_update_size = 0;
- for (int i=0;i<cache_update_prop_size;i++) {
+ for (int i = 0; i < cache_update_prop_size; i++) {
- TrackNodeCache::PropertyAnim *pa=cache_update_prop[i];
+ TrackNodeCache::PropertyAnim *pa = cache_update_prop[i];
- ERR_CONTINUE( pa->accum_pass!=accum_pass );
+ ERR_CONTINUE(pa->accum_pass != accum_pass);
#if 1
-/* switch(pa->special) {
+ /* switch(pa->special) {
case SP_NONE: pa->object->set(pa->prop,pa->value_accum); break; //you are not speshul
@@ -657,63 +615,61 @@ void AnimationPlayer::_animation_update_transforms() {
case SP_NODE2D_SCALE: static_cast<Node2D*>(pa->object)->set_scale(pa->value_accum); break;
}*/
- switch(pa->special) {
+ switch (pa->special) {
case SP_NONE: {
bool valid;
- pa->object->set(pa->prop,pa->value_accum,&valid); //you are not speshul
+ pa->object->set(pa->prop, pa->value_accum, &valid); //you are not speshul
#ifdef DEBUG_ENABLED
if (!valid) {
- ERR_PRINTS("Failed setting key at time "+rtos(playback.current.pos)+" in Animation '"+get_current_animation()+"', Track '"+String(pa->owner->path)+"'. Check if property exists or the type of key is right for the property");
+ ERR_PRINTS("Failed setting key at time " + rtos(playback.current.pos) + " in Animation '" + get_current_animation() + "', Track '" + String(pa->owner->path) + "'. Check if property exists or the type of key is right for the property");
}
#endif
} break;
case SP_NODE2D_POS: {
#ifdef DEBUG_ENABLED
- if (pa->value_accum.get_type()!=Variant::VECTOR2) {
- ERR_PRINTS("Position key at time "+rtos(playback.current.pos)+" in Animation '"+get_current_animation()+"', Track '"+String(pa->owner->path)+"' not of type Vector2()");
+ if (pa->value_accum.get_type() != Variant::VECTOR2) {
+ ERR_PRINTS("Position key at time " + rtos(playback.current.pos) + " in Animation '" + get_current_animation() + "', Track '" + String(pa->owner->path) + "' not of type Vector2()");
}
#endif
- static_cast<Node2D*>(pa->object)->set_position(pa->value_accum);
+ static_cast<Node2D *>(pa->object)->set_position(pa->value_accum);
} break;
case SP_NODE2D_ROT: {
#ifdef DEBUG_ENABLED
if (pa->value_accum.is_num()) {
- ERR_PRINTS("Rotation key at time "+rtos(playback.current.pos)+" in Animation '"+get_current_animation()+"', Track '"+String(pa->owner->path)+"' not numerical");
+ ERR_PRINTS("Rotation key at time " + rtos(playback.current.pos) + " in Animation '" + get_current_animation() + "', Track '" + String(pa->owner->path) + "' not numerical");
}
#endif
- static_cast<Node2D*>(pa->object)->set_rotation(Math::deg2rad((double)pa->value_accum));
+ static_cast<Node2D *>(pa->object)->set_rotation(Math::deg2rad((double)pa->value_accum));
} break;
case SP_NODE2D_SCALE: {
#ifdef DEBUG_ENABLED
- if (pa->value_accum.get_type()!=Variant::VECTOR2) {
- ERR_PRINTS("Scale key at time "+rtos(playback.current.pos)+" in Animation '"+get_current_animation()+"', Track '"+String(pa->owner->path)+"' not of type Vector2()");
+ if (pa->value_accum.get_type() != Variant::VECTOR2) {
+ ERR_PRINTS("Scale key at time " + rtos(playback.current.pos) + " in Animation '" + get_current_animation() + "', Track '" + String(pa->owner->path) + "' not of type Vector2()");
}
#endif
- static_cast<Node2D*>(pa->object)->set_scale(pa->value_accum);
+ static_cast<Node2D *>(pa->object)->set_scale(pa->value_accum);
} break;
}
#else
- pa->object->set(pa->prop,pa->value_accum);
+ pa->object->set(pa->prop, pa->value_accum);
#endif
}
- cache_update_prop_size=0;
+ cache_update_prop_size = 0;
}
void AnimationPlayer::_animation_process(float p_delta) {
-
-
//bool any_active=false;
if (playback.current.from) {
- end_notify=false;
+ end_notify = false;
_animation_process2(p_delta);
_animation_update_transforms();
if (end_notify) {
@@ -722,46 +678,44 @@ void AnimationPlayer::_animation_process(float p_delta) {
play(queued.front()->get());
String new_name = playback.assigned;
queued.pop_front();
- end_notify=false;
+ end_notify = false;
emit_signal(SceneStringNames::get_singleton()->animation_changed, old, new_name);
} else {
- //stop();
+ //stop();
playing = false;
_set_process(false);
- end_notify=false;
- emit_signal(SceneStringNames::get_singleton()->animation_finished,playback.assigned);
+ end_notify = false;
+ emit_signal(SceneStringNames::get_singleton()->animation_finished, playback.assigned);
}
}
} else {
_set_process(false);
}
-
}
-
-Error AnimationPlayer::add_animation(const StringName& p_name, const Ref<Animation>& p_animation) {
+Error AnimationPlayer::add_animation(const StringName &p_name, const Ref<Animation> &p_animation) {
#ifdef DEBUG_ENABLED
- ERR_EXPLAIN("Invalid animation name: "+String(p_name));
- ERR_FAIL_COND_V( String(p_name).find("/")!=-1 || String(p_name).find(":")!=-1 || String(p_name).find(",")!=-1 || String(p_name).find("[")!=-1, ERR_INVALID_PARAMETER );
+ ERR_EXPLAIN("Invalid animation name: " + String(p_name));
+ ERR_FAIL_COND_V(String(p_name).find("/") != -1 || String(p_name).find(":") != -1 || String(p_name).find(",") != -1 || String(p_name).find("[") != -1, ERR_INVALID_PARAMETER);
#endif
- ERR_FAIL_COND_V( p_animation.is_null() , ERR_INVALID_PARAMETER );
+ ERR_FAIL_COND_V(p_animation.is_null(), ERR_INVALID_PARAMETER);
//print_line("Add anim: "+String(p_name)+" name: "+p_animation->get_name());
if (animation_set.has(p_name)) {
_unref_anim(animation_set[p_name].animation);
- animation_set[p_name].animation=p_animation;
+ animation_set[p_name].animation = p_animation;
clear_caches();
} else {
AnimationData ad;
- ad.animation=p_animation;
- ad.name=p_name;
- animation_set[p_name]=ad;
+ ad.animation = p_animation;
+ ad.name = p_name;
+ animation_set[p_name] = ad;
}
_ref_anim(p_animation);
@@ -769,9 +723,9 @@ Error AnimationPlayer::add_animation(const StringName& p_name, const Ref<Animati
return OK;
}
-void AnimationPlayer::remove_animation(const StringName& p_name) {
+void AnimationPlayer::remove_animation(const StringName &p_name) {
- ERR_FAIL_COND(!animation_set.has(p_name) );
+ ERR_FAIL_COND(!animation_set.has(p_name));
stop_all();
_unref_anim(animation_set[p_name].animation);
@@ -779,154 +733,140 @@ void AnimationPlayer::remove_animation(const StringName& p_name) {
clear_caches();
_change_notify();
-
}
-void AnimationPlayer::_ref_anim(const Ref<Animation>& p_anim) {
+void AnimationPlayer::_ref_anim(const Ref<Animation> &p_anim) {
if (used_anims.has(p_anim))
used_anims[p_anim]++;
else {
- used_anims[p_anim]=1;
- Ref<Animation>(p_anim)->connect("changed",this,"_animation_changed");
+ used_anims[p_anim] = 1;
+ Ref<Animation>(p_anim)->connect("changed", this, "_animation_changed");
}
-
}
-void AnimationPlayer::_unref_anim(const Ref<Animation>& p_anim) {
+void AnimationPlayer::_unref_anim(const Ref<Animation> &p_anim) {
ERR_FAIL_COND(!used_anims.has(p_anim));
-
- int & n = used_anims[p_anim];
+ int &n = used_anims[p_anim];
n--;
- if (n==0) {
+ if (n == 0) {
- Ref<Animation>(p_anim)->disconnect("changed",this,"_animation_changed");
+ Ref<Animation>(p_anim)->disconnect("changed", this, "_animation_changed");
used_anims.erase(p_anim);
}
-
}
+void AnimationPlayer::rename_animation(const StringName &p_name, const StringName &p_new_name) {
-void AnimationPlayer::rename_animation(const StringName& p_name,const StringName& p_new_name) {
-
-
- ERR_FAIL_COND(!animation_set.has(p_name) );
- ERR_FAIL_COND( String(p_new_name).find("/")!=-1 || String(p_new_name).find(":")!=-1 );
- ERR_FAIL_COND( animation_set.has(p_new_name) );
+ ERR_FAIL_COND(!animation_set.has(p_name));
+ ERR_FAIL_COND(String(p_new_name).find("/") != -1 || String(p_new_name).find(":") != -1);
+ ERR_FAIL_COND(animation_set.has(p_new_name));
//print_line("Rename anim: "+String(p_name)+" name: "+String(p_new_name));
stop_all();
AnimationData ad = animation_set[p_name];
- ad.name=p_new_name;
+ ad.name = p_new_name;
animation_set.erase(p_name);
- animation_set[p_new_name]=ad;
+ animation_set[p_new_name] = ad;
List<BlendKey> to_erase;
- Map<BlendKey,float> to_insert;
- for(Map<BlendKey, float >::Element *E=blend_times.front();E;E=E->next()) {
-
- BlendKey bk=E->key();
- BlendKey new_bk=bk;
- bool erase=false;
- if (bk.from==p_name) {
- new_bk.from=p_new_name;
- erase=true;
+ Map<BlendKey, float> to_insert;
+ for (Map<BlendKey, float>::Element *E = blend_times.front(); E; E = E->next()) {
+
+ BlendKey bk = E->key();
+ BlendKey new_bk = bk;
+ bool erase = false;
+ if (bk.from == p_name) {
+ new_bk.from = p_new_name;
+ erase = true;
}
- if (bk.to==p_name) {
- new_bk.to=p_new_name;
- erase=true;
+ if (bk.to == p_name) {
+ new_bk.to = p_new_name;
+ erase = true;
}
if (erase) {
to_erase.push_back(bk);
- to_insert[new_bk]=E->get();
+ to_insert[new_bk] = E->get();
}
}
- while(to_erase.size()) {
+ while (to_erase.size()) {
blend_times.erase(to_erase.front()->get());
to_erase.pop_front();
}
- while(to_insert.size()) {
- blend_times[to_insert.front()->key()]=to_insert.front()->get();
+ while (to_insert.size()) {
+ blend_times[to_insert.front()->key()] = to_insert.front()->get();
to_insert.erase(to_insert.front());
}
- if (autoplay==p_name)
- autoplay=p_new_name;
+ if (autoplay == p_name)
+ autoplay = p_new_name;
clear_caches();
_change_notify();
}
-
-bool AnimationPlayer::has_animation(const StringName& p_name) const {
+bool AnimationPlayer::has_animation(const StringName &p_name) const {
return animation_set.has(p_name);
}
-Ref<Animation> AnimationPlayer::get_animation(const StringName& p_name) const {
+Ref<Animation> AnimationPlayer::get_animation(const StringName &p_name) const {
- ERR_FAIL_COND_V( !animation_set.has(p_name), Ref<Animation>() );
+ ERR_FAIL_COND_V(!animation_set.has(p_name), Ref<Animation>());
- const AnimationData& data = animation_set[p_name];
+ const AnimationData &data = animation_set[p_name];
return data.animation;
-
}
-void AnimationPlayer::get_animation_list( List<StringName> * p_animations) const {
+void AnimationPlayer::get_animation_list(List<StringName> *p_animations) const {
List<String> anims;
- for( Map<StringName, AnimationData>::Element *E=animation_set.front();E;E=E->next()) {
+ for (Map<StringName, AnimationData>::Element *E = animation_set.front(); E; E = E->next()) {
anims.push_back(E->key());
}
anims.sort();
- for(List<String>::Element *E=anims.front();E;E=E->next()) {
+ for (List<String>::Element *E = anims.front(); E; E = E->next()) {
p_animations->push_back(E->get());
}
-
}
-void AnimationPlayer::set_blend_time(const StringName& p_animation1, const StringName& p_animation2, float p_time) {
+void AnimationPlayer::set_blend_time(const StringName &p_animation1, const StringName &p_animation2, float p_time) {
- ERR_FAIL_COND(p_time<0);
+ ERR_FAIL_COND(p_time < 0);
BlendKey bk;
- bk.from=p_animation1;
- bk.to=p_animation2;
- if (p_time==0)
+ bk.from = p_animation1;
+ bk.to = p_animation2;
+ if (p_time == 0)
blend_times.erase(bk);
else
- blend_times[bk]=p_time;
-
+ blend_times[bk] = p_time;
}
-
-float AnimationPlayer::get_blend_time( const StringName& p_animation1, const StringName& p_animation2) const {
+float AnimationPlayer::get_blend_time(const StringName &p_animation1, const StringName &p_animation2) const {
BlendKey bk;
- bk.from=p_animation1;
- bk.to=p_animation2;
+ bk.from = p_animation1;
+ bk.to = p_animation2;
if (blend_times.has(bk))
return blend_times[bk];
else
return 0;
-
-
}
-
-void AnimationPlayer::queue(const StringName& p_name) {
+void AnimationPlayer::queue(const StringName &p_name) {
if (!is_playing())
play(p_name);
@@ -938,73 +878,73 @@ void AnimationPlayer::clear_queue() {
queued.clear();
};
-void AnimationPlayer::play_backwards(const StringName& p_name,float p_custom_blend) {
+void AnimationPlayer::play_backwards(const StringName &p_name, float p_custom_blend) {
- play(p_name,p_custom_blend,-1,true);
+ play(p_name, p_custom_blend, -1, true);
}
-void AnimationPlayer::play(const StringName& p_name, float p_custom_blend, float p_custom_scale,bool p_from_end) {
+void AnimationPlayer::play(const StringName &p_name, float p_custom_blend, float p_custom_scale, bool p_from_end) {
//printf("animation is %ls\n", String(p_name).c_str());
//ERR_FAIL_COND(!is_inside_scene());
- StringName name=p_name;
+ StringName name = p_name;
- if (String(name)=="")
- name=playback.assigned;
+ if (String(name) == "")
+ name = playback.assigned;
if (!animation_set.has(name)) {
- ERR_EXPLAIN("Animation not found: "+name);
+ ERR_EXPLAIN("Animation not found: " + name);
ERR_FAIL();
}
- Playback &c=playback;
+ Playback &c = playback;
if (c.current.from) {
- float blend_time=0;
+ float blend_time = 0;
// find if it can blend
BlendKey bk;
- bk.from=c.current.from->name;
- bk.to=name;
+ bk.from = c.current.from->name;
+ bk.to = name;
- if (p_custom_blend>=0) {
- blend_time=p_custom_blend;
+ if (p_custom_blend >= 0) {
+ blend_time = p_custom_blend;
} else if (blend_times.has(bk)) {
- blend_time=blend_times[bk];
+ blend_time = blend_times[bk];
} else {
- bk.from="*";
+ bk.from = "*";
if (blend_times.has(bk)) {
- blend_time=blend_times[bk];
+ blend_time = blend_times[bk];
} else {
- bk.from=c.current.from->name;
- bk.to="*";
+ bk.from = c.current.from->name;
+ bk.to = "*";
if (blend_times.has(bk)) {
- blend_time=blend_times[bk];
+ blend_time = blend_times[bk];
}
}
}
- if (p_custom_blend<0 && blend_time==0 && default_blend_time)
- blend_time=default_blend_time;
- if (blend_time>0) {
+ if (p_custom_blend < 0 && blend_time == 0 && default_blend_time)
+ blend_time = default_blend_time;
+ if (blend_time > 0) {
Blend b;
- b.data=c.current;
- b.blend_time=b.blend_left=blend_time;
+ b.data = c.current;
+ b.blend_time = b.blend_left = blend_time;
c.blend.push_back(b);
}
}
- c.current.from=&animation_set[name];
- c.current.pos=p_from_end ? c.current.from->animation->get_length() : 0;
- c.current.speed_scale=p_custom_scale;
- c.assigned=p_name;
+ c.current.from = &animation_set[name];
+ c.current.pos = p_from_end ? c.current.from->animation->get_length() : 0;
+ c.current.speed_scale = p_custom_scale;
+ c.assigned = p_name;
if (!end_notify)
queued.clear();
@@ -1013,20 +953,19 @@ void AnimationPlayer::play(const StringName& p_name, float p_custom_blend, float
emit_signal(SceneStringNames::get_singleton()->animation_started, c.assigned);
- if (is_inside_tree() && get_tree()->is_editor_hint())
+ if (is_inside_tree() && get_tree()->is_editor_hint())
return; // no next in this case
-
- StringName next=animation_get_next(p_name);
- if (next!=StringName() && animation_set.has(next)) {
+ StringName next = animation_get_next(p_name);
+ if (next != StringName() && animation_set.has(next)) {
queue(next);
}
}
bool AnimationPlayer::is_playing() const {
- return playing;
- /*
+ return playing;
+ /*
if (playback.current.from==NULL)
return false;
@@ -1040,30 +979,29 @@ bool AnimationPlayer::is_playing() const {
return true;
*/
}
-void AnimationPlayer::set_current_animation(const String& p_anim) {
+void AnimationPlayer::set_current_animation(const String &p_anim) {
if (is_playing()) {
play(p_anim);
} else {
ERR_FAIL_COND(!animation_set.has(p_anim));
- playback.current.pos=0;
- playback.current.from=&animation_set[p_anim];
- playback.assigned=p_anim;
+ playback.current.pos = 0;
+ playback.current.from = &animation_set[p_anim];
+ playback.assigned = p_anim;
}
}
String AnimationPlayer::get_current_animation() const {
return (playback.assigned);
-
}
void AnimationPlayer::stop(bool p_reset) {
- Playback &c=playback;
+ Playback &c = playback;
c.blend.clear();
if (p_reset) {
- c.current.from=NULL;
+ c.current.from = NULL;
}
_set_process(false);
queued.clear();
@@ -1075,22 +1013,18 @@ void AnimationPlayer::stop_all() {
stop();
_set_process(false); // always process when starting an animation
-
}
void AnimationPlayer::set_speed_scale(float p_speed) {
- speed_scale=p_speed;
-
-
+ speed_scale = p_speed;
}
float AnimationPlayer::get_speed_scale() const {
return speed_scale;
}
-void AnimationPlayer::seek(float p_time,bool p_update) {
-
+void AnimationPlayer::seek(float p_time, bool p_update) {
if (!playback.current.from) {
if (playback.assigned)
@@ -1098,13 +1032,13 @@ void AnimationPlayer::seek(float p_time,bool p_update) {
ERR_FAIL_COND(!playback.current.from);
}
- playback.current.pos=p_time;
+ playback.current.pos = p_time;
if (p_update) {
_animation_process(0);
}
}
-void AnimationPlayer::seek_delta(float p_time,float p_delta) {
+void AnimationPlayer::seek_delta(float p_time, float p_delta) {
if (!playback.current.from) {
if (playback.assigned)
@@ -1112,30 +1046,27 @@ void AnimationPlayer::seek_delta(float p_time,float p_delta) {
ERR_FAIL_COND(!playback.current.from);
}
-
- playback.current.pos=p_time-p_delta;
- if (speed_scale!=0.0)
- p_delta/=speed_scale;
+ playback.current.pos = p_time - p_delta;
+ if (speed_scale != 0.0)
+ p_delta /= speed_scale;
_animation_process(p_delta);
//playback.current.pos=p_time;
-
}
bool AnimationPlayer::is_valid() const {
return (playback.current.from);
-
}
float AnimationPlayer::get_current_animation_pos() const {
- ERR_FAIL_COND_V(!playback.current.from,0);
+ ERR_FAIL_COND_V(!playback.current.from, 0);
return playback.current.pos;
}
float AnimationPlayer::get_current_animation_length() const {
- ERR_FAIL_COND_V(!playback.current.from,0);
+ ERR_FAIL_COND_V(!playback.current.from, 0);
return playback.current.from->animation->get_length();
}
@@ -1151,27 +1082,24 @@ void AnimationPlayer::_node_removed(Node *p_node) {
void AnimationPlayer::clear_caches() {
-
node_cache_map.clear();
- for( Map<StringName, AnimationData>::Element *E=animation_set.front();E;E=E->next()) {
+ for (Map<StringName, AnimationData>::Element *E = animation_set.front(); E; E = E->next()) {
E->get().node_cache.clear();
}
- cache_update_size=0;
- cache_update_prop_size=0;
+ cache_update_size = 0;
+ cache_update_prop_size = 0;
}
void AnimationPlayer::set_active(bool p_active) {
- if (active==p_active)
+ if (active == p_active)
return;
- active=p_active;
- _set_process(processing,true);
-
-
+ active = p_active;
+ _set_process(processing, true);
}
bool AnimationPlayer::is_active() const {
@@ -1179,90 +1107,85 @@ bool AnimationPlayer::is_active() const {
return active;
}
-StringName AnimationPlayer::find_animation(const Ref<Animation>& p_animation) const {
+StringName AnimationPlayer::find_animation(const Ref<Animation> &p_animation) const {
- for( Map<StringName, AnimationData>::Element *E=animation_set.front();E;E=E->next()) {
+ for (Map<StringName, AnimationData>::Element *E = animation_set.front(); E; E = E->next()) {
- if (E->get().animation==p_animation)
+ if (E->get().animation == p_animation)
return E->key();
}
return "";
}
-void AnimationPlayer::set_autoplay(const String& p_name) {
+void AnimationPlayer::set_autoplay(const String &p_name) {
- autoplay=p_name;
+ autoplay = p_name;
}
-String AnimationPlayer::get_autoplay() const{
+String AnimationPlayer::get_autoplay() const {
return autoplay;
}
void AnimationPlayer::set_animation_process_mode(AnimationProcessMode p_mode) {
- if (animation_process_mode==p_mode)
+ if (animation_process_mode == p_mode)
return;
bool pr = processing;
if (pr)
_set_process(false);
- animation_process_mode=p_mode;
+ animation_process_mode = p_mode;
if (pr)
_set_process(true);
-
}
-AnimationPlayer::AnimationProcessMode AnimationPlayer::get_animation_process_mode() const{
+AnimationPlayer::AnimationProcessMode AnimationPlayer::get_animation_process_mode() const {
return animation_process_mode;
}
+void AnimationPlayer::_set_process(bool p_process, bool p_force) {
-void AnimationPlayer::_set_process(bool p_process,bool p_force) {
-
- if (processing==p_process && !p_force)
+ if (processing == p_process && !p_force)
return;
- switch(animation_process_mode) {
+ switch (animation_process_mode) {
case ANIMATION_PROCESS_FIXED: set_fixed_process_internal(p_process && active); break;
case ANIMATION_PROCESS_IDLE: set_process_internal(p_process && active); break;
}
- processing=p_process;
+ processing = p_process;
}
-void AnimationPlayer::animation_set_next(const StringName& p_animation, const StringName& p_next) {
+void AnimationPlayer::animation_set_next(const StringName &p_animation, const StringName &p_next) {
ERR_FAIL_COND(!animation_set.has(p_animation));
- animation_set[p_animation].next=p_next;
-
+ animation_set[p_animation].next = p_next;
}
-StringName AnimationPlayer::animation_get_next(const StringName& p_animation) const{
+StringName AnimationPlayer::animation_get_next(const StringName &p_animation) const {
if (!animation_set.has(p_animation))
return StringName();
return animation_set[p_animation].next;
-
}
void AnimationPlayer::set_default_blend_time(float p_default) {
- default_blend_time=p_default;
+ default_blend_time = p_default;
}
float AnimationPlayer::get_default_blend_time() const {
- return default_blend_time;
+ return default_blend_time;
}
+void AnimationPlayer::set_root(const NodePath &p_root) {
-void AnimationPlayer::set_root(const NodePath& p_root) {
-
- root=p_root;
+ root = p_root;
clear_caches();
}
@@ -1271,111 +1194,105 @@ NodePath AnimationPlayer::get_root() const {
return root;
}
-void AnimationPlayer::get_argument_options(const StringName& p_function,int p_idx,List<String>*r_options) const {
+void AnimationPlayer::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const {
String pf = p_function;
- if (p_function=="play" || p_function=="remove_animation" || p_function=="has_animation" || p_function=="queue") {
+ if (p_function == "play" || p_function == "remove_animation" || p_function == "has_animation" || p_function == "queue") {
List<StringName> al;
get_animation_list(&al);
- for (List<StringName>::Element *E=al.front();E;E=E->next()) {
+ for (List<StringName>::Element *E = al.front(); E; E = E->next()) {
- r_options->push_back("\""+String(E->get())+"\"");
+ r_options->push_back("\"" + String(E->get()) + "\"");
}
}
- Node::get_argument_options(p_function,p_idx,r_options);
+ Node::get_argument_options(p_function, p_idx, r_options);
}
void AnimationPlayer::_bind_methods() {
- ClassDB::bind_method(D_METHOD("_node_removed"),&AnimationPlayer::_node_removed);
- ClassDB::bind_method(D_METHOD("_animation_changed"),&AnimationPlayer::_animation_changed);
+ ClassDB::bind_method(D_METHOD("_node_removed"), &AnimationPlayer::_node_removed);
+ ClassDB::bind_method(D_METHOD("_animation_changed"), &AnimationPlayer::_animation_changed);
- ClassDB::bind_method(D_METHOD("add_animation","name","animation:Animation"),&AnimationPlayer::add_animation);
- ClassDB::bind_method(D_METHOD("remove_animation","name"),&AnimationPlayer::remove_animation);
- ClassDB::bind_method(D_METHOD("rename_animation","name","newname"),&AnimationPlayer::rename_animation);
- ClassDB::bind_method(D_METHOD("has_animation","name"),&AnimationPlayer::has_animation);
- ClassDB::bind_method(D_METHOD("get_animation:Animation","name"),&AnimationPlayer::get_animation);
- ClassDB::bind_method(D_METHOD("get_animation_list"),&AnimationPlayer::_get_animation_list);
+ ClassDB::bind_method(D_METHOD("add_animation", "name", "animation:Animation"), &AnimationPlayer::add_animation);
+ ClassDB::bind_method(D_METHOD("remove_animation", "name"), &AnimationPlayer::remove_animation);
+ ClassDB::bind_method(D_METHOD("rename_animation", "name", "newname"), &AnimationPlayer::rename_animation);
+ ClassDB::bind_method(D_METHOD("has_animation", "name"), &AnimationPlayer::has_animation);
+ ClassDB::bind_method(D_METHOD("get_animation:Animation", "name"), &AnimationPlayer::get_animation);
+ ClassDB::bind_method(D_METHOD("get_animation_list"), &AnimationPlayer::_get_animation_list);
ClassDB::bind_method(D_METHOD("animation_set_next", "anim_from", "anim_to"), &AnimationPlayer::animation_set_next);
ClassDB::bind_method(D_METHOD("animation_get_next", "anim_from"), &AnimationPlayer::animation_get_next);
- ClassDB::bind_method(D_METHOD("set_blend_time","anim_from","anim_to","sec"),&AnimationPlayer::set_blend_time);
- ClassDB::bind_method(D_METHOD("get_blend_time","anim_from","anim_to"),&AnimationPlayer::get_blend_time);
+ ClassDB::bind_method(D_METHOD("set_blend_time", "anim_from", "anim_to", "sec"), &AnimationPlayer::set_blend_time);
+ ClassDB::bind_method(D_METHOD("get_blend_time", "anim_from", "anim_to"), &AnimationPlayer::get_blend_time);
- ClassDB::bind_method(D_METHOD("set_default_blend_time","sec"),&AnimationPlayer::set_default_blend_time);
- ClassDB::bind_method(D_METHOD("get_default_blend_time"),&AnimationPlayer::get_default_blend_time);
+ ClassDB::bind_method(D_METHOD("set_default_blend_time", "sec"), &AnimationPlayer::set_default_blend_time);
+ ClassDB::bind_method(D_METHOD("get_default_blend_time"), &AnimationPlayer::get_default_blend_time);
- ClassDB::bind_method(D_METHOD("play","name","custom_blend","custom_speed","from_end"),&AnimationPlayer::play,DEFVAL(""),DEFVAL(-1),DEFVAL(1.0),DEFVAL(false));
- ClassDB::bind_method(D_METHOD("play_backwards","name","custom_blend"),&AnimationPlayer::play_backwards,DEFVAL(""),DEFVAL(-1));
- ClassDB::bind_method(D_METHOD("stop","reset"),&AnimationPlayer::stop,DEFVAL(true));
- ClassDB::bind_method(D_METHOD("stop_all"),&AnimationPlayer::stop_all);
- ClassDB::bind_method(D_METHOD("is_playing"),&AnimationPlayer::is_playing);
- ClassDB::bind_method(D_METHOD("set_current_animation","anim"),&AnimationPlayer::set_current_animation);
- ClassDB::bind_method(D_METHOD("get_current_animation"),&AnimationPlayer::get_current_animation);
- ClassDB::bind_method(D_METHOD("queue","name"),&AnimationPlayer::queue);
- ClassDB::bind_method(D_METHOD("clear_queue"),&AnimationPlayer::clear_queue);
+ ClassDB::bind_method(D_METHOD("play", "name", "custom_blend", "custom_speed", "from_end"), &AnimationPlayer::play, DEFVAL(""), DEFVAL(-1), DEFVAL(1.0), DEFVAL(false));
+ ClassDB::bind_method(D_METHOD("play_backwards", "name", "custom_blend"), &AnimationPlayer::play_backwards, DEFVAL(""), DEFVAL(-1));
+ ClassDB::bind_method(D_METHOD("stop", "reset"), &AnimationPlayer::stop, DEFVAL(true));
+ ClassDB::bind_method(D_METHOD("stop_all"), &AnimationPlayer::stop_all);
+ ClassDB::bind_method(D_METHOD("is_playing"), &AnimationPlayer::is_playing);
+ ClassDB::bind_method(D_METHOD("set_current_animation", "anim"), &AnimationPlayer::set_current_animation);
+ ClassDB::bind_method(D_METHOD("get_current_animation"), &AnimationPlayer::get_current_animation);
+ ClassDB::bind_method(D_METHOD("queue", "name"), &AnimationPlayer::queue);
+ ClassDB::bind_method(D_METHOD("clear_queue"), &AnimationPlayer::clear_queue);
- ClassDB::bind_method(D_METHOD("set_active","active"),&AnimationPlayer::set_active);
- ClassDB::bind_method(D_METHOD("is_active"),&AnimationPlayer::is_active);
+ ClassDB::bind_method(D_METHOD("set_active", "active"), &AnimationPlayer::set_active);
+ ClassDB::bind_method(D_METHOD("is_active"), &AnimationPlayer::is_active);
- ClassDB::bind_method(D_METHOD("set_speed_scale","speed"),&AnimationPlayer::set_speed_scale);
- ClassDB::bind_method(D_METHOD("get_speed_scale"),&AnimationPlayer::get_speed_scale);
+ ClassDB::bind_method(D_METHOD("set_speed_scale", "speed"), &AnimationPlayer::set_speed_scale);
+ ClassDB::bind_method(D_METHOD("get_speed_scale"), &AnimationPlayer::get_speed_scale);
- ClassDB::bind_method(D_METHOD("set_autoplay","name"),&AnimationPlayer::set_autoplay);
- ClassDB::bind_method(D_METHOD("get_autoplay"),&AnimationPlayer::get_autoplay);
+ ClassDB::bind_method(D_METHOD("set_autoplay", "name"), &AnimationPlayer::set_autoplay);
+ ClassDB::bind_method(D_METHOD("get_autoplay"), &AnimationPlayer::get_autoplay);
- ClassDB::bind_method(D_METHOD("set_root","path"),&AnimationPlayer::set_root);
- ClassDB::bind_method(D_METHOD("get_root"),&AnimationPlayer::get_root);
+ ClassDB::bind_method(D_METHOD("set_root", "path"), &AnimationPlayer::set_root);
+ ClassDB::bind_method(D_METHOD("get_root"), &AnimationPlayer::get_root);
- ClassDB::bind_method(D_METHOD("seek","pos_sec","update"),&AnimationPlayer::seek,DEFVAL(false));
- ClassDB::bind_method(D_METHOD("get_pos"),&AnimationPlayer::get_current_animation_pos);
+ ClassDB::bind_method(D_METHOD("seek", "pos_sec", "update"), &AnimationPlayer::seek, DEFVAL(false));
+ ClassDB::bind_method(D_METHOD("get_pos"), &AnimationPlayer::get_current_animation_pos);
- ClassDB::bind_method(D_METHOD("find_animation","animation:Animation"),&AnimationPlayer::find_animation);
+ ClassDB::bind_method(D_METHOD("find_animation", "animation:Animation"), &AnimationPlayer::find_animation);
- ClassDB::bind_method(D_METHOD("clear_caches"),&AnimationPlayer::clear_caches);
+ ClassDB::bind_method(D_METHOD("clear_caches"), &AnimationPlayer::clear_caches);
- ClassDB::bind_method(D_METHOD("set_animation_process_mode","mode"),&AnimationPlayer::set_animation_process_mode);
- ClassDB::bind_method(D_METHOD("get_animation_process_mode"),&AnimationPlayer::get_animation_process_mode);
+ ClassDB::bind_method(D_METHOD("set_animation_process_mode", "mode"), &AnimationPlayer::set_animation_process_mode);
+ ClassDB::bind_method(D_METHOD("get_animation_process_mode"), &AnimationPlayer::get_animation_process_mode);
- ClassDB::bind_method(D_METHOD("get_current_animation_pos"),&AnimationPlayer::get_current_animation_pos);
- ClassDB::bind_method(D_METHOD("get_current_animation_length"),&AnimationPlayer::get_current_animation_length);
+ ClassDB::bind_method(D_METHOD("get_current_animation_pos"), &AnimationPlayer::get_current_animation_pos);
+ ClassDB::bind_method(D_METHOD("get_current_animation_length"), &AnimationPlayer::get_current_animation_length);
- ClassDB::bind_method(D_METHOD("advance","delta"),&AnimationPlayer::advance);
+ ClassDB::bind_method(D_METHOD("advance", "delta"), &AnimationPlayer::advance);
+ ADD_GROUP("Playback", "playback_");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "playback_process_mode", PROPERTY_HINT_ENUM, "Fixed,Idle"), "set_animation_process_mode", "get_animation_process_mode");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "playback_default_blend_time", PROPERTY_HINT_RANGE, "0,4096,0.01"), "set_default_blend_time", "get_default_blend_time");
+ ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "root_node"), "set_root", "get_root");
- ADD_GROUP("Playback","playback_");
- ADD_PROPERTY( PropertyInfo( Variant::INT, "playback_process_mode", PROPERTY_HINT_ENUM, "Fixed,Idle"), "set_animation_process_mode", "get_animation_process_mode");
- ADD_PROPERTY( PropertyInfo( Variant::REAL, "playback_default_blend_time", PROPERTY_HINT_RANGE, "0,4096,0.01"), "set_default_blend_time", "get_default_blend_time");
- ADD_PROPERTY( PropertyInfo( Variant::NODE_PATH, "root_node"), "set_root", "get_root");
+ ADD_SIGNAL(MethodInfo("animation_finished", PropertyInfo(Variant::STRING, "name")));
+ ADD_SIGNAL(MethodInfo("animation_changed", PropertyInfo(Variant::STRING, "old_name"), PropertyInfo(Variant::STRING, "new_name")));
+ ADD_SIGNAL(MethodInfo("animation_started", PropertyInfo(Variant::STRING, "name")));
- ADD_SIGNAL( MethodInfo("animation_finished", PropertyInfo(Variant::STRING,"name")) );
- ADD_SIGNAL( MethodInfo("animation_changed", PropertyInfo(Variant::STRING,"old_name"), PropertyInfo(Variant::STRING,"new_name")) );
- ADD_SIGNAL( MethodInfo("animation_started", PropertyInfo(Variant::STRING,"name")) );
-
- BIND_CONSTANT( ANIMATION_PROCESS_FIXED );
- BIND_CONSTANT( ANIMATION_PROCESS_IDLE );
+ BIND_CONSTANT(ANIMATION_PROCESS_FIXED);
+ BIND_CONSTANT(ANIMATION_PROCESS_IDLE);
}
AnimationPlayer::AnimationPlayer() {
-
- accum_pass=1;
- cache_update_size=0;
- cache_update_prop_size=0;
- speed_scale=1;
- end_notify=false;
- animation_process_mode=ANIMATION_PROCESS_IDLE;
- processing=false;
- default_blend_time=0;
- root=SceneStringNames::get_singleton()->path_pp;
+ accum_pass = 1;
+ cache_update_size = 0;
+ cache_update_prop_size = 0;
+ speed_scale = 1;
+ end_notify = false;
+ animation_process_mode = ANIMATION_PROCESS_IDLE;
+ processing = false;
+ default_blend_time = 0;
+ root = SceneStringNames::get_singleton()->path_pp;
playing = false;
- active=true;
+ active = true;
}
-
-AnimationPlayer::~AnimationPlayer()
-{
+AnimationPlayer::~AnimationPlayer() {
}
-
-
diff --git a/scene/animation/animation_player.h b/scene/animation/animation_player.h
index 7fab651213..b5679d62f1 100644
--- a/scene/animation/animation_player.h
+++ b/scene/animation/animation_player.h
@@ -29,35 +29,31 @@
#ifndef ANIMATION_PLAYER_H
#define ANIMATION_PLAYER_H
-
-#include "scene/resources/animation.h"
-#include "scene/3d/spatial.h"
-#include "scene/3d/skeleton.h"
#include "scene/2d/node_2d.h"
+#include "scene/3d/skeleton.h"
+#include "scene/3d/spatial.h"
+#include "scene/resources/animation.h"
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
class AnimationPlayer : public Node {
- GDCLASS( AnimationPlayer, Node );
+ GDCLASS(AnimationPlayer, Node);
OBJ_CATEGORY("Animation Nodes");
public:
-
enum AnimationProcessMode {
ANIMATION_PROCESS_FIXED,
ANIMATION_PROCESS_IDLE,
};
private:
-
enum {
- NODE_CACHE_UPDATE_MAX=1024,
- BLEND_FROM_MAX=3
+ NODE_CACHE_UPDATE_MAX = 1024,
+ BLEND_FROM_MAX = 3
};
-
enum SpecialProperty {
SP_NONE,
SP_NODE2D_POS,
@@ -71,8 +67,8 @@ private:
uint32_t id;
RES resource;
Node *node;
- Spatial* spatial;
- Node2D* node_2d;
+ Spatial *spatial;
+ Node2D *node_2d;
Skeleton *skeleton;
int bone_idx;
// accumulated transforms
@@ -90,14 +86,22 @@ private:
Object *object;
Variant value_accum;
uint64_t accum_pass;
- PropertyAnim() { accum_pass=0; object=NULL; }
+ PropertyAnim() {
+ accum_pass = 0;
+ object = NULL;
+ }
};
- Map<StringName,PropertyAnim> property_anim;
-
-
- TrackNodeCache() { skeleton=NULL; spatial=NULL; node=NULL; accum_pass=0; bone_idx=-1; node_2d=NULL; }
+ Map<StringName, PropertyAnim> property_anim;
+ TrackNodeCache() {
+ skeleton = NULL;
+ spatial = NULL;
+ node = NULL;
+ accum_pass = 0;
+ bone_idx = -1;
+ node_2d = NULL;
+ }
};
struct TrackNodeCacheKey {
@@ -105,36 +109,34 @@ private:
uint32_t id;
int bone_idx;
- inline bool operator<(const TrackNodeCacheKey& p_right) const {
+ inline bool operator<(const TrackNodeCacheKey &p_right) const {
- if (id<p_right.id)
+ if (id < p_right.id)
return true;
- else if (id>p_right.id)
+ else if (id > p_right.id)
return false;
else
- return bone_idx<p_right.bone_idx;
+ return bone_idx < p_right.bone_idx;
}
};
- Map<TrackNodeCacheKey,TrackNodeCache> node_cache_map;
+ Map<TrackNodeCacheKey, TrackNodeCache> node_cache_map;
- TrackNodeCache* cache_update[NODE_CACHE_UPDATE_MAX];
+ TrackNodeCache *cache_update[NODE_CACHE_UPDATE_MAX];
int cache_update_size;
- TrackNodeCache::PropertyAnim* cache_update_prop[NODE_CACHE_UPDATE_MAX];
+ TrackNodeCache::PropertyAnim *cache_update_prop[NODE_CACHE_UPDATE_MAX];
int cache_update_prop_size;
- Map<Ref<Animation>,int> used_anims;
+ Map<Ref<Animation>, int> used_anims;
uint64_t accum_pass;
- float speed_scale;
- float default_blend_time;
-
+ float speed_scale;
+ float default_blend_time;
struct AnimationData {
String name;
StringName next;
- Vector<TrackNodeCache*> node_cache;
+ Vector<TrackNodeCache *> node_cache;
Ref<Animation> animation;
-
};
Map<StringName, AnimationData> animation_set;
@@ -142,27 +144,23 @@ private:
StringName from;
StringName to;
- bool operator<(const BlendKey& bk) const { return from==bk.from?String(to)<String(bk.to):String(from)<String(bk.from); }
+ bool operator<(const BlendKey &bk) const { return from == bk.from ? String(to) < String(bk.to) : String(from) < String(bk.from); }
};
-
- Map<BlendKey, float > blend_times;
-
+ Map<BlendKey, float> blend_times;
struct PlaybackData {
- AnimationData* from;
+ AnimationData *from;
float pos;
float speed_scale;
PlaybackData() {
- pos=0;
- speed_scale=1.0;
- from=NULL;
-
+ pos = 0;
+ speed_scale = 1.0;
+ from = NULL;
}
-
};
struct Blend {
@@ -174,8 +172,8 @@ private:
Blend() {
- blend_left=0;
- blend_time=0;
+ blend_left = 0;
+ blend_time = 0;
}
};
@@ -197,75 +195,73 @@ private:
NodePath root;
- void _animation_process_animation(AnimationData* p_anim,float p_time, float p_delta,float p_interp, bool p_allow_discrete=true);
+ void _animation_process_animation(AnimationData *p_anim, float p_time, float p_delta, float p_interp, bool p_allow_discrete = true);
- void _generate_node_caches(AnimationData* p_anim);
- void _animation_process_data(PlaybackData &cd,float p_delta,float p_blend);
+ void _generate_node_caches(AnimationData *p_anim);
+ void _animation_process_data(PlaybackData &cd, float p_delta, float p_blend);
void _animation_process2(float p_delta);
void _animation_update_transforms();
void _animation_process(float p_delta);
void _node_removed(Node *p_node);
-// bind helpers
+ // bind helpers
PoolVector<String> _get_animation_list() const {
List<StringName> animations;
get_animation_list(&animations);
PoolVector<String> ret;
- while(animations.size()) {
+ while (animations.size()) {
- ret.push_back( animations.front()->get());
+ ret.push_back(animations.front()->get());
animations.pop_front();
}
return ret;
}
void _animation_changed();
- void _ref_anim(const Ref<Animation>& p_anim);
- void _unref_anim(const Ref<Animation>& p_anim);
+ void _ref_anim(const Ref<Animation> &p_anim);
+ void _unref_anim(const Ref<Animation> &p_anim);
+ void _set_process(bool p_process, bool p_force = false);
- void _set_process(bool p_process,bool p_force=false);
-
- bool playing;
+ bool playing;
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;
+ 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);
static void _bind_methods();
public:
+ StringName find_animation(const Ref<Animation> &p_animation) const;
- StringName find_animation(const Ref<Animation>& p_animation) const;
-
- Error add_animation(const StringName& p_name, const Ref<Animation>& p_animation);
- void remove_animation(const StringName& p_name);
- void rename_animation(const StringName& p_name,const StringName& p_new_name);
- bool has_animation(const StringName& p_name) const;
- Ref<Animation> get_animation(const StringName& p_name) const;
- void get_animation_list( List<StringName> * p_animations) const;
+ Error add_animation(const StringName &p_name, const Ref<Animation> &p_animation);
+ void remove_animation(const StringName &p_name);
+ void rename_animation(const StringName &p_name, const StringName &p_new_name);
+ bool has_animation(const StringName &p_name) const;
+ Ref<Animation> get_animation(const StringName &p_name) const;
+ void get_animation_list(List<StringName> *p_animations) const;
- void set_blend_time(const StringName& p_animation1, const StringName& p_animation2, float p_time);
- float get_blend_time( const StringName& p_animation1, const StringName& p_animation2) const;
+ void set_blend_time(const StringName &p_animation1, const StringName &p_animation2, float p_time);
+ float get_blend_time(const StringName &p_animation1, const StringName &p_animation2) const;
- void animation_set_next(const StringName& p_animation, const StringName& p_next);
- StringName animation_get_next(const StringName& p_animation) const;
+ void animation_set_next(const StringName &p_animation, const StringName &p_next);
+ StringName animation_get_next(const StringName &p_animation) const;
- void set_default_blend_time(float p_default);
- float get_default_blend_time() const;
+ void set_default_blend_time(float p_default);
+ float get_default_blend_time() const;
- void play(const StringName& p_name=StringName(),float p_custom_blend=-1,float p_custom_scale=1.0,bool p_from_end=false);
- void play_backwards(const StringName& p_name=StringName(),float p_custom_blend=-1);
- void queue(const StringName& p_name);
+ void play(const StringName &p_name = StringName(), float p_custom_blend = -1, float p_custom_scale = 1.0, bool p_from_end = false);
+ void play_backwards(const StringName &p_name = StringName(), float p_custom_blend = -1);
+ void queue(const StringName &p_name);
void clear_queue();
- void stop(bool p_reset=true);
+ void stop(bool p_reset = true);
bool is_playing() const;
String get_current_animation() const;
- void set_current_animation(const String& p_anim);
+ void set_current_animation(const String &p_anim);
void stop_all();
void set_active(bool p_active);
bool is_active() const;
@@ -274,34 +270,30 @@ public:
void set_speed_scale(float p_speed);
float get_speed_scale() const;
- void set_autoplay(const String& pname);
+ void set_autoplay(const String &pname);
String get_autoplay() const;
void set_animation_process_mode(AnimationProcessMode p_mode);
AnimationProcessMode get_animation_process_mode() const;
- void seek(float p_time,bool p_update=false);
- void seek_delta(float p_time,float p_delta);
+ void seek(float p_time, bool p_update = false);
+ void seek_delta(float p_time, float p_delta);
float get_current_animation_pos() const;
float get_current_animation_length() const;
void advance(float p_time);
- void set_root(const NodePath& p_root);
+ void set_root(const NodePath &p_root);
NodePath get_root() const;
void clear_caches(); ///< must be called by hand if an animation was modified after added
- void get_argument_options(const StringName& p_function,int p_idx,List<String>*r_options) const;
-
+ void get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const;
AnimationPlayer();
~AnimationPlayer();
-
};
-
-VARIANT_ENUM_CAST( AnimationPlayer::AnimationProcessMode );
-
+VARIANT_ENUM_CAST(AnimationPlayer::AnimationProcessMode);
#endif
diff --git a/scene/animation/animation_tree_player.cpp b/scene/animation/animation_tree_player.cpp
index d7e98ddd2b..6f4279526a 100644
--- a/scene/animation/animation_tree_player.cpp
+++ b/scene/animation/animation_tree_player.cpp
@@ -31,7 +31,6 @@
#include "scene/scene_string_names.h"
-
void AnimationTreePlayer::set_animation_process_mode(AnimationProcessMode p_mode) {
if (animation_process_mode == p_mode)
@@ -43,322 +42,312 @@ void AnimationTreePlayer::set_animation_process_mode(AnimationProcessMode p_mode
animation_process_mode = p_mode;
if (pr)
_set_process(true);
-
}
-AnimationTreePlayer::AnimationProcessMode AnimationTreePlayer::get_animation_process_mode() const{
+AnimationTreePlayer::AnimationProcessMode AnimationTreePlayer::get_animation_process_mode() const {
return animation_process_mode;
}
-void AnimationTreePlayer::_set_process(bool p_process, bool p_force)
-{
+void AnimationTreePlayer::_set_process(bool p_process, bool p_force) {
if (processing == p_process && !p_force)
return;
switch (animation_process_mode) {
- case ANIMATION_PROCESS_FIXED: set_fixed_process_internal(p_process && active); break;
- case ANIMATION_PROCESS_IDLE: set_process_internal(p_process && active); break;
+ case ANIMATION_PROCESS_FIXED: set_fixed_process_internal(p_process && active); break;
+ case ANIMATION_PROCESS_IDLE: set_process_internal(p_process && active); break;
}
processing = p_process;
}
+bool AnimationTreePlayer::_set(const StringName &p_name, const Variant &p_value) {
-bool AnimationTreePlayer::_set(const StringName& p_name, const Variant& p_value) {
-
- if (String(p_name)=="base_path") {
+ if (String(p_name) == "base_path") {
set_base_path(p_value);
return true;
}
- if (String(p_name)=="master_player") {
+ if (String(p_name) == "master_player") {
set_master_player(p_value);
return true;
}
- if(String(p_name) == SceneStringNames::get_singleton()->playback_active) {
+ if (String(p_name) == SceneStringNames::get_singleton()->playback_active) {
set_active(p_value);
return true;
}
- if (String(p_name)!="data")
+ if (String(p_name) != "data")
return false;
+ Dictionary data = p_value;
- Dictionary data=p_value;
+ Array nodes = data.get_valid("nodes");
- Array nodes=data.get_valid("nodes");
-
- for(int i=0;i<nodes.size();i++) {
+ for (int i = 0; i < nodes.size(); i++) {
Dictionary node = nodes[i];
StringName id = node.get_valid("id");
Point2 pos = node.get_valid("pos");
- NodeType nt=NODE_MAX;
+ NodeType nt = NODE_MAX;
String type = node.get_valid("type");
- if (type=="output")
- nt=NODE_OUTPUT;
- else if (type=="animation")
- nt=NODE_ANIMATION;
- else if (type=="oneshot")
- nt=NODE_ONESHOT;
- else if (type=="mix")
- nt=NODE_MIX;
- else if (type=="blend2")
- nt=NODE_BLEND2;
- else if (type=="blend3")
- nt=NODE_BLEND3;
- else if (type=="blend4")
- nt=NODE_BLEND4;
- else if (type=="timescale")
- nt=NODE_TIMESCALE;
- else if (type=="timeseek")
- nt=NODE_TIMESEEK;
- else if (type=="transition")
- nt=NODE_TRANSITION;
-
- ERR_FAIL_COND_V(nt==NODE_MAX,false);
-
- if (nt!=NODE_OUTPUT)
- add_node(nt,id);
- node_set_pos(id,pos);
-
-
- switch(nt) {
+ if (type == "output")
+ nt = NODE_OUTPUT;
+ else if (type == "animation")
+ nt = NODE_ANIMATION;
+ else if (type == "oneshot")
+ nt = NODE_ONESHOT;
+ else if (type == "mix")
+ nt = NODE_MIX;
+ else if (type == "blend2")
+ nt = NODE_BLEND2;
+ else if (type == "blend3")
+ nt = NODE_BLEND3;
+ else if (type == "blend4")
+ nt = NODE_BLEND4;
+ else if (type == "timescale")
+ nt = NODE_TIMESCALE;
+ else if (type == "timeseek")
+ nt = NODE_TIMESEEK;
+ else if (type == "transition")
+ nt = NODE_TRANSITION;
+
+ ERR_FAIL_COND_V(nt == NODE_MAX, false);
+
+ if (nt != NODE_OUTPUT)
+ add_node(nt, id);
+ node_set_pos(id, pos);
+
+ switch (nt) {
case NODE_OUTPUT: {
} break;
case NODE_ANIMATION: {
if (node.has("from"))
- animation_node_set_master_animation(id,node.get_valid("from"));
+ animation_node_set_master_animation(id, node.get_valid("from"));
else
- animation_node_set_animation(id,node.get_valid("animation"));
- Array filters= node.get_valid("filter");
- for(int i=0;i<filters.size();i++) {
+ animation_node_set_animation(id, node.get_valid("animation"));
+ Array filters = node.get_valid("filter");
+ for (int i = 0; i < filters.size(); i++) {
- animation_node_set_filter_path(id,filters[i],true);
+ animation_node_set_filter_path(id, filters[i], true);
}
- } break;
+ } break;
case NODE_ONESHOT: {
- oneshot_node_set_fadein_time(id,node.get_valid("fade_in"));
- oneshot_node_set_fadeout_time(id,node.get_valid("fade_out"));
- oneshot_node_set_mix_mode(id,node.get_valid("mix"));
- oneshot_node_set_autorestart(id,node.get_valid("autorestart"));
- oneshot_node_set_autorestart_delay(id,node.get_valid("autorestart_delay"));
- oneshot_node_set_autorestart_random_delay(id,node.get_valid("autorestart_random_delay"));
- Array filters= node.get_valid("filter");
- for(int i=0;i<filters.size();i++) {
+ oneshot_node_set_fadein_time(id, node.get_valid("fade_in"));
+ oneshot_node_set_fadeout_time(id, node.get_valid("fade_out"));
+ oneshot_node_set_mix_mode(id, node.get_valid("mix"));
+ oneshot_node_set_autorestart(id, node.get_valid("autorestart"));
+ oneshot_node_set_autorestart_delay(id, node.get_valid("autorestart_delay"));
+ oneshot_node_set_autorestart_random_delay(id, node.get_valid("autorestart_random_delay"));
+ Array filters = node.get_valid("filter");
+ for (int i = 0; i < filters.size(); i++) {
- oneshot_node_set_filter_path(id,filters[i],true);
+ oneshot_node_set_filter_path(id, filters[i], true);
}
} break;
case NODE_MIX: {
- mix_node_set_amount(id,node.get_valid("mix"));
+ mix_node_set_amount(id, node.get_valid("mix"));
} break;
case NODE_BLEND2: {
- blend2_node_set_amount(id,node.get_valid("blend"));
- Array filters= node.get_valid("filter");
- for(int i=0;i<filters.size();i++) {
+ blend2_node_set_amount(id, node.get_valid("blend"));
+ Array filters = node.get_valid("filter");
+ for (int i = 0; i < filters.size(); i++) {
- blend2_node_set_filter_path(id,filters[i],true);
+ blend2_node_set_filter_path(id, filters[i], true);
}
} break;
case NODE_BLEND3: {
- blend3_node_set_amount(id,node.get_valid("blend"));
+ blend3_node_set_amount(id, node.get_valid("blend"));
} break;
case NODE_BLEND4: {
- blend4_node_set_amount(id,node.get_valid("blend"));
+ blend4_node_set_amount(id, node.get_valid("blend"));
} break;
case NODE_TIMESCALE: {
- timescale_node_set_scale(id,node.get_valid("scale"));
+ timescale_node_set_scale(id, node.get_valid("scale"));
} break;
case NODE_TIMESEEK: {
} break;
case NODE_TRANSITION: {
- transition_node_set_xfade_time(id,node.get_valid("xfade"));
+ transition_node_set_xfade_time(id, node.get_valid("xfade"));
Array transitions = node.get_valid("transitions");
- transition_node_set_input_count(id,transitions.size());
+ transition_node_set_input_count(id, transitions.size());
- for(int x=0;x<transitions.size();x++) {
+ for (int x = 0; x < transitions.size(); x++) {
- Dictionary d =transitions[x];
+ Dictionary d = transitions[x];
bool aa = d.get_valid("auto_advance");
- transition_node_set_input_auto_advance(id,x,aa);
-
+ transition_node_set_input_auto_advance(id, x, aa);
}
} break;
default: {};
}
-
}
-
Array connections = data.get_valid("connections");
- ERR_FAIL_COND_V(connections.size()%3,false);
+ ERR_FAIL_COND_V(connections.size() % 3, false);
- int cc=connections.size()/3;
+ int cc = connections.size() / 3;
- for(int i=0;i<cc;i++) {
+ for (int i = 0; i < cc; i++) {
- StringName src = connections[i*3+0];
- StringName dst = connections[i*3+1];
- int dst_in = connections[i*3+2];
- connect_nodes(src,dst,dst_in);
+ StringName src = connections[i * 3 + 0];
+ StringName dst = connections[i * 3 + 1];
+ int dst_in = connections[i * 3 + 2];
+ connect_nodes(src, dst, dst_in);
}
set_active(data.get_valid("active"));
set_master_player(data.get_valid("master"));
return true;
-
}
-bool AnimationTreePlayer::_get(const StringName& p_name,Variant &r_ret) const {
+bool AnimationTreePlayer::_get(const StringName &p_name, Variant &r_ret) const {
- if (String(p_name)=="base_path") {
- r_ret=base_path;
+ if (String(p_name) == "base_path") {
+ r_ret = base_path;
return true;
}
- if (String(p_name)=="master_player") {
- r_ret=master;
+ if (String(p_name) == "master_player") {
+ r_ret = master;
return true;
}
if (String(p_name) == "playback/active") {
- r_ret=is_active();
+ r_ret = is_active();
return true;
}
- if (String(p_name)!="data")
+ if (String(p_name) != "data")
return false;
Dictionary data;
Array nodes;
- for(Map<StringName,NodeBase*>::Element *E=node_map.front();E;E=E->next()) {
+ for (Map<StringName, NodeBase *>::Element *E = node_map.front(); E; E = E->next()) {
NodeBase *n = node_map[E->key()];
Dictionary node;
- node["id"]=E->key();
- node["pos"]=n->pos;
-
- switch(n->type) {
- case NODE_OUTPUT: node["type"]= "output"; break;
- case NODE_ANIMATION: node["type"]= "animation"; break;
- case NODE_ONESHOT: node["type"]= "oneshot"; break;
- case NODE_MIX: node["type"]= "mix"; break;
- case NODE_BLEND2: node["type"]= "blend2"; break;
- case NODE_BLEND3: node["type"]= "blend3"; break;
- case NODE_BLEND4: node["type"]= "blend4"; break;
- case NODE_TIMESCALE: node["type"]= "timescale"; break;
- case NODE_TIMESEEK: node["type"]= "timeseek"; break;
- case NODE_TRANSITION: node["type"]= "transition"; break;
- default: node["type"]= ""; break;
+ node["id"] = E->key();
+ node["pos"] = n->pos;
+
+ switch (n->type) {
+ case NODE_OUTPUT: node["type"] = "output"; break;
+ case NODE_ANIMATION: node["type"] = "animation"; break;
+ case NODE_ONESHOT: node["type"] = "oneshot"; break;
+ case NODE_MIX: node["type"] = "mix"; break;
+ case NODE_BLEND2: node["type"] = "blend2"; break;
+ case NODE_BLEND3: node["type"] = "blend3"; break;
+ case NODE_BLEND4: node["type"] = "blend4"; break;
+ case NODE_TIMESCALE: node["type"] = "timescale"; break;
+ case NODE_TIMESEEK: node["type"] = "timeseek"; break;
+ case NODE_TRANSITION: node["type"] = "transition"; break;
+ default: node["type"] = ""; break;
}
- switch(n->type) {
+ switch (n->type) {
case NODE_OUTPUT: {
} break;
case NODE_ANIMATION: {
- AnimationNode *an = static_cast<AnimationNode*>(n);
- if (master!=NodePath() && an->from!="") {
- node["from"]=an->from;
+ AnimationNode *an = static_cast<AnimationNode *>(n);
+ if (master != NodePath() && an->from != "") {
+ node["from"] = an->from;
} else {
- node["animation"]=an->animation;
+ node["animation"] = an->animation;
}
Array k;
List<NodePath> keys;
an->filter.get_key_list(&keys);
k.resize(keys.size());
- int i=0;
- for(List<NodePath>::Element *E=keys.front();E;E=E->next()) {
- k[i++]=E->get();
+ int i = 0;
+ for (List<NodePath>::Element *E = keys.front(); E; E = E->next()) {
+ k[i++] = E->get();
}
- node["filter"]=k;
- } break;
+ node["filter"] = k;
+ } break;
case NODE_ONESHOT: {
- OneShotNode *osn = static_cast<OneShotNode*>(n);
- node["fade_in"]=osn->fade_in;
- node["fade_out"]=osn->fade_out;
- node["mix"]=osn->mix;
- node["autorestart"]=osn->autorestart;
- node["autorestart_delay"]=osn->autorestart_delay;
- node["autorestart_random_delay"]=osn->autorestart_random_delay;
+ OneShotNode *osn = static_cast<OneShotNode *>(n);
+ node["fade_in"] = osn->fade_in;
+ node["fade_out"] = osn->fade_out;
+ node["mix"] = osn->mix;
+ node["autorestart"] = osn->autorestart;
+ node["autorestart_delay"] = osn->autorestart_delay;
+ node["autorestart_random_delay"] = osn->autorestart_random_delay;
Array k;
List<NodePath> keys;
osn->filter.get_key_list(&keys);
k.resize(keys.size());
- int i=0;
- for(List<NodePath>::Element *E=keys.front();E;E=E->next()) {
- k[i++]=E->get();
+ int i = 0;
+ for (List<NodePath>::Element *E = keys.front(); E; E = E->next()) {
+ k[i++] = E->get();
}
- node["filter"]=k;
+ node["filter"] = k;
} break;
case NODE_MIX: {
- MixNode *mn = static_cast<MixNode*>(n);
- node["mix"]=mn->amount;
+ MixNode *mn = static_cast<MixNode *>(n);
+ node["mix"] = mn->amount;
} break;
case NODE_BLEND2: {
- Blend2Node *bn = static_cast<Blend2Node*>(n);
- node["blend"]=bn->value;
+ Blend2Node *bn = static_cast<Blend2Node *>(n);
+ node["blend"] = bn->value;
Array k;
List<NodePath> keys;
bn->filter.get_key_list(&keys);
k.resize(keys.size());
- int i=0;
- for(List<NodePath>::Element *E=keys.front();E;E=E->next()) {
- k[i++]=E->get();
+ int i = 0;
+ for (List<NodePath>::Element *E = keys.front(); E; E = E->next()) {
+ k[i++] = E->get();
}
- node["filter"]=k;
+ node["filter"] = k;
} break;
case NODE_BLEND3: {
- Blend3Node *bn = static_cast<Blend3Node*>(n);
- node["blend"]=bn->value;
+ Blend3Node *bn = static_cast<Blend3Node *>(n);
+ node["blend"] = bn->value;
} break;
case NODE_BLEND4: {
- Blend4Node *bn = static_cast<Blend4Node*>(n);
- node["blend"]=bn->value;
+ Blend4Node *bn = static_cast<Blend4Node *>(n);
+ node["blend"] = bn->value;
} break;
case NODE_TIMESCALE: {
- TimeScaleNode *tsn = static_cast<TimeScaleNode*>(n);
- node["scale"]=tsn->scale;
+ TimeScaleNode *tsn = static_cast<TimeScaleNode *>(n);
+ node["scale"] = tsn->scale;
} break;
case NODE_TIMESEEK: {
} break;
case NODE_TRANSITION: {
- TransitionNode *tn = static_cast<TransitionNode*>(n);
- node["xfade"]=tn->xfade;
+ TransitionNode *tn = static_cast<TransitionNode *>(n);
+ node["xfade"] = tn->xfade;
Array transitions;
- for(int i=0;i<tn->input_data.size();i++) {
+ for (int i = 0; i < tn->input_data.size(); i++) {
Dictionary d;
- d["auto_advance"]=tn->input_data[i].auto_advance;
+ d["auto_advance"] = tn->input_data[i].auto_advance;
transitions.push_back(d);
-
}
- node["transitions"]=transitions;
+ node["transitions"] = transitions;
} break;
default: {};
@@ -367,39 +356,38 @@ bool AnimationTreePlayer::_get(const StringName& p_name,Variant &r_ret) const {
nodes.push_back(node);
}
- data["nodes"]=nodes;
+ data["nodes"] = nodes;
//connectiosn
List<Connection> connections;
get_connection_list(&connections);
Array connections_arr;
- connections_arr.resize(connections.size()*3);
+ connections_arr.resize(connections.size() * 3);
- int idx=0;
- for (List<Connection>::Element *E=connections.front();E;E=E->next()) {
+ int idx = 0;
+ for (List<Connection>::Element *E = connections.front(); E; E = E->next()) {
- connections_arr.set(idx+0,E->get().src_node);
- connections_arr.set(idx+1,E->get().dst_node);
- connections_arr.set(idx+2,E->get().dst_input);
+ connections_arr.set(idx + 0, E->get().src_node);
+ connections_arr.set(idx + 1, E->get().dst_node);
+ connections_arr.set(idx + 2, E->get().dst_input);
- idx+=3;
+ idx += 3;
}
- data["connections"]=connections_arr;
- data["active"]=active;
- data["master"]=master;
+ data["connections"] = connections_arr;
+ data["active"] = active;
+ data["master"] = master;
- r_ret=data;
+ r_ret = data;
return true;
-
}
-void AnimationTreePlayer::_get_property_list( List<PropertyInfo> *p_list) const {
+void AnimationTreePlayer::_get_property_list(List<PropertyInfo> *p_list) const {
- p_list->push_back( PropertyInfo(Variant::NODE_PATH,"base_path" ) );
- p_list->push_back( PropertyInfo(Variant::NODE_PATH,"master_player" ) );
- p_list->push_back( PropertyInfo(Variant::DICTIONARY,"data",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_STORAGE|PROPERTY_USAGE_NETWORK) );
+ p_list->push_back(PropertyInfo(Variant::NODE_PATH, "base_path"));
+ p_list->push_back(PropertyInfo(Variant::NODE_PATH, "master_player"));
+ p_list->push_back(PropertyInfo(Variant::DICTIONARY, "data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_NETWORK));
}
void AnimationTreePlayer::advance(float p_time) {
@@ -409,7 +397,7 @@ void AnimationTreePlayer::advance(float p_time) {
void AnimationTreePlayer::_notification(int p_what) {
- switch(p_what) {
+ switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
@@ -421,38 +409,37 @@ void AnimationTreePlayer::_notification(int p_what) {
}
} break;
case NOTIFICATION_READY: {
- dirty_caches=true;
- if (master!=NodePath()) {
+ dirty_caches = true;
+ if (master != NodePath()) {
_update_sources();
}
} break;
case NOTIFICATION_INTERNAL_PROCESS: {
- if (animation_process_mode==ANIMATION_PROCESS_FIXED)
+ if (animation_process_mode == ANIMATION_PROCESS_FIXED)
break;
if (processing)
- _process_animation( get_process_delta_time() );
+ _process_animation(get_process_delta_time());
} break;
case NOTIFICATION_INTERNAL_FIXED_PROCESS: {
- if (animation_process_mode==ANIMATION_PROCESS_IDLE)
+ if (animation_process_mode == ANIMATION_PROCESS_IDLE)
break;
if (processing)
_process_animation(get_fixed_process_delta_time());
} break;
}
-
}
-void AnimationTreePlayer::_compute_weights(float *p_fallback_weight, HashMap<NodePath,float> *p_weights, float p_coeff, const HashMap<NodePath,bool> *p_filter, float p_filtered_coeff) {
+void AnimationTreePlayer::_compute_weights(float *p_fallback_weight, HashMap<NodePath, float> *p_weights, float p_coeff, const HashMap<NodePath, bool> *p_filter, float p_filtered_coeff) {
if (p_filter != NULL) {
List<NodePath> key_list;
p_filter->get_key_list(&key_list);
- for (List<NodePath>::Element *E = key_list.front();E; E=E->next()) {
+ for (List<NodePath>::Element *E = key_list.front(); E; E = E->next()) {
if ((*p_filter)[E->get()]) {
@@ -463,45 +450,43 @@ void AnimationTreePlayer::_compute_weights(float *p_fallback_weight, HashMap<Nod
}
} else if (p_weights->has(E->get())) {
- (*p_weights)[E->get()] *= p_coeff;
+ (*p_weights)[E->get()] *= p_coeff;
}
}
}
List<NodePath> key_list;
p_weights->get_key_list(&key_list);
-
- for (List<NodePath>::Element *E = key_list.front();E;E=E->next()) {
+
+ for (List<NodePath>::Element *E = key_list.front(); E; E = E->next()) {
if (p_filter == NULL || !p_filter->has(E->get())) {
(*p_weights)[E->get()] *= p_coeff;
}
}
*p_fallback_weight *= p_coeff;
-
}
-
-float AnimationTreePlayer::_process_node(const StringName& p_node,AnimationNode **r_prev_anim, float p_time, bool p_seek, float p_fallback_weight, HashMap<NodePath,float>* p_weights) {
+float AnimationTreePlayer::_process_node(const StringName &p_node, AnimationNode **r_prev_anim, float p_time, bool p_seek, float p_fallback_weight, HashMap<NodePath, float> *p_weights) {
ERR_FAIL_COND_V(!node_map.has(p_node), 0);
- NodeBase *nb=node_map[p_node];
+ NodeBase *nb = node_map[p_node];
//transform to seconds...
- switch(nb->type) {
+ switch (nb->type) {
case NODE_OUTPUT: {
- NodeOut *on = static_cast<NodeOut*>(nb);
+ NodeOut *on = static_cast<NodeOut *>(nb);
HashMap<NodePath, float> weights;
- return _process_node(on->inputs[0].node,r_prev_anim,p_time,p_seek, p_fallback_weight, &weights);
+ return _process_node(on->inputs[0].node, r_prev_anim, p_time, p_seek, p_fallback_weight, &weights);
} break;
case NODE_ANIMATION: {
- AnimationNode *an = static_cast<AnimationNode*>(nb);
+ AnimationNode *an = static_cast<AnimationNode *>(nb);
float rem = 0;
if (!an->animation.is_null()) {
@@ -512,11 +497,11 @@ float AnimationTreePlayer::_process_node(const StringName& p_node,AnimationNode
//const Animation *a = an->animation.operator->();
if (p_seek) {
- an->time=p_time;
- an->step=0;
+ an->time = p_time;
+ an->step = 0;
} else {
- an->time=MAX(0,an->time+p_time);
- an->step=p_time;
+ an->time = MAX(0, an->time + p_time);
+ an->step = p_time;
}
float anim_size = an->animation->get_length();
@@ -524,16 +509,16 @@ float AnimationTreePlayer::_process_node(const StringName& p_node,AnimationNode
if (an->animation->has_loop()) {
if (anim_size)
- an->time=Math::fposmod(an->time,anim_size);
+ an->time = Math::fposmod(an->time, anim_size);
} else if (an->time > anim_size) {
- an->time=anim_size;
+ an->time = anim_size;
}
- an->skip=true;
+ an->skip = true;
- for (List<AnimationNode::TrackRef>::Element *E=an->tref.front();E;E=E->next()) {
+ for (List<AnimationNode::TrackRef>::Element *E = an->tref.front(); E; E = E->next()) {
NodePath track_path = an->animation->track_get_path(E->get().local_track);
if (an->filter.has(track_path) && an->filter[track_path]) {
E->get().weight = 0;
@@ -545,114 +530,111 @@ float AnimationTreePlayer::_process_node(const StringName& p_node,AnimationNode
E->get().weight = p_fallback_weight;
}
}
- if (E->get().weight>CMP_EPSILON)
- an->skip=false;
+ if (E->get().weight > CMP_EPSILON)
+ an->skip = false;
}
rem = anim_size - an->time;
-
}
-
if (!(*r_prev_anim))
- active_list=an;
+ active_list = an;
else
- (*r_prev_anim)->next=an;
+ (*r_prev_anim)->next = an;
- an->next=NULL;
- *r_prev_anim=an;
+ an->next = NULL;
+ *r_prev_anim = an;
return rem;
-
} break;
case NODE_ONESHOT: {
- OneShotNode *osn = static_cast<OneShotNode*>(nb);
+ OneShotNode *osn = static_cast<OneShotNode *>(nb);
if (!osn->active) {
//make it as if this node doesn't exist, pass input 0 by.
- return _process_node(osn->inputs[0].node,r_prev_anim,p_time,p_seek, p_fallback_weight, p_weights);
+ return _process_node(osn->inputs[0].node, r_prev_anim, p_time, p_seek, p_fallback_weight, p_weights);
}
float os_seek = p_seek;
if (p_seek)
- osn->time=p_time;
+ osn->time = p_time;
if (osn->start) {
- osn->time=0;
+ osn->time = 0;
os_seek = true;
}
float blend;
- if (osn->time<osn->fade_in) {
+ if (osn->time < osn->fade_in) {
- if (osn->fade_in>0)
- blend = osn->time/osn->fade_in;
+ if (osn->fade_in > 0)
+ blend = osn->time / osn->fade_in;
else
- blend=0; //wtf
+ blend = 0; //wtf
- } else if (!osn->start && osn->remaining<osn->fade_out) {
+ } else if (!osn->start && osn->remaining < osn->fade_out) {
if (osn->fade_out)
- blend=(osn->remaining/osn->fade_out);
+ blend = (osn->remaining / osn->fade_out);
else
- blend=1.0;
+ blend = 1.0;
} else
- blend=1.0;
+ blend = 1.0;
float main_rem;
float os_rem;
HashMap<NodePath, float> os_weights(*p_weights);
float os_fallback_weight = p_fallback_weight;
- _compute_weights(&p_fallback_weight, p_weights, osn->mix?1.0 : 1.0 - blend, &osn->filter, 1.0);
+ _compute_weights(&p_fallback_weight, p_weights, osn->mix ? 1.0 : 1.0 - blend, &osn->filter, 1.0);
_compute_weights(&os_fallback_weight, &os_weights, blend, &osn->filter, 0.0);
- main_rem = _process_node(osn->inputs[0].node,r_prev_anim,p_time,p_seek, p_fallback_weight, p_weights);
- os_rem = _process_node(osn->inputs[1].node,r_prev_anim,p_time,os_seek, os_fallback_weight, &os_weights);
+ main_rem = _process_node(osn->inputs[0].node, r_prev_anim, p_time, p_seek, p_fallback_weight, p_weights);
+ os_rem = _process_node(osn->inputs[1].node, r_prev_anim, p_time, os_seek, os_fallback_weight, &os_weights);
if (osn->start) {
- osn->remaining=os_rem;
- osn->start=false;
+ osn->remaining = os_rem;
+ osn->start = false;
}
if (!p_seek) {
- osn->time+=p_time;
- osn->remaining=os_rem;
- if (osn->remaining<=0)
- osn->active=false;
+ osn->time += p_time;
+ osn->remaining = os_rem;
+ if (osn->remaining <= 0)
+ osn->active = false;
}
- return MAX(main_rem,osn->remaining);
+ return MAX(main_rem, osn->remaining);
} break;
case NODE_MIX: {
- MixNode *mn = static_cast<MixNode*>(nb);
+ MixNode *mn = static_cast<MixNode *>(nb);
HashMap<NodePath, float> mn_weights(*p_weights);
float mn_fallback_weight = p_fallback_weight;
_compute_weights(&mn_fallback_weight, &mn_weights, mn->amount);
- float rem = _process_node(mn->inputs[0].node,r_prev_anim, p_time,p_seek,p_fallback_weight,p_weights);
- _process_node(mn->inputs[1].node,r_prev_anim,p_time,p_seek,mn_fallback_weight,&mn_weights);
+ float rem = _process_node(mn->inputs[0].node, r_prev_anim, p_time, p_seek, p_fallback_weight, p_weights);
+ _process_node(mn->inputs[1].node, r_prev_anim, p_time, p_seek, mn_fallback_weight, &mn_weights);
return rem;
} break;
case NODE_BLEND2: {
- Blend2Node *bn = static_cast<Blend2Node*>(nb);
+ Blend2Node *bn = static_cast<Blend2Node *>(nb);
HashMap<NodePath, float> bn_weights(*p_weights);
float bn_fallback_weight = p_fallback_weight;
- _compute_weights(&p_fallback_weight,p_weights, 1.0 - bn->value, &bn->filter, 1.0);
- _compute_weights(&bn_fallback_weight,&bn_weights, bn->value, &bn->filter, 0.0);
- float rem = _process_node(bn->inputs[0].node,r_prev_anim,p_time,p_seek,p_fallback_weight,p_weights);
- _process_node(bn->inputs[1].node,r_prev_anim,p_time,p_seek,bn_fallback_weight,&bn_weights);
+ _compute_weights(&p_fallback_weight, p_weights, 1.0 - bn->value, &bn->filter, 1.0);
+ _compute_weights(&bn_fallback_weight, &bn_weights, bn->value, &bn->filter, 0.0);
+ float rem = _process_node(bn->inputs[0].node, r_prev_anim, p_time, p_seek, p_fallback_weight, p_weights);
+ _process_node(bn->inputs[1].node, r_prev_anim, p_time, p_seek, bn_fallback_weight, &bn_weights);
return rem;
} break;
case NODE_BLEND3: {
- Blend3Node *bn = static_cast<Blend3Node*>(nb);
+ Blend3Node *bn = static_cast<Blend3Node *>(nb);
float rem;
float blend, lower_blend, upper_blend;
@@ -670,18 +652,18 @@ float AnimationTreePlayer::_process_node(const StringName& p_node,AnimationNode
float upper_fallback_weight = p_fallback_weight;
HashMap<NodePath, float> lower_weights(*p_weights);
float lower_fallback_weight = p_fallback_weight;
- _compute_weights(&upper_fallback_weight,&upper_weights, upper_blend);
- _compute_weights(&p_fallback_weight,p_weights, blend);
- _compute_weights(&lower_fallback_weight,&lower_weights, lower_blend);
+ _compute_weights(&upper_fallback_weight, &upper_weights, upper_blend);
+ _compute_weights(&p_fallback_weight, p_weights, blend);
+ _compute_weights(&lower_fallback_weight, &lower_weights, lower_blend);
- rem = _process_node(bn->inputs[1].node,r_prev_anim,p_time,p_seek,p_fallback_weight,p_weights);
- _process_node(bn->inputs[0].node,r_prev_anim,p_time,p_seek,lower_fallback_weight,&lower_weights);
- _process_node(bn->inputs[2].node,r_prev_anim,p_time,p_seek,upper_fallback_weight,&upper_weights);
+ rem = _process_node(bn->inputs[1].node, r_prev_anim, p_time, p_seek, p_fallback_weight, p_weights);
+ _process_node(bn->inputs[0].node, r_prev_anim, p_time, p_seek, lower_fallback_weight, &lower_weights);
+ _process_node(bn->inputs[2].node, r_prev_anim, p_time, p_seek, upper_fallback_weight, &upper_weights);
return rem;
} break;
case NODE_BLEND4: {
- Blend4Node *bn = static_cast<Blend4Node*>(nb);
+ Blend4Node *bn = static_cast<Blend4Node *>(nb);
HashMap<NodePath, float> weights1(*p_weights);
float fallback_weight1 = p_fallback_weight;
@@ -690,26 +672,26 @@ float AnimationTreePlayer::_process_node(const StringName& p_node,AnimationNode
HashMap<NodePath, float> weights3(*p_weights);
float fallback_weight3 = p_fallback_weight;
- _compute_weights(&p_fallback_weight,p_weights, 1.0-bn->value.x);
- _compute_weights(&fallback_weight1,&weights1, bn->value.x);
- _compute_weights(&fallback_weight2,&weights2, 1.0-bn->value.y);
- _compute_weights(&fallback_weight3,&weights3, bn->value.y);
+ _compute_weights(&p_fallback_weight, p_weights, 1.0 - bn->value.x);
+ _compute_weights(&fallback_weight1, &weights1, bn->value.x);
+ _compute_weights(&fallback_weight2, &weights2, 1.0 - bn->value.y);
+ _compute_weights(&fallback_weight3, &weights3, bn->value.y);
- float rem = _process_node(bn->inputs[0].node,r_prev_anim,p_time,p_seek,p_fallback_weight,p_weights);
- _process_node(bn->inputs[1].node,r_prev_anim,p_time,p_seek,fallback_weight1,&weights1);
- float rem2 = _process_node(bn->inputs[2].node,r_prev_anim,p_time,p_seek,fallback_weight2,&weights2);
- _process_node(bn->inputs[3].node,r_prev_anim,p_time,p_seek,fallback_weight3,&weights3);
+ float rem = _process_node(bn->inputs[0].node, r_prev_anim, p_time, p_seek, p_fallback_weight, p_weights);
+ _process_node(bn->inputs[1].node, r_prev_anim, p_time, p_seek, fallback_weight1, &weights1);
+ float rem2 = _process_node(bn->inputs[2].node, r_prev_anim, p_time, p_seek, fallback_weight2, &weights2);
+ _process_node(bn->inputs[3].node, r_prev_anim, p_time, p_seek, fallback_weight3, &weights3);
- return MAX(rem,rem2);
+ return MAX(rem, rem2);
} break;
case NODE_TIMESCALE: {
- TimeScaleNode *tsn = static_cast<TimeScaleNode*>(nb);
+ TimeScaleNode *tsn = static_cast<TimeScaleNode *>(nb);
float rem;
if (p_seek)
- rem = _process_node(tsn->inputs[0].node,r_prev_anim,p_time,true,p_fallback_weight,p_weights);
+ rem = _process_node(tsn->inputs[0].node, r_prev_anim, p_time, true, p_fallback_weight, p_weights);
else
- rem = _process_node(tsn->inputs[0].node,r_prev_anim,p_time*tsn->scale,false,p_fallback_weight,p_weights);
+ rem = _process_node(tsn->inputs[0].node, r_prev_anim, p_time * tsn->scale, false, p_fallback_weight, p_weights);
if (tsn->scale == 0)
return Math_INF;
else
@@ -718,105 +700,96 @@ float AnimationTreePlayer::_process_node(const StringName& p_node,AnimationNode
} break;
case NODE_TIMESEEK: {
- TimeSeekNode *tsn = static_cast<TimeSeekNode*>(nb);
- if (tsn->seek_pos>=0 && !p_seek) {
+ TimeSeekNode *tsn = static_cast<TimeSeekNode *>(nb);
+ if (tsn->seek_pos >= 0 && !p_seek) {
p_time = tsn->seek_pos;
p_seek = true;
}
- tsn->seek_pos=-1;
+ tsn->seek_pos = -1;
- return _process_node(tsn->inputs[0].node,r_prev_anim,p_time,p_seek,p_fallback_weight,p_weights);
+ return _process_node(tsn->inputs[0].node, r_prev_anim, p_time, p_seek, p_fallback_weight, p_weights);
- } break;
+ } break;
case NODE_TRANSITION: {
- TransitionNode *tn = static_cast<TransitionNode*>(nb);
+ TransitionNode *tn = static_cast<TransitionNode *>(nb);
HashMap<NodePath, float> prev_weights(*p_weights);
float prev_fallback_weight = p_fallback_weight;
- if (tn->prev<0) { // process current animation, check for transition
+ if (tn->prev < 0) { // process current animation, check for transition
- float rem = _process_node(tn->inputs[tn->current].node,r_prev_anim,p_time,p_seek,p_fallback_weight,p_weights);
+ float rem = _process_node(tn->inputs[tn->current].node, r_prev_anim, p_time, p_seek, p_fallback_weight, p_weights);
if (p_seek)
- tn->time=p_time;
+ tn->time = p_time;
else
- tn->time+=p_time;
+ tn->time += p_time;
if (tn->input_data[tn->current].auto_advance && rem <= tn->xfade) {
- tn->set_current((tn->current+1) % tn->inputs.size());
+ tn->set_current((tn->current + 1) % tn->inputs.size());
}
-
return rem;
- } else { // cross-fading from tn->prev to tn->current
+ } else { // cross-fading from tn->prev to tn->current
-
- float blend = tn->xfade? (tn->prev_xfading/tn->xfade) : 1;
+ float blend = tn->xfade ? (tn->prev_xfading / tn->xfade) : 1;
float rem;
- _compute_weights(&p_fallback_weight,p_weights, 1.0-blend);
- _compute_weights(&prev_fallback_weight,&prev_weights, blend);
+ _compute_weights(&p_fallback_weight, p_weights, 1.0 - blend);
+ _compute_weights(&prev_fallback_weight, &prev_weights, blend);
if (!p_seek && tn->switched) { //just switched, seek to start of current
- rem = _process_node(tn->inputs[tn->current].node,r_prev_anim,0,true,p_fallback_weight,p_weights);
+ rem = _process_node(tn->inputs[tn->current].node, r_prev_anim, 0, true, p_fallback_weight, p_weights);
} else {
- rem = _process_node(tn->inputs[tn->current].node,r_prev_anim,p_time,p_seek,p_fallback_weight,p_weights);
-
+ rem = _process_node(tn->inputs[tn->current].node, r_prev_anim, p_time, p_seek, p_fallback_weight, p_weights);
}
- tn->switched=false;
+ tn->switched = false;
- if (p_seek) { // don't seek prev animation
- _process_node(tn->inputs[tn->prev].node,r_prev_anim,0,false,prev_fallback_weight,&prev_weights);
- tn->time=p_time;
+ if (p_seek) { // don't seek prev animation
+ _process_node(tn->inputs[tn->prev].node, r_prev_anim, 0, false, prev_fallback_weight, &prev_weights);
+ tn->time = p_time;
} else {
- _process_node(tn->inputs[tn->prev].node,r_prev_anim,p_time,false,prev_fallback_weight,&prev_weights);
- tn->time+=p_time;
- tn->prev_xfading-=p_time;
- if (tn->prev_xfading<0) {
+ _process_node(tn->inputs[tn->prev].node, r_prev_anim, p_time, false, prev_fallback_weight, &prev_weights);
+ tn->time += p_time;
+ tn->prev_xfading -= p_time;
+ if (tn->prev_xfading < 0) {
- tn->prev=-1;
+ tn->prev = -1;
}
-
}
return rem;
}
-
} break;
default: {}
}
-
-
return 0;
}
-
void AnimationTreePlayer::_process_animation(float p_delta) {
- if (last_error!=CONNECT_OK)
+ if (last_error != CONNECT_OK)
return;
if (dirty_caches)
_recompute_caches();
-
- active_list=NULL;
- AnimationNode *prev=NULL;
+ active_list = NULL;
+ AnimationNode *prev = NULL;
if (reset_request) {
- _process_node(out_name,&prev, 0, true);
- reset_request=false;
+ _process_node(out_name, &prev, 0, true);
+ reset_request = false;
} else
- _process_node(out_name,&prev, p_delta);
+ _process_node(out_name, &prev, p_delta);
if (dirty_caches) {
//some animation changed.. ignore this pass
@@ -825,19 +798,17 @@ void AnimationTreePlayer::_process_animation(float p_delta) {
//update the tracks..
-
-
/* STEP 1 CLEAR TRACKS */
- for(TrackMap::Element *E=track_map.front();E;E=E->next()) {
+ for (TrackMap::Element *E = track_map.front(); E; E = E->next()) {
Track &t = E->get();
t.loc.zero();
- t.rot=Quat();
- t.scale.x=0;
- t.scale.y=0;
- t.scale.z=0;
+ t.rot = Quat();
+ t.scale.x = 0;
+ t.scale.y = 0;
+ t.scale.z = 0;
t.value = t.object->get(t.property);
t.value.zero();
@@ -845,634 +816,554 @@ void AnimationTreePlayer::_process_animation(float p_delta) {
t.skip = false;
}
-
/* STEP 2 PROCESS ANIMATIONS */
- AnimationNode *anim_list=active_list;
+ AnimationNode *anim_list = active_list;
Quat empty_rot;
-
- while(anim_list) {
+ while (anim_list) {
if (!anim_list->animation.is_null() && !anim_list->skip) {
//check if animation is meaningful
Animation *a = anim_list->animation.operator->();
- for(List<AnimationNode::TrackRef>::Element *E=anim_list->tref.front();E;E=E->next()) {
-
+ for (List<AnimationNode::TrackRef>::Element *E = anim_list->tref.front(); E; E = E->next()) {
AnimationNode::TrackRef &tr = E->get();
- if (tr.track==NULL || tr.local_track<0 || tr.weight < CMP_EPSILON)
+ if (tr.track == NULL || tr.local_track < 0 || tr.weight < CMP_EPSILON)
continue;
- switch(a->track_get_type(tr.local_track)) {
+ switch (a->track_get_type(tr.local_track)) {
case Animation::TYPE_TRANSFORM: { ///< Transform a node or a bone.
Vector3 loc;
Quat rot;
Vector3 scale;
- a->transform_track_interpolate(tr.local_track,anim_list->time,&loc,&rot,&scale);
+ a->transform_track_interpolate(tr.local_track, anim_list->time, &loc, &rot, &scale);
- tr.track->loc+=loc*tr.weight;
+ tr.track->loc += loc * tr.weight;
- scale.x-=1.0;
- scale.y-=1.0;
- scale.z-=1.0;
- tr.track->scale+=scale*tr.weight;
-
- tr.track->rot = tr.track->rot * empty_rot.slerp(rot,tr.weight);
+ scale.x -= 1.0;
+ scale.y -= 1.0;
+ scale.z -= 1.0;
+ tr.track->scale += scale * tr.weight;
+ tr.track->rot = tr.track->rot * empty_rot.slerp(rot, tr.weight);
} break;
case Animation::TYPE_VALUE: { ///< Set a value in a property, can be interpolated.
- if (a->value_track_get_update_mode(tr.local_track)==Animation::UPDATE_CONTINUOUS) {
- Variant value = a->value_track_interpolate(tr.local_track,anim_list->time);
- Variant::blend(tr.track->value,value,tr.weight,tr.track->value);
+ if (a->value_track_get_update_mode(tr.local_track) == Animation::UPDATE_CONTINUOUS) {
+ Variant value = a->value_track_interpolate(tr.local_track, anim_list->time);
+ Variant::blend(tr.track->value, value, tr.weight, tr.track->value);
} else {
- int index = a->track_find_key(tr.local_track,anim_list->time);
+ int index = a->track_find_key(tr.local_track, anim_list->time);
tr.track->value = a->track_get_key_value(tr.local_track, index);
}
} break;
case Animation::TYPE_METHOD: { ///< Call any method on a specific node.
List<int> indices;
- a->method_track_get_key_indices(tr.local_track,anim_list->time,anim_list->step,&indices);
- for(List<int>::Element *E=indices.front();E;E=E->next()) {
+ a->method_track_get_key_indices(tr.local_track, anim_list->time, anim_list->step, &indices);
+ for (List<int>::Element *E = indices.front(); E; E = E->next()) {
- StringName method = a->method_track_get_name(tr.local_track,E->get());
- Vector<Variant> args=a->method_track_get_params(tr.local_track,E->get());
+ StringName method = a->method_track_get_name(tr.local_track, E->get());
+ Vector<Variant> args = a->method_track_get_params(tr.local_track, E->get());
args.resize(VARIANT_ARG_MAX);
- tr.track->object->call(method,args[0],args[1],args[2],args[3],args[4]);
+ tr.track->object->call(method, args[0], args[1], args[2], args[3], args[4]);
}
} break;
}
-
}
}
- anim_list=anim_list->next;
+ anim_list = anim_list->next;
}
/* STEP 3 APPLY TRACKS */
- for(TrackMap::Element *E=track_map.front();E;E=E->next()) {
+ for (TrackMap::Element *E = track_map.front(); E; E = E->next()) {
Track &t = E->get();
if (t.skip || !t.object)
continue;
- if(t.property) { // value track
- t.object->set(t.property,t.value);
+ if (t.property) { // value track
+ t.object->set(t.property, t.value);
continue;
}
Transform xform;
- xform.basis=t.rot;
- xform.origin=t.loc;
+ xform.basis = t.rot;
+ xform.origin = t.loc;
- t.scale.x+=1.0;
- t.scale.y+=1.0;
- t.scale.z+=1.0;
+ t.scale.x += 1.0;
+ t.scale.y += 1.0;
+ t.scale.z += 1.0;
xform.basis.scale(t.scale);
- if (t.bone_idx>=0) {
+ if (t.bone_idx >= 0) {
if (t.skeleton)
- t.skeleton->set_bone_pose(t.bone_idx,xform);
+ t.skeleton->set_bone_pose(t.bone_idx, xform);
} else if (t.spatial) {
t.spatial->set_transform(xform);
}
}
-
-
-
}
+void AnimationTreePlayer::add_node(NodeType p_type, const StringName &p_node) {
-void AnimationTreePlayer::add_node(NodeType p_type, const StringName& p_node) {
+ ERR_FAIL_COND(p_type == NODE_OUTPUT);
+ ERR_FAIL_COND(node_map.has(p_node));
- ERR_FAIL_COND( p_type == NODE_OUTPUT );
- ERR_FAIL_COND( node_map.has(p_node));
+ NodeBase *n = NULL;
- NodeBase *n=NULL;
-
- switch(p_type) {
+ switch (p_type) {
case NODE_ANIMATION: {
- n = memnew( AnimationNode );
+ n = memnew(AnimationNode);
} break;
case NODE_ONESHOT: {
- n = memnew( OneShotNode );
+ n = memnew(OneShotNode);
} break;
case NODE_MIX: {
- n = memnew( MixNode );
+ n = memnew(MixNode);
} break;
case NODE_BLEND2: {
- n = memnew( Blend2Node );
+ n = memnew(Blend2Node);
} break;
case NODE_BLEND3: {
- n = memnew( Blend3Node );
+ n = memnew(Blend3Node);
} break;
case NODE_BLEND4: {
- n = memnew( Blend4Node );
+ n = memnew(Blend4Node);
} break;
case NODE_TIMESCALE: {
- n = memnew( TimeScaleNode );
-
+ n = memnew(TimeScaleNode);
} break;
case NODE_TIMESEEK: {
- n = memnew( TimeSeekNode );
+ n = memnew(TimeSeekNode);
} break;
case NODE_TRANSITION: {
- n = memnew( TransitionNode );
-
+ n = memnew(TransitionNode);
} break;
default: {}
}
//n->name+=" "+itos(p_node);
- node_map[p_node]=n;
+ node_map[p_node] = n;
}
+StringName AnimationTreePlayer::node_get_input_source(const StringName &p_node, int p_input) const {
-StringName AnimationTreePlayer::node_get_input_source(const StringName& p_node,int p_input) const {
-
- ERR_FAIL_COND_V(!node_map.has(p_node),StringName());
- ERR_FAIL_INDEX_V( p_input,node_map[p_node]->inputs.size(),StringName() );
+ ERR_FAIL_COND_V(!node_map.has(p_node), StringName());
+ ERR_FAIL_INDEX_V(p_input, node_map[p_node]->inputs.size(), StringName());
return node_map[p_node]->inputs[p_input].node;
-
}
+int AnimationTreePlayer::node_get_input_count(const StringName &p_node) const {
-int AnimationTreePlayer::node_get_input_count(const StringName& p_node) const {
-
- ERR_FAIL_COND_V(!node_map.has(p_node),-1);
+ ERR_FAIL_COND_V(!node_map.has(p_node), -1);
return node_map[p_node]->inputs.size();
-
}
-#define GET_NODE( m_type, m_cast )\
- ERR_FAIL_COND(!node_map.has(p_node));\
- ERR_EXPLAIN("Invalid parameter for node type.");\
- ERR_FAIL_COND(node_map[p_node]->type!=m_type);\
- m_cast *n = static_cast<m_cast*>( node_map[p_node] );\
-
-
-
-void AnimationTreePlayer::animation_node_set_animation(const StringName& p_node,const Ref<Animation>& p_animation) {
-
- GET_NODE( NODE_ANIMATION, AnimationNode );
- n->animation=p_animation;
- dirty_caches=true;
+#define GET_NODE(m_type, m_cast) \
+ ERR_FAIL_COND(!node_map.has(p_node)); \
+ ERR_EXPLAIN("Invalid parameter for node type."); \
+ ERR_FAIL_COND(node_map[p_node]->type != m_type); \
+ m_cast *n = static_cast<m_cast *>(node_map[p_node]);
+void AnimationTreePlayer::animation_node_set_animation(const StringName &p_node, const Ref<Animation> &p_animation) {
+ GET_NODE(NODE_ANIMATION, AnimationNode);
+ n->animation = p_animation;
+ dirty_caches = true;
}
-void AnimationTreePlayer::animation_node_set_master_animation(const StringName& p_node,const String& p_master_animation) {
+void AnimationTreePlayer::animation_node_set_master_animation(const StringName &p_node, const String &p_master_animation) {
- GET_NODE( NODE_ANIMATION, AnimationNode );
- n->from=p_master_animation;
- dirty_caches=true;
- if (master!=NodePath())
+ GET_NODE(NODE_ANIMATION, AnimationNode);
+ n->from = p_master_animation;
+ dirty_caches = true;
+ if (master != NodePath())
_update_sources();
-
-
}
-void AnimationTreePlayer::animation_node_set_filter_path(const StringName& p_node,const NodePath& p_track_path,bool p_filter) {
+void AnimationTreePlayer::animation_node_set_filter_path(const StringName &p_node, const NodePath &p_track_path, bool p_filter) {
- GET_NODE( NODE_ANIMATION, AnimationNode );
+ GET_NODE(NODE_ANIMATION, AnimationNode);
if (p_filter)
- n->filter[p_track_path]=true;
+ n->filter[p_track_path] = true;
else
n->filter.erase(p_track_path);
-
}
-void AnimationTreePlayer::animation_node_set_get_filtered_paths(const StringName& p_node,List<NodePath> *r_paths) const{
+void AnimationTreePlayer::animation_node_set_get_filtered_paths(const StringName &p_node, List<NodePath> *r_paths) const {
- GET_NODE( NODE_ANIMATION, AnimationNode );
+ GET_NODE(NODE_ANIMATION, AnimationNode);
n->filter.get_key_list(r_paths);
}
-void AnimationTreePlayer::oneshot_node_set_fadein_time(const StringName& p_node,float p_time) {
-
- GET_NODE( NODE_ONESHOT, OneShotNode );
- n->fade_in=p_time;
+void AnimationTreePlayer::oneshot_node_set_fadein_time(const StringName &p_node, float p_time) {
+ GET_NODE(NODE_ONESHOT, OneShotNode);
+ n->fade_in = p_time;
}
+void AnimationTreePlayer::oneshot_node_set_fadeout_time(const StringName &p_node, float p_time) {
-void AnimationTreePlayer::oneshot_node_set_fadeout_time(const StringName& p_node,float p_time) {
-
- GET_NODE( NODE_ONESHOT, OneShotNode );
- n->fade_out=p_time;
-
-
+ GET_NODE(NODE_ONESHOT, OneShotNode);
+ n->fade_out = p_time;
}
-void AnimationTreePlayer::oneshot_node_set_mix_mode(const StringName& p_node,bool p_mix) {
+void AnimationTreePlayer::oneshot_node_set_mix_mode(const StringName &p_node, bool p_mix) {
- GET_NODE( NODE_ONESHOT, OneShotNode );
- n->mix=p_mix;
+ GET_NODE(NODE_ONESHOT, OneShotNode);
+ n->mix = p_mix;
}
+void AnimationTreePlayer::oneshot_node_set_autorestart(const StringName &p_node, bool p_active) {
-void AnimationTreePlayer::oneshot_node_set_autorestart(const StringName& p_node,bool p_active) {
-
- GET_NODE( NODE_ONESHOT, OneShotNode );
- n->autorestart=p_active;
-
+ GET_NODE(NODE_ONESHOT, OneShotNode);
+ n->autorestart = p_active;
}
-void AnimationTreePlayer::oneshot_node_set_autorestart_delay(const StringName& p_node,float p_time) {
-
- GET_NODE( NODE_ONESHOT, OneShotNode );
- n->autorestart_delay=p_time;
+void AnimationTreePlayer::oneshot_node_set_autorestart_delay(const StringName &p_node, float p_time) {
+ GET_NODE(NODE_ONESHOT, OneShotNode);
+ n->autorestart_delay = p_time;
}
-void AnimationTreePlayer::oneshot_node_set_autorestart_random_delay(const StringName& p_node,float p_time) {
-
- GET_NODE( NODE_ONESHOT, OneShotNode );
- n->autorestart_random_delay=p_time;
+void AnimationTreePlayer::oneshot_node_set_autorestart_random_delay(const StringName &p_node, float p_time) {
+ GET_NODE(NODE_ONESHOT, OneShotNode);
+ n->autorestart_random_delay = p_time;
}
-void AnimationTreePlayer::oneshot_node_start(const StringName& p_node) {
-
- GET_NODE( NODE_ONESHOT, OneShotNode );
- n->active=true;
- n->start=true;
+void AnimationTreePlayer::oneshot_node_start(const StringName &p_node) {
+ GET_NODE(NODE_ONESHOT, OneShotNode);
+ n->active = true;
+ n->start = true;
}
+void AnimationTreePlayer::oneshot_node_stop(const StringName &p_node) {
-void AnimationTreePlayer::oneshot_node_stop(const StringName& p_node) {
-
- GET_NODE( NODE_ONESHOT, OneShotNode );
- n->active=false;
-
+ GET_NODE(NODE_ONESHOT, OneShotNode);
+ n->active = false;
}
+void AnimationTreePlayer::oneshot_node_set_filter_path(const StringName &p_node, const NodePath &p_filter, bool p_enable) {
-void AnimationTreePlayer::oneshot_node_set_filter_path(const StringName& p_node,const NodePath& p_filter,bool p_enable) {
-
- GET_NODE( NODE_ONESHOT, OneShotNode );
+ GET_NODE(NODE_ONESHOT, OneShotNode);
if (p_enable)
- n->filter[p_filter]=true;
+ n->filter[p_filter] = true;
else
n->filter.erase(p_filter);
-
}
-void AnimationTreePlayer::oneshot_node_set_get_filtered_paths(const StringName& p_node,List<NodePath> *r_paths) const{
+void AnimationTreePlayer::oneshot_node_set_get_filtered_paths(const StringName &p_node, List<NodePath> *r_paths) const {
- GET_NODE( NODE_ONESHOT, OneShotNode );
+ GET_NODE(NODE_ONESHOT, OneShotNode);
n->filter.get_key_list(r_paths);
}
+void AnimationTreePlayer::mix_node_set_amount(const StringName &p_node, float p_amount) {
-void AnimationTreePlayer::mix_node_set_amount(const StringName& p_node,float p_amount) {
-
- GET_NODE( NODE_MIX, MixNode );
- n->amount=p_amount;
-
+ GET_NODE(NODE_MIX, MixNode);
+ n->amount = p_amount;
}
+void AnimationTreePlayer::blend2_node_set_amount(const StringName &p_node, float p_amount) {
-void AnimationTreePlayer::blend2_node_set_amount(const StringName& p_node,float p_amount) {
-
- GET_NODE( NODE_BLEND2, Blend2Node );
- n->value=p_amount;
-
+ GET_NODE(NODE_BLEND2, Blend2Node);
+ n->value = p_amount;
}
-void AnimationTreePlayer::blend2_node_set_filter_path(const StringName& p_node,const NodePath& p_filter,bool p_enable) {
+void AnimationTreePlayer::blend2_node_set_filter_path(const StringName &p_node, const NodePath &p_filter, bool p_enable) {
- GET_NODE( NODE_BLEND2, Blend2Node );
+ GET_NODE(NODE_BLEND2, Blend2Node);
if (p_enable)
- n->filter[p_filter]=true;
+ n->filter[p_filter] = true;
else
n->filter.erase(p_filter);
-
}
-void AnimationTreePlayer::blend2_node_set_get_filtered_paths(const StringName& p_node,List<NodePath> *r_paths) const{
+void AnimationTreePlayer::blend2_node_set_get_filtered_paths(const StringName &p_node, List<NodePath> *r_paths) const {
- GET_NODE( NODE_BLEND2, Blend2Node );
+ GET_NODE(NODE_BLEND2, Blend2Node);
n->filter.get_key_list(r_paths);
}
+void AnimationTreePlayer::blend3_node_set_amount(const StringName &p_node, float p_amount) {
-void AnimationTreePlayer::blend3_node_set_amount(const StringName& p_node,float p_amount) {
-
- GET_NODE( NODE_BLEND3, Blend3Node );
- n->value=p_amount;
-
+ GET_NODE(NODE_BLEND3, Blend3Node);
+ n->value = p_amount;
}
-void AnimationTreePlayer::blend4_node_set_amount(const StringName& p_node,const Vector2& p_amount) {
-
- GET_NODE( NODE_BLEND4, Blend4Node );
- n->value=p_amount;
+void AnimationTreePlayer::blend4_node_set_amount(const StringName &p_node, const Vector2 &p_amount) {
+ GET_NODE(NODE_BLEND4, Blend4Node);
+ n->value = p_amount;
}
-void AnimationTreePlayer::timescale_node_set_scale(const StringName& p_node,float p_scale) {
-
-
- GET_NODE( NODE_TIMESCALE, TimeScaleNode );
- n->scale=p_scale;
+void AnimationTreePlayer::timescale_node_set_scale(const StringName &p_node, float p_scale) {
+ GET_NODE(NODE_TIMESCALE, TimeScaleNode);
+ n->scale = p_scale;
}
-void AnimationTreePlayer::timeseek_node_seek(const StringName& p_node,float p_pos) {
-
-
- GET_NODE( NODE_TIMESEEK, TimeSeekNode );
- n->seek_pos=p_pos;
+void AnimationTreePlayer::timeseek_node_seek(const StringName &p_node, float p_pos) {
+ GET_NODE(NODE_TIMESEEK, TimeSeekNode);
+ n->seek_pos = p_pos;
}
-void AnimationTreePlayer::transition_node_set_input_count(const StringName& p_node, int p_inputs) {
-
+void AnimationTreePlayer::transition_node_set_input_count(const StringName &p_node, int p_inputs) {
- GET_NODE( NODE_TRANSITION, TransitionNode );
- ERR_FAIL_COND(p_inputs<1);
+ GET_NODE(NODE_TRANSITION, TransitionNode);
+ ERR_FAIL_COND(p_inputs < 1);
n->inputs.resize(p_inputs);
n->input_data.resize(p_inputs);
- last_error=_cycle_test(out_name);
-
+ last_error = _cycle_test(out_name);
}
-void AnimationTreePlayer::transition_node_set_input_auto_advance(const StringName& p_node, int p_input,bool p_auto_advance) {
+void AnimationTreePlayer::transition_node_set_input_auto_advance(const StringName &p_node, int p_input, bool p_auto_advance) {
- GET_NODE( NODE_TRANSITION, TransitionNode );
- ERR_FAIL_INDEX(p_input,n->input_data.size());
-
- n->input_data[p_input].auto_advance=p_auto_advance;
+ GET_NODE(NODE_TRANSITION, TransitionNode);
+ ERR_FAIL_INDEX(p_input, n->input_data.size());
+ n->input_data[p_input].auto_advance = p_auto_advance;
}
-void AnimationTreePlayer::transition_node_set_xfade_time(const StringName& p_node, float p_time) {
-
+void AnimationTreePlayer::transition_node_set_xfade_time(const StringName &p_node, float p_time) {
- GET_NODE( NODE_TRANSITION, TransitionNode );
- n->xfade=p_time;
+ GET_NODE(NODE_TRANSITION, TransitionNode);
+ n->xfade = p_time;
}
void AnimationTreePlayer::TransitionNode::set_current(int p_current) {
- ERR_FAIL_INDEX(p_current,inputs.size());
+ ERR_FAIL_INDEX(p_current, inputs.size());
- if (current==p_current)
+ if (current == p_current)
return;
- prev=current;
- prev_xfading=xfade;
- prev_time=time;
- time=0;
- current=p_current;
- switched=true;
+ prev = current;
+ prev_xfading = xfade;
+ prev_time = time;
+ time = 0;
+ current = p_current;
+ switched = true;
}
-void AnimationTreePlayer::transition_node_set_current(const StringName& p_node, int p_current) {
+void AnimationTreePlayer::transition_node_set_current(const StringName &p_node, int p_current) {
- GET_NODE( NODE_TRANSITION, TransitionNode );
+ GET_NODE(NODE_TRANSITION, TransitionNode);
n->set_current(p_current);
}
-
-void AnimationTreePlayer::node_set_pos(const StringName& p_node, const Vector2& p_pos) {
+void AnimationTreePlayer::node_set_pos(const StringName &p_node, const Vector2 &p_pos) {
ERR_FAIL_COND(!node_map.has(p_node));
- node_map[p_node]->pos=p_pos;
-
+ node_map[p_node]->pos = p_pos;
}
-AnimationTreePlayer::NodeType AnimationTreePlayer::node_get_type(const StringName& p_node) const {
+AnimationTreePlayer::NodeType AnimationTreePlayer::node_get_type(const StringName &p_node) const {
- ERR_FAIL_COND_V(!node_map.has(p_node),NODE_OUTPUT);
+ ERR_FAIL_COND_V(!node_map.has(p_node), NODE_OUTPUT);
return node_map[p_node]->type;
-
}
-Point2 AnimationTreePlayer::node_get_pos(const StringName& p_node) const {
+Point2 AnimationTreePlayer::node_get_pos(const StringName &p_node) const {
- ERR_FAIL_COND_V(!node_map.has(p_node),Point2());
+ ERR_FAIL_COND_V(!node_map.has(p_node), Point2());
return node_map[p_node]->pos;
-
-
}
-#define GET_NODE_V( m_type, m_cast, m_ret )\
- ERR_FAIL_COND_V(!node_map.has(p_node),m_ret);\
- ERR_EXPLAIN("Invalid parameter for node type.");\
- ERR_FAIL_COND_V(node_map[p_node]->type!=m_type,m_ret);\
- m_cast *n = static_cast<m_cast*>( node_map[p_node] );\
+#define GET_NODE_V(m_type, m_cast, m_ret) \
+ ERR_FAIL_COND_V(!node_map.has(p_node), m_ret); \
+ ERR_EXPLAIN("Invalid parameter for node type."); \
+ ERR_FAIL_COND_V(node_map[p_node]->type != m_type, m_ret); \
+ m_cast *n = static_cast<m_cast *>(node_map[p_node]);
-Ref<Animation> AnimationTreePlayer::animation_node_get_animation(const StringName& p_node) const {
+Ref<Animation> AnimationTreePlayer::animation_node_get_animation(const StringName &p_node) const {
GET_NODE_V(NODE_ANIMATION, AnimationNode, Ref<Animation>());
return n->animation;
-
}
-String AnimationTreePlayer::animation_node_get_master_animation(const StringName& p_node) const {
+String AnimationTreePlayer::animation_node_get_master_animation(const StringName &p_node) const {
GET_NODE_V(NODE_ANIMATION, AnimationNode, String());
return n->from;
-
}
-bool AnimationTreePlayer::animation_node_is_path_filtered(const StringName& p_node,const NodePath& p_path) const {
+bool AnimationTreePlayer::animation_node_is_path_filtered(const StringName &p_node, const NodePath &p_path) const {
- GET_NODE_V(NODE_ANIMATION, AnimationNode, 0 );
+ GET_NODE_V(NODE_ANIMATION, AnimationNode, 0);
return n->filter.has(p_path);
}
-float AnimationTreePlayer::oneshot_node_get_fadein_time(const StringName& p_node) const {
+float AnimationTreePlayer::oneshot_node_get_fadein_time(const StringName &p_node) const {
-
- GET_NODE_V(NODE_ONESHOT, OneShotNode, 0 );
+ GET_NODE_V(NODE_ONESHOT, OneShotNode, 0);
return n->fade_in;
-
}
-float AnimationTreePlayer::oneshot_node_get_fadeout_time(const StringName& p_node) const {
+float AnimationTreePlayer::oneshot_node_get_fadeout_time(const StringName &p_node) const {
- GET_NODE_V(NODE_ONESHOT, OneShotNode, 0 );
+ GET_NODE_V(NODE_ONESHOT, OneShotNode, 0);
return n->fade_out;
-
}
-bool AnimationTreePlayer::oneshot_node_get_mix_mode(const StringName& p_node) const {
+bool AnimationTreePlayer::oneshot_node_get_mix_mode(const StringName &p_node) const {
- GET_NODE_V(NODE_ONESHOT, OneShotNode, 0 );
+ GET_NODE_V(NODE_ONESHOT, OneShotNode, 0);
return n->mix;
-
}
-bool AnimationTreePlayer::oneshot_node_has_autorestart(const StringName& p_node) const {
+bool AnimationTreePlayer::oneshot_node_has_autorestart(const StringName &p_node) const {
- GET_NODE_V(NODE_ONESHOT, OneShotNode, 0 );
+ GET_NODE_V(NODE_ONESHOT, OneShotNode, 0);
return n->autorestart;
-
}
-float AnimationTreePlayer::oneshot_node_get_autorestart_delay(const StringName& p_node) const {
+float AnimationTreePlayer::oneshot_node_get_autorestart_delay(const StringName &p_node) const {
- GET_NODE_V(NODE_ONESHOT, OneShotNode, 0 );
+ GET_NODE_V(NODE_ONESHOT, OneShotNode, 0);
return n->autorestart_delay;
-
}
-float AnimationTreePlayer::oneshot_node_get_autorestart_random_delay(const StringName& p_node) const {
+float AnimationTreePlayer::oneshot_node_get_autorestart_random_delay(const StringName &p_node) const {
- GET_NODE_V(NODE_ONESHOT, OneShotNode, 0 );
+ GET_NODE_V(NODE_ONESHOT, OneShotNode, 0);
return n->autorestart_random_delay;
-
}
-bool AnimationTreePlayer::oneshot_node_is_active(const StringName& p_node) const {
-
+bool AnimationTreePlayer::oneshot_node_is_active(const StringName &p_node) const {
- GET_NODE_V(NODE_ONESHOT, OneShotNode, 0 );
+ GET_NODE_V(NODE_ONESHOT, OneShotNode, 0);
return n->active;
-
}
-bool AnimationTreePlayer::oneshot_node_is_path_filtered(const StringName& p_node,const NodePath& p_path) const {
+bool AnimationTreePlayer::oneshot_node_is_path_filtered(const StringName &p_node, const NodePath &p_path) const {
- GET_NODE_V(NODE_ONESHOT, OneShotNode, 0 );
+ GET_NODE_V(NODE_ONESHOT, OneShotNode, 0);
return n->filter.has(p_path);
}
+float AnimationTreePlayer::mix_node_get_amount(const StringName &p_node) const {
-float AnimationTreePlayer::mix_node_get_amount(const StringName& p_node) const {
-
- GET_NODE_V(NODE_MIX, MixNode, 0 );
+ GET_NODE_V(NODE_MIX, MixNode, 0);
return n->amount;
-
}
-float AnimationTreePlayer::blend2_node_get_amount(const StringName& p_node) const {
+float AnimationTreePlayer::blend2_node_get_amount(const StringName &p_node) const {
- GET_NODE_V(NODE_BLEND2, Blend2Node, 0 );
+ GET_NODE_V(NODE_BLEND2, Blend2Node, 0);
return n->value;
-
}
-bool AnimationTreePlayer::blend2_node_is_path_filtered(const StringName& p_node,const NodePath& p_path) const {
+bool AnimationTreePlayer::blend2_node_is_path_filtered(const StringName &p_node, const NodePath &p_path) const {
- GET_NODE_V(NODE_BLEND2, Blend2Node, 0 );
+ GET_NODE_V(NODE_BLEND2, Blend2Node, 0);
return n->filter.has(p_path);
}
-float AnimationTreePlayer::blend3_node_get_amount(const StringName& p_node) const {
-
+float AnimationTreePlayer::blend3_node_get_amount(const StringName &p_node) const {
- GET_NODE_V(NODE_BLEND3, Blend3Node, 0 );
+ GET_NODE_V(NODE_BLEND3, Blend3Node, 0);
return n->value;
-
}
-Vector2 AnimationTreePlayer::blend4_node_get_amount(const StringName& p_node) const {
+Vector2 AnimationTreePlayer::blend4_node_get_amount(const StringName &p_node) const {
- GET_NODE_V(NODE_BLEND4, Blend4Node, Vector2() );
+ GET_NODE_V(NODE_BLEND4, Blend4Node, Vector2());
return n->value;
-
}
-float AnimationTreePlayer::timescale_node_get_scale(const StringName& p_node) const {
+float AnimationTreePlayer::timescale_node_get_scale(const StringName &p_node) const {
- GET_NODE_V(NODE_TIMESCALE, TimeScaleNode, 0 );
+ GET_NODE_V(NODE_TIMESCALE, TimeScaleNode, 0);
return n->scale;
-
}
-void AnimationTreePlayer::transition_node_delete_input(const StringName& p_node, int p_input) {
+void AnimationTreePlayer::transition_node_delete_input(const StringName &p_node, int p_input) {
GET_NODE(NODE_TRANSITION, TransitionNode);
- ERR_FAIL_INDEX(p_input,n->inputs.size());
+ ERR_FAIL_INDEX(p_input, n->inputs.size());
- if (n->inputs.size()<=1)
+ if (n->inputs.size() <= 1)
return;
-
n->inputs.remove(p_input);
n->input_data.remove(p_input);
- last_error=_cycle_test(out_name);
+ last_error = _cycle_test(out_name);
}
+int AnimationTreePlayer::transition_node_get_input_count(const StringName &p_node) const {
-int AnimationTreePlayer::transition_node_get_input_count(const StringName& p_node) const {
-
- GET_NODE_V(NODE_TRANSITION, TransitionNode, 0 );
+ GET_NODE_V(NODE_TRANSITION, TransitionNode, 0);
return n->inputs.size();
}
-bool AnimationTreePlayer::transition_node_has_input_auto_advance(const StringName& p_node, int p_input) const {
+bool AnimationTreePlayer::transition_node_has_input_auto_advance(const StringName &p_node, int p_input) const {
- GET_NODE_V(NODE_TRANSITION, TransitionNode, false );
- ERR_FAIL_INDEX_V(p_input,n->inputs.size(),false);
+ GET_NODE_V(NODE_TRANSITION, TransitionNode, false);
+ ERR_FAIL_INDEX_V(p_input, n->inputs.size(), false);
return n->input_data[p_input].auto_advance;
-
}
-float AnimationTreePlayer::transition_node_get_xfade_time(const StringName& p_node) const {
+float AnimationTreePlayer::transition_node_get_xfade_time(const StringName &p_node) const {
- GET_NODE_V(NODE_TRANSITION, TransitionNode, 0 );
+ GET_NODE_V(NODE_TRANSITION, TransitionNode, 0);
return n->xfade;
-
}
-int AnimationTreePlayer::transition_node_get_current(const StringName& p_node) const {
+int AnimationTreePlayer::transition_node_get_current(const StringName &p_node) const {
- GET_NODE_V(NODE_TRANSITION, TransitionNode, -1 );
+ GET_NODE_V(NODE_TRANSITION, TransitionNode, -1);
return n->current;
-
}
- /*misc */
+/*misc */
void AnimationTreePlayer::get_node_list(List<StringName> *p_node_list) const {
- for(Map<StringName,NodeBase*>::Element *E=node_map.front();E;E=E->next()) {
+ for (Map<StringName, NodeBase *>::Element *E = node_map.front(); E; E = E->next()) {
- p_node_list->push_back( E->key() );
+ p_node_list->push_back(E->key());
}
}
-void AnimationTreePlayer::remove_node(const StringName& p_node) {
+void AnimationTreePlayer::remove_node(const StringName &p_node) {
- ERR_FAIL_COND( !node_map.has(p_node) );
+ ERR_FAIL_COND(!node_map.has(p_node));
ERR_EXPLAIN("Node 0 (output) can't be removed.");
- ERR_FAIL_COND( p_node == out_name );
+ ERR_FAIL_COND(p_node == out_name);
- for(Map<StringName,NodeBase*>::Element *E=node_map.front();E;E=E->next()) {
+ for (Map<StringName, NodeBase *>::Element *E = node_map.front(); E; E = E->next()) {
NodeBase *nb = E->get();
- for(int i=0;i<nb->inputs.size();i++) {
+ for (int i = 0; i < nb->inputs.size(); i++) {
- if (nb->inputs[i].node==p_node)
- nb->inputs[i].node=StringName();
+ if (nb->inputs[i].node == p_node)
+ nb->inputs[i].node = StringName();
}
}
node_map.erase(p_node);
// compute last error again, just in case
- last_error=_cycle_test(out_name);
- dirty_caches=true;
+ last_error = _cycle_test(out_name);
+ dirty_caches = true;
}
-
-AnimationTreePlayer::ConnectError AnimationTreePlayer::_cycle_test(const StringName& p_at_node) {
+AnimationTreePlayer::ConnectError AnimationTreePlayer::_cycle_test(const StringName &p_at_node) {
ERR_FAIL_COND_V(!node_map.has(p_at_node), CONNECT_INCOMPLETE);
@@ -1480,11 +1371,10 @@ AnimationTreePlayer::ConnectError AnimationTreePlayer::_cycle_test(const StringN
if (nb->cycletest)
return CONNECT_CYCLE;
+ nb->cycletest = true;
- nb->cycletest=true;
-
- for(int i=0;i<nb->inputs.size();i++) {
- if (nb->inputs[i].node==StringName())
+ for (int i = 0; i < nb->inputs.size(); i++) {
+ if (nb->inputs[i].node == StringName())
return CONNECT_INCOMPLETE;
ConnectError _err = _cycle_test(nb->inputs[i].node);
@@ -1495,195 +1385,184 @@ AnimationTreePlayer::ConnectError AnimationTreePlayer::_cycle_test(const StringN
return CONNECT_OK;
}
+Error AnimationTreePlayer::connect_nodes(const StringName &p_src_node, const StringName &p_dst_node, int p_dst_input) {
-Error AnimationTreePlayer::connect_nodes(const StringName& p_src_node,const StringName& p_dst_node, int p_dst_input) {
-
- ERR_FAIL_COND_V( !node_map.has(p_src_node) , ERR_INVALID_PARAMETER);
- ERR_FAIL_COND_V( !node_map.has(p_dst_node) , ERR_INVALID_PARAMETER);
- ERR_FAIL_COND_V( p_src_node==p_dst_node , ERR_INVALID_PARAMETER);
+ ERR_FAIL_COND_V(!node_map.has(p_src_node), ERR_INVALID_PARAMETER);
+ ERR_FAIL_COND_V(!node_map.has(p_dst_node), ERR_INVALID_PARAMETER);
+ ERR_FAIL_COND_V(p_src_node == p_dst_node, ERR_INVALID_PARAMETER);
//NodeBase *src = node_map[p_src_node];
NodeBase *dst = node_map[p_dst_node];
- ERR_FAIL_INDEX_V( p_dst_input, dst->inputs.size(), ERR_INVALID_PARAMETER);
+ ERR_FAIL_INDEX_V(p_dst_input, dst->inputs.size(), ERR_INVALID_PARAMETER);
//int oldval = dst->inputs[p_dst_input].node;
- for(Map<StringName,NodeBase*>::Element *E=node_map.front();E;E=E->next()) {
+ for (Map<StringName, NodeBase *>::Element *E = node_map.front(); E; E = E->next()) {
NodeBase *nb = E->get();
- for(int i=0;i<nb->inputs.size();i++) {
+ for (int i = 0; i < nb->inputs.size(); i++) {
- if (nb->inputs[i].node==p_src_node)
- nb->inputs[i].node=StringName();
+ if (nb->inputs[i].node == p_src_node)
+ nb->inputs[i].node = StringName();
}
}
- dst->inputs[p_dst_input].node=p_src_node;
+ dst->inputs[p_dst_input].node = p_src_node;
- for(Map<StringName,NodeBase*>::Element *E=node_map.front();E;E=E->next()) {
+ for (Map<StringName, NodeBase *>::Element *E = node_map.front(); E; E = E->next()) {
NodeBase *nb = E->get();
- nb->cycletest=false;
+ nb->cycletest = false;
}
- last_error=_cycle_test(out_name);
+ last_error = _cycle_test(out_name);
if (last_error) {
- if (last_error==CONNECT_INCOMPLETE)
+ if (last_error == CONNECT_INCOMPLETE)
return ERR_UNCONFIGURED;
- else if (last_error==CONNECT_CYCLE)
+ else if (last_error == CONNECT_CYCLE)
return ERR_CYCLIC_LINK;
}
- dirty_caches=true;
+ dirty_caches = true;
return OK;
}
-bool AnimationTreePlayer::are_nodes_connected(const StringName& p_src_node,const StringName& p_dst_node, int p_dst_input) const {
+bool AnimationTreePlayer::are_nodes_connected(const StringName &p_src_node, const StringName &p_dst_node, int p_dst_input) const {
- ERR_FAIL_COND_V( !node_map.has(p_src_node) , false);
- ERR_FAIL_COND_V( !node_map.has(p_dst_node) , false);
- ERR_FAIL_COND_V( p_src_node==p_dst_node , false);
+ ERR_FAIL_COND_V(!node_map.has(p_src_node), false);
+ ERR_FAIL_COND_V(!node_map.has(p_dst_node), false);
+ ERR_FAIL_COND_V(p_src_node == p_dst_node, false);
NodeBase *dst = node_map[p_dst_node];
- return dst->inputs[p_dst_input].node==p_src_node;
-
+ return dst->inputs[p_dst_input].node == p_src_node;
}
-void AnimationTreePlayer::disconnect_nodes(const StringName& p_node, int p_input) {
+void AnimationTreePlayer::disconnect_nodes(const StringName &p_node, int p_input) {
- ERR_FAIL_COND( !node_map.has(p_node));
+ ERR_FAIL_COND(!node_map.has(p_node));
NodeBase *dst = node_map[p_node];
- ERR_FAIL_INDEX(p_input,dst->inputs.size());
- dst->inputs[p_input].node=StringName();
- last_error=CONNECT_INCOMPLETE;
- dirty_caches=true;
+ ERR_FAIL_INDEX(p_input, dst->inputs.size());
+ dst->inputs[p_input].node = StringName();
+ last_error = CONNECT_INCOMPLETE;
+ dirty_caches = true;
}
+void AnimationTreePlayer::get_connection_list(List<Connection> *p_connections) const {
-void AnimationTreePlayer::get_connection_list( List<Connection> *p_connections) const {
-
- for(Map<StringName,NodeBase*>::Element *E=node_map.front();E;E=E->next()) {
+ for (Map<StringName, NodeBase *>::Element *E = node_map.front(); E; E = E->next()) {
NodeBase *nb = E->get();
- for(int i=0;i<nb->inputs.size();i++) {
+ for (int i = 0; i < nb->inputs.size(); i++) {
- if (nb->inputs[i].node!=StringName()) {
+ if (nb->inputs[i].node != StringName()) {
Connection c;
- c.src_node=nb->inputs[i].node;
- c.dst_node=E->key();
- c.dst_input=i;
+ c.src_node = nb->inputs[i].node;
+ c.dst_node = E->key();
+ c.dst_input = i;
p_connections->push_back(c);
}
}
}
}
-AnimationTreePlayer::Track* AnimationTreePlayer::_find_track(const NodePath& p_path) {
+AnimationTreePlayer::Track *AnimationTreePlayer::_find_track(const NodePath &p_path) {
- Node *parent=get_node(base_path);
- ERR_FAIL_COND_V(!parent,NULL);
+ Node *parent = get_node(base_path);
+ ERR_FAIL_COND_V(!parent, NULL);
RES resource;
- Node *child=parent->get_node_and_resource(p_path,resource);
+ Node *child = parent->get_node_and_resource(p_path, resource);
if (!child) {
- String err = "Animation track references unknown Node: '"+String(p_path)+"'.";
+ String err = "Animation track references unknown Node: '" + String(p_path) + "'.";
WARN_PRINT(err.ascii().get_data());
return NULL;
}
- ObjectID id=child->get_instance_ID();
+ ObjectID id = child->get_instance_ID();
StringName property;
- int bone_idx=-1;
+ int bone_idx = -1;
if (p_path.get_property()) {
if (child->cast_to<Skeleton>())
- bone_idx = child->cast_to<Skeleton>()->find_bone( p_path.get_property() );
- if (bone_idx==-1)
- property=p_path.get_property();
+ bone_idx = child->cast_to<Skeleton>()->find_bone(p_path.get_property());
+ if (bone_idx == -1)
+ property = p_path.get_property();
}
TrackKey key;
- key.id=id;
- key.bone_idx=bone_idx;
- key.property=property;
+ key.id = id;
+ key.bone_idx = bone_idx;
+ key.property = property;
if (!track_map.has(key)) {
Track tr;
- tr.id=id;
- tr.object=resource.is_valid()?(Object*)resource.ptr():(Object*)child;
- tr.skeleton=child->cast_to<Skeleton>();
- tr.spatial=child->cast_to<Spatial>();
- tr.bone_idx=bone_idx;
- tr.property=property;
-
- track_map[key]=tr;
+ tr.id = id;
+ tr.object = resource.is_valid() ? (Object *)resource.ptr() : (Object *)child;
+ tr.skeleton = child->cast_to<Skeleton>();
+ tr.spatial = child->cast_to<Spatial>();
+ tr.bone_idx = bone_idx;
+ tr.property = property;
+
+ track_map[key] = tr;
}
return &track_map[key];
-
}
void AnimationTreePlayer::_recompute_caches() {
track_map.clear();
_recompute_caches(out_name);
- dirty_caches=false;
+ dirty_caches = false;
}
-void AnimationTreePlayer::_recompute_caches(const StringName& p_node) {
+void AnimationTreePlayer::_recompute_caches(const StringName &p_node) {
- ERR_FAIL_COND( !node_map.has(p_node) );
+ ERR_FAIL_COND(!node_map.has(p_node));
NodeBase *nb = node_map[p_node];
- if (nb->type==NODE_ANIMATION) {
+ if (nb->type == NODE_ANIMATION) {
- AnimationNode *an = static_cast<AnimationNode*>(nb);
+ AnimationNode *an = static_cast<AnimationNode *>(nb);
an->tref.clear();
if (!an->animation.is_null()) {
-
Ref<Animation> a = an->animation;
- for(int i=0;i<an->animation->get_track_count();i++) {
-
+ for (int i = 0; i < an->animation->get_track_count(); i++) {
Track *tr = _find_track(a->track_get_path(i));
if (!tr)
continue;
AnimationNode::TrackRef tref;
- tref.local_track=i;
- tref.track=tr;
- tref.weight=0;
+ tref.local_track = i;
+ tref.track = tr;
+ tref.weight = 0;
an->tref.push_back(tref);
-
}
}
}
- for(int i=0;i<nb->inputs.size();i++) {
+ for (int i = 0; i < nb->inputs.size(); i++) {
_recompute_caches(nb->inputs[i].node);
}
-
}
void AnimationTreePlayer::recompute_caches() {
- dirty_caches=true;
-
+ dirty_caches = true;
}
-
-
- /* playback */
+/* playback */
void AnimationTreePlayer::set_active(bool p_active) {
@@ -1699,7 +1578,6 @@ void AnimationTreePlayer::set_active(bool p_active) {
bool AnimationTreePlayer::is_active() const {
return active;
-
}
AnimationTreePlayer::ConnectError AnimationTreePlayer::get_last_error() const {
@@ -1709,33 +1587,31 @@ AnimationTreePlayer::ConnectError AnimationTreePlayer::get_last_error() const {
void AnimationTreePlayer::reset() {
-
- reset_request=true;
+ reset_request = true;
}
+void AnimationTreePlayer::set_base_path(const NodePath &p_path) {
-void AnimationTreePlayer::set_base_path(const NodePath& p_path) {
-
- base_path=p_path;
+ base_path = p_path;
recompute_caches();
}
-NodePath AnimationTreePlayer::get_base_path() const{
+NodePath AnimationTreePlayer::get_base_path() const {
return base_path;
}
-void AnimationTreePlayer::set_master_player(const NodePath& p_path) {
+void AnimationTreePlayer::set_master_player(const NodePath &p_path) {
- if (p_path==master)
+ if (p_path == master)
return;
- master=p_path;
+ master = p_path;
_update_sources();
recompute_caches();
}
-NodePath AnimationTreePlayer::get_master_player() const{
+NodePath AnimationTreePlayer::get_master_player() const {
return master;
}
@@ -1746,25 +1622,24 @@ PoolVector<String> AnimationTreePlayer::_get_node_list() {
get_node_list(&nl);
PoolVector<String> ret;
ret.resize(nl.size());
- int idx=0;
- for(List<StringName>::Element *E=nl.front();E;E=E->next()) {
- ret.set(idx++,E->get());
+ int idx = 0;
+ for (List<StringName>::Element *E = nl.front(); E; E = E->next()) {
+ ret.set(idx++, E->get());
}
return ret;
}
-
void AnimationTreePlayer::_update_sources() {
- if (master==NodePath())
+ if (master == NodePath())
return;
if (!is_inside_tree())
return;
Node *m = get_node(master);
if (!m) {
- master=NodePath();
+ master = NodePath();
ERR_FAIL_COND(!m);
}
@@ -1772,197 +1647,187 @@ void AnimationTreePlayer::_update_sources() {
if (!ap) {
- master=NodePath();
+ master = NodePath();
ERR_FAIL_COND(!ap);
}
- for (Map<StringName,NodeBase*>::Element *E=node_map.front();E;E=E->next()) {
+ for (Map<StringName, NodeBase *>::Element *E = node_map.front(); E; E = E->next()) {
- if (E->get()->type==NODE_ANIMATION) {
+ if (E->get()->type == NODE_ANIMATION) {
- AnimationNode *an = static_cast<AnimationNode*>(E->get());
+ AnimationNode *an = static_cast<AnimationNode *>(E->get());
- if (an->from!="") {
+ if (an->from != "") {
an->animation = ap->get_animation(an->from);
}
}
}
-
-
}
-bool AnimationTreePlayer::node_exists(const StringName& p_name) const {
+bool AnimationTreePlayer::node_exists(const StringName &p_name) const {
return (node_map.has(p_name));
}
-Error AnimationTreePlayer::node_rename(const StringName& p_node,const StringName& p_new_name) {
+Error AnimationTreePlayer::node_rename(const StringName &p_node, const StringName &p_new_name) {
- if (p_new_name==p_node)
+ if (p_new_name == p_node)
return OK;
- ERR_FAIL_COND_V(!node_map.has(p_node),ERR_ALREADY_EXISTS);
- ERR_FAIL_COND_V(node_map.has(p_new_name),ERR_ALREADY_EXISTS);
- ERR_FAIL_COND_V(p_new_name==StringName(),ERR_INVALID_DATA);
- ERR_FAIL_COND_V(p_node==out_name,ERR_INVALID_DATA);
- ERR_FAIL_COND_V(p_new_name==out_name,ERR_INVALID_DATA);
+ ERR_FAIL_COND_V(!node_map.has(p_node), ERR_ALREADY_EXISTS);
+ ERR_FAIL_COND_V(node_map.has(p_new_name), ERR_ALREADY_EXISTS);
+ ERR_FAIL_COND_V(p_new_name == StringName(), ERR_INVALID_DATA);
+ ERR_FAIL_COND_V(p_node == out_name, ERR_INVALID_DATA);
+ ERR_FAIL_COND_V(p_new_name == out_name, ERR_INVALID_DATA);
- for(Map<StringName,NodeBase*>::Element *E=node_map.front();E;E=E->next()) {
+ for (Map<StringName, NodeBase *>::Element *E = node_map.front(); E; E = E->next()) {
NodeBase *nb = E->get();
- for(int i=0;i<nb->inputs.size();i++) {
+ for (int i = 0; i < nb->inputs.size(); i++) {
- if (nb->inputs[i].node==p_node) {
- nb->inputs[i].node=p_new_name;
+ if (nb->inputs[i].node == p_node) {
+ nb->inputs[i].node = p_new_name;
}
}
}
- node_map[p_new_name]=node_map[p_node];
+ node_map[p_new_name] = node_map[p_node];
node_map.erase(p_node);
return OK;
-
}
-
void AnimationTreePlayer::_bind_methods() {
- ClassDB::bind_method(D_METHOD("add_node","type","id"),&AnimationTreePlayer::add_node);
-
- ClassDB::bind_method(D_METHOD("node_exists","node"),&AnimationTreePlayer::node_exists);
- ClassDB::bind_method(D_METHOD("node_rename","node","new_name"),&AnimationTreePlayer::node_rename);
-
- ClassDB::bind_method(D_METHOD("node_get_type","id"),&AnimationTreePlayer::node_get_type);
- ClassDB::bind_method(D_METHOD("node_get_input_count","id"),&AnimationTreePlayer::node_get_input_count);
- ClassDB::bind_method(D_METHOD("node_get_input_source","id","idx"),&AnimationTreePlayer::node_get_input_source);
+ ClassDB::bind_method(D_METHOD("add_node", "type", "id"), &AnimationTreePlayer::add_node);
- ClassDB::bind_method(D_METHOD("animation_node_set_animation","id","animation:Animation"),&AnimationTreePlayer::animation_node_set_animation);
- ClassDB::bind_method(D_METHOD("animation_node_get_animation:Animation","id"),&AnimationTreePlayer::animation_node_get_animation);
+ ClassDB::bind_method(D_METHOD("node_exists", "node"), &AnimationTreePlayer::node_exists);
+ ClassDB::bind_method(D_METHOD("node_rename", "node", "new_name"), &AnimationTreePlayer::node_rename);
- ClassDB::bind_method(D_METHOD("animation_node_set_master_animation","id","source"),&AnimationTreePlayer::animation_node_set_master_animation);
- ClassDB::bind_method(D_METHOD("animation_node_get_master_animation","id"),&AnimationTreePlayer::animation_node_get_master_animation);
- ClassDB::bind_method(D_METHOD("animation_node_set_filter_path","id","path","enable"),&AnimationTreePlayer::animation_node_set_filter_path);
+ ClassDB::bind_method(D_METHOD("node_get_type", "id"), &AnimationTreePlayer::node_get_type);
+ ClassDB::bind_method(D_METHOD("node_get_input_count", "id"), &AnimationTreePlayer::node_get_input_count);
+ ClassDB::bind_method(D_METHOD("node_get_input_source", "id", "idx"), &AnimationTreePlayer::node_get_input_source);
- ClassDB::bind_method(D_METHOD("oneshot_node_set_fadein_time","id","time_sec"),&AnimationTreePlayer::oneshot_node_set_fadein_time);
- ClassDB::bind_method(D_METHOD("oneshot_node_get_fadein_time","id"),&AnimationTreePlayer::oneshot_node_get_fadein_time);
+ ClassDB::bind_method(D_METHOD("animation_node_set_animation", "id", "animation:Animation"), &AnimationTreePlayer::animation_node_set_animation);
+ ClassDB::bind_method(D_METHOD("animation_node_get_animation:Animation", "id"), &AnimationTreePlayer::animation_node_get_animation);
- ClassDB::bind_method(D_METHOD("oneshot_node_set_fadeout_time","id","time_sec"),&AnimationTreePlayer::oneshot_node_set_fadeout_time);
- ClassDB::bind_method(D_METHOD("oneshot_node_get_fadeout_time","id"),&AnimationTreePlayer::oneshot_node_get_fadeout_time);
+ ClassDB::bind_method(D_METHOD("animation_node_set_master_animation", "id", "source"), &AnimationTreePlayer::animation_node_set_master_animation);
+ ClassDB::bind_method(D_METHOD("animation_node_get_master_animation", "id"), &AnimationTreePlayer::animation_node_get_master_animation);
+ ClassDB::bind_method(D_METHOD("animation_node_set_filter_path", "id", "path", "enable"), &AnimationTreePlayer::animation_node_set_filter_path);
+ ClassDB::bind_method(D_METHOD("oneshot_node_set_fadein_time", "id", "time_sec"), &AnimationTreePlayer::oneshot_node_set_fadein_time);
+ ClassDB::bind_method(D_METHOD("oneshot_node_get_fadein_time", "id"), &AnimationTreePlayer::oneshot_node_get_fadein_time);
- ClassDB::bind_method(D_METHOD("oneshot_node_set_autorestart","id","enable"),&AnimationTreePlayer::oneshot_node_set_autorestart);
- ClassDB::bind_method(D_METHOD("oneshot_node_set_autorestart_delay","id","delay_sec"),&AnimationTreePlayer::oneshot_node_set_autorestart_delay);
- ClassDB::bind_method(D_METHOD("oneshot_node_set_autorestart_random_delay","id","rand_sec"),&AnimationTreePlayer::oneshot_node_set_autorestart_random_delay);
+ ClassDB::bind_method(D_METHOD("oneshot_node_set_fadeout_time", "id", "time_sec"), &AnimationTreePlayer::oneshot_node_set_fadeout_time);
+ ClassDB::bind_method(D_METHOD("oneshot_node_get_fadeout_time", "id"), &AnimationTreePlayer::oneshot_node_get_fadeout_time);
+ ClassDB::bind_method(D_METHOD("oneshot_node_set_autorestart", "id", "enable"), &AnimationTreePlayer::oneshot_node_set_autorestart);
+ ClassDB::bind_method(D_METHOD("oneshot_node_set_autorestart_delay", "id", "delay_sec"), &AnimationTreePlayer::oneshot_node_set_autorestart_delay);
+ ClassDB::bind_method(D_METHOD("oneshot_node_set_autorestart_random_delay", "id", "rand_sec"), &AnimationTreePlayer::oneshot_node_set_autorestart_random_delay);
- ClassDB::bind_method(D_METHOD("oneshot_node_has_autorestart","id"),&AnimationTreePlayer::oneshot_node_has_autorestart);
- ClassDB::bind_method(D_METHOD("oneshot_node_get_autorestart_delay","id"),&AnimationTreePlayer::oneshot_node_get_autorestart_delay);
- ClassDB::bind_method(D_METHOD("oneshot_node_get_autorestart_random_delay","id"),&AnimationTreePlayer::oneshot_node_get_autorestart_random_delay);
+ ClassDB::bind_method(D_METHOD("oneshot_node_has_autorestart", "id"), &AnimationTreePlayer::oneshot_node_has_autorestart);
+ ClassDB::bind_method(D_METHOD("oneshot_node_get_autorestart_delay", "id"), &AnimationTreePlayer::oneshot_node_get_autorestart_delay);
+ ClassDB::bind_method(D_METHOD("oneshot_node_get_autorestart_random_delay", "id"), &AnimationTreePlayer::oneshot_node_get_autorestart_random_delay);
- ClassDB::bind_method(D_METHOD("oneshot_node_start","id"),&AnimationTreePlayer::oneshot_node_start);
- ClassDB::bind_method(D_METHOD("oneshot_node_stop","id"),&AnimationTreePlayer::oneshot_node_stop);
- ClassDB::bind_method(D_METHOD("oneshot_node_is_active","id"),&AnimationTreePlayer::oneshot_node_is_active);
- ClassDB::bind_method(D_METHOD("oneshot_node_set_filter_path","id","path","enable"),&AnimationTreePlayer::oneshot_node_set_filter_path);
+ ClassDB::bind_method(D_METHOD("oneshot_node_start", "id"), &AnimationTreePlayer::oneshot_node_start);
+ ClassDB::bind_method(D_METHOD("oneshot_node_stop", "id"), &AnimationTreePlayer::oneshot_node_stop);
+ ClassDB::bind_method(D_METHOD("oneshot_node_is_active", "id"), &AnimationTreePlayer::oneshot_node_is_active);
+ ClassDB::bind_method(D_METHOD("oneshot_node_set_filter_path", "id", "path", "enable"), &AnimationTreePlayer::oneshot_node_set_filter_path);
- ClassDB::bind_method(D_METHOD("mix_node_set_amount","id","ratio"),&AnimationTreePlayer::mix_node_set_amount);
- ClassDB::bind_method(D_METHOD("mix_node_get_amount","id"),&AnimationTreePlayer::mix_node_get_amount);
+ ClassDB::bind_method(D_METHOD("mix_node_set_amount", "id", "ratio"), &AnimationTreePlayer::mix_node_set_amount);
+ ClassDB::bind_method(D_METHOD("mix_node_get_amount", "id"), &AnimationTreePlayer::mix_node_get_amount);
- ClassDB::bind_method(D_METHOD("blend2_node_set_amount","id","blend"),&AnimationTreePlayer::blend2_node_set_amount);
- ClassDB::bind_method(D_METHOD("blend2_node_get_amount","id"),&AnimationTreePlayer::blend2_node_get_amount);
- ClassDB::bind_method(D_METHOD("blend2_node_set_filter_path","id","path","enable"),&AnimationTreePlayer::blend2_node_set_filter_path);
+ ClassDB::bind_method(D_METHOD("blend2_node_set_amount", "id", "blend"), &AnimationTreePlayer::blend2_node_set_amount);
+ ClassDB::bind_method(D_METHOD("blend2_node_get_amount", "id"), &AnimationTreePlayer::blend2_node_get_amount);
+ ClassDB::bind_method(D_METHOD("blend2_node_set_filter_path", "id", "path", "enable"), &AnimationTreePlayer::blend2_node_set_filter_path);
- ClassDB::bind_method(D_METHOD("blend3_node_set_amount","id","blend"),&AnimationTreePlayer::blend3_node_set_amount);
- ClassDB::bind_method(D_METHOD("blend3_node_get_amount","id"),&AnimationTreePlayer::blend3_node_get_amount);
+ ClassDB::bind_method(D_METHOD("blend3_node_set_amount", "id", "blend"), &AnimationTreePlayer::blend3_node_set_amount);
+ ClassDB::bind_method(D_METHOD("blend3_node_get_amount", "id"), &AnimationTreePlayer::blend3_node_get_amount);
- ClassDB::bind_method(D_METHOD("blend4_node_set_amount","id","blend"),&AnimationTreePlayer::blend4_node_set_amount);
- ClassDB::bind_method(D_METHOD("blend4_node_get_amount","id"),&AnimationTreePlayer::blend4_node_get_amount);
+ ClassDB::bind_method(D_METHOD("blend4_node_set_amount", "id", "blend"), &AnimationTreePlayer::blend4_node_set_amount);
+ ClassDB::bind_method(D_METHOD("blend4_node_get_amount", "id"), &AnimationTreePlayer::blend4_node_get_amount);
- ClassDB::bind_method(D_METHOD("timescale_node_set_scale","id","scale"),&AnimationTreePlayer::timescale_node_set_scale);
- ClassDB::bind_method(D_METHOD("timescale_node_get_scale","id"),&AnimationTreePlayer::timescale_node_get_scale);
+ ClassDB::bind_method(D_METHOD("timescale_node_set_scale", "id", "scale"), &AnimationTreePlayer::timescale_node_set_scale);
+ ClassDB::bind_method(D_METHOD("timescale_node_get_scale", "id"), &AnimationTreePlayer::timescale_node_get_scale);
- ClassDB::bind_method(D_METHOD("timeseek_node_seek","id","pos_sec"),&AnimationTreePlayer::timeseek_node_seek);
+ ClassDB::bind_method(D_METHOD("timeseek_node_seek", "id", "pos_sec"), &AnimationTreePlayer::timeseek_node_seek);
- ClassDB::bind_method(D_METHOD("transition_node_set_input_count","id","count"),&AnimationTreePlayer::transition_node_set_input_count);
- ClassDB::bind_method(D_METHOD("transition_node_get_input_count","id"),&AnimationTreePlayer::transition_node_get_input_count);
- ClassDB::bind_method(D_METHOD("transition_node_delete_input","id","input_idx"),&AnimationTreePlayer::transition_node_delete_input);
+ ClassDB::bind_method(D_METHOD("transition_node_set_input_count", "id", "count"), &AnimationTreePlayer::transition_node_set_input_count);
+ ClassDB::bind_method(D_METHOD("transition_node_get_input_count", "id"), &AnimationTreePlayer::transition_node_get_input_count);
+ ClassDB::bind_method(D_METHOD("transition_node_delete_input", "id", "input_idx"), &AnimationTreePlayer::transition_node_delete_input);
- ClassDB::bind_method(D_METHOD("transition_node_set_input_auto_advance","id","input_idx","enable"),&AnimationTreePlayer::transition_node_set_input_auto_advance);
- ClassDB::bind_method(D_METHOD("transition_node_has_input_auto_advance","id","input_idx"),&AnimationTreePlayer::transition_node_has_input_auto_advance);
+ ClassDB::bind_method(D_METHOD("transition_node_set_input_auto_advance", "id", "input_idx", "enable"), &AnimationTreePlayer::transition_node_set_input_auto_advance);
+ ClassDB::bind_method(D_METHOD("transition_node_has_input_auto_advance", "id", "input_idx"), &AnimationTreePlayer::transition_node_has_input_auto_advance);
- ClassDB::bind_method(D_METHOD("transition_node_set_xfade_time","id","time_sec"),&AnimationTreePlayer::transition_node_set_xfade_time);
- ClassDB::bind_method(D_METHOD("transition_node_get_xfade_time","id"),&AnimationTreePlayer::transition_node_get_xfade_time);
+ ClassDB::bind_method(D_METHOD("transition_node_set_xfade_time", "id", "time_sec"), &AnimationTreePlayer::transition_node_set_xfade_time);
+ ClassDB::bind_method(D_METHOD("transition_node_get_xfade_time", "id"), &AnimationTreePlayer::transition_node_get_xfade_time);
- ClassDB::bind_method(D_METHOD("transition_node_set_current","id","input_idx"),&AnimationTreePlayer::transition_node_set_current);
- ClassDB::bind_method(D_METHOD("transition_node_get_current","id"),&AnimationTreePlayer::transition_node_get_current);
+ ClassDB::bind_method(D_METHOD("transition_node_set_current", "id", "input_idx"), &AnimationTreePlayer::transition_node_set_current);
+ ClassDB::bind_method(D_METHOD("transition_node_get_current", "id"), &AnimationTreePlayer::transition_node_get_current);
+ ClassDB::bind_method(D_METHOD("node_set_pos", "id", "screen_pos"), &AnimationTreePlayer::node_set_pos);
+ ClassDB::bind_method(D_METHOD("node_get_pos", "id"), &AnimationTreePlayer::node_get_pos);
- ClassDB::bind_method(D_METHOD("node_set_pos","id","screen_pos"),&AnimationTreePlayer::node_set_pos);
- ClassDB::bind_method(D_METHOD("node_get_pos","id"),&AnimationTreePlayer::node_get_pos);
+ ClassDB::bind_method(D_METHOD("remove_node", "id"), &AnimationTreePlayer::remove_node);
+ ClassDB::bind_method(D_METHOD("connect_nodes", "id", "dst_id", "dst_input_idx"), &AnimationTreePlayer::connect_nodes);
+ ClassDB::bind_method(D_METHOD("are_nodes_connected", "id", "dst_id", "dst_input_idx"), &AnimationTreePlayer::are_nodes_connected);
+ ClassDB::bind_method(D_METHOD("disconnect_nodes", "id", "dst_input_idx"), &AnimationTreePlayer::disconnect_nodes);
- ClassDB::bind_method(D_METHOD("remove_node","id"),&AnimationTreePlayer::remove_node);
- ClassDB::bind_method(D_METHOD("connect_nodes","id","dst_id","dst_input_idx"),&AnimationTreePlayer::connect_nodes);
- ClassDB::bind_method(D_METHOD("are_nodes_connected","id","dst_id","dst_input_idx"),&AnimationTreePlayer::are_nodes_connected);
- ClassDB::bind_method(D_METHOD("disconnect_nodes","id","dst_input_idx"),&AnimationTreePlayer::disconnect_nodes);
+ ClassDB::bind_method(D_METHOD("set_active", "enabled"), &AnimationTreePlayer::set_active);
+ ClassDB::bind_method(D_METHOD("is_active"), &AnimationTreePlayer::is_active);
- ClassDB::bind_method(D_METHOD("set_active","enabled"),&AnimationTreePlayer::set_active);
- ClassDB::bind_method(D_METHOD("is_active"),&AnimationTreePlayer::is_active);
+ ClassDB::bind_method(D_METHOD("set_base_path", "path"), &AnimationTreePlayer::set_base_path);
+ ClassDB::bind_method(D_METHOD("get_base_path"), &AnimationTreePlayer::get_base_path);
- ClassDB::bind_method(D_METHOD("set_base_path","path"),&AnimationTreePlayer::set_base_path);
- ClassDB::bind_method(D_METHOD("get_base_path"),&AnimationTreePlayer::get_base_path);
+ ClassDB::bind_method(D_METHOD("set_master_player", "nodepath"), &AnimationTreePlayer::set_master_player);
+ ClassDB::bind_method(D_METHOD("get_master_player"), &AnimationTreePlayer::get_master_player);
- ClassDB::bind_method(D_METHOD("set_master_player","nodepath"),&AnimationTreePlayer::set_master_player);
- ClassDB::bind_method(D_METHOD("get_master_player"),&AnimationTreePlayer::get_master_player);
+ ClassDB::bind_method(D_METHOD("get_node_list"), &AnimationTreePlayer::_get_node_list);
- ClassDB::bind_method(D_METHOD("get_node_list"),&AnimationTreePlayer::_get_node_list);
-
- ClassDB::bind_method(D_METHOD("set_animation_process_mode","mode"),&AnimationTreePlayer::set_animation_process_mode);
- ClassDB::bind_method(D_METHOD("get_animation_process_mode"),&AnimationTreePlayer::get_animation_process_mode);
+ ClassDB::bind_method(D_METHOD("set_animation_process_mode", "mode"), &AnimationTreePlayer::set_animation_process_mode);
+ ClassDB::bind_method(D_METHOD("get_animation_process_mode"), &AnimationTreePlayer::get_animation_process_mode);
ClassDB::bind_method(D_METHOD("advance", "delta"), &AnimationTreePlayer::advance);
+ ClassDB::bind_method(D_METHOD("reset"), &AnimationTreePlayer::reset);
- ClassDB::bind_method(D_METHOD("reset"),&AnimationTreePlayer::reset);
-
- ClassDB::bind_method(D_METHOD("recompute_caches"),&AnimationTreePlayer::recompute_caches);
+ ClassDB::bind_method(D_METHOD("recompute_caches"), &AnimationTreePlayer::recompute_caches);
- ADD_GROUP("Playback","playback_");
+ ADD_GROUP("Playback", "playback_");
ADD_PROPERTY(PropertyInfo(Variant::INT, "playback_process_mode", PROPERTY_HINT_ENUM, "Fixed,Idle"), "set_animation_process_mode", "get_animation_process_mode");
- BIND_CONSTANT( NODE_OUTPUT );
- BIND_CONSTANT( NODE_ANIMATION );
- BIND_CONSTANT( NODE_ONESHOT );
- BIND_CONSTANT( NODE_MIX );
- BIND_CONSTANT( NODE_BLEND2 );
- BIND_CONSTANT( NODE_BLEND3 );
- BIND_CONSTANT( NODE_BLEND4 );
- BIND_CONSTANT( NODE_TIMESCALE );
- BIND_CONSTANT( NODE_TIMESEEK );
- BIND_CONSTANT( NODE_TRANSITION );
+ BIND_CONSTANT(NODE_OUTPUT);
+ BIND_CONSTANT(NODE_ANIMATION);
+ BIND_CONSTANT(NODE_ONESHOT);
+ BIND_CONSTANT(NODE_MIX);
+ BIND_CONSTANT(NODE_BLEND2);
+ BIND_CONSTANT(NODE_BLEND3);
+ BIND_CONSTANT(NODE_BLEND4);
+ BIND_CONSTANT(NODE_TIMESCALE);
+ BIND_CONSTANT(NODE_TIMESEEK);
+ BIND_CONSTANT(NODE_TRANSITION);
}
-
AnimationTreePlayer::AnimationTreePlayer() {
- active_list=NULL;
- out = memnew( NodeOut ) ;
- out_name="out";
- out->pos=Point2(40,40);
- node_map.insert( out_name , out);
+ active_list = NULL;
+ out = memnew(NodeOut);
+ out_name = "out";
+ out->pos = Point2(40, 40);
+ node_map.insert(out_name, out);
animation_process_mode = ANIMATION_PROCESS_IDLE;
processing = false;
- active=false;
- dirty_caches=true;
- reset_request=true;
- last_error=CONNECT_INCOMPLETE;
- base_path=String("..");
+ active = false;
+ dirty_caches = true;
+ reset_request = true;
+ last_error = CONNECT_INCOMPLETE;
+ base_path = String("..");
}
-
AnimationTreePlayer::~AnimationTreePlayer() {
- while(node_map.size()) {
- memdelete( node_map.front()->get() );
- node_map.erase( node_map.front() );
+ while (node_map.size()) {
+ memdelete(node_map.front()->get());
+ node_map.erase(node_map.front());
}
}
diff --git a/scene/animation/animation_tree_player.h b/scene/animation/animation_tree_player.h
index 5e118be034..35fce9b15d 100644
--- a/scene/animation/animation_tree_player.h
+++ b/scene/animation/animation_tree_player.h
@@ -29,16 +29,14 @@
#ifndef ANIMATION_TREE_PLAYER_H
#define ANIMATION_TREE_PLAYER_H
-
-#include "scene/resources/animation.h"
-#include "scene/3d/spatial.h"
-#include "scene/3d/skeleton.h"
#include "animation_player.h"
-
+#include "scene/3d/skeleton.h"
+#include "scene/3d/spatial.h"
+#include "scene/resources/animation.h"
class AnimationTreePlayer : public Node {
- GDCLASS( AnimationTreePlayer, Node );
+ GDCLASS(AnimationTreePlayer, Node);
OBJ_CATEGORY("Animation Nodes");
public:
@@ -71,10 +69,9 @@ public:
};
private:
-
enum {
- DISCONNECTED=-1,
+ DISCONNECTED = -1,
};
struct TrackKey {
@@ -83,23 +80,22 @@ private:
StringName property;
int bone_idx;
- inline bool operator<(const TrackKey& p_right) const {
+ inline bool operator<(const TrackKey &p_right) const {
- if (id==p_right.id) {
- if (bone_idx==p_right.bone_idx) {
- return property<p_right.property;
+ if (id == p_right.id) {
+ if (bone_idx == p_right.bone_idx) {
+ return property < p_right.property;
} else
- return bone_idx<p_right.bone_idx;
+ return bone_idx < p_right.bone_idx;
} else
- return id<p_right.id;
+ return id < p_right.id;
}
};
-
struct Track {
uint32_t id;
Object *object;
- Spatial* spatial;
+ Spatial *spatial;
Skeleton *skeleton;
int bone_idx;
StringName property;
@@ -113,12 +109,10 @@ private:
bool skip;
};
-
- typedef Map<TrackKey,Track> TrackMap;
+ typedef Map<TrackKey, Track> TrackMap;
TrackMap track_map;
-
struct Input {
StringName node;
@@ -132,23 +126,24 @@ private:
NodeType type;
Point2 pos;
-
Vector<Input> inputs;
NodeBase() { cycletest = false; };
- virtual ~NodeBase() { cycletest=false; }
+ virtual ~NodeBase() { cycletest = false; }
};
struct NodeOut : public NodeBase {
- NodeOut() { type=NODE_OUTPUT; inputs.resize(1); }
+ NodeOut() {
+ type = NODE_OUTPUT;
+ inputs.resize(1);
+ }
};
struct AnimationNode : public NodeBase {
Ref<Animation> animation;
-
struct TrackRef {
int local_track;
Track *track;
@@ -163,13 +158,17 @@ private:
String from;
bool skip;
- HashMap<NodePath,bool> filter;
+ HashMap<NodePath, bool> filter;
- AnimationNode() { type=NODE_ANIMATION; next=NULL; last_version=0; skip=false; }
+ AnimationNode() {
+ type = NODE_ANIMATION;
+ next = NULL;
+ last_version = 0;
+ skip = false;
+ }
};
-
- struct OneShotNode : public NodeBase {
+ struct OneShotNode : public NodeBase {
bool active;
bool start;
@@ -181,52 +180,84 @@ private:
float autorestart_random_delay;
bool mix;
-
float time;
float remaining;
float autorestart_remaining;
- HashMap<NodePath,bool> filter;
-
- OneShotNode() { type=NODE_ONESHOT; fade_in=0; fade_out=0; inputs.resize(2); autorestart=false; autorestart_delay=1; autorestart_remaining=0; mix=false; active=false; start=false;}
+ HashMap<NodePath, bool> filter;
+
+ OneShotNode() {
+ type = NODE_ONESHOT;
+ fade_in = 0;
+ fade_out = 0;
+ inputs.resize(2);
+ autorestart = false;
+ autorestart_delay = 1;
+ autorestart_remaining = 0;
+ mix = false;
+ active = false;
+ start = false;
+ }
};
struct MixNode : public NodeBase {
float amount;
- MixNode() { type=NODE_MIX; inputs.resize(2); }
+ MixNode() {
+ type = NODE_MIX;
+ inputs.resize(2);
+ }
};
- struct Blend2Node : public NodeBase {
+ struct Blend2Node : public NodeBase {
float value;
- HashMap<NodePath,bool> filter;
- Blend2Node() { type=NODE_BLEND2; value=0; inputs.resize(2); }
+ HashMap<NodePath, bool> filter;
+ Blend2Node() {
+ type = NODE_BLEND2;
+ value = 0;
+ inputs.resize(2);
+ }
};
struct Blend3Node : public NodeBase {
float value;
- Blend3Node() { type=NODE_BLEND3; value=0; inputs.resize(3); }
+ Blend3Node() {
+ type = NODE_BLEND3;
+ value = 0;
+ inputs.resize(3);
+ }
};
struct Blend4Node : public NodeBase {
Point2 value;
- Blend4Node() { type=NODE_BLEND4; inputs.resize(4); }
+ Blend4Node() {
+ type = NODE_BLEND4;
+ inputs.resize(4);
+ }
};
struct TimeScaleNode : public NodeBase {
float scale;
- TimeScaleNode() { type=NODE_TIMESCALE; scale=1; inputs.resize(1); }
+ TimeScaleNode() {
+ type = NODE_TIMESCALE;
+ scale = 1;
+ inputs.resize(1);
+ }
};
struct TimeSeekNode : public NodeBase {
float seek_pos;
- TimeSeekNode() { type=NODE_TIMESEEK; inputs.resize(1); seek_pos=-1; }
+ TimeSeekNode() {
+ type = NODE_TIMESEEK;
+ inputs.resize(1);
+ seek_pos = -1;
+ }
};
struct TransitionNode : public NodeBase {
@@ -234,7 +265,7 @@ private:
struct InputData {
bool auto_advance;
- InputData() { auto_advance=false; }
+ InputData() { auto_advance = false; }
};
Vector<InputData> input_data;
@@ -244,23 +275,30 @@ private:
int prev;
bool switched;
-
float time;
int current;
float xfade;
- TransitionNode() { type=NODE_TRANSITION; xfade=0; inputs.resize(1); input_data.resize(1); current=0; prev=-1; prev_time=0; prev_xfading=0; switched=false; }
+ TransitionNode() {
+ type = NODE_TRANSITION;
+ xfade = 0;
+ inputs.resize(1);
+ input_data.resize(1);
+ current = 0;
+ prev = -1;
+ prev_time = 0;
+ prev_xfading = 0;
+ switched = false;
+ }
void set_current(int p_current);
};
-
void _update_sources();
StringName out_name;
NodeOut *out;
-
NodePath base_path;
NodePath master;
@@ -270,141 +308,132 @@ private:
bool processing;
bool active;
bool dirty_caches;
- Map<StringName,NodeBase*> node_map;
+ Map<StringName, NodeBase *> node_map;
// return time left to finish animation
- float _process_node(const StringName& p_node,AnimationNode **r_prev_anim,float p_step, bool p_seek=false, float p_fallback_weight = 1.0, HashMap<NodePath,float>* p_weights = NULL);
+ float _process_node(const StringName &p_node, AnimationNode **r_prev_anim, float p_step, bool p_seek = false, float p_fallback_weight = 1.0, HashMap<NodePath, float> *p_weights = NULL);
void _process_animation(float p_delta);
bool reset_request;
ConnectError _cycle_test(const StringName &p_at_node);
- Track* _find_track(const NodePath& p_path);
+ Track *_find_track(const NodePath &p_path);
void _recompute_caches();
- void _recompute_caches(const StringName& p_node);
+ void _recompute_caches(const StringName &p_node);
PoolVector<String> _get_node_list();
-
- void _compute_weights(float *p_fallback_weight, HashMap<NodePath,float> *p_weights, float p_coeff, const HashMap<NodePath,bool> *p_filter = NULL, float p_filtered_coeff = 0);
-
-protected:
-
+ void _compute_weights(float *p_fallback_weight, HashMap<NodePath, float> *p_weights, float p_coeff, const HashMap<NodePath, bool> *p_filter = NULL, float p_filtered_coeff = 0);
-
- 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;
+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);
static void _bind_methods();
-
public:
+ void add_node(NodeType p_type, const StringName &p_node); // nodes must be >0 node 0 is built-in (exit)
+ bool node_exists(const StringName &p_name) const;
-
- void add_node(NodeType p_type, const StringName& p_node); // nodes must be >0 node 0 is built-in (exit)
- bool node_exists(const StringName& p_name) const;
-
- Error node_rename(const StringName& p_node,const StringName& p_new_name);
- int node_get_input_count(const StringName& p_node) const;
- StringName node_get_input_source(const StringName& p_node,int p_input) const;
+ Error node_rename(const StringName &p_node, const StringName &p_new_name);
+ int node_get_input_count(const StringName &p_node) const;
+ StringName node_get_input_source(const StringName &p_node, int p_input) const;
/* ANIMATION NODE */
- void animation_node_set_animation(const StringName& p_node,const Ref<Animation>& p_animation);
- Ref<Animation> animation_node_get_animation(const StringName& p_node) const;
- void animation_node_set_master_animation(const StringName& p_node,const String& p_master_animation);
- String animation_node_get_master_animation(const StringName& p_node) const;
+ void animation_node_set_animation(const StringName &p_node, const Ref<Animation> &p_animation);
+ Ref<Animation> animation_node_get_animation(const StringName &p_node) const;
+ void animation_node_set_master_animation(const StringName &p_node, const String &p_master_animation);
+ String animation_node_get_master_animation(const StringName &p_node) const;
- void animation_node_set_filter_path(const StringName& p_node,const NodePath& p_filter,bool p_enable);
- void animation_node_set_get_filtered_paths(const StringName& p_node,List<NodePath> *r_paths) const;
- bool animation_node_is_path_filtered(const StringName& p_node,const NodePath& p_path) const;
+ void animation_node_set_filter_path(const StringName &p_node, const NodePath &p_filter, bool p_enable);
+ void animation_node_set_get_filtered_paths(const StringName &p_node, List<NodePath> *r_paths) const;
+ bool animation_node_is_path_filtered(const StringName &p_node, const NodePath &p_path) const;
/* ONE SHOT NODE */
- void oneshot_node_set_fadein_time(const StringName& p_node,float p_time);
- void oneshot_node_set_fadeout_time(const StringName& p_node,float p_time);
+ void oneshot_node_set_fadein_time(const StringName &p_node, float p_time);
+ void oneshot_node_set_fadeout_time(const StringName &p_node, float p_time);
- float oneshot_node_get_fadein_time(const StringName& p_node) const;
- float oneshot_node_get_fadeout_time(const StringName& p_node) const;
+ float oneshot_node_get_fadein_time(const StringName &p_node) const;
+ float oneshot_node_get_fadeout_time(const StringName &p_node) const;
- void oneshot_node_set_autorestart(const StringName& p_node,bool p_active);
- void oneshot_node_set_autorestart_delay(const StringName& p_node,float p_time);
- void oneshot_node_set_autorestart_random_delay(const StringName& p_node,float p_time);
+ void oneshot_node_set_autorestart(const StringName &p_node, bool p_active);
+ void oneshot_node_set_autorestart_delay(const StringName &p_node, float p_time);
+ void oneshot_node_set_autorestart_random_delay(const StringName &p_node, float p_time);
- bool oneshot_node_has_autorestart(const StringName& p_node) const;
- float oneshot_node_get_autorestart_delay(const StringName& p_node) const;
- float oneshot_node_get_autorestart_random_delay(const StringName& p_node) const;
+ bool oneshot_node_has_autorestart(const StringName &p_node) const;
+ float oneshot_node_get_autorestart_delay(const StringName &p_node) const;
+ float oneshot_node_get_autorestart_random_delay(const StringName &p_node) const;
- void oneshot_node_set_mix_mode(const StringName& p_node,bool p_enabled);
- bool oneshot_node_get_mix_mode(const StringName& p_node) const;
+ void oneshot_node_set_mix_mode(const StringName &p_node, bool p_enabled);
+ bool oneshot_node_get_mix_mode(const StringName &p_node) const;
- void oneshot_node_start(const StringName& p_node);
- void oneshot_node_stop(const StringName& p_node);
- bool oneshot_node_is_active(const StringName& p_node) const;
-
- void oneshot_node_set_filter_path(const StringName& p_node,const NodePath& p_filter,bool p_enable);
- void oneshot_node_set_get_filtered_paths(const StringName& p_node,List<NodePath> *r_paths) const;
- bool oneshot_node_is_path_filtered(const StringName& p_node,const NodePath& p_path) const;
+ void oneshot_node_start(const StringName &p_node);
+ void oneshot_node_stop(const StringName &p_node);
+ bool oneshot_node_is_active(const StringName &p_node) const;
+ void oneshot_node_set_filter_path(const StringName &p_node, const NodePath &p_filter, bool p_enable);
+ void oneshot_node_set_get_filtered_paths(const StringName &p_node, List<NodePath> *r_paths) const;
+ bool oneshot_node_is_path_filtered(const StringName &p_node, const NodePath &p_path) const;
/* MIX/BLEND NODES */
- void mix_node_set_amount(const StringName& p_node,float p_amount);
- float mix_node_get_amount(const StringName& p_node) const;
+ void mix_node_set_amount(const StringName &p_node, float p_amount);
+ float mix_node_get_amount(const StringName &p_node) const;
- void blend2_node_set_amount(const StringName& p_node,float p_amount);
- float blend2_node_get_amount(const StringName& p_node) const;
- void blend2_node_set_filter_path(const StringName& p_node,const NodePath& p_filter,bool p_enable);
- void blend2_node_set_get_filtered_paths(const StringName& p_node,List<NodePath> *r_paths) const;
- bool blend2_node_is_path_filtered(const StringName& p_node,const NodePath& p_path) const;
+ void blend2_node_set_amount(const StringName &p_node, float p_amount);
+ float blend2_node_get_amount(const StringName &p_node) const;
+ void blend2_node_set_filter_path(const StringName &p_node, const NodePath &p_filter, bool p_enable);
+ void blend2_node_set_get_filtered_paths(const StringName &p_node, List<NodePath> *r_paths) const;
+ bool blend2_node_is_path_filtered(const StringName &p_node, const NodePath &p_path) const;
- void blend3_node_set_amount(const StringName& p_node,float p_amount);
- float blend3_node_get_amount(const StringName& p_node) const;
+ void blend3_node_set_amount(const StringName &p_node, float p_amount);
+ float blend3_node_get_amount(const StringName &p_node) const;
- void blend4_node_set_amount(const StringName& p_node,const Point2& p_amount);
- Point2 blend4_node_get_amount(const StringName& p_node) const;
+ void blend4_node_set_amount(const StringName &p_node, const Point2 &p_amount);
+ Point2 blend4_node_get_amount(const StringName &p_node) const;
/* TIMESCALE/TIMESEEK NODES */
- void timescale_node_set_scale(const StringName& p_node,float p_scale);
- float timescale_node_get_scale(const StringName& p_node) const;
+ void timescale_node_set_scale(const StringName &p_node, float p_scale);
+ float timescale_node_get_scale(const StringName &p_node) const;
- void timeseek_node_seek(const StringName& p_node,float p_pos);
+ void timeseek_node_seek(const StringName &p_node, float p_pos);
/* TRANSITION NODE */
- void transition_node_set_input_count(const StringName& p_node, int p_inputs); // used for transition node
- int transition_node_get_input_count(const StringName& p_node) const;
- void transition_node_delete_input(const StringName& p_node, int p_input); // used for transition node
-
- void transition_node_set_input_auto_advance(const StringName& p_node, int p_input,bool p_auto_advance); // used for transition node
- bool transition_node_has_input_auto_advance(const StringName& p_node, int p_input) const;
+ void transition_node_set_input_count(const StringName &p_node, int p_inputs); // used for transition node
+ int transition_node_get_input_count(const StringName &p_node) const;
+ void transition_node_delete_input(const StringName &p_node, int p_input); // used for transition node
- void transition_node_set_xfade_time(const StringName& p_node, float p_time); // used for transition node
- float transition_node_get_xfade_time(const StringName& p_node) const;
+ void transition_node_set_input_auto_advance(const StringName &p_node, int p_input, bool p_auto_advance); // used for transition node
+ bool transition_node_has_input_auto_advance(const StringName &p_node, int p_input) const;
- void transition_node_set_current(const StringName& p_node, int p_current);
- int transition_node_get_current(const StringName& p_node) const;
+ void transition_node_set_xfade_time(const StringName &p_node, float p_time); // used for transition node
+ float transition_node_get_xfade_time(const StringName &p_node) const;
+ void transition_node_set_current(const StringName &p_node, int p_current);
+ int transition_node_get_current(const StringName &p_node) const;
- void node_set_pos(const StringName& p_node, const Vector2& p_pos); //for display
+ void node_set_pos(const StringName &p_node, const Vector2 &p_pos); //for display
/* GETS */
- Point2 node_get_pos(const StringName& p_node) const; //for display
+ Point2 node_get_pos(const StringName &p_node) const; //for display
- NodeType node_get_type(const StringName& p_node) const;
+ NodeType node_get_type(const StringName &p_node) const;
void get_node_list(List<StringName> *p_node_list) const;
- void remove_node(const StringName& p_node);
+ void remove_node(const StringName &p_node);
- Error connect_nodes(const StringName& p_src_node,const StringName& p_dst_node, int p_dst_input);
- bool are_nodes_connected(const StringName& p_src_node,const StringName& p_dst_node, int p_input) const;
- void disconnect_nodes(const StringName& p_src_node, int p_input);
+ Error connect_nodes(const StringName &p_src_node, const StringName &p_dst_node, int p_dst_input);
+ bool are_nodes_connected(const StringName &p_src_node, const StringName &p_dst_node, int p_input) const;
+ void disconnect_nodes(const StringName &p_src_node, int p_input);
- void set_base_path(const NodePath& p_path);
+ void set_base_path(const NodePath &p_path);
NodePath get_base_path() const;
- void set_master_player(const NodePath& p_path);
+ void set_master_player(const NodePath &p_path);
NodePath get_master_player() const;
struct Connection {
@@ -414,7 +443,7 @@ public:
int dst_input;
};
- void get_connection_list( List<Connection> *p_connections) const;
+ void get_connection_list(List<Connection> *p_connections) const;
/* playback */
@@ -436,12 +465,9 @@ public:
AnimationTreePlayer();
~AnimationTreePlayer();
-
};
-VARIANT_ENUM_CAST( AnimationTreePlayer::NodeType );
-VARIANT_ENUM_CAST( AnimationTreePlayer::AnimationProcessMode );
+VARIANT_ENUM_CAST(AnimationTreePlayer::NodeType);
+VARIANT_ENUM_CAST(AnimationTreePlayer::AnimationProcessMode);
#endif // ANIMATION_TREE_PLAYER_H
-
-
diff --git a/scene/animation/tween.cpp b/scene/animation/tween.cpp
index c422e765b5..c455d20b14 100644
--- a/scene/animation/tween.cpp
+++ b/scene/animation/tween.cpp
@@ -29,63 +29,60 @@
#include "tween.h"
#include "method_bind_ext.inc"
-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
-) {
+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) {
pending_commands.push_back(PendingCommand());
- PendingCommand& cmd = pending_commands.back()->get();
+ PendingCommand &cmd = pending_commands.back()->get();
cmd.key = p_key;
- int& count = cmd.args;
- if(p_arg10.get_type() != Variant::NIL)
+ int &count = cmd.args;
+ if (p_arg10.get_type() != Variant::NIL)
count = 10;
- else if(p_arg9.get_type() != Variant::NIL)
+ else if (p_arg9.get_type() != Variant::NIL)
count = 9;
- else if(p_arg8.get_type() != Variant::NIL)
+ else if (p_arg8.get_type() != Variant::NIL)
count = 8;
- else if(p_arg7.get_type() != Variant::NIL)
+ else if (p_arg7.get_type() != Variant::NIL)
count = 7;
- else if(p_arg6.get_type() != Variant::NIL)
+ else if (p_arg6.get_type() != Variant::NIL)
count = 6;
- else if(p_arg5.get_type() != Variant::NIL)
+ else if (p_arg5.get_type() != Variant::NIL)
count = 5;
- else if(p_arg4.get_type() != Variant::NIL)
+ else if (p_arg4.get_type() != Variant::NIL)
count = 4;
- else if(p_arg3.get_type() != Variant::NIL)
+ else if (p_arg3.get_type() != Variant::NIL)
count = 3;
- else if(p_arg2.get_type() != Variant::NIL)
+ else if (p_arg2.get_type() != Variant::NIL)
count = 2;
- else if(p_arg1.get_type() != Variant::NIL)
+ else if (p_arg1.get_type() != Variant::NIL)
count = 1;
- if(count > 0)
+ if (count > 0)
cmd.arg[0] = p_arg1;
- if(count > 1)
+ if (count > 1)
cmd.arg[1] = p_arg2;
- if(count > 2)
+ if (count > 2)
cmd.arg[2] = p_arg3;
- if(count > 3)
+ if (count > 3)
cmd.arg[3] = p_arg4;
- if(count > 4)
+ if (count > 4)
cmd.arg[4] = p_arg5;
- if(count > 5)
+ if (count > 5)
cmd.arg[5] = p_arg6;
- if(count > 6)
+ if (count > 6)
cmd.arg[6] = p_arg7;
- if(count > 7)
+ if (count > 7)
cmd.arg[7] = p_arg8;
- if(count > 8)
+ if (count > 8)
cmd.arg[8] = p_arg9;
- if(count > 9)
+ if (count > 9)
cmd.arg[9] = p_arg10;
}
void Tween::_process_pending_commands() {
- for(List<PendingCommand>::Element *E=pending_commands.front();E;E=E->next()) {
+ for (List<PendingCommand>::Element *E = pending_commands.front(); E; E = E->next()) {
- PendingCommand& cmd = E->get();
+ PendingCommand &cmd = E->get();
Variant::CallError err;
Variant *arg[10] = {
&cmd.arg[0],
@@ -99,41 +96,40 @@ void Tween::_process_pending_commands() {
&cmd.arg[8],
&cmd.arg[9],
};
- this->call(cmd.key, (const Variant **) arg, cmd.args, err);
+ this->call(cmd.key, (const Variant **)arg, cmd.args, err);
}
pending_commands.clear();
}
-bool Tween::_set(const StringName& p_name, const Variant& p_value) {
+bool Tween::_set(const StringName &p_name, const Variant &p_value) {
- String name=p_name;
+ String name = p_name;
- if (name=="playback/speed" || name=="speed") { //bw compatibility
+ if (name == "playback/speed" || name == "speed") { //bw compatibility
set_speed_scale(p_value);
- } else if (name=="playback/active") {
+ } else if (name == "playback/active") {
set_active(p_value);
- } else if (name=="playback/repeat") {
+ } else if (name == "playback/repeat") {
set_repeat(p_value);
-
}
return true;
}
-bool Tween::_get(const StringName& p_name,Variant &r_ret) const {
+bool Tween::_get(const StringName &p_name, Variant &r_ret) const {
- String name=p_name;
+ String name = p_name;
- if (name=="playback/speed") { //bw compatibility
+ if (name == "playback/speed") { //bw compatibility
- r_ret=speed_scale;
- } else if (name=="playback/active") {
+ r_ret = speed_scale;
+ } else if (name == "playback/active") {
- r_ret=is_active();
- } else if(name=="playback/repeat") {
+ r_ret = is_active();
+ } else if (name == "playback/repeat") {
- r_ret=is_repeat();
+ r_ret = is_repeat();
}
return true;
@@ -141,14 +137,14 @@ bool Tween::_get(const StringName& p_name,Variant &r_ret) const {
void Tween::_get_property_list(List<PropertyInfo> *p_list) const {
- 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::REAL, "playback/speed", PROPERTY_HINT_RANGE, "-64,64,0.01") );
+ 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::REAL, "playback/speed", PROPERTY_HINT_RANGE, "-64,64,0.01"));
}
void Tween::_notification(int p_what) {
- switch(p_what) {
+ switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
@@ -163,19 +159,19 @@ void Tween::_notification(int p_what) {
} break;
case NOTIFICATION_INTERNAL_PROCESS: {
- if (tween_process_mode==TWEEN_PROCESS_FIXED)
+ if (tween_process_mode == TWEEN_PROCESS_FIXED)
break;
if (processing)
- _tween_process( get_process_delta_time() );
+ _tween_process(get_process_delta_time());
} break;
case NOTIFICATION_INTERNAL_FIXED_PROCESS: {
- if (tween_process_mode==TWEEN_PROCESS_IDLE)
+ if (tween_process_mode == TWEEN_PROCESS_IDLE)
break;
if (processing)
- _tween_process( get_fixed_process_delta_time() );
+ _tween_process(get_fixed_process_delta_time());
} break;
case NOTIFICATION_EXIT_TREE: {
@@ -186,46 +182,46 @@ void Tween::_notification(int p_what) {
void Tween::_bind_methods() {
- ClassDB::bind_method(D_METHOD("is_active"),&Tween::is_active );
- ClassDB::bind_method(D_METHOD("set_active","active"),&Tween::set_active );
-
- ClassDB::bind_method(D_METHOD("is_repeat"),&Tween::is_repeat );
- ClassDB::bind_method(D_METHOD("set_repeat","repeat"),&Tween::set_repeat );
-
- 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);
-
- 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","object","key","first_only"),&Tween::_remove );
- 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 );
-
- ClassDB::bind_method(D_METHOD("interpolate_property","object","property","initial_val","final_val","duration","trans_type","ease_type","delay"),&Tween::interpolate_property, 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(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(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(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(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(0) );
-
- ADD_SIGNAL( MethodInfo("tween_started", PropertyInfo( Variant::OBJECT,"object"), PropertyInfo( Variant::STRING,"key")) );
- ADD_SIGNAL( MethodInfo("tween_step", PropertyInfo( Variant::OBJECT,"object"), PropertyInfo( Variant::STRING,"key"), PropertyInfo( Variant::REAL,"elapsed"), PropertyInfo( Variant::OBJECT,"value")) );
- ADD_SIGNAL( MethodInfo("tween_completed", PropertyInfo( Variant::OBJECT,"object"), PropertyInfo( Variant::STRING,"key")) );
-
- ADD_PROPERTY( PropertyInfo( Variant::INT, "playback_process_mode", PROPERTY_HINT_ENUM, "Fixed,Idle"), "set_tween_process_mode", "get_tween_process_mode");
+ ClassDB::bind_method(D_METHOD("is_active"), &Tween::is_active);
+ ClassDB::bind_method(D_METHOD("set_active", "active"), &Tween::set_active);
+
+ ClassDB::bind_method(D_METHOD("is_repeat"), &Tween::is_repeat);
+ ClassDB::bind_method(D_METHOD("set_repeat", "repeat"), &Tween::set_repeat);
+
+ 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);
+
+ 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", "object", "key", "first_only"), &Tween::_remove);
+ 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);
+
+ ClassDB::bind_method(D_METHOD("interpolate_property", "object", "property", "initial_val", "final_val", "duration", "trans_type", "ease_type", "delay"), &Tween::interpolate_property, 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(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(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(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(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(0));
+
+ ADD_SIGNAL(MethodInfo("tween_started", PropertyInfo(Variant::OBJECT, "object"), PropertyInfo(Variant::STRING, "key")));
+ ADD_SIGNAL(MethodInfo("tween_step", PropertyInfo(Variant::OBJECT, "object"), PropertyInfo(Variant::STRING, "key"), PropertyInfo(Variant::REAL, "elapsed"), PropertyInfo(Variant::OBJECT, "value")));
+ ADD_SIGNAL(MethodInfo("tween_completed", PropertyInfo(Variant::OBJECT, "object"), PropertyInfo(Variant::STRING, "key")));
+
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "playback_process_mode", PROPERTY_HINT_ENUM, "Fixed,Idle"), "set_tween_process_mode", "get_tween_process_mode");
BIND_CONSTANT(TWEEN_PROCESS_FIXED);
BIND_CONSTANT(TWEEN_PROCESS_IDLE);
@@ -248,9 +244,9 @@ void Tween::_bind_methods() {
BIND_CONSTANT(EASE_OUT_IN);
}
-Variant& Tween::_get_initial_val(InterpolateData& p_data) {
+Variant &Tween::_get_initial_val(InterpolateData &p_data) {
- switch(p_data.type) {
+ switch (p_data.type) {
case INTER_PROPERTY:
case INTER_METHOD:
case FOLLOW_PROPERTY:
@@ -260,31 +256,30 @@ Variant& Tween::_get_initial_val(InterpolateData& p_data) {
case TARGETING_PROPERTY:
case TARGETING_METHOD: {
- Object *object = ObjectDB::get_instance(p_data.target_id);
- ERR_FAIL_COND_V(object == NULL,p_data.initial_val);
+ Object *object = ObjectDB::get_instance(p_data.target_id);
+ ERR_FAIL_COND_V(object == NULL, p_data.initial_val);
- static Variant initial_val;
- if(p_data.type == TARGETING_PROPERTY) {
+ static Variant initial_val;
+ if (p_data.type == TARGETING_PROPERTY) {
- bool valid = false;
- initial_val = object->get(p_data.target_key, &valid);
- ERR_FAIL_COND_V(!valid,p_data.initial_val);
- } else {
+ bool valid = false;
+ initial_val = object->get(p_data.target_key, &valid);
+ ERR_FAIL_COND_V(!valid, p_data.initial_val);
+ } else {
- Variant::CallError error;
- initial_val = object->call(p_data.target_key, NULL, 0, error);
- ERR_FAIL_COND_V(error.error != Variant::CallError::CALL_OK,p_data.initial_val);
- }
- return initial_val;
+ Variant::CallError error;
+ initial_val = object->call(p_data.target_key, NULL, 0, error);
+ ERR_FAIL_COND_V(error.error != Variant::CallError::CALL_OK, p_data.initial_val);
}
- break;
+ return initial_val;
+ } break;
}
return p_data.delta_val;
}
-Variant& Tween::_get_delta_val(InterpolateData& p_data) {
+Variant &Tween::_get_delta_val(InterpolateData &p_data) {
- switch(p_data.type) {
+ switch (p_data.type) {
case INTER_PROPERTY:
case INTER_METHOD:
return p_data.delta_val;
@@ -292,72 +287,68 @@ Variant& Tween::_get_delta_val(InterpolateData& p_data) {
case FOLLOW_PROPERTY:
case FOLLOW_METHOD: {
- Object *target = ObjectDB::get_instance(p_data.target_id);
- ERR_FAIL_COND_V(target == NULL,p_data.initial_val);
-
- Variant final_val;
+ Object *target = ObjectDB::get_instance(p_data.target_id);
+ ERR_FAIL_COND_V(target == NULL, p_data.initial_val);
- if(p_data.type == FOLLOW_PROPERTY) {
+ Variant final_val;
- bool valid = false;
- final_val = target->get(p_data.target_key, &valid);
- ERR_FAIL_COND_V(!valid,p_data.initial_val);
- } else {
+ if (p_data.type == FOLLOW_PROPERTY) {
- Variant::CallError error;
- final_val = target->call(p_data.target_key, NULL, 0, error);
- ERR_FAIL_COND_V(error.error != Variant::CallError::CALL_OK,p_data.initial_val);
- }
+ bool valid = false;
+ final_val = target->get(p_data.target_key, &valid);
+ ERR_FAIL_COND_V(!valid, p_data.initial_val);
+ } else {
- // convert INT to REAL is better for interpolaters
- if(final_val.get_type() == Variant::INT) final_val = final_val.operator real_t();
- _calc_delta_val(p_data.initial_val, final_val, p_data.delta_val);
- return p_data.delta_val;
+ Variant::CallError error;
+ final_val = target->call(p_data.target_key, NULL, 0, error);
+ ERR_FAIL_COND_V(error.error != Variant::CallError::CALL_OK, p_data.initial_val);
}
- break;
+
+ // convert INT to REAL is better for interpolaters
+ if (final_val.get_type() == Variant::INT) final_val = final_val.operator real_t();
+ _calc_delta_val(p_data.initial_val, final_val, p_data.delta_val);
+ return p_data.delta_val;
+ } break;
case TARGETING_PROPERTY:
case TARGETING_METHOD: {
- Variant initial_val = _get_initial_val(p_data);
- // convert INT to REAL is better for interpolaters
- if(initial_val.get_type() == Variant::INT) initial_val = initial_val.operator real_t();
+ Variant initial_val = _get_initial_val(p_data);
+ // convert INT to REAL is better for interpolaters
+ if (initial_val.get_type() == Variant::INT) initial_val = initial_val.operator real_t();
- //_calc_delta_val(p_data.initial_val, p_data.final_val, p_data.delta_val);
- _calc_delta_val(initial_val, p_data.final_val, p_data.delta_val);
- return p_data.delta_val;
- }
- break;
+ //_calc_delta_val(p_data.initial_val, p_data.final_val, p_data.delta_val);
+ _calc_delta_val(initial_val, p_data.final_val, p_data.delta_val);
+ return p_data.delta_val;
+ } break;
}
return p_data.initial_val;
}
-Variant Tween::_run_equation(InterpolateData& p_data) {
+Variant Tween::_run_equation(InterpolateData &p_data) {
- Variant& initial_val = _get_initial_val(p_data);
- Variant& delta_val = _get_delta_val(p_data);
+ Variant &initial_val = _get_initial_val(p_data);
+ Variant &delta_val = _get_delta_val(p_data);
Variant result;
-#define APPLY_EQUATION(element)\
+#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);
- switch(initial_val.get_type())
- {
+ switch (initial_val.get_type()) {
- case Variant::BOOL:
- 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;
+ case Variant::BOOL:
+ 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;
- case Variant::INT:
- 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:
+ 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::REAL:
- 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::REAL:
+ 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::VECTOR2:
- {
+ case Variant::VECTOR2: {
Vector2 i = initial_val;
Vector2 d = delta_val;
Vector2 r;
@@ -366,11 +357,9 @@ Variant Tween::_run_equation(InterpolateData& p_data) {
APPLY_EQUATION(y);
result = r;
- }
- break;
+ } break;
- case Variant::VECTOR3:
- {
+ case Variant::VECTOR3: {
Vector3 i = initial_val;
Vector3 d = delta_val;
Vector3 r;
@@ -380,11 +369,9 @@ Variant Tween::_run_equation(InterpolateData& p_data) {
APPLY_EQUATION(z);
result = r;
- }
- break;
+ } break;
- case Variant::BASIS:
- {
+ case Variant::BASIS: {
Basis i = initial_val;
Basis d = delta_val;
Basis r;
@@ -400,11 +387,9 @@ Variant Tween::_run_equation(InterpolateData& p_data) {
APPLY_EQUATION(elements[2][2]);
result = r;
- }
- break;
+ } break;
- case Variant::TRANSFORM2D:
- {
+ case Variant::TRANSFORM2D: {
Transform2D i = initial_val;
Transform2D d = delta_val;
Transform2D r;
@@ -417,10 +402,8 @@ Variant Tween::_run_equation(InterpolateData& p_data) {
APPLY_EQUATION(elements[2][1]);
result = r;
- }
- break;
- case Variant::QUAT:
- {
+ } break;
+ case Variant::QUAT: {
Quat i = initial_val;
Quat d = delta_val;
Quat r;
@@ -431,10 +414,8 @@ Variant Tween::_run_equation(InterpolateData& p_data) {
APPLY_EQUATION(w);
result = r;
- }
- break;
- case Variant::RECT3:
- {
+ } break;
+ case Variant::RECT3: {
Rect3 i = initial_val;
Rect3 d = delta_val;
Rect3 r;
@@ -447,10 +428,8 @@ Variant Tween::_run_equation(InterpolateData& p_data) {
APPLY_EQUATION(size.z);
result = r;
- }
- break;
- case Variant::TRANSFORM:
- {
+ } break;
+ case Variant::TRANSFORM: {
Transform i = initial_val;
Transform d = delta_val;
Transform r;
@@ -469,10 +448,8 @@ Variant Tween::_run_equation(InterpolateData& p_data) {
APPLY_EQUATION(origin.z);
result = r;
- }
- break;
- case Variant::COLOR:
- {
+ } break;
+ case Variant::COLOR: {
Color i = initial_val;
Color d = delta_val;
Color r;
@@ -483,47 +460,44 @@ Variant Tween::_run_equation(InterpolateData& p_data) {
APPLY_EQUATION(a);
result = r;
- }
- break;
+ } break;
};
#undef APPLY_EQUATION
return result;
}
-bool Tween::_apply_tween_value(InterpolateData& p_data, Variant& value) {
+bool Tween::_apply_tween_value(InterpolateData &p_data, Variant &value) {
Object *object = ObjectDB::get_instance(p_data.id);
ERR_FAIL_COND_V(object == NULL, false);
- switch(p_data.type) {
+ switch (p_data.type) {
case INTER_PROPERTY:
case FOLLOW_PROPERTY:
- case TARGETING_PROPERTY:
- {
- bool valid = false;
- object->set(p_data.key,value, &valid);
- return valid;
- }
+ case TARGETING_PROPERTY: {
+ bool valid = false;
+ object->set(p_data.key, value, &valid);
+ return valid;
+ }
case INTER_METHOD:
case FOLLOW_METHOD:
- case TARGETING_METHOD:
- {
- Variant::CallError error;
- if (value.get_type() != Variant::NIL) {
- Variant *arg[1] = { &value };
- object->call(p_data.key, (const Variant **) arg, 1, error);
- } else {
- object->call(p_data.key, NULL, 0, error);
- }
-
- if(error.error == Variant::CallError::CALL_OK)
- return true;
- return false;
+ case TARGETING_METHOD: {
+ Variant::CallError error;
+ if (value.get_type() != Variant::NIL) {
+ Variant *arg[1] = { &value };
+ object->call(p_data.key, (const Variant **)arg, 1, error);
+ } else {
+ object->call(p_data.key, NULL, 0, error);
}
+ if (error.error == Variant::CallError::CALL_OK)
+ return true;
+ return false;
+ }
+
case INTER_CALLBACK:
break;
};
@@ -538,118 +512,122 @@ void Tween::_tween_process(float p_delta) {
return;
p_delta *= speed_scale;
- pending_update ++;
+ pending_update++;
// if repeat and all interpolates was finished then reset all interpolates
- if(repeat) {
+ if (repeat) {
bool all_finished = true;
- for(List<InterpolateData>::Element *E=interpolates.front();E;E=E->next()) {
+ for (List<InterpolateData>::Element *E = interpolates.front(); E; E = E->next()) {
- InterpolateData& data = E->get();
+ InterpolateData &data = E->get();
- if(!data.finish) {
+ if (!data.finish) {
all_finished = false;
break;
}
}
- if(all_finished)
+ if (all_finished)
reset_all();
}
- for(List<InterpolateData>::Element *E=interpolates.front();E;E=E->next()) {
+ for (List<InterpolateData>::Element *E = interpolates.front(); E; E = E->next()) {
- InterpolateData& data = E->get();
- if(!data.active || data.finish)
+ InterpolateData &data = E->get();
+ if (!data.active || data.finish)
continue;
Object *object = ObjectDB::get_instance(data.id);
- if(object == NULL)
+ if (object == NULL)
continue;
bool prev_delaying = data.elapsed <= data.delay;
data.elapsed += p_delta;
- if(data.elapsed < data.delay)
+ if (data.elapsed < data.delay)
continue;
- else if(prev_delaying) {
+ else if (prev_delaying) {
- emit_signal("tween_started",object,data.key);
+ emit_signal("tween_started", object, data.key);
_apply_tween_value(data, data.initial_val);
}
- if(data.elapsed > (data.delay + data.duration)) {
+ if (data.elapsed > (data.delay + data.duration)) {
data.elapsed = data.delay + data.duration;
data.finish = true;
}
- switch(data.type)
- {
- case INTER_PROPERTY:
- case INTER_METHOD:
- break;
- case INTER_CALLBACK:
- if(data.finish) {
+ switch (data.type) {
+ case INTER_PROPERTY:
+ case INTER_METHOD:
+ break;
+ case INTER_CALLBACK:
+ if (data.finish) {
- Variant::CallError error;
- if (data.call_deferred) {
-
- switch (data.args) {
- case 0:
- object->call_deferred(data.key); break;
- case 1:
- object->call_deferred(data.key, data.arg[0]); break;
- case 2:
- object->call_deferred(data.key, data.arg[0], data.arg[1]); break;
- case 3:
- object->call_deferred(data.key, data.arg[0], data.arg[1], data.arg[2]); break;
- case 4:
- object->call_deferred(data.key, data.arg[0], data.arg[1], data.arg[2], data.arg[3]); break;
- case 5:
- object->call_deferred(data.key, data.arg[0], data.arg[1], data.arg[2], data.arg[3], data.arg[4]); break;
+ Variant::CallError error;
+ if (data.call_deferred) {
+
+ switch (data.args) {
+ case 0:
+ object->call_deferred(data.key);
+ break;
+ case 1:
+ object->call_deferred(data.key, data.arg[0]);
+ break;
+ case 2:
+ object->call_deferred(data.key, data.arg[0], data.arg[1]);
+ break;
+ case 3:
+ object->call_deferred(data.key, data.arg[0], data.arg[1], data.arg[2]);
+ break;
+ case 4:
+ object->call_deferred(data.key, data.arg[0], data.arg[1], data.arg[2], data.arg[3]);
+ break;
+ case 5:
+ object->call_deferred(data.key, data.arg[0], data.arg[1], data.arg[2], data.arg[3], data.arg[4]);
+ break;
+ }
+
+ } else {
+ Variant *arg[5] = {
+ &data.arg[0],
+ &data.arg[1],
+ &data.arg[2],
+ &data.arg[3],
+ &data.arg[4],
+ };
+ object->call(data.key, (const Variant **)arg, data.args, error);
}
-
- }
- else {
- Variant *arg[5] = {
- &data.arg[0],
- &data.arg[1],
- &data.arg[2],
- &data.arg[3],
- &data.arg[4],
- };
- object->call(data.key, (const Variant **) arg, data.args, error);
+ if (!repeat)
+ call_deferred("_remove", object, data.key, true);
}
- if (!repeat)
- call_deferred("_remove", object, data.key, true);
- }
- continue;
+ continue;
}
Variant result = _run_equation(data);
- emit_signal("tween_step",object,data.key,data.elapsed,result);
+ emit_signal("tween_step", object, data.key, data.elapsed, result);
_apply_tween_value(data, result);
if (data.finish) {
- emit_signal("tween_completed",object,data.key);
+ emit_signal("tween_completed", object, data.key);
// not repeat mode, remove completed action
if (!repeat)
call_deferred("_remove", object, data.key, true);
}
}
- pending_update --;
+ pending_update--;
}
void Tween::set_tween_process_mode(TweenProcessMode p_mode) {
- if (tween_process_mode==p_mode)
+ if (tween_process_mode == p_mode)
return;
bool pr = processing;
if (pr)
_set_process(false);
- tween_process_mode=p_mode;
+ tween_process_mode = p_mode;
if (pr)
_set_process(true);
}
@@ -659,18 +637,18 @@ Tween::TweenProcessMode Tween::get_tween_process_mode() const {
return tween_process_mode;
}
-void Tween::_set_process(bool p_process,bool p_force) {
+void Tween::_set_process(bool p_process, bool p_force) {
- if (processing==p_process && !p_force)
+ if (processing == p_process && !p_force)
return;
- switch(tween_process_mode) {
+ switch (tween_process_mode) {
case TWEEN_PROCESS_FIXED: set_fixed_process_internal(p_process && active); break;
case TWEEN_PROCESS_IDLE: set_process_internal(p_process && active); break;
}
- processing=p_process;
+ processing = p_process;
}
bool Tween::is_active() const {
@@ -680,11 +658,11 @@ bool Tween::is_active() const {
void Tween::set_active(bool p_active) {
- if (active==p_active)
+ if (active == p_active)
return;
- active=p_active;
- _set_process(processing,true);
+ active = p_active;
+ _set_process(processing, true);
}
bool Tween::is_repeat() const {
@@ -699,7 +677,7 @@ void Tween::set_repeat(bool p_repeat) {
void Tween::set_speed_scale(float p_speed) {
- speed_scale=p_speed;
+ speed_scale = p_speed;
}
float Tween::get_speed_scale() const {
@@ -716,54 +694,54 @@ bool Tween::start() {
bool Tween::reset(Object *p_object, String p_key) {
- pending_update ++;
- for(List<InterpolateData>::Element *E=interpolates.front();E;E=E->next()) {
+ pending_update++;
+ for (List<InterpolateData>::Element *E = interpolates.front(); E; E = E->next()) {
- InterpolateData& data = E->get();
+ InterpolateData &data = E->get();
Object *object = ObjectDB::get_instance(data.id);
- if(object == NULL)
+ if (object == NULL)
continue;
- if(object == p_object && (data.key == p_key || p_key == "")) {
+ if (object == p_object && (data.key == p_key || p_key == "")) {
data.elapsed = 0;
data.finish = false;
- if(data.delay == 0)
+ if (data.delay == 0)
_apply_tween_value(data, data.initial_val);
}
}
- pending_update --;
+ pending_update--;
return true;
}
bool Tween::reset_all() {
- pending_update ++;
- for(List<InterpolateData>::Element *E=interpolates.front();E;E=E->next()) {
+ pending_update++;
+ for (List<InterpolateData>::Element *E = interpolates.front(); E; E = E->next()) {
- InterpolateData& data = E->get();
+ InterpolateData &data = E->get();
data.elapsed = 0;
data.finish = false;
- if(data.delay == 0)
+ if (data.delay == 0)
_apply_tween_value(data, data.initial_val);
}
- pending_update --;
+ pending_update--;
return true;
}
bool Tween::stop(Object *p_object, String p_key) {
- pending_update ++;
- for(List<InterpolateData>::Element *E=interpolates.front();E;E=E->next()) {
+ pending_update++;
+ for (List<InterpolateData>::Element *E = interpolates.front(); E; E = E->next()) {
- InterpolateData& data = E->get();
+ InterpolateData &data = E->get();
Object *object = ObjectDB::get_instance(data.id);
- if(object == NULL)
+ if (object == NULL)
continue;
- if(object == p_object && (data.key == p_key || p_key == ""))
+ if (object == p_object && (data.key == p_key || p_key == ""))
data.active = false;
}
- pending_update --;
+ pending_update--;
return true;
}
@@ -772,13 +750,13 @@ bool Tween::stop_all() {
set_active(false);
_set_process(false);
- pending_update ++;
- for(List<InterpolateData>::Element *E=interpolates.front();E;E=E->next()) {
+ pending_update++;
+ for (List<InterpolateData>::Element *E = interpolates.front(); E; E = E->next()) {
- InterpolateData& data = E->get();
+ InterpolateData &data = E->get();
data.active = false;
}
- pending_update --;
+ pending_update--;
return true;
}
@@ -787,17 +765,17 @@ bool Tween::resume(Object *p_object, String p_key) {
set_active(true);
_set_process(true);
- pending_update ++;
- for(List<InterpolateData>::Element *E=interpolates.front();E;E=E->next()) {
+ pending_update++;
+ for (List<InterpolateData>::Element *E = interpolates.front(); E; E = E->next()) {
- InterpolateData& data = E->get();
+ InterpolateData &data = E->get();
Object *object = ObjectDB::get_instance(data.id);
- if(object == NULL)
+ if (object == NULL)
continue;
- if(object == p_object && (data.key == p_key || p_key == ""))
+ if (object == p_object && (data.key == p_key || p_key == ""))
data.active = true;
}
- pending_update --;
+ pending_update--;
return true;
}
@@ -806,13 +784,13 @@ bool Tween::resume_all() {
set_active(true);
_set_process(true);
- pending_update ++;
- for(List<InterpolateData>::Element *E=interpolates.front();E;E=E->next()) {
+ pending_update++;
+ for (List<InterpolateData>::Element *E = interpolates.front(); E; E = E->next()) {
- InterpolateData& data = E->get();
+ InterpolateData &data = E->get();
data.active = true;
}
- pending_update --;
+ pending_update--;
return true;
}
@@ -823,32 +801,32 @@ bool Tween::remove(Object *p_object, String p_key) {
void Tween::_remove(Object *p_object, String p_key, bool first_only) {
- if(pending_update != 0) {
+ if (pending_update != 0) {
call_deferred("_remove", p_object, p_key, first_only);
return;
}
List<List<InterpolateData>::Element *> for_removal;
- for(List<InterpolateData>::Element *E=interpolates.front();E;E=E->next()) {
+ for (List<InterpolateData>::Element *E = interpolates.front(); E; E = E->next()) {
- InterpolateData& data = E->get();
+ InterpolateData &data = E->get();
Object *object = ObjectDB::get_instance(data.id);
- if(object == NULL)
+ if (object == NULL)
continue;
- if(object == p_object && (data.key == p_key || p_key == "")) {
+ if (object == p_object && (data.key == p_key || p_key == "")) {
for_removal.push_back(E);
if (first_only) {
break;
}
}
}
- for(List<List<InterpolateData>::Element *>::Element *E=for_removal.front();E;E=E->next()) {
+ for (List<List<InterpolateData>::Element *>::Element *E = for_removal.front(); E; E = E->next()) {
interpolates.erase(E->get());
}
}
bool Tween::remove_all() {
- if(pending_update != 0) {
+ if (pending_update != 0) {
call_deferred("remove_all");
return true;
}
@@ -860,89 +838,87 @@ bool Tween::remove_all() {
bool Tween::seek(real_t p_time) {
- pending_update ++;
- for(List<InterpolateData>::Element *E=interpolates.front();E;E=E->next()) {
+ pending_update++;
+ for (List<InterpolateData>::Element *E = interpolates.front(); E; E = E->next()) {
- InterpolateData& data = E->get();
+ InterpolateData &data = E->get();
data.elapsed = p_time;
- if(data.elapsed < data.delay) {
+ if (data.elapsed < data.delay) {
data.finish = false;
continue;
- }
- else if(data.elapsed >= (data.delay + data.duration)) {
+ } else if (data.elapsed >= (data.delay + data.duration)) {
data.finish = true;
data.elapsed = (data.delay + data.duration);
} else
data.finish = false;
- switch(data.type)
- {
- case INTER_PROPERTY:
- case INTER_METHOD:
- break;
- case INTER_CALLBACK:
- continue;
+ switch (data.type) {
+ case INTER_PROPERTY:
+ case INTER_METHOD:
+ break;
+ case INTER_CALLBACK:
+ continue;
}
Variant result = _run_equation(data);
_apply_tween_value(data, result);
}
- pending_update --;
+ pending_update--;
return true;
}
real_t Tween::tell() const {
- pending_update ++;
+ pending_update++;
real_t pos = 0;
- for(const List<InterpolateData>::Element *E=interpolates.front();E;E=E->next()) {
+ for (const List<InterpolateData>::Element *E = interpolates.front(); E; E = E->next()) {
- const InterpolateData& data = E->get();
- if(data.elapsed > pos)
+ const InterpolateData &data = E->get();
+ if (data.elapsed > pos)
pos = data.elapsed;
}
- pending_update --;
+ pending_update--;
return pos;
}
real_t Tween::get_runtime() const {
- pending_update ++;
+ pending_update++;
real_t runtime = 0;
- for(const List<InterpolateData>::Element *E=interpolates.front();E;E=E->next()) {
+ for (const List<InterpolateData>::Element *E = interpolates.front(); E; E = E->next()) {
- const InterpolateData& data = E->get();
+ const InterpolateData &data = E->get();
real_t t = data.delay + data.duration;
- if(t > runtime)
+ if (t > runtime)
runtime = t;
}
- pending_update --;
+ pending_update--;
return runtime;
}
-bool Tween::_calc_delta_val(const Variant& p_initial_val, const Variant& p_final_val, Variant& p_delta_val) {
+bool Tween::_calc_delta_val(const Variant &p_initial_val, const Variant &p_final_val, Variant &p_delta_val) {
- const Variant& initial_val = p_initial_val;
- const Variant& final_val = p_final_val;
- Variant& delta_val = p_delta_val;
+ const Variant &initial_val = p_initial_val;
+ const Variant &final_val = p_final_val;
+ Variant &delta_val = p_delta_val;
- switch(initial_val.get_type()) {
+ switch (initial_val.get_type()) {
case Variant::BOOL:
//delta_val = p_final_val;
- delta_val = (int) p_final_val - (int) p_initial_val;
+ delta_val = (int)p_final_val - (int)p_initial_val;
break;
case Variant::INT:
- delta_val = (int) final_val - (int) initial_val;
+ delta_val = (int)final_val - (int)initial_val;
break;
case Variant::REAL:
- delta_val = (real_t) final_val - (real_t) initial_val;
+ delta_val = (real_t)final_val - (real_t)initial_val;
break;
case Variant::VECTOR2:
@@ -953,11 +929,10 @@ bool Tween::_calc_delta_val(const Variant& p_initial_val, const Variant& p_final
delta_val = final_val.operator Vector3() - initial_val.operator Vector3();
break;
- case Variant::BASIS:
- {
- Basis i = initial_val;
- Basis f = final_val;
- delta_val = Basis(f.elements[0][0] - i.elements[0][0],
+ case Variant::BASIS: {
+ Basis i = initial_val;
+ Basis f = final_val;
+ delta_val = 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],
@@ -965,41 +940,34 @@ bool Tween::_calc_delta_val(const Variant& p_initial_val, const Variant& p_final
f.elements[1][2] - i.elements[1][2],
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;
+ f.elements[2][2] - i.elements[2][2]);
+ } break;
- case Variant::TRANSFORM2D:
- {
- 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::TRANSFORM2D: {
+ 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::QUAT:
delta_val = final_val.operator Quat() - initial_val.operator Quat();
break;
- case Variant::RECT3:
- {
- Rect3 i = initial_val;
- Rect3 f = final_val;
- delta_val = Rect3(f.pos - i.pos, f.size - i.size);
- }
- break;
- case Variant::TRANSFORM:
- {
- Transform i = initial_val;
- Transform f = final_val;
- Transform d;
- d.set(f.basis.elements[0][0] - i.basis.elements[0][0],
+ case Variant::RECT3: {
+ Rect3 i = initial_val;
+ Rect3 f = final_val;
+ delta_val = Rect3(f.pos - i.pos, f.size - i.size);
+ } break;
+ case Variant::TRANSFORM: {
+ Transform i = initial_val;
+ Transform f = final_val;
+ Transform d;
+ d.set(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],
@@ -1010,19 +978,15 @@ bool Tween::_calc_delta_val(const Variant& p_initial_val, const Variant& p_final
f.basis.elements[2][2] - i.basis.elements[2][2],
f.origin.x - i.origin.x,
f.origin.y - i.origin.y,
- f.origin.z - i.origin.z
- );
+ f.origin.z - i.origin.z);
- delta_val = d;
- }
- break;
- case Variant::COLOR:
- {
- 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;
+ delta_val = d;
+ } break;
+ case Variant::COLOR: {
+ 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:
ERR_PRINT("Invalid param type, except(int/real/vector2/vector/matrix/matrix32/quat/aabb/transform/color)");
@@ -1031,31 +995,14 @@ bool Tween::_calc_delta_val(const Variant& p_initial_val, const Variant& p_final
return true;
}
-bool Tween::interpolate_property(Object *p_object
- , String 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(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
- );
+bool Tween::interpolate_property(Object *p_object, String 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 (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);
return true;
}
// convert INT to REAL is better for interpolaters
- 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 (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();
ERR_FAIL_COND_V(p_object == NULL, false);
ERR_FAIL_COND_V(!ObjectDB::instance_validate(p_object), false);
@@ -1066,7 +1013,7 @@ bool Tween::interpolate_property(Object *p_object
ERR_FAIL_COND_V(p_delay < 0, false);
bool prop_valid = false;
- p_object->get(p_property,&prop_valid);
+ p_object->get(p_property, &prop_valid);
ERR_FAIL_COND_V(!prop_valid, false);
InterpolateData data;
@@ -1084,38 +1031,21 @@ bool Tween::interpolate_property(Object *p_object
data.ease_type = p_ease_type;
data.delay = p_delay;
- if(!_calc_delta_val(data.initial_val, data.final_val, data.delta_val))
+ if (!_calc_delta_val(data.initial_val, data.final_val, data.delta_val))
return false;
interpolates.push_back(data);
return true;
}
-bool Tween::interpolate_method(Object *p_object
- , String 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(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
- );
+bool Tween::interpolate_method(Object *p_object, String 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 (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 true;
}
// convert INT to REAL is better for interpolaters
- 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 (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();
ERR_FAIL_COND_V(p_object == NULL, false);
ERR_FAIL_COND_V(!ObjectDB::instance_validate(p_object), false);
@@ -1143,30 +1073,17 @@ bool Tween::interpolate_method(Object *p_object
data.ease_type = p_ease_type;
data.delay = p_delay;
- if(!_calc_delta_val(data.initial_val, data.final_val, data.delta_val))
+ if (!_calc_delta_val(data.initial_val, data.final_val, data.delta_val))
return false;
interpolates.push_back(data);
return true;
}
-bool Tween::interpolate_callback(Object *p_object
- , real_t p_duration
- , String p_callback
- , VARIANT_ARG_DECLARE
-) {
-
- 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
- );
+bool Tween::interpolate_callback(Object *p_object, real_t p_duration, String p_callback, VARIANT_ARG_DECLARE) {
+
+ 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 true;
}
@@ -1189,19 +1106,19 @@ bool Tween::interpolate_callback(Object *p_object
data.duration = p_duration;
data.delay = 0;
- 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;
+ 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;
+ args = 0;
data.args = args;
data.arg[0] = p_arg1;
@@ -1210,29 +1127,16 @@ bool Tween::interpolate_callback(Object *p_object
data.arg[3] = p_arg4;
data.arg[4] = p_arg5;
- pending_update ++;
+ pending_update++;
interpolates.push_back(data);
- pending_update --;
+ pending_update--;
return true;
}
-bool Tween::interpolate_deferred_callback(Object *p_object
- , real_t p_duration
- , String p_callback
- , VARIANT_ARG_DECLARE
-) {
-
- 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
- );
+bool Tween::interpolate_deferred_callback(Object *p_object, real_t p_duration, String p_callback, VARIANT_ARG_DECLARE) {
+
+ 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 true;
}
ERR_FAIL_COND_V(p_object == NULL, false);
@@ -1254,19 +1158,19 @@ bool Tween::interpolate_deferred_callback(Object *p_object
data.duration = p_duration;
data.delay = 0;
- 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;
+ 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;
+ args = 0;
data.args = args;
data.arg[0] = p_arg1;
@@ -1275,38 +1179,19 @@ bool Tween::interpolate_deferred_callback(Object *p_object
data.arg[3] = p_arg4;
data.arg[4] = p_arg5;
- pending_update ++;
+ pending_update++;
interpolates.push_back(data);
- pending_update --;
+ pending_update--;
return true;
}
-bool Tween::follow_property(Object *p_object
- , String p_property
- , Variant p_initial_val
- , Object *p_target
- , String p_target_property
- , real_t p_duration
- , TransitionType p_trans_type
- , EaseType p_ease_type
- , real_t p_delay
-) {
- 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
- );
+bool Tween::follow_property(Object *p_object, String p_property, Variant p_initial_val, Object *p_target, String p_target_property, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay) {
+ 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 true;
}
// convert INT to REAL is better for interpolaters
- if(p_initial_val.get_type() == Variant::INT) p_initial_val = p_initial_val.operator real_t();
+ if (p_initial_val.get_type() == Variant::INT) p_initial_val = p_initial_val.operator real_t();
ERR_FAIL_COND_V(p_object == NULL, false);
ERR_FAIL_COND_V(!ObjectDB::instance_validate(p_object), false);
@@ -1318,15 +1203,15 @@ bool Tween::follow_property(Object *p_object
ERR_FAIL_COND_V(p_delay < 0, false);
bool prop_valid = false;
- p_object->get(p_property,&prop_valid);
+ p_object->get(p_property, &prop_valid);
ERR_FAIL_COND_V(!prop_valid, false);
bool target_prop_valid = false;
- Variant target_val = p_target->get(p_target_property,&target_prop_valid);
+ Variant target_val = p_target->get(p_target_property, &target_prop_valid);
ERR_FAIL_COND_V(!target_prop_valid, false);
// convert INT to REAL is better for interpolaters
- if(target_val.get_type() == Variant::INT) target_val = target_val.operator real_t();
+ if (target_val.get_type() == Variant::INT) target_val = target_val.operator real_t();
ERR_FAIL_COND_V(target_val.get_type() != p_initial_val.get_type(), false);
InterpolateData data;
@@ -1349,32 +1234,13 @@ bool Tween::follow_property(Object *p_object
return true;
}
-bool Tween::follow_method(Object *p_object
- , String p_method
- , Variant p_initial_val
- , Object *p_target
- , String p_target_method
- , real_t p_duration
- , TransitionType p_trans_type
- , EaseType p_ease_type
- , real_t p_delay
-) {
- 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
- );
+bool Tween::follow_method(Object *p_object, String p_method, Variant p_initial_val, Object *p_target, String p_target_method, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay) {
+ 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 true;
}
// convert INT to REAL is better for interpolaters
- if(p_initial_val.get_type() == Variant::INT) p_initial_val = p_initial_val.operator real_t();
+ if (p_initial_val.get_type() == Variant::INT) p_initial_val = p_initial_val.operator real_t();
ERR_FAIL_COND_V(p_object == NULL, false);
ERR_FAIL_COND_V(!ObjectDB::instance_validate(p_object), false);
@@ -1395,7 +1261,7 @@ bool Tween::follow_method(Object *p_object
ERR_FAIL_COND_V(error.error != Variant::CallError::CALL_OK, false);
// convert INT to REAL is better for interpolaters
- if(target_val.get_type() == Variant::INT) target_val = target_val.operator real_t();
+ if (target_val.get_type() == Variant::INT) target_val = target_val.operator real_t();
ERR_FAIL_COND_V(target_val.get_type() != p_initial_val.get_type(), false);
InterpolateData data;
@@ -1418,32 +1284,13 @@ bool Tween::follow_method(Object *p_object
return true;
}
-bool Tween::targeting_property(Object *p_object
- , String p_property
- , Object *p_initial
- , String p_initial_property
- , Variant p_final_val
- , real_t p_duration
- , TransitionType p_trans_type
- , EaseType p_ease_type
- , real_t p_delay
-) {
- 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
- );
+bool Tween::targeting_property(Object *p_object, String p_property, Object *p_initial, String p_initial_property, Variant p_final_val, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay) {
+ 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 true;
}
// convert INT to REAL is better for interpolaters
- if(p_final_val.get_type() == Variant::INT) p_final_val = p_final_val.operator real_t();
+ if (p_final_val.get_type() == Variant::INT) p_final_val = p_final_val.operator real_t();
ERR_FAIL_COND_V(p_object == NULL, false);
ERR_FAIL_COND_V(!ObjectDB::instance_validate(p_object), false);
@@ -1455,15 +1302,15 @@ bool Tween::targeting_property(Object *p_object
ERR_FAIL_COND_V(p_delay < 0, false);
bool prop_valid = false;
- p_object->get(p_property,&prop_valid);
+ p_object->get(p_property, &prop_valid);
ERR_FAIL_COND_V(!prop_valid, false);
bool initial_prop_valid = false;
- Variant initial_val = p_initial->get(p_initial_property,&initial_prop_valid);
+ Variant initial_val = p_initial->get(p_initial_property, &initial_prop_valid);
ERR_FAIL_COND_V(!initial_prop_valid, false);
// convert INT to REAL is better for interpolaters
- if(initial_val.get_type() == Variant::INT) initial_val = initial_val.operator real_t();
+ if (initial_val.get_type() == Variant::INT) initial_val = initial_val.operator real_t();
ERR_FAIL_COND_V(initial_val.get_type() != p_final_val.get_type(), false);
InterpolateData data;
@@ -1483,40 +1330,20 @@ bool Tween::targeting_property(Object *p_object
data.ease_type = p_ease_type;
data.delay = p_delay;
- if(!_calc_delta_val(data.initial_val, data.final_val, data.delta_val))
+ if (!_calc_delta_val(data.initial_val, data.final_val, data.delta_val))
return false;
interpolates.push_back(data);
return true;
}
-
-bool Tween::targeting_method(Object *p_object
- , String p_method
- , Object *p_initial
- , String p_initial_method
- , Variant p_final_val
- , real_t p_duration
- , TransitionType p_trans_type
- , EaseType p_ease_type
- , real_t p_delay
-) {
- 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
- );
+bool Tween::targeting_method(Object *p_object, String p_method, Object *p_initial, String p_initial_method, Variant p_final_val, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay) {
+ 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 true;
}
// convert INT to REAL is better for interpolaters
- if(p_final_val.get_type() == Variant::INT) p_final_val = p_final_val.operator real_t();
+ if (p_final_val.get_type() == Variant::INT) p_final_val = p_final_val.operator real_t();
ERR_FAIL_COND_V(p_object == NULL, false);
ERR_FAIL_COND_V(!ObjectDB::instance_validate(p_object), false);
@@ -1537,7 +1364,7 @@ bool Tween::targeting_method(Object *p_object
ERR_FAIL_COND_V(error.error != Variant::CallError::CALL_OK, false);
// convert INT to REAL is better for interpolaters
- if(initial_val.get_type() == Variant::INT) initial_val = initial_val.operator real_t();
+ if (initial_val.get_type() == Variant::INT) initial_val = initial_val.operator real_t();
ERR_FAIL_COND_V(initial_val.get_type() != p_final_val.get_type(), false);
InterpolateData data;
@@ -1557,7 +1384,7 @@ bool Tween::targeting_method(Object *p_object
data.ease_type = p_ease_type;
data.delay = p_delay;
- if(!_calc_delta_val(data.initial_val, data.final_val, data.delta_val))
+ if (!_calc_delta_val(data.initial_val, data.final_val, data.delta_val))
return false;
interpolates.push_back(data);
@@ -1567,14 +1394,13 @@ bool Tween::targeting_method(Object *p_object
Tween::Tween() {
//String autoplay;
- tween_process_mode=TWEEN_PROCESS_IDLE;
- processing=false;
- active=false;
- repeat=false;
- speed_scale=1;
- pending_update=0;
+ tween_process_mode = TWEEN_PROCESS_IDLE;
+ processing = false;
+ active = false;
+ repeat = false;
+ speed_scale = 1;
+ pending_update = 0;
}
Tween::~Tween() {
-
}
diff --git a/scene/animation/tween.h b/scene/animation/tween.h
index 07c2e90da2..84f866f43e 100644
--- a/scene/animation/tween.h
+++ b/scene/animation/tween.h
@@ -31,10 +31,9 @@
#include "scene/main/node.h"
-
class Tween : public Node {
- GDCLASS( Tween, Node );
+ GDCLASS(Tween, Node);
public:
enum TweenProcessMode {
@@ -42,30 +41,30 @@ public:
TWEEN_PROCESS_IDLE,
};
- enum TransitionType {
- TRANS_LINEAR,
- TRANS_SINE,
- TRANS_QUINT,
- TRANS_QUART,
- TRANS_QUAD,
- TRANS_EXPO,
- TRANS_ELASTIC,
- TRANS_CUBIC,
- TRANS_CIRC,
- TRANS_BOUNCE,
- TRANS_BACK,
+ enum TransitionType {
+ TRANS_LINEAR,
+ TRANS_SINE,
+ TRANS_QUINT,
+ TRANS_QUART,
+ TRANS_QUAD,
+ TRANS_EXPO,
+ TRANS_ELASTIC,
+ TRANS_CUBIC,
+ TRANS_CIRC,
+ TRANS_BOUNCE,
+ TRANS_BACK,
TRANS_COUNT,
- };
+ };
- enum EaseType {
- EASE_IN,
- EASE_OUT,
- EASE_IN_OUT,
+ enum EaseType {
+ EASE_IN,
+ EASE_OUT,
+ EASE_IN_OUT,
EASE_OUT_IN,
EASE_COUNT,
- };
+ };
private:
enum InterpolateType {
@@ -117,45 +116,32 @@ private:
};
List<PendingCommand> pending_commands;
- 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 _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();
typedef real_t (*interpolater)(real_t t, real_t b, real_t c, real_t d);
static interpolater interpolaters[TRANS_COUNT][EASE_COUNT];
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(InterpolateData& p_data);
- 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);
+ Variant &_get_delta_val(InterpolateData &p_data);
+ Variant &_get_initial_val(InterpolateData &p_data);
+ 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);
void _tween_process(float p_delta);
- void _set_process(bool p_process,bool p_force=false);
+ void _set_process(bool p_process, bool p_force = false);
void _remove(Object *p_node, String p_key, bool first_only);
protected:
-
- bool _set(const StringName& p_name, const Variant& p_value);
- bool _get(const StringName& p_name,Variant &r_ret) const;
+ 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);
static void _bind_methods();
public:
-
bool is_active() const;
void set_active(bool p_active);
@@ -182,89 +168,28 @@ public:
real_t tell() const;
real_t get_runtime() const;
- bool interpolate_property(Object *p_node
- , String 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 = 0
- );
-
- bool interpolate_method(Object *p_node
- , String 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 = 0
- );
-
- bool interpolate_callback(Object *p_object
- , real_t p_duration
- , String p_callback
- , VARIANT_ARG_DECLARE
- );
-
- bool interpolate_deferred_callback(Object *p_object
- , real_t p_duration
- , String p_callback
- , VARIANT_ARG_DECLARE
- );
-
- bool follow_property(Object *p_node
- , String p_property
- , Variant p_initial_val
- , Object *p_target
- , String p_target_property
- , real_t p_duration
- , TransitionType p_trans_type
- , EaseType p_ease_type
- , real_t p_delay = 0
- );
-
- bool follow_method(Object *p_node
- , String p_method
- , Variant p_initial_val
- , Object *p_target
- , String p_target_method
- , real_t p_duration
- , TransitionType p_trans_type
- , EaseType p_ease_type
- , real_t p_delay = 0
- );
-
- bool targeting_property(Object *p_node
- , String p_property
- , Object *p_initial
- , String p_initial_property
- , Variant p_final_val
- , real_t p_duration
- , TransitionType p_trans_type
- , EaseType p_ease_type
- , real_t p_delay = 0
- );
-
- bool targeting_method(Object *p_node
- , String p_method
- , Object *p_initial
- , String p_initial_method
- , Variant p_final_val
- , real_t p_duration
- , TransitionType p_trans_type
- , EaseType p_ease_type
- , real_t p_delay = 0
- );
+ bool interpolate_property(Object *p_node, String 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 = 0);
+
+ bool interpolate_method(Object *p_node, String 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 = 0);
+
+ bool interpolate_callback(Object *p_object, real_t p_duration, String p_callback, VARIANT_ARG_DECLARE);
+
+ bool interpolate_deferred_callback(Object *p_object, real_t p_duration, String p_callback, VARIANT_ARG_DECLARE);
+
+ bool follow_property(Object *p_node, String p_property, Variant p_initial_val, Object *p_target, String p_target_property, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay = 0);
+
+ bool follow_method(Object *p_node, String p_method, Variant p_initial_val, Object *p_target, String p_target_method, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay = 0);
+
+ bool targeting_property(Object *p_node, String p_property, Object *p_initial, String p_initial_property, Variant p_final_val, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay = 0);
+
+ bool targeting_method(Object *p_node, String p_method, Object *p_initial, String p_initial_method, Variant p_final_val, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay = 0);
Tween();
~Tween();
};
-VARIANT_ENUM_CAST( Tween::TweenProcessMode );
-VARIANT_ENUM_CAST( Tween::TransitionType );
-VARIANT_ENUM_CAST( Tween::EaseType );
+VARIANT_ENUM_CAST(Tween::TweenProcessMode);
+VARIANT_ENUM_CAST(Tween::TransitionType);
+VARIANT_ENUM_CAST(Tween::EaseType);
#endif
-
diff --git a/scene/animation/tween_interpolaters.cpp b/scene/animation/tween_interpolaters.cpp
index 25a27252f5..ef55b63edd 100644
--- a/scene/animation/tween_interpolaters.cpp
+++ b/scene/animation/tween_interpolaters.cpp
@@ -34,355 +34,278 @@ const real_t pi = 3.1415926535898;
// linear
///////////////////////////////////////////////////////////////////////////
namespace linear {
- static real_t in(real_t t, real_t b, real_t c, real_t d)
- {
- return c * t / d + b;
- }
+static real_t in(real_t t, real_t b, real_t c, real_t d) {
+ return c * t / d + b;
+}
- static real_t out(real_t t, real_t b, real_t c, real_t d)
- {
- return c * t / d + b;
- }
+static real_t out(real_t t, real_t b, real_t c, real_t d) {
+ return c * t / d + b;
+}
- static real_t in_out(real_t t, real_t b, real_t c, real_t d)
- {
- return c * t / d + b;
- }
+static real_t in_out(real_t t, real_t b, real_t c, real_t d) {
+ return c * t / d + b;
+}
- static real_t out_in(real_t t, real_t b, real_t c, real_t d)
- {
- return c * t / d + b;
- }
+static real_t out_in(real_t t, real_t b, real_t c, real_t d) {
+ return c * t / d + b;
+}
};
///////////////////////////////////////////////////////////////////////////
// sine
///////////////////////////////////////////////////////////////////////////
namespace sine {
- static real_t in(real_t t, real_t b, real_t c, real_t d)
- {
- return -c * cos(t / d * (pi / 2)) + c + b;
- }
+static real_t in(real_t t, real_t b, real_t c, real_t d) {
+ return -c * cos(t / d * (pi / 2)) + c + b;
+}
- static real_t out(real_t t, real_t b, real_t c, real_t d)
- {
- return c * sin(t / d * (pi / 2)) + b;
- }
+static real_t out(real_t t, real_t b, real_t c, real_t d) {
+ return c * sin(t / d * (pi / 2)) + b;
+}
- static real_t in_out(real_t t, real_t b, real_t c, real_t d)
- {
- return -c / 2 * (cos(pi * t / d) - 1) + b;
- }
+static real_t in_out(real_t t, real_t b, real_t c, real_t d) {
+ return -c / 2 * (cos(pi * t / d) - 1) + b;
+}
- static real_t out_in(real_t t, real_t b, real_t c, real_t d)
- {
- return (t < d / 2)
- ? out(t * 2, b, c / 2, d)
- : in((t * 2) - d, b + c / 2, c / 2, d)
- ;
- }
+static real_t out_in(real_t t, real_t b, real_t c, real_t d) {
+ return (t < d / 2) ? out(t * 2, b, c / 2, d) : in((t * 2) - d, b + c / 2, c / 2, d);
+}
};
///////////////////////////////////////////////////////////////////////////
// quint
///////////////////////////////////////////////////////////////////////////
namespace quint {
- static real_t in(real_t t, real_t b, real_t c, real_t d)
- {
- return c * pow(t / d, 5) + b;
- }
+static real_t in(real_t t, real_t b, real_t c, real_t d) {
+ return c * pow(t / d, 5) + b;
+}
- static real_t out(real_t t, real_t b, real_t c, real_t d)
- {
- return c * (pow(t / d - 1, 5) + 1) + b;
- }
+static real_t out(real_t t, real_t b, real_t c, real_t d) {
+ return c * (pow(t / d - 1, 5) + 1) + b;
+}
- static real_t in_out(real_t t, real_t b, real_t c, real_t d)
- {
- t = t / d * 2;
- if (t < 1) return c / 2 * pow(t, 5) + b;
- return c / 2 * (pow(t - 2, 5) + 2) + b;
- }
+static real_t in_out(real_t t, real_t b, real_t c, real_t d) {
+ t = t / d * 2;
+ if (t < 1) return c / 2 * pow(t, 5) + b;
+ return c / 2 * (pow(t - 2, 5) + 2) + b;
+}
- static real_t out_in(real_t t, real_t b, real_t c, real_t d)
- {
- return (t < d / 2)
- ? out(t * 2, b, c / 2, d)
- : in((t * 2) - d, b + c / 2, c / 2, d)
- ;
- }
+static real_t out_in(real_t t, real_t b, real_t c, real_t d) {
+ return (t < d / 2) ? out(t * 2, b, c / 2, d) : in((t * 2) - d, b + c / 2, c / 2, d);
+}
};
///////////////////////////////////////////////////////////////////////////
// quart
///////////////////////////////////////////////////////////////////////////
namespace quart {
- static real_t in(real_t t, real_t b, real_t c, real_t d)
- {
- return c * pow(t / d, 4) + b;
- }
+static real_t in(real_t t, real_t b, real_t c, real_t d) {
+ return c * pow(t / d, 4) + b;
+}
- static real_t out(real_t t, real_t b, real_t c, real_t d)
- {
- return -c * (pow(t / d - 1, 4) - 1) + b;
- }
+static real_t out(real_t t, real_t b, real_t c, real_t d) {
+ return -c * (pow(t / d - 1, 4) - 1) + b;
+}
- static real_t in_out(real_t t, real_t b, real_t c, real_t d)
- {
- t = t / d * 2;
- if (t < 1) return c / 2 * pow(t, 4) + b;
- return -c / 2 * (pow(t - 2, 4) - 2) + b;
- }
+static real_t in_out(real_t t, real_t b, real_t c, real_t d) {
+ t = t / d * 2;
+ if (t < 1) return c / 2 * pow(t, 4) + b;
+ return -c / 2 * (pow(t - 2, 4) - 2) + b;
+}
- static real_t out_in(real_t t, real_t b, real_t c, real_t d)
- {
- return (t < d / 2)
- ? out(t * 2, b, c / 2, d)
- : in((t * 2) - d, b + c / 2, c / 2, d)
- ;
- }
+static real_t out_in(real_t t, real_t b, real_t c, real_t d) {
+ return (t < d / 2) ? out(t * 2, b, c / 2, d) : in((t * 2) - d, b + c / 2, c / 2, d);
+}
};
///////////////////////////////////////////////////////////////////////////
// quad
///////////////////////////////////////////////////////////////////////////
namespace quad {
- static real_t in(real_t t, real_t b, real_t c, real_t d)
- {
- return c * pow(t / d, 2) + b;
- }
+static real_t in(real_t t, real_t b, real_t c, real_t d) {
+ return c * pow(t / d, 2) + b;
+}
- static real_t out(real_t t, real_t b, real_t c, real_t d)
- {
- t = t / d;
- return -c * t * (t - 2) + b;
- }
+static real_t out(real_t t, real_t b, real_t c, real_t d) {
+ t = t / d;
+ return -c * t * (t - 2) + b;
+}
- static real_t in_out(real_t t, real_t b, real_t c, real_t d)
- {
- t = t / d * 2;
- if (t < 1) return c / 2 * pow(t, 2) + b;
- return -c / 2 * ((t - 1) * (t - 3) - 1) + b;
- }
+static real_t in_out(real_t t, real_t b, real_t c, real_t d) {
+ t = t / d * 2;
+ if (t < 1) return c / 2 * pow(t, 2) + b;
+ return -c / 2 * ((t - 1) * (t - 3) - 1) + b;
+}
- static real_t out_in(real_t t, real_t b, real_t c, real_t d)
- {
- return (t < d / 2)
- ? out(t * 2, b, c / 2, d)
- : in((t * 2) - d, b + c / 2, c / 2, d)
- ;
- }
+static real_t out_in(real_t t, real_t b, real_t c, real_t d) {
+ return (t < d / 2) ? out(t * 2, b, c / 2, d) : in((t * 2) - d, b + c / 2, c / 2, d);
+}
};
///////////////////////////////////////////////////////////////////////////
// expo
///////////////////////////////////////////////////////////////////////////
namespace expo {
- static real_t in(real_t t, real_t b, real_t c, real_t d)
- {
- if (t == 0) return b;
- return c * pow(2, 10 * (t / d - 1)) + b - c * 0.001;
- }
+static real_t in(real_t t, real_t b, real_t c, real_t d) {
+ if (t == 0) return b;
+ return c * pow(2, 10 * (t / d - 1)) + b - c * 0.001;
+}
- static real_t out(real_t t, real_t b, real_t c, real_t d)
- {
- if (t == d) return b + c;
- return c * 1.001 * (-pow(2, -10 * t / d) + 1) + b;
- }
+static real_t out(real_t t, real_t b, real_t c, real_t d) {
+ if (t == d) return b + c;
+ return c * 1.001 * (-pow(2, -10 * t / d) + 1) + b;
+}
- static real_t in_out(real_t t, real_t b, real_t c, real_t d)
- {
- if (t == 0) return b;
- if (t == d) return b + c;
- t = t / d * 2;
- if (t < 1) return c / 2 * pow(2, 10 * (t - 1)) + b - c * 0.0005;
- return c / 2 * 1.0005 * (-pow(2, -10 * (t - 1)) + 2) + b;
- }
+static real_t in_out(real_t t, real_t b, real_t c, real_t d) {
+ if (t == 0) return b;
+ if (t == d) return b + c;
+ t = t / d * 2;
+ if (t < 1) return c / 2 * pow(2, 10 * (t - 1)) + b - c * 0.0005;
+ return c / 2 * 1.0005 * (-pow(2, -10 * (t - 1)) + 2) + b;
+}
- static real_t out_in(real_t t, real_t b, real_t c, real_t d)
- {
- return (t < d / 2)
- ? out(t * 2, b, c / 2, d)
- : in((t * 2) - d, b + c / 2, c / 2, d)
- ;
- }
+static real_t out_in(real_t t, real_t b, real_t c, real_t d) {
+ return (t < d / 2) ? out(t * 2, b, c / 2, d) : in((t * 2) - d, b + c / 2, c / 2, d);
+}
};
///////////////////////////////////////////////////////////////////////////
// elastic
///////////////////////////////////////////////////////////////////////////
namespace elastic {
- static real_t in(real_t t, real_t b, real_t c, real_t d)
- {
- if (t == 0) return b;
- if ((t /= d) == 1) return b + c;
- float p = d * 0.3f;
- float a = c;
- float s = p / 4;
- float postFix = a * pow(2,10 * (t -= 1)); // this is a fix, again, with post-increment operators
- return -(postFix * sin((t * d - s) * (2 * pi) / p )) + b;
- }
+static real_t in(real_t t, real_t b, real_t c, real_t d) {
+ if (t == 0) return b;
+ if ((t /= d) == 1) return b + c;
+ float p = d * 0.3f;
+ float a = c;
+ float s = p / 4;
+ float postFix = a * pow(2, 10 * (t -= 1)); // this is a fix, again, with post-increment operators
+ return -(postFix * sin((t * d - s) * (2 * pi) / p)) + b;
+}
- static real_t out(real_t t, real_t b, real_t c, real_t d)
- {
- if (t == 0) return b;
- if ((t /= d) == 1) return b + c;
- float p = d * 0.3f;
- float a = c;
- float s = p / 4;
- return (a * pow(2, -10 * t) * sin((t * d - s) * (2 * pi) / p ) + c + b);
- }
+static real_t out(real_t t, real_t b, real_t c, real_t d) {
+ if (t == 0) return b;
+ if ((t /= d) == 1) return b + c;
+ float p = d * 0.3f;
+ float a = c;
+ float s = p / 4;
+ return (a * pow(2, -10 * t) * sin((t * d - s) * (2 * pi) / p) + c + b);
+}
- static real_t in_out(real_t t, real_t b, real_t c, real_t d)
- {
- if (t == 0) return b;
- if ((t /= d / 2) == 2) return b + c;
- float p = d * (0.3f * 1.5f);
- float a = c;
- float s = p / 4;
-
- if (t < 1) {
- float postFix = a * pow(2, 10 * (t -= 1)); // postIncrement is evil
- return -0.5f * (postFix * sin((t * d - s) * (2 * pi) / p)) + b;
- }
- float postFix = a * pow(2, -10 * (t -= 1)); // postIncrement is evil
- return postFix * sin((t * d - s) * (2 * pi) / p ) * 0.5f + c + b;
- }
+static real_t in_out(real_t t, real_t b, real_t c, real_t d) {
+ if (t == 0) return b;
+ if ((t /= d / 2) == 2) return b + c;
+ float p = d * (0.3f * 1.5f);
+ float a = c;
+ float s = p / 4;
- static real_t out_in(real_t t, real_t b, real_t c, real_t d)
- {
- return (t < d / 2)
- ? out(t * 2, b, c / 2, d)
- : in((t * 2) - d, b + c / 2, c / 2, d)
- ;
+ if (t < 1) {
+ float postFix = a * pow(2, 10 * (t -= 1)); // postIncrement is evil
+ return -0.5f * (postFix * sin((t * d - s) * (2 * pi) / p)) + b;
}
+ float postFix = a * pow(2, -10 * (t -= 1)); // postIncrement is evil
+ return postFix * sin((t * d - s) * (2 * pi) / p) * 0.5f + c + b;
+}
+
+static real_t out_in(real_t t, real_t b, real_t c, real_t d) {
+ return (t < d / 2) ? out(t * 2, b, c / 2, d) : in((t * 2) - d, b + c / 2, c / 2, d);
+}
};
///////////////////////////////////////////////////////////////////////////
// cubic
///////////////////////////////////////////////////////////////////////////
namespace cubic {
- static real_t in(real_t t, real_t b, real_t c, real_t d)
- {
- return c * (t /= d) * t * t + b;
- }
+static real_t in(real_t t, real_t b, real_t c, real_t d) {
+ return c * (t /= d) * t * t + b;
+}
- static real_t out(real_t t, real_t b, real_t c, real_t d)
- {
- t = t / d - 1;
- return c * (t * t * t + 1) + b;
- }
+static real_t out(real_t t, real_t b, real_t c, real_t d) {
+ t = t / d - 1;
+ return c * (t * t * t + 1) + b;
+}
- static real_t in_out(real_t t, real_t b, real_t c, real_t d)
- {
- if ((t /= d / 2) < 1) return c / 2 * t * t * t + b;
- return c / 2 * ((t -= 2) * t * t + 2) + b;
- }
+static real_t in_out(real_t t, real_t b, real_t c, real_t d) {
+ if ((t /= d / 2) < 1) return c / 2 * t * t * t + b;
+ return c / 2 * ((t -= 2) * t * t + 2) + b;
+}
- static real_t out_in(real_t t, real_t b, real_t c, real_t d)
- {
- return (t < d / 2)
- ? out(t * 2, b, c / 2, d)
- : in((t * 2) - d, b + c / 2, c / 2, d)
- ;
- }
+static real_t out_in(real_t t, real_t b, real_t c, real_t d) {
+ return (t < d / 2) ? out(t * 2, b, c / 2, d) : in((t * 2) - d, b + c / 2, c / 2, d);
+}
};
///////////////////////////////////////////////////////////////////////////
// circ
///////////////////////////////////////////////////////////////////////////
namespace circ {
- static real_t in(real_t t, real_t b, real_t c, real_t d)
- {
- return -c * (sqrt(1 - (t /= d) * t) - 1) + b; // TODO: ehrich: operation with t is undefined
- }
+static real_t in(real_t t, real_t b, real_t c, real_t d) {
+ return -c * (sqrt(1 - (t /= d) * t) - 1) + b; // TODO: ehrich: operation with t is undefined
+}
- static real_t out(real_t t, real_t b, real_t c, real_t d)
- {
- return c * sqrt(1 - (t = t / d - 1) * t) + b; // TODO: ehrich: operation with t is undefined
- }
+static real_t out(real_t t, real_t b, real_t c, real_t d) {
+ return c * sqrt(1 - (t = t / d - 1) * t) + b; // TODO: ehrich: operation with t is undefined
+}
- static real_t in_out(real_t t, real_t b, real_t c, real_t d)
- {
- if ((t /= d / 2) < 1) return -c / 2 * (sqrt(1 - t * t) - 1) + b;
- return c / 2 * (sqrt(1 - t * (t -= 2)) + 1) + b; // TODO: ehrich: operation with t is undefined
- }
+static real_t in_out(real_t t, real_t b, real_t c, real_t d) {
+ if ((t /= d / 2) < 1) return -c / 2 * (sqrt(1 - t * t) - 1) + b;
+ return c / 2 * (sqrt(1 - t * (t -= 2)) + 1) + b; // TODO: ehrich: operation with t is undefined
+}
- static real_t out_in(real_t t, real_t b, real_t c, real_t d)
- {
- return (t < d / 2)
- ? out(t * 2, b, c / 2, d)
- : in((t * 2) - d, b + c / 2, c / 2, d)
- ;
- }
+static real_t out_in(real_t t, real_t b, real_t c, real_t d) {
+ return (t < d / 2) ? out(t * 2, b, c / 2, d) : in((t * 2) - d, b + c / 2, c / 2, d);
+}
};
///////////////////////////////////////////////////////////////////////////
// bounce
///////////////////////////////////////////////////////////////////////////
namespace bounce {
- static real_t out(real_t t, real_t b, real_t c, real_t d);
+static real_t out(real_t t, real_t b, real_t c, real_t d);
- static real_t in(real_t t, real_t b, real_t c, real_t d)
- {
- return c - out(d - t, 0, c, d) + b;
- }
+static real_t in(real_t t, real_t b, real_t c, real_t d) {
+ return c - out(d - t, 0, c, d) + b;
+}
- static real_t out(real_t t, real_t b, real_t c, real_t d)
- {
- if ((t /= d) < (1 / 2.75f)) {
- return c*(7.5625f*t*t) + b;
- } else if (t < (2/2.75f)) {
- float postFix = t-=(1.5f/2.75f);
- return c*(7.5625f*(postFix)*t + .75f) + b;
- } else if (t < (2.5/2.75)) {
- float postFix = t-=(2.25f/2.75f);
- return c*(7.5625f*(postFix)*t + .9375f) + b;
- } else {
- float postFix = t-=(2.625f/2.75f);
- return c*(7.5625f*(postFix)*t + .984375f) + b;
- }
+static real_t out(real_t t, real_t b, real_t c, real_t d) {
+ if ((t /= d) < (1 / 2.75f)) {
+ return c * (7.5625f * t * t) + b;
+ } else if (t < (2 / 2.75f)) {
+ float postFix = t -= (1.5f / 2.75f);
+ return c * (7.5625f * (postFix)*t + .75f) + b;
+ } else if (t < (2.5 / 2.75)) {
+ float postFix = t -= (2.25f / 2.75f);
+ return c * (7.5625f * (postFix)*t + .9375f) + b;
+ } else {
+ float postFix = t -= (2.625f / 2.75f);
+ return c * (7.5625f * (postFix)*t + .984375f) + b;
}
+}
- static real_t in_out(real_t t, real_t b, real_t c, real_t d)
- {
- return (t < d / 2)
- ? in(t * 2, b, c / 2, d)
- : out((t * 2) - d, b + c / 2, c / 2, d)
- ;
- }
+static real_t in_out(real_t t, real_t b, real_t c, real_t d) {
+ return (t < d / 2) ? in(t * 2, b, c / 2, d) : out((t * 2) - d, b + c / 2, c / 2, d);
+}
- static real_t out_in(real_t t, real_t b, real_t c, real_t d)
- {
- return (t < d / 2)
- ? out(t * 2, b, c / 2, d)
- : in((t * 2) - d, b + c / 2, c / 2, d)
- ;
- }
+static real_t out_in(real_t t, real_t b, real_t c, real_t d) {
+ return (t < d / 2) ? out(t * 2, b, c / 2, d) : in((t * 2) - d, b + c / 2, c / 2, d);
+}
};
///////////////////////////////////////////////////////////////////////////
// back
///////////////////////////////////////////////////////////////////////////
namespace back {
- static real_t in(real_t t, real_t b, real_t c, real_t d)
- {
- float s = 1.70158f;
- float postFix = t /= d;
- return c * (postFix) * t * ((s + 1) * t - s) + b;
- }
+static real_t in(real_t t, real_t b, real_t c, real_t d) {
+ float s = 1.70158f;
+ float postFix = t /= d;
+ return c * (postFix)*t * ((s + 1) * t - s) + b;
+}
- static real_t out(real_t t, real_t b, real_t c, real_t d)
- {
- float s = 1.70158f;
- return c * ((t = t / d- 1) * t * ((s + 1) * t + s) + 1) + b; // TODO: ehrich: operation with t is undefined
- }
+static real_t out(real_t t, real_t b, real_t c, real_t d) {
+ float s = 1.70158f;
+ return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b; // TODO: ehrich: operation with t is undefined
+}
- static real_t in_out(real_t t, real_t b, real_t c, real_t d)
- {
- float s = 1.70158f;
- if ((t /= d / 2) < 1) return c / 2 * (t * t * (((s *= (1.525f)) + 1) * t - s)) + b; // TODO: ehrich: operation with s is undefined
- float postFix = t -= 2;
- return c / 2 * ((postFix) * t * (((s *= (1.525f)) + 1) * t + s) + 2) + b; // TODO: ehrich: operation with s is undefined
- }
+static real_t in_out(real_t t, real_t b, real_t c, real_t d) {
+ float s = 1.70158f;
+ if ((t /= d / 2) < 1) return c / 2 * (t * t * (((s *= (1.525f)) + 1) * t - s)) + b; // TODO: ehrich: operation with s is undefined
+ float postFix = t -= 2;
+ return c / 2 * ((postFix)*t * (((s *= (1.525f)) + 1) * t + s) + 2) + b; // TODO: ehrich: operation with s is undefined
+}
- static real_t out_in(real_t t, real_t b, real_t c, real_t d)
- {
- return (t < d / 2)
- ? out(t * 2, b, c / 2, d)
- : in((t * 2) - d, b + c / 2, c / 2, d)
- ;
- }
+static real_t out_in(real_t t, real_t b, real_t c, real_t d) {
+ return (t < d / 2) ? out(t * 2, b, c / 2, d) : in((t * 2) - d, b + c / 2, c / 2, d);
+}
};
Tween::interpolater Tween::interpolaters[Tween::TRANS_COUNT][Tween::EASE_COUNT] = {
@@ -405,4 +328,3 @@ real_t Tween::_run_equation(TransitionType p_trans_type, EaseType p_ease_type, r
ERR_FAIL_COND_V(cb == NULL, b);
return cb(t, b, c, d);
}
-