summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
Diffstat (limited to 'scene')
-rw-r--r--scene/3d/camera.cpp2
-rw-r--r--scene/animation/animation_player.cpp87
-rw-r--r--scene/animation/animation_player.h26
-rw-r--r--scene/gui/video_player.cpp1
-rw-r--r--scene/main/node.cpp12
-rw-r--r--scene/main/scene_tree.cpp10
-rw-r--r--scene/main/scene_tree.h3
7 files changed, 124 insertions, 17 deletions
diff --git a/scene/3d/camera.cpp b/scene/3d/camera.cpp
index 8c7d0c23c3..abc4a03498 100644
--- a/scene/3d/camera.cpp
+++ b/scene/3d/camera.cpp
@@ -649,7 +649,7 @@ Camera::Camera() {
current = false;
force_change = false;
mode = PROJECTION_PERSPECTIVE;
- set_perspective(65.0, 0.1, 100.0);
+ set_perspective(70.0, 0.05, 100.0);
keep_aspect = KEEP_HEIGHT;
layers = 0xfffff;
v_offset = 0;
diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp
index 010f5a586f..206f3ccca2 100644
--- a/scene/animation/animation_player.cpp
+++ b/scene/animation/animation_player.cpp
@@ -33,6 +33,17 @@
#include "message_queue.h"
#include "scene/scene_string_names.h"
+#ifdef TOOLS_ENABLED
+void AnimatedValuesBackup::update_skeletons() {
+
+ for (int i = 0; i < entries.size(); i++) {
+ if (entries[i].bone_idx != -1) {
+ Object::cast_to<Skeleton>(entries[i].object)->notification(Skeleton::NOTIFICATION_UPDATE_SKELETON);
+ }
+ }
+}
+#endif
+
bool AnimationPlayer::_set(const StringName &p_name, const Variant &p_value) {
String name = p_name;
@@ -228,7 +239,11 @@ void AnimationPlayer::_notification(int p_what) {
}
}
-void AnimationPlayer::_generate_node_caches(AnimationData *p_anim) {
+void AnimationPlayer::_ensure_node_caches(AnimationData *p_anim) {
+
+ // Already cached?
+ if (p_anim->node_cache.size() == p_anim->animation->get_track_count())
+ return;
Node *parent = get_node(root);
@@ -336,11 +351,7 @@ void AnimationPlayer::_generate_node_caches(AnimationData *p_anim) {
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);
- }
-
+ _ensure_node_caches(p_anim);
ERR_FAIL_COND(p_anim->node_cache.size() != p_anim->animation->get_track_count());
Animation *a = p_anim->animation.operator->();
@@ -1205,6 +1216,70 @@ void AnimationPlayer::get_argument_options(const StringName &p_function, int p_i
Node::get_argument_options(p_function, p_idx, r_options);
}
+#ifdef TOOLS_ENABLED
+AnimatedValuesBackup AnimationPlayer::backup_animated_values() {
+
+ if (!playback.current.from)
+ return AnimatedValuesBackup();
+
+ _ensure_node_caches(playback.current.from);
+
+ AnimatedValuesBackup backup;
+
+ for (int i = 0; i < playback.current.from->node_cache.size(); i++) {
+ TrackNodeCache *nc = playback.current.from->node_cache[i];
+ if (!nc)
+ continue;
+
+ if (nc->skeleton) {
+ if (nc->bone_idx == -1)
+ continue;
+
+ AnimatedValuesBackup::Entry entry;
+ entry.object = nc->skeleton;
+ entry.bone_idx = nc->bone_idx;
+ entry.value = nc->skeleton->get_bone_pose(nc->bone_idx);
+ backup.entries.push_back(entry);
+ } else {
+ if (nc->spatial) {
+ AnimatedValuesBackup::Entry entry;
+ entry.object = nc->spatial;
+ entry.subpath.push_back("transform");
+ entry.value = nc->spatial->get_transform();
+ entry.bone_idx = -1;
+ backup.entries.push_back(entry);
+ } else {
+ for (Map<StringName, TrackNodeCache::PropertyAnim>::Element *E = nc->property_anim.front(); E; E = E->next()) {
+ AnimatedValuesBackup::Entry entry;
+ entry.object = E->value().object;
+ entry.subpath = E->value().subpath;
+ bool valid;
+ entry.value = E->value().object->get_indexed(E->value().subpath, &valid);
+ entry.bone_idx = -1;
+ if (valid)
+ backup.entries.push_back(entry);
+ }
+ }
+ }
+ }
+
+ return backup;
+}
+
+void AnimationPlayer::restore_animated_values(const AnimatedValuesBackup &p_backup) {
+
+ for (int i = 0; i < p_backup.entries.size(); i++) {
+
+ const AnimatedValuesBackup::Entry *entry = &p_backup.entries[i];
+ if (entry->bone_idx == -1) {
+ entry->object->set_indexed(entry->subpath, entry->value);
+ } else {
+ Object::cast_to<Skeleton>(entry->object)->set_bone_pose(entry->bone_idx, entry->value);
+ }
+ }
+}
+#endif
+
void AnimationPlayer::_bind_methods() {
ClassDB::bind_method(D_METHOD("_node_removed"), &AnimationPlayer::_node_removed);
diff --git a/scene/animation/animation_player.h b/scene/animation/animation_player.h
index e4e021c7fe..e39afcf199 100644
--- a/scene/animation/animation_player.h
+++ b/scene/animation/animation_player.h
@@ -38,6 +38,24 @@
@author Juan Linietsky <reduzio@gmail.com>
*/
+#ifdef TOOLS_ENABLED
+// To save/restore animated values
+class AnimatedValuesBackup {
+ struct Entry {
+ Object *object;
+ Vector<StringName> subpath; // Unused if bone
+ int bone_idx; // -1 if not a bone
+ Variant value;
+ };
+ Vector<Entry> entries;
+
+ friend class AnimationPlayer;
+
+public:
+ void update_skeletons();
+};
+#endif
+
class AnimationPlayer : public Node {
GDCLASS(AnimationPlayer, Node);
OBJ_CATEGORY("Animation Nodes");
@@ -198,7 +216,7 @@ private:
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 _ensure_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();
@@ -291,6 +309,12 @@ public:
void get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const;
+#ifdef TOOLS_ENABLED
+ // These may be interesting for games, but are too dangerous for general use
+ AnimatedValuesBackup backup_animated_values();
+ void restore_animated_values(const AnimatedValuesBackup &p_backup);
+#endif
+
AnimationPlayer();
~AnimationPlayer();
};
diff --git a/scene/gui/video_player.cpp b/scene/gui/video_player.cpp
index c7157d539d..8f567f9796 100644
--- a/scene/gui/video_player.cpp
+++ b/scene/gui/video_player.cpp
@@ -490,6 +490,7 @@ VideoPlayer::VideoPlayer() {
expand = true;
audio_track = 0;
+ bus_index = 0;
buffering_ms = 500;
server_mix_rate = 44100;
diff --git a/scene/main/node.cpp b/scene/main/node.cpp
index 506dc85475..d8baa7834d 100644
--- a/scene/main/node.cpp
+++ b/scene/main/node.cpp
@@ -2114,8 +2114,16 @@ Node *Node::_duplicate(int p_flags, Map<const Node *, Node *> *r_duplimap) const
node_tree.push_front(this);
if (instanced) {
+ // Since nodes in the instanced hierarchy won't be duplicated explicitly, we need to make an inventory
+ // of all the nodes in the tree of the instanced scene in order to transfer the values of the properties
+
for (List<const Node *>::Element *N = node_tree.front(); N; N = N->next()) {
for (int i = 0; i < N->get()->get_child_count(); ++i) {
+
+ // Skip nodes not really belonging to the instanced hierarchy; they'll be processed normally later
+ if (get_child(i)->data.owner != this)
+ continue;
+
node_tree.push_back(N->get()->get_child(i));
}
}
@@ -2124,6 +2132,7 @@ Node *Node::_duplicate(int p_flags, Map<const Node *, Node *> *r_duplimap) const
for (List<const Node *>::Element *N = node_tree.front(); N; N = N->next()) {
Node *current_node = node->get_node(get_path_to(N->get()));
+ ERR_CONTINUE(!current_node);
if (p_flags & DUPLICATE_SCRIPTS) {
bool is_valid = false;
@@ -2136,9 +2145,6 @@ Node *Node::_duplicate(int p_flags, Map<const Node *, Node *> *r_duplimap) const
List<PropertyInfo> plist;
N->get()->get_property_list(&plist);
- if (!current_node)
- continue;
-
for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) {
if (!(E->get().usage & PROPERTY_USAGE_STORAGE))
diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp
index 17abf2425a..f74bf161f0 100644
--- a/scene/main/scene_tree.cpp
+++ b/scene/main/scene_tree.cpp
@@ -127,7 +127,7 @@ void SceneTree::remove_from_group(const StringName &p_group, Node *p_node) {
group_map.erase(E);
}
-void SceneTree::_flush_transform_notifications() {
+void SceneTree::flush_transform_notifications() {
SelfList<Node> *n = xform_change_list.first();
while (n) {
@@ -448,7 +448,7 @@ bool SceneTree::iteration(float p_time) {
current_frame++;
- _flush_transform_notifications();
+ flush_transform_notifications();
MainLoop::iteration(p_time);
physics_process_time = p_time;
@@ -459,7 +459,7 @@ bool SceneTree::iteration(float p_time) {
_notify_group_pause("physics_process", Node::NOTIFICATION_PHYSICS_PROCESS);
_flush_ugc();
MessageQueue::get_singleton()->flush(); //small little hack
- _flush_transform_notifications();
+ flush_transform_notifications();
call_group_flags(GROUP_CALL_REALTIME, "_viewports", "update_worlds");
root_lock--;
@@ -487,7 +487,7 @@ bool SceneTree::idle(float p_time) {
MessageQueue::get_singleton()->flush(); //small little hack
- _flush_transform_notifications();
+ flush_transform_notifications();
_notify_group_pause("idle_process_internal", Node::NOTIFICATION_INTERNAL_PROCESS);
_notify_group_pause("idle_process", Node::NOTIFICATION_PROCESS);
@@ -503,7 +503,7 @@ bool SceneTree::idle(float p_time) {
_flush_ugc();
MessageQueue::get_singleton()->flush(); //small little hack
- _flush_transform_notifications(); //transforms after world update, to avoid unnecessary enter/exit notifications
+ flush_transform_notifications(); //transforms after world update, to avoid unnecessary enter/exit notifications
call_group_flags(GROUP_CALL_REALTIME, "_viewports", "update_worlds");
root_lock--;
diff --git a/scene/main/scene_tree.h b/scene/main/scene_tree.h
index bc3efdc42f..7898dc065a 100644
--- a/scene/main/scene_tree.h
+++ b/scene/main/scene_tree.h
@@ -157,7 +157,6 @@ private:
Map<UGCall, Vector<Variant> > unique_group_calls;
bool ugc_locked;
void _flush_ugc();
- void _flush_transform_notifications();
_FORCE_INLINE_ void _update_group_order(Group &g);
void _update_listener();
@@ -344,6 +343,8 @@ public:
void notify_group(const StringName &p_group, int p_notification);
void set_group(const StringName &p_group, const String &p_name, const Variant &p_value);
+ void flush_transform_notifications();
+
virtual void input_text(const String &p_text);
virtual void input_event(const Ref<InputEvent> &p_event);
virtual void init();