[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.
This commit is contained in:
Mario Zechner 2022-09-09 10:21:58 +02:00
parent 6d0a60e255
commit 3d5075c7a4
11 changed files with 15 additions and 25 deletions

View File

@ -311,14 +311,13 @@ namespace spine {
private: private:
Vector<EventQueueEntry> _eventQueueEntries; Vector<EventQueueEntry> _eventQueueEntries;
AnimationState &_state; AnimationState &_state;
Pool<TrackEntry> &_trackEntryPool;
bool _drainDisabled; bool _drainDisabled;
static EventQueue *newEventQueue(AnimationState &state, Pool<TrackEntry> &trackEntryPool); static EventQueue *newEventQueue(AnimationState &state);
static EventQueueEntry newEventQueueEntry(EventType eventType, TrackEntry *entry, Event *event = NULL); static EventQueueEntry newEventQueueEntry(EventType eventType, TrackEntry *entry, Event *event = NULL);
EventQueue(AnimationState &state, Pool<TrackEntry> &trackEntryPool); EventQueue(AnimationState &state);
~EventQueue(); ~EventQueue();

View File

@ -73,7 +73,7 @@ namespace spine {
TextureWrap_Repeat TextureWrap_Repeat
}; };
class SP_API AtlasPage : public SpineObject, public HasRendererObject { class SP_API AtlasPage : public SpineObject {
public: public:
String name; String name;
String texturePath; String texturePath;
@ -85,11 +85,12 @@ namespace spine {
int width, height; int width, height;
bool pma; bool pma;
int index; int index;
void *texture;
explicit AtlasPage(const String &inName) : name(inName), format(Format_RGBA8888), explicit AtlasPage(const String &inName) : name(inName), format(Format_RGBA8888),
minFilter(TextureFilter_Nearest), minFilter(TextureFilter_Nearest),
magFilter(TextureFilter_Nearest), uWrap(TextureWrap_ClampToEdge), 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) {
} }
}; };

View File

