mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-20 09:16:01 +08:00
[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:
parent
6d0a60e255
commit
3d5075c7a4
@ -311,14 +311,13 @@ namespace spine {
|
||||
private:
|
||||
Vector<EventQueueEntry> _eventQueueEntries;
|
||||
AnimationState &_state;
|
||||
Pool<TrackEntry> &_trackEntryPool;
|
||||
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);
|
||||
|
||||
EventQueue(AnimationState &state, Pool<TrackEntry> &trackEntryPool);
|
||||
EventQueue(AnimationState &state);
|
||||
|
||||
~EventQueue();
|
||||
|
||||
|
||||
@ -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) {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -211,16 +211,15 @@ EventQueueEntry::EventQueueEntry(EventType eventType, TrackEntry *trackEntry, Ev
|
||||
_event(event) {
|
||||
}
|
||||
|
||||
EventQueue *EventQueue::newEventQueue(AnimationState &state, Pool<TrackEntry> &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<TrackEntry> &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),
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -66,7 +66,6 @@ void Sequence::apply(Slot *slot, Attachment *attachment) {
|
||||
if (attachment->getRTTI().isExactly(RegionAttachment::rtti)) {
|
||||
RegionAttachment *regionAttachment = static_cast<RegionAttachment *>(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<MeshAttachment *>(attachment);
|
||||
if (meshAttachment->getRegion() != region) {
|
||||
meshAttachment->setRendererObject(region);
|
||||
meshAttachment->setRegion(region);
|
||||
meshAttachment->updateRegion();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user