Code conforms with the cocos2d-x c++ guidelines

This commit is contained in:
Ricardo Quesada 2014-11-25 17:53:52 -08:00
parent f8b9e9e445
commit 33a2d0451c
28 changed files with 71 additions and 89 deletions

View File

@ -108,7 +108,7 @@ Speed* Speed::create(ActionInterval* action, float speed)
bool Speed::initWithAction(ActionInterval *action, float speed) bool Speed::initWithAction(ActionInterval *action, float speed)
{ {
CCASSERT(action != nullptr, ""); CCASSERT(action != nullptr, "action must not be NULL");
action->retain(); action->retain();
_innerAction = action; _innerAction = action;
_speed = speed; _speed = speed;
@ -121,7 +121,7 @@ Speed *Speed::clone() const
auto a = new (std::nothrow) Speed(); auto a = new (std::nothrow) Speed();
a->initWithAction(_innerAction->clone(), _speed); a->initWithAction(_innerAction->clone(), _speed);
a->autorelease(); a->autorelease();
return a; return a;
} }
void Speed::startWithTarget(Node* target) void Speed::startWithTarget(Node* target)
@ -198,7 +198,7 @@ Follow* Follow::reverse() const
bool Follow::initWithTarget(Node *followedNode, const Rect& rect/* = Rect::ZERO*/) bool Follow::initWithTarget(Node *followedNode, const Rect& rect/* = Rect::ZERO*/)
{ {
CCASSERT(followedNode != nullptr, ""); CCASSERT(followedNode != nullptr, "FollowedNode can't be NULL");
followedNode->retain(); followedNode->retain();
_followedNode = followedNode; _followedNode = followedNode;

View File

@ -244,7 +244,8 @@ public:
inline bool isBoundarySet() const { return _boundarySet; } inline bool isBoundarySet() const { return _boundarySet; }
/** alter behavior - turn on/off boundary */ /** alter behavior - turn on/off boundary */
inline void setBoudarySet(bool value) { _boundarySet = value; } inline void setBoundarySet(bool value) { _boundarySet = value; }
CC_DEPRECATED_ATTRIBUTE inline void setBoudarySet(bool value) { setBoundarySet(value); }
// //
// Override // Override

View File

@ -498,7 +498,7 @@ void Label::setMaxLineWidth(unsigned int maxLineWidth)
} }
} }
void Label::setDimensions(unsigned int width,unsigned int height) void Label::setDimensions(unsigned int width, unsigned int height)
{ {
if (height != _labelHeight || width != _labelWidth) if (height != _labelHeight || width != _labelWidth)
{ {

View File

@ -982,7 +982,7 @@ SpriteFrame* Sprite::getSpriteFrame() const
CC_SIZE_POINTS_TO_PIXELS(_contentSize)); CC_SIZE_POINTS_TO_PIXELS(_contentSize));
} }
SpriteBatchNode* Sprite::getBatchNode() SpriteBatchNode* Sprite::getBatchNode() const
{ {
return _batchNode; return _batchNode;
} }

View File

