本文整理汇总了C++中CCASSERT函数的典型用法代码示例。如果您正苦于以下问题:C++ CCASSERT函数的具体用法?C++ CCASSERT怎么用?C++ CCASSERT使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CCASSERT函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CCASSERT
void Node::setOrderOfArrival(int orderOfArrival)
{
CCASSERT(orderOfArrival >=0, "Invalid orderOfArrival");
_orderOfArrival = orderOfArrival;
}
示例2: CCASSERT
void EventDispatcher::dispatchEventToListeners(EventListenerVector* listeners, const std::function<bool(EventListener*)>& onEvent)
{
bool shouldStopPropagation = false;
auto fixedPriorityListeners = listeners->getFixedPriorityListeners();
auto sceneGraphPriorityListeners = listeners->getSceneGraphPriorityListeners();
ssize_t i = 0;
// priority < 0
if (fixedPriorityListeners)
{
CCASSERT(listeners->getGt0Index() <= static_cast<ssize_t>(fixedPriorityListeners->size()), "Out of range exception!");
if (!fixedPriorityListeners->empty())
{
for (; i < listeners->getGt0Index(); ++i)
{
auto l = fixedPriorityListeners->at(i);
if (l->isEnabled() && !l->isPaused() && l->isRegistered() && onEvent(l))
{
shouldStopPropagation = true;
break;
}
}
}
}
if (sceneGraphPriorityListeners)
{
if (!shouldStopPropagation)
{
// priority == 0, scene graph priority
for (auto& l : *sceneGraphPriorityListeners)
{
if (l->isEnabled() && !l->isPaused() && l->isRegistered() && onEvent(l))
{
shouldStopPropagation = true;
break;
}
}
}
}
if (fixedPriorityListeners)
{
if (!shouldStopPropagation)
{
// priority > 0
ssize_t size = fixedPriorityListeners->size();
for (; i < size; ++i)
{
auto l = fixedPriorityListeners->at(i);
if (l->isEnabled() && !l->isPaused() && l->isRegistered() && onEvent(l))
{
shouldStopPropagation = true;
break;
}
}
}
}
}
示例3: sortEventListeners
void EventDispatcher::dispatchTouchEvent(EventTouch* event)
{
sortEventListeners(EventListenerTouchOneByOne::LISTENER_ID);
sortEventListeners(EventListenerTouchAllAtOnce::LISTENER_ID);
auto oneByOneListeners = getListeners(EventListenerTouchOneByOne::LISTENER_ID);
auto allAtOnceListeners = getListeners(EventListenerTouchAllAtOnce::LISTENER_ID);
// If there aren't any touch listeners, return directly.
if (nullptr == oneByOneListeners && nullptr == allAtOnceListeners)
return;
bool isNeedsMutableSet = (oneByOneListeners && allAtOnceListeners);
const std::vector<Touch*>& originalTouches = event->getTouches();
std::vector<Touch*> mutableTouches(originalTouches.size());
std::copy(originalTouches.begin(), originalTouches.end(), mutableTouches.begin());
//
// process the target handlers 1st
//
if (oneByOneListeners)
{
auto mutableTouchesIter = mutableTouches.begin();
auto touchesIter = originalTouches.begin();
for (; touchesIter != originalTouches.end(); ++touchesIter)
{
bool isSwallowed = false;
auto onTouchEvent = [&](EventListener* l) -> bool { // Return true to break
EventListenerTouchOneByOne* listener = static_cast<EventListenerTouchOneByOne*>(l);
// Skip if the listener was removed.
if (!listener->_isRegistered)
return false;
event->setCurrentTarget(listener->_node);
bool isClaimed = false;
std::vector<Touch*>::iterator removedIter;
EventTouch::EventCode eventCode = event->getEventCode();
if (eventCode == EventTouch::EventCode::BEGAN)
{
if (listener->onTouchBegan)
{
isClaimed = listener->onTouchBegan(*touchesIter, event);
if (isClaimed && listener->_isRegistered)
{
listener->_claimedTouches.push_back(*touchesIter);
}
}
}
else if (listener->_claimedTouches.size() > 0
&& ((removedIter = std::find(listener->_claimedTouches.begin(), listener->_claimedTouches.end(), *touchesIter)) != listener->_claimedTouches.end()))
{
isClaimed = true;
switch (eventCode)
{
case EventTouch::EventCode::MOVED:
if (listener->onTouchMoved)
{
listener->onTouchMoved(*touchesIter, event);
}
break;
case EventTouch::EventCode::ENDED:
if (listener->onTouchEnded)
{
listener->onTouchEnded(*touchesIter, event);
}
if (listener->_isRegistered)
{
listener->_claimedTouches.erase(removedIter);
}
break;
case EventTouch::EventCode::CANCELLED:
if (listener->onTouchCancelled)
{
listener->onTouchCancelled(*touchesIter, event);
}
if (listener->_isRegistered)
{
listener->_claimedTouches.erase(removedIter);
}
break;
default:
CCASSERT(false, "The eventcode is invalid.");
break;
}
}
// If the event was stopped, return directly.
if (event->isStopped())
{
updateListeners(event);
return true;
}
//.........这里部分代码省略.........
示例4: CCASSERT
bool RenderTexture::initWithWidthAndHeight(int w, int h, Texture2D::PixelFormat format, GLuint depthStencilFormat)
{
CCASSERT(format != Texture2D::PixelFormat::A8, "only RGB and RGBA formats are valid for a render texture");
bool ret = false;
void *data = nullptr;
do
{
_fullRect = _rtTextureRect = Rect(0,0,w,h);
//Size size = Director::getInstance()->getWinSizeInPixels();
//_fullviewPort = Rect(0,0,size.width,size.height);
w = (int)(w * CC_CONTENT_SCALE_FACTOR());
h = (int)(h * CC_CONTENT_SCALE_FACTOR());
_fullviewPort = Rect(0,0,w,h);
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &_oldFBO);
// textures must be power of two squared
int powW = 0;
int powH = 0;
if (Configuration::getInstance()->supportsNPOT())
{
powW = w;
powH = h;
}
else
{
powW = ccNextPOT(w);
powH = ccNextPOT(h);
}
auto dataLen = powW * powH * 4;
data = malloc(dataLen);
CC_BREAK_IF(! data);
memset(data, 0, dataLen);
_pixelFormat = format;
_texture = new (std::nothrow) Texture2D();
if (_texture)
{
_texture->initWithData(data, dataLen, (Texture2D::PixelFormat)_pixelFormat, powW, powH, Size((float)w, (float)h));
}
else
{
break;
}
GLint oldRBO;
glGetIntegerv(GL_RENDERBUFFER_BINDING, &oldRBO);
if (Configuration::getInstance()->checkForGLExtension("GL_QCOM"))
{
_textureCopy = new (std::nothrow) Texture2D();
if (_textureCopy)
{
_textureCopy->initWithData(data, dataLen, (Texture2D::PixelFormat)_pixelFormat, powW, powH, Size((float)w, (float)h));
}
else
{
break;
}
}
// generate FBO
glGenFramebuffers(1, &_FBO);
glBindFramebuffer(GL_FRAMEBUFFER, _FBO);
// associate texture with FBO
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _texture->getName(), 0);
if (depthStencilFormat != 0)
{
//create and attach depth buffer
glGenRenderbuffers(1, &_depthRenderBufffer);
glBindRenderbuffer(GL_RENDERBUFFER, _depthRenderBufffer);
glRenderbufferStorage(GL_RENDERBUFFER, depthStencilFormat, (GLsizei)powW, (GLsizei)powH);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, _depthRenderBufffer);
// if depth format is the one with stencil part, bind same render buffer as stencil attachment
if (depthStencilFormat == GL_DEPTH24_STENCIL8)
{
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, _depthRenderBufffer);
}
}
// check if it worked (probably worth doing :) )
CCASSERT(glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE, "Could not attach texture to framebuffer");
_texture->setAliasTexParameters();
// retained
setSprite(Sprite::createWithTexture(_texture));
_texture->release();
_sprite->setFlippedY(true);
_sprite->setBlendFunc( BlendFunc::ALPHA_PREMULTIPLIED );
glBindRenderbuffer(GL_RENDERBUFFER, oldRBO);
//.........这里部分代码省略.........
示例5: CCASSERT
void MotionStreak::setOpacity(GLubyte opacity)
{
CCASSERT(false, "Set opacity no supported");
}
示例6: CCASSERT
void Ref::retain()
{
CCASSERT(_referenceCount > 0, "reference count should be greater than 0");
++_referenceCount;
}
示例7: updateFont
void Label::visit(Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags)
{
if (! _visible || _originalUTF8String.empty())
{
return;
}
if (_systemFontDirty)
{
updateFont();
}
if (_contentDirty)
{
updateContent();
}
uint32_t flags = processParentFlags(parentTransform, parentFlags);
if (_shadowEnabled && _shadowBlurRadius <= 0 && (_shadowDirty || (flags & FLAGS_DIRTY_MASK)))
{
_position.x += _shadowOffset.width;
_position.y += _shadowOffset.height;
_transformDirty = _inverseDirty = true;
_shadowTransform = transform(parentTransform);
_position.x -= _shadowOffset.width;
_position.y -= _shadowOffset.height;
_transformDirty = _inverseDirty = true;
_shadowDirty = false;
}
if (!isVisitableByVisitingCamera())
{
return;
}
// IMPORTANT:
// To ease the migration to v3.0, we still support the Mat4 stack,
// but it is deprecated and your code should not rely on it
Director* director = Director::getInstance();
CCASSERT(nullptr != director, "Director is null when seting matrix stack");
director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform);
if (_textSprite)
{
drawTextSprite(renderer, flags);
}
else
{
draw(renderer, _modelViewTransform, flags);
}
director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
// FIX ME: Why need to set _orderOfArrival to 0??
// Please refer to https://github.com/cocos2d/cocos2d-x/pull/6920
// setOrderOfArrival(0);
}
示例8: CCASSERT
float Label::getLineHeight() const
{
CCASSERT(_currentLabelType != LabelType::STRING_TEXTURE, "Not supported system font!");
return _textSprite ? 0.0f : _commonLineHeight;
}
示例9: CCASSERT
// cocos2d-x doesn't support Samplers yet. But will be added soon
bool Material::parseSampler(GLProgramState* glProgramState, Properties* samplerProperties)
{
CCASSERT(samplerProperties->getId(), "Sampler must have an id. The id is the uniform name");
// required
auto filename = samplerProperties->getString("path");
auto texture = Director::getInstance()->getTextureCache()->addImage(filename);
if (!texture) {
CCLOG("Invalid filepath");
return false;
}
// optionals
{
Texture2D::TexParams texParams;
// mipmap
bool usemipmap = false;
const char* mipmap = getOptionalString(samplerProperties, "mipmap", "false");
if (mipmap && strcasecmp(mipmap, "true")==0) {
texture->generateMipmap();
usemipmap = true;
}
// valid options: REPEAT, CLAMP
const char* wrapS = getOptionalString(samplerProperties, "wrapS", "CLAMP_TO_EDGE");
if (strcasecmp(wrapS, "REPEAT")==0)
texParams.wrapS = GL_REPEAT;
else if(strcasecmp(wrapS, "CLAMP_TO_EDGE")==0)
texParams.wrapS = GL_CLAMP_TO_EDGE;
else
CCLOG("Invalid wrapS: %s", wrapS);
// valid options: REPEAT, CLAMP
const char* wrapT = getOptionalString(samplerProperties, "wrapT", "CLAMP_TO_EDGE");
if (strcasecmp(wrapT, "REPEAT")==0)
texParams.wrapT = GL_REPEAT;
else if(strcasecmp(wrapT, "CLAMP_TO_EDGE")==0)
texParams.wrapT = GL_CLAMP_TO_EDGE;
else
CCLOG("Invalid wrapT: %s", wrapT);
// valid options: NEAREST, LINEAR, NEAREST_MIPMAP_NEAREST, LINEAR_MIPMAP_NEAREST, NEAREST_MIPMAP_LINEAR, LINEAR_MIPMAP_LINEAR
const char* minFilter = getOptionalString(samplerProperties, "minFilter", usemipmap ? "LINEAR_MIPMAP_NEAREST" : "LINEAR");
if (strcasecmp(minFilter, "NEAREST")==0)
texParams.minFilter = GL_NEAREST;
else if(strcasecmp(minFilter, "LINEAR")==0)
texParams.minFilter = GL_LINEAR;
else if(strcasecmp(minFilter, "NEAREST_MIPMAP_NEAREST")==0)
texParams.minFilter = GL_NEAREST_MIPMAP_NEAREST;
else if(strcasecmp(minFilter, "LINEAR_MIPMAP_NEAREST")==0)
texParams.minFilter = GL_LINEAR_MIPMAP_NEAREST;
else if(strcasecmp(minFilter, "NEAREST_MIPMAP_LINEAR")==0)
texParams.minFilter = GL_NEAREST_MIPMAP_LINEAR;
else if(strcasecmp(minFilter, "LINEAR_MIPMAP_LINEAR")==0)
texParams.minFilter = GL_LINEAR_MIPMAP_LINEAR;
else
CCLOG("Invalid minFilter: %s", minFilter);
// valid options: NEAREST, LINEAR
const char* magFilter = getOptionalString(samplerProperties, "magFilter", "LINEAR");
if (strcasecmp(magFilter, "NEAREST")==0)
texParams.magFilter = GL_NEAREST;
else if(strcasecmp(magFilter, "LINEAR")==0)
texParams.magFilter = GL_LINEAR;
else
CCLOG("Invalid magFilter: %s", magFilter);
texture->setTexParameters(texParams);
}
glProgramState->setUniformTexture(samplerProperties->getId(), texture);
return true;
}
示例10: stopBlock
//.........这里部分代码省略.........
SimpleUI *simpleUI = MainGameScene::getUI();
UserInput *input = (UserInput*)simpleUI->getChildrenByName(UserInput::name());
input->dropInputEvents();
return;
}
if (!_isUndo) {
body1->SetTransform({ _positionOldFirst.x - blockSizeInMeters, body1->GetPosition().y }, 0);
body2->SetTransform({ _positionOldSecond.x - blockSizeInMeters, body2->GetPosition().y }, 0);
}
else {
body1->SetTransform({ _positionOldFirst.x + blockSizeInMeters, body1->GetPosition().y }, 0);
body2->SetTransform({ _positionOldSecond.x + blockSizeInMeters, body2->GetPosition().y }, 0);
}
sprite1->setPosition({ (body1->GetPosition().x
* ConstantsRegistry::getValueForKey(ConstantsRegistry::constants::SCALE_RATIO_BOX2D)) - size.width / 2
, (body1->GetPosition().y
* ConstantsRegistry::getValueForKey(ConstantsRegistry::constants::SCALE_RATIO_BOX2D)) - size.height / 2 });
sprite2->setPosition({ (body2->GetPosition().x
* ConstantsRegistry::getValueForKey(ConstantsRegistry::constants::SCALE_RATIO_BOX2D)) - size.width / 2
, (body2->GetPosition().y
* ConstantsRegistry::getValueForKey(ConstantsRegistry::constants::SCALE_RATIO_BOX2D)) - size.height / 2 });
stopBlock();
filter = body1->GetFixtureList()->GetFilterData();
filter.categoryBits ^= Block::blockFlags::NEED_TO_STOP;
filter.categoryBits = Block::blockFlags::STOPPED;
body1->GetFixtureList()->SetFilterData(filter);
filter = body2->GetFixtureList()->GetFilterData();
filter.categoryBits ^= Block::blockFlags::NEED_TO_STOP;
filter.categoryBits = Block::blockFlags::STOPPED;
body2->GetFixtureList()->SetFilterData(filter);
body1->SetActive(false);
body1->SetActive(true);
body2->SetActive(false);
body2->SetActive(true);
}
if ((_positionOldFirst.x - body1->GetPosition().x) < blockSizeInMeters
&& !_isUndo
&& _isExecute) {
if ((_positionOldFirst.x - (body1->GetPosition().x - offset)) >= blockSizeInMeters) {
while (offset > 0) {
offset -= ConstantsRegistry::getValueForKey(ConstantsRegistry::constants::MOVEOFFSET) / 100;
if ((_positionOldFirst.x - (body1->GetPosition().x - offset)) < blockSizeInMeters) {
stopBlock();
body1->SetTransform({ body1->GetPosition().x - offset, body1->GetPosition().y }, 0);
body2->SetTransform({ body2->GetPosition().x - offset, body2->GetPosition().y }, 0);
return;
}
}
}
CCASSERT(offset, "offset can't be 0");
if (body1->GetLinearVelocity().x > 0
&& (_positionOldFirst.x - body1->GetPosition().x) < (blockSizeInMeters / 7)) {
stopBlock();
body1->SetTransform(_positionOldFirst, 0);
body2->SetTransform(_positionOldSecond, 0);
return;
}
body1->SetLinearVelocity({ (float32)(body1->GetLinearVelocity().x - offset), body1->GetLinearVelocity().y });
body2->SetLinearVelocity({ (float32)(body2->GetLinearVelocity().x - offset), body2->GetLinearVelocity().y });
_positionOldFirst.y = body1->GetPosition().y;
_positionOldSecond.y = body2->GetPosition().y;
}
else if ((body1->GetPosition().x - _positionOldFirst.x) < blockSizeInMeters
&& _isUndo
&& _isExecute) {
if (((body1->GetPosition().x + offset) - _positionOldFirst.x) >= blockSizeInMeters) {
while (offset > 0) {
offset -= (ConstantsRegistry::getValueForKey(ConstantsRegistry::constants::MOVEOFFSET) / 100) * 10;
if (((body1->GetPosition().x + offset) - _positionOldFirst.x) < blockSizeInMeters) {
stopBlock();
body1->SetTransform({ body1->GetPosition().x + offset, body1->GetPosition().y }, 0);
body2->SetTransform({ body2->GetPosition().x + offset, body2->GetPosition().y }, 0);
return;
}
}
}
CCASSERT(offset, "offset can't be 0");
if (body1->GetLinearVelocity().x < 0
&& (_positionOldFirst.x - body1->GetPosition().x) < (blockSizeInMeters / 7)) {
stopBlock();
body1->SetTransform(_positionOldFirst, 0);
body2->SetTransform(_positionOldSecond, 0);
return;
}
body1->SetLinearVelocity({ (float32)(body1->GetLinearVelocity().x + offset), body1->GetLinearVelocity().y });
body2->SetLinearVelocity({ (float32)(body2->GetLinearVelocity().x + offset), body2->GetLinearVelocity().y });
_positionOldFirst.y = body1->GetPosition().y;
_positionOldSecond.y = body2->GetPosition().y;
}
else
stopBlock();
}
示例11: processResponse
// Process Response
static void processResponse(HttpResponse* response, char* errorBuffer)
{
auto request = response->getHttpRequest();
long responseCode = -1;
int retValue = 0;
// Process the request -> get response packet
switch (request->getRequestType())
{
case HttpRequest::Type::GET: // HTTP GET
retValue = processGetTask(request,
writeData,
response->getResponseData(),
&responseCode,
writeHeaderData,
response->getResponseHeader(),
errorBuffer);
break;
case HttpRequest::Type::POST: // HTTP POST
retValue = processPostTask(request,
writeData,
response->getResponseData(),
&responseCode,
writeHeaderData,
response->getResponseHeader(),
errorBuffer);
break;
case HttpRequest::Type::PUT:
retValue = processPutTask(request,
writeData,
response->getResponseData(),
&responseCode,
writeHeaderData,
response->getResponseHeader(),
errorBuffer);
break;
case HttpRequest::Type::DELETE:
retValue = processDeleteTask(request,
writeData,
response->getResponseData(),
&responseCode,
writeHeaderData,
response->getResponseHeader(),
errorBuffer);
break;
default:
CCASSERT(true, "CCHttpClient: unknown request type, only GET and POSt are supported");
break;
}
// write data to HttpResponse
response->setResponseCode(responseCode);
if (retValue != 0)
{
response->setSucceed(false);
response->setErrorBuffer(errorBuffer);
}
else
{
response->setSucceed(true);
}
}
示例12: CCLOG
void TriggerObj::serialize(const rapidjson::Value &val)
{
_id = (unsigned int)(DICTOOL->getIntValue_json(val, "id"));
int count = DICTOOL->getArrayCount_json(val, "conditions");
for (int i = 0; i < count; ++i)
{
const rapidjson::Value &subDict = DICTOOL->getSubDictionary_json(val, "conditions", i);
const char *classname = DICTOOL->getStringValue_json(subDict, "classname");
if (classname == nullptr)
{
continue;
}
BaseTriggerCondition *con = dynamic_cast<BaseTriggerCondition*>(ObjectFactory::getInstance()->createObject(classname));
if(con == nullptr)
{
CCLOG("class %s can not be implemented!", classname);
CCASSERT(con != nullptr, "");
}
CCASSERT(con != nullptr, "");
con->serialize(subDict);
con->init();
_cons.pushBack(con);
}
count = DICTOOL->getArrayCount_json(val, "actions");
for (int i = 0; i < count; ++i)
{
const rapidjson::Value &subDict = DICTOOL->getSubDictionary_json(val, "actions", i);
const char *classname = DICTOOL->getStringValue_json(subDict, "classname");
if (classname == nullptr)
{
continue;
}
BaseTriggerAction *act = dynamic_cast<BaseTriggerAction*>(ObjectFactory::getInstance()->createObject(classname));
if(act == nullptr)
{
CCLOG("class %s can not be implemented!", classname);
CCASSERT(act != nullptr, "");
}
act->serialize(subDict);
act->init();
_acts.pushBack(act);
}
int length = DICTOOL->getArrayCount_json(val, "events");
for (int i = 0; i < length; ++i)
{
const rapidjson::Value &sub = DICTOOL->getSubDictionary_json(val, "events", i);
int event = DICTOOL->getIntValue_json(sub, "id");
if (event < 0)
{
continue;
}
char* buf = new char[10];
sprintf(buf, "%d", event);
std::string custom_event_name(buf);
CC_SAFE_DELETE_ARRAY(buf);
EventListenerCustom* listener = EventListenerCustom::create(custom_event_name, [=](EventCustom* evt){
if (detect())
{
done();
}
});
_listeners.pushBack(listener);
TriggerMng::getInstance()->addEventListenerWithFixedPriority(listener, 1);
}
}
示例13: CCASSERT
void Physics3DRigidBody::removeConstraint( unsigned int idx )
{
CCASSERT(idx < _constraintList.size(), "idx < _constraintList.size()");
removeConstraint(_constraintList[idx]);
}
示例14: CCASSERT
void ActionTween::startWithTarget(Node *target)
{
CCASSERT(dynamic_cast<ActionTweenDelegate*>(target), "target must implement ActionTweenDelegate");
ActionInterval::startWithTarget(target);
m_fDelta = m_fTo - m_fFrom;
}
示例15: CCASSERT
void SpriteBatchNode::removeChildAtIndex(ssize_t index, bool doCleanup)
{
CCASSERT(index>=0 && index < _children.size(), "Invalid index");
removeChild(_children.at(index), doCleanup);
}