Hello. Probably a question for Nate (or whoever did the Spine-C runtime).
I want to get a list of attachments when using Spine-C.
I can use the code that's in spSkin_getAttachment:
void spSkin_getAttachment (const spSkin* self, int slotIndex, const char* name) {
const _Entry* entry = SUB_CAST(_spSkin, self)->entries;
while (entry) {
if (entry->slotIndex == slotIndex && strcmp(entry->name, name) == 0) return entry->attachment;
entry = entry->next;
}
}
It's easy enough for me to hack up a solution using the above, but the spSkin_getAttachment function needs the "spSkin" and "Entry" structs that are defined within the source file rather than the header. So, any solution I come up with needs to be in the Skin.c source file (which branches the runtime and creates a ball-ache when the runtime changes in the future i.e. all my changes need to be folded back into the official runtime if it changes).
Is it possible to move the struct defines into the Skin.h file? So I can just include the file and have a, say, SkinExtensions.c / cpp file that doesn't change Skin.c?
Cheers,
T.
This is what I've come up with in case anyone wants to use it... Nothing complex, but the issue still remains that it's hard to extend the Spine-C runtime system with minimal merging / branching.
typedef struct _Entry _Entry;
struct _Entry {
int slotIndex;
const char* name;
spAttachment* attachment;
_Entry* next;
};
typedef struct {
spSkin super;
_Entry* entries;
} _spSkin;
//get all the attachments for the given skin / skeleton
void spSkin_getAttachments(const spSkin* skin, const spSkeleton* skeleton, std::multimap<zString,zString>& attachmentsOUT)
{
const _Entry* entry = SUB_CAST(_spSkin, skin)->entries;
while (entry)
{
spSlot* slot = skeleton->slots[entry->slotIndex];
attachmentsOUT.insert(std::make_pair(zString(slot->data->name), zString(entry->attachment->name)));
entry = entry->next;
}
}
Anyone have any ideas about this?