mirror of https://github.com/axmolengine/axmol.git
Merge branch 'develop' of https://github.com/cocos2d/cocos2d-x into Spine
This commit is contained in:
commit
9fd64df099
|
@ -13,6 +13,7 @@ cocos2d-x-3.0beta0 ?? 2013
|
|||
[FIX] Updates spine runtime to the latest version.
|
||||
[FIX] Uses `const std::string&` instead of `const char*`.
|
||||
[FIX] LabelBMFont string can't be shown integrally.
|
||||
[FIX] Deprecates FileUtils::getFileData, adds FileUtils::getStringFromFile/getDataFromFile.
|
||||
[Android]
|
||||
[NEW] build/android-build.sh: add supporting to generate .apk file
|
||||
[FIX] XMLHttpRequest receives wrong binary array.
|
||||
|
|
|
@ -200,6 +200,11 @@ void ClippingNode::drawFullScreenQuadClearStencil()
|
|||
|
||||
void ClippingNode::visit()
|
||||
{
|
||||
if(!_visible)
|
||||
return;
|
||||
|
||||
kmGLPushMatrix();
|
||||
transform();
|
||||
//Add group command
|
||||
|
||||
Renderer* renderer = Director::getInstance()->getRenderer();
|
||||
|
@ -222,7 +227,31 @@ void ClippingNode::visit()
|
|||
afterDrawStencilCmd->func = CC_CALLBACK_0(ClippingNode::onAfterDrawStencil, this);
|
||||
renderer->addCommand(afterDrawStencilCmd);
|
||||
|
||||
Node::visit();
|
||||
int i = 0;
|
||||
|
||||
if(!_children.empty())
|
||||
{
|
||||
sortAllChildren();
|
||||
// draw children zOrder < 0
|
||||
for( ; i < _children.size(); i++ )
|
||||
{
|
||||
auto node = _children.at(i);
|
||||
|
||||
if ( node && node->getZOrder() < 0 )
|
||||
node->visit();
|
||||
else
|
||||
break;
|
||||
}
|
||||
// self draw
|
||||
this->draw();
|
||||
|
||||
for(auto it=_children.cbegin()+i; it != _children.cend(); ++it)
|
||||
(*it)->visit();
|
||||
}
|
||||
else
|
||||
{
|
||||
this->draw();
|
||||
}
|
||||
|
||||
CustomCommand* afterVisitCmd = CustomCommand::getCommandPool().generateCommand();
|
||||
afterVisitCmd->init(0,_vertexZ);
|
||||
|
@ -230,6 +259,8 @@ void ClippingNode::visit()
|
|||
renderer->addCommand(afterVisitCmd);
|
||||
|
||||
renderer->popGroup();
|
||||
|
||||
kmGLPopMatrix();
|
||||
}
|
||||
|
||||
Node* ClippingNode::getStencil() const
|
||||
|
|
|
@ -1038,7 +1038,7 @@ CC_DEPRECATED_ATTRIBUTE typedef __Integer CCInteger;
|
|||
CC_DEPRECATED_ATTRIBUTE typedef __Bool Bool;
|
||||
CC_DEPRECATED_ATTRIBUTE typedef __Bool CCBool;
|
||||
CC_DEPRECATED_ATTRIBUTE typedef __String CCString;
|
||||
//CC_DEPRECATED_ATTRIBUTE typedef __String String;
|
||||
CC_DEPRECATED_ATTRIBUTE typedef __String String;
|
||||
|
||||
CC_DEPRECATED_ATTRIBUTE typedef __RGBAProtocol RGBAProtocol;
|
||||
CC_DEPRECATED_ATTRIBUTE typedef __NodeRGBA NodeRGBA;
|
||||
|
|
|
@ -90,7 +90,6 @@ FT_Library FontFreeType::getFTLibrary()
|
|||
FontFreeType::FontFreeType(bool dynamicGlyphCollection)
|
||||
: _fontRef(nullptr),
|
||||
_letterPadding(5),
|
||||
_ttfData(nullptr),
|
||||
_dynamicGlyphCollection(dynamicGlyphCollection)
|
||||
{
|
||||
if(_distanceFieldEnabled)
|
||||
|
@ -101,13 +100,13 @@ bool FontFreeType::createFontObject(const std::string &fontName, int fontSize)
|
|||
{
|
||||
FT_Face face;
|
||||
|
||||
ssize_t len = 0;
|
||||
_ttfData = FileUtils::getInstance()->getFileData(fontName.c_str(), "rb", &len);
|
||||
if (!_ttfData)
|
||||
_ttfData = FileUtils::getInstance()->getDataFromFile(fontName);
|
||||
|
||||
if (_ttfData.isNull())
|
||||
return false;
|
||||
|
||||
// create the face from the data
|
||||
if (FT_New_Memory_Face(getFTLibrary(), _ttfData, len, 0, &face ))
|
||||
if (FT_New_Memory_Face(getFTLibrary(), _ttfData.getBytes(), _ttfData.getSize(), 0, &face ))
|
||||
return false;
|
||||
|
||||
//we want to use unicode
|
||||
|
@ -136,11 +135,6 @@ FontFreeType::~FontFreeType()
|
|||
{
|
||||
FT_Done_Face(_fontRef);
|
||||
}
|
||||
if (_ttfData)
|
||||
{
|
||||
free(_ttfData);
|
||||
_ttfData = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
FontAtlas * FontFreeType::createFontAtlas()
|
||||
|
|
|
@ -25,11 +25,12 @@
|
|||
#ifndef _FontFreetype_h_
|
||||
#define _FontFreetype_h_
|
||||
|
||||
#include "CCFont.h"
|
||||
#include "CCData.h"
|
||||
|
||||
#include <string>
|
||||
#include <ft2build.h>
|
||||
|
||||
#include "CCFont.h"
|
||||
|
||||
#include FT_FREETYPE_H
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
@ -73,7 +74,7 @@ private:
|
|||
FT_Face _fontRef;
|
||||
int _letterPadding;
|
||||
std::string _fontName;
|
||||
unsigned char* _ttfData;
|
||||
Data _ttfData;
|
||||
bool _dynamicGlyphCollection;
|
||||
};
|
||||
|
||||
|
|
|
@ -154,18 +154,18 @@ bool GLProgram::initWithVertexShaderByteArray(const GLchar* vShaderByteArray, co
|
|||
|
||||
bool GLProgram::initWithVertexShaderFilename(const char* vShaderFilename, const char* fShaderFilename)
|
||||
{
|
||||
const GLchar * vertexSource = (GLchar*) String::createWithContentsOfFile(FileUtils::getInstance()->fullPathForFilename(vShaderFilename).c_str())->getCString();
|
||||
const GLchar * fragmentSource = (GLchar*) String::createWithContentsOfFile(FileUtils::getInstance()->fullPathForFilename(fShaderFilename).c_str())->getCString();
|
||||
std::string vertexSource = FileUtils::getInstance()->getStringFromFile(FileUtils::getInstance()->fullPathForFilename(vShaderFilename).c_str());
|
||||
std::string fragmentSource = FileUtils::getInstance()->getStringFromFile(FileUtils::getInstance()->fullPathForFilename(fShaderFilename).c_str());
|
||||
|
||||
return initWithVertexShaderByteArray(vertexSource, fragmentSource);
|
||||
return initWithVertexShaderByteArray(vertexSource.c_str(), fragmentSource.c_str());
|
||||
}
|
||||
|
||||
std::string GLProgram::getDescription() const
|
||||
{
|
||||
return String::createWithFormat("<GLProgram = "
|
||||
return StringUtils::format("<GLProgram = "
|
||||
CC_FORMAT_PRINTF_SIZE_T
|
||||
" | Program = %i, VertexShader = %i, FragmentShader = %i>",
|
||||
(size_t)this, _program, _vertShader, _fragShader)->getCString();
|
||||
(size_t)this, _program, _vertShader, _fragShader);
|
||||
}
|
||||
|
||||
bool GLProgram::compileShader(GLuint * shader, GLenum type, const GLchar* source)
|
||||
|
|
|
@ -184,13 +184,13 @@ std::set<unsigned int>* CCBMFontConfiguration::parseConfigFile(const std::string
|
|||
{
|
||||
std::string fullpath = FileUtils::getInstance()->fullPathForFilename(controlFile);
|
||||
|
||||
String *contents = String::createWithContentsOfFile(fullpath.c_str());
|
||||
|
||||
CCASSERT(contents, "CCBMFontConfiguration::parseConfigFile | Open file error.");
|
||||
std::string contents = FileUtils::getInstance()->getStringFromFile(fullpath);
|
||||
|
||||
set<unsigned int> *validCharsString = new set<unsigned int>();
|
||||
CCASSERT(!contents.empty(), "CCBMFontConfiguration::parseConfigFile | Open file error.");
|
||||
|
||||
std::set<unsigned int> *validCharsString = new std::set<unsigned int>();
|
||||
|
||||
if (!contents)
|
||||
if (contents.empty())
|
||||
{
|
||||
CCLOG("cocos2d: Error parsing FNTfile %s", controlFile.c_str());
|
||||
return nullptr;
|
||||
|
@ -198,7 +198,7 @@ std::set<unsigned int>* CCBMFontConfiguration::parseConfigFile(const std::string
|
|||
|
||||
// parse spacing / padding
|
||||
std::string line;
|
||||
std::string strLeft = contents->getCString();
|
||||
std::string strLeft(contents);
|
||||
while (strLeft.length() > 0)
|
||||
{
|
||||
size_t pos = strLeft.find('\n');
|
||||
|
|
|
@ -673,7 +673,7 @@ bool Texture2D::initWithMipmaps(MipmapInfo* mipmaps, int mipmapsNum, PixelFormat
|
|||
|
||||
std::string Texture2D::getDescription() const
|
||||
{
|
||||
return String::createWithFormat("<Texture2D | Name = %u | Dimensions = %ld x %ld | Coordinates = (%.2f, %.2f)>", _name, (long)_pixelsWide, (long)_pixelsHigh, _maxS, _maxT)->getCString();
|
||||
return StringUtils::format("<Texture2D | Name = %u | Dimensions = %ld x %ld | Coordinates = (%.2f, %.2f)>", _name, (long)_pixelsWide, (long)_pixelsHigh, _maxS, _maxT);
|
||||
}
|
||||
|
||||
// implementation Texture2D (Image)
|
||||
|
|
|
@ -224,7 +224,7 @@ void TextureAtlas::listenBackToForeground(Object *obj)
|
|||
|
||||
std::string TextureAtlas::getDescription() const
|
||||
{
|
||||
return String::createWithFormat("<TextureAtlas | totalQuads = %zd>", _totalQuads)->getCString();
|
||||
return StringUtils::format("<TextureAtlas | totalQuads = %zd>", _totalQuads);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -89,7 +89,7 @@ void TextureCache::purgeSharedTextureCache()
|
|||
|
||||
std::string TextureCache::getDescription() const
|
||||
{
|
||||
return String::createWithFormat("<TextureCache | Number of textures = %lu>", _textures.size() )->getCString();
|
||||
return StringUtils::format("<TextureCache | Number of textures = %lu>", _textures.size());
|
||||
}
|
||||
|
||||
void TextureCache::addImageAsync(const std::string &path, Object *target, SEL_CallFuncO selector)
|
||||
|
@ -629,10 +629,10 @@ void VolatileTextureMgr::reloadAllTextures()
|
|||
case VolatileTexture::kImageFile:
|
||||
{
|
||||
Image* image = new Image();
|
||||
ssize_t size = 0;
|
||||
unsigned char* pBuffer = FileUtils::getInstance()->getFileData(vt->_fileName.c_str(), "rb", &size);
|
||||
|
||||
if (image && image->initWithImageData(pBuffer, size))
|
||||
Data data = FileUtils::getInstance()->getDataFromFile(vt->_fileName);
|
||||
|
||||
if (image && image->initWithImageData(data.getBytes(), data.getSize()))
|
||||
{
|
||||
Texture2D::PixelFormat oldPixelFormat = Texture2D::getDefaultAlphaPixelFormat();
|
||||
Texture2D::setDefaultAlphaPixelFormat(vt->_pixelFormat);
|
||||
|
@ -640,7 +640,6 @@ void VolatileTextureMgr::reloadAllTextures()
|
|||
Texture2D::setDefaultAlphaPixelFormat(oldPixelFormat);
|
||||
}
|
||||
|
||||
free(pBuffer);
|
||||
CC_SAFE_RELEASE(image);
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -57,17 +57,16 @@ static tinyxml2::XMLElement* getXMLNodeForKey(const char* pKey, tinyxml2::XMLEle
|
|||
{
|
||||
tinyxml2::XMLDocument* xmlDoc = new tinyxml2::XMLDocument();
|
||||
*doc = xmlDoc;
|
||||
//CCFileData data(UserDefault::getInstance()->getXMLFilePath().c_str(),"rt");
|
||||
ssize_t nSize;
|
||||
char* pXmlBuffer = (char*)FileUtils::getInstance()->getFileData(UserDefault::getInstance()->getXMLFilePath().c_str(), "rb", &nSize);
|
||||
//const char* pXmlBuffer = (const char*)data.getBuffer();
|
||||
if(nullptr == pXmlBuffer)
|
||||
|
||||
std::string xmlBuffer = FileUtils::getInstance()->getStringFromFile(UserDefault::getInstance()->getXMLFilePath());
|
||||
|
||||
if (xmlBuffer.empty())
|
||||
{
|
||||
CCLOG("can not read xml file");
|
||||
break;
|
||||
}
|
||||
xmlDoc->Parse(pXmlBuffer, nSize);
|
||||
free(pXmlBuffer);
|
||||
xmlDoc->Parse(xmlBuffer.c_str(), xmlBuffer.size());
|
||||
|
||||
// get root node
|
||||
*rootNode = xmlDoc->RootElement();
|
||||
if (nullptr == *rootNode)
|
||||
|
@ -288,12 +287,12 @@ string UserDefault::getStringForKey(const char* pKey, const std::string & defaul
|
|||
return ret;
|
||||
}
|
||||
|
||||
Data* UserDefault::getDataForKey(const char* pKey)
|
||||
Data UserDefault::getDataForKey(const char* pKey)
|
||||
{
|
||||
return getDataForKey(pKey, nullptr);
|
||||
return getDataForKey(pKey, Data::Null);
|
||||
}
|
||||
|
||||
Data* UserDefault::getDataForKey(const char* pKey, Data* defaultValue)
|
||||
Data UserDefault::getDataForKey(const char* pKey, const Data& defaultValue)
|
||||
{
|
||||
const char* encodedData = nullptr;
|
||||
tinyxml2::XMLElement* rootNode;
|
||||
|
@ -306,7 +305,7 @@ Data* UserDefault::getDataForKey(const char* pKey, Data* defaultValue)
|
|||
encodedData = (const char*)(node->FirstChild()->Value());
|
||||
}
|
||||
|
||||
Data* ret = defaultValue;
|
||||
Data ret = defaultValue;
|
||||
|
||||
if (encodedData)
|
||||
{
|
||||
|
@ -314,9 +313,7 @@ Data* UserDefault::getDataForKey(const char* pKey, Data* defaultValue)
|
|||
int decodedDataLen = base64Decode((unsigned char*)encodedData, (unsigned int)strlen(encodedData), &decodedData);
|
||||
|
||||
if (decodedData) {
|
||||
ret = Data::create(decodedData, decodedDataLen);
|
||||
|
||||
free(decodedData);
|
||||
ret.fastSet(decodedData, decodedDataLen);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -104,12 +104,12 @@ public:
|
|||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
Data* getDataForKey(const char* pKey);
|
||||
Data getDataForKey(const char* pKey);
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
Data* getDataForKey(const char* pKey, Data* defaultValue);
|
||||
Data getDataForKey(const char* pKey, const Data& defaultValue);
|
||||
|
||||
// set value methods
|
||||
|
||||
|
|
|
@ -73,16 +73,16 @@ static tinyxml2::XMLElement* getXMLNodeForKey(const char* pKey, tinyxml2::XMLDoc
|
|||
{
|
||||
tinyxml2::XMLDocument* xmlDoc = new tinyxml2::XMLDocument();
|
||||
*doc = xmlDoc;
|
||||
ssize_t size;
|
||||
char* pXmlBuffer = (char*)FileUtils::getInstance()->getFileData(UserDefault::getInstance()->getXMLFilePath().c_str(), "rb", &size);
|
||||
//const char* pXmlBuffer = (const char*)data.getBuffer();
|
||||
if(nullptr == pXmlBuffer)
|
||||
|
||||
std::string xmlBuffer = FileUtils::getInstance()->getStringFromFile(UserDefault::getInstance()->getXMLFilePath());
|
||||
|
||||
if (xmlBuffer.empty())
|
||||
{
|
||||
NSLog(@"can not read xml file");
|
||||
break;
|
||||
}
|
||||
xmlDoc->Parse(pXmlBuffer);
|
||||
free(pXmlBuffer);
|
||||
xmlDoc->Parse(xmlBuffer.c_str(), xmlBuffer.size());
|
||||
|
||||
// get root node
|
||||
rootNode = xmlDoc->RootElement();
|
||||
if (nullptr == rootNode)
|
||||
|
@ -363,12 +363,12 @@ string UserDefault::getStringForKey(const char* pKey, const std::string & defaul
|
|||
}
|
||||
}
|
||||
|
||||
Data* UserDefault::getDataForKey(const char* pKey)
|
||||
Data UserDefault::getDataForKey(const char* pKey)
|
||||
{
|
||||
return getDataForKey(pKey, nullptr);
|
||||
return getDataForKey(pKey, Data::Null);
|
||||
}
|
||||
|
||||
Data* UserDefault::getDataForKey(const char* pKey, Data* defaultValue)
|
||||
Data UserDefault::getDataForKey(const char* pKey, const Data& defaultValue)
|
||||
{
|
||||
#ifdef KEEP_COMPATABILITY
|
||||
tinyxml2::XMLDocument* doc = nullptr;
|
||||
|
@ -382,13 +382,12 @@ Data* UserDefault::getDataForKey(const char* pKey, Data* defaultValue)
|
|||
int decodedDataLen = base64Decode((unsigned char*)encodedData, (unsigned int)strlen(encodedData), &decodedData);
|
||||
|
||||
if (decodedData) {
|
||||
Data *ret = Data::create(decodedData, decodedDataLen);
|
||||
Data ret;
|
||||
ret.fastSet(decodedData, decodedDataLen);
|
||||
|
||||
// set value in NSUserDefaults
|
||||
setDataForKey(pKey, ret);
|
||||
|
||||
free(decodedData);
|
||||
|
||||
flush();
|
||||
|
||||
// delete xmle node
|
||||
|
@ -412,17 +411,8 @@ Data* UserDefault::getDataForKey(const char* pKey, Data* defaultValue)
|
|||
}
|
||||
else
|
||||
{
|
||||
unsigned char *bytes = {0};
|
||||
int size = 0;
|
||||
|
||||
if (data.length > 0) {
|
||||
bytes = (unsigned char*)data.bytes;
|
||||
size = static_cast<int>(data.length);
|
||||
}
|
||||
Data *ret = new Data(bytes, size);
|
||||
|
||||
ret->autorelease();
|
||||
|
||||
Data ret;
|
||||
ret.copy((unsigned char*)data.bytes, data.length);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -75,15 +75,16 @@ static tinyxml2::XMLElement* getXMLNodeForKey(const char* pKey, tinyxml2::XMLDoc
|
|||
tinyxml2::XMLDocument* xmlDoc = new tinyxml2::XMLDocument();
|
||||
*doc = xmlDoc;
|
||||
ssize_t size;
|
||||
char* pXmlBuffer = (char*)FileUtils::getInstance()->getFileData(UserDefault::getInstance()->getXMLFilePath().c_str(), "rb", &size);
|
||||
//const char* pXmlBuffer = (const char*)data.getBuffer();
|
||||
if(nullptr == pXmlBuffer)
|
||||
|
||||
std::string xmlBuffer = FileUtils::getInstance()->getStringFromFile(UserDefault::getInstance()->getXMLFilePath().c_str());
|
||||
|
||||
if (xmlBuffer.empty())
|
||||
{
|
||||
CCLOG("can not read xml file");
|
||||
break;
|
||||
}
|
||||
xmlDoc->Parse(pXmlBuffer);
|
||||
free(pXmlBuffer);
|
||||
xmlDoc->Parse(xmlBuffer.c_str());
|
||||
|
||||
// get root node
|
||||
rootNode = xmlDoc->RootElement();
|
||||
if (nullptr == rootNode)
|
||||
|
@ -335,12 +336,12 @@ string UserDefault::getStringForKey(const char* pKey, const std::string & defaul
|
|||
return getStringForKeyJNI(pKey, defaultValue.c_str());
|
||||
}
|
||||
|
||||
Data* UserDefault::getDataForKey(const char* pKey)
|
||||
Data UserDefault::getDataForKey(const char* pKey)
|
||||
{
|
||||
return getDataForKey(pKey, nullptr);
|
||||
return getDataForKey(pKey, Data::Null);
|
||||
}
|
||||
|
||||
Data* UserDefault::getDataForKey(const char* pKey, Data* defaultValue)
|
||||
Data UserDefault::getDataForKey(const char* pKey, const Data& defaultValue)
|
||||
{
|
||||
#ifdef KEEP_COMPATABILITY
|
||||
tinyxml2::XMLDocument* doc = nullptr;
|
||||
|
@ -355,12 +356,12 @@ Data* UserDefault::getDataForKey(const char* pKey, Data* defaultValue)
|
|||
int decodedDataLen = base64Decode((unsigned char*)encodedData, (unsigned int)strlen(encodedData), &decodedData);
|
||||
|
||||
if (decodedData) {
|
||||
Data *ret = Data::create(decodedData, decodedDataLen);
|
||||
Data ret;
|
||||
ret.fastSet(decodedData, decodedDataLen);
|
||||
|
||||
// set value in NSUserDefaults
|
||||
setDataForKey(pKey, ret);
|
||||
|
||||
free(decodedData);
|
||||
flush();
|
||||
|
||||
// delete xmle node
|
||||
|
@ -377,8 +378,8 @@ Data* UserDefault::getDataForKey(const char* pKey, Data* defaultValue)
|
|||
}
|
||||
#endif
|
||||
|
||||
char * encodedDefaultData = nullptr;
|
||||
unsigned int encodedDefaultDataLen = defaultValue ? base64Encode(defaultValue->getBytes(), defaultValue->getSize(), &encodedDefaultData) : 0;
|
||||
char * encodedDefaultData = NULL;
|
||||
unsigned int encodedDefaultDataLen = !defaultValue.isNull() ? base64Encode(defaultValue.getBytes(), defaultValue.getSize(), &encodedDefaultData) : 0;
|
||||
|
||||
string encodedStr = getStringForKeyJNI(pKey, encodedDefaultData);
|
||||
|
||||
|
@ -386,23 +387,19 @@ Data* UserDefault::getDataForKey(const char* pKey, Data* defaultValue)
|
|||
free(encodedDefaultData);
|
||||
|
||||
CCLOG("ENCODED STRING: --%s--%d", encodedStr.c_str(), encodedStr.length());
|
||||
|
||||
Data *ret = defaultValue;
|
||||
|
||||
unsigned char * decodedData = nullptr;
|
||||
|
||||
unsigned char * decodedData = NULL;
|
||||
int decodedDataLen = base64Decode((unsigned char*)encodedStr.c_str(), (unsigned int)encodedStr.length(), &decodedData);
|
||||
|
||||
CCLOG("AFTER DECoDE. ret %p defaultValue %p", ret, defaultValue);
|
||||
CCLOG("DECoDED DATA: %s %d", decodedData, decodedDataLen);
|
||||
CCLOG("DECODED DATA: %s %d", decodedData, decodedDataLen);
|
||||
|
||||
if (decodedData && decodedDataLen) {
|
||||
ret = Data::create(decodedData, decodedDataLen);
|
||||
free(decodedData);
|
||||
Data ret;
|
||||
ret.fastSet(decodedData, decodedDataLen);
|
||||
return ret;
|
||||
}
|
||||
|
||||
CCLOG("RETURNED %p!", ret);
|
||||
|
||||
return ret;
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ THE SOFTWARE.
|
|||
#include <stdlib.h>
|
||||
|
||||
#include "TGAlib.h"
|
||||
#include "CCData.h"
|
||||
#include "platform/CCFileUtils.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
@ -272,15 +273,11 @@ tImageTGA* tgaLoadBuffer(unsigned char* buffer, long size)
|
|||
// this is the function to call when we want to load an image
|
||||
tImageTGA * tgaLoad(const char *filename)
|
||||
{
|
||||
ssize_t size = 0;
|
||||
unsigned char* buffer = FileUtils::getInstance()->getFileData(filename, "rb", &size);
|
||||
Data data = FileUtils::getInstance()->getDataFromFile(filename);
|
||||
|
||||
if (buffer != nullptr)
|
||||
if (!data.isNull())
|
||||
{
|
||||
tImageTGA* data = tgaLoadBuffer(buffer, size);
|
||||
free(buffer);
|
||||
|
||||
return data;
|
||||
return tgaLoadBuffer(data.getBytes(), data.getSize());
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include <stdlib.h>
|
||||
|
||||
#include "ZipUtils.h"
|
||||
#include "CCData.h"
|
||||
#include "ccMacros.h"
|
||||
#include "platform/CCFileUtils.h"
|
||||
#include "unzip.h"
|
||||
|
@ -304,21 +305,15 @@ int ZipUtils::inflateGZipFile(const char *path, unsigned char **out)
|
|||
bool ZipUtils::isCCZFile(const char *path)
|
||||
{
|
||||
// load file into memory
|
||||
unsigned char* compressed = nullptr;
|
||||
Data compressedData = FileUtils::getInstance()->getDataFromFile(path);
|
||||
|
||||
ssize_t fileLen = 0;
|
||||
compressed = FileUtils::getInstance()->getFileData(path, "rb", &fileLen);
|
||||
|
||||
if(compressed == nullptr || fileLen == 0)
|
||||
if (compressedData.isNull())
|
||||
{
|
||||
CCLOG("cocos2d: ZipUtils: loading file failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ret = isCCZBuffer(compressed, fileLen);
|
||||
free(compressed);
|
||||
|
||||
return ret;
|
||||
return isCCZBuffer(compressedData.getBytes(), compressedData.getSize());
|
||||
}
|
||||
|
||||
bool ZipUtils::isCCZBuffer(const unsigned char *buffer, ssize_t len)
|
||||
|
@ -336,20 +331,15 @@ bool ZipUtils::isCCZBuffer(const unsigned char *buffer, ssize_t len)
|
|||
bool ZipUtils::isGZipFile(const char *path)
|
||||
{
|
||||
// load file into memory
|
||||
unsigned char* compressed = nullptr;
|
||||
Data compressedData = FileUtils::getInstance()->getDataFromFile(path);
|
||||
|
||||
ssize_t fileLen = 0;
|
||||
compressed = FileUtils::getInstance()->getFileData(path, "rb", &fileLen);
|
||||
|
||||
if(nullptr == compressed || 0 == fileLen)
|
||||
if (compressedData.isNull())
|
||||
{
|
||||
CCLOG("cocos2d: ZipUtils: loading file failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ret = isGZipBuffer(compressed, fileLen);
|
||||
free(compressed);
|
||||
return ret;
|
||||
return isGZipBuffer(compressedData.getBytes(), compressedData.getSize());
|
||||
}
|
||||
|
||||
bool ZipUtils::isGZipBuffer(const unsigned char *buffer, ssize_t len)
|
||||
|
@ -455,24 +445,18 @@ int ZipUtils::inflateCCZBuffer(const unsigned char *buffer, ssize_t bufferLen, u
|
|||
|
||||
int ZipUtils::inflateCCZFile(const char *path, unsigned char **out)
|
||||
{
|
||||
CCAssert(out, "");
|
||||
CCAssert(&*out, "");
|
||||
CCASSERT(out, "Invalid pointer for buffer!");
|
||||
|
||||
// load file into memory
|
||||
unsigned char* compressed = nullptr;
|
||||
Data compressedData = FileUtils::getInstance()->getDataFromFile(path);
|
||||
|
||||
ssize_t fileLen = 0;
|
||||
compressed = FileUtils::getInstance()->getFileData(path, "rb", &fileLen);
|
||||
|
||||
if(nullptr == compressed || 0 == fileLen)
|
||||
if (compressedData.isNull())
|
||||
{
|
||||
CCLOG("cocos2d: Error loading CCZ compressed file");
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ret = inflateCCZBuffer(compressed, fileLen, out);
|
||||
free(compressed);
|
||||
return ret;
|
||||
return inflateCCZBuffer(compressedData.getBytes(), compressedData.getSize(), out);
|
||||
}
|
||||
|
||||
void ZipUtils::setPvrEncryptionKeyPart(int index, unsigned int value)
|
||||
|
|
|
@ -23,6 +23,7 @@ THE SOFTWARE.
|
|||
****************************************************************************/
|
||||
|
||||
#include "CCFileUtils.h"
|
||||
#include "CCData.h"
|
||||
#include "ccMacros.h"
|
||||
#include "CCDirector.h"
|
||||
#include "CCSAXParser.h"
|
||||
|
@ -491,6 +492,69 @@ void FileUtils::purgeCachedEntries()
|
|||
_fullPathCache.clear();
|
||||
}
|
||||
|
||||
static Data getData(const std::string& filename, bool forString)
|
||||
{
|
||||
CCASSERT(!filename.empty(), "Invalid filename!");
|
||||
|
||||
Data ret;
|
||||
unsigned char* buffer = nullptr;
|
||||
ssize_t size = 0;
|
||||
const char* mode = nullptr;
|
||||
if (forString)
|
||||
mode = "rt";
|
||||
else
|
||||
mode = "rb";
|
||||
|
||||
do
|
||||
{
|
||||
// Read the file from hardware
|
||||
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(filename);
|
||||
FILE *fp = fopen(fullPath.c_str(), mode);
|
||||
CC_BREAK_IF(!fp);
|
||||
fseek(fp,0,SEEK_END);
|
||||
size = ftell(fp);
|
||||
fseek(fp,0,SEEK_SET);
|
||||
|
||||
if (forString)
|
||||
{
|
||||
buffer = (unsigned char*)malloc(sizeof(unsigned char) * (size + 1));
|
||||
buffer[size] = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer = (unsigned char*)malloc(sizeof(unsigned char) * size);
|
||||
}
|
||||
|
||||
size = fread(buffer, sizeof(unsigned char), size, fp);
|
||||
fclose(fp);
|
||||
} while (0);
|
||||
|
||||
if (nullptr == buffer || 0 == size)
|
||||
{
|
||||
std::string msg = "Get data from file(";
|
||||
msg.append(filename).append(") failed!");
|
||||
CCLOG("%s", msg.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
ret.fastSet(buffer, size);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string FileUtils::getStringFromFile(const std::string& filename)
|
||||
{
|
||||
Data data = getData(filename, true);
|
||||
std::string ret((const char*)data.getBytes());
|
||||
return ret;
|
||||
}
|
||||
|
||||
Data FileUtils::getDataFromFile(const std::string& filename)
|
||||
{
|
||||
return getData(filename, false);
|
||||
}
|
||||
|
||||
unsigned char* FileUtils::getFileData(const char* filename, const char* mode, ssize_t *size)
|
||||
{
|
||||
unsigned char * buffer = nullptr;
|
||||
|
|
|
@ -30,6 +30,7 @@ THE SOFTWARE.
|
|||
#include "CCPlatformMacros.h"
|
||||
#include "ccTypes.h"
|
||||
#include "CCValue.h"
|
||||
#include "CCData.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -75,16 +76,27 @@ public:
|
|||
*/
|
||||
virtual void purgeCachedEntries();
|
||||
|
||||
/**
|
||||
* Gets string from a file.
|
||||
*/
|
||||
virtual std::string getStringFromFile(const std::string& filename);
|
||||
|
||||
/**
|
||||
* Creates binary data from a file.
|
||||
* @return A data object.
|
||||
*/
|
||||
virtual Data getDataFromFile(const std::string& filename);
|
||||
|
||||
/**
|
||||
* Gets resource file data
|
||||
*
|
||||
* @param[in] filename The resource file name which contains the path.
|
||||
* @param[in] pszMode The read mode of the file.
|
||||
* @param[out] pSize If the file read operation succeeds, it will be the data size, otherwise 0.
|
||||
* @return Upon success, a pointer to the data is returned, otherwise nullptr.
|
||||
* @warning Recall: you are responsible for calling free() on any Non-nullptr pointer returned.
|
||||
* @return Upon success, a pointer to the data is returned, otherwise NULL.
|
||||
* @warning Recall: you are responsible for calling free() on any Non-NULL pointer returned.
|
||||
*/
|
||||
virtual unsigned char* getFileData(const char* filename, const char* mode, ssize_t *size);
|
||||
CC_DEPRECATED_ATTRIBUTE virtual unsigned char* getFileData(const char* filename, const char* mode, ssize_t *size);
|
||||
|
||||
/**
|
||||
* Gets resource file data from a zip file.
|
||||
|
|
|
@ -24,6 +24,7 @@ THE SOFTWARE.
|
|||
|
||||
|
||||
#include "CCImage.h"
|
||||
#include "CCData.h"
|
||||
|
||||
#include <string>
|
||||
#include <ctype.h>
|
||||
|
@ -420,15 +421,12 @@ bool Image::initWithImageFile(const char * strPath)
|
|||
|
||||
SDL_FreeSurface(iSurf);
|
||||
#else
|
||||
ssize_t bufferLen = 0;
|
||||
unsigned char* buffer = FileUtils::getInstance()->getFileData(_filePath.c_str(), "rb", &bufferLen);
|
||||
Data data = FileUtils::getInstance()->getDataFromFile(_filePath);
|
||||
|
||||
if (buffer != nullptr && bufferLen > 0)
|
||||
if (!data.isNull())
|
||||
{
|
||||
bRet = initWithImageData(buffer, bufferLen);
|
||||
bRet = initWithImageData(data.getBytes(), data.getSize());
|
||||
}
|
||||
|
||||
free(buffer);
|
||||
#endif // EMSCRIPTEN
|
||||
|
||||
return bRet;
|
||||
|
@ -437,19 +435,15 @@ bool Image::initWithImageFile(const char * strPath)
|
|||
bool Image::initWithImageFileThreadSafe(const char *fullpath)
|
||||
{
|
||||
bool ret = false;
|
||||
ssize_t dataLen = 0;
|
||||
_filePath = fullpath;
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
FileUtilsAndroid *fileUitls = (FileUtilsAndroid*)FileUtils::getInstance();
|
||||
unsigned char *buffer = fileUitls->getFileDataForAsync(fullpath, "rb", &dataLen);
|
||||
#else
|
||||
unsigned char *buffer = FileUtils::getInstance()->getFileData(fullpath, "rb", &dataLen);
|
||||
#endif
|
||||
if (buffer != NULL && dataLen > 0)
|
||||
|
||||
Data data = FileUtils::getInstance()->getDataFromFile(fullpath);
|
||||
|
||||
if (!data.isNull())
|
||||
{
|
||||
ret = initWithImageData(buffer, dataLen);
|
||||
ret = initWithImageData(data.getBytes(), data.getSize());
|
||||
}
|
||||
free(buffer);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -111,16 +111,15 @@ bool SAXParser::parse(const char* xmlData, size_t dataLength)
|
|||
return tinyDoc.Accept( &printer );
|
||||
}
|
||||
|
||||
bool SAXParser::parse(const char *file)
|
||||
bool SAXParser::parse(const std::string& filename)
|
||||
{
|
||||
bool ret = false;
|
||||
ssize_t size = 0;
|
||||
char* buffer = (char*)FileUtils::getInstance()->getFileData(file, "rt", &size);
|
||||
if (buffer != nullptr && size > 0)
|
||||
Data data = FileUtils::getInstance()->getDataFromFile(filename);
|
||||
if (!data.isNull())
|
||||
{
|
||||
ret = parse(buffer, size);
|
||||
ret = parse((const char*)data.getBytes(), data.getSize());
|
||||
}
|
||||
free(buffer);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
|
||||
#include "CCPlatformConfig.h"
|
||||
#include "platform/CCCommon.h"
|
||||
#include "string.h" // for size_t
|
||||
#include <string>
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -87,7 +87,7 @@ public:
|
|||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
bool parse(const char *file);
|
||||
bool parse(const std::string& filename);
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
|
|
|
@ -34,13 +34,13 @@ THE SOFTWARE.
|
|||
|
||||
using namespace std;
|
||||
|
||||
AAssetManager* cocos2d::FileUtilsAndroid::assetmanager = NULL;
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
AAssetManager* FileUtilsAndroid::assetmanager = nullptr;
|
||||
|
||||
void FileUtilsAndroid::setassetmanager(AAssetManager* a) {
|
||||
if (NULL == a) {
|
||||
LOGD("setassetmanager : received unexpected NULL parameter");
|
||||
if (nullptr == a) {
|
||||
LOGD("setassetmanager : received unexpected nullptr parameter");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -49,13 +49,13 @@ void FileUtilsAndroid::setassetmanager(AAssetManager* a) {
|
|||
|
||||
FileUtils* FileUtils::getInstance()
|
||||
{
|
||||
if (s_sharedFileUtils == NULL)
|
||||
if (s_sharedFileUtils == nullptr)
|
||||
{
|
||||
s_sharedFileUtils = new FileUtilsAndroid();
|
||||
if(!s_sharedFileUtils->init())
|
||||
{
|
||||
delete s_sharedFileUtils;
|
||||
s_sharedFileUtils = NULL;
|
||||
s_sharedFileUtils = nullptr;
|
||||
CCLOG("ERROR: Could not init CCFileUtilsAndroid");
|
||||
}
|
||||
}
|
||||
|
@ -129,19 +129,126 @@ bool FileUtilsAndroid::isAbsolutePath(const std::string& strPath) const
|
|||
return false;
|
||||
}
|
||||
|
||||
Data FileUtilsAndroid::getData(const std::string& filename, bool forString)
|
||||
{
|
||||
if (filename.empty())
|
||||
{
|
||||
return Data::Null;
|
||||
}
|
||||
|
||||
unsigned char* data = nullptr;
|
||||
ssize_t size = 0;
|
||||
string fullPath = fullPathForFilename(filename);
|
||||
|
||||
if (fullPath[0] != '/')
|
||||
{
|
||||
string relativePath = string();
|
||||
|
||||
size_t position = fullPath.find("assets/");
|
||||
if (0 == position) {
|
||||
// "assets/" is at the beginning of the path and we don't want it
|
||||
relativePath += fullPath.substr(strlen("assets/"));
|
||||
} else {
|
||||
relativePath += fullPath;
|
||||
}
|
||||
LOGD("relative path = %s", relativePath.c_str());
|
||||
|
||||
if (nullptr == FileUtilsAndroid::assetmanager) {
|
||||
LOGD("... FileUtilsAndroid::assetmanager is nullptr");
|
||||
return Data::Null;
|
||||
}
|
||||
|
||||
// read asset data
|
||||
AAsset* asset =
|
||||
AAssetManager_open(FileUtilsAndroid::assetmanager,
|
||||
relativePath.c_str(),
|
||||
AASSET_MODE_UNKNOWN);
|
||||
if (nullptr == asset) {
|
||||
LOGD("asset is nullptr");
|
||||
return Data::Null;
|
||||
}
|
||||
|
||||
off_t fileSize = AAsset_getLength(asset);
|
||||
|
||||
if (forString)
|
||||
{
|
||||
data = (unsigned char*) malloc(fileSize + 1);
|
||||
data[fileSize] = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
data = (unsigned char*) malloc(fileSize);
|
||||
}
|
||||
|
||||
int bytesread = AAsset_read(asset, (void*)data, fileSize);
|
||||
size = bytesread;
|
||||
|
||||
AAsset_close(asset);
|
||||
}
|
||||
else
|
||||
{
|
||||
do
|
||||
{
|
||||
// read rrom other path than user set it
|
||||
//CCLOG("GETTING FILE ABSOLUTE DATA: %s", filename);
|
||||
const char* mode = nullptr;
|
||||
if (forString)
|
||||
mode = "rt";
|
||||
else
|
||||
mode = "rb";
|
||||
|
||||
FILE *fp = fopen(fullPath.c_str(), mode);
|
||||
CC_BREAK_IF(!fp);
|
||||
|
||||
long fileSize;
|
||||
fseek(fp,0,SEEK_END);
|
||||
fileSize = ftell(fp);
|
||||
fseek(fp,0,SEEK_SET);
|
||||
if (forString)
|
||||
{
|
||||
data = (unsigned char*) malloc(fileSize + 1);
|
||||
data[fileSize] = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
data = (unsigned char*) malloc(fileSize);
|
||||
}
|
||||
fileSize = fread(data,sizeof(unsigned char), fileSize,fp);
|
||||
fclose(fp);
|
||||
|
||||
size = fileSize;
|
||||
} while (0);
|
||||
}
|
||||
|
||||
Data ret;
|
||||
if (data == nullptr || size == 0)
|
||||
{
|
||||
std::string msg = "Get data from file(";
|
||||
msg.append(filename).append(") failed!");
|
||||
CCLOG("%s", msg.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
ret.fastSet(data, size);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string FileUtilsAndroid::getStringFromFile(const std::string& filename)
|
||||
{
|
||||
Data data = getData(filename, true);
|
||||
std::string ret((const char*)data.getBytes());
|
||||
return ret;
|
||||
}
|
||||
|
||||
Data FileUtilsAndroid::getDataFromFile(const std::string& filename)
|
||||
{
|
||||
return getData(filename, false);
|
||||
}
|
||||
|
||||
unsigned char* FileUtilsAndroid::getFileData(const char* filename, const char* mode, ssize_t * size)
|
||||
{
|
||||
return doGetFileData(filename, mode, size, false);
|
||||
}
|
||||
|
||||
unsigned char* FileUtilsAndroid::getFileDataForAsync(const char* filename, const char* pszMode, ssize_t * pSize)
|
||||
{
|
||||
return doGetFileData(filename, pszMode, pSize, true);
|
||||
}
|
||||
|
||||
unsigned char* FileUtilsAndroid::doGetFileData(const char* filename, const char* mode, ssize_t * size, bool forAsync)
|
||||
{
|
||||
unsigned char * data = 0;
|
||||
|
||||
if ((! filename) || (! mode) || 0 == strlen(filename))
|
||||
|
@ -164,9 +271,9 @@ unsigned char* FileUtilsAndroid::doGetFileData(const char* filename, const char*
|
|||
}
|
||||
LOGD("relative path = %s", relativePath.c_str());
|
||||
|
||||
if (NULL == FileUtilsAndroid::assetmanager) {
|
||||
LOGD("... FileUtilsAndroid::assetmanager is NULL");
|
||||
return NULL;
|
||||
if (nullptr == FileUtilsAndroid::assetmanager) {
|
||||
LOGD("... FileUtilsAndroid::assetmanager is nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// read asset data
|
||||
|
@ -174,9 +281,9 @@ unsigned char* FileUtilsAndroid::doGetFileData(const char* filename, const char*
|
|||
AAssetManager_open(FileUtilsAndroid::assetmanager,
|
||||
relativePath.c_str(),
|
||||
AASSET_MODE_UNKNOWN);
|
||||
if (NULL == asset) {
|
||||
LOGD("asset is NULL");
|
||||
return NULL;
|
||||
if (nullptr == asset) {
|
||||
LOGD("asset is nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
off_t fileSize = AAsset_getLength(asset);
|
||||
|
@ -196,7 +303,7 @@ unsigned char* FileUtilsAndroid::doGetFileData(const char* filename, const char*
|
|||
do
|
||||
{
|
||||
// read rrom other path than user set it
|
||||
//CCLOG("GETTING FILE ABSOLUTE DATA: %s", filename);
|
||||
//CCLOG("GETTING FILE ABSOLUTE DATA: %s", filename);
|
||||
FILE *fp = fopen(fullPath.c_str(), mode);
|
||||
CC_BREAK_IF(!fp);
|
||||
|
||||
|
|
|
@ -55,19 +55,28 @@ public:
|
|||
|
||||
/* override funtions */
|
||||
bool init();
|
||||
virtual unsigned char* getFileData(const char* filename, const char* mode, ssize_t * size);
|
||||
|
||||
/** @deprecated Please use FileUtils::getDataFromFile or FileUtils::getStringFromFile instead. */
|
||||
CC_DEPRECATED_ATTRIBUTE virtual unsigned char* getFileData(const char* filename, const char* mode, ssize_t * size) override;
|
||||
|
||||
/**
|
||||
* Gets string from a file.
|
||||
*/
|
||||
virtual std::string getStringFromFile(const std::string& filename) override;
|
||||
|
||||
/**
|
||||
* Creates binary data from a file.
|
||||
* @return A data object.
|
||||
*/
|
||||
virtual Data getDataFromFile(const std::string& filename) override;
|
||||
|
||||
virtual std::string getWritablePath() const;
|
||||
virtual bool isFileExist(const std::string& strFilePath) const;
|
||||
virtual bool isAbsolutePath(const std::string& strPath) const;
|
||||
|
||||
/** This function is android specific. It is used for TextureCache::addImageAsync().
|
||||
Don't use it in your codes.
|
||||
*/
|
||||
unsigned char* getFileDataForAsync(const char* filename, const char* mode, ssize_t * size);
|
||||
|
||||
private:
|
||||
unsigned char* doGetFileData(const char* filename, const char* mode, ssize_t * size, bool forAsync);
|
||||
Data getData(const std::string& filename, bool forString);
|
||||
|
||||
static AAssetManager* assetmanager;
|
||||
};
|
||||
|
||||
|
|
|
@ -121,6 +121,77 @@ bool FileUtilsWin32::isAbsolutePath(const std::string& strPath) const
|
|||
return false;
|
||||
}
|
||||
|
||||
static Data getData(const std::string& filename, bool forString)
|
||||
{
|
||||
unsigned char *buffer = nullptr;
|
||||
CCASSERT(!filename.empty(), "Invalid parameters.");
|
||||
size_t size = 0;
|
||||
do
|
||||
{
|
||||
// read the file from hardware
|
||||
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(filename);
|
||||
|
||||
WCHAR wszBuf[CC_MAX_PATH] = {0};
|
||||
MultiByteToWideChar(CP_UTF8, 0, fullPath.c_str(), -1, wszBuf, sizeof(wszBuf));
|
||||
|
||||
HANDLE fileHandle = ::CreateFileW(wszBuf, GENERIC_READ, 0, NULL, OPEN_EXISTING, NULL, NULL);
|
||||
CC_BREAK_IF(fileHandle == INVALID_HANDLE_VALUE);
|
||||
|
||||
size = ::GetFileSize(fileHandle, NULL);
|
||||
|
||||
if (forString)
|
||||
{
|
||||
buffer = (unsigned char*) malloc(size + 1);
|
||||
buffer[size] = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer = (unsigned char*) malloc(size);
|
||||
}
|
||||
DWORD sizeRead = 0;
|
||||
BOOL successed = FALSE;
|
||||
successed = ::ReadFile(fileHandle, buffer, *size, &sizeRead, NULL);
|
||||
::CloseHandle(fileHandle);
|
||||
|
||||
if (!successed)
|
||||
{
|
||||
free(buffer);
|
||||
buffer = nullptr;
|
||||
}
|
||||
} while (0);
|
||||
|
||||
Data ret;
|
||||
|
||||
if (buffer == nullptr || size == 0)
|
||||
{
|
||||
std::string msg = "Get data from file(";
|
||||
// Gets error code.
|
||||
DWORD errorCode = ::GetLastError();
|
||||
char errorCodeBuffer[20] = {0};
|
||||
snprintf(errorCodeBuffer, sizeof(errorCodeBuffer), "%d", errorCode);
|
||||
|
||||
msg = msg + filename + ") failed, error code is " + errorCodeBuffer;
|
||||
CCLOG("%s", msg.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
ret.fastSet(buffer, size);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string FileUtilsAndroid::getStringFromFile(const std::string& filename)
|
||||
{
|
||||
Data data = getData(filename, true);
|
||||
std::string ret((const char*)data.getBytes());
|
||||
return ret;
|
||||
}
|
||||
|
||||
Data FileUtilsAndroid::getDataFromFile(const std::string& filename)
|
||||
{
|
||||
return getData(filename, false);
|
||||
}
|
||||
|
||||
unsigned char* FileUtilsWin32::getFileData(const char* filename, const char* mode, ssize_t* size)
|
||||
{
|
||||
unsigned char * pBuffer = NULL;
|
||||
|
@ -148,6 +219,7 @@ unsigned char* FileUtilsWin32::getFileData(const char* filename, const char* mod
|
|||
if (!successed)
|
||||
{
|
||||
free(pBuffer);
|
||||
pBuffer = nullptr;
|
||||
}
|
||||
} while (0);
|
||||
|
||||
|
|
|
@ -58,7 +58,18 @@ protected:
|
|||
* @return Upon success, a pointer to the data is returned, otherwise NULL.
|
||||
* @warning Recall: you are responsible for calling delete[] on any Non-NULL pointer returned.
|
||||
*/
|
||||
virtual unsigned char* getFileData(const char* filename, const char* mode, ssize_t * size) override;
|
||||
CC_DEPRECATED_ATTRIBUTE virtual unsigned char* getFileData(const char* filename, const char* mode, ssize_t * size) override;
|
||||
|
||||
/**
|
||||
* Gets string from a file.
|
||||
*/
|
||||
virtual std::string getStringFromFile(const std::string& filename) override;
|
||||
|
||||
/**
|
||||
* Creates binary data from a file.
|
||||
* @return A data object.
|
||||
*/
|
||||
virtual Data getDataFromFile(const std::string& filename) override;
|
||||
|
||||
/**
|
||||
* Gets full path for filename, resolution directory and search path.
|
||||
|
@ -81,6 +92,7 @@ protected:
|
|||
* @return The full path of the file, if the file can't be found, it will return an empty string.
|
||||
*/
|
||||
virtual std::string getFullPathForDirectoryAndFilename(const std::string& directory, const std::string& filename) override;
|
||||
|
||||
};
|
||||
|
||||
// end of platform group
|
||||
|
|
|
@ -22,30 +22,67 @@
|
|||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include <string.h>
|
||||
#include "CCData.h"
|
||||
#include "platform/CCCommon.h"
|
||||
#include "ccMacros.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
Data::Data(unsigned char *pBytes, ssize_t nSize)
|
||||
const Data Data::Null;
|
||||
|
||||
Data::Data() :
|
||||
_bytes(nullptr),
|
||||
_size(0)
|
||||
{
|
||||
_size = nSize;
|
||||
_bytes = new unsigned char[_size];
|
||||
memcpy(_bytes, pBytes, _size);
|
||||
CCLOGINFO("In the empty constructor of Data.");
|
||||
}
|
||||
|
||||
Data::Data(Data *pData)
|
||||
Data::Data(Data&& other)
|
||||
{
|
||||
_size = pData->_size;
|
||||
_bytes = new unsigned char[_size];
|
||||
memcpy(_bytes, pData->_bytes, _size);
|
||||
CCLOGINFO("In the move constructor of Data.");
|
||||
move(other);
|
||||
}
|
||||
|
||||
Data::Data(const Data& other)
|
||||
{
|
||||
CCLOGINFO("In the copy constructor of Data.");
|
||||
copy(other._bytes, other._size);
|
||||
}
|
||||
|
||||
Data::~Data()
|
||||
{
|
||||
CCLOGINFO("deallocing Data: %p", this);
|
||||
CC_SAFE_DELETE_ARRAY(_bytes);
|
||||
clear();
|
||||
}
|
||||
|
||||
Data& Data::operator= (const Data& other)
|
||||
{
|
||||
CCLOGINFO("In the copy assignment of Data.");
|
||||
copy(other._bytes, other._size);
|
||||
return *this;
|
||||
}
|
||||
|
||||
Data& Data::operator= (Data&& other)
|
||||
{
|
||||
CCLOGINFO("In the move assignment of Data.");
|
||||
move(other);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void Data::move(Data& other)
|
||||
{
|
||||
_bytes = other._bytes;
|
||||
_size = other._size;
|
||||
|
||||
other._bytes = nullptr;
|
||||
other._size = 0;
|
||||
}
|
||||
|
||||
bool Data::isNull() const
|
||||
{
|
||||
return (_bytes == nullptr || _size == 0);
|
||||
}
|
||||
|
||||
unsigned char* Data::getBytes() const
|
||||
|
@ -58,4 +95,29 @@ ssize_t Data::getSize() const
|
|||
return _size;
|
||||
}
|
||||
|
||||
void Data::copy(unsigned char* bytes, const ssize_t size)
|
||||
{
|
||||
clear();
|
||||
|
||||
if (size > 0)
|
||||
{
|
||||
_size = size;
|
||||
_bytes = (unsigned char*)malloc(sizeof(unsigned char) * _size);
|
||||
memcpy(_bytes, bytes, _size);
|
||||
}
|
||||
}
|
||||
|
||||
void Data::fastSet(unsigned char* bytes, const ssize_t size)
|
||||
{
|
||||
_bytes = bytes;
|
||||
_size = size;
|
||||
}
|
||||
|
||||
void Data::clear()
|
||||
{
|
||||
free(_bytes);
|
||||
_bytes = nullptr;
|
||||
_size = 0;
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
|
|
|
@ -26,41 +26,25 @@
|
|||
#define __CCDATA_H__
|
||||
|
||||
#include "CCPlatformMacros.h"
|
||||
#include "CCObject.h"
|
||||
#include <stdint.h> // for ssize_t on android
|
||||
#include <string> // for ssize_t on linux
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class CC_DLL Data : public Object
|
||||
class CC_DLL Data
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
Data(unsigned char *pBytes, const ssize_t nSize);
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
Data(Data *pData);
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
static const Data Null;
|
||||
|
||||
Data();
|
||||
Data(const Data& other);
|
||||
Data(Data&& other);
|
||||
~Data();
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
static Data* create(unsigned char *pBytes, const ssize_t nSize)
|
||||
{
|
||||
Data* pRet = new Data(pBytes, nSize);
|
||||
if (pRet)
|
||||
{
|
||||
pRet->autorelease();
|
||||
}
|
||||
return pRet;
|
||||
}
|
||||
|
||||
// Assignment operator
|
||||
Data& operator= (const Data& other);
|
||||
Data& operator= (Data&& other);
|
||||
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
|
@ -72,12 +56,31 @@ public:
|
|||
*/
|
||||
ssize_t getSize() const;
|
||||
|
||||
/** override functions
|
||||
* @js NA
|
||||
* @lua NA
|
||||
/** Copies the buffer pointer and its size.
|
||||
* @note This method will copy the whole buffer.
|
||||
* Developer should free the pointer after invoking this method.
|
||||
* @see Data::fastSet
|
||||
*/
|
||||
virtual void acceptVisitor(DataVisitor &visitor) { visitor.visit(this); }
|
||||
|
||||
void copy(unsigned char* bytes, const ssize_t size);
|
||||
|
||||
/** Fast set the buffer pointer and its size. Please use it carefully.
|
||||
* @param bytes The buffer pointer, note that it have to be allocated by 'malloc' or 'calloc',
|
||||
* since in the destructor of Data, the buffer will be deleted by 'free'.
|
||||
* @note 1. This method will move the ownship of 'bytes'pointer to Data,
|
||||
* 2. The pointer should not be used outside after it was passed to this method.
|
||||
* @see Data::copy
|
||||
*/
|
||||
void fastSet(unsigned char* bytes, const ssize_t size);
|
||||
|
||||
/** Clears data, free buffer and reset data size */
|
||||
void clear();
|
||||
|
||||
/** Check whether the data is null. */
|
||||
bool isNull() const;
|
||||
|
||||
private:
|
||||
void move(Data& other);
|
||||
|
||||
private:
|
||||
unsigned char* _bytes;
|
||||
ssize_t _size;
|
||||
|
|
|
@ -31,7 +31,6 @@
|
|||
#include "CCArray.h"
|
||||
#include "CCDictionary.h"
|
||||
#include "CCSet.h"
|
||||
#include "CCData.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -75,11 +74,6 @@ void DataVisitor::visit(const __Set *value)
|
|||
visitObject(value);
|
||||
}
|
||||
|
||||
void DataVisitor::visit(const Data *value)
|
||||
{
|
||||
visitObject(value);
|
||||
}
|
||||
|
||||
// PrettyPrinter
|
||||
PrettyPrinter::PrettyPrinter(int indentLevel/* = 0 */)
|
||||
{
|
||||
|
@ -222,12 +216,6 @@ void PrettyPrinter::visit(const __Set *p)
|
|||
_result += "</set>\n";
|
||||
}
|
||||
|
||||
void PrettyPrinter::visit(const Data *p)
|
||||
{
|
||||
//TODO Implement
|
||||
DataVisitor::visit(p);
|
||||
}
|
||||
|
||||
void PrettyPrinter::setIndentLevel(int indentLevel)
|
||||
{
|
||||
_indentLevel = indentLevel;
|
||||
|
|
|
@ -39,7 +39,6 @@ class __String;
|
|||
class __Array;
|
||||
class __Dictionary;
|
||||
class __Set;
|
||||
class Data;
|
||||
|
||||
/**
|
||||
* @addtogroup data_structures
|
||||
|
@ -80,7 +79,6 @@ public:
|
|||
virtual void visit(const __Array *p);
|
||||
virtual void visit(const __Dictionary *p);
|
||||
virtual void visit(const __Set *p);
|
||||
virtual void visit(const Data *p);
|
||||
};
|
||||
|
||||
|
||||
|
@ -101,7 +99,6 @@ public:
|
|||
virtual void visit(const __Array *p);
|
||||
virtual void visit(const __Dictionary *p);
|
||||
virtual void visit(const __Set *p);
|
||||
virtual void visit(const Data *p);
|
||||
private:
|
||||
void setIndentLevel(int indentLevel);
|
||||
int _indentLevel;
|
||||
|
|
|
@ -205,7 +205,7 @@ public: virtual void set##funName(varType var) \
|
|||
#define CC_BREAK_IF(cond) if(cond) break
|
||||
|
||||
#define __CCLOGWITHFUNCTION(s, ...) \
|
||||
log("%s : %s",__FUNCTION__, String::createWithFormat(s, ##__VA_ARGS__)->getCString())
|
||||
log("%s : %s",__FUNCTION__, StringUtils::format(s, ##__VA_ARGS__).c_str())
|
||||
|
||||
// cocos2d debug
|
||||
#if !defined(COCOS2D_DEBUG) || COCOS2D_DEBUG == 0
|
||||
|
|
|
@ -255,13 +255,8 @@ __String* __String::createWithFormat(const char* format, ...)
|
|||
|
||||
__String* __String::createWithContentsOfFile(const char* filename)
|
||||
{
|
||||
ssize_t size = 0;
|
||||
unsigned char* data = 0;
|
||||
__String* ret = NULL;
|
||||
data = FileUtils::getInstance()->getFileData(filename, "rb", &size);
|
||||
ret = __String::createWithData(data, static_cast<int>(size));
|
||||
free(data);
|
||||
return ret;
|
||||
std::string str = FileUtils::getInstance()->getStringFromFile(filename);
|
||||
return __String::create(std::move(str));
|
||||
}
|
||||
|
||||
void __String::acceptVisitor(DataVisitor &visitor)
|
||||
|
|
|
@ -239,9 +239,6 @@ public:
|
|||
|
||||
};
|
||||
|
||||
|
||||
CC_DEPRECATED_ATTRIBUTE typedef __String String;
|
||||
|
||||
// end of data_structure group
|
||||
/// @}
|
||||
|
||||
|
|
|
@ -110,7 +110,6 @@ CCBReader::CCBReader()
|
|||
CCBReader::~CCBReader()
|
||||
{
|
||||
CC_SAFE_RELEASE_NULL(_owner);
|
||||
CC_SAFE_RELEASE_NULL(_data);
|
||||
|
||||
this->_nodeLoaderLibrary->release();
|
||||
|
||||
|
@ -218,23 +217,17 @@ Node* CCBReader::readNodeGraphFromFile(const char *pCCBFileName, Object *pOwner,
|
|||
}
|
||||
|
||||
std::string strPath = FileUtils::getInstance()->fullPathForFilename(strCCBFileName.c_str());
|
||||
ssize_t size = 0;
|
||||
|
||||
unsigned char * pBytes = FileUtils::getInstance()->getFileData(strPath.c_str(), "rb", &size);
|
||||
Data *data = new Data(pBytes, size);
|
||||
free(pBytes);
|
||||
|
||||
Node *ret = this->readNodeGraphFromData(data, pOwner, parentSize);
|
||||
auto dataPtr = std::make_shared<Data>(FileUtils::getInstance()->getDataFromFile(strPath));
|
||||
|
||||
data->release();
|
||||
Node *ret = this->readNodeGraphFromData(dataPtr, pOwner, parentSize);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
Node* CCBReader::readNodeGraphFromData(Data *pData, Object *pOwner, const Size &parentSize)
|
||||
Node* CCBReader::readNodeGraphFromData(std::shared_ptr<cocos2d::Data> data, Object *pOwner, const Size &parentSize)
|
||||
{
|
||||
_data = pData;
|
||||
CC_SAFE_RETAIN(_data);
|
||||
_data = data;
|
||||
_bytes =_data->getBytes();
|
||||
_currentByte = 0;
|
||||
_currentBit = 0;
|
||||
|
|
|
@ -173,7 +173,7 @@ public:
|
|||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
cocos2d::Node* readNodeGraphFromData(cocos2d::Data *pData, cocos2d::Object *pOwner, const cocos2d::Size &parentSize);
|
||||
cocos2d::Node* readNodeGraphFromData(std::shared_ptr<cocos2d::Data> data, cocos2d::Object *pOwner, const cocos2d::Size &parentSize);
|
||||
|
||||
/**
|
||||
@lua NA
|
||||
|
@ -360,7 +360,7 @@ private:
|
|||
friend class NodeLoader;
|
||||
|
||||
private:
|
||||
cocos2d::Data *_data;
|
||||
std::shared_ptr<cocos2d::Data> _data;
|
||||
unsigned char *_bytes;
|
||||
int _currentByte;
|
||||
int _currentBit;
|
||||
|
|
|
@ -923,19 +923,16 @@ Node * NodeLoader::parsePropTypeCCBFile(Node * pNode, Node * pParent, CCBReader
|
|||
|
||||
// Load sub file
|
||||
std::string path = FileUtils::getInstance()->fullPathForFilename(ccbFileName.c_str());
|
||||
ssize_t size = 0;
|
||||
unsigned char * pBytes = FileUtils::getInstance()->getFileData(path.c_str(), "rb", &size);
|
||||
|
||||
auto dataPtr = std::make_shared<Data>(FileUtils::getInstance()->getDataFromFile(path));
|
||||
|
||||
CCBReader * reader = new CCBReader(pCCBReader);
|
||||
reader->autorelease();
|
||||
reader->getAnimationManager()->setRootContainerSize(pParent->getContentSize());
|
||||
|
||||
Data *data = new Data(pBytes, size);
|
||||
free(pBytes);
|
||||
|
||||
data->retain();
|
||||
reader->_data = data;
|
||||
reader->_bytes = data->getBytes();
|
||||
|
||||
reader->_data = dataPtr;
|
||||
reader->_bytes = dataPtr->getBytes();
|
||||
reader->_currentByte = 0;
|
||||
reader->_currentBit = 0;
|
||||
CC_SAFE_RETAIN(pCCBReader->_owner);
|
||||
|
@ -951,7 +948,6 @@ Node * NodeLoader::parsePropTypeCCBFile(Node * pNode, Node * pParent, CCBReader
|
|||
// reader->_ownerCallbackNodes = pCCBReader->_ownerCallbackNodes;
|
||||
// reader->_ownerCallbackNodes->retain();
|
||||
|
||||
data->release();
|
||||
|
||||
Node * ccbFileNode = reader->readFileWithCleanUp(false, pCCBReader->getAnimationManagers());
|
||||
|
||||
|
|
|
@ -288,11 +288,8 @@ void DataReaderHelper::addDataFromFile(const std::string& filePath)
|
|||
std::string str = &filePathStr[startPos];
|
||||
|
||||
// Read content from file
|
||||
ssize_t size;
|
||||
std::string fullPath = CCFileUtils::getInstance()->fullPathForFilename(filePath);
|
||||
unsigned char *pTempContent = (unsigned char *)CCFileUtils::getInstance()->getFileData(fullPath.c_str() , "r", &size);
|
||||
|
||||
std::string contentStr = std::string((const char*)pTempContent, size);
|
||||
std::string contentStr = FileUtils::getInstance()->getStringFromFile(fullPath);
|
||||
|
||||
DataInfo dataInfo;
|
||||
dataInfo.filename = filePathStr;
|
||||
|
@ -307,8 +304,6 @@ void DataReaderHelper::addDataFromFile(const std::string& filePath)
|
|||
{
|
||||
DataReaderHelper::addDataFromJsonCache(contentStr, &dataInfo);
|
||||
}
|
||||
|
||||
free(pTempContent);
|
||||
}
|
||||
|
||||
void DataReaderHelper::addDataFromFileAsync(const std::string& imagePath, const std::string& plistPath, const std::string& filePath, Object *target, SEL_SCHEDULE selector)
|
||||
|
@ -391,10 +386,9 @@ void DataReaderHelper::addDataFromFileAsync(const std::string& imagePath, const
|
|||
std::string str = &filePathStr[startPos];
|
||||
|
||||
std::string fullPath = CCFileUtils::getInstance()->fullPathForFilename(filePath);
|
||||
ssize_t size;
|
||||
|
||||
// XXX fileContent is being leaked
|
||||
data->fileContent = (char *)CCFileUtils::getInstance()->getFileData(fullPath.c_str() , "r", &size);
|
||||
data->fileContent = FileUtils::getInstance()->getStringFromFile(fullPath);
|
||||
|
||||
if (str == ".xml")
|
||||
{
|
||||
|
|
|
@ -122,22 +122,22 @@ const cocos2d::Size GUIReader::getFileDesignSize(const char* fileName) const
|
|||
UIWidget* GUIReader::widgetFromJsonFile(const char *fileName)
|
||||
{
|
||||
DictionaryHelper* dicHelper = DICTOOL;
|
||||
char *des = nullptr;
|
||||
|
||||
std::string jsonpath;
|
||||
JsonDictionary *jsonDict = nullptr;
|
||||
jsonpath = CCFileUtils::getInstance()->fullPathForFilename(fileName);
|
||||
int pos = jsonpath.find_last_of('/');
|
||||
m_strFilePath = jsonpath.substr(0,pos+1);
|
||||
ssize_t size = 0;
|
||||
des = (char*)(CCFileUtils::getInstance()->getFileData(jsonpath.c_str(),"r" , &size));
|
||||
if(nullptr == des || strcmp(des, "") == 0)
|
||||
|
||||
std::string des = FileUtils::getInstance()->getStringFromFile(jsonpath);
|
||||
if (des.empty())
|
||||
{
|
||||
printf("read json file[%s] error!\n", fileName);
|
||||
CCLOG("read json file[%s] error!\n", fileName);
|
||||
return nullptr;
|
||||
}
|
||||
std::string strDes(des);
|
||||
|
||||
jsonDict = new JsonDictionary();
|
||||
jsonDict->initWithDescription(strDes.c_str());
|
||||
jsonDict->initWithDescription(des.c_str());
|
||||
|
||||
UIWidget* widget = nullptr;
|
||||
const char* fileVersion = dicHelper->getStringValue_json(jsonDict, "version");
|
||||
|
@ -164,7 +164,6 @@ UIWidget* GUIReader::widgetFromJsonFile(const char *fileName)
|
|||
|
||||
CC_SAFE_DELETE(pReader);
|
||||
CC_SAFE_DELETE(jsonDict);
|
||||
free(des);
|
||||
return widget;
|
||||
}
|
||||
|
||||
|
|
|
@ -47,19 +47,16 @@ namespace cocostudio {
|
|||
|
||||
cocos2d::Node* SceneReader::createNodeWithSceneFile(const char* pszFileName)
|
||||
{
|
||||
ssize_t size = 0;
|
||||
char* pData = 0;
|
||||
cocos2d::Node *pNode = nullptr;
|
||||
do
|
||||
{
|
||||
CC_BREAK_IF(pszFileName == nullptr);
|
||||
pData = (char*)(cocos2d::FileUtils::getInstance()->getFileData(pszFileName, "r", &size));
|
||||
CC_BREAK_IF(pData == nullptr || strcmp(pData, "") == 0);
|
||||
std::string fileContent = cocos2d::FileUtils::getInstance()->getStringFromFile(pszFileName);
|
||||
CC_BREAK_IF(fileContent.empty());
|
||||
JsonDictionary *jsonDict = new JsonDictionary();
|
||||
jsonDict->initWithDescription(pData);
|
||||
jsonDict->initWithDescription(fileContent.c_str());
|
||||
pNode = createObject(jsonDict,nullptr);
|
||||
CC_SAFE_DELETE(jsonDict);
|
||||
free(pData);
|
||||
} while (0);
|
||||
|
||||
return pNode;
|
||||
|
@ -215,11 +212,12 @@ namespace cocostudio {
|
|||
{
|
||||
file_path = reDir.substr(0, pos+1);
|
||||
}
|
||||
ssize_t size = 0;
|
||||
char *des = (char*)(cocos2d::FileUtils::getInstance()->getFileData(pPath.c_str(),"r" , &size));
|
||||
|
||||
std::string des = cocos2d::FileUtils::getInstance()->getStringFromFile(pPath);
|
||||
|
||||
JsonDictionary *jsonDict = new JsonDictionary();
|
||||
jsonDict->initWithDescription(des);
|
||||
if(nullptr == des || strcmp(des, "") == 0)
|
||||
jsonDict->initWithDescription(des.c_str());
|
||||
if (des.empty())
|
||||
{
|
||||
CCLOG("read json file[%s] error!\n", pPath.c_str());
|
||||
}
|
||||
|
@ -263,7 +261,6 @@ namespace cocostudio {
|
|||
|
||||
CC_SAFE_DELETE(jsonDict);
|
||||
CC_SAFE_DELETE(subData);
|
||||
free(des);
|
||||
}
|
||||
else if(comName != nullptr && strcmp(comName, "CCComAudio") == 0)
|
||||
{
|
||||
|
@ -285,14 +282,11 @@ namespace cocostudio {
|
|||
if (nResType == 0)
|
||||
{
|
||||
pAttribute = ComAttribute::create();
|
||||
ssize_t size = 0;
|
||||
char* pData = 0;
|
||||
pData = (char*)(cocos2d::FileUtils::getInstance()->getFileData(pPath.c_str(), "r", &size));
|
||||
if(pData != nullptr && strcmp(pData, "") != 0)
|
||||
std::string fileContent = cocos2d::FileUtils::getInstance()->getStringFromFile(pPath);
|
||||
if (!fileContent.empty())
|
||||
{
|
||||
pAttribute->getDict()->initWithDescription(pData);
|
||||
pAttribute->getDict()->initWithDescription(fileContent.c_str());
|
||||
}
|
||||
free(pData);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -40,25 +40,25 @@ using std::max;
|
|||
|
||||
namespace spine {
|
||||
|
||||
CCSkeleton* CCSkeleton::createWithData (spSkeletonData* skeletonData, bool isOwnsSkeletonData) {
|
||||
CCSkeleton* node = new CCSkeleton(skeletonData, isOwnsSkeletonData);
|
||||
Skeleton* Skeleton::createWithData (spSkeletonData* skeletonData, bool isOwnsSkeletonData) {
|
||||
Skeleton* node = new Skeleton(skeletonData, isOwnsSkeletonData);
|
||||
node->autorelease();
|
||||
return node;
|
||||
}
|
||||
|
||||
CCSkeleton* CCSkeleton::createWithFile (const char* skeletonDataFile, spAtlas* atlas, float scale) {
|
||||
CCSkeleton* node = new CCSkeleton(skeletonDataFile, atlas, scale);
|
||||
Skeleton* Skeleton::createWithFile (const char* skeletonDataFile, spAtlas* atlas, float scale) {
|
||||
Skeleton* node = new Skeleton(skeletonDataFile, atlas, scale);
|
||||
node->autorelease();
|
||||
return node;
|
||||
}
|
||||
|
||||
CCSkeleton* CCSkeleton::createWithFile (const char* skeletonDataFile, const char* atlasFile, float scale) {
|
||||
CCSkeleton* node = new CCSkeleton(skeletonDataFile, atlasFile, scale);
|
||||
Skeleton* Skeleton::createWithFile (const char* skeletonDataFile, const char* atlasFile, float scale) {
|
||||
Skeleton* node = new Skeleton(skeletonDataFile, atlasFile, scale);
|
||||
node->autorelease();
|
||||
return node;
|
||||
}
|
||||
|
||||
void CCSkeleton::initialize () {
|
||||
void Skeleton::initialize () {
|
||||
atlas = 0;
|
||||
debugSlots = false;
|
||||
debugBones = false;
|
||||
|
@ -73,23 +73,23 @@ void CCSkeleton::initialize () {
|
|||
scheduleUpdate();
|
||||
}
|
||||
|
||||
void CCSkeleton::setSkeletonData (spSkeletonData *skeletonData, bool isOwnsSkeletonData) {
|
||||
void Skeleton::setSkeletonData (spSkeletonData *skeletonData, bool isOwnsSkeletonData) {
|
||||
skeleton = spSkeleton_create(skeletonData);
|
||||
rootBone = skeleton->bones[0];
|
||||
this->ownsSkeletonData = isOwnsSkeletonData;
|
||||
}
|
||||
|
||||
CCSkeleton::CCSkeleton () {
|
||||
Skeleton::Skeleton () {
|
||||
initialize();
|
||||
}
|
||||
|
||||
CCSkeleton::CCSkeleton (spSkeletonData *skeletonData, bool isOwnsSkeletonData) {
|
||||
Skeleton::Skeleton (spSkeletonData *skeletonData, bool isOwnsSkeletonData) {
|
||||
initialize();
|
||||
|
||||
setSkeletonData(skeletonData, isOwnsSkeletonData);
|
||||
}
|
||||
|
||||
CCSkeleton::CCSkeleton (const char* skeletonDataFile, spAtlas* aAtlas, float scale) {
|
||||
Skeleton::Skeleton (const char* skeletonDataFile, spAtlas* aAtlas, float scale) {
|
||||
initialize();
|
||||
|
||||
spSkeletonJson* json = spSkeletonJson_create(aAtlas);
|
||||
|
@ -101,7 +101,7 @@ CCSkeleton::CCSkeleton (const char* skeletonDataFile, spAtlas* aAtlas, float sca
|
|||
setSkeletonData(skeletonData, true);
|
||||
}
|
||||
|
||||
CCSkeleton::CCSkeleton (const char* skeletonDataFile, const char* atlasFile, float scale) {
|
||||
Skeleton::Skeleton (const char* skeletonDataFile, const char* atlasFile, float scale) {
|
||||
initialize();
|
||||
|
||||
atlas = spAtlas_readAtlasFile(atlasFile);
|
||||
|
@ -116,17 +116,17 @@ CCSkeleton::CCSkeleton (const char* skeletonDataFile, const char* atlasFile, flo
|
|||
setSkeletonData(skeletonData, true);
|
||||
}
|
||||
|
||||
CCSkeleton::~CCSkeleton () {
|
||||
Skeleton::~Skeleton () {
|
||||
if (ownsSkeletonData) spSkeletonData_dispose(skeleton->data);
|
||||
if (atlas) spAtlas_dispose(atlas);
|
||||
spSkeleton_dispose(skeleton);
|
||||
}
|
||||
|
||||
void CCSkeleton::update (float deltaTime) {
|
||||
void Skeleton::update (float deltaTime) {
|
||||
spSkeleton_update(skeleton, deltaTime * timeScale);
|
||||
}
|
||||
|
||||
void CCSkeleton::draw () {
|
||||
void Skeleton::draw () {
|
||||
CC_NODE_DRAW_SETUP();
|
||||
|
||||
GL::blendFunc(blendFunc.src, blendFunc.dst);
|
||||
|
@ -222,11 +222,11 @@ void CCSkeleton::draw () {
|
|||
}
|
||||
}
|
||||
|
||||
TextureAtlas* CCSkeleton::getTextureAtlas (spRegionAttachment* regionAttachment) const {
|
||||
TextureAtlas* Skeleton::getTextureAtlas (spRegionAttachment* regionAttachment) const {
|
||||
return (TextureAtlas*)((spAtlasRegion*)regionAttachment->rendererObject)->page->rendererObject;
|
||||
}
|
||||
|
||||
Rect CCSkeleton::getBoundingBox () const {
|
||||
Rect Skeleton::getBoundingBox () const {
|
||||
float minX = FLT_MAX, minY = FLT_MAX, maxX = FLT_MIN, maxY = FLT_MIN;
|
||||
float scaleX = getScaleX();
|
||||
float scaleY = getScaleY();
|
||||
|
@ -259,50 +259,50 @@ Rect CCSkeleton::getBoundingBox () const {
|
|||
|
||||
// --- Convenience methods for Skeleton_* functions.
|
||||
|
||||
void CCSkeleton::updateWorldTransform () {
|
||||
void Skeleton::updateWorldTransform () {
|
||||
spSkeleton_updateWorldTransform(skeleton);
|
||||
}
|
||||
|
||||
void CCSkeleton::setToSetupPose () {
|
||||
void Skeleton::setToSetupPose () {
|
||||
spSkeleton_setToSetupPose(skeleton);
|
||||
}
|
||||
void CCSkeleton::setBonesToSetupPose () {
|
||||
void Skeleton::setBonesToSetupPose () {
|
||||
spSkeleton_setBonesToSetupPose(skeleton);
|
||||
}
|
||||
void CCSkeleton::setSlotsToSetupPose () {
|
||||
void Skeleton::setSlotsToSetupPose () {
|
||||
spSkeleton_setSlotsToSetupPose(skeleton);
|
||||
}
|
||||
|
||||
spBone* CCSkeleton::findBone (const char* boneName) const {
|
||||
spBone* Skeleton::findBone (const char* boneName) const {
|
||||
return spSkeleton_findBone(skeleton, boneName);
|
||||
}
|
||||
|
||||
spSlot* CCSkeleton::findSlot (const char* slotName) const {
|
||||
spSlot* Skeleton::findSlot (const char* slotName) const {
|
||||
return spSkeleton_findSlot(skeleton, slotName);
|
||||
}
|
||||
|
||||
bool CCSkeleton::setSkin (const char* skinName) {
|
||||
bool Skeleton::setSkin (const char* skinName) {
|
||||
return spSkeleton_setSkinByName(skeleton, skinName) ? true : false;
|
||||
}
|
||||
|
||||
spAttachment* CCSkeleton::getAttachment (const char* slotName, const char* attachmentName) const {
|
||||
spAttachment* Skeleton::getAttachment (const char* slotName, const char* attachmentName) const {
|
||||
return spSkeleton_getAttachmentForSlotName(skeleton, slotName, attachmentName);
|
||||
}
|
||||
bool CCSkeleton::setAttachment (const char* slotName, const char* attachmentName) {
|
||||
bool Skeleton::setAttachment (const char* slotName, const char* attachmentName) {
|
||||
return spSkeleton_setAttachment(skeleton, slotName, attachmentName) ? true : false;
|
||||
}
|
||||
|
||||
// --- CCBlendProtocol
|
||||
|
||||
const cocos2d::BlendFunc& CCSkeleton::getBlendFunc () const {
|
||||
const cocos2d::BlendFunc& Skeleton::getBlendFunc () const {
|
||||
return blendFunc;
|
||||
}
|
||||
|
||||
void CCSkeleton::setBlendFunc (const cocos2d::BlendFunc& aBlendFunc) {
|
||||
void Skeleton::setBlendFunc (const cocos2d::BlendFunc& aBlendFunc) {
|
||||
this->blendFunc = aBlendFunc;
|
||||
}
|
||||
|
||||
void CCSkeleton::setFittedBlendingFunc(cocos2d::TextureAtlas * nextRenderedTexture)
|
||||
void Skeleton::setFittedBlendingFunc(cocos2d::TextureAtlas * nextRenderedTexture)
|
||||
{
|
||||
if(nextRenderedTexture->getTexture() && nextRenderedTexture->getTexture()->hasPremultipliedAlpha())
|
||||
{
|
||||
|
|
|
@ -42,7 +42,7 @@ namespace spine {
|
|||
/**
|
||||
Draws a skeleton.
|
||||
*/
|
||||
class CCSkeleton: public cocos2d::Node, public cocos2d::BlendProtocol {
|
||||
class Skeleton: public cocos2d::Node, public cocos2d::BlendProtocol {
|
||||
public:
|
||||
spSkeleton* skeleton;
|
||||
spBone* rootBone;
|
||||
|
@ -52,15 +52,15 @@ public:
|
|||
bool premultipliedAlpha;
|
||||
cocos2d::BlendFunc blendFunc;
|
||||
|
||||
static CCSkeleton* createWithData (spSkeletonData* skeletonData, bool ownsSkeletonData = false);
|
||||
static CCSkeleton* createWithFile (const char* skeletonDataFile, spAtlas* atlas, float scale = 0);
|
||||
static CCSkeleton* createWithFile (const char* skeletonDataFile, const char* atlasFile, float scale = 0);
|
||||
static Skeleton* createWithData (spSkeletonData* skeletonData, bool ownsSkeletonData = false);
|
||||
static Skeleton* createWithFile (const char* skeletonDataFile, spAtlas* atlas, float scale = 0);
|
||||
static Skeleton* createWithFile (const char* skeletonDataFile, const char* atlasFile, float scale = 0);
|
||||
|
||||
CCSkeleton (spSkeletonData* skeletonData, bool ownsSkeletonData = false);
|
||||
CCSkeleton (const char* skeletonDataFile, spAtlas* atlas, float scale = 0);
|
||||
CCSkeleton (const char* skeletonDataFile, const char* atlasFile, float scale = 0);
|
||||
Skeleton (spSkeletonData* skeletonData, bool ownsSkeletonData = false);
|
||||
Skeleton (const char* skeletonDataFile, spAtlas* atlas, float scale = 0);
|
||||
Skeleton (const char* skeletonDataFile, const char* atlasFile, float scale = 0);
|
||||
|
||||
virtual ~CCSkeleton ();
|
||||
virtual ~Skeleton ();
|
||||
|
||||
virtual void update (float deltaTime) override;
|
||||
virtual void draw() override;
|
||||
|
@ -93,7 +93,7 @@ public:
|
|||
virtual void setBlendFunc(const cocos2d::BlendFunc& func) override;
|
||||
|
||||
protected:
|
||||
CCSkeleton ();
|
||||
Skeleton ();
|
||||
void setSkeletonData (spSkeletonData* skeletonData, bool ownsSkeletonData);
|
||||
virtual cocos2d::TextureAtlas* getTextureAtlas (spRegionAttachment* regionAttachment) const;
|
||||
|
||||
|
|
|
@ -43,28 +43,28 @@ using std::vector;
|
|||
namespace spine {
|
||||
|
||||
static void callback (spAnimationState* state, int trackIndex, spEventType type, spEvent* event, int loopCount) {
|
||||
((CCSkeletonAnimation*)state->context)->onAnimationStateEvent(trackIndex, type, event, loopCount);
|
||||
((SkeletonAnimation*)state->context)->onAnimationStateEvent(trackIndex, type, event, loopCount);
|
||||
}
|
||||
|
||||
CCSkeletonAnimation* CCSkeletonAnimation::createWithData (spSkeletonData* skeletonData) {
|
||||
CCSkeletonAnimation* node = new CCSkeletonAnimation(skeletonData);
|
||||
SkeletonAnimation* SkeletonAnimation::createWithData (spSkeletonData* skeletonData) {
|
||||
SkeletonAnimation* node = new SkeletonAnimation(skeletonData);
|
||||
node->autorelease();
|
||||
return node;
|
||||
}
|
||||
|
||||
CCSkeletonAnimation* CCSkeletonAnimation::createWithFile (const char* skeletonDataFile, spAtlas* atlas, float scale) {
|
||||
CCSkeletonAnimation* node = new CCSkeletonAnimation(skeletonDataFile, atlas, scale);
|
||||
SkeletonAnimation* SkeletonAnimation::createWithFile (const char* skeletonDataFile, spAtlas* atlas, float scale) {
|
||||
SkeletonAnimation* node = new SkeletonAnimation(skeletonDataFile, atlas, scale);
|
||||
node->autorelease();
|
||||
return node;
|
||||
}
|
||||
|
||||
CCSkeletonAnimation* CCSkeletonAnimation::createWithFile (const char* skeletonDataFile, const char* atlasFile, float scale) {
|
||||
CCSkeletonAnimation* node = new CCSkeletonAnimation(skeletonDataFile, atlasFile, scale);
|
||||
SkeletonAnimation* SkeletonAnimation::createWithFile (const char* skeletonDataFile, const char* atlasFile, float scale) {
|
||||
SkeletonAnimation* node = new SkeletonAnimation(skeletonDataFile, atlasFile, scale);
|
||||
node->autorelease();
|
||||
return node;
|
||||
}
|
||||
|
||||
void CCSkeletonAnimation::initialize () {
|
||||
void SkeletonAnimation::initialize () {
|
||||
listenerInstance = 0;
|
||||
listenerMethod = 0;
|
||||
|
||||
|
@ -74,27 +74,27 @@ void CCSkeletonAnimation::initialize () {
|
|||
state->listener = callback;
|
||||
}
|
||||
|
||||
CCSkeletonAnimation::CCSkeletonAnimation (spSkeletonData *skeletonData)
|
||||
: CCSkeleton(skeletonData) {
|
||||
SkeletonAnimation::SkeletonAnimation (spSkeletonData *skeletonData)
|
||||
: Skeleton(skeletonData) {
|
||||
initialize();
|
||||
}
|
||||
|
||||
CCSkeletonAnimation::CCSkeletonAnimation (const char* skeletonDataFile, spAtlas* atlas, float scale)
|
||||
: CCSkeleton(skeletonDataFile, atlas, scale) {
|
||||
SkeletonAnimation::SkeletonAnimation (const char* skeletonDataFile, spAtlas* atlas, float scale)
|
||||
: Skeleton(skeletonDataFile, atlas, scale) {
|
||||
initialize();
|
||||
}
|
||||
|
||||
CCSkeletonAnimation::CCSkeletonAnimation (const char* skeletonDataFile, const char* atlasFile, float scale)
|
||||
: CCSkeleton(skeletonDataFile, atlasFile, scale) {
|
||||
SkeletonAnimation::SkeletonAnimation (const char* skeletonDataFile, const char* atlasFile, float scale)
|
||||
: Skeleton(skeletonDataFile, atlasFile, scale) {
|
||||
initialize();
|
||||
}
|
||||
|
||||
CCSkeletonAnimation::~CCSkeletonAnimation () {
|
||||
SkeletonAnimation::~SkeletonAnimation () {
|
||||
if (ownsAnimationStateData) spAnimationStateData_dispose(state->data);
|
||||
spAnimationState_dispose(state);
|
||||
}
|
||||
|
||||
void CCSkeletonAnimation::update (float deltaTime) {
|
||||
void SkeletonAnimation::update (float deltaTime) {
|
||||
super::update(deltaTime);
|
||||
|
||||
deltaTime *= timeScale;
|
||||
|
@ -103,7 +103,7 @@ void CCSkeletonAnimation::update (float deltaTime) {
|
|||
spSkeleton_updateWorldTransform(skeleton);
|
||||
}
|
||||
|
||||
void CCSkeletonAnimation::setAnimationStateData (spAnimationStateData* stateData) {
|
||||
void SkeletonAnimation::setAnimationStateData (spAnimationStateData* stateData) {
|
||||
CCAssert(stateData, "stateData cannot be null.");
|
||||
|
||||
if (ownsAnimationStateData) spAnimationStateData_dispose(state->data);
|
||||
|
@ -115,46 +115,46 @@ void CCSkeletonAnimation::setAnimationStateData (spAnimationStateData* stateData
|
|||
state->listener = callback;
|
||||
}
|
||||
|
||||
void CCSkeletonAnimation::setMix (const char* fromAnimation, const char* toAnimation, float duration) {
|
||||
void SkeletonAnimation::setMix (const char* fromAnimation, const char* toAnimation, float duration) {
|
||||
spAnimationStateData_setMixByName(state->data, fromAnimation, toAnimation, duration);
|
||||
}
|
||||
|
||||
void CCSkeletonAnimation::setAnimationListener (Object* instance, SEL_AnimationStateEvent method) {
|
||||
void SkeletonAnimation::setAnimationListener (Object* instance, SEL_AnimationStateEvent method) {
|
||||
listenerInstance = instance;
|
||||
listenerMethod = method;
|
||||
}
|
||||
|
||||
spTrackEntry* CCSkeletonAnimation::setAnimation (int trackIndex, const char* name, bool loop) {
|
||||
spTrackEntry* SkeletonAnimation::setAnimation (int trackIndex, const char* name, bool loop) {
|
||||
spAnimation* animation = spSkeletonData_findAnimation(skeleton->data, name);
|
||||
if (!animation) {
|
||||
CCLog("Spine: Animation not found: %s", name);
|
||||
log("Spine: Animation not found: %s", name);
|
||||
return 0;
|
||||
}
|
||||
return spAnimationState_setAnimation(state, trackIndex, animation, loop);
|
||||
}
|
||||
|
||||
spTrackEntry* CCSkeletonAnimation::addAnimation (int trackIndex, const char* name, bool loop, float delay) {
|
||||
spTrackEntry* SkeletonAnimation::addAnimation (int trackIndex, const char* name, bool loop, float delay) {
|
||||
spAnimation* animation = spSkeletonData_findAnimation(skeleton->data, name);
|
||||
if (!animation) {
|
||||
CCLog("Spine: Animation not found: %s", name);
|
||||
log("Spine: Animation not found: %s", name);
|
||||
return 0;
|
||||
}
|
||||
return spAnimationState_addAnimation(state, trackIndex, animation, loop, delay);
|
||||
}
|
||||
|
||||
spTrackEntry* CCSkeletonAnimation::getCurrent (int trackIndex) {
|
||||
spTrackEntry* SkeletonAnimation::getCurrent (int trackIndex) {
|
||||
return spAnimationState_getCurrent(state, trackIndex);
|
||||
}
|
||||
|
||||
void CCSkeletonAnimation::clearTracks () {
|
||||
void SkeletonAnimation::clearTracks () {
|
||||
spAnimationState_clearTracks(state);
|
||||
}
|
||||
|
||||
void CCSkeletonAnimation::clearTrack (int trackIndex) {
|
||||
void SkeletonAnimation::clearTrack (int trackIndex) {
|
||||
spAnimationState_clearTrack(state, trackIndex);
|
||||
}
|
||||
|
||||
void CCSkeletonAnimation::onAnimationStateEvent (int trackIndex, spEventType type, spEvent* event, int loopCount) {
|
||||
void SkeletonAnimation::onAnimationStateEvent (int trackIndex, spEventType type, spEvent* event, int loopCount) {
|
||||
if (listenerInstance) (listenerInstance->*listenerMethod)(this, trackIndex, type, event, loopCount);
|
||||
}
|
||||
|
||||
|
|
|
@ -40,25 +40,25 @@
|
|||
|
||||
namespace spine {
|
||||
|
||||
class CCSkeletonAnimation;
|
||||
typedef void (cocos2d::Object::*SEL_AnimationStateEvent)(spine::CCSkeletonAnimation* node, int trackIndex, spEventType type, spEvent* event, int loopCount);
|
||||
class SkeletonAnimation;
|
||||
typedef void (cocos2d::Object::*SEL_AnimationStateEvent)(spine::SkeletonAnimation* node, int trackIndex, spEventType type, spEvent* event, int loopCount);
|
||||
#define animationStateEvent_selector(_SELECTOR) (SEL_AnimationStateEvent)(&_SELECTOR)
|
||||
|
||||
/** Draws an animated skeleton, providing an AnimationState for applying one or more animations and queuing animations to be
|
||||
* played later. */
|
||||
class CCSkeletonAnimation: public CCSkeleton {
|
||||
class SkeletonAnimation: public Skeleton {
|
||||
public:
|
||||
spAnimationState* state;
|
||||
|
||||
static CCSkeletonAnimation* createWithData (spSkeletonData* skeletonData);
|
||||
static CCSkeletonAnimation* createWithFile (const char* skeletonDataFile, spAtlas* atlas, float scale = 0);
|
||||
static CCSkeletonAnimation* createWithFile (const char* skeletonDataFile, const char* atlasFile, float scale = 0);
|
||||
static SkeletonAnimation* createWithData (spSkeletonData* skeletonData);
|
||||
static SkeletonAnimation* createWithFile (const char* skeletonDataFile, spAtlas* atlas, float scale = 0);
|
||||
static SkeletonAnimation* createWithFile (const char* skeletonDataFile, const char* atlasFile, float scale = 0);
|
||||
|
||||
CCSkeletonAnimation (spSkeletonData* skeletonData);
|
||||
CCSkeletonAnimation (const char* skeletonDataFile, spAtlas* atlas, float scale = 0);
|
||||
CCSkeletonAnimation (const char* skeletonDataFile, const char* atlasFile, float scale = 0);
|
||||
SkeletonAnimation (spSkeletonData* skeletonData);
|
||||
SkeletonAnimation (const char* skeletonDataFile, spAtlas* atlas, float scale = 0);
|
||||
SkeletonAnimation (const char* skeletonDataFile, const char* atlasFile, float scale = 0);
|
||||
|
||||
virtual ~CCSkeletonAnimation ();
|
||||
virtual ~SkeletonAnimation ();
|
||||
|
||||
virtual void update (float deltaTime);
|
||||
|
||||
|
@ -75,10 +75,10 @@ public:
|
|||
virtual void onAnimationStateEvent (int trackIndex, spEventType type, spEvent* event, int loopCount);
|
||||
|
||||
protected:
|
||||
CCSkeletonAnimation ();
|
||||
SkeletonAnimation ();
|
||||
|
||||
private:
|
||||
typedef CCSkeleton super;
|
||||
typedef Skeleton super;
|
||||
cocos2d::Object* listenerInstance;
|
||||
SEL_AnimationStateEvent listenerMethod;
|
||||
bool ownsAnimationStateData;
|
||||
|
|
|
@ -52,12 +52,24 @@ void _spAtlasPage_disposeTexture (spAtlasPage* self) {
|
|||
((TextureAtlas*)self->rendererObject)->release();
|
||||
}
|
||||
|
||||
char* _spUtil_readFile (const char* path, int* length) {
|
||||
ssize_t size;
|
||||
char* data = reinterpret_cast<char*>(
|
||||
FileUtils::getInstance()->getFileData( FileUtils::getInstance()->fullPathForFilename(path).c_str(), "rb", &size));
|
||||
*length = static_cast<int>(size);
|
||||
return data;}
|
||||
char* _spUtil_readFile (const char* path, int* length)
|
||||
{
|
||||
char* ret = nullptr;
|
||||
int size = 0;
|
||||
Data data = FileUtils::getInstance()->getDataFromFile(path);
|
||||
|
||||
if (!data.isNull())
|
||||
{
|
||||
size = static_cast<int>(data.getSize());
|
||||
*length = size;
|
||||
// Allocates one more byte for string terminal, it will be safe when parsing JSON file in Spine runtime.
|
||||
ret = (char*)malloc(size + 1);
|
||||
ret[size] = '\0';
|
||||
memcpy(ret, data.getBytes(), size);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**/
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit daff147b1ff3d3754cb014c4e9c575676dea68b9
|
||||
Subproject commit 4b31f207c6743c246fc2116699ab2c995db18cf3
|
|
@ -533,18 +533,17 @@ JSBool ScriptingCore::runScript(const char *path, JSObject* global, JSContext* c
|
|||
|
||||
// a) check jsc file first
|
||||
std::string byteCodePath = RemoveFileExt(std::string(path)) + BYTE_CODE_FILE_EXT;
|
||||
ssize_t length = 0;
|
||||
unsigned char* data = futil->getFileData(byteCodePath.c_str(),
|
||||
"rb",
|
||||
&length);
|
||||
|
||||
Data data = futil->getDataFromFile(byteCodePath);
|
||||
|
||||
if (data) {
|
||||
script = JS_DecodeScript(cx, data, length, NULL, NULL);
|
||||
free(data);
|
||||
if (!data.isNull())
|
||||
{
|
||||
script = JS_DecodeScript(cx, data.getBytes(), static_cast<uint32_t>(data.getSize()), nullptr, nullptr);
|
||||
}
|
||||
|
||||
// b) no jsc file, check js file
|
||||
if (!script) {
|
||||
if (!script)
|
||||
{
|
||||
/* Clear any pending exception from previous failed decoding. */
|
||||
ReportException(cx);
|
||||
|
||||
|
@ -553,12 +552,10 @@ JSBool ScriptingCore::runScript(const char *path, JSObject* global, JSContext* c
|
|||
options.setUTF8(true).setFileAndLine(fullPath.c_str(), 1);
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
String* content = String::createWithContentsOfFile(path);
|
||||
if (content) {
|
||||
// Not supported in SpiderMonkey 19.0
|
||||
//JSScript* script = JS_CompileScript(cx, global, (char*)content, contentSize, path, 1);
|
||||
const char* contentCStr = content->getCString();
|
||||
script = JS::Compile(cx, obj, options, contentCStr, strlen(contentCStr));
|
||||
std::string jsFileContent = futil->getStringFromFile(fullPath);
|
||||
if (!jsFileContent.empty())
|
||||
{
|
||||
script = JS::Compile(cx, obj, options, jsFileContent.c_str(), jsFileContent.size());
|
||||
}
|
||||
#else
|
||||
script = JS::Compile(cx, obj, options, fullPath.c_str());
|
||||
|
|
|
@ -1 +1 @@
|
|||
4ff49d7d50964fb117a48243d728d75dd6d5ef77
|
||||
9af2a4febb0a58cf084fc9adfb24c1ac8138cd27
|
|
@ -46,17 +46,15 @@ extern "C"
|
|||
}
|
||||
filename.append(".lua");
|
||||
|
||||
long codeBufferSize = 0;
|
||||
unsigned char* codeBuffer = FileUtils::getInstance()->getFileData(filename.c_str(), "rb", &codeBufferSize);
|
||||
Data data = FileUtils::getInstance()->getDataFromFile(filename);
|
||||
|
||||
if (codeBuffer)
|
||||
if (!data.isNull())
|
||||
{
|
||||
if (luaL_loadbuffer(L, (char*)codeBuffer, codeBufferSize, filename.c_str()) != 0)
|
||||
if (luaL_loadbuffer(L, (char*)data.getBytes(), data.getSize(), filename.c_str()) != 0)
|
||||
{
|
||||
luaL_error(L, "error loading module %s from file %s :\n\t%s",
|
||||
lua_tostring(L, 1), filename.c_str(), lua_tostring(L, -1));
|
||||
}
|
||||
free(codeBuffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -1 +1 @@
|
|||
1f9ea8a4fdf66e19eb3d080042f2bc7463203562
|
||||
7e0639125fd9b16ab635af21d26824fd79b1f41a
|
|
@ -2,6 +2,10 @@
|
|||
#include "../testResource.h"
|
||||
#include "cocos2d.h"
|
||||
|
||||
#include "renderer/CCRenderer.h"
|
||||
#include "renderer/CCCustomCommand.h"
|
||||
#include "renderer/CCGroupCommand.h"
|
||||
|
||||
static std::function<Layer*()> createFunctions[] = {
|
||||
|
||||
CL(ActionManual),
|
||||
|
@ -1284,14 +1288,23 @@ void ActionFollow::onEnter()
|
|||
}
|
||||
|
||||
void ActionFollow::draw()
|
||||
{
|
||||
CustomCommand* cmd = CustomCommand::getCommandPool().generateCommand();
|
||||
cmd->init(0, _vertexZ);
|
||||
cmd->func = CC_CALLBACK_0(ActionFollow::onDraw, this);
|
||||
|
||||
Director::getInstance()->getRenderer()->addCommand(cmd);
|
||||
}
|
||||
|
||||
void ActionFollow::onDraw()
|
||||
{
|
||||
auto winSize = Director::getInstance()->getWinSize();
|
||||
|
||||
float x = winSize.width*2 - 100;
|
||||
float y = winSize.height;
|
||||
float x = winSize.width*2 - 100;
|
||||
float y = winSize.height;
|
||||
|
||||
Point vertices[] = { Point(5,5), Point(x-5,5), Point(x-5,y-5), Point(5,y-5) };
|
||||
DrawPrimitives::drawPoly(vertices, 4, true);
|
||||
Point vertices[] = { Point(5,5), Point(x-5,5), Point(x-5,y-5), Point(5,y-5) };
|
||||
DrawPrimitives::drawPoly(vertices, 4, true);
|
||||
}
|
||||
|
||||
std::string ActionFollow::subtitle() const
|
||||
|
@ -1589,10 +1602,25 @@ void ActionCatmullRomStacked::draw()
|
|||
// move to 50,50 since the "by" path will start at 50,50
|
||||
kmGLPushMatrix();
|
||||
kmGLTranslatef(50, 50, 0);
|
||||
DrawPrimitives::drawCatmullRom(_array1,50);
|
||||
kmGLGetMatrix(KM_GL_MODELVIEW, &_modelViewMV1);
|
||||
kmGLPopMatrix();
|
||||
kmGLGetMatrix(KM_GL_MODELVIEW, &_modelViewMV2);
|
||||
|
||||
CustomCommand* cmd = CustomCommand::getCommandPool().generateCommand();
|
||||
cmd->init(0, _vertexZ);
|
||||
cmd->func = CC_CALLBACK_0(ActionCatmullRomStacked::onDraw, this);
|
||||
Director::getInstance()->getRenderer()->addCommand(cmd);
|
||||
}
|
||||
|
||||
void ActionCatmullRomStacked::onDraw()
|
||||
{
|
||||
kmMat4 oldMat;
|
||||
kmGLGetMatrix(KM_GL_MODELVIEW, &oldMat);
|
||||
kmGLLoadMatrix(&_modelViewMV1);
|
||||
DrawPrimitives::drawCatmullRom(_array1,50);
|
||||
kmGLLoadMatrix(&_modelViewMV2);
|
||||
DrawPrimitives::drawCatmullRom(_array2,50);
|
||||
kmGLLoadMatrix(&oldMat);
|
||||
}
|
||||
|
||||
std::string ActionCatmullRomStacked::title() const
|
||||
|
@ -1684,15 +1712,31 @@ void ActionCardinalSplineStacked::draw()
|
|||
// move to 50,50 since the "by" path will start at 50,50
|
||||
kmGLPushMatrix();
|
||||
kmGLTranslatef(50, 50, 0);
|
||||
DrawPrimitives::drawCardinalSpline(_array, 0, 100);
|
||||
kmGLGetMatrix(KM_GL_MODELVIEW, &_modelViewMV1);
|
||||
kmGLPopMatrix();
|
||||
|
||||
auto s = Director::getInstance()->getWinSize();
|
||||
|
||||
kmGLPushMatrix();
|
||||
kmGLTranslatef(s.width/2, 50, 0);
|
||||
DrawPrimitives::drawCardinalSpline(_array, 1, 100);
|
||||
kmGLGetMatrix(KM_GL_MODELVIEW, &_modelViewMV2);
|
||||
kmGLPopMatrix();
|
||||
|
||||
CustomCommand* cmd = CustomCommand::getCommandPool().generateCommand();
|
||||
cmd->init(0, _vertexZ);
|
||||
cmd->func = CC_CALLBACK_0(ActionCardinalSplineStacked::onDraw, this);
|
||||
Director::getInstance()->getRenderer()->addCommand(cmd);
|
||||
}
|
||||
|
||||
void ActionCardinalSplineStacked::onDraw()
|
||||
{
|
||||
kmMat4 oldMat;
|
||||
kmGLGetMatrix(KM_GL_MODELVIEW, &oldMat);
|
||||
kmGLLoadMatrix(&_modelViewMV1);
|
||||
DrawPrimitives::drawCardinalSpline(_array, 0, 100);
|
||||
kmGLLoadMatrix(&_modelViewMV2);
|
||||
DrawPrimitives::drawCardinalSpline(_array, 1, 100);
|
||||
kmGLLoadMatrix(&oldMat);
|
||||
}
|
||||
|
||||
std::string ActionCardinalSplineStacked::title() const
|
||||
|
@ -2036,12 +2080,30 @@ void ActionCatmullRom::draw()
|
|||
// move to 50,50 since the "by" path will start at 50,50
|
||||
kmGLPushMatrix();
|
||||
kmGLTranslatef(50, 50, 0);
|
||||
DrawPrimitives::drawCatmullRom(_array1, 50);
|
||||
kmGLGetMatrix(KM_GL_MODELVIEW, &_modelViewMV1);
|
||||
|
||||
kmGLPopMatrix();
|
||||
|
||||
DrawPrimitives::drawCatmullRom(_array2,50);
|
||||
kmGLGetMatrix(KM_GL_MODELVIEW, &_modelViewMV2);
|
||||
|
||||
CustomCommand* cmd = CustomCommand::getCommandPool().generateCommand();
|
||||
cmd->init(0, _vertexZ);
|
||||
cmd->func = CC_CALLBACK_0(ActionCatmullRom::onDraw, this);
|
||||
Director::getInstance()->getRenderer()->addCommand(cmd);
|
||||
}
|
||||
|
||||
|
||||
void ActionCatmullRom::onDraw()
|
||||
{
|
||||
kmMat4 oldMat;
|
||||
kmGLGetMatrix(KM_GL_MODELVIEW, &oldMat);
|
||||
kmGLLoadMatrix(&_modelViewMV1);
|
||||
DrawPrimitives::drawCatmullRom(_array1, 50);
|
||||
kmGLLoadMatrix(&_modelViewMV2);
|
||||
DrawPrimitives::drawCatmullRom(_array2,50);
|
||||
kmGLLoadMatrix(&oldMat);
|
||||
}
|
||||
|
||||
|
||||
std::string ActionCatmullRom::title() const
|
||||
{
|
||||
return "CatmullRomBy / CatmullRomTo";
|
||||
|
@ -2114,15 +2176,31 @@ void ActionCardinalSpline::draw()
|
|||
// move to 50,50 since the "by" path will start at 50,50
|
||||
kmGLPushMatrix();
|
||||
kmGLTranslatef(50, 50, 0);
|
||||
DrawPrimitives::drawCardinalSpline(_array, 0, 100);
|
||||
kmGLGetMatrix(KM_GL_MODELVIEW, &_modelViewMV1);
|
||||
kmGLPopMatrix();
|
||||
|
||||
auto s = Director::getInstance()->getWinSize();
|
||||
|
||||
kmGLPushMatrix();
|
||||
kmGLTranslatef(s.width/2, 50, 0);
|
||||
DrawPrimitives::drawCardinalSpline(_array, 1, 100);
|
||||
kmGLGetMatrix(KM_GL_MODELVIEW, &_modelViewMV2);
|
||||
kmGLPopMatrix();
|
||||
|
||||
CustomCommand* cmd = CustomCommand::getCommandPool().generateCommand();
|
||||
cmd->init(0, _vertexZ);
|
||||
cmd->func = CC_CALLBACK_0(ActionCardinalSpline::onDraw, this);
|
||||
Director::getInstance()->getRenderer()->addCommand(cmd);
|
||||
}
|
||||
|
||||
void ActionCardinalSpline::onDraw()
|
||||
{
|
||||
kmMat4 oldMat;
|
||||
kmGLGetMatrix(KM_GL_MODELVIEW, &oldMat);
|
||||
kmGLLoadMatrix(&_modelViewMV1);
|
||||
DrawPrimitives::drawCardinalSpline(_array, 0, 100);
|
||||
kmGLLoadMatrix(&_modelViewMV2);
|
||||
DrawPrimitives::drawCardinalSpline(_array, 1, 100);
|
||||
kmGLLoadMatrix(&oldMat);
|
||||
}
|
||||
|
||||
std::string ActionCardinalSpline::title() const
|
||||
|
|
|
@ -343,6 +343,9 @@ public:
|
|||
virtual void onEnter();
|
||||
virtual void draw();
|
||||
virtual std::string subtitle() const override;
|
||||
|
||||
protected:
|
||||
void onDraw();
|
||||
};
|
||||
|
||||
class ActionTargeted : public ActionsDemo
|
||||
|
@ -415,6 +418,11 @@ public:
|
|||
virtual void onEnter();
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
protected:
|
||||
//cached data and callback
|
||||
kmMat4 _modelViewMV1;
|
||||
kmMat4 _modelViewMV2;
|
||||
void onDraw();
|
||||
private:
|
||||
PointArray* _array1;
|
||||
PointArray* _array2;
|
||||
|
@ -432,6 +440,10 @@ public:
|
|||
virtual std::string subtitle() const override;
|
||||
private:
|
||||
PointArray* _array;
|
||||
protected:
|
||||
void onDraw();
|
||||
kmMat4 _modelViewMV1;
|
||||
kmMat4 _modelViewMV2;
|
||||
};
|
||||
|
||||
class Issue1305 : public ActionsDemo
|
||||
|
@ -522,6 +534,10 @@ public:
|
|||
private:
|
||||
PointArray *_array1;
|
||||
PointArray *_array2;
|
||||
protected:
|
||||
void onDraw();
|
||||
kmMat4 _modelViewMV1;
|
||||
kmMat4 _modelViewMV2;
|
||||
};
|
||||
|
||||
class ActionCardinalSpline : public ActionsDemo
|
||||
|
@ -537,6 +553,10 @@ public:
|
|||
virtual std::string title() const override;
|
||||
private:
|
||||
PointArray *_array;
|
||||
protected:
|
||||
void onDraw();
|
||||
kmMat4 _modelViewMV1;
|
||||
kmMat4 _modelViewMV2;
|
||||
};
|
||||
|
||||
class PauseResumeActions : public ActionsDemo
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
#include "Box2dTest.h"
|
||||
#include "../testResource.h"
|
||||
#include "extensions/cocos-ext.h"
|
||||
#include "renderer/CCRenderer.h"
|
||||
#include "renderer/CCCustomCommand.h"
|
||||
|
||||
USING_NS_CC_EXT;
|
||||
|
||||
#define PTM_RATIO 32
|
||||
|
@ -144,13 +147,28 @@ void Box2DTestLayer::draw()
|
|||
GL::enableVertexAttribs( cocos2d::GL::VERTEX_ATTRIB_FLAG_POSITION );
|
||||
|
||||
kmGLPushMatrix();
|
||||
kmGLGetMatrix(KM_GL_MODELVIEW, &_modelViewMV);
|
||||
|
||||
world->DrawDebugData();
|
||||
CustomCommand *cmd = CustomCommand::getCommandPool().generateCommand();
|
||||
cmd->init(0, _vertexZ);
|
||||
cmd->func = CC_CALLBACK_0(Box2DTestLayer::onDraw, this);
|
||||
Director::getInstance()->getRenderer()->addCommand(cmd);
|
||||
|
||||
kmGLPopMatrix();
|
||||
#endif
|
||||
}
|
||||
|
||||
#if CC_ENABLE_BOX2D_INTEGRATION
|
||||
void Box2DTestLayer::onDraw()
|
||||
{
|
||||
kmMat4 oldMV;
|
||||
kmGLGetMatrix(KM_GL_MODELVIEW, &oldMV);
|
||||
kmGLLoadMatrix(&_modelViewMV);
|
||||
world->DrawDebugData();
|
||||
kmGLLoadMatrix(&oldMV);
|
||||
}
|
||||
#endif
|
||||
|
||||
void Box2DTestLayer::addNewSpriteAtPosition(Point p)
|
||||
{
|
||||
CCLOG("Add sprite %0.2f x %02.f",p.x,p.y);
|
||||
|
|
|
@ -24,6 +24,11 @@ public:
|
|||
void onTouchesEnded(const std::vector<Touch*>& touches, Event* event);
|
||||
|
||||
//CREATE_NODE(Box2DTestLayer);
|
||||
#if CC_ENABLE_BOX2D_INTEGRATION
|
||||
protected:
|
||||
kmMat4 _modelViewMV;
|
||||
void onDraw();
|
||||
#endif
|
||||
} ;
|
||||
|
||||
class Box2DTestScene : public TestScene
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
#include "DrawPrimitivesTest.h"
|
||||
#include "renderer/CCRenderer.h"
|
||||
#include "renderer/CCCustomCommand.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
@ -114,113 +116,128 @@ DrawPrimitivesTest::DrawPrimitivesTest()
|
|||
|
||||
void DrawPrimitivesTest::draw()
|
||||
{
|
||||
CustomCommand * cmd = CustomCommand::getCommandPool().generateCommand();
|
||||
cmd->init(0, _vertexZ);
|
||||
cmd->func = CC_CALLBACK_0(DrawPrimitivesTest::onDraw, this);
|
||||
Director::getInstance()->getRenderer()->addCommand(cmd);
|
||||
}
|
||||
|
||||
void DrawPrimitivesTest::onDraw()
|
||||
{
|
||||
kmMat4 oldMat;
|
||||
kmGLGetMatrix(KM_GL_MODELVIEW, &oldMat);
|
||||
kmGLLoadMatrix(&_modelViewTransform);
|
||||
|
||||
CHECK_GL_ERROR_DEBUG();
|
||||
//draw
|
||||
CHECK_GL_ERROR_DEBUG();
|
||||
|
||||
// draw a simple line
|
||||
// The default state is:
|
||||
// Line Width: 1
|
||||
// color: 255,255,255,255 (white, non-transparent)
|
||||
// Anti-Aliased
|
||||
// glEnable(GL_LINE_SMOOTH);
|
||||
// draw a simple line
|
||||
// The default state is:
|
||||
// Line Width: 1
|
||||
// color: 255,255,255,255 (white, non-transparent)
|
||||
// Anti-Aliased
|
||||
// glEnable(GL_LINE_SMOOTH);
|
||||
DrawPrimitives::drawLine( VisibleRect::leftBottom(), VisibleRect::rightTop() );
|
||||
|
||||
CHECK_GL_ERROR_DEBUG();
|
||||
CHECK_GL_ERROR_DEBUG();
|
||||
|
||||
// line: color, width, aliased
|
||||
// glLineWidth > 1 and GL_LINE_SMOOTH are not compatible
|
||||
// GL_SMOOTH_LINE_WIDTH_RANGE = (1,1) on iPhone
|
||||
// glDisable(GL_LINE_SMOOTH);
|
||||
glLineWidth( 5.0f );
|
||||
DrawPrimitives::setDrawColor4B(255,0,0,255);
|
||||
// line: color, width, aliased
|
||||
// glLineWidth > 1 and GL_LINE_SMOOTH are not compatible
|
||||
// GL_SMOOTH_LINE_WIDTH_RANGE = (1,1) on iPhone
|
||||
// glDisable(GL_LINE_SMOOTH);
|
||||
glLineWidth( 5.0f );
|
||||
DrawPrimitives::setDrawColor4B(255,0,0,255);
|
||||
DrawPrimitives::drawLine( VisibleRect::leftTop(), VisibleRect::rightBottom() );
|
||||
|
||||
CHECK_GL_ERROR_DEBUG();
|
||||
CHECK_GL_ERROR_DEBUG();
|
||||
|
||||
// TIP:
|
||||
// If you are going to use always the same color or width, you don't
|
||||
// need to call it before every draw
|
||||
//
|
||||
// Remember: OpenGL is a state-machine.
|
||||
// TIP:
|
||||
// If you are going to use always thde same color or width, you don't
|
||||
// need to call it before every draw
|
||||
//
|
||||
// Remember: OpenGL is a state-machine.
|
||||
|
||||
// draw big point in the center
|
||||
DrawPrimitives::setPointSize(64);
|
||||
DrawPrimitives::setDrawColor4B(0,0,255,128);
|
||||
// draw big point in the center
|
||||
DrawPrimitives::setPointSize(64);
|
||||
DrawPrimitives::setDrawColor4B(0,0,255,128);
|
||||
DrawPrimitives::drawPoint( VisibleRect::center() );
|
||||
|
||||
CHECK_GL_ERROR_DEBUG();
|
||||
CHECK_GL_ERROR_DEBUG();
|
||||
|
||||
// draw 4 small points
|
||||
Point points[] = { Point(60,60), Point(70,70), Point(60,70), Point(70,60) };
|
||||
DrawPrimitives::setPointSize(4);
|
||||
DrawPrimitives::setDrawColor4B(0,255,255,255);
|
||||
DrawPrimitives::drawPoints( points, 4);
|
||||
// draw 4 small points
|
||||
Point points[] = { Point(60,60), Point(70,70), Point(60,70), Point(70,60) };
|
||||
DrawPrimitives::setPointSize(4);
|
||||
DrawPrimitives::setDrawColor4B(0,255,255,255);
|
||||
DrawPrimitives::drawPoints( points, 4);
|
||||
|
||||
CHECK_GL_ERROR_DEBUG();
|
||||
CHECK_GL_ERROR_DEBUG();
|
||||
|
||||
// draw a green circle with 10 segments
|
||||
glLineWidth(16);
|
||||
DrawPrimitives::setDrawColor4B(0, 255, 0, 255);
|
||||
// draw a green circle with 10 segments
|
||||
glLineWidth(16);
|
||||
DrawPrimitives::setDrawColor4B(0, 255, 0, 255);
|
||||
DrawPrimitives::drawCircle( VisibleRect::center(), 100, 0, 10, false);
|
||||
|
||||
CHECK_GL_ERROR_DEBUG();
|
||||
CHECK_GL_ERROR_DEBUG();
|
||||
|
||||
// draw a green circle with 50 segments with line to center
|
||||
glLineWidth(2);
|
||||
DrawPrimitives::setDrawColor4B(0, 255, 255, 255);
|
||||
// draw a green circle with 50 segments with line to center
|
||||
glLineWidth(2);
|
||||
DrawPrimitives::setDrawColor4B(0, 255, 255, 255);
|
||||
DrawPrimitives::drawCircle( VisibleRect::center(), 50, CC_DEGREES_TO_RADIANS(90), 50, true);
|
||||
|
||||
CHECK_GL_ERROR_DEBUG();
|
||||
CHECK_GL_ERROR_DEBUG();
|
||||
|
||||
// draw a pink solid circle with 50 segments
|
||||
glLineWidth(2);
|
||||
DrawPrimitives::setDrawColor4B(255, 0, 255, 255);
|
||||
// draw a pink solid circle with 50 segments
|
||||
glLineWidth(2);
|
||||
DrawPrimitives::setDrawColor4B(255, 0, 255, 255);
|
||||
DrawPrimitives::drawSolidCircle( VisibleRect::center() + Point(140,0), 40, CC_DEGREES_TO_RADIANS(90), 50, 1.0f, 1.0f);
|
||||
|
||||
CHECK_GL_ERROR_DEBUG();
|
||||
CHECK_GL_ERROR_DEBUG();
|
||||
|
||||
// open yellow poly
|
||||
DrawPrimitives::setDrawColor4B(255, 255, 0, 255);
|
||||
glLineWidth(10);
|
||||
Point vertices[] = { Point(0,0), Point(50,50), Point(100,50), Point(100,100), Point(50,100) };
|
||||
DrawPrimitives::drawPoly( vertices, 5, false);
|
||||
// open yellow poly
|
||||
DrawPrimitives::setDrawColor4B(255, 255, 0, 255);
|
||||
glLineWidth(10);
|
||||
Point vertices[] = { Point(0,0), Point(50,50), Point(100,50), Point(100,100), Point(50,100) };
|
||||
DrawPrimitives::drawPoly( vertices, 5, false);
|
||||
|
||||
CHECK_GL_ERROR_DEBUG();
|
||||
|
||||
// filled poly
|
||||
glLineWidth(1);
|
||||
Point filledVertices[] = { Point(0,120), Point(50,120), Point(50,170), Point(25,200), Point(0,170) };
|
||||
DrawPrimitives::drawSolidPoly(filledVertices, 5, Color4F(0.5f, 0.5f, 1, 1 ) );
|
||||
CHECK_GL_ERROR_DEBUG();
|
||||
|
||||
// filled poly
|
||||
glLineWidth(1);
|
||||
Point filledVertices[] = { Point(0,120), Point(50,120), Point(50,170), Point(25,200), Point(0,170) };
|
||||
DrawPrimitives::drawSolidPoly(filledVertices, 5, Color4F(0.5f, 0.5f, 1, 1 ) );
|
||||
|
||||
|
||||
// closed purble poly
|
||||
DrawPrimitives::setDrawColor4B(255, 0, 255, 255);
|
||||
glLineWidth(2);
|
||||
Point vertices2[] = { Point(30,130), Point(30,230), Point(50,200) };
|
||||
DrawPrimitives::drawPoly( vertices2, 3, true);
|
||||
// closed purble poly
|
||||
DrawPrimitives::setDrawColor4B(255, 0, 255, 255);
|
||||
glLineWidth(2);
|
||||
Point vertices2[] = { Point(30,130), Point(30,230), Point(50,200) };
|
||||
DrawPrimitives::drawPoly( vertices2, 3, true);
|
||||
|
||||
CHECK_GL_ERROR_DEBUG();
|
||||
CHECK_GL_ERROR_DEBUG();
|
||||
|
||||
// draw quad bezier path
|
||||
// draw quad bezier path
|
||||
DrawPrimitives::drawQuadBezier(VisibleRect::leftTop(), VisibleRect::center(), VisibleRect::rightTop(), 50);
|
||||
|
||||
CHECK_GL_ERROR_DEBUG();
|
||||
CHECK_GL_ERROR_DEBUG();
|
||||
|
||||
// draw cubic bezier path
|
||||
// draw cubic bezier path
|
||||
DrawPrimitives::drawCubicBezier(VisibleRect::center(), Point(VisibleRect::center().x+30,VisibleRect::center().y+50), Point(VisibleRect::center().x+60,VisibleRect::center().y-50),VisibleRect::right(),100);
|
||||
|
||||
CHECK_GL_ERROR_DEBUG();
|
||||
CHECK_GL_ERROR_DEBUG();
|
||||
|
||||
//draw a solid polygon
|
||||
Point vertices3[] = {Point(60,160), Point(70,190), Point(100,190), Point(90,160)};
|
||||
Point vertices3[] = {Point(60,160), Point(70,190), Point(100,190), Point(90,160)};
|
||||
DrawPrimitives::drawSolidPoly( vertices3, 4, Color4F(1,1,0,1) );
|
||||
|
||||
// restore original values
|
||||
glLineWidth(1);
|
||||
DrawPrimitives::setDrawColor4B(255,255,255,255);
|
||||
DrawPrimitives::setPointSize(1);
|
||||
// restore original values
|
||||
glLineWidth(1);
|
||||
DrawPrimitives::setDrawColor4B(255,255,255,255);
|
||||
DrawPrimitives::setPointSize(1);
|
||||
|
||||
CHECK_GL_ERROR_DEBUG();
|
||||
CHECK_GL_ERROR_DEBUG();
|
||||
|
||||
//end draw
|
||||
kmGLLoadMatrix(&oldMat);
|
||||
}
|
||||
|
||||
string DrawPrimitivesTest::title() const
|
||||
|
@ -257,10 +274,10 @@ DrawNodeTest::DrawNodeTest()
|
|||
const float w=20;
|
||||
const float h=50;
|
||||
Point star[] = {
|
||||
Point(o+w,o-h), Point(o+w*2, o), // lower spike
|
||||
Point(o + w*2 + h, o+w ), Point(o + w*2, o+w*2), // right spike
|
||||
// {o +w, o+w*2+h}, {o,o+w*2}, // top spike
|
||||
// {o -h, o+w}, {o,o}, // left spike
|
||||
Point(o+w,o-h), Point(o+w*2, o), // lower spike
|
||||
Point(o + w*2 + h, o+w ), Point(o + w*2, o+w*2), // right spike
|
||||
// {o +w, o+w*2+h}, {o,o+w*2}, // top spike
|
||||
// {o -h, o+w}, {o,o}, // left spike
|
||||
};
|
||||
|
||||
draw->drawPolygon(star, sizeof(star)/sizeof(star[0]), Color4F(1,0,0,0.5), 1, Color4F(0,0,1,1));
|
||||
|
@ -272,9 +289,9 @@ DrawNodeTest::DrawNodeTest()
|
|||
const float w=20;
|
||||
const float h=50;
|
||||
Point star[] = {
|
||||
Point(o,o), Point(o+w,o-h), Point(o+w*2, o), // lower spike
|
||||
Point(o + w*2 + h, o+w ), Point(o + w*2, o+w*2), // right spike
|
||||
Point(o +w, o+w*2+h), Point(o,o+w*2), // top spike
|
||||
Point(o,o), Point(o+w,o-h), Point(o+w*2, o), // lower spike
|
||||
Point(o + w*2 + h, o+w ), Point(o + w*2, o+w*2), // right spike
|
||||
Point(o +w, o+w*2+h), Point(o,o+w*2), // top spike
|
||||
Point(o -h, o+w), // left spike
|
||||
};
|
||||
|
||||
|
|
|
@ -28,6 +28,8 @@ public:
|
|||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
virtual void draw();
|
||||
protected:
|
||||
void onDraw();
|
||||
};
|
||||
|
||||
class DrawNodeTest : public BaseLayer
|
||||
|
|
|
@ -49,7 +49,7 @@ void SpineTestScene::runThisTest()
|
|||
bool SpineTestLayer::init () {
|
||||
if (!Layer::init()) return false;
|
||||
|
||||
skeletonNode = CCSkeletonAnimation::createWithFile("spine/spineboy.json", "spine/spineboy.atlas");
|
||||
skeletonNode = SkeletonAnimation::createWithFile("spine/spineboy.json", "spine/spineboy.atlas");
|
||||
skeletonNode->setMix("walk", "jump", 0.2f);
|
||||
skeletonNode->setMix("jump", "walk", 0.4f);
|
||||
|
||||
|
@ -82,7 +82,7 @@ void SpineTestLayer::update (float deltaTime) {
|
|||
|
||||
}
|
||||
|
||||
void SpineTestLayer::animationStateEvent (CCSkeletonAnimation* node, int trackIndex, spEventType type, spEvent* event, int loopCount) {
|
||||
void SpineTestLayer::animationStateEvent (SkeletonAnimation* node, int trackIndex, spEventType type, spEvent* event, int loopCount) {
|
||||
spTrackEntry* entry = spAnimationState_getCurrent(node->state, trackIndex);
|
||||
const char* animationName = (entry && entry->animation) ? entry->animation->name : 0;
|
||||
|
||||
|
|
|
@ -38,13 +38,13 @@ public:
|
|||
|
||||
class SpineTestLayer: public cocos2d::Layer {
|
||||
private:
|
||||
spine::CCSkeletonAnimation* skeletonNode;
|
||||
spine::SkeletonAnimation* skeletonNode;
|
||||
|
||||
public:
|
||||
|
||||
virtual bool init ();
|
||||
virtual void update (float deltaTime);
|
||||
void animationStateEvent (spine::CCSkeletonAnimation* node, int trackIndex, spEventType type, spEvent* event, int loopCount);
|
||||
void animationStateEvent (spine::SkeletonAnimation* node, int trackIndex, spEventType type, spEvent* event, int loopCount);
|
||||
|
||||
CREATE_FUNC (SpineTestLayer);
|
||||
};
|
||||
|
|
|
@ -76,7 +76,7 @@
|
|||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
|
||||
<DebugInformationFormat>OldStyle</DebugInformationFormat>
|
||||
<DisableSpecificWarnings>4267;4251;4244;%(DisableSpecificWarnings)</DisableSpecificWarnings>
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
</ClCompile>
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit fda861cde4387948e95811966d9c4ceea04dc758
|
||||
Subproject commit ff3a95b059be8421677ed6817b73ae2ac577781d
|
|
@ -26,7 +26,7 @@ headers = %(cocosdir)s/cocos/2d/cocos2d.h %(cocosdir)s/cocos/audio/include/Simpl
|
|||
|
||||
# what classes to produce code for. You can use regular expressions here. When testing the regular
|
||||
# expression, it will be enclosed in "^$", like this: "^Menu*$".
|
||||
classes = New.* Sprite.* Scene Node.* Director Layer.* Menu.* Touch .*Action.* Move.* Rotate.* Blink.* Tint.* Sequence Repeat.* Fade.* Ease.* Scale.* Transition.* Spawn Animat.* Flip.* Delay.* Skew.* Jump.* Place.* Show.* Progress.* PointArray ToggleVisibility.* RemoveSelf Hide Particle.* Label.* Atlas.* TextureCache.* Texture2D Cardinal.* CatmullRom.* ParallaxNode TileMap.* TMX.* CallFunc RenderTexture GridAction Grid3DAction GridBase$ .+Grid Shaky3D Waves3D FlipX3D FlipY3D Speed ActionManager Set Data SimpleAudioEngine Scheduler Timer Orbit.* Follow.* Bezier.* CardinalSpline.* Camera.* DrawNode .*3D$ Liquid$ Waves$ ShuffleTiles$ TurnOffTiles$ Split.* Twirl$ FileUtils$ GLProgram ShaderCache Application ClippingNode MotionStreak TextFieldTTF EGLViewProtocol EGLView Component __NodeRGBA __LayerRGBA
|
||||
classes = New.* Sprite.* Scene Node.* Director Layer.* Menu.* Touch .*Action.* Move.* Rotate.* Blink.* Tint.* Sequence Repeat.* Fade.* Ease.* Scale.* Transition.* Spawn Animat.* Flip.* Delay.* Skew.* Jump.* Place.* Show.* Progress.* PointArray ToggleVisibility.* RemoveSelf Hide Particle.* Label.* Atlas.* TextureCache.* Texture2D Cardinal.* CatmullRom.* ParallaxNode TileMap.* TMX.* CallFunc RenderTexture GridAction Grid3DAction GridBase$ .+Grid Shaky3D Waves3D FlipX3D FlipY3D Speed ActionManager Set SimpleAudioEngine Scheduler Timer Orbit.* Follow.* Bezier.* CardinalSpline.* Camera.* DrawNode .*3D$ Liquid$ Waves$ ShuffleTiles$ TurnOffTiles$ Split.* Twirl$ FileUtils$ GLProgram ShaderCache Application ClippingNode MotionStreak TextFieldTTF EGLViewProtocol EGLView Component __NodeRGBA __LayerRGBA
|
||||
|
||||
classes_need_extend = Node Layer.* Sprite MenuItemFont Scene DrawNode
|
||||
|
||||
|
@ -104,7 +104,7 @@ skip = Node::[^setPosition$ setGrid setGLServerState description getUserObject .
|
|||
TextureCache::[addPVRTCImage],
|
||||
Timer::[getSelector createWithScriptHandler],
|
||||
*::[copyWith.* onEnter.* onExit.* ^description$ getObjectType onTouch.* onAcc.* onKey.* onRegisterTouchListener],
|
||||
FileUtils::[(g|s)etSearchResolutionsOrder$ (g|s)etSearchPaths$ getFileData],
|
||||
FileUtils::[(g|s)etSearchResolutionsOrder$ (g|s)etSearchPaths$ getFileData getDataFromFile],
|
||||
Application::[^application.* ^run$],
|
||||
Camera::[getEyeXYZ getCenterXYZ getUpXYZ],
|
||||
ccFontDefinition::[*],
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
[cocos2dx_spine]
|
||||
prefix = cocos2dx_spine
|
||||
|
||||
target_namespace = cc
|
||||
target_namespace = sp
|
||||
|
||||
android_headers = -I%(androidndkdir)s/platforms/android-14/arch-arm/usr/include -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.7/libs/armeabi-v7a/include -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.7/include
|
||||
android_flags = -D_SIZE_T_DEFINED_
|
||||
|
@ -20,12 +20,12 @@ extra_arguments = %(android_headers)s %(clang_headers)s %(cxxgenerator_headers)s
|
|||
|
||||
headers = %(cocosdir)s/cocos/editor-support/spine/spine-cocos2dx.h
|
||||
|
||||
skip = CCSkeleton::[createWithData],
|
||||
CCSkeletonAnimation::[createWithData]
|
||||
skip = Skeleton::[createWithData],
|
||||
SkeletonAnimation::[createWithData]
|
||||
|
||||
classes = CCSkeleton CCSkeletonAnimation
|
||||
classes = Skeleton SkeletonAnimation
|
||||
|
||||
remove_prefix = CC
|
||||
remove_prefix =
|
||||
|
||||
classes_have_no_parents =
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ headers = %(cocosdir)s/cocos/2d/cocos2d.h %(cocosdir)s/cocos/audio/include/Simpl
|
|||
|
||||
# what classes to produce code for. You can use regular expressions here. When testing the regular
|
||||
# expression, it will be enclosed in "^$", like this: "^Menu*$".
|
||||
classes = New.* Sprite.* Scene Node.* Director Layer.* Menu.* Touch .*Action.* Move.* Rotate.* Blink.* Tint.* Sequence Repeat.* Fade.* Ease.* Scale.* Transition.* Spawn Animat.* Flip.* Delay.* Skew.* Jump.* Place.* Show.* Progress.* PointArray ToggleVisibility.* RemoveSelf Hide Particle.* Label.* Atlas.* TextureCache.* Texture2D Cardinal.* CatmullRom.* ParallaxNode TileMap.* TMX.* CallFunc RenderTexture GridAction Grid3DAction GridBase$ .+Grid Shaky3D Waves3D FlipX3D FlipY3D Speed ActionManager Set Data SimpleAudioEngine Scheduler Timer Orbit.* Follow.* Bezier.* CardinalSpline.* Camera.* DrawNode .*3D$ Liquid$ Waves$ ShuffleTiles$ TurnOffTiles$ Split.* Twirl$ FileUtils$ GLProgram ShaderCache Application ClippingNode MotionStreak ^Object$ UserDefault EGLViewProtocol EGLView Image Event.* DisplayLinkDirector
|
||||
classes = New.* Sprite.* Scene Node.* Director Layer.* Menu.* Touch .*Action.* Move.* Rotate.* Blink.* Tint.* Sequence Repeat.* Fade.* Ease.* Scale.* Transition.* Spawn Animat.* Flip.* Delay.* Skew.* Jump.* Place.* Show.* Progress.* PointArray ToggleVisibility.* RemoveSelf Hide Particle.* Label.* Atlas.* TextureCache.* Texture2D Cardinal.* CatmullRom.* ParallaxNode TileMap.* TMX.* CallFunc RenderTexture GridAction Grid3DAction GridBase$ .+Grid Shaky3D Waves3D FlipX3D FlipY3D Speed ActionManager Set SimpleAudioEngine Scheduler Timer Orbit.* Follow.* Bezier.* CardinalSpline.* Camera.* DrawNode .*3D$ Liquid$ Waves$ ShuffleTiles$ TurnOffTiles$ Split.* Twirl$ FileUtils$ GLProgram ShaderCache Application ClippingNode MotionStreak ^Object$ UserDefault EGLViewProtocol EGLView Image Event.*
|
||||
|
||||
# what should we skip? in the format ClassName::[function function]
|
||||
# ClassName is a regular expression, but will be used like this: "^ClassName$" functions are also
|
||||
|
@ -102,7 +102,7 @@ skip = Node::[setGLServerState description getUserObject .*UserData getGLServerS
|
|||
TextureCache::[addPVRTCImage],
|
||||
Timer::[getSelector createWithScriptHandler],
|
||||
*::[copyWith.* onEnter.* onExit.* ^description$ getObjectType (g|s)etDelegate onTouch.* onAcc.* onKey.* onRegisterTouchListener],
|
||||
FileUtils::[(g|s)etSearchResolutionsOrder$ (g|s)etSearchPaths$ getFileData],
|
||||
FileUtils::[(g|s)etSearchResolutionsOrder$ (g|s)etSearchPaths$ getFileData getDataFromFile],
|
||||
Application::[^application.* ^run$],
|
||||
Camera::[getEyeXYZ getCenterXYZ getUpXYZ],
|
||||
ccFontDefinition::[*],
|
||||
|
|
Loading…
Reference in New Issue