@ -167,7 +167,7 @@ public:
* @return The SpriteBatchNode object if this sprite is rendered by SpriteBatchNode, * @return The SpriteBatchNode object if this sprite is rendered by SpriteBatchNode,
* nullptr if the sprite isn't used batch node. * nullptr if the sprite isn't used batch node.
*/ */
virtual SpriteBatchNode* getBatchNode(void); virtual SpriteBatchNode* getBatchNode() const;
/** /**
* Sets the batch node to sprite * Sets the batch node to sprite
* @warning This method is not recommended for game developers. Sample code for using batch node * @warning This method is not recommended for game developers. Sample code for using batch node
@ -183,7 +183,6 @@ public:
/// @} end of BatchNode methods /// @} end of BatchNode methods
/// @{ /// @{
/// @name Texture / Frame methods /// @name Texture / Frame methods

View File

@ -378,7 +378,7 @@ void SpriteBatchNode::draw(Renderer *renderer, const Mat4 &transform, uint32_t f
renderer->addCommand(&_batchCommand); renderer->addCommand(&_batchCommand);
} }
void SpriteBatchNode::increaseAtlasCapacity(void) void SpriteBatchNode::increaseAtlasCapacity()
{ {
// if we're going beyond the current TextureAtlas's capacity, // if we're going beyond the current TextureAtlas's capacity,
// all the previously initialized sprites will need to redo their texture coords // all the previously initialized sprites will need to redo their texture coords
@ -574,7 +574,7 @@ void SpriteBatchNode::removeSpriteFromAtlas(Sprite *sprite)
} }
} }
void SpriteBatchNode::updateBlendFunc(void) void SpriteBatchNode::updateBlendFunc()
{ {
if (! _textureAtlas->getTexture()->hasPremultipliedAlpha()) if (! _textureAtlas->getTexture()->hasPremultipliedAlpha())
{ {
@ -594,12 +594,12 @@ void SpriteBatchNode::setBlendFunc(const BlendFunc &blendFunc)
_blendFunc = blendFunc; _blendFunc = blendFunc;
} }
const BlendFunc& SpriteBatchNode::getBlendFunc(void) const const BlendFunc& SpriteBatchNode::getBlendFunc() const
{ {
return _blendFunc; return _blendFunc;
} }
Texture2D* SpriteBatchNode::getTexture(void) const Texture2D* SpriteBatchNode::getTexture() const
{ {
return _textureAtlas->getTexture(); return _textureAtlas->getTexture();
} }

View File

@ -79,7 +79,7 @@ public:
/** returns the TextureAtlas object */ /** returns the TextureAtlas object */
inline TextureAtlas* getTextureAtlas(void) { return _textureAtlas; } inline TextureAtlas* getTextureAtlas() { return _textureAtlas; }
/** sets the TextureAtlas object */ /** sets the TextureAtlas object */
inline void setTextureAtlas(TextureAtlas* textureAtlas) inline void setTextureAtlas(TextureAtlas* textureAtlas)

View File

