From 854b6f9a2a63c7feba922983e76d2da6ef91283a Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Fri, 25 Jul 2025 22:00:52 +0200 Subject: [PATCH] [cpp] Constructor nullability. --- spine-c/codegen/last-nullable.md | 167 ++++++++++++++++++ spine-cpp/include/spine/AnimationState.h | 6 +- spine-cpp/include/spine/AnimationStateData.h | 2 +- .../include/spine/AtlasAttachmentLoader.h | 2 +- spine-cpp/include/spine/DeformTimeline.h | 2 +- spine-cpp/include/spine/LinkedMesh.h | 4 +- spine-cpp/include/spine/SequenceTimeline.h | 2 +- spine-cpp/include/spine/SkeletonBinary.h | 4 +- spine-cpp/include/spine/SkeletonJson.h | 4 +- spine-cpp/spine-cpp-lite/spine-cpp-lite.cpp | 2 +- spine-cpp/src/spine/AnimationState.cpp | 26 ++- spine-cpp/src/spine/AnimationStateData.cpp | 2 +- spine-cpp/src/spine/AtlasAttachmentLoader.cpp | 2 +- spine-cpp/src/spine/DeformTimeline.cpp | 6 +- spine-cpp/src/spine/LinkedMesh.cpp | 8 +- spine-cpp/src/spine/SequenceTimeline.cpp | 8 +- spine-cpp/src/spine/SkeletonBinary.cpp | 13 +- spine-cpp/src/spine/SkeletonJson.cpp | 13 +- spine-cpp/tests/HeadlessTest.cpp | 10 +- 19 files changed, 222 insertions(+), 61 deletions(-) diff --git a/spine-c/codegen/last-nullable.md b/spine-c/codegen/last-nullable.md index 22cc60cc7..11de9cd87 100644 --- a/spine-c/codegen/last-nullable.md +++ b/spine-c/codegen/last-nullable.md @@ -2852,6 +2852,173 @@ For each unchecked checkbox (now with implementations inlined): 84: public void setAttachment (@Null Attachment attachment) { 85- if (this.attachment == attachment) return; 86- if (!(attachment instanceof VertexAttachment newAttachment) || !(this.attachment instanceof VertexAttachment oldAttachment) + 87- || newAttachment.getTimelineAttachment() != oldAttachment.getTimelineAttachment()) deform.clear(); + 88- this.attachment = attachment; + 89- sequenceIndex = -1; + 90- } + 91- + 92- public IntArray getDeform () { + 93- return deform; + 94- } + ``` +- [x] [../../spine-cpp/include/spine/RTTI.h:43](../../spine-cpp/include/spine/RTTI.h#L43) RTTI::RTTI(const char * className, const RTTI & baseRTTI, const RTTI * interface1, const RTTI * interface2, const RTTI * interface3) // takes nullable parameter 'interface1': const RTTI *; takes nullable parameter 'interface2': const RTTI *; takes nullable parameter 'interface3': const RTTI * + ```cpp + ../../spine-cpp/src/spine/RTTI.cpp:35 + 35:RTTI::RTTI(const char *className) : _className(className), _pBaseRTTI(NULL), _interfaceCount(0) { + 36- _interfaces[0] = NULL; + 37- _interfaces[1] = NULL; + 38- _interfaces[2] = NULL; + 39-} + 40- + 41:RTTI::RTTI(const char *className, const RTTI &baseRTTI) : _className(className), _pBaseRTTI(&baseRTTI), _interfaceCount(0) { + 42- _interfaces[0] = NULL; + 43- _interfaces[1] = NULL; + 44- _interfaces[2] = NULL; + ``` + ```java + NOT FOUND - searched for class "RTTI" (from C++ "RTTI") and method "RTTI" across all Java files + ``` +- [x] [../../spine-cpp/include/spine/SequenceTimeline.h:50](../../spine-cpp/include/spine/SequenceTimeline.h#L50) SequenceTimeline::SequenceTimeline(size_t frameCount, int slotIndex, Attachment * attachment) // takes nullable parameter 'attachment': Attachment * + ```cpp + ../../spine-cpp/src/spine/SequenceTimeline.cpp:46 + 46:SequenceTimeline::SequenceTimeline(size_t frameCount, int slotIndex, Attachment *attachment) + 47- : Timeline(frameCount, ENTRIES), SlotTimeline(), _slotIndex(slotIndex), _attachment((HasTextureRegion *) attachment) { + 48- int sequenceId = 0; + 49- if (attachment->getRTTI().instanceOf(RegionAttachment::rtti)) sequenceId = ((RegionAttachment *) attachment)->getSequence()->getId(); + 50- if (attachment->getRTTI().instanceOf(MeshAttachment::rtti)) sequenceId = ((MeshAttachment *) attachment)->getSequence()->getId(); + 51- PropertyId ids[] = {((PropertyId) Property_Sequence << 32) | ((slotIndex << 16 | sequenceId) & 0xffffffff)}; + 52- setPropertyIds(ids, 1); + 53-} + 54- + 55-SequenceTimeline::~SequenceTimeline() { + ``` + ```java + ../../spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Animation.java:1705 + 1705: public SequenceTimeline (int frameCount, int slotIndex, Attachment attachment) { + 1706- super(frameCount, + 1707- Property.sequence.ordinal() + "|" + slotIndex + "|" + ((HasTextureRegion)attachment).getSequence().getId()); + 1708- this.slotIndex = slotIndex; + 1709- this.attachment = (HasTextureRegion)attachment; + 1710- } + 1711- + 1712- public int getFrameEntries () { + 1713- return ENTRIES; + 1714- } + ``` +- [x] [../../spine-cpp/include/spine/SkeletonBinary.h:118](../../spine-cpp/include/spine/SkeletonBinary.h#L118) SkeletonBinary::SkeletonBinary(Atlas * atlas) // takes nullable parameter 'atlas': Atlas * + ```cpp + ../../spine-cpp/src/spine/SkeletonBinary.cpp:82 + 82:SkeletonBinary::SkeletonBinary(Atlas *atlas) + 83- : _attachmentLoader(new(__FILE__, __LINE__) AtlasAttachmentLoader(atlas)), _error(), _scale(1), _ownsLoader(true) { + 84-} + 85- + 86:SkeletonBinary::SkeletonBinary(AttachmentLoader *attachmentLoader, bool ownsLoader) + 87- : _attachmentLoader(attachmentLoader), _error(), _scale(1), _ownsLoader(ownsLoader) { + 88- assert(_attachmentLoader != NULL); + 89-} + 90- + 91-SkeletonBinary::~SkeletonBinary() { + ``` + ```java + ../../spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonBinary.java:173 + 173: public SkeletonBinary (AttachmentLoader attachmentLoader) { + 174- super(attachmentLoader); + 175- } + 176- + 177: public SkeletonBinary (TextureAtlas atlas) { + 178- super(atlas); + 179- } + 180- + 181- public SkeletonData readSkeletonData (FileHandle file) { + 182- if (file == null) throw new IllegalArgumentException("file cannot be null."); + ``` +- [x] [../../spine-cpp/include/spine/SkeletonBinary.h:120](../../spine-cpp/include/spine/SkeletonBinary.h#L120) SkeletonBinary::SkeletonBinary(AttachmentLoader * attachmentLoader, bool ownsLoader) // takes nullable parameter 'attachmentLoader': AttachmentLoader * + ```cpp + ../../spine-cpp/src/spine/SkeletonBinary.cpp:82 + 82:SkeletonBinary::SkeletonBinary(Atlas *atlas) + 83- : _attachmentLoader(new(__FILE__, __LINE__) AtlasAttachmentLoader(atlas)), _error(), _scale(1), _ownsLoader(true) { + 84-} + 85- + 86:SkeletonBinary::SkeletonBinary(AttachmentLoader *attachmentLoader, bool ownsLoader) + 87- : _attachmentLoader(attachmentLoader), _error(), _scale(1), _ownsLoader(ownsLoader) { + 88- assert(_attachmentLoader != NULL); + 89-} + 90- + 91-SkeletonBinary::~SkeletonBinary() { + ``` + ```java + ../../spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonBinary.java:173 + 173: public SkeletonBinary (AttachmentLoader attachmentLoader) { + 174- super(attachmentLoader); + 175- } + 176- + 177: public SkeletonBinary (TextureAtlas atlas) { + 178- super(atlas); + 179- } + 180- + 181- public SkeletonData readSkeletonData (FileHandle file) { + 182- if (file == null) throw new IllegalArgumentException("file cannot be null."); + ``` +- [x] [../../spine-cpp/include/spine/SkeletonJson.h:70](../../spine-cpp/include/spine/SkeletonJson.h#L70) SkeletonJson::SkeletonJson(Atlas * atlas) // takes nullable parameter 'atlas': Atlas * + ```cpp + ../../spine-cpp/src/spine/SkeletonJson.cpp:124 + 124:SkeletonJson::SkeletonJson(Atlas *atlas) : _attachmentLoader(new(__FILE__, __LINE__) AtlasAttachmentLoader(atlas)), _scale(1), _ownsLoader(true) { + 125-} + 126- + 127:SkeletonJson::SkeletonJson(AttachmentLoader *attachmentLoader, bool ownsLoader) + 128- : _attachmentLoader(attachmentLoader), _scale(1), _ownsLoader(ownsLoader) { + 129- assert(_attachmentLoader != NULL); + 130-} + 131- + 132-SkeletonJson::~SkeletonJson() { + 133- ArrayUtils::deleteElements(_linkedMeshes); + ``` + ```java + ../../spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonJson.java:128 + 128: public SkeletonJson (AttachmentLoader attachmentLoader) { + 129- super(attachmentLoader); + 130- } + 131- + 132: public SkeletonJson (TextureAtlas atlas) { + 133- super(atlas); + 134- } + 135- + 136- public SkeletonData readSkeletonData (FileHandle file) { + 137- if (file == null) throw new IllegalArgumentException("file cannot be null."); + ``` +- [x] [../../spine-cpp/include/spine/SkeletonJson.h:72](../../spine-cpp/include/spine/SkeletonJson.h#L72) SkeletonJson::SkeletonJson(AttachmentLoader * attachmentLoader, bool ownsLoader) // takes nullable parameter 'attachmentLoader': AttachmentLoader * + ```cpp + ../../spine-cpp/src/spine/SkeletonJson.cpp:124 + 124:SkeletonJson::SkeletonJson(Atlas *atlas) : _attachmentLoader(new(__FILE__, __LINE__) AtlasAttachmentLoader(atlas)), _scale(1), _ownsLoader(true) { + 125-} + 126- + 127:SkeletonJson::SkeletonJson(AttachmentLoader *attachmentLoader, bool ownsLoader) + 128- : _attachmentLoader(attachmentLoader), _scale(1), _ownsLoader(ownsLoader) { + 129- assert(_attachmentLoader != NULL); + 130-} + 131- + 132-SkeletonJson::~SkeletonJson() { + 133- ArrayUtils::deleteElements(_linkedMeshes); + ``` + ```java + ../../spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonJson.java:128 + 128: public SkeletonJson (AttachmentLoader attachmentLoader) { + 129- super(attachmentLoader); + 130- } + 131- + 132: public SkeletonJson (TextureAtlas atlas) { + 133- super(atlas); + 134- } + 135- + 136- public SkeletonData readSkeletonData (FileHandle file) { + 137- if (file == null) throw new IllegalArgumentException("file cannot be null."); + ``` + ``` + ```java + ../../spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SlotPose.java:84 + 84: public void setAttachment (@Null Attachment attachment) { + 85- if (this.attachment == attachment) return; + 86- if (!(attachment instanceof VertexAttachment newAttachment) || !(this.attachment instanceof VertexAttachment oldAttachment) 87- || newAttachment.getTimelineAttachment() != oldAttachment.getTimelineAttachment()) { 88- deform.clear(); 89- } diff --git a/spine-cpp/include/spine/AnimationState.h b/spine-cpp/include/spine/AnimationState.h index 715e006e9..ee608287b 100644 --- a/spine-cpp/include/spine/AnimationState.h +++ b/spine-cpp/include/spine/AnimationState.h @@ -398,7 +398,7 @@ namespace spine { friend class EventQueue; public: - explicit AnimationState(AnimationStateData *data); + explicit AnimationState(AnimationStateData &data); ~AnimationState(); @@ -437,7 +437,7 @@ namespace spine { /// @return /// A track entry to allow further customization of animation playback. References to the track entry must not be kept /// after AnimationState.Dispose. - TrackEntry &setAnimation(size_t trackIndex, Animation *animation, bool loop); + TrackEntry &setAnimation(size_t trackIndex, Animation &animation, bool loop); /// Queues an animation by name. /// @@ -452,7 +452,7 @@ namespace spine { /// /// @return A track entry to allow further customization of animation playback. References to the track entry must not be kept /// after AnimationState.Dispose - TrackEntry &addAnimation(size_t trackIndex, Animation *animation, bool loop, float delay); + TrackEntry &addAnimation(size_t trackIndex, Animation &animation, bool loop, float delay); /// Sets an empty animation for a track, discarding any queued animations, and sets the track entry's /// TrackEntry::getMixDuration(). An empty animation has no timelines and serves as a placeholder for mixing in or out. diff --git a/spine-cpp/include/spine/AnimationStateData.h b/spine-cpp/include/spine/AnimationStateData.h index be57f1a64..54b1d5a71 100644 --- a/spine-cpp/include/spine/AnimationStateData.h +++ b/spine-cpp/include/spine/AnimationStateData.h @@ -46,7 +46,7 @@ namespace spine { friend class AnimationState; public: - explicit AnimationStateData(SkeletonData *skeletonData); + explicit AnimationStateData(SkeletonData &skeletonData); /// The SkeletonData to look up animations when they are specified by name. SkeletonData &getSkeletonData(); diff --git a/spine-cpp/include/spine/AtlasAttachmentLoader.h b/spine-cpp/include/spine/AtlasAttachmentLoader.h index 25369ec51..ab3f85886 100644 --- a/spine-cpp/include/spine/AtlasAttachmentLoader.h +++ b/spine-cpp/include/spine/AtlasAttachmentLoader.h @@ -46,7 +46,7 @@ namespace spine { /// Spine Runtimes Guide. class SP_API AtlasAttachmentLoader : public AttachmentLoader { public: - explicit AtlasAttachmentLoader(Atlas *atlas); + explicit AtlasAttachmentLoader(Atlas &atlas); virtual RegionAttachment *newRegionAttachment(Skin &skin, const String &name, const String &path, Sequence *sequence); diff --git a/spine-cpp/include/spine/DeformTimeline.h b/spine-cpp/include/spine/DeformTimeline.h index d776cc450..d6698e86f 100644 --- a/spine-cpp/include/spine/DeformTimeline.h +++ b/spine-cpp/include/spine/DeformTimeline.h @@ -44,7 +44,7 @@ namespace spine { RTTI_DECL public: - explicit DeformTimeline(size_t frameCount, size_t bezierCount, int slotIndex, VertexAttachment *attachment); + explicit DeformTimeline(size_t frameCount, size_t bezierCount, int slotIndex, VertexAttachment &attachment); /// Sets the time and vertices for the specified frame. void setFrame(int frameIndex, float time, Array &vertices); diff --git a/spine-cpp/include/spine/LinkedMesh.h b/spine-cpp/include/spine/LinkedMesh.h index 3770ec45c..75ec16185 100644 --- a/spine-cpp/include/spine/LinkedMesh.h +++ b/spine-cpp/include/spine/LinkedMesh.h @@ -42,9 +42,9 @@ namespace spine { friend class SkeletonJson; public: - LinkedMesh(MeshAttachment *mesh, const int skinIndex, size_t slotIndex, const String &parent, bool inheritTimelines); + LinkedMesh(MeshAttachment &mesh, const int skinIndex, size_t slotIndex, const String &parent, bool inheritTimelines); - LinkedMesh(MeshAttachment *mesh, const String &skin, size_t slotIndex, const String &parent, bool inheritTimelines); + LinkedMesh(MeshAttachment &mesh, const String &skin, size_t slotIndex, const String &parent, bool inheritTimelines); private: MeshAttachment *_mesh; diff --git a/spine-cpp/include/spine/SequenceTimeline.h b/spine-cpp/include/spine/SequenceTimeline.h index 57c630d08..3194abe7f 100644 --- a/spine-cpp/include/spine/SequenceTimeline.h +++ b/spine-cpp/include/spine/SequenceTimeline.h @@ -47,7 +47,7 @@ namespace spine { RTTI_DECL public: - explicit SequenceTimeline(size_t frameCount, int slotIndex, Attachment *attachment); + explicit SequenceTimeline(size_t frameCount, int slotIndex, Attachment &attachment); virtual ~SequenceTimeline(); diff --git a/spine-cpp/include/spine/SkeletonBinary.h b/spine-cpp/include/spine/SkeletonBinary.h index 6518a2578..027835d56 100644 --- a/spine-cpp/include/spine/SkeletonBinary.h +++ b/spine-cpp/include/spine/SkeletonBinary.h @@ -115,9 +115,9 @@ namespace spine { static const int CURVE_STEPPED = 1; static const int CURVE_BEZIER = 2; - explicit SkeletonBinary(Atlas *atlas); + explicit SkeletonBinary(Atlas &atlas); - explicit SkeletonBinary(AttachmentLoader *attachmentLoader, bool ownsLoader = false); + explicit SkeletonBinary(AttachmentLoader &attachmentLoader, bool ownsLoader = false); ~SkeletonBinary(); diff --git a/spine-cpp/include/spine/SkeletonJson.h b/spine-cpp/include/spine/SkeletonJson.h index 80d1e68e5..d004930f6 100644 --- a/spine-cpp/include/spine/SkeletonJson.h +++ b/spine-cpp/include/spine/SkeletonJson.h @@ -67,9 +67,9 @@ namespace spine { class SP_API SkeletonJson : public SpineObject { public: - explicit SkeletonJson(Atlas *atlas); + explicit SkeletonJson(Atlas &atlas); - explicit SkeletonJson(AttachmentLoader *attachmentLoader, bool ownsLoader = false); + explicit SkeletonJson(AttachmentLoader &attachmentLoader, bool ownsLoader = false); ~SkeletonJson(); diff --git a/spine-cpp/spine-cpp-lite/spine-cpp-lite.cpp b/spine-cpp/spine-cpp-lite/spine-cpp-lite.cpp index 3f124357d..6ec60e900 100644 --- a/spine-cpp/spine-cpp-lite/spine-cpp-lite.cpp +++ b/spine-cpp/spine-cpp-lite/spine-cpp-lite.cpp @@ -610,7 +610,7 @@ spine_skeleton_drawable spine_skeleton_drawable_create(spine_skeleton_data skele drawable->skeleton = (spine_skeleton) new (__FILE__, __LINE__) Skeleton((SkeletonData *) skeletonData); AnimationStateData *stateData = new (__FILE__, __LINE__) AnimationStateData((SkeletonData *) skeletonData); drawable->animationStateData = (spine_animation_state_data) stateData; - AnimationState *state = new (__FILE__, __LINE__) AnimationState(stateData); + AnimationState *state = new (__FILE__, __LINE__) AnimationState(*stateData); drawable->animationState = (spine_animation_state) state; state->setManualTrackEntryDisposal(true); EventListener *listener = new EventListener(); diff --git a/spine-cpp/src/spine/AnimationState.cpp b/spine-cpp/src/spine/AnimationState.cpp index 5c177ce85..899502dc4 100644 --- a/spine-cpp/src/spine/AnimationState.cpp +++ b/spine-cpp/src/spine/AnimationState.cpp @@ -431,8 +431,8 @@ void EventQueue::drain() { _drainDisabled = false; } -AnimationState::AnimationState(AnimationStateData *data) - : _data(data), _queue(EventQueue::newEventQueue(*this)), _animationsChanged(false), _listener(dummyOnAnimationEventFunc), _listenerObject(NULL), +AnimationState::AnimationState(AnimationStateData &data) + : _data(&data), _queue(EventQueue::newEventQueue(*this)), _animationsChanged(false), _listener(dummyOnAnimationEventFunc), _listenerObject(NULL), _unkeyedState(0), _timeScale(1), _manualTrackEntryDisposal(false) { } @@ -652,16 +652,14 @@ void AnimationState::clearTrack(size_t trackIndex) { TrackEntry &AnimationState::setAnimation(size_t trackIndex, const String &animationName, bool loop) { Animation *animation = _data->_skeletonData->findAnimation(animationName); assert(animation != NULL); - return setAnimation(trackIndex, animation, loop); + return setAnimation(trackIndex, *animation, loop); } -TrackEntry &AnimationState::setAnimation(size_t trackIndex, Animation *animation, bool loop) { - assert(animation != NULL); - +TrackEntry &AnimationState::setAnimation(size_t trackIndex, Animation &animation, bool loop) { bool interrupt = true; TrackEntry *current = expandToIndex(trackIndex); if (current != NULL) { - if (current->_nextTrackLast == -1 && current->_animation == animation) { + if (current->_nextTrackLast == -1 && current->_animation == &animation) { // Don't mix from an entry that was never applied. _tracks[trackIndex] = current->_mixingFrom; _queue->interrupt(current); @@ -674,7 +672,7 @@ TrackEntry &AnimationState::setAnimation(size_t trackIndex, Animation *animation } } - TrackEntry *entry = newTrackEntry(trackIndex, animation, loop, current); + TrackEntry *entry = newTrackEntry(trackIndex, &animation, loop, current); setCurrent(trackIndex, entry, interrupt); _queue->drain(); @@ -684,18 +682,16 @@ TrackEntry &AnimationState::setAnimation(size_t trackIndex, Animation *animation TrackEntry &AnimationState::addAnimation(size_t trackIndex, const String &animationName, bool loop, float delay) { Animation *animation = _data->_skeletonData->findAnimation(animationName); assert(animation != NULL); - return addAnimation(trackIndex, animation, loop, delay); + return addAnimation(trackIndex, *animation, loop, delay); } -TrackEntry &AnimationState::addAnimation(size_t trackIndex, Animation *animation, bool loop, float delay) { - assert(animation != NULL); - +TrackEntry &AnimationState::addAnimation(size_t trackIndex, Animation &animation, bool loop, float delay) { TrackEntry *last = expandToIndex(trackIndex); if (last != NULL) { while (last->_next != NULL) last = last->_next; } - TrackEntry *entry = newTrackEntry(trackIndex, animation, loop, last); + TrackEntry *entry = newTrackEntry(trackIndex, &animation, loop, last); if (last == NULL) { setCurrent(trackIndex, entry, true); @@ -712,14 +708,14 @@ TrackEntry &AnimationState::addAnimation(size_t trackIndex, Animation *animation } TrackEntry &AnimationState::setEmptyAnimation(size_t trackIndex, float mixDuration) { - TrackEntry &entry = setAnimation(trackIndex, AnimationState::getEmptyAnimation(), false); + TrackEntry &entry = setAnimation(trackIndex, *AnimationState::getEmptyAnimation(), false); entry._mixDuration = mixDuration; entry._trackEnd = mixDuration; return entry; } TrackEntry &AnimationState::addEmptyAnimation(size_t trackIndex, float mixDuration, float delay) { - TrackEntry &entry = addAnimation(trackIndex, AnimationState::getEmptyAnimation(), false, delay); + TrackEntry &entry = addAnimation(trackIndex, *AnimationState::getEmptyAnimation(), false, delay); if (delay <= 0) entry._delay = MathUtil::max(entry._delay + entry._mixDuration - mixDuration, 0.0f); entry._mixDuration = mixDuration; entry._trackEnd = mixDuration; diff --git a/spine-cpp/src/spine/AnimationStateData.cpp b/spine-cpp/src/spine/AnimationStateData.cpp index 5a27ba6d1..2a3b6211c 100644 --- a/spine-cpp/src/spine/AnimationStateData.cpp +++ b/spine-cpp/src/spine/AnimationStateData.cpp @@ -33,7 +33,7 @@ using namespace spine; -AnimationStateData::AnimationStateData(SkeletonData *skeletonData) : _skeletonData(skeletonData), _defaultMix(0) { +AnimationStateData::AnimationStateData(SkeletonData &skeletonData) : _skeletonData(&skeletonData), _defaultMix(0) { } void AnimationStateData::setMix(const String &fromName, const String &toName, float duration) { diff --git a/spine-cpp/src/spine/AtlasAttachmentLoader.cpp b/spine-cpp/src/spine/AtlasAttachmentLoader.cpp index f12019262..cb60285b9 100644 --- a/spine-cpp/src/spine/AtlasAttachmentLoader.cpp +++ b/spine-cpp/src/spine/AtlasAttachmentLoader.cpp @@ -40,7 +40,7 @@ using namespace spine; -AtlasAttachmentLoader::AtlasAttachmentLoader(Atlas *atlas) : AttachmentLoader(), _atlas(atlas) { +AtlasAttachmentLoader::AtlasAttachmentLoader(Atlas &atlas) : AttachmentLoader(), _atlas(&atlas) { } bool loadSequence(Atlas *atlas, const String &basePath, Sequence *sequence) { diff --git a/spine-cpp/src/spine/DeformTimeline.cpp b/spine-cpp/src/spine/DeformTimeline.cpp index a4b0d8b99..d00f57412 100644 --- a/spine-cpp/src/spine/DeformTimeline.cpp +++ b/spine-cpp/src/spine/DeformTimeline.cpp @@ -43,9 +43,9 @@ using namespace spine; RTTI_IMPL(DeformTimeline, CurveTimeline) -DeformTimeline::DeformTimeline(size_t frameCount, size_t bezierCount, int slotIndex, VertexAttachment *attachment) - : SlotCurveTimeline(frameCount, 1, bezierCount, slotIndex), _attachment(attachment) { - PropertyId ids[] = {((PropertyId) Property_Deform << 32) | ((slotIndex << 16 | attachment->_id) & 0xffffffff)}; +DeformTimeline::DeformTimeline(size_t frameCount, size_t bezierCount, int slotIndex, VertexAttachment &attachment) + : SlotCurveTimeline(frameCount, 1, bezierCount, slotIndex), _attachment(&attachment) { + PropertyId ids[] = {((PropertyId) Property_Deform << 32) | ((slotIndex << 16 | attachment._id) & 0xffffffff)}; setPropertyIds(ids, 1); _vertices.ensureCapacity(frameCount); diff --git a/spine-cpp/src/spine/LinkedMesh.cpp b/spine-cpp/src/spine/LinkedMesh.cpp index 28755c649..2c08ccda3 100644 --- a/spine-cpp/src/spine/LinkedMesh.cpp +++ b/spine-cpp/src/spine/LinkedMesh.cpp @@ -33,10 +33,10 @@ using namespace spine; -LinkedMesh::LinkedMesh(MeshAttachment *mesh, const int skinIndex, size_t slotIndex, const String &parent, bool inheritTimelines) - : _mesh(mesh), _skinIndex(skinIndex), _skin(""), _slotIndex(slotIndex), _parent(parent), _inheritTimelines(inheritTimelines) { +LinkedMesh::LinkedMesh(MeshAttachment &mesh, const int skinIndex, size_t slotIndex, const String &parent, bool inheritTimelines) + : _mesh(&mesh), _skinIndex(skinIndex), _skin(""), _slotIndex(slotIndex), _parent(parent), _inheritTimelines(inheritTimelines) { } -LinkedMesh::LinkedMesh(MeshAttachment *mesh, const String &skin, size_t slotIndex, const String &parent, bool inheritTimelines) - : _mesh(mesh), _skinIndex(-1), _skin(skin), _slotIndex(slotIndex), _parent(parent), _inheritTimelines(inheritTimelines) { +LinkedMesh::LinkedMesh(MeshAttachment &mesh, const String &skin, size_t slotIndex, const String &parent, bool inheritTimelines) + : _mesh(&mesh), _skinIndex(-1), _skin(skin), _slotIndex(slotIndex), _parent(parent), _inheritTimelines(inheritTimelines) { } diff --git a/spine-cpp/src/spine/SequenceTimeline.cpp b/spine-cpp/src/spine/SequenceTimeline.cpp index d06b198a6..e4d46c626 100644 --- a/spine-cpp/src/spine/SequenceTimeline.cpp +++ b/spine-cpp/src/spine/SequenceTimeline.cpp @@ -43,11 +43,11 @@ using namespace spine; RTTI_IMPL_MULTI(SequenceTimeline, Timeline, SlotTimeline) -SequenceTimeline::SequenceTimeline(size_t frameCount, int slotIndex, Attachment *attachment) - : Timeline(frameCount, ENTRIES), SlotTimeline(), _slotIndex(slotIndex), _attachment((HasTextureRegion *) attachment) { +SequenceTimeline::SequenceTimeline(size_t frameCount, int slotIndex, Attachment &attachment) + : Timeline(frameCount, ENTRIES), SlotTimeline(), _slotIndex(slotIndex), _attachment((HasTextureRegion *) &attachment) { int sequenceId = 0; - if (attachment->getRTTI().instanceOf(RegionAttachment::rtti)) sequenceId = ((RegionAttachment *) attachment)->getSequence()->getId(); - if (attachment->getRTTI().instanceOf(MeshAttachment::rtti)) sequenceId = ((MeshAttachment *) attachment)->getSequence()->getId(); + if (attachment.getRTTI().instanceOf(RegionAttachment::rtti)) sequenceId = ((RegionAttachment *) &attachment)->getSequence()->getId(); + if (attachment.getRTTI().instanceOf(MeshAttachment::rtti)) sequenceId = ((MeshAttachment *) &attachment)->getSequence()->getId(); PropertyId ids[] = {((PropertyId) Property_Sequence << 32) | ((slotIndex << 16 | sequenceId) & 0xffffffff)}; setPropertyIds(ids, 1); } diff --git a/spine-cpp/src/spine/SkeletonBinary.cpp b/spine-cpp/src/spine/SkeletonBinary.cpp index fe51414f7..a0de8d6eb 100644 --- a/spine-cpp/src/spine/SkeletonBinary.cpp +++ b/spine-cpp/src/spine/SkeletonBinary.cpp @@ -79,13 +79,12 @@ using namespace spine; -SkeletonBinary::SkeletonBinary(Atlas *atlas) +SkeletonBinary::SkeletonBinary(Atlas &atlas) : _attachmentLoader(new(__FILE__, __LINE__) AtlasAttachmentLoader(atlas)), _error(), _scale(1), _ownsLoader(true) { } -SkeletonBinary::SkeletonBinary(AttachmentLoader *attachmentLoader, bool ownsLoader) - : _attachmentLoader(attachmentLoader), _error(), _scale(1), _ownsLoader(ownsLoader) { - assert(_attachmentLoader != NULL); +SkeletonBinary::SkeletonBinary(AttachmentLoader &attachmentLoader, bool ownsLoader) + : _attachmentLoader(&attachmentLoader), _error(), _scale(1), _ownsLoader(ownsLoader) { } SkeletonBinary::~SkeletonBinary() { @@ -682,7 +681,7 @@ Attachment *SkeletonBinary::readAttachment(DataInput &input, Skin &skin, int slo mesh->setWidth(width * scale); mesh->setHeight(height * scale); } - _linkedMeshes.add(new (__FILE__, __LINE__) LinkedMesh(mesh, skinIndex, slotIndex, parent, inheritTimelines)); + _linkedMeshes.add(new (__FILE__, __LINE__) LinkedMesh(*mesh, skinIndex, slotIndex, parent, inheritTimelines)); return mesh; } case AttachmentType_Path: { @@ -1236,7 +1235,7 @@ Animation *SkeletonBinary::readAnimation(DataInput &input, const String &name, S int deformLength = weighted ? (int) vertices.size() / 3 * 2 : (int) vertices.size(); DeformTimeline *timeline = new (__FILE__, __LINE__) - DeformTimeline(frameCount, input.readInt(true), slotIndex, vertexAttachment); + DeformTimeline(frameCount, input.readInt(true), slotIndex, *vertexAttachment); float time = input.readFloat(); for (int frame = 0, bezier = 0;; ++frame) { @@ -1280,7 +1279,7 @@ Animation *SkeletonBinary::readAnimation(DataInput &input, const String &name, S break; } case ATTACHMENT_SEQUENCE: { - SequenceTimeline *timeline = new (__FILE__, __LINE__) SequenceTimeline(frameCount, slotIndex, attachment); + SequenceTimeline *timeline = new (__FILE__, __LINE__) SequenceTimeline(frameCount, slotIndex, *attachment); for (int frame = 0; frame < frameCount; frame++) { float time = input.readFloat(); int modeAndIndex = input.readInt(); diff --git a/spine-cpp/src/spine/SkeletonJson.cpp b/spine-cpp/src/spine/SkeletonJson.cpp index a77edb294..46ec13223 100644 --- a/spine-cpp/src/spine/SkeletonJson.cpp +++ b/spine-cpp/src/spine/SkeletonJson.cpp @@ -121,12 +121,11 @@ static float propertyScale(const char *type, float scale) { return 1; } -SkeletonJson::SkeletonJson(Atlas *atlas) : _attachmentLoader(new(__FILE__, __LINE__) AtlasAttachmentLoader(atlas)), _scale(1), _ownsLoader(true) { +SkeletonJson::SkeletonJson(Atlas &atlas) : _attachmentLoader(new(__FILE__, __LINE__) AtlasAttachmentLoader(atlas)), _scale(1), _ownsLoader(true) { } -SkeletonJson::SkeletonJson(AttachmentLoader *attachmentLoader, bool ownsLoader) - : _attachmentLoader(attachmentLoader), _scale(1), _ownsLoader(ownsLoader) { - assert(_attachmentLoader != NULL); +SkeletonJson::SkeletonJson(AttachmentLoader &attachmentLoader, bool ownsLoader) + : _attachmentLoader(&attachmentLoader), _scale(1), _ownsLoader(ownsLoader) { } SkeletonJson::~SkeletonJson() { @@ -675,7 +674,7 @@ Attachment *SkeletonJson::readAttachment(Json *map, Skin *skin, int slotIndex, c const char *parent = Json::getString(map, "parent", NULL); if (parent) { LinkedMesh *linkedMesh = new (__FILE__, __LINE__) - LinkedMesh(mesh, Json::getString(map, "skin", NULL), slotIndex, parent, Json::getBoolean(map, "timelines", true)); + LinkedMesh(*mesh, Json::getString(map, "skin", NULL), slotIndex, parent, Json::getBoolean(map, "timelines", true)); _linkedMeshes.add(linkedMesh); return mesh; } @@ -1262,7 +1261,7 @@ Animation *SkeletonJson::readAnimation(Json *map, SkeletonData *skeletonData) { Array &vertices = vertexAttachment->_vertices; int deformLength = weighted ? (int) vertices.size() / 3 * 2 : (int) vertices.size(); - DeformTimeline *timeline = new (__FILE__, __LINE__) DeformTimeline(frames, frames, slotIndex, vertexAttachment); + DeformTimeline *timeline = new (__FILE__, __LINE__) DeformTimeline(frames, frames, slotIndex, *vertexAttachment); float time = Json::getFloat(keyMap, "time", 0); for (int frame = 0, bezier = 0;; frame++) { Array deform; @@ -1305,7 +1304,7 @@ Animation *SkeletonJson::readAnimation(Json *map, SkeletonData *skeletonData) { } timelines.add(timeline); } else if (timelineName == "sequence") { - SequenceTimeline *timeline = new (__FILE__, __LINE__) SequenceTimeline(frames, slotIndex, attachment); + SequenceTimeline *timeline = new (__FILE__, __LINE__) SequenceTimeline(frames, slotIndex, *attachment); float lastDelay = 0; for (int frame = 0; keyMap != NULL; keyMap = keyMap->_next, frame++) { float delay = Json::getFloat(keyMap, "delay", lastDelay); diff --git a/spine-cpp/tests/HeadlessTest.cpp b/spine-cpp/tests/HeadlessTest.cpp index e0ba67d70..5027beafe 100644 --- a/spine-cpp/tests/HeadlessTest.cpp +++ b/spine-cpp/tests/HeadlessTest.cpp @@ -90,10 +90,10 @@ int main(int argc, char *argv[]) { SkeletonData *skeletonData = nullptr; if (strstr(skeletonPath, ".json") != nullptr) { - SkeletonJson json(atlas); + SkeletonJson json(*atlas); skeletonData = json.readSkeletonDataFile(skeletonPath); } else { - SkeletonBinary binary(atlas); + SkeletonBinary binary(*atlas); skeletonData = binary.readSkeletonDataFile(skeletonPath); } @@ -111,8 +111,8 @@ int main(int argc, char *argv[]) { AnimationStateData *stateData = nullptr; if (animationName != nullptr) { // Create animation state only when needed - stateData = new AnimationStateData(skeletonData); - state = new AnimationState(stateData); + stateData = new AnimationStateData(*skeletonData); + state = new AnimationState(*stateData); // Find and set animation Animation *animation = skeletonData->findAnimation(animationName); @@ -122,7 +122,7 @@ int main(int argc, char *argv[]) { delete atlas; return 1; } - state->setAnimation(0, animation, true); + state->setAnimation(0, *animation, true); // Update and apply state->update(0.016f); state->apply(skeleton);