mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
fixing compile error
This commit is contained in:
parent
107c18e237
commit
11acfef705
@ -32,6 +32,8 @@
|
|||||||
|
|
||||||
#include <spine/ContainerUtil.h>
|
#include <spine/ContainerUtil.h>
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
namespace Spine
|
namespace Spine
|
||||||
{
|
{
|
||||||
Atlas::Atlas(const char* path, TextureLoader& textureLoader) : _textureLoader(textureLoader)
|
Atlas::Atlas(const char* path, TextureLoader& textureLoader) : _textureLoader(textureLoader)
|
||||||
@ -40,7 +42,7 @@ namespace Spine
|
|||||||
char *dir;
|
char *dir;
|
||||||
int length;
|
int length;
|
||||||
const char* data;
|
const char* data;
|
||||||
|
|
||||||
/* Get directory from atlas path. */
|
/* Get directory from atlas path. */
|
||||||
const char* lastForwardSlash = strrchr(path, '/');
|
const char* lastForwardSlash = strrchr(path, '/');
|
||||||
const char* lastBackwardSlash = strrchr(path, '\\');
|
const char* lastBackwardSlash = strrchr(path, '\\');
|
||||||
@ -50,28 +52,28 @@ namespace Spine
|
|||||||
dir = MALLOC(char, dirLength + 1);
|
dir = MALLOC(char, dirLength + 1);
|
||||||
memcpy(dir, path, dirLength);
|
memcpy(dir, path, dirLength);
|
||||||
dir[dirLength] = '\0';
|
dir[dirLength] = '\0';
|
||||||
|
|
||||||
data = spineReadFile(path, &length);
|
data = spineReadFile(path, &length);
|
||||||
if (data)
|
if (data)
|
||||||
{
|
{
|
||||||
load(data, length, dir);
|
load(data, length, dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
FREE(data);
|
FREE(data);
|
||||||
FREE(dir);
|
FREE(dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
Atlas::Atlas(const char* data, int length, const char* dir, TextureLoader& textureLoader) : _textureLoader(textureLoader)
|
Atlas::Atlas(const char* data, int length, const char* dir, TextureLoader& textureLoader) : _textureLoader(textureLoader)
|
||||||
{
|
{
|
||||||
load(data, length, dir);
|
load(data, length, dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
Atlas::~Atlas()
|
Atlas::~Atlas()
|
||||||
{
|
{
|
||||||
ContainerUtil::cleanUpVectorOfPointers(_pages);
|
ContainerUtil::cleanUpVectorOfPointers(_pages);
|
||||||
ContainerUtil::cleanUpVectorOfPointers(_regions);
|
ContainerUtil::cleanUpVectorOfPointers(_regions);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Atlas::flipV()
|
void Atlas::flipV()
|
||||||
{
|
{
|
||||||
for (size_t i = 0, n = _regions.size(); i < n; ++i)
|
for (size_t i = 0, n = _regions.size(); i < n; ++i)
|
||||||
@ -82,7 +84,7 @@ namespace Spine
|
|||||||
region.v2 = 1 - region.v2;
|
region.v2 = 1 - region.v2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AtlasRegion* Atlas::findRegion(std::string name)
|
AtlasRegion* Atlas::findRegion(std::string name)
|
||||||
{
|
{
|
||||||
for (size_t i = 0, n = _regions.size(); i < n; ++i)
|
for (size_t i = 0, n = _regions.size(); i < n; ++i)
|
||||||
@ -92,10 +94,10 @@ namespace Spine
|
|||||||
return _regions[i];
|
return _regions[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Atlas::dispose()
|
void Atlas::dispose()
|
||||||
{
|
{
|
||||||
for (size_t i = 0, n = _pages.size(); i < n; ++i)
|
for (size_t i = 0, n = _pages.size(); i < n; ++i)
|
||||||
@ -103,22 +105,22 @@ namespace Spine
|
|||||||
_textureLoader.unload(_pages[i]->rendererObject);
|
_textureLoader.unload(_pages[i]->rendererObject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Atlas::load(const char* begin, int length, const char* dir)
|
void Atlas::load(const char* begin, int length, const char* dir)
|
||||||
{
|
{
|
||||||
static const char* formatNames[] = { "", "Alpha", "Intensity", "LuminanceAlpha", "RGB565", "RGBA4444", "RGB888", "RGBA8888" };
|
static const char* formatNames[] = { "", "Alpha", "Intensity", "LuminanceAlpha", "RGB565", "RGBA4444", "RGB888", "RGBA8888" };
|
||||||
static const char* textureFilterNames[] = { "", "Nearest", "Linear", "MipMap", "MipMapNearestNearest", "MipMapLinearNearest",
|
static const char* textureFilterNames[] = { "", "Nearest", "Linear", "MipMap", "MipMapNearestNearest", "MipMapLinearNearest",
|
||||||
"MipMapNearestLinear", "MipMapLinearLinear" };
|
"MipMapNearestLinear", "MipMapLinearLinear" };
|
||||||
|
|
||||||
int count;
|
int count;
|
||||||
const char* end = begin + length;
|
const char* end = begin + length;
|
||||||
int dirLength = (int)strlen(dir);
|
int dirLength = (int)strlen(dir);
|
||||||
int needsSlash = dirLength > 0 && dir[dirLength - 1] != '/' && dir[dirLength - 1] != '\\';
|
int needsSlash = dirLength > 0 && dir[dirLength - 1] != '/' && dir[dirLength - 1] != '\\';
|
||||||
|
|
||||||
AtlasPage *page = 0;
|
AtlasPage *page = 0;
|
||||||
Str str;
|
Str str;
|
||||||
Str tuple[4];
|
Str tuple[4];
|
||||||
|
|
||||||
while (readLine(&begin, end, &str))
|
while (readLine(&begin, end, &str))
|
||||||
{
|
{
|
||||||
if (str.end - str.begin == 0)
|
if (str.end - str.begin == 0)
|
||||||
@ -135,27 +137,27 @@ namespace Spine
|
|||||||
path[dirLength] = '/';
|
path[dirLength] = '/';
|
||||||
}
|
}
|
||||||
strcpy(path + dirLength + needsSlash, name);
|
strcpy(path + dirLength + needsSlash, name);
|
||||||
|
|
||||||
AtlasPage* page = MALLOC(AtlasPage, 1);
|
AtlasPage* page = MALLOC(AtlasPage, 1);
|
||||||
new (page) AtlasPage(std::string(name));
|
new (page) AtlasPage(std::string(name));
|
||||||
|
|
||||||
FREE(name);
|
FREE(name);
|
||||||
|
|
||||||
assert(readTuple(&begin, end, tuple) == 2);
|
assert(readTuple(&begin, end, tuple) == 2);
|
||||||
|
|
||||||
/* size is only optional for an atlas packed with an old TexturePacker. */
|
/* 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);
|
||||||
assert(readTuple(&begin, end, tuple));
|
assert(readTuple(&begin, end, tuple));
|
||||||
|
|
||||||
page->format = (Format)indexOf(formatNames, 8, tuple);
|
page->format = (Format)indexOf(formatNames, 8, tuple);
|
||||||
|
|
||||||
assert(readTuple(&begin, end, tuple));
|
assert(readTuple(&begin, end, tuple));
|
||||||
page->minFilter = (TextureFilter)indexOf(textureFilterNames, 8, tuple);
|
page->minFilter = (TextureFilter)indexOf(textureFilterNames, 8, tuple);
|
||||||
page->magFilter = (TextureFilter)indexOf(textureFilterNames, 8, tuple + 1);
|
page->magFilter = (TextureFilter)indexOf(textureFilterNames, 8, tuple + 1);
|
||||||
|
|
||||||
assert(readValue(&begin, end, &str));
|
assert(readValue(&begin, end, &str));
|
||||||
|
|
||||||
page->uWrap = TextureWrap_ClampToEdge;
|
page->uWrap = TextureWrap_ClampToEdge;
|
||||||
page->vWrap = TextureWrap_ClampToEdge;
|
page->vWrap = TextureWrap_ClampToEdge;
|
||||||
if (!equals(&str, "none"))
|
if (!equals(&str, "none"))
|
||||||
@ -177,32 +179,32 @@ namespace Spine
|
|||||||
page->vWrap = TextureWrap_Repeat;
|
page->vWrap = TextureWrap_Repeat;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_textureLoader.load(*page, std::string(path));
|
_textureLoader.load(*page, std::string(path));
|
||||||
|
|
||||||
FREE(path);
|
FREE(path);
|
||||||
|
|
||||||
_pages.push_back(page);
|
_pages.push_back(page);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
AtlasRegion* region = MALLOC(AtlasRegion, 1);
|
AtlasRegion* region = MALLOC(AtlasRegion, 1);
|
||||||
new (region) AtlasRegion();
|
new (region) AtlasRegion();
|
||||||
|
|
||||||
region->page = page;
|
region->page = page;
|
||||||
region->name = mallocString(&str);
|
region->name = mallocString(&str);
|
||||||
|
|
||||||
assert(readValue(&begin, end, &str));
|
assert(readValue(&begin, end, &str));
|
||||||
region->rotate = equals(&str, "true");
|
region->rotate = equals(&str, "true");
|
||||||
|
|
||||||
assert(readTuple(&begin, end, tuple) == 2);
|
assert(readTuple(&begin, end, tuple) == 2);
|
||||||
region->x = toInt(tuple);
|
region->x = toInt(tuple);
|
||||||
region->y = toInt(tuple + 1);
|
region->y = toInt(tuple + 1);
|
||||||
|
|
||||||
assert(readTuple(&begin, end, tuple) == 2);
|
assert(readTuple(&begin, end, tuple) == 2);
|
||||||
region->width = toInt(tuple);
|
region->width = toInt(tuple);
|
||||||
region->height = toInt(tuple + 1);
|
region->height = toInt(tuple + 1);
|
||||||
|
|
||||||
region->u = region->x / (float)page->width;
|
region->u = region->x / (float)page->width;
|
||||||
region->v = region->y / (float)page->height;
|
region->v = region->y / (float)page->height;
|
||||||
if (region->rotate)
|
if (region->rotate)
|
||||||
@ -215,10 +217,10 @@ namespace Spine
|
|||||||
region->u2 = (region->x + region->width) / (float)page->width;
|
region->u2 = (region->x + region->width) / (float)page->width;
|
||||||
region->v2 = (region->y + region->height) / (float)page->height;
|
region->v2 = (region->y + region->height) / (float)page->height;
|
||||||
}
|
}
|
||||||
|
|
||||||
count = readTuple(&begin, end, tuple);
|
count = readTuple(&begin, end, tuple);
|
||||||
assert(count);
|
assert(count);
|
||||||
|
|
||||||
if (count == 4)
|
if (count == 4)
|
||||||
{
|
{
|
||||||
/* split is optional */
|
/* split is optional */
|
||||||
@ -227,10 +229,10 @@ namespace Spine
|
|||||||
region->splits[1] = toInt(tuple + 1);
|
region->splits[1] = toInt(tuple + 1);
|
||||||
region->splits[2] = toInt(tuple + 2);
|
region->splits[2] = toInt(tuple + 2);
|
||||||
region->splits[3] = toInt(tuple + 3);
|
region->splits[3] = toInt(tuple + 3);
|
||||||
|
|
||||||
count = readTuple(&begin, end, tuple);
|
count = readTuple(&begin, end, tuple);
|
||||||
assert(count);
|
assert(count);
|
||||||
|
|
||||||
if (count == 4)
|
if (count == 4)
|
||||||
{
|
{
|
||||||
/* pad is optional, but only present with splits */
|
/* pad is optional, but only present with splits */
|
||||||
@ -239,75 +241,75 @@ namespace Spine
|
|||||||
region->pads[1] = toInt(tuple + 1);
|
region->pads[1] = toInt(tuple + 1);
|
||||||
region->pads[2] = toInt(tuple + 2);
|
region->pads[2] = toInt(tuple + 2);
|
||||||
region->pads[3] = toInt(tuple + 3);
|
region->pads[3] = toInt(tuple + 3);
|
||||||
|
|
||||||
assert(readTuple(&begin, end, tuple));
|
assert(readTuple(&begin, end, tuple));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
region->originalWidth = toInt(tuple);
|
region->originalWidth = toInt(tuple);
|
||||||
region->originalHeight = toInt(tuple + 1);
|
region->originalHeight = toInt(tuple + 1);
|
||||||
|
|
||||||
readTuple(&begin, end, tuple);
|
readTuple(&begin, end, tuple);
|
||||||
region->offsetX = toInt(tuple);
|
region->offsetX = toInt(tuple);
|
||||||
region->offsetY = toInt(tuple + 1);
|
region->offsetY = toInt(tuple + 1);
|
||||||
|
|
||||||
assert(readValue(&begin, end, &str));
|
assert(readValue(&begin, end, &str));
|
||||||
|
|
||||||
region->index = toInt(&str);
|
region->index = toInt(&str);
|
||||||
|
|
||||||
_regions.push_back(region);
|
_regions.push_back(region);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Atlas::trim(Str* str)
|
void Atlas::trim(Str* str)
|
||||||
{
|
{
|
||||||
while (isspace((unsigned char)*str->begin) && str->begin < str->end)
|
while (isspace((unsigned char)*str->begin) && str->begin < str->end)
|
||||||
{
|
{
|
||||||
(str->begin)++;
|
(str->begin)++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (str->begin == str->end)
|
if (str->begin == str->end)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
str->end--;
|
str->end--;
|
||||||
|
|
||||||
while (isspace((unsigned char)*str->end) && str->end >= str->begin)
|
while (isspace((unsigned char)*str->end) && str->end >= str->begin)
|
||||||
{
|
{
|
||||||
str->end--;
|
str->end--;
|
||||||
}
|
}
|
||||||
|
|
||||||
str->end++;
|
str->end++;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Atlas::readLine(const char** begin, const char* end, Str* str)
|
int Atlas::readLine(const char** begin, const char* end, Str* str)
|
||||||
{
|
{
|
||||||
if (*begin == end)
|
if (*begin == end)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
str->begin = *begin;
|
str->begin = *begin;
|
||||||
|
|
||||||
/* Find next delimiter. */
|
/* Find next delimiter. */
|
||||||
while (*begin != end && **begin != '\n')
|
while (*begin != end && **begin != '\n')
|
||||||
{
|
{
|
||||||
(*begin)++;
|
(*begin)++;
|
||||||
}
|
}
|
||||||
|
|
||||||
str->end = *begin;
|
str->end = *begin;
|
||||||
trim(str);
|
trim(str);
|
||||||
|
|
||||||
if (*begin != end)
|
if (*begin != end)
|
||||||
{
|
{
|
||||||
(*begin)++;
|
(*begin)++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Atlas::beginPast(Str* str, char c)
|
int Atlas::beginPast(Str* str, char c)
|
||||||
{
|
{
|
||||||
const char* begin = str->begin;
|
const char* begin = str->begin;
|
||||||
@ -327,7 +329,7 @@ namespace Spine
|
|||||||
str->begin = begin;
|
str->begin = begin;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Atlas::readValue(const char** begin, const char* end, Str* str)
|
int Atlas::readValue(const char** begin, const char* end, Str* str)
|
||||||
{
|
{
|
||||||
readLine(begin, end, str);
|
readLine(begin, end, str);
|
||||||
@ -335,11 +337,11 @@ namespace Spine
|
|||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
trim(str);
|
trim(str);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Atlas::readTuple(const char** begin, const char* end, Str tuple[])
|
int Atlas::readTuple(const char** begin, const char* end, Str tuple[])
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
@ -349,7 +351,7 @@ namespace Spine
|
|||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < 3; ++i)
|
for (i = 0; i < 3; ++i)
|
||||||
{
|
{
|
||||||
tuple[i].begin = str.begin;
|
tuple[i].begin = str.begin;
|
||||||
@ -357,18 +359,18 @@ namespace Spine
|
|||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
tuple[i].end = str.begin - 2;
|
tuple[i].end = str.begin - 2;
|
||||||
trim(&tuple[i]);
|
trim(&tuple[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
tuple[i].begin = str.begin;
|
tuple[i].begin = str.begin;
|
||||||
tuple[i].end = str.end;
|
tuple[i].end = str.end;
|
||||||
trim(&tuple[i]);
|
trim(&tuple[i]);
|
||||||
|
|
||||||
return i + 1;
|
return i + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* Atlas::mallocString(Str* str)
|
char* Atlas::mallocString(Str* str)
|
||||||
{
|
{
|
||||||
int length = (int)(str->end - str->begin);
|
int length = (int)(str->end - str->begin);
|
||||||
@ -377,7 +379,7 @@ namespace Spine
|
|||||||
string[length] = '\0';
|
string[length] = '\0';
|
||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Atlas::indexOf(const char** array, int count, Str* str)
|
int Atlas::indexOf(const char** array, int count, Str* str)
|
||||||
{
|
{
|
||||||
int length = (int)(str->end - str->begin);
|
int length = (int)(str->end - str->begin);
|
||||||
@ -391,12 +393,12 @@ namespace Spine
|
|||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Atlas::equals(Str* str, const char* other)
|
int Atlas::equals(Str* str, const char* other)
|
||||||
{
|
{
|
||||||
return strncmp(other, str->begin, str->end - str->begin) == 0;
|
return strncmp(other, str->begin, str->end - str->begin) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Atlas::toInt(Str* str)
|
int Atlas::toInt(Str* str)
|
||||||
{
|
{
|
||||||
return (int)strtol(str->begin, (char**)&str->end, 10);
|
return (int)strtol(str->begin, (char**)&str->end, 10);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user