From cea5adfe1bdb66af2240e309836654587b5e54a8 Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Wed, 6 Apr 2022 11:19:04 +0200 Subject: [PATCH] [godot] Clean-up SpineTimline, SpineConstants. --- spine-godot/example/tests/unit-tests.gd | 19 ++++++-- spine-godot/example/tests/unit-tests.tscn | 18 ------- .../modules/spine_godot/SpineAnimation.h | 15 ++---- .../modules/spine_godot/SpineConstant.cpp | 3 +- .../godot/modules/spine_godot/SpineConstant.h | 5 +- .../modules/spine_godot/SpineTimeline.cpp | 48 +++++++++---------- .../godot/modules/spine_godot/SpineTimeline.h | 16 +++---- 7 files changed, 55 insertions(+), 69 deletions(-) diff --git a/spine-godot/example/tests/unit-tests.gd b/spine-godot/example/tests/unit-tests.gd index d207ebad3..cb537acb9 100644 --- a/spine-godot/example/tests/unit-tests.gd +++ b/spine-godot/example/tests/unit-tests.gd @@ -1,8 +1,6 @@ extends SpineSprite -func _ready(): - - # Test SpineAnimation +func test_spine_animation(): var walkAnim: SpineAnimation = get_skeleton().get_data().find_animation("walk") assert(walkAnim.get_name() == "walk") var duration = walkAnim.get_duration() @@ -10,6 +8,19 @@ func _ready(): assert(walkAnim.get_duration() == duration + 1) assert(walkAnim.get_timelines().size() == 39) var timeline: SpineTimeline = walkAnim.get_timelines()[0] - var propertyIds = timeline.getPropertyIds() + var propertyIds = timeline.get_property_ids() assert(walkAnim.has_timeline(propertyIds)) assert(!walkAnim.has_timeline([0])) + +func test_spine_timeline(): + var walkAnim: SpineAnimation = get_skeleton().get_data().find_animation("walk") + var timeline: SpineTimeline = walkAnim.get_timelines()[0] + assert(timeline.get_duration() == 1) + assert(timeline.get_property_ids() == [4294967300]) + assert(timeline.get_type() == "RotateTimeline") + +func _ready(): + + test_spine_animation() + test_spine_timeline() + print("All tests passed") diff --git a/spine-godot/example/tests/unit-tests.tscn b/spine-godot/example/tests/unit-tests.tscn index 4e2de63b1..48dca3de9 100644 --- a/spine-godot/example/tests/unit-tests.tscn +++ b/spine-godot/example/tests/unit-tests.tscn @@ -219,75 +219,57 @@ material = SubResource( 20 ) [node name="rear-upper-arm" type="SpineSpriteMeshInstance2D" parent="."] material = SubResource( 21 ) -scale = Vector2( 0.7, 0.7 ) [node name="rear-bracer" type="SpineSpriteMeshInstance2D" parent="."] material = SubResource( 22 ) -scale = Vector2( 0.7, 0.7 ) [node name="gun" type="SpineSpriteMeshInstance2D" parent="."] material = SubResource( 23 ) -scale = Vector2( 0.7, 0.7 ) [node name="rear-foot" type="SpineSpriteMeshInstance2D" parent="."] material = SubResource( 24 ) -scale = Vector2( 0.7, 0.7 ) [node name="rear-thigh" type="SpineSpriteMeshInstance2D" parent="."] material = SubResource( 25 ) -scale = Vector2( 0.7, 0.7 ) [node name="rear-shin" type="SpineSpriteMeshInstance2D" parent="."] material = SubResource( 26 ) -scale = Vector2( 0.7, 0.7 ) [node name="neck" type="SpineSpriteMeshInstance2D" parent="."] material = SubResource( 27 ) -scale = Vector2( 0.7, 0.7 ) [node name="torso" type="SpineSpriteMeshInstance2D" parent="."] material = SubResource( 28 ) -scale = Vector2( 0.7, 0.7 ) [node name="front-upper-arm" type="SpineSpriteMeshInstance2D" parent="."] material = SubResource( 29 ) -scale = Vector2( 0.7, 0.7 ) [node name="head" type="SpineSpriteMeshInstance2D" parent="."] material = SubResource( 30 ) -scale = Vector2( 0.7, 0.7 ) [node name="eye" type="SpineSpriteMeshInstance2D" parent="."] material = SubResource( 31 ) -scale = Vector2( 0.7, 0.7 ) [node name="front-thigh" type="SpineSpriteMeshInstance2D" parent="."] material = SubResource( 32 ) -scale = Vector2( 0.7, 0.7 ) [node name="front-foot" type="SpineSpriteMeshInstance2D" parent="."] material = SubResource( 33 ) -scale = Vector2( 0.7, 0.7 ) [node name="front-shin" type="SpineSpriteMeshInstance2D" parent="."] material = SubResource( 34 ) -scale = Vector2( 0.7, 0.7 ) [node name="mouth" type="SpineSpriteMeshInstance2D" parent="."] material = SubResource( 35 ) -scale = Vector2( 0.7, 0.7 ) [node name="goggles" type="SpineSpriteMeshInstance2D" parent="."] material = SubResource( 36 ) -scale = Vector2( 0.7, 0.7 ) [node name="front-bracer" type="SpineSpriteMeshInstance2D" parent="."] material = SubResource( 37 ) -scale = Vector2( 0.7, 0.7 ) [node name="front-fist" type="SpineSpriteMeshInstance2D" parent="."] material = SubResource( 38 ) -scale = Vector2( 0.7, 0.7 ) [node name="muzzle" type="SpineSpriteMeshInstance2D" parent="."] visible = false diff --git a/spine-godot/godot/modules/spine_godot/SpineAnimation.h b/spine-godot/godot/modules/spine_godot/SpineAnimation.h index dc394a93c..a3ec2daa8 100644 --- a/spine-godot/godot/modules/spine_godot/SpineAnimation.h +++ b/spine-godot/godot/modules/spine_godot/SpineAnimation.h @@ -31,7 +31,7 @@ #define GODOT_SPINEANIMATION_H #include "SpineConstant.h" - +#include "core/reference.h" #include class SpineEvent; @@ -51,19 +51,14 @@ public: SpineAnimation(); ~SpineAnimation(); - inline void set_spine_object(spine::Animation *animation) { - this->animation = animation; - } - inline spine::Animation *get_spine_object() { - return animation; - } + inline void set_spine_object(spine::Animation *animation) { this->animation = animation; } + inline spine::Animation *get_spine_object() { return animation; } - // Vector> pEvents void apply(Ref skeleton, float lastTime, float time, bool loop, Array pEvents, float alpha, SpineConstant::MixBlend blend, SpineConstant::MixDirection direction); - Array get_timelines(); // Vector> + Array get_timelines(); - bool has_timeline(Array ids);// Vector + bool has_timeline(Array ids); String get_name(); diff --git a/spine-godot/godot/modules/spine_godot/SpineConstant.cpp b/spine-godot/godot/modules/spine_godot/SpineConstant.cpp index 760ff668a..31c9d2100 100644 --- a/spine-godot/godot/modules/spine_godot/SpineConstant.cpp +++ b/spine-godot/godot/modules/spine_godot/SpineConstant.cpp @@ -57,4 +57,5 @@ void SpineConstant::_bind_methods() { BIND_ENUM_CONSTANT(Property_PathConstraintPosition); BIND_ENUM_CONSTANT(Property_PathConstraintSpacing); BIND_ENUM_CONSTANT(Property_PathConstraintMix); -} \ No newline at end of file + BIND_ENUM_CONSTANT(Property_Sequence); +} diff --git a/spine-godot/godot/modules/spine_godot/SpineConstant.h b/spine-godot/godot/modules/spine_godot/SpineConstant.h index c7f86d8b9..b8357e9bd 100644 --- a/spine-godot/godot/modules/spine_godot/SpineConstant.h +++ b/spine-godot/godot/modules/spine_godot/SpineConstant.h @@ -30,7 +30,7 @@ #ifndef GODOT_SPINECONSTANT_H #define GODOT_SPINECONSTANT_H -#include "core/variant_parser.h" +#include "core/object.h" class SpineConstant : public Object { GDCLASS(SpineConstant, Object); @@ -70,7 +70,8 @@ public: Property_TransformConstraint = 1 << 15, Property_PathConstraintPosition = 1 << 16, Property_PathConstraintSpacing = 1 << 17, - Property_PathConstraintMix = 1 << 18 + Property_PathConstraintMix = 1 << 18, + Property_Sequence = 1 << 19 }; }; diff --git a/spine-godot/godot/modules/spine_godot/SpineTimeline.cpp b/spine-godot/godot/modules/spine_godot/SpineTimeline.cpp index 29561c595..c8509ed6b 100644 --- a/spine-godot/godot/modules/spine_godot/SpineTimeline.cpp +++ b/spine-godot/godot/modules/spine_godot/SpineTimeline.cpp @@ -28,38 +28,34 @@ *****************************************************************************/ #include "SpineTimeline.h" - #include "SpineSkeleton.h" #include "SpineEvent.h" - -// enable more than 5 arguments of a method bind function #include "core/method_bind_ext.gen.inc" void SpineTimeline::_bind_methods() { - ClassDB::bind_method(D_METHOD("apply", "skeleton", "lastTime", "time", "pEvents", "alpha", "blend", "direction"), &SpineTimeline::apply); + ClassDB::bind_method(D_METHOD("apply", "skeleton", "last_time", "time", "events", "alpha", "blend", "direction"), &SpineTimeline::apply); ClassDB::bind_method(D_METHOD("get_frame_entries"), &SpineTimeline::get_frame_entries); ClassDB::bind_method(D_METHOD("get_frame_count"), &SpineTimeline::get_frame_count); ClassDB::bind_method(D_METHOD("get_frames"), &SpineTimeline::get_frames); ClassDB::bind_method(D_METHOD("get_duration"), &SpineTimeline::get_duration); - ClassDB::bind_method(D_METHOD("getPropertyIds"), &SpineTimeline::getPropertyIds); + ClassDB::bind_method(D_METHOD("get_property_ids"), &SpineTimeline::get_property_ids); + ClassDB::bind_method(D_METHOD("get_type"), &SpineTimeline::get_type); } - -SpineTimeline::SpineTimeline() : timeline(nullptr) { +SpineTimeline::SpineTimeline() : timeline(NULL) { } SpineTimeline::~SpineTimeline() { } -void SpineTimeline::apply(Ref skeleton, float lastTime, float time, Array pEvents, float alpha, +void SpineTimeline::apply(Ref skeleton, float lastTime, float time, Array events, float alpha, SpineConstant::MixBlend blend, SpineConstant::MixDirection direction) { - spine::Vector events; - events.setSize(pEvents.size(), nullptr); + spine::Vector spineEvents; + spineEvents.setSize(events.size(), nullptr); for (size_t i = 0; i < events.size(); ++i) { - events[i] = ((Ref) pEvents[i])->get_spine_object(); + events[i] = ((Ref) spineEvents[i])->get_spine_object(); } - - timeline->apply(*(skeleton->get_spine_object()), lastTime, time, &events, alpha, (spine::MixBlend) blend, (spine::MixDirection) direction); + timeline->apply(*(skeleton->get_spine_object()), lastTime, time, &spineEvents, alpha, (spine::MixBlend) blend, (spine::MixDirection) direction); } int64_t SpineTimeline::get_frame_entries() { @@ -72,28 +68,32 @@ int64_t SpineTimeline::get_frame_count() { Array SpineTimeline::get_frames() { auto &frames = timeline->getFrames(); - Array res; - res.resize(frames.size()); + Array result; + result.resize(frames.size()); - for (size_t i = 0; i < res.size(); ++i) { - res[i] = frames[i]; + for (size_t i = 0; i < result.size(); ++i) { + result[i] = frames[i]; } - return res; + return result; } float SpineTimeline::get_duration() { return timeline->getDuration(); } -Array SpineTimeline::getPropertyIds() { +Array SpineTimeline::get_property_ids() { auto &ids = timeline->getPropertyIds(); - Array res; - res.resize(ids.size()); + Array result; + result.resize(ids.size()); - for (size_t i = 0; i < res.size(); ++i) { - res[i] = (int64_t) ids[i]; + for (size_t i = 0; i < result.size(); ++i) { + result[i] = (int64_t) ids[i]; } - return res; + return result; +} + +String SpineTimeline::get_type() { + return timeline->getRTTI().getClassName(); } diff --git a/spine-godot/godot/modules/spine_godot/SpineTimeline.h b/spine-godot/godot/modules/spine_godot/SpineTimeline.h index 404d7dd26..e29e6953f 100644 --- a/spine-godot/godot/modules/spine_godot/SpineTimeline.h +++ b/spine-godot/godot/modules/spine_godot/SpineTimeline.h @@ -30,11 +30,9 @@ #ifndef GODOT_SPINETIMELINE_H #define GODOT_SPINETIMELINE_H -#include "core/variant_parser.h" - #include "spine/Timeline.h" - #include "SpineConstant.h" +#include "core/reference.h" class SpineSkeleton; class SpineEvent; @@ -52,24 +50,22 @@ public: SpineTimeline(); ~SpineTimeline(); - inline void set_spine_object(spine::Timeline *v) { timeline = v; } + inline void set_spine_object(spine::Timeline *timeline) { this->timeline = timeline; } inline spine::Timeline *get_spine_object() { return timeline; } - // Vector - void apply(Ref skeleton, float lastTime, float time, Array pEvents, float alpha, SpineConstant::MixBlend blend, SpineConstant::MixDirection direction); + void apply(Ref skeleton, float lastTime, float time, Array events, float alpha, SpineConstant::MixBlend blend, SpineConstant::MixDirection direction); int64_t get_frame_entries(); int64_t get_frame_count(); - // Vector Array get_frames(); float get_duration(); - // Vector - Array getPropertyIds(); + Array get_property_ids(); + + String get_type(); }; - #endif//GODOT_SPINETIMELINE_H