diff --git a/.clang-tidy b/.clang-tidy index f44b7418125e..cfef82b94a59 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -3,6 +3,11 @@ Checks: > -*, performance-faster-string-find, performance-for-range-copy, + performance-implicit-conversion-in-loop, + performance-inefficient-algorithm, + performance-inefficient-vector-operation, + performance-move-const-arg, + performance-type-promotion-in-math-fn, WarningsAsErrors: '*' HeaderFilterRegex: '/(?!external)/.*' diff --git a/cocos/2d/CCFastTMXLayer.cpp b/cocos/2d/CCFastTMXLayer.cpp index 54b09d2227cb..eb9bc3446ce4 100644 --- a/cocos/2d/CCFastTMXLayer.cpp +++ b/cocos/2d/CCFastTMXLayer.cpp @@ -36,6 +36,7 @@ THE SOFTWARE. */ #include "2d/CCFastTMXLayer.h" +#include #include "2d/CCFastTMXTiledMap.h" #include "2d/CCSprite.h" #include "2d/CCCamera.h" @@ -209,10 +210,10 @@ void TMXLayer::updateTiles(const Rect& culledRect) visibleTiles.origin.y += 1; // if x=0.7, width=9.5, we need to draw number 0~10 of tiles, and so is height. - visibleTiles.size.width = ceil(visibleTiles.origin.x + visibleTiles.size.width) - floor(visibleTiles.origin.x); - visibleTiles.size.height = ceil(visibleTiles.origin.y + visibleTiles.size.height) - floor(visibleTiles.origin.y); - visibleTiles.origin.x = floor(visibleTiles.origin.x); - visibleTiles.origin.y = floor(visibleTiles.origin.y); + visibleTiles.size.width = std::ceil(visibleTiles.origin.x + visibleTiles.size.width) - std::floor(visibleTiles.origin.x); + visibleTiles.size.height = std::ceil(visibleTiles.origin.y + visibleTiles.size.height) - std::floor(visibleTiles.origin.y); + visibleTiles.origin.x = std::floor(visibleTiles.origin.x); + visibleTiles.origin.y = std::floor(visibleTiles.origin.y); // for the bigger tiles. int tilesOverX = 0; @@ -221,8 +222,8 @@ void TMXLayer::updateTiles(const Rect& culledRect) float tileSizeMax = std::max(tileSize.width, tileSize.height); if (_layerOrientation == FAST_TMX_ORIENTATION_ORTHO) { - tilesOverX = ceil(tileSizeMax / mapTileSize.width) - 1; - tilesOverY = ceil(tileSizeMax / mapTileSize.height) - 1; + tilesOverX = std::ceil(tileSizeMax / mapTileSize.width) - 1; + tilesOverY = std::ceil(tileSizeMax / mapTileSize.height) - 1; if (tilesOverX < 0) tilesOverX = 0; if (tilesOverY < 0) tilesOverY = 0; @@ -234,8 +235,8 @@ void TMXLayer::updateTiles(const Rect& culledRect) if (overTileRect.size.height < 0) overTileRect.size.height = 0; overTileRect = RectApplyTransform(overTileRect, nodeToTileTransform); - tilesOverX = ceil(overTileRect.origin.x + overTileRect.size.width) - floor(overTileRect.origin.x); - tilesOverY = ceil(overTileRect.origin.y + overTileRect.size.height) - floor(overTileRect.origin.y); + tilesOverX = std::ceil(overTileRect.origin.x + overTileRect.size.width) - std::floor(overTileRect.origin.x); + tilesOverY = std::ceil(overTileRect.origin.y + overTileRect.size.height) - std::floor(overTileRect.origin.y); } else { @@ -346,15 +347,15 @@ void TMXLayer::setupTiles() switch (_layerOrientation) { case FAST_TMX_ORIENTATION_ORTHO: - _screenGridSize.width = ceil(screenSize.width / _mapTileSize.width) + 1; - _screenGridSize.height = ceil(screenSize.height / _mapTileSize.height) + 1; + _screenGridSize.width = std::ceil(screenSize.width / _mapTileSize.width) + 1; + _screenGridSize.height = std::ceil(screenSize.height / _mapTileSize.height) + 1; // tiles could be bigger than the grid, add additional rows if needed _screenGridSize.height += _tileSet->_tileSize.height / _mapTileSize.height; break; case FAST_TMX_ORIENTATION_ISO: - _screenGridSize.width = ceil(screenSize.width / _mapTileSize.width) + 2; - _screenGridSize.height = ceil(screenSize.height / (_mapTileSize.height/2)) + 4; + _screenGridSize.width = std::ceil(screenSize.width / _mapTileSize.width) + 2; + _screenGridSize.height = std::ceil(screenSize.height / (_mapTileSize.height/2)) + 4; break; case FAST_TMX_ORIENTATION_HEX: default: diff --git a/cocos/2d/CCLight.cpp b/cocos/2d/CCLight.cpp index c47998bdfc0a..07331f31eae0 100644 --- a/cocos/2d/CCLight.cpp +++ b/cocos/2d/CCLight.cpp @@ -23,6 +23,7 @@ ****************************************************************************/ #include "2d/CCLight.h" +#include #include "2d/CCScene.h" NS_CC_BEGIN @@ -60,7 +61,7 @@ void BaseLight::onExit() void BaseLight::setRotationFromDirection( const Vec3 &direction ) { - float projLen = sqrt(direction.x * direction.x + direction.z * direction.z); + float projLen = std::sqrt(direction.x * direction.x + direction.z * direction.z); float rotY = CC_RADIANS_TO_DEGREES(atan2f(-direction.x, -direction.z)); float rotX = -CC_RADIANS_TO_DEGREES(atan2f(-direction.y, projLen)); setRotation3D(Vec3(rotX, rotY, 0.0f)); @@ -205,4 +206,4 @@ AmbientLight::~AmbientLight() } -NS_CC_END \ No newline at end of file +NS_CC_END diff --git a/cocos/2d/CCTweenFunction.cpp b/cocos/2d/CCTweenFunction.cpp index dd65234b341b..f445b380f426 100644 --- a/cocos/2d/CCTweenFunction.cpp +++ b/cocos/2d/CCTweenFunction.cpp @@ -24,6 +24,7 @@ THE SOFTWARE. ****************************************************************************/ #include "2d/CCTweenFunction.h" +#include #define _USE_MATH_DEFINES // needed for M_PI and M_PI2 #include // M_PI @@ -316,20 +317,20 @@ float expoEaseInOut(float time) // Circ Ease float circEaseIn(float time) { - return -1 * (sqrt(1 - time * time) - 1); + return -1 * (std::sqrt(1 - time * time) - 1); } float circEaseOut(float time) { time = time - 1; - return sqrt(1 - time * time); + return std::sqrt(1 - time * time); } float circEaseInOut(float time) { time = time * 2; if (time < 1) - return -0.5f * (sqrt(1 - time * time) - 1); + return -0.5f * (std::sqrt(1 - time * time) - 1); time -= 2; - return 0.5f * (sqrt(1 - time * time) + 1); + return 0.5f * (std::sqrt(1 - time * time) + 1); } diff --git a/cocos/3d/CCOBB.cpp b/cocos/3d/CCOBB.cpp index a5cd8ac09409..61b9800d18f6 100755 --- a/cocos/3d/CCOBB.cpp +++ b/cocos/3d/CCOBB.cpp @@ -24,6 +24,7 @@ ****************************************************************************/ #include "3d/CCOBB.h" +#include NS_CC_BEGIN @@ -109,7 +110,7 @@ static void _getEigenVectors(Mat4* vout, Vec3* dout, Mat4 a) for(i = 0; i < 50; i++) { sm = 0.0; - for(ip = 0; ip < n; ip++) for(iq = ip+1; iq < n; iq++) sm += fabs(a.m[ip + 4 * iq]); + for(ip = 0; ip < n; ip++) for(iq = ip+1; iq < n; iq++) sm += std::fabs(a.m[ip + 4 * iq]); if( fabs(sm) < FLT_EPSILON ) { v.transpose(); @@ -127,15 +128,15 @@ static void _getEigenVectors(Mat4* vout, Vec3* dout, Mat4 a) { for(iq = ip + 1; iq < n; iq++) { - g = 100.0 * fabs(a.m[ip + iq * 4]); + g = 100.0 * std::fabs(a.m[ip + iq * 4]); float dmip = _getElement(d, ip); float dmiq = _getElement(d, iq); - if( i>3 && fabs(dmip) + g == fabs(dmip) && fabs(dmiq) + g == fabs(dmiq) ) + if( i>3 && std::fabs(dmip) + g == std::fabs(dmip) && std::fabs(dmiq) + g == std::fabs(dmiq) ) { a.m[ip + 4 * iq] = 0.0; } - else if (fabs(a.m[ip + 4 * iq]) > tresh) + else if (std::fabs(a.m[ip + 4 * iq]) > tresh) { h = dmiq - dmip; if (fabs(h) + g == fabs(h)) diff --git a/cocos/base/ccUTF8.cpp b/cocos/base/ccUTF8.cpp index b4714493f93a..7100b97344a7 100644 --- a/cocos/base/ccUTF8.cpp +++ b/cocos/base/ccUTF8.cpp @@ -526,6 +526,7 @@ long cc_utf8_strlen (const char * p, int /*max*/) unsigned int cc_utf8_find_last_not_char(const std::vector& str, unsigned short c) { std::vector char16Vector; + char16Vector.reserve(str.size()); for (const auto& e : str) { char16Vector.push_back(e); diff --git a/cocos/deprecated/CCString.cpp b/cocos/deprecated/CCString.cpp index 143fb73b678d..f639d5f1255a 100644 --- a/cocos/deprecated/CCString.cpp +++ b/cocos/deprecated/CCString.cpp @@ -260,7 +260,7 @@ __String* __String::createWithFormat(const char* format, ...) __String* __String::createWithContentsOfFile(const std::string &filename) { std::string str = FileUtils::getInstance()->getStringFromFile(filename); - return __String::create(std::move(str)); + return __String::create(str); } void __String::acceptVisitor(DataVisitor &visitor) diff --git a/cocos/editor-support/cocostudio/CCTransformHelp.cpp b/cocos/editor-support/cocostudio/CCTransformHelp.cpp index e27529d1694a..bfc311fd2c90 100644 --- a/cocos/editor-support/cocostudio/CCTransformHelp.cpp +++ b/cocos/editor-support/cocostudio/CCTransformHelp.cpp @@ -24,6 +24,7 @@ THE SOFTWARE. ****************************************************************************/ #include "editor-support/cocostudio/CCTransformHelp.h" +#include #include "editor-support/cocostudio/CCUtilMath.h" using namespace cocos2d; @@ -99,8 +100,8 @@ void TransformHelp::nodeToMatrix(const BaseData &node, AffineTransform &matrix) { if (node.skewX == -node.skewY) { - double sine = sin(node.skewX); - double cosine = cos(node.skewX); + double sine = std::sin(node.skewX); + double cosine = std::cos(node.skewX); matrix.a = node.scaleX * cosine; matrix.b = node.scaleX * -sine; @@ -109,10 +110,10 @@ void TransformHelp::nodeToMatrix(const BaseData &node, AffineTransform &matrix) } else { - matrix.a = node.scaleX * cos(node.skewY); - matrix.b = node.scaleX * sin(node.skewY); - matrix.c = node.scaleY * sin(node.skewX); - matrix.d = node.scaleY * cos(node.skewX); + matrix.a = node.scaleX * std::cos(node.skewY); + matrix.b = node.scaleX * std::sin(node.skewY); + matrix.c = node.scaleY * std::sin(node.skewX); + matrix.d = node.scaleY * std::cos(node.skewX); } matrix.tx = node.x; @@ -125,8 +126,8 @@ void TransformHelp::nodeToMatrix(const BaseData &node, Mat4 &matrix) if (node.skewX == -node.skewY) { - double sine = sin(node.skewX); - double cosine = cos(node.skewX); + double sine = std::sin(node.skewX); + double cosine = std::cos(node.skewX); matrix.m[0] = node.scaleX * cosine; matrix.m[1] = node.scaleX * -sine; @@ -135,10 +136,10 @@ void TransformHelp::nodeToMatrix(const BaseData &node, Mat4 &matrix) } else { - matrix.m[0] = node.scaleX * cos(node.skewY); - matrix.m[1] = node.scaleX * sin(node.skewY); - matrix.m[4] = node.scaleY * sin(node.skewX); - matrix.m[5] = node.scaleY * cos(node.skewX); + matrix.m[0] = node.scaleX * std::cos(node.skewY); + matrix.m[1] = node.scaleX * std::sin(node.skewY); + matrix.m[4] = node.scaleY * std::sin(node.skewX); + matrix.m[5] = node.scaleY * std::cos(node.skewX); } matrix.m[12] = node.x; @@ -166,8 +167,8 @@ void TransformHelp::matrixToNode(const AffineTransform &matrix, BaseData &node) node.skewX = -(atan2f(helpPoint1.y, helpPoint1.x) - 1.5707964f); node.skewY = atan2f(helpPoint2.y, helpPoint2.x); - node.scaleX = sqrt(matrix.a * matrix.a + matrix.b * matrix.b); - node.scaleY = sqrt(matrix.c * matrix.c + matrix.d * matrix.d); + node.scaleX = std::sqrt(matrix.a * matrix.a + matrix.b * matrix.b); + node.scaleY = std::sqrt(matrix.c * matrix.c + matrix.d * matrix.d); node.x = matrix.tx; node.y = matrix.ty; } @@ -192,8 +193,8 @@ void TransformHelp::matrixToNode(const Mat4 &matrix, BaseData &node) node.skewX = -(atan2f(helpPoint1.y, helpPoint1.x) - 1.5707964f); node.skewY = atan2f(helpPoint2.y, helpPoint2.x); - node.scaleX = sqrt(matrix.m[0] * matrix.m[0] + matrix.m[1] * matrix.m[1]); - node.scaleY = sqrt(matrix.m[4] * matrix.m[4] + matrix.m[5] * matrix.m[5]); + node.scaleX = std::sqrt(matrix.m[0] * matrix.m[0] + matrix.m[1] * matrix.m[1]); + node.scaleY = std::sqrt(matrix.m[4] * matrix.m[4] + matrix.m[5] * matrix.m[5]); node.x = matrix.m[12]; node.y = matrix.m[13]; } diff --git a/cocos/editor-support/cocostudio/CCUtilMath.cpp b/cocos/editor-support/cocostudio/CCUtilMath.cpp index 971e78f4b225..fcd40aa91690 100644 --- a/cocos/editor-support/cocostudio/CCUtilMath.cpp +++ b/cocos/editor-support/cocostudio/CCUtilMath.cpp @@ -24,6 +24,7 @@ THE SOFTWARE. ****************************************************************************/ #include "editor-support/cocostudio/CCUtilMath.h" +#include using namespace cocos2d; @@ -72,8 +73,8 @@ Vec2 circleTo(float t, Vec2 ¢er, float radius, float fromRadian, float radia { Vec2 p; - p.x = center.x + radius * cos(fromRadian + radianDif * t); - p.y = center.y + radius * sin(fromRadian + radianDif * t); + p.x = center.x + radius * std::cos(fromRadian + radianDif * t); + p.y = center.y + radius * std::sin(fromRadian + radianDif * t); return p; } diff --git a/cocos/editor-support/cocostudio/TriggerMng.cpp b/cocos/editor-support/cocostudio/TriggerMng.cpp index f61ed9651014..c3364c48899d 100755 --- a/cocos/editor-support/cocostudio/TriggerMng.cpp +++ b/cocos/editor-support/cocostudio/TriggerMng.cpp @@ -24,6 +24,7 @@ THE SOFTWARE. ****************************************************************************/ #include "editor-support/cocostudio/TriggerMng.h" +#include #include "json/prettywriter.h" #include "json/stringbuffer.h" #include "base/CCDirector.h" @@ -275,7 +276,7 @@ void TriggerMng::buildJson(rapidjson::Document &document, cocostudio::CocoLoader { int nV = atoi(str3); float fV = utils::atof(str3); - if (fabs(nV - fV) < 0.0000001) + if (std::fabs(nV - fV) < 0.0000001) { dataitem.AddMember("value", nV, allocator); } @@ -351,7 +352,7 @@ void TriggerMng::buildJson(rapidjson::Document &document, cocostudio::CocoLoader { int nV = atoi(str5); float fV = utils::atof(str5); - if (fabs(nV - fV) < 0.0000001) + if (std::fabs(nV - fV) < 0.0000001) { dataitem.AddMember("value", nV, allocator); } diff --git a/cocos/editor-support/spine/Bone.c b/cocos/editor-support/spine/Bone.c index 471cf3217052..6a167cbc0ccf 100644 --- a/cocos/editor-support/spine/Bone.c +++ b/cocos/editor-support/spine/Bone.c @@ -166,7 +166,7 @@ void spBone_updateWorldTransformWith (spBone* self, float x, float y, float rota za *= s; zc *= s; s = SQRT(za * za + zc * zc); - r = PI / 2 + atan2(zc, za); + r = PI / 2 + atan2f(zc, za); zb = COS(r) * s; zd = SIN(r) * s; la = COS_DEG(shearX) * scaleX; diff --git a/cocos/platform/CCFileUtils.cpp b/cocos/platform/CCFileUtils.cpp index 3106bcfce2b2..beb879f1f04b 100644 --- a/cocos/platform/CCFileUtils.cpp +++ b/cocos/platform/CCFileUtils.cpp @@ -898,7 +898,7 @@ std::string FileUtils::fullPathForDirectory(const std::string &dir) const { for (const auto& resolutionIt : _searchResolutionsOrderArray) { - fullpath = searchIt + longdir + resolutionIt; + fullpath.append(searchIt).append(longdir).append(resolutionIt); auto exists = isDirectoryExistInternal(fullpath); if (exists && !fullpath.empty()) @@ -1180,7 +1180,7 @@ bool FileUtils::isDirectoryExist(const std::string& dirPath) const for (const auto& resolutionIt : _searchResolutionsOrderArray) { // searchPath + file_path + resourceDirectory - fullpath = fullPathForDirectory(searchIt + dirPath + resolutionIt); + fullpath = fullPathForDirectory(std::string(searchIt).append(dirPath).append(resolutionIt)); if (isDirectoryExistInternal(fullpath)) { _fullPathCacheDir.emplace(dirPath, fullpath); diff --git a/cocos/renderer/CCGLProgramState.cpp b/cocos/renderer/CCGLProgramState.cpp index 2ff33790efb1..ef64487ed96c 100644 --- a/cocos/renderer/CCGLProgramState.cpp +++ b/cocos/renderer/CCGLProgramState.cpp @@ -500,7 +500,7 @@ bool GLProgramState::init(GLProgram* glprogram) for(auto &uniform : _glprogram->_userUniforms) { UniformValue value(&uniform.second, _glprogram); - _uniforms[uniform.second.location] = std::move(value); + _uniforms[uniform.second.location] = value; _uniformsByName[uniform.first] = uniform.second.location; } diff --git a/extensions/GUI/CCControlExtension/CCControlPotentiometer.cpp b/extensions/GUI/CCControlExtension/CCControlPotentiometer.cpp index ddb8838ce5e5..3710bfaa9180 100644 --- a/extensions/GUI/CCControlExtension/CCControlPotentiometer.cpp +++ b/extensions/GUI/CCControlExtension/CCControlPotentiometer.cpp @@ -28,6 +28,7 @@ */ #include "CCControlPotentiometer.h" +#include NS_CC_EXT_BEGIN @@ -206,7 +207,7 @@ float ControlPotentiometer::distanceBetweenPointAndPoint(Vec2 point1, Vec2 point { float dx = point1.x - point2.x; float dy = point1.y - point2.y; - return sqrt(dx*dx + dy*dy); + return std::sqrt(dx*dx + dy*dy); } float ControlPotentiometer::angleInDegreesBetweenLineFromPoint_toPoint_toLineFromPoint_toPoint( @@ -220,8 +221,8 @@ float ControlPotentiometer::angleInDegreesBetweenLineFromPoint_toPoint_toLineFro float c = endLineB.x - beginLineB.x; float d = endLineB.y - beginLineB.y; - float atanA = atan2(a, b); - float atanB = atan2(c, d); + float atanA = std::atan2(a, b); + float atanB = std::atan2(c, d); // convert radiants to degrees return (atanA - atanB) * 180 / M_PI; diff --git a/extensions/GUI/CCControlExtension/CCControlSaturationBrightnessPicker.cpp b/extensions/GUI/CCControlExtension/CCControlSaturationBrightnessPicker.cpp index 1338709bef7c..f4b0dbc06d83 100644 --- a/extensions/GUI/CCControlExtension/CCControlSaturationBrightnessPicker.cpp +++ b/extensions/GUI/CCControlExtension/CCControlSaturationBrightnessPicker.cpp @@ -32,6 +32,7 @@ */ #include "CCControlSaturationBrightnessPicker.h" +#include NS_CC_EXT_BEGIN @@ -154,8 +155,8 @@ void ControlSaturationBrightnessPicker::updateSliderPosition(Vec2 sliderPosition else if (sliderPosition.y > _startPos.y + boxPos + boxSize) sliderPosition.y = _startPos.y + boxPos + boxSize; // Use the position / slider width to determine the percentage the dragger is at - _saturation = 1.0f - fabs((_startPos.x + (float)boxPos - sliderPosition.x)/(float)boxSize); - _brightness = fabs((_startPos.y + (float)boxPos - sliderPosition.y)/(float)boxSize); + _saturation = 1.0f - std::fabs((_startPos.x + (float)boxPos - sliderPosition.x)/(float)boxSize); + _brightness = std::fabs((_startPos.y + (float)boxPos - sliderPosition.y)/(float)boxSize); } bool ControlSaturationBrightnessPicker::checkSliderPosition(Vec2 location) diff --git a/extensions/GUI/CCScrollView/CCScrollView.cpp b/extensions/GUI/CCScrollView/CCScrollView.cpp index aa5aba77a096..3db14e523227 100644 --- a/extensions/GUI/CCScrollView/CCScrollView.cpp +++ b/extensions/GUI/CCScrollView/CCScrollView.cpp @@ -25,6 +25,7 @@ ****************************************************************************/ #include "CCScrollView.h" +#include #include "platform/CCDevice.h" #include "2d/CCActionInstant.h" #include "2d/CCActionInterval.h" @@ -787,7 +788,7 @@ void ScrollView::onTouchMoved(Touch* touch, Event* /*event*/) } } - if (!_touchMoved && fabs(convertDistanceFromPointToInch(dis)) < MOVE_INCH ) + if (!_touchMoved && std::fabs(convertDistanceFromPointToInch(dis)) < MOVE_INCH ) { //CCLOG("Invalid movement, distance = [%f, %f], disInch = %f", moveDistance.x, moveDistance.y); return; diff --git a/extensions/Particle3D/PU/CCPUMeshSurfaceEmitter.cpp b/extensions/Particle3D/PU/CCPUMeshSurfaceEmitter.cpp index 48e6d28c5a78..e3996ef38f8d 100644 --- a/extensions/Particle3D/PU/CCPUMeshSurfaceEmitter.cpp +++ b/extensions/Particle3D/PU/CCPUMeshSurfaceEmitter.cpp @@ -25,6 +25,7 @@ ****************************************************************************/ #include "CCPUMeshSurfaceEmitter.h" +#include #include "extensions/Particle3D/PU/CCPUParticleSystem3D.h" #include "extensions/Particle3D/PU/CCPUUtil.h" @@ -48,14 +49,14 @@ inline void PUTriangle::calculateSquareSurface (void) */ // a, b and c are the length of each triangle - float a = sqrt ( (v1.x - v3.x) * (v1.x - v3.x) + - (v1.y - v3.y) * (v1.y - v3.y) + + float a = std::sqrt ((v1.x - v3.x) * (v1.x - v3.x) + + (v1.y - v3.y) * (v1.y - v3.y) + (v1.z - v3.z) * (v1.z - v3.z)); - float b = sqrt ( (v2.x - v1.x) * (v2.x - v1.x) + - (v2.y - v1.y) * (v2.y - v1.y) + + float b = std::sqrt ((v2.x - v1.x) * (v2.x - v1.x) + + (v2.y - v1.y) * (v2.y - v1.y) + (v2.z - v1.z) * (v2.z - v1.z)); - float c = sqrt ( (v3.x - v2.x) * (v3.x - v2.x) + - (v3.y - v2.y) * (v3.y - v2.y) + + float c = std::sqrt ((v3.x - v2.x) * (v3.x - v2.x) + + (v3.y - v2.y) * (v3.y - v2.y) + (v3.z - v2.z) * (v3.z - v2.z)); float p = 0.5f * (a + b + c); @@ -203,7 +204,7 @@ inline float MeshInfo::getGaussianRandom (float high, float cutoff) } while (w >= 1.0f); - w = sqrt((-2.0f * ::log(w)) / w); + w = std::sqrt((-2.0f * std::log(w)) / w); y1 = std::abs(x1 * w); y1 = y1 > cutoff ? cutoff : y1; y1 *= high / cutoff; diff --git a/extensions/Particle3D/PU/CCPUOnTimeObserver.cpp b/extensions/Particle3D/PU/CCPUOnTimeObserver.cpp index e89757e7c633..d3f2b16a9617 100644 --- a/extensions/Particle3D/PU/CCPUOnTimeObserver.cpp +++ b/extensions/Particle3D/PU/CCPUOnTimeObserver.cpp @@ -25,6 +25,7 @@ ****************************************************************************/ #include "extensions/Particle3D/PU/CCPUOnTimeObserver.h" +#include #include "extensions/Particle3D/PU/CCPUParticleSystem3D.h" NS_CC_BEGIN @@ -35,7 +36,7 @@ const bool PUOnTimeObserver::DEFAULT_SINCE_START_SYSTEM = false; static bool almostEquals(float a, float b, float epsilon = std::numeric_limits::epsilon()) { - return fabs(a - b) <= ( (fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon); + return std::fabs(a - b) <= ( (std::fabs(a) < std::fabs(b) ? std::fabs(b) : std::fabs(a)) * epsilon); }; //----------------------------------------------------------------------- diff --git a/extensions/Particle3D/PU/CCPUOnVelocityObserver.cpp b/extensions/Particle3D/PU/CCPUOnVelocityObserver.cpp index 92d370028c2e..c91b9b98bea2 100644 --- a/extensions/Particle3D/PU/CCPUOnVelocityObserver.cpp +++ b/extensions/Particle3D/PU/CCPUOnVelocityObserver.cpp @@ -25,13 +25,14 @@ ****************************************************************************/ #include "extensions/Particle3D/PU/CCPUOnVelocityObserver.h" +#include #include "extensions/Particle3D/PU/CCPUParticleSystem3D.h" NS_CC_BEGIN static bool almostEquals(float a, float b, float epsilon = std::numeric_limits::epsilon()) { - return fabs(a - b) <= ( (fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon); + return std::fabs(a - b) <= ( (std::fabs(a) < std::fabs(b) ? std::fabs(b) : std::fabs(a)) * epsilon); }; // Constants diff --git a/extensions/Particle3D/PU/CCPUScriptLexer.cpp b/extensions/Particle3D/PU/CCPUScriptLexer.cpp index 79d43cf6faf5..cdde136cae17 100644 --- a/extensions/Particle3D/PU/CCPUScriptLexer.cpp +++ b/extensions/Particle3D/PU/CCPUScriptLexer.cpp @@ -172,8 +172,10 @@ void PUScriptLexer::openLexer(const std::string &str,const std::string &source,P else { // Backtrack here and allow a backslash normally within the quote - if(lastc == backslash) - lexeme = lexeme + "\\" + c; + if(lastc == backslash) { + lexeme += '\\'; + lexeme += c; + } else lexeme += c; } diff --git a/extensions/Particle3D/PU/CCPUSineForceAffector.cpp b/extensions/Particle3D/PU/CCPUSineForceAffector.cpp index d8ab22bc9c96..6fac5e6ab360 100644 --- a/extensions/Particle3D/PU/CCPUSineForceAffector.cpp +++ b/extensions/Particle3D/PU/CCPUSineForceAffector.cpp @@ -25,6 +25,7 @@ ****************************************************************************/ #include "CCPUSineForceAffector.h" +#include #include "extensions/Particle3D/PU/CCPUParticleSystem3D.h" NS_CC_BEGIN @@ -50,7 +51,7 @@ void PUSineForceAffector::preUpdateAffector(float deltaTime) { // Scale by time _angle += _frequency * deltaTime; - float sineValue = sin(_angle); + float sineValue = std::sin(_angle); _scaledVector = _forceVector * deltaTime * sineValue; if (_angle > M_PI * 2.0f) diff --git a/tests/cpp-tests/Classes/BugsTest/Bug-1174.cpp b/tests/cpp-tests/Classes/BugsTest/Bug-1174.cpp index 0680e587abe7..6694207f939a 100644 --- a/tests/cpp-tests/Classes/BugsTest/Bug-1174.cpp +++ b/tests/cpp-tests/Classes/BugsTest/Bug-1174.cpp @@ -28,6 +28,7 @@ // #include "Bug-1174.h" +#include USING_NS_CC; @@ -47,7 +48,7 @@ int check_for_error( Vec2 p1, Vec2 p2, Vec2 p3, Vec2 p4, float s, float t ) auto hitPoint2 = p1 + p2_p1_s; // Since float has rounding errors, only check if diff is < 0.05 - if( (fabs( hitPoint1.x - hitPoint2.x) > 0.1f) || ( fabs(hitPoint1.y - hitPoint2.y) > 0.1f) ) + if( (std::fabs( hitPoint1.x - hitPoint2.x) > 0.1f) || ( std::fabs(hitPoint1.y - hitPoint2.y) > 0.1f) ) { log("ERROR: (%f,%f) != (%f,%f)", hitPoint1.x, hitPoint1.y, hitPoint2.x, hitPoint2.y); return 1; diff --git a/tests/cpp-tests/Classes/Camera3DTest/Camera3DTest.cpp b/tests/cpp-tests/Classes/Camera3DTest/Camera3DTest.cpp index 9302cec058e4..fbec4c16cb80 100644 --- a/tests/cpp-tests/Classes/Camera3DTest/Camera3DTest.cpp +++ b/tests/cpp-tests/Classes/Camera3DTest/Camera3DTest.cpp @@ -25,6 +25,7 @@ THE SOFTWARE. ****************************************************************************/ #include "Camera3DTest.h" +#include #include "testResource.h" #include "ui/UISlider.h" @@ -1137,7 +1138,7 @@ void CameraArcBallDemo::calculateArcBall( cocos2d::Vec3 & axis, float & angle, f //clamp -1 to 1 if (t > 1.0) t = 1.0; if (t < -1.0) t = -1.0; - angle = asin(t); //rotation angle + angle = std::asin(t); //rotation angle } /* project an x,y pair onto a sphere of radius r or a @@ -1145,10 +1146,10 @@ hyperbolic sheet if we are away from the center of the sphere. */ float CameraArcBallDemo::projectToSphere( float r, float x, float y ) { float d, t, z; - d = sqrt(x*x + y*y); + d = std::sqrt(x*x + y*y); if (d < r * 0.70710678118654752440)//inside sphere { - z = sqrt(r*r - d*d); + z = std::sqrt(r*r - d*d); } else //on hyperbola { diff --git a/tests/cpp-tests/Classes/ClickAndMoveTest/ClickAndMoveTest.cpp b/tests/cpp-tests/Classes/ClickAndMoveTest/ClickAndMoveTest.cpp index 92f8ba1390f9..f513770a6b81 100644 --- a/tests/cpp-tests/Classes/ClickAndMoveTest/ClickAndMoveTest.cpp +++ b/tests/cpp-tests/Classes/ClickAndMoveTest/ClickAndMoveTest.cpp @@ -23,6 +23,7 @@ ****************************************************************************/ #include "ClickAndMoveTest.h" +#include #include "../testResource.h" USING_NS_CC; @@ -78,12 +79,12 @@ void ClickAndMoveTestCase::onTouchEnded(Touch* touch, Event *event) float a = location.y - s->getPosition().y; float at = (float) CC_RADIANS_TO_DEGREES( atanf( o/a) ); - if( a < 0 ) + if( a < 0) { - if( o < 0 ) - at = 180 + fabs(at); + if( o < 0 ) + at = 180 + std::fabs(at); else - at = 180 - fabs(at); + at = 180 - std::fabs(at); } s->runAction( RotateTo::create(1, at) ); diff --git a/tests/cpp-tests/Classes/CocosDenshionTest/CocosDenshionTest.cpp b/tests/cpp-tests/Classes/CocosDenshionTest/CocosDenshionTest.cpp index cbdc7094418c..27e6b5e3cb90 100644 --- a/tests/cpp-tests/Classes/CocosDenshionTest/CocosDenshionTest.cpp +++ b/tests/cpp-tests/Classes/CocosDenshionTest/CocosDenshionTest.cpp @@ -23,6 +23,7 @@ ****************************************************************************/ #include "CocosDenshionTest.h" +#include #include "cocos2d.h" #include "extensions/GUI/CCControlExtension/CCControlSlider.h" #include "audio/include/SimpleAudioEngine.h" @@ -426,13 +427,13 @@ void CocosDenshionTest::addChildAt(Node *node, float percentageX, float percenta void CocosDenshionTest::updateVolumes(float) { const float musicVolume = _sliderMusicVolume->getValue(); - if (fabs(musicVolume - _musicVolume) > 0.001) { + if (std::fabs(musicVolume - _musicVolume) > 0.001) { _musicVolume = musicVolume; SimpleAudioEngine::getInstance()->setBackgroundMusicVolume(_musicVolume); } const float effectsVolume = _sliderEffectsVolume->getValue(); - if (fabs(effectsVolume - _effectsVolume) > 0.001) { + if (std::fabs(effectsVolume - _effectsVolume) > 0.001) { _effectsVolume = effectsVolume; SimpleAudioEngine::getInstance()->setEffectsVolume(_effectsVolume); } diff --git a/tests/cpp-tests/Classes/LabelTest/LabelTest.cpp b/tests/cpp-tests/Classes/LabelTest/LabelTest.cpp index e012f3750605..b8fc8e738f4f 100644 --- a/tests/cpp-tests/Classes/LabelTest/LabelTest.cpp +++ b/tests/cpp-tests/Classes/LabelTest/LabelTest.cpp @@ -23,6 +23,7 @@ ****************************************************************************/ #include "LabelTest.h" +#include #include "../testResource.h" #include "cocos2d.h" @@ -1234,7 +1235,7 @@ void BitmapFontMultiLineAlignment::onTouchesMoved(const std::vector& tou this->_arrowsShouldRetain->setPosition(Vec2(MAX(MIN(location.x, ArrowsMax*winSize.width), ArrowsMin*winSize.width), this->_arrowsShouldRetain->getPosition().y)); - float labelWidth = fabs(this->_arrowsShouldRetain->getPosition().x - this->_labelShouldRetain->getPosition().x) * 2; + float labelWidth = std::fabs(this->_arrowsShouldRetain->getPosition().x - this->_labelShouldRetain->getPosition().x) * 2; _labelShouldRetain->setWidth(labelWidth); } diff --git a/tests/cpp-tests/Classes/LabelTest/LabelTestNew.cpp b/tests/cpp-tests/Classes/LabelTest/LabelTestNew.cpp index 551e99ef913e..d53e67a43886 100644 --- a/tests/cpp-tests/Classes/LabelTest/LabelTestNew.cpp +++ b/tests/cpp-tests/Classes/LabelTest/LabelTestNew.cpp @@ -23,6 +23,7 @@ ****************************************************************************/ #include "LabelTestNew.h" +#include #include "../testResource.h" #include "renderer/CCRenderer.h" #include "2d/CCFontAtlasCache.h" @@ -785,7 +786,7 @@ void LabelFNTMultiLineAlignment::onTouchesMoved(const std::vector& touch this->_arrows->setPosition(Vec2(MAX(MIN(location.x, ArrowsMax*winSize.width), ArrowsMin*winSize.width), this->_arrows->getPosition().y)); - float labelWidth = fabs(this->_arrows->getPosition().x - this->_label->getPosition().x) * 2; + float labelWidth = std::fabs(this->_arrows->getPosition().x - this->_label->getPosition().x) * 2; this->_label->setMaxLineWidth(labelWidth); } diff --git a/tests/cpp-tests/Classes/LayerTest/LayerTest.cpp b/tests/cpp-tests/Classes/LayerTest/LayerTest.cpp index db489a1c53c2..091406b0cd88 100644 --- a/tests/cpp-tests/Classes/LayerTest/LayerTest.cpp +++ b/tests/cpp-tests/Classes/LayerTest/LayerTest.cpp @@ -23,6 +23,7 @@ ****************************************************************************/ #include "LayerTest.h" +#include #include "../testResource.h" #include "../cocos/ui/UIText.h" @@ -407,7 +408,7 @@ void LayerTest1::updateSize(Vec2 &touchLocation) { auto s = Director::getInstance()->getWinSize(); - auto newSize = Size( fabs(touchLocation.x - s.width/2)*2, fabs(touchLocation.y - s.height/2)*2); + auto newSize = Size( std::fabs(touchLocation.x - s.width/2)*2, std::fabs(touchLocation.y - s.height/2)*2); auto l = (LayerColor*) getChildByTag(kTagLayer); diff --git a/tests/cpp-tests/Classes/Scene3DTest/Scene3DTest.cpp b/tests/cpp-tests/Classes/Scene3DTest/Scene3DTest.cpp index 3ddc95155290..f1b06c32505a 100644 --- a/tests/cpp-tests/Classes/Scene3DTest/Scene3DTest.cpp +++ b/tests/cpp-tests/Classes/Scene3DTest/Scene3DTest.cpp @@ -23,7 +23,7 @@ ****************************************************************************/ #include "Scene3DTest.h" - +#include #include "ui/CocosGUI.h" #include "renderer/CCRenderState.h" #include "spine/spine-cocos2dx.h" @@ -917,7 +917,7 @@ void Scene3DTestScene::onTouchEnd(Touch* touch, Event* event) dir = collisionPoint - _player->getPosition3D(); dir.y = 0; dir.normalize(); - _player->_headingAngle = -1*acos(dir.dot(Vec3(0,0,-1))); + _player->_headingAngle = -1*std::acos(dir.dot(Vec3(0,0,-1))); dir.cross(dir,Vec3(0,0,-1),&_player->_headingAxis); _player->_targetPos=collisionPoint; _player->forward(); diff --git a/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp b/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp index 531d64134e65..6ff2beac092e 100644 --- a/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp +++ b/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp @@ -31,7 +31,7 @@ #include "3d/CCMotionStreak3D.h" #include "extensions/Particle3D/PU/CCPUParticleSystem3D.h" - +#include #include #include "../testResource.h" @@ -2576,7 +2576,7 @@ void Sprite3DNormalMappingTest::update(float dt) static float radius = 100.0f; auto light = static_cast(getChildByTag(100)); - light->setPosition3D(Vec3(radius * cos(angle), 0.0f, radius * sin(angle))); + light->setPosition3D(Vec3(radius * std::cos(angle), 0.0f, radius * std::sin(angle))); if (reverseDir){ angle -= 0.01f; if (angle < 0.0) diff --git a/tests/cpp-tests/Classes/SpriteTest/SpriteTest.cpp b/tests/cpp-tests/Classes/SpriteTest/SpriteTest.cpp index 51c319c0e283..b7e8049dfd47 100644 --- a/tests/cpp-tests/Classes/SpriteTest/SpriteTest.cpp +++ b/tests/cpp-tests/Classes/SpriteTest/SpriteTest.cpp @@ -5420,9 +5420,9 @@ void SpriteSlice9Test5::update(float dt) float angle = _elapsed; // cap the value between 0 and 0.8 - float x = ((cos(angle) + sin(angle*3)) + 2) / 5.0f; - float y1 = (sin(angle) + 1) / 2.5; - float y2 = (sin(angle+M_PI_2) + 1) / 2.5; + float x = ((std::cos(angle) + std::sin(angle*3)) + 2) / 5.0f; + float y1 = (std::sin(angle) + 1) / 2.5; + float y2 = (std::sin(angle+M_PI_2) + 1) / 2.5; float y = y1; for (int i=0; i<3; ++i) { if (i==1) { @@ -5493,9 +5493,9 @@ void SpriteSlice9Test6::update(float dt) float angle = _elapsed; // cap the value between 0 and 1 - float x = ((cos(angle*2) - sin(angle/2)) + 2) / 4; - float y1 = (sin(angle) + 1) / 2; - float y2 = (sin(angle+M_PI_2) + 1) / 2; + float x = ((std::cos(angle*2) - std::sin(angle/2)) + 2) / 4; + float y1 = (std::sin(angle) + 1) / 2; + float y2 = (std::sin(angle+M_PI_2) + 1) / 2; float y = y1; for (int i=0; i<3; ++i) { if (i==1) { diff --git a/tests/cpp-tests/Classes/TerrainTest/TerrainTest.cpp b/tests/cpp-tests/Classes/TerrainTest/TerrainTest.cpp index 8aedddc6f3ea..b3fa631ff777 100644 --- a/tests/cpp-tests/Classes/TerrainTest/TerrainTest.cpp +++ b/tests/cpp-tests/Classes/TerrainTest/TerrainTest.cpp @@ -23,6 +23,7 @@ ****************************************************************************/ #include "TerrainTest.h" +#include USING_NS_CC; @@ -196,7 +197,7 @@ void TerrainWalkThru::onTouchesEnd(const std::vector& touches, dir = collisionPoint - _player->getPosition3D(); dir.y = 0; dir.normalize(); - _player->_headingAngle = -1*acos(dir.dot(Vec3(0,0,-1))); + _player->_headingAngle = -1*std::acos(dir.dot(Vec3(0,0,-1))); dir.cross(dir,Vec3(0,0,-1),&_player->_headingAxis); _player->_targetPos=collisionPoint; _player->forward(); diff --git a/tests/cpp-tests/Classes/UnitTest/UnitTest.cpp b/tests/cpp-tests/Classes/UnitTest/UnitTest.cpp index 673f5c2c8c05..066ba4ad4631 100644 --- a/tests/cpp-tests/Classes/UnitTest/UnitTest.cpp +++ b/tests/cpp-tests/Classes/UnitTest/UnitTest.cpp @@ -23,6 +23,7 @@ ****************************************************************************/ #include "UnitTest.h" +#include #include "RefPtrTest.h" #include "ui/UIHelper.h" #include "network/Uri.h" @@ -1467,7 +1468,7 @@ static void __checkMathUtilResult(const char* description, const float* a1, cons // Check whether the result of the optimized instruction is the same as which is implemented in C for (int i = 0; i < size; ++i) { - bool r = fabs(a1[i] - a2[i]) < 0.00001f;//FLT_EPSILON; + bool r = std::fabs(a1[i] - a2[i]) < 0.00001f;//FLT_EPSILON; if (r) { log("Correct: a1[%d]=%f, a2[%d]=%f", i, a1[i], i, a2[i]);