John b9bd66b36b Updated spine-c, spine-sfml, spine-cocos2d-objc and spine-cocos2dx to 3.2.01
- Updated spine-c to 3.2.01, adding shearing and transform constraints plus various bug fixes
- Introduced CMake based system to generated IDE projects for spine-sfml, and download dependencies for all other runtimes
- Updated all spine-c based runtime READMEs with new usage and example instructions
- Moved spine-cocos2d-iphone v2 and spine-cocos2dx v2 to separate branches. These will no longer be updated
- Renamed spine-cocos2d-iphone to spine-cocos2d-iphone

Removed cocos2d-ios v2 Spine runtime. See branch cocos2d-ios-v2 for legacy apps

Moved cocos2d-ios v3 Spine runtime to top-level sphine-cocos2d-iphone directory

Added Visual Studio support to CMake build

Added Linux support for spine-sfml. Do apt-get install sfml-dev as a prerequisit, makes everyone's life easier

Refactored Mac OS X framework detection and linking, added SFML_STATIC define for Win32 build

Removed spine-cocos2dx v2 runtime. See cocos2dx-v2 branch on Github

Moved spine-cocos2dx v3 runtime to root of spine-cocos2dx

spine-c, spine-cocos2d-iphone, spine-cocos2dx, spine-sfml updated to 3.2.00

* Added CMake build for spine-c and spine-sfml
* Removed spine-cocos2dx v2 and spine-cocos2d-iphone v2. See the cocos2dx-v2 and cocos2d-ios-v2 branches if you need these runtimes still
* Added transform constraint rotate, scale, and shear offsets and mixes
* Added spTransformConstraintTimeline
* Added bone shearing
* Added spShearTimeline
* Changed spSkeleton_updateCache
* Changed JSON format, see http://esotericsoftware.com/spine-json-format

Ported 1be89d1c5766fedb91f080a23bffaef6609b86c3 to spine-c

Cleaned up spine-c, removed IDE specific files and unnecessary data/ folder. Use CMake to import into your most beloved IDE

Added spine-cocos2d-iphone to CMake, only downloads cocos2d-objc dependency. Use Xcode project in spine-cocos2d-iphone/ to run examples

Added -std=c98 -pedantic -Wall to spine-c CMake file, fixed up all warnings, fixed up .gitignore

Fixed warnings, replaced calls to stdlib cos/sin/atan2 with macros

New cocos2dx example project, for Windows, Linux and Mac OS X. Doesn't work on Windows/Linux yet

Fixed spine-cocos2dx Visual Studio projects

Reworked cocos2dx dependency resolution

Fixed up src/header paths in CMake files. Dependencies are only downloaded if you build a specific runtime example

Updated spine-sfml README with instructions for Windows

Updated spine-sfml README with instructions for Linux and Mac OS X

Fixed README formatting

More formatting, sorry, can't preview markdown...

More README changes

Renamed spine-cocos2d-iphone to spine-cocos2d-objc, fixed up Xcode project and README

Updated spine-cocos2d-objc README

Added context when exceptions are thrown during attachment and animation parsing.

Added JsonRollback, a tool for converting newer JSON so it can be loaded by an older Spine version.

[Unity] Update BoneFollower

Added coverting linkedmesh to weightedlinkedmesh.