@ -69,7 +69,7 @@ SpriteFrame* SpriteFrame::create(const std::string& filename, const Rect& rect,
return spriteFrame; return spriteFrame;
} }
SpriteFrame::SpriteFrame(void) SpriteFrame::SpriteFrame()
: _rotated(false) : _rotated(false)
, _texture(nullptr) , _texture(nullptr)
{ {
@ -123,7 +123,7 @@ bool SpriteFrame::initWithTextureFilename(const std::string& filename, const Rec
return true; return true;
} }
SpriteFrame::~SpriteFrame(void) SpriteFrame::~SpriteFrame()
{ {
CCLOGINFO("deallocing SpriteFrame: %p", this); CCLOGINFO("deallocing SpriteFrame: %p", this);
CC_SAFE_RELEASE(_texture); CC_SAFE_RELEASE(_texture);
@ -182,7 +182,7 @@ void SpriteFrame::setTexture(Texture2D * texture)
} }
} }
Texture2D* SpriteFrame::getTexture(void) Texture2D* SpriteFrame::getTexture()
{ {
if( _texture ) { if( _texture ) {
return _texture; return _texture;

View File

@ -79,35 +79,35 @@ public:
inline const Rect& getRectInPixels() const { return _rectInPixels; } inline const Rect& getRectInPixels() const { return _rectInPixels; }
void setRectInPixels(const Rect& rectInPixels); void setRectInPixels(const Rect& rectInPixels);
inline bool isRotated(void) const { return _rotated; } inline bool isRotated() const { return _rotated; }
inline void setRotated(bool rotated) { _rotated = rotated; } inline void setRotated(bool rotated) { _rotated = rotated; }
/** get rect of the frame */ /** get rect of the frame */
inline const Rect& getRect(void) const { return _rect; } inline const Rect& getRect() const { return _rect; }
/** set rect of the frame */ /** set rect of the frame */
void setRect(const Rect& rect); void setRect(const Rect& rect);
/** get offset of the frame */ /** get offset of the frame */
const Vec2& getOffsetInPixels(void) const; const Vec2& getOffsetInPixels() const;
/** set offset of the frame */ /** set offset of the frame */
void setOffsetInPixels(const Vec2& offsetInPixels); void setOffsetInPixels(const Vec2& offsetInPixels);
/** get original size of the trimmed image */ /** get original size of the trimmed image */
inline const Size& getOriginalSizeInPixels(void) const { return _originalSizeInPixels; } inline const Size& getOriginalSizeInPixels() const { return _originalSizeInPixels; }
/** set original size of the trimmed image */ /** set original size of the trimmed image */
inline void setOriginalSizeInPixels(const Size& sizeInPixels) { _originalSizeInPixels = sizeInPixels; } inline void setOriginalSizeInPixels(const Size& sizeInPixels) { _originalSizeInPixels = sizeInPixels; }
/** get original size of the trimmed image */ /** get original size of the trimmed image */
inline const Size& getOriginalSize(void) const { return _originalSize; } inline const Size& getOriginalSize() const { return _originalSize; }
/** set original size of the trimmed image */ /** set original size of the trimmed image */
inline void setOriginalSize(const Size& sizeInPixels) { _originalSize = sizeInPixels; } inline void setOriginalSize(const Size& sizeInPixels) { _originalSize = sizeInPixels; }
/** get texture of the frame */ /** get texture of the frame */
Texture2D* getTexture(void); Texture2D* getTexture();
/** set texture of the frame, the texture is retained */ /** set texture of the frame, the texture is retained */
void setTexture(Texture2D* pobTexture); void setTexture(Texture2D* pobTexture);
const Vec2& getOffset(void) const; const Vec2& getOffset() const;
void setOffset(const Vec2& offsets); void setOffset(const Vec2& offsets);
// Overrides // Overrides
@ -117,12 +117,12 @@ CC_CONSTRUCTOR_ACCESS:
/** /**
* @lua NA * @lua NA
*/ */
SpriteFrame(void); SpriteFrame();
/** /**
* @lua NA * @lua NA
*/ */
virtual ~SpriteFrame(void); virtual ~SpriteFrame();
/** Initializes a SpriteFrame with a texture, rect in points. /** Initializes a SpriteFrame with a texture, rect in points.
It is assumed that the frame was not trimmed. It is assumed that the frame was not trimmed.

View File

@ -70,11 +70,6 @@ public:
/** @deprecated Use destroyInstance() instead */ /** @deprecated Use destroyInstance() instead */
CC_DEPRECATED_ATTRIBUTE static void purgeSharedSpriteFrameCache() { return SpriteFrameCache::destroyInstance(); } CC_DEPRECATED_ATTRIBUTE static void purgeSharedSpriteFrameCache() { return SpriteFrameCache::destroyInstance(); }
protected:
// MARMALADE: Made this protected not private, as deriving from this class is pretty useful
SpriteFrameCache(){}
public:
/** /**
* @js NA * @js NA
* @lua NA * @lua NA
@ -82,7 +77,6 @@ public:
virtual ~SpriteFrameCache(); virtual ~SpriteFrameCache();
bool init(); bool init();
public:
/** Adds multiple Sprite Frames from a plist file. /** Adds multiple Sprite Frames from a plist file.
* A texture will be loaded automatically. The texture name will composed by replacing the .plist suffix with .png * A texture will be loaded automatically. The texture name will composed by replacing the .plist suffix with .png
* If you want to use another texture, you should use the addSpriteFramesWithFile(const std::string& plist, const std::string& textureFileName) method. * If you want to use another texture, you should use the addSpriteFramesWithFile(const std::string& plist, const std::string& textureFileName) method.
@ -162,7 +156,10 @@ public:
/** @deprecated use getSpriteFrameByName() instead */ /** @deprecated use getSpriteFrameByName() instead */
CC_DEPRECATED_ATTRIBUTE SpriteFrame* spriteFrameByName(const std::string&name) { return getSpriteFrameByName(name); } CC_DEPRECATED_ATTRIBUTE SpriteFrame* spriteFrameByName(const std::string&name) { return getSpriteFrameByName(name); }
private: protected:
// MARMALADE: Made this protected not private, as deriving from this class is pretty useful
SpriteFrameCache(){}
/*Adds multiple Sprite Frames with a dictionary. The texture will be associated with the created sprite frames. /*Adds multiple Sprite Frames with a dictionary. The texture will be associated with the created sprite frames.
*/ */
void addSpriteFramesWithDictionary(ValueMap& dictionary, Texture2D *texture); void addSpriteFramesWithDictionary(ValueMap& dictionary, Texture2D *texture);
@ -172,7 +169,7 @@ private:
*/ */
void removeSpriteFramesFromDictionary(ValueMap& dictionary); void removeSpriteFramesFromDictionary(ValueMap& dictionary);
protected:
Map<std::string, SpriteFrame*> _spriteFrames; Map<std::string, SpriteFrame*> _spriteFrames;
ValueMap _spriteFramesAliases; ValueMap _spriteFramesAliases;
std::set<std::string>* _loadedFileNames; std::set<std::string>* _loadedFileNames;

View File

@ -190,7 +190,7 @@ public:
void removeChild(Node* child, bool cleanup) override; void removeChild(Node* child, bool cleanup) override;
virtual std::string getDescription() const override; virtual std::string getDescription() const override;
private: protected:
Vec2 getPositionForIsoAt(const Vec2& pos); Vec2 getPositionForIsoAt(const Vec2& pos);
Vec2 getPositionForOrthoAt(const Vec2& pos); Vec2 getPositionForOrthoAt(const Vec2& pos);
Vec2 getPositionForHexAt(const Vec2& pos); Vec2 getPositionForHexAt(const Vec2& pos);
@ -211,23 +211,23 @@ private:
// index // index
ssize_t atlasIndexForExistantZ(int z); ssize_t atlasIndexForExistantZ(int z);
ssize_t atlasIndexForNewZ(int z); ssize_t atlasIndexForNewZ(int z);
protected:
//! name of the layer //! name of the layer
std::string _layerName; std::string _layerName;
//! TMX Layer supports opacity //! TMX Layer supports opacity
unsigned char _opacity; unsigned char _opacity;
//! Only used when vertexZ is used //! Only used when vertexZ is used
int _vertexZvalue; int _vertexZvalue;
bool _useAutomaticVertexZ; bool _useAutomaticVertexZ;
//! used for optimization //! used for optimization
Sprite *_reusedTile; Sprite *_reusedTile;
ccCArray *_atlasIndexArray; ccCArray *_atlasIndexArray;
// used for retina display // used for retina display
float _contentScaleFactor; float _contentScaleFactor;
/** size of the layer in tiles */ /** size of the layer in tiles */
Size _layerSize; Size _layerSize;

View File

@ -240,7 +240,7 @@ void TextFieldTTF::deleteBackward()
if (_delegate && _delegate->onTextFieldDeleteBackward(this, _inputText.c_str() + len - deleteLen, static_cast<int>(deleteLen))) if (_delegate && _delegate->onTextFieldDeleteBackward(this, _inputText.c_str() + len - deleteLen, static_cast<int>(deleteLen)))
{ {
// delegate doesn't wan't to delete backwards // delegate doesn't want to delete backwards
return; return;
} }

View File

@ -160,7 +160,7 @@ public:
// place holder text property // place holder text property
// place holder text displayed when there is no text in the text field. // place holder text displayed when there is no text in the text field.
virtual void setPlaceHolder(const std::string& text); virtual void setPlaceHolder(const std::string& text);
virtual const std::string& getPlaceHolder(void) const; virtual const std::string& getPlaceHolder() const;
virtual void setSecureTextEntry(bool value); virtual void setSecureTextEntry(bool value);
virtual bool isSecureTextEntry(); virtual bool isSecureTextEntry();

View File

@ -85,7 +85,7 @@ public:
float getWeight() const { return _weight; } float getWeight() const { return _weight; }
void setWeight(float weight); void setWeight(float weight);
/** animate transistion time */ /** animate transition time */
static float getTransitionTime() { return _transTime; } static float getTransitionTime() { return _transTime; }
/**get & set play reverse, these are deprecated, use set negative speed instead*/ /**get & set play reverse, these are deprecated, use set negative speed instead*/

View File

@ -70,18 +70,15 @@ public:
Curve* getBoneCurveByName(const std::string& name) const; Curve* getBoneCurveByName(const std::string& name) const;
CC_CONSTRUCTOR_ACCESS: CC_CONSTRUCTOR_ACCESS:
Animation3D(); Animation3D();
virtual ~Animation3D(); virtual ~Animation3D();
/**init Animation3D from bundle data*/ /**init Animation3D from bundle data*/
bool init(const Animation3DData& data); bool init(const Animation3DData& data);
protected: protected:
std::unordered_map<std::string, Curve*> _boneCurves;//bone curves map, key bone name, value AnimationCurve std::unordered_map<std::string, Curve*> _boneCurves;//bone curves map, key bone name, value AnimationCurve
float _duration; //animation duration
float _duration; //animation duration
}; };
/** /**

View File

@ -58,7 +58,7 @@ CC_CONSTRUCTOR_ACCESS:
protected: protected:
Bone3D* _attachBone; Bone3D* _attachBone;
}; };

View File

@ -53,10 +53,8 @@ public:
void addCallbacks(const std::function<void()> &callback); void addCallbacks(const std::function<void()> &callback);
private: protected:
void readDataTask(); void readDataTask();
void invokingCallbacks(); void invokingCallbacks();
//pcm data related stuff //pcm data related stuff

View File

@ -53,13 +53,13 @@ using namespace cocos2d;
using namespace cocos2d::experimental; using namespace cocos2d::experimental;
AudioCache::AudioCache() AudioCache::AudioCache()
: _pcmData(nullptr) : _dataSize(0)
, _dataSize(0) , _pcmData(nullptr)
, _bytesOfRead(0) , _bytesOfRead(0)
, _exitReadDataTask(false)
, _queBufferFrames(0) , _queBufferFrames(0)
, _queBufferBytes(0) , _queBufferBytes(0)
, _alBufferReady(false) , _alBufferReady(false)
, _exitReadDataTask(false)
{ {
} }

View File

@ -128,11 +128,10 @@ namespace cocos2d {
} }
AudioEngineImpl::AudioEngineImpl() AudioEngineImpl::AudioEngineImpl()
: _lazyInitLoop(true) : _threadPool(nullptr)
, _threadPool(nullptr) , _lazyInitLoop(true)
, _currentAudioID(0) , _currentAudioID(0)
{ {
} }
AudioEngineImpl::~AudioEngineImpl() AudioEngineImpl::~AudioEngineImpl()

View File

@ -36,15 +36,14 @@ using namespace cocos2d;
using namespace cocos2d::experimental; using namespace cocos2d::experimental;
AudioPlayer::AudioPlayer() AudioPlayer::AudioPlayer()
: _exitThread(false) : _audioCache(nullptr)
, _streamingSource(false)
, _timeDirty(false)
, _currTime(0.0f)
, _finishCallbak(nullptr) , _finishCallbak(nullptr)
, _ready(false) , _ready(false)
, _audioCache(nullptr) , _currTime(0.0f)
{ , _streamingSource(false)
, _exitThread(false)
, _timeDirty(false)
{
} }
AudioPlayer::~AudioPlayer() AudioPlayer::~AudioPlayer()

View File

@ -162,7 +162,7 @@ public:
SocketIO::SIODelegate* getDelegate() { return _delegate; }; SocketIO::SIODelegate* getDelegate() { return _delegate; };
/** /**
* @brief Disconnect from the endpoint, onClose will be called on the delegate when comlpete * @brief Disconnect from the endpoint, onClose will be called on the delegate when complete
*/ */
void disconnect(); void disconnect();
/** /**
@ -174,7 +174,7 @@ public:
*/ */
void emit(std::string eventname, std::string args); void emit(std::string eventname, std::string args);
/** /**
* @brief Used to resgister a socket.io event callback * @brief Used to register a socket.io event callback
* Event argument should be passed using CC_CALLBACK2(&Base::function, this) * Event argument should be passed using CC_CALLBACK2(&Base::function, this)
*/ */
void on(const std::string& eventName, SIOEvent e); void on(const std::string& eventName, SIOEvent e);

View File

@ -176,13 +176,13 @@ static Layer* restartSpriteTestAction()
Camera3DTestDemo::Camera3DTestDemo(void) Camera3DTestDemo::Camera3DTestDemo(void)
: BaseTest() : BaseTest()
, _camera(nullptr)
, _incRot(nullptr) , _incRot(nullptr)
, _camera(nullptr)
, _decRot(nullptr) , _decRot(nullptr)
,_bZoomOut(false) , _bZoomOut(false)
,_bZoomIn(false) , _bZoomIn(false)
,_bRotateLeft(false) , _bRotateLeft(false)
,_bRotateRight(false) , _bRotateRight(false)
{ {
} }
Camera3DTestDemo::~Camera3DTestDemo(void) Camera3DTestDemo::~Camera3DTestDemo(void)

View File

@ -790,8 +790,7 @@ void AttributeComponentTest::defaultPlay()
} }
TriggerTest::TriggerTest() TriggerTest::TriggerTest()
: _node(nullptr) : _touchListener(nullptr)
, _touchListener(nullptr)
{ {
} }

