Merge remote-tracking branch 'upstream/v3' into v3

This commit is contained in:
kompjoefriek 2015-01-26 23:18:48 +01:00
commit 722ec8713b
58 changed files with 643 additions and 316 deletions

View File

@ -1071,6 +1071,12 @@ Developers:
AknEp
Fix FileUtils::fullPathForFilename return empty string if file not found
kompjoefriek
Fix compiling warnings
tmr111116
fix random int overflow
Retired Core Developers:
WenSheng Yang

View File

@ -1,15 +1,23 @@
cocos2d-x-3.4 Jan.23 2015
cocos2d-x-3.4 xxx
[FIX] Animate3D: `setSpeed` has not effect if `Animate3D` is used in Sequence
[FIX] C++: will crash if built with armeabi-v7a enabled on Android devices that with armeabi-v7a architecture but doesn't support NEON instructions
[FIX] C++: may crash if VAO is not supported
[FIX] EditBox: content is not clipped correctly on windows
[FIX] GLProgram: will cause crash on some devices that don't support more than 8 atrributes
[FIX] ImageView: rendered content size is wrong if `ignoreSize` is true and `Scale9` is not enabled
[FIX] Label: alpha channel of text color of system font has not effect
[FIX] Label: use int for dimensions that will lose the precision
[FIX] Label: labels will become white block after resume from background on some Android devices, such as xiaomi3
[FIX] Label: improved parsing performance of bitmap font
[FIX] Lua-binding:studio-support: AnimationInfo is not binded
[FIX] New audio: not close file descriptor leads to that may causes game freeze if playing two many times(may be more than 1000) on Android
[FIX] Node: anchor point has not effect to rotation, it always rotate along (0, 0)
[FIX] SpriteFrameCache: `addSpriteFramesWithFil`e may crash if plist file doesn't exist
[FIX] Sprite3D: material files (.mtl) are not loaded for any object when creating from an .obj file
[FIX] UI::ImageView: rendered content size is wrong if `ignoreSize` is true and `Scale9` is not enabled
[FIX] UI::Slider: when scale9 is enabled, the progress bar's rendering height is wrong
[FIX] UI:Scale9Sprite: some position information will be lost when toggling `Scale9` state
[FIX] UI::TextField: will get wrong event message if clicking `TextField` twice
[FIX] UI::WebView: base URL can not work
cocos2d-x-3.4rc1 Jan.15 2015
[NEW] C++: added CC_USE_CULLING macro to control if enable auto culling or not

View File

@ -144,11 +144,11 @@ DrawNode::~DrawNode()
if (Configuration::getInstance()->supportsShareableVAO())
{
GL::bindVAO(0);
glDeleteVertexArrays(1, &_vao);
glDeleteVertexArrays(1, &_vaoGLLine);
glDeleteVertexArrays(1, &_vaoGLPoint);
GL::bindVAO(0);
_vao = 0;
_vao = _vaoGLLine = _vaoGLPoint = 0;
}
}
@ -214,60 +214,66 @@ bool DrawNode::init()
{
glGenVertexArrays(1, &_vao);
GL::bindVAO(_vao);
}
glGenBuffers(1, &_vbo);
glBindBuffer(GL_ARRAY_BUFFER, _vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(V2F_C4B_T2F)* _bufferCapacity, _buffer, GL_STREAM_DRAW);
// vertex
glEnableVertexAttribArray(GLProgram::VERTEX_ATTRIB_POSITION);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, vertices));
// color
glEnableVertexAttribArray(GLProgram::VERTEX_ATTRIB_COLOR);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, colors));
// texcood
glEnableVertexAttribArray(GLProgram::VERTEX_ATTRIB_TEX_COORD);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_TEX_COORD, 2, GL_FLOAT, GL_FALSE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, texCoords));
if (Configuration::getInstance()->supportsShareableVAO())
{
glGenBuffers(1, &_vbo);
glBindBuffer(GL_ARRAY_BUFFER, _vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(V2F_C4B_T2F)* _bufferCapacity, _buffer, GL_STREAM_DRAW);
// vertex
glEnableVertexAttribArray(GLProgram::VERTEX_ATTRIB_POSITION);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, vertices));
// color
glEnableVertexAttribArray(GLProgram::VERTEX_ATTRIB_COLOR);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, colors));
// texcood
glEnableVertexAttribArray(GLProgram::VERTEX_ATTRIB_TEX_COORD);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_TEX_COORD, 2, GL_FLOAT, GL_FALSE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, texCoords));
glGenVertexArrays(1, &_vaoGLLine);
GL::bindVAO(_vaoGLLine);
}
glGenBuffers(1, &_vboGLLine);
glBindBuffer(GL_ARRAY_BUFFER, _vboGLLine);
glBufferData(GL_ARRAY_BUFFER, sizeof(V2F_C4B_T2F)*_bufferCapacityGLLine, _bufferGLLine, GL_STREAM_DRAW);
// vertex
glEnableVertexAttribArray(GLProgram::VERTEX_ATTRIB_POSITION);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, vertices));
// color
glEnableVertexAttribArray(GLProgram::VERTEX_ATTRIB_COLOR);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, colors));
// texcood
glEnableVertexAttribArray(GLProgram::VERTEX_ATTRIB_TEX_COORD);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_TEX_COORD, 2, GL_FLOAT, GL_FALSE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, texCoords));
if (Configuration::getInstance()->supportsShareableVAO())
{
glGenBuffers(1, &_vboGLLine);
glBindBuffer(GL_ARRAY_BUFFER, _vboGLLine);
glBufferData(GL_ARRAY_BUFFER, sizeof(V2F_C4B_T2F)*_bufferCapacityGLLine, _bufferGLLine, GL_STREAM_DRAW);
// vertex
glEnableVertexAttribArray(GLProgram::VERTEX_ATTRIB_POSITION);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, vertices));
// color
glEnableVertexAttribArray(GLProgram::VERTEX_ATTRIB_COLOR);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, colors));
// texcood
glEnableVertexAttribArray(GLProgram::VERTEX_ATTRIB_TEX_COORD);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_TEX_COORD, 2, GL_FLOAT, GL_FALSE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, texCoords));
glGenVertexArrays(1, &_vaoGLPoint);
GL::bindVAO(_vaoGLPoint);
}
glGenBuffers(1, &_vboGLPoint);
glBindBuffer(GL_ARRAY_BUFFER, _vboGLPoint);
glBufferData(GL_ARRAY_BUFFER, sizeof(V2F_C4B_T2F)*_bufferCapacityGLPoint, _bufferGLPoint, GL_STREAM_DRAW);
// vertex
glEnableVertexAttribArray(GLProgram::VERTEX_ATTRIB_POSITION);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, vertices));
// color
glEnableVertexAttribArray(GLProgram::VERTEX_ATTRIB_COLOR);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, colors));
// Texture coord as pointsize
glEnableVertexAttribArray(GLProgram::VERTEX_ATTRIB_TEX_COORD);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_TEX_COORD, 2, GL_FLOAT, GL_FALSE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, texCoords));
glBindBuffer(GL_ARRAY_BUFFER, 0);
if (Configuration::getInstance()->supportsShareableVAO())
{
glGenBuffers(1, &_vboGLPoint);
glBindBuffer(GL_ARRAY_BUFFER, _vboGLPoint);
glBufferData(GL_ARRAY_BUFFER, sizeof(V2F_C4B_T2F)*_bufferCapacityGLPoint, _bufferGLPoint, GL_STREAM_DRAW);
// vertex
glEnableVertexAttribArray(GLProgram::VERTEX_ATTRIB_POSITION);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, vertices));
// color
glEnableVertexAttribArray(GLProgram::VERTEX_ATTRIB_COLOR);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, colors));
// Texture coord as pointsize
glEnableVertexAttribArray(GLProgram::VERTEX_ATTRIB_TEX_COORD);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_TEX_COORD, 2, GL_FLOAT, GL_FALSE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, texCoords));
GL::bindVAO(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
else
{
glGenBuffers(1, &_vbo);
glBindBuffer(GL_ARRAY_BUFFER, _vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(V2F_C4B_T2F)* _bufferCapacity, _buffer, GL_STREAM_DRAW);
glGenBuffers(1, &_vboGLLine);
glBindBuffer(GL_ARRAY_BUFFER, _vboGLLine);
glBufferData(GL_ARRAY_BUFFER, sizeof(V2F_C4B_T2F)*_bufferCapacityGLLine, _bufferGLLine, GL_STREAM_DRAW);
glGenBuffers(1, &_vboGLPoint);
glBindBuffer(GL_ARRAY_BUFFER, _vboGLPoint);
glBufferData(GL_ARRAY_BUFFER, sizeof(V2F_C4B_T2F)*_bufferCapacityGLPoint, _bufferGLPoint, GL_STREAM_DRAW);
}
CHECK_GL_ERROR_DEBUG();
@ -348,6 +354,11 @@ void DrawNode::onDraw(const Mat4 &transform, uint32_t flags)
glDrawArrays(GL_TRIANGLES, 0, _bufferCount);
glBindBuffer(GL_ARRAY_BUFFER, 0);
if (Configuration::getInstance()->supportsShareableVAO())
{
GL::bindVAO(0);
}
CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1, _bufferCount);
CHECK_GL_ERROR_DEBUG();
}
@ -381,6 +392,12 @@ void DrawNode::onDrawGLLine(const Mat4 &transform, uint32_t flags)
}
glLineWidth(2);
glDrawArrays(GL_LINES, 0, _bufferCountGLLine);
if (Configuration::getInstance()->supportsShareableVAO())
{
GL::bindVAO(0);
}
glBindBuffer(GL_ARRAY_BUFFER, 0);
CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1,_bufferCountGLLine);
@ -415,6 +432,12 @@ void DrawNode::onDrawGLPoint(const Mat4 &transform, uint32_t flags)
}
glDrawArrays(GL_POINTS, 0, _bufferCountGLPoint);
if (Configuration::getInstance()->supportsShareableVAO())
{
GL::bindVAO(0);
}
glBindBuffer(GL_ARRAY_BUFFER, 0);
CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1,_bufferCountGLPoint);

