From 0a2a390dcee5bf004e563373ee04c2d72c887010 Mon Sep 17 00:00:00 2001 From: Sergey Lapin Date: Sat, 23 Sep 2023 10:34:25 +0300 Subject: [PATCH] Started animation tree --- src/modules/character/animation_system.h | 130 ++---------------- .../character/animation_system_tree.cpp | 8 ++ src/modules/character/animation_system_tree.h | 13 ++ src/modules/character/character.h | 16 +-- 4 files changed, 35 insertions(+), 132 deletions(-) create mode 100644 src/modules/character/animation_system_tree.cpp create mode 100644 src/modules/character/animation_system_tree.h diff --git a/src/modules/character/animation_system.h b/src/modules/character/animation_system.h index 0fab9e3..1fe3659 100644 --- a/src/modules/character/animation_system.h +++ b/src/modules/character/animation_system.h @@ -1,8 +1,10 @@ #ifndef ANIMATION_SYSTEM_H #define ANIMATION_SYSTEM_H + +class AnimationNode; + namespace ECS { struct AnimationPlayer; -struct AnimationTreee; enum AnimationProcessMode { ANIMATION_PROCESS_PHYSICS, ANIMATION_PROCESS_IDLE, @@ -23,12 +25,6 @@ struct TrackNodeCache { NodePath path; flecs::entity_t id; Ref resource; -#if 0 - Node *node; - Spatial *spatial; - Node2D *node_2d; - Skeleton *skeleton; -#endif flecs::entity_t bone_idx; // accumulated transforms Vector3 loc_accum; @@ -39,51 +35,9 @@ struct TrackNodeCache { float audio_start; float audio_len; bool animation_playing; -#if 0 - struct PropertyAnim { - TrackNodeCache *owner; - SpecialProperty special; - Vector subpath; - Object *object; - Variant value_accum; - uint64_t accum_pass; - Variant capture; - PropertyAnim() : - owner(nullptr), - special(SP_NONE), - object(nullptr), - accum_pass(0) - { - } - }; - Map property_anim; -#endif -#if 0 - struct BezierAnim { - Vector bezier_property; - TrackNodeCache *owner; - float bezier_accum; - Object *object; - uint64_t accum_pass; - - BezierAnim() : - owner(nullptr), - bezier_accum(0.0), - object(nullptr), - accum_pass(0) - { - } - }; - Map bezier_anim; -#endif TrackNodeCache() : - used(false), id(-1), -#if 0 - node(nullptr), - spatial(nullptr), - node_2d(nullptr), - skeleton(nullptr), -#endif + used(false), + id(-1), bone_idx(-1), accum_pass(0), audio_playing(false), @@ -199,10 +153,7 @@ struct AnimationData { assert(animation); animation = anim; } - AnimationData() : - animation(nullptr), node_cache_size(0) - { - } + AnimationData() : animation(nullptr), node_cache_size(0) {} AnimationData(const AnimationData &d) { int i; @@ -236,10 +187,7 @@ struct AnimationData { memnew_placement(this, AnimationData(d)); return *this; } - const Animation *get_animation() const - { - return animation; - } + const Animation *get_animation() const { return animation; } ~AnimationData() { animation = nullptr; } @@ -305,12 +253,6 @@ struct AnimationPlayerData { TrackNodeCache *cache_update[NODE_CACHE_UPDATE_MAX]; int cache_update_size; -#if 0 - TrackNodeCache::PropertyAnim *cache_update_prop[NODE_CACHE_UPDATE_MAX]; - int cache_update_prop_size; - TrackNodeCache::BezierAnim *cache_update_bezier[NODE_CACHE_UPDATE_MAX]; - int cache_update_bezier_size; -#endif Set playing_caches; uint64_t accum_pass; float speed_scale; @@ -327,9 +269,6 @@ struct AnimationPlayerData { AnimationProcessMode animation_process_mode; bool processing; bool active; -#if 0 - NodePath root; -#endif bool playing; AnimationPlayerData(int id) { @@ -380,29 +319,6 @@ struct AnimationPlayerData { AnimationPlayerData(AnimationPlayerData &&d) { memnew_placement(this, AnimationPlayerData(d)); -#if 0 - int i; - node_cache_map = d.node_cache_map; - for (i = 0; i < NODE_CACHE_UPDATE_MAX; i++) - cache_update[i] = d.cache_update[i]; - cache_update_size = d.cache_update_size; - playing_caches = d.playing_caches; - accum_pass = d.accum_pass; - speed_scale = d.speed_scale; - default_blend_time = d.default_blend_time; - animation_set = d.animation_set; - blend_times = d.blend_times; - playback = d.playback; - queued = d.queued; - end_reached = d.end_reached; - end_notify = d.end_notify; - autoplay = d.autoplay; - reset_on_save = d.reset_on_save; - animation_process_mode = d.animation_process_mode; - processing = d.processing; - active = d.active; - playing = d.playing; -#endif d.playing = playing; d.cache_update_size = 0; d.active = false; @@ -410,29 +326,6 @@ struct AnimationPlayerData { AnimationPlayerData &operator=(const AnimationPlayerData &d) { memnew_placement(this, AnimationPlayerData(d)); -#if 0 - int i; - node_cache_map = d.node_cache_map; - for (i = 0; i < NODE_CACHE_UPDATE_MAX; i++) - cache_update[i] = d.cache_update[i]; - cache_update_size = d.cache_update_size; - playing_caches = d.playing_caches; - accum_pass = d.accum_pass; - speed_scale = d.speed_scale; - default_blend_time = d.default_blend_time; - animation_set = d.animation_set; - blend_times = d.blend_times; - playback = d.playback; - queued = d.queued; - end_reached = d.end_reached; - end_notify = d.end_notify; - autoplay = d.autoplay; - reset_on_save = d.reset_on_save; - animation_process_mode = d.animation_process_mode; - processing = d.processing; - active = d.active; - playing = d.playing; -#endif return *this; } AnimationPlayerData &operator=(AnimationPlayerData &&d) @@ -464,11 +357,13 @@ struct AnimationPlayerData { } ~AnimationPlayerData() { playing = false; } }; +/* AnimationPlayer */ /* public functions */ StringName find_animation( struct AnimationPlayerData *player, const Ref &p_animation); -Error add_animation(flecs::entity_t entity, flecs::world &ecs, struct AnimationPlayerData *player, - const StringName &p_name, const Animation *p_animation); +Error add_animation(flecs::entity_t entity, flecs::world &ecs, + struct AnimationPlayerData *player, const StringName &p_name, + const Animation *p_animation); void remove_animation(flecs::entity_t entity, flecs::world &ecs, struct AnimationPlayerData *player, const StringName &p_name); void rename_animation(struct AnimationPlayerData *player, @@ -537,7 +432,8 @@ void advance(flecs::entity_t entity, flecs::world &ecs, AnimationPlayerData *player, float p_time); void set_root(struct AnimationPlayerData *player, const NodePath &p_root); NodePath get_root(struct AnimationPlayerData *player); -void clear_caches(flecs::entity_t entity, flecs::world &ecs, struct AnimationPlayerData *player); +void clear_caches(flecs::entity_t entity, flecs::world &ecs, + struct AnimationPlayerData *player); void get_argument_options(struct AnimationPlayerData *player, const StringName &p_function, int p_idx, List *r_options); } //namespace ECS diff --git a/src/modules/character/animation_system_tree.cpp b/src/modules/character/animation_system_tree.cpp new file mode 100644 index 0000000..9de9a01 --- /dev/null +++ b/src/modules/character/animation_system_tree.cpp @@ -0,0 +1,8 @@ +#include +#include +#include +#include + +#include + +#include "animation_system_tree.h" diff --git a/src/modules/character/animation_system_tree.h b/src/modules/character/animation_system_tree.h new file mode 100644 index 0000000..4c84ded --- /dev/null +++ b/src/modules/character/animation_system_tree.h @@ -0,0 +1,13 @@ +#ifndef ANIMATION_SYSTEM_TREE +#define ANIMATION_SYSTEM_TREE +struct AnimationTree { + HashMap track_cache_map; + TrackCache track_cache_data[NODE_CACHE_UPDATE_MAX]; + Set playing_caches; + Ref root; + + AnimationProcessMode process_mode; + bool active; + NodePath animation_player; +}; +#endif diff --git a/src/modules/character/character.h b/src/modules/character/character.h index eb48bec..eebbac1 100644 --- a/src/modules/character/character.h +++ b/src/modules/character/character.h @@ -23,11 +23,7 @@ struct Skeleton { int parent; bool disable_rest; bool custom_pose_enable; - Transform - custom_pose, - rest, - pose, - pose_global, + Transform custom_pose, rest, pose, pose_global, pose_global_no_override; int sort_index; }; @@ -55,16 +51,6 @@ struct BonePose { int index; Transform pose; }; -struct AnimationTree { - void *root; - AnimationTree() : - root(nullptr) - { - } - ~AnimationTree() - { - } -}; struct CharacterSlot { String name; RID instance;