Răsfoiți Sursa

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.
NathanSweet 11 ani în urmă
părinte
comite
cc472d134f

+ 1 - 1
spine-c/example/main.c

@@ -25,7 +25,7 @@ char* _spUtil_readFile (const char* path, int* length) {
 /**/
 
 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 page name: %s, size: %d, %d\n", atlas->pages->name, atlas->pages->width, atlas->pages->height);
 

+ 12 - 7
spine-c/include/spine/Atlas.h

@@ -35,6 +35,8 @@
 extern "C" {
 #endif
 
+typedef struct spAtlas spAtlas;
+
 typedef enum {
 	SP_ATLAS_ALPHA,
 	SP_ATLAS_INTENSITY,
@@ -61,6 +63,7 @@ typedef enum {
 
 typedef struct spAtlasPage spAtlasPage;
 struct spAtlasPage {
+	const spAtlas* atlas;
 	const char* name;
 	spAtlasFormat format;
 	spAtlasFilter minFilter, magFilter;
@@ -72,7 +75,7 @@ struct spAtlasPage {
 	spAtlasPage* next;
 };
 
-spAtlasPage* spAtlasPage_create (const char* name);
+spAtlasPage* spAtlasPage_create (spAtlas* atlas, const char* name);
 void spAtlasPage_dispose (spAtlasPage* self);
 
 #ifdef SPINE_SHORT_NAMES
@@ -132,15 +135,17 @@ typedef spAtlasRegion AtlasRegion;
 
 /**/
 
-typedef struct {
+struct spAtlas {
 	spAtlasPage* pages;
 	spAtlasRegion* regions;
-} spAtlas;
+
+	void* rendererObject;
+};
 
 /* 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. */
-spAtlas* spAtlas_readAtlasFile (const char* path);
+spAtlas* spAtlas_createFromFile (const char* path, void* rendererObject);
 void spAtlas_dispose (spAtlas* atlas);
 
 /* 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
 typedef spAtlas Atlas;
-#define Atlas_readAtlas(...) spAtlas_readAtlas(__VA_ARGS__)
-#define Atlas_readAtlasFile(...) spAtlas_readAtlasFile(__VA_ARGS__)
+#define Atlas_create(...) spAtlas_create(__VA_ARGS__)
+#define Atlas_createFromFile(...) spAtlas_createFromFile(__VA_ARGS__)
 #define Atlas_dispose(...) spAtlas_dispose(__VA_ARGS__)
 #define Atlas_findRegion(...) spAtlas_findRegion(__VA_ARGS__)
 #endif

+ 6 - 5
spine-c/src/spine/Atlas.c

@@ -32,8 +32,9 @@
 #include <ctype.h>
 #include <spine/extension.h>
 
-spAtlasPage* spAtlasPage_create (const char* name) {
+spAtlasPage* spAtlasPage_create (spAtlas* atlas, const char* name) {
 	spAtlasPage* self = NEW(spAtlasPage);
+	CONST_CAST(spAtlas*, self->atlas) = atlas;
 	MALLOC_STR(self->name, name);
 	return self;
 }
@@ -171,7 +172,7 @@ static const char* formatNames[] = {"Alpha", "Intensity", "LuminanceAlpha", "RGB
 static const char* textureFilterNames[] = {"Nearest", "Linear", "MipMap", "MipMapNearestNearest", "MipMapLinearNearest",
 		"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;
 	const char* end = begin + length;
 	int dirLength = strlen(dir);
@@ -195,7 +196,7 @@ spAtlas* spAtlas_readAtlas (const char* begin, int length, const char* dir) {
 			if (needsSlash) path[dirLength] = '/';
 			strcpy(path + dirLength + needsSlash, name);
 
-			page = spAtlasPage_create(name);
+			page = spAtlasPage_create(self, name);
 			FREE(name);
 			if (lastPage)
 				lastPage->next = page;
@@ -285,7 +286,7 @@ spAtlas* spAtlas_readAtlas (const char* begin, int length, const char* dir) {
 	return self;
 }
 
-spAtlas* spAtlas_readAtlasFile (const char* path) {
+spAtlas* spAtlas_createFromFile (const char* path, void* rendererObject) {
 	int dirLength;
 	char *dir;
 	int length;
@@ -304,7 +305,7 @@ spAtlas* spAtlas_readAtlasFile (const char* path) {
 	dir[dirLength] = '\0';
 
 	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(dir);

+ 2 - 2
spine-sfml/example/main.cpp

@@ -62,7 +62,7 @@ void callback (AnimationState* state, int trackIndex, EventType type, Event* eve
 
 void spineboy () {
 	// 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);
 	json->scale = 0.6f;
 	SkeletonData *skeletonData = SkeletonJson_readSkeletonDataFile(json, "../data/spineboy.json");
@@ -136,7 +136,7 @@ void spineboy () {
 
 void goblins () {
 	// 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);
 	json->scale = 1.4f;
 	SkeletonData *skeletonData = SkeletonJson_readSkeletonDataFile(json, "../data/goblins-ffd.json");