index : cartcollect

this commit

0.5

jump

master

selection_screen

An iOS game where you catch items in a cart |

summary refs log tree commit diff stats

log msg

author

committer

range

path: root/Classes/GameModeSelectionDelegate.h

diff options

context:

1

2

3

4

5

6

7

8

9

10

15

20

25

30

35

40

space:

include

ignore

mode:

unified

ssdiff

stat only

|

Diffstat (limited to 'Classes/GameModeSelectionDelegate.h')

0 files changed, 0 insertions, 0 deletions

generated by cgit-pink 1.4.1 (git 2.36.1) at 2024-09-16 15:01:50 +0000

id='n39' href='#n39'>39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735

/*
* cocos2d for iPhone: http://www.cocos2d-iphone.org
*
* Copyright (c) 2010 Ricardo Quesada
* Copyright (c) 2011 Zynga Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/

// Only compile this code on iOS. These files should NOT be included on your Mac project.
// But in case they are included, it won't be compiled.
#import <Availability.h>
#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED

#import <unistd.h>

// cocos2d imports
#import "CCDirectorIOS.h"
#import "CCTouchDelegateProtocol.h"
#import "CCTouchDispatcher.h"
#import "../../CCScheduler.h"
#import "../../CCActionManager.h"
#import "../../CCTextureCache.h"
#import "../../ccMacros.h"
#import "../../CCScene.h"

// support imports
#import "glu.h"
#import "../../Support/OpenGL_Internal.h"
#import "../../Support/CGPointExtension.h"

#import "CCLayer.h"

#if CC_ENABLE_PROFILERS
#import "../../Support/CCProfiling.h"
#endif

#pragma mark -
#pragma mark Director - global variables (optimization)

CGFloat __ccContentScaleFactor = 1;

#pragma mark -
#pragma mark Director iOS

@interface CCDirector ()
-(void) setNextScene;
-(void) showFPS;
-(void) calculateDeltaTime;
@end

@implementation CCDirector (iOSExtensionClassMethods)

+(Class) defaultDirector
{
return [CCDirectorTimer class];
}

+ (BOOL) setDirectorType:(ccDirectorType)type
{
if( type == CCDirectorTypeDisplayLink ) {
NSString *reqSysVer = @"3.1";
NSString *currSysVer = [[UIDevice currentDevice] systemVersion];

if([currSysVer compare:reqSysVer options:NSNumericSearch] == NSOrderedAscending)
return NO;
}
switch (type) {
case CCDirectorTypeNSTimer:
[CCDirectorTimer sharedDirector];
break;
case CCDirectorTypeDisplayLink:
[CCDirectorDisplayLink sharedDirector];
break;
case CCDirectorTypeMainLoop:
[CCDirectorFast sharedDirector];
break;
case CCDirectorTypeThreadMainLoop:
[CCDirectorFastThreaded sharedDirector];
break;
default:
NSAssert(NO,@"Unknown director type");
}

return YES;
}

@end

#pragma mark -
#pragma mark CCDirectorIOS

@interface CCDirectorIOS ()
-(void) updateContentScaleFactor;

@end

@implementation CCDirectorIOS

- (id) init
{
if( (self=[super init]) ) {

// portrait mode default
deviceOrientation_ = CCDeviceOrientationPortrait;

__ccContentScaleFactor = 1;
isContentScaleSupported_ = NO;

// running thread is main thread on iOS
runningThread_ = [NSThread currentThread];
}

return self;
}

- (void) dealloc
{
[super dealloc];
}

//
// Draw the Scene
//
- (void) drawScene
{
/* calculate "global" dt */
[self calculateDeltaTime];

/* tick before glClear: issue #533 */
if( ! isPaused_ ) {
[[CCScheduler sharedScheduler] tick: dt];
}

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

/* to avoid flickr, nextScene MUST be here: after tick and before draw.
XXX: Which bug is this one. It seems that it can't be reproduced with v0.9 */
if( nextScene_ )
[self setNextScene];

glPushMatrix();

