本文整理汇总了C++中TMXMapInfo::setStoringCharacters方法的典型用法代码示例。如果您正苦于以下问题:C++ TMXMapInfo::setStoringCharacters方法的具体用法?C++ TMXMapInfo::setStoringCharacters怎么用?C++ TMXMapInfo::setStoringCharacters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TMXMapInfo
的用法示例。
在下文中一共展示了TMXMapInfo::setStoringCharacters方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: startElement
//.........这里部分代码省略.........
if (_TMXFileName.find_last_of("/") != string::npos)
{
string dir = _TMXFileName.substr(0, _TMXFileName.find_last_of("/") + 1);
tileset->_sourceImage = dir + imagename;
}
else
{
tileset->_sourceImage = _resources + (_resources.size() ? "/" : "") + imagename;
}
}
else if (elementName == "data")
{
std::string encoding = attributeDict["encoding"].asString();
std::string compression = attributeDict["compression"].asString();
if (encoding == "")
{
tmxMapInfo->setLayerAttribs(tmxMapInfo->getLayerAttribs() | TMXLayerAttribNone);
TMXLayerInfo* layer = tmxMapInfo->getLayers().back();
Size layerSize = layer->_layerSize;
int tilesAmount = layerSize.width*layerSize.height;
uint32_t *tiles = (uint32_t*) malloc(tilesAmount*sizeof(uint32_t));
// set all value to 0
memset(tiles, 0, tilesAmount*sizeof(int));
layer->_tiles = tiles;
}
else if (encoding == "base64")
{
int layerAttribs = tmxMapInfo->getLayerAttribs();
tmxMapInfo->setLayerAttribs(layerAttribs | TMXLayerAttribBase64);
tmxMapInfo->setStoringCharacters(true);
if (compression == "gzip")
{
layerAttribs = tmxMapInfo->getLayerAttribs();
tmxMapInfo->setLayerAttribs(layerAttribs | TMXLayerAttribGzip);
} else
if (compression == "zlib")
{
layerAttribs = tmxMapInfo->getLayerAttribs();
tmxMapInfo->setLayerAttribs(layerAttribs | TMXLayerAttribZlib);
}
CCASSERT( compression == "" || compression == "gzip" || compression == "zlib", "TMX: unsupported compression method" );
}
}
else if (elementName == "object")
{
TMXObjectGroup* objectGroup = tmxMapInfo->getObjectGroups().back();
// The value for "type" was blank or not a valid class name
// Create an instance of TMXObjectInfo to store the object and its properties
ValueMap dict;
// Parse everything automatically
const char* keys[] = {"name", "type", "width", "height", "gid"};
for (const auto& key : keys)
{
Value value = attributeDict[key];
dict[key] = value;
}
// But X and Y since they need special treatment
// X
示例2: endElement
void TMXMapInfo::endElement(void *ctx, const char *name)
{
CC_UNUSED_PARAM(ctx);
TMXMapInfo *tmxMapInfo = this;
std::string elementName = name;
if (elementName == "data")
{
if (tmxMapInfo->getLayerAttribs() & TMXLayerAttribBase64)
{
tmxMapInfo->setStoringCharacters(false);
TMXLayerInfo* layer = tmxMapInfo->getLayers().back();
std::string currentString = tmxMapInfo->getCurrentString();
unsigned char *buffer;
auto len = base64Decode((unsigned char*)currentString.c_str(), (unsigned int)currentString.length(), &buffer);
if (!buffer)
{
CCLOG("cocos2d: TiledMap: decode data error");
return;
}
if (tmxMapInfo->getLayerAttribs() & (TMXLayerAttribGzip | TMXLayerAttribZlib))
{
unsigned char *deflated = nullptr;
Size s = layer->_layerSize;
// int sizeHint = s.width * s.height * sizeof(uint32_t);
ssize_t sizeHint = s.width * s.height * sizeof(unsigned int);
ssize_t CC_UNUSED inflatedLen = ZipUtils::inflateMemoryWithHint(buffer, len, &deflated, sizeHint);
CCASSERT(inflatedLen == sizeHint, "inflatedLen should be equal to sizeHint!");
free(buffer);
buffer = nullptr;
if (!deflated)
{
CCLOG("cocos2d: TiledMap: inflate data error");
return;
}
layer->_tiles = reinterpret_cast<uint32_t*>(deflated);
}
else
{
layer->_tiles = reinterpret_cast<uint32_t*>(buffer);
}
tmxMapInfo->setCurrentString("");
}
else if (tmxMapInfo->getLayerAttribs() & TMXLayerAttribNone)
{
_xmlTileIndex = 0;
}
}
else if (elementName == "map")
{
// The map element has ended
tmxMapInfo->setParentElement(TMXPropertyNone);
}
else if (elementName == "layer")
{
// The layer element has ended
tmxMapInfo->setParentElement(TMXPropertyNone);
}
else if (elementName == "objectgroup")
{
// The objectgroup element has ended
tmxMapInfo->setParentElement(TMXPropertyNone);
}
else if (elementName == "object")
{
// The object element has ended
tmxMapInfo->setParentElement(TMXPropertyNone);
}
else if (elementName == "tileset")
{
_recordFirstGID = true;
}
}
示例3: endElement
void TMXMapInfo::endElement(void *ctx, const char *name)
{
CC_UNUSED_PARAM(ctx);
TMXMapInfo *tmxMapInfo = this;
std::string elementName = name;
if (elementName == "data")
{
if (tmxMapInfo->getLayerAttribs() & TMXLayerAttribBase64)
{
tmxMapInfo->setStoringCharacters(false);
TMXLayerInfo* layer = tmxMapInfo->getLayers().back();
std::string currentString = tmxMapInfo->getCurrentString();
unsigned char *buffer;
auto len = base64Decode((unsigned char*)currentString.c_str(), (unsigned int)currentString.length(), &buffer);
if (!buffer)
{
CCLOG("cocos2d: TiledMap: decode data error");
return;
}
if (tmxMapInfo->getLayerAttribs() & (TMXLayerAttribGzip | TMXLayerAttribZlib))
{
unsigned char *deflated = nullptr;
Size s = layer->_layerSize;
// int sizeHint = s.width * s.height * sizeof(uint32_t);
ssize_t sizeHint = s.width * s.height * sizeof(unsigned int);
ssize_t CC_UNUSED inflatedLen = ZipUtils::inflateMemoryWithHint(buffer, len, &deflated, sizeHint);
CCASSERT(inflatedLen == sizeHint, "inflatedLen should be equal to sizeHint!");
free(buffer);
buffer = nullptr;
if (!deflated)
{
CCLOG("cocos2d: TiledMap: inflate data error");
return;
}
layer->_tiles = reinterpret_cast<uint32_t*>(deflated);
}
else
{
layer->_tiles = reinterpret_cast<uint32_t*>(buffer);
}
tmxMapInfo->setCurrentString("");
}
else if (tmxMapInfo->getLayerAttribs() & TMXLayerAttribCSV)
{
unsigned char *buffer;
TMXLayerInfo* layer = tmxMapInfo->getLayers().back();
tmxMapInfo->setStoringCharacters(false);
std::string currentString = tmxMapInfo->getCurrentString();
vector<string> gidTokens;
istringstream filestr(currentString);
string sRow;
while(getline(filestr, sRow, '\n')) {
string sGID;
istringstream rowstr(sRow);
while (getline(rowstr, sGID, ',')) {
gidTokens.push_back(sGID);
}
}
// 32-bits per gid
buffer = (unsigned char*)malloc(gidTokens.size() * 4);
if (!buffer)
{
CCLOG("cocos2d: TiledMap: CSV buffer not allocated.");
return;
}
uint32_t* bufferPtr = reinterpret_cast<uint32_t*>(buffer);
for(auto gidToken : gidTokens) {
auto tileGid = (uint32_t)strtol(gidToken.c_str(), nullptr, 10);
*bufferPtr = tileGid;
bufferPtr++;
}
layer->_tiles = reinterpret_cast<uint32_t*>(buffer);
tmxMapInfo->setCurrentString("");
}
else if (tmxMapInfo->getLayerAttribs() & TMXLayerAttribNone)
{
_xmlTileIndex = 0;
}
}
else if (elementName == "map")
{
// The map element has ended
tmxMapInfo->setParentElement(TMXPropertyNone);
}
//.........这里部分代码省略.........