[LUA] AnimationState trackCount bugfixes (#466)

* resolved conflict

* made trackCount keep count, not maximum track index.

Prettier with varargs.

Updated .gitignore to exclude cocos2dx dependencies

Fixed up READMEs of spine-c based runtimes with proper version info. Fixed cocos2d-x CMake build to delete outdated Spine runtime shipped by cocos2d-x
2016-06-22 15:23:31 +02:00

218 lines
7.5 KiB
C

/*
Implementation notes:
- An OOP style is used where each "class" is made up of a struct and a number of functions prefixed with the struct name.
- struct fields that are const are readonly. Either they are set in a create function and can never be changed, or they can only
be changed by calling a function.
- Inheritance is done using a struct field named "super" as the first field, allowing the struct to be cast to its "super class".
This works because a pointer to a struct is guaranteed to be a pointer to the first struct field.
- 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 function pointers in its init function. The public API delegates to these
function pointers.
- Subclasses do not provide a dispose function, instead the base class' dispose function should be used, which will delegate to
a dispose function pointer.
- Classes not designed for inheritance cannot be extended because they may use an internal subclass to hide private data and don't
expose function pointers.
- The public API hides implementation details, such as init/deinit functions. An internal API is exposed by extension.h to allow
classes to be extended. Internal functions begin with underscore (_).
- OOP in C tends to lose type safety. Macros for casting are provided in extension.h to give context for why a cast is being done.
- If SPINE_SHORT_NAMES is defined, the "sp" prefix for all class names is optional.
*/
#ifndef SPINE_EXTENSION_H_
#define SPINE_EXTENSION_H_
/* All allocation uses these. */
#define MALLOC(TYPE,COUNT) ((TYPE*)_malloc(sizeof(TYPE) * (COUNT), __FILE__, __LINE__))
#define CALLOC(TYPE,COUNT) ((TYPE*)_calloc(COUNT, sizeof(TYPE), __FILE__, __LINE__))
#define NEW(TYPE) CALLOC(TYPE,1)
/* Gets the direct super class. Type safe. */
#define SUPER(VALUE) (&VALUE->super)
/* 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. */
#define SUB_CAST(TYPE,VALUE) ((TYPE*)VALUE)
/* Casts away const. Can be used as an lvalue. Not type safe, use with care. */
#define CONST_CAST(TYPE,VALUE) (*(TYPE*)&VALUE)
/* Gets the vtable for the specified type. Not type safe, use with care. */
#define VTABLE(TYPE,VALUE) ((_##TYPE##Vtable*)((TYPE*)VALUE)->vtable)
/* Frees memory. Can be used on const types. */
#define FREE(VALUE) _free((void*)VALUE)
/* Allocates a new char[], assigns it to TO, and copies FROM to it. Can be used on const types. */
#define MALLOC_STR(TO,FROM) strcpy(CONST_CAST(char*, TO) = (char*)MALLOC(char, strlen(FROM) + 1), FROM)
#define PI 3.1415926535897932385f
#define PI2 (PI * 2)
#define DEG_RAD (PI / 180)
#define RAD_DEG (180 / PI)
#define SIN_DEG(A) sinf((A) * DEG_RAD)
#define COS_DEG(A) cosf((A) * DEG_RAD)
#define ABS(A) ((A) < 0? -(A): (A))
#ifdef __STDC_VERSION__
#define FMOD(A,B) fmodf(A, B)
#define ATAN2(A,B) atan2f(A, B)
#define SIN(A) sinf(A)
#define COS(A) cosf(A)
#define SQRT(A) sqrtf(A)
#define ACOS(A) acosf(A)
#else
#define FMOD(A,B) (float)fmod(A, B)
#define ATAN2(A,B) (float)atan2(A, B)
#define COS(A) (float)cos(A)
#define SIN(A) (float)sin(A)
#define SQRT(A) (float)sqrt(A)
#define ACOS(A) (float)acos(A)
#endif
#define UNUSED(x) (void)(x)
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <spine/Skeleton.h>
#include <spine/Animation.h>
#include <spine/Atlas.h>
#include <spine/AttachmentLoader.h>
#include <spine/RegionAttachment.h>
#include <spine/MeshAttachment.h>
#include <spine/WeightedMeshAttachment.h>
#include <spine/BoundingBoxAttachment.h>
#include <spine/AnimationState.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
* Functions that must be implemented:
*/
void _spAtlasPage_createTexture (spAtlasPage* self, const char* path);
void _spAtlasPage_disposeTexture (spAtlasPage* self);
char* _spUtil_readFile (const char* path, int* length);
#ifdef SPINE_SHORT_NAMES
#define _AtlasPage_createTexture(...) _spAtlasPage_createTexture(__VA_ARGS__)
#define _AtlasPage_disposeTexture(...) _spAtlasPage_disposeTexture(__VA_ARGS__)
#define _Util_readFile(...) _spUtil_readFile(__VA_ARGS__)
#endif
/*
* Internal API available for extension:
*/
void* _malloc (size_t size, const char* file, int line);
void* _calloc (size_t num, size_t size, const char* file, int line);
void _free (void* ptr);
void _setMalloc (void* (*_malloc) (size_t size));
void _setDebugMalloc (void* (*_malloc) (size_t size, const char* file, int line));
void _setFree (void (*_free) (void* ptr));
char* _readFile (const char* path, int* length);
/**/
typedef struct _spAnimationState {
spAnimationState super;
spEvent** events;
spTrackEntry* (*createTrackEntry) (spAnimationState* self);
void (*disposeTrackEntry) (spTrackEntry* entry);
#ifdef __cplusplus
_spAnimationState() :
super(),
events(0),
createTrackEntry(0),
disposeTrackEntry(0) {
}
#endif
} _spAnimationState;
spTrackEntry* _spTrackEntry_create (spAnimationState* self);
void _spTrackEntry_dispose (spTrackEntry* self);
/**/
/* configureAttachment and disposeAttachment may be 0. */
void _spAttachmentLoader_init (spAttachmentLoader* self,
void (*dispose) (spAttachmentLoader* self),
spAttachment* (*createAttachment) (spAttachmentLoader* self, spSkin* skin, spAttachmentType type, const char* name,
const char* path),
void (*configureAttachment) (spAttachmentLoader* self, spAttachment*),
void (*disposeAttachment) (spAttachmentLoader* self, spAttachment*)
);
void _spAttachmentLoader_deinit (spAttachmentLoader* self);
/* Can only be called from createAttachment. */
void _spAttachmentLoader_setError (spAttachmentLoader* self, const char* error1, const char* error2);
void _spAttachmentLoader_setUnknownTypeError (spAttachmentLoader* self, spAttachmentType type);
#ifdef SPINE_SHORT_NAMES
#define _AttachmentLoader_init(...) _spAttachmentLoader_init(__VA_ARGS__)
#define _AttachmentLoader_deinit(...) _spAttachmentLoader_deinit(__VA_ARGS__)
#define _AttachmentLoader_setError(...) _spAttachmentLoader_setError(__VA_ARGS__)
#define _AttachmentLoader_setUnknownTypeError(...) _spAttachmentLoader_setUnknownTypeError(__VA_ARGS__)
#endif
/**/
void _spAttachment_init (spAttachment* self, const char* name, spAttachmentType type,
void (*dispose) (spAttachment* self));
void _spAttachment_deinit (spAttachment* self);
#ifdef SPINE_SHORT_NAMES
#define _Attachment_init(...) _spAttachment_init(__VA_ARGS__)
#define _Attachment_deinit(...) _spAttachment_deinit(__VA_ARGS__)
#endif
/**/
void _spTimeline_init (spTimeline* self, spTimelineType type,
void (*dispose) (spTimeline* self),
void (*apply) (const spTimeline* self, spSkeleton* skeleton, float lastTime, float time, spEvent** firedEvents,
int* eventsCount, float alpha));
void _spTimeline_deinit (spTimeline* self);
#ifdef SPINE_SHORT_NAMES
#define _Timeline_init(...) _spTimeline_init(__VA_ARGS__)
#define _Timeline_deinit(...) _spTimeline_deinit(__VA_ARGS__)
#endif
/**/
void _spCurveTimeline_init (spCurveTimeline* self, spTimelineType type, int framesCount,
void (*dispose) (spTimeline* self),
void (*apply) (const spTimeline* self, spSkeleton* skeleton, float lastTime, float time, spEvent** firedEvents,
int* eventsCount, float alpha));
void _spCurveTimeline_deinit (spCurveTimeline* self);
#ifdef SPINE_SHORT_NAMES
#define _CurveTimeline_init(...) _spCurveTimeline_init(__VA_ARGS__)
#define _CurveTimeline_deinit(...) _spCurveTimeline_deinit(__VA_ARGS__)
#endif
#ifdef __cplusplus
}
#endif
#endif /* SPINE_EXTENSION_H_ */