[self applyOrientation];

// By default enable VertexArray, ColorArray, TextureCoordArray and Texture2D
CC_ENABLE_DEFAULT_GL_STATES();

/* draw the scene */
[runningScene_ visit];

/* draw the notification node */
[notificationNode_ visit];

if( displayFPS_ )
[self showFPS];

#if CC_ENABLE_PROFILERS
[self showProfilers];
#endif

CC_DISABLE_DEFAULT_GL_STATES();

glPopMatrix();

[openGLView_ swapBuffers];
}

-(void) setProjection:(ccDirectorProjection)projection
{
CGSize size = winSizeInPixels_;

switch (projection) {
case kCCDirectorProjection2D:
glViewport(0, 0, size.width, size.height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
ccglOrtho(0, size.width, 0, size.height, -1024 * CC_CONTENT_SCALE_FACTOR(), 1024 * CC_CONTENT_SCALE_FACTOR());
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
break;

case kCCDirectorProjection3D:
{
float zeye = [self getZEye];

glViewport(0, 0, size.width, size.height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
// gluPerspective(60, (GLfloat)size.width/size.height, zeye-size.height/2, zeye+size.height/2 );
gluPerspective(60, (GLfloat)size.width/size.height, 0.5f, 1500);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt( size.width/2, size.height/2, zeye,
size.width/2, size.height/2, 0,
0.0f, 1.0f, 0.0f);
break;
}

case kCCDirectorProjectionCustom:
if( projectionDelegate_ )
[projectionDelegate_ updateProjection];
break;

default:
CCLOG(@"cocos2d: Director: unrecognized projecgtion");
break;
}

projection_ = projection;
}

#pragma mark Director Integration with a UIKit view

-(void) setOpenGLView:(EAGLView *)view
{
if( view != openGLView_ ) {

[super setOpenGLView:view];

// set size
winSizeInPixels_ = CGSizeMake(winSizeInPoints_.width * __ccContentScaleFactor, winSizeInPoints_.height *__ccContentScaleFactor);

if( __ccContentScaleFactor != 1 )
[self updateContentScaleFactor];

CCTouchDispatcher *touchDispatcher = [CCTouchDispatcher sharedDispatcher];
[openGLView_ setTouchDelegate: touchDispatcher];
[touchDispatcher setDispatchEvents: YES];
}
}

#pragma mark Director - Retina Display

-(CGFloat) contentScaleFactor
{
return __ccContentScaleFactor;
}

-(void) setContentScaleFactor:(CGFloat)scaleFactor
{
if( scaleFactor != __ccContentScaleFactor ) {

__ccContentScaleFactor = scaleFactor;
winSizeInPixels_ = CGSizeMake( winSizeInPoints_.width * scaleFactor, winSizeInPoints_.height * scaleFactor );

if( openGLView_ )
[self updateContentScaleFactor];

// update projection
[self setProjection:projection_];
}
}

-(void) updateContentScaleFactor
{
// Based on code snippet from: http://developer.apple.com/iphone/prerelease/library/snippets/sp2010/sp28.html
if ([openGLView_ respondsToSelector:@selector(setContentScaleFactor:)])
{
[openGLView_ setContentScaleFactor: __ccContentScaleFactor];

isContentScaleSupported_ = YES;
}
else
CCLOG(@"cocos2d: 'setContentScaleFactor:' is not supported on this device");
}

-(BOOL) enableRetinaDisplay:(BOOL)enabled
{
// Already enabled ?
if( enabled && __ccContentScaleFactor == 2 )
return YES;

// Already disabled
if( ! enabled && __ccContentScaleFactor == 1 )
return YES;

// setContentScaleFactor is not supported
if (! [openGLView_ respondsToSelector:@selector(setContentScaleFactor:)])
return NO;

// SD device
if ([[UIScreen mainScreen] scale] == 1.0)
return NO;

float newScale = enabled ? 2 : 1;
[self setContentScaleFactor:newScale];

return YES;
}

// overriden, don't call super
-(void) reshapeProjection:(CGSize)size
{
winSizeInPoints_ = [openGLView_ bounds].size;
winSizeInPixels_ = CGSizeMake(winSizeInPoints_.width * __ccContentScaleFactor, winSizeInPoints_.height *__ccContentScaleFactor);

[self setProjection:projection_];
}

#pragma mark Director Scene Landscape

-(CGPoint)convertToGL:(CGPoint)uiPoint
{
CGSize s = winSizeInPoints_;
float newY = s.height - uiPoint.y;
float newX = s.width - uiPoint.x;

CGPoint ret = CGPointZero;
switch ( deviceOrientation_) {
case CCDeviceOrientationPortrait:
ret = ccp( uiPoint.x, newY );
break;
case CCDeviceOrientationPortraitUpsideDown:
ret = ccp(newX, uiPoint.y);
break;
case CCDeviceOrientationLandscapeLeft:
ret.x = uiPoint.y;
ret.y = uiPoint.x;
break;
case CCDeviceOrientationLandscapeRight:
ret.x = newY;
ret.y = newX;
break;
}
return ret;
}

-(CGPoint)convertToUI:(CGPoint)glPoint
{
CGSize winSize = winSizeInPoints_;
int oppositeX = winSize.width - glPoint.x;
int oppositeY = winSize.height - glPoint.y;
CGPoint uiPoint = CGPointZero;
switch ( deviceOrientation_) {
case CCDeviceOrientationPortrait:
uiPoint = ccp(glPoint.x, oppositeY);
break;
case CCDeviceOrientationPortraitUpsideDown:
uiPoint = ccp(oppositeX, glPoint.y);
break;
case CCDeviceOrientationLandscapeLeft:
uiPoint = ccp(glPoint.y, glPoint.x);
break;
case CCDeviceOrientationLandscapeRight:
// Can't use oppositeX/Y because x/y are flipped
uiPoint = ccp(winSize.width-glPoint.y, winSize.height-glPoint.x);
break;
}
return uiPoint;
}

// get the current size of the glview
-(CGSize) winSize
{
CGSize s = winSizeInPoints_;

if( deviceOrientation_ == CCDeviceOrientationLandscapeLeft || deviceOrientation_ == CCDeviceOrientationLandscapeRight ) {
// swap x,y in landscape mode
CGSize tmp = s;
s.width = tmp.height;
s.height = tmp.width;
}
return s;
}

-(CGSize) winSizeInPixels
{
CGSize s = [self winSize];

s.width *= CC_CONTENT_SCALE_FACTOR();
s.height *= CC_CONTENT_SCALE_FACTOR();

return s;
}

-(ccDeviceOrientation) deviceOrientation
{
return deviceOrientation_;
}

- (void) setDeviceOrientation:(ccDeviceOrientation) orientation
{
if( deviceOrientation_ != orientation ) {
deviceOrientation_ = orientation;
switch( deviceOrientation_) {
case CCDeviceOrientationPortrait:
[[UIApplication sharedApplication] setStatusBarOrientation: UIInterfaceOrientationPortrait animated:NO];
break;
case CCDeviceOrientationPortraitUpsideDown:
[[UIApplication sharedApplication] setStatusBarOrientation: UIInterfaceOrientationPortraitUpsideDown animated:NO];
break;
case CCDeviceOrientationLandscapeLeft:
[[UIApplication sharedApplication] setStatusBarOrientation: UIInterfaceOrientationLandscapeRight animated:NO];
break;
case CCDeviceOrientationLandscapeRight:
[[UIApplication sharedApplication] setStatusBarOrientation: UIInterfaceOrientationLandscapeLeft animated:NO];
break;
default:
NSLog(@"Director: Unknown device orientation");
break;
}
}
}

-(void) applyOrientation
{
CGSize s = winSizeInPixels_;
float w = s.width / 2;
float h = s.height / 2;

// XXX it's using hardcoded values.
// What if the the screen size changes in the future?
switch ( deviceOrientation_ ) {
case CCDeviceOrientationPortrait:
// nothing
break;
case CCDeviceOrientationPortraitUpsideDown:
// upside down
glTranslatef(w,h,0);
glRotatef(180,0,0,1);
glTranslatef(-w,-h,0);
break;
case CCDeviceOrientationLandscapeRight:
glTranslatef(w,h,0);
glRotatef(90,0,0,1);
glTranslatef(-h,-w,0);
break;
case CCDeviceOrientationLandscapeLeft:
glTranslatef(w,h,0);
glRotatef(-90,0,0,1);
glTranslatef(-h,-w,0);
break;
}
}

-(void) end
{
// don't release the event handlers
// They are needed in case the director is run again
[[CCTouchDispatcher sharedDispatcher] removeAllDelegates];

[super end];
}

@end

#pragma mark -
#pragma mark Director TimerDirector

@implementation CCDirectorTimer
- (void)startAnimation
{
NSAssert( animationTimer == nil, @"animationTimer must be nil. Calling startAnimation twice?");

if( gettimeofday( &lastUpdate_, NULL) != 0 ) {
CCLOG(@"cocos2d: Director: Error in gettimeofday");
}

animationTimer = [NSTimer scheduledTimerWithTimeInterval:animationInterval_ target:self selector:@selector(mainLoop) userInfo:nil repeats:YES];

//
// If you want to attach the opengl view into UIScrollView
// uncomment this line to prevent 'freezing'.
// It doesn't work on with the Fast Director
//
// [[NSRunLoop currentRunLoop] addTimer:animationTimer
// forMode:NSRunLoopCommonModes];
}

-(void) mainLoop
{
[self drawScene];
}

- (void)stopAnimation
{
[animationTimer invalidate];
animationTimer = nil;
}

- (void)setAnimationInterval:(NSTimeInterval)interval
{
animationInterval_ = interval;

if(animationTimer) {
[self stopAnimation];
[self startAnimation];
}
}

-(void) dealloc
{
[animationTimer release];
[super dealloc];
}
@end

#pragma mark -
#pragma mark Director DirectorFast

@implementation CCDirectorFast

- (id) init
{
if(( self = [super init] )) {

#if CC_DIRECTOR_DISPATCH_FAST_EVENTS
CCLOG(@"cocos2d: Fast Events enabled");
#else
CCLOG(@"cocos2d: Fast Events disabled");
#endif
isRunning = NO;

// XXX:
// XXX: Don't create any autorelease object before calling "fast director"
// XXX: else it will be leaked
// XXX:
autoreleasePool = [NSAutoreleasePool new];
}

return self;
}

- (void) startAnimation
{
NSAssert( isRunning == NO, @"isRunning must be NO. Calling startAnimation twice?");

// XXX:
// XXX: release autorelease objects created
// XXX: between "use fast director" and "runWithScene"
// XXX:
[autoreleasePool release];
autoreleasePool = nil;

if ( gettimeofday( &lastUpdate_, NULL) != 0 ) {
CCLOG(@"cocos2d: Director: Error in gettimeofday");
}

isRunning = YES;

SEL selector = @selector(mainLoop);
NSMethodSignature* sig = [[[CCDirector sharedDirector] class]
instanceMethodSignatureForSelector:selector];
NSInvocation* invocation = [NSInvocation
invocationWithMethodSignature:sig];
[invocation setTarget:[CCDirector sharedDirector]];
[invocation setSelector:selector];
[invocation performSelectorOnMainThread:@selector(invokeWithTarget:)
withObject:[CCDirector sharedDirector] waitUntilDone:NO];

// NSInvocationOperation *loopOperation = [[[NSInvocationOperation alloc]
// initWithTarget:self selector:@selector(mainLoop) object:nil]
// autorelease];
//
// [loopOperation performSelectorOnMainThread:@selector(start) withObject:nil
// waitUntilDone:NO];
}

-(void) mainLoop
{
while (isRunning) {

NSAutoreleasePool *loopPool = [NSAutoreleasePool new];

#if CC_DIRECTOR_DISPATCH_FAST_EVENTS
while( CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.004f, FALSE) == kCFRunLoopRunHandledSource);
#else
while(CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, TRUE) == kCFRunLoopRunHandledSource);
#endif

if (isPaused_) {
usleep(250000); // Sleep for a quarter of a second (250,000 microseconds) so that the framerate is 4 fps.
}

[self drawScene];

#if CC_DIRECTOR_DISPATCH_FAST_EVENTS
while( CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.004f, FALSE) == kCFRunLoopRunHandledSource);
#else
while(CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, TRUE) == kCFRunLoopRunHandledSource);
#endif

