From 7fd0ca217c0e905897a3c3f67ac20f6b51287c48 Mon Sep 17 00:00:00 2001 From: boyu0 Date: Mon, 14 Jul 2014 20:42:08 +0800 Subject: [PATCH 1/3] Implement utils::atof() --- cocos/base/ccUtils.cpp | 24 ++++++++++++++++++++++++ cocos/base/ccUtils.h | 5 +++++ 2 files changed, 29 insertions(+) diff --git a/cocos/base/ccUtils.cpp b/cocos/base/ccUtils.cpp index 5a025b25ec..36cafb1c20 100644 --- a/cocos/base/ccUtils.cpp +++ b/cocos/base/ccUtils.cpp @@ -24,6 +24,9 @@ THE SOFTWARE. ****************************************************************************/ #include "base/ccUtils.h" + +#include + #include "base/CCDirector.h" #include "renderer/CCCustomCommand.h" #include "renderer/CCRenderer.h" @@ -160,6 +163,27 @@ std::vector findChildren(const Node &node, const std::string &name) return vec; } + +#define MAX_ITOA_BUFFER_SIZE 256 +double atof(const char* str) +{ + if (str == nullptr) + { + return 0.0; + } + + char buf[MAX_ITOA_BUFFER_SIZE]; + strncpy(buf, str, MAX_ITOA_BUFFER_SIZE); + + // strip string, only remain 7 numbers after '.' + char* dot = strchr(buf, '.'); + if (dot != nullptr && dot - buf + 8 < MAX_ITOA_BUFFER_SIZE) + { + dot[8] = '\0'; + } + + return ::atof(buf); +} } diff --git a/cocos/base/ccUtils.h b/cocos/base/ccUtils.h index 939d71b854..1fba5b1b40 100644 --- a/cocos/base/ccUtils.h +++ b/cocos/base/ccUtils.h @@ -73,6 +73,11 @@ namespace utils * @since v3.2 */ std::vector findChildren(const Node &node, const std::string &name); + + /** Same to ::atof, but strip the string, remain 7 numbers after '.' before call atof。 + * Why we need this? Because in android c++_static, atof ( and std::atof ) is unsupported for numbers have long decimal part and contain several numbers can approximate to 1 ( like 90.099998474121094 ), it will return inf. this function is used to fix this bug. + */ + double atof(const char* str); } NS_CC_END From c7fec217ba294015582b74a81cee4c1ad6a800fe Mon Sep 17 00:00:00 2001 From: boyu0 Date: Mon, 14 Jul 2014 20:45:24 +0800 Subject: [PATCH 2/3] Change atof() to utils::atof() --- cocos/3d/CCObjLoader.cpp | 3 +- cocos/base/CCConsole.cpp | 13 ++--- cocos/base/CCNS.cpp | 18 +++---- cocos/base/CCUserDefault.cpp | 2 +- cocos/base/CCUserDefaultAndroid.cpp | 5 +- cocos/base/CCValue.cpp | 5 +- cocos/deprecated/CCString.cpp | 5 +- .../cocostudio/CCActionNode.cpp | 3 +- .../cocostudio/CCActionObject.cpp | 3 +- .../cocostudio/CCDataReaderHelper.cpp | 47 ++++++++++--------- .../cocostudio/CCSGUIReader.cpp | 4 +- .../cocostudio/CCSSceneReader.cpp | 8 ++-- .../editor-support/cocostudio/TriggerMng.cpp | 4 +- .../cocostudio/WidgetReader/WidgetReader.cpp | 2 +- cocos/platform/CCFileUtils.cpp | 5 +- cocos/platform/desktop/CCGLView.cpp | 3 +- .../CocoStudioSceneTest/TriggerCode/acts.cpp | 42 ++++++++--------- .../CocoStudioSceneTest/TriggerCode/cons.cpp | 2 +- 18 files changed, 93 insertions(+), 81 deletions(-) diff --git a/cocos/3d/CCObjLoader.cpp b/cocos/3d/CCObjLoader.cpp index 4c5da0d89e..1ad3e446eb 100644 --- a/cocos/3d/CCObjLoader.cpp +++ b/cocos/3d/CCObjLoader.cpp @@ -28,6 +28,7 @@ #include "CCObjLoader.h" #include "platform/CCFileUtils.h" +#include "base/ccUtils.h" NS_CC_BEGIN @@ -102,7 +103,7 @@ static inline int parseInt(const char*& token) static inline float parseFloat(const char*& token) { token += strspn(token, " \t"); - float f = (float)atof(token); + float f = (float)utils::atof(token); token += strcspn(token, " \t\r"); return f; } diff --git a/cocos/base/CCConsole.cpp b/cocos/base/CCConsole.cpp index e06185654c..8e149e76c1 100644 --- a/cocos/base/CCConsole.cpp +++ b/cocos/base/CCConsole.cpp @@ -63,6 +63,7 @@ #include "renderer/CCTextureCache.h" #include "CCGLView.h" #include "base/base64.h" +#include "base/ccUtils.h" NS_CC_BEGIN extern const char* cocos2dVersion(void); @@ -660,8 +661,8 @@ void Console::commandTouch(int fd, const std::string& args) if((argv.size() == 3) && (isFloat(argv[1]) && isFloat(argv[2]))) { - float x = std::atof(argv[1].c_str()); - float y = std::atof(argv[2].c_str()); + float x = utils::atof(argv[1].c_str()); + float y = utils::atof(argv[2].c_str()); srand ((unsigned)time(nullptr)); _touchId = rand(); @@ -686,10 +687,10 @@ void Console::commandTouch(int fd, const std::string& args) && (isFloat(argv[3])) && (isFloat(argv[4]))) { - float x1 = std::atof(argv[1].c_str()); - float y1 = std::atof(argv[2].c_str()); - float x2 = std::atof(argv[3].c_str()); - float y2 = std::atof(argv[4].c_str()); + float x1 = utils::atof(argv[1].c_str()); + float y1 = utils::atof(argv[2].c_str()); + float x2 = utils::atof(argv[3].c_str()); + float y2 = utils::atof(argv[4].c_str()); srand ((unsigned)time(nullptr)); _touchId = rand(); diff --git a/cocos/base/CCNS.cpp b/cocos/base/CCNS.cpp index 452e3a7458..0073a740f4 100644 --- a/cocos/base/CCNS.cpp +++ b/cocos/base/CCNS.cpp @@ -28,6 +28,8 @@ THE SOFTWARE. #include #include +#include "base/ccUtils.h" + using namespace std; NS_CC_BEGIN @@ -133,10 +135,10 @@ Rect RectFromString(const std::string& str) strArray sizeInfo; CC_BREAK_IF(!splitWithForm(sizeStr.c_str(), sizeInfo)); - float x = (float) atof(pointInfo[0].c_str()); - float y = (float) atof(pointInfo[1].c_str()); - float width = (float) atof(sizeInfo[0].c_str()); - float height = (float) atof(sizeInfo[1].c_str()); + float x = (float) utils::atof(pointInfo[0].c_str()); + float y = (float) utils::atof(pointInfo[1].c_str()); + float width = (float) utils::atof(sizeInfo[0].c_str()); + float height = (float) utils::atof(sizeInfo[1].c_str()); result = Rect(x, y, width, height); } while (0); @@ -153,8 +155,8 @@ Vec2 PointFromString(const std::string& str) strArray strs; CC_BREAK_IF(!splitWithForm(str, strs)); - float x = (float) atof(strs[0].c_str()); - float y = (float) atof(strs[1].c_str()); + float x = (float) utils::atof(strs[0].c_str()); + float y = (float) utils::atof(strs[1].c_str()); ret = Vec2(x, y); } while (0); @@ -171,8 +173,8 @@ Size SizeFromString(const std::string& pszContent) strArray strs; CC_BREAK_IF(!splitWithForm(pszContent, strs)); - float width = (float) atof(strs[0].c_str()); - float height = (float) atof(strs[1].c_str()); + float width = (float) utils::atof(strs[0].c_str()); + float height = (float) utils::atof(strs[1].c_str()); ret = Size(width, height); } while (0); diff --git a/cocos/base/CCUserDefault.cpp b/cocos/base/CCUserDefault.cpp index 2c19feb45c..d49d9c1551 100644 --- a/cocos/base/CCUserDefault.cpp +++ b/cocos/base/CCUserDefault.cpp @@ -250,7 +250,7 @@ double UserDefault::getDoubleForKey(const char* pKey, double defaultValue) if (value) { - ret = atof(value); + ret = utils::atof(value); } if (doc) delete doc; diff --git a/cocos/base/CCUserDefaultAndroid.cpp b/cocos/base/CCUserDefaultAndroid.cpp index 63ee9182db..c6c3a166d1 100644 --- a/cocos/base/CCUserDefaultAndroid.cpp +++ b/cocos/base/CCUserDefaultAndroid.cpp @@ -24,6 +24,7 @@ THE SOFTWARE. ****************************************************************************/ #include "base/CCUserDefault.h" #include "base/CCPlatformConfig.h" +#include "base/ccUtils.h" #include "platform/CCCommon.h" #include "base/base64.h" @@ -243,7 +244,7 @@ float UserDefault::getFloatForKey(const char* pKey, float defaultValue) { if (node->FirstChild()) { - float ret = atof((const char*)node->FirstChild()->Value()); + float ret = utils::atof((const char*)node->FirstChild()->Value()); // set value in NSUserDefaults setFloatForKey(pKey, ret); @@ -279,7 +280,7 @@ double UserDefault::getDoubleForKey(const char* pKey, double defaultValue) { if (node->FirstChild()) { - double ret = atof((const char*)node->FirstChild()->Value()); + double ret = utils::atof((const char*)node->FirstChild()->Value()); // set value in NSUserDefaults setDoubleForKey(pKey, ret); diff --git a/cocos/base/CCValue.cpp b/cocos/base/CCValue.cpp index 00b4904810..d5e0e06a4e 100644 --- a/cocos/base/CCValue.cpp +++ b/cocos/base/CCValue.cpp @@ -25,6 +25,7 @@ #include "base/CCValue.h" #include #include +#include "base/ccUtils.h" NS_CC_BEGIN @@ -504,7 +505,7 @@ float Value::asFloat() const if (_type == Type::STRING) { - return atof(_field.strVal->c_str()); + return utils::atof(_field.strVal->c_str()); } if (_type == Type::INTEGER) @@ -540,7 +541,7 @@ double Value::asDouble() const if (_type == Type::STRING) { - return static_cast(atof(_field.strVal->c_str())); + return static_cast(utils::atof(_field.strVal->c_str())); } if (_type == Type::INTEGER) diff --git a/cocos/deprecated/CCString.cpp b/cocos/deprecated/CCString.cpp index 06bf28d7de..38d153b95f 100644 --- a/cocos/deprecated/CCString.cpp +++ b/cocos/deprecated/CCString.cpp @@ -29,6 +29,7 @@ Copyright (c) 2013-2014 Chukong Technologies #include #include #include "CCArray.h" +#include "base/ccUtils.h" NS_CC_BEGIN @@ -118,7 +119,7 @@ float __String::floatValue() const { return 0.0f; } - return (float)atof(_string.c_str()); + return (float)utils::atof(_string.c_str()); } double __String::doubleValue() const @@ -127,7 +128,7 @@ double __String::doubleValue() const { return 0.0; } - return atof(_string.c_str()); + return utils::atof(_string.c_str()); } bool __String::boolValue() const diff --git a/cocos/editor-support/cocostudio/CCActionNode.cpp b/cocos/editor-support/cocostudio/CCActionNode.cpp index f0c6ee782e..116eeb1592 100644 --- a/cocos/editor-support/cocostudio/CCActionNode.cpp +++ b/cocos/editor-support/cocostudio/CCActionNode.cpp @@ -28,6 +28,7 @@ THE SOFTWARE. #include "ui/UIWidget.h" #include "ui/UIHelper.h" #include "cocostudio/CocoLoader.h" +#include "base/ccUtils.h" using namespace cocos2d; using namespace ui; @@ -184,7 +185,7 @@ void ActionNode::initWithDictionary(const rapidjson::Value& dic, Ref* root) } float ActionNode::valueToFloat(const std::string& value) { - return atof(value.c_str()); + return utils::atof(value.c_str()); } void ActionNode::initWithBinary(CocoLoader *cocoLoader, diff --git a/cocos/editor-support/cocostudio/CCActionObject.cpp b/cocos/editor-support/cocostudio/CCActionObject.cpp index b064cb2fc2..67d6c25fb7 100644 --- a/cocos/editor-support/cocostudio/CCActionObject.cpp +++ b/cocos/editor-support/cocostudio/CCActionObject.cpp @@ -29,6 +29,7 @@ THE SOFTWARE. #include "base/CCDirector.h" #include "base/CCScheduler.h" #include "2d/CCActionInstant.h" +#include "base/ccUtils.h" using namespace cocos2d; @@ -189,7 +190,7 @@ bool ActionObject::valueToBool(const std::string& value) } float ActionObject::valueToFloat(const std::string& value) { - return atof(value.c_str()); + return utils::atof(value.c_str()); } void ActionObject::addActionNode(ActionNode* node) diff --git a/cocos/editor-support/cocostudio/CCDataReaderHelper.cpp b/cocos/editor-support/cocostudio/CCDataReaderHelper.cpp index 88be54e2cb..22b076371c 100644 --- a/cocos/editor-support/cocostudio/CCDataReaderHelper.cpp +++ b/cocos/editor-support/cocostudio/CCDataReaderHelper.cpp @@ -25,6 +25,7 @@ THE SOFTWARE. #include "platform/CCFileUtils.h" #include "base/CCDirector.h" #include "base/CCScheduler.h" +#include "base/ccUtils.h" #include "tinyxml2.h" @@ -1763,7 +1764,7 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json, if (key.compare(CONTENT_SCALE) == 0) { std::string value = tpChildArray[i].GetValue(&tCocoLoader); - dataInfo->contentScale = atof(value.c_str()); + dataInfo->contentScale = utils::atof(value.c_str()); } else if ( 0 == key.compare(ARMATURE_DATA)) { @@ -1879,7 +1880,7 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json, armatureData->name = name; } - float version = atof(pAramtureDataArray[1].GetValue(cocoLoader)); + float version = utils::atof(pAramtureDataArray[1].GetValue(cocoLoader)); dataInfo->cocoStudioVersion = armatureData->dataVersion = version; //DICTOOL->getFloatValue_json(json, VERSION, 0.1f); int length = pAramtureDataArray[3].GetChildNum(); //DICTOOL->getArrayCount_json(json, BONE_DATA, 0); @@ -1989,27 +1990,27 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json, str = SkinDataValue[i].GetValue(cocoLoader); if (key.compare(A_X) == 0) { - sdd->skinData.x = atof(str) * s_PositionReadScale; + sdd->skinData.x = utils::atof(str) * s_PositionReadScale; } else if (key.compare(A_Y) == 0) { - sdd->skinData.y = atof(str) * s_PositionReadScale; + sdd->skinData.y = utils::atof(str) * s_PositionReadScale; } else if (key.compare(A_SCALE_X) == 0) { - sdd->skinData.scaleX = atof(str); + sdd->skinData.scaleX = utils::atof(str); } else if (key.compare(A_SCALE_Y) == 0) { - sdd->skinData.scaleY = atof(str); + sdd->skinData.scaleY = utils::atof(str); } else if (key.compare(A_SKEW_X) == 0) { - sdd->skinData.skewX = atof(str); + sdd->skinData.skewX = utils::atof(str); } else if (key.compare(A_SKEW_Y) == 0) { - sdd->skinData.skewY = atof(str); + sdd->skinData.skewY = utils::atof(str); } } @@ -2168,7 +2169,7 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json, movementData->scale = 1.0; if(str != nullptr) { - movementData->scale = atof(str); + movementData->scale = utils::atof(str); } } else if (key.compare(A_TWEEN_EASING) == 0) @@ -2220,7 +2221,7 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json, { if(str != nullptr) { - movementBoneData->delay = atof(str); + movementBoneData->delay = utils::atof(str); } } else if (key.compare(FRAME_DATA) == 0) @@ -2382,7 +2383,7 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json, str = pFrameData[ii].GetValue(cocoLoader); if (str != nullptr) { - frameData->easingParams[ii] = atof(str); + frameData->easingParams[ii] = utils::atof(str); } } } @@ -2421,28 +2422,28 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json, { if(str != nullptr) { - textureData->width = atof(str); + textureData->width = utils::atof(str); } } else if (key.compare(A_HEIGHT) == 0) { if(str != nullptr) { - textureData->height = atof(str); + textureData->height = utils::atof(str); } } else if (key.compare(A_PIVOT_X) == 0) { if(str != nullptr) { - textureData->pivotX = atof(str); + textureData->pivotX = utils::atof(str); } } else if (key.compare(A_PIVOT_Y) == 0) { if(str != nullptr) { - textureData->pivotY = atof(str); + textureData->pivotY = utils::atof(str); } } else if (key.compare(CONTOUR_DATA) == 0) @@ -2481,8 +2482,8 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json, { pVerTexPoint = pVerTexPointArray[ii].GetChildArray(cocoLoader); Vec2 vertex; - vertex.x = atof(pVerTexPoint[0].GetValue(cocoLoader)); - vertex.y = atof(pVerTexPoint[1].GetValue(cocoLoader)); + vertex.x = utils::atof(pVerTexPoint[0].GetValue(cocoLoader)); + vertex.y = utils::atof(pVerTexPoint[1].GetValue(cocoLoader)); contourData->vertexList.push_back(vertex); } break; } @@ -2505,11 +2506,11 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json, str = child->GetValue(cocoLoader); if (key.compare(A_X) == 0) { - node->x = atof(str) * dataInfo->contentScale; + node->x = utils::atof(str) * dataInfo->contentScale; } else if (key.compare(A_Y) == 0) { - node->y = atof(str) * dataInfo->contentScale; + node->y = utils::atof(str) * dataInfo->contentScale; } else if (key.compare(A_Z) == 0) { @@ -2517,19 +2518,19 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json, } else if (key.compare(A_SKEW_X) == 0) { - node->skewX = atof(str); + node->skewX = utils::atof(str); } else if (key.compare(A_SKEW_Y) == 0) { - node->skewY = atof(str); + node->skewY = utils::atof(str); } else if (key.compare(A_SCALE_X) == 0) { - node->scaleX = atof(str); + node->scaleX = utils::atof(str); } else if (key.compare(A_SCALE_Y) == 0) { - node->scaleY = atof(str); + node->scaleY = utils::atof(str); } else if (key.compare(COLOR_INFO) == 0) { diff --git a/cocos/editor-support/cocostudio/CCSGUIReader.cpp b/cocos/editor-support/cocostudio/CCSGUIReader.cpp index 7e706e4455..d86f04c166 100644 --- a/cocos/editor-support/cocostudio/CCSGUIReader.cpp +++ b/cocos/editor-support/cocostudio/CCSGUIReader.cpp @@ -1241,9 +1241,9 @@ Widget* WidgetPropertiesReader0300::createWidget(const rapidjson::Value& data, c SpriteFrameCache::getInstance()->addSpriteFramesWithFile(file); } }else if (key == "designWidth"){ - fileDesignWidth = atof(tpChildArray[i].GetValue(cocoLoader)); + fileDesignWidth = utils::atof(tpChildArray[i].GetValue(cocoLoader)); }else if (key == "designHeight"){ - fileDesignHeight = atof(tpChildArray[i].GetValue(cocoLoader)); + fileDesignHeight = utils::atof(tpChildArray[i].GetValue(cocoLoader)); }else if (key == "widgetTree"){ if (fileDesignWidth <= 0 || fileDesignHeight <= 0) { diff --git a/cocos/editor-support/cocostudio/CCSSceneReader.cpp b/cocos/editor-support/cocostudio/CCSSceneReader.cpp index 92177e9284..ab855a30cc 100644 --- a/cocos/editor-support/cocostudio/CCSSceneReader.cpp +++ b/cocos/editor-support/cocostudio/CCSSceneReader.cpp @@ -510,12 +510,12 @@ void SceneReader::setPropertyFromJsonDict(CocoLoader *cocoLoader, stExpCocoNode if (key == "x") { - x = atof(value.c_str()); + x = utils::atof(value.c_str()); node->setPositionX(x); } else if (key == "y") { - y = atof(value.c_str()); + y = utils::atof(value.c_str()); node->setPositionY(y); } else if (key == "visible") @@ -535,7 +535,7 @@ void SceneReader::setPropertyFromJsonDict(CocoLoader *cocoLoader, stExpCocoNode } else if(key == "scalex") { - fScaleX = atof(value.c_str()); + fScaleX = utils::atof(value.c_str()); node->setScaleX(fScaleX); } else if(key == "scaley") @@ -545,7 +545,7 @@ void SceneReader::setPropertyFromJsonDict(CocoLoader *cocoLoader, stExpCocoNode } else if(key == "rotation") { - fRotationZ = atof(value.c_str()); + fRotationZ = utils::atof(value.c_str()); node->setRotation(fRotationZ); } } diff --git a/cocos/editor-support/cocostudio/TriggerMng.cpp b/cocos/editor-support/cocostudio/TriggerMng.cpp index 779b5dca86..23a482baa5 100755 --- a/cocos/editor-support/cocostudio/TriggerMng.cpp +++ b/cocos/editor-support/cocostudio/TriggerMng.cpp @@ -270,7 +270,7 @@ bool TriggerMng::isEmpty(void) const else if(type == rapidjson::kNumberType) { int nV = atoi(str3); - float fV = atof(str3); + float fV = utils::atof(str3); if (fabs(nV - fV) < 0.0000001) { dataitem.AddMember("value", nV, allocator); @@ -346,7 +346,7 @@ bool TriggerMng::isEmpty(void) const else if(type == rapidjson::kNumberType) { int nV = atoi(str5); - float fV = atof(str5); + float fV = utils::atof(str5); if (fabs(nV - fV) < 0.0000001) { dataitem.AddMember("value", nV, allocator); diff --git a/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.cpp index f68f2af107..69eda57774 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.cpp @@ -87,7 +87,7 @@ namespace cocostudio }; valueToFloat = [=](const std::string& str) -> float{ - return atof(str.c_str()); + return utils::atof(str.c_str()); }; } diff --git a/cocos/platform/CCFileUtils.cpp b/cocos/platform/CCFileUtils.cpp index c655dbba03..4d0c71df93 100644 --- a/cocos/platform/CCFileUtils.cpp +++ b/cocos/platform/CCFileUtils.cpp @@ -31,6 +31,7 @@ THE SOFTWARE. #include "base/ccMacros.h" #include "base/CCDirector.h" #include "platform/CCSAXParser.h" +#include "base/ccUtils.h" #include "tinyxml2.h" #include "unzip.h" @@ -257,7 +258,7 @@ public: else if (sName == "integer") _curArray->push_back(Value(atoi(_curValue.c_str()))); else - _curArray->push_back(Value(atof(_curValue.c_str()))); + _curArray->push_back(Value(utils::atof(_curValue.c_str()))); } else if (SAX_DICT == curState) { @@ -266,7 +267,7 @@ public: else if (sName == "integer") (*_curDict)[_curKey] = Value(atoi(_curValue.c_str())); else - (*_curDict)[_curKey] = Value(atof(_curValue.c_str())); + (*_curDict)[_curKey] = Value(utils::atof(_curValue.c_str())); } _curValue.clear(); diff --git a/cocos/platform/desktop/CCGLView.cpp b/cocos/platform/desktop/CCGLView.cpp index a934875204..4c4fbd7072 100644 --- a/cocos/platform/desktop/CCGLView.cpp +++ b/cocos/platform/desktop/CCGLView.cpp @@ -30,6 +30,7 @@ THE SOFTWARE. #include "base/CCEventKeyboard.h" #include "base/CCEventMouse.h" #include "base/CCIMEDispatcher.h" +#include "base/ccUtils.h" #include @@ -356,7 +357,7 @@ bool GLView::initWithRect(const std::string& viewName, Rect rect, float frameZoo // check OpenGL version at first const GLubyte* glVersion = glGetString(GL_VERSION); - if ( atof((const char*)glVersion) < 1.5 ) + if ( utils::atof((const char*)glVersion) < 1.5 ) { char strComplain[256] = {0}; sprintf(strComplain, diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioSceneTest/TriggerCode/acts.cpp b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioSceneTest/TriggerCode/acts.cpp index d48f64e1e7..28eb7a08a3 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioSceneTest/TriggerCode/acts.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioSceneTest/TriggerCode/acts.cpp @@ -189,7 +189,7 @@ void TMoveTo::serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCo { if (str != nullptr) { - _duration = atof(str); + _duration = utils::atof(str); } } @@ -197,7 +197,7 @@ void TMoveTo::serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCo { if (str != nullptr) { - _pos.x = atof(str); + _pos.x = utils::atof(str); } } else if (key == "y") @@ -311,7 +311,7 @@ void TMoveBy::serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCo { if (str != nullptr) { - _duration = atof(str); + _duration = utils::atof(str); } } @@ -319,14 +319,14 @@ void TMoveBy::serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCo { if (str != nullptr) { - _pos.x = atof(str); + _pos.x = utils::atof(str); } } else if (key == "y") { if (str != nullptr) { - _pos.y = atof(str); + _pos.y = utils::atof(str); } } else if (key == "IsReverse") @@ -424,7 +424,7 @@ void TRotateTo::serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExp { if (str != nullptr) { - _duration = atof(str); + _duration = utils::atof(str); } } @@ -432,7 +432,7 @@ void TRotateTo::serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExp { if (str != nullptr) { - _deltaAngle = atof(str); + _deltaAngle = utils::atof(str); } } } @@ -537,7 +537,7 @@ void TRotateBy::serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExp { if (str != nullptr) { - _duration = atof(str); + _duration = utils::atof(str); } } @@ -545,7 +545,7 @@ void TRotateBy::serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExp { if (str != nullptr) { - _deltaAngle = atof(str); + _deltaAngle = utils::atof(str); } } else if (key == "IsReverse") @@ -647,7 +647,7 @@ void TScaleTo::serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpC { if (str != nullptr) { - _duration = atof(str); + _duration = utils::atof(str); } } @@ -655,14 +655,14 @@ void TScaleTo::serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpC { if (str != nullptr) { - _scale.x = atof(str); + _scale.x = utils::atof(str); } } else if (key == "ScaleY") { if (str != nullptr) { - _scale.y = atof(str); + _scale.y = utils::atof(str); } } } @@ -771,7 +771,7 @@ void TScaleBy::serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpC { if (str != nullptr) { - _duration = atof(str); + _duration = utils::atof(str); } } @@ -779,14 +779,14 @@ void TScaleBy::serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpC { if (str != nullptr) { - _scale.x = atof(str); + _scale.x = utils::atof(str); } } else if (key == "ScaleY") { if (str != nullptr) { - _scale.y = atof(str); + _scale.y = utils::atof(str); } } else if (key == "IsReverse") @@ -889,7 +889,7 @@ void TSkewTo::serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCo { if (str != nullptr) { - _duration = atof(str); + _duration = utils::atof(str); } } @@ -897,14 +897,14 @@ void TSkewTo::serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCo { if (str != nullptr) { - _skew.x = atof(str); + _skew.x = utils::atof(str); } } else if (key == "SkewY") { if (str != nullptr) { - _skew.y = atof(str); + _skew.y = utils::atof(str); } } } @@ -1012,7 +1012,7 @@ void TSkewBy::serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCo { if (str != nullptr) { - _duration = atof(str); + _duration = utils::atof(str); } } @@ -1020,14 +1020,14 @@ void TSkewBy::serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCo { if (str != nullptr) { - _skew.x = atof(str); + _skew.x = utils::atof(str); } } else if (key == "SkewY") { if (str != nullptr) { - _skew.y = atof(str); + _skew.y = utils::atof(str); } } else if (key == "IsReverse") diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioSceneTest/TriggerCode/cons.cpp b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioSceneTest/TriggerCode/cons.cpp index 9ed21d1579..1810fc2112 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioSceneTest/TriggerCode/cons.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioSceneTest/TriggerCode/cons.cpp @@ -64,7 +64,7 @@ void TimeElapsed::serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stE { if (str != nullptr) { - _totalTime = atof(str); //DICTOOL->getFloatValue_json(subDict, "value"); + _totalTime = utils::atof(str); //DICTOOL->getFloatValue_json(subDict, "value"); } } } From 2354c79c3f359a7627259c9f1b82b8593a836ef4 Mon Sep 17 00:00:00 2001 From: boyu0 Date: Mon, 14 Jul 2014 23:05:16 +0800 Subject: [PATCH 3/3] Fix compile error --- cocos/base/CCUserDefault.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/cocos/base/CCUserDefault.cpp b/cocos/base/CCUserDefault.cpp index d49d9c1551..ef52f03c0d 100644 --- a/cocos/base/CCUserDefault.cpp +++ b/cocos/base/CCUserDefault.cpp @@ -27,6 +27,7 @@ THE SOFTWARE. #include "platform/CCFileUtils.h" #include "tinyxml2.h" #include "base/base64.h" +#include "base/ccUtils.h" #if (CC_TARGET_PLATFORM != CC_PLATFORM_IOS && CC_TARGET_PLATFORM != CC_PLATFORM_MAC && CC_TARGET_PLATFORM != CC_PLATFORM_ANDROID)