Uses C++11 iterator in samples

or it just uses touches->anyObject() instead of creating an iterator
and removes more unneeded casts
This commit is contained in:
Ricardo Quesada 2013-06-21 20:02:43 -07:00
parent 64d7cd404e
commit 404193eb9f
11 changed files with 71 additions and 90 deletions

View File

@ -72,16 +72,14 @@ void BugsTestMainLayer::onEnter()
void BugsTestMainLayer::ccTouchesBegan(Set *pTouches, Event *pEvent)
{
SetIterator it = pTouches->begin();
Touch* touch = (Touch*)(*it);
Touch* touch = (Touch*) pTouches->anyObject();
_beginPos = touch->getLocation();
}
void BugsTestMainLayer::ccTouchesMoved(Set *pTouches, Event *pEvent)
{
SetIterator it = pTouches->begin();
Touch* touch = (Touch*)(*it);
Touch* touch = (Touch*) pTouches->anyObject();
Point touchLocation = touch->getLocation();
float nMoveY = touchLocation.y - _beginPos.y;

View File

@ -212,15 +212,10 @@ void ChipmunkTestLayer::onEnter()
void ChipmunkTestLayer::ccTouchesEnded(Set* touches, Event* event)
{
//Add a new body/atlas sprite at the touched location
SetIterator it;
Touch* touch;
for( it = touches->begin(); it != touches->end(); it++)
for( auto &item: *touches)
{
touch = (Touch*)(*it);
if(!touch)
break;
Touch* touch = static_cast<Touch*>(item);
Point location = touch->getLocation();

View File

@ -39,8 +39,7 @@ MainLayer::MainLayer()
void MainLayer::ccTouchesEnded(Set *pTouches, Event *pEvent)
{
SetIterator it = pTouches->begin();
Touch* touch = (Touch*)(*it);
Touch* touch = (Touch*) pTouches->anyObject();
Point location = touch->getLocation();

View File

@ -188,16 +188,14 @@ void CocosDenshionTest::menuCallback(Object * pSender)
void CocosDenshionTest::ccTouchesBegan(Set *pTouches, Event *pEvent)
{
SetIterator it = pTouches->begin();
Touch* touch = (Touch*)(*it);
Touch* touch = (Touch*)pTouches->anyObject();
_beginPos = touch->getLocation();
}
void CocosDenshionTest::ccTouchesMoved(Set *pTouches, Event *pEvent)
{
SetIterator it = pTouches->begin();
Touch* touch = (Touch*)(*it);
Touch* touch = (Touch*)pTouches->anyObject();
Point touchLocation = touch->getLocation();
float nMoveY = touchLocation.y - _beginPos.y;

View File

@ -613,8 +613,7 @@ void LayerGradientTest::ccTouchesMoved(Set * touches, Event *event)
{
Size s = Director::sharedDirector()->getWinSize();
SetIterator it = touches->begin();
Touch* touch = (Touch*)(*it);
Touch* touch = (Touch*) touches->anyObject();
Point start = touch->getLocation();
Point diff = ccpSub( ccp(s.width/2,s.height/2), start);

View File

@ -92,8 +92,7 @@ void MotionStreakTest2::onEnter()
void MotionStreakTest2::ccTouchesMoved(Set* touches, Event* event)
{
SetIterator it = touches->begin();
Touch* touch = (Touch*)(*it);
Touch* touch = (Touch*) touches->anyObject();
Point touchLocation = touch->getLocation();

View File

@ -69,12 +69,12 @@ void MutiTouchTestLayer::registerWithTouchDispatcher(void)
Director::sharedDirector()->getTouchDispatcher()->addStandardDelegate(this, 0);
}
void MutiTouchTestLayer::ccTouchesBegan(Set *pTouches, Event *pEvent)
void MutiTouchTestLayer::ccTouchesBegan(Set *touches, Event *pEvent)
{
SetIterator iter = pTouches->begin();
for (; iter != pTouches->end(); iter++)
for ( auto &item: *touches )
{
Touch* pTouch = (Touch*)(*iter);
Touch* pTouch = (Touch*)item;
TouchPoint* pTouchPoint = TouchPoint::touchPointWithParent(this);
Point location = pTouch->getLocation();
@ -88,24 +88,22 @@ void MutiTouchTestLayer::ccTouchesBegan(Set *pTouches, Event *pEvent)
}
void MutiTouchTestLayer::ccTouchesMoved(Set *pTouches, Event *pEvent)
void MutiTouchTestLayer::ccTouchesMoved(Set *touches, Event *pEvent)
{
SetIterator iter = pTouches->begin();
for (; iter != pTouches->end(); iter++)
for( auto &item: *touches)
{
Touch* pTouch = (Touch*)(*iter);
Touch* pTouch = (Touch*)item;
TouchPoint* pTP = (TouchPoint*)s_dic.objectForKey(pTouch->getID());
Point location = pTouch->getLocation();
pTP->setTouchPos(location);
}
}
void MutiTouchTestLayer::ccTouchesEnded(Set *pTouches, Event *pEvent)
void MutiTouchTestLayer::ccTouchesEnded(Set *touches, Event *pEvent)
{
SetIterator iter = pTouches->begin();
for (; iter != pTouches->end(); iter++)
for ( auto &item: *touches )
{
Touch* pTouch = (Touch*)(*iter);
Touch* pTouch = (Touch*)item;
TouchPoint* pTP = (TouchPoint*)s_dic.objectForKey(pTouch->getID());
removeChild(pTP, true);
s_dic.removeObjectForKey(pTouch->getID());

View File

@ -363,11 +363,10 @@ string RenderTextureZbuffer::subtitle()
void RenderTextureZbuffer::ccTouchesBegan(cocos2d::Set *touches, cocos2d::Event *event)
{
SetIterator iter;
Touch *touch;
for (iter = touches->begin(); iter != touches->end(); ++iter)
for (auto &item: *touches)
{
touch = (Touch *)(*iter);
Touch *touch = static_cast<Touch*>(item);
Point location = touch->getLocation();
sp1->setPosition(location);
@ -384,11 +383,9 @@ void RenderTextureZbuffer::ccTouchesBegan(cocos2d::Set *touches, cocos2d::Event
void RenderTextureZbuffer::ccTouchesMoved(Set* touches, Event* event)
{
SetIterator iter;
Touch *touch;
for (iter = touches->begin(); iter != touches->end(); ++iter)
for (auto &item: *touches)
{
touch = (Touch *)(*iter);
Touch *touch = static_cast<Touch*>(item);
Point location = touch->getLocation();
sp1->setPosition(location);
@ -675,10 +672,10 @@ SpriteRenderTextureBug::SimpleSprite* SpriteRenderTextureBug::addNewSpriteWithCo
void SpriteRenderTextureBug::ccTouchesEnded(Set* touches, Event* event)
{
SetIterator iter = touches->begin();
for(; iter != touches->end(); ++iter)
for (auto &item: *touches)
{
Point location = ((Touch*)(*iter))->getLocation();
Touch *touch = static_cast<Touch*>(item);
Point location = touch->getLocation();
addNewSpriteWithCoords(location);
}
}

View File

@ -1 +1 @@
418e09b00ebb88c844d37c2b3b5d64e42cb12270
9d636101bc1bf33b3bfec3876b688be6d848c863

View File

@ -276,11 +276,11 @@ void TextureMipMap::onEnter()
addChild(img1);
EaseOut* scale1 = EaseOut::create(ScaleBy::create(4, 0.01f), 3);
ActionInterval* sc_back = scale1->reverse();
auto scale1 = EaseOut::create(ScaleBy::create(4, 0.01f), 3);
auto sc_back = scale1->reverse();
EaseOut* scale2 = scale1->clone();
ActionInterval* sc_back2 = scale2->reverse();
auto scale2 = scale1->clone();
auto sc_back2 = scale2->reverse();
img0->runAction(RepeatForever::create(Sequence::create(scale1, sc_back, NULL)));
img1->runAction(RepeatForever::create(Sequence::create(scale2, sc_back2, NULL)));
@ -326,11 +326,11 @@ void TexturePVRMipMap::onEnter()
img->setPosition(ccp( s.width/2.0f+100, s.height/2.0f));
addChild(img);
EaseOut* scale1 = EaseOut::create(ScaleBy::create(4, 0.01f), 3);
ActionInterval* sc_back = scale1->reverse();
auto scale1 = EaseOut::create(ScaleBy::create(4, 0.01f), 3);
auto sc_back = scale1->reverse();
EaseOut* scale2 = scale1->clone();
ActionInterval* sc_back2 = scale2->reverse();
auto scale2 = scale1->clone();
auto sc_back2 = scale2->reverse();
imgMipMap->runAction(RepeatForever::create(Sequence::create(scale1, sc_back, NULL)));
img->runAction(RepeatForever::create(Sequence::create(scale2, sc_back2, NULL)));
@ -369,11 +369,11 @@ void TexturePVRMipMap2::onEnter()
img->setPosition(ccp( s.width/2.0f+100, s.height/2.0f));
addChild(img);
EaseOut* scale1 = EaseOut::create(ScaleBy::create(4, 0.01f), 3);
ActionInterval* sc_back = scale1->reverse();
auto scale1 = EaseOut::create(ScaleBy::create(4, 0.01f), 3);
auto sc_back = scale1->reverse();
EaseOut* scale2 = scale1->clone();
ActionInterval* sc_back2 = scale2->reverse();
auto scale2 = scale1->clone();
auto sc_back2 = scale2->reverse();
imgMipMap->runAction(RepeatForever::create(Sequence::create(scale1, sc_back, NULL)));
img->runAction(RepeatForever::create(Sequence::create(scale2, sc_back2, NULL)));
@ -1271,10 +1271,10 @@ void TextureAlias::onEnter()
sprite2->getTexture()->setAliasTexParameters();
// scale them to show
ScaleBy* sc = ScaleBy::create(3, 8.0f);
ScaleBy* sc_back = (ScaleBy*) (sc->reverse());
RepeatForever* scaleforever = RepeatForever::create(Sequence::create(sc, sc_back, NULL));
RepeatForever* scaleToo = scaleforever->clone();
auto sc = ScaleBy::create(3, 8.0f);
auto sc_back = sc->reverse();
auto scaleforever = RepeatForever::create(Sequence::create(sc, sc_back, NULL));
auto scaleToo = scaleforever->clone();
sprite2->runAction(scaleforever);
sprite->runAction(scaleToo);
@ -1366,14 +1366,14 @@ void TexturePixelFormat::onEnter()
// remove texture from texture manager
TextureCache::sharedTextureCache()->removeTexture(sprite6->getTexture());
FadeOut* fadeout = FadeOut::create(2);
FadeIn* fadein = FadeIn::create(2);
Sequence* seq = Sequence::create(DelayTime::create(2), fadeout, fadein, NULL);
RepeatForever* seq_4ever = RepeatForever::create(seq);
RepeatForever* seq_4ever2 = seq_4ever->clone();
RepeatForever* seq_4ever3 = seq_4ever->clone();
RepeatForever* seq_4ever4 = seq_4ever->clone();
RepeatForever* seq_4ever5 = seq_4ever->clone();
auto fadeout = FadeOut::create(2);
auto fadein = FadeIn::create(2);
auto seq = Sequence::create(DelayTime::create(2), fadeout, fadein, NULL);
auto seq_4ever = RepeatForever::create(seq);
auto seq_4ever2 = seq_4ever->clone();
auto seq_4ever3 = seq_4ever->clone();
auto seq_4ever4 = seq_4ever->clone();
auto seq_4ever5 = seq_4ever->clone();
sprite1->runAction(seq_4ever);
sprite2->runAction(seq_4ever2);
@ -1456,15 +1456,15 @@ void TextureAsync::onEnter()
_imageOffset = 0;
Size size =Director::sharedDirector()->getWinSize();
Size size = Director::sharedDirector()->getWinSize();
LabelTTF *label = LabelTTF::create("Loading...", "Marker Felt", 32);
label->setPosition(ccp( size.width/2, size.height/2));
addChild(label, 10);
ScaleBy* scale = ScaleBy::create(0.3f, 2);
ScaleBy* scale_back = (ScaleBy*)scale->reverse();
Sequence* seq = Sequence::create(scale, scale_back, NULL);
auto scale = ScaleBy::create(0.3f, 2);
auto scale_back = scale->reverse();
auto seq = Sequence::create(scale, scale_back, NULL);
label->runAction(RepeatForever::create(seq));
scheduleOnce(schedule_selector(TextureAsync::loadImages), 1.0f);
@ -1547,11 +1547,11 @@ void TextureGlClamp::onEnter()
ccTexParams params = {GL_LINEAR,GL_LINEAR,GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE};
sprite->getTexture()->setTexParameters(&params);
RotateBy* rotate = RotateBy::create(4, 360);
auto rotate = RotateBy::create(4, 360);
sprite->runAction(rotate);
ScaleBy* scale = ScaleBy::create(2, 0.04f);
ScaleBy* scaleBack = (ScaleBy*) (scale->reverse());
Sequence* seq = Sequence::create(scale, scaleBack, NULL);
auto scale = ScaleBy::create(2, 0.04f);
auto scaleBack = scale->reverse();
auto seq = Sequence::create(scale, scaleBack, NULL);
sprite->runAction(seq);
}
@ -1584,11 +1584,11 @@ void TextureGlRepeat::onEnter()
ccTexParams params = {GL_LINEAR,GL_LINEAR,GL_REPEAT,GL_REPEAT};
sprite->getTexture()->setTexParameters(&params);
RotateBy* rotate = RotateBy::create(4, 360);
auto rotate = RotateBy::create(4, 360);
sprite->runAction(rotate);
ScaleBy* scale = ScaleBy::create(2, 0.04f);
ScaleBy* scaleBack = (ScaleBy*) (scale->reverse());
Sequence* seq = Sequence::create(scale, scaleBack, NULL);
auto scale = ScaleBy::create(2, 0.04f);
auto scaleBack = scale->reverse();
auto seq = Sequence::create(scale, scaleBack, NULL);
sprite->runAction(seq);
}
@ -1957,11 +1957,11 @@ std::string TexturePVRv3Premult::subtitle()
void TexturePVRv3Premult::transformSprite(cocos2d::Sprite *sprite)
{
FadeOut *fade = FadeOut::create(2);
DelayTime *dl = DelayTime::create(2);
FadeOut *fadein = (FadeOut*)fade->reverse();
Sequence *seq = Sequence::create(fade, fadein, dl, NULL);
RepeatForever *repeat = RepeatForever::create(seq);
auto fade = FadeOut::create(2);
auto dl = DelayTime::create(2);
auto fadein = fade->reverse();
auto seq = Sequence::create(fade, fadein, dl, NULL);
auto repeat = RepeatForever::create(seq);
sprite->runAction(repeat);
}

View File

@ -158,16 +158,14 @@ void TestController::closeCallback(Object * pSender)
void TestController::ccTouchesBegan(Set *pTouches, Event *pEvent)
{
SetIterator it = pTouches->begin();
Touch* touch = (Touch*)(*it);
Touch* touch = (Touch*)pTouches->anyObject();
_beginPos = touch->getLocation();
}
void TestController::ccTouchesMoved(Set *pTouches, Event *pEvent)
{
SetIterator it = pTouches->begin();
Touch* touch = (Touch*)(*it);
Touch* touch = (Touch*)pTouches->anyObject();
Point touchLocation = touch->getLocation();
float nMoveY = touchLocation.y - _beginPos.y;