Skip to content

Commit

Permalink
Convert skeleton modifications to nodes.
Browse files Browse the repository at this point in the history
  • Loading branch information
fire committed Aug 5, 2022
1 parent faff5e1 commit e109244
Show file tree
Hide file tree
Showing 46 changed files with 1,431 additions and 3,694 deletions.
2 changes: 1 addition & 1 deletion core/object/worker_thread_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ WorkerThreadPool::GroupID WorkerThreadPool::_add_group_task(const Callable &p_ca
group->tasks_used = 0;
p_tasks = 0;
if (p_template_userdata) {
memdelete(p_template_userdata);
p_template_userdata->~BaseTemplateUserdata();
}

} else {
Expand Down
2 changes: 0 additions & 2 deletions editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@
#include "editor/plugins/shader_file_editor_plugin.h"
#include "editor/plugins/skeleton_2d_editor_plugin.h"
#include "editor/plugins/skeleton_3d_editor_plugin.h"
#include "editor/plugins/skeleton_ik_3d_editor_plugin.h"
#include "editor/plugins/sprite_2d_editor_plugin.h"
#include "editor/plugins/sprite_frames_editor_plugin.h"
#include "editor/plugins/style_box_editor_plugin.h"
Expand Down Expand Up @@ -7169,7 +7168,6 @@ EditorNode::EditorNode() {
add_editor_plugin(memnew(ShaderEditorPlugin));
add_editor_plugin(memnew(ShaderFileEditorPlugin));
add_editor_plugin(memnew(Skeleton3DEditorPlugin));
add_editor_plugin(memnew(SkeletonIK3DEditorPlugin));
add_editor_plugin(memnew(SpriteFramesEditorPlugin));
add_editor_plugin(memnew(StyleBoxEditorPlugin));
add_editor_plugin(memnew(SubViewportPreviewEditorPlugin));
Expand Down
95 changes: 0 additions & 95 deletions editor/plugins/skeleton_ik_3d_editor_plugin.cpp

This file was deleted.

61 changes: 0 additions & 61 deletions editor/plugins/skeleton_ik_3d_editor_plugin.h

This file was deleted.

4 changes: 3 additions & 1 deletion modules/gridmap/grid_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -572,11 +572,12 @@ bool GridMap::_octant_update(const OctantKey &p_key) {
NavigationServer3D::get_singleton()->region_set_map(region, get_world_3d()->get_navigation_map());
nm.region = region;

#ifdef DEBUG_ENABLED
// add navigation debugmesh visual instances if debug is enabled
SceneTree *st = SceneTree::get_singleton();
if (st && st->is_debugging_navigation_hint()) {
if (!nm.navmesh_debug_instance.is_valid()) {
RID navmesh_debug_rid = navmesh->get_debug_mesh()->get_rid();
RID navmesh_debug_rid = navmesh->_get_debug_mesh()->get_rid();
nm.navmesh_debug_instance = RS::get_singleton()->instance_create();
RS::get_singleton()->instance_set_base(nm.navmesh_debug_instance, navmesh_debug_rid);
RS::get_singleton()->mesh_surface_set_material(navmesh_debug_rid, 0, st->get_debug_navigation_material()->get_rid());
Expand All @@ -586,6 +587,7 @@ bool GridMap::_octant_update(const OctantKey &p_key) {
RS::get_singleton()->instance_set_transform(nm.navmesh_debug_instance, get_global_transform() * nm.xform);
}
}
#endif
}

g.navmesh_ids[E] = nm;
Expand Down
110 changes: 0 additions & 110 deletions scene/2d/skeleton_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -540,30 +540,15 @@ Bone2D::~Bone2D() {

bool Skeleton2D::_set(const StringName &p_path, const Variant &p_value) {
String path = p_path;

if (path.begins_with("modification_stack")) {
set_modification_stack(p_value);
return true;
}
return true;
}

bool Skeleton2D::_get(const StringName &p_path, Variant &r_ret) const {
String path = p_path;

if (path.begins_with("modification_stack")) {
r_ret = get_modification_stack();
return true;
}
return true;
}

void Skeleton2D::_get_property_list(List<PropertyInfo> *p_list) const {
p_list->push_back(
PropertyInfo(Variant::OBJECT, PNAME("modification_stack"),
PROPERTY_HINT_RESOURCE_TYPE,
"SkeletonModificationStack2D",
PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_DEFERRED_SET_RESOURCE | PROPERTY_USAGE_DO_NOT_SHARE_ON_DUPLICATE));
}

void Skeleton2D::_make_bone_setup_dirty() {
Expand Down Expand Up @@ -670,24 +655,7 @@ void Skeleton2D::_notification(int p_what) {

if (p_what == NOTIFICATION_TRANSFORM_CHANGED) {
RS::get_singleton()->skeleton_set_base_transform_2d(skeleton, get_global_transform());
} else if (p_what == NOTIFICATION_INTERNAL_PROCESS) {
if (modification_stack.is_valid()) {
execute_modifications(get_process_delta_time(), SkeletonModificationStack2D::EXECUTION_MODE::execution_mode_process);
}
} else if (p_what == NOTIFICATION_INTERNAL_PHYSICS_PROCESS) {
if (modification_stack.is_valid()) {
execute_modifications(get_physics_process_delta_time(), SkeletonModificationStack2D::EXECUTION_MODE::execution_mode_physics_process);
}
}
#ifdef TOOLS_ENABLED
else if (p_what == NOTIFICATION_DRAW) {
if (Engine::get_singleton()->is_editor_hint()) {
if (modification_stack.is_valid()) {
modification_stack->draw_editor_gizmos();
}
}
}
#endif // TOOLS_ENABLED
}

RID Skeleton2D::get_skeleton() const {
Expand All @@ -706,80 +674,6 @@ Transform2D Skeleton2D::get_bone_local_pose_override(int p_bone_idx) {
return bones[p_bone_idx].local_pose_override;
}

void Skeleton2D::set_modification_stack(Ref<SkeletonModificationStack2D> p_stack) {
if (modification_stack.is_valid()) {
modification_stack->is_setup = false;
modification_stack->set_skeleton(nullptr);

set_process_internal(false);
set_physics_process_internal(false);
}
modification_stack = p_stack;
if (modification_stack.is_valid()) {
modification_stack->set_skeleton(this);
modification_stack->setup();

set_process_internal(true);
set_physics_process_internal(true);

#ifdef TOOLS_ENABLED
modification_stack->set_editor_gizmos_dirty(true);
#endif // TOOLS_ENABLED
}
}

Ref<SkeletonModificationStack2D> Skeleton2D::get_modification_stack() const {
return modification_stack;
}

void Skeleton2D::execute_modifications(real_t p_delta, int p_execution_mode) {
if (!modification_stack.is_valid()) {
return;
}

// Do not cache the transform changes caused by the modifications!
for (int i = 0; i < bones.size(); i++) {
bones[i].bone->copy_transform_to_cache = false;
}

if (modification_stack->skeleton != this) {
modification_stack->set_skeleton(this);
}

modification_stack->execute(p_delta, p_execution_mode);

// Only apply the local pose override on _process. Otherwise, just calculate the local_pose_override and reset the transform.
if (p_execution_mode == SkeletonModificationStack2D::EXECUTION_MODE::execution_mode_process) {
for (int i = 0; i < bones.size(); i++) {
if (bones[i].local_pose_override_amount > 0) {
bones[i].bone->set_meta("_local_pose_override_enabled_", true);

Transform2D final_trans = bones[i].bone->cache_transform;
final_trans = final_trans.interpolate_with(bones[i].local_pose_override, bones[i].local_pose_override_amount);
bones[i].bone->set_transform(final_trans);
bones[i].bone->propagate_call("force_update_transform");

if (bones[i].local_pose_override_persistent) {
bones.write[i].local_pose_override_amount = 0.0;
}
} else {
// TODO: see if there is a way to undo the override without having to resort to setting every bone's transform.
bones[i].bone->remove_meta("_local_pose_override_enabled_");
bones[i].bone->set_transform(bones[i].bone->cache_transform);
}
}
}

// Cache any future transform changes
for (int i = 0; i < bones.size(); i++) {
bones[i].bone->copy_transform_to_cache = true;
}

#ifdef TOOLS_ENABLED
modification_stack->set_editor_gizmos_dirty(true);
#endif // TOOLS_ENABLED
}

void Skeleton2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("_update_bone_setup"), &Skeleton2D::_update_bone_setup);
ClassDB::bind_method(D_METHOD("_update_transform"), &Skeleton2D::_update_transform);
Expand All @@ -789,10 +683,6 @@ void Skeleton2D::_bind_methods() {

ClassDB::bind_method(D_METHOD("get_skeleton"), &Skeleton2D::get_skeleton);

ClassDB::bind_method(D_METHOD("set_modification_stack", "modification_stack"), &Skeleton2D::set_modification_stack);
ClassDB::bind_method(D_METHOD("get_modification_stack"), &Skeleton2D::get_modification_stack);
ClassDB::bind_method(D_METHOD("execute_modifications", "delta", "execution_mode"), &Skeleton2D::execute_modifications);

ClassDB::bind_method(D_METHOD("set_bone_local_pose_override", "bone_idx", "override_pose", "strength", "persistent"), &Skeleton2D::set_bone_local_pose_override);
ClassDB::bind_method(D_METHOD("get_bone_local_pose_override", "bone_idx"), &Skeleton2D::get_bone_local_pose_override);

Expand Down
7 changes: 0 additions & 7 deletions scene/2d/skeleton_2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#define SKELETON_2D_H

#include "scene/2d/node_2d.h"
#include "scene/resources/skeleton_modification_2d.h"

class Skeleton2D;

Expand Down Expand Up @@ -101,8 +100,6 @@ class Bone2D : public Node2D {
~Bone2D();
};

class SkeletonModificationStack2D;

class Skeleton2D : public Node2D {
GDCLASS(Skeleton2D, Node2D);

Expand Down Expand Up @@ -138,8 +135,6 @@ class Skeleton2D : public Node2D {

RID skeleton;

Ref<SkeletonModificationStack2D> modification_stack;

protected:
void _notification(int p_what);
static void _bind_methods();
Expand All @@ -156,8 +151,6 @@ class Skeleton2D : public Node2D {
void set_bone_local_pose_override(int p_bone_idx, Transform2D p_override, real_t p_amount, bool p_persistent = true);
Transform2D get_bone_local_pose_override(int p_bone_idx);

Ref<SkeletonModificationStack2D> get_modification_stack() const;
void set_modification_stack(Ref<SkeletonModificationStack2D> p_stack);
void execute_modifications(real_t p_delta, int p_execution_mode);

Skeleton2D();
Expand Down
Loading

0 comments on commit e109244

Please sign in to comment.