[loopPool release];
}
}
- (void) stopAnimation
{
isRunning = NO;
}

- (void)setAnimationInterval:(NSTimeInterval)interval
{
NSLog(@"FastDirectory doesn't support setAnimationInterval, yet");
}
@end

#pragma mark -
#pragma mark Director DirectorThreadedFast

@implementation CCDirectorFastThreaded

- (id) init
{
if(( self = [super init] )) {
isRunning = NO;
}

return self;
}

- (void) startAnimation
{
NSAssert( isRunning == NO, @"isRunning must be NO. Calling startAnimation twice?");

if ( gettimeofday( &lastUpdate_, NULL) != 0 ) {
CCLOG(@"cocos2d: ThreadedFastDirector: Error on gettimeofday");
}

isRunning = YES;

NSThread *thread = [[NSThread alloc] initWithTarget:self selector:@selector(mainLoop) object:nil];
[thread start];
[thread release];
}

-(void) mainLoop
{
while( ![[NSThread currentThread] isCancelled] ) {
if( isRunning )
[self performSelectorOnMainThread:@selector(drawScene) withObject:nil waitUntilDone:YES];

if (isPaused_) {
usleep(250000); // Sleep for a quarter of a second (250,000 microseconds) so that the framerate is 4 fps.
} else {
// usleep(2000);
}
}
}
- (void) stopAnimation
{
isRunning = NO;
}