View File

@ -223,10 +223,9 @@ public:
cocos2d::Node* createGameScene(); cocos2d::Node* createGameScene();
private: private:
cocos2d::Node *_node; void defaultPlay();
cocos2d::EventListener* _touchListener; cocos2d::EventListener* _touchListener;
private:
void defaultPlay();
}; };
#endif // __HELLOWORLD_SCENE_H__ #endif // __HELLOWORLD_SCENE_H__

View File

@ -77,7 +77,6 @@ void Light::updateLightState()
} }
NotificationCenterTest::NotificationCenterTest() NotificationCenterTest::NotificationCenterTest()
: _showImage(false)
{ {
auto s = Director::getInstance()->getWinSize(); auto s = Director::getInstance()->getWinSize();

View File

@ -11,8 +11,6 @@ public:
void toggleSwitch(cocos2d::Ref *sender); void toggleSwitch(cocos2d::Ref *sender);
void connectToSwitch(cocos2d::Ref *sender); void connectToSwitch(cocos2d::Ref *sender);
void doNothing(cocos2d::Ref *sender); void doNothing(cocos2d::Ref *sender);
private:
bool _showImage;
}; };
void runNotificationCenterTest(); void runNotificationCenterTest();

View File

@ -1350,17 +1350,14 @@ public:
Sprite::onExit(); Sprite::onExit();
} }
private: private:
EventListenerTouchOneByOne* _eventListener;
EventListenerTouchOneByOne * _eventListener; TappedCallback _tappedCallback;
int _fixedPriority;
TappedCallback _tappedCallback;
}; };
DanglingNodePointersTest::DanglingNodePointersTest() DanglingNodePointersTest::DanglingNodePointersTest()
{ {
#if CC_NODE_DEBUG_VERIFY_EVENT_LISTENERS == 1 && COCOS2D_DEBUG > 0 #if CC_NODE_DEBUG_VERIFY_EVENT_LISTENERS == 1 && COCOS2D_DEBUG > 0
Vec2 origin = Director::getInstance()->getVisibleOrigin(); Vec2 origin = Director::getInstance()->getVisibleOrigin();
Size size = Director::getInstance()->getVisibleSize(); Size size = Director::getInstance()->getVisibleSize();

View File

@ -155,8 +155,8 @@ std::string Parallax2::title() const
//------------------------------------------------------------------ //------------------------------------------------------------------
Issue2572::Issue2572() Issue2572::Issue2572()
: _preListSize(0) : _preListSize(0)
, _printCount(0)
, _moveTimer(0.0f) , _moveTimer(0.0f)
, _printCount(0)
, _addTimer(0.0f) , _addTimer(0.0f)
{ {
_addChildStep = 1.0f; _addChildStep = 1.0f;