Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Checks: >
performance-move-constructor-init,
performance-type-promotion-in-math-fn,
performance-unnecessary-copy-initialization,
performance-unnecessary-value-param,
readability-container-size-empty,
readability-delete-null-pointer,
readability-redundant-control-flow,
Expand Down
6 changes: 4 additions & 2 deletions cocos/2d/CCActionInterval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ THE SOFTWARE.

#include <stdarg.h>

#include <utility>

#include "2d/CCSprite.h"
#include "2d/CCNode.h"
#include "2d/CCSpriteFrame.h"
Expand Down Expand Up @@ -2800,7 +2802,7 @@ void TargetedAction::setForcedTarget(Node* forcedTarget)

// ActionFloat

ActionFloat* ActionFloat::create(float duration, float from, float to, ActionFloatCallback callback)
ActionFloat* ActionFloat::create(float duration, float from, float to, const ActionFloatCallback& callback)
{
auto ref = new (std::nothrow) ActionFloat();
if (ref && ref->initWithDuration(duration, from, to, callback))
Expand All @@ -2813,7 +2815,7 @@ ActionFloat* ActionFloat::create(float duration, float from, float to, ActionFlo
return nullptr;
}

bool ActionFloat::initWithDuration(float duration, float from, float to, ActionFloatCallback callback)
bool ActionFloat::initWithDuration(float duration, float from, float to, const ActionFloatCallback& callback)
{
if (ActionInterval::initWithDuration(duration))
{
Expand Down
4 changes: 2 additions & 2 deletions cocos/2d/CCActionInterval.h
Original file line number Diff line number Diff line change
Expand Up @@ -1650,7 +1650,7 @@ class CC_DLL ActionFloat : public ActionInterval
*
* @return An autoreleased ActionFloat object
*/
static ActionFloat* create(float duration, float from, float to, ActionFloatCallback callback);
static ActionFloat* create(float duration, float from, float to, const ActionFloatCallback& callback);

/**
* Overridden ActionInterval methods
Expand All @@ -1664,7 +1664,7 @@ class CC_DLL ActionFloat : public ActionInterval
ActionFloat() {};
virtual ~ActionFloat() {};

bool initWithDuration(float duration, float from, float to, ActionFloatCallback callback);
bool initWithDuration(float duration, float from, float to, const ActionFloatCallback& callback);

protected:
/* From value */
Expand Down
6 changes: 3 additions & 3 deletions cocos/2d/CCNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ Node* Node::getChildByName(const std::string& name) const
return nullptr;
}

void Node::enumerateChildren(const std::string &name, std::function<bool (Node *)> callback) const
void Node::enumerateChildren(const std::string &name, const std::function<bool (Node *)>& callback) const
{
CCASSERT(!name.empty(), "Invalid name");
CCASSERT(callback != nullptr, "Invalid callback function");
Expand Down Expand Up @@ -869,7 +869,7 @@ void Node::enumerateChildren(const std::string &name, std::function<bool (Node *
}
}

bool Node::doEnumerateRecursive(const Node* node, const std::string &name, std::function<bool (Node *)> callback) const
bool Node::doEnumerateRecursive(const Node* node, const std::string &name, const std::function<bool (Node *)>& callback) const
{
bool ret =false;

Expand All @@ -894,7 +894,7 @@ bool Node::doEnumerateRecursive(const Node* node, const std::string &name, std::
return ret;
}

bool Node::doEnumerate(std::string name, std::function<bool (Node *)> callback) const
bool Node::doEnumerate(std::string name, const std::function<bool (Node *)>& callback) const
{
// name may be xxx/yyy, should find its parent
size_t pos = name.find('/');
Expand Down
6 changes: 3 additions & 3 deletions cocos/2d/CCNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,7 @@ class CC_DLL Node : public Ref
*
* @since v3.2
*/
virtual void enumerateChildren(const std::string &name, std::function<bool(Node* node)> callback) const;
virtual void enumerateChildren(const std::string &name, const std::function<bool(Node* node)>& callback) const;
/**
* Returns the array of the node's children.
*
Expand Down Expand Up @@ -1886,8 +1886,8 @@ class CC_DLL Node : public Ref
virtual void disableCascadeColor();
virtual void updateColor() {}

bool doEnumerate(std::string name, std::function<bool (Node *)> callback) const;
bool doEnumerateRecursive(const Node* node, const std::string &name, std::function<bool (Node *)> callback) const;
bool doEnumerate(std::string name, const std::function<bool (Node *)>& callback) const;
bool doEnumerateRecursive(const Node* node, const std::string &name, const std::function<bool (Node *)>& callback) const;

//check whether this camera mask is visible by the current visiting camera
bool isVisitableByVisitingCamera() const;
Expand Down
10 changes: 6 additions & 4 deletions cocos/2d/CCRenderTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ THE SOFTWARE.

#include "2d/CCRenderTexture.h"

#include <utility>

#include "base/ccUtils.h"
#include "platform/CCFileUtils.h"
#include "base/CCEventType.h"
Expand Down Expand Up @@ -506,7 +508,7 @@ void RenderTexture::visit(Renderer *renderer, const Mat4 &parentTransform, uint3
// setOrderOfArrival(0);
}

bool RenderTexture::saveToFileAsNonPMA(const std::string& filename, bool isRGBA, std::function<void(RenderTexture*, const std::string&)> callback)
bool RenderTexture::saveToFileAsNonPMA(const std::string& filename, bool isRGBA, const std::function<void(RenderTexture*, const std::string&)>& callback)
{
std::string basename(filename);
std::transform(basename.begin(), basename.end(), basename.begin(), ::tolower);
Expand All @@ -528,7 +530,7 @@ bool RenderTexture::saveToFileAsNonPMA(const std::string& filename, bool isRGBA,
return saveToFileAsNonPMA(filename, Image::Format::JPG, false, callback);
}

bool RenderTexture::saveToFile(const std::string& filename, bool isRGBA, std::function<void (RenderTexture*, const std::string&)> callback)
bool RenderTexture::saveToFile(const std::string& filename, bool isRGBA, const std::function<void (RenderTexture*, const std::string&)>& callback)
{
std::string basename(filename);
std::transform(basename.begin(), basename.end(), basename.begin(), ::tolower);
Expand All @@ -550,7 +552,7 @@ bool RenderTexture::saveToFile(const std::string& filename, bool isRGBA, std::fu
return saveToFile(filename, Image::Format::JPG, false, callback);
}

bool RenderTexture::saveToFileAsNonPMA(const std::string& fileName, Image::Format format, bool isRGBA, std::function<void(RenderTexture*, const std::string&)> callback)
bool RenderTexture::saveToFileAsNonPMA(const std::string& fileName, Image::Format format, bool isRGBA, const std::function<void(RenderTexture*, const std::string&)>& callback)
{
CCASSERT(format == Image::Format::JPG || format == Image::Format::PNG,
"the image can only be saved as JPG or PNG format");
Expand All @@ -566,7 +568,7 @@ bool RenderTexture::saveToFileAsNonPMA(const std::string& fileName, Image::Forma
return true;
}

bool RenderTexture::saveToFile(const std::string& fileName, Image::Format format, bool isRGBA, std::function<void (RenderTexture*, const std::string&)> callback)
bool RenderTexture::saveToFile(const std::string& fileName, Image::Format format, bool isRGBA, const std::function<void (RenderTexture*, const std::string&)>& callback)
{
CCASSERT(format == Image::Format::JPG || format == Image::Format::PNG,
"the image can only be saved as JPG or PNG format");
Expand Down
8 changes: 4 additions & 4 deletions cocos/2d/CCRenderTexture.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class CC_DLL RenderTexture : public Node
* @param callback When the file is save finished,it will callback this function.
* @return Returns true if the operation is successful.
*/
bool saveToFileAsNonPMA(const std::string& filename, bool isRGBA = true, std::function<void(RenderTexture*, const std::string&)> callback = nullptr);
bool saveToFileAsNonPMA(const std::string& filename, bool isRGBA = true, const std::function<void(RenderTexture*, const std::string&)>& callback = nullptr);


/** Saves the texture into a file using JPEG format. The file will be saved in the Documents folder.
Expand All @@ -170,7 +170,7 @@ class CC_DLL RenderTexture : public Node
* @param callback When the file is save finished,it will callback this function.
* @return Returns true if the operation is successful.
*/
bool saveToFile(const std::string& filename, bool isRGBA = true, std::function<void (RenderTexture*, const std::string&)> callback = nullptr);
bool saveToFile(const std::string& filename, bool isRGBA = true, const std::function<void (RenderTexture*, const std::string&)>& callback = nullptr);

/** saves the texture into a file in non-PMA. The format could be JPG or PNG. The file will be saved in the Documents folder.
Returns true if the operation is successful.
Expand All @@ -184,7 +184,7 @@ class CC_DLL RenderTexture : public Node
* @param callback When the file is save finished,it will callback this function.
* @return Returns true if the operation is successful.
*/
bool saveToFileAsNonPMA(const std::string& fileName, Image::Format format, bool isRGBA, std::function<void(RenderTexture*, const std::string&)> callback);
bool saveToFileAsNonPMA(const std::string& fileName, Image::Format format, bool isRGBA, const std::function<void(RenderTexture*, const std::string&)>& callback);

/** saves the texture into a file. The format could be JPG or PNG. The file will be saved in the Documents folder.
Returns true if the operation is successful.
Expand All @@ -198,7 +198,7 @@ class CC_DLL RenderTexture : public Node
* @param callback When the file is save finished,it will callback this function.
* @return Returns true if the operation is successful.
*/
bool saveToFile(const std::string& filename, Image::Format format, bool isRGBA = true, std::function<void (RenderTexture*, const std::string&)> callback = nullptr);
bool saveToFile(const std::string& filename, Image::Format format, bool isRGBA = true, const std::function<void (RenderTexture*, const std::string&)>& callback = nullptr);

/** Listen "come to background" message, and save render texture.
* It only has effect on Android.
Expand Down
9 changes: 5 additions & 4 deletions cocos/2d/CCTMXXMLParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ THE SOFTWARE.
****************************************************************************/

#include "2d/CCTMXXMLParser.h"
#include <unordered_map>
#include <sstream>
#include "2d/CCTMXTiledMap.h"
#include "base/CCDirector.h"
#include "base/ZipUtils.h"
#include "base/base64.h"
#include "base/CCDirector.h"
#include "platform/CCFileUtils.h"
#include <sstream>
#include <unordered_map>
#include <utility>

using namespace std;

Expand Down Expand Up @@ -63,7 +64,7 @@ ValueMap& TMXLayerInfo::getProperties()
return _properties;
}

void TMXLayerInfo::setProperties(ValueMap var)
void TMXLayerInfo::setProperties(const ValueMap& var)
{
_properties = var;
}
Expand Down
2 changes: 1 addition & 1 deletion cocos/2d/CCTMXXMLParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class CC_DLL TMXLayerInfo : public Ref
*/
virtual ~TMXLayerInfo();

void setProperties(ValueMap properties);
void setProperties(const ValueMap& properties);
ValueMap& getProperties();

ValueMap _properties;
Expand Down
2 changes: 1 addition & 1 deletion cocos/3d/CCTerrain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ void Terrain::setAlphaMap(cocos2d::Texture2D * newAlphaMapTexture)
_alphaMap = newAlphaMapTexture;
}

void Terrain::setDetailMap(unsigned int index, DetailMap detailMap)
void Terrain::setDetailMap(unsigned int index, const DetailMap& detailMap)
{
if(index>4)
{
Expand Down
2 changes: 1 addition & 1 deletion cocos/3d/CCTerrain.h
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ class CC_DLL Terrain : public Node
/** set the alpha map*/
void setAlphaMap(cocos2d::Texture2D * newAlphaMapTexture);
/**set the Detail Map */
void setDetailMap(unsigned int index, DetailMap detailMap);
void setDetailMap(unsigned int index, const DetailMap& detailMap);

// Overrides, internal use only
virtual void draw(cocos2d::Renderer* renderer, const cocos2d::Mat4 &transform, uint32_t flags) override;
Expand Down
2 changes: 1 addition & 1 deletion cocos/audio/AudioEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ AudioProfile* AudioEngine::getProfile(const std::string &name)
}
}

void AudioEngine::preload(const std::string& filePath, std::function<void(bool isSuccess)> callback)
void AudioEngine::preload(const std::string& filePath, const std::function<void(bool isSuccess)>& callback)
{
if (!isEnabled())
{
Expand Down
2 changes: 1 addition & 1 deletion cocos/audio/include/AudioEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ class EXPORT_DLL AudioEngine
* @param filePath The file path of an audio.
* @param callback A callback which will be called after loading is finished.
*/
static void preload(const std::string& filePath, std::function<void(bool isSuccess)> callback);
static void preload(const std::string& filePath, const std::function<void(bool isSuccess)>& callback);

/**
* Gets playing audio count.
Expand Down
2 changes: 1 addition & 1 deletion cocos/audio/linux/AudioEngine-linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ void AudioEngineImpl::uncacheAll()
mapId.clear();
}

int AudioEngineImpl::preload(const std::string& filePath, std::function<void(bool isSuccess)> callback)
int AudioEngineImpl::preload(const std::string& filePath, const std::function<void(bool isSuccess)>& callback)
{
FMOD::Sound * sound = findSound(filePath);
if (!sound) {
Expand Down
2 changes: 1 addition & 1 deletion cocos/audio/linux/AudioEngine-linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class CC_DLL AudioEngineImpl : public cocos2d::Ref
void uncacheAll();


int preload(const std::string& filePath, std::function<void(bool isSuccess)> callback);
int preload(const std::string& filePath, const std::function<void(bool isSuccess)>& callback);

void update(float dt);

Expand Down
5 changes: 3 additions & 2 deletions cocos/base/ObjectFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/

#include <functional>
#include "base/ObjectFactory.h"
#include <functional>
#include <utility>


NS_CC_BEGIN
Expand All @@ -44,7 +45,7 @@ ObjectFactory::TInfo::TInfo(const std::string& type, Instance ins)
ObjectFactory::getInstance()->registerType(*this);
}

ObjectFactory::TInfo::TInfo(const std::string& type, InstanceFunc ins)
ObjectFactory::TInfo::TInfo(const std::string& type, const InstanceFunc& ins)
:_class(type)
,_fun(nullptr)
,_func(ins)
Expand Down
2 changes: 1 addition & 1 deletion cocos/base/ObjectFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class CC_DLL ObjectFactory
{
TInfo();
TInfo(const std::string& type, Instance ins = nullptr);
TInfo(const std::string& type, InstanceFunc ins = nullptr);
TInfo(const std::string& type, const InstanceFunc& ins = nullptr);
TInfo(const TInfo &t);
~TInfo();
TInfo& operator= (const TInfo &t);
Expand Down
4 changes: 2 additions & 2 deletions cocos/editor-support/cocosbuilder/CCBAnimationManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ void CCBAnimationManager::addDocumentCallbackNode(Node *node)
_documentCallbackNodes.pushBack(node);
}

void CCBAnimationManager::addDocumentCallbackName(std::string name)
void CCBAnimationManager::addDocumentCallbackName(const std::string& name)
{
_documentCallbackNames.push_back(Value(name));
}
Expand Down Expand Up @@ -170,7 +170,7 @@ void CCBAnimationManager::addDocumentOutletNode(Node *node)
_documentOutletNodes.pushBack(node);
}

void CCBAnimationManager::addDocumentOutletName(std::string name)
void CCBAnimationManager::addDocumentOutletName(const std::string& name)
{
_documentOutletNames.push_back(Value(name));
}
Expand Down
4 changes: 2 additions & 2 deletions cocos/editor-support/cocosbuilder/CCBAnimationManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ class CC_DLL CCBAnimationManager : public cocos2d::Ref


void addDocumentCallbackNode(cocos2d::Node *node);
void addDocumentCallbackName(std::string name);
void addDocumentCallbackName(const std::string& name);
void addDocumentCallbackControlEvents(cocos2d::extension::Control::EventType eventType);

void addDocumentOutletNode(cocos2d::Node *node);
void addDocumentOutletName(std::string name);
void addDocumentOutletName(const std::string& name);

void setDocumentControllerName(const std::string &name);

Expand Down
19 changes: 10 additions & 9 deletions cocos/editor-support/cocosbuilder/CCBReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,17 @@
#include "2d/CCSpriteFrameCache.h"
#include "renderer/CCTextureCache.h"

#include "editor-support/cocosbuilder/CCBAnimationManager.h"
#include "editor-support/cocosbuilder/CCBKeyframe.h"
#include "editor-support/cocosbuilder/CCBMemberVariableAssigner.h"
#include "editor-support/cocosbuilder/CCBReader.h"
#include "editor-support/cocosbuilder/CCBSelectorResolver.h"
#include "editor-support/cocosbuilder/CCBSequenceProperty.h"
#include "editor-support/cocosbuilder/CCNodeLoader.h"
#include "editor-support/cocosbuilder/CCNodeLoaderLibrary.h"
#include "editor-support/cocosbuilder/CCNodeLoaderListener.h"
#include "editor-support/cocosbuilder/CCBMemberVariableAssigner.h"
#include "editor-support/cocosbuilder/CCBSelectorResolver.h"
#include "editor-support/cocosbuilder/CCBAnimationManager.h"
#include "editor-support/cocosbuilder/CCBSequenceProperty.h"
#include "editor-support/cocosbuilder/CCBKeyframe.h"
#include <sstream>
#include <utility>

using namespace cocos2d;
using namespace cocos2d::extension;
Expand Down Expand Up @@ -191,7 +192,7 @@ CCBReader::CCBAnimationManagerMapPtr CCBReader::getAnimationManagers()
return _animationManagers;
}

void CCBReader::setAnimationManagers(CCBAnimationManagerMapPtr x)
void CCBReader::setAnimationManagers(const CCBAnimationManagerMapPtr& x)
{
_animationManagers = x;
}
Expand Down Expand Up @@ -255,7 +256,7 @@ Node* CCBReader::readNodeGraphFromFile(const char *pCCBFileName, Ref *pOwner, co

Node* CCBReader::readNodeGraphFromData(std::shared_ptr<cocos2d::Data> data, Ref *pOwner, const Size &parentSize)
{
_data = data;
_data = std::move(data);
_bytes =_data->getBytes();
_currentByte = 0;
_currentBit = 0;
Expand Down Expand Up @@ -320,7 +321,7 @@ void CCBReader::cleanUpNodeGraph(Node *node)
}
}

Node* CCBReader::readFileWithCleanUp(bool bCleanUp, CCBAnimationManagerMapPtr am)
Node* CCBReader::readFileWithCleanUp(bool bCleanUp, const CCBAnimationManagerMapPtr& am)
{
if (! readHeader())
{
Expand Down Expand Up @@ -1069,7 +1070,7 @@ Vector<CCBAnimationManager*>& CCBReader::getAnimationManagersForNodes()
return _animationManagersForNodes;
}

void CCBReader::addOwnerOutletName(std::string name)
void CCBReader::addOwnerOutletName(const std::string& name)
{
_ownerOutletNames.push_back(name);
}
Expand Down
Loading