mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-21 01:36:02 +08:00
Fixed multithreaded atlas loading.
Sometimes I wonder what I was thinking.
This commit is contained in:
parent
3b5109032c
commit
1a628a66f7
@ -77,23 +77,18 @@ static void trim (Str* str) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Tokenize string without modification. Returns 0 on failure. */
|
/* Tokenize string without modification. Returns 0 on failure. */
|
||||||
static int readLine (const char* begin, const char* end, Str* str) {
|
static int readLine (const char** begin, const char* end, Str* str) {
|
||||||
static const char* nextStart;
|
if (*begin == end) return 0;
|
||||||
if (begin) {
|
str->begin = *begin;
|
||||||
nextStart = begin;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (nextStart == end) return 0;
|
|
||||||
str->begin = nextStart;
|
|
||||||
|
|
||||||
/* Find next delimiter. */
|
/* Find next delimiter. */
|
||||||
while (nextStart != end && *nextStart != '\n')
|
while (*begin != end && **begin != '\n')
|
||||||
nextStart++;
|
(*begin)++;
|
||||||
|
|
||||||
str->end = nextStart;
|
str->end = *begin;
|
||||||
trim(str);
|
trim(str);
|
||||||
|
|
||||||
if (nextStart != end) nextStart++;
|
if (*begin != end) (*begin)++;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,18 +106,18 @@ static int beginPast (Str* str, char c) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Returns 0 on failure. */
|
/* Returns 0 on failure. */
|
||||||
static int readValue (const char* end, Str* str) {
|
static int readValue (const char** begin, const char* end, Str* str) {
|
||||||
readLine(0, end, str);
|
readLine(begin, end, str);
|
||||||
if (!beginPast(str, ':')) return 0;
|
if (!beginPast(str, ':')) return 0;
|
||||||
trim(str);
|
trim(str);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Returns the number of tuple values read (1, 2, 4, or 0 for failure). */
|
/* Returns the number of tuple values read (1, 2, 4, or 0 for failure). */
|
||||||
static int readTuple (const char* end, Str tuple[]) {
|
static int readTuple (const char** begin, const char* end, Str tuple[]) {
|
||||||
int i;
|
int i;
|
||||||
Str str = {NULL, NULL};
|
Str str = {NULL, NULL};
|
||||||
readLine(0, end, &str);
|
readLine(begin, end, &str);
|
||||||
if (!beginPast(&str, ':')) return 0;
|
if (!beginPast(&str, ':')) return 0;
|
||||||
|
|
||||||
for (i = 0; i < 3; ++i) {
|
for (i = 0; i < 3; ++i) {
|
||||||
@ -187,8 +182,7 @@ spAtlas* spAtlas_create (const char* begin, int length, const char* dir, void* r
|
|||||||
self = NEW(spAtlas);
|
self = NEW(spAtlas);
|
||||||
self->rendererObject = rendererObject;
|
self->rendererObject = rendererObject;
|
||||||
|
|
||||||
readLine(begin, 0, 0);
|
while (readLine(&begin, end, &str)) {
|
||||||
while (readLine(0, end, &str)) {
|
|
||||||
if (str.end - str.begin == 0) {
|
if (str.end - str.begin == 0) {
|
||||||
page = 0;
|
page = 0;
|
||||||
} else if (!page) {
|
} else if (!page) {
|
||||||
@ -206,21 +200,21 @@ spAtlas* spAtlas_create (const char* begin, int length, const char* dir, void* r
|
|||||||
self->pages = page;
|
self->pages = page;
|
||||||
lastPage = page;
|
lastPage = page;
|
||||||
|
|
||||||
switch (readTuple(end, tuple)) {
|
switch (readTuple(&begin, end, tuple)) {
|
||||||
case 0:
|
case 0:
|
||||||
return abortAtlas(self);
|
return abortAtlas(self);
|
||||||
case 2: /* size is only optional for an atlas packed with an old TexturePacker. */
|
case 2: /* size is only optional for an atlas packed with an old TexturePacker. */
|
||||||
page->width = toInt(tuple);
|
page->width = toInt(tuple);
|
||||||
page->height = toInt(tuple + 1);
|
page->height = toInt(tuple + 1);
|
||||||
if (!readTuple(end, tuple)) return abortAtlas(self);
|
if (!readTuple(&begin, end, tuple)) return abortAtlas(self);
|
||||||
}
|
}
|
||||||
page->format = (spAtlasFormat)indexOf(formatNames, 7, tuple);
|
page->format = (spAtlasFormat)indexOf(formatNames, 7, tuple);
|
||||||
|
|
||||||
if (!readTuple(end, tuple)) return abortAtlas(self);
|
if (!readTuple(&begin, end, tuple)) return abortAtlas(self);
|
||||||
page->minFilter = (spAtlasFilter)indexOf(textureFilterNames, 7, tuple);
|
page->minFilter = (spAtlasFilter)indexOf(textureFilterNames, 7, tuple);
|
||||||
page->magFilter = (spAtlasFilter)indexOf(textureFilterNames, 7, tuple + 1);
|
page->magFilter = (spAtlasFilter)indexOf(textureFilterNames, 7, tuple + 1);
|
||||||
|
|
||||||
if (!readValue(end, &str)) return abortAtlas(self);
|
if (!readValue(&begin, end, &str)) return abortAtlas(self);
|
||||||
if (!equals(&str, "none")) {
|
if (!equals(&str, "none")) {
|
||||||
page->uWrap = *str.begin == 'x' ? SP_ATLAS_REPEAT : (*str.begin == 'y' ? SP_ATLAS_CLAMPTOEDGE : SP_ATLAS_REPEAT);
|
page->uWrap = *str.begin == 'x' ? SP_ATLAS_REPEAT : (*str.begin == 'y' ? SP_ATLAS_CLAMPTOEDGE : SP_ATLAS_REPEAT);
|
||||||
page->vWrap = *str.begin == 'x' ? SP_ATLAS_CLAMPTOEDGE : (*str.begin == 'y' ? SP_ATLAS_REPEAT : SP_ATLAS_REPEAT);
|
page->vWrap = *str.begin == 'x' ? SP_ATLAS_CLAMPTOEDGE : (*str.begin == 'y' ? SP_ATLAS_REPEAT : SP_ATLAS_REPEAT);
|
||||||
@ -239,14 +233,14 @@ spAtlas* spAtlas_create (const char* begin, int length, const char* dir, void* r
|
|||||||
region->page = page;
|
region->page = page;
|
||||||
region->name = mallocString(&str);
|
region->name = mallocString(&str);
|
||||||
|
|
||||||
if (!readValue(end, &str)) return abortAtlas(self);
|
if (!readValue(&begin, end, &str)) return abortAtlas(self);
|
||||||
region->rotate = equals(&str, "true");
|
region->rotate = equals(&str, "true");
|
||||||
|
|
||||||
if (readTuple(end, tuple) != 2) return abortAtlas(self);
|
if (readTuple(&begin, end, tuple) != 2) return abortAtlas(self);
|
||||||
region->x = toInt(tuple);
|
region->x = toInt(tuple);
|
||||||
region->y = toInt(tuple + 1);
|
region->y = toInt(tuple + 1);
|
||||||
|
|
||||||
if (readTuple(end, tuple) != 2) return abortAtlas(self);
|
if (readTuple(&begin, end, tuple) != 2) return abortAtlas(self);
|
||||||
region->width = toInt(tuple);
|
region->width = toInt(tuple);
|
||||||
region->height = toInt(tuple + 1);
|
region->height = toInt(tuple + 1);
|
||||||
|
|
||||||
@ -260,7 +254,7 @@ spAtlas* spAtlas_create (const char* begin, int length, const char* dir, void* r
|
|||||||
region->v2 = (region->y + region->height) / (float)page->height;
|
region->v2 = (region->y + region->height) / (float)page->height;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(count = readTuple(end, tuple))) return abortAtlas(self);
|
if (!(count = readTuple(&begin, end, tuple))) return abortAtlas(self);
|
||||||
if (count == 4) { /* split is optional */
|
if (count == 4) { /* split is optional */
|
||||||
region->splits = MALLOC(int, 4);
|
region->splits = MALLOC(int, 4);
|
||||||
region->splits[0] = toInt(tuple);
|
region->splits[0] = toInt(tuple);
|
||||||
@ -268,7 +262,7 @@ spAtlas* spAtlas_create (const char* begin, int length, const char* dir, void* r
|
|||||||
region->splits[2] = toInt(tuple + 2);
|
region->splits[2] = toInt(tuple + 2);
|
||||||
region->splits[3] = toInt(tuple + 3);
|
region->splits[3] = toInt(tuple + 3);
|
||||||
|
|
||||||
if (!(count = readTuple(end, tuple))) return abortAtlas(self);
|
if (!(count = readTuple(&begin, end, tuple))) return abortAtlas(self);
|
||||||
if (count == 4) { /* pad is optional, but only present with splits */
|
if (count == 4) { /* pad is optional, but only present with splits */
|
||||||
region->pads = MALLOC(int, 4);
|
region->pads = MALLOC(int, 4);
|
||||||
region->pads[0] = toInt(tuple);
|
region->pads[0] = toInt(tuple);
|
||||||
@ -276,18 +270,18 @@ spAtlas* spAtlas_create (const char* begin, int length, const char* dir, void* r
|
|||||||
region->pads[2] = toInt(tuple + 2);
|
region->pads[2] = toInt(tuple + 2);
|
||||||
region->pads[3] = toInt(tuple + 3);
|
region->pads[3] = toInt(tuple + 3);
|
||||||
|
|
||||||
if (!readTuple(end, tuple)) return abortAtlas(self);
|
if (!readTuple(&begin, end, tuple)) return abortAtlas(self);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
region->originalWidth = toInt(tuple);
|
region->originalWidth = toInt(tuple);
|
||||||
region->originalHeight = toInt(tuple + 1);
|
region->originalHeight = toInt(tuple + 1);
|
||||||
|
|
||||||
readTuple(end, tuple);
|
readTuple(&begin, end, tuple);
|
||||||
region->offsetX = toInt(tuple);
|
region->offsetX = toInt(tuple);
|
||||||
region->offsetY = toInt(tuple + 1);
|
region->offsetY = toInt(tuple + 1);
|
||||||
|
|
||||||
if (!readValue(end, &str)) return abortAtlas(self);
|
if (!readValue(&begin, end, &str)) return abortAtlas(self);
|
||||||
region->index = toInt(&str);
|
region->index = toInt(&str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user