Merge branch 'v3' of github.com:cocos2d/cocos2d-x into use-const

This commit is contained in:
minggo 2014-12-30 13:36:10 +08:00
commit ba4ae50868
14 changed files with 133 additions and 66 deletions

View File

@ -61,6 +61,10 @@ THE SOFTWARE.
#include "platform/CCApplication.h" #include "platform/CCApplication.h"
//#include "platform/CCGLViewImpl.h" //#include "platform/CCGLViewImpl.h"
#if CC_ENABLE_SCRIPT_BINDING
#include "CCScriptSupport.h"
#endif
/** /**
Position of the FPS Position of the FPS
@ -127,6 +131,9 @@ bool Director::init(void)
// purge ? // purge ?
_purgeDirectorInNextLoop = false; _purgeDirectorInNextLoop = false;
// restart ?
_restartDirectorInNextLoop = false;
_winSizeInPoints = Size::ZERO; _winSizeInPoints = Size::ZERO;
@ -941,17 +948,22 @@ void Director::end()
_purgeDirectorInNextLoop = true; _purgeDirectorInNextLoop = true;
} }
void Director::purgeDirector() void Director::restart()
{
_restartDirectorInNextLoop = true;
}
void Director::reset()
{ {
// cleanup scheduler // cleanup scheduler
getScheduler()->unscheduleAll(); getScheduler()->unscheduleAll();
// Disable event dispatching // Remove all events
if (_eventDispatcher) if (_eventDispatcher)
{ {
_eventDispatcher->setEnabled(false); _eventDispatcher->removeAllEventListeners();
} }
if (_runningScene) if (_runningScene)
{ {
_runningScene->onExit(); _runningScene->onExit();
@ -961,22 +973,22 @@ void Director::purgeDirector()
_runningScene = nullptr; _runningScene = nullptr;
_nextScene = nullptr; _nextScene = nullptr;
// remove all objects, but don't release it. // remove all objects, but don't release it.
// runWithScene might be executed after 'end'. // runWithScene might be executed after 'end'.
_scenesStack.clear(); _scenesStack.clear();
stopAnimation(); stopAnimation();
CC_SAFE_RELEASE_NULL(_FPSLabel); CC_SAFE_RELEASE_NULL(_FPSLabel);
CC_SAFE_RELEASE_NULL(_drawnBatchesLabel); CC_SAFE_RELEASE_NULL(_drawnBatchesLabel);
CC_SAFE_RELEASE_NULL(_drawnVerticesLabel); CC_SAFE_RELEASE_NULL(_drawnVerticesLabel);
// purge bitmap cache // purge bitmap cache
FontFNT::purgeCachedData(); FontFNT::purgeCachedData();
FontFreeType::shutdownFreeType(); FontFreeType::shutdownFreeType();
// purge all managed caches // purge all managed caches
#if defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1))) #if defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)))
@ -997,13 +1009,18 @@ void Director::purgeDirector()
GLProgramStateCache::destroyInstance(); GLProgramStateCache::destroyInstance();
FileUtils::destroyInstance(); FileUtils::destroyInstance();
AsyncTaskPool::destoryInstance(); AsyncTaskPool::destoryInstance();
// cocos2d-x specific data structures // cocos2d-x specific data structures
UserDefault::destroyInstance(); UserDefault::destroyInstance();
GL::invalidateStateCache(); GL::invalidateStateCache();
destroyTextureCache(); destroyTextureCache();
}
void Director::purgeDirector()
{
reset();
CHECK_GL_ERROR_DEBUG(); CHECK_GL_ERROR_DEBUG();
@ -1018,6 +1035,23 @@ void Director::purgeDirector()
release(); release();
} }
void Director::restartDirector()
{
reset();
// Texture cache need to be reinitialized
initTextureCache();
// release the objects
PoolManager::getInstance()->getCurrentPool()->clear();
// Real restart in script level
#if CC_ENABLE_SCRIPT_BINDING
ScriptEvent scriptEvent(kRestartGame, NULL);
ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&scriptEvent);
#endif
}
void Director::setNextScene() void Director::setNextScene()
{ {
bool runningIsTransition = dynamic_cast<TransitionScene*>(_runningScene) != nullptr; bool runningIsTransition = dynamic_cast<TransitionScene*>(_runningScene) != nullptr;
@ -1305,6 +1339,11 @@ void DisplayLinkDirector::mainLoop()
_purgeDirectorInNextLoop = false; _purgeDirectorInNextLoop = false;
purgeDirector(); purgeDirector();
} }
else if (_restartDirectorInNextLoop)
{
_restartDirectorInNextLoop = false;
restartDirector();
}
else if (! _invalid) else if (! _invalid)
{ {
drawScene(); drawScene();

View File

@ -287,6 +287,10 @@ public:
The "delta time" will be 0 (as if the game wasn't paused) The "delta time" will be 0 (as if the game wasn't paused)
*/ */
void resume(); void resume();
/** Restart the director
*/
void restart();
/** Stops the animation. Nothing will be drawn. The main loop won't be triggered anymore. /** Stops the animation. Nothing will be drawn. The main loop won't be triggered anymore.
If you don't want to pause your animation call [pause] instead. If you don't want to pause your animation call [pause] instead.
@ -396,9 +400,14 @@ public:
void resetMatrixStack(); void resetMatrixStack();
protected: protected:
void reset();
void purgeDirector(); void purgeDirector();
bool _purgeDirectorInNextLoop; // this flag will be set to true in end() bool _purgeDirectorInNextLoop; // this flag will be set to true in end()
void restartDirector();
bool _restartDirectorInNextLoop; // this flag will be set to true in restart()
void setNextScene(); void setNextScene();
void showStats(); void showStats();

View File

@ -211,7 +211,8 @@ enum ScriptEventType
kAccelerometerEvent, kAccelerometerEvent,
kControlEvent, kControlEvent,
kCommonEvent, kCommonEvent,
kComponentEvent kComponentEvent,
kRestartGame
}; };
struct BasicScriptData struct BasicScriptData

View File

@ -1218,19 +1218,19 @@ Offset<ProjectNodeOptions> FlatBuffersSerialize::createProjectNodeOptionsForSimu
if (name == "FileData") if (name == "FileData")
{ {
const tinyxml2::XMLAttribute* attribute = child->FirstAttribute(); const tinyxml2::XMLAttribute* attributeFileData = child->FirstAttribute();
while (attribute) while (attributeFileData)
{ {
name = attribute->Name(); name = attributeFileData->Name();
std::string value = attribute->Value(); std::string value = attributeFileData->Value();
if (name == "Path") if (name == "Path")
{ {
filename = value; filename = value;
} }
attribute = attribute->Next(); attributeFileData = attributeFileData->Next();
} }
} }

View File

@ -151,9 +151,9 @@ cocos2d::Node* ArmatureNodeReader::createNodeWithFlatBuffers(const flatbuffers:
std::string ArmatureNodeReader::getArmatureName(const std::string& exporJsonPath) std::string ArmatureNodeReader::getArmatureName(const std::string& exporJsonPath)
{ {
//FileUtils.getFileData(exporJsonPath, "r", size) // need read armature name in exportJsonPath //FileUtils.getFileData(exporJsonPath, "r", size) // need read armature name in exportJsonPath
int end = exporJsonPath.find_last_of("."); size_t end = exporJsonPath.find_last_of(".");
int start = exporJsonPath.find_last_of("\\") + 1; size_t start = exporJsonPath.find_last_of("\\") + 1;
int start1 = exporJsonPath.find_last_of("/") + 1; size_t start1 = exporJsonPath.find_last_of("/") + 1;
if (start < start1) if (start < start1)
start = start1; start = start1;

View File

@ -185,11 +185,11 @@ namespace cocostudio
if (name == "InnerNodeSize") if (name == "InnerNodeSize")
{ {
auto attribute = child->FirstAttribute(); auto attributeInnerNodeSize = child->FirstAttribute();
while (attribute) while (attributeInnerNodeSize)
{ {
name = attribute->Name(); name = attributeInnerNodeSize->Name();
std::string value = attribute->Value(); std::string value = attributeInnerNodeSize->Value();
if (name == "Width") if (name == "Width")
{ {
@ -200,17 +200,17 @@ namespace cocostudio
innerSize.height = atof(value.c_str()); innerSize.height = atof(value.c_str());
} }
attribute = attribute->Next(); attributeInnerNodeSize = attributeInnerNodeSize->Next();
} }
} }
else if (name == "Size" && backGroundScale9Enabled) else if (name == "Size" && backGroundScale9Enabled)
{ {
auto attribute = child->FirstAttribute(); auto attributeSize = child->FirstAttribute();
while (attribute) while (attributeSize)
{ {
name = attribute->Name(); name = attributeSize->Name();
std::string value = attribute->Value(); std::string value = attributeSize->Value();
if (name == "X") if (name == "X")
{ {
@ -221,17 +221,17 @@ namespace cocostudio
scale9Size.height = atof(value.c_str()); scale9Size.height = atof(value.c_str());
} }
attribute = attribute->Next(); attributeSize = attributeSize->Next();
} }
} }
else if (name == "SingleColor") else if (name == "SingleColor")
{ {
auto attribute = child->FirstAttribute(); auto attributeSingleColor = child->FirstAttribute();
while (attribute) while (attributeSingleColor)
{ {
name = attribute->Name(); name = attributeSingleColor->Name();
std::string value = attribute->Value(); std::string value = attributeSingleColor->Value();
if (name == "R") if (name == "R")
{ {
@ -246,17 +246,17 @@ namespace cocostudio
bgColor.b = atoi(value.c_str()); bgColor.b = atoi(value.c_str());
} }
attribute = attribute->Next(); attributeSingleColor = attributeSingleColor->Next();
} }
} }
else if (name == "EndColor") else if (name == "EndColor")
{ {
auto attribute = child->FirstAttribute(); auto attributeEndColor = child->FirstAttribute();
while (attribute) while (attributeEndColor)
{ {
name = attribute->Name(); name = attributeEndColor->Name();
std::string value = attribute->Value(); std::string value = attributeEndColor->Value();
if (name == "R") if (name == "R")
{ {
@ -271,17 +271,17 @@ namespace cocostudio
bgEndColor.b = atoi(value.c_str()); bgEndColor.b = atoi(value.c_str());
} }
attribute = attribute->Next(); attributeEndColor = attributeEndColor->Next();
} }
} }
else if (name == "FirstColor") else if (name == "FirstColor")
{ {
auto attribute = child->FirstAttribute(); auto attributeFirstColor = child->FirstAttribute();
while (attribute) while (attributeFirstColor)
{ {
name = attribute->Name(); name = attributeFirstColor->Name();
std::string value = attribute->Value(); std::string value = attributeFirstColor->Value();
if (name == "R") if (name == "R")
{ {
@ -296,16 +296,16 @@ namespace cocostudio
bgStartColor.b = atoi(value.c_str()); bgStartColor.b = atoi(value.c_str());
} }
attribute = attribute->Next(); attributeFirstColor = attributeFirstColor->Next();
} }
} }
else if (name == "ColorVector") else if (name == "ColorVector")
{ {
auto attribute = child->FirstAttribute(); auto attributeColorVector = child->FirstAttribute();
while (attribute) while (attributeColorVector)
{ {
name = attribute->Name(); name = attributeColorVector->Name();
std::string value = attribute->Value(); std::string value = attributeColorVector->Value();
if (name == "ScaleX") if (name == "ScaleX")
{ {
@ -316,7 +316,7 @@ namespace cocostudio
colorVector.y = atof(value.c_str()); colorVector.y = atof(value.c_str());
} }
attribute = attribute->Next(); attributeColorVector = attributeColorVector->Next();
} }
} }
else if (name == "FileData") else if (name == "FileData")
@ -324,12 +324,12 @@ namespace cocostudio
std::string texture; std::string texture;
std::string texturePng; std::string texturePng;
auto attribute = child->FirstAttribute(); auto attributeFileData = child->FirstAttribute();
while (attribute) while (attributeFileData)
{ {
name = attribute->Name(); name = attributeFileData->Name();
std::string value = attribute->Value(); std::string value = attributeFileData->Value();
if (name == "Path") if (name == "Path")
{ {
@ -345,7 +345,7 @@ namespace cocostudio
texture = value; texture = value;
} }
attribute = attribute->Next(); attributeFileData = attributeFileData->Next();
} }
if (resourceType == 1) if (resourceType == 1)

View File

@ -98,12 +98,12 @@ namespace cocostudio
if (name == "FileData") if (name == "FileData")
{ {
const tinyxml2::XMLAttribute* attribute = child->FirstAttribute(); const tinyxml2::XMLAttribute* attributeFileData = child->FirstAttribute();
while (attribute) while (attributeFileData)
{ {
name = attribute->Name(); name = attributeFileData->Name();
std::string value = attribute->Value(); std::string value = attributeFileData->Value();
if (name == "Path") if (name == "Path")
{ {
@ -112,7 +112,7 @@ namespace cocostudio
filename = convert; filename = convert;
} }
attribute = attribute->Next(); attributeFileData = attributeFileData->Next();
} }
} }

View File

@ -779,7 +779,7 @@ namespace cocostudio
//assume versionString is like "2.0.6.0" //assume versionString is like "2.0.6.0"
if (versionString.length() > 0) if (versionString.length() > 0)
{ {
int p1, p2, p3, v1, v2, v3; size_t p1, p2, p3, v1, v2, v3;
p1 = p2 = p3 = v1 = v2 = v3 = 0; p1 = p2 = p3 = v1 = v2 = v3 = 0;
p1 = versionString.find('.'); p1 = versionString.find('.');
if (p1 > 0) if (p1 > 0)

View File

@ -595,8 +595,7 @@ void Renderer::fillQuads(const QuadCommand *cmd)
for(ssize_t i=0; i< cmd->getQuadCount() * 4; ++i) for(ssize_t i=0; i< cmd->getQuadCount() * 4; ++i)
{ {
V3F_C4B_T2F *q = &_quadVerts[i + _numberQuads * 4]; Vec3 *vec1 = (Vec3*)&(_quadVerts[i + _numberQuads * 4].vertices);
Vec3 *vec1 = (Vec3*)&q->vertices;
modelView.transformPoint(vec1); modelView.transformPoint(vec1);
} }

View File

@ -7135,7 +7135,7 @@ int lua_cocos2dx_ui_Button_getTitleColor(lua_State* tolua_S)
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_ui_Button_getTitleColor'", nullptr); tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_ui_Button_getTitleColor'", nullptr);
return 0; return 0;
} }
const cocos2d::Color3B& ret = cobj->getTitleColor(); cocos2d::Color3B ret = cobj->getTitleColor();
color3b_to_luaval(tolua_S, ret); color3b_to_luaval(tolua_S, ret);
return 1; return 1;
} }

View File

@ -234,6 +234,21 @@ void Manifest::genResumeAssetsList(Downloader::DownloadUnits *units) const
} }
} }
std::vector<std::string> Manifest::getSearchPaths() const
{
std::vector<std::string> searchPaths;
searchPaths.push_back(_manifestRoot);
for (int i = (int)_searchPaths.size()-1; i >= 0; i--)
{
std::string path = _searchPaths[i];
if (path.size() > 0 && path[path.size() - 1] != '/')
path.append("/");
path = _manifestRoot + path;
searchPaths.push_back(path);
}
return searchPaths;
}
void Manifest::prependSearchPaths() void Manifest::prependSearchPaths()
{ {

View File

@ -95,6 +95,10 @@ public:
*/ */
const std::string& getVersion() const; const std::string& getVersion() const;
/** @brief Get the search paths list related to the Manifest.
*/
std::vector<std::string> getSearchPaths() const;
protected: protected:
/** @brief Constructor for Manifest class /** @brief Constructor for Manifest class

View File

@ -1991,7 +1991,7 @@ void QuaternionTest::addNewSpriteWithCoords(Vec2 p)
void QuaternionTest::update(float delta) void QuaternionTest::update(float delta)
{ {
_accAngle += delta * _arcSpeed; _accAngle += delta * _arcSpeed;
const float pi = 3.1415926f; const float pi = M_PI;
if (_accAngle >= 2 * pi) if (_accAngle >= 2 * pi)
_accAngle -= 2 * pi; _accAngle -= 2 * pi;

View File

@ -7,7 +7,7 @@ uniform vec4 u_color;
varying vec3 v_normal; varying vec3 v_normal;
void main(void) void main(void)
{ {
vec3 light_direction = vec3(1,-1,0); vec3 light_direction = vec3(1,-1,-1);
light_direction = normalize(light_direction); light_direction = normalize(light_direction);
vec3 light_color = vec3(1,1,1); vec3 light_color = vec3(1,1,1);
vec3 normal = normalize(v_normal); vec3 normal = normalize(v_normal);