- (void)setAnimationInterval:(NSTimeInterval)interval
{
NSLog(@"FastDirector doesn't support setAnimationInterval, yet");
}
@end

#pragma mark -
#pragma mark DirectorDisplayLink

// Allows building DisplayLinkDirector for pre-3.1 SDKS
// without getting compiler warnings.
@interface NSObject(CADisplayLink)
+ (id) displayLinkWithTarget:(id)arg1 selector:(SEL)arg2;
- (void) addToRunLoop:(id)arg1 forMode:(id)arg2;
- (void) setFrameInterval:(int)interval;
- (void) invalidate;
@end

@implementation CCDirectorDisplayLink

- (void)setAnimationInterval:(NSTimeInterval)interval
{
animationInterval_ = interval;
if(displayLink){
[self stopAnimation];
[self startAnimation];
}
}

- (void) startAnimation
{
NSAssert( displayLink == nil, @"displayLink must be nil. Calling startAnimation twice?");

if ( gettimeofday( &lastUpdate_, NULL) != 0 ) {
CCLOG(@"cocos2d: DisplayLinkDirector: Error on gettimeofday");
}

// approximate frame rate
// assumes device refreshes at 60 fps
int frameInterval = (int) floor(animationInterval_ * 60.0f);

CCLOG(@"cocos2d: Frame interval: %d", frameInterval);

displayLink = [NSClassFromString(@"CADisplayLink") displayLinkWithTarget:self selector:@selector(mainLoop:)];
[displayLink setFrameInterval:frameInterval];
[displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
}

-(void) mainLoop:(id)sender
{
[self drawScene];
}

- (void) stopAnimation
{
[displayLink invalidate];
displayLink = nil;
}

-(void) dealloc
{
[displayLink release];
[super dealloc];
}
@end

#endif // __IPHONE_OS_VERSION_MAX_ALLOWED

generated by cgit-pink 1.4.1 (git 2.36.1) at 2024-09-16 15:01:51 +0000