mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-04 22:34:53 +08:00
Allow spine-c to be compiled as C++.
This commit is contained in:
parent
6076689082
commit
dfd090d220
@ -27,6 +27,10 @@
|
||||
#include <math.h>
|
||||
#include <spine/extension.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
namespace spine {
|
||||
#endif
|
||||
|
||||
Animation* Animation_new (int timelineCount) {
|
||||
Animation* self = NEW(Animation);
|
||||
self->timelineCount = timelineCount;
|
||||
@ -453,3 +457,7 @@ void AttachmentTimeline_setFrame (AttachmentTimeline* self, int frameIndex, floa
|
||||
else
|
||||
self->attachmentNames[frameIndex] = 0;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -27,6 +27,10 @@
|
||||
#include <ctype.h>
|
||||
#include <spine/extension.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
namespace spine {
|
||||
#endif
|
||||
|
||||
void _AtlasPage_init (AtlasPage* self, const char* name) {
|
||||
CONST_CAST(_AtlasPageVtable*, self->vtable) = NEW(_AtlasPageVtable);
|
||||
self->name = name; /* name is guaranteed to be memory we allocated. */
|
||||
@ -295,3 +299,7 @@ AtlasRegion* Atlas_findRegion (const Atlas* self, const char* name) {
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -27,6 +27,10 @@
|
||||
#include <stdio.h>
|
||||
#include <spine/extension.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
namespace spine {
|
||||
#endif
|
||||
|
||||
void _AtlasAttachmentLoader_free (AttachmentLoader* self) {
|
||||
_AttachmentLoader_deinit(self);
|
||||
}
|
||||
@ -59,3 +63,7 @@ AtlasAttachmentLoader* AtlasAttachmentLoader_new (Atlas* atlas) {
|
||||
VTABLE(AttachmentLoader, self) ->free = _AtlasAttachmentLoader_free;
|
||||
return self;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -27,6 +27,10 @@
|
||||
#include <spine/extension.h>
|
||||
#include <spine/Slot.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
namespace spine {
|
||||
#endif
|
||||
|
||||
void _Attachment_init (Attachment* self, const char* name, AttachmentType type) {
|
||||
CONST_CAST(_AttachmentVtable*, self->vtable) = NEW(_AttachmentVtable);
|
||||
MALLOC_STR(self->name, name);
|
||||
@ -46,3 +50,7 @@ void Attachment_free (Attachment* self) {
|
||||
void Attachment_draw (Attachment* self, Slot* slot) {
|
||||
VTABLE(Attachment, self)->draw(self, slot);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -26,6 +26,10 @@
|
||||
#include <spine/AttachmentLoader.h>
|
||||
#include <spine/extension.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
namespace spine {
|
||||
#endif
|
||||
|
||||
void _AttachmentLoader_init (AttachmentLoader* self) {
|
||||
CONST_CAST(_AttachmentLoaderVtable*, self->vtable) = NEW(_AttachmentLoaderVtable);
|
||||
}
|
||||
@ -54,3 +58,7 @@ void _AttachmentLoader_setError (AttachmentLoader* self, const char* error1, con
|
||||
MALLOC_STR(self->error1, error1);
|
||||
MALLOC_STR(self->error2, error2);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -27,6 +27,10 @@
|
||||
#include <math.h>
|
||||
#include <spine/extension.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
namespace spine {
|
||||
#endif
|
||||
|
||||
static int yDown;
|
||||
|
||||
void Bone_setYDown (int value) {
|
||||
@ -88,3 +92,7 @@ void Bone_updateWorldTransform (Bone* self, int flipX, int flipY) {
|
||||
CONST_CAST(float, self->m11) = -self->m11;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -26,6 +26,10 @@
|
||||
#include <spine/BoneData.h>
|
||||
#include <spine/extension.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
namespace spine {
|
||||
#endif
|
||||
|
||||
BoneData* BoneData_new (const char* name, BoneData* parent) {
|
||||
BoneData* self = NEW(BoneData);
|
||||
MALLOC_STR(self->name, name);
|
||||
@ -39,3 +43,7 @@ void BoneData_free (BoneData* self) {
|
||||
FREE(self->name);
|
||||
FREE(self);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -23,12 +23,16 @@
|
||||
/* Json */
|
||||
/* JSON parser in C. */
|
||||
|
||||
#include <spine/Json.h>
|
||||
#include "Json.h"
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <spine/extension.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
namespace spine {
|
||||
#endif
|
||||
|
||||
static const char* ep;
|
||||
|
||||
const char* Json_getError (void) {
|
||||
@ -88,7 +92,7 @@ static const char* parse_number (Json *item, const char* num) {
|
||||
subscale = (subscale * 10) + (*num++ - '0'); /* Number? */
|
||||
}
|
||||
|
||||
n = sign * n * pow(10.0, (scale + subscale * signsubscale)); /* number = +/- number.fraction * 10^+/- exponent */
|
||||
n = sign * n * pow(10.0f, (scale + subscale * signsubscale)); /* number = +/- number.fraction * 10^+/- exponent */
|
||||
|
||||
item->valuefloat = n;
|
||||
item->valueint = (int)n;
|
||||
@ -369,3 +373,7 @@ int Json_getInt (Json* value, const char* name, int defaultValue) {
|
||||
value = Json_getItem(value, name);
|
||||
return value ? value->valuefloat : defaultValue;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -27,6 +27,10 @@
|
||||
#include <math.h>
|
||||
#include <spine/extension.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
namespace spine {
|
||||
#endif
|
||||
|
||||
void _RegionAttachment_init (RegionAttachment* self, const char* name) {
|
||||
self->scaleX = 1;
|
||||
self->scaleY = 1;
|
||||
@ -66,3 +70,7 @@ void RegionAttachment_updateOffset (RegionAttachment* self) {
|
||||
self->offset[6] = localX2Cos - localYSin;
|
||||
self->offset[7] = localYCos + localX2Sin;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -27,6 +27,10 @@
|
||||
#include <string.h>
|
||||
#include <spine/extension.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
namespace spine {
|
||||
#endif
|
||||
|
||||
void _Skeleton_init (Skeleton* self, SkeletonData* data) {
|
||||
CONST_CAST(SkeletonData*, self->data) = data;
|
||||
|
||||
@ -209,3 +213,7 @@ int Skeleton_setAttachment (Skeleton* self, const char* slotName, const char* at
|
||||
void Skeleton_update (Skeleton* self, float deltaTime) {
|
||||
self->time += deltaTime;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -27,6 +27,10 @@
|
||||
#include <string.h>
|
||||
#include <spine/extension.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
namespace spine {
|
||||
#endif
|
||||
|
||||
SkeletonData* SkeletonData_new () {
|
||||
return NEW(SkeletonData);
|
||||
}
|
||||
@ -69,3 +73,7 @@ Skin* SkeletonData_findSkin (const SkeletonData* self, const char* skinName) {
|
||||
if (strcmp(self->skins[i]->name, skinName) == 0) return self->skins[i];
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -27,11 +27,15 @@
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include "Json.h"
|
||||
#include <spine/extension.h>
|
||||
#include <spine/Json.h>
|
||||
#include <spine/RegionAttachment.h>
|
||||
#include <spine/AtlasAttachmentLoader.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
namespace spine {
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
SkeletonJson super;
|
||||
int ownsLoader;
|
||||
@ -314,7 +318,8 @@ Animation* SkeletonJson_readAnimation (SkeletonJson* self, const char* json, con
|
||||
readCurve(SUPER(timeline), iii, frame);
|
||||
}
|
||||
animation->timelines[animation->timelineCount++] = (Timeline*)timeline;
|
||||
animation->duration = fmaxf(animation->duration, timeline->frames[frameCount * 2 - 2]);
|
||||
float duration = timeline->frames[frameCount * 2 - 2];
|
||||
if (duration > animation->duration) animation->duration = animation->duration;
|
||||
|
||||
} else {
|
||||
int isScale = strcmp(timelineType, "scale") == 0;
|
||||
@ -329,7 +334,8 @@ Animation* SkeletonJson_readAnimation (SkeletonJson* self, const char* json, con
|
||||
readCurve(SUPER(timeline), iii, frame);
|
||||
}
|
||||
animation->timelines[animation->timelineCount++] = (Timeline*)timeline;
|
||||
animation->duration = fmaxf(animation->duration, timeline->frames[frameCount * 3 - 3]);
|
||||
float duration = timeline->frames[frameCount * 3 - 3];
|
||||
if (duration > animation->duration) animation->duration = animation->duration;
|
||||
} else {
|
||||
Animation_free(animation);
|
||||
_SkeletonJson_setError(self, 0, "Invalid timeline type for a bone: ", timelineType);
|
||||
@ -368,7 +374,8 @@ Animation* SkeletonJson_readAnimation (SkeletonJson* self, const char* json, con
|
||||
readCurve(SUPER(timeline), iii, frame);
|
||||
}
|
||||
animation->timelines[animation->timelineCount++] = (Timeline*)timeline;
|
||||
animation->duration = fmaxf(animation->duration, timeline->frames[frameCount * 5 - 5]);
|
||||
float duration = timeline->frames[frameCount * 5 - 5];
|
||||
if (duration > animation->duration) animation->duration = animation->duration;
|
||||
|
||||
} else if (strcmp(timelineType, "attachment") == 0) {
|
||||
AttachmentTimeline *timeline = AttachmentTimeline_new(frameCount);
|
||||
@ -380,7 +387,8 @@ Animation* SkeletonJson_readAnimation (SkeletonJson* self, const char* json, con
|
||||
name->type == Json_NULL ? 0 : name->valuestring);
|
||||
}
|
||||
animation->timelines[animation->timelineCount++] = (Timeline*)timeline;
|
||||
animation->duration = fmaxf(animation->duration, timeline->frames[frameCount - 1]);
|
||||
float duration = timeline->frames[frameCount- 1];
|
||||
if (duration > animation->duration) animation->duration = animation->duration;
|
||||
|
||||
} else {
|
||||
Animation_free(animation);
|
||||
@ -393,3 +401,7 @@ Animation* SkeletonJson_readAnimation (SkeletonJson* self, const char* json, con
|
||||
|
||||
return animation;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -26,6 +26,10 @@
|
||||
#include <spine/Skin.h>
|
||||
#include <spine/extension.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
namespace spine {
|
||||
#endif
|
||||
|
||||
SkinEntry* _SkinEntry_new (int slotIndex, const char* name, Attachment* attachment) {
|
||||
SkinEntry* self = NEW(SkinEntry);
|
||||
self->slotIndex = slotIndex;
|
||||
@ -80,3 +84,7 @@ Attachment* Skin_getAttachment (const Skin* self, int slotIndex, const char* nam
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -27,6 +27,10 @@
|
||||
#include <spine/extension.h>
|
||||
#include <spine/Skeleton.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
namespace spine {
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
Slot super;
|
||||
float attachmentTime;
|
||||
@ -79,3 +83,7 @@ void Slot_setToBindPose (Slot* self) {
|
||||
}
|
||||
Slot_setAttachment(self, attachment);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -26,6 +26,10 @@
|
||||
#include <spine/SlotData.h>
|
||||
#include <spine/extension.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
namespace spine {
|
||||
#endif
|
||||
|
||||
SlotData* SlotData_new (const char* name, BoneData* boneData) {
|
||||
SlotData* self = NEW(SlotData);
|
||||
MALLOC_STR(self->name, name);
|
||||
@ -50,3 +54,7 @@ void SlotData_setAttachmentName (SlotData* self, const char* attachmentName) {
|
||||
else
|
||||
CONST_CAST(char*, self->attachmentName) = 0;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -26,6 +26,10 @@
|
||||
#include <spine/extension.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
namespace spine {
|
||||
#endif
|
||||
|
||||
char* _readFile (const char* path, int* length) {
|
||||
FILE *file = fopen(path, "rb");
|
||||
if (!file) return 0;
|
||||
@ -40,3 +44,7 @@ char* _readFile (const char* path, int* length) {
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user