View File

@ -154,7 +154,7 @@ void TMXLayer::draw(Renderer *renderer, const Mat4& transform, uint32_t flags)
_dirty = false;
}
if(_renderCommands.size() < _primitives.size())
if(_renderCommands.size() < static_cast<size_t>(_primitives.size()))
{
_renderCommands.resize(_primitives.size());
}

View File

@ -148,11 +148,11 @@ public:
private:
std::set<unsigned int>* parseConfigFile(const std::string& controlFile);
std::set<unsigned int>* parseBinaryConfigFile(unsigned char* pData, unsigned long size, const std::string& controlFile);
void parseCharacterDefinition(std::string line, BMFontDef *characterDefinition);
void parseInfoArguments(std::string line);
void parseCommonArguments(std::string line);
void parseImageFileName(std::string line, const std::string& fntFile);
void parseKerningEntry(std::string line);
void parseCharacterDefinition(const char* line, BMFontDef *characterDefinition);
void parseInfoArguments(const char* line);
void parseCommonArguments(const char* line);
void parseImageFileName(const char* line, const std::string& fntFile);
void parseKerningEntry(const char* line);
void purgeKerningDictionary();
void purgeFontDefDictionary();
};
@ -206,7 +206,7 @@ bool BMFontConfiguration::initWithFNTfile(const std::string& FNTfile)
_fontDefDictionary = nullptr;
_characterSet = this->parseConfigFile(FNTfile);
if (! _characterSet)
{
return false;
@ -271,48 +271,49 @@ void BMFontConfiguration::purgeFontDefDictionary()
}
std::set<unsigned int>* BMFontConfiguration::parseConfigFile(const std::string& controlFile)
{
std::string fullpath = FileUtils::getInstance()->fullPathForFilename(controlFile);
Data data = FileUtils::getInstance()->getDataFromFile(fullpath);
CCASSERT((!data.isNull() && data.getSize() > 0), "BMFontConfiguration::parseConfigFile | Open file error.");
{
Data data = FileUtils::getInstance()->getDataFromFile(controlFile);
CCASSERT((!data.isNull()), "BMFontConfiguration::parseConfigFile | Open file error.");
if (memcmp("BMF", data.getBytes(), 3) == 0) {
std::set<unsigned int>* ret = parseBinaryConfigFile(data.getBytes(), data.getSize(), controlFile);
return ret;
}
std::string contents((const char*)data.getBytes(), data.getSize());
std::set<unsigned int> *validCharsString = new std::set<unsigned int>();
if (contents.empty())
auto contents = (const char*)data.getBytes();
if (contents[0] == 0)
{
CCLOG("cocos2d: Error parsing FNTfile %s", controlFile.c_str());
return nullptr;
}
// parse spacing / padding
std::string line;
std::string strLeft(contents);
while (strLeft.length() > 0)
std::set<unsigned int> *validCharsString = new std::set<unsigned int>();
auto contentsLen = data.getSize();
char line[512];
auto next = strchr(contents, '\n');
auto base = contents;
int lineLength = 0;
int parseCount = 0;
while (next)
{
size_t pos = strLeft.find('\n');
lineLength = next - base;
memcpy(line, contents + parseCount, lineLength);
line[lineLength] = 0;
if (pos != std::string::npos)
parseCount += lineLength + 1;
if (parseCount < contentsLen)
{
// the data is more than a line.get one line
line = strLeft.substr(0, pos);
strLeft = strLeft.substr(pos + 1);
}
base = next + 1;
next = strchr(base, '\n');
}
else
{
// get the left data
line = strLeft;
strLeft.erase();
next = nullptr;
}
if(line.substr(0,strlen("info face")) == "info face")
if (memcmp(line, "info face", 9) == 0)
{
// FIXME: info parsing is incomplete
// Not needed for the Hiero editors, but needed for the AngelCode editor
@ -320,19 +321,19 @@ std::set<unsigned int>* BMFontConfiguration::parseConfigFile(const std::string&
this->parseInfoArguments(line);
}
// Check to see if the start of the line is something we are interested in
else if(line.substr(0,strlen("common lineHeight")) == "common lineHeight")
else if (memcmp(line, "common lineHeight", 17) == 0)
{
this->parseCommonArguments(line);
}
else if(line.substr(0,strlen("page id")) == "page id")
else if (memcmp(line, "page id", 7) == 0)
{
this->parseImageFileName(line, controlFile);
}
else if(line.substr(0,strlen("chars c")) == "chars c")
else if (memcmp(line, "chars c", 7) == 0)
{
// Ignore this line
}
else if(line.substr(0,strlen("char")) == "char")
else if (memcmp(line, "char", 4) == 0)
{
// Parse the current line and create a new CharDef
tFontDefHashElement* element = (tFontDefHashElement*)malloc( sizeof(*element) );
@ -347,7 +348,7 @@ std::set<unsigned int>* BMFontConfiguration::parseConfigFile(const std::string&
// {
// this->parseKerningCapacity(line);
// }
else if(line.substr(0,strlen("kerning first")) == "kerning first")
else if (memcmp(line, "kerning first", 13) == 0)
{
this->parseKerningEntry(line);
}
@ -514,7 +515,7 @@ std::set<unsigned int>* BMFontConfiguration::parseBinaryConfigFile(unsigned char
return validCharsString;
}
void BMFontConfiguration::parseImageFileName(std::string line, const std::string& fntFile)
void BMFontConfiguration::parseImageFileName(const char* line, const std::string& fntFile)
{
//////////////////////////////////////////////////////////////////////////
// line to parse:
@ -522,19 +523,16 @@ void BMFontConfiguration::parseImageFileName(std::string line, const std::string
//////////////////////////////////////////////////////////////////////////
// page ID. Sanity check
auto index = line.find('=')+1;
auto index2 = line.find(' ', index);
std::string value = line.substr(index, index2-index);
CCASSERT(atoi(value.c_str()) == 0, "LabelBMFont file could not be found");
int pageId;
sscanf(line, "page id=%d", &pageId);
CCASSERT(pageId == 0, "LabelBMFont file could not be found");
// file
index = line.find('"')+1;
index2 = line.find('"', index);
value = line.substr(index, index2-index);
_atlasName = FileUtils::getInstance()->fullPathFromRelativeFile(value.c_str(), fntFile);
char fileName[255];
sscanf(strchr(line,'"') + 1, "%[^\"]", fileName);
_atlasName = FileUtils::getInstance()->fullPathFromRelativeFile(fileName, fntFile);
}
void BMFontConfiguration::parseInfoArguments(std::string line)
void BMFontConfiguration::parseInfoArguments(const char* line)
{
//////////////////////////////////////////////////////////////////////////
// possible lines to parse:
@ -543,45 +541,42 @@ void BMFontConfiguration::parseInfoArguments(std::string line)
//////////////////////////////////////////////////////////////////////////
// padding
auto index = line.find("padding=");
auto index2 = line.find(' ', index);
std::string value = line.substr(index, index2-index);
sscanf(value.c_str(), "padding=%d,%d,%d,%d", &_padding.top, &_padding.right, &_padding.bottom, &_padding.left);
CCLOG("cocos2d: padding: %d,%d,%d,%d", _padding.left, _padding.top, _padding.right, _padding.bottom);
sscanf(strstr(line,"padding=") + 8, "%d,%d,%d,%d", &_padding.top, &_padding.right, &_padding.bottom, &_padding.left);
//CCLOG("cocos2d: padding: %d,%d,%d,%d", _padding.left, _padding.top, _padding.right, _padding.bottom);
}
void BMFontConfiguration::parseCommonArguments(std::string line)
void BMFontConfiguration::parseCommonArguments(const char* line)
{
//////////////////////////////////////////////////////////////////////////
// line to parse:
// common lineHeight=104 base=26 scaleW=1024 scaleH=512 pages=1 packed=0
//////////////////////////////////////////////////////////////////////////
// Height
auto index = line.find("lineHeight=");
auto index2 = line.find(' ', index);
std::string value = line.substr(index, index2-index);
sscanf(value.c_str(), "lineHeight=%d", &_commonHeight);
auto tmp = strstr(line, "lineHeight=") + 11;
sscanf(tmp, "%d", &_commonHeight);
// scaleW. sanity check
index = line.find("scaleW=") + strlen("scaleW=");
index2 = line.find(' ', index);
value = line.substr(index, index2-index);
CCASSERT(atoi(value.c_str()) <= Configuration::getInstance()->getMaxTextureSize(), "CCLabelBMFont: page can't be larger than supported");
int value;
tmp = strstr(tmp, "scaleW=") + 7;
sscanf(tmp, "%d", &value);
int maxTextureSize = Configuration::getInstance()->getMaxTextureSize();
CCASSERT(value <= maxTextureSize, "CCLabelBMFont: page can't be larger than supported");
// scaleH. sanity check
index = line.find("scaleH=") + strlen("scaleH=");
index2 = line.find(' ', index);
value = line.substr(index, index2-index);
CCASSERT(atoi(value.c_str()) <= Configuration::getInstance()->getMaxTextureSize(), "CCLabelBMFont: page can't be larger than supported");
tmp = strstr(tmp, "scaleH=") + 7;
sscanf(tmp, "%d", &value);
CCASSERT(value <= maxTextureSize, "CCLabelBMFont: page can't be larger than supported");
// pages. sanity check
index = line.find("pages=") + strlen("pages=");
index2 = line.find(' ', index);
value = line.substr(index, index2-index);
CCASSERT(atoi(value.c_str()) == 1, "CCBitfontAtlas: only supports 1 page");
tmp = strstr(tmp, "pages=") + 6;
sscanf(tmp, "%d", &value);
CCASSERT(value == 1, "CCBitfontAtlas: only supports 1 page");
// packed (ignore) What does this mean ??
}
void BMFontConfiguration::parseCharacterDefinition(std::string line, BMFontDef *characterDefinition)
void BMFontConfiguration::parseCharacterDefinition(const char* line, BMFontDef *characterDefinition)
{
//////////////////////////////////////////////////////////////////////////
// line to parse:
@ -589,75 +584,48 @@ void BMFontConfiguration::parseCharacterDefinition(std::string line, BMFontDef *
//////////////////////////////////////////////////////////////////////////
// Character ID
auto index = line.find("id=");
auto index2 = line.find(' ', index);
std::string value = line.substr(index, index2-index);
sscanf(value.c_str(), "id=%u", &characterDefinition->charID);
auto tmp = strstr(line, "id=") + 3;
sscanf(tmp, "%u", &characterDefinition->charID);
// Character x
index = line.find("x=");
index2 = line.find(' ', index);
value = line.substr(index, index2-index);
sscanf(value.c_str(), "x=%f", &characterDefinition->rect.origin.x);
tmp = strstr(tmp, "x=") + 2;
sscanf(tmp, "%f", &characterDefinition->rect.origin.x);
// Character y
index = line.find("y=");
index2 = line.find(' ', index);
value = line.substr(index, index2-index);
sscanf(value.c_str(), "y=%f", &characterDefinition->rect.origin.y);
tmp = strstr(tmp, "y=") + 2;
sscanf(tmp, "%f", &characterDefinition->rect.origin.y);
// Character width
index = line.find("width=");
index2 = line.find(' ', index);
value = line.substr(index, index2-index);
sscanf(value.c_str(), "width=%f", &characterDefinition->rect.size.width);
tmp = strstr(tmp, "width=") + 6;
sscanf(tmp, "%f", &characterDefinition->rect.size.width);
// Character height
index = line.find("height=");
index2 = line.find(' ', index);
value = line.substr(index, index2-index);
sscanf(value.c_str(), "height=%f", &characterDefinition->rect.size.height);
tmp = strstr(tmp, "height=") + 7;
sscanf(tmp, "%f", &characterDefinition->rect.size.height);
// Character xoffset
index = line.find("xoffset=");
index2 = line.find(' ', index);
value = line.substr(index, index2-index);
sscanf(value.c_str(), "xoffset=%hd", &characterDefinition->xOffset);
tmp = strstr(tmp, "xoffset=") + 8;
sscanf(tmp, "%hd", &characterDefinition->xOffset);
// Character yoffset
index = line.find("yoffset=");
index2 = line.find(' ', index);
value = line.substr(index, index2-index);
sscanf(value.c_str(), "yoffset=%hd", &characterDefinition->yOffset);
tmp = strstr(tmp, "yoffset=") + 8;
sscanf(tmp, "%hd", &characterDefinition->yOffset);
// Character xadvance
index = line.find("xadvance=");
index2 = line.find(' ', index);
value = line.substr(index, index2-index);
sscanf(value.c_str(), "xadvance=%hd", &characterDefinition->xAdvance);
tmp = strstr(tmp, "xadvance=") + 9;
sscanf(tmp, "%hd", &characterDefinition->xAdvance);
}
void BMFontConfiguration::parseKerningEntry(std::string line)
void BMFontConfiguration::parseKerningEntry(const char* line)
{
//////////////////////////////////////////////////////////////////////////
// line to parse:
// kerning first=121 second=44 amount=-7
//////////////////////////////////////////////////////////////////////////
// first
int first;
auto index = line.find("first=");
auto index2 = line.find(' ', index);
std::string value = line.substr(index, index2-index);
sscanf(value.c_str(), "first=%d", &first);
int first, second, amount;
auto tmp = strstr(line, "first=") + 6;
sscanf(tmp, "%d", &first);
// second
int second;
index = line.find("second=");
index2 = line.find(' ', index);
value = line.substr(index, index2-index);
sscanf(value.c_str(), "second=%d", &second);
tmp = strstr(tmp, "second=") + 7;
sscanf(tmp, "%d", &second);
// amount
int amount;
index = line.find("amount=");
index2 = line.find(' ', index);
value = line.substr(index, index2-index);
sscanf(value.c_str(), "amount=%d", &amount);
tmp = strstr(tmp, "amount=") + 7;
sscanf(tmp, "%d", &amount);
tKerningHashElement *element = (tKerningHashElement *)calloc( sizeof( *element ), 1 );
element->amount = amount;

View File

@ -317,10 +317,10 @@ void Grid3D::beforeBlit()
{
if(_needDepthTestForBlit)
{
_oldDepthTestValue = glIsEnabled(GL_DEPTH_TEST);
_oldDepthTestValue = glIsEnabled(GL_DEPTH_TEST) != GL_FALSE;
GLboolean depthWriteMask;
glGetBooleanv(GL_DEPTH_WRITEMASK, &depthWriteMask);
_oldDepthWriteValue = depthWriteMask;
_oldDepthWriteValue = depthWriteMask != GL_FALSE;
CHECK_GL_ERROR_DEBUG();
glEnable(GL_DEPTH_TEST);
glDepthMask(true);

View File

@ -594,8 +594,9 @@ void LayerColor::onDraw(const Mat4& transform, uint32_t flags)
{
getGLProgram()->use();
getGLProgram()->setUniformsForBuiltins(transform);
GL::enableVertexAttribs( GL::VERTEX_ATTRIB_FLAG_POSITION | GL::VERTEX_ATTRIB_FLAG_COLOR );
//
// Attributes
//
@ -606,10 +607,11 @@ void LayerColor::onDraw(const Mat4& transform, uint32_t flags)
setGLBufferData(_squareColors, 4 * sizeof(Color4F), 1);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_FLOAT, GL_FALSE, 0, 0);
#else
glBindBuffer(GL_ARRAY_BUFFER, 0);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 3, GL_FLOAT, GL_FALSE, 0, _noMVPVertices);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_FLOAT, GL_FALSE, 0, _squareColors);
#endif // EMSCRIPTEN
GL::blendFunc( _blendFunc.src, _blendFunc.dst );
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

View File

@ -1280,7 +1280,7 @@ uint32_t Node::processParentFlags(const Mat4& parentTransform, uint32_t parentFl
bool Node::isVisitableByVisitingCamera() const
{
auto camera = Camera::getVisitingCamera();
bool visibleByCamera = camera ? (unsigned short)camera->getCameraFlag() & _cameraMask : true;
bool visibleByCamera = camera ? ((unsigned short)camera->getCameraFlag() & _cameraMask) != 0 : true;
return visibleByCamera;
}

View File

@ -207,8 +207,14 @@ bool Bundle3D::loadObj(MeshDatas& meshdatas, MaterialDatas& materialdatas, NodeD
materialdatas.resetData();
nodedatas.resetData();
std::string mtlPath = "";
if (mtl_basepath)
mtlPath = mtl_basepath;
else
mtlPath = fullPath.substr(0, fullPath.find_last_of("\\/") + 1).c_str();
ObjLoader::shapes_t shapes;
auto ret = ObjLoader::LoadObj(shapes, fullPath.c_str(), mtl_basepath);
auto ret = ObjLoader::LoadObj(shapes, fullPath.c_str(), mtlPath.c_str());
if (ret.empty())
{
//fill data
@ -1791,7 +1797,7 @@ NodeData* Bundle3D::parseNodesRecursivelyBinary(bool& skeleton)
CCLOG("warning: Failed to read nodedata: uvMapping '%s'.", _path.c_str());
return nullptr;
}
for( int j = 0 ;j < uvMapping ; j++ )
for(int j = 0 ; j < uvMapping ; j++)
{
unsigned int textureIndexSize=0;
if (_binaryReader.read(&textureIndexSize, 4, 1) != 1)
@ -1799,7 +1805,7 @@ NodeData* Bundle3D::parseNodesRecursivelyBinary(bool& skeleton)
CCLOG("warning: Failed to read meshdata: attribCount '%s'.", _path.c_str());
return nullptr;
}
for(int k =0; k < textureIndexSize ; k++ )
for(unsigned int k = 0; k < textureIndexSize ; k++)
{
unsigned int index=0;
if (_binaryReader.read(&index, 4, 1) != 1)

View File

@ -161,7 +161,7 @@ static ssize_t updateVertex( std::map<vertex_index, ssize_t>& vertexCache, std::
return it->second;
}
assert(in_positions.size() > (3*i.v_idx+2));
assert(in_positions.size() > static_cast<size_t>(3*i.v_idx+2));
positions.push_back(in_positions[3*i.v_idx+0]);
positions.push_back(in_positions[3*i.v_idx+1]);

View File

@ -275,7 +275,7 @@ ssize_t Skeleton3D::getBoneCount() const
//get bone
Bone3D* Skeleton3D::getBoneByIndex(unsigned int index) const
{
if (index < _bones.size())
if (index < static_cast<unsigned int>(_bones.size()))
return _bones.at(index);
return nullptr;

View File

@ -54,7 +54,7 @@ const float AudioEngine::TIME_UNKNOWN = -1.0f;
std::unordered_map<std::string,std::list<int>> AudioEngine::_audioPathIDMap;
//profileName,ProfileHelper
std::unordered_map<std::string, AudioEngine::ProfileHelper> AudioEngine::_audioPathProfileHelperMap;
int AudioEngine::_maxInstances = MAX_AUDIOINSTANCES;
unsigned int AudioEngine::_maxInstances = MAX_AUDIOINSTANCES;
AudioEngine::ProfileHelper* AudioEngine::_defaultProfileHelper = nullptr;
std::unordered_map<int, AudioEngine::AudioInfo> AudioEngine::_audioIDInfoMap;
AudioEngineImpl* AudioEngine::_audioEngineImpl = nullptr;

View File

@ -262,7 +262,7 @@ protected:
//profileName,ProfileHelper
static std::unordered_map<std::string, ProfileHelper> _audioPathProfileHelperMap;
static int _maxInstances;
static unsigned int _maxInstances;
static ProfileHelper* _defaultProfileHelper;

View File

@ -36,7 +36,7 @@
// The renderer[android:GLSurfaceView.Renderer WP8:Cocos2dRenderer] was recreated.
// This message is used for reloading resources before renderer is recreated on Android/WP8.
// This message is posted in cocos/platform/android/javaactivity.cpp and cocos\platform\wp8-xaml\cpp\Cocos2dRenderer.cpp.
#define EVENT_RENDERER_RECREATED "event_renderer_recreated"
#define EVENT_RENDERER_RECREATED "event_renderer_recreated"
// The application will come to background.
// This message is used for doing something before coming to background, such as save RenderTexture.

View File

@ -249,7 +249,7 @@ protected:
_allocated += _pageSize;
size_t aligned_size = AllocatorBase::nextPow2BlockSize(block_size);
uint8_t* block = (uint8_t*)p;
for (int i = 0; i < _pageSize; ++i, block += aligned_size)
for (unsigned int i = 0; i < _pageSize; ++i, block += aligned_size)
{
push_front(block);
}

View File

@ -44,7 +44,7 @@ public:
template<typename T>
static inline T random_int(T min, T max) {
std::uniform_int_distribution<> dist(min, max);
std::uniform_int_distribution<T> dist(min, max);
auto &mt = RandomHelper::getEngine();
return dist(mt);
}
@ -57,7 +57,7 @@ private:
*/
template<typename T>
inline T random(T min, T max) {
return RandomHelper::random_int(min, max);
return RandomHelper::random_int<T>(min, max);
}
template<>

View File

@ -566,14 +566,14 @@ Frame* ActionTimelineCache::loadVisibleFrameWithFlatBuffers(const flatbuffers::B
{
VisibleFrame* frame = VisibleFrame::create();
bool visible = flatbuffers->value();
bool visible = flatbuffers->value() != 0;
frame->setVisible(visible);
int frameIndex = flatbuffers->frameIndex();
frame->setFrameIndex(frameIndex);
bool tween = flatbuffers->tween();
bool tween = flatbuffers->tween() != 0;
frame->setTween(tween);
return frame;
@ -590,7 +590,7 @@ Frame* ActionTimelineCache::loadPositionFrameWithFlatBuffers(const flatbuffers::
int frameIndex = flatbuffers->frameIndex();
frame->setFrameIndex(frameIndex);
bool tween = flatbuffers->tween();
bool tween = flatbuffers->tween() != 0;
frame->setTween(tween);
return frame;
@ -608,7 +608,7 @@ Frame* ActionTimelineCache::loadScaleFrameWithFlatBuffers(const flatbuffers::Sca
int frameIndex = flatbuffers->frameIndex();
frame->setFrameIndex(frameIndex);
bool tween = flatbuffers->tween();
bool tween = flatbuffers->tween() != 0;
frame->setTween(tween);
return frame;
@ -626,7 +626,7 @@ Frame* ActionTimelineCache::loadRotationSkewFrameWithFlatBuffers(const flatbuffe
int frameIndex = flatbuffers->frameIndex();
frame->setFrameIndex(frameIndex);
bool tween = flatbuffers->tween();
bool tween = flatbuffers->tween() != 0;
frame->setTween(tween);
return frame;
@ -643,7 +643,7 @@ Frame* ActionTimelineCache::loadColorFrameWithFlatBuffers(const flatbuffers::Col
int frameIndex = flatbuffers->frameIndex();
frame->setFrameIndex(frameIndex);
bool tween = flatbuffers->tween();
bool tween = flatbuffers->tween() != 0;
frame->setTween(tween);
return frame;
@ -700,7 +700,7 @@ Frame* ActionTimelineCache::loadTextureFrameWithFlatBuffers(const flatbuffers::T
int frameIndex = flatbuffers->frameIndex();
frame->setFrameIndex(frameIndex);
bool tween = flatbuffers->tween();
bool tween = flatbuffers->tween() != 0;
frame->setTween(tween);
return frame;
@ -720,7 +720,7 @@ Frame* ActionTimelineCache::loadEventFrameWithFlatBuffers(const flatbuffers::Eve
int frameIndex = flatbuffers->frameIndex();
frame->setFrameIndex(frameIndex);
bool tween = flatbuffers->tween();
bool tween = flatbuffers->tween() != 0;
frame->setTween(tween);
return frame;
@ -737,7 +737,7 @@ Frame* ActionTimelineCache::loadAlphaFrameWithFlatBuffers(const flatbuffers::Int
int frameIndex = flatbuffers->frameIndex();
frame->setFrameIndex(frameIndex);
bool tween = flatbuffers->tween();
bool tween = flatbuffers->tween() != 0;
frame->setTween(tween);
return frame;
@ -754,7 +754,7 @@ Frame* ActionTimelineCache::loadAlphaFrameWithFlatBuffers(const flatbuffers::Int
int frameIndex = flatbuffers->frameIndex();
frame->setFrameIndex(frameIndex);
bool tween = flatbuffers->tween();
bool tween = flatbuffers->tween() != 0;
frame->setTween(tween);
return frame;
@ -771,7 +771,7 @@ Frame* ActionTimelineCache::loadZOrderFrameWithFlatBuffers(const flatbuffers::In
int frameIndex = flatbuffers->frameIndex();
frame->setFrameIndex(frameIndex);
bool tween = flatbuffers->tween();
bool tween = flatbuffers->tween() != 0;
frame->setTween(tween);
return frame;
@ -790,7 +790,7 @@ Frame* ActionTimelineCache::loadInnerActionFrameWithFlatBuffers(const flatbuffer
int frameIndex = flatbuffers->frameIndex();
frame->setFrameIndex(frameIndex);
bool tween = flatbuffers->tween();
bool tween = flatbuffers->tween() != 0;
frame->setTween(tween);
frame->setInnerActionType(innerActionType);

View File

@ -525,7 +525,7 @@ void InnerActionFrame::onEnter(Frame *nextFrame, int currentFrameIndex)
}
}
void InnerActionFrame::setStartFrameIndex(int frameIndex) throw()
void InnerActionFrame::setStartFrameIndex(int frameIndex)
{
if(_enterWithName)
{
@ -536,7 +536,7 @@ void InnerActionFrame::setStartFrameIndex(int frameIndex) throw()
}
void InnerActionFrame::setEndFrameIndex(int frameIndex) throw()
void InnerActionFrame::setEndFrameIndex(int frameIndex)
{
if(_enterWithName)
{
@ -546,7 +546,7 @@ void InnerActionFrame::setEndFrameIndex(int frameIndex) throw()
_endFrameIndex = frameIndex;
}
void InnerActionFrame::setAnimationName(const std::string& animationName) throw()
void InnerActionFrame::setAnimationName(const std::string& animationName)
{
if(!_enterWithName)
{

View File

@ -268,13 +268,13 @@ public:
inline void setEnterWithName(bool isEnterWithName) { _enterWithName = isEnterWithName;}
void setStartFrameIndex(int frameIndex) throw();
void setStartFrameIndex(int frameIndex);
inline int getStartFrameIndex() const { return _startFrameIndex; }
void setEndFrameIndex(int frameIndex) throw();
void setEndFrameIndex(int frameIndex);
inline int getEndFrameIndex() const { return _endFrameIndex; }
void setAnimationName(const std::string& animationNamed) throw();
void setAnimationName(const std::string& animationNamed);
inline void setSingleFrameIndex(int frameIndex) { _singleFrameIndex = frameIndex;}
inline int getSingleFrameIndex() const { return _singleFrameIndex;}

View File

@ -544,7 +544,7 @@ namespace cocostudio
Button* button = static_cast<Button*>(node);
auto options = (ButtonOptions*)buttonOptions;
bool scale9Enabled = options->scale9Enabled();
bool scale9Enabled = options->scale9Enabled() != 0;
button->setScale9Enabled(scale9Enabled);
bool normalFileExist = false;
@ -777,7 +777,7 @@ namespace cocostudio
}
}
bool displaystate = options->displaystate();
bool displaystate = options->displaystate() != 0;
button->setBright(displaystate);
button->setEnabled(displaystate);

View File

@ -753,10 +753,10 @@ namespace cocostudio
checkBox->addChild(label);
}
bool selectedstate = options->selectedState();
bool selectedstate = options->selectedState() != 0;
checkBox->setSelected(selectedstate);
bool displaystate = options->displaystate();
bool displaystate = options->displaystate() != 0;
checkBox->setBright(displaystate);
checkBox->setEnabled(displaystate);

View File

@ -181,11 +181,10 @@ namespace cocostudio
break;
}
bool loop = options->loop();
bool loop = options->loop() != 0;
audio->setLoop(loop);
audio->setName(options->name()->c_str());
audio->setLoop(options->loop());
return component;
}

View File

@ -24,6 +24,8 @@
#include "GameMapReader.h"
#include "2d/CCTMXXMLParser.h"
#include "cocostudio/CSParseBinary_generated.h"
#include "cocostudio/WidgetReader/NodeReader/NodeReader.h"
@ -159,6 +161,77 @@ namespace cocostudio
}
if (fileExist)
{
/* Whether tileset is valid. */
auto mapInfo = TMXMapInfo::create(path);
auto& layers = mapInfo->getLayers();
bool valid = false;
std::string layerName = "";
for (const auto &layerInfo : layers)
{
valid = false;
if (layerInfo->_visible)
{
Size size = layerInfo->_layerSize;
auto& tilesets = mapInfo->getTilesets();
if (tilesets.size()>0)
{
TMXTilesetInfo* tileset = nullptr;
for (auto iter = tilesets.crbegin(); iter != tilesets.crend(); ++iter)
{
tileset = *iter;
if (tileset)
{
for( int y=0; y < size.height; y++ )
{
for( int x=0; x < size.width; x++ )
{
int pos = static_cast<int>(x + size.width * y);
int gid = layerInfo->_tiles[ pos ];
if( gid != 0 )
{
if( (gid & kTMXFlippedMask) >= tileset->_firstGid )
{
valid = true;
break;
}
}
}
if (valid)
{
break;
}
}
}
}
}
if (!valid)
{
layerName = layerInfo->_name;
break;
}
}
else
{
valid = true;
}
}
if (!valid)
{
Node* node = Node::create();
setPropsWithFlatBuffers(node, (Table*)gameMapOptions);
auto label = Label::create();
label->setString(__String::createWithFormat("Some error of gid are in TMX Layer '%s'", layerName.c_str())->getCString());
node->setScale(1.0f);
node->addChild(label);
return node;
}
/**/
tmx = TMXTiledMap::create(path);
if (tmx)
{

View File

@ -355,7 +355,7 @@ namespace cocostudio
imageView->addChild(label);
}
bool scale9Enabled = options->scale9Enabled();
bool scale9Enabled = options->scale9Enabled() != 0;
imageView->setScale9Enabled(scale9Enabled);
auto widgetReader = WidgetReader::getInstance();

View File

@ -570,10 +570,10 @@ namespace cocostudio
Layout* panel = static_cast<Layout*>(node);
auto options = (PanelOptions*)layoutOptions;
bool clipEnabled = options->clipEnabled();
bool clipEnabled = options->clipEnabled() != 0;
panel->setClippingEnabled(clipEnabled);
bool backGroundScale9Enabled = options->backGroundScale9Enabled();
bool backGroundScale9Enabled = options->backGroundScale9Enabled() != 0;
panel->setBackGroundImageScale9Enabled(backGroundScale9Enabled);

View File

@ -398,10 +398,10 @@ namespace cocostudio
ListView* listView = static_cast<ListView*>(node);
auto options = (ListViewOptions*)listViewOptions;
bool clipEnabled = options->clipEnabled();
bool clipEnabled = options->clipEnabled() != 0;
listView->setClippingEnabled(clipEnabled);
bool backGroundScale9Enabled = options->backGroundScale9Enabled();
bool backGroundScale9Enabled = options->backGroundScale9Enabled() != 0;
listView->setBackGroundImageScale9Enabled(backGroundScale9Enabled);
@ -506,7 +506,7 @@ namespace cocostudio
listView->setInnerContainerSize(innerSize);
// int direction = options->direction();
// listView->setDirection((ScrollView::Direction)direction);
bool bounceEnabled = options->bounceEnabled();
bool bounceEnabled = options->bounceEnabled() != 0;
listView->setBounceEnabled(bounceEnabled);
// int gravityValue = options->gravity();

View File

@ -472,7 +472,7 @@ namespace cocostudio
int zorder = options->zOrder();
int tag = options->tag();
int actionTag = options->actionTag();
bool visible = options->visible();
bool visible = options->visible() != 0;
float w = options->size()->width();
float h = options->size()->height();
int alpha = options->alpha();
@ -521,16 +521,16 @@ namespace cocostudio
auto layoutComponent = ui::LayoutComponent::bindLayoutComponent(node);
bool positionXPercentEnabled = layoutComponentTable->positionXPercentEnabled();
bool positionYPercentEnabled = layoutComponentTable->positionYPercentEnabled();
bool positionXPercentEnabled = layoutComponentTable->positionXPercentEnabled() != 0;
bool positionYPercentEnabled = layoutComponentTable->positionYPercentEnabled() != 0;
float positionXPercent = layoutComponentTable->positionXPercent();
float positionYPercent = layoutComponentTable->positionYPercent();
bool sizeXPercentEnable = layoutComponentTable->sizeXPercentEnable();
bool sizeYPercentEnable = layoutComponentTable->sizeYPercentEnable();
bool sizeXPercentEnable = layoutComponentTable->sizeXPercentEnable() != 0;
bool sizeYPercentEnable = layoutComponentTable->sizeYPercentEnable() != 0;
float sizeXPercent = layoutComponentTable->sizeXPercent();
float sizeYPercent = layoutComponentTable->sizeYPercent();
bool stretchHorizontalEnabled = layoutComponentTable->stretchHorizontalEnabled();
bool stretchVerticalEnabled = layoutComponentTable->stretchVerticalEnabled();
bool stretchHorizontalEnabled = layoutComponentTable->stretchHorizontalEnabled() != 0;
bool stretchVerticalEnabled = layoutComponentTable->stretchVerticalEnabled() != 0;
std::string horizontalEdge = layoutComponentTable->horizontalEdge()->c_str();
std::string verticalEdge = layoutComponentTable->verticalEdge()->c_str();
float leftMargin = layoutComponentTable->leftMargin();

View File

@ -311,10 +311,10 @@ namespace cocostudio
PageView* pageView = static_cast<PageView*>(node);
auto options = (PageViewOptions*)pageViewOptions;
bool clipEnabled = options->clipEnabled();
bool clipEnabled = options->clipEnabled() != 0;
pageView->setClippingEnabled(clipEnabled);
bool backGroundScale9Enabled = options->backGroundScale9Enabled();
bool backGroundScale9Enabled = options->backGroundScale9Enabled() != 0;
pageView->setBackGroundImageScale9Enabled(backGroundScale9Enabled);

View File

@ -397,10 +397,10 @@ namespace cocostudio
ScrollView* scrollView = static_cast<ScrollView*>(node);
auto options = (ScrollViewOptions*)scrollViewOptions;
bool clipEnabled = options->clipEnabled();
bool clipEnabled = options->clipEnabled() != 0;
scrollView->setClippingEnabled(clipEnabled);
bool backGroundScale9Enabled = options->backGroundScale9Enabled();
bool backGroundScale9Enabled = options->backGroundScale9Enabled() != 0;
scrollView->setBackGroundImageScale9Enabled(backGroundScale9Enabled);
@ -505,7 +505,7 @@ namespace cocostudio
scrollView->setInnerContainerSize(innerSize);
int direction = options->direction();
scrollView->setDirection((ScrollView::Direction)direction);
bool bounceEnabled = options->bounceEnabled();
bool bounceEnabled = options->bounceEnabled() != 0;
scrollView->setBounceEnabled(bounceEnabled);

View File

@ -787,7 +787,7 @@ namespace cocostudio
slider->addChild(label);
}
bool displaystate = options->displaystate();
bool displaystate = options->displaystate() != 0;
slider->setBright(displaystate);
slider->setEnabled(displaystate);

View File

@ -224,8 +224,8 @@ namespace cocostudio
sprite->setColor(Color3B(red, green, blue));
}
bool flipX = nodeOptions->flipX();
bool flipY = nodeOptions->flipY();
bool flipX = nodeOptions->flipX() != 0;
bool flipY = nodeOptions->flipY() != 0;
if(flipX != false)
sprite->setFlippedX(flipX);

View File

@ -291,7 +291,7 @@ namespace cocostudio
std::string fontName = options->fontName()->c_str();
textField->setFontName(fontName);
bool maxLengthEnabled = options->maxLengthEnabled();
bool maxLengthEnabled = options->maxLengthEnabled() != 0;
textField->setMaxLengthEnabled(maxLengthEnabled);
if (maxLengthEnabled)
@ -299,7 +299,7 @@ namespace cocostudio
int maxLength = options->maxLength();
textField->setMaxLength(maxLength);
}
bool passwordEnabled = options->passwordEnabled();
bool passwordEnabled = options->passwordEnabled() != 0;
textField->setPasswordEnabled(passwordEnabled);
if (passwordEnabled)
{

View File

@ -292,7 +292,7 @@ namespace cocostudio
Text* label = static_cast<Text*>(node);
auto options = (TextOptions*)textOptions;
bool touchScaleEnabled = options->touchScaleEnable();
bool touchScaleEnabled = options->touchScaleEnable() != 0;
label->setTouchScaleChangeEnabled(touchScaleEnabled);
std::string text = options->text()->c_str();
@ -348,7 +348,7 @@ namespace cocostudio
label->setUnifySizeEnabled(false);
bool IsCustomSize = options->isCustomSize();
bool IsCustomSize = options->isCustomSize() != 0;
label->ignoreContentAdaptWithSize(!IsCustomSize);
auto widgetOptions = options->widgetOptions();

View File

@ -772,7 +772,7 @@ namespace cocostudio
widget->setAnchorPoint(Vec2::ZERO);
widget->setUnifySizeEnabled(true);
bool ignoreSize = options->ignoreSize();
bool ignoreSize = options->ignoreSize() != 0;
widget->ignoreContentAdaptWithSize(ignoreSize);
widget->setUnifySizeEnabled(false);
@ -788,7 +788,7 @@ namespace cocostudio
widget->setActionTag(actionTag);
widget->setUserObject(timeline::ActionTimelineData::create(actionTag));
bool touchEnabled = options->touchEnabled();
bool touchEnabled = options->touchEnabled() != 0;
widget->setTouchEnabled(touchEnabled);
std::string name = options->name()->c_str();
@ -807,7 +807,7 @@ namespace cocostudio
float rotationSkewY = options->rotationSkew()->rotationSkewY();
widget->setRotationSkewY(rotationSkewY);
bool visible = options->visible();
bool visible = options->visible() != 0;
widget->setVisible(visible);
int zOrder = options->zOrder();
@ -824,9 +824,9 @@ namespace cocostudio
Vec2 anchorPoint(f_anchorPoint->scaleX(), f_anchorPoint->scaleY());
widget->setAnchorPoint(anchorPoint);
bool flippedX = options->flipX();
bool flippedX = options->flipX() != 0;
widget->setFlippedX(flippedX);
bool flippedY = options->flipY();
bool flippedY = options->flipY() != 0;
widget->setFlippedY(flippedY);
std::string callbackType = options->callBackType()->c_str();
@ -844,16 +844,16 @@ namespace cocostudio
auto layoutComponent = ui::LayoutComponent::bindLayoutComponent(node);
bool positionXPercentEnabled = layoutComponentTable->positionXPercentEnabled();
bool positionYPercentEnabled = layoutComponentTable->positionYPercentEnabled();
bool positionXPercentEnabled = layoutComponentTable->positionXPercentEnabled() != 0;
bool positionYPercentEnabled = layoutComponentTable->positionYPercentEnabled() != 0;
float positionXPercent = layoutComponentTable->positionXPercent();
float positionYPercent = layoutComponentTable->positionYPercent();
bool sizeXPercentEnable = layoutComponentTable->sizeXPercentEnable();
bool sizeYPercentEnable = layoutComponentTable->sizeYPercentEnable();
bool sizeXPercentEnable = layoutComponentTable->sizeXPercentEnable() != 0;
bool sizeYPercentEnable = layoutComponentTable->sizeYPercentEnable() != 0;
float sizeXPercent = layoutComponentTable->sizeXPercent();
float sizeYPercent = layoutComponentTable->sizeYPercent();
bool stretchHorizontalEnabled = layoutComponentTable->stretchHorizontalEnabled();
bool stretchVerticalEnabled = layoutComponentTable->stretchVerticalEnabled();
bool stretchHorizontalEnabled = layoutComponentTable->stretchHorizontalEnabled() != 0;
bool stretchVerticalEnabled = layoutComponentTable->stretchVerticalEnabled() != 0;
std::string horizontalEdge = layoutComponentTable->horizontalEdge()->c_str();
std::string verticalEdge = layoutComponentTable->verticalEdge()->c_str();
float leftMargin = layoutComponentTable->leftMargin();

View File

@ -1103,7 +1103,7 @@ bool FileUtils::createDirectory(const std::string& path)
if ((GetFileAttributesA(path.c_str())) == INVALID_FILE_ATTRIBUTES)
{
subpath = "";
for (int i = 0; i < dirs.size(); ++i)
for (unsigned int i = 0; i < dirs.size(); ++i)
{
subpath += dirs[i];
if (!isDirectoryExist(subpath))

View File

@ -54,7 +54,6 @@ public class Cocos2dxWebViewHelper {
onJsCallback(index, message);
}
@SuppressWarnings("unused")
public static int createWebView() {
final int index = viewTag;
sCocos2dxActivity.runOnUiThread(new Runnable() {
@ -72,7 +71,6 @@ public class Cocos2dxWebViewHelper {
return viewTag++;
}
@SuppressWarnings("unused")
public static void removeWebView(final int index) {
sCocos2dxActivity.runOnUiThread(new Runnable() {
@Override
@ -86,7 +84,6 @@ public class Cocos2dxWebViewHelper {
});
}
@SuppressWarnings("unused")
public static void setVisible(final int index, final boolean visible) {
sCocos2dxActivity.runOnUiThread(new Runnable() {
@Override
@ -99,7 +96,6 @@ public class Cocos2dxWebViewHelper {
});
}
@SuppressWarnings("unused")
public static void setWebViewRect(final int index, final int left, final int top, final int maxWidth, final int maxHeight) {
sCocos2dxActivity.runOnUiThread(new Runnable() {
@Override
@ -112,7 +108,6 @@ public class Cocos2dxWebViewHelper {
});
}
@SuppressWarnings("unused")
public static void setJavascriptInterfaceScheme(final int index, final String scheme) {
sCocos2dxActivity.runOnUiThread(new Runnable() {
@Override
@ -125,33 +120,30 @@ public class Cocos2dxWebViewHelper {
});
}
@SuppressWarnings("unused")
public static void loadData(final int index, final String data, final String mimeType, final String encoding, final String baseURL) {
sCocos2dxActivity.runOnUiThread(new Runnable() {
@Override
public void run() {
Cocos2dxWebView webView = webViews.get(index);
if (webView != null) {
webView.loadDataWithBaseURL(baseURL, data, mimeType, encoding, null);
webView.loadDataWithBaseURL(baseURL, data, mimeType, encoding, null);
}
}
});
}
@SuppressWarnings("unused")
public static void loadHTMLString(final int index, final String htmlString, final String mimeType, final String encoding) {
public static void loadHTMLString(final int index, final String data, final String baseUrl) {
sCocos2dxActivity.runOnUiThread(new Runnable() {
@Override
public void run() {
Cocos2dxWebView webView = webViews.get(index);
if (webView != null) {
webView.loadData(htmlString, mimeType, encoding);
webView.loadDataWithBaseURL(baseUrl, data, null, null, null);
}
}
});
}
@SuppressWarnings("unused")
public static void loadUrl(final int index, final String url) {
sCocos2dxActivity.runOnUiThread(new Runnable() {
@Override
@ -164,7 +156,6 @@ public class Cocos2dxWebViewHelper {
});
}
@SuppressWarnings("unused")
public static void loadFile(final int index, final String filePath) {
if (CocosPlayClient.isEnabled() && !CocosPlayClient.isDemo()) {
CocosPlayClient.updateAssets(filePath);
@ -212,7 +203,6 @@ public class Cocos2dxWebViewHelper {
return task.get();
}
@SuppressWarnings("unused")
public static boolean canGoBack(final int index) {
Callable<Boolean> callable = new Callable<Boolean>() {
@Override
@ -230,7 +220,6 @@ public class Cocos2dxWebViewHelper {
}
}
@SuppressWarnings("unused")
public static boolean canGoForward(final int index) {
Callable<Boolean> callable = new Callable<Boolean>() {
@Override
@ -248,7 +237,6 @@ public class Cocos2dxWebViewHelper {
}
}
@SuppressWarnings("unused")
public static void goBack(final int index) {
sCocos2dxActivity.runOnUiThread(new Runnable() {
@Override
@ -261,7 +249,6 @@ public class Cocos2dxWebViewHelper {
});
}
@SuppressWarnings("unused")
public static void goForward(final int index) {
sCocos2dxActivity.runOnUiThread(new Runnable() {
@Override
@ -274,7 +261,6 @@ public class Cocos2dxWebViewHelper {
});
}
@SuppressWarnings("unused")
public static void evaluateJS(final int index, final String js) {
sCocos2dxActivity.runOnUiThread(new Runnable() {
@Override
@ -287,7 +273,6 @@ public class Cocos2dxWebViewHelper {
});
}
@SuppressWarnings("unused")
public static void setScalesPageToFit(final int index, final boolean scalesPageToFit) {
sCocos2dxActivity.runOnUiThread(new Runnable() {
@Override

View File

@ -222,9 +222,11 @@ void enableVertexAttribs(uint32_t flags)
// hardcoded!
for(int i=0; i < MAX_ATTRIBUTES; i++) {
unsigned int bit = 1 << i;
bool enabled = flags & bit;
bool enabledBefore = s_attributeFlags & bit;
if(enabled != enabledBefore) {
//FIXME:Cache is disabled, try to enable cache as before
bool enabled = (flags & bit) != 0;
bool enabledBefore = (s_attributeFlags & bit) != 0;
if(enabled != enabledBefore)
{
if( enabled )
glEnableVertexAttribArray(i);
else

View File

@ -842,6 +842,19 @@ int LuaStack::luaLoadChunksFromZIP(lua_State *L)
ssize_t bufferSize = 0;
unsigned char *zbuffer = zip->getFileData(filename.c_str(), &bufferSize);
if (bufferSize) {
// remove extension
std::size_t found = filename.rfind(".lua");
if (found != std::string::npos)
{
filename.erase(found);
}
// replace path seperator '/' '\' to '.'
for (int i=0; i<filename.size(); i++) {
if (filename[i] == '/' || filename[i] == '\\') {
filename[i] = '.';
}
}
CCLOG("[luaLoadChunksFromZIP] add %s to preload", filename.c_str());
if (stack->luaLoadBuffer(L, (char*)zbuffer, (int)bufferSize, filename.c_str()) == 0) {
lua_setfield(L, -2, filename.c_str());
++count;

View File

@ -839,7 +839,7 @@ bool luaval_to_fontdefinition(lua_State* L, int lo, FontDefinition* outValue , c
lua_pushstring(L, "fontName");
lua_gettable(L,lo);
outValue->_fontName = tolua_tocppstring(L,lo,defautlFontName);
outValue->_fontName = tolua_tocppstring(L, lua_gettop(L), defautlFontName);
lua_pop(L,1);
lua_pushstring(L, "fontSize");
@ -861,7 +861,7 @@ bool luaval_to_fontdefinition(lua_State* L, int lo, FontDefinition* outValue , c
lua_gettable(L,lo);
if (!lua_isnil(L,-1))
{
luaval_to_color3b(L, -1, &outValue->_fontFillColor);
luaval_to_color3b(L, lua_gettop(L), &outValue->_fontFillColor);
}
lua_pop(L,1);
@ -869,7 +869,7 @@ bool luaval_to_fontdefinition(lua_State* L, int lo, FontDefinition* outValue , c
lua_gettable(L,lo);
if (!lua_isnil(L,-1))
{
luaval_to_size(L, -1, &outValue->_dimensions);
luaval_to_size(L, lua_gettop(L), &outValue->_dimensions);
}
lua_pop(L,1);
@ -890,7 +890,7 @@ bool luaval_to_fontdefinition(lua_State* L, int lo, FontDefinition* outValue , c
lua_gettable(L,lo);
if (!lua_isnil(L,-1))
{
luaval_to_size(L, -1, &outValue->_shadow._shadowOffset);
luaval_to_size(L, lua_gettop(L), &outValue->_shadow._shadowOffset);
}
lua_pop(L,1);
@ -927,7 +927,7 @@ bool luaval_to_fontdefinition(lua_State* L, int lo, FontDefinition* outValue , c
lua_gettable(L,lo);
if (!lua_isnil(L,-1))
{
luaval_to_color3b(L, -1, &outValue->_stroke._strokeColor);
luaval_to_color3b(L, lua_gettop(L), &outValue->_stroke._strokeColor);
}
lua_pop(L,1);

View File

@ -694,11 +694,11 @@ static int tolua_Cocos2d_glClearColor00(lua_State* tolua_S)
else
#endif
{
unsigned int red = (unsigned int)tolua_tonumber(tolua_S,1,0);
unsigned int green = (unsigned int)tolua_tonumber(tolua_S,2,0);
unsigned int blue = (unsigned int)tolua_tonumber(tolua_S,3,0);
unsigned int alpha = (unsigned int)tolua_tonumber(tolua_S,4,0);
glClearColor((GLclampf)red , (GLclampf)green , (GLclampf)blue , (GLclampf)alpha);
GLclampf red = (GLclampf)tolua_tonumber(tolua_S,1,0);
GLclampf green = (GLclampf)tolua_tonumber(tolua_S,2,0);
GLclampf blue = (GLclampf)tolua_tonumber(tolua_S,3,0);
GLclampf alpha = (GLclampf)tolua_tonumber(tolua_S,4,0);
glClearColor(red , green , blue , alpha);
}
return 0;
#ifndef TOLUA_RELEASE

View File

@ -517,6 +517,8 @@ void EditBoxImplWin::doAnimationWhenKeyboardMove(float duration, float distance)
{
}
static const int CC_EDIT_BOX_PADDING = 5;
bool EditBoxImplWin::initWithSize(const Size& size)
{
//! int fontSize = getFontSizeAccordingHeightJni(size.height-12);
@ -524,7 +526,7 @@ bool EditBoxImplWin::initWithSize(const Size& size)
_label->setSystemFontSize(size.height-12);
// align the text vertically center
_label->setAnchorPoint(Vec2(0, 0.5f));
_label->setPosition(Vec2(5, size.height / 2.0f));
_label->setPosition(Vec2(CC_EDIT_BOX_PADDING, size.height / 2.0f));
_label->setColor(_colText);
_editBox->addChild(_label);
@ -532,7 +534,7 @@ bool EditBoxImplWin::initWithSize(const Size& size)
_labelPlaceHolder->setSystemFontSize(size.height-12);
// align the text vertically center
_labelPlaceHolder->setAnchorPoint(Vec2(0, 0.5f));
_labelPlaceHolder->setPosition(5, size.height / 2.0f);
_labelPlaceHolder->setPosition(CC_EDIT_BOX_PADDING, size.height / 2.0f);
_labelPlaceHolder->setVisible(false);
_labelPlaceHolder->setColor(_colPlaceHolder);
_editBox->addChild(_labelPlaceHolder);
@ -631,7 +633,14 @@ void EditBoxImplWin::setText(const char* pText)
//! std::string strWithEllipsis = getStringWithEllipsisJni(strToShow.c_str(), _editSize.width, _editSize.height-12);
//! _label->setString(strWithEllipsis.c_str());
_label->setString(strToShow.c_str());
_label->setString(strToShow.c_str());
float maxWidth = _editSize.width - 2 * CC_EDIT_BOX_PADDING;
auto labelSize = _label->getContentSize();
if (labelSize.width > maxWidth)
{
_label->setDimensions(maxWidth, labelSize.height);
}
}
else
{

View File

@ -193,11 +193,22 @@ namespace ui {
this->cleanupSlicedSprites();
_protectedChildren.clear();
if(this->_scale9Image != sprite)
if(nullptr != sprite)
{
CC_SAFE_RELEASE(this->_scale9Image);
_scale9Image = sprite;
CC_SAFE_RETAIN(_scale9Image);
if (nullptr == sprite->getSpriteFrame())
{
return false;
}
if (nullptr == _scale9Image)
{
_scale9Image = sprite;
_scale9Image->retain();
}
else
{
_scale9Image->setSpriteFrame(sprite->getSpriteFrame());
}
}
if (!_scale9Image)

View File

@ -594,16 +594,16 @@ const char* TextField::getPasswordStyleText()const
void TextField::update(float dt)
{
if (getAttachWithIME())
{
attachWithIMEEvent();
setAttachWithIME(false);
}
if (getDetachWithIME())
{
detachWithIMEEvent();
setDetachWithIME(false);
}
if (getAttachWithIME())
{
attachWithIMEEvent();
setAttachWithIME(false);
}
if (getInsertText())
{
insertTextEvent();

View File

@ -72,7 +72,7 @@ public:
* @param string The content for the main page.
* @param baseURL The base URL for the content.
*/
void loadHTMLString(const std::string &string, const std::string &baseURL);
void loadHTMLString(const std::string &string, const std::string &baseURL = "");
/**
* Loads the given URL.

View File

@ -41,6 +41,39 @@
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,"",__VA_ARGS__)
static const std::string s_defaultBaseUrl = "file:///android_asset/";
static const std::string s_sdRootBaseUrl = "file://";
static std::string getFixedBaseUrl(const std::string& baseUrl)
{
std::string fixedBaseUrl;
if (baseUrl.empty())
{
fixedBaseUrl = s_defaultBaseUrl;
}
else if (baseUrl.find(s_sdRootBaseUrl) != std::string::npos)
{
fixedBaseUrl = baseUrl;
}
else if (baseUrl.c_str()[0] != '/') {
if(baseUrl.find("assets/") == 0) {
fixedBaseUrl = s_defaultBaseUrl + baseUrl.c_str()[7];
}
else {
fixedBaseUrl = s_defaultBaseUrl + baseUrl;
}
}
else {
fixedBaseUrl = s_sdRootBaseUrl + baseUrl;
}
if (fixedBaseUrl.c_str()[fixedBaseUrl.length() - 1] != '/') {
fixedBaseUrl += "/";
}
return fixedBaseUrl;
}
extern "C" {
/*
* Class: org_cocos2dx_lib_Cocos2dxWebViewHelper
@ -144,7 +177,7 @@ void loadDataJNI(const int index, const std::string &data, const std::string &MI
jstring jData = t.env->NewStringUTF(data.c_str());
jstring jMIMEType = t.env->NewStringUTF(MIMEType.c_str());
jstring jEncoding = t.env->NewStringUTF(encoding.c_str());
jstring jBaseURL = t.env->NewStringUTF(baseURL.c_str());
jstring jBaseURL = t.env->NewStringUTF(getFixedBaseUrl(baseURL).c_str());
t.env->CallStaticVoidMethod(t.classID, t.methodID, index, jData, jMIMEType, jEncoding, jBaseURL);
t.env->DeleteLocalRef(jData);
@ -158,10 +191,10 @@ void loadDataJNI(const int index, const std::string &data, const std::string &MI
void loadHTMLStringJNI(const int index, const std::string &string, const std::string &baseURL) {
// LOGD("error: %s,%d",__func__,__LINE__);
cocos2d::JniMethodInfo t;
if (cocos2d::JniHelper::getStaticMethodInfo(t, CLASS_NAME, "loadHTMLString", "(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V")) {
if (cocos2d::JniHelper::getStaticMethodInfo(t, CLASS_NAME, "loadHTMLString", "(ILjava/lang/String;Ljava/lang/String;)V")) {
jstring jString = t.env->NewStringUTF(string.c_str());
jstring jBaseURL = t.env->NewStringUTF(baseURL.c_str());
t.env->CallStaticVoidMethod(t.classID, t.methodID, index, jString, jBaseURL,nullptr);
jstring jBaseURL = t.env->NewStringUTF(getFixedBaseUrl(baseURL).c_str());
t.env->CallStaticVoidMethod(t.classID, t.methodID, index, jString, jBaseURL);
t.env->DeleteLocalRef(jString);
t.env->DeleteLocalRef(jBaseURL);

View File

@ -34,6 +34,30 @@
#include "platform/CCFileUtils.h"
#include "ui/UIWebView.h"
static std::string getFixedBaseUrl(const std::string& baseUrl)
{
std::string fixedBaseUrl;
if (baseUrl.empty() || baseUrl.c_str()[0] != '/') {
fixedBaseUrl = [[[NSBundle mainBundle] resourcePath] UTF8String];
fixedBaseUrl += "/";
fixedBaseUrl += baseUrl;
}
else {
fixedBaseUrl = baseUrl;
}
size_t pos = 0;
while ((pos = fixedBaseUrl.find(" ")) != std::string::npos) {
fixedBaseUrl.replace(pos, 1, "%20");
}
if (fixedBaseUrl.c_str()[fixedBaseUrl.length() - 1] != '/') {
fixedBaseUrl += "/";
}
return fixedBaseUrl;
}
@interface UIWebViewWrapper : NSObject
@property (nonatomic) std::function<bool(std::string url)> shouldStartLoading;
@property (nonatomic) std::function<void(std::string url)> didFinishLoading;
@ -136,11 +160,11 @@
[self.uiWebView loadData:[NSData dataWithBytes:data.c_str() length:data.length()]
MIMEType:@(MIMEType.c_str())
textEncodingName:@(encodingName.c_str())
baseURL:[NSURL URLWithString:@(baseURL.c_str())]];
baseURL:[NSURL URLWithString:@(getFixedBaseUrl(baseURL).c_str())]];
}
- (void)loadHTMLString:(const std::string &)string baseURL:(const std::string &)baseURL {
[self.uiWebView loadHTMLString:@(string.c_str()) baseURL:[NSURL URLWithString:@(baseURL.c_str())]];
[self.uiWebView loadHTMLString:@(string.c_str()) baseURL:[NSURL URLWithString:@(getFixedBaseUrl(baseURL).c_str())]];
}
- (void)loadUrl:(const std::string &)urlString {

View File

@ -823,7 +823,7 @@ void AssetsManagerEx::onProgress(double total, double downloaded, const std::str
{
if (customId == VERSION_ID || customId == MANIFEST_ID)
{
_percent = 100 * (total - downloaded) / total;
_percent = 100 * downloaded / total;
// Notify progression event
dispatchUpdateEvent(EventAssetsManagerEx::EventCode::UPDATE_PROGRESSION, customId);
return;
@ -865,7 +865,7 @@ void AssetsManagerEx::onProgress(double total, double downloaded, const std::str
if ((int)currentPercent != (int)_percent) {
_percent = currentPercent;
// Notify progression event
dispatchUpdateEvent(EventAssetsManagerEx::EventCode::UPDATE_PROGRESSION, "");
dispatchUpdateEvent(EventAssetsManagerEx::EventCode::UPDATE_PROGRESSION, customId);
}
}
}

View File

@ -52,7 +52,7 @@ size_t bufferWriteFunc(void *ptr, size_t size, size_t nmemb, void *userdata)
Downloader::StreamData *streamBuffer = (Downloader::StreamData *)userdata;
size_t written = size * nmemb;
// Avoid pointer overflow
if (streamBuffer->offset + written <= streamBuffer->total)
if (streamBuffer->offset + written <= static_cast<size_t>(streamBuffer->total))
{
memcpy(streamBuffer->buffer + streamBuffer->offset, ptr, written);
streamBuffer->offset += written;

View File

@ -144,7 +144,7 @@ bool Manifest::versionEquals(const Manifest *b) const
return false;
// Check groups version
for (int i = 0; i < _groups.size(); ++i) {
for (unsigned int i = 0; i < _groups.size(); ++i) {
std::string gid =_groups[i];
// Check group name
if (gid != bGroups[i])

2
plugin

@ -1 +1 @@
Subproject commit 3609894790678a7a3a9e66cefe881f75534f98b0
Subproject commit dc25546289ab18dd273199124dada948638eb5e1

View File

@ -55,6 +55,9 @@ static AppDelegate s_sharedApplication;
sharegroup: nil
multiSampling: NO
numberOfSamples: 0 ];
// Enable or disable multiple touches
[eaglView setMultipleTouchEnabled:NO];
// Use RootViewController manage CCEAGLView
_viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];

View File

@ -69,7 +69,8 @@ static std::function<Layer*()> createFunctions[] =
CL(Sprite3DWithOBBPerformanceTest),
CL(Sprite3DMirrorTest),
CL(QuaternionTest),
CL(Sprite3DEmptyTest)
CL(Sprite3DEmptyTest),
CL(UseCaseSprite3D)
};
#define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0]))
@ -2105,3 +2106,128 @@ void QuaternionTest::update(float delta)
Quaternion::createFromAxisAngle(Vec3(0.f, 0.f, 1.f), _accAngle - pi * 0.5f, &quat);
_sprite->setRotationQuat(quat);
}
UseCaseSprite3D::UseCaseSprite3D()
: _caseIdx(0)
, _sprite3d(nullptr)
, _sprite2d(nullptr)
{
auto s = Director::getInstance()->getWinSize();
_useCaseTitles[0] = "transparent 3d sprite and 2d sprite";
auto itemPrev = MenuItemImage::create("Images/b1.png", "Images/b2.png",
[&](Ref *sender) {
_caseIdx--;
if (_caseIdx < 0)
_caseIdx = 0;
this->switchCase();
});
auto itemNext = MenuItemImage::create("Images/f1.png", "Images/f2.png",
[&](Ref *sender) {
_caseIdx++;
if (_caseIdx >= (int)USECASE::MAX_CASE_NUM)
_caseIdx = (int)USECASE::MAX_CASE_NUM - 1;
this->switchCase();
});
auto menu = Menu::create(itemPrev, itemNext, nullptr);
menu->alignItemsHorizontally();
menu->setScale(0.5);
menu->setAnchorPoint(Vec2(0,0));
menu->setPosition(Vec2(s.width/2,70));
_label = Label::create();
_label->setPosition(s.width * 0.5f, s.height * 0.8f);
addChild(_label);
addChild(menu);
//setup camera
auto camera = Camera::createPerspective(40, s.width / s.height, 0.01f, 1000.f);
camera->setCameraFlag(CameraFlag::USER1);
camera->setPosition3D(Vec3(0.f, 30.f, 100.f));
camera->lookAt(Vec3(0.f, 0.f, 0.f));
addChild(camera);
switchCase();
}
std::string UseCaseSprite3D::title() const
{
return "Use Case For 2D + 3D";
}
std::string UseCaseSprite3D::subtitle() const
{
return "";
}
void UseCaseSprite3D::switchCase()
{
if (_sprite3d)
{
removeChild(_sprite3d);
_sprite3d = nullptr;
}
if (_sprite2d)
{
removeChild(_sprite2d);
_sprite2d = nullptr;
}
auto s = Director::getInstance()->getWinSize();
_label->setString(_useCaseTitles[_caseIdx]);
if (_caseIdx == 0)
{
std::string filename = "Sprite3DTest/girl.c3b";
auto sprite = Sprite3D::create(filename);
sprite->setScale(0.15f);
addChild(sprite);
auto animation = Animation3D::create(filename);
if (animation)
{
auto animate = Animate3D::create(animation);
sprite->runAction(RepeatForever::create(animate));
}
auto circleBack = Sprite3D::create();
auto circle = Sprite::create("Sprite3DTest/circle.png");
circleBack->setScale(0.5f);
circleBack->addChild(circle);
circle->runAction(RepeatForever::create(RotateBy::create(3, Vec3(0.f, 0.f, 360.f))));
circleBack->setRotation3D(Vec3(90, 0, 0));
addChild(circleBack);
auto pos = sprite->getPosition3D();
circleBack->setPosition3D(Vec3(pos.x, pos.y, pos.z - 1));
_sprite3d = sprite;
_sprite2d = circleBack;
_sprite3d->setOpacity(250);
_sprite3d->setCameraMask(2);
_sprite2d->setCameraMask(2);
}
scheduleUpdate();
update(0.f);
}
void UseCaseSprite3D::update(float delta)
{
static float accAngle = 0.f;
accAngle += delta * CC_DEGREES_TO_RADIANS(60);
float radius = 30.f;
float x = cosf(accAngle) * radius, z = sinf(accAngle) * radius;
_sprite3d->setPositionX(x);
_sprite3d->setPositionZ(z);
_sprite2d->setPositionX(x);
_sprite2d->setPositionZ(z);
}

View File

@ -455,6 +455,32 @@ protected:
float _accAngle;
};
class UseCaseSprite3D : public Sprite3DTestDemo
{
public:
CREATE_FUNC(UseCaseSprite3D);
UseCaseSprite3D();
virtual std::string title() const override;
virtual std::string subtitle() const override;
virtual void update(float delta) override;
protected:
void switchCase();
enum class USECASE{
_3D_WITH_2D,
MAX_CASE_NUM,
};
cocos2d::Label* _label;
int _caseIdx; // use case index
std::string _useCaseTitles[(int)USECASE::MAX_CASE_NUM];
cocos2d::Sprite3D* _sprite3d;
cocos2d::Sprite3D* _sprite2d;
};
class Sprite3DTestScene : public TestScene
{
public:

View File

@ -124,11 +124,11 @@ bool WebViewTest::init()
Button *loadHTMLBtn = Button::create("cocosui/animationbuttonnormal.png",
"cocosui/animationbuttonpressed.png");
loadHTMLBtn->setTitleText("Load HTML");
loadHTMLBtn->setTitleText("Load Data");
loadHTMLBtn->setPosition(Vec2(winSize/2) - Vec2( _webView->getContentSize().width/2 +
loadHTMLBtn->getContentSize().width/2 + 10,0 ));
loadHTMLBtn->addClickEventListener([=](Ref*){
_webView->loadHTMLString("<body style=\"font-size:50px;\">Hello World</body>","text/html");
_webView->loadHTMLString("<body style=\"font-size:50px;\">Hello World <img src=\"Icon.png\"/> </body>","Images/");
});
this->addChild(loadHTMLBtn);

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

View File

@ -676,7 +676,8 @@ function LayoutComponentTest:configureGUIScene()
local back_label = ccui.Helper:seekWidgetByName(root, "back")
back_label:addTouchEventListener(function(sender, eventType)
self:unscheduleUpdate()
scheduler:unscheduleScriptEntry(schedulerEntry)
schedulerEntry = 0
runCocoStudioUIEditorTestScene()
end)

View File

@ -45,6 +45,10 @@ end
function LabelAtlasTest.onNodeEvent(tag)
if tag == "exit" then
LabelAtlasTest.layer:unscheduleUpdate()
elseif tag == "enter" then
if nil ~= LabelAtlasTest.layer then
LabelAtlasTest.layer:scheduleUpdateWithPriorityLua(LabelAtlasTest.step, 0)
end
end
end
@ -64,8 +68,6 @@ function LabelAtlasTest.create()
label2:setPosition( cc.p(10,200) )
label2:setOpacity( 32 )
layer:scheduleUpdateWithPriorityLua(LabelAtlasTest.step, 0)
Helper.titleLabel:setString("LabelAtlas")
Helper.subtitleLabel:setString("Updating label should be fast")
@ -105,6 +107,10 @@ end
function LabelAtlasColorTest.onNodeEvent(tag)
if tag == "exit" then
LabelAtlasColorTest.layer:unscheduleUpdate()
elseif tag == "enter" then
if nil ~= LabelAtlasColorTest.layer then
LabelAtlasColorTest.layer:scheduleUpdateWithPriorityLua(LabelAtlasColorTest.step, 0)
end
end
end
@ -135,7 +141,6 @@ function LabelAtlasColorTest.create()
label2:runAction( repeatAction )
layer:registerScriptHandler(LabelAtlasColorTest.onNodeEvent)
layer:scheduleUpdateWithPriorityLua(LabelAtlasColorTest.step, 0)
Helper.titleLabel:setString("LabelAtlas")
Helper.subtitleLabel:setString("Opacity + Color should work at the same time")
@ -161,6 +166,8 @@ Atlas3.__index = Atlas3
function Atlas3.onNodeEvent(tag)
if tag == "exit" then
Atlas3.layer:unscheduleUpdate()
elseif tag == "enter" then
Atlas3.layer:scheduleUpdateWithPriorityLua(Atlas3.step, 0)
end
end
@ -211,7 +218,6 @@ function Atlas3.create()
label3:setPosition( VisibleRect:rightTop() )
layer:registerScriptHandler(Atlas3.onNodeEvent)
layer:scheduleUpdateWithPriorityLua(Atlas3.step, 0)
Helper.titleLabel:setString( "LabelBMFont" )
Helper.subtitleLabel:setString( "Testing alignment. Testing opacity + tint" )

View File

@ -28,6 +28,10 @@ LabelFNTColorAndOpacity.__index = LabelFNTColorAndOpacity
function LabelFNTColorAndOpacity.onNodeEvent(tag)
if tag == "exit" then
LabelFNTColorAndOpacity.layer:unscheduleUpdate()
elseif tag == "enter" then
if nil ~= LabelFNTColorAndOpacity.layer then
LabelFNTColorAndOpacity.layer:scheduleUpdateWithPriorityLua(LabelFNTColorAndOpacity.step, 0)
end
end
end
@ -73,7 +77,6 @@ function LabelFNTColorAndOpacity.create()
label3:setPosition( VisibleRect:rightTop() )
layer:registerScriptHandler(LabelFNTColorAndOpacity.onNodeEvent)
layer:scheduleUpdateWithPriorityLua(LabelFNTColorAndOpacity.step, 0)
Helper.titleLabel:setString( "New Label + .FNT file" )
Helper.subtitleLabel:setString( "Testing opacity + tint" )