@ -64,9 +64,6 @@ namespace spine {
IkConstraint(IkConstraintData &data, Skeleton &skeleton); IkConstraint(IkConstraintData &data, Skeleton &skeleton);
/// Applies the constraint to the constrained bones.
void apply();
virtual void update(); virtual void update();
virtual int getOrder(); virtual int getOrder();

View File

@ -39,7 +39,7 @@
namespace spine { namespace spine {
/// Attachment that displays a texture region using a mesh. /// 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 SkeletonBinary;
friend class SkeletonJson; friend class SkeletonJson;

View File

@ -44,7 +44,7 @@ namespace spine {
class Bone; class Bone;
/// Attachment that displays a texture region. /// 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 SkeletonBinary;
friend class SkeletonJson; friend class SkeletonJson;

View File

@ -211,16 +211,15 @@ EventQueueEntry::EventQueueEntry(EventType eventType, TrackEntry *trackEntry, Ev
_event(event) { _event(event) {
} }
EventQueue *EventQueue::newEventQueue(AnimationState &state, Pool<TrackEntry> &trackEntryPool) { EventQueue *EventQueue::newEventQueue(AnimationState &state) {
return new (__FILE__, __LINE__) EventQueue(state, trackEntryPool); return new (__FILE__, __LINE__) EventQueue(state);
} }
EventQueueEntry EventQueue::newEventQueueEntry(EventType eventType, TrackEntry *entry, Event *event) { EventQueueEntry EventQueue::newEventQueueEntry(EventType eventType, TrackEntry *entry, Event *event) {
return EventQueueEntry(eventType, entry, event); return EventQueueEntry(eventType, entry, event);
} }
EventQueue::EventQueue(AnimationState &state, Pool<TrackEntry> &trackEntryPool) : _state(state), EventQueue::EventQueue(AnimationState &state) : _state(state),
_trackEntryPool(trackEntryPool),
_drainDisabled(false) { _drainDisabled(false) {
} }
@ -314,7 +313,7 @@ void EventQueue::drain() {
} }
AnimationState::AnimationState(AnimationStateData *data) : _data(data), AnimationState::AnimationState(AnimationStateData *data) : _data(data),
_queue(EventQueue::newEventQueue(*this, _trackEntryPool)), _queue(EventQueue::newEventQueue(*this)),
_animationsChanged(false), _animationsChanged(false),
_listener(dummyOnAnimationEventFunc), _listener(dummyOnAnimationEventFunc),
_listenerObject(NULL), _listenerObject(NULL),

View File

@ -69,7 +69,7 @@ Atlas::Atlas(const char *data, int length, const char *dir, TextureLoader *textu
Atlas::~Atlas() { Atlas::~Atlas() {
if (_textureLoader) { if (_textureLoader) {
for (size_t i = 0, n = _pages.size(); i < n; ++i) { for (size_t i = 0, n = _pages.size(); i < n; ++i) {
_textureLoader->unload(_pages[i]->getRendererObject()); _textureLoader->unload(_pages[i]->texture);
} }
} }
ContainerUtil::cleanUpVectorOfPointers(_pages); ContainerUtil::cleanUpVectorOfPointers(_pages);
@ -291,6 +291,7 @@ void Atlas::load(const char *begin, int length, const char *dir, bool createText
} else { } else {
AtlasRegion *region = new (__FILE__, __LINE__) AtlasRegion(); AtlasRegion *region = new (__FILE__, __LINE__) AtlasRegion();
region->page = page; region->page = page;
region->rendererObject = page->texture;
region->name = String(line->copy(), true); region->name = String(line->copy(), true);
while (true) { while (true) {
line = reader.readLine(); line = reader.readLine();

View File

@ -63,7 +63,6 @@ namespace spine {
} else { } else {
AtlasRegion *region = findRegion(path); AtlasRegion *region = findRegion(path);
if (!region) return NULL; if (!region) return NULL;
attachment->setRendererObject(region);
attachment->setRegion(region); attachment->setRegion(region);
} }
return attachment; return attachment;
@ -78,7 +77,6 @@ namespace spine {
} else { } else {
AtlasRegion *region = findRegion(path); AtlasRegion *region = findRegion(path);
if (!region) return NULL; if (!region) return NULL;
attachment->setRendererObject(region);
attachment->setRegion(region); attachment->setRegion(region);
} }
return attachment; return attachment;

View File

@ -34,7 +34,7 @@ using namespace spine;
RTTI_IMPL(MeshAttachment, VertexAttachment) RTTI_IMPL(MeshAttachment, VertexAttachment)
MeshAttachment::MeshAttachment(const String &name) : VertexAttachment(name), HasRendererObject(), MeshAttachment::MeshAttachment(const String &name) : VertexAttachment(name),
_parentMesh(NULL), _parentMesh(NULL),
_path(), _path(),
_color(1, 1, 1, 1), _color(1, 1, 1, 1),
@ -203,7 +203,6 @@ Attachment *MeshAttachment::copy() {
if (_parentMesh) return newLinkedMesh(); if (_parentMesh) return newLinkedMesh();
MeshAttachment *copy = new (__FILE__, __LINE__) MeshAttachment(getName()); MeshAttachment *copy = new (__FILE__, __LINE__) MeshAttachment(getName());
copy->setRendererObject(getRendererObject());
copy->setRegion(_region); copy->setRegion(_region);
copy->setSequence(_sequence != NULL ? _sequence->copy() : NULL); copy->setSequence(_sequence != NULL ? _sequence->copy() : NULL);
copy->_path = _path; copy->_path = _path;
@ -224,7 +223,6 @@ Attachment *MeshAttachment::copy() {
MeshAttachment *MeshAttachment::newLinkedMesh() { MeshAttachment *MeshAttachment::newLinkedMesh() {
MeshAttachment *copy = new (__FILE__, __LINE__) MeshAttachment(getName()); MeshAttachment *copy = new (__FILE__, __LINE__) MeshAttachment(getName());
copy->setRendererObject(getRendererObject());
copy->setRegion(_region); copy->setRegion(_region);
copy->_path = _path; copy->_path = _path;
copy->_color.set(_color); copy->_color.set(_color);

View File

@ -47,7 +47,7 @@ const int RegionAttachment::URY = 5;
const int RegionAttachment::BRX = 6; const int RegionAttachment::BRX = 6;
const int RegionAttachment::BRY = 7; const int RegionAttachment::BRY = 7;
RegionAttachment::RegionAttachment(const String &name) : Attachment(name), HasRendererObject(), RegionAttachment::RegionAttachment(const String &name) : Attachment(name),
_x(0), _x(0),
_y(0), _y(0),
_rotation(0), _rotation(0),
@ -247,7 +247,6 @@ spine::Color &RegionAttachment::getColor() {
Attachment *RegionAttachment::copy() { Attachment *RegionAttachment::copy() {
RegionAttachment *copy = new (__FILE__, __LINE__) RegionAttachment(getName()); RegionAttachment *copy = new (__FILE__, __LINE__) RegionAttachment(getName());
copy->_region = _region; copy->_region = _region;
copy->setRendererObject(getRendererObject());
copy->_path = _path; copy->_path = _path;
copy->_x = _x; copy->_x = _x;
copy->_y = _y; copy->_y = _y;

View File

@ -66,7 +66,6 @@ void Sequence::apply(Slot *slot, Attachment *attachment) {
if (attachment->getRTTI().isExactly(RegionAttachment::rtti)) { if (attachment->getRTTI().isExactly(RegionAttachment::rtti)) {
RegionAttachment *regionAttachment = static_cast<RegionAttachment *>(attachment); RegionAttachment *regionAttachment = static_cast<RegionAttachment *>(attachment);
if (regionAttachment->getRegion() != region) { if (regionAttachment->getRegion() != region) {
regionAttachment->setRendererObject(region);
regionAttachment->setRegion(region); regionAttachment->setRegion(region);
regionAttachment->updateRegion(); regionAttachment->updateRegion();
} }
@ -75,7 +74,6 @@ void Sequence::apply(Slot *slot, Attachment *attachment) {
if (attachment->getRTTI().isExactly(MeshAttachment::rtti)) { if (attachment->getRTTI().isExactly(MeshAttachment::rtti)) {
MeshAttachment *meshAttachment = static_cast<MeshAttachment *>(attachment); MeshAttachment *meshAttachment = static_cast<MeshAttachment *>(attachment);
if (meshAttachment->getRegion() != region) { if (meshAttachment->getRegion() != region) {
meshAttachment->setRendererObject(region);
meshAttachment->setRegion(region); meshAttachment->setRegion(region);
meshAttachment->updateRegion(); meshAttachment->updateRegion();
} }