From 4c417dd2c242e418404274f8784100293bd6db41 Mon Sep 17 00:00:00 2001 From: badlogic Date: Tue, 26 Apr 2022 23:34:57 +0200 Subject: [PATCH] [godot] Rework invalidation of native spine objects, add unit test. --- .../assets/spineboy/spinebody-data-res.tres | 2 +- spine-godot/example/tests/unit-tests.gd | 13 + spine-godot/spine_godot/SpineAnimation.cpp | 24 +- spine-godot/spine_godot/SpineAnimation.h | 2 +- spine-godot/spine_godot/SpineAttachment.cpp | 10 +- spine-godot/spine_godot/SpineAttachment.h | 2 +- spine-godot/spine_godot/SpineBone.cpp | 242 +++++++++--------- spine-godot/spine_godot/SpineBone.h | 2 +- spine-godot/spine_godot/SpineBoneData.cpp | 100 ++++---- spine-godot/spine_godot/SpineBoneData.h | 2 +- spine-godot/spine_godot/SpineCommon.h | 79 +++++- .../spine_godot/SpineConstraintData.cpp | 20 +- spine-godot/spine_godot/SpineConstraintData.h | 2 +- spine-godot/spine_godot/SpineEvent.cpp | 48 ++-- spine-godot/spine_godot/SpineEvent.h | 2 +- spine-godot/spine_godot/SpineEventData.cpp | 44 ++-- spine-godot/spine_godot/SpineEventData.h | 4 +- spine-godot/spine_godot/SpineIkConstraint.cpp | 72 +++--- spine-godot/spine_godot/SpineIkConstraint.h | 2 +- .../spine_godot/SpineIkConstraintData.cpp | 30 +-- .../spine_godot/SpineObjectWrapper.cpp | 33 --- spine-godot/spine_godot/SpineObjectWrapper.h | 61 ----- .../spine_godot/SpinePathConstraint.cpp | 72 +++--- spine-godot/spine_godot/SpinePathConstraint.h | 2 +- .../spine_godot/SpineSkeletonDataResource.cpp | 3 + spine-godot/spine_godot/SpineSkin.cpp | 48 ++-- spine-godot/spine_godot/SpineSkin.h | 2 +- spine-godot/spine_godot/SpineSlot.cpp | 64 ++--- spine-godot/spine_godot/SpineSlot.h | 2 +- spine-godot/spine_godot/SpineSlotData.cpp | 52 ++-- spine-godot/spine_godot/SpineSlotData.h | 2 +- spine-godot/spine_godot/SpineSprite.cpp | 3 + spine-godot/spine_godot/SpineTimeline.cpp | 28 +- spine-godot/spine_godot/SpineTimeline.h | 2 +- spine-godot/spine_godot/SpineTrackEntry.cpp | 184 ++++++------- spine-godot/spine_godot/SpineTrackEntry.h | 2 +- .../spine_godot/SpineTransformConstraint.cpp | 80 +++--- .../spine_godot/SpineTransformConstraint.h | 2 +- 38 files changed, 672 insertions(+), 672 deletions(-) delete mode 100644 spine-godot/spine_godot/SpineObjectWrapper.cpp delete mode 100644 spine-godot/spine_godot/SpineObjectWrapper.h diff --git a/spine-godot/example/assets/spineboy/spinebody-data-res.tres b/spine-godot/example/assets/spineboy/spinebody-data-res.tres index 5ba572eda..b2e8bd73d 100644 --- a/spine-godot/example/assets/spineboy/spinebody-data-res.tres +++ b/spine-godot/example/assets/spineboy/spinebody-data-res.tres @@ -16,5 +16,5 @@ mix = 0.2 [resource] atlas_res = ExtResource( 1 ) skeleton_file_res = ExtResource( 2 ) -default_mix = 0.2 +default_mix = 0.1 animation_mixes = [ SubResource( 1 ), SubResource( 2 ) ] diff --git a/spine-godot/example/tests/unit-tests.gd b/spine-godot/example/tests/unit-tests.gd index cb537acb9..9a48ab841 100644 --- a/spine-godot/example/tests/unit-tests.gd +++ b/spine-godot/example/tests/unit-tests.gd @@ -19,8 +19,21 @@ func test_spine_timeline(): assert(timeline.get_property_ids() == [4294967300]) assert(timeline.get_type() == "RotateTimeline") +func test_spine_object_invalidation(): + var skeleton_data = get_skeleton().get_data() + var bone_data = skeleton_data.find_bone("gun"); + var old_bone_data_x = bone_data.get_x(); + var bone = get_skeleton().find_bone("gun") + var old_bone_x = bone.get_x() + skeleton_data_res = null + assert(old_bone_x != bone.get_x()) + assert(old_bone_data_x == bone_data.get_x()) + skeleton_data.atlas_res = null; + assert(old_bone_data_x != bone_data.get_x()) + func _ready(): test_spine_animation() test_spine_timeline() + test_spine_object_invalidation() print("All tests passed") diff --git a/spine-godot/spine_godot/SpineAnimation.cpp b/spine-godot/spine_godot/SpineAnimation.cpp index fc677ff68..b95968d68 100644 --- a/spine-godot/spine_godot/SpineAnimation.cpp +++ b/spine-godot/spine_godot/SpineAnimation.cpp @@ -46,26 +46,26 @@ void SpineAnimation::_bind_methods() { } String SpineAnimation::get_name() { - SPINE_CHECK(spine_object, "") - return spine_object->getName().buffer(); + SPINE_CHECK(get_spine_object(), "") + return get_spine_object()->getName().buffer(); } float SpineAnimation::get_duration() { - SPINE_CHECK(spine_object, 0) - return spine_object->getDuration(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getDuration(); } void SpineAnimation::set_duration(float duration) { - SPINE_CHECK(spine_object,) - spine_object->setDuration(duration); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setDuration(duration); } void SpineAnimation::apply(Ref skeleton, float last_time, float time, bool loop, Array events, float alpha, SpineConstant::MixBlend blend, SpineConstant::MixDirection direction) { - SPINE_CHECK(spine_object,) + SPINE_CHECK(get_spine_object(),) spine::Vector spineEvents; - spine_object->apply(*(skeleton->get_spine_object()), last_time, time, loop, &spineEvents, alpha, (spine::MixBlend) blend, (spine::MixDirection) direction); + get_spine_object()->apply(*(skeleton->get_spine_object()), last_time, time, loop, &spineEvents, alpha, (spine::MixBlend) blend, (spine::MixDirection) direction); for (int i = 0; i < (int)spineEvents.size(); ++i) { auto event_ref = memnew(SpineEvent); event_ref->set_spine_object(skeleton->get_spine_owner(), spineEvents[i]); @@ -75,8 +75,8 @@ void SpineAnimation::apply(Ref skeleton, float last_time, float t Array SpineAnimation::get_timelines() { Array result; - SPINE_CHECK(spine_object, result) - auto &timelines = spine_object->getTimelines(); + SPINE_CHECK(get_spine_object(), result) + auto &timelines = get_spine_object()->getTimelines(); result.resize((int)timelines.size()); for (int i = 0; i < (int)result.size(); ++i) { @@ -88,12 +88,12 @@ Array SpineAnimation::get_timelines() { } bool SpineAnimation::has_timeline(Array ids) { - SPINE_CHECK(spine_object, false) + SPINE_CHECK(get_spine_object(), false) spine::Vector property_ids; property_ids.setSize(ids.size(), 0); for (int i = 0; i < (int)property_ids.size(); ++i) { property_ids[i] = (spine::PropertyId) ids[i]; } - return spine_object->hasTimeline(property_ids); + return get_spine_object()->hasTimeline(property_ids); } diff --git a/spine-godot/spine_godot/SpineAnimation.h b/spine-godot/spine_godot/SpineAnimation.h index 6fee5eb01..3ba29b22c 100644 --- a/spine-godot/spine_godot/SpineAnimation.h +++ b/spine-godot/spine_godot/SpineAnimation.h @@ -39,7 +39,7 @@ class SpineSkeleton; class SpineTimeline; class SpineSkeletonDataResource; -class SpineAnimation : public SpineObjectWrapper { +class SpineAnimation : public SpineSkeletonDataResourceOwnedObject { GDCLASS(SpineAnimation, SpineObjectWrapper) protected: diff --git a/spine-godot/spine_godot/SpineAttachment.cpp b/spine-godot/spine_godot/SpineAttachment.cpp index 341d9e431..7b84c655b 100644 --- a/spine-godot/spine_godot/SpineAttachment.cpp +++ b/spine-godot/spine_godot/SpineAttachment.cpp @@ -36,17 +36,17 @@ void SpineAttachment::_bind_methods() { } SpineAttachment::~SpineAttachment() { - if (spine_object) spine_object->dereference(); + if (get_spine_object()) get_spine_object()->dereference(); } String SpineAttachment::get_attachment_name() { - SPINE_CHECK(spine_object, "") - return spine_object->getName().buffer(); + SPINE_CHECK(get_spine_object(), "") + return get_spine_object()->getName().buffer(); } Ref SpineAttachment::copy() { - SPINE_CHECK(spine_object, nullptr) - auto copy = spine_object->copy(); + SPINE_CHECK(get_spine_object(), nullptr) + auto copy = get_spine_object()->copy(); if (!copy) return nullptr; Ref attachment_ref(memnew(SpineAttachment)); attachment_ref->set_spine_object(get_spine_owner(), copy); diff --git a/spine-godot/spine_godot/SpineAttachment.h b/spine-godot/spine_godot/SpineAttachment.h index 8e874290e..f50b8b9b9 100644 --- a/spine-godot/spine_godot/SpineAttachment.h +++ b/spine-godot/spine_godot/SpineAttachment.h @@ -35,7 +35,7 @@ class SpineSkeletonDataResource; -class SpineAttachment : public SpineObjectWrapper { +class SpineAttachment : public SpineSkeletonDataResourceOwnedObject { GDCLASS(SpineAttachment, SpineObjectWrapper) protected: diff --git a/spine-godot/spine_godot/SpineBone.cpp b/spine-godot/spine_godot/SpineBone.cpp index 52cb22cfa..ded49c6ea 100644 --- a/spine-godot/spine_godot/SpineBone.cpp +++ b/spine-godot/spine_godot/SpineBone.cpp @@ -99,65 +99,65 @@ void SpineBone::_bind_methods() { } void SpineBone::update_world_transform() { - SPINE_CHECK(spine_object,) - spine_object->updateWorldTransform(); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->updateWorldTransform(); } void SpineBone::set_to_setup_pose() { - SPINE_CHECK(spine_object,) - spine_object->setToSetupPose(); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setToSetupPose(); } Vector2 SpineBone::world_to_local(Vector2 world_position) { - SPINE_CHECK(spine_object, Vector2()) + SPINE_CHECK(get_spine_object(), Vector2()) float x, y; - spine_object->worldToLocal(world_position.x, world_position.y, x, y); + get_spine_object()->worldToLocal(world_position.x, world_position.y, x, y); return Vector2(x, y); } Vector2 SpineBone::local_to_world(Vector2 local_position) { - SPINE_CHECK(spine_object, Vector2()) + SPINE_CHECK(get_spine_object(), Vector2()) float x, y; - spine_object->localToWorld(local_position.x, local_position.y, x, y); + get_spine_object()->localToWorld(local_position.x, local_position.y, x, y); return Vector2(x, y); } float SpineBone::world_to_local_rotation(float world_rotation) { - SPINE_CHECK(spine_object, 0) - return spine_object->worldToLocalRotation(world_rotation); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->worldToLocalRotation(world_rotation); } float SpineBone::local_to_world_rotation(float local_rotation) { - SPINE_CHECK(spine_object, 0) - return spine_object->localToWorldRotation(local_rotation); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->localToWorldRotation(local_rotation); } void SpineBone::rotate_world(float degrees) { - SPINE_CHECK(spine_object,) - spine_object->rotateWorld(degrees); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->rotateWorld(degrees); } float SpineBone::get_world_to_local_rotation_x() { - SPINE_CHECK(spine_object, 0) - return spine_object->getWorldToLocalRotationX(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getWorldToLocalRotationX(); } float SpineBone::get_world_to_local_rotation_y() { - SPINE_CHECK(spine_object, 0) - return spine_object->getWorldToLocalRotationY(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getWorldToLocalRotationY(); } Ref SpineBone::get_data() { - SPINE_CHECK(spine_object, nullptr) - auto &bone_data = spine_object->getData(); + SPINE_CHECK(get_spine_object(), nullptr) + auto &bone_data = get_spine_object()->getData(); Ref bone_data_ref(memnew(SpineBoneData)); bone_data_ref->set_spine_object(*get_spine_owner()->get_skeleton_data_res(), &bone_data); return bone_data_ref; } Ref SpineBone::get_parent() { - SPINE_CHECK(spine_object, nullptr) - auto parent = spine_object->getParent(); + SPINE_CHECK(get_spine_object(), nullptr) + auto parent = get_spine_object()->getParent(); if (!parent) return nullptr; Ref parent_ref(memnew(SpineBone)); parent_ref->set_spine_object(get_spine_owner(), parent); @@ -166,8 +166,8 @@ Ref SpineBone::get_parent() { Array SpineBone::get_children() { Array result; - SPINE_CHECK(spine_object, result) - auto children = spine_object->getChildren(); + SPINE_CHECK(get_spine_object(), result) + auto children = get_spine_object()->getChildren(); result.resize((int)children.size()); for (int i = 0; i < children.size(); ++i) { auto child = children[i]; @@ -179,238 +179,238 @@ Array SpineBone::get_children() { } float SpineBone::get_x() { - SPINE_CHECK(spine_object, 0) - return spine_object->getX(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getX(); } void SpineBone::set_x(float v) { - SPINE_CHECK(spine_object,) - spine_object->setX(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setX(v); } float SpineBone::get_y() { - SPINE_CHECK(spine_object, 0) - return spine_object->getY(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getY(); } void SpineBone::set_y(float v) { - SPINE_CHECK(spine_object,) - spine_object->setY(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setY(v); } float SpineBone::get_rotation() { - SPINE_CHECK(spine_object, 0) - return spine_object->getRotation(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getRotation(); } void SpineBone::set_rotation(float v) { - SPINE_CHECK(spine_object,) - spine_object->setRotation(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setRotation(v); } float SpineBone::get_scale_x() { - SPINE_CHECK(spine_object, 0) - return spine_object->getScaleX(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getScaleX(); } void SpineBone::set_scale_x(float v) { - SPINE_CHECK(spine_object,) - spine_object->setScaleX(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setScaleX(v); } float SpineBone::get_scale_y() { - SPINE_CHECK(spine_object, 0) - return spine_object->getScaleY(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getScaleY(); } void SpineBone::set_scale_y(float v) { - SPINE_CHECK(spine_object,) - spine_object->setScaleY(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setScaleY(v); } float SpineBone::get_shear_x() { - SPINE_CHECK(spine_object, 0) - return spine_object->getShearX(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getShearX(); } void SpineBone::set_shear_x(float v) { - SPINE_CHECK(spine_object,) - spine_object->setShearX(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setShearX(v); } float SpineBone::get_shear_y() { - SPINE_CHECK(spine_object, 0) - return spine_object->getShearY(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getShearY(); } void SpineBone::set_shear_y(float v) { - SPINE_CHECK(spine_object,) - spine_object->setShearY(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setShearY(v); } float SpineBone::get_applied_rotation() { - SPINE_CHECK(spine_object, 0) - return spine_object->getAppliedRotation(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getAppliedRotation(); } void SpineBone::set_applied_rotation(float v) { - SPINE_CHECK(spine_object,) - spine_object->setAppliedRotation(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setAppliedRotation(v); } float SpineBone::get_a_x() { - SPINE_CHECK(spine_object, 0) - return spine_object->getAX(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getAX(); } void SpineBone::set_a_x(float v) { - SPINE_CHECK(spine_object,) - spine_object->setAX(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setAX(v); } float SpineBone::get_a_y() { - SPINE_CHECK(spine_object, 0) - return spine_object->getAY(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getAY(); } void SpineBone::set_a_y(float v) { - SPINE_CHECK(spine_object,) - spine_object->setAY(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setAY(v); } float SpineBone::get_a_scale_x() { - SPINE_CHECK(spine_object, 0) - return spine_object->getAScaleX(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getAScaleX(); } void SpineBone::set_a_scale_x(float v) { - SPINE_CHECK(spine_object,) - spine_object->setAScaleX(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setAScaleX(v); } float SpineBone::get_a_scale_y() { - SPINE_CHECK(spine_object, 0) - return spine_object->getAScaleY(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getAScaleY(); } void SpineBone::set_a_scale_y(float v) { - SPINE_CHECK(spine_object,) - spine_object->setAScaleY(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setAScaleY(v); } float SpineBone::get_a_shear_x() { - SPINE_CHECK(spine_object, 0) - return spine_object->getAShearX(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getAShearX(); } void SpineBone::set_a_shear_x(float v) { - SPINE_CHECK(spine_object,) - spine_object->setAShearX(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setAShearX(v); } float SpineBone::get_a_shear_y() { - SPINE_CHECK(spine_object, 0) - return spine_object->getAShearY(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getAShearY(); } void SpineBone::set_a_shear_y(float v) { - SPINE_CHECK(spine_object,) - spine_object->setAShearY(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setAShearY(v); } float SpineBone::get_a() { - SPINE_CHECK(spine_object, 0) - return spine_object->getA(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getA(); } void SpineBone::set_a(float v) { - SPINE_CHECK(spine_object,) - spine_object->setA(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setA(v); } float SpineBone::get_b() { - SPINE_CHECK(spine_object, 0) - return spine_object->getB(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getB(); } void SpineBone::set_b(float v) { - SPINE_CHECK(spine_object,) - spine_object->setB(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setB(v); } float SpineBone::get_c() { - SPINE_CHECK(spine_object, 0) - return spine_object->getC(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getC(); } void SpineBone::set_c(float v) { - SPINE_CHECK(spine_object,) - spine_object->setC(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setC(v); } float SpineBone::get_d() { - SPINE_CHECK(spine_object, 0) - return spine_object->getD(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getD(); } void SpineBone::set_d(float v) { - SPINE_CHECK(spine_object,) - spine_object->setD(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setD(v); } float SpineBone::get_world_x() { - SPINE_CHECK(spine_object, 0) - return spine_object->getWorldX(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getWorldX(); } void SpineBone::set_world_x(float v) { - SPINE_CHECK(spine_object,) - spine_object->setWorldX(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setWorldX(v); } float SpineBone::get_world_y() { - SPINE_CHECK(spine_object, 0) - return spine_object->getWorldY(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getWorldY(); } void SpineBone::set_world_y(float v) { - SPINE_CHECK(spine_object,) - spine_object->setWorldY(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setWorldY(v); } float SpineBone::get_world_rotation_x() { - SPINE_CHECK(spine_object, 0) - return spine_object->getWorldRotationX(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getWorldRotationX(); } float SpineBone::get_world_rotation_y() { - SPINE_CHECK(spine_object, 0) - return spine_object->getWorldRotationY(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getWorldRotationY(); } float SpineBone::get_world_scale_x() { - SPINE_CHECK(spine_object, 0) - return spine_object->getWorldScaleX(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getWorldScaleX(); } float SpineBone::get_world_scale_y() { - SPINE_CHECK(spine_object, 0) - return spine_object->getWorldScaleY(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getWorldScaleY(); } bool SpineBone::is_active() { - SPINE_CHECK(spine_object, false) - return spine_object->isActive(); + SPINE_CHECK(get_spine_object(), false) + return get_spine_object()->isActive(); } void SpineBone::set_active(bool v) { - SPINE_CHECK(spine_object,) - spine_object->setActive(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setActive(v); } // External feature functions void SpineBone::apply_world_transform_2d(const Variant &o) { - SPINE_CHECK(spine_object,) + SPINE_CHECK(get_spine_object(),) if (o.get_type() == Variant::OBJECT) { auto node2d = Object::cast_to(o.operator Object*()); if (node2d) { @@ -429,7 +429,7 @@ void SpineBone::apply_world_transform_2d(const Variant &o) { } Transform2D SpineBone::get_transform() { - SPINE_CHECK(spine_object, Transform2D()) + SPINE_CHECK(get_spine_object(), Transform2D()) Transform2D transform; transform.rotate(Math::deg2rad(-get_rotation())); transform.scale(Size2(get_scale_x(), get_scale_y())); @@ -438,7 +438,7 @@ Transform2D SpineBone::get_transform() { } void SpineBone::set_transform(Transform2D transform) { - SPINE_CHECK(spine_object,) + SPINE_CHECK(get_spine_object(),) Vector2 position = transform.get_origin(); position.y *= -1; float rotation = Math::rad2deg(-transform.get_rotation()); @@ -452,7 +452,7 @@ void SpineBone::set_transform(Transform2D transform) { } Transform2D SpineBone::get_global_transform() { - SPINE_CHECK(spine_object, Transform2D()) + SPINE_CHECK(get_spine_object(), Transform2D()) if (!get_spine_owner()) return get_transform(); if (!get_spine_owner()->is_visible_in_tree()) return get_transform(); Transform2D local; @@ -463,7 +463,7 @@ Transform2D SpineBone::get_global_transform() { } void SpineBone::set_global_transform(Transform2D transform) { - SPINE_CHECK(spine_object,) + SPINE_CHECK(get_spine_object(),) if (!get_spine_owner()) set_transform(transform); if (!get_spine_owner()->is_visible_in_tree()) return; transform = get_spine_owner()->get_global_transform().affine_inverse() * transform; diff --git a/spine-godot/spine_godot/SpineBone.h b/spine-godot/spine_godot/SpineBone.h index d04977865..7b5eaee40 100644 --- a/spine-godot/spine_godot/SpineBone.h +++ b/spine-godot/spine_godot/SpineBone.h @@ -38,7 +38,7 @@ class SpineSkeleton; class SpineSprite; -class SpineBone : public SpineObjectWrapper { +class SpineBone : public SpineSpriteOwnedObject { GDCLASS(SpineBone, SpineObjectWrapper) protected: diff --git a/spine-godot/spine_godot/SpineBoneData.cpp b/spine-godot/spine_godot/SpineBoneData.cpp index 85b3ee844..7749495e5 100644 --- a/spine-godot/spine_godot/SpineBoneData.cpp +++ b/spine-godot/spine_godot/SpineBoneData.cpp @@ -59,18 +59,18 @@ void SpineBoneData::_bind_methods() { } int SpineBoneData::get_index() { - SPINE_CHECK(spine_object, 0) - return spine_object->getIndex(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getIndex(); } String SpineBoneData::get_bone_name() { - SPINE_CHECK(spine_object, "") - return spine_object->getName().buffer(); + SPINE_CHECK(get_spine_object(), "") + return get_spine_object()->getName().buffer(); } Ref SpineBoneData::get_parent() { - SPINE_CHECK(spine_object, nullptr) - auto parent = spine_object->getParent(); + SPINE_CHECK(get_spine_object(), nullptr) + auto parent = get_spine_object()->getParent(); if (!parent) return nullptr; Ref parent_ref(memnew(SpineBoneData)); parent_ref->set_spine_object(get_spine_owner(), parent); @@ -78,112 +78,112 @@ Ref SpineBoneData::get_parent() { } float SpineBoneData::get_length() { - SPINE_CHECK(spine_object, 0) - return spine_object->getLength(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getLength(); } void SpineBoneData::set_length(float v) { - SPINE_CHECK(spine_object,) - spine_object->setLength(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setLength(v); } float SpineBoneData::get_x() { - SPINE_CHECK(spine_object, 0) - return spine_object->getX(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getX(); } void SpineBoneData::set_x(float v) { - SPINE_CHECK(spine_object,) - spine_object->setX(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setX(v); } float SpineBoneData::get_y() { - SPINE_CHECK(spine_object, 0) - return spine_object->getY(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getY(); } void SpineBoneData::set_y(float v) { - SPINE_CHECK(spine_object,) - spine_object->setY(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setY(v); } float SpineBoneData::get_rotation() { - SPINE_CHECK(spine_object, 0) - return spine_object->getRotation(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getRotation(); } void SpineBoneData::set_rotation(float v) { - SPINE_CHECK(spine_object,) - spine_object->setRotation(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setRotation(v); } float SpineBoneData::get_scale_x() { - SPINE_CHECK(spine_object, 0) - return spine_object->getScaleX(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getScaleX(); } void SpineBoneData::set_scale_x(float v) { - SPINE_CHECK(spine_object,) - spine_object->setScaleX(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setScaleX(v); } float SpineBoneData::get_scale_y() { - SPINE_CHECK(spine_object, 0) - return spine_object->getScaleY(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getScaleY(); } void SpineBoneData::set_scale_y(float v) { - SPINE_CHECK(spine_object,) - spine_object->setScaleY(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setScaleY(v); } float SpineBoneData::get_shear_x() { - SPINE_CHECK(spine_object, 0) - return spine_object->getShearX(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getShearX(); } void SpineBoneData::set_shear_x(float v) { - SPINE_CHECK(spine_object,) - spine_object->setShearX(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setShearX(v); } float SpineBoneData::get_shear_y() { - SPINE_CHECK(spine_object, 0) - return spine_object->getShearY(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getShearY(); } void SpineBoneData::set_shear_y(float v) { - SPINE_CHECK(spine_object,) - spine_object->setShearY(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setShearY(v); } SpineConstant::TransformMode SpineBoneData::get_transform_mode() { - SPINE_CHECK(spine_object, SpineConstant::TransformMode::TransformMode_Normal) - return (SpineConstant::TransformMode) spine_object->getTransformMode(); + SPINE_CHECK(get_spine_object(), SpineConstant::TransformMode::TransformMode_Normal) + return (SpineConstant::TransformMode) get_spine_object()->getTransformMode(); } void SpineBoneData::set_transform_mode(SpineConstant::TransformMode v) { - SPINE_CHECK(spine_object,) - spine_object->setTransformMode((spine::TransformMode) v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setTransformMode((spine::TransformMode) v); } bool SpineBoneData::is_skin_required() { - SPINE_CHECK(spine_object, false) - return spine_object->isSkinRequired(); + SPINE_CHECK(get_spine_object(), false) + return get_spine_object()->isSkinRequired(); } void SpineBoneData::set_skin_required(bool v) { - SPINE_CHECK(spine_object,) - spine_object->setSkinRequired(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setSkinRequired(v); } Color SpineBoneData::get_color() { - SPINE_CHECK(spine_object, Color()) - auto color = spine_object->getColor(); + SPINE_CHECK(get_spine_object(), Color()) + auto color = get_spine_object()->getColor(); return Color(color.r, color.g, color.b, color.a); } void SpineBoneData::set_color(Color color) { - SPINE_CHECK(spine_object,) - spine_object->getColor().set(color.r, color.g, color.b, color.a); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->getColor().set(color.r, color.g, color.b, color.a); } diff --git a/spine-godot/spine_godot/SpineBoneData.h b/spine-godot/spine_godot/SpineBoneData.h index 2445c11c6..62b74fa97 100644 --- a/spine-godot/spine_godot/SpineBoneData.h +++ b/spine-godot/spine_godot/SpineBoneData.h @@ -36,7 +36,7 @@ class SpineSkeletonDataResource; -class SpineBoneData : public SpineObjectWrapper { +class SpineBoneData : public SpineSkeletonDataResourceOwnedObject { GDCLASS(SpineBoneData, SpineObjectWrapper) protected: diff --git a/spine-godot/spine_godot/SpineCommon.h b/spine-godot/spine_godot/SpineCommon.h index 3d95aeb6e..dfdf37b1d 100644 --- a/spine-godot/spine_godot/SpineCommon.h +++ b/spine-godot/spine_godot/SpineCommon.h @@ -52,8 +52,6 @@ #define VARIANT_FLOAT Variant::REAL #endif -#include "SpineObjectWrapper.h" - #define SPINE_CHECK(obj, ret) \ if (!(obj)) { \ ERR_PRINT("Native Spine object not set."); \ @@ -62,4 +60,81 @@ #define SPINE_STRING(x) spine::String((x).utf8()) +// Can't do template classes with Godot's object model :( +class SpineObjectWrapper : public REFCOUNTED { + GDCLASS(SpineObjectWrapper, REFCOUNTED) + + Object* spine_owner; + void* spine_object; + +protected: + static void _bind_methods() { + ClassDB::bind_method(D_METHOD("_internal_spine_objects_invalidated"), &SpineObjectWrapper::spine_objects_invalidated); + } + + void spine_objects_invalidated() { + spine_object = nullptr; + spine_owner->disconnect("_internal_spine_objects_invalidated", this, "_internal_spine_objects_invalidated"); + } + + SpineObjectWrapper(): spine_owner(nullptr), spine_object(nullptr) { + } + + template void _set_spine_object_internal(const OWNER* _owner, OBJECT* _object) { + if (spine_owner) { + ERR_PRINT("Owner already set."); + return; + } + if (spine_object) { + ERR_PRINT("Object already set."); + return; + } + if (!_owner) { + ERR_PRINT("Owner must not be null."); + return; + } + + spine_owner = (Object*)_owner; + spine_object = _object; + spine_owner->connect("_internal_spine_objects_invalidated", this, "_internal_spine_objects_invalidated"); + } + + void *_get_spine_object_internal() { return spine_object; } + void *_get_spine_owner_internal() { return spine_owner; } +}; + +class SpineSprite; + +template class SpineSpriteOwnedObject: public SpineObjectWrapper { +public: + void set_spine_object(const SpineSprite* _owner, OBJECT* _object) { + _set_spine_object_internal(_owner, _object); + } + + OBJECT *get_spine_object() { + return (OBJECT*)_get_spine_object_internal(); + } + + SpineSprite *get_spine_owner() { + return (SpineSprite*)_get_spine_owner_internal(); + } +}; + +class SpineSkeletonDataResource; + +template class SpineSkeletonDataResourceOwnedObject: public SpineObjectWrapper { +public: + void set_spine_object(const SpineSkeletonDataResource* _owner, OBJECT* _object) { + _set_spine_object_internal(_owner, _object); + } + + OBJECT *get_spine_object() { + return (OBJECT*)_get_spine_object_internal(); + } + + SpineSkeletonDataResource *get_spine_owner() { + return (SpineSkeletonDataResource*)_get_spine_owner_internal(); + } +}; + #endif diff --git a/spine-godot/spine_godot/SpineConstraintData.cpp b/spine-godot/spine_godot/SpineConstraintData.cpp index 9a8aad157..84b25eed7 100644 --- a/spine-godot/spine_godot/SpineConstraintData.cpp +++ b/spine-godot/spine_godot/SpineConstraintData.cpp @@ -40,26 +40,26 @@ void SpineConstraintData::_bind_methods() { } String SpineConstraintData::get_constraint_name() { - SPINE_CHECK(spine_object, "") - return spine_object->getName().buffer(); + SPINE_CHECK(get_spine_object(), "") + return get_spine_object()->getName().buffer(); } int SpineConstraintData::get_order() { - SPINE_CHECK(spine_object, 0) - return (int)spine_object->getOrder(); + SPINE_CHECK(get_spine_object(), 0) + return (int)get_spine_object()->getOrder(); } void SpineConstraintData::set_order(int v) { - SPINE_CHECK(spine_object,) - spine_object->setOrder(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setOrder(v); } bool SpineConstraintData::is_skin_required() { - SPINE_CHECK(spine_object, false) - return spine_object->isSkinRequired(); + SPINE_CHECK(get_spine_object(), false) + return get_spine_object()->isSkinRequired(); } void SpineConstraintData::set_skin_required(bool v) { - SPINE_CHECK(spine_object,) - spine_object->setSkinRequired(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setSkinRequired(v); } diff --git a/spine-godot/spine_godot/SpineConstraintData.h b/spine-godot/spine_godot/SpineConstraintData.h index 258fc77a6..4e8371071 100644 --- a/spine-godot/spine_godot/SpineConstraintData.h +++ b/spine-godot/spine_godot/SpineConstraintData.h @@ -35,7 +35,7 @@ class SpineSkeletonDataResource; -class SpineConstraintData : public SpineObjectWrapper { +class SpineConstraintData : public SpineSkeletonDataResourceOwnedObject { GDCLASS(SpineConstraintData, SpineObjectWrapper) protected: diff --git a/spine-godot/spine_godot/SpineEvent.cpp b/spine-godot/spine_godot/SpineEvent.cpp index 1ab0c9917..e2d4fb85f 100644 --- a/spine-godot/spine_godot/SpineEvent.cpp +++ b/spine-godot/spine_godot/SpineEvent.cpp @@ -47,63 +47,63 @@ void SpineEvent::_bind_methods() { } Ref SpineEvent::get_data() { - SPINE_CHECK(spine_object, nullptr) + SPINE_CHECK(get_spine_object(), nullptr) Ref event_data(memnew(SpineEventData)); - event_data->set_spine_object(*get_spine_owner()->get_skeleton_data_res(), (spine::EventData*)&spine_object->getData()); + event_data->set_spine_object(*get_spine_owner()->get_skeleton_data_res(), (spine::EventData*)&get_spine_object()->getData()); return event_data; } float SpineEvent::get_time() { - SPINE_CHECK(spine_object, 0) - return spine_object->getTime(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getTime(); } int SpineEvent::get_int_value() { - SPINE_CHECK(spine_object, 0) - return spine_object->getIntValue(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getIntValue(); } void SpineEvent::set_int_value(int v) { - SPINE_CHECK(spine_object,) - spine_object->setIntValue(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setIntValue(v); } float SpineEvent::get_float_value() { - SPINE_CHECK(spine_object, 0) - return spine_object->getFloatValue(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getFloatValue(); } void SpineEvent::set_float_value(float v) { - SPINE_CHECK(spine_object,) - spine_object->setFloatValue(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setFloatValue(v); } String SpineEvent::get_string_value() { - SPINE_CHECK(spine_object, "") - return spine_object->getStringValue().buffer(); + SPINE_CHECK(get_spine_object(), "") + return get_spine_object()->getStringValue().buffer(); } void SpineEvent::set_string_value(const String &v) { - SPINE_CHECK(spine_object,) - spine_object->setStringValue(spine::String(v.utf8())); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setStringValue(spine::String(v.utf8())); } float SpineEvent::get_volume() { - SPINE_CHECK(spine_object, 0) - return spine_object->getVolume(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getVolume(); } void SpineEvent::set_volume(float v) { - SPINE_CHECK(spine_object,) - spine_object->setVolume(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setVolume(v); } float SpineEvent::get_balance() { - SPINE_CHECK(spine_object, 0) - return spine_object->getBalance(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getBalance(); } void SpineEvent::set_balance(float v) { - SPINE_CHECK(spine_object,) - spine_object->setBalance(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setBalance(v); } diff --git a/spine-godot/spine_godot/SpineEvent.h b/spine-godot/spine_godot/SpineEvent.h index da8f8960a..8245d71ac 100644 --- a/spine-godot/spine_godot/SpineEvent.h +++ b/spine-godot/spine_godot/SpineEvent.h @@ -36,7 +36,7 @@ class SpineSprite; -class SpineEvent : public SpineObjectWrapper { +class SpineEvent : public SpineSpriteOwnedObject { GDCLASS(SpineEvent, SpineObjectWrapper) protected: diff --git a/spine-godot/spine_godot/SpineEventData.cpp b/spine-godot/spine_godot/SpineEventData.cpp index 4713b7db6..d79eeaf8f 100644 --- a/spine-godot/spine_godot/SpineEventData.cpp +++ b/spine-godot/spine_godot/SpineEventData.cpp @@ -45,56 +45,56 @@ void SpineEventData::_bind_methods() { } String SpineEventData::get_event_name() { - SPINE_CHECK(spine_object, "") - return spine_object->getName().buffer(); + SPINE_CHECK(get_spine_object(), "") + return get_spine_object()->getName().buffer(); } int SpineEventData::get_int_value() { - SPINE_CHECK(spine_object, 0) - return spine_object->getIntValue(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getIntValue(); } void SpineEventData::set_int_value(int v) { - SPINE_CHECK(spine_object,) - spine_object->setIntValue(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setIntValue(v); } float SpineEventData::get_float_value() { - SPINE_CHECK(spine_object, 0) - return spine_object->getFloatValue(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getFloatValue(); } void SpineEventData::set_float_value(float v) { - SPINE_CHECK(spine_object,) - spine_object->setFloatValue(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setFloatValue(v); } String SpineEventData::get_string_value() { - SPINE_CHECK(spine_object, "") - return spine_object->getStringValue().buffer(); + SPINE_CHECK(get_spine_object(), "") + return get_spine_object()->getStringValue().buffer(); } void SpineEventData::set_string_value(const String &v) { - SPINE_CHECK(spine_object,) - spine_object->setStringValue(spine::String(v.utf8())); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setStringValue(spine::String(v.utf8())); } float SpineEventData::get_volume() { - SPINE_CHECK(spine_object, 0) - return spine_object->getVolume(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getVolume(); } void SpineEventData::set_volume(float v) { - SPINE_CHECK(spine_object,) - spine_object->setVolume(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setVolume(v); } float SpineEventData::get_balance() { - SPINE_CHECK(spine_object, 0) - return spine_object->getBalance(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getBalance(); } void SpineEventData::set_balance(float v) { - SPINE_CHECK(spine_object,) - spine_object->setBalance(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setBalance(v); } diff --git a/spine-godot/spine_godot/SpineEventData.h b/spine-godot/spine_godot/SpineEventData.h index 899425645..7f163199d 100644 --- a/spine-godot/spine_godot/SpineEventData.h +++ b/spine-godot/spine_godot/SpineEventData.h @@ -35,8 +35,8 @@ class SpineSkeletonDataResource; -class SpineEventData : public SpineObjectWrapper { - GDCLASS(SpineEventData, REFCOUNTED); +class SpineEventData : public SpineSkeletonDataResourceOwnedObject { + GDCLASS(SpineEventData, SpineObjectWrapper); protected: static void _bind_methods(); diff --git a/spine-godot/spine_godot/SpineIkConstraint.cpp b/spine-godot/spine_godot/SpineIkConstraint.cpp index febe45069..f117ce697 100644 --- a/spine-godot/spine_godot/SpineIkConstraint.cpp +++ b/spine-godot/spine_godot/SpineIkConstraint.cpp @@ -54,18 +54,18 @@ void SpineIkConstraint::_bind_methods() { } void SpineIkConstraint::update() { - SPINE_CHECK(spine_object,) - spine_object->update(); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->update(); } int SpineIkConstraint::get_order() { - SPINE_CHECK(spine_object, 0) - return spine_object->getOrder(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getOrder(); } Ref SpineIkConstraint::get_data() { - SPINE_CHECK(spine_object, nullptr) - auto &ik_constraint_data = spine_object->getData(); + SPINE_CHECK(get_spine_object(), nullptr) + auto &ik_constraint_data = get_spine_object()->getData(); Ref ik_constraint_data_ref(memnew(SpineIkConstraintData)); ik_constraint_data_ref->set_spine_object(*get_spine_owner()->get_skeleton_data_res(), &ik_constraint_data); return ik_constraint_data_ref; @@ -73,8 +73,8 @@ Ref SpineIkConstraint::get_data() { Array SpineIkConstraint::get_bones() { Array result; - SPINE_CHECK(spine_object, result) - auto &bones = spine_object->getBones(); + SPINE_CHECK(get_spine_object(), result) + auto &bones = get_spine_object()->getBones(); result.resize((int)bones.size()); for (int i = 0; i < bones.size(); ++i) { auto bone = bones[i]; @@ -86,8 +86,8 @@ Array SpineIkConstraint::get_bones() { } Ref SpineIkConstraint::get_target() { - SPINE_CHECK(spine_object, nullptr) - auto target = spine_object->getTarget(); + SPINE_CHECK(get_spine_object(), nullptr) + auto target = get_spine_object()->getTarget(); if (!target) return nullptr; Ref target_ref(memnew(SpineBone)); target_ref->set_spine_object(get_spine_owner(), target); @@ -95,65 +95,65 @@ Ref SpineIkConstraint::get_target() { } void SpineIkConstraint::set_target(Ref v) { - SPINE_CHECK(spine_object,) - spine_object->setTarget(v.is_valid() && v->get_spine_object() ? v->get_spine_object() : nullptr); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setTarget(v.is_valid() && v->get_spine_object() ? v->get_spine_object() : nullptr); } int SpineIkConstraint::get_bend_direction() { - SPINE_CHECK(spine_object, 0) - return spine_object->getBendDirection(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getBendDirection(); } void SpineIkConstraint::set_bend_direction(int v) { - SPINE_CHECK(spine_object,) - spine_object->setBendDirection(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setBendDirection(v); } bool SpineIkConstraint::get_compress() { - SPINE_CHECK(spine_object, false) - return spine_object->getCompress(); + SPINE_CHECK(get_spine_object(), false) + return get_spine_object()->getCompress(); } void SpineIkConstraint::set_compress(bool v) { - SPINE_CHECK(spine_object,) - spine_object->setCompress(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setCompress(v); } bool SpineIkConstraint::get_stretch() { - SPINE_CHECK(spine_object, false) - return spine_object->getStretch(); + SPINE_CHECK(get_spine_object(), false) + return get_spine_object()->getStretch(); } void SpineIkConstraint::set_stretch(bool v) { - SPINE_CHECK(spine_object,) - spine_object->setStretch(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setStretch(v); } float SpineIkConstraint::get_mix() { - SPINE_CHECK(spine_object, 0) - return spine_object->getMix(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getMix(); } void SpineIkConstraint::set_mix(float v) { - SPINE_CHECK(spine_object,) - spine_object->setMix(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setMix(v); } float SpineIkConstraint::get_softness() { - SPINE_CHECK(spine_object, 0) - return spine_object->getSoftness(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getSoftness(); } void SpineIkConstraint::set_softness(float v) { - SPINE_CHECK(spine_object,) - spine_object->setSoftness(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setSoftness(v); } bool SpineIkConstraint::is_active() { - SPINE_CHECK(spine_object, false) - return spine_object->isActive(); + SPINE_CHECK(get_spine_object(), false) + return get_spine_object()->isActive(); } void SpineIkConstraint::set_active(bool v) { - SPINE_CHECK(spine_object,) - spine_object->setActive(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setActive(v); } diff --git a/spine-godot/spine_godot/SpineIkConstraint.h b/spine-godot/spine_godot/SpineIkConstraint.h index 2a0aff8d5..e8600ad6b 100644 --- a/spine-godot/spine_godot/SpineIkConstraint.h +++ b/spine-godot/spine_godot/SpineIkConstraint.h @@ -36,7 +36,7 @@ class SpineBone; class SpineSprite; -class SpineIkConstraint : public SpineObjectWrapper { +class SpineIkConstraint : public SpineSpriteOwnedObject { GDCLASS(SpineIkConstraint, SpineObjectWrapper) protected: diff --git a/spine-godot/spine_godot/SpineIkConstraintData.cpp b/spine-godot/spine_godot/SpineIkConstraintData.cpp index 3de3e2995..ed28432d8 100644 --- a/spine-godot/spine_godot/SpineIkConstraintData.cpp +++ b/spine-godot/spine_godot/SpineIkConstraintData.cpp @@ -50,7 +50,7 @@ void SpineIkConstraintData::_bind_methods() { Array SpineIkConstraintData::get_bones() { Array result; - SPINE_CHECK(spine_object, result) + SPINE_CHECK(get_spine_object(), result) auto bones = get_spine_constraint_data()->getBones(); result.resize((int)bones.size()); for (int i = 0; i < bones.size(); ++i) { @@ -62,7 +62,7 @@ Array SpineIkConstraintData::get_bones() { } Ref SpineIkConstraintData::get_target() { - SPINE_CHECK(spine_object, nullptr) + SPINE_CHECK(get_spine_object(), nullptr) auto target = get_spine_constraint_data()->getTarget(); if (!target) return nullptr; Ref target_ref(memnew(SpineBoneData)); @@ -71,66 +71,66 @@ Ref SpineIkConstraintData::get_target() { } void SpineIkConstraintData::set_target(Ref v) { - SPINE_CHECK(spine_object,) + SPINE_CHECK(get_spine_object(),) get_spine_constraint_data()->setTarget(v.is_valid() && v->get_spine_object() ? v->get_spine_object() : nullptr); } int SpineIkConstraintData::get_bend_direction() { - SPINE_CHECK(spine_object, 0) + SPINE_CHECK(get_spine_object(), 0) return get_spine_constraint_data()->getBendDirection(); } void SpineIkConstraintData::set_bend_direction(int v) { - SPINE_CHECK(spine_object,) + SPINE_CHECK(get_spine_object(),) get_spine_constraint_data()->setBendDirection(v); } bool SpineIkConstraintData::get_compress() { - SPINE_CHECK(spine_object, false) + SPINE_CHECK(get_spine_object(), false) return get_spine_constraint_data()->getCompress(); } void SpineIkConstraintData::set_compress(bool v) { - SPINE_CHECK(spine_object,) + SPINE_CHECK(get_spine_object(),) get_spine_constraint_data()->setCompress(v); } bool SpineIkConstraintData::get_stretch() { - SPINE_CHECK(spine_object, false) + SPINE_CHECK(get_spine_object(), false) return get_spine_constraint_data()->getStretch(); } void SpineIkConstraintData::set_stretch(bool v) { - SPINE_CHECK(spine_object,) + SPINE_CHECK(get_spine_object(),) get_spine_constraint_data()->setStretch(v); } bool SpineIkConstraintData::get_uniform() { - SPINE_CHECK(spine_object, false) + SPINE_CHECK(get_spine_object(), false) return get_spine_constraint_data()->getUniform(); } void SpineIkConstraintData::set_uniform(bool v) { - SPINE_CHECK(spine_object,) + SPINE_CHECK(get_spine_object(),) get_spine_constraint_data()->setUniform(v); } float SpineIkConstraintData::get_mix() { - SPINE_CHECK(spine_object, 0) + SPINE_CHECK(get_spine_object(), 0) return get_spine_constraint_data()->getMix(); } void SpineIkConstraintData::set_mix(float v) { - SPINE_CHECK(spine_object,) + SPINE_CHECK(get_spine_object(),) get_spine_constraint_data()->setMix(v); } float SpineIkConstraintData::get_softness() { - SPINE_CHECK(spine_object, 0) + SPINE_CHECK(get_spine_object(), 0) return get_spine_constraint_data()->getSoftness(); } void SpineIkConstraintData::set_softness(float v) { - SPINE_CHECK(spine_object,) + SPINE_CHECK(get_spine_object(),) get_spine_constraint_data()->setSoftness(v); } diff --git a/spine-godot/spine_godot/SpineObjectWrapper.cpp b/spine-godot/spine_godot/SpineObjectWrapper.cpp deleted file mode 100644 index 2b4177e3d..000000000 --- a/spine-godot/spine_godot/SpineObjectWrapper.cpp +++ /dev/null @@ -1,33 +0,0 @@ -/****************************************************************************** -* Spine Runtimes License Agreement - * Last updated January 1, 2020. Replaces all prior versions. - * - * Copyright (c) 2013-2020, Esoteric Software LLC - * - * Integration of the Spine Runtimes into software or otherwise creating - * derivative works of the Spine Runtimes is permitted under the terms and - * conditions of Section 2 of the Spine Editor License Agreement: - * http://esotericsoftware.com/spine-editor-license - * - * Otherwise, it is permitted to integrate the Spine Runtimes into software - * or otherwise create derivative works of the Spine Runtimes (collectively, - * "Products"), provided that each user of the Products must obtain their own - * Spine Editor license and redistribution of the Products in any form must - * include this license and copyright notice. - * - * THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, - * BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - *****************************************************************************/ - -#include "SpineObjectWrapper.h" - - - diff --git a/spine-godot/spine_godot/SpineObjectWrapper.h b/spine-godot/spine_godot/SpineObjectWrapper.h deleted file mode 100644 index b197efaf5..000000000 --- a/spine-godot/spine_godot/SpineObjectWrapper.h +++ /dev/null @@ -1,61 +0,0 @@ -/****************************************************************************** -* Spine Runtimes License Agreement - * Last updated January 1, 2020. Replaces all prior versions. - * - * Copyright (c) 2013-2020, Esoteric Software LLC - * - * Integration of the Spine Runtimes into software or otherwise creating - * derivative works of the Spine Runtimes is permitted under the terms and - * conditions of Section 2 of the Spine Editor License Agreement: - * http://esotericsoftware.com/spine-editor-license - * - * Otherwise, it is permitted to integrate the Spine Runtimes into software - * or otherwise create derivative works of the Spine Runtimes (collectively, - * "Products"), provided that each user of the Products must obtain their own - * Spine Editor license and redistribution of the Products in any form must - * include this license and copyright notice. - * - * THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, - * BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - *****************************************************************************/ - -#ifndef GODOT_SPINEOBJECTWRAPPER_H -#define GODOT_SPINEOBJECTWRAPPER_H - -#include "SpineCommon.h" - -template class SpineObjectWrapper: public REFCOUNTED { -protected: - Object *owner; - OBJECT *spine_object; - -public: - SpineObjectWrapper(): owner(nullptr), spine_object(nullptr) {}; - - void set_spine_object(const OWNER *_owner, OBJECT *_object) { - if (!_owner) { - ERR_PRINT("Owner must not be null."); - return; - } - owner = (Object*)_owner; - spine_object = _object; - } - - OBJECT *get_spine_object() { - return spine_object; - } - - OWNER *get_spine_owner() { - return (OWNER*)owner; - } -}; - -#endif diff --git a/spine-godot/spine_godot/SpinePathConstraint.cpp b/spine-godot/spine_godot/SpinePathConstraint.cpp index 460c24f5f..d40a08aad 100644 --- a/spine-godot/spine_godot/SpinePathConstraint.cpp +++ b/spine-godot/spine_godot/SpinePathConstraint.cpp @@ -54,69 +54,69 @@ void SpinePathConstraint::_bind_methods() { } void SpinePathConstraint::update() { - SPINE_CHECK(spine_object,) - spine_object->update(); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->update(); } int SpinePathConstraint::get_order() { - SPINE_CHECK(spine_object, 0) - return spine_object->getOrder(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getOrder(); } float SpinePathConstraint::get_position() { - SPINE_CHECK(spine_object, 0) - return spine_object->getPosition(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getPosition(); } void SpinePathConstraint::set_position(float v) { - SPINE_CHECK(spine_object,) - spine_object->setPosition(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setPosition(v); } float SpinePathConstraint::get_spacing() { - SPINE_CHECK(spine_object, 0) - return spine_object->getSpacing(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getSpacing(); } void SpinePathConstraint::set_spacing(float v) { - SPINE_CHECK(spine_object,) - spine_object->setSpacing(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setSpacing(v); } float SpinePathConstraint::get_mix_rotate() { - SPINE_CHECK(spine_object, 0) - return spine_object->getMixRotate(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getMixRotate(); } void SpinePathConstraint::set_mix_rotate(float v) { - SPINE_CHECK(spine_object,) - spine_object->setMixRotate(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setMixRotate(v); } float SpinePathConstraint::get_mix_x() { - SPINE_CHECK(spine_object, 0) - return spine_object->getMixX(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getMixX(); } void SpinePathConstraint::set_mix_x(float v) { - SPINE_CHECK(spine_object,) - spine_object->setMixX(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setMixX(v); } float SpinePathConstraint::get_mix_y() { - SPINE_CHECK(spine_object, 0) - return spine_object->getMixY(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getMixY(); } void SpinePathConstraint::set_mix_y(float v) { - SPINE_CHECK(spine_object,) - spine_object->setMixY(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setMixY(v); } Array SpinePathConstraint::get_bones() { Array result; - SPINE_CHECK(spine_object, result) - auto &bones = spine_object->getBones(); + SPINE_CHECK(get_spine_object(), result) + auto &bones = get_spine_object()->getBones(); result.resize((int)bones.size()); for (int i = 0; i < bones.size(); ++i) { auto bone = bones[i]; @@ -128,8 +128,8 @@ Array SpinePathConstraint::get_bones() { } Ref SpinePathConstraint::get_target() { - SPINE_CHECK(spine_object, nullptr) - auto target = spine_object->getTarget(); + SPINE_CHECK(get_spine_object(), nullptr) + auto target = get_spine_object()->getTarget(); if (!target) return nullptr; Ref target_ref(memnew(SpineSlot)); target_ref->set_spine_object(get_spine_owner(), target); @@ -137,24 +137,24 @@ Ref SpinePathConstraint::get_target() { } void SpinePathConstraint::set_target(Ref v) { - SPINE_CHECK(spine_object,) - spine_object->setTarget(v.is_valid() && v->get_spine_object() ? v->get_spine_object() : nullptr); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setTarget(v.is_valid() && v->get_spine_object() ? v->get_spine_object() : nullptr); } Ref SpinePathConstraint::get_data() { - SPINE_CHECK(spine_object, nullptr) - auto &data = spine_object->getData(); + SPINE_CHECK(get_spine_object(), nullptr) + auto &data = get_spine_object()->getData(); Ref data_ref(memnew(SpinePathConstraintData)); data_ref->set_spine_object(*get_spine_owner()->get_skeleton_data_res(), &data); return data_ref; } bool SpinePathConstraint::is_active() { - SPINE_CHECK(spine_object, false) - return spine_object->isActive(); + SPINE_CHECK(get_spine_object(), false) + return get_spine_object()->isActive(); } void SpinePathConstraint::set_active(bool v) { - SPINE_CHECK(spine_object,) - spine_object->setActive(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setActive(v); } diff --git a/spine-godot/spine_godot/SpinePathConstraint.h b/spine-godot/spine_godot/SpinePathConstraint.h index e8afe7723..3e19cf452 100644 --- a/spine-godot/spine_godot/SpinePathConstraint.h +++ b/spine-godot/spine_godot/SpinePathConstraint.h @@ -34,7 +34,7 @@ #include "SpineSlot.h" #include -class SpinePathConstraint : public SpineObjectWrapper { +class SpinePathConstraint : public SpineSpriteOwnedObject { GDCLASS(SpinePathConstraint, SpineObjectWrapper) protected: diff --git a/spine-godot/spine_godot/SpineSkeletonDataResource.cpp b/spine-godot/spine_godot/SpineSkeletonDataResource.cpp index e6eac32c4..fe1b70dab 100644 --- a/spine-godot/spine_godot/SpineSkeletonDataResource.cpp +++ b/spine-godot/spine_godot/SpineSkeletonDataResource.cpp @@ -117,6 +117,7 @@ void SpineSkeletonDataResource::_bind_methods() { ClassDB::bind_method(D_METHOD("get_fps"), &SpineSkeletonDataResource::get_fps); ADD_SIGNAL(MethodInfo("skeleton_data_changed")); + ADD_SIGNAL(MethodInfo("_internal_spine_objects_invalidated")); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "atlas_res", PropertyHint::PROPERTY_HINT_RESOURCE_TYPE, "SpineAtlasResource"), "set_atlas_res", "get_atlas_res"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "skeleton_file_res", PropertyHint::PROPERTY_HINT_RESOURCE_TYPE, "SpineSkeletonFileResource"), "set_skeleton_file_res", "get_skeleton_file_res"); @@ -146,6 +147,8 @@ void SpineSkeletonDataResource::update_skeleton_data() { animation_state_data = nullptr; } + emit_signal("_internal_spine_objects_invalidated"); + if (atlas_res.is_valid() && skeleton_file_res.is_valid()) { load_resources(atlas_res->get_spine_atlas(), skeleton_file_res->get_json(), skeleton_file_res->get_binary()); } diff --git a/spine-godot/spine_godot/SpineSkin.cpp b/spine-godot/spine_godot/SpineSkin.cpp index 3bebcfec2..992121a59 100644 --- a/spine-godot/spine_godot/SpineSkin.cpp +++ b/spine-godot/spine_godot/SpineSkin.cpp @@ -51,11 +51,11 @@ SpineSkin::SpineSkin() : owns_skin(false) { } SpineSkin::~SpineSkin() { - if (owns_skin) delete spine_object; + if (owns_skin) delete get_spine_object(); } Ref SpineSkin::init(const String &name, SpineSprite *sprite) { - if (spine_object) { + if (get_spine_object()) { ERR_PRINT("Can not initialize an already initialized skin."); return this; } @@ -73,13 +73,13 @@ Ref SpineSkin::init(const String &name, SpineSprite *sprite) { } void SpineSkin::set_attachment(int slot_index, const String &name, Ref attachment) { - SPINE_CHECK(spine_object,) - spine_object->setAttachment(slot_index, SPINE_STRING(name), attachment.is_valid() && attachment->get_spine_object()? attachment->get_spine_object() : nullptr); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setAttachment(slot_index, SPINE_STRING(name), attachment.is_valid() && attachment->get_spine_owner()? attachment->get_spine_object() : nullptr); } Ref SpineSkin::get_attachment(int slot_index, const String &name) { - SPINE_CHECK(spine_object, nullptr) - auto attachment = spine_object->getAttachment(slot_index, SPINE_STRING(name)); + SPINE_CHECK(get_spine_object(), nullptr) + auto attachment = get_spine_object()->getAttachment(slot_index, SPINE_STRING(name)); if (attachment) return nullptr; Ref attachment_ref(memnew(SpineAttachment)); attachment_ref->set_spine_object(get_spine_owner(), attachment); @@ -87,15 +87,15 @@ Ref SpineSkin::get_attachment(int slot_index, const String &nam } void SpineSkin::remove_attachment(int slot_index, const String &name) { - SPINE_CHECK(spine_object,) - spine_object->removeAttachment(slot_index, SPINE_STRING(name)); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->removeAttachment(slot_index, SPINE_STRING(name)); } Array SpineSkin::find_names_for_slot(int slot_index) { Array result; - SPINE_CHECK(spine_object, result) + SPINE_CHECK(get_spine_object(), result) spine::Vector names; - spine_object->findNamesForSlot(slot_index, names); + get_spine_object()->findNamesForSlot(slot_index, names); result.resize((int)names.size()); for (int i = 0; i < names.size(); ++i) { result[i] = names[i].buffer(); @@ -105,9 +105,9 @@ Array SpineSkin::find_names_for_slot(int slot_index) { Array SpineSkin::find_attachments_for_slot(int slot_index) { Array result; - SPINE_CHECK(spine_object, result) + SPINE_CHECK(get_spine_object(), result) spine::Vector attachments; - spine_object->findAttachmentsForSlot(slot_index, attachments); + get_spine_object()->findAttachmentsForSlot(slot_index, attachments); result.resize((int)attachments.size()); for (int i = 0; i < attachments.size(); ++i) { if (!attachments[i]) { @@ -122,32 +122,32 @@ Array SpineSkin::find_attachments_for_slot(int slot_index) { } String SpineSkin::get_name() { - SPINE_CHECK(spine_object, "") - return spine_object->getName().buffer(); + SPINE_CHECK(get_spine_object(), "") + return get_spine_object()->getName().buffer(); } void SpineSkin::add_skin(Ref other) { - SPINE_CHECK(spine_object,) + SPINE_CHECK(get_spine_object(),) if (!other.is_valid() || !other->get_spine_object()) { ERR_PRINT("other is not a valid SpineSkin."); return; } - spine_object->addSkin(other->get_spine_object()); + get_spine_object()->addSkin(other->get_spine_object()); } void SpineSkin::copy_skin(Ref other) { - SPINE_CHECK(spine_object,) + SPINE_CHECK(get_spine_object(),) if (!other.is_valid() || !other->get_spine_object()) { ERR_PRINT("other is not a valid SpineSkin."); return; } - spine_object->copySkin(other->get_spine_object()); + get_spine_object()->copySkin(other->get_spine_object()); } Array SpineSkin::get_attachments() { Array result; - SPINE_CHECK(spine_object, result) - auto entries = spine_object->getAttachments(); + SPINE_CHECK(get_spine_object(), result) + auto entries = get_spine_object()->getAttachments(); while(entries.hasNext()) { spine::Skin::AttachmentMap::Entry &entry = entries.next(); Ref entry_ref = memnew(SpineSkinEntry); @@ -164,8 +164,8 @@ Array SpineSkin::get_attachments() { Array SpineSkin::get_bones() { Array result; - SPINE_CHECK(spine_object, result) - auto bones = spine_object->getBones(); + SPINE_CHECK(get_spine_object(), result) + auto bones = get_spine_object()->getBones(); result.resize((int)bones.size()); for (int i = 0; i < bones.size(); ++i) { Ref bone_ref(memnew(SpineBoneData)); @@ -177,8 +177,8 @@ Array SpineSkin::get_bones() { Array SpineSkin::get_constraints() { Array result; - SPINE_CHECK(spine_object, result) - auto constraints = spine_object->getConstraints(); + SPINE_CHECK(get_spine_object(), result) + auto constraints = get_spine_object()->getConstraints(); result.resize((int)constraints.size()); for (int i = 0; i < constraints.size(); ++i) { Ref constraint_ref(memnew(SpineConstraintData)); diff --git a/spine-godot/spine_godot/SpineSkin.h b/spine-godot/spine_godot/SpineSkin.h index 00e6f1ea6..deed0bdda 100644 --- a/spine-godot/spine_godot/SpineSkin.h +++ b/spine-godot/spine_godot/SpineSkin.h @@ -36,7 +36,7 @@ class SpineSkeletonDataResource; class SpineSprite; -class SpineSkin : public SpineObjectWrapper { +class SpineSkin : public SpineSkeletonDataResourceOwnedObject { GDCLASS(SpineSkin, SpineObjectWrapper) protected: diff --git a/spine-godot/spine_godot/SpineSlot.cpp b/spine-godot/spine_godot/SpineSlot.cpp index 375907440..b4344ad5a 100644 --- a/spine-godot/spine_godot/SpineSlot.cpp +++ b/spine-godot/spine_godot/SpineSlot.cpp @@ -53,58 +53,58 @@ void SpineSlot::_bind_methods() { } void SpineSlot::set_to_setup_pose() { - SPINE_CHECK(spine_object,) - spine_object->setToSetupPose(); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setToSetupPose(); } Ref SpineSlot::get_data() { - SPINE_CHECK(spine_object, nullptr) - auto &slot_data = spine_object->getData(); + SPINE_CHECK(get_spine_object(), nullptr) + auto &slot_data = get_spine_object()->getData(); Ref slot_data_ref(memnew(SpineSlotData)); slot_data_ref->set_spine_object(*get_spine_owner()->get_skeleton_data_res(), &slot_data); return slot_data_ref; } Ref SpineSlot::get_bone() { - SPINE_CHECK(spine_object, nullptr) - auto &bone = spine_object->getBone(); + SPINE_CHECK(get_spine_object(), nullptr) + auto &bone = get_spine_object()->getBone(); Ref bone_ref(memnew(SpineBone)); bone_ref->set_spine_object(get_spine_owner(), &bone); return bone_ref; } Color SpineSlot::get_color() { - SPINE_CHECK(spine_object, Color(0, 0, 0, 0)) - auto &color = spine_object->getColor(); + SPINE_CHECK(get_spine_object(), Color(0, 0, 0, 0)) + auto &color = get_spine_object()->getColor(); return Color(color.r, color.g, color.b, color.a); } void SpineSlot::set_color(Color v) { - SPINE_CHECK(spine_object,) - auto &color = spine_object->getColor(); + SPINE_CHECK(get_spine_object(),) + auto &color = get_spine_object()->getColor(); color.set(v.r, v.g, v.b, v.a); } Color SpineSlot::get_dark_color() { - SPINE_CHECK(spine_object, Color(0, 0, 0, 0)) - auto &color = spine_object->getDarkColor(); + SPINE_CHECK(get_spine_object(), Color(0, 0, 0, 0)) + auto &color = get_spine_object()->getDarkColor(); return Color(color.r, color.g, color.b, color.a); } void SpineSlot::set_dark_color(Color v) { - SPINE_CHECK(spine_object,) - auto &color = spine_object->getDarkColor(); + SPINE_CHECK(get_spine_object(),) + auto &color = get_spine_object()->getDarkColor(); color.set(v.r, v.g, v.b, v.a); } bool SpineSlot::has_dark_color() { - SPINE_CHECK(spine_object, false) - return spine_object->hasDarkColor(); + SPINE_CHECK(get_spine_object(), false) + return get_spine_object()->hasDarkColor(); } Ref SpineSlot::get_attachment() { - SPINE_CHECK(spine_object, nullptr) - auto attachment = spine_object->getAttachment(); + SPINE_CHECK(get_spine_object(), nullptr) + auto attachment = get_spine_object()->getAttachment(); if (!attachment) return nullptr; Ref attachment_ref(memnew(SpineAttachment)); attachment_ref->set_spine_object(*get_spine_owner()->get_skeleton_data_res(), attachment); @@ -112,24 +112,24 @@ Ref SpineSlot::get_attachment() { } void SpineSlot::set_attachment(Ref v) { - SPINE_CHECK(spine_object,) - spine_object->setAttachment(v.is_valid() && v->get_spine_object() ? v->get_spine_object() : nullptr); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setAttachment(v.is_valid() && v->get_spine_object() ? v->get_spine_object() : nullptr); } int SpineSlot::get_attachment_state() { - SPINE_CHECK(spine_object, 0) - return spine_object->getAttachmentState(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getAttachmentState(); } void SpineSlot::set_attachment_state(int v) { - SPINE_CHECK(spine_object,) - spine_object->setAttachmentState(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setAttachmentState(v); } Array SpineSlot::get_deform() { Array result; - SPINE_CHECK(spine_object, result) - auto &deform = spine_object->getDeform(); + SPINE_CHECK(get_spine_object(), result) + auto &deform = get_spine_object()->getDeform(); result.resize((int)deform.size()); for (int i = 0; i < (int)deform.size(); ++i) { result[i] = deform[i]; @@ -138,8 +138,8 @@ Array SpineSlot::get_deform() { } void SpineSlot::set_deform(Array v) { - SPINE_CHECK(spine_object,) - auto &deform = spine_object->getDeform(); + SPINE_CHECK(get_spine_object(),) + auto &deform = get_spine_object()->getDeform(); deform.setSize(v.size(), 0); for (int i = 0; i < v.size(); ++i) { deform[i] = v[i]; @@ -147,11 +147,11 @@ void SpineSlot::set_deform(Array v) { } int SpineSlot::get_sequence_index() { - SPINE_CHECK(spine_object, 0) - return spine_object->getAttachmentState(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getAttachmentState(); } void SpineSlot::set_sequence_index(int v) { - SPINE_CHECK(spine_object,) - spine_object->setAttachmentState(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setAttachmentState(v); } diff --git a/spine-godot/spine_godot/SpineSlot.h b/spine-godot/spine_godot/SpineSlot.h index 83a0ab120..4a39e29a9 100644 --- a/spine-godot/spine_godot/SpineSlot.h +++ b/spine-godot/spine_godot/SpineSlot.h @@ -38,7 +38,7 @@ class SpineSkeleton; class SpineSprite; -class SpineSlot : public SpineObjectWrapper { +class SpineSlot : public SpineSpriteOwnedObject { GDCLASS(SpineSlot, SpineObjectWrapper) protected: diff --git a/spine-godot/spine_godot/SpineSlotData.cpp b/spine-godot/spine_godot/SpineSlotData.cpp index b2210cc89..9b81f105b 100644 --- a/spine-godot/spine_godot/SpineSlotData.cpp +++ b/spine-godot/spine_godot/SpineSlotData.cpp @@ -48,71 +48,71 @@ void SpineSlotData::_bind_methods() { } int SpineSlotData::get_index() { - SPINE_CHECK(spine_object, 0) - return spine_object->getIndex(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getIndex(); } String SpineSlotData::get_name() { - SPINE_CHECK(spine_object, String("")) - return spine_object->getName().buffer(); + SPINE_CHECK(get_spine_object(), String("")) + return get_spine_object()->getName().buffer(); } Ref SpineSlotData::get_bone_data() { - SPINE_CHECK(spine_object, nullptr) - auto &bone_data = spine_object->getBoneData(); + SPINE_CHECK(get_spine_object(), nullptr) + auto &bone_data = get_spine_object()->getBoneData(); Ref bone_data_ref(memnew(SpineBoneData)); bone_data_ref->set_spine_object(get_spine_owner(), &bone_data); return bone_data_ref; } Color SpineSlotData::get_color() { - SPINE_CHECK(spine_object, Color(0, 0, 0, 0)) - auto &color = spine_object->getColor(); + SPINE_CHECK(get_spine_object(), Color(0, 0, 0, 0)) + auto &color = get_spine_object()->getColor(); return Color(color.r, color.g, color.b, color.a); } void SpineSlotData::set_color(Color v) { - SPINE_CHECK(spine_object,) - auto &color = spine_object->getColor(); + SPINE_CHECK(get_spine_object(),) + auto &color = get_spine_object()->getColor(); color.set(v.r, v.g, v.b, v.a); } Color SpineSlotData::get_dark_color() { - SPINE_CHECK(spine_object, Color(0, 0, 0, 0)) - auto &color = spine_object->getDarkColor(); + SPINE_CHECK(get_spine_object(), Color(0, 0, 0, 0)) + auto &color = get_spine_object()->getDarkColor(); return Color(color.r, color.g, color.b, color.a); } void SpineSlotData::set_dark_color(Color v) { - SPINE_CHECK(spine_object,) - auto &color = spine_object->getDarkColor(); + SPINE_CHECK(get_spine_object(),) + auto &color = get_spine_object()->getDarkColor(); color.set(v.r, v.g, v.b, v.a); } bool SpineSlotData::has_dark_color() { - SPINE_CHECK(spine_object, false) - return spine_object->hasDarkColor(); + SPINE_CHECK(get_spine_object(), false) + return get_spine_object()->hasDarkColor(); } void SpineSlotData::set_has_dark_color(bool v) { - SPINE_CHECK(spine_object,) - spine_object->setHasDarkColor(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setHasDarkColor(v); } String SpineSlotData::get_attachment_name() { - SPINE_CHECK(spine_object, "") - return spine_object->getAttachmentName().buffer(); + SPINE_CHECK(get_spine_object(), "") + return get_spine_object()->getAttachmentName().buffer(); } void SpineSlotData::set_attachment_name(const String &v) { - SPINE_CHECK(spine_object,) - spine_object->setAttachmentName(SPINE_STRING(v)); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setAttachmentName(SPINE_STRING(v)); } SpineConstant::BlendMode SpineSlotData::get_blend_mode() { - SPINE_CHECK(spine_object, SpineConstant::BlendMode_Normal) - return (SpineConstant::BlendMode)spine_object->getBlendMode(); + SPINE_CHECK(get_spine_object(), SpineConstant::BlendMode_Normal) + return (SpineConstant::BlendMode)get_spine_object()->getBlendMode(); } void SpineSlotData::set_blend_mode(SpineConstant::BlendMode v) { - SPINE_CHECK(spine_object,) - spine_object->setBlendMode((spine::BlendMode) v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setBlendMode((spine::BlendMode) v); } diff --git a/spine-godot/spine_godot/SpineSlotData.h b/spine-godot/spine_godot/SpineSlotData.h index ef9663937..f48fab983 100644 --- a/spine-godot/spine_godot/SpineSlotData.h +++ b/spine-godot/spine_godot/SpineSlotData.h @@ -36,7 +36,7 @@ class SpineSkeletonDataResource; -class SpineSlotData : public SpineObjectWrapper { +class SpineSlotData : public SpineSkeletonDataResourceOwnedObject { GDCLASS(SpineSlotData, SpineObjectWrapper) protected: diff --git a/spine-godot/spine_godot/SpineSprite.cpp b/spine-godot/spine_godot/SpineSprite.cpp index 6e0545e33..2de327ff1 100644 --- a/spine-godot/spine_godot/SpineSprite.cpp +++ b/spine-godot/spine_godot/SpineSprite.cpp @@ -63,6 +63,7 @@ void SpineSprite::_bind_methods() { ADD_SIGNAL(MethodInfo("before_animation_state_apply", PropertyInfo(Variant::OBJECT, "spine_sprite", PROPERTY_HINT_TYPE_STRING, "SpineSprite"))); ADD_SIGNAL(MethodInfo("before_world_transforms_change", PropertyInfo(Variant::OBJECT, "spine_sprite", PROPERTY_HINT_TYPE_STRING, "SpineSprite"))); ADD_SIGNAL(MethodInfo("world_transforms_changed", PropertyInfo(Variant::OBJECT, "spine_sprite", PROPERTY_HINT_TYPE_STRING, "SpineSprite"))); + ADD_SIGNAL(MethodInfo("_internal_spine_objects_invalidated")); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "skeleton_data_res", PropertyHint::PROPERTY_HINT_RESOURCE_TYPE, "SpineSkeletonDataResource"), "set_skeleton_data_res", "get_skeleton_data_res"); ADD_PROPERTY(PropertyInfo(Variant::INT, "update_mode", PROPERTY_HINT_ENUM, "Process,Physics,Manual"), "set_update_mode", "get_update_mode"); @@ -118,6 +119,8 @@ void SpineSprite::on_skeleton_data_changed() { skeleton.unref(); animation_state.unref(); + emit_signal("_internal_spine_objects_invalidated"); + if (skeleton_data_res.is_valid()) { #if VERSION_MAJOR > 3 if (!skeleton_data_res->is_connected("skeleton_data_changed", callable_mp(this, &SpineSprite::on_skeleton_data_changed))) diff --git a/spine-godot/spine_godot/SpineTimeline.cpp b/spine-godot/spine_godot/SpineTimeline.cpp index 8937ae5fd..97adcf306 100644 --- a/spine-godot/spine_godot/SpineTimeline.cpp +++ b/spine-godot/spine_godot/SpineTimeline.cpp @@ -46,30 +46,30 @@ void SpineTimeline::_bind_methods() { void SpineTimeline::apply(Ref skeleton, float last_time, float time, Array events, float alpha, SpineConstant::MixBlend blend, SpineConstant::MixDirection direction) { - SPINE_CHECK(spine_object,) + SPINE_CHECK(get_spine_object(),) if (!skeleton->get_spine_object()) return; spine::Vector spine_events; spine_events.setSize((int)events.size(), nullptr); for (int i = 0; i < events.size(); ++i) { events[i] = ((Ref) spine_events[i])->get_spine_object(); } - spine_object->apply(*(skeleton->get_spine_object()), last_time, time, &spine_events, alpha, (spine::MixBlend) blend, (spine::MixDirection) direction); + get_spine_object()->apply(*(skeleton->get_spine_object()), last_time, time, &spine_events, alpha, (spine::MixBlend) blend, (spine::MixDirection) direction); } int SpineTimeline::get_frame_entries() { - SPINE_CHECK(spine_object, 0) - return (int)spine_object->getFrameEntries(); + SPINE_CHECK(get_spine_object(), 0) + return (int)get_spine_object()->getFrameEntries(); } int SpineTimeline::get_frame_count() { - SPINE_CHECK(spine_object, 0) - return (int)spine_object->getFrameCount(); + SPINE_CHECK(get_spine_object(), 0) + return (int)get_spine_object()->getFrameCount(); } Array SpineTimeline::get_frames() { Array result; - SPINE_CHECK(spine_object, result) - auto &frames = spine_object->getFrames(); + SPINE_CHECK(get_spine_object(), result) + auto &frames = get_spine_object()->getFrames(); result.resize((int)frames.size()); for (int i = 0; i < result.size(); ++i) { result[i] = frames[i]; @@ -78,14 +78,14 @@ Array SpineTimeline::get_frames() { } float SpineTimeline::get_duration() { - SPINE_CHECK(spine_object, 0) - return spine_object->getDuration(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getDuration(); } Array SpineTimeline::get_property_ids() { Array result; - SPINE_CHECK(spine_object, result) - auto &ids = spine_object->getPropertyIds(); + SPINE_CHECK(get_spine_object(), result) + auto &ids = get_spine_object()->getPropertyIds(); result.resize((int)ids.size()); for (int i = 0; i < result.size(); ++i) { result[i] = (spine::PropertyId) ids[i]; @@ -94,6 +94,6 @@ Array SpineTimeline::get_property_ids() { } String SpineTimeline::get_type() { - SPINE_CHECK(spine_object, "") - return spine_object->getRTTI().getClassName(); + SPINE_CHECK(get_spine_object(), "") + return get_spine_object()->getRTTI().getClassName(); } diff --git a/spine-godot/spine_godot/SpineTimeline.h b/spine-godot/spine_godot/SpineTimeline.h index 20559ad8d..ddb4eaf1d 100644 --- a/spine-godot/spine_godot/SpineTimeline.h +++ b/spine-godot/spine_godot/SpineTimeline.h @@ -39,7 +39,7 @@ class SpineSkeleton; class SpineEvent; -class SpineTimeline : public SpineObjectWrapper { +class SpineTimeline : public SpineSkeletonDataResourceOwnedObject { GDCLASS(SpineTimeline, SpineObjectWrapper) protected: diff --git a/spine-godot/spine_godot/SpineTrackEntry.cpp b/spine-godot/spine_godot/SpineTrackEntry.cpp index 54cae8a64..f5f7e6a70 100644 --- a/spine-godot/spine_godot/SpineTrackEntry.cpp +++ b/spine-godot/spine_godot/SpineTrackEntry.cpp @@ -80,13 +80,13 @@ void SpineTrackEntry::_bind_methods() { } int SpineTrackEntry::get_track_index() { - SPINE_CHECK(spine_object, 0) - return spine_object->getTrackIndex(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getTrackIndex(); } Ref SpineTrackEntry::get_animation() { - SPINE_CHECK(spine_object, nullptr) - auto animation = spine_object->getAnimation(); + SPINE_CHECK(get_spine_object(), nullptr) + auto animation = get_spine_object()->getAnimation(); if (!animation) return nullptr; Ref animation_ref(memnew(SpineAnimation)); animation_ref->set_spine_object(*get_spine_owner()->get_skeleton_data_res(), animation); @@ -94,8 +94,8 @@ Ref SpineTrackEntry::get_animation() { } Ref SpineTrackEntry::get_previous() { - SPINE_CHECK(spine_object, nullptr) - auto previous = spine_object->getPrevious(); + SPINE_CHECK(get_spine_object(), nullptr) + auto previous = get_spine_object()->getPrevious(); if (!previous) return nullptr; Ref previous_ref(memnew(SpineTrackEntry)); previous_ref->set_spine_object(get_spine_owner(), previous); @@ -103,163 +103,163 @@ Ref SpineTrackEntry::get_previous() { } bool SpineTrackEntry::get_loop() { - SPINE_CHECK(spine_object, false) - return spine_object->getLoop(); + SPINE_CHECK(get_spine_object(), false) + return get_spine_object()->getLoop(); } void SpineTrackEntry::set_loop(bool v) { - SPINE_CHECK(spine_object,) - spine_object->setLoop(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setLoop(v); } bool SpineTrackEntry::get_hold_previous() { - SPINE_CHECK(spine_object, false) - return spine_object->getHoldPrevious(); + SPINE_CHECK(get_spine_object(), false) + return get_spine_object()->getHoldPrevious(); } void SpineTrackEntry::set_hold_previous(bool v) { - SPINE_CHECK(spine_object,) - spine_object->setHoldPrevious(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setHoldPrevious(v); } bool SpineTrackEntry::get_reverse() { - SPINE_CHECK(spine_object, false) - return spine_object->getReverse(); + SPINE_CHECK(get_spine_object(), false) + return get_spine_object()->getReverse(); } void SpineTrackEntry::set_reverse(bool v) { - SPINE_CHECK(spine_object,) - spine_object->setReverse(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setReverse(v); } bool SpineTrackEntry::get_shortest_rotation() { - SPINE_CHECK(spine_object, false) - return spine_object->getShortestRotation(); + SPINE_CHECK(get_spine_object(), false) + return get_spine_object()->getShortestRotation(); } void SpineTrackEntry::set_shortest_rotation(bool v) { - SPINE_CHECK(spine_object,) - spine_object->setShortestRotation(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setShortestRotation(v); } float SpineTrackEntry::get_delay() { - SPINE_CHECK(spine_object, 0) - return spine_object->getDelay(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getDelay(); } void SpineTrackEntry::set_delay(float v) { - SPINE_CHECK(spine_object,) - spine_object->setDelay(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setDelay(v); } float SpineTrackEntry::get_track_time() { - SPINE_CHECK(spine_object, 0) - return spine_object->getTrackTime(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getTrackTime(); } void SpineTrackEntry::set_track_time(float v) { - SPINE_CHECK(spine_object,) - spine_object->setTrackTime(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setTrackTime(v); } float SpineTrackEntry::get_track_end() { - SPINE_CHECK(spine_object, 0) - return spine_object->getTrackEnd(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getTrackEnd(); } void SpineTrackEntry::set_track_end(float v) { - SPINE_CHECK(spine_object,) - spine_object->setTrackEnd(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setTrackEnd(v); } float SpineTrackEntry::get_animation_start() { - SPINE_CHECK(spine_object, 0) - return spine_object->getAnimationStart(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getAnimationStart(); } void SpineTrackEntry::set_animation_start(float v) { - SPINE_CHECK(spine_object,) - spine_object->setAnimationStart(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setAnimationStart(v); } float SpineTrackEntry::get_animation_end() { - SPINE_CHECK(spine_object, 0) - return spine_object->getAnimationEnd(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getAnimationEnd(); } void SpineTrackEntry::set_animation_end(float v) { - SPINE_CHECK(spine_object,) - spine_object->setAnimationEnd(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setAnimationEnd(v); } float SpineTrackEntry::get_animation_last() { - SPINE_CHECK(spine_object, 0) - return spine_object->getAnimationLast(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getAnimationLast(); } void SpineTrackEntry::set_animation_last(float v) { - SPINE_CHECK(spine_object,) - spine_object->setAnimationLast(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setAnimationLast(v); } float SpineTrackEntry::get_animation_time() { - SPINE_CHECK(spine_object, 0) - return spine_object->getAnimationTime(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getAnimationTime(); } float SpineTrackEntry::get_time_scale() { - SPINE_CHECK(spine_object, 0) - return spine_object->getTimeScale(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getTimeScale(); } void SpineTrackEntry::set_time_scale(float v) { - SPINE_CHECK(spine_object,) - spine_object->setTimeScale(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setTimeScale(v); } float SpineTrackEntry::get_alpha() { - SPINE_CHECK(spine_object, 0) - return spine_object->getAlpha(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getAlpha(); } void SpineTrackEntry::set_alpha(float v) { - SPINE_CHECK(spine_object,) - spine_object->setAlpha(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setAlpha(v); } float SpineTrackEntry::get_event_threshold() { - SPINE_CHECK(spine_object, 0) - return spine_object->getEventThreshold(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getEventThreshold(); } void SpineTrackEntry::set_event_threshold(float v) { - SPINE_CHECK(spine_object,) - spine_object->setEventThreshold(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setEventThreshold(v); } float SpineTrackEntry::get_attachment_threshold() { - SPINE_CHECK(spine_object, 0) - return spine_object->getAttachmentThreshold(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getAttachmentThreshold(); } void SpineTrackEntry::set_attachment_threshold(float v) { - SPINE_CHECK(spine_object,) - spine_object->setAttachmentThreshold(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setAttachmentThreshold(v); } float SpineTrackEntry::get_draw_order_threshold() { - SPINE_CHECK(spine_object, 0) - return spine_object->getDrawOrderThreshold(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getDrawOrderThreshold(); } void SpineTrackEntry::set_draw_order_threshold(float v) { - SPINE_CHECK(spine_object,) - spine_object->setDrawOrderThreshold(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setDrawOrderThreshold(v); } Ref SpineTrackEntry::get_next() { - SPINE_CHECK(spine_object, nullptr) - auto next = spine_object->getNext(); + SPINE_CHECK(get_spine_object(), nullptr) + auto next = get_spine_object()->getNext(); if (!next) return nullptr; Ref next_ref(memnew(SpineTrackEntry)); next_ref->set_spine_object(get_spine_owner(), next); @@ -267,43 +267,43 @@ Ref SpineTrackEntry::get_next() { } bool SpineTrackEntry::is_complete() { - SPINE_CHECK(spine_object, false) - return spine_object->isComplete(); + SPINE_CHECK(get_spine_object(), false) + return get_spine_object()->isComplete(); } float SpineTrackEntry::get_mix_time() { - SPINE_CHECK(spine_object, 0) - return spine_object->getMixTime(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getMixTime(); } void SpineTrackEntry::set_mix_time(float v) { - SPINE_CHECK(spine_object,) - spine_object->setMixTime(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setMixTime(v); } float SpineTrackEntry::get_mix_duration() { - SPINE_CHECK(spine_object, 0) - return spine_object->getMixDuration(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getMixDuration(); } void SpineTrackEntry::set_mix_duration(float v) { - SPINE_CHECK(spine_object,) - spine_object->setMixDuration(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setMixDuration(v); } SpineConstant::MixBlend SpineTrackEntry::get_mix_blend() { - SPINE_CHECK(spine_object, SpineConstant::MixBlend_Setup) - return (SpineConstant::MixBlend)spine_object->getMixBlend(); + SPINE_CHECK(get_spine_object(), SpineConstant::MixBlend_Setup) + return (SpineConstant::MixBlend)get_spine_object()->getMixBlend(); } void SpineTrackEntry::set_mix_blend(SpineConstant::MixBlend v) { - SPINE_CHECK(spine_object,) - spine_object->setMixBlend((spine::MixBlend) v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setMixBlend((spine::MixBlend) v); } Ref SpineTrackEntry::get_mixing_from() { - SPINE_CHECK(spine_object, nullptr) - auto mixing_from = spine_object->getMixingFrom(); + SPINE_CHECK(get_spine_object(), nullptr) + auto mixing_from = get_spine_object()->getMixingFrom(); if (!mixing_from) return nullptr; Ref mixing_from_ref(memnew(SpineTrackEntry)); mixing_from_ref->set_spine_object(get_spine_owner(), mixing_from); @@ -311,8 +311,8 @@ Ref SpineTrackEntry::get_mixing_from() { } Ref SpineTrackEntry::get_mixing_to() { - SPINE_CHECK(spine_object, nullptr) - auto mixing_to = spine_object->getMixingTo(); + SPINE_CHECK(get_spine_object(), nullptr) + auto mixing_to = get_spine_object()->getMixingTo(); if (!mixing_to) return nullptr; Ref mixing_to_ref(memnew(SpineTrackEntry)); mixing_to_ref->set_spine_object(get_spine_owner(), mixing_to); @@ -320,11 +320,11 @@ Ref SpineTrackEntry::get_mixing_to() { } void SpineTrackEntry::reset_rotation_directions() { - SPINE_CHECK(spine_object,) - spine_object->resetRotationDirections(); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->resetRotationDirections(); } float SpineTrackEntry::get_track_complete() { - SPINE_CHECK(spine_object, 0) - return spine_object->getTrackComplete(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getTrackComplete(); } diff --git a/spine-godot/spine_godot/SpineTrackEntry.h b/spine-godot/spine_godot/SpineTrackEntry.h index 132274668..a6d9a886f 100644 --- a/spine-godot/spine_godot/SpineTrackEntry.h +++ b/spine-godot/spine_godot/SpineTrackEntry.h @@ -37,7 +37,7 @@ #include "SpineSprite.h" -class SpineTrackEntry : public SpineObjectWrapper { +class SpineTrackEntry : public SpineSpriteOwnedObject { GDCLASS(SpineTrackEntry, SpineObjectWrapper); protected: diff --git a/spine-godot/spine_godot/SpineTransformConstraint.cpp b/spine-godot/spine_godot/SpineTransformConstraint.cpp index aa571d8c9..70b36d331 100644 --- a/spine-godot/spine_godot/SpineTransformConstraint.cpp +++ b/spine-godot/spine_godot/SpineTransformConstraint.cpp @@ -54,18 +54,18 @@ void SpineTransformConstraint::_bind_methods() { } void SpineTransformConstraint::update() { - SPINE_CHECK(spine_object,) - spine_object->update(); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->update(); } int SpineTransformConstraint::get_order() { - SPINE_CHECK(spine_object, 0) - return spine_object->getOrder(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getOrder(); } Ref SpineTransformConstraint::get_data() { - SPINE_CHECK(spine_object, nullptr) - auto &data = spine_object->getData(); + SPINE_CHECK(get_spine_object(), nullptr) + auto &data = get_spine_object()->getData(); Ref data_ref(memnew(SpineTransformConstraintData)); data_ref->set_spine_object(*get_spine_owner()->get_skeleton_data_res(), &data); return data_ref; @@ -73,8 +73,8 @@ Ref SpineTransformConstraint::get_data() { Array SpineTransformConstraint::get_bones() { Array result; - SPINE_CHECK(spine_object, result) - auto &bones = spine_object->getBones(); + SPINE_CHECK(get_spine_object(), result) + auto &bones = get_spine_object()->getBones(); result.resize((int)bones.size()); for (int i = 0; i < bones.size(); ++i) { auto bone = bones[i]; @@ -86,8 +86,8 @@ Array SpineTransformConstraint::get_bones() { } Ref SpineTransformConstraint::get_target() { - SPINE_CHECK(spine_object, nullptr) - auto target = spine_object->getTarget(); + SPINE_CHECK(get_spine_object(), nullptr) + auto target = get_spine_object()->getTarget(); if (!target) return nullptr; Ref target_ref(memnew(SpineBone)); target_ref->set_spine_object(get_spine_owner(), target); @@ -95,76 +95,76 @@ Ref SpineTransformConstraint::get_target() { } void SpineTransformConstraint::set_target(Ref v) { - SPINE_CHECK(spine_object,) - spine_object->setTarget(v.is_valid() && v->get_spine_object() ? v->get_spine_object() : nullptr); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setTarget(v.is_valid() && v->get_spine_object() ? v->get_spine_object() : nullptr); } float SpineTransformConstraint::get_mix_rotate() { - SPINE_CHECK(spine_object, 0) - return spine_object->getMixRotate(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getMixRotate(); } void SpineTransformConstraint::set_mix_rotate(float v) { - SPINE_CHECK(spine_object,) - spine_object->setMixRotate(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setMixRotate(v); } float SpineTransformConstraint::get_mix_x() { - SPINE_CHECK(spine_object, 0) - return spine_object->getMixX(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getMixX(); } void SpineTransformConstraint::set_mix_x(float v) { - SPINE_CHECK(spine_object,) - spine_object->setMixX(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setMixX(v); } float SpineTransformConstraint::get_mix_y() { - SPINE_CHECK(spine_object, 0) - return spine_object->getMixY(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getMixY(); } void SpineTransformConstraint::set_mix_y(float v) { - SPINE_CHECK(spine_object,) - spine_object->setMixY(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setMixY(v); } float SpineTransformConstraint::get_mix_scale_x() { - SPINE_CHECK(spine_object, 0) - return spine_object->getMixScaleX(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getMixScaleX(); } void SpineTransformConstraint::set_mix_scale_x(float v) { - SPINE_CHECK(spine_object,) - spine_object->setMixScaleX(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setMixScaleX(v); } float SpineTransformConstraint::get_mix_scale_y() { - SPINE_CHECK(spine_object, 0) - return spine_object->getMixScaleY(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getMixScaleY(); } void SpineTransformConstraint::set_mix_scale_y(float v) { - SPINE_CHECK(spine_object,) - spine_object->setMixScaleY(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setMixScaleY(v); } float SpineTransformConstraint::get_mix_shear_y() { - SPINE_CHECK(spine_object, 0) - return spine_object->getMixShearY(); + SPINE_CHECK(get_spine_object(), 0) + return get_spine_object()->getMixShearY(); } void SpineTransformConstraint::set_mix_shear_y(float v) { - SPINE_CHECK(spine_object,) - spine_object->setMixShearY(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setMixShearY(v); } bool SpineTransformConstraint::is_active() { - SPINE_CHECK(spine_object, false) - return spine_object->isActive(); + SPINE_CHECK(get_spine_object(), false) + return get_spine_object()->isActive(); } void SpineTransformConstraint::set_active(bool v) { - SPINE_CHECK(spine_object,) - spine_object->setActive(v); + SPINE_CHECK(get_spine_object(),) + get_spine_object()->setActive(v); } diff --git a/spine-godot/spine_godot/SpineTransformConstraint.h b/spine-godot/spine_godot/SpineTransformConstraint.h index 30b10736a..8be8ded46 100644 --- a/spine-godot/spine_godot/SpineTransformConstraint.h +++ b/spine-godot/spine_godot/SpineTransformConstraint.h @@ -35,7 +35,7 @@ #include "SpineBone.h" #include -class SpineTransformConstraint : public SpineObjectWrapper { +class SpineTransformConstraint : public SpineSpriteOwnedObject { GDCLASS(SpineTransformConstraint, SpineObjectWrapper) protected: