From 3d5075c7a47e016ac7ff808fc15f8ead21d978da Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Fri, 9 Sep 2022 10:21:58 +0200 Subject: [PATCH] [cpp] Refactor renderer object system Attachments and AtlasPages no longer implement HasRendererObject. Instead, the TextureRegion provides the renderer object. This decouples everything from AtlasRegion, making substituting custom texture regions less error prone. --- spine-cpp/spine-cpp/include/spine/AnimationState.h | 5 ++--- spine-cpp/spine-cpp/include/spine/Atlas.h | 5 +++-- spine-cpp/spine-cpp/include/spine/IkConstraint.h | 3 --- spine-cpp/spine-cpp/include/spine/MeshAttachment.h | 2 +- spine-cpp/spine-cpp/include/spine/RegionAttachment.h | 2 +- spine-cpp/spine-cpp/src/spine/AnimationState.cpp | 9 ++++----- spine-cpp/spine-cpp/src/spine/Atlas.cpp | 3 ++- spine-cpp/spine-cpp/src/spine/AtlasAttachmentLoader.cpp | 2 -- spine-cpp/spine-cpp/src/spine/MeshAttachment.cpp | 4 +--- spine-cpp/spine-cpp/src/spine/RegionAttachment.cpp | 3 +-- spine-cpp/spine-cpp/src/spine/Sequence.cpp | 2 -- 11 files changed, 15 insertions(+), 25 deletions(-) diff --git a/spine-cpp/spine-cpp/include/spine/AnimationState.h b/spine-cpp/spine-cpp/include/spine/AnimationState.h index 3ee959c6d..d7acd6363 100644 --- a/spine-cpp/spine-cpp/include/spine/AnimationState.h +++ b/spine-cpp/spine-cpp/include/spine/AnimationState.h @@ -311,14 +311,13 @@ namespace spine { private: Vector _eventQueueEntries; AnimationState &_state; - Pool &_trackEntryPool; bool _drainDisabled; - static EventQueue *newEventQueue(AnimationState &state, Pool &trackEntryPool); + static EventQueue *newEventQueue(AnimationState &state); static EventQueueEntry newEventQueueEntry(EventType eventType, TrackEntry *entry, Event *event = NULL); - EventQueue(AnimationState &state, Pool &trackEntryPool); + EventQueue(AnimationState &state); ~EventQueue(); diff --git a/spine-cpp/spine-cpp/include/spine/Atlas.h b/spine-cpp/spine-cpp/include/spine/Atlas.h index 2cdabe762..c65688d6d 100644 --- a/spine-cpp/spine-cpp/include/spine/Atlas.h +++ b/spine-cpp/spine-cpp/include/spine/Atlas.h @@ -73,7 +73,7 @@ namespace spine { TextureWrap_Repeat }; - class SP_API AtlasPage : public SpineObject, public HasRendererObject { + class SP_API AtlasPage : public SpineObject { public: String name; String texturePath; @@ -85,11 +85,12 @@ namespace spine { int width, height; bool pma; int index; + void *texture; explicit AtlasPage(const String &inName) : name(inName), format(Format_RGBA8888), minFilter(TextureFilter_Nearest), magFilter(TextureFilter_Nearest), uWrap(TextureWrap_ClampToEdge), - vWrap(TextureWrap_ClampToEdge), width(0), height(0), pma(false), index(0) { + vWrap(TextureWrap_ClampToEdge), width(0), height(0), pma(false), index(0), texture(NULL) { } }; diff --git a/spine-cpp/spine-cpp/include/spine/IkConstraint.h b/spine-cpp/spine-cpp/include/spine/IkConstraint.h index 477108dfc..c00193fca 100644 --- a/spine-cpp/spine-cpp/include/spine/IkConstraint.h +++ b/spine-cpp/spine-cpp/include/spine/IkConstraint.h @@ -64,9 +64,6 @@ namespace spine { IkConstraint(IkConstraintData &data, Skeleton &skeleton); - /// Applies the constraint to the constrained bones. - void apply(); - virtual void update(); virtual int getOrder(); diff --git a/spine-cpp/spine-cpp/include/spine/MeshAttachment.h b/spine-cpp/spine-cpp/include/spine/MeshAttachment.h index 6961a2dd3..757a85385 100644 --- a/spine-cpp/spine-cpp/include/spine/MeshAttachment.h +++ b/spine-cpp/spine-cpp/include/spine/MeshAttachment.h @@ -39,7 +39,7 @@ namespace spine { /// Attachment that displays a texture region using a mesh. - class SP_API MeshAttachment : public VertexAttachment, public HasRendererObject { + class SP_API MeshAttachment : public VertexAttachment { friend class SkeletonBinary; friend class SkeletonJson; diff --git a/spine-cpp/spine-cpp/include/spine/RegionAttachment.h b/spine-cpp/spine-cpp/include/spine/RegionAttachment.h index bd8cc1827..2202fb402 100644 --- a/spine-cpp/spine-cpp/include/spine/RegionAttachment.h +++ b/spine-cpp/spine-cpp/include/spine/RegionAttachment.h @@ -44,7 +44,7 @@ namespace spine { class Bone; /// Attachment that displays a texture region. - class SP_API RegionAttachment : public Attachment, public HasRendererObject { + class SP_API RegionAttachment : public Attachment { friend class SkeletonBinary; friend class SkeletonJson; diff --git a/spine-cpp/spine-cpp/src/spine/AnimationState.cpp b/spine-cpp/spine-cpp/src/spine/AnimationState.cpp index 8f85a6111..02328d2a3 100644 --- a/spine-cpp/spine-cpp/src/spine/AnimationState.cpp +++ b/spine-cpp/spine-cpp/src/spine/AnimationState.cpp @@ -211,16 +211,15 @@ EventQueueEntry::EventQueueEntry(EventType eventType, TrackEntry *trackEntry, Ev _event(event) { } -EventQueue *EventQueue::newEventQueue(AnimationState &state, Pool &trackEntryPool) { - return new (__FILE__, __LINE__) EventQueue(state, trackEntryPool); +EventQueue *EventQueue::newEventQueue(AnimationState &state) { + return new (__FILE__, __LINE__) EventQueue(state); } EventQueueEntry EventQueue::newEventQueueEntry(EventType eventType, TrackEntry *entry, Event *event) { return EventQueueEntry(eventType, entry, event); } -EventQueue::EventQueue(AnimationState &state, Pool &trackEntryPool) : _state(state), - _trackEntryPool(trackEntryPool), +EventQueue::EventQueue(AnimationState &state) : _state(state), _drainDisabled(false) { } @@ -314,7 +313,7 @@ void EventQueue::drain() { } AnimationState::AnimationState(AnimationStateData *data) : _data(data), - _queue(EventQueue::newEventQueue(*this, _trackEntryPool)), + _queue(EventQueue::newEventQueue(*this)), _animationsChanged(false), _listener(dummyOnAnimationEventFunc), _listenerObject(NULL), diff --git a/spine-cpp/spine-cpp/src/spine/Atlas.cpp b/spine-cpp/spine-cpp/src/spine/Atlas.cpp index d13a0806c..c29e2f570 100644 --- a/spine-cpp/spine-cpp/src/spine/Atlas.cpp +++ b/spine-cpp/spine-cpp/src/spine/Atlas.cpp @@ -69,7 +69,7 @@ Atlas::Atlas(const char *data, int length, const char *dir, TextureLoader *textu Atlas::~Atlas() { if (_textureLoader) { for (size_t i = 0, n = _pages.size(); i < n; ++i) { - _textureLoader->unload(_pages[i]->getRendererObject()); + _textureLoader->unload(_pages[i]->texture); } } ContainerUtil::cleanUpVectorOfPointers(_pages); @@ -291,6 +291,7 @@ void Atlas::load(const char *begin, int length, const char *dir, bool createText } else { AtlasRegion *region = new (__FILE__, __LINE__) AtlasRegion(); region->page = page; + region->rendererObject = page->texture; region->name = String(line->copy(), true); while (true) { line = reader.readLine(); diff --git a/spine-cpp/spine-cpp/src/spine/AtlasAttachmentLoader.cpp b/spine-cpp/spine-cpp/src/spine/AtlasAttachmentLoader.cpp index 78d56179b..fbd22e9ea 100644 --- a/spine-cpp/spine-cpp/src/spine/AtlasAttachmentLoader.cpp +++ b/spine-cpp/spine-cpp/src/spine/AtlasAttachmentLoader.cpp @@ -63,7 +63,6 @@ namespace spine { } else { AtlasRegion *region = findRegion(path); if (!region) return NULL; - attachment->setRendererObject(region); attachment->setRegion(region); } return attachment; @@ -78,7 +77,6 @@ namespace spine { } else { AtlasRegion *region = findRegion(path); if (!region) return NULL; - attachment->setRendererObject(region); attachment->setRegion(region); } return attachment; diff --git a/spine-cpp/spine-cpp/src/spine/MeshAttachment.cpp b/spine-cpp/spine-cpp/src/spine/MeshAttachment.cpp index 44fc15960..57562f508 100644 --- a/spine-cpp/spine-cpp/src/spine/MeshAttachment.cpp +++ b/spine-cpp/spine-cpp/src/spine/MeshAttachment.cpp @@ -34,7 +34,7 @@ using namespace spine; RTTI_IMPL(MeshAttachment, VertexAttachment) -MeshAttachment::MeshAttachment(const String &name) : VertexAttachment(name), HasRendererObject(), +MeshAttachment::MeshAttachment(const String &name) : VertexAttachment(name), _parentMesh(NULL), _path(), _color(1, 1, 1, 1), @@ -203,7 +203,6 @@ Attachment *MeshAttachment::copy() { if (_parentMesh) return newLinkedMesh(); MeshAttachment *copy = new (__FILE__, __LINE__) MeshAttachment(getName()); - copy->setRendererObject(getRendererObject()); copy->setRegion(_region); copy->setSequence(_sequence != NULL ? _sequence->copy() : NULL); copy->_path = _path; @@ -224,7 +223,6 @@ Attachment *MeshAttachment::copy() { MeshAttachment *MeshAttachment::newLinkedMesh() { MeshAttachment *copy = new (__FILE__, __LINE__) MeshAttachment(getName()); - copy->setRendererObject(getRendererObject()); copy->setRegion(_region); copy->_path = _path; copy->_color.set(_color); diff --git a/spine-cpp/spine-cpp/src/spine/RegionAttachment.cpp b/spine-cpp/spine-cpp/src/spine/RegionAttachment.cpp index 14ea9746a..54252d8c9 100644 --- a/spine-cpp/spine-cpp/src/spine/RegionAttachment.cpp +++ b/spine-cpp/spine-cpp/src/spine/RegionAttachment.cpp @@ -47,7 +47,7 @@ const int RegionAttachment::URY = 5; const int RegionAttachment::BRX = 6; const int RegionAttachment::BRY = 7; -RegionAttachment::RegionAttachment(const String &name) : Attachment(name), HasRendererObject(), +RegionAttachment::RegionAttachment(const String &name) : Attachment(name), _x(0), _y(0), _rotation(0), @@ -247,7 +247,6 @@ spine::Color &RegionAttachment::getColor() { Attachment *RegionAttachment::copy() { RegionAttachment *copy = new (__FILE__, __LINE__) RegionAttachment(getName()); copy->_region = _region; - copy->setRendererObject(getRendererObject()); copy->_path = _path; copy->_x = _x; copy->_y = _y; diff --git a/spine-cpp/spine-cpp/src/spine/Sequence.cpp b/spine-cpp/spine-cpp/src/spine/Sequence.cpp index f07f1c861..3b4bcf5d1 100644 --- a/spine-cpp/spine-cpp/src/spine/Sequence.cpp +++ b/spine-cpp/spine-cpp/src/spine/Sequence.cpp @@ -66,7 +66,6 @@ void Sequence::apply(Slot *slot, Attachment *attachment) { if (attachment->getRTTI().isExactly(RegionAttachment::rtti)) { RegionAttachment *regionAttachment = static_cast(attachment); if (regionAttachment->getRegion() != region) { - regionAttachment->setRendererObject(region); regionAttachment->setRegion(region); regionAttachment->updateRegion(); } @@ -75,7 +74,6 @@ void Sequence::apply(Slot *slot, Attachment *attachment) { if (attachment->getRTTI().isExactly(MeshAttachment::rtti)) { MeshAttachment *meshAttachment = static_cast(attachment); if (meshAttachment->getRegion() != region) { - meshAttachment->setRendererObject(region); meshAttachment->setRegion(region); meshAttachment->updateRegion(); }