From b9be14800d8cd9e9160b46864c4b283597e0305e Mon Sep 17 00:00:00 2001 From: Sergey Lapin Date: Fri, 15 Sep 2023 22:14:02 +0300 Subject: [PATCH] Update indentation --- src/modules/.clang-format | 22 ++- src/modules/character/animation_system.h | 4 +- src/modules/character/character.cpp | 155 +++++++++++-------- src/modules/character/character_skeleton.cpp | 143 ++++++++++++----- src/modules/character/character_slot.cpp | 154 ++++++++++++------ src/modules/character/register_types.cpp | 8 +- 6 files changed, 327 insertions(+), 159 deletions(-) diff --git a/src/modules/.clang-format b/src/modules/.clang-format index 0b244c7..117d21f 100644 --- a/src/modules/.clang-format +++ b/src/modules/.clang-format @@ -60,7 +60,7 @@ BreakBeforeBraces: Custom # BreakConstructorInitializersBeforeComma: false BreakConstructorInitializers: AfterColon # BreakStringLiterals: true -ColumnLimit: 0 +ColumnLimit: 79 # CommentPragmas: '^ IWYU pragma:' # CompactNamespaces: false ConstructorInitializerAllOnOneLineOrOnePerLine: true @@ -80,15 +80,23 @@ Cpp11BracedListStyle: false # - BOOST_FOREACH # IfMacros: # - KJ_IF_MAYBE -# IncludeBlocks: Preserve +IncludeBlocks: Preserve IncludeCategories: - - Regex: '".*"' - Priority: 1 + - Regex: '^<([A-Za-z0-9\/-_])+>' + Priority: -6 + - Regex: '^<[\w]+>' + Priority: -6 + - Regex: '^<(core|scene)/.*\.h>' + Priority: -5 - Regex: '^<.*\.h>' - Priority: 2 + Priority: -2 - Regex: '^<.*' - Priority: 3 -# IncludeIsMainRegex: '(Test)?$' + Priority: -2 + - Regex: '".*"' + Priority: -1 + - Regex: '.*' + Priority: 1 +IncludeIsMainRegex: '(Test)?$' # IncludeIsMainSourceRegex: '' # IndentAccessModifiers: false IndentCaseLabels: true diff --git a/src/modules/character/animation_system.h b/src/modules/character/animation_system.h index d5d6924..c037b90 100644 --- a/src/modules/character/animation_system.h +++ b/src/modules/character/animation_system.h @@ -21,7 +21,7 @@ enum SpecialProperty { struct TrackNodeCache { NodePath path; uint32_t id; - RES resource; + Ref resource; #if 0 Node *node; Spatial *spatial; @@ -170,7 +170,9 @@ struct AnimationPlayerData { AnimationMethodCallMode method_call_mode; bool processing; bool active; +#if 0 NodePath root; +#endif bool playing; }; /* public functions */ diff --git a/src/modules/character/character.cpp b/src/modules/character/character.cpp index 1aec03c..7a749b3 100644 --- a/src/modules/character/character.cpp +++ b/src/modules/character/character.cpp @@ -1,10 +1,9 @@ -#include "character.h" -#include "animation_system.h" -#include "skeleton-prep.h" +/* vim: set tabstop=8:softtabstop=8:shiftwidth=8:noexpandtab */ +#include +#include #include #include #include -#include #include #include #include @@ -15,7 +14,12 @@ #include #include #include -#include + +#include +#include "animation_system.h" +#include "skeleton-prep.h" + +#include "character.h" namespace ECS { Skeleton::Skeleton() @@ -25,9 +29,7 @@ Skeleton::Skeleton() dirty = true; process_order_dirty = true; } -Skeleton::~Skeleton() -{ -} +Skeleton::~Skeleton() {} } //namespace ECS ECS::RigidBody::RigidBody(RID rid, enum type type) @@ -36,9 +38,7 @@ ECS::RigidBody::RigidBody(RID rid, enum type type) this->type = type; } -ECS::RigidBody::~RigidBody() -{ -} +ECS::RigidBody::~RigidBody() {} ECS::CShape::CShape(RID body, const Transform &offset, Ref shape) { @@ -48,10 +48,7 @@ ECS::CShape::CShape(RID body, const Transform &offset, Ref shape) ps->body_add_shape(body, shape->get_rid(), offset, false); } -ECS::CShape::~CShape() -{ - shape = Ref(nullptr); -} +ECS::CShape::~CShape() { shape = Ref(nullptr); } ECS::CharacterSlot::CharacterSlot(Ref mesh, Ref skin) { @@ -62,7 +59,8 @@ ECS::CharacterSlot::CharacterSlot(Ref mesh, Ref skin) this->bound = false; } -ECS::BoneComponent::BoneComponent(int index, int parent_index, const Transform &rest) +ECS::BoneComponent::BoneComponent( + int index, int parent_index, const Transform &rest) { this->index = index; this->parent_index = parent_index; @@ -94,11 +92,13 @@ int Character::create_character(int id) List anim_list; scene_data[id].animations.get_key_list(&anim_list); List::Element *e = anim_list.front(); - ECS::AnimationPlayerData *player = root.get_mut(); + ECS::AnimationPlayerData *player = + root.get_mut(); while (e) { - ECS::add_animation(player, e->get(), - scene_data[id].animations[e->get()]); - flecs::log::trace("added animation %s", String(e->get()).ascii().get_data()); + ECS::add_animation( + player, e->get(), scene_data[id].animations[e->get()]); + flecs::log::trace("added animation %s", + String(e->get()).ascii().get_data()); e = e->next(); } root.modified(); @@ -110,9 +110,9 @@ int Character::create_character(int id) root.modified(); print_line("body created for root"); for (i = 0; i < scene_data[id].shapes.size(); i++) { - ecs.entity() - .child_of(root) - .emplace(body, scene_data[id].shapes[i].offset, scene_data[id].shapes[i].shape); + ecs.entity().child_of(root).emplace(body, + scene_data[id].shapes[i].offset, + scene_data[id].shapes[i].shape); } for (i = 0; i < scene_data[id].bones.size(); i++) { int index = i, parent_index = scene_data[id].bones[i].parent; @@ -124,10 +124,15 @@ int Character::create_character(int id) } for (i = 0; i < scene_data[id].meshes.size(); i++) { // flecs::log::trace("creating slot -"); - flecs::entity entity = ecs.entity(scene_data[id].meshes[i].slot_name.ascii().get_data()) - .child_of(root) - .emplace(scene_data[id].meshes[i].mesh, - scene_data[id].meshes[i].skin); + flecs::entity entity = + ecs.entity(scene_data[id] + .meshes[i] + .slot_name.ascii() + .get_data()) + .child_of(root) + .emplace( + scene_data[id].meshes[i].mesh, + scene_data[id].meshes[i].skin); } // print_line("character created"); int xid = entities.size(); @@ -232,8 +237,10 @@ void Character::set_scene(int id, const Ref &scene) List::Element *e = anim_list.front(); while (e) { StringName anim_name = e->get(); - Ref animation = anim->get_animation(anim_name); - scene_data[id].animations[anim_name] = animation; + Ref animation = + anim->get_animation(anim_name); + scene_data[id].animations[anim_name] = + animation; e = e->next(); } } @@ -242,20 +249,28 @@ void Character::set_scene(int id, const Ref &scene) int bone_count = skel->get_bone_count(); scene_data[id].bones.resize(bone_count); for (i = 0; i < bone_count; i++) { - scene_data[id].bones.write[i].name = skel->get_bone_name(i); + scene_data[id].bones.write[i].name = + skel->get_bone_name(i); scene_data[id].bones.write[i].index = i; - scene_data[id].bones.write[i].parent = skel->get_bone_parent(i); - scene_data[id].bones.write[i].rest = skel->get_bone_rest(i); - // print_line("added bone: " + scene_data[id].bones.write[i].name + " " + itos(i)); + scene_data[id].bones.write[i].parent = + skel->get_bone_parent(i); + scene_data[id].bones.write[i].rest = + skel->get_bone_rest(i); + // print_line("added + //bone: " + scene_data[id].bones.write[i].name + //+ " " + itos(i)); } } for (i = 0; i < tmp->get_child_count(); i++) queue.push_back(tmp->get_child(i)); } memdelete(node); - print_line("meshes loaded: " + itos(id) + " " + itos(scene_data[id].meshes.size())); - print_line("shapes loaded: " + itos(id) + " " + itos(scene_data[id].shapes.size())); - print_line("animations loaded: " + itos(id) + " " + itos(scene_data[id].animations.size())); + print_line("meshes loaded: " + itos(id) + " " + + itos(scene_data[id].meshes.size())); + print_line("shapes loaded: " + itos(id) + " " + + itos(scene_data[id].shapes.size())); + print_line("animations loaded: " + itos(id) + " " + + itos(scene_data[id].animations.size())); } Ref Character::get_scene(int id) const { @@ -272,15 +287,18 @@ Character::Character() void Character::_bind_methods() { ClassDB::bind_method(D_METHOD("__initialize"), &Character::initialize); - ClassDB::bind_method(D_METHOD("create_character", "id"), &Character::create_character); - ClassDB::bind_method(D_METHOD("destroy_character", "id"), &Character::destroy_character); + ClassDB::bind_method(D_METHOD("create_character", "id"), + &Character::create_character); + ClassDB::bind_method(D_METHOD("destroy_character", "id"), + &Character::destroy_character); ClassDB::bind_method(D_METHOD("_progress"), &Character::progress); } void Character::init_bone() { ecs.component() .on_add([](flecs::entity e, ECS::BoneComponent &s) { - // flecs::log::trace("added bonecomponent %s", e.name().c_str()); + // flecs::log::trace("added bonecomponent %s", + // e.name().c_str()); flecs::entity parent = e.parent(); parent.add(); if (parent.has()) { @@ -306,13 +324,16 @@ 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()); + // flecs::log::trace("bonecomponent set %s (%d) [%s]", + // e.name().c_str(), skel->bone_count, + // out.ascii().get_data()); parent.remove(); parent.add(); }); ecs.component() .on_add([](flecs::entity e, ECS::BonePose &s) { - // flecs::log::trace("added bonepose %s", e.name().c_str()); + // flecs::log::trace("added + //bonepose %s", e.name().c_str()); }) .on_set([](flecs::entity e, ECS::BonePose &s) { #if 0 @@ -330,7 +351,8 @@ void Character::init_bone() .with() .parent() .kind(flecs::OnUpdate) - .each([this](flecs::entity e, ECS::BonePose &s, const ECS::Dirty &d) { + .each([this](flecs::entity e, ECS::BonePose &s, + const ECS::Dirty &d) { flecs::entity parent = e.parent(); /* Don't update unbound skeleton */ if (!parent.has()) { @@ -342,7 +364,8 @@ 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()); + // flecs::log::trace("set bonepose %s %d %s", + // e.name().c_str(), s.index, out.ascii().get_data()); parent.modified(); parent.add(); parent.remove(); @@ -351,8 +374,8 @@ void Character::init_bone() } void Character::animation_system_init() { - ecs.component() - .on_set([](flecs::entity e, ECS::AnimationPlayerData &s) { + ecs.component().on_set( + [](flecs::entity e, ECS::AnimationPlayerData &s) { flecs::log::trace("created animation player"); }); ecs.system("UpdateAnimation") @@ -360,7 +383,9 @@ void Character::animation_system_init() .each([](flecs::entity e, ECS::AnimationPlayerData &player) { if (!player.playing) ECS::play(&player, "stand1-loop"); - ECS::advance(&player, SceneTree::get_singleton()->get_physics_process_time()); + ECS::advance(&player, + SceneTree::get_singleton() + ->get_physics_process_time()); }); } void Character::initialize() @@ -370,25 +395,28 @@ void Character::initialize() SceneTree *st = SceneTree::get_singleton(); ecs.import (); init_skeleton(); - ecs.component() - .on_add([](flecs::entity e, ECS::MetaData &s) { - flecs::log::trace("added metadata %s", e.name().c_str()); - }); + ecs.component().on_add([](flecs::entity e, + ECS::MetaData &s) { + flecs::log::trace("added metadata %s", e.name().c_str()); + }); init_bone(); init_slot(); - ecs.component() - .on_add([](flecs::entity e, ECS::AnimationTree &s) { - flecs::log::trace("animationtree slot %s", e.name().c_str()); - }); - ecs.component() - .on_add([](flecs::entity e, ECS::RigidBody &s) { - flecs::log::trace("added rigidbody %s", e.name().c_str()); + ecs.component().on_add( + [](flecs::entity e, ECS::AnimationTree &s) { + flecs::log::trace( + "animationtree slot %s", e.name().c_str()); }); + ecs.component().on_add([](flecs::entity e, + ECS::RigidBody &s) { + flecs::log::trace("added rigidbody %s", e.name().c_str()); + }); const String path = "res://characters/"; - Ref scene1 = ResourceLoader::load(path + "male-base.tscn", "PackedScene", true, &err); + Ref scene1 = ResourceLoader::load( + path + "male-base.tscn", "PackedScene", true, &err); if (err == OK && scene1.is_valid()) set_scene(0, scene1); - Ref scene2 = ResourceLoader::load(path + "female-base.tscn", "PackedScene", true, &err); + Ref scene2 = ResourceLoader::load( + path + "female-base.tscn", "PackedScene", true, &err); if (err == OK && scene2.is_valid()) set_scene(1, scene2); initialized = true; @@ -401,9 +429,12 @@ void Character::initialize() return; if (!root.has()) return; - float delta = SceneTree::get_singleton()->get_physics_process_time(); - struct ECS::BonePose *bp = root.get_mut(); - // bp->pose.basis = bp->pose.basis.rotated(Vector3(0, 1, 0), 0.016f); + float delta = SceneTree::get_singleton() + ->get_physics_process_time(); + struct ECS::BonePose *bp = + root.get_mut(); + // 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(); }); diff --git a/src/modules/character/character_skeleton.cpp b/src/modules/character/character_skeleton.cpp index 77f8c0c..2fee044 100644 --- a/src/modules/character/character_skeleton.cpp +++ b/src/modules/character/character_skeleton.cpp @@ -1,25 +1,27 @@ - -#include "character.h" +#include #include #include -#include #include #include #include #include -#include + +#include +#include "character.h" void Character::init_skeleton() { VisualServer *vs = VS::get_singleton(); ecs.component() .on_add([](flecs::entity e, ECS::Skeleton &s) { - // flecs::log::trace("added skeleton %s", e.name().c_str()); + // flecs::log::trace("added + //skeleton %s", e.name().c_str()); if (e.has()) e.remove(); }) .on_set([](flecs::entity e, ECS::Skeleton &s) { - // flecs::log::trace("on set: set skeleton %s", e.name().c_str()); + // flecs::log::trace("on set: set + //skeleton %s", e.name().c_str()); // s.process_order_dirty = true; e.add(); }); @@ -38,15 +40,21 @@ void Character::init_skeleton() .kind(flecs::PreUpdate) .each([](flecs::entity e, ECS::Skeleton &sk) { if (sk.process_order_dirty) { - flecs::log::trace("skeletons: %d dirty: sorting bones", sk.bone_count); + flecs::log::trace( + "skeletons: %d dirty: sorting bones", + sk.bone_count); int i; - struct ECS::Skeleton::bone_data *bonesptr = sk.bones.ptrw(); + struct ECS::Skeleton::bone_data *bonesptr = + sk.bones.ptrw(); int len = sk.bones.size(); sk.process_order.resize(len); int *order = sk.process_order.ptrw(); for (i = 0; i < len; i++) { if (bonesptr[i].parent >= len) { - flecs::log::err("Bone %d has bad parent %d", i, bonesptr[i].parent); + flecs::log::err( + "Bone %d has bad " + "parent %d", + i, bonesptr[i].parent); bonesptr[i].parent = -1; } order[i] = i; @@ -57,14 +65,23 @@ void Character::init_skeleton() // fucking bubblesort bool swapped = false; for (i = 0; i < len; i++) { - int parent_idx = bonesptr[order[i]].parent; + int parent_idx = + bonesptr[order[i]] + .parent; if (parent_idx < 0) continue; - int parent_order = bonesptr[parent_idx].sort_index; + int parent_order = + bonesptr[parent_idx] + .sort_index; if (parent_order > i) { - bonesptr[order[i]].sort_index = parent_order; - bonesptr[parent_idx].sort_index = i; - SWAP(order[i], order[parent_order]); + bonesptr[order[i]] + .sort_index = + parent_order; + bonesptr[parent_idx] + .sort_index = + i; + SWAP(order[i], + order[parent_order]); swapped = true; } } @@ -73,9 +90,12 @@ void Character::init_skeleton() pass_count++; } if (pass_count >= len * len) - flecs::log::err("Skeleton parenthood graph is cyclic"); + flecs::log::err("Skeleton parenthood " + "graph is cyclic"); sk.process_order_dirty = false; - flecs::log::trace("skeletons: %d dirty: sorting bones done", sk.bone_count); + flecs::log::trace("skeletons: %d dirty: " + "sorting bones done", + sk.bone_count); } e.add(); }); @@ -87,61 +107,98 @@ void Character::init_skeleton() .each([](flecs::entity e, ECS::Skeleton &sk) { int i; VisualServer *vs = VS::get_singleton(); - // flecs::log::trace("skeletons: %d dirty: update try", sk.bone_count); + // flecs::log::trace("skeletons: %d dirty: update try", + // sk.bone_count); if (sk.process_order_dirty) return; - // flecs::log::trace("skeletons: %d dirty: update", sk.bone_count); - struct ECS::Skeleton::bone_data *bonesptr = sk.bones.ptrw(); + // flecs::log::trace("skeletons: + //%d dirty: update", sk.bone_count); + struct ECS::Skeleton::bone_data *bonesptr = + sk.bones.ptrw(); int len = sk.bones.size(); const int *order = sk.process_order.ptr(); for (i = 0; i < len; i++) { - struct ECS::Skeleton::bone_data &b = bonesptr[order[i]]; + struct ECS::Skeleton::bone_data &b = + bonesptr[order[i]]; if (b.disable_rest) { if (b.enabled) { Transform pose = b.pose; if (b.custom_pose_enable) - pose = b.custom_pose * pose; + pose = b.custom_pose * + pose; if (b.parent >= 0) { - b.pose_global = bonesptr[b.parent].pose_global * pose; - b.pose_global_no_override = bonesptr[b.parent].pose_global_no_override * pose; + b.pose_global = + bonesptr[b.parent] + .pose_global * + pose; + b.pose_global_no_override = + bonesptr[b.parent] + .pose_global_no_override * + pose; } else { b.pose_global = pose; - b.pose_global_no_override = pose; + b.pose_global_no_override = + pose; } } else { if (b.parent >= 0) { - b.pose_global = bonesptr[b.parent].pose_global; - b.pose_global_no_override = bonesptr[b.parent].pose_global_no_override; + b.pose_global = + bonesptr[b.parent] + .pose_global; + b.pose_global_no_override = + bonesptr[b.parent] + .pose_global_no_override; } else { - b.pose_global = Transform(); - b.pose_global_no_override = Transform(); + b.pose_global = + Transform(); + b.pose_global_no_override = + Transform(); } } } else { if (b.enabled) { Transform pose = b.pose; if (b.custom_pose_enable) - pose = b.custom_pose * pose; + pose = b.custom_pose * + pose; if (b.parent >= 0) { - b.pose_global = bonesptr[b.parent].pose_global * (b.rest * pose); - b.pose_global_no_override = bonesptr[b.parent].pose_global_no_override * (b.rest * pose); + b.pose_global = + bonesptr[b.parent] + .pose_global * + (b.rest * + pose); + b.pose_global_no_override = + bonesptr[b.parent] + .pose_global_no_override * + (b.rest * + pose); } else { - b.pose_global = b.rest * pose; - b.pose_global_no_override = b.rest * pose; + b.pose_global = + b.rest * pose; + b.pose_global_no_override = + b.rest * pose; } } else { if (b.parent >= 0) { - b.pose_global = bonesptr[b.parent].pose_global * b.rest; - b.pose_global_no_override = bonesptr[b.parent].pose_global_no_override * b.rest; + b.pose_global = + bonesptr[b.parent] + .pose_global * + b.rest; + b.pose_global_no_override = + bonesptr[b.parent] + .pose_global_no_override * + b.rest; } else { b.pose_global = b.rest; - b.pose_global_no_override = b.rest; + b.pose_global_no_override = + b.rest; } } } } - // flecs::log::trace("transform should be ready"); + // flecs::log::trace("transform should be + // ready"); e.add(); assert(sk.skin_bone_indices_ptrs); uint32_t bind_count = sk.skin->get_bind_count(); @@ -150,8 +207,11 @@ void Character::init_skeleton() if (!e.has()) return; for (i = 0; i < (int)bind_count; i++) { - uint32_t bone_index = sk.skin_bone_indices_ptrs[i]; - Transform xform = bonesptr[bone_index].pose_global * sk.skin->get_bind_pose(i); + uint32_t bone_index = + sk.skin_bone_indices_ptrs[i]; + Transform xform = + bonesptr[bone_index].pose_global * + sk.skin->get_bind_pose(i); #if 0 if (i == 0) { String out; @@ -161,8 +221,9 @@ void Character::init_skeleton() out.ascii().get_data()); } #endif - vs->skeleton_bone_set_transform(sk.skeleton, - i, bonesptr[bone_index].pose_global * sk.skin->get_bind_pose(i)); + vs->skeleton_bone_set_transform(sk.skeleton, i, + bonesptr[bone_index].pose_global * + sk.skin->get_bind_pose(i)); } sk.dirty = false; e.remove(); diff --git a/src/modules/character/character_slot.cpp b/src/modules/character/character_slot.cpp index b7f7700..9558bd7 100644 --- a/src/modules/character/character_slot.cpp +++ b/src/modules/character/character_slot.cpp @@ -1,11 +1,13 @@ -#include "character.h" +#include #include -#include #include #include #include #include -#include + +#include + +#include "character.h" void Character::init_slot() { @@ -18,18 +20,23 @@ void Character::init_slot() .on_remove([vs](flecs::entity e, ECS::CharacterSlot &s) { if (s.instance.is_valid()) { vs->instance_set_scenario(s.instance, RID()); - vs->instance_attach_skeleton(s.instance, RID()); + vs->instance_attach_skeleton( + s.instance, RID()); vs->instance_set_base(s.instance, RID()); vs->free(s.instance); s.instance = RID(); - // print_line("mesh instance slot removed " + s.name); + // print_line("mesh + //instance slot removed " + s.name); } - // flecs::log::trace("removed slot %s", e.name().c_str()); + // 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()); + // 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()); + flecs::log::err( + "invalid mesh %s", e.name().c_str()); }); ecs.system("UpdateSlot") .without() @@ -40,11 +47,16 @@ void Character::init_slot() assert(e.parent().has()); if (!slot.instance.is_valid()) { slot.name = e.name().c_str(); - RID scenario = st->get_root()->get_world()->get_scenario(); + RID scenario = st->get_root() + ->get_world() + ->get_scenario(); slot.instance = vs->instance_create(); - vs->instance_set_scenario(slot.instance, scenario); - vs->instance_set_base(slot.instance, slot.mesh->get_rid()); - // flecs::log::trace("created instance for %s", e.name().c_str()); + vs->instance_set_scenario( + 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("AttachToSkeleton") @@ -58,21 +70,28 @@ void Character::init_slot() assert(parent.has()); assert(!e.has()); assert(slot.instance.is_valid()); - const ECS::Skeleton *skel = parent.get(); + const ECS::Skeleton *skel = + parent.get(); assert(skel->skeleton.is_valid()); - // flecs::log::trace("binding slot for %s", e.name().c_str()); + // 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()) slot.skin_internal = skel->skin; - if (skel->skeleton.is_valid() && !skel->skin.is_null()) { - uint32_t bind_count = skel->skin->get_bind_count(); - vs->skeleton_allocate(skel->skeleton, bind_count); - vs->instance_attach_skeleton(slot.instance, skel->skeleton); + if (skel->skeleton.is_valid() && + !skel->skin.is_null()) { + uint32_t bind_count = + skel->skin->get_bind_count(); + vs->skeleton_allocate( + skel->skeleton, bind_count); + vs->instance_attach_skeleton( + slot.instance, skel->skeleton); slot.bound = true; e.add(); parent.add(); - // flecs::log::trace("bound slot for %s", e.name().c_str()); + // flecs::log::trace("bound + //slot for %s", e.name().c_str()); } }); ecs.system("BindSlotsToSkeleton") @@ -87,63 +106,108 @@ void Character::init_slot() assert(!e.has()); assert(!e.has()); ECS::Skeleton *skel = parent.get_mut(); - if (skel->skin.is_null() && slot.skin_internal.is_null()) { - const struct ECS::Skeleton::bone_data *bonesptr = skel->bones.ptr(); + if (skel->skin.is_null() && + slot.skin_internal.is_null()) { + 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()); + // flecs::log::trace("binding + //slot for %s", e.name().c_str()); slot.skin_internal.instance(); - slot.skin_internal->set_bind_count(skel->bones.size()); + 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()); + // 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]]; + const struct ECS::Skeleton::bone_data + &b = bonesptr[order[i]]; if (b.parent >= 0) - slot.skin_internal->set_bind_pose(order[i], slot.skin_internal->get_bind_pose(b.parent) * b.rest); + slot.skin_internal->set_bind_pose( + order[i], + slot.skin_internal->get_bind_pose( + b.parent) * + b.rest); else - slot.skin_internal->set_bind_pose(order[i], b.rest); + slot.skin_internal + ->set_bind_pose( + order[i], + b.rest); } for (i = 0; i < len; i++) { - slot.skin_internal->set_bind_bone(i, i); - slot.skin_internal->set_bind_pose(i, slot.skin_internal->get_bind_pose(i).affine_inverse()); + slot.skin_internal->set_bind_bone( + i, i); + slot.skin_internal->set_bind_pose(i, + slot.skin_internal + ->get_bind_pose(i) + .affine_inverse()); } skel->skin = slot.skin_internal; - // flecs::log::trace("created skin for %s: %d", e.name().c_str(), len); + // 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 = skel->skin->get_bind_count(); + uint32_t bind_count = + skel->skin->get_bind_count(); assert(bind_count > 0); skel->skin_bone_indices.resize(bind_count); - skel->skin_bone_indices_ptrs = skel->skin_bone_indices.ptrw(); + skel->skin_bone_indices_ptrs = + skel->skin_bone_indices.ptrw(); for (i = 0; i < bind_count; i++) { - StringName bind_name = skel->skin->get_bind_name(i); + StringName bind_name = + skel->skin->get_bind_name(i); if (bind_name != StringName()) { int j; bool found = false; for (j = 0; j < len; j++) { - if (bonesptr[j].name == bind_name) { - skel->skin_bone_indices_ptrs[i] = j; + if (bonesptr[j].name == + bind_name) { + skel->skin_bone_indices_ptrs + [i] = + j; found = true; break; } } if (!found) { - skel->skin_bone_indices_ptrs[i] = 0; - flecs::log::err("no bind name %s in skeleton", String(bind_name).ascii().get_data()); + skel->skin_bone_indices_ptrs + [i] = 0; + flecs::log::err( + "no bind name " + "%s in " + "skeleton", + String(bind_name) + .ascii() + .get_data()); } - } else if (skel->skin->get_bind_bone(i) >= 0) { - uint32_t bind_index = skel->skin->get_bind_bone(i); + } else if (skel->skin->get_bind_bone( + i) >= 0) { + uint32_t bind_index = + skel->skin + ->get_bind_bone( + i); if (bind_index >= len) { - skel->skin_bone_indices_ptrs[i] = 0; - flecs::log::err("bind %d bad index %d", i, bind_index); + skel->skin_bone_indices_ptrs + [i] = 0; + flecs::log::err( + "bind %d bad " + "index %d", + i, bind_index); } else - skel->skin_bone_indices_ptrs[i] = bind_index; + skel->skin_bone_indices_ptrs + [i] = + bind_index; } else { - flecs::log::err("no bind name for %d", i); - skel->skin_bone_indices_ptrs[i] = 0; + flecs::log::err( + "no bind name for %d", + i); + skel->skin_bone_indices_ptrs + [i] = 0; } } e.add(); - } else if (!skel->skin.is_null() && slot.skin_internal.is_null()) { + } else if (!skel->skin.is_null() && + slot.skin_internal.is_null()) { slot.skin_internal = skel->skin; e.add(); } diff --git a/src/modules/character/register_types.cpp b/src/modules/character/register_types.cpp index 4c039d9..0e7f9c7 100644 --- a/src/modules/character/register_types.cpp +++ b/src/modules/character/register_types.cpp @@ -1,6 +1,7 @@ -#include "register_types.h" -#include "character.h" #include +#include "character.h" + +#include "register_types.h" void register_character_types() { @@ -30,7 +31,8 @@ void register_character_types() #endif ClassDB::register_class(); Character::get_singleton(); - Engine::get_singleton()->add_singleton(Engine::Singleton("Character", Character::get_singleton())); + Engine::get_singleton()->add_singleton( + Engine::Singleton("Character", Character::get_singleton())); } void unregister_character_types()