mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
Renamed spAtlas constructor methods to match others. Added void* to spAtlas constructors.
Inside _spAtlasPage_createTexture you can use `self->atlas->rendererObject` to get the void* specified at atlas creation.
This commit is contained in:
parent
3910298c91
commit
cc472d134f
@ -25,7 +25,7 @@ char* _spUtil_readFile (const char* path, int* length) {
|
|||||||
/**/
|
/**/
|
||||||
|
|
||||||
int main (void) {
|
int main (void) {
|
||||||
spAtlas* atlas = spAtlas_readAtlasFile("data/spineboy.atlas");
|
spAtlas* atlas = spAtlas_createFromFile("data/spineboy.atlas", 0);
|
||||||
printf("First region name: %s, x: %d, y: %d\n", atlas->regions->name, atlas->regions->x, atlas->regions->y);
|
printf("First region name: %s, x: %d, y: %d\n", atlas->regions->name, atlas->regions->x, atlas->regions->y);
|
||||||
printf("First page name: %s, size: %d, %d\n", atlas->pages->name, atlas->pages->width, atlas->pages->height);
|
printf("First page name: %s, size: %d, %d\n", atlas->pages->name, atlas->pages->width, atlas->pages->height);
|
||||||
|
|
||||||
|
|||||||
@ -35,6 +35,8 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
typedef struct spAtlas spAtlas;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
SP_ATLAS_ALPHA,
|
SP_ATLAS_ALPHA,
|
||||||
SP_ATLAS_INTENSITY,
|
SP_ATLAS_INTENSITY,
|
||||||
@ -61,6 +63,7 @@ typedef enum {
|
|||||||
|
|
||||||
typedef struct spAtlasPage spAtlasPage;
|
typedef struct spAtlasPage spAtlasPage;
|
||||||
struct spAtlasPage {
|
struct spAtlasPage {
|
||||||
|
const spAtlas* atlas;
|
||||||
const char* name;
|
const char* name;
|
||||||
spAtlasFormat format;
|
spAtlasFormat format;
|
||||||
spAtlasFilter minFilter, magFilter;
|
spAtlasFilter minFilter, magFilter;
|
||||||
@ -72,7 +75,7 @@ struct spAtlasPage {
|
|||||||
spAtlasPage* next;
|
spAtlasPage* next;
|
||||||
};
|
};
|
||||||
|
|
||||||
spAtlasPage* spAtlasPage_create (const char* name);
|
spAtlasPage* spAtlasPage_create (spAtlas* atlas, const char* name);
|
||||||
void spAtlasPage_dispose (spAtlasPage* self);
|
void spAtlasPage_dispose (spAtlasPage* self);
|
||||||
|
|
||||||
#ifdef SPINE_SHORT_NAMES
|
#ifdef SPINE_SHORT_NAMES
|
||||||
@ -132,15 +135,17 @@ typedef spAtlasRegion AtlasRegion;
|
|||||||
|
|
||||||
/**/
|
/**/
|
||||||
|
|
||||||
typedef struct {
|
struct spAtlas {
|
||||||
spAtlasPage* pages;
|
spAtlasPage* pages;
|
||||||
spAtlasRegion* regions;
|
spAtlasRegion* regions;
|
||||||
} spAtlas;
|
|
||||||
|
void* rendererObject;
|
||||||
|
};
|
||||||
|
|
||||||
/* Image files referenced in the atlas file will be prefixed with dir. */
|
/* Image files referenced in the atlas file will be prefixed with dir. */
|
||||||
spAtlas* spAtlas_readAtlas (const char* data, int length, const char* dir);
|
spAtlas* spAtlas_create (const char* data, int length, const char* dir, void* rendererObject);
|
||||||
/* Image files referenced in the atlas file will be prefixed with the directory containing the atlas file. */
|
/* Image files referenced in the atlas file will be prefixed with the directory containing the atlas file. */
|
||||||
spAtlas* spAtlas_readAtlasFile (const char* path);
|
spAtlas* spAtlas_createFromFile (const char* path, void* rendererObject);
|
||||||
void spAtlas_dispose (spAtlas* atlas);
|
void spAtlas_dispose (spAtlas* atlas);
|
||||||
|
|
||||||
/* Returns 0 if the region was not found. */
|
/* Returns 0 if the region was not found. */
|
||||||
@ -148,8 +153,8 @@ spAtlasRegion* spAtlas_findRegion (const spAtlas* self, const char* name);
|
|||||||
|
|
||||||
#ifdef SPINE_SHORT_NAMES
|
#ifdef SPINE_SHORT_NAMES
|
||||||
typedef spAtlas Atlas;
|
typedef spAtlas Atlas;
|
||||||
#define Atlas_readAtlas(...) spAtlas_readAtlas(__VA_ARGS__)
|
#define Atlas_create(...) spAtlas_create(__VA_ARGS__)
|
||||||
#define Atlas_readAtlasFile(...) spAtlas_readAtlasFile(__VA_ARGS__)
|
#define Atlas_createFromFile(...) spAtlas_createFromFile(__VA_ARGS__)
|
||||||
#define Atlas_dispose(...) spAtlas_dispose(__VA_ARGS__)
|
#define Atlas_dispose(...) spAtlas_dispose(__VA_ARGS__)
|
||||||
#define Atlas_findRegion(...) spAtlas_findRegion(__VA_ARGS__)
|
#define Atlas_findRegion(...) spAtlas_findRegion(__VA_ARGS__)
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -32,8 +32,9 @@
|
|||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <spine/extension.h>
|
#include <spine/extension.h>
|
||||||
|
|
||||||
spAtlasPage* spAtlasPage_create (const char* name) {
|
spAtlasPage* spAtlasPage_create (spAtlas* atlas, const char* name) {
|
||||||
spAtlasPage* self = NEW(spAtlasPage);
|
spAtlasPage* self = NEW(spAtlasPage);
|
||||||
|
CONST_CAST(spAtlas*, self->atlas) = atlas;
|
||||||
MALLOC_STR(self->name, name);
|
MALLOC_STR(self->name, name);
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
@ -171,7 +172,7 @@ static const char* formatNames[] = {"Alpha", "Intensity", "LuminanceAlpha", "RGB
|
|||||||
static const char* textureFilterNames[] = {"Nearest", "Linear", "MipMap", "MipMapNearestNearest", "MipMapLinearNearest",
|
static const char* textureFilterNames[] = {"Nearest", "Linear", "MipMap", "MipMapNearestNearest", "MipMapLinearNearest",
|
||||||
"MipMapNearestLinear", "MipMapLinearLinear"};
|
"MipMapNearestLinear", "MipMapLinearLinear"};
|
||||||
|
|
||||||
spAtlas* spAtlas_readAtlas (const char* begin, int length, const char* dir) {
|
spAtlas* spAtlas_create (const char* begin, int length, const char* dir, void* rendererObject) {
|
||||||
int count;
|
int count;
|
||||||
const char* end = begin + length;
|
const char* end = begin + length;
|
||||||
int dirLength = strlen(dir);
|
int dirLength = strlen(dir);
|
||||||
@ -195,7 +196,7 @@ spAtlas* spAtlas_readAtlas (const char* begin, int length, const char* dir) {
|
|||||||
if (needsSlash) path[dirLength] = '/';
|
if (needsSlash) path[dirLength] = '/';
|
||||||
strcpy(path + dirLength + needsSlash, name);
|
strcpy(path + dirLength + needsSlash, name);
|
||||||
|
|
||||||
page = spAtlasPage_create(name);
|
page = spAtlasPage_create(self, name);
|
||||||
FREE(name);
|
FREE(name);
|
||||||
if (lastPage)
|
if (lastPage)
|
||||||
lastPage->next = page;
|
lastPage->next = page;
|
||||||
@ -285,7 +286,7 @@ spAtlas* spAtlas_readAtlas (const char* begin, int length, const char* dir) {
|
|||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
spAtlas* spAtlas_readAtlasFile (const char* path) {
|
spAtlas* spAtlas_createFromFile (const char* path, void* rendererObject) {
|
||||||
int dirLength;
|
int dirLength;
|
||||||
char *dir;
|
char *dir;
|
||||||
int length;
|
int length;
|
||||||
@ -304,7 +305,7 @@ spAtlas* spAtlas_readAtlasFile (const char* path) {
|
|||||||
dir[dirLength] = '\0';
|
dir[dirLength] = '\0';
|
||||||
|
|
||||||
data = _spUtil_readFile(path, &length);
|
data = _spUtil_readFile(path, &length);
|
||||||
if (data) atlas = spAtlas_readAtlas(data, length, dir);
|
if (data) atlas = spAtlas_create(data, length, dir, rendererObject);
|
||||||
|
|
||||||
FREE(data);
|
FREE(data);
|
||||||
FREE(dir);
|
FREE(dir);
|
||||||
|
|||||||
@ -62,7 +62,7 @@ void callback (AnimationState* state, int trackIndex, EventType type, Event* eve
|
|||||||
|
|
||||||
void spineboy () {
|
void spineboy () {
|
||||||
// Load atlas, skeleton, and animations.
|
// Load atlas, skeleton, and animations.
|
||||||
Atlas* atlas = Atlas_readAtlasFile("../data/spineboy.atlas");
|
Atlas* atlas = Atlas_createFromFile("../data/spineboy.atlas", 0);
|
||||||
SkeletonJson* json = SkeletonJson_create(atlas);
|
SkeletonJson* json = SkeletonJson_create(atlas);
|
||||||
json->scale = 0.6f;
|
json->scale = 0.6f;
|
||||||
SkeletonData *skeletonData = SkeletonJson_readSkeletonDataFile(json, "../data/spineboy.json");
|
SkeletonData *skeletonData = SkeletonJson_readSkeletonDataFile(json, "../data/spineboy.json");
|
||||||
@ -136,7 +136,7 @@ void spineboy () {
|
|||||||
|
|
||||||
void goblins () {
|
void goblins () {
|
||||||
// Load atlas, skeleton, and animations.
|
// Load atlas, skeleton, and animations.
|
||||||
Atlas* atlas = Atlas_readAtlasFile("../data/goblins-ffd.atlas");
|
Atlas* atlas = Atlas_createFromFile("../data/goblins-ffd.atlas", 0);
|
||||||
SkeletonJson* json = SkeletonJson_create(atlas);
|
SkeletonJson* json = SkeletonJson_create(atlas);
|
||||||
json->scale = 1.4f;
|
json->scale = 1.4f;
|
||||||
SkeletonData *skeletonData = SkeletonJson_readSkeletonDataFile(json, "../data/goblins-ffd.json");
|
SkeletonData *skeletonData = SkeletonJson_readSkeletonDataFile(json, "../data/goblins-ffd.json");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user