Skip to content

Commit

Permalink
Merge pull request cocos2d#12835 from zilongshanren/improve-coding-style
Browse files Browse the repository at this point in the history
add more descriptive message to ASSET macro.
  • Loading branch information
zilongshanren committed Jul 14, 2015
2 parents af4442d + 91dfb07 commit 7e4e82d
Show file tree
Hide file tree
Showing 25 changed files with 189 additions and 183 deletions.
2 changes: 1 addition & 1 deletion cocos/2d/CCActionEase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ NS_CC_BEGIN

bool ActionEase::initWithAction(ActionInterval *action)
{
CCASSERT(action != nullptr, "");
CCASSERT(action != nullptr, "action couldn't be nullptr!");

if (ActionInterval::initWithDuration(action->getDuration()))
{
Expand Down
6 changes: 3 additions & 3 deletions cocos/2d/CCActionGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ void GridAction::startWithTarget(Node *target)
if (targetGrid && targetGrid->getReuseGrid() > 0)
{
if (targetGrid->isActive() && targetGrid->getGridSize().width == _gridSize.width
&& targetGrid->getGridSize().height == _gridSize.height /*&& dynamic_cast<GridBase*>(targetGrid) != nullptr*/)
&& targetGrid->getGridSize().height == _gridSize.height)
{
targetGrid->reuse();
}
else
{
CCASSERT(0, "");
CCASSERT(0, "Invalid grid parameters!");
}
}
else
Expand Down Expand Up @@ -93,7 +93,7 @@ GridAction* GridAction::reverse() const
GridBase* GridAction::getGrid()
{
// Abstract class needs implementation
CCASSERT(0, "");
CCASSERT(0, "Subclass should implement this method!");

return nullptr;
}
Expand Down
18 changes: 9 additions & 9 deletions cocos/2d/CCActionInterval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,13 @@ void ActionInterval::setAmplitudeRate(float amp)
{
CC_UNUSED_PARAM(amp);
// Abstract class needs implementation
CCASSERT(0, "");
CCASSERT(0, "Subclass should implement this method!");
}

float ActionInterval::getAmplitudeRate()
{
// Abstract class needs implementation
CCASSERT(0, "");
CCASSERT(0, "Subclass should implement this method!");

return 0;
}
Expand Down Expand Up @@ -248,8 +248,8 @@ Sequence* Sequence::create(const Vector<FiniteTimeAction*>& arrayOfActions)

bool Sequence::initWithTwoActions(FiniteTimeAction *actionOne, FiniteTimeAction *actionTwo)
{
CCASSERT(actionOne != nullptr, "");
CCASSERT(actionTwo != nullptr, "");
CCASSERT(actionOne != nullptr, "actionOne can't be nullptr!");
CCASSERT(actionTwo != nullptr, "actionTwo can't be nullptr!");

float d = actionOne->getDuration() + actionTwo->getDuration();
ActionInterval::initWithDuration(d);
Expand Down Expand Up @@ -504,7 +504,7 @@ RepeatForever *RepeatForever::create(ActionInterval *action)

bool RepeatForever::initWithAction(ActionInterval *action)
{
CCASSERT(action != nullptr, "");
CCASSERT(action != nullptr, "action can't be nullptr!");
action->retain();
_innerAction = action;
return true;
Expand Down Expand Up @@ -645,8 +645,8 @@ Spawn* Spawn::createWithTwoActions(FiniteTimeAction *action1, FiniteTimeAction *

bool Spawn::initWithTwoActions(FiniteTimeAction *action1, FiniteTimeAction *action2)
{
CCASSERT(action1 != nullptr, "");
CCASSERT(action2 != nullptr, "");
CCASSERT(action1 != nullptr, "action1 can't be nullptr!");
CCASSERT(action2 != nullptr, "action2 can't be nullptr!");

bool ret = false;

Expand Down Expand Up @@ -2189,8 +2189,8 @@ ReverseTime* ReverseTime::create(FiniteTimeAction *action)

bool ReverseTime::initWithAction(FiniteTimeAction *action)
{
CCASSERT(action != nullptr, "");
CCASSERT(action != _other, "");
CCASSERT(action != nullptr, "action can't be nullptr!");
CCASSERT(action != _other, "action doesn't equal to _other!");

if (ActionInterval::initWithDuration(action->getDuration()))
{
Expand Down
18 changes: 9 additions & 9 deletions cocos/2d/CCActionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ void ActionManager::resumeTargets(const Vector<Node*>& targetsToResume)

void ActionManager::addAction(Action *action, Node *target, bool paused)
{
CCASSERT(action != nullptr, "");
CCASSERT(target != nullptr, "");
CCASSERT(action != nullptr, "action can't be nullptr!");
CCASSERT(target != nullptr, "target can't be nullptr!");

tHashElement *element = nullptr;
// we should convert it to Ref*, because we save it as Ref*
Expand All @@ -186,7 +186,7 @@ void ActionManager::addAction(Action *action, Node *target, bool paused)

actionAllocWithHashElement(element);

CCASSERT(! ccArrayContainsObject(element->actions, action), "");
CCASSERT(! ccArrayContainsObject(element->actions, action), "action already be added!");
ccArrayAppendObject(element->actions, action);

action->startWithTarget(target);
Expand Down Expand Up @@ -265,8 +265,8 @@ void ActionManager::removeAction(Action *action)

void ActionManager::removeActionByTag(int tag, Node *target)
{
CCASSERT(tag != Action::INVALID_TAG, "");
CCASSERT(target != nullptr, "");
CCASSERT(tag != Action::INVALID_TAG, "Invalid tag value!");
CCASSERT(target != nullptr, "target can't be nullptr!");

tHashElement *element = nullptr;
HASH_FIND_PTR(_targets, &target, element);
Expand All @@ -289,8 +289,8 @@ void ActionManager::removeActionByTag(int tag, Node *target)

void ActionManager::removeAllActionsByTag(int tag, Node *target)
{
CCASSERT(tag != Action::INVALID_TAG, "");
CCASSERT(target != nullptr, "");
CCASSERT(tag != Action::INVALID_TAG, "Invalid tag value!");
CCASSERT(target != nullptr, "target can't be nullptr!");

tHashElement *element = nullptr;
HASH_FIND_PTR(_targets, &target, element);
Expand Down Expand Up @@ -321,7 +321,7 @@ void ActionManager::removeActionsByFlags(unsigned int flags, Node *target)
{
return;
}
CCASSERT(target != nullptr, "");
CCASSERT(target != nullptr, "target can't be nullptr!");

tHashElement *element = nullptr;
HASH_FIND_PTR(_targets, &target, element);
Expand Down Expand Up @@ -352,7 +352,7 @@ void ActionManager::removeActionsByFlags(unsigned int flags, Node *target)
// and, it is not possible to get the address of a reference
Action* ActionManager::getActionByTag(int tag, const Node *target) const
{
CCASSERT(tag != Action::INVALID_TAG, "");
CCASSERT(tag != Action::INVALID_TAG, "Invalid tag value!");

tHashElement *element = nullptr;
HASH_FIND_PTR(_targets, &target, element);
Expand Down
4 changes: 2 additions & 2 deletions cocos/2d/CCCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ Vec2 Camera::project(const Vec3& src) const
Vec4 clipPos;
getViewProjectionMatrix().transformVector(Vec4(src.x, src.y, src.z, 1.0f), &clipPos);

CCASSERT(clipPos.w != 0.0f, "");
CCASSERT(clipPos.w != 0.0f, "clipPos.w can't be 0.0f!");
float ndcX = clipPos.x / clipPos.w;
float ndcY = clipPos.y / clipPos.w;

Expand All @@ -255,7 +255,7 @@ Vec2 Camera::projectGL(const Vec3& src) const
Vec4 clipPos;
getViewProjectionMatrix().transformVector(Vec4(src.x, src.y, src.z, 1.0f), &clipPos);

CCASSERT(clipPos.w != 0.0f, "");
CCASSERT(clipPos.w != 0.0f, "clipPos.w can't be 0.0f!");
float ndcX = clipPos.x / clipPos.w;
float ndcY = clipPos.y / clipPos.w;

Expand Down
6 changes: 3 additions & 3 deletions cocos/2d/CCGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,17 +245,17 @@ void GridBase::afterDraw(cocos2d::Node *target)

void GridBase::blit(void)
{
CCASSERT(0, "");
CCASSERT(0, "Subclass should implement it.");
}

void GridBase::reuse(void)
{
CCASSERT(0, "");
CCASSERT(0, "Subclass should implement it!");
}

void GridBase::calculateVertexPoints(void)
{
CCASSERT(0, "");
CCASSERT(0, "Subclass should implement it.");
}

// implementation of Grid3D
Expand Down
12 changes: 6 additions & 6 deletions cocos/2d/CCMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,11 +376,11 @@ void Menu::alignItemsInColumnsWithArray(const ValueVector& rows)
int rowColumns = 0;

for(const auto &child : _children) {
CCASSERT(row < rows.size(), "");
CCASSERT(row < rows.size(), "row should less than rows.size()!");

rowColumns = rows[row].asInt();
// can not have zero columns on a row
CCASSERT(rowColumns, "");
CCASSERT(rowColumns, "rowColumns can't be 0.");

float tmp = child->getContentSize().height;
rowHeight = (unsigned int)((rowHeight >= tmp || isnan(tmp)) ? rowHeight : tmp);
Expand All @@ -397,7 +397,7 @@ void Menu::alignItemsInColumnsWithArray(const ValueVector& rows)
}

// check if too many rows/columns for available menu items
CCASSERT(! columnsOccupied, "");
CCASSERT(! columnsOccupied, "columnsOccupied should be 0.");

Size winSize = Director::getInstance()->getWinSize();

Expand Down Expand Up @@ -472,11 +472,11 @@ void Menu::alignItemsInRowsWithArray(const ValueVector& columns)

for(const auto &child : _children) {
// check if too many menu items for the amount of rows/columns
CCASSERT(column < columns.size(), "");
CCASSERT(column < columns.size(), "column should be less than columns.size().");

columnRows = columns[column].asInt();
// can't have zero rows on a column
CCASSERT(columnRows, "");
CCASSERT(columnRows, "columnRows can't be 0.");

// columnWidth = fmaxf(columnWidth, [item contentSize].width);
float tmp = child->getContentSize().width;
Expand All @@ -499,7 +499,7 @@ void Menu::alignItemsInRowsWithArray(const ValueVector& columns)
}

// check if too many rows/columns for available menu items.
CCASSERT(! rowsOccupied, "");
CCASSERT(! rowsOccupied, "rowsOccupied should be 0.");

Size winSize = Director::getInstance()->getWinSize();

Expand Down
2 changes: 1 addition & 1 deletion cocos/2d/CCParticleSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ bool ParticleSystem::initWithDictionary(ValueMap& dictionary, const std::string&
else if( dictionary.find("textureImageData") != dictionary.end() )
{
std::string textureData = dictionary.at("textureImageData").asString();
CCASSERT(!textureData.empty(), "");
CCASSERT(!textureData.empty(), "textureData can't be empty!");

auto dataLen = textureData.size();
if (dataLen != 0)
Expand Down
7 changes: 4 additions & 3 deletions cocos/2d/CCSprite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ bool Sprite::initWithSpriteFrameName(const std::string& spriteFrameName)

bool Sprite::initWithSpriteFrame(SpriteFrame *spriteFrame)
{
CCASSERT(spriteFrame != nullptr, "");
CCASSERT(spriteFrame != nullptr, "spriteFrame can't be nullptr!");

bool bRet = initWithTexture(spriteFrame->getTexture(), spriteFrame->getRect());
setSpriteFrame(spriteFrame);
Expand Down Expand Up @@ -673,7 +673,7 @@ void Sprite::addChild(Node *child, int zOrder, int tag)
{
Sprite* childSprite = dynamic_cast<Sprite*>(child);
CCASSERT( childSprite, "CCSprite only supports Sprites as children when using SpriteBatchNode");
CCASSERT(childSprite->getTexture()->getName() == _textureAtlas->getTexture()->getName(), "");
CCASSERT(childSprite->getTexture()->getName() == _textureAtlas->getTexture()->getName(), "childSprite's texture name should be equal to _textureAtlas's texture name!");
//put it in descendants array of batch node
_batchNode->appendChild(childSprite);

Expand All @@ -694,7 +694,8 @@ void Sprite::addChild(Node *child, int zOrder, const std::string &name)
{
Sprite* childSprite = dynamic_cast<Sprite*>(child);
CCASSERT( childSprite, "CCSprite only supports Sprites as children when using SpriteBatchNode");
CCASSERT(childSprite->getTexture()->getName() == _textureAtlas->getTexture()->getName(), "");
CCASSERT(childSprite->getTexture()->getName() == _textureAtlas->getTexture()->getName(),
"childSprite's texture name should be equal to _textureAtlas's texture name.");
//put it in descendants array of batch node
_batchNode->appendChild(childSprite);

Expand Down
2 changes: 1 addition & 1 deletion cocos/2d/CCTMXXMLParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ void TMXMapInfo::endElement(void *ctx, const char *name)
ssize_t sizeHint = s.width * s.height * sizeof(unsigned int);

ssize_t CC_UNUSED inflatedLen = ZipUtils::inflateMemoryWithHint(buffer, len, &deflated, sizeHint);
CCASSERT(inflatedLen == sizeHint, "");
CCASSERT(inflatedLen == sizeHint, "inflatedLen should be equal to sizeHint!");

free(buffer);
buffer = nullptr;
Expand Down
3 changes: 2 additions & 1 deletion cocos/base/CCEventDispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,8 @@ void EventDispatcher::dispatchTouchEvent(EventTouch* event)
return true;
}

CCASSERT((*touchesIter)->getID() == (*mutableTouchesIter)->getID(), "");
CCASSERT((*touchesIter)->getID() == (*mutableTouchesIter)->getID(),
"touchesIter ID should be equal to mutableTouchesIter's ID.");

if (isClaimed && listener->_isRegistered && listener->_needSwallow)
{
Expand Down
2 changes: 1 addition & 1 deletion cocos/base/CCEventListenerAcceleration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ EventListenerAcceleration* EventListenerAcceleration::clone()

bool EventListenerAcceleration::checkAvailable()
{
CCASSERT(onAccelerationEvent, "");
CCASSERT(onAccelerationEvent, "onAccelerationEvent can't be nullptr!");

return true;
}
Expand Down
12 changes: 6 additions & 6 deletions cocos/base/CCScheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ void Scheduler::schedule(const ccSchedulerFunc& callback, void *target, float in
}
else
{
CCASSERT(element->paused == paused, "");
CCASSERT(element->paused == paused, "element's paused should be paused!");
}

if (element->timers == nullptr)
Expand Down Expand Up @@ -694,7 +694,7 @@ void Scheduler::unscheduleScriptEntry(unsigned int scheduleScriptEntryID)

void Scheduler::resumeTarget(void *target)
{
CCASSERT(target != nullptr, "");
CCASSERT(target != nullptr, "target can't be nullptr!");

// custom selectors
tHashTimerEntry *element = nullptr;
Expand All @@ -709,14 +709,14 @@ void Scheduler::resumeTarget(void *target)
HASH_FIND_PTR(_hashForUpdates, &target, elementUpdate);
if (elementUpdate)
{
CCASSERT(elementUpdate->entry != nullptr, "");
CCASSERT(elementUpdate->entry != nullptr, "elementUpdate's entry can't be nullptr!");
elementUpdate->entry->paused = false;
}
}

void Scheduler::pauseTarget(void *target)
{
CCASSERT(target != nullptr, "");
CCASSERT(target != nullptr, "target can't be nullptr!");

// custom selectors
tHashTimerEntry *element = nullptr;
Expand All @@ -731,7 +731,7 @@ void Scheduler::pauseTarget(void *target)
HASH_FIND_PTR(_hashForUpdates, &target, elementUpdate);
if (elementUpdate)
{
CCASSERT(elementUpdate->entry != nullptr, "");
CCASSERT(elementUpdate->entry != nullptr, "elementUpdate's entry can't be nullptr!");
elementUpdate->entry->paused = true;
}
}
Expand Down Expand Up @@ -1001,7 +1001,7 @@ void Scheduler::schedule(SEL_SCHEDULE selector, Ref *target, float interval, uns
}
else
{
CCASSERT(element->paused == paused, "");
CCASSERT(element->paused == paused, "element's paused should be paused.");
}

if (element->timers == nullptr)
Expand Down
4 changes: 2 additions & 2 deletions cocos/base/ZipUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ int ZipUtils::inflateGZipFile(const char *path, unsigned char **out)
int len;
unsigned int offset = 0;

CCASSERT(out, "");
CCASSERT(&*out, "");
CCASSERT(out, "out can't be nullptr.");
CCASSERT(&*out, "&*out can't be nullptr.");

gzFile inFile = gzopen(path, "rb");
if( inFile == nullptr ) {
Expand Down
2 changes: 1 addition & 1 deletion cocos/editor-support/cocosbuilder/CCBReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ CCBReader::~CCBReader()

void CCBReader::setCCBRootPath(const char* ccbRootPath)
{
CCASSERT(ccbRootPath != nullptr, "");
CCASSERT(ccbRootPath != nullptr, "ccbRootPath can't be nullptr!");
_CCBRootPath = ccbRootPath;
}

Expand Down
6 changes: 4 additions & 2 deletions cocos/editor-support/cocosbuilder/CCNodeLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,8 @@ Node * NodeLoader::parsePropTypeCCBFile(Node * pNode, Node * pParent, CCBReader
auto& ownerCallbackNodes = reader->getOwnerCallbackNodes();
if (!ownerCallbackNames.empty() && !ownerCallbackNodes.empty())
{
CCASSERT(ownerCallbackNames.size() == ownerCallbackNodes.size(), "");
CCASSERT(ownerCallbackNames.size() == ownerCallbackNodes.size(),
"ownerCallbackNames size should equal to ownerCallbackNodes size.");
ssize_t nCount = ownerCallbackNames.size();

for (ssize_t i = 0 ; i < nCount; i++)
Expand All @@ -982,7 +983,8 @@ Node * NodeLoader::parsePropTypeCCBFile(Node * pNode, Node * pParent, CCBReader
auto ownerOutletNodes = reader->getOwnerOutletNodes();
if (!ownerOutletNames.empty() && !ownerOutletNodes.empty())
{
CCASSERT(ownerOutletNames.size() == ownerOutletNodes.size(), "");
CCASSERT(ownerOutletNames.size() == ownerOutletNodes.size(),
"ownerOutletNames size should be equal to ownerOutletNodes's size.");
ssize_t nCount = ownerOutletNames.size();

for (ssize_t i = 0 ; i < nCount; i++)
Expand Down
Loading

0 comments on commit 7e4e82d

Please sign in to comment.