Removed debug

This commit is contained in:
2023-09-19 03:43:56 +03:00
parent 49b11221a6
commit 7201a8c801
4 changed files with 79 additions and 264 deletions

View File

@@ -29,22 +29,8 @@ static void _animation_process(flecs::entity_t entity, flecs::world &ecs,
// static void _node_removed(struct AnimationPlayerData *player,
// Node *p_node);
static void _stop_playing_caches(struct AnimationPlayerData *player);
static void _animation_changed(struct AnimationPlayerData *player);
static void _ref_anim(
struct AnimationPlayerData *player, const Ref<Animation> &p_anim);
static void _unref_anim(
struct AnimationPlayerData *player, const Ref<Animation> &p_anim);
static void _set_process(struct AnimationPlayerData *player, bool p_process,
bool p_force = false);
/* protected functions (need redesign) */
#if 0
bool _set(const StringName &p_name, const Variant &p_value);
bool _get(const StringName &p_name, Variant &r_ret) const;
virtual void _validate_property(PropertyInfo &property) const;
void _get_property_list(List<PropertyInfo> *p_list) const;
void _notification(int p_what);
static void _bind_methods();
#endif
} //namespace ECS
void ECS::play(struct ECS::AnimationPlayerData *player,
const StringName &p_name, float p_custom_blend, float p_custom_scale,
@@ -154,18 +140,9 @@ static void ECS::_ensure_node_caches(struct ECS::AnimationPlayerData *player,
{
// Already cached?
assert(p_anim->animation.is_valid());
flecs::log::trace("cached tracks %d", p_anim->node_cache_size);
flecs::log::trace(
"animation tracks %d", p_anim->animation->get_track_count());
flecs::log::trace("animation %p", p_anim->animation.ptr());
if (p_anim->node_cache_size == p_anim->animation->get_track_count()) {
return;
}
#if 0
Node *parent = p_root_override ? p_root_override : get_node(root);
ERR_FAIL_COND(!parent);
#endif
Animation *a = p_anim->animation.operator->();
@@ -177,13 +154,6 @@ static void ECS::_ensure_node_caches(struct ECS::AnimationPlayerData *player,
Vector<StringName> leftover_path;
/* handle entities here instead */
print_line("TRACK: " + itos(i));
#if 0
Node *child = parent->get_node_and_resource(a->track_get_path(i), resource, leftover_path);
ERR_CONTINUE_MSG(!child, "On Animation: '" + p_anim->name + "', couldn't resolve track: '" + String(a->track_get_path(i)) + "'."); // couldn't find the child node
uint32_t id = resource.is_valid() ? resource->get_instance_id() : child->get_instance_id();
#endif
int bone_idx = -1;
int id = -1; /* supposed to be object id but... */
NodePath np = a->track_get_path(i);
String vpath = np;
print_line("path: " + vpath);
@@ -192,22 +162,7 @@ static void ECS::_ensure_node_caches(struct ECS::AnimationPlayerData *player,
np.get_subname_count() ==
1 /* && Object::cast_to<Skeleton>(child) */) {
/* use entities */
#if 0
Skeleton *sk = Object::cast_to<Skeleton>(child);
bone_idx = sk->find_bone(a->track_get_path(i).get_subname(0));
if (bone_idx == -1) {
continue;
}
#endif
}
#if 0
{
if (!child->is_connected("tree_exiting", this, "_node_removed")) {
child->connect("tree_exiting", this, "_node_removed", make_binds(child), CONNECT_ONESHOT);
}
}
#endif
ECS::TrackNodeCacheKey key;
key.id = entity;
@@ -217,103 +172,63 @@ static void ECS::_ensure_node_caches(struct ECS::AnimationPlayerData *player,
flecs::entity_t bone_id = bone_e.id();
key.bone_idx = bone_id;
String path = np.get_subname(0);
print_line("TRACK: " + itos(i) +
" BONE IDX: " + itos(bone_id) +
" ID: " + itos(entity) + " PATH: " + path);
if (!player->node_cache_map.has(key))
player->node_cache_map[key] = ECS::TrackNodeCache();
p_anim->node_cache[i] = &player->node_cache_map[key];
p_anim->node_cache[i]->path = a->track_get_path(i);
#if 0
p_anim->node_cache[i]->node = child;
#endif
p_anim->node_cache[i]->resource = resource;
#if 0
p_anim->node_cache[i]->node_2d = Object::cast_to<Node2D>(child);
#endif
if (a->track_get_type(i) == Animation::TYPE_TRANSFORM) {
// special cases and caches for transform tracks
#if 0
// cache spatial
p_anim->node_cache[i]->spatial = Object::cast_to<Spatial>(child);
// cache skeleton
p_anim->node_cache[i]->skeleton = Object::cast_to<Skeleton>(child);
#endif
if (true /* || p_anim->node_cache[i]->skeleton */) {
if (a->track_get_path(i).get_subname_count() ==
1) {
StringName bone_name =
a->track_get_path(i)
.get_subname(0);
if (a->track_get_path(i).get_subname_count() == 1) {
StringName bone_name =
a->track_get_path(i).get_subname(0);
/* use entities */
p_anim->node_cache[i]->bone_idx =
key.bone_idx;
#if 0
p_anim->node_cache[i]->bone_idx = p_anim->node_cache[i]->skeleton->find_bone(bone_name);
#endif
#if 0
if (p_anim->node_cache[i]->bone_idx <
0) {
// broken track (nonexistent
// bone)
p_anim->node_cache[i]->skeleton = nullptr;
p_anim->node_cache[i]->spatial = nullptr;
ERR_CONTINUE(
p_anim->node_cache[i]
->bone_idx <
0);
}
} else {
#if 0
// no property, just use spatialnode
p_anim->node_cache[i]->skeleton = nullptr;
#endif
}
#endif
}
/* use entities */
p_anim->node_cache[i]->bone_idx = key.bone_idx;
}
}
#if 0
if (a->track_get_type(i) == Animation::TYPE_VALUE) {
if (!p_anim->node_cache[i]->property_anim.has(
a->track_get_path(i)
.get_concatenated_subnames())) {
TrackNodeCache::PropertyAnim pa;
pa.subpath = leftover_path;
#if 0
pa.object = resource.is_valid() ? (Object *)resource.ptr() : (Object *)child;
#endif
pa.special = SP_NONE;
pa.owner = p_anim->node_cache[i];
p_anim->node_cache[i]->property_anim
[a->track_get_path(i)
.get_concatenated_subnames()] =
pa;
}
#ifdef VALUE_TRACK_SUPPORT
if (a->track_get_type(i) == Animation::TYPE_VALUE) {
if (!p_anim->node_cache[i]->property_anim.has(
a->track_get_path(i)
.get_concatenated_subnames())) {
TrackNodeCache::PropertyAnim pa;
pa.subpath = leftover_path;
pa.object = resource.is_valid()
? (Object *)resource.ptr()
: (Object *)child;
pa.special = SP_NONE;
pa.owner = p_anim->node_cache[i];
p_anim->node_cache[i]->property_anim
[a->track_get_path(i)
.get_concatenated_subnames()] =
pa;
}
if (a->track_get_type(i) == Animation::TYPE_BEZIER &&
leftover_path.size()) {
if (!p_anim->node_cache[i]->bezier_anim.has(
a->track_get_path(i)
.get_concatenated_subnames())) {
TrackNodeCache::BezierAnim ba;
ba.bezier_property = leftover_path;
}
#endif
#ifdef BEZIER_TRACK_SUPPORT
if (a->track_get_type(i) == Animation::TYPE_BEZIER &&
leftover_path.size()) {
if (!p_anim->node_cache[i]->bezier_anim.has(
a->track_get_path(i)
.get_concatenated_subnames())) {
TrackNodeCache::BezierAnim ba;
ba.bezier_property = leftover_path;
#if 0
ba.object = resource.is_valid() ? (Object *)resource.ptr() : (Object *)child;
#endif
ba.owner = p_anim->node_cache[i];
ba.owner = p_anim->node_cache[i];
p_anim->node_cache[i]->bezier_anim
[a->track_get_path(i)
.get_concatenated_subnames()] =
ba;
}
#endif
p_anim->node_cache[i]->bezier_anim
[a->track_get_path(i)
.get_concatenated_subnames()] =
ba;
}
}
#endif
}
}
static void ECS::_animation_process_animation(flecs::entity_t entity,
@@ -326,9 +241,6 @@ static void ECS::_animation_process_animation(flecs::entity_t entity,
p_anim->animation->get_track_count());
Animation *a = p_anim->animation.ptr();
#if 0
bool can_call = is_inside_tree() && !Engine::get_singleton()->is_editor_hint();
#endif
for (int i = 0; i < a->get_track_count(); i++) {
// If an animation changes this animation (or it
@@ -349,18 +261,11 @@ static void ECS::_animation_process_animation(flecs::entity_t entity,
continue; // do nothing if the track is
// disabled
}
flecs::log::trace("track keys: %d", i);
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)) {
case Animation::TYPE_TRANSFORM: {
#if 0
if (!nc->spatial) {
continue;
}
#endif
Vector3 loc;
Quat rot;
Vector3 scale;
@@ -370,9 +275,8 @@ static void ECS::_animation_process_animation(flecs::entity_t entity,
//ERR_CONTINUE(err!=OK); //used for
//testing, should be removed
if (err != OK) {
if (err != OK)
continue;
}
if (nc->accum_pass != player->accum_pass) {
ERR_CONTINUE(
@@ -385,9 +289,6 @@ static void ECS::_animation_process_animation(flecs::entity_t entity,
nc->loc_accum = loc;
nc->rot_accum = rot;
nc->scale_accum = scale;
print_line("cache update: " +
itos(nc->bone_idx));
} else {
nc->loc_accum =
nc->loc_accum
@@ -400,17 +301,11 @@ static void ECS::_animation_process_animation(flecs::entity_t entity,
.linear_interpolate(
scale,
p_interp);
print_line("cache update2: " +
itos(nc->bone_idx));
}
} break;
case Animation::TYPE_VALUE: {
#if 0
if (!nc->node) {
continue;
}
#endif
#ifdef VALUE_TRACK_SUPPORT
//StringName
//property=a->track_get_path(i).get_property();
@@ -608,8 +503,10 @@ static void ECS::_animation_process_animation(flecs::entity_t entity,
}
}
#endif
} break;
case Animation::TYPE_METHOD: {
#ifdef METHOD_TRACK_SUPPORT
#if 0
if (!nc->node) {
continue;
@@ -683,8 +580,10 @@ static void ECS::_animation_process_animation(flecs::entity_t entity,
#endif
}
#endif
} break;
case Animation::TYPE_BEZIER: {
#ifdef BEZIER_TRACK_SUPPORT
#if 0
if (!nc->node) {
continue;
@@ -717,9 +616,13 @@ static void ECS::_animation_process_animation(flecs::entity_t entity,
bezier, p_interp);
}
#endif
} break;
case Animation::TYPE_AUDIO: {
#ifndef AUDIO_TRACK_SUPPORT
/* Convert audio support to "server" */
/* This requires node to be audio
* source? */
#if 0
if (!nc->node) {
continue;
@@ -888,11 +791,12 @@ static void ECS::_animation_process_animation(flecs::entity_t entity,
}
}
}
#endif
} break;
case Animation::TYPE_ANIMATION: {
/* animations of animations - need
* rework */
#if 0
/* animations of animations - need
* rework */
#if 0
AnimationPlayer *player = Object::cast_to<AnimationPlayer>(nc->node);
if (!player) {
@@ -954,6 +858,7 @@ static void ECS::_animation_process_animation(flecs::entity_t entity,
}
}
}
#endif
#endif
} break;
}
@@ -971,7 +876,6 @@ static void ECS::_animation_process_data(flecs::entity_t entity,
return;
}
assert(cd.from->animation.is_valid());
flecs::log::trace("animation %p", cd.from->animation.ptr());
float len = cd.from->animation->get_length();
bool loop = cd.from->animation->has_loop();
if (!loop) {
@@ -1025,8 +929,6 @@ static void ECS::_animation_process2(flecs::entity_t entity, flecs::world &ecs,
ERR_PRINT("bad animation2");
return;
}
flecs::log::trace("length: %d",
player->playback.current.from->animation->get_length());
_animation_process_data(entity, ecs, player, c.current, p_delta, 1.0f,
c.seeked && p_delta != 0, p_started);
if (p_delta != 0)
@@ -1069,19 +971,11 @@ static void ECS::_animation_update_transforms(flecs::entity_t entity,
bone_entity.get_mut<ECS::BonePose>();
bone->pose = t;
bone_entity.modified<ECS::BonePose>();
flecs::log::err("good bone %d", nc->bone_idx);
} else
flecs::log::err("bad bone %d", nc->bone_idx);
#if 0
/* update transform on skeleton or node */
if (nc->skeleton && nc->bone_idx >= 0)
nc->skeleton->set_bone_pose(nc->bone_idx, t);
else if (nc->spatial)
nc->spatial->set_transform(t);
#endif
}
}
}
player->cache_update_size = 0;
#ifdef VALUE_TRACK_SUPPORT
for (i = 0; i < player->cache_update_prop_size; i++) {
TrackNodeCache::PropertyAnim *pa =
player->cache_update_prop[i];
@@ -1120,12 +1014,15 @@ static void ECS::_animation_update_transforms(flecs::entity_t entity,
break;
}
}
#endif
player->cache_update_prop_size = 0;
#ifdef BEZIER_TRACK_SUPPORT
for (i = 0; i < player->cache_update_bezier_size; i++) {
TrackNodeCache::BezierAnim *ba =
player->cache_update_bezier[i];
ba->object->set_indexed(ba->bezier_property, ba->bezier_accum);
}
#endif
player->cache_update_bezier_size = 0;
}
static void ECS::_set_process(
@@ -1170,20 +1067,6 @@ static void ECS::_animation_process(flecs::entity_t entity, flecs::world &ecs,
}
void ECS::_stop_playing_caches(struct ECS::AnimationPlayerData *player)
{
#if 0
for (Set<TrackNodeCache *>::Element *E = player->playing_caches.front(); E; E = E->next()) {
if (E->get()->node && E->get()->audio_playing) {
E->get()->node->call("stop");
}
if (E->get()->node && E->get()->animation_playing) {
AnimationPlayer *player = Object::cast_to<AnimationPlayer>(E->get()->node);
if (!player) {
continue;
}
player->stop();
}
}
#endif
player->playing_caches.clear();
}
@@ -1213,11 +1096,8 @@ Error ECS::add_animation(struct ECS::AnimationPlayerData *player,
const StringName &p_name, const Ref<Animation> &p_animation)
{
ERR_FAIL_COND_V(p_animation.is_null(), ERR_INVALID_PARAMETER);
print_line("animation name: " + p_name);
print_line("animation length: " + itos(p_animation->get_length()));
if (player->animation_set.has(p_name)) {
_unref_anim(player, player->animation_set[p_name].animation);
player->animation_set[p_name].animation = p_animation;
clear_caches(player);
} else {
@@ -1228,7 +1108,6 @@ Error ECS::add_animation(struct ECS::AnimationPlayerData *player,
player->animation_set[p_name].animation = p_animation;
}
_ref_anim(player, p_animation);
return OK;
}
void ECS::remove_animation(
@@ -1236,26 +1115,11 @@ void ECS::remove_animation(
{
ERR_FAIL_COND(!player->animation_set.has(p_name));
#if 0
stop();
#endif
#if 0
_unref_anim(player, player->animation_set[p_name].animation);
#endif
stop(player);
player->animation_set.erase(p_name);
clear_caches(player);
}
static void ECS::_ref_anim(
struct ECS::AnimationPlayerData *player, const Ref<Animation> &p_anim)
{
}
static void ECS::_unref_anim(
struct ECS::AnimationPlayerData *player, const Ref<Animation> &p_anim)
{
}
void ECS::clear_caches(struct ECS::AnimationPlayerData *player)
{
_stop_playing_caches(player);
@@ -1272,11 +1136,19 @@ void ECS::clear_caches(struct ECS::AnimationPlayerData *player)
void ECS::advance(flecs::entity_t entity, flecs::world &ecs,
ECS::AnimationPlayerData *player, float p_time)
{
if (player->playback.current.from) {
flecs::log::trace("length: %f",
player->playback.current.from->animation
->get_length());
}
ECS::_animation_process(entity, ecs, player, p_time);
player->playback.current.from = nullptr;
}
void ECS::stop(struct ECS::AnimationPlayerData *player, bool p_reset)
{
_stop_playing_caches(player);
Playback &c = player->playback;
c.blend.clear();
if (p_reset) {
c.current.from = nullptr;
c.current.speed_scale = 1.0f;
c.current.pos = 0.0f;
}
_set_process(player, false);
player->queued.clear();
}

View File

@@ -186,9 +186,9 @@ struct BasicTrack : public Track {
struct AnimationData {
String name;
StringName next;
Ref<Animation> animation;
int node_cache_size;
struct TrackNodeCache *node_cache[128];
Ref<Animation> animation;
AnimationData(Ref<Animation> anim) :
animation(anim), node_cache_size(0)
{

View File

@@ -123,7 +123,6 @@ int Character::create_character(int id)
.set<ECS::BonePose>({ index, Transform() });
}
for (i = 0; i < scene_data[id].meshes.size(); i++) {
// flecs::log::trace("creating slot -");
ecs.entity(scene_data[id]
.meshes[i]
.slot_name.ascii()
@@ -133,9 +132,7 @@ int Character::create_character(int id)
scene_data[id].meshes[i].mesh,
scene_data[id].meshes[i].skin);
}
// print_line("character created");
int xid = entities.size();
// print_line(itos(xid) + ":" + itos(root.id()));
entities[xid] = root.id();
return xid;
}
@@ -296,8 +293,6 @@ void Character::init_bone()
{
ecs.component<ECS::BoneComponent>()
.on_add([](flecs::entity e, ECS::BoneComponent &s) {
// flecs::log::trace("added bonecomponent %s",
// e.name().c_str());
flecs::entity parent = e.parent();
parent.add<ECS::Dirty>();
if (parent.has<ECS::Bound>()) {
@@ -323,25 +318,12 @@ void Character::init_bone()
skel->dirty = true;
String out;
VariantWriter::write_to_string(s.rest, out);
// flecs::log::trace("bonecomponent set %s (%d) [%s]",
// e.name().c_str(), skel->bone_count,
// out.ascii().get_data());
parent.remove<ECS::SkeletonOrderPrepared>();
parent.add<ECS::Dirty>();
});
ecs.component<ECS::BonePose>()
.on_add([](flecs::entity e, ECS::BonePose &s) {
// flecs::log::trace("added
//bonepose %s", e.name().c_str());
})
.on_add([](flecs::entity e, ECS::BonePose &s) {})
.on_set([](flecs::entity e, ECS::BonePose &s) {
#if 0
const Transform &xform = s.pose;
String out;
VariantWriter::write_to_string(xform, out);
flecs::log::trace("bone pose set %s: %d %s",
e.name().c_str(), s.index, out.ascii().get_data());
#endif
e.add<ECS::Dirty>();
});
ecs.system<ECS::BonePose, ECS::Dirty>()
@@ -363,8 +345,6 @@ void Character::init_bone()
skel->dirty = true;
String out;
VariantWriter::write_to_string(s.pose, out);
// flecs::log::trace("set bonepose %s %d %s",
// e.name().c_str(), s.index, out.ascii().get_data());
parent.modified<ECS::Skeleton>();
parent.add<ECS::Dirty>();
parent.remove<ECS::SkeletonTransformReady>();
@@ -374,14 +354,12 @@ void Character::init_bone()
void Character::animation_system_init()
{
ecs.component<ECS::AnimationPlayerData>().on_set(
[](flecs::entity e, ECS::AnimationPlayerData &s) {
flecs::log::trace("created animation player");
});
[](flecs::entity e, ECS::AnimationPlayerData &s) {});
ecs.system<ECS::AnimationPlayerData>("UpdateAnimation")
.kind(flecs::OnUpdate)
.each([](flecs::entity e, ECS::AnimationPlayerData &player) {
if (!player.playing)
ECS::play(&player, "stand1-loop");
ECS::play(&player, "male-mx-walk-loop");
flecs::world w = e.world();
ECS::advance(e.id(), w, &player,
SceneTree::get_singleton()
@@ -420,24 +398,7 @@ void Character::initialize()
if (err == OK && scene2.is_valid())
set_scene(1, scene2);
initialized = true;
ecs.system<ECS::Skeleton>("UpdateBone")
.with<ECS::Bound>()
.kind(flecs::OnUpdate)
.each([](flecs::entity e, ECS::Skeleton &sk) {
flecs::entity root = e.lookup("Root");
if (!root.is_valid() || !root.is_alive())
return;
if (!root.has<ECS::BonePose>())
return;
float delta = SceneTree::get_singleton()
->get_physics_process_time();
struct ECS::BonePose *bp =
root.get_mut<ECS::BonePose>();
// bp->pose.basis =
//bp->pose.basis.rotated(Vector3(0, 1, 0), 0.016f);
bp->pose.origin += Vector3(0.2f * delta, 0.0f, 0.0f);
root.modified<ECS::BonePose>();
});
animation_system_init();
if (!Engine::get_singleton()->is_editor_hint()) {
err = st->connect("physics_frame", this, "_progress");

View File

@@ -25,15 +25,9 @@ void Character::init_slot()
vs->instance_set_base(s.instance, RID());
vs->free(s.instance);
s.instance = RID();
// print_line("mesh
//instance slot removed " + s.name);
}
// flecs::log::trace("removed slot
//%s", e.name().c_str());
})
.on_set([st](flecs::entity e, ECS::CharacterSlot &s) {
// flecs::log::trace("set slot
//%s", e.name().c_str());
if (s.mesh.is_null() || !s.mesh.is_valid())
flecs::log::err(
"invalid mesh %s", e.name().c_str());
@@ -55,8 +49,6 @@ void Character::init_slot()
slot.instance, scenario);
vs->instance_set_base(
slot.instance, slot.mesh->get_rid());
// flecs::log::trace("created
//instance for %s", e.name().c_str());
}
});
ecs.system<ECS::CharacterSlot>("AttachToSkeleton")
@@ -73,8 +65,6 @@ void Character::init_slot()
const ECS::Skeleton *skel =
parent.get<ECS::Skeleton>();
assert(skel->skeleton.is_valid());
// flecs::log::trace("binding slot
//for %s", e.name().c_str());
if (skel->skeleton.is_valid())
slot.skeleton = skel->skeleton;
if (slot.skin.is_null() && !skel->skin.is_null())
@@ -90,8 +80,6 @@ void Character::init_slot()
slot.bound = true;
e.add<ECS::Bound>();
parent.add<ECS::Bound>();
// flecs::log::trace("bound
//slot for %s", e.name().c_str());
}
});
ecs.system<ECS::CharacterSlot>("BindSlotsToSkeleton")
@@ -111,14 +99,10 @@ void Character::init_slot()
const struct ECS::Skeleton::bone_data
*bonesptr = skel->bones.ptr();
const int *order = skel->process_order.ptr();
// flecs::log::trace("binding
//slot for %s", e.name().c_str());
slot.skin_internal.instance();
slot.skin_internal->set_bind_count(
skel->bones.size());
int len = skel->bones.size();
// flecs::log::trace("creating
//skin for %s", e.name().c_str());
for (i = 0; i < len; i++) {
const struct ECS::Skeleton::bone_data
&b = bonesptr[order[i]];
@@ -143,8 +127,6 @@ void Character::init_slot()
.affine_inverse());
}
skel->skin = slot.skin_internal;
// flecs::log::trace("created
//skin for %s: %d", e.name().c_str(), len);
assert(skel->skeleton.is_valid());
skel->skin = slot.skin_internal;
uint32_t bind_count =