Moar refuctoring. All the refuctorings are belong to Spine.

This commit is contained in:
NathanSweet 2013-04-02 02:46:49 +02:00
parent e3cc3e4fb2
commit ca163b5e52
43 changed files with 641 additions and 294 deletions

View File

@ -13,7 +13,7 @@ typedef struct {
int extraData;
} ExampleAtlasPage;
void _ExampleAtlasPage_free (AtlasPage* page) {
void _ExampleAtlasPage_dispose (AtlasPage* page) {
ExampleAtlasPage* self = SUB_CAST(ExampleAtlasPage, page);
_AtlasPage_deinit(SUPER(self));
@ -22,10 +22,10 @@ void _ExampleAtlasPage_free (AtlasPage* page) {
FREE(self);
}
AtlasPage* AtlasPage_new (const char* name) {
AtlasPage* AtlasPage_create (const char* name) {
ExampleAtlasPage* self = NEW(ExampleAtlasPage);
_AtlasPage_init(SUPER(self), name);
VTABLE(AtlasPage, self) ->free = _ExampleAtlasPage_free;
VTABLE(AtlasPage, self) ->dispose = _ExampleAtlasPage_dispose;
self->extraData = 123;
@ -39,7 +39,7 @@ typedef struct {
int extraData;
} ExampleSkeleton;
void _ExampleSkeleton_free (Skeleton* skeleton) {
void _ExampleSkeleton_dispose (Skeleton* skeleton) {
ExampleSkeleton* self = SUB_CAST(ExampleSkeleton, skeleton);
_Skeleton_deinit(SUPER(self));
@ -48,10 +48,10 @@ void _ExampleSkeleton_free (Skeleton* skeleton) {
FREE(self);
}
Skeleton* Skeleton_new (SkeletonData* data) {
Skeleton* Skeleton_create (SkeletonData* data) {
ExampleSkeleton* self = NEW(ExampleSkeleton);
_Skeleton_init(SUPER(self), data);
VTABLE(Skeleton, self) ->free = _ExampleSkeleton_free;
VTABLE(Skeleton, self) ->dispose = _ExampleSkeleton_dispose;
self->extraData = 789;
@ -65,7 +65,7 @@ typedef struct {
int extraData;
} ExampleRegionAttachment;
void _ExampleRegionAttachment_free (Attachment* attachment) {
void _ExampleRegionAttachment_dispose (Attachment* attachment) {
ExampleRegionAttachment* self = SUB_CAST(ExampleRegionAttachment, attachment);
_RegionAttachment_deinit(SUPER(self));
@ -79,10 +79,10 @@ void _ExampleRegionAttachment_draw (Attachment* attachment, Slot* slot) {
// Draw or queue region for drawing.
}
RegionAttachment* RegionAttachment_new (const char* name, AtlasRegion* region) {
RegionAttachment* RegionAttachment_create (const char* name, AtlasRegion* region) {
ExampleRegionAttachment* self = NEW(ExampleRegionAttachment);
_RegionAttachment_init(SUPER(self), name);
VTABLE(Attachment, self) ->free = _ExampleRegionAttachment_free;
VTABLE(Attachment, self) ->dispose = _ExampleRegionAttachment_dispose;
VTABLE(Attachment, self) ->draw = _ExampleRegionAttachment_draw;
self->extraData = 456;
@ -103,22 +103,22 @@ int main (void) {
printf("First region name: %s, x: %d, y: %d\n", atlas->regions->name, atlas->regions->x, atlas->regions->y);
printf("First page name: %s, extraData: %d\n", atlas->pages->name, ((ExampleAtlasPage*)atlas->pages)->extraData);
SkeletonJson* json = SkeletonJson_new(atlas);
SkeletonJson* json = SkeletonJson_create(atlas);
SkeletonData *skeletonData = SkeletonJson_readSkeletonDataFile(json, "data/spineboy-skeleton.json");
if (!skeletonData) printf("Error: %s\n", json->error);
printf("Attachment extraData: %d\n", ((ExampleRegionAttachment*)skeletonData->defaultSkin->entries->attachment)->extraData);
printf("Default skin name: %s\n", skeletonData->defaultSkin->name);
Skeleton* skeleton = Skeleton_new(skeletonData);
Skeleton* skeleton = Skeleton_create(skeletonData);
printf("Skeleton extraData: %d\n", ((ExampleSkeleton*)skeleton)->extraData);
Animation* animation = SkeletonJson_readAnimationFile(json, "data/spineboy-walk.json", skeletonData);
if (!animation) printf("Error: %s\n", json->error);
printf("Animation timelineCount: %d\n", animation->timelineCount);
Skeleton_free(skeleton);
SkeletonData_free(skeletonData);
SkeletonJson_free(json);
Atlas_free(atlas);
Skeleton_dispose(skeleton);
SkeletonData_dispose(skeletonData);
SkeletonJson_dispose(json);
Atlas_dispose(atlas);
return 0;
}

View File

@ -42,11 +42,11 @@ typedef struct {
float duration;
} Animation;
Animation* Animation_new (int timelineCount);
void Animation_free (Animation* animation);
Animation* Animation_create (int timelineCount);
void Animation_dispose (Animation* self);
void Animation_apply (const Animation* animation, Skeleton* skeleton, float time, int/*bool*/loop);
void Animation_mix (const Animation* animation, Skeleton* skeleton, float time, int/*bool*/loop, float alpha);
void Animation_apply (const Animation* self, Skeleton* skeleton, float time, int/*bool*/loop);
void Animation_mix (const Animation* self, Skeleton* skeleton, float time, int/*bool*/loop, float alpha);
/**/
@ -54,8 +54,8 @@ struct Timeline {
const void* const vtable;
};
void Timeline_free (Timeline* timeline);
void Timeline_apply (const Timeline* timeline, Skeleton* skeleton, float time, float alpha);
void Timeline_dispose (Timeline* self);
void Timeline_apply (const Timeline* self, Skeleton* skeleton, float time, float alpha);
/**/
@ -64,14 +64,14 @@ typedef struct {
float* curves; /* dfx, dfy, ddfx, ddfy, dddfx, dddfy, ... */
} CurveTimeline;
void CurveTimeline_setLinear (CurveTimeline* timeline, int frameIndex);
void CurveTimeline_setStepped (CurveTimeline* timeline, int frameIndex);
void CurveTimeline_setLinear (CurveTimeline* self, int frameIndex);
void CurveTimeline_setStepped (CurveTimeline* self, int frameIndex);
/* Sets the control handle positions for an interpolation bezier curve used to transition from this keyframe to the next.
* cx1 and cx2 are from 0 to 1, representing the percent of time between the two keyframes. cy1 and cy2 are the percent of
* the difference between the keyframe's values. */
void CurveTimeline_setCurve (CurveTimeline* timeline, int frameIndex, float cx1, float cy1, float cx2, float cy2);
float CurveTimeline_getCurvePercent (const CurveTimeline* timeline, int frameIndex, float percent);
void CurveTimeline_setCurve (CurveTimeline* self, int frameIndex, float cx1, float cy1, float cx2, float cy2);
float CurveTimeline_getCurvePercent (const CurveTimeline* self, int frameIndex, float percent);
/**/
@ -82,25 +82,25 @@ typedef struct BaseTimeline {
int boneIndex;
} RotateTimeline;
RotateTimeline* RotateTimeline_new (int frameCount);
RotateTimeline* RotateTimeline_create (int frameCount);
void RotateTimeline_setFrame (RotateTimeline* timeline, int frameIndex, float time, float angle);
void RotateTimeline_setFrame (RotateTimeline* self, int frameIndex, float time, float angle);
/**/
typedef struct BaseTimeline TranslateTimeline;
TranslateTimeline* TranslateTimeline_new (int frameCount);
TranslateTimeline* TranslateTimeline_create (int frameCount);
void TranslateTimeline_setFrame (TranslateTimeline* timeline, int frameIndex, float time, float x, float y);
void TranslateTimeline_setFrame (TranslateTimeline* self, int frameIndex, float time, float x, float y);
/**/
typedef struct BaseTimeline ScaleTimeline;
ScaleTimeline* ScaleTimeline_new (int frameCount);
ScaleTimeline* ScaleTimeline_create (int frameCount);
void ScaleTimeline_setFrame (ScaleTimeline* timeline, int frameIndex, float time, float x, float y);
void ScaleTimeline_setFrame (ScaleTimeline* self, int frameIndex, float time, float x, float y);
/**/
@ -111,9 +111,9 @@ typedef struct {
int slotIndex;
} ColorTimeline;
ColorTimeline* ColorTimeline_new (int frameCount);
ColorTimeline* ColorTimeline_create (int frameCount);
void ColorTimeline_setFrame (ColorTimeline* timeline, int frameIndex, float time, float r, float g, float b, float a);
void ColorTimeline_setFrame (ColorTimeline* self, int frameIndex, float time, float r, float g, float b, float a);
/**/
@ -125,10 +125,10 @@ typedef struct {
const char** const attachmentNames;
} AttachmentTimeline;
AttachmentTimeline* AttachmentTimeline_new (int frameCount);
AttachmentTimeline* AttachmentTimeline_create (int frameCount);
/* @param attachmentName May be 0. */
void AttachmentTimeline_setFrame (AttachmentTimeline* timeline, int frameIndex, float time, const char* attachmentName);
void AttachmentTimeline_setFrame (AttachmentTimeline* self, int frameIndex, float time, const char* attachmentName);
#ifdef __cplusplus
}

View File

@ -0,0 +1,58 @@
/*******************************************************************************
* Copyright (c) 2013, Esoteric Software
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
******************************************************************************/
#ifndef SPINE_ANIMATIONSTATE_H_
#define SPINE_ANIMATIONSTATE_H_
#include <spine/AnimationStateData.h>
#ifdef __cplusplus
namespace spine {
extern "C" {
#endif
typedef struct {
AnimationStateData* const data;
Animation* const animation;
float time;
int/*bool*/loop;
} AnimationState;
/* @param data May be 0 for no mixing. */
AnimationState* AnimationState_create (AnimationStateData* data);
void AnimationState_dispose (AnimationState* self);
void AnimationState_update (AnimationState* self, float delta);
void AnimationState_apply (AnimationState* self, Skeleton* skeleton);
void AnimationState_setAnimation (AnimationState* self, Animation* animation, int/**/loop);
#ifdef __cplusplus
}
}
#endif
#endif /* SPINE_ANIMATIONSTATE_H_ */

View File

@ -0,0 +1,52 @@
/*******************************************************************************
* Copyright (c) 2013, Esoteric Software
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
******************************************************************************/
#ifndef SPINE_ANIMATIONSTATEDATA_H_
#define SPINE_ANIMATIONSTATEDATA_H_
#include <spine/Animation.h>
#ifdef __cplusplus
namespace spine {
extern "C" {
#endif
typedef struct {
const void* const entries;
} AnimationStateData;
AnimationStateData* AnimationStateData_create ();
void AnimationStateData_dispose (AnimationStateData* self);
void AnimationStateData_setMix (AnimationStateData* self, Animation* from, Animation* to, float duration);
/* Returns 0 if there is no mixing between the animations. */
float AnimationStateData_getMix (AnimationStateData* self, Animation* from, Animation* to);
#ifdef __cplusplus
}
}
#endif
#endif /* SPINE_ANIMATIONSTATEDATA_H_ */

View File

@ -60,8 +60,8 @@ struct AtlasPage {
const void* const vtable;
};
AtlasPage* AtlasPage_new (const char* name);
void AtlasPage_free (AtlasPage* page);
AtlasPage* AtlasPage_create (const char* name);
void AtlasPage_dispose (AtlasPage* self);
/**/
@ -80,8 +80,8 @@ struct AtlasRegion {
AtlasRegion* next;
};
AtlasRegion* AtlasRegion_new ();
void AtlasRegion_free (AtlasRegion* region);
AtlasRegion* AtlasRegion_create ();
void AtlasRegion_dispose (AtlasRegion* self);
/**/
@ -92,10 +92,10 @@ typedef struct {
Atlas* Atlas_readAtlas (const char* data, unsigned long length);
Atlas* Atlas_readAtlasFile (const char* path);
void Atlas_free (Atlas* atlas);
void Atlas_dispose (Atlas* atlas);
/* Returns 0 if the region was not found. */
AtlasRegion* Atlas_findRegion (const Atlas* atlas, const char* name);
AtlasRegion* Atlas_findRegion (const Atlas* self, const char* name);
#ifdef __cplusplus
}

View File

@ -39,7 +39,7 @@ typedef struct {
Atlas* atlas;
} AtlasAttachmentLoader;
AtlasAttachmentLoader* AtlasAttachmentLoader_new (Atlas* atlas);
AtlasAttachmentLoader* AtlasAttachmentLoader_create (Atlas* atlas);
#ifdef __cplusplus
}

View File

@ -45,9 +45,9 @@ struct Attachment {
const void* const vtable;
};
void Attachment_free (Attachment* attachment);
void Attachment_dispose (Attachment* self);
void Attachment_draw (Attachment* attachment, struct Slot* slot);
void Attachment_draw (Attachment* self, struct Slot* slot);
#ifdef __cplusplus
}

View File

@ -41,10 +41,10 @@ struct AttachmentLoader {
const void* const vtable;
};
void AttachmentLoader_free (AttachmentLoader* loader);
void AttachmentLoader_dispose (AttachmentLoader* self);
/* Returns 0 to not load an attachment. If 0 is returned and AttachmentLoader.error1 is set, an error occurred. */
Attachment* AttachmentLoader_newAttachment (AttachmentLoader* loader, AttachmentType type, const char* name);
Attachment* AttachmentLoader_newAttachment (AttachmentLoader* self, AttachmentType type, const char* name);
#ifdef __cplusplus
}

View File

@ -50,12 +50,12 @@ struct Bone {
void Bone_setYDown (int/*bool*/yDown);
/* @param parent May be 0. */
Bone* Bone_new (BoneData* data, Bone* parent);
void Bone_free (Bone* bone);
Bone* Bone_create (BoneData* data, Bone* parent);
void Bone_dispose (Bone* self);
void Bone_setToBindPose (Bone* bone);
void Bone_setToBindPose (Bone* self);
void Bone_updateWorldTransform (Bone* bone, int/*bool*/flipX, int/*bool*/flipY);
void Bone_updateWorldTransform (Bone* self, int/*bool*/flipX, int/*bool*/flipY);
#ifdef __cplusplus
}

View File

@ -41,8 +41,8 @@ struct BoneData {
float scaleX, scaleY;
};
BoneData* BoneData_new (const char* name, BoneData* parent);
void BoneData_free (BoneData* boneData);
BoneData* BoneData_create (const char* name, BoneData* parent);
void BoneData_dispose (BoneData* self);
#ifdef __cplusplus
}

View File

@ -41,9 +41,9 @@ struct RegionAttachment {
float offset[8];
};
RegionAttachment* RegionAttachment_new (const char* name, AtlasRegion* region);
RegionAttachment* RegionAttachment_create (const char* name, AtlasRegion* region);
void RegionAttachment_updateOffset (RegionAttachment* attachment);
void RegionAttachment_updateOffset (RegionAttachment* self);
#ifdef __cplusplus
}

View File

@ -54,38 +54,40 @@ struct Skeleton {
const void* const vtable;
};
void Skeleton_free (Skeleton* skeleton);
void Skeleton_dispose (Skeleton* self);
void Skeleton_updateWorldTransform (const Skeleton* skeleton);
void Skeleton_updateWorldTransform (const Skeleton* self);
void Skeleton_setToBindPose (const Skeleton* skeleton);
void Skeleton_setBonesToBindPose (const Skeleton* skeleton);
void Skeleton_setSlotsToBindPose (const Skeleton* skeleton);
void Skeleton_setToBindPose (const Skeleton* self);
void Skeleton_setBonesToBindPose (const Skeleton* self);
void Skeleton_setSlotsToBindPose (const Skeleton* self);
Bone* Skeleton_getRootBone (const Skeleton* skeleton);
Bone* Skeleton_getRootBone (const Skeleton* self);
/* Returns 0 if the bone was not found. */
Bone* Skeleton_findBone (const Skeleton* skeleton, const char* boneName);
Bone* Skeleton_findBone (const Skeleton* self, const char* boneName);
/* Returns -1 if the bone was not found. */
int Skeleton_findBoneIndex (const Skeleton* skeleton, const char* boneName);
int Skeleton_findBoneIndex (const Skeleton* self, const char* boneName);
/* Returns 0 if the slot was not found. */
Slot* Skeleton_findSlot (const Skeleton* skeleton, const char* slotName);
Slot* Skeleton_findSlot (const Skeleton* self, const char* slotName);
/* Returns -1 if the slot was not found. */
int Skeleton_findSlotIndex (const Skeleton* skeleton, const char* slotName);
int Skeleton_findSlotIndex (const Skeleton* self, const char* slotName);
/* Returns 0 if the skin was not found. */
int Skeleton_setSkinByName (Skeleton* skeleton, const char* skinName);
/* @param skin May be 0.*/
void Skeleton_setSkin (Skeleton* skeleton, Skin* skin);
/* Sets the skin used to look up attachments not found in the SkeletonData defaultSkin. Attachments from the new skin are
* attached if the corresponding attachment from the old skin was attached.
* @param skin May be 0.*/
void Skeleton_setSkin (Skeleton* self, Skin* skin);
/* Returns 0 if the skin was not found. See Skeleton_setSkin. */
int Skeleton_setSkinByName (Skeleton* self, const char* skinName);
/* Returns 0 if the slot or attachment was not found. */
Attachment* Skeleton_getAttachmentForSlotName (const Skeleton* skeleton, const char* slotName, const char* attachmentName);
Attachment* Skeleton_getAttachmentForSlotName (const Skeleton* self, const char* slotName, const char* attachmentName);
/* Returns 0 if the slot or attachment was not found. */
Attachment* Skeleton_getAttachmentForSlotIndex (const Skeleton* skeleton, int slotIndex, const char* attachmentName);
Attachment* Skeleton_getAttachmentForSlotIndex (const Skeleton* self, int slotIndex, const char* attachmentName);
/* Returns 0 if the slot or attachment was not found. */
int Skeleton_setAttachment (Skeleton* skeleton, const char* slotName, const char* attachmentName);
int Skeleton_setAttachment (Skeleton* self, const char* slotName, const char* attachmentName);
void Skeleton_update (Skeleton* skeleton, float deltaTime);
void Skeleton_update (Skeleton* self, float deltaTime);
#ifdef __cplusplus
}

View File

@ -47,16 +47,16 @@ typedef struct {
Skin* defaultSkin;
} SkeletonData;
SkeletonData* SkeletonData_new ();
void SkeletonData_free (SkeletonData* skeletonData);
SkeletonData* SkeletonData_create ();
void SkeletonData_dispose (SkeletonData* self);
BoneData* SkeletonData_findBone (const SkeletonData* skeletonData, const char* boneName);
int SkeletonData_findBoneIndex (const SkeletonData* skeletonData, const char* boneName);
BoneData* SkeletonData_findBone (const SkeletonData* self, const char* boneName);
int SkeletonData_findBoneIndex (const SkeletonData* self, const char* boneName);
SlotData* SkeletonData_findSlot (const SkeletonData* skeletonData, const char* slotName);
int SkeletonData_findSlotIndex (const SkeletonData* skeletonData, const char* slotName);
SlotData* SkeletonData_findSlot (const SkeletonData* self, const char* slotName);
int SkeletonData_findSlotIndex (const SkeletonData* self, const char* slotName);
Skin* SkeletonData_findSkin (const SkeletonData* skeletonData, const char* skinName);
Skin* SkeletonData_findSkin (const SkeletonData* self, const char* skinName);
#ifdef __cplusplus
}}

View File

@ -43,15 +43,15 @@ typedef struct {
const char* const error;
} SkeletonJson;
SkeletonJson* SkeletonJson_newWithLoader (AttachmentLoader* attachmentLoader);
SkeletonJson* SkeletonJson_new (Atlas* atlas);
void SkeletonJson_free (SkeletonJson* skeletonJson);
SkeletonJson* SkeletonJson_createWithLoader (AttachmentLoader* attachmentLoader);
SkeletonJson* SkeletonJson_create (Atlas* atlas);
void SkeletonJson_dispose (SkeletonJson* self);
SkeletonData* SkeletonJson_readSkeletonData (SkeletonJson* skeletonJson, const char* json);
SkeletonData* SkeletonJson_readSkeletonDataFile (SkeletonJson* skeletonJson, const char* path);
SkeletonData* SkeletonJson_readSkeletonData (SkeletonJson* self, const char* json);
SkeletonData* SkeletonJson_readSkeletonDataFile (SkeletonJson* self, const char* path);
Animation* SkeletonJson_readAnimation (SkeletonJson* skeletonJson, const char* json, const SkeletonData *skeletonData);
Animation* SkeletonJson_readAnimationFile (SkeletonJson* skeletonJson, const char* path, const SkeletonData *skeletonData);
Animation* SkeletonJson_readAnimation (SkeletonJson* self, const char* json, const SkeletonData *skeletonData);
Animation* SkeletonJson_readAnimationFile (SkeletonJson* self, const char* path, const SkeletonData *skeletonData);
#ifdef __cplusplus
}

View File

@ -33,26 +33,22 @@ namespace spine {
extern "C" {
#endif
typedef struct SkinEntry SkinEntry;
struct SkinEntry {
int slotIndex;
const char* name;
Attachment* attachment;
const SkinEntry* next;
};
struct Skeleton;
typedef struct {
const char* const name;
const SkinEntry* const entries;
} Skin;
Skin* Skin_new (const char* name);
void Skin_free (Skin* skin);
Skin* Skin_create (const char* name);
void Skin_dispose (Skin* self);
/* The Skin owns the attachment. */
void Skin_addAttachment (Skin* skin, int slotIndex, const char* name, Attachment* attachment);
void Skin_addAttachment (Skin* self, int slotIndex, const char* name, Attachment* attachment);
/* Returns 0 if the attachment was not found. */
Attachment* Skin_getAttachment (const Skin* skin, int slotIndex, const char* name);
Attachment* Skin_getAttachment (const Skin* self, int slotIndex, const char* name);
/** Attach each attachment in this skin if the corresponding attachment in oldSkin is currently attached. */
void Skin_attachAll (const Skin* self, struct Skeleton* skeleton, const Skin* oldSkin);
#ifdef __cplusplus
}

View File

@ -45,16 +45,16 @@ typedef struct Slot {
Attachment* const attachment;
} Slot;
Slot* Slot_new (SlotData* data, struct Skeleton* skeleton, Bone* bone);
void Slot_free (Slot* slot);
Slot* Slot_create (SlotData* data, struct Skeleton* skeleton, Bone* bone);
void Slot_dispose (Slot* self);
/* @param attachment May be 0 to clear the attachment for the slot. */
void Slot_setAttachment (Slot* slot, Attachment* attachment);
void Slot_setAttachment (Slot* self, Attachment* attachment);
void Slot_setAttachmentTime (Slot* slot, float time);
float Slot_getAttachmentTime (const Slot* slot);
void Slot_setAttachmentTime (Slot* self, float time);
float Slot_getAttachmentTime (const Slot* self);
void Slot_setToBindPose (Slot* slot);
void Slot_setToBindPose (Slot* self);
#ifdef __cplusplus
}

View File

@ -40,11 +40,11 @@ typedef struct {
float r, g, b, a;
} SlotData;
SlotData* SlotData_new (const char* name, BoneData* boneData);
void SlotData_free (SlotData* slotData);
SlotData* SlotData_create (const char* name, BoneData* boneData);
void SlotData_dispose (SlotData* self);
/* @param attachmentName May be 0 for no bind pose attachment. */
void SlotData_setAttachmentName (SlotData* slotData, const char* attachmentName);
void SlotData_setAttachmentName (SlotData* self, const char* attachmentName);
#ifdef __cplusplus
}

View File

@ -33,13 +33,13 @@
- Inheritance is done using a struct field named "super" as the first field, allowing the struct to be cast to its "super class".
- Classes intended for inheritance provide init/deinit functions which subclasses must call in their new/free functions.
- Classes intended for inheritance provide init/deinit functions which subclasses must call in their create/dispose functions.
- Polymorphism is done by a base class providing a "vtable" pointer to a struct containing function pointers. The public API
delegates to the appropriate vtable function. Subclasses may change the vtable pointers.
- Subclasses do not provide a free function, instead the base class' free function should be used, which will delegate to a free
function in its vtable.
- Subclasses do not provide a dispose function, instead the base class' dispose function should be used, which will delegate to
a dispose function in its vtable.
- Classes not designed for inheritance cannot be extended. They may use an internal subclass to hide private data and don't
expose a vtable.
@ -47,7 +47,7 @@
- The public API hides implementation details such as vtable structs and init/deinit functions. An internal API is exposed in
extension.h to allow classes to be extended. Internal structs and functions begin with underscore (_).
- OOP in C tends to lose type safety. Macros are provided in extension.h to give more context about why a cast is being done.
- OOP in C tends to lose type safety. Macros are provided in extension.h to give context for why a cast is being done.
*/
#ifndef SPINE_EXTENSION_H_
@ -61,7 +61,7 @@
/* Gets the direct super class. Type safe. */
#define SUPER(VALUE) (&VALUE->super)
/* Cast to a super class. Not type safe, use with care. */
/* Cast to a super class. Not type safe, use with care. Prefer SUPER() where possible. */
#define SUPER_CAST(TYPE,VALUE) ((TYPE*)VALUE)
/* Cast to a sub class. Not type safe, use with care. */
@ -77,7 +77,7 @@
#define FREE(VALUE) free((void*)VALUE)
/* Allocates a new char[], assigns it to TO, and copies FROM to it. Can be used on const. */
#define MALLOC_STR(TO,FROM) strcpy(CONST_CAST(char*, TO) = (char*)malloc(strlen(FROM)), FROM)
#define MALLOC_STR(TO,FROM) strcpy(CONST_CAST(char*, TO) = (char*)malloc(strlen(FROM) + 1), FROM)
#include <stdlib.h>
#include <string.h>
@ -96,9 +96,9 @@ extern "C" {
* Functions that must be implemented:
*/
RegionAttachment* RegionAttachment_new (const char* name, AtlasRegion* region);
RegionAttachment* RegionAttachment_create (const char* name, AtlasRegion* region);
AtlasPage* AtlasPage_new (const char* name);
AtlasPage* AtlasPage_create (const char* name);
char* _Util_readFile (const char* path, int* length);
@ -109,61 +109,61 @@ char* _Util_readFile (const char* path, int* length);
char* _readFile (const char* path, int* length);
typedef struct _SkeletonVtable {
void (*free) (Skeleton* skeleton);
void (*dispose) (Skeleton* skeleton);
} _SkeletonVtable;
void _Skeleton_init (Skeleton* skeleton, SkeletonData* data);
void _Skeleton_deinit (Skeleton* skeleton);
void _Skeleton_init (Skeleton* self, SkeletonData* data);
void _Skeleton_deinit (Skeleton* self);
/**/
typedef struct _AttachmentVtable {
void (*draw) (Attachment* attachment, struct Slot* slot);
void (*free) (Attachment* attachment);
void (*draw) (Attachment* self, struct Slot* slot);
void (*dispose) (Attachment* self);
} _AttachmentVtable;
void _Attachment_init (Attachment* attachment, const char* name, AttachmentType type);
void _Attachment_deinit (Attachment* attachment);
void _Attachment_init (Attachment* self, const char* name, AttachmentType type);
void _Attachment_deinit (Attachment* self);
/**/
void _RegionAttachment_init (RegionAttachment* attachment, const char* name);
void _RegionAttachment_deinit (RegionAttachment* attachment);
void _RegionAttachment_init (RegionAttachment* self, const char* name);
void _RegionAttachment_deinit (RegionAttachment* self);
/**/
typedef struct _TimelineVtable {
void (*apply) (const Timeline* timeline, Skeleton* skeleton, float time, float alpha);
void (*free) (Timeline* timeline);
void (*apply) (const Timeline* self, Skeleton* skeleton, float time, float alpha);
void (*dispose) (Timeline* self);
} _TimelineVtable;
void _Timeline_init (Timeline* timeline);
void _Timeline_deinit (Timeline* timeline);
void _Timeline_init (Timeline* self);
void _Timeline_deinit (Timeline* self);
/**/
void _CurveTimeline_init (CurveTimeline* timeline, int frameCount);
void _CurveTimeline_deinit (CurveTimeline* timeline);
void _CurveTimeline_init (CurveTimeline* self, int frameCount);
void _CurveTimeline_deinit (CurveTimeline* self);
/**/
typedef struct _AtlasPageVtable {
void (*free) (AtlasPage* page);
void (*dispose) (AtlasPage* self);
} _AtlasPageVtable;
void _AtlasPage_init (AtlasPage* page, const char* name);
void _AtlasPage_deinit (AtlasPage* page);
void _AtlasPage_init (AtlasPage* self, const char* name);
void _AtlasPage_deinit (AtlasPage* self);
/**/
typedef struct _AttachmentLoaderVtable {
Attachment* (*newAttachment) (AttachmentLoader* loader, AttachmentType type, const char* name);
void (*free) (AttachmentLoader* loader);
Attachment* (*newAttachment) (AttachmentLoader* self, AttachmentType type, const char* name);
void (*dispose) (AttachmentLoader* self);
} _AttachmentLoaderVtable;
void _AttachmentLoader_init (AttachmentLoader* loader);
void _AttachmentLoader_deinit (AttachmentLoader* loader);
void _AttachmentLoader_setError (AttachmentLoader* loader, const char* error1, const char* error2);
void _AttachmentLoader_init (AttachmentLoader* self);
void _AttachmentLoader_deinit (AttachmentLoader* self);
void _AttachmentLoader_setError (AttachmentLoader* self, const char* error1, const char* error2);
#ifdef __cplusplus
}

View File

@ -27,6 +27,8 @@
#define SPINE_SPINE_H_
#include <spine/Animation.h>
#include <spine/AnimationState.h>
#include <spine/AnimationStateData.h>
#include <spine/Atlas.h>
#include <spine/AtlasAttachmentLoader.h>
#include <spine/Attachment.h>

View File

@ -31,17 +31,17 @@
namespace spine {
#endif
Animation* Animation_new (int timelineCount) {
Animation* Animation_create (int timelineCount) {
Animation* self = NEW(Animation);
self->timelineCount = timelineCount;
self->timelines = MALLOC(Timeline*, timelineCount);
return self;
}
void Animation_free (Animation* self) {
void Animation_dispose (Animation* self) {
int i;
for (i = 0; i < self->timelineCount; ++i)
Timeline_free(self->timelines[i]);
Timeline_dispose(self->timelines[i]);
FREE(self->timelines);
FREE(self);
}
@ -72,8 +72,8 @@ void _Timeline_deinit (Timeline* self) {
FREE(self->vtable);
}
void Timeline_free (Timeline* self) {
VTABLE(Timeline, self) ->free(self);
void Timeline_dispose (Timeline* self) {
VTABLE(Timeline, self) ->dispose(self);
}
void Timeline_apply (const Timeline* self, Skeleton* skeleton, float time, float alpha) {
@ -183,7 +183,7 @@ static int binarySearch (float *values, int valuesLength, float target, int step
/**/
void _BaseTimeline_free (Timeline* timeline) {
void _BaseTimeline_dispose (Timeline* timeline) {
struct BaseTimeline* self = SUB_CAST(struct BaseTimeline, timeline);
_CurveTimeline_deinit(SUPER(self));
FREE(self->frames);
@ -191,10 +191,10 @@ void _BaseTimeline_free (Timeline* timeline) {
}
/* Many timelines have structure identical to struct BaseTimeline and extend CurveTimeline. **/
struct BaseTimeline* _BaseTimeline_new (int frameCount, int frameSize) {
struct BaseTimeline* _BaseTimeline_create (int frameCount, int frameSize) {
struct BaseTimeline* self = NEW(struct BaseTimeline);
_CurveTimeline_init(SUPER(self), frameCount);
VTABLE(Timeline, self) ->free = _BaseTimeline_free;
VTABLE(Timeline, self) ->dispose = _BaseTimeline_dispose;
CONST_CAST(int, self->framesLength) = frameCount * frameSize;
CONST_CAST(float*, self->frames) = CALLOC(float, self->framesLength);
@ -244,8 +244,8 @@ void _RotateTimeline_apply (const Timeline* timeline, Skeleton* skeleton, float
bone->rotation += amount * alpha;
}
RotateTimeline* RotateTimeline_new (int frameCount) {
RotateTimeline* self = _BaseTimeline_new(frameCount, 2);
RotateTimeline* RotateTimeline_create (int frameCount) {
RotateTimeline* self = _BaseTimeline_create(frameCount, 2);
VTABLE(Timeline, self) ->apply = _RotateTimeline_apply;
return self;
}
@ -289,8 +289,8 @@ void _TranslateTimeline_apply (const Timeline* timeline, Skeleton* skeleton, flo
* alpha;
}
TranslateTimeline* TranslateTimeline_new (int frameCount) {
TranslateTimeline* self = _BaseTimeline_new(frameCount, 3);
TranslateTimeline* TranslateTimeline_create (int frameCount) {
TranslateTimeline* self = _BaseTimeline_create(frameCount, 3);
VTABLE(Timeline, self) ->apply = _TranslateTimeline_apply;
return self;
}
@ -330,8 +330,8 @@ void _ScaleTimeline_apply (const Timeline* timeline, Skeleton* skeleton, float t
- bone->scaleY) * alpha;
}
ScaleTimeline* ScaleTimeline_new (int frameCount) {
ScaleTimeline* self = _BaseTimeline_new(frameCount, 3);
ScaleTimeline* ScaleTimeline_create (int frameCount) {
ScaleTimeline* self = _BaseTimeline_create(frameCount, 3);
VTABLE(Timeline, self) ->apply = _ScaleTimeline_apply;
return self;
}
@ -391,8 +391,8 @@ void _ColorTimeline_apply (const Timeline* timeline, Skeleton* skeleton, float t
}
}
ColorTimeline* ColorTimeline_new (int frameCount) {
ColorTimeline* self = (ColorTimeline*)_BaseTimeline_new(frameCount, 5);
ColorTimeline* ColorTimeline_create (int frameCount) {
ColorTimeline* self = (ColorTimeline*)_BaseTimeline_create(frameCount, 5);
VTABLE(Timeline, self) ->apply = _ColorTimeline_apply;
return self;
}
@ -424,7 +424,7 @@ void _AttachmentTimeline_apply (const Timeline* timeline, Skeleton* skeleton, fl
attachmentName ? Skeleton_getAttachmentForSlotIndex(skeleton, self->slotIndex, attachmentName) : 0);
}
void _AttachmentTimeline_free (Timeline* timeline) {
void _AttachmentTimeline_dispose (Timeline* timeline) {
_Timeline_deinit(timeline);
AttachmentTimeline* self = (AttachmentTimeline*)timeline;
@ -436,10 +436,10 @@ void _AttachmentTimeline_free (Timeline* timeline) {
FREE(self);
}
AttachmentTimeline* AttachmentTimeline_new (int frameCount) {
AttachmentTimeline* AttachmentTimeline_create (int frameCount) {
AttachmentTimeline* self = NEW(AttachmentTimeline);
_Timeline_init(SUPER(self));
VTABLE(Timeline, self) ->free = _AttachmentTimeline_free;
VTABLE(Timeline, self) ->dispose = _AttachmentTimeline_dispose;
VTABLE(Timeline, self) ->apply = _AttachmentTimeline_apply;
CONST_CAST(char**, self->attachmentNames) = CALLOC(char*, frameCount);

View File

@ -0,0 +1,90 @@
/*******************************************************************************
* Copyright (c) 2013, Esoteric Software
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
******************************************************************************/
#include <spine/AnimationState.h>
#include <spine/extension.h>
#ifdef __cplusplus
namespace spine {
#endif
typedef struct {
AnimationState super;
Animation *previous;
float previousTime;
int/*bool*/previousLoop;
float mixTime;
float mixDuration;
} _Internal;
AnimationState* AnimationState_create (AnimationStateData* data) {
AnimationState* self = SUPER(NEW(_Internal));
CONST_CAST(AnimationStateData*, self->data) = data;
return self;
}
void AnimationState_dispose (AnimationState* self) {
FREE(self);
}
void AnimationState_update (AnimationState* self, float delta) {
self->time += delta;
SUB_CAST(_Internal, self) ->previousTime += delta;
SUB_CAST(_Internal, self) ->mixTime += delta;
}
void AnimationState_apply (AnimationState* self, Skeleton* skeleton) {
if (!self->animation) return;
_Internal* internal = SUB_CAST(_Internal, self);
if (internal->previous) {
Animation_apply(internal->previous, skeleton, internal->previousTime, internal->previousLoop);
float alpha = internal->mixTime / internal->mixDuration;
if (alpha >= 1) {
alpha = 1;
internal->previous = 0;
}
Animation_mix(self->animation, skeleton, self->time, self->loop, alpha);
} else
Animation_apply(self->animation, skeleton, self->time, self->loop);
}
void AnimationState_setAnimation (AnimationState* self, Animation* newAnimation, int/**/loop) {
_Internal* internal = SUB_CAST(_Internal, self);
internal->previous = 0;
if (newAnimation && self->animation && self->data) {
internal->mixDuration = AnimationStateData_getMix(self->data, self->animation, newAnimation);
if (internal->mixDuration > 0) {
internal->mixTime = 0;
internal->previous = self->animation;
}
}
CONST_CAST(Animation*, self->animation) = newAnimation;
self->loop = loop;
self->time = 0;
}
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,138 @@
/*******************************************************************************
* Copyright (c) 2013, Esoteric Software
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
******************************************************************************/
#include <spine/AnimationStateData.h>
#include <spine/extension.h>
#ifdef __cplusplus
namespace spine {
#endif
typedef struct _ToEntry _ToEntry;
struct _ToEntry {
Animation* animation;
float duration;
_ToEntry* next;
};
_ToEntry* _ToEntry_create (Animation* to, float duration) {
_ToEntry* self = NEW(_ToEntry);
self->animation = to;
self->duration = duration;
return self;
}
void _ToEntry_dispose (_ToEntry* self) {
FREE(self);
}
/**/
typedef struct _FromEntry _FromEntry;
struct _FromEntry {
Animation* animation;
_ToEntry* toEntries;
_FromEntry* next;
};
_FromEntry* _FromEntry_create (Animation* from) {
_FromEntry* self = NEW(_FromEntry);
self->animation = from;
return self;
}
void _FromEntry_dispose (_FromEntry* self) {
FREE(self);
}
/**/
AnimationStateData* AnimationStateData_create () {
return NEW(AnimationStateData);
}
void AnimationStateData_dispose (AnimationStateData* self) {
_FromEntry* fromEntry = (_FromEntry*)self->entries;
while (fromEntry) {
_ToEntry* toEntry = fromEntry->toEntries;
while (toEntry) {
_ToEntry* next = toEntry->next;
_ToEntry_dispose(toEntry);
toEntry = next;
}
_FromEntry* next = fromEntry->next;
_FromEntry_dispose(fromEntry);
fromEntry = next;
}
FREE(self);
}
void AnimationStateData_setMix (AnimationStateData* self, Animation* from, Animation* to, float duration) {
/* Find existing FromEntry. */
_FromEntry* fromEntry = (_FromEntry*)self->entries;
while (fromEntry) {
if (fromEntry->animation == from) {
/* Find existing ToEntry. */
_ToEntry* toEntry = fromEntry->toEntries;
while (toEntry) {
if (toEntry->animation == to) {
toEntry->duration = duration;
return;
}
toEntry = toEntry->next;
}
break; /* Add new ToEntry to the existing FromEntry. */
}
fromEntry = fromEntry->next;
}
if (!fromEntry) {
fromEntry = _FromEntry_create(from);
fromEntry->next = (_FromEntry*)self->entries;
CONST_CAST(_FromEntry*, self->entries) = fromEntry;
}
_ToEntry* toEntry = _ToEntry_create(to, duration);
toEntry->next = fromEntry->toEntries;
fromEntry->toEntries = toEntry;
}
float AnimationStateData_getMix (AnimationStateData* self, Animation* from, Animation* to) {
_FromEntry* fromEntry = (_FromEntry*)self->entries;
while (fromEntry) {
if (fromEntry->animation == from) {
_ToEntry* toEntry = fromEntry->toEntries;
while (toEntry) {
if (toEntry->animation == to) return toEntry->duration;
toEntry = toEntry->next;
}
}
fromEntry = fromEntry->next;
}
return 0;
}
#ifdef __cplusplus
}
#endif

View File

@ -41,17 +41,17 @@ void _AtlasPage_deinit (AtlasPage* self) {
FREE(self->name);
}
void AtlasPage_free (AtlasPage* self) {
VTABLE(AtlasPage, self) ->free(self);
void AtlasPage_dispose (AtlasPage* self) {
VTABLE(AtlasPage, self) ->dispose(self);
}
/**/
AtlasRegion* AtlasRegion_new () {
AtlasRegion* AtlasRegion_create () {
return NEW(AtlasRegion) ;
}
void AtlasRegion_free (AtlasRegion* self) {
void AtlasRegion_dispose (AtlasRegion* self) {
FREE(self->name);
FREE(self->splits);
FREE(self->pads);
@ -164,7 +164,7 @@ static int toInt (Str* str) {
}
static Atlas* abortAtlas (Atlas* self) {
Atlas_free(self);
Atlas_dispose(self);
return 0;
}
@ -187,7 +187,7 @@ Atlas* Atlas_readAtlas (const char* begin, unsigned long length) {
if (str.end - str.begin == 0) {
page = 0;
} else if (!page) {
page = AtlasPage_new(mallocString(&str));
page = AtlasPage_create(mallocString(&str));
if (lastPage)
lastPage->next = page;
else
@ -207,7 +207,7 @@ Atlas* Atlas_readAtlas (const char* begin, unsigned long length) {
page->vWrap = *str.begin == 'x' ? ATLAS_CLAMPTOEDGE : (*str.begin == 'y' ? ATLAS_REPEAT : ATLAS_REPEAT);
}
} else {
AtlasRegion *region = AtlasRegion_new();
AtlasRegion *region = AtlasRegion_create();
if (lastRegion)
lastRegion->next = region;
else
@ -273,18 +273,18 @@ Atlas* Atlas_readAtlasFile (const char* path) {
return atlas;
}
void Atlas_free (Atlas* self) {
void Atlas_dispose (Atlas* self) {
AtlasPage* page = self->pages;
while (page) {
AtlasPage* nextPage = page->next;
AtlasPage_free(page);
AtlasPage_dispose(page);
page = nextPage;
}
AtlasRegion* region = self->regions;
while (region) {
AtlasRegion* nextRegion = region->next;
AtlasRegion_free(region);
AtlasRegion_dispose(region);
region = nextRegion;
}

View File

@ -31,7 +31,7 @@
namespace spine {
#endif
void _AtlasAttachmentLoader_free (AttachmentLoader* self) {
void _AtlasAttachmentLoader_dispose (AttachmentLoader* self) {
_AttachmentLoader_deinit(self);
}
@ -44,7 +44,7 @@ Attachment* _AtlasAttachmentLoader_newAttachment (AttachmentLoader* loader, Atta
_AttachmentLoader_setError(loader, "Region not found: ", name);
return 0;
}
return SUPER_CAST(Attachment, RegionAttachment_new(name, region)) ;
return SUPER_CAST(Attachment, RegionAttachment_create(name, region)) ;
}
default: {
char buffer[16];
@ -55,12 +55,12 @@ Attachment* _AtlasAttachmentLoader_newAttachment (AttachmentLoader* loader, Atta
}
}
AtlasAttachmentLoader* AtlasAttachmentLoader_new (Atlas* atlas) {
AtlasAttachmentLoader* AtlasAttachmentLoader_create (Atlas* atlas) {
AtlasAttachmentLoader* self = NEW(AtlasAttachmentLoader);
_AttachmentLoader_init(SUPER(self));
self->atlas = atlas;
VTABLE(AttachmentLoader, self) ->newAttachment = _AtlasAttachmentLoader_newAttachment;
VTABLE(AttachmentLoader, self) ->free = _AtlasAttachmentLoader_free;
VTABLE(AttachmentLoader, self) ->dispose = _AtlasAttachmentLoader_dispose;
return self;
}

View File

@ -43,8 +43,8 @@ void _Attachment_deinit (Attachment* self) {
FREE(self);
}
void Attachment_free (Attachment* self) {
VTABLE(Attachment, self)->free(self);
void Attachment_dispose (Attachment* self) {
VTABLE(Attachment, self)->dispose(self);
}
void Attachment_draw (Attachment* self, Slot* slot) {

View File

@ -40,8 +40,8 @@ void _AttachmentLoader_deinit (AttachmentLoader* self) {
FREE(self->error2);
}
void AttachmentLoader_free (AttachmentLoader* self) {
VTABLE(AttachmentLoader, self) ->free(self);
void AttachmentLoader_dispose (AttachmentLoader* self) {
VTABLE(AttachmentLoader, self) ->dispose(self);
}
Attachment* AttachmentLoader_newAttachment (AttachmentLoader* self, AttachmentType type, const char* name) {

View File

@ -37,7 +37,7 @@ void Bone_setYDown (int value) {
yDown = value;
}
Bone* Bone_new (BoneData* data, Bone* parent) {
Bone* Bone_create (BoneData* data, Bone* parent) {
Bone* self = NEW(Bone);
CONST_CAST(BoneData*, self->data) = data;
CONST_CAST(Bone*, self->parent) = parent;
@ -46,7 +46,7 @@ Bone* Bone_new (BoneData* data, Bone* parent) {
return self;
}
void Bone_free (Bone* self) {
void Bone_dispose (Bone* self) {
FREE(self);
}

View File

@ -30,7 +30,7 @@
namespace spine {
#endif
BoneData* BoneData_new (const char* name, BoneData* parent) {
BoneData* BoneData_create (const char* name, BoneData* parent) {
BoneData* self = NEW(BoneData);
MALLOC_STR(self->name, name);
CONST_CAST(BoneData*, self->parent) = parent;
@ -39,7 +39,7 @@ BoneData* BoneData_new (const char* name, BoneData* parent) {
return self;
}
void BoneData_free (BoneData* self) {
void BoneData_dispose (BoneData* self) {
FREE(self->name);
FREE(self);
}

View File

@ -1,7 +1,7 @@
/*
Copyright (c) 2009 Dave Gamble
Permission is hereby granted, free of charge, to any person obtaining a copy
Permission is hereby granted, dispose of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@ -48,19 +48,19 @@ static int Json_strcasecmp (const char* s1, const char* s2) {
}
/* Internal constructor. */
static Json *Json_new_Item (void) {
static Json *Json_new (void) {
return (Json*)CALLOC(Json, 1);
}
/* Delete a Json structure. */
void Json_free (Json *c) {
void Json_dispose (Json *c) {
Json *next;
while (c) {
next = c->next;
if (c->child) Json_free(c->child);
if (c->valuestring) free((char*)c->valuestring);
if (c->name) free((char*)c->name);
free(c);
if (c->child) Json_dispose(c->child);
if (c->valuestring) FREE(c->valuestring);
if (c->name) FREE(c->name);
FREE(c);
c = next;
}
}
@ -207,15 +207,15 @@ static const char* skip (const char* in) {
}
/* Parse an object - create a new root, and populate. */
Json *Json_new (const char* value) {
Json *Json_create (const char* value) {
const char* end = 0;
Json *c = Json_new_Item();
Json *c = Json_new();
ep = 0;
if (!c) return 0; /* memory fail */
end = parse_value(c, skip(value));
if (!end) {
Json_free(c);
Json_dispose(c);
return 0;
} /* parse failure. ep is set. */
@ -267,14 +267,14 @@ static const char* parse_array (Json *item, const char* value) {
value = skip(value + 1);
if (*value == ']') return value + 1; /* empty array. */
item->child = child = Json_new_Item();
item->child = child = Json_new();
if (!item->child) return 0; /* memory fail */
value = skip(parse_value(child, skip(value))); /* skip any spacing, get the value. */
if (!value) return 0;
while (*value == ',') {
Json *new_item;
if (!(new_item = Json_new_Item())) return 0; /* memory fail */
if (!(new_item = Json_new())) return 0; /* memory fail */
child->next = new_item;
new_item->prev = child;
child = new_item;
@ -299,7 +299,7 @@ static const char* parse_object (Json *item, const char* value) {
value = skip(value + 1);
if (*value == '}') return value + 1; /* empty array. */
item->child = child = Json_new_Item();
item->child = child = Json_new();
if (!item->child) return 0;
value = skip(parse_string(child, skip(value)));
if (!value) return 0;
@ -314,7 +314,7 @@ static const char* parse_object (Json *item, const char* value) {
while (*value == ',') {
Json *new_item;
if (!(new_item = Json_new_Item())) return 0; /* memory fail */
if (!(new_item = Json_new())) return 0; /* memory fail */
child->next = new_item;
new_item->prev = child;
child = new_item;

View File

@ -1,7 +1,7 @@
/*
Copyright (c) 2009 Dave Gamble
Permission is hereby granted, free of charge, to any person obtaining a copy
Permission is hereby granted, dispose of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@ -54,11 +54,11 @@ typedef struct Json {
const char* name; /* The item's name string, if this item is the child of, or is in the list of subitems of an object. */
} Json;
/* Supply a block of JSON, and this returns a Json object you can interrogate. Call Json_free when finished. */
Json* Json_new (const char* value);
/* Supply a block of JSON, and this returns a Json object you can interrogate. Call Json_dispose when finished. */
Json* Json_create (const char* value);
/* Delete a Json entity and all subentities. */
void Json_free (Json* json);
void Json_dispose (Json* json);
/* Returns the number of items in an array (or object). */
int Json_getSize (Json* json);
@ -72,7 +72,7 @@ const char* Json_getString (Json* json, const char* name, const char* defaultVal
float Json_getFloat (Json* json, const char* name, float defaultValue);
int Json_getInt (Json* json, const char* name, int defaultValue);
/* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when Json_new() returns 0. 0 when Json_new() succeeds. */
/* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when Json_create() returns 0. 0 when Json_create() succeeds. */
const char* Json_getError (void);
#ifdef __cplusplus

View File

@ -51,7 +51,7 @@ void _Skeleton_init (Skeleton* self, SkeletonData* data) {
}
}
}
self->bones[i] = Bone_new(boneData, parent);
self->bones[i] = Bone_create(boneData, parent);
}
self->slotCount = data->slotCount;
@ -68,7 +68,7 @@ void _Skeleton_init (Skeleton* self, SkeletonData* data) {
}
}
self->slots[i] = Slot_new(slotData, self, bone);
self->slots[i] = Slot_create(slotData, self, bone);
}
self->drawOrder = MALLOC(Slot*, self->slotCount);
@ -85,18 +85,18 @@ void _Skeleton_deinit (Skeleton* self) {
int i;
for (i = 0; i < self->boneCount; ++i)
Bone_free(self->bones[i]);
Bone_dispose(self->bones[i]);
FREE(self->bones);
for (i = 0; i < self->slotCount; ++i)
Slot_free(self->slots[i]);
Slot_dispose(self->slots[i]);
FREE(self->slots);
FREE(self->drawOrder);
}
void Skeleton_free (Skeleton* self) {
VTABLE(Skeleton, self) ->free(self);
void Skeleton_dispose (Skeleton* self) {
VTABLE(Skeleton, self) ->dispose(self);
}
void Skeleton_updateWorldTransform (const Skeleton* self) {
@ -163,18 +163,7 @@ int Skeleton_setSkinByName (Skeleton* self, const char* skinName) {
}
void Skeleton_setSkin (Skeleton* self, Skin* newSkin) {
if (self->skin && newSkin) {
/* Attach each attachment in the new skin if the corresponding attachment in the old skin is currently attached. */
const SkinEntry *entry = self->skin->entries;
while (entry) {
Slot *slot = self->slots[entry->slotIndex];
if (slot->attachment == entry->attachment) {
Attachment *attachment = Skin_getAttachment(newSkin, entry->slotIndex, entry->name);
if (attachment) Slot_setAttachment(slot, attachment);
}
entry = entry->next;
}
}
if (self->skin && newSkin) Skin_attachAll(newSkin, self, self->skin);
CONST_CAST(Skin*, self->skin) = newSkin;
}

View File

@ -31,11 +31,11 @@
namespace spine {
#endif
SkeletonData* SkeletonData_new () {
SkeletonData* SkeletonData_create () {
return NEW(SkeletonData);
}
void SkeletonData_free (SkeletonData* self) {
void SkeletonData_dispose (SkeletonData* self) {
FREE(self);
}

View File

@ -41,22 +41,22 @@ typedef struct {
int ownsLoader;
} _Internal;
SkeletonJson* SkeletonJson_newWithLoader (AttachmentLoader* attachmentLoader) {
SkeletonJson* SkeletonJson_createWithLoader (AttachmentLoader* attachmentLoader) {
SkeletonJson* self = SUPER(NEW(_Internal));
self->scale = 1;
self->attachmentLoader = attachmentLoader;
return self;
}
SkeletonJson* SkeletonJson_new (Atlas* atlas) {
AtlasAttachmentLoader* attachmentLoader = AtlasAttachmentLoader_new(atlas);
SkeletonJson* self = SkeletonJson_newWithLoader(SUPER(attachmentLoader));
SkeletonJson* SkeletonJson_create (Atlas* atlas) {
AtlasAttachmentLoader* attachmentLoader = AtlasAttachmentLoader_create(atlas);
SkeletonJson* self = SkeletonJson_createWithLoader(SUPER(attachmentLoader));
SUB_CAST(_Internal, self) ->ownsLoader = 1;
return self;
}
void SkeletonJson_free (SkeletonJson* self) {
if (SUB_CAST(_Internal, self) ->ownsLoader) AttachmentLoader_free(self->attachmentLoader);
void SkeletonJson_dispose (SkeletonJson* self) {
if (SUB_CAST(_Internal, self) ->ownsLoader) AttachmentLoader_dispose(self->attachmentLoader);
FREE(self->error);
FREE(self);
}
@ -68,7 +68,7 @@ void _SkeletonJson_setError (SkeletonJson* self, Json* root, const char* value1,
int length = strlen(value1);
if (value2) strncat(message + length, value2, 256 - length);
MALLOC_STR(self->error, message);
if (root) Json_free(root);
if (root) Json_dispose(root);
}
static float toColor (const char* value, int index) {
@ -100,13 +100,13 @@ SkeletonData* SkeletonJson_readSkeletonData (SkeletonJson* self, const char* jso
FREE(self->error);
CONST_CAST(char*, self->error) = 0;
Json* root = Json_new(json);
Json* root = Json_create(json);
if (!root) {
_SkeletonJson_setError(self, 0, "Invalid skeleton JSON: ", Json_getError());
return 0;
}
SkeletonData* skeletonData = SkeletonData_new();
SkeletonData* skeletonData = SkeletonData_create();
int i, ii, iii;
Json* bones = Json_getItem(root, "bones");
@ -122,13 +122,13 @@ SkeletonData* SkeletonJson_readSkeletonData (SkeletonJson* self, const char* jso
if (parentName) {
parent = SkeletonData_findBone(skeletonData, parentName);
if (!parent) {
SkeletonData_free(skeletonData);
SkeletonData_dispose(skeletonData);
_SkeletonJson_setError(self, root, "Parent bone not found: ", parentName);
return 0;
}
}
BoneData* boneData = BoneData_new(boneName, parent);
BoneData* boneData = BoneData_create(boneName, parent);
boneData->length = Json_getFloat(boneMap, "parent", 0) * self->scale;
boneData->x = Json_getFloat(boneMap, "x", 0) * self->scale;
boneData->y = Json_getFloat(boneMap, "y", 0) * self->scale;
@ -152,12 +152,12 @@ SkeletonData* SkeletonJson_readSkeletonData (SkeletonJson* self, const char* jso
const char* boneName = Json_getString(slotMap, "bone", 0);
BoneData* boneData = SkeletonData_findBone(skeletonData, boneName);
if (!boneData) {
SkeletonData_free(skeletonData);
SkeletonData_dispose(skeletonData);
_SkeletonJson_setError(self, root, "Slot bone not found: ", boneName);
return 0;
}
SlotData* slotData = SlotData_new(slotName, boneData);
SlotData* slotData = SlotData_create(slotName, boneData);
const char* color = Json_getString(slotMap, "color", 0);
if (color) {
@ -182,7 +182,7 @@ SkeletonData* SkeletonJson_readSkeletonData (SkeletonJson* self, const char* jso
for (i = 0; i < skinCount; ++i) {
Json* slotMap = Json_getItemAt(skinsMap, i);
const char* skinName = slotMap->name;
Skin *skin = Skin_new(skinName);
Skin *skin = Skin_create(skinName);
skeletonData->skins[i] = skin;
skeletonData->skinCount++;
if (strcmp(skinName, "default") == 0) skeletonData->defaultSkin = skin;
@ -206,7 +206,7 @@ SkeletonData* SkeletonJson_readSkeletonData (SkeletonJson* self, const char* jso
else if (strcmp(typeString, "regionSequence") == 0)
type = ATTACHMENT_REGION_SEQUENCE;
else {
SkeletonData_free(skeletonData);
SkeletonData_dispose(skeletonData);
_SkeletonJson_setError(self, root, "Unknown attachment type: ", typeString);
return 0;
}
@ -214,7 +214,7 @@ SkeletonData* SkeletonJson_readSkeletonData (SkeletonJson* self, const char* jso
Attachment* attachment = AttachmentLoader_newAttachment(self->attachmentLoader, type, attachmentName);
if (!attachment) {
if (self->attachmentLoader->error1) {
SkeletonData_free(skeletonData);
SkeletonData_dispose(skeletonData);
_SkeletonJson_setError(self, root, self->attachmentLoader->error1, self->attachmentLoader->error2);
return 0;
}
@ -239,7 +239,7 @@ SkeletonData* SkeletonJson_readSkeletonData (SkeletonJson* self, const char* jso
}
}
Json_free(root);
Json_dispose(root);
return skeletonData;
}
@ -270,7 +270,7 @@ Animation* SkeletonJson_readAnimation (SkeletonJson* self, const char* json, con
FREE(self->error);
CONST_CAST(char*, self->error) = 0;
Json* root = Json_new(json);
Json* root = Json_create(json);
if (!root) {
_SkeletonJson_setError(self, 0, "Invalid animation JSON: ", Json_getError());
return 0;
@ -288,7 +288,7 @@ Animation* SkeletonJson_readAnimation (SkeletonJson* self, const char* json, con
timelineCount += Json_getSize(Json_getItemAt(bones, i));
for (i = 0; i < slotCount; ++i)
timelineCount += Json_getSize(Json_getItemAt(slots, i));
Animation* animation = Animation_new(timelineCount);
Animation* animation = Animation_create(timelineCount);
animation->timelineCount = 0;
for (i = 0; i < boneCount; ++i) {
@ -298,7 +298,7 @@ Animation* SkeletonJson_readAnimation (SkeletonJson* self, const char* json, con
int boneIndex = SkeletonData_findBoneIndex(skeletonData, boneName);
if (boneIndex == -1) {
Animation_free(animation);
Animation_dispose(animation);
_SkeletonJson_setError(self, root, "Bone not found: ", boneName);
return 0;
}
@ -310,7 +310,7 @@ Animation* SkeletonJson_readAnimation (SkeletonJson* self, const char* json, con
const char* timelineType = timelineArray->name;
if (strcmp(timelineType, "rotate") == 0) {
RotateTimeline *timeline = RotateTimeline_new(frameCount);
RotateTimeline *timeline = RotateTimeline_create(frameCount);
timeline->boneIndex = boneIndex;
for (iii = 0; iii < frameCount; ++iii) {
Json* frame = Json_getItemAt(timelineArray, iii);
@ -319,12 +319,12 @@ Animation* SkeletonJson_readAnimation (SkeletonJson* self, const char* json, con
}
animation->timelines[animation->timelineCount++] = (Timeline*)timeline;
float duration = timeline->frames[frameCount * 2 - 2];
if (duration > animation->duration) animation->duration = animation->duration;
if (duration > animation->duration) animation->duration = duration;
} else {
int isScale = strcmp(timelineType, "scale") == 0;
if (isScale || strcmp(timelineType, "translate") == 0) {
TranslateTimeline *timeline = isScale ? ScaleTimeline_new(frameCount) : TranslateTimeline_new(frameCount);
TranslateTimeline *timeline = isScale ? ScaleTimeline_create(frameCount) : TranslateTimeline_create(frameCount);
float scale = isScale ? 1 : self->scale;
timeline->boneIndex = boneIndex;
for (iii = 0; iii < frameCount; ++iii) {
@ -335,9 +335,9 @@ Animation* SkeletonJson_readAnimation (SkeletonJson* self, const char* json, con
}
animation->timelines[animation->timelineCount++] = (Timeline*)timeline;
float duration = timeline->frames[frameCount * 3 - 3];
if (duration > animation->duration) animation->duration = animation->duration;
if (duration > animation->duration) animation->duration = duration;
} else {
Animation_free(animation);
Animation_dispose(animation);
_SkeletonJson_setError(self, 0, "Invalid timeline type for a bone: ", timelineType);
return 0;
}
@ -352,7 +352,7 @@ Animation* SkeletonJson_readAnimation (SkeletonJson* self, const char* json, con
int slotIndex = SkeletonData_findSlotIndex(skeletonData, slotName);
if (slotIndex == -1) {
Animation_free(animation);
Animation_dispose(animation);
_SkeletonJson_setError(self, root, "Slot not found: ", slotName);
return 0;
}
@ -364,7 +364,7 @@ Animation* SkeletonJson_readAnimation (SkeletonJson* self, const char* json, con
const char* timelineType = timelineArray->name;
if (strcmp(timelineType, "color") == 0) {
ColorTimeline *timeline = ColorTimeline_new(frameCount);
ColorTimeline *timeline = ColorTimeline_create(frameCount);
timeline->slotIndex = slotIndex;
for (iii = 0; iii < frameCount; ++iii) {
Json* frame = Json_getItemAt(timelineArray, iii);
@ -375,10 +375,10 @@ Animation* SkeletonJson_readAnimation (SkeletonJson* self, const char* json, con
}
animation->timelines[animation->timelineCount++] = (Timeline*)timeline;
float duration = timeline->frames[frameCount * 5 - 5];
if (duration > animation->duration) animation->duration = animation->duration;
if (duration > animation->duration) animation->duration = duration;
} else if (strcmp(timelineType, "attachment") == 0) {
AttachmentTimeline *timeline = AttachmentTimeline_new(frameCount);
AttachmentTimeline *timeline = AttachmentTimeline_create(frameCount);
timeline->slotIndex = slotIndex;
for (iii = 0; iii < frameCount; ++iii) {
Json* frame = Json_getItemAt(timelineArray, iii);
@ -388,10 +388,10 @@ Animation* SkeletonJson_readAnimation (SkeletonJson* self, const char* json, con
}
animation->timelines[animation->timelineCount++] = (Timeline*)timeline;
float duration = timeline->frames[frameCount- 1];
if (duration > animation->duration) animation->duration = animation->duration;
if (duration > animation->duration) animation->duration = duration;
} else {
Animation_free(animation);
Animation_dispose(animation);
_SkeletonJson_setError(self, 0, "Invalid timeline type for a slot: ", timelineType);
return 0;
}

View File

@ -30,33 +30,46 @@
namespace spine {
#endif
SkinEntry* _SkinEntry_new (int slotIndex, const char* name, Attachment* attachment) {
SkinEntry* self = NEW(SkinEntry);
typedef struct _Entry _Entry;
struct _Entry {
int slotIndex;
const char* name;
Attachment* attachment;
_Entry* next;
};
_Entry* _Entry_create (int slotIndex, const char* name, Attachment* attachment) {
_Entry* self = NEW(_Entry);
self->slotIndex = slotIndex;
MALLOC_STR(self->name, name);
self->attachment = attachment;
return self;
}
void _SkinEntry_free (SkinEntry* self) {
Attachment_free(self->attachment);
void _Entry_dispose (_Entry* self) {
Attachment_dispose(self->attachment);
FREE(self->name);
FREE(self);
}
/**/
Skin* Skin_new (const char* name) {
typedef struct {
Skin super;
_Entry* entries;
} _Internal;
Skin* Skin_create (const char* name) {
Skin* self = NEW(Skin);
MALLOC_STR(self->name, name);
return self;
}
void Skin_free (Skin* self) {
SkinEntry* entry = CONST_CAST(SkinEntry*, self->entries);
void Skin_dispose (Skin* self) {
_Entry* entry = SUB_CAST(_Internal, self)->entries;
while (entry) {
SkinEntry* nextEtry = CONST_CAST(SkinEntry*, entry->next);
_SkinEntry_free(entry);
_Entry* nextEtry = entry->next;
_Entry_dispose(entry);
entry = nextEtry;
}
@ -65,19 +78,13 @@ void Skin_free (Skin* self) {
}
void Skin_addAttachment (Skin* self, int slotIndex, const char* name, Attachment* attachment) {
SkinEntry* newEntry = _SkinEntry_new(slotIndex, name, attachment);
SkinEntry* entry = CONST_CAST(SkinEntry*, self->entries);
if (!entry)
CONST_CAST(SkinEntry*, self->entries) = newEntry;
else {
while (entry->next)
entry = (SkinEntry*)entry->next;
entry->next = newEntry;
}
_Entry* newEntry = _Entry_create(slotIndex, name, attachment);
newEntry->next = SUB_CAST(_Internal, self)->entries;
SUB_CAST(_Internal, self)->entries = newEntry;
}
Attachment* Skin_getAttachment (const Skin* self, int slotIndex, const char* name) {
const SkinEntry* entry = self->entries;
const _Entry* entry = SUB_CAST(_Internal, self) ->entries;
while (entry) {
if (entry->slotIndex == slotIndex && strcmp(entry->name, name) == 0) return entry->attachment;
entry = entry->next;
@ -85,6 +92,18 @@ Attachment* Skin_getAttachment (const Skin* self, int slotIndex, const char* nam
return 0;
}
void Skin_attachAll (const Skin* self, Skeleton* skeleton, const Skin* oldSkin) {
const _Entry *entry = SUB_CAST(_Internal, oldSkin) ->entries;
while (entry) {
Slot *slot = skeleton->slots[entry->slotIndex];
if (slot->attachment == entry->attachment) {
Attachment *attachment = Skin_getAttachment(self, entry->slotIndex, entry->name);
if (attachment) Slot_setAttachment(slot, attachment);
}
entry = entry->next;
}
}
#ifdef __cplusplus
}
#endif

View File

@ -36,7 +36,7 @@ typedef struct {
float attachmentTime;
} _Internal;
Slot* Slot_new (SlotData* data, Skeleton* skeleton, Bone* bone) {
Slot* Slot_create (SlotData* data, Skeleton* skeleton, Bone* bone) {
Slot* self = SUPER(NEW(_Internal));
CONST_CAST(SlotData*, self->data) = data;
CONST_CAST(Skeleton*, self->skeleton) = skeleton;
@ -48,7 +48,7 @@ Slot* Slot_new (SlotData* data, Skeleton* skeleton, Bone* bone) {
return self;
}
void Slot_free (Slot* self) {
void Slot_dispose (Slot* self) {
FREE(self);
}

View File

@ -30,7 +30,7 @@
namespace spine {
#endif
SlotData* SlotData_new (const char* name, BoneData* boneData) {
SlotData* SlotData_create (const char* name, BoneData* boneData) {
SlotData* self = NEW(SlotData);
MALLOC_STR(self->name, name);
CONST_CAST(BoneData*, self->boneData) = boneData;
@ -41,7 +41,7 @@ SlotData* SlotData_new (const char* name, BoneData* boneData) {
return self;
}
void SlotData_free (SlotData* self) {
void SlotData_dispose (SlotData* self) {
FREE(self->name);
FREE(self->attachmentName);
FREE(self);

View File

@ -36,6 +36,7 @@ public class AnimationState {
float mixTime, mixDuration;
public AnimationState (AnimationStateData data) {
if (data == null) throw new IllegalArgumentException("data cannot be null.");
this.data = data;
}
@ -69,7 +70,7 @@ public class AnimationState {
public void setAnimation (Animation animation, boolean loop, float time) {
previous = null;
if (animation != null && current != null) {
mixDuration = data.getMixing(current, animation);
mixDuration = data.getMix(current, animation);
if (mixDuration > 0) {
mixTime = 0;
previous = current;

View File

@ -33,7 +33,7 @@ public class AnimationStateData {
final Key tempKey = new Key();
/** Set the mixing duration between two animations. */
public void setMixing (Animation from, Animation to, float duration) {
public void setMix (Animation from, Animation to, float duration) {
if (from == null) throw new IllegalArgumentException("from cannot be null.");
if (to == null) throw new IllegalArgumentException("to cannot be null.");
Key key = new Key();
@ -42,7 +42,7 @@ public class AnimationStateData {
animationToMixTime.put(key, duration);
}
public float getMixing (Animation from, Animation to) {
public float getMix (Animation from, Animation to) {
tempKey.a1 = from;
tempKey.a2 = to;
Float time = animationToMixTime.get(tempKey);

View File

@ -225,7 +225,7 @@ public class Skeleton {
}
/** Sets the skin used to look up attachments not found in the {@link SkeletonData#getDefaultSkin() default skin}. Attachments
* from the new skin are attached if the corresponding attachment from the old skin is currently attached.
* from the new skin are attached if the corresponding attachment from the old skin was attached.
* @param newSkin May be null. */
public void setSkin (Skin newSkin) {
if (skin != null && newSkin != null) newSkin.attachAll(this, skin);

View File

@ -107,7 +107,7 @@ public class Skin {
}
}
/** Attach all attachments from this skin if the corresponding attachment from the old skin is currently attached. */
/** Attach each attachment in this skin if the corresponding attachment in the old skin is currently attached. */
void attachAll (Skeleton skeleton, Skin oldSkin) {
for (Entry<Key, Attachment> entry : oldSkin.attachments.entries()) {
int slotIndex = entry.key.slotIndex;

View File

@ -56,7 +56,7 @@ public class AnimationStateTest extends ApplicationAdapter {
// Define mixing between animations.
AnimationStateData mixing = new AnimationStateData();
mixing.setMixing(walkAnimation, jumpAnimation, 0.4f);
mixing.setMix(walkAnimation, jumpAnimation, 0.4f);
state = new AnimationState(mixing);
state.setAnimation(walkAnimation, true);

View File

@ -32,10 +32,10 @@ using namespace spine;
int main () {
Atlas* atlas = Atlas_readAtlasFile("../data/spineboy.atlas");
SkeletonJson* json = SkeletonJson_new(atlas);
SkeletonJson* json = SkeletonJson_create(atlas);
SkeletonData *skeletonData = SkeletonJson_readSkeletonDataFile(json, "../data/spineboy-skeleton.json");
Animation* animation = SkeletonJson_readAnimationFile(json, "../data/spineboy-walk.json", skeletonData);
SkeletonJson_free(json);
SkeletonJson_dispose(json);
SkeletonDrawable* drawable = new SkeletonDrawable(skeletonData);
Skeleton* skeleton = drawable->skeleton;
@ -66,6 +66,6 @@ int main () {
Skeleton_updateWorldTransform(skeleton);
}
SkeletonData_free(skeletonData);
Atlas_free(atlas);
SkeletonData_dispose(skeletonData);
Atlas_dispose(atlas);
}

View File

@ -41,7 +41,7 @@ using sf::VertexArray;
namespace spine {
void _SfmlAtlasPage_free (AtlasPage* page) {
void _SfmlAtlasPage_dispose (AtlasPage* page) {
SfmlAtlasPage* self = SUB_CAST(SfmlAtlasPage, page);
_AtlasPage_deinit(SUPER(self));
@ -50,10 +50,10 @@ void _SfmlAtlasPage_free (AtlasPage* page) {
FREE(page);
}
AtlasPage* AtlasPage_new (const char* name) {
AtlasPage* AtlasPage_create (const char* name) {
SfmlAtlasPage* self = NEW(SfmlAtlasPage);
_AtlasPage_init(SUPER(self), name);
VTABLE(AtlasPage, self) ->free = _SfmlAtlasPage_free;
VTABLE(AtlasPage, self) ->dispose = _SfmlAtlasPage_dispose;
self->texture = new Texture();
self->texture->loadFromFile(name);
@ -63,17 +63,17 @@ AtlasPage* AtlasPage_new (const char* name) {
/**/
void _SfmlSkeleton_free (Skeleton* self) {
void _SfmlSkeleton_dispose (Skeleton* self) {
_Skeleton_deinit(self);
FREE(self);
}
Skeleton* _SfmlSkeleton_new (SkeletonData* data, SkeletonDrawable* drawable) {
Skeleton* _SfmlSkeleton_create (SkeletonData* data, SkeletonDrawable* drawable) {
Bone_setYDown(1);
SfmlSkeleton* self = NEW(SfmlSkeleton);
_Skeleton_init(SUPER(self), data);
VTABLE(Skeleton, self) ->free = _SfmlSkeleton_free;
VTABLE(Skeleton, self) ->dispose = _SfmlSkeleton_dispose;
CONST_CAST(SkeletonDrawable*, self->drawable) = drawable;
@ -83,12 +83,12 @@ Skeleton* _SfmlSkeleton_new (SkeletonData* data, SkeletonDrawable* drawable) {
SkeletonDrawable::SkeletonDrawable (SkeletonData* skeletonData) :
vertexArray(new VertexArray(Quads, skeletonData->boneCount * 4)),
texture(0) {
skeleton = _SfmlSkeleton_new(skeletonData, this);
skeleton = _SfmlSkeleton_create(skeletonData, this);
}
SkeletonDrawable::~SkeletonDrawable () {
delete vertexArray;
Skeleton_free(skeleton);
Skeleton_dispose(skeleton);
}
void SkeletonDrawable::draw (RenderTarget& target, RenderStates states) const {
@ -101,7 +101,7 @@ void SkeletonDrawable::draw (RenderTarget& target, RenderStates states) const {
/**/
void _SfmlRegionAttachment_free (Attachment* self) {
void _SfmlRegionAttachment_dispose (Attachment* self) {
_RegionAttachment_deinit(SUB_CAST(RegionAttachment, self) );
FREE(self);
}
@ -150,10 +150,10 @@ void _SfmlRegionAttachment_draw (Attachment* attachment, Slot* slot) {
skeleton->drawable->vertexArray->append(vertices[3]);
}
RegionAttachment* RegionAttachment_new (const char* name, AtlasRegion* region) {
RegionAttachment* RegionAttachment_create (const char* name, AtlasRegion* region) {
SfmlRegionAttachment* self = NEW(SfmlRegionAttachment);
_RegionAttachment_init(SUPER(self), name);
VTABLE(Attachment, self) ->free = _SfmlRegionAttachment_free;
VTABLE(Attachment, self) ->dispose = _SfmlRegionAttachment_dispose;
VTABLE(Attachment, self) ->draw = _SfmlRegionAttachment_draw;
self->texture = ((SfmlAtlasPage*)region->page)->texture;