diff --git a/.gitignore b/.gitignore index 20cdc3c..94cef62 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ build *.pbxuser *.mode1v3 -*.mode2v3 \ No newline at end of file +*.mode2v3 +*.xcuserstate diff --git a/Classes/AppDelegate.h b/Classes/AppDelegate.h deleted file mode 100644 index 00bac72..0000000 --- a/Classes/AppDelegate.h +++ /dev/null @@ -1,7 +0,0 @@ -#import "cocos2d.h" - -@interface AppDelegate : NSObject -{ - UIWindow *window; -} -@end diff --git a/Classes/AppDelegate.m b/Classes/AppDelegate.m deleted file mode 100644 index 656e178..0000000 --- a/Classes/AppDelegate.m +++ /dev/null @@ -1,49 +0,0 @@ -#import "AppDelegate.h" -#import "Game.h" -#import "Main.h" - -@implementation AppDelegate - -- (void)applicationDidFinishLaunching:(UIApplication *)application { - - [application setStatusBarStyle:UIStatusBarStyleBlackTranslucent animated:YES]; - - window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; -// [window setUserInteractionEnabled:YES]; -// [window setMultipleTouchEnabled:YES]; - - [[Director sharedDirector] setPixelFormat:kRGBA8]; - [[Director sharedDirector] attachInWindow:window]; -// [[Director sharedDirector] setDisplayFPS:YES]; - [[Director sharedDirector] setAnimationInterval:1.0/kFPS]; - - [Texture2D setDefaultAlphaPixelFormat:kTexture2DPixelFormat_RGBA8888]; - - [window makeKeyAndVisible]; - - Scene *scene = [[Scene node] addChild:[Game node] z:0]; - [[Director sharedDirector] runWithScene: scene]; -} - -- (void)dealloc { - [window release]; - [super dealloc]; -} - -- (void)applicationWillResignActive:(UIApplication*)application { - [[Director sharedDirector] pause]; -} - -- (void)applicationDidBecomeActive:(UIApplication*)application { - [[Director sharedDirector] resume]; -} - -- (void)applicationDidReceiveMemoryWarning:(UIApplication*)application { - [[TextureMgr sharedTextureMgr] removeAllTextures]; -} - -- (void)applicationSignificantTimeChange:(UIApplication*)application { - [[Director sharedDirector] setNextDeltaTimeZero:YES]; -} - -@end diff --git a/README.md b/README.md index 49e671c..97269f5 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Jump on platforms, collect coins on the way, and get highest score. * [Tweejump on the App Store][1] (Free) * [Tweejump video on YouTube][2] -Powered by [Cocos2D][3] framework. +Powered by [Cocos2D 1.0.1][3] framework. [1]: http://itunes.apple.com/us/app/tweejump/id318903704?mt=8 [2]: http://www.youtube.com/watch?v=AtPiVIlCfMY diff --git a/Support/cocos2d/Action.h b/Support/cocos2d/Action.h deleted file mode 100644 index 4955920..0000000 --- a/Support/cocos2d/Action.h +++ /dev/null @@ -1,110 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2008,2009 Ricardo Quesada - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - -#import -#include - -#import "ccTypes.h" - -enum { - //! Default tag - kActionTagInvalid = -1, -}; - -@class CocosNode; -/** Base class for actions - */ -@interface Action : NSObject { - CocosNode *target; - int tag; -} - -/** The "target". The action will modify the target properties */ -@property (readwrite,assign) CocosNode *target; -/** The action tag. An identifier of the action */ -@property (readwrite,assign) int tag; - -+(id) action; --(id) init; - --(id) copyWithZone: (NSZone*) zone; - -//! called before the action start --(void) start; -//! return YES if the action has finished --(BOOL) isDone; -//! called after the action has finished --(void) stop; -//! called every frame with it's delta time. DON'T override unless you know what you are doing. --(void) step: (ccTime) dt; -//! called once per frame. time a value between 0 and 1 -//! For example: -//! * 0 means that the action just started -//! * 0.5 means that the action is in the middle -//! * 1 means that the action is over --(void) update: (ccTime) time; - -@end - -/** Base class actions that do have a finite time duration. - Possible actions: - - An action with a duration of 0 seconds - - An action with a duration of 35.5 seconds - Infitite time actions are valid - */ -@interface FiniteTimeAction : Action -{ - //! duration in seconds - ccTime duration; -} -//! duration in seconds of the action -@property (readwrite) ccTime duration; - -/** returns a reversed action */ -- (FiniteTimeAction*) reverse; -@end - - -@class IntervalAction; -/** Repeats an action for ever. - To repeat the an action for a limited number of times use the Repeat action. - @warning This action can't be Sequenceable because it is not an IntervalAction - */ -@interface RepeatForever : Action -{ - IntervalAction *other; -} -/** creates the action */ -+(id) actionWithAction: (IntervalAction*) action; -/** initializes the action */ --(id) initWithAction: (IntervalAction*) action; -@end - -/** Changes the speed of an action, making it take longer (speed>1) - or less (speed<1) time. - Useful to simulate 'slow motion' or 'fast forward' effect. - @warning This action can't be Sequenceable because it is not an IntervalAction - */ -@interface Speed : Action -{ - IntervalAction *other; - float speed; -} -/** alter the speed of the inner function in runtime */ -@property (readwrite) float speed; -/** creates the action */ -+(id) actionWithAction: (IntervalAction*) action speed:(float)rate; -/** initializes the action */ --(id) initWithAction: (IntervalAction*) action speed:(float)rate; -@end diff --git a/Support/cocos2d/Action.m b/Support/cocos2d/Action.m deleted file mode 100644 index 4f3475c..0000000 --- a/Support/cocos2d/Action.m +++ /dev/null @@ -1,222 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2008,2009 Ricardo Quesada - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - - -#import "Action.h" -#import "CocosNode.h" -#import "ccMacros.h" - -#import "IntervalAction.h" - -// -// Action Base Class -// -#pragma mark - -#pragma mark Action -@implementation Action - -@synthesize target; -@synthesize tag; - -+(id) action -{ - return [[[self alloc] init] autorelease]; -} - --(id) init -{ - if( !(self=[super init]) ) - return nil; - - target = nil; - tag = kActionTagInvalid; - return self; -} - --(void) dealloc -{ - CCLOG(@"deallocing %@", self); - [super dealloc]; -} - --(id) copyWithZone: (NSZone*) zone -{ - Action *copy = [[[self class] allocWithZone: zone] init]; - copy.target = target; - copy.tag = tag; - return copy; -} - --(void) start -{ - // override me -} - --(void) stop -{ - // override me -} - --(BOOL) isDone -{ - return YES; -} - --(void) step: (ccTime) dt -{ - NSLog(@"[Action step]. override me"); -} - --(void) update: (ccTime) time -{ - NSLog(@"[Action update]. override me"); -} -@end - -// -// FiniteTimeAction -// -#pragma mark - -#pragma mark FiniteTimeAction -@implementation FiniteTimeAction -@synthesize duration; - -- (FiniteTimeAction*) reverse -{ - CCLOG(@"FiniteTimeAction#reverse: Implement me"); - return nil; -} -@end - - -// -// RepeatForever -// -#pragma mark - -#pragma mark RepeatForever -@implementation RepeatForever -+(id) actionWithAction: (IntervalAction*) action -{ - return [[[self alloc] initWithAction: action] autorelease]; -} - --(id) initWithAction: (IntervalAction*) action -{ - if( !(self=[super init]) ) - return nil; - - other = [action retain]; - return self; -} - --(id) copyWithZone: (NSZone*) zone -{ - Action *copy = [[[self class] allocWithZone: zone] initWithAction:[[other copy] autorelease] ]; - return copy; -} - --(void) dealloc -{ - [other release]; - [super dealloc]; -} - --(void) start -{ - [super start]; - other.target = target; - [other start]; -} - --(void) step:(ccTime) dt -{ - [other step: dt]; - if( [other isDone] ) { - [other start]; - } -} - - --(BOOL) isDone -{ - return NO; -} - -- (IntervalAction *) reverse -{ - return [RepeatForever actionWithAction:[other reverse]]; -} - -@end - -// -// Speed -// -#pragma mark - -#pragma mark Speed -@implementation Speed -@synthesize speed; - -+(id) actionWithAction: (IntervalAction*) action speed:(float)r -{ - return [[[self alloc] initWithAction: action speed:r] autorelease]; -} - --(id) initWithAction: (IntervalAction*) action speed:(float)r -{ - if( !(self=[super init]) ) - return nil; - - other = [action retain]; - speed = r; - return self; -} - --(id) copyWithZone: (NSZone*) zone -{ - Action *copy = [[[self class] allocWithZone: zone] initWithAction:[[other copy] autorelease] speed:speed]; - return copy; -} - --(void) dealloc -{ - [other release]; - [super dealloc]; -} - --(void) start -{ - [super start]; - other.target = target; - [other start]; -} - --(void) step:(ccTime) dt -{ - [other step: dt * speed]; -} - --(BOOL) isDone -{ - return [other isDone]; -} - -- (IntervalAction *) reverse -{ - return [Speed actionWithAction:[other reverse] speed:speed]; -} -@end - - - diff --git a/Support/cocos2d/AtlasNode.h b/Support/cocos2d/AtlasNode.h deleted file mode 100644 index 9bdd318..0000000 --- a/Support/cocos2d/AtlasNode.h +++ /dev/null @@ -1,70 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2008,2009 Ricardo Quesada - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - -#import "TextureAtlas.h" -#import "CocosNode.h" - -/** AtlasNode is a subclass of CocosNode that implements the CocosNodeRGBA and - CocosNodeTexture protocol - - It knows how to render a TextureAtlas object. - If you are going to render a TextureAtlas consider subclassing AtlasNode (or a subclass of AtlasNode) - - All features from CocosNode are valid, plus the following features: - - opacity and RGB colors - */ -@interface AtlasNode : CocosNode { - - // texture atlas - TextureAtlas *textureAtlas_; - // chars per row - int itemsPerRow; - // chars per column - int itemsPerColumn; - - // texture coordinate x increment - float texStepX; - // texture coordinate y increment - float texStepY; - - // width of each char - int itemWidth; - // height of each char - int itemHeight; - - // texture opacity - GLubyte opacity_; - - // texture color - GLubyte r_,g_,b_; - -} - -/** conforms to CocosNodeTexture protocol */ -@property (readwrite,retain) TextureAtlas *textureAtlas; - -/** conforms to CocosNodeRGBA protocol */ -@property (readonly) GLubyte r, g, b, opacity; - -/** creates an AtlasNode with an Atlas file the width and height of each item and the quantity of items to render*/ -+(id) atlasWithTileFile:(NSString*)tile tileWidth:(int)w tileHeight:(int)h itemsToRender: (int) c; - -/** initializes an AtlasNode with an Atlas file the width and height of each item and the quantity of items to render*/ --(id) initWithTileFile:(NSString*)tile tileWidth:(int)w tileHeight:(int)h itemsToRender: (int) c; - -/** updates the Atlas (indexed vertex array). - * Shall be overriden in subclasses - */ --(void) updateAtlasValues; -@end diff --git a/Support/cocos2d/AtlasNode.m b/Support/cocos2d/AtlasNode.m deleted file mode 100644 index 46d7a35..0000000 --- a/Support/cocos2d/AtlasNode.m +++ /dev/null @@ -1,146 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2008,2009 Ricardo Quesada - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - -#import "AtlasNode.h" -#import "ccMacros.h" - - -@interface AtlasNode (Private) --(void) calculateMaxItems; --(void) calculateTexCoordsSteps; -@end - -@implementation AtlasNode - -@synthesize opacity=opacity_, r=r_, g=g_, b=b_; -@synthesize textureAtlas = textureAtlas_; - -#pragma mark AtlasNode - Creation & Init -+(id) atlasWithTileFile:(NSString*)tile tileWidth:(int)w tileHeight:(int)h itemsToRender: (int) c -{ - return [[[self alloc] initWithTileFile:tile tileWidth:w tileHeight:h itemsToRender:c] autorelease]; -} - - --(id) initWithTileFile:(NSString*)tile tileWidth:(int)w tileHeight:(int)h itemsToRender: (int) c -{ - if( ! (self=[super init]) ) - return nil; - - // retained - self.textureAtlas = [TextureAtlas textureAtlasWithFile:tile capacity:c]; - - itemWidth = w; - itemHeight = h; - - opacity_ = 255; - r_ = g_ = b_ = 255; - - [self calculateMaxItems]; - [self calculateTexCoordsSteps]; - - return self; -} - --(void) dealloc -{ - [textureAtlas_ release]; - - [super dealloc]; -} - -#pragma mark AtlasNode - Atlas generation - --(void) calculateMaxItems -{ - CGSize s = [[textureAtlas_ texture] contentSize]; - itemsPerColumn = s.height / itemHeight; - itemsPerRow = s.width / itemWidth; -} - --(void) calculateTexCoordsSteps -{ - texStepX = itemWidth / (float) [[textureAtlas_ texture] pixelsWide]; - texStepY = itemHeight / (float) [[textureAtlas_ texture] pixelsHigh]; -} - --(void) updateAtlasValues -{ - [NSException raise:@"AtlasNode:Abstract" format:@"updateAtlasValue not overriden"]; -} - -#pragma mark AtlasNode - draw -- (void) draw -{ - glEnableClientState( GL_VERTEX_ARRAY); - glEnableClientState( GL_TEXTURE_COORD_ARRAY ); - - glEnable( GL_TEXTURE_2D); - - glColor4ub( r_, g_, b_, opacity_); - - BOOL preMulti = [[textureAtlas_ texture] hasPremultipliedAlpha]; - if( ! preMulti ) - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - - [textureAtlas_ drawQuads]; - - if( !preMulti ) - glBlendFunc(CC_BLEND_SRC, CC_BLEND_DST); - - // is this chepear than saving/restoring color state ? - glColor4ub( 255, 255, 255, 255); - - glDisable( GL_TEXTURE_2D); - - glDisableClientState(GL_VERTEX_ARRAY ); - glDisableClientState( GL_TEXTURE_COORD_ARRAY ); -} - -#pragma mark AtlasNode - RGBA protocol - --(void) setRGB: (GLubyte) rr :(GLubyte) gg :(GLubyte)bb -{ - r_=rr; - g_=gg; - b_=bb; -} - --(void) setOpacity:(GLubyte)opacity -{ - // special opacity for premultiplied textures - opacity_ = opacity; - if( [[textureAtlas_ texture] hasPremultipliedAlpha] ) - r_ = g_ = b_ = opacity_; -} - --(CGSize) contentSize -{ - [NSException raise:@"ContentSizeAbstract" format:@"ContentSize was not overriden"]; - return CGSizeMake(0,0); -} - -#pragma mark AtlasNode - CocosNodeTexture protocol --(void) setTexture:(Texture2D*)texture -{ - textureAtlas_.texture = texture; -} - --(Texture2D*) texture -{ - return textureAtlas_.texture; -} - - -@end diff --git a/Support/cocos2d/AtlasSprite.h b/Support/cocos2d/AtlasSprite.h deleted file mode 100644 index 6c44b36..0000000 --- a/Support/cocos2d/AtlasSprite.h +++ /dev/null @@ -1,146 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2009 Matt Oswald - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - -#import "CocosNode.h" -#import "TextureAtlas.h" - -@class AtlasSpriteManager; -@class AtlasSpriteFrame; - -#pragma mark AltasSprite - -/** AtlasSprite is a CocosNode object that implements the CocosNodeSize, CocosNodeFrames, CocosNodeOpacity and - * CocosNodeRGB protocols. - * - * AtlasSprite can be used as a replacement of Sprite. - * - * AtlasSprite has all the features from CocosNode with the following additions and limitations: - * - New features - * - It is MUCH faster than Sprite - * - supports flipX, flipY - * - * - Limitations - * - Their parent can only be an AtlasSpriteManager - * - They can't have children - * - Camera is not supported yet (eg: OrbitCamera action doesn't work) - * - GridBase actions are supported (eg: Lens, Ripple, Twirl) - * - They can't Aliased or AntiAliased (but AtlasSpriteManager can) - * - Parallax scroller is not supported, but can be simulated with a "proxy" sprite. - * - * @since v0.7.1 - */ -@interface AtlasSprite : CocosNode -{ - // weak reference - TextureAtlas *textureAtlas_; - NSUInteger atlasIndex_; - - // texture pixels - CGRect rect_; - - // texture, vertex and color info - ccV3F_C4B_T2F_Quad quad_; - - // whether or not this Sprite needs to be updated in the Atlas - BOOL dirty; - - // opacity and RGB protocol - GLubyte opacity_; - GLubyte r_, g_, b_; - - // Animations that belong to the sprite - NSMutableDictionary *animations; - - // image is flipped - BOOL flipX_; - BOOL flipY_; -} - -/** whether or not the Sprite needs to be updated in the Atlas */ -@property (readonly) BOOL dirty; -/** the quad (tex coords, vertex coords and color) information */ -@property (readonly) ccV3F_C4B_T2F_Quad quad; -/** returns the altas index of the AtlasSprite */ -@property (readonly) NSUInteger atlasIndex; -/** returns the rect of the AtlasSprite */ -@property (readonly) CGRect textureRect; -/** whether or not the sprite is flipped horizontally */ -@property (readwrite) BOOL flipX; -/** whether or not the sprite is flipped vertically */ -@property (readwrite) BOOL flipY; -/** opacity and RGB colors. conforms to CocosNodeRGBA protocol */ -@property (readonly) GLubyte opacity, r, g, b; - -/** creates an AtlasSprite with an AtlasSpriteManager inidicating the Rect of the Atlas */ -+(id)spriteWithRect:(CGRect)rect spriteManager:(AtlasSpriteManager*)manager; -/** initializes an AtlasSprite with an AtlasSpriteManager indicating the rect of the Atlas */ --(id)initWithRect:(CGRect)rect spriteManager:(AtlasSpriteManager*)manager; - --(void)insertInAtlasAtIndex:(NSUInteger)index; --(void)updatePosition; - -/** updates the texture rect of the AtlasSprite */ --(void) setTextureRect:(CGRect) rect; - -@end - -#pragma mark AtlasAnimation -/** an Animation object used within Sprites to perform animations */ -@interface AtlasAnimation : NSObject -{ - NSString *name; - float delay; - NSMutableArray *frames; -} - -@property (readwrite,assign) NSString *name; - -/** delay between frames in seconds */ -@property (readwrite,assign) float delay; -/** array of frames */ -@property (readonly) NSMutableArray *frames; - -/** creates an AtlasAnimation with an AtlasSpriteManager, a name, delay between frames */ -+(id) animationWithName:(NSString*)name delay:(float)delay; - -/** creates an AtlasAnimation with an AtlasSpriteManager, a name, delay between frames and the AtlasSpriteFrames */ -+(id) animationWithName:(NSString*)name delay:(float)delay frames:frame1,... NS_REQUIRES_NIL_TERMINATION; - -/** initializes an Animation with an AtlasSpriteManger, a name and delay between frames */ --(id) initWithName:(NSString*)name delay:(float)delay; - -/** initializes an AtlasAnimation with an AtlasSpriteManager, a name, and the AltasSpriteFrames */ --(id) initWithName:(NSString*)name delay:(float)delay firstFrame:(AtlasSpriteFrame*)frame vaList:(va_list) args; - -/** adds a frame to an Animation */ --(void) addFrameWithRect:(CGRect)rect; -@end - -#pragma mark AltasSpriteFrame -/** An AtlasSpriteFrame is an NSObject that encapsulates a CGRect. - * And a CGRect represents a frame within the AtlasSpriteManager - */ -@interface AtlasSpriteFrame : NSObject -{ - CGRect rect; -} -/** rect of the frame */ -@property (readwrite) CGRect rect; - -/** create an AtlasSpriteFrame with a CGRect */ -+(id) frameWithRect:(CGRect)frame; -/** initializes an AtlasSpriteFrame with a CGRect */ --(id) initWithRect:(CGRect)frame; -@end - diff --git a/Support/cocos2d/AtlasSprite.m b/Support/cocos2d/AtlasSprite.m deleted file mode 100644 index 2c440b4..0000000 --- a/Support/cocos2d/AtlasSprite.m +++ /dev/null @@ -1,508 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2009 Matt Oswald - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - -#import "AtlasSpriteManager.h" -#import "AtlasSprite.h" -#import "Support/CGPointExtension.h" - -#pragma mark - -#pragma mark AltasSprite - -enum { - kIndexNotInitialized = 0xffffffff, -}; - -@interface AtlasSprite (Private) --(void)updateTextureCoords; --(void) initAnimationDictionary; -@end - -@implementation AtlasSprite - -@synthesize dirty; -@synthesize quad = quad_; -@synthesize atlasIndex = atlasIndex_; -@synthesize textureRect = rect_; -@synthesize opacity=opacity_, r=r_, g=g_, b=b_; - -+(id)spriteWithRect:(CGRect)rect spriteManager:(AtlasSpriteManager*)manager -{ - return [[[self alloc] initWithRect:rect spriteManager:manager] autorelease]; -} - --(id)initWithRect:(CGRect)rect spriteManager:(AtlasSpriteManager*)manager -{ - if( (self = [super init])) { - textureAtlas_ = [manager textureAtlas]; // weak reference. Don't release - - atlasIndex_ = kIndexNotInitialized; - - dirty = YES; - - flipY_ = flipX_ = NO; - - // default transform anchor: center - anchorPoint_ = ccp(0.5f, 0.5f); - - // RGB and opacity - r_ = g_ = b_ = opacity_ = 255; - ccColor4B tmpColor = {255,255,255,255}; - quad_.bl.colors = tmpColor; - quad_.br.colors = tmpColor; - quad_.tl.colors = tmpColor; - quad_.tr.colors = tmpColor; - - animations = nil; // lazy alloc - - [self setTextureRect:rect]; - } - - return self; -} - -- (NSString*) description -{ - return [NSString stringWithFormat:@"<%@ = %08X | Rect = (%.2f,%.2f,%.2f,%.2f) | tag = %i>", [self class], self, rect_.origin.x, rect_.origin.y, rect_.size.width, rect_.size.height, tag]; -} - -- (void) dealloc -{ - [animations release]; - [super dealloc]; -} - --(void) initAnimationDictionary -{ - animations = [[NSMutableDictionary dictionaryWithCapacity:2] retain]; -} - --(void)setTextureRect:(CGRect) rect -{ - rect_ = rect; - - [self updateTextureCoords]; - - // Don't update Atlas if index == -1. issue #283 - if( atlasIndex_ == kIndexNotInitialized) - dirty = YES; - else - [textureAtlas_ updateQuad:&quad_ atIndex:atlasIndex_]; - - if( ! CGSizeEqualToSize(rect.size, contentSize_)) { - [self setContentSize:rect.size]; - dirty = YES; - } -} - --(void)updateTextureCoords -{ - float atlasWidth = textureAtlas_.texture.pixelsWide; - float atlasHeight = textureAtlas_.texture.pixelsHigh; - - float left = rect_.origin.x / atlasWidth; - float right = (rect_.origin.x + rect_.size.width) / atlasWidth; - float top = rect_.origin.y / atlasHeight; - float bottom = (rect_.origin.y + rect_.size.height) / atlasHeight; - - - if( flipX_) - CC_SWAP(left,right); - if( flipY_) - CC_SWAP(top,bottom); - - quad_.bl.texCoords.u = left; - quad_.bl.texCoords.v = bottom; - quad_.br.texCoords.u = right; - quad_.br.texCoords.v = bottom; - quad_.tl.texCoords.u = left; - quad_.tl.texCoords.v = top; - quad_.tr.texCoords.u = right; - quad_.tr.texCoords.v = top; - -} - --(void)updatePosition -{ - // algorithm from pyglet ( http://www.pyglet.org ) - - // if not visible - // then everything is 0 - if( ! visible ) { - quad_.br.vertices = quad_.tl.vertices = quad_.tr.vertices = quad_.bl.vertices = (ccVertex3F){0,0,0}; - - } - - // rotation ? -> update: rotation, scale, position - else if( rotation_ ) { - float x1 = -transformAnchor_.x * scaleX_; - float y1 = -transformAnchor_.y * scaleY_; - - float x2 = x1 + rect_.size.width * scaleX_; - float y2 = y1 + rect_.size.height * scaleY_; - float x = position_.x; - float y = position_.y; - - float r = -CC_DEGREES_TO_RADIANS(rotation_); - float cr = cosf(r); - float sr = sinf(r); - float ax = x1 * cr - y1 * sr + x; - float ay = x1 * sr + y1 * cr + y; - float bx = x2 * cr - y1 * sr + x; - float by = x2 * sr + y1 * cr + y; - float cx = x2 * cr - y2 * sr + x; - float cy = x2 * sr + y2 * cr + y; - float dx = x1 * cr - y2 * sr + x; - float dy = x1 * sr + y2 * cr + y; - quad_.bl.vertices = (ccVertex3F) { (int)ax, (int)ay, vertexZ_ }; - quad_.br.vertices = (ccVertex3F) { (int)bx, (int)by, vertexZ_ }; - quad_.tl.vertices = (ccVertex3F) { (int)dx, (int)dy, vertexZ_ }; - quad_.tr.vertices = (ccVertex3F) { (int)cx, (int)cy, vertexZ_ }; - - } - - // scale ? -> update: scale, position - else if(scaleX_ != 1 || scaleY_ != 1) - { - float x = position_.x; - float y = position_.y; - - float x1 = (x- transformAnchor_.x * scaleX_); - float y1 = (y- transformAnchor_.y * scaleY_); - float x2 = (x1 + rect_.size.width * scaleX_); - float y2 = (y1 + rect_.size.height * scaleY_); - - quad_.bl.vertices = (ccVertex3F) { (int)x1, (int)y1, vertexZ_ }; - quad_.br.vertices = (ccVertex3F) { (int)x2, (int)y1, vertexZ_ }; - quad_.tl.vertices = (ccVertex3F) { (int)x1, (int)y2, vertexZ_ }; - quad_.tr.vertices = (ccVertex3F) { (int)x2, (int)y2, vertexZ_ }; - } - - // update position - else { - float x = position_.x; - float y = position_.y; - - float x1 = (x-transformAnchor_.x); - float y1 = (y-transformAnchor_.y); - float x2 = (x1 + rect_.size.width); - float y2 = (y1 + rect_.size.height); - - quad_.bl.vertices = (ccVertex3F) { (int)x1, (int)y1, vertexZ_ }; - quad_.br.vertices = (ccVertex3F) { (int)x2, (int)y1, vertexZ_ }; - quad_.tl.vertices = (ccVertex3F) { (int)x1, (int)y2, vertexZ_ }; - quad_.tr.vertices = (ccVertex3F) { (int)x2, (int)y2, vertexZ_ }; - } - - [textureAtlas_ updateQuad:&quad_ atIndex:atlasIndex_]; - dirty = NO; - return; -} - --(void)insertInAtlasAtIndex:(NSUInteger)index -{ - atlasIndex_ = index; - [textureAtlas_ insertQuad:&quad_ atIndex:atlasIndex_]; -} - -// -// CocosNode property overloads -// -#pragma mark AltasSprite - property overloads --(void)setPosition:(CGPoint)pos -{ - [super setPosition:pos]; - dirty = YES; -} - --(void)setRotation:(float)rot -{ - [super setRotation:rot]; - dirty = YES; -} - --(void)setScaleX:(float) sx -{ - [super setScaleX:sx]; - dirty = YES; -} - --(void)setScaleY:(float) sy -{ - [super setScaleY:sy]; - dirty = YES; -} - --(void)setScale:(float) s -{ - [super setScale:s]; - dirty = YES; -} - --(void) setVertexZ:(float)z -{ - [super setVertexZ:z]; - dirty = YES; -} - --(void)setAnchorPoint:(CGPoint)anchor -{ - [super setAnchorPoint:anchor]; - dirty = YES; -} - --(void)setRelativeTransformAnchor:(BOOL)relative -{ - CCLOG(@"relativeTransformAnchor is ignored in AtlasSprite"); -} - --(void)setVisible:(BOOL)v -{ - [super setVisible:v]; - dirty = YES; -} - --(void)setFlipX:(BOOL)b -{ - if( flipX_ != b ) { - flipX_ = b; - [self setTextureRect:rect_]; - } -} --(BOOL) flipX -{ - return flipX_; -} - --(void) setFlipY:(BOOL)b -{ - if( flipY_ != b ) { - flipY_ = b; - [self setTextureRect:rect_]; - } -} --(BOOL) flipY -{ - return flipY_; -} - -// -// Composition overload -// --(id) addChild:(CocosNode*)child z:(int)z tag:(int) aTag -{ - NSAssert(NO, @"AtlasSprite can't have children"); - return nil; -} - -// -// RGBA protocol -// --(void) updateColor -{ - if( atlasIndex_ != kIndexNotInitialized) - [textureAtlas_ updateQuad:&quad_ atIndex:atlasIndex_]; - else - dirty = YES; -} --(void) setOpacity:(GLubyte) anOpacity -{ - opacity_ = anOpacity; - - // special opacity for premultiplied textures - if( [[textureAtlas_ texture] hasPremultipliedAlpha] ) - r_ = g_ = b_ = opacity_; - - ccColor4B color = (ccColor4B) {r_, g_, b_, opacity_ }; - - quad_.bl.colors = color; - quad_.br.colors = color; - quad_.tl.colors = color; - quad_.tr.colors = color; - - [self updateColor]; -} - --(void) setRGB: (GLubyte)r :(GLubyte)g :(GLubyte)b -{ - r_ = r; - g_ = g; - b_ = b; - ccColor4B color = {r_, g_, b_, opacity_ }; - quad_.bl.colors = color; - quad_.br.colors = color; - quad_.tl.colors = color; - quad_.tr.colors = color; - - [self updateColor]; -} - -// -// CocosNodeSize protocol -// --(CGSize)contentSize -{ - return rect_.size; -} - -// -// CocosNodeFrames protocol -// --(void) setDisplayFrame:(id)newFrame -{ - AtlasSpriteFrame *frame = (AtlasSpriteFrame*)newFrame; - CGRect rect = [frame rect]; - - [self setTextureRect: rect]; -} - --(void) setDisplayFrame: (NSString*) animationName index:(int) frameIndex -{ - if( ! animations ) - [self initAnimationDictionary]; - - AtlasAnimation *a = [animations objectForKey: animationName]; - AtlasSpriteFrame *frame = [[a frames] objectAtIndex:frameIndex]; - - NSAssert( frame, @"AtlasSprite#setDisplayFrame. Invalid frame"); - CGRect rect = [frame rect]; - - [self setTextureRect: rect]; - -} - --(BOOL) isFrameDisplayed:(id)frame -{ - AtlasSpriteFrame *spr = (AtlasSpriteFrame*)frame; - CGRect r = [spr rect]; - return CGRectEqualToRect(r, rect_); -} - --(id) displayFrame -{ - return [AtlasSpriteFrame frameWithRect:rect_]; -} -// XXX: duplicated code. Sprite.m and AtlasSprite.m share this same piece of code --(void) addAnimation: (id) anim -{ - // lazy alloc - if( ! animations ) - [self initAnimationDictionary]; - - [animations setObject:anim forKey:[anim name]]; -} -// XXX: duplicated code. Sprite.m and AtlasSprite.m share this same piece of code --(id)animationByName: (NSString*) animationName -{ - NSAssert( animationName != nil, @"animationName parameter must be non nil"); - return [animations objectForKey:animationName]; -} -@end - - -#pragma mark - -#pragma mark AltasAnimation - -@implementation AtlasAnimation -@synthesize name, delay, frames; - -+(id) animationWithName:(NSString*)aname delay:(float)d frames:rect1,... -{ - va_list args; - va_start(args,rect1); - - id s = [[[self alloc] initWithName:aname delay:d firstFrame:rect1 vaList:args] autorelease]; - - va_end(args); - return s; -} - -+(id) animationWithName:(NSString*)aname delay:(float)d -{ - return [[[self alloc] initWithName:aname delay:d] autorelease]; -} - --(id) initWithName:(NSString*)t delay:(float)d -{ - return [self initWithName:t delay:d firstFrame:nil vaList:nil]; -} - -/* initializes an AtlasAnimation with an AtlasSpriteManager, a name, and the frames from AtlasSpriteFrames */ --(id) initWithName:(NSString*)t delay:(float)d firstFrame:(AtlasSpriteFrame*)frame vaList:(va_list)args -{ - if( (self=[super init]) ) { - - name = t; - frames = [[NSMutableArray array] retain]; - delay = d; - - if( frame ) { - [frames addObject:frame]; - - AtlasSpriteFrame *frame2 = va_arg(args, AtlasSpriteFrame*); - while(frame2) { - [frames addObject:frame2]; - frame2 = va_arg(args, AtlasSpriteFrame*); - } - } - } - return self; -} - --(void) dealloc -{ - CCLOG( @"deallocing %@",self); - [frames release]; - [super dealloc]; -} - --(void) addFrameWithRect:(CGRect)rect -{ - AtlasSpriteFrame *frame = [AtlasSpriteFrame frameWithRect:rect]; - [frames addObject:frame]; -} -@end - -#pragma mark - -#pragma mark AtlasSpriteFrame -@implementation AtlasSpriteFrame -@synthesize rect; - -+(id) frameWithRect:(CGRect)frame -{ - return [[[self alloc] initWithRect:(CGRect)frame] autorelease]; -} --(id) initWithRect:(CGRect)frame -{ - if( ([super init]) ) { - rect = frame; - } - return self; -} - -- (NSString*) description -{ - return [NSString stringWithFormat:@"<%@ = %08X | Rect = (%.2f,%.2f,%.2f,%.2f)>", [self class], self, - rect.origin.x, - rect.origin.y, - rect.size.width, - rect.size.height]; -} - -- (void) dealloc -{ - CCLOG( @"deallocing %@",self); - [super dealloc]; -} -@end - diff --git a/Support/cocos2d/AtlasSpriteManager.h b/Support/cocos2d/AtlasSpriteManager.h deleted file mode 100644 index 6fe82b8..0000000 --- a/Support/cocos2d/AtlasSpriteManager.h +++ /dev/null @@ -1,70 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2009 Matt Oswald - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - -#import "CocosNode.h" -#import "TextureAtlas.h" -#import "ccMacros.h" - -#pragma mark AtlasSpriteManager - -@class AtlasSprite; - -/** AtlasSpriteManager is the object that draws all the AtlasSprite objects - * that belongs to this Manager. Use 1 AtlasSpriteManager per TextureAtlas -* - * Limitations: - * - The only object that is accepted as children are AtlasSprite - * - It's children are all Aliased or all Antialiased. They can't be some Aliased and some Antialiased - * - * @since v0.7.1 - */ -@interface AtlasSpriteManager : CocosNode -{ -@private - unsigned int totalSprites_; - TextureAtlas *textureAtlas_; -} - -/** returns the TextureAtlas that is used */ -@property (readwrite,retain) TextureAtlas * textureAtlas; - -/** creates an AtlasSpriteManager with a texture2d */ -+(id)spriteManagerWithTexture:(Texture2D *)tex; -/** creates an AtlasSpriteManager with a texture2d and capacity */ -+(id)spriteManagerWithTexture:(Texture2D *)tex capacity:(NSUInteger)capacity; -/** creates an AtlasSpriteManager with a file image (.png, .jpeg, .pvr, etc) */ -+(id)spriteManagerWithFile:(NSString*) fileImage; -/** creates an AtlasSpriteManager with a file image (.png, .jpeg, .pvr, etc) and capacity */ -+(id)spriteManagerWithFile:(NSString*)fileImage capacity:(NSUInteger)capacity; - -/** initializes an AtlasSpriteManager with a texture2d and capacity */ --(id)initWithTexture:(Texture2D *)tex capacity:(NSUInteger)capacity; -/** initializes an AtlasSpriteManager with a file image (.png, .jpeg, .pvr, etc) */ --(id)initWithFile:(NSString*)fileImage capacity:(NSUInteger)capacity; - --(NSUInteger)indexForNewChildAtZ:(int)z; - -/** creates an sprite with a rect in the AtlasSpriteManage */ --(AtlasSprite*) createSpriteWithRect:(CGRect)rect; - -/** removes a child given a certain index. It will also cleanup the running actions depending on the cleanup parameter. - @warning Removing a child from an AtlasSpriteManager is very slow - */ --(void)removeChildAtIndex:(NSUInteger)index cleanup:(BOOL)doCleanup; - -/** removes a child given a reference. It will also cleanup the running actions depending on the cleanup parameter. - @warning Removing a child from an AtlasSpriteManager is very slow - */ --(void)removeChild: (AtlasSprite *)sprite cleanup:(BOOL)doCleanup; -@end diff --git a/Support/cocos2d/AtlasSpriteManager.m b/Support/cocos2d/AtlasSpriteManager.m deleted file mode 100644 index 50d1c68..0000000 --- a/Support/cocos2d/AtlasSpriteManager.m +++ /dev/null @@ -1,315 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2009 Matt Oswald - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - -#import "AtlasSprite.h" -#import "AtlasSpriteManager.h" -#import "Grid.h" - -const int defaultCapacity = 29; - -#pragma mark AtlasSprite - -@interface AtlasSprite (Remove) --(void)setIndex:(int)index; -@end - -@implementation AtlasSprite (Remove) --(void)setIndex:(int)index -{ - atlasIndex_ = index; -} -@end - -@interface AtlasSpriteManager (private) --(void) resizeAtlas; -@end - -#pragma mark AtlasSpriteManager -@implementation AtlasSpriteManager - -@synthesize textureAtlas = textureAtlas_; - --(void)dealloc -{ - [textureAtlas_ release]; - - [super dealloc]; -} - -/* - * creation with Texture2D - */ -+(id)spriteManagerWithTexture:(Texture2D *)tex -{ - return [[[AtlasSpriteManager alloc] initWithTexture:tex capacity:defaultCapacity] autorelease]; -} - -+(id)spriteManagerWithTexture:(Texture2D *)tex capacity:(NSUInteger)capacity -{ - return [[[AtlasSpriteManager alloc] initWithTexture:tex capacity:capacity] autorelease]; -} - -/* - * creation with File Image - */ -+(id)spriteManagerWithFile:(NSString*)fileImage capacity:(NSUInteger)capacity -{ - return [[[AtlasSpriteManager alloc] initWithFile:fileImage capacity:capacity] autorelease]; -} - -+(id)spriteManagerWithFile:(NSString*) imageFile -{ - return [[[AtlasSpriteManager alloc] initWithFile:imageFile capacity:defaultCapacity] autorelease]; -} - - -/* - * init with Texture2D - */ --(id)initWithTexture:(Texture2D *)tex capacity:(NSUInteger)capacity -{ - if( (self=[super init])) { - totalSprites_ = 0; - textureAtlas_ = [[TextureAtlas alloc] initWithTexture:tex capacity:capacity]; - - // no lazy alloc in this node - children = [[NSMutableArray alloc] initWithCapacity:capacity]; - } - - return self; -} - -/* - * init with FileImage - */ --(id)initWithFile:(NSString *)fileImage capacity:(NSUInteger)capacity -{ - if( (self=[super init]) ) { - totalSprites_ = 0; - textureAtlas_ = [[TextureAtlas alloc] initWithFile:fileImage capacity:capacity]; - - // no lazy alloc in this node - children = [[NSMutableArray alloc] initWithCapacity:capacity]; - } - - return self; -} - - -#pragma mark AtlasSpriteManager - composition - -// override visit. -// Don't call visit on it's children --(void) visit -{ - - // CAREFUL: - // This visit is almost identical to CocosNode#visit - // with the exception that it doesn't call visit on it's children - // - // The alternative is to have a void AtlasSprite#visit, but this - // although is less mantainable, is faster - // - if (!visible) - return; - - glPushMatrix(); - - if ( grid && grid.active) - [grid beforeDraw]; - - [self transform]; - - [self draw]; - - if ( grid && grid.active) - [grid afterDraw:self.camera]; - - glPopMatrix(); -} - --(NSUInteger)indexForNewChildAtZ:(int)z -{ - NSUInteger index = 0; - - for( AtlasSprite *sprite in children) { - if ( sprite.zOrder > z ) { - break; - } - index++; - } - - return index; -} - --(AtlasSprite*) createSpriteWithRect:(CGRect)rect -{ - return [AtlasSprite spriteWithRect:rect spriteManager:self]; -} - -// override addChild: --(id) addChild:(AtlasSprite*)child z:(int)z tag:(int) aTag -{ - NSAssert( child != nil, @"Argument must be non-nil"); - NSAssert( [child isKindOfClass:[AtlasSprite class]], @"AtlasSpriteManager only supports AtlasSprites as children"); - - if(totalSprites_ == textureAtlas_.capacity) - [self resizeAtlas]; - - NSUInteger index = [self indexForNewChildAtZ:z]; - [child insertInAtlasAtIndex: index]; - - totalSprites_++; - [super addChild:child z:z tag:aTag]; - - NSUInteger count = [children count]; - index++; - for(; index < count; index++) { - AtlasSprite *sprite = (AtlasSprite *)[children objectAtIndex:index]; - NSAssert([sprite atlasIndex] == index - 1, @"AtlasSpriteManager: index failed"); - [sprite setIndex:index]; - } - - return self; -} - -// override removeChild: --(void)removeChild: (AtlasSprite *)sprite cleanup:(BOOL)doCleanup -{ - // explicit nil handling - if (sprite == nil) - return; - // ignore non-children - if( ![children containsObject:sprite] ) - return; - - NSUInteger index= sprite.atlasIndex; - [super removeChild:sprite cleanup:doCleanup]; - - [textureAtlas_ removeQuadAtIndex:index]; - - // update all sprites beyond this one - NSUInteger count = [children count]; - for(; index < count; index++) - { - AtlasSprite *other = (AtlasSprite *)[children objectAtIndex:index]; - NSAssert([other atlasIndex] == index + 1, @"AtlasSpriteManager: index failed"); - [other setIndex:index]; - } - totalSprites_--; -} - -// override reorderChild --(void) reorderChild:(AtlasSprite*)child z:(int)z -{ - // reorder child in the children array - [super reorderChild:child z:z]; - - - // What's the new atlas index ? - NSUInteger newAtlasIndex = 0; - for( AtlasSprite *sprite in children) { - if( [sprite isEqual:child] ) - break; - newAtlasIndex++; - } - - if( newAtlasIndex != child.atlasIndex ) { - - [textureAtlas_ insertQuadFromIndex:child.atlasIndex atIndex:newAtlasIndex]; - - // update atlas index - NSUInteger count = MAX( newAtlasIndex, child.atlasIndex); - NSUInteger index = MIN( newAtlasIndex, child.atlasIndex); - for( ; index < count+1 ; index++ ) { - AtlasSprite *sprite = (AtlasSprite *)[children objectAtIndex:index]; - [sprite setIndex: index]; - } - } -} - --(void)removeChildAtIndex:(NSUInteger)index cleanup:(BOOL)doCleanup -{ - [self removeChild:(AtlasSprite *)[children objectAtIndex:index] cleanup:doCleanup]; -} - --(void)removeAllChildrenWithCleanup:(BOOL)doCleanup -{ - [super removeAllChildrenWithCleanup:doCleanup]; - - totalSprites_ = 0; - [textureAtlas_ removeAllQuads]; -} - -#pragma mark AtlasSpriteManager - draw --(void)draw -{ - for( AtlasSprite *child in children ) - { - if( child.dirty ) - [child updatePosition]; - } - - if(totalSprites_ > 0) - { - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_COLOR_ARRAY); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glEnable(GL_TEXTURE_2D); - - BOOL preMulti = [[textureAtlas_ texture] hasPremultipliedAlpha]; - if( !preMulti ) - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - - [textureAtlas_ drawNumberOfQuads:totalSprites_]; - - if( !preMulti ) - glBlendFunc(CC_BLEND_SRC, CC_BLEND_DST); - - glDisable(GL_TEXTURE_2D); - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - glDisableClientState(GL_COLOR_ARRAY); - glDisableClientState(GL_VERTEX_ARRAY); - } -} - -#pragma mark AtlasSpriteManager - private --(void) resizeAtlas -{ - // if we're going beyond the current TextureAtlas's capacity, - // all the previously initialized sprites will need to redo their texture coords - // this is likely computationally expensive - NSUInteger quantity = (textureAtlas_.totalQuads + 1) * 4 / 3; - - CCLOG(@"Resizing TextureAtlas capacity, from [%d] to [%d].", textureAtlas_.totalQuads, quantity); - - - if( ! [textureAtlas_ resizeCapacity:quantity] ) { - // serious problems - CCLOG(@"WARNING: Not enough memory to resize the atlas"); - NSAssert(NO,@"XXX: AltasSpriteManager#resizeAtlas SHALL handle this assert"); - } -} - -#pragma mark AtlasSpriteManager - CocosNodeTexture protocol --(void) setTexture:(Texture2D*)texture -{ - textureAtlas_.texture = texture; -} - --(Texture2D*) texture -{ - return textureAtlas_.texture; -} -@end diff --git a/Support/cocos2d/BitmapFontAtlas.h b/Support/cocos2d/BitmapFontAtlas.h deleted file mode 100644 index 2996da0..0000000 --- a/Support/cocos2d/BitmapFontAtlas.h +++ /dev/null @@ -1,93 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2008,2009 Ricardo Quesada - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - * Portions of this code are based and inspired on: - * http://www.71squared.co.uk/2009/04/iphone-game-programming-tutorial-4-bitmap-font-class - * by Michael Daley - * - */ - -#import "AtlasNode.h" -#import "AtlasSpriteManager.h" - -/** bitmap font definition */ -typedef struct _bitmapFontDef { - //! ID of the character - unsigned char charID; - //! origin and size of the font - CGRect rect; - //! The X amount the image should be offset when drawing the image (in pixels) - int xOffset; - //! The Y amount the image should be offset when drawing the image (in pixels) - int yOffset; - //! The amount to move the current position after drawing the character (in pixels) - int xAdvance; -} ccBitmapFontDef; - -/** BitmapFontAtlas is a subclass of AtlasSpriteManger. - - Features: - - Treats each character like an AtlasSprite. This means that each individual character can be: - - rotated - - scaled - - translated - - tinted - - chage the opacity - - It can be used as part of a menu item. - - anchorPoint can be used to align the "label" - - Supports Hiero format (http://slick.cokeandcode.com/demos/hiero.jnlp) - - Limitations: - - All inner characters are using an anchorPoint of (0.5f, 0.5f) and it is not recommend to change it - because it might affect the rendering - - BitmapFontAtlas implements the protocol CocosNodeLabel, like Label and LabelAtlas. - BitmapFontAtlas has the flexibility of Label, the speed of LabelAtlas and all the features of AtlasSprite. - If in doubt, use BitmapFontAtlas instead of LabelAtlas / Label. - - @since v0.8 - */ - -enum { - kBitmapFontAtlasMaxChars = 256, -}; - -@interface BitmapFontAtlas : AtlasSpriteManager -{ - // string to render - NSString *string_; - - // values for kerning - NSMutableDictionary *kerningDictionary; - - // FNTConfig: Common Height - NSUInteger commonHeight; - - // The characters building up the font - ccBitmapFontDef bitmapFontArray[kBitmapFontAtlasMaxChars]; - - // texture color - GLubyte r_,g_,b_, opacity_; -} - -/** conforms to CocosNodeRGBA protocol */ -@property (readonly) GLubyte r, g, b, opacity; - -/** creates a bitmap font altas with an initial string and the FNT file */ -+(id) bitmapFontAtlasWithString:(NSString*)string fntFile:(NSString*)fntFile; - -/** init a bitmap font altas with an initial string and the FNT file */ --(id) initWithString:(NSString*)string fntFile:(NSString*)fntFile; - -/** updates the font chars based on the string to render */ --(void) createFontChars; -@end diff --git a/Support/cocos2d/BitmapFontAtlas.m b/Support/cocos2d/BitmapFontAtlas.m deleted file mode 100644 index 245dd5f..0000000 --- a/Support/cocos2d/BitmapFontAtlas.m +++ /dev/null @@ -1,379 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2009 Ricardo Quesada - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - * Portions of this code are based and inspired on: - * http://www.71squared.co.uk/2009/04/iphone-game-programming-tutorial-4-bitmap-font-class - * by Michael Daley - * - * - * Use this editor to generate bitmap font atlas: - * http://slick.cokeandcode.com/demos/hiero.jnlp - */ - -#import "BitmapFontAtlas.h" -#import "AtlasSprite.h" -#import "Support/FileUtils.h" -#import "Support/CGPointExtension.h" - -@interface BitmapFontAtlas (Private) --(NSString*) atlasNameFromFntFile:(NSString*)fntFile; - --(int) kerningAmmountForFirst:(unichar)first second:(unichar)second; - --(void) parseConfigFile:(NSString*)controlFile; --(void) parseCharacterDefinition:(NSString*)line charDef:(ccBitmapFontDef*)characterDefinition; --(void) parseCommonArguments:(NSString*)line; --(void) parseKerningCapacity:(NSString*)line; --(void) parseKerningEntry:(NSString*)line; -@end - -@implementation BitmapFontAtlas - -@synthesize opacity=opacity_,r=r_,g=g_,b=b_; - -#pragma mark BitmapFontAtlas - Creation & Init -+(id) bitmapFontAtlasWithString:(NSString*)string fntFile:(NSString*)fntFile -{ - return [[[self alloc] initWithString:string fntFile:fntFile] autorelease]; -} - - --(id) initWithString:(NSString*)theString fntFile:(NSString*)fntFile -{ - NSString *textureAtlasName = [self atlasNameFromFntFile:fntFile]; - - if ((self=[super initWithFile:textureAtlasName capacity:[theString length]])) { - - // will be allocated later - kerningDictionary = nil; - - r_ = g_ = b_ = opacity_ = 255; - contentSize_ = CGSizeZero; - - anchorPoint_ = ccp(0.5f, 0.5f); - - [self parseConfigFile:fntFile]; - [self setString:theString]; - } - - return self; -} - --(void) dealloc -{ - [string_ release]; - [kerningDictionary release]; - [super dealloc]; -} - -// -// obtain the texture atlas image -// --(NSString*) atlasNameFromFntFile:(NSString*)fntFile -{ - NSString *fullpath = [FileUtils fullPathFromRelativePath:fntFile]; - NSString *contents = [NSString stringWithContentsOfFile:fullpath]; - NSArray *lines = [[NSArray alloc] initWithArray:[contents componentsSeparatedByString:@"\n"]]; - NSEnumerator *nse = [lines objectEnumerator]; - NSString *line; - NSString *propertyValue; // ret value - - // Loop through all the lines in the lines array processing each one - while( (line = [nse nextObject]) ) { - // Check to see if the start of the line is something we are interested in - if([line hasPrefix:@"page id="]) { - - // Break the values for this line up using = - NSArray *values = [line componentsSeparatedByString:@"="]; - - // Get the enumerator for the array of components which has been created - NSEnumerator *nse = [values objectEnumerator]; - - // We need to move past the first entry in the array before we start assigning values - [nse nextObject]; - - // page ID. Sanity check - propertyValue = [nse nextObject]; - NSAssert( [propertyValue intValue] == 0, @"XXX: BitmapFontAtlas only supports 1 page"); - - // file - propertyValue = [nse nextObject]; - NSArray *array = [propertyValue componentsSeparatedByString:@"\""]; - propertyValue = [array objectAtIndex:1]; - break; - } - } - // Finished with lines so release it - [lines release]; - - return propertyValue; -} - -#pragma mark BitmapFontAtlas - FNT parser -- (void)parseConfigFile:(NSString*)fntFile -{ - NSString *fullpath = [FileUtils fullPathFromRelativePath:fntFile]; - NSString *contents = [NSString stringWithContentsOfFile:fullpath]; - - // Move all lines in the string, which are denoted by \n, into an array - NSArray *lines = [[NSArray alloc] initWithArray:[contents componentsSeparatedByString:@"\n"]]; - - // Create an enumerator which we can use to move through the lines read from the control file - NSEnumerator *nse = [lines objectEnumerator]; - - // Create a holder for each line we are going to work with - NSString *line; - - // Loop through all the lines in the lines array processing each one - while( (line = [nse nextObject]) ) { - // Check to see if the start of the line is something we are interested in - if([line hasPrefix:@"common lineHeight"]) { - [self parseCommonArguments:line]; - } - if([line hasPrefix:@"chars c"]) { - // Ignore this line - } else if([line hasPrefix:@"char"]) { - // Parse the current line and create a new CharDef - ccBitmapFontDef characterDefinition; - [self parseCharacterDefinition:line charDef:&characterDefinition]; - - // Add the CharDef returned to the charArray - bitmapFontArray[ characterDefinition.charID ] = characterDefinition; - } else if([line hasPrefix:@"kernings count"]) { - [self parseKerningCapacity:line]; - } else if([line hasPrefix:@"kerning first"]) { - [self parseKerningEntry:line]; - } - } - // Finished with lines so release it - [lines release]; -} - --(void) parseCommonArguments:(NSString*)line -{ - // - // line to parse: - // common lineHeight=104 base=26 scaleW=1024 scaleH=512 pages=1 packed=0 - // - NSArray *values = [line componentsSeparatedByString:@"="]; - NSEnumerator *nse = [values objectEnumerator]; - NSString *propertyValue; - - // We need to move past the first entry in the array before we start assigning values - [nse nextObject]; - - // Character ID - propertyValue = [nse nextObject]; - commonHeight = [propertyValue intValue]; - - // base (ignore) - propertyValue = [nse nextObject]; - - // scaleW. sanity check - propertyValue = [nse nextObject]; - NSAssert( [propertyValue intValue] <= 1024, @"BitmapFontAtlas: page can't be larger than 1024x1024"); - - // scaleH. sanity check - propertyValue = [nse nextObject]; - NSAssert( [propertyValue intValue] <= 1024, @"BitmapFontAtlas: page can't be larger than 1024x1024"); - - // pages - propertyValue = [nse nextObject]; - NSAssert( [propertyValue intValue] == 1, @"BitfontAtlas: only supports 1 page"); - - // packed (ignore) What does this mean ?? -} -- (void)parseCharacterDefinition:(NSString*)line charDef:(ccBitmapFontDef*)characterDefinition -{ - // Break the values for this line up using = - NSArray *values = [line componentsSeparatedByString:@"="]; - NSEnumerator *nse = [values objectEnumerator]; - NSString *propertyValue; - - // We need to move past the first entry in the array before we start assigning values - [nse nextObject]; - - // Character ID - propertyValue = [nse nextObject]; - characterDefinition->charID = [propertyValue intValue]; - // Character x - propertyValue = [nse nextObject]; - characterDefinition->rect.origin.x = [propertyValue intValue]; - // Character y - propertyValue = [nse nextObject]; - characterDefinition->rect.origin.y = [propertyValue intValue]; - // Character width - propertyValue = [nse nextObject]; - characterDefinition->rect.size.width = [propertyValue intValue]; - // Character height - propertyValue = [nse nextObject]; - characterDefinition->rect.size.height = [propertyValue intValue]; - // Character xoffset - propertyValue = [nse nextObject]; - characterDefinition->xOffset = [propertyValue intValue]; - // Character yoffset - propertyValue = [nse nextObject]; - characterDefinition->yOffset = [propertyValue intValue]; - // Character xadvance - propertyValue = [nse nextObject]; - characterDefinition->xAdvance = [propertyValue intValue]; -} - --(void) parseKerningCapacity:(NSString*) line -{ - NSAssert(!kerningDictionary, @"dictionary already initialized"); - - // Break the values for this line up using = - NSArray *values = [line componentsSeparatedByString:@"="]; - NSEnumerator *nse = [values objectEnumerator]; - NSString *propertyValue; - - // We need to move past the first entry in the array before we start assigning values - [nse nextObject]; - - // count - propertyValue = [nse nextObject]; - int capacity = [propertyValue intValue]; - - if( capacity != -1 ) - kerningDictionary = [[NSMutableDictionary dictionaryWithCapacity: [propertyValue intValue]] retain]; -} - --(void) parseKerningEntry:(NSString*) line -{ - NSArray *values = [line componentsSeparatedByString:@"="]; - NSEnumerator *nse = [values objectEnumerator]; - NSString *propertyValue; - - // We need to move past the first entry in the array before we start assigning values - [nse nextObject]; - - // first - propertyValue = [nse nextObject]; - int first = [propertyValue intValue]; - - // second - propertyValue = [nse nextObject]; - int second = [propertyValue intValue]; - - // second - propertyValue = [nse nextObject]; - int ammount = [propertyValue intValue]; - - NSString *key = [NSString stringWithFormat:@"%d,%d", first, second]; - NSNumber *value = [NSNumber numberWithInt:ammount]; - - [kerningDictionary setObject:value forKey:key]; -} - -#pragma mark BitmapFontAtlas - Atlas generation - --(int) kerningAmmountForFirst:(unichar)first second:(unichar)second -{ - int ret = 0; - NSString *key = [NSString stringWithFormat:@"%d,%d", first, second]; - NSNumber *value = [kerningDictionary objectForKey:key]; - if(value) - ret = [value intValue]; - - return ret; -} - --(void) createFontChars -{ - int nextFontPositionX = 0; - unichar prev = -1; - int kerningAmmount = 0; - - CGSize tmpSize = CGSizeZero; - - NSUInteger l = [string_ length]; - for(NSUInteger i=0; i - -#import "CocosNode.h" - -/** - A Camera is used in every CocosNode. - Useful to look at the object from different views. - The OpenGL gluLookAt() function is used to locate the - camera. - - If the object is transformed by any of the scale, rotation or - position attributes, then they will override the camera. -*/ - -@interface Camera : NSObject { - float eyeX; - float eyeY; - float eyeZ; - - float centerX; - float centerY; - float centerZ; - - float upX; - float upY; - float upZ; - - BOOL dirty; -} - -@property BOOL dirty; - -/** returns the Z eye */ -+(float) getZEye; - -/** sets the camera in the defaul position */ --(void) restore; -/** Sets the camera using gluLookAt using its eye, center and up_vector */ --(void) locate; -/** sets the eye values */ --(void) setEyeX: (float)x eyeY:(float)y eyeZ:(float)z; -/** sets the center values */ --(void) setCenterX: (float)x centerY:(float)y centerZ:(float)z; -/** sets the up values */ --(void) setUpX: (float)x upY:(float)y upZ:(float)z; - -/** get the eye vector values */ --(void) eyeX:(float*)x eyeY:(float*)y eyeZ:(float*)z; -/** get the center vector values */ --(void) centerX:(float*)x centerY:(float*)y centerZ:(float*)z; -/** get the up vector values */ --(void) upX:(float*)x upY:(float*)y upZ:(float*)z; - - -@end diff --git a/Support/cocos2d/Camera.m b/Support/cocos2d/Camera.m deleted file mode 100644 index 0133b6e..0000000 --- a/Support/cocos2d/Camera.m +++ /dev/null @@ -1,158 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2008,2009 Ricardo Quesada - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - - -#import "Director.h" -#import "Camera.h" -#import "ccMacros.h" - -#import "Support/glu.h" - -@implementation Camera - -@synthesize dirty; - --(id) init -{ - if( !(self=[super init]) ) - return nil; - - [self restore]; - return self; -} - -- (NSString*) description -{ - return [NSString stringWithFormat:@"<%@ = %08X | center = (%.2f,%.2f,%.2f)>", [self class], self, centerX, centerY, centerZ]; -} - - -- (void) dealloc -{ - CCLOG(@"deallocing %@", self); - [super dealloc]; -} - --(void) restore -{ - CGSize s = [[Director sharedDirector] displaySize]; - - eyeX = s.width/2; - eyeY = s.height/2; - eyeZ = [Camera getZEye]; - - centerX = s.width/2; - centerY = s.height/2; - centerZ = 0.0f; - - upX = 0.0f; - upY = 1.0f; - upZ = 0.0f; - - dirty = NO; -} - --(void) locate -{ - if( dirty ) { - ccDeviceOrientation orientation = [[Director sharedDirector] deviceOrientation]; - - glLoadIdentity(); - - switch( orientation ) { - case CCDeviceOrientationPortrait: - break; - case CCDeviceOrientationPortraitUpsideDown: - glRotatef(-180,0,0,1); - break; - case CCDeviceOrientationLandscapeLeft: - glRotatef(-90,0,0,1); - break; - case CCDeviceOrientationLandscapeRight: - glRotatef(90,0,0,1); - break; - } - - gluLookAt( eyeX, eyeY, eyeZ, - centerX, centerY, centerZ, - upX, upY, upZ - ); - - switch( orientation ) { - case CCDeviceOrientationPortrait: - case CCDeviceOrientationPortraitUpsideDown: - // none - break; - case CCDeviceOrientationLandscapeLeft: - glTranslatef(-80,80,0); - break; - case CCDeviceOrientationLandscapeRight: - glTranslatef(-80,80,0); - break; - } - } -} - -+(float) getZEye -{ - CGSize s = [[Director sharedDirector] displaySize]; - return ( s.height / 1.1566f ); -} - --(void) setEyeX: (float)x eyeY:(float)y eyeZ:(float)z -{ - eyeX = x; - eyeY = y; - eyeZ = z; - dirty = YES; -} - --(void) setCenterX: (float)x centerY:(float)y centerZ:(float)z -{ - centerX = x; - centerY = y; - centerZ = z; - dirty = YES; -} - --(void) setUpX: (float)x upY:(float)y upZ:(float)z -{ - upX = x; - upY = y; - upZ = z; - dirty = YES; -} - --(void) eyeX: (float*)x eyeY:(float*)y eyeZ:(float*)z -{ - *x = eyeX; - *y = eyeY; - *z = eyeZ; -} - --(void) centerX: (float*)x centerY:(float*)y centerZ:(float*)z -{ - *x = centerX; - *y = centerY; - *z = centerZ; -} - --(void) upX: (float*)x upY:(float*)y upZ:(float*)z -{ - *x = upX; - *y = upY; - *z = upZ; -} - -@end diff --git a/Support/cocos2d/CameraAction.h b/Support/cocos2d/CameraAction.h deleted file mode 100644 index 7e22b6d..0000000 --- a/Support/cocos2d/CameraAction.h +++ /dev/null @@ -1,57 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2008,2009 Ricardo Quesada - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - -#import "IntervalAction.h" - -/** Base class for Camera actions - */ -@interface CameraAction : IntervalAction { - float centerXOrig; - float centerYOrig; - float centerZOrig; - - float eyeXOrig; - float eyeYOrig; - float eyeZOrig; - - float upXOrig; - float upYOrig; - float upZOrig; -} -@end - -/** Orbit Camera action - Orbits the camera around the center of the screen using spherical coordinates - */ -@interface OrbitCamera : CameraAction { - float radius; - float deltaRadius; - float angleZ; - float deltaAngleZ; - float angleX; - float deltaAngleX; - - float radZ; - float radDeltaZ; - float radX; - float radDeltaX; - -} -/** creates an OrbitCamera action with radius, delta-radius, z, deltaZ, x, deltaX */ -+(id) actionWithDuration:(float) t radius:(float)r deltaRadius:(float) dr angleZ:(float)z deltaAngleZ:(float)dz angleX:(float)x deltaAngleX:(float)dx; -/** initializes an OrbitCamera action with radius, delta-radius, z, deltaZ, x, deltaX */ --(id) initWithDuration:(float) t radius:(float)r deltaRadius:(float) dr angleZ:(float)z deltaAngleZ:(float)dz angleX:(float)x deltaAngleX:(float)dx; -/** positions the camera according to spherical coordinates */ --(void) sphericalRadius:(float*) r zenith:(float*) zenith azimuth:(float*) azimuth; -@end diff --git a/Support/cocos2d/CameraAction.m b/Support/cocos2d/CameraAction.m deleted file mode 100644 index 555a6fc..0000000 --- a/Support/cocos2d/CameraAction.m +++ /dev/null @@ -1,127 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2008,2009 Ricardo Quesada - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - - -#import "CameraAction.h" -#import "CocosNode.h" -#import "Camera.h" -#import "ccMacros.h" - -// -// CameraAction -// -@implementation CameraAction --(void) start -{ - [super start]; - [[target camera] centerX:¢erXOrig centerY:¢erYOrig centerZ: ¢erZOrig]; - [[target camera] eyeX:&eyeXOrig eyeY:&eyeYOrig eyeZ: &eyeZOrig]; - [[target camera] upX:&upXOrig upY:&upYOrig upZ: &upZOrig]; -} - --(id) reverse -{ - return [ReverseTime actionWithAction:self]; -} -@end - -@implementation OrbitCamera -+(id) actionWithDuration:(float)t radius:(float)r deltaRadius:(float) dr angleZ:(float)z deltaAngleZ:(float)dz angleX:(float)x deltaAngleX:(float)dx -{ - return [[[self alloc] initWithDuration:t radius:r deltaRadius:dr angleZ:z deltaAngleZ:dz angleX:x deltaAngleX:dx] autorelease]; -} - --(id) copyWithZone: (NSZone*) zone -{ - return [[[self class] allocWithZone: zone] initWithDuration:duration radius:radius deltaRadius:deltaRadius angleZ:angleZ deltaAngleZ:deltaAngleZ angleX:angleX deltaAngleX:deltaAngleX]; -} - - --(id) initWithDuration:(float)t radius:(float)r deltaRadius:(float) dr angleZ:(float)z deltaAngleZ:(float)dz angleX:(float)x deltaAngleX:(float)dx -{ - if(!(self=[super initWithDuration:t]) ) - return nil; - - radius = r; - deltaRadius = dr; - angleZ = z; - deltaAngleZ = dz; - angleX = x; - deltaAngleX = dx; - - radDeltaZ = (CGFloat)CC_DEGREES_TO_RADIANS(dz); - radDeltaX = (CGFloat)CC_DEGREES_TO_RADIANS(dx); - - return self; -} - --(void) start -{ - [super start]; - float r, zenith, azimuth; - - [self sphericalRadius: &r zenith:&zenith azimuth:&azimuth]; - if( isnan(radius) ) - radius = r; - if( isnan(angleZ) ) - angleZ = (CGFloat)CC_RADIANS_TO_DEGREES(zenith); - if( isnan(angleX) ) - angleX = (CGFloat)CC_RADIANS_TO_DEGREES(azimuth); - - radZ = (CGFloat)CC_DEGREES_TO_RADIANS(angleZ); - radX = (CGFloat)CC_DEGREES_TO_RADIANS(angleX); -} - --(void) update: (ccTime) t -{ - float r = (radius + deltaRadius * t) *[Camera getZEye]; - float za = radZ + radDeltaZ * t; - float xa = radX + radDeltaX * t; - - float i = sinf(za) * cosf(xa) * r + centerXOrig; - float j = sinf(za) * sinf(xa) * r + centerYOrig; - float k = cosf(za) * r + centerZOrig; - - [[target camera] setEyeX:i eyeY:j eyeZ:k]; -} - --(void) sphericalRadius:(float*) newRadius zenith:(float*) zenith azimuth:(float*) azimuth -{ - float ex, ey, ez, cx, cy, cz, x, y, z; - float r; // radius - float s; - - [[target camera] eyeX:&ex eyeY:&ey eyeZ:&ez]; - [[target camera] centerX:&cx centerY:&cy centerZ:&cz]; - - x = ex-cx; - y = ey-cy; - z = ez-cz; - - r = sqrtf( powf(x,2) + powf(y,2) + powf(z,2)); - s = sqrtf( powf(x,2) + powf(y,2)); - if(s==0.0f) - s=0.00000001f; - if(r==0.0f) - r=0.00000001f; - - *zenith = acosf( z/r); - if( x < 0 ) - *azimuth= (CGFloat)M_PI - asinf(y/s); - else - *azimuth = asinf(y/s); - - *newRadius = r / [Camera getZEye]; -} -@end diff --git a/Support/cocos2d/CocosNode.h b/Support/cocos2d/CocosNode.h deleted file mode 100644 index 472aed9..0000000 --- a/Support/cocos2d/CocosNode.h +++ /dev/null @@ -1,436 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2008,2009 Ricardo Quesada - * Copyright (C) 2009 Valentin Milea - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - -#import - -#import "Action.h" -#import "cctypes.h" -#import "Support/Texture2D.h" - -enum { - kCocosNodeTagInvalid = -1, -}; - -@class Camera; -@class GridBase; - -/** CocosNode is the main element. Anything thats gets drawn or contains things that get drawn is a CocosNode. - The most popular CocosNodes are: Scene, Layer, Sprite, Menu. - - The main features of a CocosNode are: - - They can contain other cocos nodes (addChild, getChildByTag, removeChild, etc) - - They can schedule periodic callback (schedule, unschedule, etc) - - They can execute actions (runAction, stopAction, etc) - - Some CocosNodes provide extra functionality for them or their children. - - Subclassing a CocosNode usually means (one/all) of: - - overriding init to initialize resources and schedule callbacks - - create callbacks to handle the advancement of time - - overriding draw to render the node - - Features of CocosNode: - - position - - scale (x, y) - - rotation (in degrees) - - Camera ( using spherical coordinates ) - - GridBase (to do mesh transformations) - - anchor point - - size - - visible - - z-order - - openGL z position - - Limitations: - - A CocosNode is a "void" object. It doesn't have a texture - - Since it has no texture, is has no size - - It can't receive touches - - It can't receive accelerometer values - */ -@interface CocosNode : NSObject { - - // rotation angle - float rotation_; - - // scaling factors - float scaleX_, scaleY_; - - // position of the node - CGPoint position_; - - // If YES the transformtions will be relative to (-transform.x, -transform.y). - // Sprites, Labels and any other "small" object uses it. - // Scenes, Layers and other "whole screen" object don't use it. - BOOL relativeTransformAnchor_; - - // transformation anchor point - CGPoint transformAnchor_; - - // anchor point - CGPoint anchorPoint_; - // untransformed size of the node - CGSize contentSize_; - - CGAffineTransform transform_, inverse_; - BOOL isTransformDirty_, isInverseDirty_; - - // openGL real Z vertex - float vertexZ_; - - // is visible - BOOL visible; - - // a Camera - Camera *camera; - - // a Grid - GridBase *grid; - - // z-order value - int zOrder; - - // array of children - NSMutableArray *children; - - // is running - BOOL isRunning; - - // weakref to parent - CocosNode *parent; - - // a tag. any number you want to assign to the node - int tag; - - // actions - struct ccArray *actions; - int actionIndex; - Action *currentAction; - BOOL currentActionSalvaged; - - // scheduled selectors - NSMutableDictionary *scheduledSelectors; -} - -/** The z order of the node relative to it's "brothers": children of the same parent */ -@property(readonly) int zOrder; -/** The real openGL Z vertex. - Differences between openGL Z vertex and cocos2d Z order: - - OpenGL Z modifies the Z vertex, and not the Z order in the relation between parent-children - - OpenGL Z might require to set 2D projection - - cocos2d Z order works OK if all the nodes uses the same openGL Z vertex. eg: vertexZ = 0 - @warning: Use it at your own risk since it might break the cocos2d parent-children z order - @since v0.8 - */ -@property (readwrite) float vertexZ; -/** The rotation (angle) of the node in degrees. 0 is the default rotation angle */ -@property(readwrite,assign) float rotation; -/** The scale factor of the node. 1.0 is the default scale factor */ -@property(readwrite,assign) float scale, scaleX, scaleY; -/** Position (x,y) of the node in OpenGL coordinates. (0,0) is the left-bottom corner */ -@property(readwrite,assign) CGPoint position; -/** A Camera object that lets you move the node using camera coordinates. - * If you use the Camera then position, scale & rotation won't be used */ -@property(readonly) Camera* camera; -/** A Grid object that is used when applying Effects */ -@property(readwrite,retain) GridBase* grid; -/** Whether of not the node is visible. Default is YES */ -@property(readwrite,assign) BOOL visible; -/** The transformation anchor point in absolute pixels. - since v0.8 you can only read it. If you wish to modify it, use anchorPoint instead - */ -@property(readonly) CGPoint transformAnchor; -/** Anchor point. (0,0) means bottom-left corner, (1,1) means top-right corner, (0.5, 0.5) means center - Sprites and other "textured" Nodes have a default anchorPoint of (0.5f, 0.5f) - @since v0.8 - */ -@property(readwrite) CGPoint anchorPoint; -/** The untransformed size of the node. - The contentSize remains the same no matter the node is scaled or rotated. - All nodes has a size. Layer and Scene has the same size of the screen. - @since v0.8 - */ -@property (readwrite) CGSize contentSize; -/** A weak reference to the parent */ -@property(readwrite,assign) CocosNode* parent; -/** If YES the transformtions will be relative to (-transform.x, -transform.y). - * Sprites, Labels and any other sizeble object use it. - * Scenes, Layers and other "whole screen" object don't use it. - */ -@property(readwrite,assign) BOOL relativeTransformAnchor; -/** A tag used to identify the node easily */ -@property(readwrite,assign) int tag; -/** An array with the children */ -@property (readonly) NSArray *children; - -// initializators -//! creates a node -+(id) node; -//! initializes the node --(id) init; - - -// scene managment - -/** callback that is called every time the CocosNode enters the 'stage' - If the CocosNode enters the 'stage' with a transition, this callback is called when the transition starts. - */ --(void) onEnter; -/** callback that is called when the CocosNode enters in the 'stage'. - If the CocosNode enters the 'stage' with a transition, this callback is called when the transition finishes. - @since v0.8 - */ --(void) onTransitionDidFinish; -/** callback that is called every time the CocosNode leaves the 'stage'. */ --(void) onExit; - - -// composition: ADD - -/** Adds a child to the container with z-order as 0. - It returns self, so you can chain several addChilds. - @since v0.7.1 - */ --(id) addChild: (CocosNode*)node; - -/** Adds a child to the container with a z-order - It returns self, so you can chain several addChilds. - @since v0.7.1 - */ --(id) addChild: (CocosNode*)node z:(int)z; - -/** Adds a child to the container with z order and tag - It returns self, so you can chain several addChilds. - @since v0.7.1 - */ --(id) addChild: (CocosNode*)node z:(int)z tag:(int)tag; - -// composition: REMOVE - -/** Removes a child from the container. It will also cleanup all running actions depending on the cleanup parameter. - @since v0.7.1 - */ --(void) removeChild: (CocosNode*)node cleanup:(BOOL)cleanup; - -/** Removes a child from the container by tag value. It will also cleanup all running actions depending on the cleanup parameter - @since v0.7.1 - */ --(void) removeChildByTag:(int) tag cleanup:(BOOL)cleanup; - -/** Removes all children from the container and do a cleanup all running actions depending on the cleanup parameter. - @since v0.7.1 - */ --(void) removeAllChildrenWithCleanup:(BOOL)cleanup; - -// composition: GET -/** Gets a child from the container given its tag - @return returns a CocosNode object - @since v0.7.1 - */ --(CocosNode*) getChildByTag:(int) tag; - -/** Reorders a child according to a new z value. - * The child MUST be already added. - */ --(void) reorderChild:(CocosNode*)child z:(int)zOrder; - -// draw - -/** override this method to draw your own node. */ --(void) draw; -/** recursive method that visit its children and draw them */ --(void) visit; - - -// transformations - -/** performs OpenGL view-matrix transformation based on position, scale, rotation and other attributes. */ --(void) transform; - -/** performs OpenGL view-matrix transformation of it's ancestors. - Generally the ancestors are already transformed, but in certain cases (eg: attaching a FBO) - it's necessary to transform the ancestors again. - @since v0.7.2 - */ --(void) transformAncestors; - - -// actions - -/** Executes an action, and returns the action that is executed. - The node becomes the action's target. - @warning Starting from v0.8 actions don't retain their target anymore. - @since v0.7.1 - @return An Action pointer - */ --(Action*) runAction: (Action*) action; -/** Removes all actions from the running action list */ --(void) stopAllActions; -/** Removes an action from the running action list */ --(void) stopAction: (Action*) action; -/** Removes an action from the running action list given its tag - @since v0.7.1 -*/ --(void) stopActionByTag:(int) tag; -/** Gets an action from the running action list given its tag - @since v0.7.1 - @return the Action the with the given tag - */ --(Action*) getActionByTag:(int) tag; -/** Returns the numbers of actions that are running plus the ones that are schedule to run (actions in actionsToAdd and actions arrays). - * Composable actions are counted as 1 action. Example: - * If you are running 1 Sequence of 7 actions, it will return 1. - * If you are running 7 Sequences of 2 actions, it will return 7. - */ --(int) numberOfRunningActions; - -// timers - -/** check whether a selector is scheduled. */ -//-(BOOL) isScheduled: (SEL) selector; - -/** schedules a selector. - The scheduled selector will be ticked every frame - */ --(void) schedule: (SEL) s; -/** schedules a selector with an interval time in seconds. - If time is 0 it will be ticked every frame. - */ --(void) schedule: (SEL) s interval:(ccTime)seconds; -/** unschedule a selector */ --(void) unschedule: (SEL) s; -/** activate all scheduled timers. - Called internally by onEnter - */ --(void) activateTimers; -/** deactivate all scheduled timers. - Called internally by onExit - */ --(void) deactivateTimers; - - -// transformation methods - -/// actual affine transforms used -/// XXX: needs documentation -/// @since v0.7.1 -- (CGAffineTransform)nodeToParentTransform; -/// XXX: needs documentation -/// @since v0.7.1 -- (CGAffineTransform)parentToNodeTransform; -/// XXX: needs documentation -/// @since v0.7.1 -- (CGAffineTransform)nodeToWorldTransform; -/// XXX: needs documentation -/// @since v0.7.1 -- (CGAffineTransform)worldToNodeTransform; -/** converts a world coordinate to local coordinate - @since v0.7.1 - */ -- (CGPoint)convertToNodeSpace:(CGPoint)worldPoint; -/** converts local coordinate to world space - @since v0.7.1 - */ -- (CGPoint)convertToWorldSpace:(CGPoint)nodePoint; -/** converts a world coordinate to local coordinate - treating the returned/received node point as anchor relative - @since v0.7.1 - */ -- (CGPoint)convertToNodeSpaceAR:(CGPoint)worldPoint; -/** converts local coordinate to world space - treating the returned/received node point as anchor relative - @since v0.7.1 - */ -- (CGPoint)convertToWorldSpaceAR:(CGPoint)nodePoint; -// convenience methods which take a UITouch instead of CGPoint -/// XXX: needs documentation -/// @since v0.7.1 -- (CGPoint)convertTouchToNodeSpace:(UITouch *)touch; -/// XXX: needs documentation -/// @since v0.7.1 -- (CGPoint)convertTouchToNodeSpaceAR:(UITouch *)touch; -@end - -// -// protocols -// - -/// CocosNode RGBA protocol -@protocol CocosNodeRGBA -/** set the color of the node - * example: [node setRGB: 255:128:24]; or [node setRGB:0xff:0x88:0x22]; - @since v0.7.1 - */ --(void) setRGB: (GLubyte)r :(GLubyte)g :(GLubyte)b; -/// The red component of the node's color. --(GLubyte) r; -/// The green component of the node's color. --(GLubyte) g; -/// The blue component of the node's color. --(GLubyte) b; -/// returns the opacity --(GLubyte) opacity; -/** sets the opacity. - @warning If the the texture has premultiplied colors then R = G = B = Opacity - */ --(void) setOpacity: (GLubyte) opacity; -@end - - -/** CocosNodes that uses a Texture2D to render the images. - @since v0.8 - */ -@protocol CocosNodeTexture -/** returns the used texture */ --(Texture2D*) texture; -/** sets a new texture. it will be retained */ --(void) setTexture:(Texture2D*)texture; -@end - -/** Common interface for Labels */ -@protocol CocosNodeLabel -/** sets a new label using an NSString */ --(void) setString:(NSString*)label; -@end - - - -/// Objects that supports the Animation protocol -/// @since v0.7.1 -@protocol CocosAnimation -/** reaonly array with the frames */ --(NSArray*) frames; -/** delay of the animations */ --(float) delay; -/** name of the animation */ --(NSString*) name; -@end - -/// Nodes supports frames protocol -/// @since v0.7.1 -@protocol CocosNodeFrames -/** sets a new display frame to the node */ --(void) setDisplayFrame:(id)newFrame; -/** changes the display frame based on an animation and an index */ --(void) setDisplayFrame: (NSString*) animationName index:(int) frameIndex; -/** returns the current displayed frame */ --(BOOL) isFrameDisplayed:(id)frame; -/** returns the current displayed frame */ --(id) displayFrame; -/** returns an Animation given it's name */ --(id)animationByName: (NSString*) animationName; -/** adds an Animation to the Sprite */ --(void) addAnimation: (id) animation; -@end - diff --git a/Support/cocos2d/CocosNode.m b/Support/cocos2d/CocosNode.m deleted file mode 100644 index 4b60a90..0000000 --- a/Support/cocos2d/CocosNode.m +++ /dev/null @@ -1,830 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2008,2009 Ricardo Quesada - * Copyright (C) 2009 Valentin Milea - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - - -#import "CocosNode.h" -#import "Camera.h" -#import "Grid.h" -#import "Scheduler.h" -#import "ccMacros.h" -#import "Director.h" -#import "Support/CGPointExtension.h" -#import "Support/ccArray.h" -#import "Support/TransformUtils.h" - -@interface CocosNode (Private) --(void) step_: (ccTime) dt; -// lazy allocs --(void) actionAlloc; --(void) childrenAlloc; --(void) timerAlloc; -// helper that reorder a child --(void) insertChild:(CocosNode*)child z:(int)z; -// used internally to alter the zOrder variable. DON'T call this method manually --(void) _setZOrder:(int) z; --(void) detachChild:(CocosNode *)child cleanup:(BOOL)doCleanup; -@end - -@implementation CocosNode - -@synthesize visible; -@synthesize parent, children; -@synthesize grid; -@synthesize zOrder; -@synthesize tag; -@synthesize vertexZ = vertexZ_; - -#pragma mark CocosNode - Transform related properties - -@synthesize rotation=rotation_, scaleX=scaleX_, scaleY=scaleY_, position=position_; -@synthesize transformAnchor=transformAnchor_, relativeTransformAnchor=relativeTransformAnchor_; - -// getters synthesized, setters explicit --(void) setRotation: (float)newRotation -{ - rotation_ = newRotation; - isTransformDirty_ = isInverseDirty_ = YES; -} - --(void) setScaleX: (float)newScaleX -{ - scaleX_ = newScaleX; - isTransformDirty_ = isInverseDirty_ = YES; -} - --(void) setScaleY: (float)newScaleY -{ - scaleY_ = newScaleY; - isTransformDirty_ = isInverseDirty_ = YES; -} - --(void) setPosition: (CGPoint)newPosition -{ - position_ = newPosition; - isTransformDirty_ = isInverseDirty_ = YES; -} - --(void) setTransformAnchor: (CGPoint)newTransformAnchor -{ - transformAnchor_ = newTransformAnchor; - isTransformDirty_ = isInverseDirty_ = YES; -} - --(void) setRelativeTransformAnchor: (BOOL)newValue -{ - relativeTransformAnchor_ = newValue; - isTransformDirty_ = isInverseDirty_ = YES; -} - --(void) setAnchorPoint:(CGPoint)point -{ - if( ! CGPointEqualToPoint(point, anchorPoint_) ) { - anchorPoint_ = point; - self.transformAnchor = ccp( contentSize_.width * anchorPoint_.x, contentSize_.height * anchorPoint_.y ); - } -} --(CGPoint) anchorPoint -{ - return anchorPoint_; -} --(void) setContentSize:(CGSize)size -{ - if( ! CGSizeEqualToSize(size, contentSize_) ) { - contentSize_ = size; - self.transformAnchor = ccp( contentSize_.width * anchorPoint_.x, contentSize_.height * anchorPoint_.y ); - } -} --(CGSize) contentSize -{ - return contentSize_; -} - --(float) scale -{ - if( scaleX_ == scaleY_) - return scaleX_; - else - [NSException raise:@"CocosNode scale:" format:@"scaleX is different from scaleY"]; - - return 0; -} - --(void) setScale:(float) s -{ - scaleX_ = scaleY_ = s; - isTransformDirty_ = isInverseDirty_ = YES; -} - - -#pragma mark CocosNode - Init & cleanup - -+(id) node -{ - return [[[self alloc] init] autorelease]; -} - --(id) init -{ - if (!(self=[super init]) ) - return nil; - - isRunning = NO; - - - rotation_ = 0.0f; - scaleX_ = scaleY_ = 1.0f; - position_ = CGPointZero; - transformAnchor_ = CGPointZero; - anchorPoint_ = CGPointZero; - contentSize_ = CGSizeZero; - - // "whole screen" objects. like Scenes and Layers, should set relativeTransformAnchor to NO - relativeTransformAnchor_ = YES; - - isTransformDirty_ = isInverseDirty_ = YES; - - - vertexZ_ = 0; - - grid = nil; - - visible = YES; - - tag = kCocosNodeTagInvalid; - - zOrder = 0; - - // lazy alloc - camera = nil; - - // children (lazy allocs) - children = nil; - - // actions (lazy allocs) - actions = nil; - - // scheduled selectors (lazy allocs) - scheduledSelectors = nil; - - return self; -} - -- (void)cleanup -{ - // actions - [self stopAllActions]; - - // timers - [scheduledSelectors release]; - scheduledSelectors = nil; - - [children makeObjectsPerformSelector:@selector(cleanup)]; -} - -- (NSString*) description -{ - return [NSString stringWithFormat:@"<%@ = %08X | Tag = %i>", [self class], self, tag]; -} - -- (void) dealloc -{ - CCLOG( @"deallocing %@", self); - - // attributes - [camera release]; - - [grid release]; - - // children - - for (CocosNode *child in children) { - child.parent = nil; - [child cleanup]; - } - - [children release]; - - // timers - [scheduledSelectors release]; - - // actions - [self stopAllActions]; - ccArrayFree(actions); - - [super dealloc]; -} - -#pragma mark CocosNode Composition - --(void) childrenAlloc -{ - children = [[NSMutableArray arrayWithCapacity:4] retain]; -} - -// camera: lazy alloc --(Camera*) camera -{ - if( ! camera ) - camera = [[Camera alloc] init]; - - return camera; -} - -/* "add" logic MUST only be on this selector - * If a class want's to extend the 'addChild' behaviour it only needs - * to override this selector - */ --(id) addChild: (CocosNode*) child z:(int)z tag:(int) aTag -{ - NSAssert( child != nil, @"Argument must be non-nil"); - NSAssert( child.parent == nil, @"child already added. It can't be added again"); - - if( ! children ) - [self childrenAlloc]; - - [self insertChild:child z:z]; - - child.tag = aTag; - - [child setParent: self]; - - if( isRunning ) - [child onEnter]; - return self; -} - --(id) addChild: (CocosNode*) child z:(int)z -{ - NSAssert( child != nil, @"Argument must be non-nil"); - return [self addChild:child z:z tag:child.tag]; -} - --(id) addChild: (CocosNode*) child -{ - NSAssert( child != nil, @"Argument must be non-nil"); - return [self addChild:child z:child.zOrder tag:child.tag]; -} - -/* "remove" logic MUST only be on this method - * If a class want's to extend the 'removeChild' behavior it only needs - * to override this method - */ --(void) removeChild: (CocosNode*)child cleanup:(BOOL)cleanup -{ - // explicit nil handling - if (child == nil) - return; - - if ( [children containsObject:child] ) - [self detachChild:child cleanup:cleanup]; -} - --(void) removeChildByTag:(int)aTag cleanup:(BOOL)cleanup -{ - NSAssert( aTag != kCocosNodeTagInvalid, @"Invalid tag"); - - CocosNode *child = [self getChildByTag:aTag]; - - if (child == nil) - CCLOG(@"removeChildByTag: child not found!"); - else - [self removeChild:child cleanup:cleanup]; -} - --(void) removeAllChildrenWithCleanup:(BOOL)cleanup -{ - // not using detachChild improves speed here - for( CocosNode * c in children) { - if( cleanup) { - [c cleanup]; - } - [c setParent: nil]; - if( isRunning ) - [c onExit]; - } - - [children removeAllObjects]; -} - --(CocosNode*) getChildByTag:(int) aTag -{ - NSAssert( aTag != kCocosNodeTagInvalid, @"Invalid tag"); - - for( CocosNode *node in children ) { - if( node.tag == aTag ) - return node; - } - // not found - return nil; -} - --(void) detachChild:(CocosNode *) child cleanup:(BOOL) doCleanup -{ - [child setParent: nil]; - - // stop timers - if( isRunning ) - [child onExit]; - - // If you don't do cleanup, the child's actions will not get removed and the - // its scheduledSelectors dict will not get released! - if (doCleanup) - [child cleanup]; - - [children removeObject: child]; -} - -// used internally to alter the zOrder variable. DON'T call this method manually --(void) _setZOrder:(int) z -{ - zOrder = z; -} - -// helper used by reorderChild & add --(void) insertChild:(CocosNode*) child z:(int)z -{ - int index=0; - BOOL added = NO; - for( CocosNode *a in children ) { - if ( a.zOrder > z ) { - added = YES; - [ children insertObject:child atIndex:index]; - break; - } - index++; - } - - if( ! added ) - [children addObject:child]; - - [child _setZOrder:z]; -} - --(void) reorderChild:(CocosNode*) child z:(int)z -{ - NSAssert( child != nil, @"Child must be non-nil"); - - [child retain]; - [children removeObject:child]; - - [self insertChild:child z:z]; - - [child release]; -} - -#pragma mark CocosNode Draw - --(void) draw -{ - // override me - // Only use this function to draw your staff. - // DON'T draw your stuff outside this method -} - --(void) visit -{ - if (!visible) - return; - - glPushMatrix(); - - if ( grid && grid.active) { - [grid beforeDraw]; - [self transformAncestors]; - } - - [self transform]; - - for (CocosNode * child in children) { - if ( child.zOrder < 0 ) - [child visit]; - else - break; - } - - [self draw]; - - for (CocosNode * child in children) { - if ( child.zOrder >= 0 ) - [child visit]; - } - - if ( grid && grid.active) - [grid afterDraw:self.camera]; - - glPopMatrix(); -} - -#pragma mark CocosNode - Transformations - --(void) transformAncestors -{ - if( self.parent ) { - [self.parent transformAncestors]; - [self.parent transform]; - } -} - --(void) transform -{ - if ( !(grid && grid.active) ) - [camera locate]; - - // transformations - - // BEGIN original implementation - // - // translate - if ( relativeTransformAnchor_ && (transformAnchor_.x != 0 || transformAnchor_.y != 0 ) ) - glTranslatef( (int)(-transformAnchor_.x), (int)(-transformAnchor_.y), vertexZ_); - - if (transformAnchor_.x != 0 || transformAnchor_.y != 0 ) - glTranslatef( (int)(position_.x + transformAnchor_.x), (int)(position_.y + transformAnchor_.y), vertexZ_); - else if ( position_.x !=0 || position_.y !=0) - glTranslatef( (int)(position_.x), (int)(position_.y), vertexZ_ ); - - // rotate - if (rotation_ != 0.0f ) - glRotatef( -rotation_, 0.0f, 0.0f, 1.0f ); - - // scale - if (scaleX_ != 1.0f || scaleY_ != 1.0f) - glScalef( scaleX_, scaleY_, 1.0f ); - - // restore and re-position point - if (transformAnchor_.x != 0.0f || transformAnchor_.y != 0.0f) - glTranslatef((int)(-transformAnchor_.x), (int)(-transformAnchor_.y), vertexZ_); - // - // END original implementation - - /* - // BEGIN alternative -- using cached transform - // - static GLfloat m[16]; - CGAffineTransform t = [self nodeToParentTransform]; - CGAffineToGL(&t, m); - glMultMatrixf(m); - glTranslatef(0, 0, vertexZ_); - // - // END alternative - */ -} - -#pragma mark CocosNode SceneManagement - --(void) onEnter -{ - for( id child in children ) - [child onEnter]; - - [self activateTimers]; - - isRunning = YES; -} - --(void) onTransitionDidFinish -{ - for( id child in children ) - [child onTransitionDidFinish]; -} - --(void) onExit -{ - [self deactivateTimers]; - - isRunning = NO; - - for( id child in children ) - [child onExit]; -} - -#pragma mark CocosNode Actions - --(void) actionAlloc -{ - if( actions == nil ) - actions = ccArrayNew(4); - else if( actions->num == actions->max ) - ccArrayDoubleCapacity(actions); -} - --(Action*) runAction:(Action*) action -{ - NSAssert( action != nil, @"Argument must be non-nil"); - - // lazy alloc - [self actionAlloc]; - - NSAssert( !ccArrayContainsObject(actions, action), @"Action already running"); - - ccArrayAppendObject(actions, action); - - action.target = self; - [action start]; - - [self schedule: @selector(step_:)]; - - return action; -} - --(void) stopAllActions -{ - if( actions == nil ) - return; - - if( ccArrayContainsObject(actions, currentAction) && !currentActionSalvaged ) { - [currentAction retain]; - currentActionSalvaged = YES; - } - - ccArrayRemoveAllObjects(actions); -} - --(void) stopAction: (Action*) action -{ - // explicit nil handling - if (action == nil) - return; - - if( actions != nil ) { - NSUInteger i = ccArrayGetIndexOfObject(actions, action); - - if( i != NSNotFound ) { - if( action == currentAction && !currentActionSalvaged ) { - [currentAction retain]; - currentActionSalvaged = YES; - } - ccArrayRemoveObjectAtIndex(actions, i); - - // update actionIndex in case we are in step_, looping over the actions - if( actionIndex >= (int) i ) - actionIndex--; - } - } else - CCLOG(@"stopAction: Action not found!"); -} - --(void) stopActionByTag:(int) aTag -{ - NSAssert( aTag != kActionTagInvalid, @"Invalid tag"); - - if( actions != nil ) { - NSUInteger limit = actions->num; - for( NSUInteger i = 0; i < limit; i++) { - Action *a = actions->arr[i]; - - if( a.tag == aTag ) { - if( a == currentAction && !currentActionSalvaged ) { - [currentAction retain]; - currentActionSalvaged = YES; - } - ccArrayRemoveObjectAtIndex(actions, i); - - // update actionIndex in case we are in step_, looping over the actions - if (actionIndex >= (int) i) - actionIndex--; - return; - } - } - } - - CCLOG(@"stopActionByTag: Action not found!"); -} - --(Action*) getActionByTag:(int) aTag -{ - NSAssert( aTag != kActionTagInvalid, @"Invalid tag"); - - if( actions != nil ) { - NSUInteger limit = actions->num; - for( NSUInteger i = 0; i < limit; i++) { - Action *a = actions->arr[i]; - - if( a.tag == aTag ) - return a; - } - } - - CCLOG(@"getActionByTag: Action not found"); - return nil; -} - --(int) numberOfRunningActions -{ - return actions ? actions->num : 0; -} - --(void) step_: (ccTime) dt -{ - // !Running the actions may indirectly release the CocosNode, so we're - // !retaining self to prevent deallocation. - // ![self retain]; - - // (!) UPDATE: Retaining isn't currently necessary because the Timer which runs - // step_ retains the node, keeping it alive. Even if an action indirectly calls - // Scheduler#unscheduleTimer (i.e. CallFunc calls [parent removeChild:self] which - // calls [self onExit] which calls [self deactivateTimers]), the Timer won't be - // deallocated until the next Scheduler#tick. - // Bottom line: Node doesn't run the risk of deallocating itself in step_ as - // long as the implementation of Scheduler stays the same. We can ommit the - // expensive retain/release. - - // call all actions - - // The 'actions' ccArray may change while inside this loop. - for( actionIndex = 0; actionIndex < (int) actions->num; actionIndex++) { - currentAction = actions->arr[actionIndex]; - currentActionSalvaged = NO; - - [currentAction step: dt]; - - if( currentActionSalvaged ) { - // The currentAction told the node to stop it. To prevent the action from - // accidentally deallocating itself before finishing its step, we retained - // it. Now that step is done, it's safe to release it. - [currentAction release]; - } - else if( [currentAction isDone] ) { - [currentAction stop]; - - Action *a = currentAction; - // Make currentAction nil to prevent stopAction from salvaging it. - currentAction = nil; - [self stopAction:a]; - } - } - currentAction = nil; - - if( actions->num == 0 ) - [self unschedule: @selector(step_:)]; - - // !And releasing self when done. - // ![self release]; - // !If the node had a retain count of 1 before getting released, it's now - // !deallocated. However, since we don't access any ivar, we're fine. -} - -#pragma mark CocosNode Timers - --(void) timerAlloc -{ - scheduledSelectors = [[NSMutableDictionary dictionaryWithCapacity: 2] retain]; -} - --(void) schedule: (SEL) selector -{ - [self schedule:selector interval:0]; -} - --(void) schedule: (SEL) selector interval:(ccTime)interval -{ - NSAssert( selector != nil, @"Argument must be non-nil"); - NSAssert( interval >=0, @"Arguemnt must be positive"); - - if( !scheduledSelectors ) - [self timerAlloc]; - - if( [scheduledSelectors objectForKey: NSStringFromSelector(selector) ] ) { - return; - } - - Timer *timer = [Timer timerWithTarget:self selector:selector interval:interval]; - - if( isRunning ) - [[Scheduler sharedScheduler] scheduleTimer:timer]; - - [scheduledSelectors setObject:timer forKey:NSStringFromSelector(selector) ]; -} - --(void) unschedule: (SEL) selector -{ - // explicit nil handling - if (selector == nil) - return; - - Timer *timer = nil; - - if( ! (timer = [scheduledSelectors objectForKey: NSStringFromSelector(selector)] ) ) - { - CCLOG(@"CocosNode.unschedule: Selector not scheduled: %@",NSStringFromSelector(selector) ); - return; - } - - [scheduledSelectors removeObjectForKey: NSStringFromSelector(selector) ]; - if( isRunning ) - [[Scheduler sharedScheduler] unscheduleTimer:timer]; -} - -- (void) activateTimers -{ - for( id key in scheduledSelectors ) - [[Scheduler sharedScheduler] scheduleTimer: [scheduledSelectors objectForKey:key]]; -} - -- (void) deactivateTimers -{ - for( id key in scheduledSelectors ) - [[Scheduler sharedScheduler] unscheduleTimer: [scheduledSelectors objectForKey:key]]; -} - - -#pragma mark CocosNode Transform - -- (CGAffineTransform)nodeToParentTransform -{ - if ( isTransformDirty_ ) { - - transform_ = CGAffineTransformIdentity; - - if ( !relativeTransformAnchor_ ) { - transform_ = CGAffineTransformTranslate(transform_, (int)transformAnchor_.x, (int)transformAnchor_.y); - } - - transform_ = CGAffineTransformTranslate(transform_, (int)position_.x, (int)position_.y); - transform_ = CGAffineTransformRotate(transform_, -CC_DEGREES_TO_RADIANS(rotation_)); - transform_ = CGAffineTransformScale(transform_, scaleX_, scaleY_); - - transform_ = CGAffineTransformTranslate(transform_, -(int)transformAnchor_.x, -(int)transformAnchor_.y); - - isTransformDirty_ = NO; - } - - return transform_; -} - -- (CGAffineTransform)parentToNodeTransform -{ - if ( isInverseDirty_ ) { - inverse_ = CGAffineTransformInvert([self nodeToParentTransform]); - isInverseDirty_ = NO; - } - - return inverse_; -} - -- (CGAffineTransform)nodeToWorldTransform -{ - CGAffineTransform t = [self nodeToParentTransform]; - - for (CocosNode *p = parent; p != nil; p = p.parent) - t = CGAffineTransformConcat(t, [p nodeToParentTransform]); - - return t; -} - -- (CGAffineTransform)worldToNodeTransform -{ - return CGAffineTransformInvert([self nodeToWorldTransform]); -} - -- (CGPoint)convertToNodeSpace:(CGPoint)worldPoint -{ - return CGPointApplyAffineTransform(worldPoint, [self worldToNodeTransform]); -} - -- (CGPoint)convertToWorldSpace:(CGPoint)nodePoint -{ - return CGPointApplyAffineTransform(nodePoint, [self nodeToWorldTransform]); -} - -- (CGPoint)convertToNodeSpaceAR:(CGPoint)worldPoint -{ - CGPoint nodePoint = [self convertToNodeSpace:worldPoint]; - return ccpSub(nodePoint, transformAnchor_); -} - -- (CGPoint)convertToWorldSpaceAR:(CGPoint)nodePoint -{ - nodePoint = ccpAdd(nodePoint, transformAnchor_); - return [self convertToWorldSpace:nodePoint]; -} - -// convenience methods which take a UITouch instead of CGPoint - -- (CGPoint)convertTouchToNodeSpace:(UITouch *)touch -{ - CGPoint point = [touch locationInView: [touch view]]; - point = [[Director sharedDirector] convertCoordinate: point]; - return [self convertToNodeSpace:point]; -} - -- (CGPoint)convertTouchToNodeSpaceAR:(UITouch *)touch -{ - CGPoint point = [touch locationInView: [touch view]]; - point = [[Director sharedDirector] convertCoordinate: point]; - return [self convertToNodeSpaceAR:point]; -} - -@end diff --git a/Support/cocos2d/Director.h b/Support/cocos2d/Director.h deleted file mode 100644 index c67a5f2..0000000 --- a/Support/cocos2d/Director.h +++ /dev/null @@ -1,283 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2008,2009 Ricardo Quesada - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - - -// -#import "ccTypes.h" - -// OpenGL related -#import "Support/EAGLView.h" - - -@protocol TouchEventsDelegate; - -enum { - kEventHandled = YES, - kEventIgnored = NO, -}; - - -// Fast FPS display. FPS are updated 10 times per second without consuming resources -// uncomment this line to use the old method that updated -//#define FAST_FPS_DISPLAY 1 - -/** Possible Pixel Formats for the EAGLView */ -typedef enum { - kRGB565, - kRGBA8 -} tPixelFormat; - -/** Possible DepthBuffer Formats for the EAGLView */ -typedef enum { - kDepthBufferNone, - kDepthBuffer16, - kDepthBuffer24, -} tDepthBufferFormat; - -/** Possible device orientations */ -typedef enum { - /// Device oriented vertically, home button on the bottom - CCDeviceOrientationPortrait = UIDeviceOrientationPortrait, - /// Device oriented vertically, home button on the top - CCDeviceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown, - /// Device oriented horizontally, home button on the right - CCDeviceOrientationLandscapeLeft = UIDeviceOrientationLandscapeLeft, - /// Device oriented horizontally, home button on the left - CCDeviceOrientationLandscapeRight = UIDeviceOrientationLandscapeRight, -} ccDeviceOrientation; - -@class LabelAtlas; -@class Scene; - -/**Class that creates and handle the main Window and manages how -and when to execute the Scenes -*/ -@interface Director : NSObject -{ - EAGLView *openGLView_; - - // internal timer - NSTimer *animationTimer; - NSTimeInterval animationInterval; - NSTimeInterval oldAnimationInterval; - - tPixelFormat pixelFormat_; - tDepthBufferFormat depthBufferFormat_; - - /* landscape mode ? */ - BOOL landscape; - - /* orientation */ - ccDeviceOrientation deviceOrientation_; - - /* display FPS ? */ - BOOL displayFPS; - int frames; - ccTime accumDt; - ccTime frameRate; -#ifdef FAST_FPS_DISPLAY - LabelAtlas *FPSLabel; -#endif - - /* is the running scene paused */ - BOOL paused; - - /* The running scene */ - Scene *runningScene_; - - /* will be the next 'runningScene' in the next frame - nextScene is a weak reference. */ - Scene *nextScene; - - /* event handler */ - NSMutableArray *eventHandlers; - - /* scheduled scenes */ - NSMutableArray *scenesStack_; - - /* last time the main loop was updated */ - struct timeval lastUpdate; - /* delta time since last tick to main loop */ - ccTime dt; - /* whether or not the next delta time will be zero */ - BOOL nextDeltaTimeZero_; - - /* are touch events enabled. Default is YES */ - BOOL eventsEnabled; -} - -/** The current running Scene. Director can only run one Scene at the time */ -@property (readonly) Scene* runningScene; -/** The FPS value */ -@property (readwrite, assign) NSTimeInterval animationInterval; -/** Whether or not to display the FPS on the bottom-left corner */ -@property (readwrite, assign) BOOL displayFPS; -/** Whether or not to propagate the touch events to the running Scene. Default YES */ -@property (readwrite, assign) BOOL eventsEnabled; -/** The OpenGL view */ -@property (readonly) EAGLView *openGLView; -/** Pixel format used to create the context */ -@property (readonly) tPixelFormat pixelFormat; -/** whether or not the next delta time will be zero */ -@property (readwrite,assign) BOOL nextDeltaTimeZero; -/** The device orientattion */ -@property (readwrite) ccDeviceOrientation deviceOrientation; - -/** returns a shared instance of the director */ -+(Director *)sharedDirector; -/** Uses a Director that triggers the main loop as fast as it can. - * Although it is faster, it will consume more battery - * To use it, it must be called before calling any director function - */ -+(void) useFastDirector; - - -// iPhone Specific - -/** change default pixel format. - Call this class method before attaching it to a UIWindow/UIView - Default pixel format: kRGB565. Supported pixel formats: kRGBA8 and kRGB565 - */ --(void) setPixelFormat: (tPixelFormat) p; - -/** change depth buffer format. - Call this class method before attaching it to a UIWindow/UIView - Default depth buffer: 0 (none). Supported: kDepthBufferNone, kDepthBuffer16, and kDepthBuffer24 - */ --(void) setDepthBufferFormat: (tDepthBufferFormat) db; - -// Integration with UIKit -/** detach the cocos2d view from the view/window */ --(BOOL)detach; - -/** attach in UIWindow using the full frame */ --(BOOL)attachInWindow:(UIWindow *)window; - -/** attach in UIView using the full frame */ --(BOOL)attachInView:(UIView *)view; - -/** attach in UIView using the given frame */ --(BOOL)attachInView:(UIView *)view withFrame:(CGRect)frame; - -// Landscape - -/** returns the size of the OpenGL view according to the landspace */ -- (CGSize) winSize; -/** returns the display size of the OpenGL view */ --(CGSize) displaySize; - -/** returns whether or not the screen is in landscape mode - @deprecated Use deviceOrientation instead - */ -- (BOOL) landscape __attribute__((deprecated)); -/** sets lanscape mode - @deprecated Use setDeviceOrientation instead - */ -- (void) setLandscape: (BOOL) on __attribute__((deprecated)); - -/** converts a UIKit coordinate to an OpenGL coordinate - Useful to convert (multi) touchs coordinates to the current layout (portrait or landscape) - */ --(CGPoint) convertCoordinate: (CGPoint) p; - -// Scene Management - -/**Enters the Director's main loop with the given Scene. - * Call it to run only your FIRST scene. - * Don't call it if there is already a running scene. - */ -- (void) runWithScene:(Scene*) scene; - -/**Suspends the execution of the running scene, pushing it on the stack of suspended scenes. - * The new scene will be executed. - * Try to avoid big stacks of pushed scenes to reduce memory allocation. - * ONLY call it if there is a running scene. - */ -- (void) pushScene:(Scene*) scene; - -/**Pops out a scene from the queue. - * This scene will replace the running one. - * The running scene will be deleted. If there are no more scenes in the stack the execution is terminated. - * ONLY call it if there is a running scene. - */ -- (void) popScene; - -/** Replaces the running scene with a new one. The running scene is terminated. - * ONLY call it if there is a running scene. - */ --(void) replaceScene: (Scene*) scene; - -/** Ends the execution, releases the running scene */ --(void) end; - -/** Pauses the running scene. - The running scene will be _drawed_ but all scheduled timers will be paused - While paused, the draw rate will be 4 FPS to reduce CPU consuption - */ --(void) pause; - -/** Resumes the paused scene - The scheduled timers will be activated again. - The "delta time" will be 0 (as if the game wasn't paused) - */ --(void) resume; - -/** Stops the animation. Nothing will be drawn. The main loop won't be triggered anymore. - If you wan't to pause your animation call [pause] instead. - */ --(void) stopAnimation; - -/** The main loop is triggered again. - Call this function only if [stopAnimation] was called earlier - @warning Dont' call this function to start the main loop. To run the main loop call runWithScene - */ --(void) startAnimation; - - -// Events - -/** adds a delegate to the list of multi-touch handlers */ --(void) addEventHandler: (id) delegate; -/** removes a delegate from the list of multi-touch handlers */ --(void) removeEventHandler: (id) delegate; - -// OpenGL Helper - -/** enables/disables OpenGL alpha blending */ -- (void) setAlphaBlending: (BOOL) on; -/** enables/disables OpenGL depth test */ -- (void) setDepthTest: (BOOL) on; -/** enables/disables OpenGL texture 2D */ -- (void) setTexture2D: (BOOL) on; -/** sets Cocos OpenGL default projection */ -- (void) setDefaultProjection; -/** sets a 2D projection */ --(void) set2Dprojection; -/** sets a 3D projection */ --(void) set3Dprojection; -@end - -/** FastDirector is a Director that triggers the main loop as fast as possible. - * In some circumstances it is faster than the normal Director. - */ -@interface FastDirector : Director -{ - BOOL isRunning; - - NSAutoreleasePool *autoreleasePool; -} -@end - - - diff --git a/Support/cocos2d/Director.m b/Support/cocos2d/Director.m deleted file mode 100644 index c1e44b2..0000000 --- a/Support/cocos2d/Director.m +++ /dev/null @@ -1,966 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2008,2009 Ricardo Quesada - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - -/* Idea of decoupling Window from Director taken from OC3D project: http://code.google.com/p/oc3d/ - */ - -// cocos2d imports -#import "Director.h" -#import "TouchDispatcher.h" -#import "Camera.h" -#import "Scheduler.h" -#import "LabelAtlas.h" -#import "ccMacros.h" -#import "ccExceptions.h" -#import "Transition.h" -#import "Scene.h" - -// support imports -#import "Support/glu.h" -#import "Support/OpenGL_Internal.h" -#import "Support/Texture2D.h" -#import "Support/CGPointExtension.h" - -#import "Layer.h" - -#define kDefaultFPS 60.0 // 60 frames per second - - -@interface Director (Private) --(BOOL)isOpenGLAttached; --(BOOL)initOpenGLViewWithView:(UIView *)view withFrame:(CGRect)rect; - --(void) initGLDefaultValues; - --(void) mainLoop; --(void) setNextScene; -// rotates the screen if Landscape mode is activated --(void) applyLandscape; -// shows the FPS in the screen --(void) showFPS; -// calculates delta time since last time it was called --(void) calculateDeltaTime; - - -@end - -@implementation Director - -@synthesize animationInterval; -@synthesize runningScene = runningScene_; -@synthesize displayFPS, eventsEnabled; -@synthesize openGLView=openGLView_; -@synthesize pixelFormat=pixelFormat_; -@synthesize nextDeltaTimeZero=nextDeltaTimeZero_; -@synthesize deviceOrientation=deviceOrientation_; - -// -// singleton stuff -// -static Director *_sharedDirector = nil; - -+ (Director *)sharedDirector -{ - @synchronized([Director class]) - { - if (!_sharedDirector) - [[self alloc] init]; - - return _sharedDirector; - } - // to avoid compiler warning - return nil; -} - -// This function was created to avoid confussion for the users -// Calling [FastDirector sharedDirector] is enough, but is somewhat -// confusing since the user needs to understand what's under the hood -+ (void) useFastDirector -{ - NSAssert(_sharedDirector==nil, @"A Director was alloced. To use Fast Director this must be the first call to Director"); - [FastDirector sharedDirector]; -} - -+(id)alloc -{ - @synchronized([Director class]) - { - NSAssert(_sharedDirector == nil, @"Attempted to allocate a second instance of a singleton."); - _sharedDirector = [super alloc]; - return _sharedDirector; - } - // to avoid compiler warning - return nil; -} - -- (id) init -{ - //Create a full-screen window - - // default values - pixelFormat_ = kRGB565; - depthBufferFormat_ = 0; - - // scenes - runningScene_ = nil; - nextScene = nil; - - oldAnimationInterval = animationInterval = 1.0 / kDefaultFPS; - eventHandlers = [[NSMutableArray arrayWithCapacity:8] retain]; - scenesStack_ = [[NSMutableArray arrayWithCapacity:10] retain]; - - // landscape - deviceOrientation_ = CCDeviceOrientationPortrait; - - // FPS - displayFPS = NO; - frames = 0; - - // paused ? - paused = NO; - - // touch events enabled ? - eventsEnabled = YES; - - return self; -} - -- (void) dealloc -{ - CCLOG( @"deallocing %@", self); - -#ifdef FAST_FPS_DISPLAY - [FPSLabel release]; -#endif - [eventHandlers release]; - [runningScene_ release]; - [scenesStack_ release]; - - [super dealloc]; -} - --(void) initGLDefaultValues -{ - // This method SHOULD be called only after openGLView_ was initialized - NSAssert( openGLView_, @"openGLView_ must be initialized"); - - [self setAlphaBlending: YES]; - [self setDepthTest: YES]; - [self setDefaultProjection]; - - // set other opengl default values - glClearColor(0.0f, 0.0f, 0.0f, 1.0f); - -#ifdef FAST_FPS_DISPLAY - FPSLabel = [[LabelAtlas labelAtlasWithString:@"00.0" charMapFile:@"fps_images.png" itemWidth:16 itemHeight:24 startCharMap:'.'] retain]; -#endif -} - -// -// main loop -// -- (void) mainLoop -{ - /* clear window */ - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - /* calculate "global" dt */ - [self calculateDeltaTime]; - if( ! paused ) - [[Scheduler sharedScheduler] tick: dt]; - - - /* to avoid flickr, nextScene MUST be here: after tick and before draw */ - if( nextScene ) - [self setNextScene]; - - glPushMatrix(); - - [self applyLandscape]; - - /* draw the scene */ - [runningScene_ visit]; - if( displayFPS ) - [self showFPS]; - - glPopMatrix(); - - /* swap buffers */ - [openGLView_ swapBuffers]; -} - --(void) calculateDeltaTime -{ - struct timeval now; - - if( gettimeofday( &now, NULL) != 0 ) { - CCLOG(@"error in gettimeofday"); - dt = 0; - return; - } - - // new delta time - if( nextDeltaTimeZero_ ) { - dt = 0; - nextDeltaTimeZero_ = NO; - } else { - dt = (now.tv_sec - lastUpdate.tv_sec) + (now.tv_usec - lastUpdate.tv_usec) / 1000000.0f; - dt = MAX(0,dt); - } - - lastUpdate = now; -} - -#pragma mark Director Scene iPhone Specific - --(void) setPixelFormat: (tPixelFormat) format -{ - if( [self isOpenGLAttached] ) { - NSException* myException = [NSException - exceptionWithName:@"DirectorAlreadyInitialized" - reason:@"Can't change the pixel format after the director was initialized" - userInfo:nil]; - @throw myException; - } - - pixelFormat_ = format; -} - --(void) setDepthBufferFormat: (tDepthBufferFormat) format -{ - if( [self isOpenGLAttached] ) { - NSException* myException = [NSException - exceptionWithName:@"DirectorAlreadyInitialized" - reason:@"Can't change the depth buffer format after the director was initialized" - userInfo:nil]; - @throw myException; - } - - depthBufferFormat_ = format; -} - -#pragma mark Director Scene OpenGL Helper - -- (void) setDefaultProjection -{ -// [self set2Dprojection]; - [self set3Dprojection]; -} - --(void)set2Dprojection -{ - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glOrthof(0, openGLView_.frame.size.width, 0, openGLView_.frame.size.height, -1, 1); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); -} - -// set a 3d projection matrix --(void)set3Dprojection -{ - glViewport(0, 0, openGLView_.frame.size.width, openGLView_.frame.size.height); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - gluPerspective(60, (GLfloat)openGLView_.frame.size.width/openGLView_.frame.size.height, 0.5f, 1500.0f); - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - gluLookAt( openGLView_.frame.size.width/2, openGLView_.frame.size.height/2, [Camera getZEye], - openGLView_.frame.size.width/2, openGLView_.frame.size.height/2, 0, - 0.0f, 1.0f, 0.0f); -} - -- (void) setAlphaBlending: (BOOL) on -{ - if (on) { - glEnable(GL_BLEND); - glBlendFunc(CC_BLEND_SRC, CC_BLEND_DST); - } else - glDisable(GL_BLEND); -} - -- (void) setTexture2D: (BOOL) on -{ - if (on) - glEnable(GL_TEXTURE_2D); - else - glDisable(GL_TEXTURE_2D); -} - -- (void) setDepthTest: (BOOL) on -{ - if (on) { - glClearDepthf(1.0f); - glEnable(GL_DEPTH_TEST); - glDepthFunc(GL_LEQUAL); - glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); - } else - glDisable( GL_DEPTH_TEST ); -} - -#pragma mark Director Integration with a UIKit view - -// is the view currently attached --(BOOL)isOpenGLAttached -{ - return ([openGLView_ superview]!=nil); -} - -// detach or attach to a view or a window --(BOOL)detach -{ - // check if the view is attached - if(![self isOpenGLAttached]) - { - // the view is not attached - NSException* myException = [NSException - exceptionWithName:kccException_OpenGLViewNotAttached - reason:@"Can't detach the OpenGL View, because it is not attached. Attach it first." - userInfo:nil]; - @throw myException; - - return NO; - } - - // remove from the superview - [openGLView_ removeFromSuperview]; - - // check if the view is not attached anymore - if(![self isOpenGLAttached]) - { - return YES; - } - - // the view is still attached - NSException* myException = [NSException - exceptionWithName:kccException_OpenGLViewCantDetach - reason:@"Can't detach the OpenGL View, it is still attached to the superview." - userInfo:nil]; - @throw myException; - - return NO; -} - --(BOOL)attachInWindow:(UIWindow *)window -{ - if([self initOpenGLViewWithView:window withFrame:[window bounds]]) - { - return YES; - } - - return NO; -} - --(BOOL)attachInView:(UIView *)view -{ - if([self initOpenGLViewWithView:view withFrame:[view bounds]]) - { - return YES; - } - - return NO; -} - --(BOOL)attachInView:(UIView *)view withFrame:(CGRect)frame -{ - if([self initOpenGLViewWithView:view withFrame:frame]) - { - return YES; - } - - return NO; -} - --(BOOL)initOpenGLViewWithView:(UIView *)view withFrame:(CGRect)rect -{ - // check if the view is not attached - if([self isOpenGLAttached]) - { - // the view is already attached - NSException* myException = [NSException - exceptionWithName:kccException_OpenGLViewAlreadyAttached - reason:@"Can't re-attach the OpenGL View, because it is already attached. Detach it first." - userInfo:nil]; - @throw myException; - - return NO; - } - - // check if the view is not initialized - if(!openGLView_) - { - // define the pixel format - NSString *pFormat = kEAGLColorFormatRGB565; - GLuint depthFormat = 0; - - if(pixelFormat_==kRGBA8) - pFormat = kEAGLColorFormatRGBA8; - - if(depthBufferFormat_ == kDepthBuffer16) - depthFormat = GL_DEPTH_COMPONENT16_OES; - else if(depthBufferFormat_ == kDepthBuffer24) - depthFormat = GL_DEPTH_COMPONENT24_OES; - - // alloc and init the opengl view - openGLView_ = [[EAGLView alloc] initWithFrame:rect pixelFormat:pFormat depthFormat:depthFormat preserveBackbuffer:NO]; - - // check if the view was alloced and initialized - if(!openGLView_) - { - // the view was not created - NSException* myException = [NSException - exceptionWithName:kccException_OpenGLViewCantInit - reason:@"Could not alloc and init the OpenGL View." - userInfo:nil]; - @throw myException; - - return NO; - } - - // set autoresizing enabled when attaching the glview to another view - [openGLView_ setAutoresizesEAGLSurface:YES]; - - // set the touch delegate of the glview to self - [openGLView_ setTouchDelegate:self]; - } - else - { - // set the (new) frame of the glview - [openGLView_ setFrame:rect]; - } - - // check if the superview has touchs enabled and enable it in our view - if([view isUserInteractionEnabled]) - { - [openGLView_ setUserInteractionEnabled:YES]; - [self setEventsEnabled:YES]; - } - else - { - [openGLView_ setUserInteractionEnabled:NO]; - [self setEventsEnabled:NO]; - } - - // check if multi touches are enabled and set them - if([view isMultipleTouchEnabled]) - { - [openGLView_ setMultipleTouchEnabled:YES]; - } - else - { - [openGLView_ setMultipleTouchEnabled:NO]; - } - - // add the glview to his (new) superview - [view addSubview:openGLView_]; - - // set the background color of the glview - // [backgroundColor setOpenGLClearColor]; - - // check if the glview is attached now - if([self isOpenGLAttached]) - { - [self initGLDefaultValues]; - return YES; - } - - // the glview is not attached, but it should have been - NSException* myException = [NSException - exceptionWithName:kccException_OpenGLViewCantAttach - reason:@"Can't attach the OpenGL View." - userInfo:nil]; - @throw myException; - - return NO; -} - -#pragma mark Director Scene Landscape - -// convert a coordinate from uikit to opengl --(CGPoint)convertCoordinate:(CGPoint)p -{ - int newY = openGLView_.frame.size.height - p.y; - int newX = openGLView_.frame.size.width -p.x; - - CGPoint ret; - switch ( deviceOrientation_) { - case CCDeviceOrientationPortrait: - ret = ccp( p.x, newY ); - break; - case CCDeviceOrientationPortraitUpsideDown: - ret = ccp(newX, p.y); - break; - case CCDeviceOrientationLandscapeLeft: - ret.x = p.y; - ret.y = p.x; - break; - case CCDeviceOrientationLandscapeRight: - ret.x = newY; - ret.y = newX; - break; - } - return ret; -} - -// get the current size of the glview --(CGSize)winSize -{ - CGSize s = openGLView_.frame.size; - if( deviceOrientation_ == CCDeviceOrientationLandscapeLeft || deviceOrientation_ == CCDeviceOrientationLandscapeRight ) { - // swap x,y in landscape mode - s.width = openGLView_.frame.size.height; - s.height = openGLView_.frame.size.width; - } - return s; -} - -// return the current frame size --(CGSize)displaySize -{ - return openGLView_.frame.size; -} - -- (BOOL) landscape -{ - return deviceOrientation_ == CCDeviceOrientationLandscapeLeft; -} - -- (void) setLandscape: (BOOL) on -{ - if( on ) - [self setDeviceOrientation:CCDeviceOrientationLandscapeLeft]; - else - [self setDeviceOrientation:CCDeviceOrientationPortrait]; -} - -- (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: UIInterfaceOrientationPortrait 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) applyLandscape -{ - switch ( deviceOrientation_ ) { - case CCDeviceOrientationPortrait: - // nothing - break; - case CCDeviceOrientationPortraitUpsideDown: - // upside down - glTranslatef(160,240,0); - glRotatef(180,0,0,1); - glTranslatef(-160,-240,0); - break; - case CCDeviceOrientationLandscapeRight: - glTranslatef(160,240,0); - glRotatef(90,0,0,1); - glTranslatef(-240,-160,0); - break; - case CCDeviceOrientationLandscapeLeft: - glTranslatef(160,240,0); - glRotatef(-90,0,0,1); - glTranslatef(-240,-160,0); - break; - } -} - -#pragma mark Director Scene Management - -- (void)runWithScene:(Scene*) scene -{ - NSAssert( scene != nil, @"Argument must be non-nil"); - NSAssert( runningScene_ == nil, @"You can't run an scene if another Scene is running. Use replaceScene or pushScene instead"); - - [self pushScene:scene]; - [self startAnimation]; -} - --(void) replaceScene: (Scene*) scene -{ - NSAssert( scene != nil, @"Argument must be non-nil"); - - NSUInteger index = [scenesStack_ count]; - - [scenesStack_ replaceObjectAtIndex:index-1 withObject:scene]; - nextScene = scene; // nextScene is a weak ref -} - -- (void) pushScene: (Scene*) scene -{ - NSAssert( scene != nil, @"Argument must be non-nil"); - - [scenesStack_ addObject: scene]; - nextScene = scene; // nextScene is a weak ref -} - --(void) popScene -{ - NSAssert( runningScene_ != nil, @"A running Scene is needed"); - - [scenesStack_ removeLastObject]; - NSUInteger c = [scenesStack_ count]; - - if( c == 0 ) { - [self end]; - } else { - nextScene = [scenesStack_ objectAtIndex:c-1]; - } -} - --(void) end -{ - // remove all objects, but don't release it. - // runWithScene might be executed after 'end'. - [scenesStack_ removeAllObjects]; - - [runningScene_ onExit]; - [runningScene_ release]; - runningScene_ = nil; - nextScene = nil; - - // don't release the event handlers - // They are needed in case the director is run again - [eventHandlers removeAllObjects]; - - [self stopAnimation]; - [self detach]; -} - --(void) setNextScene -{ - BOOL runningIsTransition = [runningScene_ isKindOfClass:[TransitionScene class]]; - BOOL newIsTransition = [nextScene isKindOfClass:[TransitionScene class]]; - - // If it is not a transition, call onExit - if( ! newIsTransition ) - [runningScene_ onExit]; - - [runningScene_ release]; - - runningScene_ = [nextScene retain]; - nextScene = nil; - - if( ! runningIsTransition ) { - [runningScene_ onEnter]; - [runningScene_ onTransitionDidFinish]; - } -} - --(void) pause -{ - if( paused ) - return; - - oldAnimationInterval = animationInterval; - - // when paused, don't consume CPU - [self setAnimationInterval:1/4.0]; - paused = YES; -} - --(void) resume -{ - if( ! paused ) - return; - - [self setAnimationInterval: oldAnimationInterval]; - - if( gettimeofday( &lastUpdate, NULL) != 0 ) { - NSException* myException = [NSException - exceptionWithName:@"GetTimeOfDay" - reason:@"GetTimeOfDay abnormal error" - userInfo:nil]; - @throw myException; - } - - paused = NO; - dt = 0; -} - -- (void)startAnimation -{ - [eventHandlers insertObject:[TouchDispatcher sharedDispatcher] atIndex:0]; - - NSAssert( animationTimer == nil, @"animationTimer must be nil. Calling startAnimation twice?"); - - if( gettimeofday( &lastUpdate, NULL) != 0 ) { - NSException* myException = [NSException - exceptionWithName:@"GetTimeOfDay" - reason:@"GetTimeOfDay abnormal error" - userInfo:nil]; - @throw myException; - } - - 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)stopAnimation -{ - [eventHandlers removeObject:[TouchDispatcher sharedDispatcher]]; - - [animationTimer invalidate]; - animationTimer = nil; -} - -- (void)setAnimationInterval:(NSTimeInterval)interval -{ - animationInterval = interval; - - if(animationTimer) { - [self stopAnimation]; - [self startAnimation]; - } -} - -#pragma mark Director Events - --(void) addEventHandler:(id) delegate -{ - NSAssert( delegate != nil, @"Director.addEventHandler: delegate must be non nil"); - [eventHandlers insertObject:delegate atIndex:1]; -} - --(void) removeEventHandler:(id) delegate -{ - NSAssert( delegate != nil, @"Director.removeEventHandler: delegate must be non nil"); - [eventHandlers removeObject:delegate]; -} - -// -// multi touch proxies -// -- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event -{ - if( eventsEnabled ) { - NSArray *copyArray = [eventHandlers copy]; - for( id eventHandler in copyArray ) { - if( [eventHandler respondsToSelector:@selector(ccTouchesBegan:withEvent:)] ) { - if( [eventHandler ccTouchesBegan:touches withEvent:event] == kEventHandled ) - break; - } - } - - [copyArray release]; - } -} - -- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event -{ - if( eventsEnabled ) { - NSArray *copyArray = [eventHandlers copy]; - for( id eventHandler in copyArray ) { - if( [eventHandler respondsToSelector:@selector(ccTouchesMoved:withEvent:)] ) { - if( [eventHandler ccTouchesMoved:touches withEvent:event] == kEventHandled ) - break; - } - } - [copyArray release]; - } -} - -- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event -{ - if( eventsEnabled ) { - NSArray *copyArray = [eventHandlers copy]; - for( id eventHandler in copyArray ) { - if( [eventHandler respondsToSelector:@selector(ccTouchesEnded:withEvent:)] ) { - if( [eventHandler ccTouchesEnded:touches withEvent:event] == kEventHandled ) - break; - } - } - [copyArray release]; - } -} - -- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event -{ - if( eventsEnabled ) { - NSArray *copyArray = [eventHandlers copy]; - for( id eventHandler in copyArray ) { - if( [eventHandler respondsToSelector:@selector(ccTouchesCancelled:withEvent:)] ) { - if( [eventHandler ccTouchesCancelled:touches withEvent:event] == kEventHandled ) - break; - } - } - [copyArray release]; - } -} - - -#ifdef FAST_FPS_DISPLAY - -// display the FPS using a LabelAtlas -// updates the FPS every frame --(void) showFPS -{ - frames++; - accumDt += dt; - - if ( accumDt > 0.1) { - frameRate = frames/accumDt; - frames = 0; - accumDt = 0; - } - - NSString *str = [NSString stringWithFormat:@"%.1f",frameRate]; -// glTranslatef(10.0, 10.0, 0); - [FPSLabel setString:str]; - [FPSLabel draw]; -} -#else -// display the FPS using a manually generated Texture (very slow) -// updates the FPS 3 times per second aprox. --(void) showFPS -{ - frames++; - accumDt += dt; - - if ( accumDt > 0.3) { - frameRate = frames/accumDt; - frames = 0; - accumDt = 0; - } - - NSString *str = [NSString stringWithFormat:@"%.2f",frameRate]; - Texture2D *texture = [[Texture2D alloc] initWithString:str dimensions:CGSizeMake(100,30) alignment:UITextAlignmentLeft fontName:@"Arial" fontSize:24]; - glEnable(GL_TEXTURE_2D); - glEnableClientState( GL_VERTEX_ARRAY); - glEnableClientState( GL_TEXTURE_COORD_ARRAY ); - - glColor4ub(224,224,244,200); - [texture drawAtPoint: ccp(5,2)]; - [texture release]; - - glDisable(GL_TEXTURE_2D); - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_TEXTURE_COORD_ARRAY); -} -#endif - -@end - -#pragma mark - -#pragma mark Director FastDirector - -@implementation FastDirector - -- (id) init -{ - CCLOG(@"Using Fast Director"); - - if(( self = [super init] )) { - 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 -{ - [eventHandlers insertObject:[TouchDispatcher sharedDispatcher] atIndex:0]; - - // XXX: - // XXX: release autorelease objects created - // XXX: between "use fast director" and "runWithScene" - // XXX: - [autoreleasePool release]; - autoreleasePool = nil; - - if ( gettimeofday( &lastUpdate, NULL) != 0 ) { - NSException* myException = [NSException - exceptionWithName:@"GetTimeOfDay" - reason:@"GetTimeOfDay abnormal error" - userInfo:nil]; - @throw myException; - } - - - isRunning = YES; - - SEL selector = @selector(preMainLoop); - NSMethodSignature* sig = [[[Director sharedDirector] class] - instanceMethodSignatureForSelector:selector]; - NSInvocation* invocation = [NSInvocation - invocationWithMethodSignature:sig]; - [invocation setTarget:[Director sharedDirector]]; - [invocation setSelector:selector]; - [invocation performSelectorOnMainThread:@selector(invokeWithTarget:) - withObject:[Director sharedDirector] waitUntilDone:NO]; -} - --(void) preMainLoop -{ - while (isRunning) { - - NSAutoreleasePool *loopPool = [NSAutoreleasePool new]; - - while(CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, TRUE) == kCFRunLoopRunHandledSource); - - if (paused) { - usleep(250000); // Sleep for a quarter of a second (250,000 microseconds) so that the framerate is 4 fps. - } - - [self mainLoop]; - - while(CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, TRUE) == kCFRunLoopRunHandledSource); - - [loopPool release]; - } -} -- (void) stopAnimation -{ - [eventHandlers removeObject:[TouchDispatcher sharedDispatcher]]; - - isRunning = NO; -} - -- (void)setAnimationInterval:(NSTimeInterval)interval -{ - NSLog(@"FastDirectory doesn't support setAnimationInterval, yet"); -} -@end - diff --git a/Support/cocos2d/EaseAction.h b/Support/cocos2d/EaseAction.h deleted file mode 100644 index 80f9500..0000000 --- a/Support/cocos2d/EaseAction.h +++ /dev/null @@ -1,72 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2008, 2009 Jason Booth - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - -#import "IntervalAction.h" - -/** Base class for Easing actions - */ -@interface EaseAction : IntervalAction -{ - IntervalAction * other; -} -/** creates the action */ -+(id) actionWithAction: (IntervalAction*) action; -/** initializes the action */ --(id) initWithAction: (IntervalAction*) action; -@end - -/** Base class for Easing actions with rate parameters - */ -@interface EaseRateAction : EaseAction -{ - float rate; -} -/** rate value for the actions */ -@property (readwrite,assign) float rate; -/** Creates the action with the inner action and the rate parameter */ -+(id) actionWithAction: (IntervalAction*) action rate:(float)rate; -/** Initializes the action with the inner action and the rate parameter */ --(id) initWithAction: (IntervalAction*) action rate:(float)rate; -@end - -/** EaseIn action with a rate - */ -@interface EaseIn : EaseRateAction {} @end - -/** EaseOut action with a rate - */ -@interface EaseOut : EaseRateAction {} @end - -/** EaseInOut action with a rate - */ -@interface EaseInOut : EaseRateAction {} @end - -/** Ease Exponential In - */ -@interface EaseExponentialIn : EaseAction {} @end -/** Ease Exponential Out - */ -@interface EaseExponentialOut : EaseAction {} @end -/** Ease Exponential InOut - */ -@interface EaseExponentialInOut : EaseAction {} @end -/** Ease Sine In - */ -@interface EaseSineIn : EaseAction {} @end -/** Ease Sine Out - */ -@interface EaseSineOut : EaseAction {} @end -/** Ease Sine InOut - */ -@interface EaseSineInOut : EaseAction {} @end diff --git a/Support/cocos2d/EaseAction.m b/Support/cocos2d/EaseAction.m deleted file mode 100644 index 6f204c2..0000000 --- a/Support/cocos2d/EaseAction.m +++ /dev/null @@ -1,230 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2008, 2009 Jason Booth - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - -#import "EaseAction.h" - -// -// EaseAction -// -@implementation EaseAction - -+(id) actionWithAction: (IntervalAction*) action -{ - return [[[self alloc] initWithAction: action] autorelease ]; -} - --(id) initWithAction: (IntervalAction*) action -{ - NSAssert( action!=nil, @"Ease: arguments must be non-nil"); - - if( !(self=[super initWithDuration: action.duration]) ) - return nil; - - other = [action retain]; - return self; -} - --(id) copyWithZone: (NSZone*) zone -{ - Action *copy = [[[self class] allocWithZone:zone] initWithAction:[[other copy] autorelease]]; - return copy; -} - --(void) dealloc -{ - [other release]; - [super dealloc]; -} - --(void) start -{ - [super start]; - other.target = target; - [other start]; -} - --(void) update: (ccTime) t -{ - [other update: t]; -} - --(IntervalAction*) reverse -{ - return [[self class] actionWithAction: [other reverse]]; -} -@end - - -// -// EaseRateAction -// -@implementation EaseRateAction -@synthesize rate; -+(id) actionWithAction: (IntervalAction*) action rate:(float)aRate -{ - return [[[self alloc] initWithAction: action rate:aRate] autorelease ]; -} - --(id) initWithAction: (IntervalAction*) action rate:(float)aRate -{ - if( (self=[super initWithAction:action ]) ) { - self.rate = aRate; - } - return self; -} - --(id) copyWithZone: (NSZone*) zone -{ - Action *copy = [[[self class] allocWithZone:zone] initWithAction:[[other copy] autorelease] rate:rate]; - return copy; -} - --(void) dealloc -{ - [super dealloc]; -} - --(IntervalAction*) reverse -{ - return [[self class] actionWithAction: [other reverse] rate:1/rate]; -} -@end - -// -// EeseIn -// -@implementation EaseIn --(void) update: (ccTime) t -{ - [other update: powf(t,rate)]; -} -@end - -// -// EaseOut -// -@implementation EaseOut --(void) update: (ccTime) t -{ - [other update: powf(t,1/rate)]; -} -@end - -// -// EaseInOut -// -@implementation EaseInOut --(void) update: (ccTime) t -{ - int sign =1; - int r = (int) rate; - if (r % 2 == 0) - sign = -1; - - if ((t*=2) < 1) - [other update: 0.5f * powf (t, rate)]; - else - [other update: sign*0.5f * (powf (t-2, rate) + sign*2)]; -} - -// InOut and OutIn are symmetrical --(IntervalAction*) reverse -{ - return [[self class] actionWithAction: [other reverse] rate:rate]; -} - -@end - -// -// EaseExponentialIn -// -@implementation EaseExponentialIn --(void) update: (ccTime) t -{ - [other update: (t==0) ? 0 : powf(2, 10 * (t/1 - 1)) - 1 * 0.001f]; -} -- (IntervalAction*) reverse -{ - return [EaseExponentialOut actionWithAction: [other reverse]]; -} -@end - -// -// EaseExponentialOut -// -@implementation EaseExponentialOut --(void) update: (ccTime) t -{ - [other update: (t==1) ? 1 : (-powf(2, -10 * t/1) + 1)]; -} -- (IntervalAction*) reverse -{ - return [EaseExponentialIn actionWithAction: [other reverse]]; -} -@end - -// -// EaseExponentialInOut -// -@implementation EaseExponentialInOut --(void) update: (ccTime) t -{ - if ((t/=0.5f) < 1) - t = 0.5f * powf(2, 10 * (t - 1)); - else - t = 0.5f * (-powf(2, -10 * --t) + 2); - [other update:t]; -} -@end - -// -// EaseSineIn -// -@implementation EaseSineIn --(void) update: (ccTime) t -{ - [other update:-1*cosf(t * (float)M_PI_2) +1]; -} -- (IntervalAction*) reverse -{ - return [EaseSineOut actionWithAction: [other reverse]]; -} -@end - -// -// EaseSineOut -// -@implementation EaseSineOut --(void) update: (ccTime) t -{ - [other update:sinf(t * (float)M_PI_2)]; -} -- (IntervalAction*) reverse -{ - return [EaseSineIn actionWithAction: [other reverse]]; -} -@end - -// -// EaseSineInOut -// -@implementation EaseSineInOut --(void) update: (ccTime) t -{ - [other update:-0.5f*(cosf( (float)M_PI*t) - 1)]; -} -@end - - - diff --git a/Support/cocos2d/Grabber.h b/Support/cocos2d/Grabber.h deleted file mode 100644 index ad4e601..0000000 --- a/Support/cocos2d/Grabber.h +++ /dev/null @@ -1,32 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2009 On-Core - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - -#import -#import -#import - -@class Texture2D; - -/** FBO class that grabs the the contents of the screen */ -@interface Grabber : NSObject -{ - GLuint fbo; - GLint oldFBO; -} - --(void)grab:(Texture2D*)texture; --(void)beforeRender:(Texture2D*)texture; --(void)afterRender:(Texture2D*)texture; - -@end diff --git a/Support/cocos2d/Grabber.m b/Support/cocos2d/Grabber.m deleted file mode 100644 index 29b98c9..0000000 --- a/Support/cocos2d/Grabber.m +++ /dev/null @@ -1,74 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2009 On-Core - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - -#import "Grabber.h" -#import "ccMacros.h" - -#import "Support/Texture2D.h" -#import "Support/OpenGL_Internal.h" - -@implementation Grabber - --(id) init -{ - if(( self = [super init] )) { - // generate FBO - glGenFramebuffersOES(1, &fbo); - } - return self; -} --(void)grab:(Texture2D*)texture -{ - glGetIntegerv(GL_FRAMEBUFFER_BINDING_OES, &oldFBO); - - // bind - glBindFramebufferOES(GL_FRAMEBUFFER_OES, fbo); - - // associate texture with FBO - glFramebufferTexture2DOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_TEXTURE_2D, texture.name, 0); - - // check if it worked (probably worth doing :) ) - GLuint status = glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES); - if (status != GL_FRAMEBUFFER_COMPLETE_OES) - { - [NSException raise:@"Frame Grabber" format:@"Could not attach texture to framebuffer"]; - } - - glBindFramebufferOES(GL_FRAMEBUFFER_OES, oldFBO); -} - --(void)beforeRender:(Texture2D*)texture -{ - glGetIntegerv(GL_FRAMEBUFFER_BINDING_OES, &oldFBO); - glBindFramebufferOES(GL_FRAMEBUFFER_OES, fbo); - - // BUG XXX: doesn't work with RGB565. - glClearColor(0.0f,0.0f,0.0f,0.0f); - - glClear(GL_COLOR_BUFFER_BIT); -} - --(void)afterRender:(Texture2D*)texture -{ - glBindFramebufferOES(GL_FRAMEBUFFER_OES, oldFBO); -} - -- (void) dealloc -{ - CCLOG( @"deallocing %@", self); - glDeleteFramebuffersOES(1, &fbo); - [super dealloc]; -} - -@end diff --git a/Support/cocos2d/Grid.h b/Support/cocos2d/Grid.h deleted file mode 100644 index ee3c09f..0000000 --- a/Support/cocos2d/Grid.h +++ /dev/null @@ -1,108 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2009 On-Core - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - -#import - -#import "CocosNode.h" -#import "Camera.h" -#import "ccTypes.h" - -@class Texture2D; -@class Grabber; - -/** Base class for other - */ -@interface GridBase : NSObject -{ - BOOL active; - int reuseGrid; - ccGridSize gridSize; - Texture2D * texture; - CGPoint step; - Grabber * grabber; -} - -@property BOOL active; -@property int reuseGrid; -@property (readonly) ccGridSize gridSize; -@property CGPoint step; -@property (nonatomic, retain) Texture2D *texture; -@property (nonatomic, retain) Grabber *grabber; - --(id)initWithSize:(ccGridSize)gridSize; --(void)beforeDraw; --(void)afterDraw:(Camera*)camera; --(void)blit; --(void)reuse; - -@end - -//////////////////////////////////////////////////////////// - -/** - Grid3D is a 3D grid implementation. Each vertex has 3 dimensions: x,y,z - */ -@interface Grid3D : GridBase -{ - GLvoid *texCoordinates; - GLvoid *vertices; - GLvoid *originalVertices; - GLushort *indices; -} - -/** creates a Grid3D (non-tiled) grid with a grid size */ -+(id)gridWithSize:(ccGridSize)gridSize; -/** initizlies a Grid3D (non-tiled) grid with a grid size */ --(id)initWithSize:(ccGridSize)gridSize; - -/** returns the vertex at a given position */ --(ccVertex3F)vertex:(ccGridSize)pos; -/** returns the original (non-transformed) vertex at a given position */ --(ccVertex3F)originalVertex:(ccGridSize)pos; -/** sets a new vertex at a given position */ --(void)setVertex:(ccGridSize)pos vertex:(ccVertex3F)vertex; - --(void)calculateVertexPoints; - -@end - -//////////////////////////////////////////////////////////// - -/** - TiledGrid3D is a 3D grid implementation. It differs from Grid3D in that - the tiles can be separated from the grid. -*/ -@interface TiledGrid3D : GridBase -{ - GLvoid *texCoordinates; - GLvoid *vertices; - GLvoid *originalVertices; - GLushort *indices; -} - -/** creates a TiledGrid3D with a grid size */ -+(id)gridWithSize:(ccGridSize)gridSize; -/** initializes a TiledGrid3D with a grid size */ --(id)initWithSize:(ccGridSize)gridSize; - -/** returns the tile at the given position */ --(ccQuad3)tile:(ccGridSize)pos; -/** returns the original tile (untransformed) at the given position */ --(ccQuad3)originalTile:(ccGridSize)pos; -/** sets a new tile */ --(void)setTile:(ccGridSize)pos coords:(ccQuad3)coords; - --(void)calculateVertexPoints; - -@end diff --git a/Support/cocos2d/Grid.m b/Support/cocos2d/Grid.m deleted file mode 100644 index 944bb07..0000000 --- a/Support/cocos2d/Grid.m +++ /dev/null @@ -1,480 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2009 On-Core - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - -#import "ccMacros.h" -#import "Grid.h" -#import "Texture2D.h" -#import "Director.h" -#import "Grabber.h" - -#import "Support/glu.h" -#import "Support/CGPointExtension.h" - -@implementation GridBase - -@synthesize active; -@synthesize reuseGrid; -@synthesize texture; -@synthesize grabber; -@synthesize gridSize; -@synthesize step; - -#define kTextureSize 512 --(id)initWithSize:(ccGridSize)gSize -{ - if ( (self = [super init] ) ) - { - active = NO; - reuseGrid = 0; - gridSize = gSize; - - CGSize win = [[Director sharedDirector] winSize]; - - if ( self.texture == nil ) - { - Texture2DPixelFormat format = [Director sharedDirector].pixelFormat == kRGB565 ? kTexture2DPixelFormat_RGB565 : kTexture2DPixelFormat_RGBA8888; - - void *data = malloc((int)(kTextureSize * kTextureSize * 4)); - memset(data, 0, (int)(kTextureSize * kTextureSize * 4)); - - texture = [[Texture2D alloc] initWithData:data pixelFormat:format pixelsWide:kTextureSize pixelsHigh:kTextureSize contentSize:win]; - free( data ); - } - - grabber = [[Grabber alloc] init]; - [grabber grab:self.texture]; - - step.x = win.width / gridSize.x; - step.y = win.height / gridSize.y; - } - - return self; -} -- (NSString*) description -{ - return [NSString stringWithFormat:@"<%@ = %08X | Dimensions = %ix%i>", [self class], self, gridSize.x, gridSize.y]; -} - -- (void) dealloc -{ - CCLOG( @"deallocing %@", self); - - [texture release]; - [grabber release]; - [super dealloc]; -} - - -// This routine can be merged with Director --(void)applyLandscape -{ - ccDeviceOrientation orientation = [[Director sharedDirector] deviceOrientation]; - - switch (orientation) { - case CCDeviceOrientationLandscapeLeft: - glTranslatef(160,240,0); - glRotatef(-90,0,0,1); - glTranslatef(-240,-160,0); - break; - case CCDeviceOrientationLandscapeRight: - glTranslatef(160,240,0); - glRotatef(90,0,0,1); - glTranslatef(-240,-160,0); - break; - case CCDeviceOrientationPortraitUpsideDown: - glTranslatef(160,240,0); - glRotatef(180,0,0,1); - glTranslatef(-160,-240,0); - break; - default: - break; - } -} - --(void)set2DProjection -{ - CGSize winSize = [[Director sharedDirector] winSize]; - - glLoadIdentity(); - glViewport(0, 0, winSize.width, winSize.height); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glOrthof(0, winSize.width, 0, winSize.height, -100, 100); - glMatrixMode(GL_MODELVIEW); -} - -// This routine can be merged with Director --(void)set3DProjection -{ - CGSize winSize = [[Director sharedDirector] displaySize]; - - glViewport(0, 0, winSize.width, winSize.height); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - gluPerspective(60, (GLfloat)winSize.width/winSize.height, 0.5f, 1500.0f); - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - gluLookAt( winSize.width/2, winSize.height/2, [Camera getZEye], - winSize.width/2, winSize.height/2, 0, - 0.0f, 1.0f, 0.0f - ); -} - --(void)beforeDraw -{ - [self set2DProjection]; - [grabber beforeRender:self.texture]; -} - --(void)afterDraw:(Camera *)camera -{ - [grabber afterRender:self.texture]; - - [self set3DProjection]; - [self applyLandscape]; - - BOOL cDirty = camera.dirty; - camera.dirty = YES; - [camera locate]; - camera.dirty = cDirty; - - glEnable(GL_TEXTURE_2D); - glBindTexture(GL_TEXTURE_2D, self.texture.name); - - [self blit]; - - glDisable(GL_TEXTURE_2D); -} - --(void)blit -{ - [NSException raise:@"GridBase" format:@"Abstract class needs implementation"]; -} - --(void)reuse -{ - [NSException raise:@"GridBase" format:@"Abstract class needs implementation"]; -} - -@end - -//////////////////////////////////////////////////////////// - -@implementation Grid3D - -+(id)gridWithSize:(ccGridSize)gridSize -{ - return [[[Grid3D alloc] initWithSize:gridSize] autorelease]; -} - --(id)initWithSize:(ccGridSize)gSize -{ - if ( (self = [super initWithSize:gSize] ) ) - { - [self calculateVertexPoints]; - } - - return self; -} - --(void)dealloc -{ - free(texCoordinates); - free(vertices); - free(indices); - free(originalVertices); - [super dealloc]; -} - --(void)blit -{ - int n = gridSize.x * gridSize.y; - - glEnableClientState( GL_VERTEX_ARRAY); - glEnableClientState( GL_TEXTURE_COORD_ARRAY ); - - glVertexPointer(3, GL_FLOAT, 0, vertices); - glTexCoordPointer(2, GL_FLOAT, 0, texCoordinates); - glDrawElements(GL_TRIANGLES, n*6, GL_UNSIGNED_SHORT, indices); - - glDisableClientState(GL_VERTEX_ARRAY ); - glDisableClientState( GL_TEXTURE_COORD_ARRAY ); -} - --(void)calculateVertexPoints -{ - float width = (float)self.texture.pixelsWide; - float height = (float)self.texture.pixelsHigh; - - int x, y, i; - - vertices = malloc((gridSize.x+1)*(gridSize.y+1)*sizeof(ccVertex3F)); - originalVertices = malloc((gridSize.x+1)*(gridSize.y+1)*sizeof(ccVertex3F)); - texCoordinates = malloc((gridSize.x+1)*(gridSize.y+1)*sizeof(CGPoint)); - indices = malloc(gridSize.x*gridSize.y*sizeof(GLushort)*6); - - float *vertArray = (float*)vertices; - float *texArray = (float*)texCoordinates; - GLushort *idxArray = (GLushort *)indices; - - for( y = 0; y < (gridSize.y+1); y++ ) - { - for( x = 0; x < (gridSize.x+1); x++ ) - { - int idx = (y * (gridSize.x+1)) + x; - - vertArray[idx*3] = -1; - vertArray[idx*3+1] = -1; - vertArray[idx*3+2] = -1; - texArray[idx*2] = -1; - texArray[idx*2+1] = -1; - } - } - - for( x = 0; x < gridSize.x; x++ ) - { - for( y = 0; y < gridSize.y; y++ ) - { - int idx = (y * gridSize.x) + x; - - float x1 = x * step.x; - float x2 = x1 + step.x; - float y1 = y * step.y; - float y2 = y1 + step.y; - - GLushort a = x * (gridSize.y+1) + y; - GLushort b = (x+1) * (gridSize.y+1) + y; - GLushort c = (x+1) * (gridSize.y+1) + (y+1); - GLushort d = x * (gridSize.y+1) + (y+1); - - GLushort tempidx[6] = { a, b, d, b, c, d }; - - memcpy(&idxArray[6*idx], tempidx, 6*sizeof(GLushort)); - - int l1[4] = { a*3, b*3, c*3, d*3 }; - ccVertex3F e = {x1,y1,0}; - ccVertex3F f = {x2,y1,0}; - ccVertex3F g = {x2,y2,0}; - ccVertex3F h = {x1,y2,0}; - - ccVertex3F l2[4] = { e, f, g, h }; - - int tex1[4] = { a*2, b*2, c*2, d*2 }; - CGPoint tex2[4] = { ccp(x1,y1), ccp(x2,y1), ccp(x2,y2), ccp(x1,y2) }; - - for( i = 0; i < 4; i++ ) - { - vertArray[ l1[i] ] = l2[i].x; - vertArray[ l1[i] + 1 ] = l2[i].y; - vertArray[ l1[i] + 2 ] = l2[i].z; - - texArray[ tex1[i] ] = tex2[i].x / width; - texArray[ tex1[i] + 1 ] = tex2[i].y / height; - } - } - } - - memcpy(originalVertices, vertices, (gridSize.x+1)*(gridSize.y+1)*sizeof(ccVertex3F)); -} - --(ccVertex3F)vertex:(ccGridSize)pos -{ - int index = (pos.x * (gridSize.y+1) + pos.y) * 3; - float *vertArray = (float *)vertices; - - ccVertex3F vert = { vertArray[index], vertArray[index+1], vertArray[index+2] }; - - return vert; -} - --(ccVertex3F)originalVertex:(ccGridSize)pos -{ - int index = (pos.x * (gridSize.y+1) + pos.y) * 3; - float *vertArray = (float *)originalVertices; - - ccVertex3F vert = { vertArray[index], vertArray[index+1], vertArray[index+2] }; - - return vert; -} - --(void)setVertex:(ccGridSize)pos vertex:(ccVertex3F)vertex -{ - int index = (pos.x * (gridSize.y+1) + pos.y) * 3; - float *vertArray = (float *)vertices; - vertArray[index] = vertex.x; - vertArray[index+1] = vertex.y; - vertArray[index+2] = vertex.z; -} - --(void)reuse -{ - if ( reuseGrid > 0 ) - { - memcpy(originalVertices, vertices, (gridSize.x+1)*(gridSize.y+1)*sizeof(ccVertex3F)); - reuseGrid--; - } -} - -@end - -//////////////////////////////////////////////////////////// - -@implementation TiledGrid3D - -+(id)gridWithSize:(ccGridSize)gridSize -{ - return [[[TiledGrid3D alloc] initWithSize:gridSize] autorelease]; -} - --(id)initWithSize:(ccGridSize)gSize -{ - if ( (self = [super initWithSize:gSize] ) ) - { - [self calculateVertexPoints]; - } - - return self; -} - --(void)dealloc -{ - free(texCoordinates); - free(vertices); - free(indices); - free(originalVertices); - [super dealloc]; -} - --(void)blit -{ - int n = gridSize.x * gridSize.y; - - glEnableClientState( GL_VERTEX_ARRAY); - glEnableClientState( GL_TEXTURE_COORD_ARRAY ); - - glVertexPointer(3, GL_FLOAT, 0, vertices); - glTexCoordPointer(2, GL_FLOAT, 0, texCoordinates); - glDrawElements(GL_TRIANGLES, n*6, GL_UNSIGNED_SHORT, indices); - - glDisableClientState(GL_VERTEX_ARRAY ); - glDisableClientState( GL_TEXTURE_COORD_ARRAY ); -} - --(void)calculateVertexPoints -{ - float width = (float)self.texture.pixelsWide; - float height = (float)self.texture.pixelsHigh; - - int numQuads = gridSize.x * gridSize.y; - - vertices = malloc(numQuads*12*sizeof(GLfloat)); - originalVertices = malloc(numQuads*12*sizeof(GLfloat)); - texCoordinates = malloc(numQuads*8*sizeof(GLfloat)); - indices = malloc(numQuads*6*sizeof(GLushort)); - - float *vertArray = (float*)vertices; - float *texArray = (float*)texCoordinates; - GLushort *idxArray = (GLushort *)indices; - - int x, y; - - for( x = 0; x < gridSize.x; x++ ) - { - for( y = 0; y < gridSize.y; y++ ) - { - float x1 = x * step.x; - float x2 = x1 + step.x; - float y1 = y * step.y; - float y2 = y1 + step.y; - - *vertArray++ = x1; - *vertArray++ = y1; - *vertArray++ = 0; - *vertArray++ = x2; - *vertArray++ = y1; - *vertArray++ = 0; - *vertArray++ = x1; - *vertArray++ = y2; - *vertArray++ = 0; - *vertArray++ = x2; - *vertArray++ = y2; - *vertArray++ = 0; - - *texArray++ = x1 / width; - *texArray++ = y1 / height; - *texArray++ = x2 / width; - *texArray++ = y1 / height; - *texArray++ = x1 / width; - *texArray++ = y2 / height; - *texArray++ = x2 / width; - *texArray++ = y2 / height; - } - } - - for( x = 0; x < numQuads; x++) - { - idxArray[x*6+0] = x*4+0; - idxArray[x*6+1] = x*4+1; - idxArray[x*6+2] = x*4+2; - - idxArray[x*6+3] = x*4+1; - idxArray[x*6+4] = x*4+2; - idxArray[x*6+5] = x*4+3; - } - - memcpy(originalVertices, vertices, numQuads*12*sizeof(GLfloat)); -} - --(void)setTile:(ccGridSize)pos coords:(ccQuad3)coords -{ - int idx = (gridSize.y * pos.x + pos.y) * 4 * 3; - float *vertArray = (float*)vertices; - memcpy(&vertArray[idx], &coords, sizeof(ccQuad3)); -} - --(ccQuad3)originalTile:(ccGridSize)pos -{ - int idx = (gridSize.y * pos.x + pos.y) * 4 * 3; - float *vertArray = (float*)originalVertices; - - ccQuad3 ret; - memcpy(&ret, &vertArray[idx], sizeof(ccQuad3)); - - return ret; -} - --(ccQuad3)tile:(ccGridSize)pos -{ - int idx = (gridSize.y * pos.x + pos.y) * 4 * 3; - float *vertArray = (float*)vertices; - - ccQuad3 ret; - memcpy(&ret, &vertArray[idx], sizeof(ccQuad3)); - - return ret; -} - --(void)reuse -{ - if ( reuseGrid > 0 ) - { - int numQuads = gridSize.x * gridSize.y; - - memcpy(originalVertices, vertices, numQuads*12*sizeof(GLfloat)); - reuseGrid--; - } -} - -@end diff --git a/Support/cocos2d/GridAction.m b/Support/cocos2d/GridAction.m deleted file mode 100644 index 7610786..0000000 --- a/Support/cocos2d/GridAction.m +++ /dev/null @@ -1,345 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2009 On-Core - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - -#import "GridAction.h" -#import "Director.h" - -@implementation GridAction - -@synthesize gridSize; - -+(id) actionWithSize:(ccGridSize)size duration:(ccTime)d -{ - return [[[self alloc] initWithSize:size duration:d ] autorelease]; -} - --(id) initWithSize:(ccGridSize)gSize duration:(ccTime)d -{ - if ( (self = [super initWithDuration:d]) ) - { - gridSize = gSize; - } - - return self; -} - --(void)start -{ - [super start]; - - GridBase *newgrid = [self grid]; - - if ( target.grid && target.grid.reuseGrid > 0 ) - { - if ( target.grid.active && target.grid.gridSize.x == gridSize.x && target.grid.gridSize.y == gridSize.y && [target.grid isKindOfClass:[newgrid class]] ) - { - [target.grid reuse]; - } - else - { - [NSException raise:@"GridBase" format:@"Cannot reuse grid"]; - } - } - else - { - if ( target.grid && target.grid.active ) - target.grid.active = NO; - target.grid = newgrid; - target.grid.active = YES; - } -} - --(GridBase *)grid -{ - [NSException raise:@"GridBase" format:@"Abstract class needs implementation"]; - return nil; -} - -- (IntervalAction*) reverse -{ - return [ReverseTime actionWithAction:self]; -} -@end - -//////////////////////////////////////////////////////////// - -@implementation Grid3DAction - --(GridBase *)grid -{ - return [Grid3D gridWithSize:gridSize]; -} - --(ccVertex3F)vertex:(ccGridSize)pos -{ - Grid3D *g = (Grid3D *)target.grid; - return [g vertex:pos]; -} - --(ccVertex3F)originalVertex:(ccGridSize)pos -{ - Grid3D *g = (Grid3D *)target.grid; - return [g originalVertex:pos]; -} - --(void)setVertex:(ccGridSize)pos vertex:(ccVertex3F)vertex -{ - Grid3D *g = (Grid3D *)target.grid; - return [g setVertex:pos vertex:vertex]; -} -@end - -//////////////////////////////////////////////////////////// - -@implementation TiledGrid3DAction - --(GridBase *)grid -{ - return [TiledGrid3D gridWithSize:gridSize]; -} - --(ccQuad3)tile:(ccGridSize)pos -{ - TiledGrid3D *g = (TiledGrid3D *)target.grid; - return [g tile:pos]; -} - --(ccQuad3)originalTile:(ccGridSize)pos -{ - TiledGrid3D *g = (TiledGrid3D *)target.grid; - return [g originalTile:pos]; -} - --(void)setTile:(ccGridSize)pos coords:(ccQuad3)coords -{ - TiledGrid3D *g = (TiledGrid3D *)target.grid; - [g setTile:pos coords:coords]; -} - -@end - -//////////////////////////////////////////////////////////// - -@interface IntervalAction (Amplitude) --(void)setAmplitudeRate:(CGFloat)amp; --(CGFloat)getAmplitudeRate; -@end - -@implementation IntervalAction (Amplitude) --(void)setAmplitudeRate:(CGFloat)amp -{ - [NSException raise:@"IntervalAction (Amplitude)" format:@"Abstract class needs implementation"]; -} - --(CGFloat)getAmplitudeRate -{ - [NSException raise:@"IntervalAction (Amplitude)" format:@"Abstract class needs implementation"]; - return 0; -} -@end - -//////////////////////////////////////////////////////////// - -@implementation AccelDeccelAmplitude - -@synthesize rate; - -+(id)actionWithAction:(Action*)action duration:(ccTime)d -{ - return [[[self alloc] initWithAction:action duration:d ] autorelease]; -} - --(id)initWithAction:(Action *)action duration:(ccTime)d -{ - if ( (self = [super initWithDuration:d]) ) - { - rate = 1.0f; - other = [action retain]; - } - - return self; -} - --(void)dealloc -{ - [other release]; - [super dealloc]; -} - --(void)start -{ - [super start]; - other.target = self.target; - [other start]; -} - --(void) update: (ccTime) time; -{ - float f = time*2; - - if (f > 1) - { - f -= 1; - f = 1 - f; - } - - [other setAmplitudeRate:powf(f, rate)]; - [other update:time]; -} - -- (IntervalAction*) reverse -{ - return [AccelDeccelAmplitude actionWithAction:[other reverse] duration:self.duration]; -} - -@end - -//////////////////////////////////////////////////////////// - -@implementation AccelAmplitude - -@synthesize rate; - -+(id)actionWithAction:(Action*)action duration:(ccTime)d -{ - return [[[self alloc] initWithAction:action duration:d ] autorelease]; -} - --(id)initWithAction:(Action *)action duration:(ccTime)d -{ - if ( (self = [super initWithDuration:d]) ) - { - rate = 1.0f; - other = [action retain]; - } - - return self; -} - --(void)dealloc -{ - [other release]; - [super dealloc]; -} - --(void)start -{ - [super start]; - other.target = self.target; - [other start]; -} - --(void) update: (ccTime) time; -{ - [other setAmplitudeRate:powf(time, rate)]; - [other update:time]; -} - -- (IntervalAction*) reverse -{ - return [AccelAmplitude actionWithAction:[other reverse] duration:self.duration]; -} - -@end - -//////////////////////////////////////////////////////////// - -@implementation DeccelAmplitude - -@synthesize rate; - -+(id)actionWithAction:(Action*)action duration:(ccTime)d -{ - return [[[self alloc] initWithAction:action duration:d ] autorelease]; -} - --(id)initWithAction:(Action *)action duration:(ccTime)d -{ - if ( (self = [super initWithDuration:d]) ) - { - rate = 1.0f; - other = [action retain]; - } - - return self; -} - --(void)dealloc -{ - [other release]; - [super dealloc]; -} - --(void)start -{ - [super start]; - other.target = self.target; - [other start]; -} - --(void) update: (ccTime) time; -{ - [other setAmplitudeRate:powf((1-time), rate)]; - [other update:time]; -} - -- (IntervalAction*) reverse -{ - return [DeccelAmplitude actionWithAction:[other reverse] duration:self.duration]; -} - -@end - -//////////////////////////////////////////////////////////// - -@implementation StopGrid - --(void)start -{ - [super start]; - - if ( self.target.grid && self.target.grid.active ) - self.target.grid.active = NO; -} - -@end - -//////////////////////////////////////////////////////////// - -@implementation ReuseGrid - -+(id)actionWithTimes:(int)times -{ - return [[[self alloc] initWithTimes:times ] autorelease]; -} - --(id)initWithTimes:(int)times -{ - if ( (self = [super init]) ) - { - t = times; - } - - return self; -} - --(void)start -{ - [super start]; - - if ( self.target.grid && self.target.grid.active ) - self.target.grid.reuseGrid += t; -} - -@end diff --git a/Support/cocos2d/InstantAction.h b/Support/cocos2d/InstantAction.h deleted file mode 100644 index 0ac3d9a..0000000 --- a/Support/cocos2d/InstantAction.h +++ /dev/null @@ -1,95 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2008,2009 Ricardo Quesada - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - - -#import - -#import "Action.h" - -/** Instant actions are immediate actions. They don't have a duration like - the Interval Actions. -*/ -@interface InstantAction : FiniteTimeAction -{} -@end - -/** Show the node - */ - @interface Show : InstantAction -{ -} -@end - -/** Hide the node - */ -@interface Hide : InstantAction -{ -} -@end - -/** Toggles the visibility of a node - */ -@interface ToggleVisibility : InstantAction -{ -} -@end - -/** Places the node in a certain position - */ -@interface Place : InstantAction -{ - CGPoint position; -} -/** creates a Place action with a position */ -+(id) actionWithPosition: (CGPoint) pos; -/** Initializes a Place action with a position */ --(id) initWithPosition: (CGPoint) pos; -@end - -/** Calls a 'callback' - */ -@interface CallFunc : InstantAction -{ - id targetCallback; - SEL selector; -} -/** creates the action with the callback */ -+(id) actionWithTarget: (id) t selector:(SEL) s; -/** initializes the action with the callback */ --(id) initWithTarget: (id) t selector:(SEL) s; -/** exeuctes the callback */ --(void) execute; -@end - -/** Calls a 'callback' with the node as the first argument - N means Node - */ -@interface CallFuncN : CallFunc -{ -} -@end - -/** Calls a 'callback' with the node as the first argument and the 2nd argument is data - * ND means: Node Data - */ -@interface CallFuncND : CallFuncN -{ - void *data; - NSInvocation *invocation; -} -/** creates the action with the callback and the data to pass as an argument */ -+(id) actionWithTarget: (id) t selector:(SEL) s data:(void*)d; -/** initializes the action with the callback and the data to pass as an argument */ --(id) initWithTarget:(id) t selector:(SEL) s data:(void*) d; -@end diff --git a/Support/cocos2d/InstantAction.m b/Support/cocos2d/InstantAction.m deleted file mode 100644 index 513a270..0000000 --- a/Support/cocos2d/InstantAction.m +++ /dev/null @@ -1,221 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2008,2009 Ricardo Quesada - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - - -#import "InstantAction.h" -#import "CocosNode.h" - -// -// InstantAction -// -@implementation InstantAction - --(id) init -{ - if( (self=[super init]) ) - duration = 0; - return self; -} - --(id) copyWithZone: (NSZone*) zone -{ - InstantAction *copy = [[[self class] allocWithZone: zone] init]; - return copy; -} - -- (BOOL) isDone -{ - return YES; -} --(void) step: (ccTime) dt -{ - [self update: 1]; -} --(void) update: (ccTime) t -{ - // ignore -} --(FiniteTimeAction*) reverse -{ - return [[self copy] autorelease]; -} -@end - -// -// Show -// -@implementation Show --(void) start -{ - [super start]; - target.visible = YES; -} --(FiniteTimeAction*) reverse -{ - return [Hide action]; -} -@end - -// -// Hide -// -@implementation Hide --(void) start -{ - [super start]; - target.visible = NO; -} --(FiniteTimeAction*) reverse -{ - return [Show action]; -} -@end - -// -// ToggleVisibility -// -@implementation ToggleVisibility --(void) start -{ - [super start]; - target.visible = ! target.visible; -} -@end - -// -// Place -// -@implementation Place -+(id) actionWithPosition: (CGPoint) pos -{ - return [[[self alloc]initWithPosition:pos]autorelease]; -} - --(id) initWithPosition: (CGPoint) pos -{ - if( (self=[super init]) ) - position = pos; - return self; -} - --(id) copyWithZone: (NSZone*) zone -{ - InstantAction *copy = [[[self class] allocWithZone: zone] initWithPosition: position]; - return copy; -} - --(void) start -{ - [super start]; - target.position = position; -} -@end - -// -// CallFunc -// -@implementation CallFunc -+(id) actionWithTarget: (id) t selector:(SEL) s -{ - return [[[self alloc] initWithTarget: t selector: s] autorelease]; -} - --(id) initWithTarget: (id) t selector:(SEL) s -{ - if( (self=[super init]) ) { - targetCallback = [t retain]; - selector = s; - } - return self; -} - --(void) dealloc -{ - [targetCallback release]; - [super dealloc]; -} - --(id) copyWithZone: (NSZone*) zone -{ - InstantAction *copy = [[[self class] allocWithZone: zone] initWithTarget:targetCallback selector:selector]; - return copy; -} - - --(void) start -{ - [super start]; - [self execute]; -} - --(void) execute -{ - [targetCallback performSelector:selector]; -} -@end - -// -// CallFuncN -// -@implementation CallFuncN - --(void) execute -{ - [targetCallback performSelector:selector withObject:target]; -} -@end - -// -// CallFuncND -// -@implementation CallFuncND - -+(id) actionWithTarget: (id) t selector:(SEL) s data:(void*) d -{ - return [[[self alloc] initWithTarget: t selector: s data:d] autorelease]; -} - --(id) initWithTarget:(id) t selector:(SEL) s data:(void*) d -{ - if( (self=[super initWithTarget:t selector:s]) ) { - data = d; - NSMethodSignature * sig = [[t class] instanceMethodSignatureForSelector:s]; - invocation = [NSInvocation invocationWithMethodSignature:sig]; - [invocation setTarget:t]; - [invocation setSelector:s]; - [invocation retain]; - } - return self; -} - --(id) copyWithZone: (NSZone*) zone -{ - InstantAction *copy = [[[self class] allocWithZone: zone] initWithTarget:targetCallback selector:selector data:data]; - return copy; -} - - --(void) dealloc -{ - [invocation release]; - [super dealloc]; -} - --(void) execute -{ - [invocation setArgument:&target atIndex:2]; - [invocation setArgument:&data atIndex:3]; - [invocation invoke]; -} -@end diff --git a/Support/cocos2d/IntervalAction.h b/Support/cocos2d/IntervalAction.h deleted file mode 100644 index 7e06480..0000000 --- a/Support/cocos2d/IntervalAction.h +++ /dev/null @@ -1,356 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2008,2009 Ricardo Quesada - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - -#import "CocosNode.h" -#import "Action.h" - -#include - -/** An interval action is an action that takes place within a certain period of time. -It has an start time, and a finish time. The finish time is the parameter -duration plus the start time. - -These IntervalAction actions have some interesting properties, like: - - They can run normally (default) - - They can run reversed with the reverse method - - They can run with the time altered with the Accelerate, AccelDeccel and Speed actions. - -For example, you can simulate a Ping Pong effect running the action normally and -then running it again in Reverse mode. - -Example: - - Action * pingPongAction = [Sequence actions: action, [action reverse], nil]; -*/ -@interface IntervalAction: FiniteTimeAction -{ - struct timeval lastUpdate; - ccTime elapsed; -} - -@property (readonly) ccTime elapsed; - -/** creates the action */ -+(id) actionWithDuration: (ccTime) d; -/** initializes the action */ --(id) initWithDuration: (ccTime) d; -/** called when the action is about to start */ --(void) start; -/** returns YES if the action has finished */ --(BOOL) isDone; -/** returns a reversed action */ -- (IntervalAction*) reverse; -@end - -/** Runs actions sequentially, one after another - */ -@interface Sequence : IntervalAction -{ - NSArray *actions; - ccTime split; - int last; -} -/** helper contructor to create an array of sequenceable actions */ -+(id) actions: (FiniteTimeAction*) action1, ... NS_REQUIRES_NIL_TERMINATION; -/** creates the action */ -+(id) actionOne:(FiniteTimeAction*)actionOne two:(FiniteTimeAction*)actionTwo; -/** initializes the action */ --(id) initOne:(FiniteTimeAction*)actionOne two:(FiniteTimeAction*)actionTwo; -@end - - -/** Repeats an action a number of times. - * To repeat an action forever use the RepeatForever action. - */ -@interface Repeat : IntervalAction -{ - unsigned int times; - unsigned int total; - FiniteTimeAction *other; -} -/** creates the Repeat action. Times is an unsigned integer between 1 and pow(2,30) */ -+(id) actionWithAction:(FiniteTimeAction*)action times: (unsigned int)times; -/** initializes the action. Times is an unsigned integer between 1 and pow(2,30) */ --(id) initWithAction:(FiniteTimeAction*)action times: (unsigned int)times; -@end - -/** Spawn a new action immediately - */ -@interface Spawn : IntervalAction -{ - FiniteTimeAction *one; - FiniteTimeAction *two; -} -/** helper constructor to create an array of spawned actions */ -+(id) actions: (FiniteTimeAction*) action1, ... NS_REQUIRES_NIL_TERMINATION; -/** creates the Spawn action */ -+(id) actionOne: (FiniteTimeAction*) one two:(FiniteTimeAction*) two; -/** initializes the Spawn action with the 2 actions to spawn */ --(id) initOne: (FiniteTimeAction*) one two:(FiniteTimeAction*) two; -@end - -/** Rotates a CocosNode object to a certain angle by modifying it's - rotation attribute. - The direction will be decided by the shortest angle. -*/ -@interface RotateTo : IntervalAction -{ - float angle; - float startAngle; -} -/** creates the action */ -+(id) actionWithDuration:(ccTime)duration angle:(float)angle; -/** initializes the action */ --(id) initWithDuration:(ccTime)duration angle:(float)angle; -@end - -/** Rotates a CocosNode object clockwise a number of degrees by modiying it's rotation attribute. -*/ -@interface RotateBy : IntervalAction -{ - float angle; - float startAngle; -} -/** creates the action */ -+(id) actionWithDuration:(ccTime)duration angle:(float)deltaAngle; -/** initializes the action */ --(id) initWithDuration:(ccTime)duration angle:(float)deltaAngle; -@end - -/** Moves a CocosNode object to the position x,y. x and y are absolute coordinates by modifying it's position attribute. -*/ -@interface MoveTo : IntervalAction -{ - CGPoint endPosition; - CGPoint startPosition; - CGPoint delta; -} -/** creates the action */ -+(id) actionWithDuration:(ccTime)duration position:(CGPoint)position; -/** initializes the action */ --(id) initWithDuration:(ccTime)duration position:(CGPoint)position; -@end - -/** Moves a CocosNode object x,y pixels by modifying it's position attribute. - x and y are relative to the position of the object. - Duration is is seconds. -*/ -@interface MoveBy : MoveTo -{ -} -/** creates the action */ -+(id) actionWithDuration: (ccTime)duration position:(CGPoint)deltaPosition; -/** initializes the action */ --(id) initWithDuration: (ccTime)duration position:(CGPoint)deltaPosition; -@end - -/** Moves a CocosNode object simulating a jump movement by modifying it's position attribute. -*/ - @interface JumpBy : IntervalAction -{ - CGPoint startPosition; - CGPoint delta; - ccTime height; - int jumps; -} -/** creates the action */ -+(id) actionWithDuration: (ccTime)duration position:(CGPoint)position height:(ccTime)height jumps:(int)jumps; -/** initializes the action */ --(id) initWithDuration: (ccTime)duration position:(CGPoint)position height:(ccTime)height jumps:(int)jumps; -@end - -/** Moves a CocosNode object to a position simulating a jump movement by modifying it's position attribute. -*/ - @interface JumpTo : JumpBy -{ -} -@end - -/** bezier configuration structure - */ -typedef struct _ccBezierConfig { - //! startPosition of the bezier - CGPoint startPosition; - //! end position of the bezier - CGPoint endPosition; - //! Bezier control point 1 - CGPoint controlPoint_1; - //! Bezier control point 2 - CGPoint controlPoint_2; -} ccBezierConfig; - -/** A action that moves the target with a cubic Bezier curve. - Since BezierBy moves the target "relative" it will be easier if - the startPosition of the Bezier configuration is (0,0) - */ -@interface BezierBy : IntervalAction -{ - ccBezierConfig config; - CGPoint startPosition; -} - -/** creates the action with a duration and a bezier configuration */ -+(id) actionWithDuration: (ccTime) t bezier:(ccBezierConfig) c; - -/** initializes the action with a duration and a bezier configuration */ --(id) initWithDuration: (ccTime) t bezier:(ccBezierConfig) c; -@end - -/** Scales a CocosNode object to a zoom factor by modifying it's scale attribute. - @warning This action doesn't support "reverse" - */ -@interface ScaleTo : IntervalAction -{ - float scaleX; - float scaleY; - float startScaleX; - float startScaleY; - float endScaleX; - float endScaleY; - float deltaX; - float deltaY; -} -/** creates the action with the same scale factor for X and Y */ -+(id) actionWithDuration: (ccTime)duration scale:(float) s; -/** initializes the action with the same scale factor for X and Y */ --(id) initWithDuration: (ccTime)duration scale:(float) s; -/** creates the action with and X factor and a Y factor */ -+(id) actionWithDuration: (ccTime)duration scaleX:(float) sx scaleY:(float)sy; -/** initializes the action with and X factor and a Y factor */ --(id) initWithDuration: (ccTime)duration scaleX:(float) sx scaleY:(float)sy; -@end - -/** Scales a CocosNode object a zoom factor by modifying it's scale attribute. -*/ -@interface ScaleBy : ScaleTo -{ -} -@end - -/** Blinks a CocosNode object by modifying it's visible attribute -*/ -@interface Blink : IntervalAction -{ - int times; -} -/** creates the action */ -+(id) actionWithDuration: (ccTime)duration blinks:(unsigned int)blinks; -/** initilizes the action */ --(id) initWithDuration: (ccTime)duration blinks:(unsigned int)blinks; -@end - -/** Fades in a CocosNode that implements the CocosNodeOpacity protocol, from opacity 0 to 255. - The "reverse" of this action is FadeOut - */ -@interface FadeIn : IntervalAction -{ -} -@end - -/** Fades out a CocosNode that implements the CocosNodeOpacity protocol, from opacity 255 to 0. - The "reverse" of this action is FadeIn -*/ -@interface FadeOut : IntervalAction -{ -} -@end - -/** Fades a CocosNode that implements the CocosNodeOpacity protocol from current opacity to a custom one. - @warning This action doesn't support "reverse" - */ -@interface FadeTo : IntervalAction -{ - GLubyte toOpacity; - GLubyte fromOpacity; -} -/** creates an action with duration and opactiy */ -+(id) actionWithDuration:(ccTime)duration opacity:(GLubyte)opactiy; -/** initializes the action with duration and opacity */ --(id) initWithDuration:(ccTime)duration opacity:(GLubyte)opacity; -@end - -/** Tints a CocosNode that implements the CocosNodeRGB protocol from current tint to a custom one. - @warning This action doesn't support "reverse" - @since v0.7.2 -*/ -@interface TintTo : IntervalAction -{ - GLubyte toR, toG, toB; - GLubyte fromR, fromG, fromB; -} -/** creates an action with duration and opactiy */ -+(id) actionWithDuration:(ccTime)duration red:(GLubyte)red green:(GLubyte)green blue:(GLubyte)blue; -/** initializes the action with duration and opacity */ --(id) initWithDuration:(ccTime)duration red:(GLubyte)red green:(GLubyte)green blue:(GLubyte)blue; -@end - -/** Tints a CocosNode that implements the CocosNodeRGB protocol from current tint to a custom one. - @since v0.7.2 - */ -@interface TintBy : IntervalAction -{ - GLshort deltaR, deltaG, deltaB; - GLshort fromR, fromG, fromB; -} -/** creates an action with duration and opactiy */ -+(id) actionWithDuration:(ccTime)duration red:(GLshort)deltaRed green:(GLshort)deltaGreen blue:(GLshort)deltaBlue; -/** initializes the action with duration and opacity */ --(id) initWithDuration:(ccTime)duration red:(GLshort)deltaRed green:(GLshort)deltaGreen blue:(GLshort)deltaBlue; -@end - -/** Delays the action a certain amount of seconds -*/ -@interface DelayTime : IntervalAction -{ -} -@end - -/** Executes an action in reverse order, from time=duration to time=0 - - @warning Use this action carefully. This action is not - sequenceable. Use it as the default "reversed" method - of your own actions, but using it outside the "reversed" - scope is not recommended. -*/ -@interface ReverseTime : IntervalAction -{ - FiniteTimeAction * other; -} -/** creates the action */ -+(id) actionWithAction: (FiniteTimeAction*) action; -/** initializes the action */ --(id) initWithAction: (FiniteTimeAction*) action; -@end - - -@class Animation; -@class Texture2D; -/** Animates a sprite given the name of an Animation */ -@interface Animate : IntervalAction -{ - Animation *animation; - id origFrame; - BOOL restoreOriginalFrame; -} -/** creates the action with an Animation and will restore the original frame when the animation is over */ -+(id) actionWithAnimation:(id) a; -/** initializes the action with an Animation and will restore the original frame when the animtion is over */ --(id) initWithAnimation:(id) a; -/** creates the action with an Animation */ -+(id) actionWithAnimation:(id) a restoreOriginalFrame:(BOOL)b; -/** initializes the action with an Animation */ --(id) initWithAnimation:(id) a restoreOriginalFrame:(BOOL)b; -@end - - diff --git a/Support/cocos2d/IntervalAction.m b/Support/cocos2d/IntervalAction.m deleted file mode 100644 index b8ec599..0000000 --- a/Support/cocos2d/IntervalAction.m +++ /dev/null @@ -1,1124 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2008,2009 Ricardo Quesada - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - - -#import "IntervalAction.h" -#import "Sprite.h" -#import "CocosNode.h" -#import "Support/CGPointExtension.h" - -// -// IntervalAction -// -#pragma mark - -#pragma mark IntervalAction -@implementation IntervalAction - -@synthesize elapsed; - --(id) init -{ - NSException* myException = [NSException - exceptionWithName:@"IntervalActionInit" - reason:@"Init not supported. Use InitWithDuration" - userInfo:nil]; - @throw myException; - -} - -+(id) actionWithDuration: (ccTime) d -{ - return [[[self alloc] initWithDuration:d ] autorelease]; -} - --(id) initWithDuration: (ccTime) d -{ - if( !(self=[super init]) ) - return nil; - - duration = d; - elapsed = 0.0f; - return self; -} - --(id) copyWithZone: (NSZone*) zone -{ - Action *copy = [[[self class] allocWithZone: zone] initWithDuration: [self duration] ]; - return copy; -} - - -- (BOOL) isDone -{ - return (elapsed >= duration); -} - --(void) step: (ccTime) dt -{ - elapsed += dt; - [self update: MIN(1, elapsed/duration)]; -} - --(void) start -{ - if( gettimeofday( &lastUpdate, NULL) != 0 ) { - NSException* myException = [NSException - exceptionWithName:@"GetTimeOfDay" - reason:@"GetTimeOfDay abnormal error" - userInfo:nil]; - @throw myException; - } - - elapsed = 0.0f; -} - -- (IntervalAction*) reverse -{ - NSException* myException = [NSException - exceptionWithName:@"ReverseActionNotImplemented" - reason:@"Reverse Action not implemented" - userInfo:nil]; - @throw myException; -} -@end - -// -// Sequence -// -#pragma mark - -#pragma mark Sequence -@implementation Sequence -+(id) actionOne: (FiniteTimeAction*) one two: (FiniteTimeAction*) two -{ - return [[[self alloc] initOne:one two:two ] autorelease]; -} - -+(id) actions: (FiniteTimeAction*) action1, ... -{ - va_list params; - va_start(params,action1); - - FiniteTimeAction *now; - FiniteTimeAction *prev = action1; - - while( action1 ) { - now = va_arg(params,FiniteTimeAction*); - if ( now ) - prev = [Sequence actionOne: prev two: now]; - else - break; - } - va_end(params); - return prev; -} - --(id) initOne: (FiniteTimeAction*) one_ two: (FiniteTimeAction*) two_ -{ - NSAssert( one_!=nil, @"Sequence: argument one must be non-nil"); - NSAssert( two_!=nil, @"Sequence: argument two must be non-nil"); - - FiniteTimeAction *one = one_; - FiniteTimeAction *two = two_; - - ccTime d = [one duration] + [two duration]; - [super initWithDuration: d]; - - actions = [[NSArray arrayWithObjects: one, two, nil] retain]; - - return self; -} - --(id) copyWithZone: (NSZone*) zone -{ - Action *copy = [[[self class] allocWithZone:zone] initOne:[[[actions objectAtIndex:0] copy] autorelease] two:[[[actions objectAtIndex:1] copy] autorelease] ]; - return copy; -} - --(void) dealloc -{ - [actions release]; - [super dealloc]; -} - --(void) start -{ - [super start]; - for( Action * action in actions ) - action.target = target; - - split = [[actions objectAtIndex:0] duration] / duration; - last = -1; -} - --(void) update: (ccTime) t -{ - int found = 0; - ccTime new_t = 0.0f; - - if( t >= split ) { - found = 1; - if ( split == 1 ) - new_t = 1; - else - new_t = (t-split) / (1 - split ); - } else { - found = 0; - if( split != 0 ) - new_t = t / split; - else - new_t = 1; - } - - if (last == -1 && found==1) { - [[actions objectAtIndex:0] start]; - [[actions objectAtIndex:0] update:1.0f]; - [[actions objectAtIndex:0] stop]; - } - - if (last != found ) { - if( last != -1 ) { - [[actions objectAtIndex: last] update: 1.0f]; - [[actions objectAtIndex: last] stop]; - } - [[actions objectAtIndex: found] start]; - } - [[actions objectAtIndex:found] update: new_t]; - last = found; -} - -- (IntervalAction *) reverse -{ - return [Sequence actionOne: [[actions objectAtIndex:1] reverse] two: [[actions objectAtIndex:0] reverse ] ]; -} -@end - -// -// Repeat -// -#pragma mark - -#pragma mark Repeat -@implementation Repeat -+(id) actionWithAction: (FiniteTimeAction*) action times: (unsigned int) t -{ - return [[[self alloc] initWithAction: action times: t] autorelease]; -} - --(id) initWithAction: (FiniteTimeAction*) action times: (unsigned int) t -{ - int d = [action duration] * t; - - if( !(self=[super initWithDuration: d ]) ) - return nil; - - times = t; - other = [action retain]; - - total = 0; - return self; -} - --(id) copyWithZone: (NSZone*) zone -{ - Action *copy = [[[self class] allocWithZone:zone] initWithAction:[[other copy] autorelease] times:times]; - return copy; -} - --(void) dealloc -{ - [other release]; - [super dealloc]; -} - --(void) start -{ - total = 0; - [super start]; - other.target = target; - [other start]; -} - -//-(void) step:(ccTime) dt -//{ -// [other step: dt]; -// if( [other isDone] ) { -// total++; -// [other start]; -// } -//} - -// issue #80. Instead of hooking step:, hook update: since it can be called by any -// container action like Repeat, Sequence, AccelDeccel, etc.. --(void) update:(ccTime) dt -{ - ccTime t = dt * times; - float r = fmodf(t, 1.0f); - if( t > total+1 ) { - [other update:1.0f]; - total++; - [other stop]; - [other start]; - [other update:0.0f]; - } else { - // fix last repeat position - // else it could be 0. - if( dt== 1.0f) - r=1.0f; - [other update: MIN(r,1)]; - } -} - --(BOOL) isDone -{ - return ( total == times ); -} - -- (IntervalAction *) reverse -{ - return [Repeat actionWithAction:[other reverse] times: times]; -} -@end - -// -// Spawn -// -#pragma mark - -#pragma mark Spawn - -@implementation Spawn -+(id) actions: (FiniteTimeAction*) action1, ... -{ - va_list params; - va_start(params,action1); - - FiniteTimeAction *now; - FiniteTimeAction *prev = action1; - - while( action1 ) { - now = va_arg(params,FiniteTimeAction*); - if ( now ) - prev = [Spawn actionOne: prev two: now]; - else - break; - } - va_end(params); - return prev; -} - -+(id) actionOne: (FiniteTimeAction*) one two: (FiniteTimeAction*) two -{ - return [[[self alloc] initOne:one two:two ] autorelease]; -} - --(id) initOne: (FiniteTimeAction*) one_ two: (FiniteTimeAction*) two_ -{ - NSAssert( one_!=nil, @"Spawn: argument one must be non-nil"); - NSAssert( two_!=nil, @"Spawn: argument two must be non-nil"); - - ccTime d1 = [one_ duration]; - ccTime d2 = [two_ duration]; - - [super initWithDuration: fmaxf(d1,d2)]; - - one = one_; - two = two_; - - if( d1 > d2 ) - two = [Sequence actionOne: two_ two:[DelayTime actionWithDuration: (d1-d2)] ]; - else if( d1 < d2) - one = [Sequence actionOne: one_ two: [DelayTime actionWithDuration: (d2-d1)] ]; - - [one retain]; - [two retain]; - return self; -} - --(id) copyWithZone: (NSZone*) zone -{ - Action *copy = [[[self class] allocWithZone: zone] initOne: [[one copy] autorelease] two: [[two copy] autorelease] ]; - return copy; -} - --(void) dealloc -{ - [one release]; - [two release]; - [super dealloc]; -} - --(void) start -{ - [super start]; - one.target = target; - two.target = target; - [one start]; - [two start]; -} - --(void) update: (ccTime) t -{ - [one update:t]; - [two update:t]; -} - -- (IntervalAction *) reverse -{ - return [Spawn actionOne: [one reverse] two: [two reverse ] ]; -} -@end - -// -// RotateTo -// -#pragma mark - -#pragma mark RotateTo - -@implementation RotateTo -+(id) actionWithDuration: (ccTime) t angle:(float) a -{ - return [[[self alloc] initWithDuration:t angle:a ] autorelease]; -} - --(id) initWithDuration: (ccTime) t angle:(float) a -{ - if( !(self=[super initWithDuration: t]) ) - return nil; - - angle = a; - return self; -} - --(id) copyWithZone: (NSZone*) zone -{ - Action *copy = [[[self class] allocWithZone: zone] initWithDuration:[self duration] angle: angle]; - return copy; -} - --(void) start -{ - [super start]; - startAngle = target.rotation; - angle -= startAngle; - if (angle > 180) - angle = -360 + angle; - if (angle < -180) - angle = 360 + angle; -} --(void) update: (ccTime) t -{ - target.rotation = startAngle + angle * t; -} -@end - - -// -// RotateBy -// -#pragma mark - -#pragma mark RotateBy - -@implementation RotateBy -+(id) actionWithDuration: (ccTime) t angle:(float) a -{ - return [[[self alloc] initWithDuration:t angle:a ] autorelease]; -} - --(id) initWithDuration: (ccTime) t angle:(float) a -{ - if( !(self=[super initWithDuration: t]) ) - return nil; - - angle = a; - return self; -} - --(id) copyWithZone: (NSZone*) zone -{ - Action *copy = [[[self class] allocWithZone: zone] initWithDuration: [self duration] angle: angle]; - return copy; -} - --(void) start -{ - [super start]; - startAngle = [target rotation]; -} - --(void) update: (ccTime) t -{ - // XXX: shall I add % 360 - target.rotation = (startAngle + angle * t ); -} - --(IntervalAction*) reverse -{ - return [RotateBy actionWithDuration: duration angle: -angle]; -} - -@end - -// -// MoveTo -// -#pragma mark - -#pragma mark MoveTo - -@implementation MoveTo -+(id) actionWithDuration: (ccTime) t position: (CGPoint) p -{ - return [[[self alloc] initWithDuration:t position:p ] autorelease]; -} - --(id) initWithDuration: (ccTime) t position: (CGPoint) p -{ - if( !(self=[super initWithDuration: t]) ) - return nil; - - endPosition = p; - return self; -} - --(id) copyWithZone: (NSZone*) zone -{ - Action *copy = [[[self class] allocWithZone: zone] initWithDuration: [self duration] position: endPosition]; - return copy; -} - --(void) start -{ - [super start]; - startPosition = [target position]; - delta = ccpSub( endPosition, startPosition ); -} - --(void) update: (ccTime) t -{ - target.position = ccp( (startPosition.x + delta.x * t ), (startPosition.y + delta.y * t ) ); -} -@end - -// -// MoveBy -// -#pragma mark - -#pragma mark MoveBy - -@implementation MoveBy -+(id) actionWithDuration: (ccTime) t position: (CGPoint) p -{ - return [[[self alloc] initWithDuration:t position:p ] autorelease]; -} - --(id) initWithDuration: (ccTime) t position: (CGPoint) p -{ - if( !(self=[super initWithDuration: t]) ) - return nil; - - delta = p; - return self; -} - --(id) copyWithZone: (NSZone*) zone -{ - Action *copy = [[[self class] allocWithZone: zone] initWithDuration: [self duration] position: delta]; - return copy; -} - --(void) start -{ - CGPoint dTmp = delta; - [super start]; - delta = dTmp; -} - --(IntervalAction*) reverse -{ - return [MoveBy actionWithDuration: duration position: ccp( -delta.x, -delta.y)]; -} -@end - -// -// JumpBy -// -#pragma mark - -#pragma mark JumpBy - -@implementation JumpBy -+(id) actionWithDuration: (ccTime) t position: (CGPoint) pos height: (ccTime) h jumps:(int)j -{ - return [[[self alloc] initWithDuration: t position: pos height: h jumps:j] autorelease]; -} - --(id) initWithDuration: (ccTime) t position: (CGPoint) pos height: (ccTime) h jumps:(int)j -{ - if( !(self=[super initWithDuration:t]) ) - return nil; - - delta = pos; - height = h; - jumps = j; - return self; -} - --(id) copyWithZone: (NSZone*) zone -{ - Action *copy = [[[self class] allocWithZone: zone] initWithDuration: [self duration] position: delta height:height jumps:jumps]; - return copy; -} - --(void) start -{ - [super start]; - startPosition = target.position; -} - --(void) update: (ccTime) t -{ - ccTime y = height * fabsf( sinf(t * (CGFloat)M_PI * jumps ) ); - y += delta.y * t; - ccTime x = delta.x * t; - target.position = ccp( startPosition.x + x, startPosition.y + y ); -} - --(IntervalAction*) reverse -{ - return [JumpBy actionWithDuration: duration position: ccp(-delta.x,-delta.y) height: height jumps:jumps]; -} -@end - -// -// JumpTo -// -#pragma mark - -#pragma mark JumpTo - -@implementation JumpTo --(void) start -{ - [super start]; - delta = ccp( delta.x - startPosition.x, delta.y - startPosition.y ); -} -@end - - -#pragma mark - -#pragma mark BezierBy - -// Bezier cubic formula: -// ((1 - t) + t)3 = 1 -// Expands to… -// (1 - t)3 + 3t(1-t)2 + 3t2(1 - t) + t3 = 1 -static inline float bezierat( float a, float b, float c, float d, ccTime t ) -{ - return (powf(1-t,3) * a + - 3*t*(powf(1-t,2))*b + - 3*powf(t,2)*(1-t)*c + - powf(t,3)*d ); -} - -// -// BezierBy -// -@implementation BezierBy -+(id) actionWithDuration: (ccTime) t bezier:(ccBezierConfig) c -{ - return [[[self alloc] initWithDuration:t bezier:c ] autorelease]; -} - --(id) initWithDuration: (ccTime) t bezier:(ccBezierConfig) c -{ - if( (self=[super initWithDuration: t]) ) { - config = c; - } - return self; -} - --(id) copyWithZone: (NSZone*) zone -{ - Action *copy = [[[self class] allocWithZone: zone] initWithDuration: [self duration] bezier: config]; - return copy; -} - --(void) start -{ - [super start]; - startPosition = target.position; -} - --(void) update: (ccTime) t -{ - float xa = config.startPosition.x; - float xb = config.controlPoint_1.x; - float xc = config.controlPoint_2.x; - float xd = config.endPosition.x; - - float ya = config.startPosition.y; - float yb = config.controlPoint_1.y; - float yc = config.controlPoint_2.y; - float yd = config.endPosition.y; - - float x = bezierat(xa, xb, xc, xd, t); - float y = bezierat(ya, yb, yc, yd, t); - target.position = ccpAdd( startPosition, ccp(x,y)); -} - -- (IntervalAction*) reverse -{ - // XXX: reverse it's not working as expected - ccBezierConfig r; - r.startPosition = ccpNeg( config.startPosition); - r.endPosition = ccpNeg(config.endPosition); - r.controlPoint_1 = ccpNeg(config.controlPoint_1); - r.controlPoint_2 = ccpNeg(config.controlPoint_2); - - BezierBy *action = [BezierBy actionWithDuration:[self duration] bezier:r]; - return action; -} -@end - -// -// ScaleTo -// -#pragma mark - -#pragma mark ScaleTo -@implementation ScaleTo -+(id) actionWithDuration: (ccTime) t scale:(float) s -{ - return [[[self alloc] initWithDuration: t scale:s] autorelease]; -} - --(id) initWithDuration: (ccTime) t scale:(float) s -{ - if( !(self=[super initWithDuration: t]) ) - return nil; - - endScaleX = s; - endScaleY = s; - return self; -} - -+(id) actionWithDuration: (ccTime) t scaleX:(float)sx scaleY:(float)sy -{ - return [[[self alloc] initWithDuration: t scaleX:sx scaleY:sy] autorelease]; -} - --(id) initWithDuration: (ccTime) t scaleX:(float)sx scaleY:(float)sy -{ - if( !(self=[super initWithDuration: t]) ) - return nil; - - endScaleX = sx; - endScaleY = sy; - return self; -} - --(id) copyWithZone: (NSZone*) zone -{ - Action *copy = [[[self class] allocWithZone: zone] initWithDuration: [self duration] scaleX:endScaleX scaleY:endScaleY]; - return copy; -} - --(void) start -{ - [super start]; - startScaleX = [target scaleX]; - startScaleY = [target scaleY]; - deltaX = endScaleX - startScaleX; - deltaY = endScaleY - startScaleY; -} - --(void) update: (ccTime) t -{ - [target setScaleX: (startScaleX + deltaX * t ) ]; - [target setScaleY: (startScaleY + deltaY * t ) ]; -} -@end - -// -// ScaleBy -// -#pragma mark - -#pragma mark ScaleBy -@implementation ScaleBy --(void) start -{ - [super start]; - deltaX = startScaleX * endScaleX - startScaleX; - deltaY = startScaleY * endScaleY - startScaleY; -} - --(IntervalAction*) reverse -{ - return [ScaleBy actionWithDuration: duration scaleX: 1/endScaleX scaleY:1/endScaleY]; -} -@end - -// -// Blink -// -#pragma mark - -#pragma mark Blink -@implementation Blink -+(id) actionWithDuration: (ccTime) t blinks: (unsigned int) b -{ - return [[[ self alloc] initWithDuration: t blinks: b] autorelease]; -} - --(id) initWithDuration: (ccTime) t blinks: (unsigned int) b -{ - if( ! (self=[super initWithDuration: t] ) ) - return nil; - times = b; - return self; -} - --(id) copyWithZone: (NSZone*) zone -{ - Action *copy = [[[self class] allocWithZone: zone] initWithDuration: [self duration] blinks: times]; - return copy; -} - --(void) update: (ccTime) t -{ - ccTime slice = 1.0f / times; - ccTime m = fmodf(t, slice); - target.visible = (m > slice/2) ? YES : NO; -} - --(IntervalAction*) reverse -{ - // return 'self' - return [Blink actionWithDuration: duration blinks: times]; -} -@end - -// -// FadeIn -// -#pragma mark - -#pragma mark FadeIn -@implementation FadeIn --(void) update: (ccTime) t -{ - [(id) target setOpacity: 255 *t]; -} --(IntervalAction*) reverse -{ - return [FadeOut actionWithDuration: duration]; -} -@end - -// -// FadeOut -// -#pragma mark - -#pragma mark FadeOut -@implementation FadeOut --(void) update: (ccTime) t -{ - [(id) target setOpacity: 255 *(1-t)]; -} --(IntervalAction*) reverse -{ - return [FadeIn actionWithDuration: duration]; -} -@end - -// -// FadeTo -// -#pragma mark - -#pragma mark FadeTo -@implementation FadeTo -+(id) actionWithDuration: (ccTime) t opacity: (GLubyte) o -{ - return [[[ self alloc] initWithDuration: t opacity: o] autorelease]; -} - --(id) initWithDuration: (ccTime) t opacity: (GLubyte) o -{ - if( (self=[super initWithDuration: t] ) ) - toOpacity = o; - return self; -} - --(id) copyWithZone: (NSZone*) zone -{ - Action *copy = [[[self class] allocWithZone: zone] initWithDuration: [self duration] opacity: toOpacity]; - return copy; -} - --(void) start -{ - [super start]; - fromOpacity = [(id)target opacity]; -} - --(void) update: (ccTime) t -{ - [(id)target setOpacity: fromOpacity + ( toOpacity - fromOpacity ) * t]; -} -@end - -// -// TintTo -// -#pragma mark - -#pragma mark TintTo -@implementation TintTo -+(id) actionWithDuration:(ccTime)t red:(GLubyte)r green:(GLubyte)g blue:(GLubyte)b -{ - return [[(TintTo*)[ self alloc] initWithDuration:t red:r green:g blue:b] autorelease]; -} - --(id) initWithDuration: (ccTime) t red:(GLubyte)r green:(GLubyte)g blue:(GLubyte)b -{ - if( (self=[super initWithDuration: t] ) ) { - toR = r; - toG = g; - toB = b; - } - return self; -} - --(id) copyWithZone: (NSZone*) zone -{ - Action *copy = [(TintTo*)[[self class] allocWithZone: zone] initWithDuration: [self duration] red:toR green:toG blue:toB]; - return copy; -} - --(void) start -{ - [super start]; - - id tn = (id) target; - - fromR = [tn r]; - fromG = [tn g]; - fromB = [tn b]; -} - --(void) update: (ccTime) t -{ - id tn = (id) target; - [tn setRGB:fromR + (toR - fromR) * t :fromG + (toG - fromG) * t :fromB + (toB - fromB) * t]; -} -@end - -// -// TintBy -// -#pragma mark - -#pragma mark TintBy -@implementation TintBy -+(id) actionWithDuration:(ccTime)t red:(GLshort)r green:(GLshort)g blue:(GLshort)b -{ - return [[(TintBy*)[ self alloc] initWithDuration:t red:r green:g blue:b] autorelease]; -} - --(id) initWithDuration:(ccTime)t red:(GLshort)r green:(GLshort)g blue:(GLshort)b -{ - if( (self=[super initWithDuration: t] ) ) { - deltaR = r; - deltaG = g; - deltaB = b; - } - return self; -} - --(id) copyWithZone: (NSZone*) zone -{ - return[(TintBy*)[[self class] allocWithZone: zone] initWithDuration: [self duration] red:deltaR green:deltaG blue:deltaB]; -} - --(void) start -{ - [super start]; - - id tn = (id) target; - fromR = [tn r]; - fromG = [tn g]; - fromB = [tn b]; -} - --(void) update: (ccTime) t -{ - id tn = (id) target; - [tn setRGB:fromR + deltaR * t :fromG + deltaG * t :fromB + deltaB * t]; -} -- (IntervalAction*) reverse -{ - return [TintBy actionWithDuration:duration red:-deltaR green:-deltaG blue:-deltaB]; -} -@end - -// -// DelayTime -// -#pragma mark - -#pragma mark DelayTime -@implementation DelayTime --(void) update: (ccTime) t -{ - return; -} - --(id)reverse -{ - return [DelayTime actionWithDuration:duration]; -} -@end - -// -// ReverseTime -// -#pragma mark - -#pragma mark ReverseTime -@implementation ReverseTime -+(id) actionWithAction: (FiniteTimeAction*) action -{ - // casting to prevent warnings - ReverseTime *a = [super alloc]; - return [[a initWithAction:action] autorelease]; -} - --(id) initWithAction: (FiniteTimeAction*) action -{ - if( !(self=[super initWithDuration: [action duration]]) ) - return nil; - - other = [action retain]; - return self; -} - --(id) copyWithZone: (NSZone*) zone -{ - return [[[self class] allocWithZone: zone] initWithAction:[[other copy] autorelease] ]; -} - --(void) dealloc -{ - [other release]; - [super dealloc]; -} - --(void) start -{ - [super start]; - other.target = target; - [other start]; -} - --(void) stop -{ - [other stop]; - [super stop]; -} - --(void) update:(ccTime)t -{ - [other update:1-t]; -} - --(IntervalAction*) reverse -{ - return [[other copy] autorelease]; -} -@end - -// -// Animate -// -#pragma mark - -#pragma mark Animate -@implementation Animate - -+(id) actionWithAnimation: (id)anim -{ - return [[[self alloc] initWithAnimation:anim restoreOriginalFrame:YES] autorelease]; -} - -+(id) actionWithAnimation: (id)anim restoreOriginalFrame:(BOOL)b -{ - return [[[self alloc] initWithAnimation:anim restoreOriginalFrame:b] autorelease]; -} - --(id) initWithAnimation: (id)anim -{ - NSAssert( anim!=nil, @"Animate: argument Animation must be non-nil"); - return [self initWithAnimation:anim restoreOriginalFrame:YES]; -} - --(id) initWithAnimation: (id)anim restoreOriginalFrame:(BOOL) b -{ - NSAssert( anim!=nil, @"Animate: argument Animation must be non-nil"); - - if( (self=[super initWithDuration: [[anim frames] count] * [anim delay]]) ) { - - restoreOriginalFrame = b; - animation = [anim retain]; - origFrame = nil; - } - return self; -} - --(id) copyWithZone: (NSZone*) zone -{ - return [[[self class] allocWithZone: zone] initWithAnimation: animation]; -} - --(void) dealloc -{ - [animation release]; - [origFrame release]; - [super dealloc]; -} - --(void) start -{ - [super start]; - id sprite = (id) target; - - [origFrame release]; - - origFrame = [[sprite displayFrame] retain]; -} - --(void) stop -{ - if( restoreOriginalFrame ) { - id sprite = (id) target; - [sprite setDisplayFrame:origFrame]; - } - - [super stop]; -} - --(void) update: (ccTime) t -{ - NSUInteger idx=0; - - ccTime slice = 1.0f / [[animation frames] count]; - - if(t !=0 ) - idx = t/ slice; - - if( idx >= [[animation frames] count] ) { - idx = [[animation frames] count] -1; - } - id sprite = (id) target; - if (! [sprite isFrameDisplayed: [[animation frames] objectAtIndex: idx]] ) { - [sprite setDisplayFrame: [[animation frames] objectAtIndex:idx]]; - } -} -@end diff --git a/Support/cocos2d/Label.h b/Support/cocos2d/Label.h deleted file mode 100644 index 9954f68..0000000 --- a/Support/cocos2d/Label.h +++ /dev/null @@ -1,50 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2008,2009 Ricardo Quesada - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - - -#import - -#import "Support/Texture2D.h" - -#import "TextureNode.h" - -/** Label is a subclass of TextureNode that knows how to render text labels - * - * All features from TextureNode are valid in Label - * - * Label are slow. Consider using LabelAtlas or BitmapFontAtlas instead. - */ -@interface Label : TextureNode -{ - CGSize _dimensions; - UITextAlignment _alignment; - NSString * _fontName; - CGFloat _fontSize; -} - -/** creates a label from a fontname, alignment, dimension and font size */ -+ (id) labelWithString:(NSString*)string dimensions:(CGSize)dimensions alignment:(UITextAlignment)alignment fontName:(NSString*)name fontSize:(CGFloat)size; -/** creates a label from a fontname and font size */ -+ (id) labelWithString:(NSString*)string fontName:(NSString*)name fontSize:(CGFloat)size; -/** initializes the label with a font name, alignment, dimension and font size */ -- (id) initWithString:(NSString*)string dimensions:(CGSize)dimensions alignment:(UITextAlignment)alignment fontName:(NSString*)name fontSize:(CGFloat)size; -/** initializes the label with a font name and font size */ -- (id) initWithString:(NSString*)string fontName:(NSString*)name fontSize:(CGFloat)size; - -/** changes the string to render - * @warning Changing the string is as expensive as creating a new Label. To obtain better performance use LabelAtlas - */ -- (void) setString:(NSString*)string; - -@end diff --git a/Support/cocos2d/Label.m b/Support/cocos2d/Label.m deleted file mode 100644 index 79344c8..0000000 --- a/Support/cocos2d/Label.m +++ /dev/null @@ -1,86 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2008,2009 Ricardo Quesada - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - - -#import "Label.h" -#import "Support/CGPointExtension.h" - -@implementation Label - -- (id) init -{ - NSException* myException = [NSException - exceptionWithName:@"LabelInit" - reason:@"Use initWithString:dimensions:aligment:fontName:font instead" - userInfo:nil]; - @throw myException; -} - -+ (id) labelWithString:(NSString*)string dimensions:(CGSize)dimensions alignment:(UITextAlignment)alignment fontName:(NSString*)name fontSize:(CGFloat)size -{ - return [[[self alloc] initWithString: string dimensions:dimensions alignment:alignment fontName:name fontSize:size]autorelease]; -} - -+ (id) labelWithString:(NSString*)string fontName:(NSString*)name fontSize:(CGFloat)size -{ - return [[[self alloc] initWithString: string fontName:name fontSize:size]autorelease]; -} - - -- (id) initWithString:(NSString*)string dimensions:(CGSize)dimensions alignment:(UITextAlignment)alignment fontName:(NSString*)name fontSize:(CGFloat)size; -{ - if( (self=[super init]) ) { - - _dimensions = dimensions; - _alignment = alignment; - _fontName = [name retain]; - _fontSize = size; - - [self setString:string]; - } - return self; -} - -- (id) initWithString:(NSString*)string fontName:(NSString*)name fontSize:(CGFloat)size; -{ - if( (self=[super init]) ) { - - _dimensions = CGSizeZero; - _fontName = [name retain]; - _fontSize = size; - - [self setString:string]; - } - return self; -} - -- (void) setString:(NSString*)string -{ - if( CGSizeEqualToSize( _dimensions, CGSizeZero ) ) - // WARNING: double retain - self.texture = [[Texture2D alloc] initWithString:string fontName:_fontName fontSize:_fontSize]; - else - // WARNING: double retain - self.texture = [[Texture2D alloc] initWithString:string dimensions:_dimensions alignment:_alignment fontName:_fontName fontSize:_fontSize]; - - // end of warning. 1 retain only - [self.texture release]; -} - -- (void) dealloc -{ - [_fontName release]; - [super dealloc]; -} -@end diff --git a/Support/cocos2d/LabelAtlas.h b/Support/cocos2d/LabelAtlas.h deleted file mode 100644 index 0c1e591..0000000 --- a/Support/cocos2d/LabelAtlas.h +++ /dev/null @@ -1,43 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2008,2009 Ricardo Quesada - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - -#import "AtlasNode.h" -#import "TextureAtlas.h" - -/** LabelAtlas is a subclass of AtlasNode. - - It can be as a replacement of Label since it is MUCH faster. - - LabelAtlas versus Label: - - LabelAtlas is MUCH faster than Label - - LabelAtlas "characters" have a fixed height and width - - LabelAtlas "characters" can be anything you want since they are taken from an image file - - A more flexible class is BitmapFontAtlas. It supports variable width characters and it also has a nice editor. - */ -@interface LabelAtlas : AtlasNode { - - // string to render - NSString *string; - - // the first char in the charmap - char mapStartChar; -} - -/** creates the LabelAtlas with a string, a char map file(the atlas), the width and height of each element and the starting char of the atlas */ -+(id) labelAtlasWithString:(NSString*) string charMapFile: (NSString*) charmapfile itemWidth:(int)w itemHeight:(int)h startCharMap:(char)c; - -/** initializes the LabelAtlas with a string, a char map file(the atlas), the width and height of each element and the starting char of the atlas */ --(id) initWithString:(NSString*) string charMapFile: (NSString*) charmapfile itemWidth:(int)w itemHeight:(int)h startCharMap:(char)c; -@end diff --git a/Support/cocos2d/LabelAtlas.m b/Support/cocos2d/LabelAtlas.m deleted file mode 100644 index d623d02..0000000 --- a/Support/cocos2d/LabelAtlas.m +++ /dev/null @@ -1,134 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2008 Ricardo Quesada - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - -#import "LabelAtlas.h" -#import "ccMacros.h" - - -@implementation LabelAtlas - -#pragma mark LabelAtlas - Creation & Init -+(id) labelAtlasWithString:(NSString*) string charMapFile: (NSString*) charmapfile itemWidth:(int)w itemHeight:(int)h startCharMap:(char)c -{ - return [[[self alloc] initWithString:string charMapFile:charmapfile itemWidth:w itemHeight:h startCharMap:c] autorelease]; -} - - --(id) initWithString:(NSString*) theString charMapFile: (NSString*) charmapfile itemWidth:(int)w itemHeight:(int)h startCharMap:(char)c -{ - - if (! (self=[super initWithTileFile:charmapfile tileWidth:w tileHeight:h itemsToRender:[theString length] ]) ) - return nil; - - string = [theString retain]; - mapStartChar = c; - - [self updateAtlasValues]; - - return self; -} - --(void) dealloc -{ - [string release]; - - [super dealloc]; -} - -#pragma mark LabelAtlas - Atlas generation - --(void) updateAtlasValues -{ - int n = [string length]; - - ccV3F_C4B_T2F_Quad quad; - - const char *s = [string UTF8String]; - - for( int i=0; i textureAtlas_.totalQuads ) - [textureAtlas_ resizeCapacity: newString.length]; - - [string release]; - string = [newString retain]; - [self updateAtlasValues]; - - CGSize s; - s.width = [string length] * itemWidth; - s.height = itemHeight; - [self setContentSize:s]; -} - -#pragma mark LabelAtlas - draw -- (void) draw -{ - glEnableClientState( GL_VERTEX_ARRAY); - glEnableClientState( GL_TEXTURE_COORD_ARRAY ); - - glEnable( GL_TEXTURE_2D); - - glColor4ub( r_, g_, b_, opacity_); - - BOOL preMulti = [[textureAtlas_ texture] hasPremultipliedAlpha]; - if( ! preMulti ) - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - - [textureAtlas_ drawNumberOfQuads: string.length]; - - if( !preMulti ) - glBlendFunc(CC_BLEND_SRC, CC_BLEND_DST); - - // is this chepear than saving/restoring color state ? - glColor4ub( 255, 255, 255, 255); - - glDisable( GL_TEXTURE_2D); - - glDisableClientState(GL_VERTEX_ARRAY ); - glDisableClientState( GL_TEXTURE_COORD_ARRAY ); -} -@end diff --git a/Support/cocos2d/Layer.h b/Support/cocos2d/Layer.h deleted file mode 100644 index 2419423..0000000 --- a/Support/cocos2d/Layer.h +++ /dev/null @@ -1,122 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2008,2009 Ricardo Quesada - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - - -#import - -#import "CocosNode.h" - -// -// TouchEventDelegate -// -/**Touch event delegate - * return YES if the event was handled - * return NO if the event was not handled - */ -@protocol TouchEventsDelegate -@optional -- (BOOL)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event; -- (BOOL)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event; -- (BOOL)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event; -- (BOOL)ccTouchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event; -@end - - -// -// Layer -// -/** Layer is a subclass of CocosNode that implements the TouchEventsDelegate protocol. - - All features from CocosNode are valid, plus the following new features: - - It can receive iPhone Touches - - It can receive Accelerometer input -*/ -@interface Layer : CocosNode -{ - //! whether or not it will receive Touch events - BOOL isTouchEnabled; - - //! whether or not it will receive Accelerometer events - BOOL isAccelerometerEnabled; -} - -@property(nonatomic,assign) BOOL isTouchEnabled; -@property(nonatomic,assign) BOOL isAccelerometerEnabled; - -@end - -// -// ColorLayer -// -/** ColorLayer is a subclass of Layer that implements the CocosNodeSize, CocosNodeOpacity and CocosNodeRGB protocol. - - All features from Layer are valid, plus the following new features: - - opacity - - RGB colors - - contentSize - */ -@interface ColorLayer : Layer -{ - GLubyte r,g,b,opacity; - GLfloat squareVertices[4 * 2]; - GLubyte squareColors[4 * 4]; -} - -/** creates the Layer with color, width and height */ -+ (id) layerWithColor: (GLuint) aColor width:(GLfloat)w height:(GLfloat)h; -/** creates the layer with color. Width and height are the window size. */ -+ (id) layerWithColor: (GLuint) aColor; - -/** initializes a Layer with color, width and height */ -- (id) initWithColor: (GLuint) aColor width:(GLint)w height:(GLint)h; -/** initializes a Layer with color. Width and height are the window size. */ -- (id) initWithColor: (GLuint) aColor; - -/** initializes the witdh and height of the layer */ -- (void) initWidth: (GLfloat)w height:(GLfloat)h; - -/** changes the color of the layer - @deprecated Use CocosNodeRGB protocol instead - */ -- (void) changeColor: (GLuint) aColor __attribute__ ((deprecated)); - -/** change width */ --(void) changeWidth: (GLfloat)w; -/** change height */ --(void) changeHeight: (GLfloat)h; - -/* deprecated */ -@property (readonly) GLuint color __attribute__ ((deprecated)); - -/** conforms to CocosNodeRGB and CocosNodeOpacity protocol */ -@property (readonly) GLubyte r,g,b,opacity; - -@end - -/** A Layer with the ability to multiplex it's children */ -@interface MultiplexLayer : Layer -{ - unsigned int enabledLayer; - NSMutableArray *layers; -} - -/** creates a MultiplexLayer with one or more layers */ -+(id) layerWithLayers: (Layer*) layer, ... NS_REQUIRES_NIL_TERMINATION; -/** initializes a MultiplexLayer with one or more layers */ --(id) initWithLayers: (Layer*) layer vaList:(va_list) params; -/** switches to a certain layer indexed by n*/ --(void) switchTo: (unsigned int) n; -/** release the current layer and switches to another layer indexed by n */ --(void) switchToAndReleaseMe: (unsigned int) n; -@end diff --git a/Support/cocos2d/Layer.m b/Support/cocos2d/Layer.m deleted file mode 100644 index 1b54f5f..0000000 --- a/Support/cocos2d/Layer.m +++ /dev/null @@ -1,312 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2008,2009 Ricardo Quesada - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - - -#import -#import - -#import "Layer.h" -#import "Director.h" -#import "ccMacros.h" -#import "Support/CGPointExtension.h" - -#pragma mark - -#pragma mark Layer - -@implementation Layer - -@synthesize isTouchEnabled, isAccelerometerEnabled; - --(id) init -{ - if( ! (self=[super init]) ) - return nil; - - CGSize s = [[Director sharedDirector] winSize]; - anchorPoint_ = ccp(0.5f, 0.5f); - [self setContentSize:s]; - self.relativeTransformAnchor = NO; - - isTouchEnabled = NO; - isAccelerometerEnabled = NO; - - return self; -} - --(void) onEnter -{ - - // register 'parent' nodes first - // since events are propagated in reverse order - if( isTouchEnabled ) - [[Director sharedDirector] addEventHandler:self]; - - // the iterate over all the children - [super onEnter]; - - if( isAccelerometerEnabled ) - [[UIAccelerometer sharedAccelerometer] setDelegate:self]; -} - --(void) onExit -{ - if( isTouchEnabled ) - [[Director sharedDirector] removeEventHandler:self]; - - if( isAccelerometerEnabled ) - [[UIAccelerometer sharedAccelerometer] setDelegate:nil]; - - [super onExit]; -} -@end - -#pragma mark - -#pragma mark ColorLayer - -@interface ColorLayer (Private) --(void) updateColor; -@end - -@implementation ColorLayer - -// Opacity and RGB color protocol -@synthesize r,g,b,opacity; - - -- (id) init -{ - NSException* myException = [NSException - exceptionWithName:@"ColorLayerInit" - reason:@"Use ColorLayer initWithColor instead" - userInfo:nil]; - @throw myException; -} - -+ (id) layerWithColor: (GLuint) aColor width:(GLfloat)w height:(GLfloat) h -{ - return [[[self alloc] initWithColor: aColor width:w height:h] autorelease]; -} - -+ (id) layerWithColor: (GLuint) aColor -{ - return [[[self alloc] initWithColor: aColor] autorelease]; -} - -- (id) initWithColor: (GLuint) aColor width:(GLint)w height:(GLint) h -{ - if( (self=[super init]) ) { - r = (aColor >> 24) & 0xff; - g = (aColor >> 16) & 0xff; - b = (aColor >> 8) & 0xff; - opacity = (aColor) & 0xff; - - [self updateColor]; - - [self initWidth:w height:h]; - } - return self; -} - -- (id) initWithColor: (GLuint) aColor -{ - CGSize s = [[Director sharedDirector] winSize]; - - return [self initWithColor: aColor width:s.width height:s.height]; -} - --(void) changeWidth: (GLfloat) w -{ - squareVertices[2] = w; - squareVertices[6] = w; -} - --(void) changeHeight: (GLfloat) h -{ - squareVertices[5] = h; - squareVertices[7] = h; -} - -- (void) updateColor -{ - for( NSUInteger i=0; i < sizeof(squareColors) / sizeof(squareColors[0]);i++ ) - { - if( i % 4 == 0 ) - squareColors[i] = r; - else if( i % 4 == 1) - squareColors[i] = g; - else if( i % 4 ==2 ) - squareColors[i] = b; - else - squareColors[i] = opacity; - } -} - -- (void) initWidth: (GLfloat) w height:(GLfloat) h -{ - for (NSUInteger i=0; i> 24) & 0xff; - g = (aColor >> 16) & 0xff; - b = (aColor >> 8) & 0xff; - opacity = (aColor) & 0xff; - [self updateColor]; -} - -//-(void) setColor:(GLuint)aColor -//{ -// return [self changeColor:aColor]; -//} --(GLuint) color -{ - GLuint ret; - ret = (r << 24) | (g << 16) | (b << 8) | opacity; - return ret; -} - -#pragma mark Protocols -// Color Protocol --(void) setRGB: (GLubyte)rr :(GLubyte)gg :(GLubyte)bb -{ - r = rr; - g = gg; - b = bb; - [self updateColor]; -} - -// Opacity Protocol --(void) setOpacity: (GLubyte) o -{ - opacity = o; - [self updateColor]; -} - -// Size protocol --(CGSize) contentSize -{ - CGSize ret; - ret.width = squareVertices[2]; - ret.height = squareVertices[5]; - return ret; -} -@end - -#pragma mark - -#pragma mark MultiplexLayer - -@implementation MultiplexLayer -+(id) layerWithLayers: (Layer*) layer, ... -{ - va_list args; - va_start(args,layer); - - id s = [[[self alloc] initWithLayers: layer vaList:args] autorelease]; - - va_end(args); - return s; -} - --(id) initWithLayers: (Layer*) layer vaList:(va_list) params -{ - if( ! (self=[super init]) ) - return nil; - - layers = [[NSMutableArray array] retain]; - - [layers addObject: layer]; - - Layer *l = va_arg(params,Layer*); - while( l ) { - [layers addObject: l]; - l = va_arg(params,Layer*); - } - - enabledLayer = 0; - [self addChild: [layers objectAtIndex: enabledLayer]]; - - return self; -} - --(void) dealloc -{ - [layers release]; - [super dealloc]; -} - --(void) switchTo: (unsigned int) n -{ - if( n >= [layers count] ) { - NSException* myException = [NSException - exceptionWithName:@"MultiplexLayerInvalidIndex" - reason:@"Invalid index in MultiplexLayer switchTo message" - userInfo:nil]; - @throw myException; - } - - [self removeChild: [layers objectAtIndex:enabledLayer] cleanup:NO]; - - enabledLayer = n; - - [self addChild: [layers objectAtIndex:n]]; -} - --(void) switchToAndReleaseMe: (unsigned int) n -{ - if( n >= [layers count] ) { - NSException* myException = [NSException - exceptionWithName:@"MultiplexLayerInvalidIndex" - reason:@"Invalid index in MultiplexLayer switchTo message" - userInfo:nil]; - @throw myException; - } - - [self removeChild: [layers objectAtIndex:enabledLayer] cleanup:NO]; - - [layers replaceObjectAtIndex:enabledLayer withObject:[NSNull null]]; - - enabledLayer = n; - - [self addChild: [layers objectAtIndex:n]]; -} - -@end diff --git a/Support/cocos2d/Menu.h b/Support/cocos2d/Menu.h deleted file mode 100644 index 4c26647..0000000 --- a/Support/cocos2d/Menu.h +++ /dev/null @@ -1,72 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2008,2009 Ricardo Quesada - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - -#import - -#import "MenuItem.h" -#import "Layer.h" -#import "TargetedTouchDelegate.h" - -typedef enum { - kMenuStateWaiting, - kMenuStateTrackingTouch -} MenuState; - -/** A Menu - * - * Features and Limitation: - * - You can add MenuItem objects in runtime using addChild: - * - But the only accecpted children are MenuItem objects - */ -@interface Menu : CocosNode -{ - MenuState state; - MenuItem *selectedItem; - GLubyte opacity_, r_, g_, b_; -} - -/** creates a menu with it's items */ -+ (id) menuWithItems: (MenuItem*) item, ... NS_REQUIRES_NIL_TERMINATION; - -/** initializes a menu with it's items */ -- (id) initWithItems: (MenuItem*) item vaList: (va_list) args; - -/** align items vertically */ --(void) alignItemsVertically; -/** align items vertically with padding - @since v0.7.2 - */ --(void) alignItemsVerticallyWithPadding:(float) padding; - -/** align items horizontally */ --(void) alignItemsHorizontally; -/** align items horizontally with padding - @since v0.7.2 - */ --(void) alignItemsHorizontallyWithPadding: (float) padding; - - -/** align items in rows of columns */ --(void) alignItemsInColumns: (NSNumber *) columns, ... NS_REQUIRES_NIL_TERMINATION; --(void) alignItemsInColumns: (NSNumber *) columns vaList: (va_list) args; - -/** align items in columns of rows */ --(void) alignItemsInRows: (NSNumber *) rows, ... NS_REQUIRES_NIL_TERMINATION; --(void) alignItemsInRows: (NSNumber *) rows vaList: (va_list) args; - - -/** conforms to CocosNodeRGBA protocol */ -@property (readonly) GLubyte opacity, r, g, b; - -@end diff --git a/Support/cocos2d/Menu.m b/Support/cocos2d/Menu.m deleted file mode 100644 index 77fbfae..0000000 --- a/Support/cocos2d/Menu.m +++ /dev/null @@ -1,391 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2008,2009 Ricardo Quesada - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - - -#import "Menu.h" -#import "Director.h" -#import "TouchDispatcher.h" -#import "Support/CGPointExtension.h" - -enum { - kDefaultPadding = 5, -}; - -@interface Menu (Private) -// returns touched menu item, if any --(MenuItem *) itemForTouch: (UITouch *) touch; -@end - -@implementation Menu - -@synthesize opacity=opacity_, r=r_, g=g_, b=b_; - -- (id) init -{ - NSException* myException = [NSException - exceptionWithName:@"MenuInit" - reason:@"Use initWithItems instead" - userInfo:nil]; - @throw myException; -} - -+(id) menuWithItems: (MenuItem*) item, ... -{ - va_list args; - va_start(args,item); - - id s = [[[self alloc] initWithItems: item vaList:args] autorelease]; - - va_end(args); - return s; -} - --(id) initWithItems: (MenuItem*) item vaList: (va_list) args -{ - if( !(self=[super init]) ) - return nil; - - // menu in the center of the screen - CGSize s = [[Director sharedDirector] winSize]; - - self.relativeTransformAnchor = NO; - anchorPoint_ = ccp(0.5f, 0.5f); - [self setContentSize:s]; - - // XXX: in v0.7, winSize should return the visible size - // XXX: so the bar calculation should be done there - CGRect r = [[UIApplication sharedApplication] statusBarFrame]; - ccDeviceOrientation orientation = [[Director sharedDirector] deviceOrientation]; - if( orientation == CCDeviceOrientationLandscapeLeft || orientation == CCDeviceOrientationLandscapeRight ) - s.height -= r.size.width; - else - s.height -= r.size.height; - self.position = ccp(s.width/2, s.height/2); - - int z=0; - - if (item) { - [self addChild: item z:z]; - MenuItem *i = va_arg(args, MenuItem*); - while(i) { - z++; - [self addChild: i z:z]; - i = va_arg(args, MenuItem*); - } - } -// [self alignItemsVertically]; - - selectedItem = nil; - state = kMenuStateWaiting; - - return self; -} - --(void) dealloc -{ - [super dealloc]; -} - -/* - * override add: - */ --(id) addChild:(MenuItem*)child z:(int)z tag:(int) aTag -{ - NSAssert( [child isKindOfClass:[MenuItem class]], @"Menu only supports MenuItem objects as children"); - return [super addChild:child z:z tag:aTag]; -} - -#pragma mark Menu - Events - --(void) onEnter -{ - [[TouchDispatcher sharedDispatcher] addEventHandler:self priority:0 swallowTouches:NO]; - [super onEnter]; -} - --(void) onExit -{ - [[TouchDispatcher sharedDispatcher] removeEventHandler:self]; - [super onExit]; -} - --(BOOL) ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event -{ - if( state != kMenuStateWaiting ) return NO; - - selectedItem = [self itemForTouch:touch]; - [selectedItem selected]; - - state = kMenuStateTrackingTouch; - return YES; -} - --(void) ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event -{ - NSAssert(state == kMenuStateTrackingTouch, @"[Menu ccTouchEnded] -- invalid state"); - - [selectedItem unselected]; - [selectedItem activate]; - - state = kMenuStateWaiting; -} - --(void) ccTouchCancelled:(UITouch *)touch withEvent:(UIEvent *)event -{ - NSAssert(state == kMenuStateTrackingTouch, @"[Menu ccTouchCancelled] -- invalid state"); - - [selectedItem unselected]; - - state = kMenuStateWaiting; -} - --(void) ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event -{ - NSAssert(state == kMenuStateTrackingTouch, @"[Menu ccTouchMoved] -- invalid state"); - - MenuItem *currentItem = [self itemForTouch:touch]; - - if (currentItem != selectedItem) { - [selectedItem unselected]; - selectedItem = currentItem; - [selectedItem selected]; - } -} - -#pragma mark Menu - Alignment --(void) alignItemsVertically -{ - return [self alignItemsVerticallyWithPadding:kDefaultPadding]; -} --(void) alignItemsVerticallyWithPadding:(float)padding -{ - float height = -padding; - for(MenuItem *item in children) - height += [item contentSize].height * item.scaleY + padding; - - float y = height / 2.0f; - for(MenuItem *item in children) { - [item setPosition:ccp(0, y - [item contentSize].height * item.scaleY / 2.0f)]; - y -= [item contentSize].height * item.scaleY + padding; - } -} - --(void) alignItemsHorizontally -{ - return [self alignItemsHorizontallyWithPadding:kDefaultPadding]; -} - --(void) alignItemsHorizontallyWithPadding:(float)padding -{ - - float width = -padding; - for(MenuItem* item in children) - width += [item contentSize].width * item.scaleX + padding; - - float x = -width / 2.0f; - for(MenuItem* item in children) { - [item setPosition:ccp(x + [item contentSize].width * item.scaleX / 2.0f, 0)]; - x += [item contentSize].width * item.scaleX + padding; - } -} - --(void) alignItemsInColumns: (NSNumber *) columns, ... -{ - va_list args; - va_start(args, columns); - - [self alignItemsInColumns:columns vaList:args]; - - va_end(args); -} - --(void) alignItemsInColumns: (NSNumber *) columns vaList: (va_list) args -{ - NSMutableArray *rows = [[NSMutableArray alloc] initWithObjects:columns, nil]; - columns = va_arg(args, NSNumber*); - while(columns) { - [rows addObject:columns]; - columns = va_arg(args, NSNumber*); - } - - int height = -5; - NSUInteger row = 0, rowHeight = 0, columnsOccupied = 0, rowColumns; - for(MenuItem *item in children) { - NSAssert( row < [rows count], @"Too many menu items for the amount of rows/columns."); - - rowColumns = [(NSNumber *) [rows objectAtIndex:row] unsignedIntegerValue]; - NSAssert( rowColumns, @"Can't have zero columns on a row"); - - rowHeight = fmaxf(rowHeight, [item contentSize].height); - ++columnsOccupied; - - if(columnsOccupied >= rowColumns) { - height += rowHeight + 5; - - columnsOccupied = 0; - rowHeight = 0; - ++row; - } - } - NSAssert( !columnsOccupied, @"Too many rows/columns for available menu items." ); - - CGSize winSize = [[Director sharedDirector] winSize]; - - row = 0; rowHeight = 0; rowColumns = 0; - float w, x, y = height / 2; - for(MenuItem *item in children) { - if(rowColumns == 0) { - rowColumns = [(NSNumber *) [rows objectAtIndex:row] unsignedIntegerValue]; - w = winSize.width / (1 + rowColumns); - x = w; - } - - rowHeight = fmaxf(rowHeight, [item contentSize].height); - [item setPosition:ccp(x - winSize.width / 2, - y - [item contentSize].height / 2)]; - - x += w + 10; - ++columnsOccupied; - - if(columnsOccupied >= rowColumns) { - y -= rowHeight + 5; - - columnsOccupied = 0; - rowColumns = 0; - rowHeight = 0; - ++row; - } - } - - [rows release]; -} - --(void) alignItemsInRows: (NSNumber *) rows, ... -{ - va_list args; - va_start(args, rows); - - [self alignItemsInRows:rows vaList:args]; - - va_end(args); -} - --(void) alignItemsInRows: (NSNumber *) rows vaList: (va_list) args -{ - NSMutableArray *columns = [[NSMutableArray alloc] initWithObjects:rows, nil]; - rows = va_arg(args, NSNumber*); - while(rows) { - [columns addObject:rows]; - rows = va_arg(args, NSNumber*); - } - - NSMutableArray *columnWidths = [[NSMutableArray alloc] init]; - NSMutableArray *columnHeights = [[NSMutableArray alloc] init]; - - int width = -10, columnHeight = -5; - NSUInteger column = 0, columnWidth = 0, rowsOccupied = 0, columnRows; - for(MenuItem *item in children) { - NSAssert( column < [columns count], @"Too many menu items for the amount of rows/columns."); - - columnRows = [(NSNumber *) [columns objectAtIndex:column] unsignedIntegerValue]; - NSAssert( columnRows, @"Can't have zero rows on a column"); - - columnWidth = fmaxf(columnWidth, [item contentSize].width); - columnHeight += [item contentSize].height + 5; - ++rowsOccupied; - - if(rowsOccupied >= columnRows) { - [columnWidths addObject:[NSNumber numberWithUnsignedInteger:columnWidth]]; - [columnHeights addObject:[NSNumber numberWithUnsignedInteger:columnHeight]]; - width += columnWidth + 10; - - rowsOccupied = 0; - columnWidth = 0; - columnHeight = -5; - ++column; - } - } - NSAssert( !rowsOccupied, @"Too many rows/columns for available menu items."); - - CGSize winSize = [[Director sharedDirector] winSize]; - - column = 0; columnWidth = 0; columnRows = 0; - float x = -width / 2, y; - for(MenuItem *item in children) { - if(columnRows == 0) { - columnRows = [(NSNumber *) [columns objectAtIndex:column] unsignedIntegerValue]; - y = ([(NSNumber *) [columnHeights objectAtIndex:column] intValue] + winSize.height) / 2; - } - - columnWidth = fmaxf(columnWidth, [item contentSize].width); - [item setPosition:ccp(x + [(NSNumber *) [columnWidths objectAtIndex:column] unsignedIntegerValue] / 2, - y - winSize.height / 2)]; - - y -= [item contentSize].height + 10; - ++rowsOccupied; - - if(rowsOccupied >= columnRows) { - x += columnWidth + 5; - - rowsOccupied = 0; - columnRows = 0; - columnWidth = 0; - ++column; - } - } - - [columns release]; - [columnWidths release]; - [columnHeights release]; -} - -#pragma mark Menu - Opacity Protocol - -/** Override synthesized setOpacity to recurse items */ -- (void) setOpacity:(GLubyte)newOpacity -{ - opacity_ = newOpacity; - for(id item in children) - [item setOpacity:opacity_]; -} - -- (void) setRGB:(GLubyte)r:(GLubyte)g:(GLubyte)b -{ - r_=r; - g_=g; - b_=b; - for(id item in children) - [item setRGB:r:g:b]; -} - -#pragma mark Menu - Private - --(MenuItem *) itemForTouch: (UITouch *) touch; -{ - CGPoint touchLocation = [touch locationInView: [touch view]]; - touchLocation = [[Director sharedDirector] convertCoordinate: touchLocation]; - - for( MenuItem* item in children ) { - CGPoint local = [item convertToNodeSpace:touchLocation]; - - CGRect r = [item rect]; - r.origin = CGPointZero; - - if( CGRectContainsPoint( r, local ) ) - return item; - } - return nil; -} - -@end diff --git a/Support/cocos2d/MenuItem.h b/Support/cocos2d/MenuItem.h deleted file mode 100644 index 92a481c..0000000 --- a/Support/cocos2d/MenuItem.h +++ /dev/null @@ -1,199 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2008,2009 Ricardo Quesada - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - -#import - -#import "CocosNode.h" - -@class Label; -@class LabelAtlas; -@class Sprite; - -#define kItemSize 32 - -/** Menu Item base class - * - * Subclass MenuItem (or any subclass) to create your custom MenuItem - */ -@interface MenuItem : CocosNode -{ - NSInvocation *invocation; - BOOL isEnabled; -} - -/** Creates a menu item with a target/selector */ -+(id) itemWithTarget:(id)target selector:(SEL)selector; - -/** Initializes a menu item with a target/selector */ --(id) initWithTarget:(id)target selector:(SEL)selector; - -/** Returns the outside box */ --(CGRect) rect; - -/** Activate the item */ --(void) activate; - -/** The item was selected (not activated), similar to "mouse-over" */ --(void) selected; - -/** The item was unselected */ --(void) unselected; - -/** Enable or disabled the MenuItem */ --(void) setIsEnabled:(BOOL)enabled; -/** Returns whether or not the MenuItem is enabled */ --(BOOL) isEnabled; -@end - -/** An abstract class for "label" MenuItems - Any CocosNode that supports the CocosNodeLabel protocol can be added. - Supported nodes: - - BitmapFontAtlas - - LabelAtlas - - Label - */ -@interface MenuItemLabel : MenuItem -{ - CocosNode *label_; -} - -/** Label that is rendered. It can be any CocosNode that implements the CocosNodeLabel */ -@property (readwrite,retain) CocosNode* label; - -/** creates a MenuItemLabel with a Label, target and selector */ -+(id) itemWithLabel:(CocosNode*)label target:(id)target selector:(SEL)selector; - -/** initializes a MenuItemLabel with a Label, target and selector */ --(id) initWithLabel:(CocosNode*)label target:(id)target selector:(SEL)selector; - -/** sets a new string to the inner label */ --(void) setString:(NSString*)label; - -/** Enable or disabled the MenuItemFont - @warning setIsEnabled changes the RGB color of the font - */ --(void) setIsEnabled: (BOOL)enabled; -@end - -/** A MenuItemAtlasFont - Helper class that creates a MenuItemLabel class with a LabelAtlas - */ -@interface MenuItemAtlasFont : MenuItemLabel -{ -} - -/** creates a menu item from a string and atlas with a target/selector */ -+(id) itemFromString: (NSString*) value charMapFile:(NSString*) charMapFile itemWidth:(int)itemWidth itemHeight:(int)itemHeight startCharMap:(char)startCharMap; - -/** creates a menu item from a string and atlas. Use it with MenuItemToggle */ -+(id) itemFromString: (NSString*) value charMapFile:(NSString*) charMapFile itemWidth:(int)itemWidth itemHeight:(int)itemHeight startCharMap:(char)startCharMap target:(id) rec selector:(SEL) cb; - -/** initializes a menu item from a string and atlas with a target/selector */ --(id) initFromString: (NSString*) value charMapFile:(NSString*) charMapFile itemWidth:(int)itemWidth itemHeight:(int)itemHeight startCharMap:(char)startCharMap target:(id) rec selector:(SEL) cb; - - -@end - -/** A MenuItemFont - Helper class that creates a MenuItemLabel class with a Label - */ -@interface MenuItemFont : MenuItemLabel -{ -} -/** set font size */ -+(void) setFontSize: (int) s; - -/** get font size */ -+(int) fontSize; - -/** set the font name */ -+(void) setFontName: (NSString*) n; - -/** get the font name */ -+(NSString*) fontName; - -/** creates a menu item from a string. Use it with MenuItemToggle */ -+(id) itemFromString: (NSString*) value; - -/** creates a menu item from a string with a target/selector */ -+(id) itemFromString: (NSString*) value target:(id) r selector:(SEL) s; - -/** initializes a menu item from a string with a target/selector */ --(id) initFromString: (NSString*) value target:(id) r selector:(SEL) s; -@end - -/** A MenuItemImage - A class that creates a MenuItem with 3 images: - - unselected image - - selected image - - disabled image - - For best results try that all images are of the same size - */ -@interface MenuItemImage : MenuItem -{ - BOOL selected; - Sprite *normalImage_, *selectedImage_, *disabledImage_; -} - -/// Sprite (image) that is displayed when the MenuItem is not selected -@property (readwrite,retain) Sprite *normalImage; -/// Sprite (image) that is displayed when the MenuItem is selected -@property (readwrite,retain) Sprite *selectedImage; -/// Sprite (image) that is displayed when the MenuItem is disabled -@property (readwrite,retain) Sprite *disabledImage; - -/** creates a menu item with a normal and selected image*/ -+(id) itemFromNormalImage: (NSString*)value selectedImage:(NSString*) value2; -/** creates a menu item with a normal and selected image with target/selector */ -+(id) itemFromNormalImage: (NSString*)value selectedImage:(NSString*) value2 target:(id) r selector:(SEL) s; -/** creates a menu item with a normal,selected and disabled image with target/selector */ -+(id) itemFromNormalImage: (NSString*)value selectedImage:(NSString*) value2 disabledImage:(NSString*) value3 target:(id) r selector:(SEL) s; -/** initializes a menu item with a normal, selected and disabled image with target/selector */ --(id) initFromNormalImage: (NSString*) value selectedImage:(NSString*)value2 disabledImage:(NSString*) value3 target:(id) r selector:(SEL) s; -@end - - - -/** A MenuItemToggle - A simple container class that "toggles" it's inner items - The inner itmes can be any MenuItem - */ -@interface MenuItemToggle : MenuItem -{ - NSUInteger selectedIndex_; - NSMutableArray* subItems_; - GLubyte opacity_, r_, g_, b_; -} - -/** conforms with CocosNodeRGBA protocol */ -@property (readonly) GLubyte opacity,r,g,b; - -/** returns the selected item */ -@property (readwrite) NSUInteger selectedIndex; -/** NSMutableArray that contains the subitems. You can add/remove items in runtime, and you can replace the array with a new one. - @since v0.7.2 - */ -@property (readwrite,retain) NSMutableArray *subItems; - -/** creates a menu item from a list of items with a target/selector */ -+(id) itemWithTarget:(id)t selector:(SEL)s items:(MenuItem*) item, ... NS_REQUIRES_NIL_TERMINATION; - -/** initializes a menu item from a list of items with a target selector */ --(id) initWithTarget:(id)t selector:(SEL)s items:(MenuItem*) item vaList:(va_list) args; - -/** return the selected item */ --(MenuItem*) selectedItem; -@end - diff --git a/Support/cocos2d/MenuItem.m b/Support/cocos2d/MenuItem.m deleted file mode 100644 index 4547968..0000000 --- a/Support/cocos2d/MenuItem.m +++ /dev/null @@ -1,564 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2008,2009 Ricardo Quesada - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - -#import "MenuItem.h" -#import "Label.h" -#import "LabelAtlas.h" -#import "IntervalAction.h" -#import "Sprite.h" -#import "Support/CGPointExtension.h" - -static int _fontSize = kItemSize; -static NSString *_fontName = @"Marker Felt"; -static BOOL _fontNameRelease = NO; - -enum { - kCurrentItem = 0xc0c05001, -}; - -enum { - kZoomActionTag = 0xc0c05002, -}; - - - -#pragma mark - -#pragma mark MenuItem - -@implementation MenuItem - --(id) init -{ - NSException* myException = [NSException - exceptionWithName:@"MenuItemInit" - reason:@"Init not supported. Use InitFromString" - userInfo:nil]; - @throw myException; -} - -+(id) itemWithTarget:(id) r selector:(SEL) s -{ - return [[[self alloc] initWithTarget:r selector:s] autorelease]; -} - --(id) initWithTarget:(id) rec selector:(SEL) cb -{ - if((self=[super init]) ) { - - anchorPoint_ = ccp(0.5f, 0.5f); - NSMethodSignature * sig = nil; - - if( rec && cb ) { - sig = [[rec class] instanceMethodSignatureForSelector:cb]; - - invocation = nil; - invocation = [NSInvocation invocationWithMethodSignature:sig]; - [invocation setTarget:rec]; - [invocation setSelector:cb]; - [invocation setArgument:&self atIndex:2]; - [invocation retain]; - } - - isEnabled = YES; - } - - return self; -} - --(void) dealloc -{ - [invocation release]; - [super dealloc]; -} - --(void) selected -{ - NSAssert(1,@"MenuItem.selected must be overriden"); -} - --(void) unselected -{ - NSAssert(1,@"MenuItem.unselected must be overriden"); -} - --(void) activate -{ - if(isEnabled) - [invocation invoke]; -} - --(void) setIsEnabled: (BOOL)enabled -{ - isEnabled = enabled; -} - --(BOOL) isEnabled -{ - return isEnabled; -} - --(CGRect) rect -{ - return CGRectMake( self.position.x - contentSize_.width/2, self.position.y-contentSize_.height/2, - contentSize_.width, contentSize_.height); -} -@end - - -#pragma mark - -#pragma mark MenuItemLabel - -@implementation MenuItemLabel - -+(id) itemWithLabel:(CocosNode*)label target:(id)target selector:(SEL)selector -{ - return [[[self class] alloc] initWithLabel:label target:target selector:selector]; -} - --(id) initWithLabel:(CocosNode*)label target:(id)target selector:(SEL)selector -{ - if( (self=[super initWithTarget:target selector:selector]) ) { - self.label = label; - } - return self; -} - --(CocosNode*) label -{ - return label_; -} --(void) setLabel:(CocosNode*) label -{ - [label_ release]; - label_ = [label retain]; - [self setContentSize:[label_ contentSize]]; -} - -- (void) dealloc -{ - [label_ release]; - [super dealloc]; -} - --(void) setString:(NSString *)string -{ - [label_ setString:string]; - [self setContentSize: [label_ contentSize]]; -} - --(void) activate { - if(isEnabled) { - [self stopAllActions]; - - self.scale = 1.0f; - - [super activate]; - } -} - --(void) selected -{ - // subclass to change the default action - if(isEnabled) { - [self stopActionByTag:kZoomActionTag]; - Action *zoomAction = [ScaleTo actionWithDuration:0.1f scale:1.2f]; - zoomAction.tag = kZoomActionTag; - [self runAction:zoomAction]; - } -} - --(void) unselected -{ - // subclass to change the default action - if(isEnabled) { - [self stopActionByTag:kZoomActionTag]; - Action *zoomAction = [ScaleTo actionWithDuration:0.1f scale:1.0f]; - zoomAction.tag = kZoomActionTag; - [self runAction:zoomAction]; - } -} - --(void) setIsEnabled: (BOOL)enabled -{ - if(enabled == NO) - [label_ setRGB:126 :126 :126]; - else - [label_ setRGB:255 :255 :255]; - - [super setIsEnabled:enabled]; -} - --(void) draw -{ - [label_ draw]; -} - -- (void) setOpacity: (GLubyte)opacity -{ - [label_ setOpacity:opacity]; -} --(GLubyte) opacity -{ - return [label_ opacity]; -} -- (void) setRGB:(GLubyte)r:(GLubyte)g:(GLubyte)b -{ - [label_ setRGB:r:g:b]; -} --(GLubyte)r -{ - return [label_ r]; -} --(GLubyte)g -{ - return [label_ g]; -} --(GLubyte)b -{ - return [label_ b]; -} -@end - -#pragma mark - -#pragma mark MenuItemAtlasFont - -@implementation MenuItemAtlasFont - -+(id) itemFromString: (NSString*) value charMapFile:(NSString*) charMapFile itemWidth:(int)itemWidth itemHeight:(int)itemHeight startCharMap:(char)startCharMap -{ - return [MenuItemAtlasFont itemFromString:value charMapFile:charMapFile itemWidth:itemWidth itemHeight:itemHeight startCharMap:startCharMap target:nil selector:nil]; -} - -+(id) itemFromString: (NSString*) value charMapFile:(NSString*) charMapFile itemWidth:(int)itemWidth itemHeight:(int)itemHeight startCharMap:(char)startCharMap target:(id) rec selector:(SEL) cb -{ - return [[[self alloc] initFromString:value charMapFile:charMapFile itemWidth:itemWidth itemHeight:itemHeight startCharMap:startCharMap target:rec selector:cb] autorelease]; -} - --(id) initFromString: (NSString*) value charMapFile:(NSString*) charMapFile itemWidth:(int)itemWidth itemHeight:(int)itemHeight startCharMap:(char)startCharMap target:(id) rec selector:(SEL) cb -{ - NSAssert( [value length] != 0, @"value lenght must be greater than 0"); - - LabelAtlas *label = [[LabelAtlas alloc] initWithString:value charMapFile:charMapFile itemWidth:itemWidth itemHeight:itemHeight startCharMap:startCharMap]; - [label autorelease]; - - if((self=[super initWithLabel:label target:rec selector:cb]) ) { - // do something ? - } - - return self; -} - --(void) dealloc -{ - [super dealloc]; -} -@end - - -#pragma mark - -#pragma mark MenuItemFont - -@implementation MenuItemFont - -+(void) setFontSize: (int) s -{ - _fontSize = s; -} - -+(int) fontSize -{ - return _fontSize; -} - -+(void) setFontName: (NSString*) n -{ - if( _fontNameRelease ) - [_fontName release]; - - _fontName = [n retain]; - _fontNameRelease = YES; -} - -+(NSString*) fontName -{ - return _fontName; -} - -+(id) itemFromString: (NSString*) value target:(id) r selector:(SEL) s -{ - return [[[self alloc] initFromString: value target:r selector:s] autorelease]; -} - -+(id) itemFromString: (NSString*) value -{ - return [[[self alloc] initFromString: value target:nil selector:nil] autorelease]; -} - --(id) initFromString: (NSString*) value target:(id) rec selector:(SEL) cb -{ - NSAssert( [value length] != 0, @"Value lenght must be greater than 0"); - - Label *label = [Label labelWithString:value fontName:_fontName fontSize:_fontSize]; - - if((self=[super initWithLabel:label target:rec selector:cb]) ) { - // do something ? - } - - return self; -} - --(void) dealloc -{ - [super dealloc]; -} -@end - -#pragma mark MenuItemImage - -@implementation MenuItemImage - -@synthesize selectedImage=selectedImage_, normalImage=normalImage_, disabledImage=disabledImage_; - -+(id) itemFromNormalImage: (NSString*)value selectedImage:(NSString*) value2 -{ - return [self itemFromNormalImage:value selectedImage:value2 disabledImage: nil target:nil selector:nil]; -} - -+(id) itemFromNormalImage: (NSString*)value selectedImage:(NSString*) value2 target:(id) t selector:(SEL) s -{ - return [self itemFromNormalImage:value selectedImage:value2 disabledImage: nil target:t selector:s]; -} - -+(id) itemFromNormalImage: (NSString*)value selectedImage:(NSString*) value2 disabledImage: (NSString*) value3 -{ - return [[[self alloc] initFromNormalImage:value selectedImage:value2 disabledImage:value3 target:nil selector:nil] autorelease]; -} - -+(id) itemFromNormalImage: (NSString*)value selectedImage:(NSString*) value2 disabledImage: (NSString*) value3 target:(id) t selector:(SEL) s -{ - return [[[self alloc] initFromNormalImage:value selectedImage:value2 disabledImage:value3 target:t selector:s] autorelease]; -} - --(id) initFromNormalImage: (NSString*) normalI selectedImage:(NSString*)selectedI disabledImage: (NSString*) disabledI target:(id) t selector:(SEL) sel -{ - if( (self=[super initWithTarget:t selector:sel]) ) { - - self.normalImage = [Sprite spriteWithFile:normalI]; - self.selectedImage = [Sprite spriteWithFile:selectedI]; - - if(disabledI == nil) - self.disabledImage = nil; - else - self.disabledImage = [Sprite spriteWithFile:disabledI]; - - // [normalImage setOpacity:opacity_]; - // [normalImage setRGB:r_:g_:b_]; - // [selectedImage setOpacity:opacity_]; - // [selectedImage setRGB:r_:g_:b_]; - // [disabledImage setOpacity:opacity_]; - // [disabledImage setRGB:r_:g_:b_]; - - [self setContentSize: [normalImage_ contentSize]]; - } - return self; -} - --(void) dealloc -{ - [normalImage_ release]; - [selectedImage_ release]; - [disabledImage_ release]; - - [super dealloc]; -} - --(void) selected -{ - selected = YES; -} - --(void) unselected -{ - selected = NO; -} - --(void) draw -{ - if(isEnabled) { - if( selected ) - [selectedImage_ draw]; - else - [normalImage_ draw]; - - } else { - if(disabledImage_ != nil) - [disabledImage_ draw]; - - // disabled image was not provided - else - [normalImage_ draw]; - } -} - -- (void) setOpacity: (GLubyte)opacity -{ - [normalImage_ setOpacity:opacity]; - [selectedImage_ setOpacity:opacity]; - [disabledImage_ setOpacity:opacity]; -} - -- (void) setRGB:(GLubyte)r:(GLubyte)g:(GLubyte)b -{ - [normalImage_ setRGB:r:g:b]; - [selectedImage_ setRGB:r:g:b]; - [disabledImage_ setRGB:r:g:b]; -} --(GLubyte) opacity -{ - return [normalImage_ opacity]; -} --(GLubyte)r -{ - return [normalImage_ r]; -} --(GLubyte)g -{ - return [normalImage_ g]; -} --(GLubyte)b -{ - return [normalImage_ b]; -} - -@end - -#pragma mark MenuItemToggle - -// -// MenuItemToggle -// -@implementation MenuItemToggle - -@synthesize subItems = subItems_; -@synthesize opacity=opacity_, r=r_, g=g_, b=b_; - -+(id) itemWithTarget: (id)t selector: (SEL)sel items: (MenuItem*) item, ... -{ - va_list args; - va_start(args, item); - - id s = [[[self alloc] initWithTarget: t selector:sel items: item vaList:args] autorelease]; - - va_end(args); - return s; -} - --(id) initWithTarget: (id)t selector: (SEL)sel items:(MenuItem*) item vaList: (va_list) args -{ - if( (self=[super initWithTarget:t selector:sel]) ) { - - self.subItems = [NSMutableArray arrayWithCapacity:2]; - - int z = 0; - MenuItem *i = item; - while(i) { - z++; - [subItems_ addObject:i]; - i = va_arg(args, MenuItem*); - } - - selectedIndex_ = NSUIntegerMax; - [self setSelectedIndex:0]; - } - - return self; -} - --(void) dealloc -{ - [subItems_ release]; - [super dealloc]; -} - --(void)setSelectedIndex:(NSUInteger)index -{ - if( index != selectedIndex_ ) { - selectedIndex_=index; - [self removeChildByTag:kCurrentItem cleanup:NO]; - - MenuItem *item = [subItems_ objectAtIndex:selectedIndex_]; - [self addChild:item z:0 tag:kCurrentItem]; - - CGSize s = [item contentSize]; - [self setContentSize: s]; - item.position = ccp( s.width/2, s.height/2 ); - } -} - --(NSUInteger) selectedIndex -{ - return selectedIndex_; -} - - --(void) selected -{ - [[subItems_ objectAtIndex:selectedIndex_] selected]; -} - --(void) unselected -{ - [[subItems_ objectAtIndex:selectedIndex_] unselected]; -} - --(void) activate -{ - // update index - - if( isEnabled ) { - NSUInteger newIndex = (selectedIndex_ + 1) % [subItems_ count]; - [self setSelectedIndex:newIndex]; - - [invocation invoke]; - } -} - --(void) setIsEnabled: (BOOL)enabled -{ - [super setIsEnabled:enabled]; - for(MenuItem* item in subItems_) - [item setIsEnabled:enabled]; -} - --(MenuItem*) selectedItem -{ - return [subItems_ objectAtIndex:selectedIndex_]; -} - -- (void) setOpacity: (GLubyte)opacity -{ - opacity_ = opacity; - for(MenuItem* item in subItems_) - [item setOpacity:opacity]; -} - -- (void) setRGB:(GLubyte)r:(GLubyte)g:(GLubyte)b -{ - r_ = r; - g_ = g; - b_ = b; - for(MenuItem* item in subItems_) - [item setRGB:r:g:b]; -} -@end diff --git a/Support/cocos2d/ParallaxNode.h b/Support/cocos2d/ParallaxNode.h deleted file mode 100644 index 4374712..0000000 --- a/Support/cocos2d/ParallaxNode.h +++ /dev/null @@ -1,32 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2009 Ricardo Quesada - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - -#import "CocosNode.h" - -/** ParallaxNode: A node that simulates a parallax scroller - - The children will be moved faster / slower than the parent according the the parallax ratio. - - */ -@interface ParallaxNode : CocosNode { - NSMutableDictionary *parallaxDictionary; -} - -/** Adds a child to the container with a z-order, a parallax ratio and a position offset - It returns self, so you can chain several addChilds. - @since v0.8 - */ --(id) addChild: (CocosNode*)node z:(int)z parallaxRatio:(CGPoint)c positionOffset:(CGPoint)positionOffset; - -@end diff --git a/Support/cocos2d/ParallaxNode.m b/Support/cocos2d/ParallaxNode.m deleted file mode 100644 index 5be6ca3..0000000 --- a/Support/cocos2d/ParallaxNode.m +++ /dev/null @@ -1,105 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2009 Ricardo Quesada - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - -#import "ParallaxNode.h" -#import "Support/CGPointExtension.h" - - -@interface CGPointObject : NSObject -{ - CGPoint point_; - CGPoint offset_; -} -@property (readwrite) CGPoint point; -@property (readwrite) CGPoint offset; -+(id) pointWithCGPoint:(CGPoint)point offset:(CGPoint)offset; --(id) initWithCGPoint:(CGPoint)point offset:(CGPoint)offset; -@end -@implementation CGPointObject -@synthesize point = point_; -@synthesize offset = offset_; - -+(id) pointWithCGPoint:(CGPoint)point offset:(CGPoint)offset -{ - return [[[self alloc] initWithCGPoint:point offset:offset] autorelease]; -} --(id) initWithCGPoint:(CGPoint)aPoint offset:(CGPoint)offset -{ - if( (self=[super init])) { - point_ = aPoint; - offset_ = offset; - } - return self; -} -@end - - -@implementation ParallaxNode - --(id) init -{ - if( (self=[super init]) ) { - parallaxDictionary = [[NSMutableDictionary dictionaryWithCapacity:5] retain]; - } - return self; -} - -- (void) dealloc -{ - [parallaxDictionary release]; - [super dealloc]; -} - --(NSString*) addressForObject:(CocosNode*)child -{ - return [NSString stringWithFormat:@"<%08X>", child]; -} --(id) addChild: (CocosNode*) child z:(int)z parallaxRatio:(CGPoint)c positionOffset:(CGPoint)offset -{ - NSAssert( child != nil, @"Argument must be non-nil"); - [parallaxDictionary setObject:[CGPointObject pointWithCGPoint:c offset:offset] forKey:[self addressForObject:child]]; - - CGPoint pos = self.position; - float x = pos.x * c.x + offset.x; - float y = pos.y * c.y + offset.y; - child.position = ccp(x,y); - - return [super addChild: child z:z tag:child.tag]; -} - --(void) removeChild:(CocosNode*)node cleanup:(BOOL)cleanup -{ - [parallaxDictionary removeObjectForKey:[self addressForObject:node]]; - [super removeChild:node cleanup:cleanup]; -} - --(void) removeAllChildrenWithCleanup:(BOOL)cleanup -{ - [parallaxDictionary removeAllObjects]; - [super removeAllChildrenWithCleanup:cleanup]; -} - --(void) setPosition:(CGPoint)pos -{ - for( CocosNode *node in children) { - CGPointObject *point = [parallaxDictionary objectForKey:[self addressForObject:node]]; - float x = -pos.x + pos.x * point.point.x + point.offset.x; - float y = -pos.y + pos.y * point.point.y + point.offset.y; - - node.position = ccp(x,y); - } - - [super setPosition:pos]; -} -@end diff --git a/Support/cocos2d/ParticleExamples.h b/Support/cocos2d/ParticleExamples.h deleted file mode 100644 index 6268421..0000000 --- a/Support/cocos2d/ParticleExamples.h +++ /dev/null @@ -1,82 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2008,2009 Ricardo Quesada - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - -#import "PointParticleSystem.h" -#import "QuadParticleSystem.h" - -//! Fire particle system -@interface ParticleFire: PointParticleSystem -{ -} -@end - -//! Fireworks particle system -@interface ParticleFireworks : PointParticleSystem -{ -} -@end - -//! Sun particle system -@interface ParticleSun : PointParticleSystem -{ -} -@end - -//! Galaxy particle system -@interface ParticleGalaxy : PointParticleSystem -{ -} -@end - -//! Flower particle system -@interface ParticleFlower : PointParticleSystem -{ -} -@end - -//! Meteor particle system -@interface ParticleMeteor : PointParticleSystem -{ -} -@end - -//! Spiral particle system -@interface ParticleSpiral : PointParticleSystem -{ -} -@end - -//! Explosion particle system -@interface ParticleExplosion : PointParticleSystem -{ -} -@end - -//! Smoke particle system -@interface ParticleSmoke : PointParticleSystem -{ -} -@end - -//! Snow particle system -@interface ParticleSnow : PointParticleSystem -{ -} -@end - -//! Rain particle system -@interface ParticleRain : PointParticleSystem -{ -} -@end diff --git a/Support/cocos2d/ParticleExamples.m b/Support/cocos2d/ParticleExamples.m deleted file mode 100644 index c041762..0000000 --- a/Support/cocos2d/ParticleExamples.m +++ /dev/null @@ -1,883 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2008,2009 Ricardo Quesada - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - - -// cocos2d -#import "ParticleExamples.h" -#import "TextureMgr.h" -#import "Director.h" -#import "Support/CGPointExtension.h" - -// -// ParticleFireworks -// -@implementation ParticleFireworks --(id) init -{ - return [self initWithTotalParticles:1500]; -} - --(id) initWithTotalParticles:(int)p -{ - if( !(self=[super initWithTotalParticles:p]) ) - return nil; - - // duration - duration = -1; - - // gravity - gravity.x = 0; - gravity.y = -90; - - // angle - angle = 90; - angleVar = 20; - - // radial - radialAccel = 0; - radialAccelVar = 0; - - // speed of particles - speed = 180; - speedVar = 50; - - // emitter position - self.position = ccp(160, 160); - - // life of particles - life = 3.5f; - lifeVar = 1; - - // emits per frame - emissionRate = totalParticles/life; - - // color of particles - startColor.r = 0.5f; - startColor.g = 0.5f; - startColor.b = 0.5f; - startColor.a = 1.0f; - startColorVar.r = 0.5f; - startColorVar.g = 0.5f; - startColorVar.b = 0.5f; - startColorVar.a = 0.1f; - endColor.r = 0.1f; - endColor.g = 0.1f; - endColor.b = 0.1f; - endColor.a = 0.2f; - endColorVar.r = 0.1f; - endColorVar.g = 0.1f; - endColorVar.b = 0.1f; - endColorVar.a = 0.2f; - - // size, in pixels - startSize = 8.0f; - startSizeVar = 2.0f; - endSize = kParticleStartSizeEqualToEndSize; - - self.texture = [[TextureMgr sharedTextureMgr] addImage: @"fire.png"]; - - // additive - blendAdditive = NO; - - return self; -} -@end - -// -// ParticleFire -// -@implementation ParticleFire --(id) init -{ - return [self initWithTotalParticles:250]; -} - --(id) initWithTotalParticles:(int) p -{ - if( !(self=[super initWithTotalParticles:p]) ) - return nil; - - // duration - duration = -1; - - // gravity - gravity.x = 0; - gravity.y = 0; - - // angle - angle = 90; - angleVar = 10; - - // radial acceleration - radialAccel = 0; - radialAccelVar = 0; - - // emitter position - self.position = ccp(160, 60); - posVar = ccp(40, 20); - - // life of particles - life = 3; - lifeVar = 0.25f; - - // speed of particles - speed = 60; - speedVar = 20; - - // size, in pixels - startSize = 54.0f; - startSizeVar = 10.0f; - endSize = kParticleStartSizeEqualToEndSize; - - // emits per frame - emissionRate = totalParticles/life; - - // color of particles - startColor.r = 0.76f; - startColor.g = 0.25f; - startColor.b = 0.12f; - startColor.a = 1.0f; - startColorVar.r = 0.0f; - startColorVar.g = 0.0f; - startColorVar.b = 0.0f; - startColorVar.a = 0.0f; - endColor.r = 0.0f; - endColor.g = 0.0f; - endColor.b = 0.0f; - endColor.a = 1.0f; - endColorVar.r = 0.0f; - endColorVar.g = 0.0f; - endColorVar.b = 0.0f; - endColorVar.a = 0.0f; - - self.texture = [[TextureMgr sharedTextureMgr] addImage: @"fire.png"]; - - // additive - blendAdditive = YES; - - return self; -} -@end - -// -// ParticleSun -// -@implementation ParticleSun --(id) init -{ - return [self initWithTotalParticles:350]; -} - --(id) initWithTotalParticles:(int) p -{ - if( !(self=[super initWithTotalParticles:p]) ) - return nil; - - // additive - blendAdditive = YES; - - // duration - duration = -1; - - // gravity - gravity.x = 0; - gravity.y = 0; - - // angle - angle = 90; - angleVar = 360; - - // radial acceleration - radialAccel = 0; - radialAccelVar = 0; - - // emitter position - self.position = ccp(160, 240); - posVar = CGPointZero; - - // life of particles - life = 1; - lifeVar = 0.5f; - - // speed of particles - speed = 20; - speedVar = 5; - - // size, in pixels - startSize = 30.0f; - startSizeVar = 10.0f; - endSize = kParticleStartSizeEqualToEndSize; - - // emits per seconds - emissionRate = totalParticles/life; - - // color of particles - startColor.r = 0.76f; - startColor.g = 0.25f; - startColor.b = 0.12f; - startColor.a = 1.0f; - startColorVar.r = 0.0f; - startColorVar.g = 0.0f; - startColorVar.b = 0.0f; - startColorVar.a = 0.0f; - endColor.r = 0.0f; - endColor.g = 0.0f; - endColor.b = 0.0f; - endColor.a = 1.0f; - endColorVar.r = 0.0f; - endColorVar.g = 0.0f; - endColorVar.b = 0.0f; - endColorVar.a = 0.0f; - - self.texture = [[TextureMgr sharedTextureMgr] addImage: @"fire.png"]; - - return self; -} -@end - -// -// ParticleGalaxy -// -@implementation ParticleGalaxy --(id) init -{ - return [self initWithTotalParticles:200]; -} - --(id) initWithTotalParticles:(int)p -{ - if( !(self=[super initWithTotalParticles:p]) ) - return nil; - - // duration - duration = -1; - - // gravity - gravity.x = 0; - gravity.y = 0; - - // angle - angle = 90; - angleVar = 360; - - // speed of particles - speed = 60; - speedVar = 10; - - // radial - radialAccel = -80; - radialAccelVar = 0; - - // tagential - tangentialAccel = 80; - tangentialAccelVar = 0; - - // emitter position - self.position = ccp(160, 240); - posVar = CGPointZero; - - // life of particles - life = 4; - lifeVar = 1; - - // size, in pixels - startSize = 37.0f; - startSizeVar = 10.0f; - endSize = kParticleStartSizeEqualToEndSize; - - // emits per second - emissionRate = totalParticles/life; - - // color of particles - startColor.r = 0.12f; - startColor.g = 0.25f; - startColor.b = 0.76f; - startColor.a = 1.0f; - startColorVar.r = 0.0f; - startColorVar.g = 0.0f; - startColorVar.b = 0.0f; - startColorVar.a = 0.0f; - endColor.r = 0.0f; - endColor.g = 0.0f; - endColor.b = 0.0f; - endColor.a = 1.0f; - endColorVar.r = 0.0f; - endColorVar.g = 0.0f; - endColorVar.b = 0.0f; - endColorVar.a = 0.0f; - - self.texture = [[TextureMgr sharedTextureMgr] addImage: @"fire.png"]; - - // additive - blendAdditive = YES; - - return self; -} -@end - -// -// ParticleFlower -// -@implementation ParticleFlower --(id) init -{ - return [self initWithTotalParticles:250]; -} - --(id) initWithTotalParticles:(int) p -{ - if( !(self=[super initWithTotalParticles:p]) ) - return nil; - - // duration - duration = -1; - - // gravity - gravity.x = 0; - gravity.y = 0; - - // angle - angle = 90; - angleVar = 360; - - // speed of particles - speed = 80; - speedVar = 10; - - // radial - radialAccel = -60; - radialAccelVar = 0; - - // tagential - tangentialAccel = 15; - tangentialAccelVar = 0; - - // emitter position - self.position = ccp(160, 240); - posVar = CGPointZero; - - // life of particles - life = 4; - lifeVar = 1; - - // size, in pixels - startSize = 30.0f; - startSizeVar = 10.0f; - endSize = kParticleStartSizeEqualToEndSize; - - // emits per second - emissionRate = totalParticles/life; - - // color of particles - startColor.r = 0.50f; - startColor.g = 0.50f; - startColor.b = 0.50f; - startColor.a = 1.0f; - startColorVar.r = 0.5f; - startColorVar.g = 0.5f; - startColorVar.b = 0.5f; - startColorVar.a = 0.5f; - endColor.r = 0.0f; - endColor.g = 0.0f; - endColor.b = 0.0f; - endColor.a = 1.0f; - endColorVar.r = 0.0f; - endColorVar.g = 0.0f; - endColorVar.b = 0.0f; - endColorVar.a = 0.0f; - - self.texture = [[TextureMgr sharedTextureMgr] addImage: @"fire.png"]; - - // additive - blendAdditive = YES; - - return self; -} -@end - -// -// ParticleMeteor -// -@implementation ParticleMeteor --(id) init -{ - return [self initWithTotalParticles:150]; -} - --(id) initWithTotalParticles:(int) p -{ - if( !(self=[super initWithTotalParticles:p]) ) - return nil; - - // duration - duration = -1; - - // gravity - gravity.x = -200; - gravity.y = 200; - - // angle - angle = 90; - angleVar = 360; - - // speed of particles - speed = 15; - speedVar = 5; - - // radial - radialAccel = 0; - radialAccelVar = 0; - - // tagential - tangentialAccel = 0; - tangentialAccelVar = 0; - - // emitter position - self.position = ccp(160, 240); - posVar = CGPointZero; - - // life of particles - life = 2; - lifeVar = 1; - - // size, in pixels - startSize = 60.0f; - startSizeVar = 10.0f; - endSize = kParticleStartSizeEqualToEndSize; - - // emits per second - emissionRate = totalParticles/life; - - // color of particles - startColor.r = 0.2f; - startColor.g = 0.4f; - startColor.b = 0.7f; - startColor.a = 1.0f; - startColorVar.r = 0.0f; - startColorVar.g = 0.0f; - startColorVar.b = 0.2f; - startColorVar.a = 0.1f; - endColor.r = 0.0f; - endColor.g = 0.0f; - endColor.b = 0.0f; - endColor.a = 1.0f; - endColorVar.r = 0.0f; - endColorVar.g = 0.0f; - endColorVar.b = 0.0f; - endColorVar.a = 0.0f; - - self.texture = [[TextureMgr sharedTextureMgr] addImage: @"fire.png"]; - - // additive - blendAdditive = YES; - - return self; -} -@end - -// -// ParticleSpiral -// -@implementation ParticleSpiral --(id) init -{ - return [self initWithTotalParticles:500]; -} - --(id) initWithTotalParticles:(int) p -{ - if( !(self=[super initWithTotalParticles:p]) ) - return nil; - - // duration - duration = -1; - - // gravity - gravity.x = 0; - gravity.y = 0; - - // angle - angle = 90; - angleVar = 0; - - // speed of particles - speed = 150; - speedVar = 0; - - // radial - radialAccel = -380; - radialAccelVar = 0; - - // tagential - tangentialAccel = 45; - tangentialAccelVar = 0; - - // emitter position - self.position = ccp(160, 240); - posVar = CGPointZero; - - // life of particles - life = 12; - lifeVar = 0; - - // size, in pixels - startSize = 20.0f; - startSizeVar = 0.0f; - endSize = kParticleStartSizeEqualToEndSize; - - // emits per second - emissionRate = totalParticles/life; - - // color of particles - startColor.r = 0.5f; - startColor.g = 0.5f; - startColor.b = 0.5f; - startColor.a = 1.0f; - startColorVar.r = 0.5f; - startColorVar.g = 0.5f; - startColorVar.b = 0.5f; - startColorVar.a = 0.0f; - endColor.r = 0.5f; - endColor.g = 0.5f; - endColor.b = 0.5f; - endColor.a = 1.0f; - endColorVar.r = 0.5f; - endColorVar.g = 0.5f; - endColorVar.b = 0.5f; - endColorVar.a = 0.0f; - - self.texture = [[TextureMgr sharedTextureMgr] addImage: @"fire.png"]; - - // additive - blendAdditive = NO; - - return self; -} -@end - -// -// ParticleExplosion -// -@implementation ParticleExplosion --(id) init -{ - return [self initWithTotalParticles:700]; -} - --(id) initWithTotalParticles:(int)p -{ - if( !(self=[super initWithTotalParticles:p]) ) - return nil; - - // duration - duration = 0.1f; - - // gravity - gravity.x = 0; - gravity.y = -100; - - // angle - angle = 90; - angleVar = 360; - - // speed of particles - speed = 70; - speedVar = 40; - - // radial - radialAccel = 0; - radialAccelVar = 0; - - // tagential - tangentialAccel = 0; - tangentialAccelVar = 0; - - // emitter position - self.position = ccp(160, 240); - posVar = CGPointZero; - - // life of particles - life = 5.0f; - lifeVar = 2; - - // size, in pixels - startSize = 15.0f; - startSizeVar = 10.0f; - endSize = kParticleStartSizeEqualToEndSize; - - // emits per second - emissionRate = totalParticles/duration; - - // color of particles - startColor.r = 0.7f; - startColor.g = 0.1f; - startColor.b = 0.2f; - startColor.a = 1.0f; - startColorVar.r = 0.5f; - startColorVar.g = 0.5f; - startColorVar.b = 0.5f; - startColorVar.a = 0.0f; - endColor.r = 0.5f; - endColor.g = 0.5f; - endColor.b = 0.5f; - endColor.a = 0.0f; - endColorVar.r = 0.5f; - endColorVar.g = 0.5f; - endColorVar.b = 0.5f; - endColorVar.a = 0.0f; - - self.texture = [[TextureMgr sharedTextureMgr] addImage: @"fire.png"]; - - // additive - blendAdditive = NO; - - return self; -} -@end - -// -// ParticleSmoke -// -@implementation ParticleSmoke --(id) init -{ - return [self initWithTotalParticles:200]; -} - --(id) initWithTotalParticles:(int) p -{ - if( !(self=[super initWithTotalParticles:p]) ) - return nil; - - // duration - duration = -1; - - // gravity - gravity.x = 0; - gravity.y = 0; - - // angle - angle = 90; - angleVar = 5; - - // radial acceleration - radialAccel = 0; - radialAccelVar = 0; - - // emitter position - self.position = ccp(160, 0); - posVar = ccp(20, 0); - - // life of particles - life = 4; - lifeVar = 1; - - // speed of particles - speed = 25; - speedVar = 10; - - // size, in pixels - startSize = 60.0f; - startSizeVar = 10.0f; - endSize = kParticleStartSizeEqualToEndSize; - - // emits per frame - emissionRate = totalParticles/life; - - // color of particles - startColor.r = 0.8f; - startColor.g = 0.8f; - startColor.b = 0.8f; - startColor.a = 1.0f; - startColorVar.r = 0.02f; - startColorVar.g = 0.02f; - startColorVar.b = 0.02f; - startColorVar.a = 0.0f; - endColor.r = 0.0f; - endColor.g = 0.0f; - endColor.b = 0.0f; - endColor.a = 1.0f; - endColorVar.r = 0.0f; - endColorVar.g = 0.0f; - endColorVar.b = 0.0f; - endColorVar.a = 0.0f; - - self.texture = [[TextureMgr sharedTextureMgr] addImage: @"fire.png"]; - - // additive - blendAdditive = NO; - - return self; -} -@end - -@implementation ParticleSnow --(id) init -{ - return [self initWithTotalParticles:700]; -} - --(id) initWithTotalParticles:(int)p -{ - if( !(self=[super initWithTotalParticles:p]) ) - return nil; - - // duration - duration = -1; - - // gravity - gravity.x = 0; - gravity.y = -1; - - // angle - angle = -90; - angleVar = 5; - - // speed of particles - speed = 5; - speedVar = 1; - - // radial - radialAccel = 0; - radialAccelVar = 1; - - // tagential - tangentialAccel = 0; - tangentialAccelVar = 1; - - // emitter position - self.position = (CGPoint) { - [[Director sharedDirector] winSize].width / 2, - [[Director sharedDirector] winSize].height + 10 - }; - posVar = ccp( [[Director sharedDirector] winSize].width / 2, 0 ); - - // life of particles - life = 45; - lifeVar = 15; - - // size, in pixels - startSize = 10.0f; - startSizeVar = 5.0f; - endSize = kParticleStartSizeEqualToEndSize; - - // emits per second - emissionRate = 10; - - // color of particles - startColor.r = 1.0f; - startColor.g = 1.0f; - startColor.b = 1.0f; - startColor.a = 1.0f; - startColorVar.r = 0.0f; - startColorVar.g = 0.0f; - startColorVar.b = 0.0f; - startColorVar.a = 0.0f; - endColor.r = 1.0f; - endColor.g = 1.0f; - endColor.b = 1.0f; - endColor.a = 0.0f; - endColorVar.r = 0.0f; - endColorVar.g = 0.0f; - endColorVar.b = 0.0f; - endColorVar.a = 0.0f; - - self.texture = [[TextureMgr sharedTextureMgr] addImage: @"fire.png"]; - - // additive - blendAdditive = NO; - - return self; -} -@end - -@implementation ParticleRain --(id) init -{ - return [self initWithTotalParticles:1000]; -} - --(id) initWithTotalParticles:(int)p -{ - if( !(self=[super initWithTotalParticles:p]) ) - return nil; - - // duration - duration = -1; - - // gravity - gravity.x = 10; - gravity.y = -10; - - // angle - angle = -90; - angleVar = 5; - - // speed of particles - speed = 130; - speedVar = 30; - - // radial - radialAccel = 0; - radialAccelVar = 1; - - // tagential - tangentialAccel = 0; - tangentialAccelVar = 1; - - // emitter position - self.position = (CGPoint) { - [[Director sharedDirector] winSize].width / 2, - [[Director sharedDirector] winSize].height - }; - posVar = ccp( [[Director sharedDirector] winSize].width / 2, 0 ); - - // life of particles - life = 4.5f; - lifeVar = 0; - - // size, in pixels - startSize = 4.0f; - startSizeVar = 2.0f; - endSize = kParticleStartSizeEqualToEndSize; - - // emits per second - emissionRate = 20; - - // color of particles - startColor.r = 0.7f; - startColor.g = 0.8f; - startColor.b = 1.0f; - startColor.a = 1.0f; - startColorVar.r = 0.0f; - startColorVar.g = 0.0f; - startColorVar.b = 0.0f; - startColorVar.a = 0.0f; - endColor.r = 0.7f; - endColor.g = 0.8f; - endColor.b = 1.0f; - endColor.a = 0.5f; - endColorVar.r = 0.0f; - endColorVar.g = 0.0f; - endColorVar.b = 0.0f; - endColorVar.a = 0.0f; - - self.texture = [[TextureMgr sharedTextureMgr] addImage: @"fire.png"]; - - // additive - blendAdditive = NO; - - return self; -} -@end diff --git a/Support/cocos2d/ParticleSystem.h b/Support/cocos2d/ParticleSystem.h deleted file mode 100644 index a24cef2..0000000 --- a/Support/cocos2d/ParticleSystem.h +++ /dev/null @@ -1,251 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2008,2009 Ricardo Quesada - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - -#import - -#import "CocosNode.h" -#import "ccTypes.h" - -enum { - kParticleStartSizeEqualToEndSize = -1, - kParticleDurationInfinity = -1, -}; - -typedef enum { - kPositionTypeLocal, - kPositionTypeWorld, - kPositionTypeCenterOfGravity, -} tPositionType; - -/** Structure that contains the values of each particle - */ -typedef struct sParticle -{ - CGPoint pos; - CGPoint startPos; - CGPoint dir; - float radialAccel; - float tangentialAccel; - ccColor4F color; - ccColor4F deltaColor; - float size; - float deltaSize; - float angle; - float deltaAngle; - float life; -} Particle; - -@class Texture2D; - -/** Particle System base class - Attributes of a Particle System: - * duration - * gravity - * emmision rate - * total max particles - * angle +- variance - * speed +- variance - * tangential acceleration +- variance - * radial acceleration +- variance - * start size +- variance - * end size +- variance - * start color +- variance - * end color +- variance - * life +- variance - * blend additive or not - * one texture - - Limitations: - * size can't be bigger than 64 - * the system can't be scaled since the particles are rendered using GL_POINT_SPRITE - */ -@interface ParticleSystem : CocosNode -{ - int id; - - // is the particle system active ? - BOOL active; - // duration in seconds of the system. -1 is infinity - float duration; - // time elapsed since the start of the system (in seconds) - float elapsed; - - /// Gravity of the particles - CGPoint gravity; - - // position is from "superclass" CocosNode - // Emitter source position - CGPoint source; - // Position variance - CGPoint posVar; - - // The angle (direction) of the particles measured in degrees - float angle; - // Angle variance measured in degrees; - float angleVar; - - // The speed the particles will have. - float speed; - // The speed variance - float speedVar; - - // Tangential acceleration - float tangentialAccel; - // Tangential acceleration variance - float tangentialAccelVar; - - // Radial acceleration - float radialAccel; - // Radial acceleration variance - float radialAccelVar; - - // start ize of the particles - float startSize; - // start Size variance - float startSizeVar; - // End size of the particle - float endSize; - // end size of variance - float endSizeVar; - - // How many seconds will the particle live - float life; - // Life variance - float lifeVar; - - // Start color of the particles - ccColor4F startColor; - // Start color variance - ccColor4F startColorVar; - // End color of the particles - ccColor4F endColor; - // End color variance - ccColor4F endColorVar; - - // start angle of the particles - float startSpin; - // start angle variance - float startSpinVar; - // End angle of the particle - float endSpin; - // end angle ariance - float endSpinVar; - - // Array of particles - Particle *particles; - // Maximum particles - int totalParticles; - // Count of active particles - int particleCount; - - // additive color or blend - BOOL blendAdditive; - // color modulate - BOOL colorModulate; - - // How many particles can be emitted per second - float emissionRate; - float emitCounter; - - // Texture of the particles - Texture2D *texture; - - // position type: world, local, center of gravity - tPositionType positionType_; - - // particle idx - int particleIdx; -} - -/** Is the emitter active */ -@property (readonly) BOOL active; -/** Quantity of particles that are being simulated at the moment */ -@property (readonly) int particleCount; -/** Gravity value */ -@property (readwrite,assign) CGPoint gravity; -/** How many seconds the emitter wil run. -1 means 'forever' */ -@property (readwrite,assign) float duration; -/** Source location of particles respective to emitter location */ -@property (readwrite,assign) CGPoint source; -/** Position variance of the emitter */ -@property (readwrite,assign) CGPoint posVar; -/** life, and life variation of each particle */ -@property (readwrite,assign) float life; -/** life variance of each particle */ -@property (readwrite,assign) float lifeVar; -/** angle and angle variation of each particle */ -@property (readwrite,assign) float angle; -/** angle variance of each particle */ -@property (readwrite,assign) float angleVar; -/** speed of each particle */ -@property (readwrite,assign) float speed; -/** speed variance of each particle */ -@property (readwrite,assign) float speedVar; -/** tangential acceleration of each particle */ -@property (readwrite,assign) float tangentialAccel; -/** tangential acceleration variance of each particle */ -@property (readwrite,assign) float tangentialAccelVar; -/** radial acceleration of each particle */ -@property (readwrite,assign) float radialAccel; -/** radial acceleration variance of each particle */ -@property (readwrite,assign) float radialAccelVar; -/** start size in pixels of each particle */ -@property (readwrite,assign) float startSize; -/** size variance in pixels of each particle */ -@property (readwrite,assign) float startSizeVar; -/** end size in pixels of each particle */ -@property (readwrite,assign) float endSize; -/** end size variance in pixels of each particle */ -@property (readwrite,assign) float endSizeVar; -/** start color of each particle */ -@property (readwrite,assign) ccColor4F startColor; -/** start color variance of each particle */ -@property (readwrite,assign) ccColor4F startColorVar; -/** end color and end color variation of each particle */ -@property (readwrite,assign) ccColor4F endColor; -/** end color variance of each particle */ -@property (readwrite,assign) ccColor4F endColorVar; -//* initial angle of each particle -@property (readwrite,assign) float startSpin; -//* initial angle of each particle -@property (readwrite,assign) float startSpinVar; -//* initial angle of each particle -@property (readwrite,assign) float endSpin; -//* initial angle of each particle -@property (readwrite,assign) float endSpinVar; -/** emission rate of the particles */ -@property (readwrite,assign) float emissionRate; -/** maximum particles of the system */ -@property (readwrite,assign) int totalParticles; -/** texture used to render the particles */ -@property (readwrite, retain) Texture2D * texture; -/** whether or not the particles are using "blend additive */ -@property (readwrite) BOOL blendAdditive; -/** position type */ -@property (readwrite) tPositionType positionType; - -//! Initializes a system with a fixed number of particles --(id) initWithTotalParticles:(int) numberOfParticles; -//! Add a particle to the emitter --(BOOL) addParticle; -//! Initializes a particle --(void) initParticle: (Particle*) particle; -//! stop emitting particles. Running particles will continue to run until they die --(void) stopSystem; -//! Kill all living particles. --(void) resetSystem; -//! whether or not the system is full --(BOOL) isFull; -@end - diff --git a/Support/cocos2d/ParticleSystem.m b/Support/cocos2d/ParticleSystem.m deleted file mode 100644 index e5f7987..0000000 --- a/Support/cocos2d/ParticleSystem.m +++ /dev/null @@ -1,209 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2008,2009 Ricardo Quesada - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - -// ideas taken from: -// . The ocean spray in your face [Jeff Lander] -// http://www.double.co.nz/dust/col0798.pdf -// . Building an Advanced Particle System [John van der Burg] -// http://www.gamasutra.com/features/20000623/vanderburg_01.htm -// . LOVE game engine -// http://love.sf.net - -// opengl -#import - -// cocos2d -#import "ParticleSystem.h" -#import "Primitives.h" -#import "TextureMgr.h" -#import "ccMacros.h" - -// support -#import "Support/OpenGL_Internal.h" -#import "Support/CGPointExtension.h" - -@implementation ParticleSystem -@synthesize active, duration; -@synthesize source, posVar; -@synthesize particleCount; -@synthesize life, lifeVar; -@synthesize angle, angleVar; -@synthesize speed, speedVar; -@synthesize tangentialAccel, tangentialAccelVar; -@synthesize radialAccel, radialAccelVar; -@synthesize startColor, startColorVar, endColor, endColorVar; -@synthesize startSpin, startSpinVar, endSpin, endSpinVar; -@synthesize emissionRate; -@synthesize totalParticles; -@synthesize startSize, startSizeVar; -@synthesize endSize, endSizeVar; -@synthesize gravity; -@synthesize texture; -@synthesize blendAdditive; -@synthesize positionType = positionType_; - --(id) init { - NSException* myException = [NSException - exceptionWithName:@"Particle.init" - reason:@"Particle.init shall not be called. Use initWithTotalParticles instead." - userInfo:nil]; - @throw myException; -} - --(id) initWithTotalParticles:(int) numberOfParticles -{ - if( (self=[super init]) ) { - - totalParticles = numberOfParticles; - - particles = malloc( sizeof(Particle) * totalParticles ); - - if( ! particles ) { - NSLog(@"Particle system: not enough memory"); - if( particles ) - free(particles); - return nil; - } - - bzero( particles, sizeof(Particle) * totalParticles ); - - // default, active - active = YES; - - // default: additive - blendAdditive = NO; - - // default position type; - positionType_ = kPositionTypeWorld; - - // default: modulate - // XXX: not used - // colorModulate = YES; - - [self schedule:@selector(step:)]; - } - - return self; -} - --(void) dealloc -{ - free( particles ); - - [texture release]; - - [super dealloc]; -} - --(BOOL) addParticle -{ - if( [self isFull] ) - return NO; - - Particle * particle = &particles[ particleCount ]; - - [self initParticle: particle]; - particleCount++; - - return YES; -} - --(void) initParticle: (Particle*) particle -{ - CGPoint v; - - // position - // XXX: source should be deprecated. - particle->pos.x = (int) (source.x + posVar.x * CCRANDOM_MINUS1_1()); - particle->pos.y = (int) (source.y + posVar.y * CCRANDOM_MINUS1_1()); - - // direction - float a = CC_DEGREES_TO_RADIANS( angle + angleVar * CCRANDOM_MINUS1_1() ); - v.y = sinf( a ); - v.x = cosf( a ); - float s = speed + speedVar * CCRANDOM_MINUS1_1(); - particle->dir = ccpMult( v, s ); - - // radial accel - particle->radialAccel = radialAccel + radialAccelVar * CCRANDOM_MINUS1_1(); - - // tangential accel - particle->tangentialAccel = tangentialAccel + tangentialAccelVar * CCRANDOM_MINUS1_1(); - - // life - particle->life = life + lifeVar * CCRANDOM_MINUS1_1(); - - // Color - ccColor4F start; - start.r = startColor.r + startColorVar.r * CCRANDOM_MINUS1_1(); - start.g = startColor.g + startColorVar.g * CCRANDOM_MINUS1_1(); - start.b = startColor.b + startColorVar.b * CCRANDOM_MINUS1_1(); - start.a = startColor.a + startColorVar.a * CCRANDOM_MINUS1_1(); - - ccColor4F end; - end.r = endColor.r + endColorVar.r * CCRANDOM_MINUS1_1(); - end.g = endColor.g + endColorVar.g * CCRANDOM_MINUS1_1(); - end.b = endColor.b + endColorVar.b * CCRANDOM_MINUS1_1(); - end.a = endColor.a + endColorVar.a * CCRANDOM_MINUS1_1(); - - particle->color = start; - particle->deltaColor.r = (end.r - start.r) / particle->life; - particle->deltaColor.g = (end.g - start.g) / particle->life; - particle->deltaColor.b = (end.b - start.b) / particle->life; - particle->deltaColor.a = (end.a - start.a) / particle->life; - - // size - float startS = startSize + startSizeVar * CCRANDOM_MINUS1_1(); - particle->size = startS; - if( endSize == kParticleStartSizeEqualToEndSize ) - particle->deltaSize = 0; - else { - float endS = endSize + endSizeVar * CCRANDOM_MINUS1_1(); - particle->deltaSize = (endS - startS) / particle->life; - } - - // angle - float startA = startSpin + startSpinVar * CCRANDOM_MINUS1_1(); - float endA = endSpin + endSpinVar * CCRANDOM_MINUS1_1(); - particle->angle = startA; - particle->deltaAngle = (endA - startA) / particle->life; - - // position - particle->startPos = self.position; -} - --(void) stopSystem -{ - active = NO; - elapsed = duration; - emitCounter = 0; -} - --(void) resetSystem -{ - active = YES; - elapsed = 0; - for(particleIdx = 0; particleIdx < particleCount; ++particleIdx) { - Particle *p = &particles[particleIdx]; - p->life = 0; - } -} - --(BOOL) isFull -{ - return (particleCount == totalParticles); -} -@end - - diff --git a/Support/cocos2d/PointParticleSystem.h b/Support/cocos2d/PointParticleSystem.h deleted file mode 100644 index aa91131..0000000 --- a/Support/cocos2d/PointParticleSystem.h +++ /dev/null @@ -1,34 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2008,2009 Ricardo Quesada - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - -#import "ParticleSystem.h" - -/** PointParticleSystem is a subclass of ParticleSystem - Attributes of a Particle System: - * All the attributes of Particle System - - Features: - * consumes small memory: uses 1 vertex (x,y) per particle, no need to assign tex coordinates - * size can't be bigger than 64 - * the system can't be scaled since the particles are rendered using GL_POINT_SPRITE - */ -@interface PointParticleSystem : ParticleSystem -{ - // Array of (x,y,size) - ccPointSprite *vertices; - // vertices buffer id - GLuint verticesID; -} -@end - diff --git a/Support/cocos2d/PointParticleSystem.m b/Support/cocos2d/PointParticleSystem.m deleted file mode 100644 index 87ddb37..0000000 --- a/Support/cocos2d/PointParticleSystem.m +++ /dev/null @@ -1,248 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2008,2009 Ricardo Quesada - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - -// opengl -#import - -// cocos2d -#import "PointParticleSystem.h" -#import "TextureMgr.h" -#import "ccMacros.h" - -// support -#import "Support/OpenGL_Internal.h" -#import "Support/CGPointExtension.h" - -@implementation PointParticleSystem - --(id) initWithTotalParticles:(int) numberOfParticles -{ - if( (self=[super initWithTotalParticles:numberOfParticles]) ) { - - vertices = malloc( sizeof(ccPointSprite) * totalParticles ); - - if( ! vertices ) { - NSLog(@"Particle system: not enough memory"); - if( vertices ) - free(vertices); - return nil; - } - - glGenBuffers(1, &verticesID); - - // initial binding - glBindBuffer(GL_ARRAY_BUFFER, verticesID); - glBufferData(GL_ARRAY_BUFFER, sizeof(ccPointSprite)*totalParticles, vertices,GL_DYNAMIC_DRAW); - glBindBuffer(GL_ARRAY_BUFFER, 0); - } - - return self; -} - --(void) dealloc -{ - free(vertices); - glDeleteBuffers(1, &verticesID); - - [super dealloc]; -} - -// XXX -// XXX: All subclasses of ParticleSystem share this code -// XXX: so some parts of this coded should be moved to the base class -// XXX -// XXX: BUT the change shall NOT DROP a single FPS -// XXX: --(void) step: (ccTime) dt -{ - if( active && emissionRate ) { - float rate = 1.0f / emissionRate; - emitCounter += dt; - while( particleCount < totalParticles && emitCounter > rate ) { - [self addParticle]; - emitCounter -= rate; - } - - elapsed += dt; - if(duration != -1 && duration < elapsed) - [self stopSystem]; - } - - particleIdx = 0; - - // test performance with [self absolutePosition]; - CGPoint absolutePosition = position_; - - while( particleIdx < particleCount ) - { - Particle *p = &particles[particleIdx]; - - if( p->life > 0 ) { - - CGPoint tmp, radial, tangential; - - radial = CGPointZero; - // radial acceleration - if(p->pos.x || p->pos.y) - radial = ccpNormalize(p->pos); - tangential = radial; - radial = ccpMult(radial, p->radialAccel); - - // tangential acceleration - float newy = tangential.x; - tangential.x = -tangential.y; - tangential.y = newy; - tangential = ccpMult(tangential, p->tangentialAccel); - - // (gravity + radial + tangential) * dt - tmp = ccpAdd( ccpAdd( radial, tangential), gravity); - tmp = ccpMult( tmp, dt); - p->dir = ccpAdd( p->dir, tmp); - tmp = ccpMult(p->dir, dt); - p->pos = ccpAdd( p->pos, tmp ); - - p->color.r += (p->deltaColor.r * dt); - p->color.g += (p->deltaColor.g * dt); - p->color.b += (p->deltaColor.b * dt); - p->color.a += (p->deltaColor.a * dt); - - p->size += (p->deltaSize * dt); - - p->life -= dt; - - // - // update values in point - // - CGPoint newPos = p->pos; - if( positionType_ == kPositionTypeWorld ) { - newPos = ccpSub(absolutePosition, p->startPos); - newPos = ccpSub( p->pos, newPos); - } - - // place vertices and colos in array - vertices[particleIdx].pos = newPos; - vertices[particleIdx].size = p->size; - vertices[particleIdx].colors = p->color; - - // update particle counter - particleIdx++; - - } else { - // life < 0 - if( particleIdx != particleCount-1 ) - particles[particleIdx] = particles[particleCount-1]; - particleCount--; - } - } - glBindBuffer(GL_ARRAY_BUFFER, verticesID); - glBufferData(GL_ARRAY_BUFFER, sizeof(ccPointSprite)*totalParticles, vertices,GL_DYNAMIC_DRAW); - glBindBuffer(GL_ARRAY_BUFFER, 0); -} - --(void) draw -{ -// int blendSrc, blendDst; -// int colorMode; - - glEnable(GL_TEXTURE_2D); - glBindTexture(GL_TEXTURE_2D, texture.name); - - glEnable(GL_POINT_SPRITE_OES); - glTexEnvi( GL_POINT_SPRITE_OES, GL_COORD_REPLACE_OES, GL_TRUE ); - - glBindBuffer(GL_ARRAY_BUFFER, verticesID); - - glEnableClientState(GL_VERTEX_ARRAY); - glVertexPointer(2,GL_FLOAT,sizeof(vertices[0]),0); - - glEnableClientState(GL_COLOR_ARRAY); - glColorPointer(4, GL_FLOAT, sizeof(vertices[0]),(GLvoid*) offsetof(ccPointSprite,colors) ); - - glEnableClientState(GL_POINT_SIZE_ARRAY_OES); - glPointSizePointerOES(GL_FLOAT,sizeof(vertices[0]),(GLvoid*) offsetof(ccPointSprite,size) ); - - - BOOL premultipliedColors = [texture hasPremultipliedAlpha]; - if( blendAdditive ) - glBlendFunc(GL_SRC_ALPHA, GL_ONE); - else if( ! premultipliedColors ) - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); - - // save color mode -#if 0 - glGetTexEnviv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, &colorMode); - if( colorModulate ) - glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); - else - glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE ); -#endif - - glDrawArrays(GL_POINTS, 0, particleIdx); - - // restore blend state - if( blendAdditive || ! premultipliedColors ) - glBlendFunc( CC_BLEND_SRC, CC_BLEND_DST); - -#if 0 - // restore color mode - glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, colorMode); -#endif - - // unbind VBO buffer - glBindBuffer(GL_ARRAY_BUFFER, 0); - - glDisableClientState(GL_POINT_SIZE_ARRAY_OES); - glDisableClientState(GL_COLOR_ARRAY); - glDisableClientState(GL_VERTEX_ARRAY); - glDisable(GL_TEXTURE_2D); - glDisable(GL_POINT_SPRITE_OES); -} - -#pragma mark Non supported properties - -// -// SPIN IS NOT SUPPORTED -// --(void) setStartSpin:(float)a -{ - NSAssert(a == 0, @"PointParticleSystem doesn't support spinning"); - [super setStartSpin:a]; -} --(void) setStartSpinVar:(float)a -{ - NSAssert(a == 0, @"PointParticleSystem doesn't support spinning"); - [super setStartSpin:a]; -} --(void) setEndSpin:(float)a -{ - NSAssert(a == 0, @"PointParticleSystem doesn't support spinning"); - [super setStartSpin:a]; -} --(void) setEndSpinVar:(float)a -{ - NSAssert(a == 0, @"PointParticleSystem doesn't support spinning"); - [super setStartSpin:a]; -} - -// -// SIZE > 64 IS NOT SUPPORTED -// --(void) setStartSize:(float)size -{ - NSAssert(size <= 64, @"PointParticleSystem doesn't support size > 64"); - [super setStartSize:size]; -} -@end - - diff --git a/Support/cocos2d/Primitives.h b/Support/cocos2d/Primitives.h deleted file mode 100644 index d6a2e70..0000000 --- a/Support/cocos2d/Primitives.h +++ /dev/null @@ -1,48 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2008,2009 Ricardo Quesada - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - -/** - @file - Drawing OpenGL ES primitives. - - drawPoint - - drawLine - - drawPoly - - drawCircle - - You can change the color, width and other property by calling the - glColor4ub(), glLineWitdh(), glPointSize(). - - @warning These functions draws the Line, Point, Polygon, immediately. They aren't batched. If you are going to make a game that depends on these primitives, I suggest creating a batch. - */ - -#import // for CGPoint -#import // for BOOL - -/** draws a point given x and y coordinate */ -void drawPoint( CGPoint point ); - -/** draws an array of points. - @since v0.7.2 - */ -void drawPoints( CGPoint *points, unsigned int numberOfPoints ); - -/** draws a line given the origin and destination point */ -void drawLine( CGPoint origin, CGPoint destination ); - -/** draws a poligon given a pointer to CGPoint coordiantes and the number of vertices. The polygon can be closed or open - */ -void drawPoly( CGPoint *vertices, int numOfVertices, BOOL closePolygon ); - -/** draws a circle given the center, radius and number of segments. */ -void drawCircle( CGPoint center, float radius, float angle, int segments, BOOL drawLineToCenter); diff --git a/Support/cocos2d/Primitives.m b/Support/cocos2d/Primitives.m deleted file mode 100644 index 0030cdb..0000000 --- a/Support/cocos2d/Primitives.m +++ /dev/null @@ -1,106 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2008,2009 Ricardo Quesada - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - -#import -#import -#import -#import - -#import "Primitives.h" - -void drawPoint( CGPoint point ) -{ - glVertexPointer(2, GL_FLOAT, 0, &point); - glEnableClientState(GL_VERTEX_ARRAY); - - glDrawArrays(GL_POINTS, 0, 1); - - glDisableClientState(GL_VERTEX_ARRAY); -} - -void drawPoints( CGPoint *points, unsigned int numberOfPoints ) -{ - glVertexPointer(2, GL_FLOAT, 0, points); - glEnableClientState(GL_VERTEX_ARRAY); - - glDrawArrays(GL_POINTS, 0, numberOfPoints); - - glDisableClientState(GL_VERTEX_ARRAY); -} - - -void drawLine( CGPoint origin, CGPoint destination ) -{ - CGPoint vertices[2]; - - vertices[0] = origin; - vertices[1] = destination; - - glVertexPointer(2, GL_FLOAT, 0, vertices); - glEnableClientState(GL_VERTEX_ARRAY); - - glDrawArrays(GL_LINES, 0, 2); - - glDisableClientState(GL_VERTEX_ARRAY); -} - - -void drawPoly( CGPoint *poli, int points, BOOL closePolygon ) -{ - glVertexPointer(2, GL_FLOAT, 0, poli); - glEnableClientState(GL_VERTEX_ARRAY); - - if( closePolygon ) - glDrawArrays(GL_LINE_LOOP, 0, points); - else - glDrawArrays(GL_LINE_STRIP, 0, points); - - glDisableClientState(GL_VERTEX_ARRAY); -} - -void drawCircle( CGPoint center, float r, float a, int segs, BOOL drawLineToCenter) -{ - int additionalSegment = 1; - if (drawLineToCenter) - additionalSegment++; - - const float coef = 2.0f * (float)M_PI/segs; - - float *vertices = malloc( sizeof(float)*2*(segs+2)); - if( ! vertices ) - return; - - memset( vertices,0, sizeof(float)*2*(segs+2)); - - for(int i=0;i<=segs;i++) - { - float rads = i*coef; - float j = r * cosf(rads + a) + center.x; - float k = r * sinf(rads + a) + center.y; - - vertices[i*2] = j; - vertices[i*2+1] =k; - } - vertices[(segs+1)*2] = center.x; - vertices[(segs+1)*2+1] = center.y; - - glVertexPointer(2, GL_FLOAT, 0, vertices); - glEnableClientState(GL_VERTEX_ARRAY); - - glDrawArrays(GL_LINE_STRIP, 0, segs+additionalSegment); - - glDisableClientState(GL_VERTEX_ARRAY); - - free( vertices ); -} diff --git a/Support/cocos2d/QuadParticleSystem.h b/Support/cocos2d/QuadParticleSystem.h deleted file mode 100644 index d15fb0e..0000000 --- a/Support/cocos2d/QuadParticleSystem.h +++ /dev/null @@ -1,44 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2009 Leonardo Kasperavičius - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - -#import "ParticleSystem.h" - -/** QuadParticleSystem is a subclass of ParticleSystem - - It includes all the features of ParticleSystem. - - Special features and Limitations: - - Particle size can be any float number. - - The system can be scaled - - The particles can be rotated - - It is a bit slower that PointParticleSystem - - It consumes more RAM and more GPU memory than PointParticleSystem - @since v0.8 - */ -@interface QuadParticleSystem : ParticleSystem -{ - ccV2F_C4F_T2F_Quad *quads; // quads to be rendered - GLushort *indices; // indices - GLuint quadsID; // VBO id -} - - -// initialices the indices for the vertices --(void) initIndices; -// initilizes the text coords --(void) initTexCoords; - - -@end - diff --git a/Support/cocos2d/QuadParticleSystem.m b/Support/cocos2d/QuadParticleSystem.m deleted file mode 100644 index 4306983..0000000 --- a/Support/cocos2d/QuadParticleSystem.m +++ /dev/null @@ -1,310 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2009 Leonardo Kasperavičius - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - -// opengl -#import - -// cocos2d -#import "QuadParticleSystem.h" -#import "TextureMgr.h" -#import "ccMacros.h" - -// support -#import "Support/OpenGL_Internal.h" -#import "Support/CGPointExtension.h" - -@implementation QuadParticleSystem - -// overriding the init method --(id) initWithTotalParticles:(int) numberOfParticles -{ - // base initialization - if( (self=[super initWithTotalParticles:numberOfParticles]) ) { - - // allocating data space - quads = malloc( sizeof(quads[0]) * totalParticles ); - indices = malloc( sizeof(indices[0]) * totalParticles * 6 ); - - if( !quads || !indices) { - NSLog(@"Particle system: not enough memory"); - if( quads ) - free( quads ); - if(indices) - free(indices); - return nil; - } - - // initialize only once the texCoords and the indices - [self initTexCoords]; - [self initIndices]; - - // create the VBO buffer - glGenBuffers(1, &quadsID); - - // initial binding - glBindBuffer(GL_ARRAY_BUFFER, quadsID); - glBufferData(GL_ARRAY_BUFFER, sizeof(quads[0])*totalParticles, quads,GL_DYNAMIC_DRAW); - glBindBuffer(GL_ARRAY_BUFFER, 0); - } - - return self; -} - --(void) dealloc -{ - free(quads); - free(indices); - glDeleteBuffers(1, &quadsID); - - [super dealloc]; -} - --(void) initTexCoords -{ - for(int i=0; i rate ) { - [self addParticle]; - emitCounter -= rate; - } - - elapsed += dt; - if(duration != -1 && duration < elapsed) - [self stopSystem]; - } - - particleIdx = 0; - - // test performance with [self absolutePosition]; - CGPoint absolutePosition = position_; - - while( particleIdx < particleCount ) - { - Particle *p = &particles[particleIdx]; - - if( p->life > 0 ) { - - CGPoint tmp, radial, tangential; - - radial = CGPointZero; - // radial acceleration - if(p->pos.x || p->pos.y) - radial = ccpNormalize(p->pos); - tangential = radial; - radial = ccpMult(radial, p->radialAccel); - - // tangential acceleration - float newy = tangential.x; - tangential.x = -tangential.y; - tangential.y = newy; - tangential = ccpMult(tangential, p->tangentialAccel); - - // (gravity + radial + tangential) * dt - tmp = ccpAdd( ccpAdd( radial, tangential), gravity); - tmp = ccpMult( tmp, dt); - p->dir = ccpAdd( p->dir, tmp); - tmp = ccpMult(p->dir, dt); - p->pos = ccpAdd( p->pos, tmp ); - - p->color.r += (p->deltaColor.r * dt); - p->color.g += (p->deltaColor.g * dt); - p->color.b += (p->deltaColor.b * dt); - p->color.a += (p->deltaColor.a * dt); - - p->size += (p->deltaSize * dt); - - p->life -= dt; - - // - // update values in quad - // - - CGPoint newPos = p->pos; - if( positionType_ == kPositionTypeWorld ) { - newPos = ccpSub(absolutePosition, p->startPos); - newPos = ccpSub( p->pos, newPos); - } - - // colors - quads[particleIdx].bl.colors = p->color; - quads[particleIdx].br.colors = p->color; - quads[particleIdx].tl.colors = p->color; - quads[particleIdx].tr.colors = p->color; - - // vertices - float size_2 = p->size/2; - p->angle += (p->deltaAngle * dt); - if( p->angle ) { - float x1 = -size_2; - float y1 = -size_2; - - float x2 = x1 + p->size; - float y2 = y1 + p->size; - float x = newPos.x; - float y = newPos.y; - - float r = (float)-CC_DEGREES_TO_RADIANS(p->angle); - float cr = cosf(r); - float sr = sinf(r); - float ax = x1 * cr - y1 * sr + x; - float ay = x1 * sr + y1 * cr + y; - float bx = x2 * cr - y1 * sr + x; - float by = x2 * sr + y1 * cr + y; - float cx = x2 * cr - y2 * sr + x; - float cy = x2 * sr + y2 * cr + y; - float dx = x1 * cr - y2 * sr + x; - float dy = x1 * sr + y2 * cr + y; - - quads[particleIdx].bl.vertices.x = ax; - quads[particleIdx].bl.vertices.y = ay; - - // bottom-left vertex: - quads[particleIdx].br.vertices.x = bx; - quads[particleIdx].br.vertices.y = by; - - // top-right vertex: - quads[particleIdx].tl.vertices.x = dx; - quads[particleIdx].tl.vertices.y = dy; - - // top-right vertex: - quads[particleIdx].tr.vertices.x = cx; - quads[particleIdx].tr.vertices.y = cy; - } else { - // top-left vertex: - quads[particleIdx].bl.vertices.x = newPos.x - size_2; - quads[particleIdx].bl.vertices.y = newPos.y - size_2; - - // bottom-left vertex: - quads[particleIdx].br.vertices.x = newPos.x + size_2; - quads[particleIdx].br.vertices.y = newPos.y - size_2; - - // top-right vertex: - quads[particleIdx].tl.vertices.x = newPos.x - size_2; - quads[particleIdx].tl.vertices.y = newPos.y + size_2; - - // top-right vertex: - quads[particleIdx].tr.vertices.x = newPos.x + size_2; - quads[particleIdx].tr.vertices.y = newPos.y + size_2; - } - - // update particle counter - particleIdx++; - - } else { - // life < 0 - if( particleIdx != particleCount-1 ) - particles[particleIdx] = particles[particleCount-1]; - particleCount--; - } - } - glBindBuffer(GL_ARRAY_BUFFER, quadsID); - glBufferData(GL_ARRAY_BUFFER, sizeof(quads[0])*totalParticles, quads,GL_DYNAMIC_DRAW); - glBindBuffer(GL_ARRAY_BUFFER, 0); -} - -// overriding draw method --(void) draw -{ - glEnable(GL_TEXTURE_2D); - - glBindTexture(GL_TEXTURE_2D, texture.name); - - glBindBuffer(GL_ARRAY_BUFFER, quadsID); - -#define kPointSize sizeof(quads[0].bl) - glEnableClientState(GL_VERTEX_ARRAY); - glVertexPointer(2,GL_FLOAT, kPointSize, 0); - - glEnableClientState(GL_COLOR_ARRAY); - glColorPointer(4, GL_FLOAT, kPointSize, (GLvoid*) offsetof(ccV2F_C4F_T2F,colors) ); - - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glTexCoordPointer(2, GL_FLOAT, kPointSize, (GLvoid*) offsetof(ccV2F_C4F_T2F,texCoords) ); - - - BOOL premultipliedColors = [texture hasPremultipliedAlpha]; - if( blendAdditive ) - glBlendFunc(GL_SRC_ALPHA, GL_ONE); - else if( ! premultipliedColors ) - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); - - // save color mode -#if 0 - glGetTexEnviv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, &colorMode); - if( colorModulate ) - glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); - else - glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE ); -#endif - - glDrawElements(GL_TRIANGLES, particleIdx*6, GL_UNSIGNED_SHORT, indices); - - // restore blend state - if( blendAdditive || ! premultipliedColors ) - glBlendFunc( CC_BLEND_SRC, CC_BLEND_DST ); - -#if 0 - // restore color mode - glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, colorMode); -#endif - - glBindBuffer(GL_ARRAY_BUFFER, 0); - - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - glDisableClientState(GL_COLOR_ARRAY); - glDisableClientState(GL_VERTEX_ARRAY); - glDisable(GL_TEXTURE_2D); -} - -@end - - diff --git a/Support/cocos2d/Scene.h b/Support/cocos2d/Scene.h deleted file mode 100644 index 175c925..0000000 --- a/Support/cocos2d/Scene.h +++ /dev/null @@ -1,33 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2008,2009 Ricardo Quesada - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - - -#import - -#import "CocosNode.h" - -/** Scene is a subclass of CocosNode that is used only as an abstract concept. - - Scene an CocosNode are almost identical with the difference that Scene has it's - anchor point (by default) at the center of the screen. - - For the moment Scene has no other logic than that, but in future releases it might have - additional logic. - - It is a good practice to use and Scene as the parent of all your nodes. -*/ -@interface Scene : CocosNode { - -} -@end diff --git a/Support/cocos2d/Scene.m b/Support/cocos2d/Scene.m deleted file mode 100644 index 30df23b..0000000 --- a/Support/cocos2d/Scene.m +++ /dev/null @@ -1,32 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2008,2009 Ricardo Quesada - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - - -#import "Scene.h" -#import "Director.h" -#import "Support/CGPointExtension.h" - -@implementation Scene --(id) init -{ - if( (self=[super init]) ) { - CGSize s = [[Director sharedDirector] winSize]; - self.relativeTransformAnchor = NO; - anchorPoint_ = ccp(0.5f, 0.5f); - [self setContentSize:s]; - } - - return self; -} -@end diff --git a/Support/cocos2d/Scheduler.h b/Support/cocos2d/Scheduler.h deleted file mode 100644 index d14d89f..0000000 --- a/Support/cocos2d/Scheduler.h +++ /dev/null @@ -1,86 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2008,2009 Ricardo Quesada - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - - -// cocoa related -#import - -#import "ccTypes.h" - -typedef void (*TICK_IMP)(id, SEL, ccTime); - -// -// Timer -// -/** Light weight timer */ -@interface Timer : NSObject -{ - id target; - SEL selector; - TICK_IMP impMethod; - - ccTime interval; - ccTime elapsed; -} - -@property (readwrite,assign) ccTime interval; - -/** constructor for timer */ -+(id) timerWithTarget:(id) t selector:(SEL)s; - -/** constructor for timer with interval */ -+(id) timerWithTarget:(id) t selector:(SEL)s interval:(ccTime) i; - -/** init for Timer */ --(id) initWithTarget:(id) t selector:(SEL)s; - -/** init for Timer with interval */ --(id) initWithTarget:(id) t selector:(SEL)s interval:(ccTime) i; - - -/** triggers the timer */ --(void) fire: (ccTime) dt; -@end - -// -// Scheduler -// -/**Class manages all the schedulers -*/ -@interface Scheduler : NSObject -{ - NSMutableArray *scheduledMethods; - NSMutableArray *methodsToRemove; - NSMutableArray *methodsToAdd; -} - -/** returns a shared instance of the Scheduler */ -+(Scheduler *)sharedScheduler; - -/** the scheduler is ticked */ --(void) tick: (ccTime) dt; - -/** schedule a target/selector */ --(Timer*) scheduleTarget:(id) r selector:(SEL) s; - -/** schedule a target/selector with interval */ --(Timer*) scheduleTarget:(id) r selector:(SEL) s interval: (ccTime) i; - - -/** schedule a Timer */ --(void) scheduleTimer: (Timer*) t; - -/** unschedule a timer */ --(void) unscheduleTimer: (Timer*) t; -@end diff --git a/Support/cocos2d/Scheduler.m b/Support/cocos2d/Scheduler.m deleted file mode 100644 index 07a7a64..0000000 --- a/Support/cocos2d/Scheduler.m +++ /dev/null @@ -1,216 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2008,2009 Ricardo Quesada - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - -// cocos2d imports -#import "Scheduler.h" -#import "ccMacros.h" - -// -// Timer -// -@implementation Timer - -@synthesize interval; - --(id) init -{ - NSException* myException = [NSException - exceptionWithName:@"TimerInvalid" - reason:@"Invalid init for Timer. Use initWithTarget:sel:" - userInfo:nil]; - @throw myException; -} - -+(id) timerWithTarget:(id) t selector:(SEL)s -{ - return [[[self alloc] initWithTarget:t selector:s] autorelease]; -} - -+(id) timerWithTarget:(id) t selector:(SEL)s interval:(ccTime) i -{ - return [[[self alloc] initWithTarget:t selector:s interval:i] autorelease]; -} - - --(id) initWithTarget:(id) t selector:(SEL)s -{ - return [self initWithTarget:t selector:s interval:0]; -} - --(id) initWithTarget:(id) t selector:(SEL)s interval:(ccTime) seconds -{ - if( (self=[super init]) ) { -#ifdef DEBUG - NSMethodSignature *sig = [t methodSignatureForSelector:s]; - NSAssert(sig !=0 , @"Signature not found for selector - does it have the following form? -(void) name: (ccTime) dt"); -#endif - - target = [t retain]; - selector = s; - impMethod = (TICK_IMP) [t methodForSelector:s]; - - interval = seconds; - } - return self; -} - --(void) dealloc -{ - CCLOG( @"deallocing %@", self); - - [target release]; - [super dealloc]; -} - --(void) fire: (ccTime) dt -{ - elapsed += dt; - if( elapsed >= interval ) { - impMethod(target, selector, elapsed); - elapsed = 0; - } -} -@end - -// -// Scheduler -// -@implementation Scheduler - -static Scheduler *sharedScheduler; - -+ (Scheduler *)sharedScheduler -{ - @synchronized([Scheduler class]) - { - if (!sharedScheduler) - [[Scheduler alloc] init]; - - return sharedScheduler; - } - // to avoid compiler warning - return nil; -} - -+(id)alloc -{ - @synchronized([Scheduler class]) - { - NSAssert(sharedScheduler == nil, @"Attempted to allocate a second instance of a singleton."); - sharedScheduler = [super alloc]; - return sharedScheduler; - } - // to avoid compiler warning - return nil; -} - -- (id) init -{ - if( ! (self=[super init]) ) - return nil; - - scheduledMethods = [[NSMutableArray arrayWithCapacity:50] retain]; - methodsToRemove = [[NSMutableArray arrayWithCapacity:20] retain]; - methodsToAdd = [[NSMutableArray arrayWithCapacity:20] retain]; - - return self; -} - -- (void) dealloc -{ - CCLOG( @"deallocing %@", self); - [scheduledMethods release]; - [methodsToRemove release]; - [methodsToAdd release]; - - [super dealloc]; -} - --(Timer*) scheduleTarget: (id) target selector:(SEL)sel -{ - Timer *t = [Timer timerWithTarget:target selector:sel]; - - [methodsToAdd addObject: t]; - - return t; -} - --(Timer*) scheduleTarget: (id) target selector:(SEL)sel interval:(ccTime) i -{ - Timer *t = [Timer timerWithTarget:target selector:sel]; - - [t setInterval:i]; - - [methodsToAdd addObject: t]; - - return t; -} - --(void) scheduleTimer: (Timer*) t -{ - // it is possible that sometimes (in transitions in particular) an scene unschedule a timer - // and before the timer is deleted, it is re-scheduled - if( [methodsToRemove containsObject:t] ) - { - [methodsToRemove removeObject:t]; - return; - } - - if( [scheduledMethods containsObject:t] || [methodsToAdd containsObject:t]) { - NSLog(@"Scheduler.schedulerTimer: timer %@ already scheduled", t); - NSException* myException = [NSException - exceptionWithName:@"SchedulerTimerAlreadyScheduled" - reason:@"Scheduler.scheduleTimer already scheduled" - userInfo:nil]; - @throw myException; - } - - [methodsToAdd addObject: t]; -} - --(void) unscheduleTimer: (Timer*) t; -{ - // someone wants to remove it before it was added - if( [methodsToAdd containsObject:t] ) { - [methodsToAdd removeObject:t]; - return; - } - - if( ![scheduledMethods containsObject:t] ) { - NSLog(@"Scheduler.unscheduleTimer: timer not scheduled"); - NSException* myException = [NSException - exceptionWithName:@"SchedulerTimerNotFound" - reason:@"Scheduler.unscheduleTimer not found" - userInfo:nil]; - @throw myException; - } - - [methodsToRemove addObject:t]; -} - --(void) tick: (ccTime) dt -{ - for( id k in methodsToRemove ) - [scheduledMethods removeObject:k]; - - [methodsToRemove removeAllObjects]; - - for( id k in methodsToAdd ) - [scheduledMethods addObject:k]; - [methodsToAdd removeAllObjects]; - - for( Timer *t in scheduledMethods ) - [t fire: dt]; -} -@end diff --git a/Support/cocos2d/Sprite.h b/Support/cocos2d/Sprite.h deleted file mode 100644 index 2313c3e..0000000 --- a/Support/cocos2d/Sprite.h +++ /dev/null @@ -1,100 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2008,2009 Ricardo Quesada - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - - -#import - -#import "Support/Texture2D.h" - -#import "TextureNode.h" - -#pragma mark Sprite - -@class Animation; -/** Sprite is a subclass of TextureNode that implements the CocosNodeFrames protocol. - * - * Sprite supports ALL CocosNode transformations, but in contrast to AtlasSprite it is much slower. - * ONLY use Sprite if you can't achieve the same with effect with AtlasSprite, otherwise the use of - * AtlasSprite is recommended. - * - * All features from TextureNode are valid, plus the following new features: - * - it supports animations (frames) - * - * Limitations of Sprite: - * - It doesn't perform as well as AtlasSprite - */ -@interface Sprite : TextureNode -{ - NSMutableDictionary *animations; -} - -/** creates an sprite with an image file */ -+ (id) spriteWithFile:(NSString *)imageFile; -/** creates an sprite from a CGImageRef image */ -+ (id) spriteWithCGImage:(CGImageRef)image; - -/** initializes the sprite with an image file */ -- (id) initWithFile:(NSString *) imageFile; -/** creates an sprite from a CGImageRef image */ -- (id) initWithCGImage:(CGImageRef)image; -/** creates an sprite with a Texture2D instance */ -+(id) spriteWithTexture:(Texture2D*) tex; -/** initializes the sprite with a Texture2D instance */ --(id) initWithTexture:(Texture2D*) tex; -@end - -#pragma mark Animation - -/** an Animation object used within Sprites to perform animations */ -@interface Animation : NSObject -{ - NSString *name; - float delay; - NSMutableArray *frames; -} - -@property (readwrite,copy) NSString * name; - -// CocosAnimation -@property (readwrite,assign) float delay; -@property (readwrite,retain) NSMutableArray *frames; - -/** creates an Animation with name, delay and frames from image files */ -+(id) animationWithName: (NSString*) name delay:(float)delay; - -/** creates an Animation with name, delay and frames from image files */ -+(id) animationWithName: (NSString*) name delay:(float)delay images:image1,... NS_REQUIRES_NIL_TERMINATION; - -/** creates an Animation with name, delay and frames from Texture2D objects */ -+(id) animationWithName: (NSString*) name delay:(float)delay textures:tex1,... NS_REQUIRES_NIL_TERMINATION; - -/** initializes an Animation with name, delay and frames from Texture2D objects */ --(id) initWithName: (NSString*) name delay:(float)delay firstTexture:(Texture2D*)tex vaList:(va_list) args; - - - -/** initializes an Animation with name and delay - */ --(id) initWithName: (NSString*) name delay:(float)delay; - -/** initializes an Animation with name, delay and frames from image files - */ --(id) initWithName: (NSString*) name delay:(float)delay firstImage:(NSString*)filename vaList:(va_list) args; - -/** adds a frame to an Animation */ --(void) addFrameWithFilename: (NSString*) filename; - -/** adds a frame from a Texture2D object to an Animation */ --(void) addFrameWithTexture: (Texture2D*) tex; -@end diff --git a/Support/cocos2d/Sprite.m b/Support/cocos2d/Sprite.m deleted file mode 100644 index e63a634..0000000 --- a/Support/cocos2d/Sprite.m +++ /dev/null @@ -1,251 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2008 Ricardo Quesada - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - -#import "TextureMgr.h" -#import "Sprite.h" -#import "ccMacros.h" -#import "Support/CGPointExtension.h" - -#pragma mark Sprite - -@interface Sprite (Private) -// lazy allocation --(void) initAnimationDictionary; -@end - -@implementation Sprite - -#pragma mark Sprite - image file -+ (id) spriteWithFile:(NSString*) filename -{ - return [[[self alloc] initWithFile:filename] autorelease]; -} - -- (id) initWithFile:(NSString*) filename -{ - self = [super init]; - if( self ) { - // texture is retained - self.texture = [[TextureMgr sharedTextureMgr] addImage: filename]; - - // lazy alloc - animations = nil; - } - - return self; -} - -#pragma mark Sprite - CGImageRef - -+ (id) spriteWithCGImage: (CGImageRef) image -{ - return [[[self alloc] initWithCGImage:image] autorelease]; -} - -- (id) initWithCGImage: (CGImageRef) image -{ - self = [super init]; - if( self ) { - // texture is retained - self.texture = [[TextureMgr sharedTextureMgr] addCGImage: image]; - - // lazy alloc - animations = nil; - } - - return self; -} - -#pragma mark Sprite - Texture2D - -+ (id) spriteWithTexture:(Texture2D*) tex -{ - return [[[self alloc] initWithTexture:tex] autorelease]; -} - -- (id) initWithTexture:(Texture2D*) tex -{ - if( (self = [super init]) ) { - // texture is retained - self.texture = tex; - - // lazy alloc - animations = nil; - } - return self; -} - -#pragma mark Sprite - --(void) dealloc -{ - [animations release]; - [super dealloc]; -} - --(void) initAnimationDictionary -{ - animations = [[NSMutableDictionary dictionaryWithCapacity:2] retain]; -} - -// -// CocosNodeFrames protocol -// --(void) setDisplayFrame:(id)frame -{ - self.texture = frame; -} - --(void) setDisplayFrame: (NSString*) animationName index:(int) frameIndex -{ - if( ! animations ) - [self initAnimationDictionary]; - - Animation *a = [animations objectForKey: animationName]; - Texture2D *frame = [[a frames] objectAtIndex:frameIndex]; - self.texture = frame; -} - --(BOOL) isFrameDisplayed:(id)frame -{ - return texture_ == frame; -} --(id) displayFrame -{ - return texture_; -} --(void) addAnimation: (id) anim -{ - // lazy alloc - if( ! animations ) - [self initAnimationDictionary]; - - [animations setObject:anim forKey:[anim name]]; -} --(id)animationByName: (NSString*) animationName -{ - NSAssert( animationName != nil, @"animationName parameter must be non nil"); - return [animations objectForKey:animationName]; -} -@end - -#pragma mark - -#pragma mark Animation - -@implementation Animation -@synthesize name, delay, frames; - -+(id) animationWithName:(NSString*)n delay:(float)d -{ - return [[[self alloc] initWithName:n delay:d] autorelease]; -} - --(id) initWithName: (NSString*) n delay:(float)d -{ - return [self initWithName:n delay:d firstImage:nil vaList:nil]; -} - --(void) dealloc -{ - CCLOG( @"deallocing %@",self); - [name release]; - [frames release]; - [super dealloc]; -} - -#pragma mark Animation - image files - -+(id) animationWithName: (NSString*) name delay:(float)delay images:image1,... -{ - va_list args; - va_start(args,image1); - - id s = [[[self alloc] initWithName:name delay:delay firstImage:image1 vaList:args] autorelease]; - - va_end(args); - return s; -} - --(id) initWithName: (NSString*) n delay:(float)d firstImage:(NSString*)image vaList: (va_list) args -{ - if( ! (self=[super init]) ) - return nil; - - name = [n retain]; - frames = [[NSMutableArray array] retain]; - delay = d; - - if( image ) { - Texture2D *tex = [[TextureMgr sharedTextureMgr] addImage: image]; - [frames addObject:tex]; - - NSString *filename = va_arg(args, NSString*); - while(filename) { - tex = [[TextureMgr sharedTextureMgr] addImage: filename]; - [frames addObject:tex]; - - filename = va_arg(args, NSString*); - } - } - return self; -} - --(void) addFrameWithFilename: (NSString*) filename -{ - Texture2D *tex = [[TextureMgr sharedTextureMgr] addImage: filename]; - [frames addObject:tex]; -} - -#pragma mark Animation - Texture2D - -+(id) animationWithName: (NSString*) name delay:(float)delay textures:tex1,... -{ - va_list args; - va_start(args,tex1); - - id s = [[[self alloc] initWithName:name delay:delay firstTexture:tex1 vaList:args] autorelease]; - - va_end(args); - return s; -} - --(id) initWithName:(NSString*)n delay:(float)d firstTexture:(Texture2D*)tex vaList:(va_list)args -{ - self = [super init]; - if( self ) { - name = [n retain]; - frames = [[NSMutableArray array] retain]; - delay = d; - - if( tex ) { - [frames addObject:tex]; - - Texture2D *newTex = va_arg(args, Texture2D*); - while(newTex) { - [frames addObject:newTex]; - - newTex = va_arg(args, Texture2D*); - } - } - } - return self; -} - --(void) addFrameWithTexture: (Texture2D*) tex -{ - [frames addObject:tex]; -} - -@end - diff --git a/Support/cocos2d/Support/EAGLView.m b/Support/cocos2d/Support/EAGLView.m deleted file mode 100755 index 25db666..0000000 --- a/Support/cocos2d/Support/EAGLView.m +++ /dev/null @@ -1,316 +0,0 @@ -/* - -===== IMPORTANT ===== - -This is sample code demonstrating API, technology or techniques in development. -Although this sample code has been reviewed for technical accuracy, it is not -final. Apple is supplying this information to help you plan for the adoption of -the technologies and programming interfaces described herein. This information -is subject to change, and software implemented based on this sample code should -be tested with final operating system software and final documentation. Newer -versions of this sample code may be provided with future seeds of the API or -technology. For information about updates to this and other developer -documentation, view the New & Updated sidebars in subsequent documentation -seeds. - -===================== - -File: EAGLView.m -Abstract: Convenience class that wraps the CAEAGLLayer from CoreAnimation into a -UIView subclass. - -Version: 1.3 - -Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc. -("Apple") in consideration of your agreement to the following terms, and your -use, installation, modification or redistribution of this Apple software -constitutes acceptance of these terms. If you do not agree with these terms, -please do not use, install, modify or redistribute this Apple software. - -In consideration of your agreement to abide by the following terms, and subject -to these terms, Apple grants you a personal, non-exclusive license, under -Apple's copyrights in this original Apple software (the "Apple Software"), to -use, reproduce, modify and redistribute the Apple Software, with or without -modifications, in source and/or binary forms; provided that if you redistribute -the Apple Software in its entirety and without modifications, you must retain -this notice and the following text and disclaimers in all such redistributions -of the Apple Software. -Neither the name, trademarks, service marks or logos of Apple Inc. may be used -to endorse or promote products derived from the Apple Software without specific -prior written permission from Apple. Except as expressly stated in this notice, -no other rights or licenses, express or implied, are granted by Apple herein, -including but not limited to any patent rights that may be infringed by your -derivative works or by other works in which the Apple Software may be -incorporated. - -The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO -WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED -WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN -COMBINATION WITH YOUR PRODUCTS. - -IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE -GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR -DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF -CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF -APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -Copyright (C) 2008 Apple Inc. All Rights Reserved. - -*/ - -#import - -#import "EAGLView.h" -#import "OpenGL_Internal.h" - -//CLASS IMPLEMENTATIONS: - -@implementation EAGLView - -@synthesize delegate=_delegate, autoresizesSurface=_autoresize, surfaceSize=_size, framebuffer = _framebuffer, pixelFormat = _format, depthFormat = _depthFormat, context = _context, touchDelegate; - -+ (Class) layerClass -{ - return [CAEAGLLayer class]; -} - -- (BOOL) _createSurface -{ - CAEAGLLayer* eaglLayer = (CAEAGLLayer*)[self layer]; - CGSize newSize; - GLuint oldRenderbuffer; - GLuint oldFramebuffer; - - if(![EAGLContext setCurrentContext:_context]) { - return NO; - } - - newSize = [eaglLayer bounds].size; - newSize.width = roundf(newSize.width); - newSize.height = roundf(newSize.height); - - glGetIntegerv(GL_RENDERBUFFER_BINDING_OES, (GLint *) &oldRenderbuffer); - glGetIntegerv(GL_FRAMEBUFFER_BINDING_OES, (GLint *) &oldFramebuffer); - - glGenRenderbuffersOES(1, &_renderbuffer); - glBindRenderbufferOES(GL_RENDERBUFFER_OES, _renderbuffer); - - if(![_context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:eaglLayer]) { - glDeleteRenderbuffersOES(1, &_renderbuffer); - glBindRenderbufferOES(GL_RENDERBUFFER_BINDING_OES, oldRenderbuffer); - return NO; - } - - glGenFramebuffersOES(1, &_framebuffer); - glBindFramebufferOES(GL_FRAMEBUFFER_OES, _framebuffer); - glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, _renderbuffer); - if (_depthFormat) { - glGenRenderbuffersOES(1, &_depthBuffer); - glBindRenderbufferOES(GL_RENDERBUFFER_OES, _depthBuffer); - glRenderbufferStorageOES(GL_RENDERBUFFER_OES, _depthFormat, newSize.width, newSize.height); - glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, _depthBuffer); - } - - _size = newSize; - if(!_hasBeenCurrent) { - glViewport(0, 0, newSize.width, newSize.height); - glScissor(0, 0, newSize.width, newSize.height); - _hasBeenCurrent = YES; - } - else { - glBindFramebufferOES(GL_FRAMEBUFFER_OES, oldFramebuffer); - } - glBindRenderbufferOES(GL_RENDERBUFFER_OES, oldRenderbuffer); - - - CHECK_GL_ERROR(); - - [_delegate didResizeEAGLSurfaceForView:self]; - - return YES; -} - -- (void) _destroySurface -{ - EAGLContext *oldContext = [EAGLContext currentContext]; - - if (oldContext != _context) - [EAGLContext setCurrentContext:_context]; - - if(_depthFormat) { - glDeleteRenderbuffersOES(1, &_depthBuffer); - _depthBuffer = 0; - } - - glDeleteRenderbuffersOES(1, &_renderbuffer); - _renderbuffer = 0; - - glDeleteFramebuffersOES(1, &_framebuffer); - _framebuffer = 0; - - if (oldContext != _context) - [EAGLContext setCurrentContext:oldContext]; - else - [EAGLContext setCurrentContext:nil]; -} - -- (id) initWithFrame:(CGRect)frame -{ - return [self initWithFrame:frame pixelFormat:kEAGLColorFormatRGB565 depthFormat:0 preserveBackbuffer:NO]; -} - -- (id) initWithFrame:(CGRect)frame pixelFormat:(NSString*)format -{ - return [self initWithFrame:frame pixelFormat:format depthFormat:0 preserveBackbuffer:NO]; -} - -- (id) initWithFrame:(CGRect)frame pixelFormat:(NSString*)format depthFormat:(GLuint)depth preserveBackbuffer:(BOOL)retained -{ - if((self = [super initWithFrame:frame])) - { - - [self setOpaque:YES]; - - CAEAGLLayer* eaglLayer = (CAEAGLLayer*)[self layer]; - - [eaglLayer setDrawableProperties:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:retained], kEAGLDrawablePropertyRetainedBacking, format, kEAGLDrawablePropertyColorFormat, nil]]; - _format = format; - _depthFormat = depth; - - _context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1]; - if(_context == nil) { - [self release]; - return nil; - } - - if(![self _createSurface]) { - [self release]; - return nil; - } - } - - return self; -} - -- (void) dealloc -{ - [self _destroySurface]; - - [_context release]; - _context = nil; - - [super dealloc]; -} - -- (void) layoutSubviews -{ - CGRect bounds = [self bounds]; - - if(_autoresize && ((roundf(bounds.size.width) != _size.width) || (roundf(bounds.size.height) != _size.height))) { - [self _destroySurface]; -#if __DEBUG__ - REPORT_ERROR(@"Resizing surface from %fx%f to %fx%f", _size.width, _size.height, roundf(bounds.size.width), roundf(bounds.size.height)); -#endif - [self _createSurface]; - } -} - -- (void) setAutoresizesEAGLSurface:(BOOL)autoresizesEAGLSurface; -{ - _autoresize = autoresizesEAGLSurface; - if(_autoresize) - [self layoutSubviews]; -} - -- (void) setCurrentContext -{ - if(![EAGLContext setCurrentContext:_context]) { - printf("Failed to set current context %p in %s\n", _context, __FUNCTION__); - } -} - -- (BOOL) isCurrentContext -{ - return ([EAGLContext currentContext] == _context ? YES : NO); -} - -- (void) clearCurrentContext -{ - if(![EAGLContext setCurrentContext:nil]) - printf("Failed to clear current context in %s\n", __FUNCTION__); -} - -- (void) swapBuffers -{ - EAGLContext *oldContext = [EAGLContext currentContext]; - //GLuint oldRenderbuffer; - - if(oldContext != _context) - [EAGLContext setCurrentContext:_context]; - -#if DEBUG - CHECK_GL_ERROR(); -#endif - - //glGetIntegerv(GL_RENDERBUFFER_BINDING_OES, (GLint *) &oldRenderbuffer); - glBindRenderbufferOES(GL_RENDERBUFFER_OES, _renderbuffer); - //glBindRenderbufferOES(GL_RENDERBUFFER_OES, _framebuffer); - - if(![_context presentRenderbuffer:GL_RENDERBUFFER_OES]) - printf("Failed to swap renderbuffer in %s\n", __FUNCTION__); - - if(oldContext != _context) - [EAGLContext setCurrentContext:oldContext]; -} - -- (CGPoint) convertPointFromViewToSurface:(CGPoint)point -{ - CGRect bounds = [self bounds]; - - return CGPointMake((point.x - bounds.origin.x) / bounds.size.width * _size.width, (point.y - bounds.origin.y) / bounds.size.height * _size.height); -} - -- (CGRect) convertRectFromViewToSurface:(CGRect)rect -{ - CGRect bounds = [self bounds]; - - return CGRectMake((rect.origin.x - bounds.origin.x) / bounds.size.width * _size.width, (rect.origin.y - bounds.origin.y) / bounds.size.height * _size.height, rect.size.width / bounds.size.width * _size.width, rect.size.height / bounds.size.height * _size.height); -} - -// Pass the touches to the superview - -- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event -{ - if(touchDelegate) - { - [touchDelegate touchesBegan:touches withEvent:event]; - } -} - -- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event -{ - if(touchDelegate) - { - [touchDelegate touchesMoved:touches withEvent:event]; - } -} - -- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event -{ - if(touchDelegate) - { - [touchDelegate touchesEnded:touches withEvent:event]; - } -} -- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event -{ - if(touchDelegate) - { - [touchDelegate touchesCancelled:touches withEvent:event]; - } -} - -@end diff --git a/Support/cocos2d/Support/FileUtils.h b/Support/cocos2d/Support/FileUtils.h deleted file mode 100644 index 759becd..0000000 --- a/Support/cocos2d/Support/FileUtils.h +++ /dev/null @@ -1,24 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2008,2009 Ricardo Quesada - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - -#import - - -/** Helper class to handle file operations */ -@interface FileUtils : NSObject -{ -} -/** converts a relative path to a full path */ -+(NSString*) fullPathFromRelativePath:(NSString*) relPath; -@end diff --git a/Support/cocos2d/Support/FileUtils.m b/Support/cocos2d/Support/FileUtils.m deleted file mode 100644 index 61174f3..0000000 --- a/Support/cocos2d/Support/FileUtils.m +++ /dev/null @@ -1,34 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2008,2009 Ricardo Quesada - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - -#import "FileUtils.h" - -@implementation FileUtils -+(NSString*) fullPathFromRelativePath:(NSString*) relPath -{ - NSMutableArray *imagePathComponents = [NSMutableArray arrayWithArray:[relPath pathComponents]]; - NSString *file = [imagePathComponents lastObject]; - - [imagePathComponents removeLastObject]; - NSString *imageDirectory = [NSString pathWithComponents:imagePathComponents]; - - NSString *fullpath = [[NSBundle mainBundle] pathForResource:file - ofType:nil - inDirectory:imageDirectory]; - if (fullpath == nil) - fullpath = relPath; - - return fullpath; -} -@end diff --git a/Support/cocos2d/Support/PVRTexture.m b/Support/cocos2d/Support/PVRTexture.m deleted file mode 100755 index ac86ed7..0000000 --- a/Support/cocos2d/Support/PVRTexture.m +++ /dev/null @@ -1,280 +0,0 @@ -/* - -File: PVRTexture.m -Abstract: The PVRTexture class is responsible for loading .pvr files. - -Version: 1.0 - -Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc. -("Apple") in consideration of your agreement to the following terms, and your -use, installation, modification or redistribution of this Apple software -constitutes acceptance of these terms. If you do not agree with these terms, -please do not use, install, modify or redistribute this Apple software. - -In consideration of your agreement to abide by the following terms, and subject -to these terms, Apple grants you a personal, non-exclusive license, under -Apple's copyrights in this original Apple software (the "Apple Software"), to -use, reproduce, modify and redistribute the Apple Software, with or without -modifications, in source and/or binary forms; provided that if you redistribute -the Apple Software in its entirety and without modifications, you must retain -this notice and the following text and disclaimers in all such redistributions -of the Apple Software. -Neither the name, trademarks, service marks or logos of Apple Inc. may be used -to endorse or promote products derived from the Apple Software without specific -prior written permission from Apple. Except as expressly stated in this notice, -no other rights or licenses, express or implied, are granted by Apple herein, -including but not limited to any patent rights that may be infringed by your -derivative works or by other works in which the Apple Software may be -incorporated. - -The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO -WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED -WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN -COMBINATION WITH YOUR PRODUCTS. - -IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE -GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR -DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF -CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF -APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -Copyright (C) 2008 Apple Inc. All Rights Reserved. - -*/ - -#import "PVRTexture.h" - -#define PVR_TEXTURE_FLAG_TYPE_MASK 0xff - -static char gPVRTexIdentifier[4] = "PVR!"; - -enum -{ - kPVRTextureFlagTypePVRTC_2 = 24, - kPVRTextureFlagTypePVRTC_4 -}; - -typedef struct _PVRTexHeader -{ - uint32_t headerLength; - uint32_t height; - uint32_t width; - uint32_t numMipmaps; - uint32_t flags; - uint32_t dataLength; - uint32_t bpp; - uint32_t bitmaskRed; - uint32_t bitmaskGreen; - uint32_t bitmaskBlue; - uint32_t bitmaskAlpha; - uint32_t pvrTag; - uint32_t numSurfs; -} PVRTexHeader; - - -@implementation PVRTexture - -@synthesize name = _name; -@synthesize width = _width; -@synthesize height = _height; -@synthesize internalFormat = _internalFormat; -@synthesize hasAlpha = _hasAlpha; - -// cocos2d integration -@synthesize retainName = _retainName; - - -- (BOOL)unpackPVRData:(NSData *)data -{ - BOOL success = FALSE; - PVRTexHeader *header = NULL; - uint32_t flags, pvrTag; - uint32_t dataLength = 0, dataOffset = 0, dataSize = 0; - uint32_t blockSize = 0, widthBlocks = 0, heightBlocks = 0; - uint32_t width = 0, height = 0, bpp = 4; - uint8_t *bytes = NULL; - uint32_t formatFlags; - - header = (PVRTexHeader *)[data bytes]; - - pvrTag = CFSwapInt32LittleToHost(header->pvrTag); - - if ((uint32_t)gPVRTexIdentifier[0] != ((pvrTag >> 0) & 0xff) || - (uint32_t)gPVRTexIdentifier[1] != ((pvrTag >> 8) & 0xff) || - (uint32_t)gPVRTexIdentifier[2] != ((pvrTag >> 16) & 0xff) || - (uint32_t)gPVRTexIdentifier[3] != ((pvrTag >> 24) & 0xff)) - { - return FALSE; - } - - flags = CFSwapInt32LittleToHost(header->flags); - formatFlags = flags & PVR_TEXTURE_FLAG_TYPE_MASK; - - if (formatFlags == kPVRTextureFlagTypePVRTC_4 || formatFlags == kPVRTextureFlagTypePVRTC_2) - { - [_imageData removeAllObjects]; - - if (formatFlags == kPVRTextureFlagTypePVRTC_4) - _internalFormat = GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG; - else if (formatFlags == kPVRTextureFlagTypePVRTC_2) - _internalFormat = GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG; - - _width = width = CFSwapInt32LittleToHost(header->width); - _height = height = CFSwapInt32LittleToHost(header->height); - - if (CFSwapInt32LittleToHost(header->bitmaskAlpha)) - _hasAlpha = TRUE; - else - _hasAlpha = FALSE; - - dataLength = CFSwapInt32LittleToHost(header->dataLength); - - bytes = ((uint8_t *)[data bytes]) + sizeof(PVRTexHeader); - - // Calculate the data size for each texture level and respect the minimum number of blocks - while (dataOffset < dataLength) - { - if (formatFlags == kPVRTextureFlagTypePVRTC_4) - { - blockSize = 4 * 4; // Pixel by pixel block size for 4bpp - widthBlocks = width / 4; - heightBlocks = height / 4; - bpp = 4; - } - else - { - blockSize = 8 * 4; // Pixel by pixel block size for 2bpp - widthBlocks = width / 8; - heightBlocks = height / 4; - bpp = 2; - } - - // Clamp to minimum number of blocks - if (widthBlocks < 2) - widthBlocks = 2; - if (heightBlocks < 2) - heightBlocks = 2; - - dataSize = widthBlocks * heightBlocks * ((blockSize * bpp) / 8); - - [_imageData addObject:[NSData dataWithBytes:bytes+dataOffset length:dataSize]]; - - dataOffset += dataSize; - - width = MAX(width >> 1, 1); - height = MAX(height >> 1, 1); - } - - success = TRUE; - } - - return success; -} - - -- (BOOL)createGLTexture -{ - int width = _width; - int height = _height; - NSData *data; - GLenum err; - - if ([_imageData count] > 0) - { - if (_name != 0) - glDeleteTextures(1, &_name); - - glGenTextures(1, &_name); - glBindTexture(GL_TEXTURE_2D, _name); - } - - for (NSUInteger i=0; i < [_imageData count]; i++) - { - data = [_imageData objectAtIndex:i]; - glCompressedTexImage2D(GL_TEXTURE_2D, i, _internalFormat, width, height, 0, [data length], [data bytes]); - - err = glGetError(); - if (err != GL_NO_ERROR) - { - NSLog(@"Error uploading compressed texture level: %d. glError: 0x%04X", i, err); - return FALSE; - } - - width = MAX(width >> 1, 1); - height = MAX(height >> 1, 1); - } - - [_imageData removeAllObjects]; - - return TRUE; -} - - -- (id)initWithContentsOfFile:(NSString *)path -{ - if((self = [super init])) - { - NSData *data = [NSData dataWithContentsOfFile:path]; - - _imageData = [[NSMutableArray alloc] initWithCapacity:10]; - - _name = 0; - _width = _height = 0; - _internalFormat = GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG; - _hasAlpha = FALSE; - - _retainName = NO; // cocos2d integration - - if (!data || ![self unpackPVRData:data] || ![self createGLTexture]) - { - [self release]; - self = nil; - } - } - - return self; -} - - -- (id)initWithContentsOfURL:(NSURL *)url -{ - if (![url isFileURL]) - { - [self release]; - return nil; - } - - return [self initWithContentsOfFile:[url path]]; -} - - -+ (id)pvrTextureWithContentsOfFile:(NSString *)path -{ - return [[[self alloc] initWithContentsOfFile:path] autorelease]; -} - - -+ (id)pvrTextureWithContentsOfURL:(NSURL *)url -{ - if (![url isFileURL]) - return nil; - - return [PVRTexture pvrTextureWithContentsOfFile:[url path]]; -} - - -- (void)dealloc -{ - [_imageData release]; - - if (_name != 0 && ! _retainName ) - glDeleteTextures(1, &_name); - - [super dealloc]; -} - -@end - diff --git a/Support/cocos2d/Support/Texture2D.h b/Support/cocos2d/Support/Texture2D.h deleted file mode 100755 index 7731516..0000000 --- a/Support/cocos2d/Support/Texture2D.h +++ /dev/null @@ -1,224 +0,0 @@ -/* - -===== IMPORTANT ===== - -This is sample code demonstrating API, technology or techniques in development. -Although this sample code has been reviewed for technical accuracy, it is not -final. Apple is supplying this information to help you plan for the adoption of -the technologies and programming interfaces described herein. This information -is subject to change, and software implemented based on this sample code should -be tested with final operating system software and final documentation. Newer -versions of this sample code may be provided with future seeds of the API or -technology. For information about updates to this and other developer -documentation, view the New & Updated sidebars in subsequent documentation -seeds. - -===================== - -File: Texture2D.h -Abstract: Creates OpenGL 2D textures from images or text. - -Version: 1.6 - -Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc. -("Apple") in consideration of your agreement to the following terms, and your -use, installation, modification or redistribution of this Apple software -constitutes acceptance of these terms. If you do not agree with these terms, -please do not use, install, modify or redistribute this Apple software. - -In consideration of your agreement to abide by the following terms, and subject -to these terms, Apple grants you a personal, non-exclusive license, under -Apple's copyrights in this original Apple software (the "Apple Software"), to -use, reproduce, modify and redistribute the Apple Software, with or without -modifications, in source and/or binary forms; provided that if you redistribute -the Apple Software in its entirety and without modifications, you must retain -this notice and the following text and disclaimers in all such redistributions -of the Apple Software. -Neither the name, trademarks, service marks or logos of Apple Inc. may be used -to endorse or promote products derived from the Apple Software without specific -prior written permission from Apple. Except as expressly stated in this notice, -no other rights or licenses, express or implied, are granted by Apple herein, -including but not limited to any patent rights that may be infringed by your -derivative works or by other works in which the Apple Software may be -incorporated. - -The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO -WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED -WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN -COMBINATION WITH YOUR PRODUCTS. - -IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE -GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR -DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF -CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF -APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -Copyright (C) 2008 Apple Inc. All Rights Reserved. - -*/ - -#import -#import - -//CONSTANTS: - -/** Possible texture pixel formats */ -typedef enum { - kTexture2DPixelFormat_Automatic = 0, - //! 32-bit texture: RGBA8888 - kTexture2DPixelFormat_RGBA8888, - //! 16-bit texture: used with images that have alpha pre-multiplied - kTexture2DPixelFormat_RGB565, - //! 8-bit textures used as masks - kTexture2DPixelFormat_A8, - //! 16-bit textures: RGBA4444 - kTexture2DPixelFormat_RGBA4444, - //! 16-bit textures: RGB5A1 - kTexture2DPixelFormat_RGB5A1, -} Texture2DPixelFormat; - -/// Default pixel format: RGBA4444 -#define kTexture2DPixelFormat_Default kTexture2DPixelFormat_RGBA4444 - -//CLASS INTERFACES: - -/** Texture2D class - * This class allows to easily create OpenGL 2D textures from images, text or raw data. - * The created Texture2D object will always have power-of-two dimensions. - * Depending on how you create the Texture2D object, the actual image area of the texture might be smaller than the texture dimensions i.e. "contentSize" != (pixelsWide, pixelsHigh) and (maxS, maxT) != (1.0, 1.0). - * Be aware that the content of the generated textures will be upside-down! - */ -@interface Texture2D : NSObject -{ - GLuint _name; - CGSize _size; - NSUInteger _width, - _height; - Texture2DPixelFormat _format; - GLfloat _maxS, - _maxT; - BOOL _hasPremultipliedAlpha; -} -/** Intializes with a texture2d with data */ -- (id) initWithData:(const void*)data pixelFormat:(Texture2DPixelFormat)pixelFormat pixelsWide:(NSUInteger)width pixelsHigh:(NSUInteger)height contentSize:(CGSize)size; - -/** pixelFormat */ -@property(readonly) Texture2DPixelFormat pixelFormat; -/** width in pixels */ -@property(readonly) NSUInteger pixelsWide; -/** hight in pixels */ -@property(readonly) NSUInteger pixelsHigh; - -/** texture name */ -@property(readonly) GLuint name; - -/** content size */ -@property(readonly, nonatomic) CGSize contentSize; -/** texture max S */ -@property(readonly) GLfloat maxS; -/** texture max T */ -@property(readonly) GLfloat maxT; -/** whether or not the texture has their Alpha premultiplied */ -@property(readonly) BOOL hasPremultipliedAlpha; -@end - -/** -Drawing extensions to make it easy to draw basic quads using a Texture2D object. -These functions require GL_TEXTURE_2D and both GL_VERTEX_ARRAY and GL_TEXTURE_COORD_ARRAY client states to be enabled. -*/ -@interface Texture2D (Drawing) -/** draws a texture at a given point */ -- (void) drawAtPoint:(CGPoint)point; -/** draws a texture inside a rect */ -- (void) drawInRect:(CGRect)rect; -@end - -/** -Extensions to make it easy to create a Texture2D object from an image file. -Note that RGBA type textures will have their alpha premultiplied - use the blending mode (GL_ONE, GL_ONE_MINUS_SRC_ALPHA). -*/ -@interface Texture2D (Image) -/** Initializes a texture from a UIImage object */ -- (id) initWithImage:(UIImage *)uiImage; -@end - -/** -Extensions to make it easy to create a Texture2D object from a string of text. -Note that the generated textures are of type A8 - use the blending mode (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA). -*/ -@interface Texture2D (Text) -/** Initializes a texture from a string with dimensions, alignment, font name and font size */ -- (id) initWithString:(NSString*)string dimensions:(CGSize)dimensions alignment:(UITextAlignment)alignment fontName:(NSString*)name fontSize:(CGFloat)size; -/** Initializes a texture from a string with font name and font size */ -- (id) initWithString:(NSString*)string fontName:(NSString*)name fontSize:(CGFloat)size; -@end - -/** - Extensions to make it easy to create a Texture2D object from a PVRTC file - Note that the generated textures are don't have their alpha premultiplied - use the blending mode (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA). - */ -@interface Texture2D (PVRTC) -/** Initializes a texture from a PVRTC buffer */ --(id) initWithPVRTCData: (const void*)data level:(int)level bpp:(int)bpp hasAlpha:(BOOL)hasAlpha length:(int)length; -/** Initializes a texture from a PVRTC file */ --(id) initWithPVRTCFile: (NSString*) file; -@end - -/** - Extension to set the Min / Mag filter - */ -typedef struct _ccTexParams { - GLuint minFilter; - GLuint magFilter; - GLuint wrapS; - GLuint wrapT; -} ccTexParams; - -@interface Texture2D (GLFilter) -/** sets the min filter, mag filter, wrap s and wrap t texture parameters - @since v0.8 - */ --(void) setTexParameters: (ccTexParams*) texParams; - -/** sets antialias texture parameters: - TEXTURE_MIN_FILTER = LINEAR - TEXTURE_MAG_FILTER = LINEAR - @since v0.8 - */ -- (void) setAntiAliasTexParameters; - -/** sets alias texture parameters: - TEXTURE_MIN_FILTER = NEAREST - TEXTURE_MAG_FILTER = NEAREST - @since v0.8 - */ -- (void) setAliasTexParameters; - -@end - -@interface Texture2D (PixelFormat) -/** sets the default pixel format for UIImages that contains alpha channel. - If the UIImage contains alpha channel, then the options are: - - generate 32-bit textures: RGBA8 (kTexture2DPixelFormat_RGBA8888) - - generate 16-bit textures: RGBA4 (default: kTexture2DPixelFormat_RGBA4444) - - generate 16-bit textures: RGB5A1 (kTexture2DPixelFormat_RGB5A1) - You can also use the following option, but you will lose the alpha channel: - - generate 16-bit textures: RGB565 (kTexture2DPixelFormat_RGB565) - - To use this function you MUST disable the "compres .PNG files" in XCode, otherwise all your .PNG images - will be pre-multiplied wihtout alpha channel. - @since v0.8 - */ -+(void) setDefaultAlphaPixelFormat:(Texture2DPixelFormat)format; - -/** returns the alpha pixel format - @since v0.8 - */ -+(Texture2DPixelFormat) defaultAlphaPixelFormat; -@end - - - diff --git a/Support/cocos2d/Support/Texture2D.m b/Support/cocos2d/Support/Texture2D.m deleted file mode 100755 index dd17e73..0000000 --- a/Support/cocos2d/Support/Texture2D.m +++ /dev/null @@ -1,521 +0,0 @@ -/* - -===== IMPORTANT ===== - -This is sample code demonstrating API, technology or techniques in development. -Although this sample code has been reviewed for technical accuracy, it is not -final. Apple is supplying this information to help you plan for the adoption of -the technologies and programming interfaces described herein. This information -is subject to change, and software implemented based on this sample code should -be tested with final operating system software and final documentation. Newer -versions of this sample code may be provided with future seeds of the API or -technology. For information about updates to this and other developer -documentation, view the New & Updated sidebars in subsequent documentation -seeds. - -===================== - -File: Texture2D.m -Abstract: Creates OpenGL 2D textures from images or text. - -Version: 1.6 - -Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc. -("Apple") in consideration of your agreement to the following terms, and your -use, installation, modification or redistribution of this Apple software -constitutes acceptance of these terms. If you do not agree with these terms, -please do not use, install, modify or redistribute this Apple software. - -In consideration of your agreement to abide by the following terms, and subject -to these terms, Apple grants you a personal, non-exclusive license, under -Apple's copyrights in this original Apple software (the "Apple Software"), to -use, reproduce, modify and redistribute the Apple Software, with or without -modifications, in source and/or binary forms; provided that if you redistribute -the Apple Software in its entirety and without modifications, you must retain -this notice and the following text and disclaimers in all such redistributions -of the Apple Software. -Neither the name, trademarks, service marks or logos of Apple Inc. may be used -to endorse or promote products derived from the Apple Software without specific -prior written permission from Apple. Except as expressly stated in this notice, -no other rights or licenses, express or implied, are granted by Apple herein, -including but not limited to any patent rights that may be infringed by your -derivative works or by other works in which the Apple Software may be -incorporated. - -The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO -WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED -WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN -COMBINATION WITH YOUR PRODUCTS. - -IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE -GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR -DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF -CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF -APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -Copyright (C) 2008 Apple Inc. All Rights Reserved. - -*/ - -/* - * Support for RGBA_4_4_4_4 and RGBA_5_5_5_1 was copied from: - * https://devforums.apple.com/message/37855#37855 by a1studmuffin - */ - -#import - -#import "Texture2D.h" -#import "PVRTexture.h" - - -//CONSTANTS: - -#define kMaxTextureSize 1024 - -//CLASS IMPLEMENTATIONS: - - -// If the image has alpha, you can create RGBA8 (32-bit) or RGBA4 (16-bit) or RGB5A1 (16-bit) -// Default is: RGBA4444 (16-bit textures) -static Texture2DPixelFormat defaultAlphaPixelFormat = kTexture2DPixelFormat_Default; - -@implementation Texture2D - -@synthesize contentSize=_size, pixelFormat=_format, pixelsWide=_width, pixelsHigh=_height, name=_name, maxS=_maxS, maxT=_maxT; -@synthesize hasPremultipliedAlpha=_hasPremultipliedAlpha; -- (id) initWithData:(const void*)data pixelFormat:(Texture2DPixelFormat)pixelFormat pixelsWide:(NSUInteger)width pixelsHigh:(NSUInteger)height contentSize:(CGSize)size -{ - GLint saveName; - if((self = [super init])) { - glGenTextures(1, &_name); - glGetIntegerv(GL_TEXTURE_BINDING_2D, &saveName); - glBindTexture(GL_TEXTURE_2D, _name); - - [self setAntiAliasTexParameters]; - - // Specify OpenGL texture image - - switch(pixelFormat) - { - case kTexture2DPixelFormat_RGBA8888: - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); - break; - case kTexture2DPixelFormat_RGBA4444: - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, data); - break; - case kTexture2DPixelFormat_RGB5A1: - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, data); - break; - case kTexture2DPixelFormat_RGB565: - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, data); - break; - case kTexture2DPixelFormat_A8: - glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, width, height, 0, GL_ALPHA, GL_UNSIGNED_BYTE, data); - break; - default: - [NSException raise:NSInternalInconsistencyException format:@""]; - - } - - glBindTexture(GL_TEXTURE_2D, saveName); - - _size = size; - _width = width; - _height = height; - _format = pixelFormat; - _maxS = size.width / (float)width; - _maxT = size.height / (float)height; - - _hasPremultipliedAlpha = NO; - } - return self; -} - -- (void) dealloc -{ -#if DEBUG - NSLog(@"deallocing %@", self); -#endif - if(_name) - glDeleteTextures(1, &_name); - - [super dealloc]; -} - -- (NSString*) description -{ - return [NSString stringWithFormat:@"<%@ = %08X | Name = %i | Dimensions = %ix%i | Coordinates = (%.2f, %.2f)>", [self class], self, _name, _width, _height, _maxS, _maxT]; -} - -@end - -@implementation Texture2D (Image) - -- (id) initWithImage:(UIImage *)uiImage -{ - NSUInteger width, - height, - i; - CGContextRef context = nil; - void* data = nil;; - CGColorSpaceRef colorSpace; - void* tempData; - unsigned int* inPixel32; - unsigned short* outPixel16; - BOOL hasAlpha; - CGImageAlphaInfo info; - CGAffineTransform transform; - CGSize imageSize; - Texture2DPixelFormat pixelFormat; - CGImageRef image; - BOOL sizeToFit = NO; - - - image = [uiImage CGImage]; - - if(image == NULL) { - [self release]; - NSLog(@"Image is Null"); - return nil; - } - - - info = CGImageGetAlphaInfo(image); - hasAlpha = ((info == kCGImageAlphaPremultipliedLast) || (info == kCGImageAlphaPremultipliedFirst) || (info == kCGImageAlphaLast) || (info == kCGImageAlphaFirst) ? YES : NO); - - size_t bpp = CGImageGetBitsPerComponent(image); - if(CGImageGetColorSpace(image)) { - if(hasAlpha || bpp >= 8) - pixelFormat = defaultAlphaPixelFormat; - else - pixelFormat = kTexture2DPixelFormat_RGB565; - } else //NOTE: No colorspace means a mask image - pixelFormat = kTexture2DPixelFormat_A8; - - imageSize = CGSizeMake(CGImageGetWidth(image), CGImageGetHeight(image)); - transform = CGAffineTransformIdentity; - - width = imageSize.width; - - if((width != 1) && (width & (width - 1))) { - i = 1; - while((sizeToFit ? 2 * i : i) < width) - i *= 2; - width = i; - } - height = imageSize.height; - if((height != 1) && (height & (height - 1))) { - i = 1; - while((sizeToFit ? 2 * i : i) < height) - i *= 2; - height = i; - } - while((width > kMaxTextureSize) || (height > kMaxTextureSize)) { - width /= 2; - height /= 2; - transform = CGAffineTransformScale(transform, 0.5f, 0.5f); - imageSize.width *= 0.5f; - imageSize.height *= 0.5f; - } - - // Create the bitmap graphics context - - switch(pixelFormat) { - case kTexture2DPixelFormat_RGBA8888: - case kTexture2DPixelFormat_RGBA4444: - case kTexture2DPixelFormat_RGB5A1: - colorSpace = CGColorSpaceCreateDeviceRGB(); - data = malloc(height * width * 4); - context = CGBitmapContextCreate(data, width, height, 8, 4 * width, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big); - CGColorSpaceRelease(colorSpace); - break; - case kTexture2DPixelFormat_RGB565: - colorSpace = CGColorSpaceCreateDeviceRGB(); - data = malloc(height * width * 4); - context = CGBitmapContextCreate(data, width, height, 8, 4 * width, colorSpace, kCGImageAlphaNoneSkipLast | kCGBitmapByteOrder32Big); - CGColorSpaceRelease(colorSpace); - break; - case kTexture2DPixelFormat_A8: - data = malloc(height * width); - context = CGBitmapContextCreate(data, width, height, 8, width, NULL, kCGImageAlphaOnly); - break; - default: - [NSException raise:NSInternalInconsistencyException format:@"Invalid pixel format"]; - } - - - CGContextClearRect(context, CGRectMake(0, 0, width, height)); - CGContextTranslateCTM(context, 0, height - imageSize.height); - - if(!CGAffineTransformIsIdentity(transform)) - CGContextConcatCTM(context, transform); - CGContextDrawImage(context, CGRectMake(0, 0, CGImageGetWidth(image), CGImageGetHeight(image)), image); - - // Repack the pixel data into the right format - - if(pixelFormat == kTexture2DPixelFormat_RGB565) { - //Convert "RRRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA" to "RRRRRGGGGGGBBBBB" - tempData = malloc(height * width * 2); - inPixel32 = (unsigned int*)data; - outPixel16 = (unsigned short*)tempData; - for(i = 0; i < width * height; ++i, ++inPixel32) - *outPixel16++ = ((((*inPixel32 >> 0) & 0xFF) >> 3) << 11) | ((((*inPixel32 >> 8) & 0xFF) >> 2) << 5) | ((((*inPixel32 >> 16) & 0xFF) >> 3) << 0); - free(data); - data = tempData; - - } - else if (pixelFormat == kTexture2DPixelFormat_RGBA4444) { - //Convert "RRRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA" to "RRRRGGGGBBBBAAAA" - tempData = malloc(height * width * 2); - inPixel32 = (unsigned int*)data; - outPixel16 = (unsigned short*)tempData; - for(i = 0; i < width * height; ++i, ++inPixel32) - *outPixel16++ = - ((((*inPixel32 >> 0) & 0xFF) >> 4) << 12) | // R - ((((*inPixel32 >> 8) & 0xFF) >> 4) << 8) | // G - ((((*inPixel32 >> 16) & 0xFF) >> 4) << 4) | // B - ((((*inPixel32 >> 24) & 0xFF) >> 4) << 0); // A - - - free(data); - data = tempData; - - } - else if (pixelFormat == kTexture2DPixelFormat_RGB5A1) { - //Convert "RRRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA" to "RRRRRGGGGGBBBBBA" - tempData = malloc(height * width * 2); - inPixel32 = (unsigned int*)data; - outPixel16 = (unsigned short*)tempData; - for(i = 0; i < width * height; ++i, ++inPixel32) - *outPixel16++ = - ((((*inPixel32 >> 0) & 0xFF) >> 3) << 11) | // R - ((((*inPixel32 >> 8) & 0xFF) >> 3) << 6) | // G - ((((*inPixel32 >> 16) & 0xFF) >> 3) << 1) | // B - ((((*inPixel32 >> 24) & 0xFF) >> 7) << 0); // A - - - free(data); - data = tempData; - } - self = [self initWithData:data pixelFormat:pixelFormat pixelsWide:width pixelsHigh:height contentSize:imageSize]; - - // should be after calling super init - _hasPremultipliedAlpha = (info == kCGImageAlphaPremultipliedLast || info == kCGImageAlphaPremultipliedFirst); - - CGContextRelease(context); - free(data); - - return self; -} - -@end - -@implementation Texture2D (Text) - -- (id) initWithString:(NSString*)string fontName:(NSString*)name fontSize:(CGFloat)size -{ - CGSize dim = [string sizeWithFont: [UIFont fontWithName:name size:size]]; - return [self initWithString:string dimensions:dim alignment:UITextAlignmentCenter fontName:name fontSize:size]; -} - -- (id) initWithString:(NSString*)string dimensions:(CGSize)dimensions alignment:(UITextAlignment)alignment fontName:(NSString*)name fontSize:(CGFloat)size -{ - NSUInteger width, - height, - i; - CGContextRef context; - void* data; - CGColorSpaceRef colorSpace; - UIFont * font; - - font = [UIFont fontWithName:name size:size]; - - width = dimensions.width; - if((width != 1) && (width & (width - 1))) { - i = 1; - while(i < width) - i *= 2; - width = i; - } - height = dimensions.height; - if((height != 1) && (height & (height - 1))) { - i = 1; - while(i < height) - i *= 2; - height = i; - } - - colorSpace = CGColorSpaceCreateDeviceGray(); - data = calloc(height, width); - context = CGBitmapContextCreate(data, width, height, 8, width, colorSpace, kCGImageAlphaNone); - CGColorSpaceRelease(colorSpace); - - - CGContextSetGrayFillColor(context, 1.0f, 1.0f); - CGContextTranslateCTM(context, 0.0f, height); - CGContextScaleCTM(context, 1.0f, -1.0f); //NOTE: NSString draws in UIKit referential i.e. renders upside-down compared to CGBitmapContext referential - UIGraphicsPushContext(context); - [string drawInRect:CGRectMake(0, 0, dimensions.width, dimensions.height) withFont:font lineBreakMode:UILineBreakModeWordWrap alignment:alignment]; - UIGraphicsPopContext(); - - self = [self initWithData:data pixelFormat:kTexture2DPixelFormat_A8 pixelsWide:width pixelsHigh:height contentSize:dimensions]; - - CGContextRelease(context); - free(data); - - return self; -} - -@end - -@implementation Texture2D (Drawing) - -- (void) drawAtPoint:(CGPoint)point -{ - GLfloat coordinates[] = { 0.0f, _maxT, - _maxS, _maxT, - 0.0f, 0.0f, - _maxS, 0.0f }; - GLfloat width = (GLfloat)_width * _maxS, - height = (GLfloat)_height * _maxT; - -#if 0 - GLfloat vertices[] = { -width / 2 + point.x, -height / 2 + point.y, 0.0f, - width / 2 + point.x, -height / 2 + point.y, 0.0f, - -width / 2 + point.x, height / 2 + point.y, 0.0f, - width / 2 + point.x, height / 2 + point.y, 0.0f }; - -#else // anchor is done by cocos2d automagically - GLfloat vertices[] = { point.x, point.y, 0.0f, - width + point.x, point.y, 0.0f, - point.x, height + point.y, 0.0f, - width + point.x, height + point.y, 0.0f }; -#endif - - glBindTexture(GL_TEXTURE_2D, _name); - glVertexPointer(3, GL_FLOAT, 0, vertices); - glTexCoordPointer(2, GL_FLOAT, 0, coordinates); - glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); -} - - -- (void) drawInRect:(CGRect)rect -{ - GLfloat coordinates[] = { 0.0f, _maxT, - _maxS, _maxT, - 0.0f, 0.0f, - _maxS, 0.0f }; - GLfloat vertices[] = { rect.origin.x, rect.origin.y, /*0.0f,*/ - rect.origin.x + rect.size.width, rect.origin.y, /*0.0f,*/ - rect.origin.x, rect.origin.y + rect.size.height, /*0.0f,*/ - rect.origin.x + rect.size.width, rect.origin.y + rect.size.height, /*0.0f*/ }; - - glBindTexture(GL_TEXTURE_2D, _name); - glVertexPointer(2, GL_FLOAT, 0, vertices); - glTexCoordPointer(2, GL_FLOAT, 0, coordinates); - glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); -} - -@end - -@implementation Texture2D (PVRTC) --(id) initWithPVRTCData: (const void*)data level:(int)level bpp:(int)bpp hasAlpha:(BOOL)hasAlpha length:(int)length -{ - GLint saveName; - - if((self = [super init])) { - glGenTextures(1, &_name); - glGetIntegerv(GL_TEXTURE_BINDING_2D, &saveName); - glBindTexture(GL_TEXTURE_2D, _name); - - [self setAntiAliasTexParameters]; - - GLenum format; - GLsizei size = length * length * bpp / 8; - if(hasAlpha) { - format = (bpp == 4) ? GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG : GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG; - } else { - format = (bpp == 4) ? GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG : GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG; - } - if(size < 32) { - size = 32; - } - glCompressedTexImage2D(GL_TEXTURE_2D, level, format, length, length, 0, size, data); - - glBindTexture(GL_TEXTURE_2D, saveName); - - _size = CGSizeMake(length, length); - _width = length; - _height = length; - _maxS = 1.0f; - _maxT = 1.0f; - } - return self; -} - --(id) initWithPVRTCFile: (NSString*) file -{ - - if( (self = [super init]) ) { - PVRTexture *pvr = [[PVRTexture alloc] initWithContentsOfFile:file]; - pvr.retainName = YES; // don't dealloc texture on release - - _name = pvr.name; // texture id - _maxS = 1.0f; - _maxT = 1.0f; - _width = pvr.width; // width - _height = pvr.height; // height - _size = CGSizeMake(_width, _height); - - [pvr release]; - - [self setAntiAliasTexParameters]; - } - return self; -} -@end - -// -// Use to apply MIN/MAG filter -// -@implementation Texture2D (GLFilter) - --(void) setTexParameters: (ccTexParams*) texParams -{ - glBindTexture( GL_TEXTURE_2D, self.name ); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, texParams->minFilter ); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, texParams->magFilter ); - glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, texParams->wrapS ); - glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, texParams->wrapT ); -} - --(void) setAliasTexParameters -{ - ccTexParams texParams = { GL_NEAREST, GL_NEAREST, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE }; - [self setTexParameters: &texParams]; -} - --(void) setAntiAliasTexParameters -{ - ccTexParams texParams = { GL_LINEAR, GL_LINEAR, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE }; - [self setTexParameters: &texParams]; -} -@end - -// -// Texture options for images that contains alpha -// -@implementation Texture2D (PixelFormat) -+(void) setDefaultAlphaPixelFormat:(Texture2DPixelFormat)format -{ - defaultAlphaPixelFormat = format; -} - -+(Texture2DPixelFormat) defaultAlphaPixelFormat -{ - return defaultAlphaPixelFormat; -} -@end diff --git a/Support/cocos2d/Support/TransformUtils.h b/Support/cocos2d/Support/TransformUtils.h deleted file mode 100644 index ee61c85..0000000 --- a/Support/cocos2d/Support/TransformUtils.h +++ /dev/null @@ -1,19 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2008,2009 Ricardo Quesada - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - -#import -#import - -void CGAffineToGL(const CGAffineTransform *t, GLfloat *m); -void GLToCGAffine(const GLfloat *m, CGAffineTransform *t); diff --git a/Support/cocos2d/Support/TransformUtils.m b/Support/cocos2d/Support/TransformUtils.m deleted file mode 100644 index 5e272ac..0000000 --- a/Support/cocos2d/Support/TransformUtils.m +++ /dev/null @@ -1,34 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2008,2009 Ricardo Quesada - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - -#import "TransformUtils.h" - -void CGAffineToGL(const CGAffineTransform *t, GLfloat *m) -{ - // | m[0] m[4] m[8] m[12] | | m11 m21 m31 m41 | | a c 0 tx | - // | m[1] m[5] m[9] m[13] | | m12 m22 m32 m42 | | b d 0 ty | - // | m[2] m[6] m[10] m[14] | <=> | m13 m23 m33 m43 | <=> | 0 0 1 0 | - // | m[3] m[7] m[11] m[15] | | m14 m24 m34 m44 | | 0 0 0 1 | - - m[2] = m[3] = m[6] = m[7] = m[8] = m[9] = m[11] = m[14] = 0.0f; - m[10] = m[15] = 1.0f; - m[0] = t->a; m[4] = t->c; m[12] = t->tx; - m[1] = t->b; m[5] = t->d; m[13] = t->ty; -} - -void GLToCGAffine(const GLfloat *m, CGAffineTransform *t) -{ - t->a = m[0]; t->c = m[4]; t->tx = m[12]; - t->b = m[1]; t->d = m[5]; t->ty = m[13]; -} diff --git a/Support/cocos2d/Support/UIColor-OpenGL.h b/Support/cocos2d/Support/UIColor-OpenGL.h deleted file mode 100644 index bfc4f61..0000000 --- a/Support/cocos2d/Support/UIColor-OpenGL.h +++ /dev/null @@ -1,30 +0,0 @@ -/* OC3D - * - * Copyright (C) 2008 Boris Stock - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; version 3 or (it is your choice) any later - * version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#import -#import -#import -#import -#import - -@interface UIColor(OpenGL) -- (void)setOpenGLClearColor; -- (void)setOpenGLColor; -@end diff --git a/Support/cocos2d/Support/UIColor-OpenGL.m b/Support/cocos2d/Support/UIColor-OpenGL.m deleted file mode 100644 index eee44c1..0000000 --- a/Support/cocos2d/Support/UIColor-OpenGL.m +++ /dev/null @@ -1,69 +0,0 @@ -/* OC3D - * - * Copyright (C) 2008 Boris Stock - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; version 3 or (it is your choice) any later - * version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#import "UIColor-OpenGL.h" - -@implementation UIColor(OpenGL) - -- (void)setOpenGLClearColor -{ - CGColorRef color = self.CGColor; - int numComponents = CGColorGetNumberOfComponents(color); - if (numComponents == 2) - { - const CGFloat *components = CGColorGetComponents(color); - CGFloat all = components[0]; - CGFloat alpha = components[1]; - glClearColor(all,all, all, alpha); - } - else - { - const CGFloat *components = CGColorGetComponents(color); - CGFloat red = components[0]; - CGFloat green = components[1]; - CGFloat blue = components[2]; - CGFloat alpha = components[3]; - glClearColor(red,green, blue, alpha); - } -} - -- (void)setOpenGLColor -{ - CGColorRef color = self.CGColor; - int numComponents = CGColorGetNumberOfComponents(color); - if (numComponents == 2) - { - const CGFloat *components = CGColorGetComponents(color); - CGFloat all = components[0]; - CGFloat alpha = components[1]; - glColor4f(all,all, all, alpha); - } - else - { - const CGFloat *components = CGColorGetComponents(color); - CGFloat red = components[0]; - CGFloat green = components[1]; - CGFloat blue = components[2]; - CGFloat alpha = components[3]; - glColor4f(red,green, blue, alpha); - } -} - -@end diff --git a/Support/cocos2d/Support/ccArray.h b/Support/cocos2d/Support/ccArray.h deleted file mode 100644 index 2560efc..0000000 --- a/Support/cocos2d/Support/ccArray.h +++ /dev/null @@ -1,212 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2008,2009 Ricardo Quesada - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - -/* Copyright (c) 2007 Scott Lembcke - * - * 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. - */ - -/** - @file - Based on Chipmunk cpArray. - ccArray is a faster alternative to NSMutableArray, it does pretty much the - same thing (stores NSObjects and retains/releases them appropriately). It's - faster because: - - it uses a plain C interface so it doesn't incur Objective-c messaging overhead - - it assumes you know what you're doing, so it doesn't spend time on safety checks - (index out of bounds, required capacity etc.) - - comparisons are done using pointer equality instead of isEqual - */ - -#ifndef CC_ARRAY_H -#define CC_ARRAY_H - -#import - -#import -#import - -typedef struct ccArray { - NSUInteger num, max; - id *arr; -} ccArray; - -/** Allocates and initializes a new array with specified capacity */ -static inline ccArray* ccArrayNew(NSUInteger capacity) { - if (capacity == 0) - capacity = 1; - - ccArray *arr = malloc( sizeof(ccArray) ); - arr->num = 0; - arr->arr = malloc( capacity * sizeof(id) ); - arr->max = capacity; - - return arr; -} - -static inline void ccArrayRemoveAllObjects(ccArray *arr); - -/** Frees array after removing all remaining objects. Silently ignores nil arr. */ -static inline void ccArrayFree(ccArray *arr) -{ - if( arr == nil ) return; - - ccArrayRemoveAllObjects(arr); - - free(arr->arr); - free(arr); -} - -/** Doubles array capacity */ -static inline void ccArrayDoubleCapacity(ccArray *arr) -{ - arr->max *= 2; - arr->arr = realloc( arr->arr, arr->max * sizeof(id) ); -} - -/** Increases array capacity such that max >= num + extra. */ -static inline void ccArrayEnsureExtraCapacity(ccArray *arr, NSUInteger extra) -{ - while (arr->max < arr->num + extra) - ccArrayDoubleCapacity(arr); -} - -/** Returns index of first occurence of object, NSNotFound if object not found. */ -static inline NSUInteger ccArrayGetIndexOfObject(ccArray *arr, id object) -{ - for( NSUInteger i = 0; i < arr->num; i++) - if( arr->arr[i] == object ) return i; - return NSNotFound; -} - -/** Returns a Boolean value that indicates whether object is present in array. */ -static inline BOOL ccArrayContainsObject(ccArray *arr, id object) -{ - return ccArrayGetIndexOfObject(arr, object) != NSNotFound; -} - -/** Appends an object. Bahaviour undefined if array doesn't have enough capacity. */ -static inline void ccArrayAppendObject(ccArray *arr, id object) -{ - arr->arr[arr->num] = [object retain]; - arr->num++; -} - -/** Appends an object. Capacity of arr is increased if needed. */ -static inline void ccArrayAppendObjectWithResize(ccArray *arr, id object) -{ - ccArrayEnsureExtraCapacity(arr, 1); - ccArrayAppendObject(arr, object); -} - -/** Appends objects from plusArr to arr. Behaviour undefined if arr doesn't have - enough capacity. */ -static inline void ccArrayAppendArray(ccArray *arr, ccArray *plusArr) -{ - for( NSUInteger i = 0; i < plusArr->num; i++) - ccArrayAppendObject(arr, plusArr->arr[i]); -} - -/** Appends objects from plusArr to arr. Capacity of arr is increased if needed. */ -static inline void ccArrayAppendArrayWithResize(ccArray *arr, ccArray *plusArr) -{ - ccArrayEnsureExtraCapacity(arr, plusArr->num); - ccArrayAppendArray(arr, plusArr); -} - -/** Removes all objects from arr */ -static inline void ccArrayRemoveAllObjects(ccArray *arr) -{ - while( arr->num > 0 ) - [arr->arr[--arr->num] release]; -} - -/** Removes object at specified index and pushes back all subsequent objects. - Behaviour undefined if index outside [0, num-1]. */ -static inline void ccArrayRemoveObjectAtIndex(ccArray *arr, NSUInteger index) -{ - [arr->arr[index] release]; - - for( NSUInteger last = --arr->num; index < last; index++) - arr->arr[index] = arr->arr[index + 1]; -} - -/** Removes object at specified index and fills the gap with the last object, - thereby avoiding the need to push back subsequent objects. - Behaviour undefined if index outside [0, num-1]. */ -static inline void ccArrayFastRemoveObjectAtIndex(ccArray *arr, NSUInteger index) -{ - [arr->arr[index] release]; - NSUInteger last = --arr->num; - arr->arr[index] = arr->arr[last]; -} - -/** Searches for the first occurance of object and removes it. If object is not - found the function has no effect. */ -static inline void ccArrayRemoveObject(ccArray *arr, id object) -{ - NSUInteger index = ccArrayGetIndexOfObject(arr, object); - if (index != NSNotFound) - ccArrayRemoveObjectAtIndex(arr, index); -} - -/** Removes from arr all objects in minusArr. For each object in minusArr, the - first matching instance in arr will be removed. */ -static inline void ccArrayRemoveArray(ccArray *arr, ccArray *minusArr) -{ - for( NSUInteger i = 0; i < minusArr->num; i++) - ccArrayRemoveObject(arr, minusArr->arr[i]); -} - -/** Removes from arr all objects in minusArr. For each object in minusArr, all - matching instances in arr will be removed. */ -static inline void ccArrayFullRemoveArray(ccArray *arr, ccArray *minusArr) -{ - NSUInteger back = 0; - - for( NSUInteger i = 0; i < arr->num; i++) { - if( ccArrayContainsObject(minusArr, arr->arr[i]) ) { - [arr->arr[i] release]; - back++; - } else - arr->arr[i - back] = arr->arr[i]; - } - - arr->num -= back; -} - -/** Sends to each object in arr the message identified by given selector. */ -static inline void ccArrayMakeObjectsPerformSelector(ccArray *arr, SEL sel) -{ - for( NSUInteger i = 0; i < arr->num; i++) - [arr->arr[i] performSelector:sel]; -} - -#endif // CC_ARRAY_H diff --git a/Support/cocos2d/TargetedTouchDelegate.h b/Support/cocos2d/TargetedTouchDelegate.h deleted file mode 100644 index 10cc574..0000000 --- a/Support/cocos2d/TargetedTouchDelegate.h +++ /dev/null @@ -1,32 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2009 Valentin Milea - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ -#import - -/** - TargetedTouchDelegate -*/ -@protocol TargetedTouchDelegate - -/** Return YES to claim the touch. - Updates of claimed touches (move/ended/cancelled) are sent only to the - delegate(s) that claimed them when they began. In other words, updates - will "target" their specific handler, without bothering the other handlers. - */ -- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event; -@optional -// touch updates: -- (void)ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event; -- (void)ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event; -- (void)ccTouchCancelled:(UITouch *)touch withEvent:(UIEvent *)event; -@end diff --git a/Support/cocos2d/TextureAtlas.m b/Support/cocos2d/TextureAtlas.m deleted file mode 100644 index d9769f0..0000000 --- a/Support/cocos2d/TextureAtlas.m +++ /dev/null @@ -1,271 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2008,2009 Ricardo Quesada - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - -// cocos2d -#import "TextureAtlas.h" -#import "TextureMgr.h" -#import "ccMacros.h" - -// support -#import "Support/Texture2D.h" - -@interface TextureAtlas (Private) --(void) initIndices; -@end - -//According to some tests GL_TRIANGLE_STRIP is slower, MUCH slower. Probably I'm doing something very wrong -//#define USE_TRIANGLE_STRIP 1 - -@implementation TextureAtlas - -@synthesize totalQuads = totalQuads_, capacity = capacity_; -@synthesize texture = texture_; - -#pragma mark TextureAtlas - alloc & init - -+(id) textureAtlasWithFile:(NSString*) file capacity: (NSUInteger) n -{ - return [[[self alloc] initWithFile:file capacity:n] autorelease]; -} - -+(id) textureAtlasWithTexture:(Texture2D *)tex capacity:(NSUInteger)n -{ - return [[[self alloc] initWithTexture:tex capacity:n] autorelease]; -} - --(id) initWithFile:(NSString*)file capacity:(NSUInteger)n -{ - // retained in property - Texture2D *tex = [[TextureMgr sharedTextureMgr] addImage:file]; - - return [self initWithTexture:tex capacity:n]; -} - --(id) initWithTexture:(Texture2D*)tex capacity:(NSUInteger)n -{ - if( (self=[super init]) ) { - - capacity_ = n; - - // retained in property - self.texture = tex; - - quads = malloc( sizeof(quads[0]) * capacity_ ); - indices = malloc( sizeof(indices[0]) * capacity_ * 6 ); - - if( ! ( quads && indices) ) { - NSLog(@"TextureAtlas: not enough memory"); - if( quads ) - free(quads); - if( indices ) - free(indices); - return nil; - } - - [self initIndices]; - } - - return self; -} - -- (NSString*) description -{ - return [NSString stringWithFormat:@"<%@ = %08X | totalQuads = %i>", [self class], self, totalQuads_]; -} - --(void) dealloc -{ - CCLOG(@"deallocing %@",self); - - free(quads); - free(indices); - - [texture_ release]; - - [super dealloc]; -} - --(void) initIndices -{ - for( NSUInteger i=0;i< capacity_;i++) { -#ifdef USE_TRIANGLE_STRIP - indices[i*6+0] = i*4+0; - indices[i*6+1] = i*4+0; - indices[i*6+2] = i*4+2; - indices[i*6+3] = i*4+1; - indices[i*6+4] = i*4+3; - indices[i*6+5] = i*4+3; -#else - indices[i*6+0] = i*4+0; - indices[i*6+1] = i*4+1; - indices[i*6+2] = i*4+2; - - // inverted index. issue #179 - indices[i*6+3] = i*4+3; - indices[i*6+4] = i*4+2; - indices[i*6+5] = i*4+1; -// indices[i*6+3] = i*4+2; -// indices[i*6+4] = i*4+3; -// indices[i*6+5] = i*4+1; -#endif - } -} - -#pragma mark TextureAtlas - Update, Insert, Move & Remove - --(void) updateQuad:(ccV3F_C4B_T2F_Quad*)quad atIndex:(NSUInteger) n -{ - - NSAssert( n >= 0 && n < capacity_, @"updateQuadWithTexture: Invalid index"); - - totalQuads_ = MAX( n+1, totalQuads_); - - quads[n] = *quad; -} - - --(void) insertQuad:(ccV3F_C4B_T2F_Quad*)quad atIndex:(NSUInteger)index -{ - NSAssert( index >= 0 && index < capacity_, @"updateQuadWithTexture: Invalid index"); - - totalQuads_++; - - NSUInteger remaining = (totalQuads_-1) - index; - - // last object doesn't need to be moved - if( remaining ) { - // tex coordinates - memmove( &quads[index+1],&quads[index], sizeof(quads[0]) * remaining ); - } - - quads[index] = *quad; -} - - --(void) insertQuadFromIndex:(NSUInteger)oldIndex atIndex:(NSUInteger)newIndex -{ - NSAssert( newIndex >= 0 && newIndex < totalQuads_, @"insertQuadFromIndex:atIndex: Invalid index"); - NSAssert( oldIndex >= 0 && oldIndex < totalQuads_, @"insertQuadFromIndex:atIndex: Invalid index"); - - if( oldIndex == newIndex ) - return; - - NSUInteger howMany = abs( oldIndex - newIndex); - int dst = oldIndex; - int src = oldIndex + 1; - if( oldIndex > newIndex) { - dst = newIndex+1; - src = newIndex; - } - - // tex coordinates - ccV3F_C4B_T2F_Quad quadsBackup = quads[oldIndex]; - memmove( &quads[dst],&quads[src], sizeof(quads[0]) * howMany ); - quads[newIndex] = quadsBackup; -} - --(void) removeQuadAtIndex:(NSUInteger) index -{ - NSAssert( index >= 0 && index < totalQuads_, @"removeQuadAtIndex: Invalid index"); - - NSUInteger remaining = (totalQuads_-1) - index; - - // last object doesn't need to be moved - if( remaining ) { - // tex coordinates - memmove( &quads[index],&quads[index+1], sizeof(quads[0]) * remaining ); - } - - totalQuads_--; -} - --(void) removeAllQuads -{ - totalQuads_ = 0; -} - -#pragma mark TextureAtlas - Resize - --(BOOL) resizeCapacity: (NSUInteger) newCapacity -{ - if( newCapacity == capacity_ ) - return YES; - - // update capacity and totolQuads - totalQuads_ = MIN(totalQuads_,newCapacity); - capacity_ = newCapacity; - - void * tmpQuads = realloc( quads, sizeof(quads[0]) * capacity_ ); - void * tmpIndices = realloc( indices, sizeof(indices[0]) * capacity_ * 6 ); - - if( ! ( tmpQuads && tmpIndices) ) { - NSLog(@"TextureAtlas: not enough memory"); - if( tmpQuads ) - free(tmpQuads); - else - free(quads); - - if( tmpIndices ) - free(tmpIndices); - else - free(indices); - - indices = nil; - quads = nil; - capacity_ = totalQuads_ = 0; - return NO; - } - - quads = tmpQuads; - indices = tmpIndices; - - [self initIndices]; - - return YES; -} - -#pragma mark TextureAtlas - Drawing - --(void) drawQuads -{ - return [self drawNumberOfQuads: totalQuads_]; -} - --(void) drawNumberOfQuads: (NSUInteger) n -{ -#define kPointSize sizeof(quads[0].bl) - glBindTexture(GL_TEXTURE_2D, [texture_ name]); - - int offset = (int)quads; - - // vertex - int diff = offsetof( ccV3F_C4B_T2F, vertices); - glVertexPointer(3, GL_FLOAT, kPointSize, (void*) (offset + diff) ); - - // color - diff = offsetof( ccV3F_C4B_T2F, colors); - glColorPointer(4, GL_UNSIGNED_BYTE, kPointSize, (void*)(offset + diff)); - - // tex coords - diff = offsetof( ccV3F_C4B_T2F, texCoords); - glTexCoordPointer(2, GL_FLOAT, kPointSize, (void*)(offset + diff)); - -#ifdef USE_TRIANGLE_STRIP - glDrawElements(GL_TRIANGLE_STRIP, n*6, GL_UNSIGNED_SHORT, indices); -#else - glDrawElements(GL_TRIANGLES, n*6, GL_UNSIGNED_SHORT, indices); -#endif -} - -@end diff --git a/Support/cocos2d/TextureMgr.h b/Support/cocos2d/TextureMgr.h deleted file mode 100644 index f411e53..0000000 --- a/Support/cocos2d/TextureMgr.h +++ /dev/null @@ -1,81 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2008,2009 Ricardo Quesada - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - -#import - -#import "Support/Texture2D.h" - -/** Singleton that handles the loading of textures - * Once the texture is loaded, the next time it will return - * a reference of the previously loaded texture reducing GPU & CPU memory - */ -@interface TextureMgr : NSObject -{ - NSMutableDictionary *textures; -} - -/** Retruns ths shared instance of the Texture Manager */ -+ (TextureMgr *) sharedTextureMgr; - -/** Returns a Texture2D object given an file image - * If the file image was not previously loaded, it will create a new Texture2D - * object and it will return it. - * Otherwise it will return a reference of a previosly loaded image. - * Supported images extensions: .png, .bmp, .tiff, .jpeg, .pvr - */ --(Texture2D*) addImage: (NSString*) fileimage; - -/** Returns a Texture2D object given an PVRTC RAW filename - * If the file image was not previously loaded, it will create a new Texture2D - * object and it will return it. Otherwise it will return a reference of a previosly loaded image - * - * It can only load square images: width == height, and it must be a power of 2 (128,256,512...) - * bpp can only be 2 or 4. 2 means more compression but lower quality. - * hasAlpha: whether or not the image contains alpha channel - */ --(Texture2D*) addPVRTCImage: (NSString*) fileimage bpp:(int)bpp hasAlpha:(BOOL)alpha width:(int)w; - -/** Returns a Texture2D object given an PVRTC filename - * If the file image was not previously loaded, it will create a new Texture2D - * object and it will return it. Otherwise it will return a reference of a previosly loaded image - */ --(Texture2D*) addPVRTCImage: (NSString*) filename; - - -/** Returns a Texture2D object given an CGImageRef image - * If the image was not previously loaded, it will create a new Texture2D - * object and it will return it. - * Otherwise it will return a reference of a previosly loaded image - */ --(Texture2D*) addCGImage: (CGImageRef) image; - -/** Purges the dictionary of loaded textures. - * Call this method if you receive the "Memory Warning" - * In the short term: it will free some resources preventing your app from being killed - * In the medium term: it will allocate more resources - * In the long term: it will be the same - */ --(void) removeAllTextures; - -/** Removes unused textures - * Textures that have a retain count of 1 will be deleted - * It is convinient to call this method after when starting a new Scene - * @since v0.8 - */ --(void) removeUnusedTextures; - -/** Deletes a texture from the Texture Manager - */ --(void) removeTexture: (Texture2D*) tex; -@end diff --git a/Support/cocos2d/TextureMgr.m b/Support/cocos2d/TextureMgr.m deleted file mode 100644 index 95df061..0000000 --- a/Support/cocos2d/TextureMgr.m +++ /dev/null @@ -1,176 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2008,2009 Ricardo Quesada - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - -#import "TextureMgr.h" -#import "ccMacros.h" -#import "Support/FileUtils.h" -#import "Support/Texture2D.h" - - -@implementation TextureMgr -// -// singleton stuff -// -static TextureMgr *sharedTextureMgr; - -+ (TextureMgr *)sharedTextureMgr -{ - @synchronized([TextureMgr class]) - { - if (!sharedTextureMgr) - [[TextureMgr alloc] init]; - - return sharedTextureMgr; - } - // to avoid compiler warning - return nil; -} - -+(id)alloc -{ - @synchronized([TextureMgr class]) - { - NSAssert(sharedTextureMgr == nil, @"Attempted to allocate a second instance of a singleton."); - sharedTextureMgr = [super alloc]; - return sharedTextureMgr; - } - // to avoid compiler warning - return nil; -} - --(id) init -{ - if( (self=[super init]) ) - textures = [[NSMutableDictionary dictionaryWithCapacity: 10] retain]; - - return self; -} - --(void) dealloc -{ - [textures release]; - [super dealloc]; -} - -// public interfaces - --(Texture2D*) addImage: (NSString*) path -{ - NSAssert(path != nil, @"TextureMgr: fileimage MUST not be nill"); - - Texture2D * tex; - - if( (tex=[textures objectForKey: path] ) ) { - return tex; - } - - // Split up directory and filename - NSString *fullpath = [FileUtils fullPathFromRelativePath: path ]; - - // all images are handled by UIImage except PVR extension that is handled by our own handler - if ( [[path lowercaseString] hasSuffix:@".pvr"] ) - return [self addPVRTCImage:fullpath]; - - tex = [ [Texture2D alloc] initWithImage: [UIImage imageWithContentsOfFile: fullpath ] ]; - - [textures setObject: tex forKey:path]; - - return [tex autorelease]; -} - --(Texture2D*) addPVRTCImage: (NSString*) path bpp:(int)bpp hasAlpha:(BOOL)alpha width:(int)w -{ - NSAssert(path != nil, @"TextureMgr: fileimage MUST not be nill"); - NSAssert( bpp==2 || bpp==4, @"TextureMgr: bpp must be either 2 or 4"); - - Texture2D * tex; - - if( (tex=[textures objectForKey: path] ) ) { - return tex; - } - - // Split up directory and filename - NSString *fullpath = [FileUtils fullPathFromRelativePath:path]; - - NSData *nsdata = [[NSData alloc] initWithContentsOfFile:fullpath]; - tex = [[Texture2D alloc] initWithPVRTCData:[nsdata bytes] level:0 bpp:bpp hasAlpha:alpha length:w]; - [textures setObject: tex forKey:path]; - [nsdata release]; - - return [tex autorelease]; -} - --(Texture2D*) addPVRTCImage: (NSString*) fileimage -{ - NSAssert(fileimage != nil, @"TextureMgr: fileimage MUST not be nill"); - - Texture2D * tex; - - if( (tex=[textures objectForKey: fileimage] ) ) { - return tex; - } - - tex = [[Texture2D alloc] initWithPVRTCFile: fileimage]; - if( tex ) - [textures setObject: tex forKey:fileimage]; - - return [tex autorelease]; -} - - --(Texture2D*) addCGImage: (CGImageRef) image -{ - NSAssert(image != nil, @"TextureMgr: image MUST not be nill"); - - Texture2D * tex; - NSString *key = [NSString stringWithFormat:@"%08X",(unsigned long)image]; - - if( (tex=[textures objectForKey: key] ) ) { - return tex; - } - - tex = [[Texture2D alloc] initWithImage: [UIImage imageWithCGImage:image]]; - [textures setObject: tex forKey:key]; - - return [tex autorelease]; -} - --(void) removeAllTextures -{ - [textures removeAllObjects]; -} - --(void) removeUnusedTextures -{ - NSArray *keys = [textures allKeys]; - for( id key in keys ) { - id value = [textures objectForKey:key]; - if( [value retainCount] == 1 ) { - CCLOG(@"removing texture: %@", key); - [textures removeObjectForKey:key]; - } - } -} - --(void) removeTexture: (Texture2D*) tex -{ - if( ! tex ) - return; - - NSArray *keys = [textures allKeysForObject:tex]; - - for( NSUInteger i = 0; i < [keys count]; i++ ) - [textures removeObjectForKey:[keys objectAtIndex:i]]; -} -@end diff --git a/Support/cocos2d/TextureNode.h b/Support/cocos2d/TextureNode.h deleted file mode 100644 index 544065f..0000000 --- a/Support/cocos2d/TextureNode.h +++ /dev/null @@ -1,49 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2008,2009 Ricardo Quesada - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - - -#import - -#import "Support/Texture2D.h" - -#import "CocosNode.h" - - -/** TextureNode is a subclass of CocosNode that implements the CocosNodeRGBA - * and CocosNodeTexture protocol. - * - * As the name implies it, it knows how to render a textures. - * - * All features from CocosNode are valid, plus the following new features: - * - opacity and RGB - * - texture (can be Aliased or AntiAliased) - */ -@interface TextureNode : CocosNode { - - /// texture - Texture2D *texture_; - - /// texture opacity - GLubyte opacity_; - - /// texture color - GLubyte r_,g_,b_; -} - -/** The texture that is rendered */ -@property (readwrite,retain) Texture2D *texture; - -/** conforms to CocosNodeRGBA protocol */ -@property (readonly) GLubyte r, g, b, opacity; -@end diff --git a/Support/cocos2d/TextureNode.m b/Support/cocos2d/TextureNode.m deleted file mode 100644 index eefa7ea..0000000 --- a/Support/cocos2d/TextureNode.m +++ /dev/null @@ -1,98 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2008,2009 Ricardo Quesada - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - -#import -#import -#import - -#import "TextureMgr.h" -#import "TextureNode.h" -#import "ccMacros.h" -#import "Support/CGPointExtension.h" - -@implementation TextureNode - -@synthesize opacity=opacity_, r=r_, g=g_, b=b_; - -- (id) init -{ - if( (self=[super init]) ) { - opacity_ = r_ = g_ = b_ = 255; - anchorPoint_ = ccp(0.5f, 0.5f); - } - - return self; -} - --(void) dealloc -{ - [texture_ release]; - [super dealloc]; -} - --(void) setTexture:(Texture2D*) texture -{ - [texture_ release]; - texture_ = [texture retain]; - [self setContentSize: texture.contentSize]; -} - --(Texture2D*) texture -{ - return texture_; -} - -#pragma mark TextureNode - RGBA protocol --(void) setRGB: (GLubyte) rr :(GLubyte) gg :(GLubyte)bb -{ - r_=rr; - g_=gg; - b_=bb; -} - --(void) setOpacity:(GLubyte)opacity -{ - // special opacity for premultiplied textures - opacity_ = opacity; - if( [texture_ hasPremultipliedAlpha] ) - r_ = g_ = b_ = opacity_; -} - -- (void) draw -{ - glEnableClientState( GL_VERTEX_ARRAY); - glEnableClientState( GL_TEXTURE_COORD_ARRAY ); - - glEnable( GL_TEXTURE_2D); - - glColor4ub( r_, g_, b_, opacity_); - - BOOL preMulti = [texture_ hasPremultipliedAlpha]; - if( !preMulti ) - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - - [texture_ drawAtPoint: CGPointZero]; - - if( !preMulti ) - glBlendFunc(CC_BLEND_SRC, CC_BLEND_DST); - - // is this chepear than saving/restoring color state ? - glColor4ub( 255, 255, 255, 255); - - glDisable( GL_TEXTURE_2D); - - glDisableClientState(GL_VERTEX_ARRAY ); - glDisableClientState( GL_TEXTURE_COORD_ARRAY ); -} -@end diff --git a/Support/cocos2d/TileMapAtlas.h b/Support/cocos2d/TileMapAtlas.h deleted file mode 100644 index 2b96d5a..0000000 --- a/Support/cocos2d/TileMapAtlas.h +++ /dev/null @@ -1,61 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2008,2009 Ricardo Quesada - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - -#import "TextureAtlas.h" -#import "AtlasNode.h" -#import "Support/TGAlib.h" - -/** TileMapAtlas is a subclass of AtlasNode. - - It knows how to render a map based of tiles. - The tiles must be in a .PNG format while the map must be a .TGA file. - - For more information regarding the format, please see this post: - http://blog.sapusmedia.com/2008/12/how-to-use-tilemap-editor-for-cocos2d.html - - All features from AtlasNode are valid in TileMapAtlas - */ -@interface TileMapAtlas : AtlasNode { - - /// info about the map file - tImageTGA *tgaInfo; - - /// x,y to altas dicctionary - NSMutableDictionary *posToAtlasIndex; - - /// numbers of tiles to render - int itemsToRender; -} - -/** TileMap info */ -@property (readonly) tImageTGA *tgaInfo; - -/** creates the TileMap with a tile file (atlas) with a map file and the width and height of each tile */ -+(id) tileMapAtlasWithTileFile:(NSString*)tile mapFile:(NSString*)map tileWidth:(int)w tileHeight:(int)h; - -/** initializes the TileMap with a tile file (atlas) with a map file and the width and height of each tile */ --(id) initWithTileFile:(NSString*)tile mapFile:(NSString*)map tileWidth:(int)w tileHeight:(int)h; - -/** returns a tile from position x,y. - For the moment only channel R is used - */ --(ccColor3B) tileAt: (ccGridSize) position; - -/** sets a tile at position x,y. - For the moment only channel R is used - */ --(void) setTile:(ccColor3B)tile at:(ccGridSize)position; -/** dealloc the map from memory */ --(void) releaseMap; -@end diff --git a/Support/cocos2d/TouchDispatcher.h b/Support/cocos2d/TouchDispatcher.h deleted file mode 100644 index fc73317..0000000 --- a/Support/cocos2d/TouchDispatcher.h +++ /dev/null @@ -1,51 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2009 Valentin Milea - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - -#import -#import "Layer.h" -#import "TargetedTouchDelegate.h" - -/** TouchDispatcher - * XXX: add description - */ -@interface TouchDispatcher : NSObject -{ -@private - NSMutableArray *touchHandlers; - BOOL dispatchEvents; -} - -+ (TouchDispatcher*)sharedDispatcher; - -/** When NO, dispatcher is muted. Default YES. */ -@property (readwrite, assign) BOOL dispatchEvents; - -/** Adds a delegate to the list of multi-touch event handlers, with priority 0 - and touch swallowing on. */ --(void) addEventHandler:(id) delegate; -/** Adds a delegate to the list of multi-touch event handlers. - If a handler swallows touches, it will be the exclusive owner of the touch(es) - it claims. Not swallowing allows other handlers to claim and receive updates on - the same touch. */ --(void) addEventHandler:(id) delegate - priority:(int) priority swallowTouches:(BOOL) swallowTouches; -/** Changes the priority of a previously added event handler. The lower the number, - the higher the priority */ --(void) setPriority:(int) priority forEventHandler:(id) delegate; -/** Removes a delegate from the list of multi-touch event handlers. */ --(void) removeEventHandler:(id) delegate; -/** Removes all multi-touch event handlers. */ --(void) removeAllEventHandlers; - -@end diff --git a/Support/cocos2d/TouchDispatcher.m b/Support/cocos2d/TouchDispatcher.m deleted file mode 100644 index 70fdbe9..0000000 --- a/Support/cocos2d/TouchDispatcher.m +++ /dev/null @@ -1,209 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2009 Valentin Milea - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - -#import "TouchDispatcher.h" -#import "TouchHandler.h" -#import "Director.h" - -@implementation TouchDispatcher - -@synthesize dispatchEvents; - -static TouchDispatcher *sharedDispatcher = nil; - -+(TouchDispatcher*) sharedDispatcher -{ - @synchronized(self) { - if (sharedDispatcher == nil) - [[self alloc] init]; // assignment not done here - } - return sharedDispatcher; -} - -+(id) allocWithZone:(NSZone *)zone -{ - @synchronized(self) { - if (sharedDispatcher == nil) { - sharedDispatcher = [super allocWithZone:zone]; - return sharedDispatcher; // assignment and return on first allocation - } - } - return nil; // on subsequent allocation attempts return nil -} - --(id) copyWithZone:(NSZone *)zone { return self; } --(id) retain { return self; } --(unsigned) retainCount { return UINT_MAX; } --(void) release { } --(id) autorelease { return self; } - --(id) init -{ - self = [super init]; - - dispatchEvents = YES; - touchHandlers = [[NSMutableArray alloc] initWithCapacity:8]; - - return self; -} - --(void) dealloc -{ - [touchHandlers release]; - [super dealloc]; -} - -// -// handlers management -// - -// private helper --(void) insertHandler:(TouchHandler *)handler -{ - NSUInteger i = 0; - for( TouchHandler *h in touchHandlers ) { - if( h.priority >= handler.priority ) - break; - i++; - } - [touchHandlers insertObject:handler atIndex:i]; -} - --(void) addEventHandler:(id) delegate -{ - [self addEventHandler:delegate priority:0 swallowTouches:YES]; -} - --(void) addEventHandler:(id) delegate priority:(int) priority swallowTouches:(BOOL) swallowTouches -{ - NSAssert( delegate != nil, @"TouchDispatcher.addEventHandler:priority:swallowTouches: -- Delegate must be non nil"); - - TouchHandler *handler = [TouchHandler handlerWithDelegate:delegate]; - handler.swallowsTouches = swallowTouches; - - handler.priority = priority; - [self insertHandler:handler]; -} - --(void) removeEventHandler:(id) delegate -{ - if( delegate == nil ) - return; - - TouchHandler *handler = nil; - for( handler in touchHandlers ) - if( handler.delegate == delegate ) break; - - if( handler != nil ) - [touchHandlers removeObject:handler]; -} - --(void) setPriority:(int) priority forEventHandler:(id) delegate -{ - NSAssert( delegate != nil, @"TouchDispatcher.setPriority:forEventHandler: -- Delegate must be non nil"); - - NSUInteger i = [touchHandlers indexOfObject:delegate]; - if( i == NSNotFound ) - [NSException raise:NSInvalidArgumentException format:@"Delegate not found"]; - - TouchHandler *handler = [touchHandlers objectAtIndex:i]; - - if( handler.priority != priority ) { - [handler retain]; - [touchHandlers removeObjectAtIndex:i]; - - handler.priority = priority; - [self insertHandler:handler]; - [handler release]; - } -} - - --(void) removeAllEventHandlers -{ - [touchHandlers removeAllObjects]; -} - -// -// multi touch proxies -// --(BOOL) ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event -{ - if( dispatchEvents ) { - - NSArray *handlers = [touchHandlers copy]; - - for( UITouch *touch in touches) { - for( TouchHandler *handler in handlers ) { - BOOL touchWasClaimed = [handler.delegate ccTouchBegan:touch withEvent:event]; - - if( touchWasClaimed ) { - [handler.claimedTouches addObject:touch]; - - if( handler.swallowsTouches ) - break; - } - } - } - [handlers release]; - } - - return kEventIgnored; -} - --(void) updateKnownTouches:(NSSet *)touches withEvent:(UIEvent *)event selector:(SEL)selector unclaim:(BOOL)doUnclaim -{ - NSArray *handlers = [touchHandlers copy]; - - for( UITouch *touch in touches) { - for( TouchHandler *handler in handlers ) { - if( [handler.claimedTouches containsObject:touch] ) { - - if( dispatchEvents && [handler.delegate respondsToSelector:selector] ) - [handler.delegate performSelector:selector withObject:touch withObject:event]; - - if( doUnclaim ) - [handler.claimedTouches removeObject:touch]; - - if( handler.swallowsTouches ) - break; - } - } - } - [handlers release]; -} - --(BOOL) ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event -{ - if (dispatchEvents) - [self updateKnownTouches:touches withEvent:event selector:@selector(ccTouchMoved:withEvent:) unclaim:NO]; - - return kEventIgnored; -} - --(BOOL) ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event -{ - [self updateKnownTouches:touches withEvent:event selector:@selector(ccTouchEnded:withEvent:) unclaim:YES]; - - return kEventIgnored; -} - --(BOOL) ccTouchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event -{ - [self updateKnownTouches:touches withEvent:event selector:@selector(ccTouchCancelled:withEvent:) unclaim:YES]; - - return kEventIgnored; -} - -@end diff --git a/Support/cocos2d/TouchHandler.h b/Support/cocos2d/TouchHandler.h deleted file mode 100644 index 2789797..0000000 --- a/Support/cocos2d/TouchHandler.h +++ /dev/null @@ -1,38 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2009 Valentin Milea - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - -#import -#import "TargetedTouchDelegate.h" - -/** - TouchHandler - XXX: add description -*/ -@interface TouchHandler : NSObject { -@private - id delegate; - int priority; - BOOL swallowsTouches; - NSMutableSet *claimedTouches; -} - -@property(nonatomic, readonly) id delegate; -@property(nonatomic, readwrite) int priority; // default 0 -@property(nonatomic, readwrite) BOOL swallowsTouches; // default NO -@property(nonatomic, readonly) NSMutableSet *claimedTouches; - -+ (id)handlerWithDelegate:(id) aDelegate; -- (id)initWithDelegate:(id) aDelegate; - -@end diff --git a/Support/cocos2d/TouchHandler.m b/Support/cocos2d/TouchHandler.m deleted file mode 100644 index 152cf62..0000000 --- a/Support/cocos2d/TouchHandler.m +++ /dev/null @@ -1,42 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2009 Valentin Milea - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - -#import "TouchHandler.h" - -@implementation TouchHandler - -@synthesize delegate, priority, swallowsTouches, claimedTouches; - -+ (id)handlerWithDelegate:(id) aDelegate -{ - return [[[self alloc] initWithDelegate:aDelegate] autorelease]; -} - -- (id)initWithDelegate:(id) aDelegate -{ - if ((self = [super init]) == nil) - return nil; - - delegate = aDelegate; - claimedTouches = [[NSMutableSet alloc] initWithCapacity:2]; - - return self; -} - -- (void)dealloc { - [claimedTouches release]; - [super dealloc]; -} - -@end diff --git a/Support/cocos2d/Transition.h b/Support/cocos2d/Transition.h deleted file mode 100644 index d3b8c4f..0000000 --- a/Support/cocos2d/Transition.h +++ /dev/null @@ -1,261 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2008,2009 Ricardo Quesada - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - -#import "Scene.h" -@class IntervalAction; -@class CocosNode; - -/** Orientation Type used by some transitions - */ -typedef enum { - /// An horizontal orientation where the Left is nearer - kOrientationLeftOver = 0, - /// An horizontal orientation where the Right is nearer - kOrientationRightOver = 1, - /// A vertical orientation where the Up is nearer - kOrientationUpOver = 0, - /// A vertical orientation where the Bottom is nearer - kOrientationDownOver = 1, -} tOrientation; - -/** Base class for Transition scenes - */ -@interface TransitionScene : Scene { - Scene * inScene; - Scene * outScene; - ccTime duration; -} -/** creates a base transition with duration and incoming scene */ -+(id) transitionWithDuration:(ccTime) t scene:(Scene*)s; -/** initializes a transition with duration and incoming scene */ --(id) initWithDuration:(ccTime) t scene:(Scene*)s; -/** called after the transition finishes */ --(void) finish; -/** used by some transitions to hide the outter scene */ --(void) hideOutShowIn; -@end - -/** A Transition that supports orientation like. - * Possible orientation: LeftOver, RightOver, UpOver, DownOver - */ -@interface OrientedTransitionScene : TransitionScene -{ - tOrientation orientation; -} -/** creates a base transition with duration and incoming scene */ -+(id) transitionWithDuration:(ccTime) t scene:(Scene*)s orientation:(tOrientation)o; -/** initializes a transition with duration and incoming scene */ --(id) initWithDuration:(ccTime) t scene:(Scene*)s orientation:(tOrientation)o; -@end - - -/** RotoZoom Transition. - Rotate and zoom out the outgoing scene, and then rotate and zoom in the incoming - */ -@interface RotoZoomTransition : TransitionScene -{} -@end - -/** JumpZoom Transition. - Zoom out and jump the outgoing scene, and then jump and zoom in the incoming -*/ -@interface JumpZoomTransition : TransitionScene -{} -@end - -/** MoveInL Transition. - Move in from to the left the incoming scene. -*/ -@interface MoveInLTransition : TransitionScene -{} -/** initializes the scenes */ --(void) initScenes; -/** returns the action that will be performed */ --(IntervalAction*) action; -@end - -/** MoveInR Transition. - Move in from to the right the incoming scene. - */ -@interface MoveInRTransition : MoveInLTransition -{} -@end - -/** MoveInT Transition. - Move in from to the top the incoming scene. - */ -@interface MoveInTTransition : MoveInLTransition -{} -@end - -/** MoveInB Transition. - Move in from to the bottom the incoming scene. - */ -@interface MoveInBTransition : MoveInLTransition -{} -@end - -/** SlideInL Transition. - Slide in the incoming scene from the left border. - */ -@interface SlideInLTransition : TransitionScene -{} -/** initializes the scenes */ --(void) initScenes; -/** returns the action that will be performed */ --(IntervalAction*) action; -@end - -/** SlideInR Transition. - Slide in the incoming scene from the right border. - */ -@interface SlideInRTransition : SlideInLTransition -{} -@end - -/** SlideInB Transition. - Slide in the incoming scene from the bottom border. - */ -@interface SlideInBTransition : SlideInLTransition -{} -@end - -/** SlideInT Transition. - Slide in the incoming scene from the top border. - */ -@interface SlideInTTransition : SlideInLTransition -{} -@end - -/** - Shrink the outgoing scene while grow the incoming scene - */ -@interface ShrinkGrowTransition : TransitionScene -{} -@end - -/** FlipX Transition. - Flips the screen horizontally. - The front face is the outgoing scene and the back face is the incoming scene. - */ -@interface FlipXTransition : OrientedTransitionScene -{} -@end - -/** FlipY Transition. - Flips the screen vertically. - The front face is the outgoing scene and the back face is the incoming scene. - */ -@interface FlipYTransition : OrientedTransitionScene -{} -@end - -/** FlipAngular Transition. - Flips the screen half horizontally and half vertically. - The front face is the outgoing scene and the back face is the incoming scene. - */ -@interface FlipAngularTransition : OrientedTransitionScene -{} -@end - -/** ZoomFlipX Transition. - Flips the screen horizontally doing a zoom out/in - The front face is the outgoing scene and the back face is the incoming scene. - */ -@interface ZoomFlipXTransition : OrientedTransitionScene -{ -} -@end - -/** ZoomFlipY Transition. - Flips the screen vertically doing a little zooming out/in - The front face is the outgoing scene and the back face is the incoming scene. - */ -@interface ZoomFlipYTransition : OrientedTransitionScene -{} -@end - -/** ZoomFlipAngular Transition. - Flips the screen half horizontally and half vertically doing a little zooming out/in. - The front face is the outgoing scene and the back face is the incoming scene. - */ -@interface ZoomFlipAngularTransition : OrientedTransitionScene -{} -@end - -/** Fade Transition. - Fade out the outgoing scene and then fade in the incoming scene.''' - */ -@interface FadeTransition : TransitionScene -{ - unsigned int RGBA; -} -/** creates the transition with a duration and with an RGB color - * Example: [FadeTransition transitionWithDuration:2 scene:s withColorRGB:0xff0000]; // red color - */ -+(id) transitionWithDuration:(ccTime)duration scene:(Scene*)scene withColorRGB:(unsigned int)rgb; -/** initializes the transition with a duration and with an RGB color */ --(id) initWithDuration:(ccTime)duration scene:(Scene*)scene withColorRGB:(unsigned int)rgb; -@end - -/** TurnOffTiles Transition. - Turn off the tiles of the outgoing scene in random order - */ -@interface TurnOffTilesTransition : TransitionScene -{} -@end - -/** SplitCols Transition. - The odd columns goes upwards while the even columns goes downwards. - */ -@interface SplitColsTransition : TransitionScene -{} --(IntervalAction*) action; -@end - -/** SplitRows Transition. - The odd rows goes to the left while the even rows goes to the right. - */ -@interface SplitRowsTransition : SplitColsTransition -{} -@end - -/** FadeTRTransition. - Fade the tiles of the outgoing scene from the left-bottom corner the to top-right corner. - */ -@interface FadeTRTransition : TransitionScene -{} --(IntervalAction*) actionWithSize:(ccGridSize) vector; -@end - -/** FadeBLTransition. - Fade the tiles of the outgoing scene from the top-right corner to the bottom-left corner. - */ -@interface FadeBLTransition : FadeTRTransition -{} -@end - -/** FadeUp Transition. - * Fade the tiles of the outgoing scene from the bottom to the top. - */ -@interface FadeUpTransition : FadeTRTransition -{} -@end - -/** FadeDown Transition. - * Fade the tiles of the outgoing scene from the top to the bottom. - */ -@interface FadeDownTransition : FadeTRTransition -{} -@end diff --git a/Support/cocos2d/Transition.m b/Support/cocos2d/Transition.m deleted file mode 100644 index 98ecd7a..0000000 --- a/Support/cocos2d/Transition.m +++ /dev/null @@ -1,892 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2008,2009 Ricardo Quesada - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - - -#import "Transition.h" -#import "CocosNode.h" -#import "Director.h" -#import "IntervalAction.h" -#import "InstantAction.h" -#import "CameraAction.h" -#import "Layer.h" -#import "Camera.h" -#import "TiledGridAction.h" -#import "EaseAction.h" -#import "Support/CGPointExtension.h" - -enum { - kSceneFade = 0xFADEFADE, -}; - -@interface TransitionScene (Private) --(void) addScenes; -@end - -@implementation TransitionScene -+(id) transitionWithDuration:(ccTime) t scene:(Scene*)s -{ - return [[[self alloc] initWithDuration:t scene:s] autorelease]; -} - --(id) initWithDuration:(ccTime) t scene:(Scene*)s -{ - NSAssert( s != nil, @"Argument scene must be non-nil"); - - if( (self=[super init]) ) { - - duration = t; - - // Don't retain them, it will be reatined when added - inScene = s; - outScene = [[Director sharedDirector] runningScene]; - - if( inScene == outScene ) { - NSException* myException = [NSException - exceptionWithName:@"TransitionWithInvalidScene" - reason:@"Incoming scene must be different from the outgoing scene" - userInfo:nil]; - @throw myException; - } - - // disable events while transitions - [[Director sharedDirector] setEventsEnabled: NO]; - - [self addScenes]; - } - return self; -} - --(void) addScenes -{ - // add both scenes - [self addChild: inScene z:1]; - [self addChild: outScene z:0]; -} - --(void) setNewScene: (ccTime) dt { - - [self unschedule:_cmd]; - - [[Director sharedDirector] replaceScene: inScene]; - - // enable events while transitions - [[Director sharedDirector] setEventsEnabled: YES]; - - // issue #267 - [outScene setVisible:YES]; - -} - --(void) finish -{ - /* clean up */ - [inScene setVisible:YES]; - [inScene setPosition:ccp(0,0)]; - [inScene setScale:1.0f]; - [inScene setRotation:0.0f]; - [inScene.camera restore]; - - [outScene setVisible:NO]; - [outScene setPosition:ccp(0,0)]; - [outScene setScale:1.0f]; - [outScene setRotation:0.0f]; - [outScene.camera restore]; - -// [inScene stopAllActions]; -// [outScene stopAllActions]; - - [self schedule:@selector(setNewScene:) interval:0]; -} - --(void) hideOutShowIn -{ - [inScene setVisible:YES]; - [outScene setVisible:NO]; -} - -// custom onEnter --(void) onEnter -{ - // don't call [super onEnter] - // outScene should not receive the onEnter callback - // inScene should receive it now - -// [super onEnter]; - [inScene onEnter]; - [self activateTimers]; - isRunning = YES; -} - -// custom onExit --(void) onExit -{ - // don't call [super onExit] - // inScene should not receive the onExit callback - // outScene should receive ti now -// [super onExit]; - [outScene onExit]; - [inScene onTransitionDidFinish]; - -// [self removeChild:inScene cleanup:NO]; -// [self removeChild:outScene cleanup:NO]; - - [self deactivateTimers]; - isRunning = NO; -} - --(void) onTransitionDidFinish -{ - // Don't propagate the event. consume it -} - --(void) dealloc -{ - [super dealloc]; -} -@end - -// -// Oriented Transition -// -@implementation OrientedTransitionScene -+(id) transitionWithDuration:(ccTime) t scene:(Scene*)s orientation:(tOrientation)o -{ - return [[[self alloc] initWithDuration:t scene:s orientation:o] autorelease]; -} - --(id) initWithDuration:(ccTime) t scene:(Scene*)s orientation:(tOrientation)o -{ - if( !(self=[super initWithDuration:t scene:s]) ) - return nil; - orientation = o; - return self; -} -@end - - -// -// RotoZoom -// -@implementation RotoZoomTransition --(void) onEnter -{ - [super onEnter]; - - [inScene setScale:0.001f]; - [outScene setScale:1.0f]; - - [inScene setAnchorPoint:ccp(0.5f, 0.5f)]; - [outScene setAnchorPoint:ccp(0.5f, 0.5f)]; - - IntervalAction *rotozoom = [Sequence actions: [Spawn actions: - [ScaleBy actionWithDuration:duration/2 scale:0.001f], - [RotateBy actionWithDuration:duration/2 angle:360 *2], - nil], - [DelayTime actionWithDuration:duration/2], - nil]; - - - [outScene runAction: rotozoom]; - [inScene runAction: [Sequence actions: - [rotozoom reverse], - [CallFunc actionWithTarget:self selector:@selector(finish)], - nil]]; -} -@end - -// -// JumpZoom -// -@implementation JumpZoomTransition --(void) onEnter -{ - [super onEnter]; - CGSize s = [[Director sharedDirector] winSize]; - - [inScene setScale:0.5f]; - [inScene setPosition:ccp( s.width,0 )]; - - [inScene setAnchorPoint:ccp(0.5f, 0.5f)]; - [outScene setAnchorPoint:ccp(0.5f, 0.5f)]; - - IntervalAction *jump = [JumpBy actionWithDuration:duration/4 position:ccp(-s.width,0) height:s.width/4 jumps:2]; - IntervalAction *scaleIn = [ScaleTo actionWithDuration:duration/4 scale:1.0f]; - IntervalAction *scaleOut = [ScaleTo actionWithDuration:duration/4 scale:0.5f]; - - IntervalAction *jumpZoomOut = [Sequence actions: scaleOut, jump, nil]; - IntervalAction *jumpZoomIn = [Sequence actions: jump, scaleIn, nil]; - - IntervalAction *delay = [DelayTime actionWithDuration:duration/2]; - - [outScene runAction: jumpZoomOut]; - [inScene runAction: [Sequence actions: delay, - jumpZoomIn, - [CallFunc actionWithTarget:self selector:@selector(finish)], - nil] ]; -} -@end - -// -// MoveInL -// -@implementation MoveInLTransition --(void) onEnter -{ - [super onEnter]; - - [self initScenes]; - - IntervalAction *a = [self action]; - - [inScene runAction: [Sequence actions: - [EaseOut actionWithAction:a rate:2.0f], - [CallFunc actionWithTarget:self selector:@selector(finish)], - nil] ]; - -} --(IntervalAction*) action -{ - return [MoveTo actionWithDuration:duration position:ccp(0,0)]; -} - --(void) initScenes -{ - CGSize s = [[Director sharedDirector] winSize]; - [inScene setPosition: ccp( -s.width,0) ]; -} -@end - -// -// MoveInR -// -@implementation MoveInRTransition --(void) initScenes -{ - CGSize s = [[Director sharedDirector] winSize]; - [inScene setPosition: ccp( s.width,0) ]; -} -@end - -// -// MoveInT -// -@implementation MoveInTTransition --(void) initScenes -{ - CGSize s = [[Director sharedDirector] winSize]; - [inScene setPosition: ccp( 0, s.height) ]; -} -@end - -// -// MoveInB -// -@implementation MoveInBTransition --(void) initScenes -{ - CGSize s = [[Director sharedDirector] winSize]; - [inScene setPosition: ccp( 0, -s.height) ]; -} -@end - -// -// SlideInL -// -@implementation SlideInLTransition --(void) onEnter -{ - [super onEnter]; - - [self initScenes]; - - IntervalAction *in = [self action]; - IntervalAction *out = [in copy]; - - [inScene runAction: [EaseOut actionWithAction:in rate:2.0f]]; - [outScene runAction: [Sequence actions: - [EaseOut actionWithAction:out rate:2.0f], - [CallFunc actionWithTarget:self selector:@selector(finish)], - nil] ]; - - [out release]; -} - --(IntervalAction*) action -{ - CGSize s = [[Director sharedDirector] winSize]; - return [MoveBy actionWithDuration:duration position:ccp(s.width,0)]; -} - --(void) initScenes -{ - CGSize s = [[Director sharedDirector] winSize]; - [inScene setPosition: ccp( -s.width,0) ]; -} -@end - -// -// SlideInR -// -@implementation SlideInRTransition --(void) initScenes -{ - CGSize s = [[Director sharedDirector] winSize]; - [inScene setPosition: ccp( s.width,0) ]; -} - --(IntervalAction*) action -{ - CGSize s = [[Director sharedDirector] winSize]; - return [MoveBy actionWithDuration:duration position:ccp(-s.width,0)]; -} - -@end - -// -// SlideInT -// -@implementation SlideInTTransition --(void) initScenes -{ - CGSize s = [[Director sharedDirector] winSize]; - [inScene setPosition: ccp(0,s.height) ]; -} - --(IntervalAction*) action -{ - CGSize s = [[Director sharedDirector] winSize]; - return [MoveBy actionWithDuration:duration position:ccp(0,-s.height)]; -} - -@end - -// -// SlideInB -// -@implementation SlideInBTransition --(void) initScenes -{ - CGSize s = [[Director sharedDirector] winSize]; - [inScene setPosition: ccp(0,-s.height) ]; -} - --(IntervalAction*) action -{ - CGSize s = [[Director sharedDirector] winSize]; - return [MoveBy actionWithDuration:duration position:ccp(0,s.height)]; -} -@end - -// -// ShrinkGrow Transition -// -@implementation ShrinkGrowTransition --(void) onEnter -{ - [super onEnter]; - - [inScene setScale:0.001f]; - [outScene setScale:1.0f]; - - [inScene setAnchorPoint:ccp(2/3.0f,0.5f)]; - [outScene setAnchorPoint:ccp(1/3.0f,0.5f)]; - - IntervalAction *scaleOut = [ScaleTo actionWithDuration:duration scale:0.01f]; - IntervalAction *scaleIn = [ScaleTo actionWithDuration:duration scale:1.0f]; - - [inScene runAction: [EaseOut actionWithAction:scaleIn rate:2.0f]]; - [outScene runAction: [Sequence actions: - [EaseOut actionWithAction:scaleOut rate:2.0f], - [CallFunc actionWithTarget:self selector:@selector(finish)], - nil] ]; -} -@end - -// -// FlipX Transition -// -@implementation FlipXTransition --(void) onEnter -{ - [super onEnter]; - - IntervalAction *inA, *outA; - [inScene setVisible: NO]; - - float inDeltaZ, inAngleZ; - float outDeltaZ, outAngleZ; - - if( orientation == kOrientationRightOver ) { - inDeltaZ = 90; - inAngleZ = 270; - outDeltaZ = 90; - outAngleZ = 0; - } else { - inDeltaZ = -90; - inAngleZ = 90; - outDeltaZ = -90; - outAngleZ = 0; - } - inA = [Sequence actions: - [DelayTime actionWithDuration:duration/2], - [Show action], - [OrbitCamera actionWithDuration: duration/2 radius: 1 deltaRadius:0 angleZ:inAngleZ deltaAngleZ:inDeltaZ angleX:0 deltaAngleX:0], - [CallFunc actionWithTarget:self selector:@selector(finish)], - nil ]; - outA = [Sequence actions: - [OrbitCamera actionWithDuration: duration/2 radius: 1 deltaRadius:0 angleZ:outAngleZ deltaAngleZ:outDeltaZ angleX:0 deltaAngleX:0], - [Hide action], - [DelayTime actionWithDuration:duration/2], - nil ]; - - [inScene runAction: inA]; - [outScene runAction: outA]; - -} -@end - -// -// FlipY Transition -// -@implementation FlipYTransition --(void) onEnter -{ - [super onEnter]; - - IntervalAction *inA, *outA; - [inScene setVisible: NO]; - - float inDeltaZ, inAngleZ; - float outDeltaZ, outAngleZ; - - if( orientation == kOrientationUpOver ) { - inDeltaZ = 90; - inAngleZ = 270; - outDeltaZ = 90; - outAngleZ = 0; - } else { - inDeltaZ = -90; - inAngleZ = 90; - outDeltaZ = -90; - outAngleZ = 0; - } - inA = [Sequence actions: - [DelayTime actionWithDuration:duration/2], - [Show action], - [OrbitCamera actionWithDuration: duration/2 radius: 1 deltaRadius:0 angleZ:inAngleZ deltaAngleZ:inDeltaZ angleX:90 deltaAngleX:0], - [CallFunc actionWithTarget:self selector:@selector(finish)], - nil ]; - outA = [Sequence actions: - [OrbitCamera actionWithDuration: duration/2 radius: 1 deltaRadius:0 angleZ:outAngleZ deltaAngleZ:outDeltaZ angleX:90 deltaAngleX:0], - [Hide action], - [DelayTime actionWithDuration:duration/2], - nil ]; - - [inScene runAction: inA]; - [outScene runAction: outA]; - -} -@end - -// -// FlipAngular Transition -// -@implementation FlipAngularTransition --(void) onEnter -{ - [super onEnter]; - - IntervalAction *inA, *outA; - [inScene setVisible: NO]; - - float inDeltaZ, inAngleZ; - float outDeltaZ, outAngleZ; - - if( orientation == kOrientationRightOver ) { - inDeltaZ = 90; - inAngleZ = 270; - outDeltaZ = 90; - outAngleZ = 0; - } else { - inDeltaZ = -90; - inAngleZ = 90; - outDeltaZ = -90; - outAngleZ = 0; - } - inA = [Sequence actions: - [DelayTime actionWithDuration:duration/2], - [Show action], - [OrbitCamera actionWithDuration: duration/2 radius: 1 deltaRadius:0 angleZ:inAngleZ deltaAngleZ:inDeltaZ angleX:-45 deltaAngleX:0], - [CallFunc actionWithTarget:self selector:@selector(finish)], - nil ]; - outA = [Sequence actions: - [OrbitCamera actionWithDuration: duration/2 radius: 1 deltaRadius:0 angleZ:outAngleZ deltaAngleZ:outDeltaZ angleX:45 deltaAngleX:0], - [Hide action], - [DelayTime actionWithDuration:duration/2], - nil ]; - - [inScene runAction: inA]; - [outScene runAction: outA]; -} -@end - -// -// ZoomFlipX Transition -// -@implementation ZoomFlipXTransition --(void) onEnter -{ - [super onEnter]; - - IntervalAction *inA, *outA; - [inScene setVisible: NO]; - - float inDeltaZ, inAngleZ; - float outDeltaZ, outAngleZ; - - if( orientation == kOrientationRightOver ) { - inDeltaZ = 90; - inAngleZ = 270; - outDeltaZ = 90; - outAngleZ = 0; - } else { - inDeltaZ = -90; - inAngleZ = 90; - outDeltaZ = -90; - outAngleZ = 0; - } - inA = [Sequence actions: - [DelayTime actionWithDuration:duration/2], - [Spawn actions: - [OrbitCamera actionWithDuration: duration/2 radius: 1 deltaRadius:0 angleZ:inAngleZ deltaAngleZ:inDeltaZ angleX:0 deltaAngleX:0], - [ScaleTo actionWithDuration:duration/2 scale:1], - [Show action], - nil], - [CallFunc actionWithTarget:self selector:@selector(finish)], - nil ]; - outA = [Sequence actions: - [Spawn actions: - [OrbitCamera actionWithDuration: duration/2 radius: 1 deltaRadius:0 angleZ:outAngleZ deltaAngleZ:outDeltaZ angleX:0 deltaAngleX:0], - [ScaleTo actionWithDuration:duration/2 scale:0.5f], - nil], - [Hide action], - [DelayTime actionWithDuration:duration/2], - nil ]; - - inScene.scale = 0.5f; - [inScene runAction: inA]; - [outScene runAction: outA]; -} -@end - -// -// ZoomFlipY Transition -// -@implementation ZoomFlipYTransition --(void) onEnter -{ - [super onEnter]; - - IntervalAction *inA, *outA; - [inScene setVisible: NO]; - - float inDeltaZ, inAngleZ; - float outDeltaZ, outAngleZ; - - if( orientation == kOrientationUpOver ) { - inDeltaZ = 90; - inAngleZ = 270; - outDeltaZ = 90; - outAngleZ = 0; - } else { - inDeltaZ = -90; - inAngleZ = 90; - outDeltaZ = -90; - outAngleZ = 0; - } - - inA = [Sequence actions: - [DelayTime actionWithDuration:duration/2], - [Spawn actions: - [OrbitCamera actionWithDuration: duration/2 radius: 1 deltaRadius:0 angleZ:inAngleZ deltaAngleZ:inDeltaZ angleX:90 deltaAngleX:0], - [ScaleTo actionWithDuration:duration/2 scale:1], - [Show action], - nil], - [CallFunc actionWithTarget:self selector:@selector(finish)], - nil ]; - outA = [Sequence actions: - [Spawn actions: - [OrbitCamera actionWithDuration: duration/2 radius: 1 deltaRadius:0 angleZ:outAngleZ deltaAngleZ:outDeltaZ angleX:90 deltaAngleX:0], - [ScaleTo actionWithDuration:duration/2 scale:0.5f], - nil], - [Hide action], - [DelayTime actionWithDuration:duration/2], - nil ]; - - inScene.scale = 0.5f; - [inScene runAction: inA]; - [outScene runAction: outA]; -} -@end - -// -// ZoomFlipAngular Transition -// -@implementation ZoomFlipAngularTransition --(void) onEnter -{ - [super onEnter]; - - IntervalAction *inA, *outA; - [inScene setVisible: NO]; - - float inDeltaZ, inAngleZ; - float outDeltaZ, outAngleZ; - - if( orientation == kOrientationRightOver ) { - inDeltaZ = 90; - inAngleZ = 270; - outDeltaZ = 90; - outAngleZ = 0; - } else { - inDeltaZ = -90; - inAngleZ = 90; - outDeltaZ = -90; - outAngleZ = 0; - } - - inA = [Sequence actions: - [DelayTime actionWithDuration:duration/2], - [Spawn actions: - [OrbitCamera actionWithDuration: duration/2 radius: 1 deltaRadius:0 angleZ:inAngleZ deltaAngleZ:inDeltaZ angleX:-45 deltaAngleX:0], - [ScaleTo actionWithDuration:duration/2 scale:1], - [Show action], - nil], - [Show action], - [CallFunc actionWithTarget:self selector:@selector(finish)], - nil ]; - outA = [Sequence actions: - [Spawn actions: - [OrbitCamera actionWithDuration: duration/2 radius: 1 deltaRadius:0 angleZ:outAngleZ deltaAngleZ:outDeltaZ angleX:45 deltaAngleX:0], - [ScaleTo actionWithDuration:duration/2 scale:0.5f], - nil], - [Hide action], - [DelayTime actionWithDuration:duration/2], - nil ]; - - inScene.scale = 0.5f; - [inScene runAction: inA]; - [outScene runAction: outA]; -} -@end - - -// -// Fade Transition -// -@implementation FadeTransition -+(id) transitionWithDuration:(ccTime)d scene:(Scene*)s withColorRGB:(unsigned int)rgb -{ - return [[[self alloc] initWithDuration:d scene:s withColorRGB:rgb] autorelease]; -} - --(id) initWithDuration:(ccTime)d scene:(Scene*)s withColorRGB:(unsigned int)rgb -{ - self = [super initWithDuration:d scene:s]; - if( self ) - RGBA = rgb << 8; - - return self; -} - --(id) initWithDuration:(ccTime)d scene:(Scene*)s -{ - return [self initWithDuration:d scene:s withColorRGB:0x00000000]; -} - --(void) onEnter -{ - [super onEnter]; - - ColorLayer *l = [ColorLayer layerWithColor:RGBA]; - [inScene setVisible: NO]; - - [self addChild: l z:2 tag:kSceneFade]; - - - CocosNode *f = [self getChildByTag:kSceneFade]; - - IntervalAction *a = [Sequence actions: - [FadeIn actionWithDuration:duration/2], - [CallFunc actionWithTarget:self selector:@selector(hideOutShowIn)], - [FadeOut actionWithDuration:duration/2], - [CallFunc actionWithTarget:self selector:@selector(finish)], - nil ]; - [f runAction: a]; -} - --(void) onExit -{ - [super onExit]; - [self removeChildByTag:kSceneFade cleanup:NO]; -} -@end - -// -// TurnOffTilesTransition -// -@implementation TurnOffTilesTransition - -// override addScenes, and change the order --(void) addScenes -{ - // add both scenes - [self addChild: inScene z:0]; - [self addChild: outScene z:1]; -} - --(void) onEnter -{ - [super onEnter]; - CGSize s = [[Director sharedDirector] winSize]; - float aspect = s.width / s.height; - int x = 12 * aspect; - int y = 12; - - id toff = [TurnOffTiles actionWithSize: ccg(x,y) duration:duration]; - [outScene runAction: [Sequence actions: toff, - [CallFunc actionWithTarget:self selector:@selector(finish)], - [StopGrid action], - nil] - ]; - -} -@end - -#pragma mark Split Transitions - -// -// SplitCols Transition -// -@implementation SplitColsTransition - --(void) onEnter -{ - [super onEnter]; - - inScene.visible = NO; - - id split = [self action]; - id seq = [Sequence actions: - split, - [CallFunc actionWithTarget:self selector:@selector(hideOutShowIn)], - [split reverse], - nil - ]; - [self runAction: [Sequence actions: - [EaseInOut actionWithAction:seq rate:3.0f], - [CallFunc actionWithTarget:self selector:@selector(finish)], - [StopGrid action], - nil] - ]; -} - --(IntervalAction*) action -{ - return [SplitCols actionWithCols:3 duration:duration/2.0f]; -} -@end - -// -// SplitRows Transition -// -@implementation SplitRowsTransition --(IntervalAction*) action -{ - return [SplitRows actionWithRows:3 duration:duration/2.0f]; -} -@end - - -#pragma mark Fade Grid Transitions - -// -// FadeTR Transition -// -@implementation FadeTRTransition -// override addScenes, and change the order --(void) addScenes -{ - // add both scenes - [self addChild: inScene z:0]; - [self addChild: outScene z:1]; -} - --(void) onEnter -{ - [super onEnter]; - - CGSize s = [[Director sharedDirector] winSize]; - float aspect = s.width / s.height; - int x = 12 * aspect; - int y = 12; - - id action = [self actionWithSize:ccg(x,y)]; - - [outScene runAction: [Sequence actions: - action, - [CallFunc actionWithTarget:self selector:@selector(finish)], - [StopGrid action], - nil] - ]; -} - --(IntervalAction*) actionWithSize: (ccGridSize) v -{ - return [FadeOutTRTiles actionWithSize:v duration:duration]; -} -@end - -// -// FadeBL Transition -// -@implementation FadeBLTransition --(IntervalAction*) actionWithSize: (ccGridSize) v -{ - return [FadeOutBLTiles actionWithSize:v duration:duration]; -} -@end - -// -// FadeUp Transition -// -@implementation FadeUpTransition --(IntervalAction*) actionWithSize: (ccGridSize) v -{ - return [FadeOutUpTiles actionWithSize:v duration:duration]; -} -@end - -// -// FadeDown Transition -// -@implementation FadeDownTransition --(IntervalAction*) actionWithSize: (ccGridSize) v -{ - return [FadeOutDownTiles actionWithSize:v duration:duration]; -} -@end - - - diff --git a/Support/cocos2d/ccExceptions.h b/Support/cocos2d/ccExceptions.h deleted file mode 100644 index 9f3ab58..0000000 --- a/Support/cocos2d/ccExceptions.h +++ /dev/null @@ -1,23 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2008,2009 Ricardo Quesada - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - -// cocos2d Exceptions -// based on OC3D OC3DConstants.h file -// - -static NSString *kccException_OpenGLViewAlreadyAttached = @"kccException_OpenGLViewAlreadyAttached"; -static NSString *kccException_OpenGLViewNotAttached = @"kccException_OpenGLViewNotAttached"; -static NSString *kccException_OpenGLViewCantDetach = @"kccException_OpenGLViewCantDetach"; -static NSString *kccException_OpenGLViewCantAttach = @"kccException_OpenGLViewCantAttach"; -static NSString *kccException_OpenGLViewCantInit = @"kccException_OpenGLViewCantInit"; diff --git a/Support/cocos2d/ccMacros.h b/Support/cocos2d/ccMacros.h deleted file mode 100644 index 3fc0028..0000000 --- a/Support/cocos2d/ccMacros.h +++ /dev/null @@ -1,55 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2008,2009 Ricardo Quesada - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - -#import - -/** - @file - cocos2d helper macros - */ - -#ifdef DEBUG -//#define CCLOG(s, …) NSLog((@”%s %s:%d ” s), __func__, basename(__FILE__), __LINE__, ## __VA_ARGS__); -#define CCLOG(...) NSLog(__VA_ARGS__) -#else -#define CCLOG(...) do {} while (0) -#endif - -//simple macro that swaps 2 variables -#define CC_SWAP( x, y ) \ -({ __typeof__(x) temp = (x); \ - x = y; y = temp; \ -}) - - - - -/// returns a random float between -1 and 1 -#define CCRANDOM_MINUS1_1() ((random() / (float)0x3fffffff )-1.0f) - -/// returns a random float between 0 and 1 -#define CCRANDOM_0_1() ((random() / (float)0x7fffffff )) - -/// converts degrees to radians -#define CC_DEGREES_TO_RADIANS(__ANGLE__) ((__ANGLE__) / 180.0f * (float)M_PI) - -/// converts radians to degrees -#define CC_RADIANS_TO_DEGREES(__ANGLE__) ((__ANGLE__) / (float)M_PI * 180.0f) - -/// default gl blend src function -//#define CC_BLEND_SRC GL_SRC_ALPHA -#define CC_BLEND_SRC GL_ONE -/// default gl blend dst function -#define CC_BLEND_DST GL_ONE_MINUS_SRC_ALPHA - diff --git a/Support/cocos2d/ccTypes.h b/Support/cocos2d/ccTypes.h deleted file mode 100644 index 0becdb5..0000000 --- a/Support/cocos2d/ccTypes.h +++ /dev/null @@ -1,173 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2008,2009 Ricardo Quesada - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - -/** - @file - cocos2d (cc) types -*/ - -#import // CGPoint - -/** RGB color composed of bytes 3 bytes -@since v0.8 - */ -typedef struct _ccColor3B -{ - unsigned char r; - unsigned char g; - unsigned char b; -} ccColor3B; - -/** RGBA color composed of 4 bytes -@since v0.8 -*/ -typedef struct _ccColor4B -{ - unsigned char r; - unsigned char g; - unsigned char b; - unsigned char a; -} ccColor4B; - -/** RGBA color composed of 4 floats -@since v0.8 -*/ -typedef struct _ccColor4F { - float r; - float g; - float b; - float a; -} ccColor4F; - -/** A vertex composed of 2 floats: x, y - @since v0.8 - */ -#define ccVertex2F CGPoint - -/** A vertex composed of 2 floats: x, y - @since v0.8 - */ -typedef struct _ccVertex3F -{ - float x; - float y; - float z; -} ccVertex3F; - -/** A texcoord composed of 2 floats: u, y - @since v0.8 - */ -typedef struct _ccTex2F { - float u; - float v; -} ccTex2F; - - -//! Point Sprite component -typedef struct _ccPointSprite -{ - ccVertex2F pos; // 8 bytes - ccColor4F colors; // 16 bytes - float size; // 4 bytes -} ccPointSprite; - -//! A 2D Quad. 4 * 2 floats -typedef struct _ccQuad2 { - ccVertex2F tl; - ccVertex2F tr; - ccVertex2F bl; - ccVertex2F br; -} ccQuad2; - - -//! A 3D Quad. 4 * 3 floats -typedef struct _ccQuad3 { - ccVertex3F bl; - ccVertex3F br; - ccVertex3F tl; - ccVertex3F tr; -} ccQuad3; - -//! A 2D grid size -typedef struct _ccGridSize -{ - int x; - int y; -} ccGridSize; - -//! helper function to create a ccGridSize -static inline ccGridSize -ccg(const int x, const int y) -{ - ccGridSize v = {x, y}; - return v; -} - -//! a Point with a vertex point, a tex coord point and a color 4F -typedef struct _ccV2F_C4F_T2F -{ - //! vertices (2F) - ccVertex2F vertices; - //! colors (4F) - ccColor4F colors; - //! tex coords (2F) - ccTex2F texCoords; -} ccV2F_C4F_T2F; - -//! a Point with a vertex point, a tex coord point and a color 4B -typedef struct _ccV3F_C4B_T2F -{ - //! vertices (3F) - ccVertex3F vertices; // 12 bytes -// char __padding__[4]; - - //! colors (4B) - ccColor4B colors; // 4 bytes -// char __padding2__[4]; - - // tex coords (2F) - ccTex2F texCoords; // 8 byts -} ccV3F_C4B_T2F; - -//! 4 ccVertex3FTex2FColor4B -typedef struct _ccV3F_C4B_T2F_Quad -{ - //! top left - ccV3F_C4B_T2F tl; - //! bottom left - ccV3F_C4B_T2F bl; - //! top right - ccV3F_C4B_T2F tr; - //! bottom right - ccV3F_C4B_T2F br; -} ccV3F_C4B_T2F_Quad; - -//! 4 ccVertex2FTex2FColor4F Quad -typedef struct _ccV2F_C4F_T2F_Quad -{ - //! bottom left - ccV2F_C4F_T2F bl; - //! bottom right - ccV2F_C4F_T2F br; - //! top left - ccV2F_C4F_T2F tl; - //! top right - ccV2F_C4F_T2F tr; -} ccV2F_C4F_T2F_Quad; - - -//! delta time type -//! if you want more resolution redefine it as a double -typedef float ccTime; -//typedef double ccTime; diff --git a/Support/cocos2d/cocos2d.h b/Support/cocos2d/cocos2d.h deleted file mode 100644 index 2902e04..0000000 --- a/Support/cocos2d/cocos2d.h +++ /dev/null @@ -1,92 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2008,2009 Ricardo Quesada - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - - -/** @mainpage cocos2d for iPhone API reference - * - * @image html cocos2d-Icon.png - * - * @section intro Introduction - * cocos2d API reference - * - *
- * - * @todo A native english speaker should check the grammar. We need your help! - * - */ - -// 0x00 HI ME LO -// 00 00 08 00 -#define COCOS2D_VERSION 0x00000800 - -// -// all cocos2d include files -// -#import "Action.h" -#import "Camera.h" -#import "CameraAction.h" -#import "CocosNode.h" -#import "Director.h" -#import "TouchDispatcher.h" -#import "InstantAction.h" -#import "IntervalAction.h" -#import "EaseAction.h" -#import "Label.h" -#import "Layer.h" -#import "Menu.h" -#import "MenuItem.h" -#import "ParticleSystem.h" -#import "PointParticleSystem.h" -#import "QuadParticleSystem.h" -#import "ParticleExamples.h" -#import "Primitives.h" -#import "Scene.h" -#import "Scheduler.h" -#import "Sprite.h" -#import "TextureMgr.h" -#import "TextureNode.h" -#import "Transition.h" -#import "TextureAtlas.h" -#import "LabelAtlas.h" -#import "TileMapAtlas.h" -#import "AtlasNode.h" -#import "EaseAction.h" -#import "TiledGridAction.h" -#import "Grabber.h" -#import "Grid.h" -#import "Grid3DAction.h" -#import "GridAction.h" -#import "AtlasSprite.h" -#import "AtlasSpriteManager.h" -#import "BitmapFontAtlas.h" -#import "ParallaxNode.h" - -// -// cocos2d macros -// -#import "ccTypes.h" -#import "ccMacros.h" - -// -// cocos2d helper files -// -#import "Support/OpenGL_Internal.h" -#import "Support/Texture2D.h" -#import "Support/EAGLView.h" -#import "Support/FileUtils.h" -#import "Support/CGPointExtension.h" - - -// free functions -NSString * cocos2dVersion(void); diff --git a/Support/cocos2d/cocos2d.m b/Support/cocos2d/cocos2d.m deleted file mode 100644 index 2a5e247..0000000 --- a/Support/cocos2d/cocos2d.m +++ /dev/null @@ -1,22 +0,0 @@ -/* cocos2d for iPhone - * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2008,2009 Ricardo Quesada - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. - * - */ - -#import - -static NSString *version = @"cocos2d v0.8.0"; - -NSString *cocos2dVersion() -{ - return version; -} diff --git a/tweejump.xcodeproj/haqu.mode2v3 b/tweejump.xcodeproj/haqu.mode2v3 deleted file mode 100644 index 56d2619..0000000 --- a/tweejump.xcodeproj/haqu.mode2v3 +++ /dev/null @@ -1,1506 +0,0 @@ - - - - - ActivePerspectiveName - Project - AllowedModules - - - BundleLoadPath - - MaxInstances - n - Module - PBXSmartGroupTreeModule - Name - Groups and Files Outline View - - - BundleLoadPath - - MaxInstances - n - Module - PBXNavigatorGroup - Name - Editor - - - BundleLoadPath - - MaxInstances - n - Module - XCTaskListModule - Name - Task List - - - BundleLoadPath - - MaxInstances - n - Module - XCDetailModule - Name - File and Smart Group Detail Viewer - - - BundleLoadPath - - MaxInstances - 1 - Module - PBXBuildResultsModule - Name - Detailed Build Results Viewer - - - BundleLoadPath - - MaxInstances - 1 - Module - PBXProjectFindModule - Name - Project Batch Find Tool - - - BundleLoadPath - - MaxInstances - n - Module - XCProjectFormatConflictsModule - Name - Project Format Conflicts List - - - BundleLoadPath - - MaxInstances - n - Module - PBXBookmarksModule - Name - Bookmarks Tool - - - BundleLoadPath - - MaxInstances - n - Module - PBXClassBrowserModule - Name - Class Browser - - - BundleLoadPath - - MaxInstances - n - Module - PBXCVSModule - Name - Source Code Control Tool - - - BundleLoadPath - - MaxInstances - n - Module - PBXDebugBreakpointsModule - Name - Debug Breakpoints Tool - - - BundleLoadPath - - MaxInstances - n - Module - XCDockableInspector - Name - Inspector - - - BundleLoadPath - - MaxInstances - n - Module - PBXOpenQuicklyModule - Name - Open Quickly Tool - - - BundleLoadPath - - MaxInstances - 1 - Module - PBXDebugSessionModule - Name - Debugger - - - BundleLoadPath - - MaxInstances - 1 - Module - PBXDebugCLIModule - Name - Debug Console - - - BundleLoadPath - - MaxInstances - n - Module - XCSnapshotModule - Name - Snapshots Tool - - - BundlePath - /Developer/Library/PrivateFrameworks/DevToolsInterface.framework/Resources - Description - CondensedDescriptionKey - DockingSystemVisible - - Extension - mode2v3 - FavBarConfig - - PBXProjectModuleGUID - 4D0631F30FC305A5008ECEEE - XCBarModuleItemNames - - XCBarModuleItems - - - FirstTimeWindowDisplayed - - Identifier - com.apple.perspectives.project.mode2v3 - MajorVersion - 34 - MinorVersion - 0 - Name - Condensed - Notifications - - OpenEditors - - - Content - - PBXProjectModuleGUID - 4D5555240FDE6172004554D7 - PBXProjectModuleLabel - Game.m - PBXSplitModuleInNavigatorKey - - Split0 - - PBXProjectModuleGUID - 4D5555250FDE6172004554D7 - PBXProjectModuleLabel - Game.m - _historyCapacity - 0 - bookmark - 4D5555260FDE6172004554D7 - history - - 4D55551C0FDE5F6D004554D7 - - - SplitCount - 1 - - StatusBarVisibility - - - Geometry - - Frame - {{0, 20}, {869, 751}} - PBXModuleWindowStatusBarHidden2 - - RubberWindowFrame - 678 283 869 792 0 0 1920 1178 - - - - PerspectiveWidths - - -1 - - Perspectives - - - ChosenToolbarItems - - active-combo-popup - build-and-go - com.apple.ide.PBXToolbarStopButton - get-info - - ControllerClassBaseName - - IconName - WindowOfProject - Identifier - perspective.project - IsVertical - - Layout - - - Proportion - 350pt - Tabs - - - BecomeActive - - ContentConfiguration - - PBXBottomSmartGroupGIDs - - PBXProjectModuleGUID - 1C9437FD063B20B00039CFAC - PBXProjectModuleLabel - Files - PBXProjectStructureProvided - yes - PBXSmartGroupTreeModuleColumnData - - PBXSmartGroupTreeModuleColumnWidthsKey - - 227 - 20 - 43 - 43 - - PBXSmartGroupTreeModuleColumnsKey_v4 - - MainColumn - FileBuiltColumn - ErrorsColumn - WarningsColumn - - - PBXSmartGroupTreeModuleOutlineStateKey_v7 - - PBXSmartGroupTreeModuleOutlineStateExpansionKey - - 29B97314FDCFA39411CA2CEA - 080E96DDFE201D6D7F000001 - 4D0631D70FC30087008ECEEE - 29B97317FDCFA39411CA2CEA - - PBXSmartGroupTreeModuleOutlineStateSelectionKey - - - 20 - 19 - 0 - - - PBXSmartGroupTreeModuleOutlineStateVisibleRectKey - {{0, 0}, {333, 334}} - - PBXTopSmartGroupGIDs - - XCIncludePerspectivesSwitch - - - GeometryConfiguration - - Frame - {{10, 27}, {350, 352}} - GroupTreeTableConfiguration - - MainColumn - 227 - FileBuiltColumn - 20 - ErrorsColumn - 43 - WarningsColumn - 43 - - RubberWindowFrame - 1570 758 350 420 0 0 1920 1178 - - Module - PBXSmartGroupTreeModule - - - ContentConfiguration - - PBXBottomSmartGroupGIDs - - 1C37FBAC04509CD000000102 - 1C37FAAC04509CD000000102 - - PBXProjectModuleGUID - 1C9437FE063B20B00039CFAC - PBXProjectModuleLabel - Targets - PBXProjectStructureProvided - no - PBXSmartGroupTreeModuleColumnData - - PBXSmartGroupTreeModuleColumnWidthsKey - - 333 - - PBXSmartGroupTreeModuleColumnsKey_v4 - - MainColumn - - - PBXSmartGroupTreeModuleOutlineStateKey_v7 - - PBXSmartGroupTreeModuleOutlineStateExpansionKey - - PBXSmartGroupTreeModuleOutlineStateSelectionKey - - - 1 - - - PBXSmartGroupTreeModuleOutlineStateVisibleRectKey - {{0, 0}, {333, 329}} - - PBXTopSmartGroupGIDs - - XCIncludePerspectivesSwitch - - - GeometryConfiguration - - Frame - {{10, 31}, {350, 347}} - GroupTreeTableConfiguration - - MainColumn - 333 - - - Module - PBXSmartGroupTreeModule - - - ContentConfiguration - - PBXBottomSmartGroupGIDs - - 1C08E77C0454961000C914BD - 1C37FABC05509CD000000102 - 1C37FABC05539CD112110102 - E2644B35053B69B200211256 - 1C37FABC04509CD000100104 - 1CC0EA4004350EF90044410B - 1CC0EA4004350EF90041110B - - PBXProjectModuleGUID - 1C9437FF063B20B00039CFAC - PBXProjectModuleLabel - Other - PBXProjectStructureProvided - no - PBXSmartGroupTreeModuleColumnData - - PBXSmartGroupTreeModuleColumnWidthsKey - - 555 - - PBXSmartGroupTreeModuleColumnsKey_v4 - - MainColumn - - - PBXSmartGroupTreeModuleOutlineStateKey_v7 - - PBXSmartGroupTreeModuleOutlineStateExpansionKey - - PBXSmartGroupTreeModuleOutlineStateSelectionKey - - - 0 - - - PBXSmartGroupTreeModuleOutlineStateVisibleRectKey - {{0, 0}, {555, 301}} - - PBXTopSmartGroupGIDs - - XCIncludePerspectivesSwitch - - - GeometryConfiguration - - Frame - {{0, 0}, {572, 319}} - GroupTreeTableConfiguration - - MainColumn - 555 - - - Module - PBXSmartGroupTreeModule - - - - - Name - Project - ServiceClasses - - XCModuleDock - XCDockableTabModule - PBXSmartGroupTreeModule - PBXSmartGroupTreeModule - PBXSmartGroupTreeModule - - TableOfContents - - 4D5554FD0FDE561D004554D7 - 4D5554FE0FDE561D004554D7 - 1C9437FD063B20B00039CFAC - 1C9437FE063B20B00039CFAC - 1C9437FF063B20B00039CFAC - - ToolbarConfiguration - xcode.toolbar.config.default.shortV3 - - - PerspectivesBarVisible - - ShelfIsVisible - - SourceDescription - file at '/Developer/Library/PrivateFrameworks/DevToolsInterface.framework/Resources/XCPerspectivesSpecificationMode2.xcperspec' - StatusbarIsVisible - - TimeStamp - 0.0 - ToolbarDisplayMode - 1 - ToolbarIsVisible - - ToolbarSizeMode - 1 - Type - Perspectives - UpdateMessage - - WindowJustification - 0 - WindowOrderList - - 4D5555110FDE59D0004554D7 - 4D5555130FDE59D0004554D7 - 1C530D5B069F1CE1000CFCEE - 1C530D54069F1CE1000CFCEE - 1C530D52069F1CE1000CFCEE - 4D5555240FDE6172004554D7 - /Users/haqu/Desktop/tweejump/tweejump.xcodeproj - - WindowString - 1570 758 350 420 0 0 1920 1178 - WindowToolsV3 - - - Identifier - windowTool.detail - IsVertical - 0 - Layout - - - Dock - - - BecomeActive - 1 - ContentConfiguration - - PBXBottomSmartGroupGIDs - - 1C37FBAC04509CD000000102 - 1C37FAAC04509CD000000102 - 1C08E77C0454961000C914BD - 1C37FABC05509CD000000102 - 1C37FABC05539CD112110102 - E2644B35053B69B200211256 - 1C37FABC04509CD000100104 - 1CC0EA4004350EF90044410B - 1CC0EA4004350EF90041110B - - PBXProjectModuleGUID - 1CE0B1FE06471DED0097A5F4 - PBXProjectModuleLabel - Files - PBXProjectStructureProvided - yes - PBXSmartGroupTreeModuleColumnData - - PBXSmartGroupTreeModuleColumnWidthsKey - - 245 - - PBXSmartGroupTreeModuleColumnsKey_v4 - - MainColumn - - - PBXSmartGroupTreeModuleOutlineStateKey_v7 - - PBXSmartGroupTreeModuleOutlineStateExpansionKey - - 00C654E9FEEE28EC7F000001 - 1C37FABC05509CD000000102 - - PBXSmartGroupTreeModuleOutlineStateSelectionKey - - - 0 - - - PBXSmartGroupTreeModuleOutlineStateVisibleRectKey - {{0, 0}, {245, 350}} - - PBXTopSmartGroupGIDs - - XCIncludePerspectivesSwitch - 0 - - GeometryConfiguration - - Frame - {{0, 0}, {262, 368}} - GroupTreeTableConfiguration - - MainColumn - 245 - - RubberWindowFrame - 31 446 744 409 0 0 1440 878 - - Module - PBXSmartGroupTreeModule - Proportion - 262pt - - - ContentConfiguration - - PBXProjectModuleGUID - 1CA1AED706398EBD00589147 - PBXProjectModuleLabel - Detail - - GeometryConfiguration - - Frame - {{267, 0}, {477, 368}} - RubberWindowFrame - 31 446 744 409 0 0 1440 878 - - Module - XCDetailModule - Proportion - 477pt - - - Proportion - 100% - - - Name - Detail - ServiceClasses - - PBXSmartGroupTreeModule - XCDetailModule - - StatusbarIsVisible - 1 - TableOfContents - - 1C335F2C07B51CD20023D4EE - 1C335F2D07B51CD20023D4EE - 1C335F2E07B51CD20023D4EE - 1CE0B1FE06471DED0097A5F4 - 1CA1AED706398EBD00589147 - - ToolbarConfiguration - xcode.toolbar.config.defaultV3 - WindowString - 31 446 744 409 0 0 1440 878 - WindowToolGUID - 1C335F2C07B51CD20023D4EE - WindowToolIsVisible - 1 - - - Identifier - MENUSEPARATOR - - - FirstTimeWindowDisplayed - - Identifier - windowTool.build - IsVertical - - Layout - - - Dock - - - ContentConfiguration - - PBXProjectModuleGUID - 1CD0528F0623707200166675 - PBXProjectModuleLabel - - StatusBarVisibility - - - GeometryConfiguration - - Frame - {{0, 0}, {500, 158}} - RubberWindowFrame - 358 416 500 440 0 0 1920 1178 - - Module - PBXNavigatorGroup - Proportion - 158pt - - - ContentConfiguration - - PBXProjectModuleGUID - XCMainBuildResultsModuleGUID - PBXProjectModuleLabel - Build - XCBuildResultsTrigger_Collapse - 1021 - XCBuildResultsTrigger_Open - 1011 - - GeometryConfiguration - - Frame - {{0, 163}, {500, 236}} - RubberWindowFrame - 358 416 500 440 0 0 1920 1178 - - Module - PBXBuildResultsModule - Proportion - 236pt - - - Proportion - 399pt - - - Name - Build Results - ServiceClasses - - PBXBuildResultsModule - - StatusbarIsVisible - - TableOfContents - - 1C530D52069F1CE1000CFCEE - 4D5555090FDE59D0004554D7 - 1CD0528F0623707200166675 - XCMainBuildResultsModuleGUID - - ToolbarConfiguration - xcode.toolbar.config.buildV3 - WindowString - 358 416 500 440 0 0 1920 1178 - WindowToolGUID - 1C530D52069F1CE1000CFCEE - WindowToolIsVisible - - - - FirstTimeWindowDisplayed - - Identifier - windowTool.debugger - IsVertical - - Layout - - - Dock - - - ContentConfiguration - - Debugger - - HorizontalSplitView - - _collapsingFrameDimension - 0.0 - _indexOfCollapsedView - 0 - _percentageOfCollapsedView - 0.0 - isCollapsed - yes - sizes - - {{0, 0}, {333, 211}} - {{333, 0}, {384, 211}} - - - VerticalSplitView - - _collapsingFrameDimension - 0.0 - _indexOfCollapsedView - 0 - _percentageOfCollapsedView - 0.0 - isCollapsed - yes - sizes - - {{0, 0}, {717, 211}} - {{0, 211}, {717, 185}} - - - - LauncherConfigVersion - 8 - PBXProjectModuleGUID - 1C162984064C10D400B95A72 - PBXProjectModuleLabel - Debug - GLUTExamples (Underwater) - - GeometryConfiguration - - DebugConsoleVisible - None - DebugConsoleWindowFrame - {{200, 200}, {500, 300}} - DebugSTDIOWindowFrame - {{200, 200}, {500, 300}} - Frame - {{0, 0}, {717, 396}} - PBXDebugSessionStackFrameViewKey - - DebugVariablesTableConfiguration - - Name - 120 - Value - 85 - Summary - 154 - - Frame - {{333, 0}, {384, 211}} - RubberWindowFrame - 358 419 717 437 0 0 1920 1178 - - RubberWindowFrame - 358 419 717 437 0 0 1920 1178 - - Module - PBXDebugSessionModule - Proportion - 396pt - - - Proportion - 396pt - - - Name - Debugger - ServiceClasses - - PBXDebugSessionModule - - StatusbarIsVisible - - TableOfContents - - 1C530D54069F1CE1000CFCEE - 4D55550A0FDE59D0004554D7 - 1C162984064C10D400B95A72 - 4D55550B0FDE59D0004554D7 - 4D55550C0FDE59D0004554D7 - 4D55550D0FDE59D0004554D7 - 4D55550E0FDE59D0004554D7 - 4D55550F0FDE59D0004554D7 - - ToolbarConfiguration - xcode.toolbar.config.debugV3 - WindowString - 358 419 717 437 0 0 1920 1178 - WindowToolGUID - 1C530D54069F1CE1000CFCEE - WindowToolIsVisible - - - - FirstTimeWindowDisplayed - - Identifier - windowTool.find - IsVertical - - Layout - - - Dock - - - Dock - - - ContentConfiguration - - PBXProjectModuleGUID - 1CDD528C0622207200134675 - PBXProjectModuleLabel - <No Editor> - StatusBarVisibility - - - GeometryConfiguration - - Frame - {{0, 0}, {784, 137}} - RubberWindowFrame - 27 357 784 687 0 0 1920 1178 - - Module - PBXNavigatorGroup - Proportion - 784pt - - - Proportion - 137pt - - - ContentConfiguration - - PBXProjectModuleGUID - 1CD0528E0623707200166675 - PBXProjectModuleLabel - Project Find - - GeometryConfiguration - - Frame - {{0, 142}, {784, 504}} - RubberWindowFrame - 27 357 784 687 0 0 1920 1178 - - Module - PBXProjectFindModule - Proportion - 504pt - - - Proportion - 646pt - - - Name - Project Find - ServiceClasses - - PBXProjectFindModule - - StatusbarIsVisible - - TableOfContents - - 1C530D57069F1CE1000CFCEE - 4D857E0A0FD748A900B350BA - 4D857E0B0FD748A900B350BA - 1CDD528C0622207200134675 - 1CD0528E0623707200166675 - - WindowString - 27 357 784 687 0 0 1920 1178 - WindowToolGUID - 1C530D57069F1CE1000CFCEE - WindowToolIsVisible - - - - Identifier - MENUSEPARATOR - - - FirstTimeWindowDisplayed - - Identifier - windowTool.debuggerConsole - IsVertical - - Layout - - - Dock - - - ContentConfiguration - - PBXProjectModuleGUID - 1C78EAAC065D492600B07095 - PBXProjectModuleLabel - Debugger Console - - GeometryConfiguration - - Frame - {{0, 0}, {636, 582}} - RubberWindowFrame - 20 555 636 623 0 0 1920 1178 - - Module - PBXDebugCLIModule - Proportion - 582pt - - - Proportion - 582pt - - - Name - Debugger Console - ServiceClasses - - PBXDebugCLIModule - - StatusbarIsVisible - - TableOfContents - - 1C530D5B069F1CE1000CFCEE - 4D5555100FDE59D0004554D7 - 1C78EAAC065D492600B07095 - - ToolbarConfiguration - xcode.toolbar.config.consoleV3 - WindowString - 20 555 636 623 0 0 1920 1178 - WindowToolGUID - 1C530D5B069F1CE1000CFCEE - WindowToolIsVisible - - - - Identifier - windowTool.snapshots - Layout - - - Dock - - - Module - XCSnapshotModule - Proportion - 100% - - - Proportion - 100% - - - Name - Snapshots - ServiceClasses - - XCSnapshotModule - - StatusbarIsVisible - Yes - ToolbarConfiguration - xcode.toolbar.config.snapshots - WindowString - 315 824 300 550 0 0 1440 878 - WindowToolIsVisible - Yes - - - Identifier - windowTool.scm - Layout - - - Dock - - - ContentConfiguration - - PBXProjectModuleGUID - 1C78EAB2065D492600B07095 - PBXProjectModuleLabel - <No Editor> - PBXSplitModuleInNavigatorKey - - Split0 - - PBXProjectModuleGUID - 1C78EAB3065D492600B07095 - - SplitCount - 1 - - StatusBarVisibility - 1 - - GeometryConfiguration - - Frame - {{0, 0}, {452, 0}} - RubberWindowFrame - 743 379 452 308 0 0 1280 1002 - - Module - PBXNavigatorGroup - Proportion - 0pt - - - BecomeActive - 1 - ContentConfiguration - - PBXProjectModuleGUID - 1CD052920623707200166675 - PBXProjectModuleLabel - SCM - - GeometryConfiguration - - ConsoleFrame - {{0, 259}, {452, 0}} - Frame - {{0, 7}, {452, 259}} - RubberWindowFrame - 743 379 452 308 0 0 1280 1002 - TableConfiguration - - Status - 30 - FileName - 199 - Path - 197.09500122070312 - - TableFrame - {{0, 0}, {452, 250}} - - Module - PBXCVSModule - Proportion - 262pt - - - Proportion - 266pt - - - Name - SCM - ServiceClasses - - PBXCVSModule - - StatusbarIsVisible - 1 - TableOfContents - - 1C78EAB4065D492600B07095 - 1C78EAB5065D492600B07095 - 1C78EAB2065D492600B07095 - 1CD052920623707200166675 - - ToolbarConfiguration - xcode.toolbar.config.scm - WindowString - 743 379 452 308 0 0 1280 1002 - - - Identifier - windowTool.breakpoints - IsVertical - 0 - Layout - - - Dock - - - BecomeActive - 1 - ContentConfiguration - - PBXBottomSmartGroupGIDs - - 1C77FABC04509CD000000102 - - PBXProjectModuleGUID - 1CE0B1FE06471DED0097A5F4 - PBXProjectModuleLabel - Files - PBXProjectStructureProvided - no - PBXSmartGroupTreeModuleColumnData - - PBXSmartGroupTreeModuleColumnWidthsKey - - 168 - - PBXSmartGroupTreeModuleColumnsKey_v4 - - MainColumn - - - PBXSmartGroupTreeModuleOutlineStateKey_v7 - - PBXSmartGroupTreeModuleOutlineStateExpansionKey - - 1C77FABC04509CD000000102 - - PBXSmartGroupTreeModuleOutlineStateSelectionKey - - - 0 - - - PBXSmartGroupTreeModuleOutlineStateVisibleRectKey - {{0, 0}, {168, 350}} - - PBXTopSmartGroupGIDs - - XCIncludePerspectivesSwitch - 0 - - GeometryConfiguration - - Frame - {{0, 0}, {185, 368}} - GroupTreeTableConfiguration - - MainColumn - 168 - - RubberWindowFrame - 315 424 744 409 0 0 1440 878 - - Module - PBXSmartGroupTreeModule - Proportion - 185pt - - - ContentConfiguration - - PBXProjectModuleGUID - 1CA1AED706398EBD00589147 - PBXProjectModuleLabel - Detail - - GeometryConfiguration - - Frame - {{190, 0}, {554, 368}} - RubberWindowFrame - 315 424 744 409 0 0 1440 878 - - Module - XCDetailModule - Proportion - 554pt - - - Proportion - 368pt - - - MajorVersion - 3 - MinorVersion - 0 - Name - Breakpoints - ServiceClasses - - PBXSmartGroupTreeModule - XCDetailModule - - StatusbarIsVisible - 1 - TableOfContents - - 1CDDB66807F98D9800BB5817 - 1CDDB66907F98D9800BB5817 - 1CE0B1FE06471DED0097A5F4 - 1CA1AED706398EBD00589147 - - ToolbarConfiguration - xcode.toolbar.config.breakpointsV3 - WindowString - 315 424 744 409 0 0 1440 878 - WindowToolGUID - 1CDDB66807F98D9800BB5817 - WindowToolIsVisible - 1 - - - Identifier - windowTool.debugAnimator - Layout - - - Dock - - - Module - PBXNavigatorGroup - Proportion - 100% - - - Proportion - 100% - - - Name - Debug Visualizer - ServiceClasses - - PBXNavigatorGroup - - StatusbarIsVisible - 1 - ToolbarConfiguration - xcode.toolbar.config.debugAnimatorV3 - WindowString - 100 100 700 500 0 0 1280 1002 - - - Identifier - windowTool.bookmarks - Layout - - - Dock - - - Module - PBXBookmarksModule - Proportion - 100% - - - Proportion - 100% - - - Name - Bookmarks - ServiceClasses - - PBXBookmarksModule - - StatusbarIsVisible - 0 - WindowString - 538 42 401 187 0 0 1280 1002 - - - Identifier - windowTool.projectFormatConflicts - Layout - - - Dock - - - Module - XCProjectFormatConflictsModule - Proportion - 100% - - - Proportion - 100% - - - Name - Project Format Conflicts - ServiceClasses - - XCProjectFormatConflictsModule - - StatusbarIsVisible - 0 - WindowContentMinSize - 450 300 - WindowString - 50 850 472 307 0 0 1440 877 - - - Identifier - windowTool.classBrowser - Layout - - - Dock - - - BecomeActive - 1 - ContentConfiguration - - OptionsSetName - Hierarchy, all classes - PBXProjectModuleGUID - 1CA6456E063B45B4001379D8 - PBXProjectModuleLabel - Class Browser - NSObject - - GeometryConfiguration - - ClassesFrame - {{0, 0}, {368, 96}} - ClassesTreeTableConfiguration - - PBXClassNameColumnIdentifier - 208 - PBXClassBookColumnIdentifier - 22 - - Frame - {{0, 0}, {624, 318}} - MembersFrame - {{0, 105}, {368, 395}} - MembersTreeTableConfiguration - - PBXMemberTypeIconColumnIdentifier - 22 - PBXMemberNameColumnIdentifier - 216 - PBXMemberTypeColumnIdentifier - 91 - PBXMemberBookColumnIdentifier - 22 - - PBXModuleWindowStatusBarHidden2 - 1 - RubberWindowFrame - 128 171 624 339 0 0 1440 878 - - Module - PBXClassBrowserModule - Proportion - 319pt - - - Proportion - 319pt - - - Name - Class Browser - ServiceClasses - - PBXClassBrowserModule - - StatusbarIsVisible - 0 - TableOfContents - - 1C530D60069F1CE1000CFCEE - 1C530D61069F1CE1000CFCEE - 1CA6456E063B45B4001379D8 - - ToolbarConfiguration - xcode.toolbar.config.classbrowser - WindowString - 128 171 624 339 0 0 1440 878 - WindowToolGUID - 1C530D60069F1CE1000CFCEE - WindowToolIsVisible - 0 - - - Identifier - windowTool.refactoring - IncludeInToolsMenu - 0 - Layout - - - Dock - - - BecomeActive - 1 - GeometryConfiguration - - Frame - {0, 0}, {500, 335} - RubberWindowFrame - {0, 0}, {500, 335} - - Module - XCRefactoringModule - Proportion - 100% - - - Proportion - 100% - - - Name - Refactoring - ServiceClasses - - XCRefactoringModule - - WindowString - 200 200 500 356 0 0 1920 1200 - - - - diff --git a/tweejump.xcodeproj/haqu.pbxuser b/tweejump.xcodeproj/haqu.pbxuser deleted file mode 100644 index b7be544..0000000 --- a/tweejump.xcodeproj/haqu.pbxuser +++ /dev/null @@ -1,266 +0,0 @@ -// !$*UTF8*$! -{ - 1D6058900D05DD3D006BFB54 /* tweejump */ = { - activeExec = 0; - executables = ( - 4D0631CC0FC30058008ECEEE /* tweejump */, - ); - }; - 29B97313FDCFA39411CA2CEA /* Project object */ = { - activeBuildConfigurationName = Distribution; - activeExecutable = 4D0631CC0FC30058008ECEEE /* tweejump */; - activeSDKPreference = iphoneos2.2.1; - activeTarget = 1D6058900D05DD3D006BFB54 /* tweejump */; - addToTargets = ( - 1D6058900D05DD3D006BFB54 /* tweejump */, - ); - breakpoints = ( - ); - codeSenseManager = 4D0631D40FC30076008ECEEE /* Code sense */; - executables = ( - 4D0631CC0FC30058008ECEEE /* tweejump */, - ); - perUserDictionary = { - PBXPerProjectTemplateStateSaveDate = 266229274; - PBXWorkspaceStateSaveDate = 266229274; - }; - perUserProjectItems = { - 4D55551C0FDE5F6D004554D7 /* PBXBookmark */ = 4D55551C0FDE5F6D004554D7 /* PBXBookmark */; - 4D5555260FDE6172004554D7 /* PBXTextBookmark */ = 4D5555260FDE6172004554D7 /* PBXTextBookmark */; - 4DFD4D860FD7C8AB00AA55A0 = 4DFD4D860FD7C8AB00AA55A0 /* PBXTextBookmark */; - 4DFD4D8D0FD7C96E00AA55A0 = 4DFD4D8D0FD7C96E00AA55A0 /* PBXTextBookmark */; - 4DFD4D8E0FD7C96E00AA55A0 = 4DFD4D8E0FD7C96E00AA55A0 /* PBXTextBookmark */; - 4DFD4D970FD7C96E00AA55A0 = 4DFD4D970FD7C96E00AA55A0 /* PBXTextBookmark */; - 4DFD4D9B0FD7C96F00AA55A0 = 4DFD4D9B0FD7C96F00AA55A0 /* PBXTextBookmark */; - }; - sourceControlManager = 4D0631D30FC30076008ECEEE /* Source Control */; - userBuildSettings = { - }; - }; - 29B97316FDCFA39411CA2CEA /* main.m */ = { - uiCtxt = { - sepNavIntBoundsRect = "{{0, 0}, {810, 735}}"; - sepNavSelRange = "{130, 0}"; - sepNavVisRange = "{0, 240}"; - sepNavWindowFrame = "{{38, 360}, {869, 792}}"; - }; - }; - 32CA4F630368D1EE00C91783 /* Prefix.pch */ = { - uiCtxt = { - sepNavIntBoundsRect = "{{0, 0}, {810, 735}}"; - sepNavSelRange = "{0, 0}"; - sepNavVisRange = "{0, 81}"; - sepNavWindowFrame = "{{15, 381}, {869, 792}}"; - }; - }; - 4D0631CC0FC30058008ECEEE /* tweejump */ = { - isa = PBXExecutable; - activeArgIndices = ( - ); - argumentStrings = ( - ); - autoAttachOnCrash = 1; - breakpointsEnabled = 0; - configStateDict = { - }; - customDataFormattersEnabled = 1; - debuggerPlugin = GDBDebugging; - disassemblyDisplayState = 0; - dylibVariantSuffix = ""; - enableDebugStr = 1; - environmentEntries = ( - ); - executableSystemSymbolLevel = 0; - executableUserSymbolLevel = 0; - libgmallocEnabled = 0; - name = tweejump; - savedGlobals = { - }; - sourceDirectories = ( - ); - }; - 4D0631D30FC30076008ECEEE /* Source Control */ = { - isa = PBXSourceControlManager; - fallbackIsa = XCSourceControlManager; - isSCMEnabled = 0; - scmConfiguration = { - }; - }; - 4D0631D40FC30076008ECEEE /* Code sense */ = { - isa = PBXCodeSenseManager; - indexTemplatePath = ""; - }; - 4D0631E90FC30572008ECEEE /* AppDelegate.m */ = { - uiCtxt = { - sepNavIntBoundsRect = "{{0, 0}, {810, 800}}"; - sepNavSelRange = "{689, 0}"; - sepNavVisRange = "{0, 1352}"; - sepNavWindowFrame = "{{734, 137}, {869, 792}}"; - }; - }; - 4D0631EA0FC30572008ECEEE /* AppDelegate.h */ = { - uiCtxt = { - sepNavIntBoundsRect = "{{0, 0}, {810, 735}}"; - sepNavSelRange = "{106, 0}"; - sepNavVisRange = "{0, 132}"; - sepNavWindowFrame = "{{314, 108}, {869, 792}}"; - }; - }; - 4D5448260FD48DF30010F348 /* Main.h */ = { - uiCtxt = { - sepNavIntBoundsRect = "{{0, 0}, {810, 735}}"; - sepNavSelRange = "{87, 0}"; - sepNavVisRange = "{0, 577}"; - sepNavWindowFrame = "{{68, 319}, {869, 792}}"; - }; - }; - 4D5448270FD48DF30010F348 /* Main.m */ = { - uiCtxt = { - sepNavIntBoundsRect = "{{0, 0}, {439, 2064}}"; - sepNavSelRange = "{1920, 0}"; - sepNavVisRange = "{1708, 244}"; - sepNavWindowFrame = "{{84, 321}, {922, 789}}"; - }; - }; - 4D5449CF0FD4D67A0010F348 /* Highscores.m */ = { - uiCtxt = { - sepNavIntBoundsRect = "{{0, 0}, {723, 4432}}"; - sepNavSelRange = "{365, 5}"; - sepNavVisRange = "{254, 141}"; - sepNavWindowFrame = "{{589, 105}, {922, 789}}"; - }; - }; - 4D5449D00FD4D67A0010F348 /* Highscores.h */ = { - uiCtxt = { - sepNavIntBoundsRect = "{{0, 0}, {863, 732}}"; - sepNavSelRange = "{225, 0}"; - sepNavVisRange = "{0, 305}"; - sepNavWindowFrame = "{{153, 258}, {922, 789}}"; - }; - }; - 4D55551C0FDE5F6D004554D7 /* PBXBookmark */ = { - isa = PBXBookmark; - fRef = 4DD044C90FC918D300897B73 /* Game.m */; - }; - 4D5555260FDE6172004554D7 /* PBXTextBookmark */ = { - isa = PBXTextBookmark; - fRef = 4DD044C90FC918D300897B73 /* Game.m */; - name = "Game.m: 172"; - rLen = 0; - rLoc = 4247; - rType = 0; - vrLen = 1089; - vrLoc = 3884; - }; - 4DD043610FC9081800897B73 /* AtlasSpriteManager.m */ = { - uiCtxt = { - sepNavIntBoundsRect = "{{0, 0}, {810, 5216}}"; - sepNavSelRange = "{1380, 0}"; - sepNavVisRange = "{835, 1120}"; - sepNavWindowFrame = "{{15, 381}, {869, 792}}"; - }; - }; - 4DD043690FC9081800897B73 /* ccMacros.h */ = { - uiCtxt = { - sepNavIntBoundsRect = "{{0, 0}, {810, 896}}"; - sepNavSelRange = "{0, 0}"; - sepNavVisRange = "{0, 1084}"; - sepNavWindowFrame = "{{84, 318}, {869, 792}}"; - }; - }; - 4DD0436F0FC9081800897B73 /* Director.h */ = { - uiCtxt = { - sepNavIntBoundsRect = "{{0, 0}, {723, 4720}}"; - sepNavSelRange = "{676, 2}"; - sepNavVisRange = "{531, 237}"; - }; - }; - 4DD043700FC9081800897B73 /* Director.m */ = { - uiCtxt = { - sepNavIntBoundsRect = "{{0, 0}, {723, 15840}}"; - sepNavSelRange = "{3735, 10}"; - sepNavVisRange = "{3564, 249}"; - }; - }; - 4DD043910FC9081800897B73 /* Primitives.h */ = { - uiCtxt = { - sepNavIntBoundsRect = "{{0, 0}, {723, 768}}"; - sepNavSelRange = "{1304, 8}"; - sepNavVisRange = "{1174, 369}"; - sepNavWindowFrame = "{{222, 195}, {922, 789}}"; - }; - }; - 4DD043B20FC9081800897B73 /* TextureAtlas.m */ = { - uiCtxt = { - sepNavIntBoundsRect = "{{0, 0}, {723, 4368}}"; - sepNavSelRange = "{1658, 0}"; - sepNavVisRange = "{1562, 222}"; - }; - }; - 4DD044C80FC918D300897B73 /* Game.h */ = { - uiCtxt = { - sepNavIntBoundsRect = "{{0, 0}, {810, 735}}"; - sepNavSelRange = "{244, 0}"; - sepNavVisRange = "{0, 355}"; - sepNavWindowFrame = "{{579, 230}, {869, 792}}"; - }; - }; - 4DD044C90FC918D300897B73 /* Game.m */ = { - uiCtxt = { - sepNavIntBoundsRect = "{{0, 0}, {810, 6352}}"; - sepNavSelRange = "{4247, 0}"; - sepNavVisRange = "{3884, 1089}"; - sepNavWindowFrame = "{{678, 283}, {869, 792}}"; - }; - }; - 4DFD4D860FD7C8AB00AA55A0 /* PBXTextBookmark */ = { - isa = PBXTextBookmark; - fRef = 4DD044C90FC918D300897B73 /* Game.m */; - rLen = 0; - rLoc = 7515; - rType = 0; - }; - 4DFD4D8D0FD7C96E00AA55A0 /* PBXTextBookmark */ = { - isa = PBXTextBookmark; - comments = "error: invalid lvalue in assignment"; - fRef = 4D5448270FD48DF30010F348 /* Main.m */; - rLen = 1; - rLoc = 79; - rType = 1; - }; - 4DFD4D8E0FD7C96E00AA55A0 /* PBXTextBookmark */ = { - isa = PBXTextBookmark; - fRef = 4D5448270FD48DF30010F348 /* Main.m */; - name = "Main.m: 80"; - rLen = 0; - rLoc = 1920; - rType = 0; - vrLen = 244; - vrLoc = 1708; - }; - 4DFD4D970FD7C96E00AA55A0 /* PBXTextBookmark */ = { - isa = PBXTextBookmark; - fRef = 4DD044C90FC918D300897B73 /* Game.m */; - name = "Game.m: 284"; - rLen = 0; - rLoc = 7515; - rType = 0; - vrLen = 271; - vrLoc = 7465; - }; - 4DFD4D9B0FD7C96F00AA55A0 /* PBXTextBookmark */ = { - isa = PBXTextBookmark; - fRef = 4DD044C90FC918D300897B73 /* Game.m */; - name = "Game.m: 284"; - rLen = 0; - rLoc = 7515; - rType = 0; - vrLen = 271; - vrLoc = 7465; - }; - 8D1107310486CEB800E47090 /* Info.plist */ = { - uiCtxt = { - sepNavWindowFrame = "{{222, 192}, {869, 792}}"; - }; - }; -} diff --git a/tweejump.xcodeproj/project.pbxproj b/tweejump.xcodeproj/project.pbxproj old mode 100755 new mode 100644 index 54bf1b9..4122499 --- a/tweejump.xcodeproj/project.pbxproj +++ b/tweejump.xcodeproj/project.pbxproj @@ -3,438 +3,708 @@ archiveVersion = 1; classes = { }; - objectVersion = 45; + objectVersion = 46; objects = { /* Begin PBXBuildFile section */ - 1D60589B0D05DD56006BFB54 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B97316FDCFA39411CA2CEA /* main.m */; }; - 1D60589F0D05DD5A006BFB54 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D30AB110D05D00D00671497 /* Foundation.framework */; }; - 1DF5F4E00D08C38300B7A737 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1DF5F4DF0D08C38300B7A737 /* UIKit.framework */; }; - 28FD15000DC6FC520079059D /* OpenGLES.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 28FD14FF0DC6FC520079059D /* OpenGLES.framework */; }; - 28FD15080DC6FC5B0079059D /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 28FD15070DC6FC5B0079059D /* QuartzCore.framework */; }; - 4D0631D60FC3007F008ECEEE /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4D0631D50FC3007F008ECEEE /* CoreGraphics.framework */; }; - 4D0631EB0FC30572008ECEEE /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D0631E90FC30572008ECEEE /* AppDelegate.m */; }; - 4D2C560C0FCD447F00331A7C /* sprites.png in Resources */ = {isa = PBXBuildFile; fileRef = 4D2C560B0FCD447F00331A7C /* sprites.png */; }; - 4D5448280FD48DF30010F348 /* Main.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D5448270FD48DF30010F348 /* Main.m */; }; - 4D5449D10FD4D67A0010F348 /* Highscores.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D5449CF0FD4D67A0010F348 /* Highscores.m */; }; - 4D544A9C0FD4EEFF0010F348 /* playAgainButton.png in Resources */ = {isa = PBXBuildFile; fileRef = 4D544A9A0FD4EEFF0010F348 /* playAgainButton.png */; }; - 4D544A9D0FD4EEFF0010F348 /* changePlayerButton.png in Resources */ = {isa = PBXBuildFile; fileRef = 4D544A9B0FD4EEFF0010F348 /* changePlayerButton.png */; }; - 4D5555020FDE56B0004554D7 /* Default.png in Resources */ = {isa = PBXBuildFile; fileRef = 4D5555010FDE56B0004554D7 /* Default.png */; }; - 4D74D7700FD6B36900C364B4 /* bitmapFont.fnt in Resources */ = {isa = PBXBuildFile; fileRef = 4D74D76F0FD6B36900C364B4 /* bitmapFont.fnt */; }; - 4D74D7720FD6B36D00C364B4 /* bitmapFont.png in Resources */ = {isa = PBXBuildFile; fileRef = 4D74D7710FD6B36D00C364B4 /* bitmapFont.png */; }; - 4D857DE10FD740E200B350BA /* icon.png in Resources */ = {isa = PBXBuildFile; fileRef = 4D857DE00FD740E200B350BA /* icon.png */; }; - 4DD043C10FC9081800897B73 /* Action.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DD0435B0FC9081800897B73 /* Action.m */; }; - 4DD043C20FC9081800897B73 /* AtlasNode.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DD0435D0FC9081800897B73 /* AtlasNode.m */; }; - 4DD043C30FC9081800897B73 /* AtlasSprite.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DD0435F0FC9081800897B73 /* AtlasSprite.m */; }; - 4DD043C40FC9081800897B73 /* AtlasSpriteManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DD043610FC9081800897B73 /* AtlasSpriteManager.m */; }; - 4DD043C50FC9081800897B73 /* BitmapFontAtlas.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DD043630FC9081800897B73 /* BitmapFontAtlas.m */; }; - 4DD043C60FC9081800897B73 /* Camera.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DD043650FC9081800897B73 /* Camera.m */; }; - 4DD043C70FC9081800897B73 /* CameraAction.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DD043670FC9081800897B73 /* CameraAction.m */; }; - 4DD043C80FC9081800897B73 /* cocos2d.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DD0436C0FC9081800897B73 /* cocos2d.m */; }; - 4DD043C90FC9081800897B73 /* CocosNode.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DD0436E0FC9081800897B73 /* CocosNode.m */; }; - 4DD043CA0FC9081800897B73 /* Director.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DD043700FC9081800897B73 /* Director.m */; }; - 4DD043CB0FC9081800897B73 /* EaseAction.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DD043720FC9081800897B73 /* EaseAction.m */; }; - 4DD043CC0FC9081800897B73 /* Grabber.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DD043740FC9081800897B73 /* Grabber.m */; }; - 4DD043CD0FC9081800897B73 /* Grid.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DD043760FC9081800897B73 /* Grid.m */; }; - 4DD043CE0FC9081800897B73 /* Grid3DAction.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DD043780FC9081800897B73 /* Grid3DAction.m */; }; - 4DD043CF0FC9081800897B73 /* GridAction.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DD0437A0FC9081800897B73 /* GridAction.m */; }; - 4DD043D00FC9081800897B73 /* InstantAction.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DD0437C0FC9081800897B73 /* InstantAction.m */; }; - 4DD043D10FC9081800897B73 /* IntervalAction.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DD0437E0FC9081800897B73 /* IntervalAction.m */; }; - 4DD043D20FC9081800897B73 /* Label.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DD043800FC9081800897B73 /* Label.m */; }; - 4DD043D30FC9081800897B73 /* LabelAtlas.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DD043820FC9081800897B73 /* LabelAtlas.m */; }; - 4DD043D40FC9081800897B73 /* Layer.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DD043840FC9081800897B73 /* Layer.m */; }; - 4DD043D50FC9081800897B73 /* Menu.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DD043860FC9081800897B73 /* Menu.m */; }; - 4DD043D60FC9081800897B73 /* MenuItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DD043880FC9081800897B73 /* MenuItem.m */; }; - 4DD043D70FC9081800897B73 /* ParallaxNode.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DD0438A0FC9081800897B73 /* ParallaxNode.m */; }; - 4DD043D80FC9081800897B73 /* ParticleExamples.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DD0438C0FC9081800897B73 /* ParticleExamples.m */; }; - 4DD043D90FC9081800897B73 /* ParticleSystem.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DD0438E0FC9081800897B73 /* ParticleSystem.m */; }; - 4DD043DA0FC9081800897B73 /* PointParticleSystem.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DD043900FC9081800897B73 /* PointParticleSystem.m */; }; - 4DD043DB0FC9081800897B73 /* Primitives.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DD043920FC9081800897B73 /* Primitives.m */; }; - 4DD043DC0FC9081800897B73 /* QuadParticleSystem.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DD043940FC9081800897B73 /* QuadParticleSystem.m */; }; - 4DD043DD0FC9081800897B73 /* Scene.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DD043960FC9081800897B73 /* Scene.m */; }; - 4DD043DE0FC9081800897B73 /* Scheduler.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DD043980FC9081800897B73 /* Scheduler.m */; }; - 4DD043DF0FC9081800897B73 /* Sprite.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DD0439A0FC9081800897B73 /* Sprite.m */; }; - 4DD043E00FC9081800897B73 /* CGPointExtension.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DD0439E0FC9081800897B73 /* CGPointExtension.m */; }; - 4DD043E10FC9081800897B73 /* EAGLView.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DD043A00FC9081800897B73 /* EAGLView.m */; }; - 4DD043E20FC9081800897B73 /* FileUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DD043A20FC9081800897B73 /* FileUtils.m */; }; - 4DD043E30FC9081800897B73 /* glu.c in Sources */ = {isa = PBXBuildFile; fileRef = 4DD043A30FC9081800897B73 /* glu.c */; }; - 4DD043E40FC9081800897B73 /* PVRTexture.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DD043A70FC9081800897B73 /* PVRTexture.m */; }; - 4DD043E50FC9081800897B73 /* Texture2D.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DD043A90FC9081800897B73 /* Texture2D.m */; }; - 4DD043E60FC9081800897B73 /* TGAlib.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DD043AB0FC9081800897B73 /* TGAlib.m */; }; - 4DD043E70FC9081800897B73 /* TransformUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DD043AD0FC9081800897B73 /* TransformUtils.m */; }; - 4DD043E80FC9081800897B73 /* UIColor-OpenGL.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DD043AF0FC9081800897B73 /* UIColor-OpenGL.m */; }; - 4DD043E90FC9081800897B73 /* TextureAtlas.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DD043B20FC9081800897B73 /* TextureAtlas.m */; }; - 4DD043EA0FC9081800897B73 /* TextureMgr.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DD043B40FC9081800897B73 /* TextureMgr.m */; }; - 4DD043EB0FC9081800897B73 /* TextureNode.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DD043B60FC9081800897B73 /* TextureNode.m */; }; - 4DD043EC0FC9081800897B73 /* TiledGridAction.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DD043B80FC9081800897B73 /* TiledGridAction.m */; }; - 4DD043ED0FC9081800897B73 /* TileMapAtlas.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DD043BA0FC9081800897B73 /* TileMapAtlas.m */; }; - 4DD043EE0FC9081800897B73 /* TouchDispatcher.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DD043BC0FC9081800897B73 /* TouchDispatcher.m */; }; - 4DD043EF0FC9081800897B73 /* TouchHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DD043BE0FC9081800897B73 /* TouchHandler.m */; }; - 4DD043F00FC9081800897B73 /* Transition.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DD043C00FC9081800897B73 /* Transition.m */; }; - 4DD044CA0FC918D300897B73 /* Game.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DD044C90FC918D300897B73 /* Game.m */; }; + F49E735C15ACCF46009C8E84 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F49E735B15ACCF46009C8E84 /* QuartzCore.framework */; }; + F49E735E15ACCF46009C8E84 /* OpenGLES.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F49E735D15ACCF46009C8E84 /* OpenGLES.framework */; }; + F49E736015ACCF46009C8E84 /* OpenAL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F49E735F15ACCF46009C8E84 /* OpenAL.framework */; }; + F49E736215ACCF46009C8E84 /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F49E736115ACCF46009C8E84 /* AudioToolbox.framework */; }; + F49E736415ACCF46009C8E84 /* AVFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F49E736315ACCF46009C8E84 /* AVFoundation.framework */; }; + F49E736615ACCF46009C8E84 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F49E736515ACCF46009C8E84 /* UIKit.framework */; }; + F49E736815ACCF46009C8E84 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F49E736715ACCF46009C8E84 /* Foundation.framework */; }; + F49E736A15ACCF46009C8E84 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F49E736915ACCF46009C8E84 /* CoreGraphics.framework */; }; + F49E736E15ACCF46009C8E84 /* Default.png in Resources */ = {isa = PBXBuildFile; fileRef = F49E736D15ACCF46009C8E84 /* Default.png */; }; + F49E737015ACCF46009C8E84 /* fps_images.png in Resources */ = {isa = PBXBuildFile; fileRef = F49E736F15ACCF46009C8E84 /* fps_images.png */; }; + F49E737215ACCF47009C8E84 /* Icon-72.png in Resources */ = {isa = PBXBuildFile; fileRef = F49E737115ACCF47009C8E84 /* Icon-72.png */; }; + F49E737415ACCF47009C8E84 /* Icon-Small-50.png in Resources */ = {isa = PBXBuildFile; fileRef = F49E737315ACCF47009C8E84 /* Icon-Small-50.png */; }; + F49E737615ACCF47009C8E84 /* Icon-Small.png in Resources */ = {isa = PBXBuildFile; fileRef = F49E737515ACCF47009C8E84 /* Icon-Small.png */; }; + F49E737815ACCF47009C8E84 /* Icon-Small@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = F49E737715ACCF47009C8E84 /* Icon-Small@2x.png */; }; + F49E737A15ACCF47009C8E84 /* Icon.png in Resources */ = {isa = PBXBuildFile; fileRef = F49E737915ACCF47009C8E84 /* Icon.png */; }; + F49E737F15ACCF47009C8E84 /* iTunesArtwork in Resources */ = {isa = PBXBuildFile; fileRef = F49E737E15ACCF47009C8E84 /* iTunesArtwork */; }; + F49E738415ACCF47009C8E84 /* CCAction.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E738315ACCF47009C8E84 /* CCAction.m */; }; + F49E738715ACCF47009C8E84 /* CCActionCamera.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E738615ACCF47009C8E84 /* CCActionCamera.m */; }; + F49E738A15ACCF47009C8E84 /* CCActionEase.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E738915ACCF47009C8E84 /* CCActionEase.m */; }; + F49E738D15ACCF47009C8E84 /* CCActionGrid.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E738C15ACCF47009C8E84 /* CCActionGrid.m */; }; + F49E739015ACCF47009C8E84 /* CCActionGrid3D.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E738F15ACCF47009C8E84 /* CCActionGrid3D.m */; }; + F49E739315ACCF47009C8E84 /* CCActionInstant.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E739215ACCF47009C8E84 /* CCActionInstant.m */; }; + F49E739615ACCF47009C8E84 /* CCActionInterval.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E739515ACCF47009C8E84 /* CCActionInterval.m */; }; + F49E739915ACCF47009C8E84 /* CCActionManager.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E739815ACCF47009C8E84 /* CCActionManager.m */; }; + F49E739C15ACCF47009C8E84 /* CCActionPageTurn3D.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E739B15ACCF47009C8E84 /* CCActionPageTurn3D.m */; }; + F49E739F15ACCF47009C8E84 /* CCActionProgressTimer.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E739E15ACCF47009C8E84 /* CCActionProgressTimer.m */; }; + F49E73A215ACCF47009C8E84 /* CCActionTiledGrid.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E73A115ACCF47009C8E84 /* CCActionTiledGrid.m */; }; + F49E73A515ACCF47009C8E84 /* CCActionTween.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E73A415ACCF47009C8E84 /* CCActionTween.m */; }; + F49E73A815ACCF47009C8E84 /* CCAnimation.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E73A715ACCF47009C8E84 /* CCAnimation.m */; }; + F49E73AB15ACCF47009C8E84 /* CCAnimationCache.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E73AA15ACCF47009C8E84 /* CCAnimationCache.m */; }; + F49E73AE15ACCF47009C8E84 /* CCAtlasNode.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E73AD15ACCF47009C8E84 /* CCAtlasNode.m */; }; + F49E73B115ACCF47009C8E84 /* CCBlockSupport.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E73B015ACCF47009C8E84 /* CCBlockSupport.m */; }; + F49E73B415ACCF47009C8E84 /* CCCamera.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E73B315ACCF47009C8E84 /* CCCamera.m */; }; + F49E73B815ACCF47009C8E84 /* CCConfiguration.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E73B715ACCF47009C8E84 /* CCConfiguration.m */; }; + F49E73BB15ACCF47009C8E84 /* CCDirector.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E73BA15ACCF47009C8E84 /* CCDirector.m */; }; + F49E73BE15ACCF47009C8E84 /* CCDrawingPrimitives.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E73BD15ACCF47009C8E84 /* CCDrawingPrimitives.m */; }; + F49E73C115ACCF47009C8E84 /* CCGrabber.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E73C015ACCF47009C8E84 /* CCGrabber.m */; }; + F49E73C415ACCF47009C8E84 /* CCGrid.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E73C315ACCF47009C8E84 /* CCGrid.m */; }; + F49E73C715ACCF47009C8E84 /* CCLabelAtlas.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E73C615ACCF47009C8E84 /* CCLabelAtlas.m */; }; + F49E73CA15ACCF47009C8E84 /* CCLabelBMFont.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E73C915ACCF47009C8E84 /* CCLabelBMFont.m */; }; + F49E73CD15ACCF47009C8E84 /* CCLabelTTF.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E73CC15ACCF47009C8E84 /* CCLabelTTF.m */; }; + F49E73D015ACCF47009C8E84 /* CCLayer.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E73CF15ACCF47009C8E84 /* CCLayer.m */; }; + F49E73D415ACCF47009C8E84 /* CCMenu.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E73D315ACCF47009C8E84 /* CCMenu.m */; }; + F49E73D715ACCF47009C8E84 /* CCMenuItem.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E73D615ACCF47009C8E84 /* CCMenuItem.m */; }; + F49E73DA15ACCF47009C8E84 /* CCMotionStreak.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E73D915ACCF47009C8E84 /* CCMotionStreak.m */; }; + F49E73DD15ACCF47009C8E84 /* CCNode.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E73DC15ACCF47009C8E84 /* CCNode.m */; }; + F49E73E015ACCF48009C8E84 /* CCParallaxNode.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E73DF15ACCF48009C8E84 /* CCParallaxNode.m */; }; + F49E73E315ACCF48009C8E84 /* CCParticleExamples.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E73E215ACCF48009C8E84 /* CCParticleExamples.m */; }; + F49E73E615ACCF48009C8E84 /* CCParticleSystem.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E73E515ACCF48009C8E84 /* CCParticleSystem.m */; }; + F49E73E915ACCF48009C8E84 /* CCParticleSystemPoint.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E73E815ACCF48009C8E84 /* CCParticleSystemPoint.m */; }; + F49E73EC15ACCF48009C8E84 /* CCParticleSystemQuad.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E73EB15ACCF48009C8E84 /* CCParticleSystemQuad.m */; }; + F49E73EF15ACCF48009C8E84 /* CCProgressTimer.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E73EE15ACCF48009C8E84 /* CCProgressTimer.m */; }; + F49E73F315ACCF48009C8E84 /* CCRenderTexture.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E73F215ACCF48009C8E84 /* CCRenderTexture.m */; }; + F49E73F615ACCF48009C8E84 /* CCRibbon.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E73F515ACCF48009C8E84 /* CCRibbon.m */; }; + F49E73F915ACCF48009C8E84 /* CCScene.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E73F815ACCF48009C8E84 /* CCScene.m */; }; + F49E73FC15ACCF48009C8E84 /* CCScheduler.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E73FB15ACCF48009C8E84 /* CCScheduler.m */; }; + F49E73FF15ACCF48009C8E84 /* CCSprite.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E73FE15ACCF48009C8E84 /* CCSprite.m */; }; + F49E740215ACCF48009C8E84 /* CCSpriteBatchNode.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E740115ACCF48009C8E84 /* CCSpriteBatchNode.m */; }; + F49E740515ACCF48009C8E84 /* CCSpriteFrame.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E740415ACCF48009C8E84 /* CCSpriteFrame.m */; }; + F49E740815ACCF48009C8E84 /* CCSpriteFrameCache.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E740715ACCF48009C8E84 /* CCSpriteFrameCache.m */; }; + F49E740B15ACCF48009C8E84 /* CCTexture2D.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E740A15ACCF48009C8E84 /* CCTexture2D.m */; }; + F49E740E15ACCF48009C8E84 /* CCTextureAtlas.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E740D15ACCF48009C8E84 /* CCTextureAtlas.m */; }; + F49E741115ACCF48009C8E84 /* CCTextureCache.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E741015ACCF48009C8E84 /* CCTextureCache.m */; }; + F49E741415ACCF48009C8E84 /* CCTexturePVR.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E741315ACCF48009C8E84 /* CCTexturePVR.m */; }; + F49E741715ACCF48009C8E84 /* CCTileMapAtlas.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E741615ACCF48009C8E84 /* CCTileMapAtlas.m */; }; + F49E741A15ACCF48009C8E84 /* CCTMXLayer.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E741915ACCF48009C8E84 /* CCTMXLayer.m */; }; + F49E741D15ACCF48009C8E84 /* CCTMXObjectGroup.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E741C15ACCF48009C8E84 /* CCTMXObjectGroup.m */; }; + F49E742015ACCF48009C8E84 /* CCTMXTiledMap.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E741F15ACCF48009C8E84 /* CCTMXTiledMap.m */; }; + F49E742315ACCF48009C8E84 /* CCTMXXMLParser.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E742215ACCF48009C8E84 /* CCTMXXMLParser.m */; }; + F49E742615ACCF48009C8E84 /* CCTransition.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E742515ACCF48009C8E84 /* CCTransition.m */; }; + F49E742915ACCF48009C8E84 /* CCTransitionPageTurn.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E742815ACCF48009C8E84 /* CCTransitionPageTurn.m */; }; + F49E742C15ACCF48009C8E84 /* CCTransitionRadial.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E742B15ACCF48009C8E84 /* CCTransitionRadial.m */; }; + F49E743015ACCF48009C8E84 /* cocos2d.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E742F15ACCF48009C8E84 /* cocos2d.m */; }; + F49E743715ACCF48009C8E84 /* CCDirectorIOS.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E743615ACCF48009C8E84 /* CCDirectorIOS.m */; }; + F49E743B15ACCF48009C8E84 /* CCTouchDispatcher.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E743A15ACCF48009C8E84 /* CCTouchDispatcher.m */; }; + F49E743E15ACCF48009C8E84 /* CCTouchHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E743D15ACCF48009C8E84 /* CCTouchHandler.m */; }; + F49E744115ACCF49009C8E84 /* EAGLView.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E744015ACCF49009C8E84 /* EAGLView.m */; }; + F49E744415ACCF49009C8E84 /* ES1Renderer.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E744315ACCF49009C8E84 /* ES1Renderer.m */; }; + F49E744715ACCF49009C8E84 /* glu.c in Sources */ = {isa = PBXBuildFile; fileRef = F49E744615ACCF49009C8E84 /* glu.c */; }; + F49E744C15ACCF49009C8E84 /* CCDirectorMac.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E744B15ACCF49009C8E84 /* CCDirectorMac.m */; }; + F49E744F15ACCF49009C8E84 /* CCEventDispatcher.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E744E15ACCF49009C8E84 /* CCEventDispatcher.m */; }; + F49E745215ACCF49009C8E84 /* MacGLView.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E745115ACCF49009C8E84 /* MacGLView.m */; }; + F49E745515ACCF49009C8E84 /* MacWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E745415ACCF49009C8E84 /* MacWindow.m */; }; + F49E745815ACCF49009C8E84 /* base64.c in Sources */ = {isa = PBXBuildFile; fileRef = F49E745715ACCF49009C8E84 /* base64.c */; }; + F49E745C15ACCF49009C8E84 /* CCArray.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E745B15ACCF49009C8E84 /* CCArray.m */; }; + F49E746015ACCF49009C8E84 /* CCFileUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E745F15ACCF49009C8E84 /* CCFileUtils.m */; }; + F49E746315ACCF49009C8E84 /* CCProfiling.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E746215ACCF49009C8E84 /* CCProfiling.m */; }; + F49E746515ACCF49009C8E84 /* ccUtils.c in Sources */ = {isa = PBXBuildFile; fileRef = F49E746415ACCF49009C8E84 /* ccUtils.c */; }; + F49E746915ACCF49009C8E84 /* CGPointExtension.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E746815ACCF49009C8E84 /* CGPointExtension.m */; }; + F49E746D15ACCF49009C8E84 /* TGAlib.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E746C15ACCF49009C8E84 /* TGAlib.m */; }; + F49E747015ACCF49009C8E84 /* TransformUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E746F15ACCF49009C8E84 /* TransformUtils.m */; }; + F49E747515ACCF49009C8E84 /* ZipUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E747415ACCF49009C8E84 /* ZipUtils.m */; }; + F49E74AA15ACCF4A009C8E84 /* FontLabel.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E74A915ACCF4A009C8E84 /* FontLabel.m */; }; + F49E74AD15ACCF4A009C8E84 /* FontLabelStringDrawing.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E74AC15ACCF4A009C8E84 /* FontLabelStringDrawing.m */; }; + F49E74B015ACCF4A009C8E84 /* FontManager.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E74AF15ACCF4A009C8E84 /* FontManager.m */; }; + F49E74B315ACCF4A009C8E84 /* ZAttributedString.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E74B215ACCF4A009C8E84 /* ZAttributedString.m */; }; + F49E74B715ACCF4A009C8E84 /* ZFont.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E74B615ACCF4A009C8E84 /* ZFont.m */; }; + F49E74BC15ACCF4A009C8E84 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E74BB15ACCF4A009C8E84 /* main.m */; }; + F49E74BF15ACCF4A009C8E84 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E74BE15ACCF4A009C8E84 /* AppDelegate.m */; }; + F49E74C215ACCF4A009C8E84 /* RootViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F49E74C115ACCF4A009C8E84 /* RootViewController.m */; }; + F4D0CBD415ACD01C007C74DF /* Game.m in Sources */ = {isa = PBXBuildFile; fileRef = F4D0CBCF15ACD01C007C74DF /* Game.m */; }; + F4D0CBD515ACD01C007C74DF /* Highscores.m in Sources */ = {isa = PBXBuildFile; fileRef = F4D0CBD115ACD01C007C74DF /* Highscores.m */; }; + F4D0CBD615ACD01C007C74DF /* Main.m in Sources */ = {isa = PBXBuildFile; fileRef = F4D0CBD315ACD01C007C74DF /* Main.m */; }; + F4D0CBDF15ACD027007C74DF /* bitmapFont.fnt in Resources */ = {isa = PBXBuildFile; fileRef = F4D0CBD915ACD027007C74DF /* bitmapFont.fnt */; }; + F4D0CBE015ACD027007C74DF /* bitmapFont.png in Resources */ = {isa = PBXBuildFile; fileRef = F4D0CBDA15ACD027007C74DF /* bitmapFont.png */; }; + F4D0CBE115ACD027007C74DF /* changePlayerButton.png in Resources */ = {isa = PBXBuildFile; fileRef = F4D0CBDC15ACD027007C74DF /* changePlayerButton.png */; }; + F4D0CBE215ACD027007C74DF /* playAgainButton.png in Resources */ = {isa = PBXBuildFile; fileRef = F4D0CBDD15ACD027007C74DF /* playAgainButton.png */; }; + F4D0CBE315ACD027007C74DF /* sprites.png in Resources */ = {isa = PBXBuildFile; fileRef = F4D0CBDE15ACD027007C74DF /* sprites.png */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ - 1D30AB110D05D00D00671497 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; - 1D6058910D05DD3D006BFB54 /* tweejump.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = tweejump.app; sourceTree = BUILT_PRODUCTS_DIR; }; - 1DF5F4DF0D08C38300B7A737 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; - 28FD14FF0DC6FC520079059D /* OpenGLES.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGLES.framework; path = System/Library/Frameworks/OpenGLES.framework; sourceTree = SDKROOT; }; - 28FD15070DC6FC5B0079059D /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; }; - 29B97316FDCFA39411CA2CEA /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; - 32CA4F630368D1EE00C91783 /* Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Prefix.pch; path = tweejump_Prefix.pch; sourceTree = ""; }; - 4D0631D50FC3007F008ECEEE /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; - 4D0631E90FC30572008ECEEE /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; - 4D0631EA0FC30572008ECEEE /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; - 4D2C560B0FCD447F00331A7C /* sprites.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = sprites.png; path = Images/sprites.png; sourceTree = ""; }; - 4D5448260FD48DF30010F348 /* Main.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Main.h; sourceTree = ""; }; - 4D5448270FD48DF30010F348 /* Main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Main.m; sourceTree = ""; }; - 4D5449CF0FD4D67A0010F348 /* Highscores.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Highscores.m; sourceTree = ""; }; - 4D5449D00FD4D67A0010F348 /* Highscores.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Highscores.h; sourceTree = ""; }; - 4D544A9A0FD4EEFF0010F348 /* playAgainButton.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = playAgainButton.png; path = Images/playAgainButton.png; sourceTree = ""; }; - 4D544A9B0FD4EEFF0010F348 /* changePlayerButton.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = changePlayerButton.png; path = Images/changePlayerButton.png; sourceTree = ""; }; - 4D5555010FDE56B0004554D7 /* Default.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Default.png; path = Images/Default.png; sourceTree = ""; }; - 4D74D76F0FD6B36900C364B4 /* bitmapFont.fnt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = bitmapFont.fnt; path = Images/bitmapFont.fnt; sourceTree = ""; }; - 4D74D7710FD6B36D00C364B4 /* bitmapFont.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = bitmapFont.png; path = Images/bitmapFont.png; sourceTree = ""; }; - 4D857DE00FD740E200B350BA /* icon.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = icon.png; path = Images/icon.png; sourceTree = ""; }; - 4DD0435A0FC9081800897B73 /* Action.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Action.h; sourceTree = ""; }; - 4DD0435B0FC9081800897B73 /* Action.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Action.m; sourceTree = ""; }; - 4DD0435C0FC9081800897B73 /* AtlasNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AtlasNode.h; sourceTree = ""; }; - 4DD0435D0FC9081800897B73 /* AtlasNode.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AtlasNode.m; sourceTree = ""; }; - 4DD0435E0FC9081800897B73 /* AtlasSprite.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AtlasSprite.h; sourceTree = ""; }; - 4DD0435F0FC9081800897B73 /* AtlasSprite.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AtlasSprite.m; sourceTree = ""; }; - 4DD043600FC9081800897B73 /* AtlasSpriteManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AtlasSpriteManager.h; sourceTree = ""; }; - 4DD043610FC9081800897B73 /* AtlasSpriteManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AtlasSpriteManager.m; sourceTree = ""; }; - 4DD043620FC9081800897B73 /* BitmapFontAtlas.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BitmapFontAtlas.h; sourceTree = ""; }; - 4DD043630FC9081800897B73 /* BitmapFontAtlas.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BitmapFontAtlas.m; sourceTree = ""; }; - 4DD043640FC9081800897B73 /* Camera.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Camera.h; sourceTree = ""; }; - 4DD043650FC9081800897B73 /* Camera.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Camera.m; sourceTree = ""; }; - 4DD043660FC9081800897B73 /* CameraAction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CameraAction.h; sourceTree = ""; }; - 4DD043670FC9081800897B73 /* CameraAction.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CameraAction.m; sourceTree = ""; }; - 4DD043680FC9081800897B73 /* ccExceptions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ccExceptions.h; sourceTree = ""; }; - 4DD043690FC9081800897B73 /* ccMacros.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ccMacros.h; sourceTree = ""; }; - 4DD0436A0FC9081800897B73 /* ccTypes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ccTypes.h; sourceTree = ""; }; - 4DD0436B0FC9081800897B73 /* cocos2d.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cocos2d.h; sourceTree = ""; }; - 4DD0436C0FC9081800897B73 /* cocos2d.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = cocos2d.m; sourceTree = ""; }; - 4DD0436D0FC9081800897B73 /* CocosNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CocosNode.h; sourceTree = ""; }; - 4DD0436E0FC9081800897B73 /* CocosNode.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CocosNode.m; sourceTree = ""; }; - 4DD0436F0FC9081800897B73 /* Director.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Director.h; sourceTree = ""; }; - 4DD043700FC9081800897B73 /* Director.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Director.m; sourceTree = ""; }; - 4DD043710FC9081800897B73 /* EaseAction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EaseAction.h; sourceTree = ""; }; - 4DD043720FC9081800897B73 /* EaseAction.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EaseAction.m; sourceTree = ""; }; - 4DD043730FC9081800897B73 /* Grabber.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Grabber.h; sourceTree = ""; }; - 4DD043740FC9081800897B73 /* Grabber.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Grabber.m; sourceTree = ""; }; - 4DD043750FC9081800897B73 /* Grid.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Grid.h; sourceTree = ""; }; - 4DD043760FC9081800897B73 /* Grid.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Grid.m; sourceTree = ""; }; - 4DD043770FC9081800897B73 /* Grid3DAction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Grid3DAction.h; sourceTree = ""; }; - 4DD043780FC9081800897B73 /* Grid3DAction.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Grid3DAction.m; sourceTree = ""; }; - 4DD043790FC9081800897B73 /* GridAction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GridAction.h; sourceTree = ""; }; - 4DD0437A0FC9081800897B73 /* GridAction.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GridAction.m; sourceTree = ""; }; - 4DD0437B0FC9081800897B73 /* InstantAction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InstantAction.h; sourceTree = ""; }; - 4DD0437C0FC9081800897B73 /* InstantAction.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = InstantAction.m; sourceTree = ""; }; - 4DD0437D0FC9081800897B73 /* IntervalAction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IntervalAction.h; sourceTree = ""; }; - 4DD0437E0FC9081800897B73 /* IntervalAction.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IntervalAction.m; sourceTree = ""; }; - 4DD0437F0FC9081800897B73 /* Label.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Label.h; sourceTree = ""; }; - 4DD043800FC9081800897B73 /* Label.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Label.m; sourceTree = ""; }; - 4DD043810FC9081800897B73 /* LabelAtlas.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LabelAtlas.h; sourceTree = ""; }; - 4DD043820FC9081800897B73 /* LabelAtlas.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LabelAtlas.m; sourceTree = ""; }; - 4DD043830FC9081800897B73 /* Layer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Layer.h; sourceTree = ""; }; - 4DD043840FC9081800897B73 /* Layer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Layer.m; sourceTree = ""; }; - 4DD043850FC9081800897B73 /* Menu.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Menu.h; sourceTree = ""; }; - 4DD043860FC9081800897B73 /* Menu.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Menu.m; sourceTree = ""; }; - 4DD043870FC9081800897B73 /* MenuItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MenuItem.h; sourceTree = ""; }; - 4DD043880FC9081800897B73 /* MenuItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MenuItem.m; sourceTree = ""; }; - 4DD043890FC9081800897B73 /* ParallaxNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ParallaxNode.h; sourceTree = ""; }; - 4DD0438A0FC9081800897B73 /* ParallaxNode.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ParallaxNode.m; sourceTree = ""; }; - 4DD0438B0FC9081800897B73 /* ParticleExamples.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ParticleExamples.h; sourceTree = ""; }; - 4DD0438C0FC9081800897B73 /* ParticleExamples.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ParticleExamples.m; sourceTree = ""; }; - 4DD0438D0FC9081800897B73 /* ParticleSystem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ParticleSystem.h; sourceTree = ""; }; - 4DD0438E0FC9081800897B73 /* ParticleSystem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ParticleSystem.m; sourceTree = ""; }; - 4DD0438F0FC9081800897B73 /* PointParticleSystem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PointParticleSystem.h; sourceTree = ""; }; - 4DD043900FC9081800897B73 /* PointParticleSystem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PointParticleSystem.m; sourceTree = ""; }; - 4DD043910FC9081800897B73 /* Primitives.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Primitives.h; sourceTree = ""; }; - 4DD043920FC9081800897B73 /* Primitives.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Primitives.m; sourceTree = ""; }; - 4DD043930FC9081800897B73 /* QuadParticleSystem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QuadParticleSystem.h; sourceTree = ""; }; - 4DD043940FC9081800897B73 /* QuadParticleSystem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QuadParticleSystem.m; sourceTree = ""; }; - 4DD043950FC9081800897B73 /* Scene.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Scene.h; sourceTree = ""; }; - 4DD043960FC9081800897B73 /* Scene.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Scene.m; sourceTree = ""; }; - 4DD043970FC9081800897B73 /* Scheduler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Scheduler.h; sourceTree = ""; }; - 4DD043980FC9081800897B73 /* Scheduler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Scheduler.m; sourceTree = ""; }; - 4DD043990FC9081800897B73 /* Sprite.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Sprite.h; sourceTree = ""; }; - 4DD0439A0FC9081800897B73 /* Sprite.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Sprite.m; sourceTree = ""; }; - 4DD0439C0FC9081800897B73 /* ccArray.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ccArray.h; sourceTree = ""; }; - 4DD0439D0FC9081800897B73 /* CGPointExtension.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CGPointExtension.h; sourceTree = ""; }; - 4DD0439E0FC9081800897B73 /* CGPointExtension.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CGPointExtension.m; sourceTree = ""; }; - 4DD0439F0FC9081800897B73 /* EAGLView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EAGLView.h; sourceTree = ""; }; - 4DD043A00FC9081800897B73 /* EAGLView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EAGLView.m; sourceTree = ""; }; - 4DD043A10FC9081800897B73 /* FileUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FileUtils.h; sourceTree = ""; }; - 4DD043A20FC9081800897B73 /* FileUtils.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FileUtils.m; sourceTree = ""; }; - 4DD043A30FC9081800897B73 /* glu.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = glu.c; sourceTree = ""; }; - 4DD043A40FC9081800897B73 /* glu.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = glu.h; sourceTree = ""; }; - 4DD043A50FC9081800897B73 /* OpenGL_Internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OpenGL_Internal.h; sourceTree = ""; }; - 4DD043A60FC9081800897B73 /* PVRTexture.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PVRTexture.h; sourceTree = ""; }; - 4DD043A70FC9081800897B73 /* PVRTexture.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PVRTexture.m; sourceTree = ""; }; - 4DD043A80FC9081800897B73 /* Texture2D.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Texture2D.h; sourceTree = ""; }; - 4DD043A90FC9081800897B73 /* Texture2D.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Texture2D.m; sourceTree = ""; }; - 4DD043AA0FC9081800897B73 /* TGAlib.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TGAlib.h; sourceTree = ""; }; - 4DD043AB0FC9081800897B73 /* TGAlib.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TGAlib.m; sourceTree = ""; }; - 4DD043AC0FC9081800897B73 /* TransformUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TransformUtils.h; sourceTree = ""; }; - 4DD043AD0FC9081800897B73 /* TransformUtils.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TransformUtils.m; sourceTree = ""; }; - 4DD043AE0FC9081800897B73 /* UIColor-OpenGL.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIColor-OpenGL.h"; sourceTree = ""; }; - 4DD043AF0FC9081800897B73 /* UIColor-OpenGL.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIColor-OpenGL.m"; sourceTree = ""; }; - 4DD043B00FC9081800897B73 /* TargetedTouchDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TargetedTouchDelegate.h; sourceTree = ""; }; - 4DD043B10FC9081800897B73 /* TextureAtlas.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextureAtlas.h; sourceTree = ""; }; - 4DD043B20FC9081800897B73 /* TextureAtlas.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TextureAtlas.m; sourceTree = ""; }; - 4DD043B30FC9081800897B73 /* TextureMgr.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextureMgr.h; sourceTree = ""; }; - 4DD043B40FC9081800897B73 /* TextureMgr.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TextureMgr.m; sourceTree = ""; }; - 4DD043B50FC9081800897B73 /* TextureNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextureNode.h; sourceTree = ""; }; - 4DD043B60FC9081800897B73 /* TextureNode.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TextureNode.m; sourceTree = ""; }; - 4DD043B70FC9081800897B73 /* TiledGridAction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TiledGridAction.h; sourceTree = ""; }; - 4DD043B80FC9081800897B73 /* TiledGridAction.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TiledGridAction.m; sourceTree = ""; }; - 4DD043B90FC9081800897B73 /* TileMapAtlas.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TileMapAtlas.h; sourceTree = ""; }; - 4DD043BA0FC9081800897B73 /* TileMapAtlas.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TileMapAtlas.m; sourceTree = ""; }; - 4DD043BB0FC9081800897B73 /* TouchDispatcher.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TouchDispatcher.h; sourceTree = ""; }; - 4DD043BC0FC9081800897B73 /* TouchDispatcher.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TouchDispatcher.m; sourceTree = ""; }; - 4DD043BD0FC9081800897B73 /* TouchHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TouchHandler.h; sourceTree = ""; }; - 4DD043BE0FC9081800897B73 /* TouchHandler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TouchHandler.m; sourceTree = ""; }; - 4DD043BF0FC9081800897B73 /* Transition.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Transition.h; sourceTree = ""; }; - 4DD043C00FC9081800897B73 /* Transition.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Transition.m; sourceTree = ""; }; - 4DD044C80FC918D300897B73 /* Game.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Game.h; sourceTree = ""; }; - 4DD044C90FC918D300897B73 /* Game.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Game.m; sourceTree = ""; }; - 8D1107310486CEB800E47090 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + F49E735715ACCF46009C8E84 /* tweejump.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = tweejump.app; sourceTree = BUILT_PRODUCTS_DIR; }; + F49E735B15ACCF46009C8E84 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; }; + F49E735D15ACCF46009C8E84 /* OpenGLES.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGLES.framework; path = System/Library/Frameworks/OpenGLES.framework; sourceTree = SDKROOT; }; + F49E735F15ACCF46009C8E84 /* OpenAL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenAL.framework; path = System/Library/Frameworks/OpenAL.framework; sourceTree = SDKROOT; }; + F49E736115ACCF46009C8E84 /* AudioToolbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioToolbox.framework; path = System/Library/Frameworks/AudioToolbox.framework; sourceTree = SDKROOT; }; + F49E736315ACCF46009C8E84 /* AVFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AVFoundation.framework; path = System/Library/Frameworks/AVFoundation.framework; sourceTree = SDKROOT; }; + F49E736515ACCF46009C8E84 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; + F49E736715ACCF46009C8E84 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; + F49E736915ACCF46009C8E84 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; + F49E736D15ACCF46009C8E84 /* Default.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Default.png; path = Resources/Default.png; sourceTree = ""; }; + F49E736F15ACCF46009C8E84 /* fps_images.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = fps_images.png; path = Resources/fps_images.png; sourceTree = ""; }; + F49E737115ACCF47009C8E84 /* Icon-72.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "Icon-72.png"; path = "Resources/Icon-72.png"; sourceTree = ""; }; + F49E737315ACCF47009C8E84 /* Icon-Small-50.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "Icon-Small-50.png"; path = "Resources/Icon-Small-50.png"; sourceTree = ""; }; + F49E737515ACCF47009C8E84 /* Icon-Small.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "Icon-Small.png"; path = "Resources/Icon-Small.png"; sourceTree = ""; }; + F49E737715ACCF47009C8E84 /* Icon-Small@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "Icon-Small@2x.png"; path = "Resources/Icon-Small@2x.png"; sourceTree = ""; }; + F49E737915ACCF47009C8E84 /* Icon.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Icon.png; path = Resources/Icon.png; sourceTree = ""; }; + F49E737B15ACCF47009C8E84 /* Icon@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "Icon@2x.png"; path = "Resources/Icon@2x.png"; sourceTree = ""; }; + F49E737D15ACCF47009C8E84 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = Info.plist; path = Resources/Info.plist; sourceTree = ""; }; + F49E737E15ACCF47009C8E84 /* iTunesArtwork */ = {isa = PBXFileReference; lastKnownFileType = file; name = iTunesArtwork; path = Resources/iTunesArtwork; sourceTree = ""; }; + F49E738215ACCF47009C8E84 /* CCAction.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CCAction.h; path = libs/cocos2d/CCAction.h; sourceTree = ""; }; + F49E738315ACCF47009C8E84 /* CCAction.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CCAction.m; path = libs/cocos2d/CCAction.m; sourceTree = ""; }; + F49E738515ACCF47009C8E84 /* CCActionCamera.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CCActionCamera.h; path = libs/cocos2d/CCActionCamera.h; sourceTree = ""; }; + F49E738615ACCF47009C8E84 /* CCActionCamera.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CCActionCamera.m; path = libs/cocos2d/CCActionCamera.m; sourceTree = ""; }; + F49E738815ACCF47009C8E84 /* CCActionEase.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CCActionEase.h; path = libs/cocos2d/CCActionEase.h; sourceTree = ""; }; + F49E738915ACCF47009C8E84 /* CCActionEase.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CCActionEase.m; path = libs/cocos2d/CCActionEase.m; sourceTree = ""; }; + F49E738B15ACCF47009C8E84 /* CCActionGrid.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CCActionGrid.h; path = libs/cocos2d/CCActionGrid.h; sourceTree = ""; }; + F49E738C15ACCF47009C8E84 /* CCActionGrid.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CCActionGrid.m; path = libs/cocos2d/CCActionGrid.m; sourceTree = ""; }; + F49E738E15ACCF47009C8E84 /* CCActionGrid3D.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CCActionGrid3D.h; path = libs/cocos2d/CCActionGrid3D.h; sourceTree = ""; }; + F49E738F15ACCF47009C8E84 /* CCActionGrid3D.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CCActionGrid3D.m; path = libs/cocos2d/CCActionGrid3D.m; sourceTree = ""; }; + F49E739115ACCF47009C8E84 /* CCActionInstant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CCActionInstant.h; path = libs/cocos2d/CCActionInstant.h; sourceTree = ""; }; + F49E739215ACCF47009C8E84 /* CCActionInstant.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CCActionInstant.m; path = libs/cocos2d/CCActionInstant.m; sourceTree = ""; }; + F49E739415ACCF47009C8E84 /* CCActionInterval.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CCActionInterval.h; path = libs/cocos2d/CCActionInterval.h; sourceTree = ""; }; + F49E739515ACCF47009C8E84 /* CCActionInterval.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CCActionInterval.m; path = libs/cocos2d/CCActionInterval.m; sourceTree = ""; }; + F49E739715ACCF47009C8E84 /* CCActionManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CCActionManager.h; path = libs/cocos2d/CCActionManager.h; sourceTree = ""; }; + F49E739815ACCF47009C8E84 /* CCActionManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CCActionManager.m; path = libs/cocos2d/CCActionManager.m; sourceTree = ""; }; + F49E739A15ACCF47009C8E84 /* CCActionPageTurn3D.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CCActionPageTurn3D.h; path = libs/cocos2d/CCActionPageTurn3D.h; sourceTree = ""; }; + F49E739B15ACCF47009C8E84 /* CCActionPageTurn3D.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CCActionPageTurn3D.m; path = libs/cocos2d/CCActionPageTurn3D.m; sourceTree = ""; }; + F49E739D15ACCF47009C8E84 /* CCActionProgressTimer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CCActionProgressTimer.h; path = libs/cocos2d/CCActionProgressTimer.h; sourceTree = ""; }; + F49E739E15ACCF47009C8E84 /* CCActionProgressTimer.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CCActionProgressTimer.m; path = libs/cocos2d/CCActionProgressTimer.m; sourceTree = ""; }; + F49E73A015ACCF47009C8E84 /* CCActionTiledGrid.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CCActionTiledGrid.h; path = libs/cocos2d/CCActionTiledGrid.h; sourceTree = ""; }; + F49E73A115ACCF47009C8E84 /* CCActionTiledGrid.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CCActionTiledGrid.m; path = libs/cocos2d/CCActionTiledGrid.m; sourceTree = ""; }; + F49E73A315ACCF47009C8E84 /* CCActionTween.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CCActionTween.h; path = libs/cocos2d/CCActionTween.h; sourceTree = ""; }; + F49E73A415ACCF47009C8E84 /* CCActionTween.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CCActionTween.m; path = libs/cocos2d/CCActionTween.m; sourceTree = ""; }; + F49E73A615ACCF47009C8E84 /* CCAnimation.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CCAnimation.h; path = libs/cocos2d/CCAnimation.h; sourceTree = ""; }; + F49E73A715ACCF47009C8E84 /* CCAnimation.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CCAnimation.m; path = libs/cocos2d/CCAnimation.m; sourceTree = ""; }; + F49E73A915ACCF47009C8E84 /* CCAnimationCache.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CCAnimationCache.h; path = libs/cocos2d/CCAnimationCache.h; sourceTree = ""; }; + F49E73AA15ACCF47009C8E84 /* CCAnimationCache.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CCAnimationCache.m; path = libs/cocos2d/CCAnimationCache.m; sourceTree = ""; }; + F49E73AC15ACCF47009C8E84 /* CCAtlasNode.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CCAtlasNode.h; path = libs/cocos2d/CCAtlasNode.h; sourceTree = ""; }; + F49E73AD15ACCF47009C8E84 /* CCAtlasNode.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CCAtlasNode.m; path = libs/cocos2d/CCAtlasNode.m; sourceTree = ""; }; + F49E73AF15ACCF47009C8E84 /* CCBlockSupport.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CCBlockSupport.h; path = libs/cocos2d/CCBlockSupport.h; sourceTree = ""; }; + F49E73B015ACCF47009C8E84 /* CCBlockSupport.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CCBlockSupport.m; path = libs/cocos2d/CCBlockSupport.m; sourceTree = ""; }; + F49E73B215ACCF47009C8E84 /* CCCamera.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CCCamera.h; path = libs/cocos2d/CCCamera.h; sourceTree = ""; }; + F49E73B315ACCF47009C8E84 /* CCCamera.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CCCamera.m; path = libs/cocos2d/CCCamera.m; sourceTree = ""; }; + F49E73B515ACCF47009C8E84 /* ccConfig.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ccConfig.h; path = libs/cocos2d/ccConfig.h; sourceTree = ""; }; + F49E73B615ACCF47009C8E84 /* CCConfiguration.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CCConfiguration.h; path = libs/cocos2d/CCConfiguration.h; sourceTree = ""; }; + F49E73B715ACCF47009C8E84 /* CCConfiguration.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CCConfiguration.m; path = libs/cocos2d/CCConfiguration.m; sourceTree = ""; }; + F49E73B915ACCF47009C8E84 /* CCDirector.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CCDirector.h; path = libs/cocos2d/CCDirector.h; sourceTree = ""; }; + F49E73BA15ACCF47009C8E84 /* CCDirector.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CCDirector.m; path = libs/cocos2d/CCDirector.m; sourceTree = ""; }; + F49E73BC15ACCF47009C8E84 /* CCDrawingPrimitives.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CCDrawingPrimitives.h; path = libs/cocos2d/CCDrawingPrimitives.h; sourceTree = ""; }; + F49E73BD15ACCF47009C8E84 /* CCDrawingPrimitives.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CCDrawingPrimitives.m; path = libs/cocos2d/CCDrawingPrimitives.m; sourceTree = ""; }; + F49E73BF15ACCF47009C8E84 /* CCGrabber.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CCGrabber.h; path = libs/cocos2d/CCGrabber.h; sourceTree = ""; }; + F49E73C015ACCF47009C8E84 /* CCGrabber.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CCGrabber.m; path = libs/cocos2d/CCGrabber.m; sourceTree = ""; }; + F49E73C215ACCF47009C8E84 /* CCGrid.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CCGrid.h; path = libs/cocos2d/CCGrid.h; sourceTree = ""; }; + F49E73C315ACCF47009C8E84 /* CCGrid.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CCGrid.m; path = libs/cocos2d/CCGrid.m; sourceTree = ""; }; + F49E73C515ACCF47009C8E84 /* CCLabelAtlas.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CCLabelAtlas.h; path = libs/cocos2d/CCLabelAtlas.h; sourceTree = ""; }; + F49E73C615ACCF47009C8E84 /* CCLabelAtlas.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CCLabelAtlas.m; path = libs/cocos2d/CCLabelAtlas.m; sourceTree = ""; }; + F49E73C815ACCF47009C8E84 /* CCLabelBMFont.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CCLabelBMFont.h; path = libs/cocos2d/CCLabelBMFont.h; sourceTree = ""; }; + F49E73C915ACCF47009C8E84 /* CCLabelBMFont.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CCLabelBMFont.m; path = libs/cocos2d/CCLabelBMFont.m; sourceTree = ""; }; + F49E73CB15ACCF47009C8E84 /* CCLabelTTF.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CCLabelTTF.h; path = libs/cocos2d/CCLabelTTF.h; sourceTree = ""; }; + F49E73CC15ACCF47009C8E84 /* CCLabelTTF.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CCLabelTTF.m; path = libs/cocos2d/CCLabelTTF.m; sourceTree = ""; }; + F49E73CE15ACCF47009C8E84 /* CCLayer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CCLayer.h; path = libs/cocos2d/CCLayer.h; sourceTree = ""; }; + F49E73CF15ACCF47009C8E84 /* CCLayer.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CCLayer.m; path = libs/cocos2d/CCLayer.m; sourceTree = ""; }; + F49E73D115ACCF47009C8E84 /* ccMacros.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ccMacros.h; path = libs/cocos2d/ccMacros.h; sourceTree = ""; }; + F49E73D215ACCF47009C8E84 /* CCMenu.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CCMenu.h; path = libs/cocos2d/CCMenu.h; sourceTree = ""; }; + F49E73D315ACCF47009C8E84 /* CCMenu.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CCMenu.m; path = libs/cocos2d/CCMenu.m; sourceTree = ""; }; + F49E73D515ACCF47009C8E84 /* CCMenuItem.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CCMenuItem.h; path = libs/cocos2d/CCMenuItem.h; sourceTree = ""; }; + F49E73D615ACCF47009C8E84 /* CCMenuItem.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CCMenuItem.m; path = libs/cocos2d/CCMenuItem.m; sourceTree = ""; }; + F49E73D815ACCF47009C8E84 /* CCMotionStreak.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CCMotionStreak.h; path = libs/cocos2d/CCMotionStreak.h; sourceTree = ""; }; + F49E73D915ACCF47009C8E84 /* CCMotionStreak.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CCMotionStreak.m; path = libs/cocos2d/CCMotionStreak.m; sourceTree = ""; }; + F49E73DB15ACCF47009C8E84 /* CCNode.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CCNode.h; path = libs/cocos2d/CCNode.h; sourceTree = ""; }; + F49E73DC15ACCF47009C8E84 /* CCNode.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CCNode.m; path = libs/cocos2d/CCNode.m; sourceTree = ""; }; + F49E73DE15ACCF47009C8E84 /* CCParallaxNode.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CCParallaxNode.h; path = libs/cocos2d/CCParallaxNode.h; sourceTree = ""; }; + F49E73DF15ACCF48009C8E84 /* CCParallaxNode.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CCParallaxNode.m; path = libs/cocos2d/CCParallaxNode.m; sourceTree = ""; }; + F49E73E115ACCF48009C8E84 /* CCParticleExamples.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CCParticleExamples.h; path = libs/cocos2d/CCParticleExamples.h; sourceTree = ""; }; + F49E73E215ACCF48009C8E84 /* CCParticleExamples.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CCParticleExamples.m; path = libs/cocos2d/CCParticleExamples.m; sourceTree = ""; }; + F49E73E415ACCF48009C8E84 /* CCParticleSystem.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CCParticleSystem.h; path = libs/cocos2d/CCParticleSystem.h; sourceTree = ""; }; + F49E73E515ACCF48009C8E84 /* CCParticleSystem.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CCParticleSystem.m; path = libs/cocos2d/CCParticleSystem.m; sourceTree = ""; }; + F49E73E715ACCF48009C8E84 /* CCParticleSystemPoint.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CCParticleSystemPoint.h; path = libs/cocos2d/CCParticleSystemPoint.h; sourceTree = ""; }; + F49E73E815ACCF48009C8E84 /* CCParticleSystemPoint.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CCParticleSystemPoint.m; path = libs/cocos2d/CCParticleSystemPoint.m; sourceTree = ""; }; + F49E73EA15ACCF48009C8E84 /* CCParticleSystemQuad.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CCParticleSystemQuad.h; path = libs/cocos2d/CCParticleSystemQuad.h; sourceTree = ""; }; + F49E73EB15ACCF48009C8E84 /* CCParticleSystemQuad.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CCParticleSystemQuad.m; path = libs/cocos2d/CCParticleSystemQuad.m; sourceTree = ""; }; + F49E73ED15ACCF48009C8E84 /* CCProgressTimer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CCProgressTimer.h; path = libs/cocos2d/CCProgressTimer.h; sourceTree = ""; }; + F49E73EE15ACCF48009C8E84 /* CCProgressTimer.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CCProgressTimer.m; path = libs/cocos2d/CCProgressTimer.m; sourceTree = ""; }; + F49E73F015ACCF48009C8E84 /* CCProtocols.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CCProtocols.h; path = libs/cocos2d/CCProtocols.h; sourceTree = ""; }; + F49E73F115ACCF48009C8E84 /* CCRenderTexture.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CCRenderTexture.h; path = libs/cocos2d/CCRenderTexture.h; sourceTree = ""; }; + F49E73F215ACCF48009C8E84 /* CCRenderTexture.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CCRenderTexture.m; path = libs/cocos2d/CCRenderTexture.m; sourceTree = ""; }; + F49E73F415ACCF48009C8E84 /* CCRibbon.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CCRibbon.h; path = libs/cocos2d/CCRibbon.h; sourceTree = ""; }; + F49E73F515ACCF48009C8E84 /* CCRibbon.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CCRibbon.m; path = libs/cocos2d/CCRibbon.m; sourceTree = ""; }; + F49E73F715ACCF48009C8E84 /* CCScene.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CCScene.h; path = libs/cocos2d/CCScene.h; sourceTree = ""; }; + F49E73F815ACCF48009C8E84 /* CCScene.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CCScene.m; path = libs/cocos2d/CCScene.m; sourceTree = ""; }; + F49E73FA15ACCF48009C8E84 /* CCScheduler.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CCScheduler.h; path = libs/cocos2d/CCScheduler.h; sourceTree = ""; }; + F49E73FB15ACCF48009C8E84 /* CCScheduler.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CCScheduler.m; path = libs/cocos2d/CCScheduler.m; sourceTree = ""; }; + F49E73FD15ACCF48009C8E84 /* CCSprite.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CCSprite.h; path = libs/cocos2d/CCSprite.h; sourceTree = ""; }; + F49E73FE15ACCF48009C8E84 /* CCSprite.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CCSprite.m; path = libs/cocos2d/CCSprite.m; sourceTree = ""; }; + F49E740015ACCF48009C8E84 /* CCSpriteBatchNode.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CCSpriteBatchNode.h; path = libs/cocos2d/CCSpriteBatchNode.h; sourceTree = ""; }; + F49E740115ACCF48009C8E84 /* CCSpriteBatchNode.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CCSpriteBatchNode.m; path = libs/cocos2d/CCSpriteBatchNode.m; sourceTree = ""; }; + F49E740315ACCF48009C8E84 /* CCSpriteFrame.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CCSpriteFrame.h; path = libs/cocos2d/CCSpriteFrame.h; sourceTree = ""; }; + F49E740415ACCF48009C8E84 /* CCSpriteFrame.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CCSpriteFrame.m; path = libs/cocos2d/CCSpriteFrame.m; sourceTree = ""; }; + F49E740615ACCF48009C8E84 /* CCSpriteFrameCache.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CCSpriteFrameCache.h; path = libs/cocos2d/CCSpriteFrameCache.h; sourceTree = ""; }; + F49E740715ACCF48009C8E84 /* CCSpriteFrameCache.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CCSpriteFrameCache.m; path = libs/cocos2d/CCSpriteFrameCache.m; sourceTree = ""; }; + F49E740915ACCF48009C8E84 /* CCTexture2D.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CCTexture2D.h; path = libs/cocos2d/CCTexture2D.h; sourceTree = ""; }; + F49E740A15ACCF48009C8E84 /* CCTexture2D.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CCTexture2D.m; path = libs/cocos2d/CCTexture2D.m; sourceTree = ""; }; + F49E740C15ACCF48009C8E84 /* CCTextureAtlas.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CCTextureAtlas.h; path = libs/cocos2d/CCTextureAtlas.h; sourceTree = ""; }; + F49E740D15ACCF48009C8E84 /* CCTextureAtlas.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CCTextureAtlas.m; path = libs/cocos2d/CCTextureAtlas.m; sourceTree = ""; }; + F49E740F15ACCF48009C8E84 /* CCTextureCache.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CCTextureCache.h; path = libs/cocos2d/CCTextureCache.h; sourceTree = ""; }; + F49E741015ACCF48009C8E84 /* CCTextureCache.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CCTextureCache.m; path = libs/cocos2d/CCTextureCache.m; sourceTree = ""; }; + F49E741215ACCF48009C8E84 /* CCTexturePVR.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CCTexturePVR.h; path = libs/cocos2d/CCTexturePVR.h; sourceTree = ""; }; + F49E741315ACCF48009C8E84 /* CCTexturePVR.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CCTexturePVR.m; path = libs/cocos2d/CCTexturePVR.m; sourceTree = ""; }; + F49E741515ACCF48009C8E84 /* CCTileMapAtlas.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CCTileMapAtlas.h; path = libs/cocos2d/CCTileMapAtlas.h; sourceTree = ""; }; + F49E741615ACCF48009C8E84 /* CCTileMapAtlas.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CCTileMapAtlas.m; path = libs/cocos2d/CCTileMapAtlas.m; sourceTree = ""; }; + F49E741815ACCF48009C8E84 /* CCTMXLayer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CCTMXLayer.h; path = libs/cocos2d/CCTMXLayer.h; sourceTree = ""; }; + F49E741915ACCF48009C8E84 /* CCTMXLayer.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CCTMXLayer.m; path = libs/cocos2d/CCTMXLayer.m; sourceTree = ""; }; + F49E741B15ACCF48009C8E84 /* CCTMXObjectGroup.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CCTMXObjectGroup.h; path = libs/cocos2d/CCTMXObjectGroup.h; sourceTree = ""; }; + F49E741C15ACCF48009C8E84 /* CCTMXObjectGroup.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CCTMXObjectGroup.m; path = libs/cocos2d/CCTMXObjectGroup.m; sourceTree = ""; }; + F49E741E15ACCF48009C8E84 /* CCTMXTiledMap.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CCTMXTiledMap.h; path = libs/cocos2d/CCTMXTiledMap.h; sourceTree = ""; }; + F49E741F15ACCF48009C8E84 /* CCTMXTiledMap.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CCTMXTiledMap.m; path = libs/cocos2d/CCTMXTiledMap.m; sourceTree = ""; }; + F49E742115ACCF48009C8E84 /* CCTMXXMLParser.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CCTMXXMLParser.h; path = libs/cocos2d/CCTMXXMLParser.h; sourceTree = ""; }; + F49E742215ACCF48009C8E84 /* CCTMXXMLParser.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CCTMXXMLParser.m; path = libs/cocos2d/CCTMXXMLParser.m; sourceTree = ""; }; + F49E742415ACCF48009C8E84 /* CCTransition.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CCTransition.h; path = libs/cocos2d/CCTransition.h; sourceTree = ""; }; + F49E742515ACCF48009C8E84 /* CCTransition.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CCTransition.m; path = libs/cocos2d/CCTransition.m; sourceTree = ""; }; + F49E742715ACCF48009C8E84 /* CCTransitionPageTurn.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CCTransitionPageTurn.h; path = libs/cocos2d/CCTransitionPageTurn.h; sourceTree = ""; }; + F49E742815ACCF48009C8E84 /* CCTransitionPageTurn.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CCTransitionPageTurn.m; path = libs/cocos2d/CCTransitionPageTurn.m; sourceTree = ""; }; + F49E742A15ACCF48009C8E84 /* CCTransitionRadial.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CCTransitionRadial.h; path = libs/cocos2d/CCTransitionRadial.h; sourceTree = ""; }; + F49E742B15ACCF48009C8E84 /* CCTransitionRadial.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CCTransitionRadial.m; path = libs/cocos2d/CCTransitionRadial.m; sourceTree = ""; }; + F49E742D15ACCF48009C8E84 /* ccTypes.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ccTypes.h; path = libs/cocos2d/ccTypes.h; sourceTree = ""; }; + F49E742E15ACCF48009C8E84 /* cocos2d.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = cocos2d.h; path = libs/cocos2d/cocos2d.h; sourceTree = ""; }; + F49E742F15ACCF48009C8E84 /* cocos2d.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = cocos2d.m; path = libs/cocos2d/cocos2d.m; sourceTree = ""; }; + F49E743215ACCF48009C8E84 /* CCGL.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CCGL.h; path = libs/cocos2d/Platforms/CCGL.h; sourceTree = ""; }; + F49E743315ACCF48009C8E84 /* CCNS.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CCNS.h; path = libs/cocos2d/Platforms/CCNS.h; sourceTree = ""; }; + F49E743515ACCF48009C8E84 /* CCDirectorIOS.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CCDirectorIOS.h; path = libs/cocos2d/Platforms/iOS/CCDirectorIOS.h; sourceTree = ""; }; + F49E743615ACCF48009C8E84 /* CCDirectorIOS.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CCDirectorIOS.m; path = libs/cocos2d/Platforms/iOS/CCDirectorIOS.m; sourceTree = ""; }; + F49E743815ACCF48009C8E84 /* CCTouchDelegateProtocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CCTouchDelegateProtocol.h; path = libs/cocos2d/Platforms/iOS/CCTouchDelegateProtocol.h; sourceTree = ""; }; + F49E743915ACCF48009C8E84 /* CCTouchDispatcher.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CCTouchDispatcher.h; path = libs/cocos2d/Platforms/iOS/CCTouchDispatcher.h; sourceTree = ""; }; + F49E743A15ACCF48009C8E84 /* CCTouchDispatcher.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CCTouchDispatcher.m; path = libs/cocos2d/Platforms/iOS/CCTouchDispatcher.m; sourceTree = ""; }; + F49E743C15ACCF48009C8E84 /* CCTouchHandler.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CCTouchHandler.h; path = libs/cocos2d/Platforms/iOS/CCTouchHandler.h; sourceTree = ""; }; + F49E743D15ACCF48009C8E84 /* CCTouchHandler.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CCTouchHandler.m; path = libs/cocos2d/Platforms/iOS/CCTouchHandler.m; sourceTree = ""; }; + F49E743F15ACCF49009C8E84 /* EAGLView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = EAGLView.h; path = libs/cocos2d/Platforms/iOS/EAGLView.h; sourceTree = ""; }; + F49E744015ACCF49009C8E84 /* EAGLView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = EAGLView.m; path = libs/cocos2d/Platforms/iOS/EAGLView.m; sourceTree = ""; }; + F49E744215ACCF49009C8E84 /* ES1Renderer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ES1Renderer.h; path = libs/cocos2d/Platforms/iOS/ES1Renderer.h; sourceTree = ""; }; + F49E744315ACCF49009C8E84 /* ES1Renderer.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = ES1Renderer.m; path = libs/cocos2d/Platforms/iOS/ES1Renderer.m; sourceTree = ""; }; + F49E744515ACCF49009C8E84 /* ESRenderer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ESRenderer.h; path = libs/cocos2d/Platforms/iOS/ESRenderer.h; sourceTree = ""; }; + F49E744615ACCF49009C8E84 /* glu.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = glu.c; path = libs/cocos2d/Platforms/iOS/glu.c; sourceTree = ""; }; + F49E744815ACCF49009C8E84 /* glu.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = glu.h; path = libs/cocos2d/Platforms/iOS/glu.h; sourceTree = ""; }; + F49E744A15ACCF49009C8E84 /* CCDirectorMac.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CCDirectorMac.h; path = libs/cocos2d/Platforms/Mac/CCDirectorMac.h; sourceTree = ""; }; + F49E744B15ACCF49009C8E84 /* CCDirectorMac.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CCDirectorMac.m; path = libs/cocos2d/Platforms/Mac/CCDirectorMac.m; sourceTree = ""; }; + F49E744D15ACCF49009C8E84 /* CCEventDispatcher.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CCEventDispatcher.h; path = libs/cocos2d/Platforms/Mac/CCEventDispatcher.h; sourceTree = ""; }; + F49E744E15ACCF49009C8E84 /* CCEventDispatcher.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CCEventDispatcher.m; path = libs/cocos2d/Platforms/Mac/CCEventDispatcher.m; sourceTree = ""; }; + F49E745015ACCF49009C8E84 /* MacGLView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = MacGLView.h; path = libs/cocos2d/Platforms/Mac/MacGLView.h; sourceTree = ""; }; + F49E745115ACCF49009C8E84 /* MacGLView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = MacGLView.m; path = libs/cocos2d/Platforms/Mac/MacGLView.m; sourceTree = ""; }; + F49E745315ACCF49009C8E84 /* MacWindow.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = MacWindow.h; path = libs/cocos2d/Platforms/Mac/MacWindow.h; sourceTree = ""; }; + F49E745415ACCF49009C8E84 /* MacWindow.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = MacWindow.m; path = libs/cocos2d/Platforms/Mac/MacWindow.m; sourceTree = ""; }; + F49E745715ACCF49009C8E84 /* base64.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = base64.c; path = libs/cocos2d/Support/base64.c; sourceTree = ""; }; + F49E745915ACCF49009C8E84 /* base64.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = base64.h; path = libs/cocos2d/Support/base64.h; sourceTree = ""; }; + F49E745A15ACCF49009C8E84 /* CCArray.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CCArray.h; path = libs/cocos2d/Support/CCArray.h; sourceTree = ""; }; + F49E745B15ACCF49009C8E84 /* CCArray.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CCArray.m; path = libs/cocos2d/Support/CCArray.m; sourceTree = ""; }; + F49E745D15ACCF49009C8E84 /* ccCArray.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ccCArray.h; path = libs/cocos2d/Support/ccCArray.h; sourceTree = ""; }; + F49E745E15ACCF49009C8E84 /* CCFileUtils.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CCFileUtils.h; path = libs/cocos2d/Support/CCFileUtils.h; sourceTree = ""; }; + F49E745F15ACCF49009C8E84 /* CCFileUtils.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CCFileUtils.m; path = libs/cocos2d/Support/CCFileUtils.m; sourceTree = ""; }; + F49E746115ACCF49009C8E84 /* CCProfiling.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CCProfiling.h; path = libs/cocos2d/Support/CCProfiling.h; sourceTree = ""; }; + F49E746215ACCF49009C8E84 /* CCProfiling.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CCProfiling.m; path = libs/cocos2d/Support/CCProfiling.m; sourceTree = ""; }; + F49E746415ACCF49009C8E84 /* ccUtils.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = ccUtils.c; path = libs/cocos2d/Support/ccUtils.c; sourceTree = ""; }; + F49E746615ACCF49009C8E84 /* ccUtils.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ccUtils.h; path = libs/cocos2d/Support/ccUtils.h; sourceTree = ""; }; + F49E746715ACCF49009C8E84 /* CGPointExtension.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CGPointExtension.h; path = libs/cocos2d/Support/CGPointExtension.h; sourceTree = ""; }; + F49E746815ACCF49009C8E84 /* CGPointExtension.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CGPointExtension.m; path = libs/cocos2d/Support/CGPointExtension.m; sourceTree = ""; }; + F49E746A15ACCF49009C8E84 /* OpenGL_Internal.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = OpenGL_Internal.h; path = libs/cocos2d/Support/OpenGL_Internal.h; sourceTree = ""; }; + F49E746B15ACCF49009C8E84 /* TGAlib.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = TGAlib.h; path = libs/cocos2d/Support/TGAlib.h; sourceTree = ""; }; + F49E746C15ACCF49009C8E84 /* TGAlib.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = TGAlib.m; path = libs/cocos2d/Support/TGAlib.m; sourceTree = ""; }; + F49E746E15ACCF49009C8E84 /* TransformUtils.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = TransformUtils.h; path = libs/cocos2d/Support/TransformUtils.h; sourceTree = ""; }; + F49E746F15ACCF49009C8E84 /* TransformUtils.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = TransformUtils.m; path = libs/cocos2d/Support/TransformUtils.m; sourceTree = ""; }; + F49E747115ACCF49009C8E84 /* uthash.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = uthash.h; path = libs/cocos2d/Support/uthash.h; sourceTree = ""; }; + F49E747215ACCF49009C8E84 /* utlist.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = utlist.h; path = libs/cocos2d/Support/utlist.h; sourceTree = ""; }; + F49E747315ACCF49009C8E84 /* ZipUtils.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ZipUtils.h; path = libs/cocos2d/Support/ZipUtils.h; sourceTree = ""; }; + F49E747415ACCF49009C8E84 /* ZipUtils.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = ZipUtils.m; path = libs/cocos2d/Support/ZipUtils.m; sourceTree = ""; }; + F49E747615ACCF49009C8E84 /* LICENSE_cocos2d.txt */ = {isa = PBXFileReference; lastKnownFileType = text; name = LICENSE_cocos2d.txt; path = libs/LICENSE_cocos2d.txt; sourceTree = ""; }; + F49E74A815ACCF4A009C8E84 /* FontLabel.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = FontLabel.h; path = libs/FontLabel/FontLabel.h; sourceTree = ""; }; + F49E74A915ACCF4A009C8E84 /* FontLabel.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = FontLabel.m; path = libs/FontLabel/FontLabel.m; sourceTree = ""; }; + F49E74AB15ACCF4A009C8E84 /* FontLabelStringDrawing.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = FontLabelStringDrawing.h; path = libs/FontLabel/FontLabelStringDrawing.h; sourceTree = ""; }; + F49E74AC15ACCF4A009C8E84 /* FontLabelStringDrawing.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = FontLabelStringDrawing.m; path = libs/FontLabel/FontLabelStringDrawing.m; sourceTree = ""; }; + F49E74AE15ACCF4A009C8E84 /* FontManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = FontManager.h; path = libs/FontLabel/FontManager.h; sourceTree = ""; }; + F49E74AF15ACCF4A009C8E84 /* FontManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = FontManager.m; path = libs/FontLabel/FontManager.m; sourceTree = ""; }; + F49E74B115ACCF4A009C8E84 /* ZAttributedString.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ZAttributedString.h; path = libs/FontLabel/ZAttributedString.h; sourceTree = ""; }; + F49E74B215ACCF4A009C8E84 /* ZAttributedString.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = ZAttributedString.m; path = libs/FontLabel/ZAttributedString.m; sourceTree = ""; }; + F49E74B415ACCF4A009C8E84 /* ZAttributedStringPrivate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ZAttributedStringPrivate.h; path = libs/FontLabel/ZAttributedStringPrivate.h; sourceTree = ""; }; + F49E74B515ACCF4A009C8E84 /* ZFont.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ZFont.h; path = libs/FontLabel/ZFont.h; sourceTree = ""; }; + F49E74B615ACCF4A009C8E84 /* ZFont.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = ZFont.m; path = libs/FontLabel/ZFont.m; sourceTree = ""; }; + F49E74B815ACCF4A009C8E84 /* LICENSE_FontLabel.txt */ = {isa = PBXFileReference; lastKnownFileType = text; name = LICENSE_FontLabel.txt; path = libs/LICENSE_FontLabel.txt; sourceTree = ""; }; + F49E74BA15ACCF4A009C8E84 /* Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Prefix.pch; sourceTree = ""; }; + F49E74BB15ACCF4A009C8E84 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; + F49E74BD15ACCF4A009C8E84 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; + F49E74BE15ACCF4A009C8E84 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; + F49E74C015ACCF4A009C8E84 /* RootViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RootViewController.h; sourceTree = ""; }; + F49E74C115ACCF4A009C8E84 /* RootViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RootViewController.m; sourceTree = ""; }; + F49E74C615ACCF4A009C8E84 /* GameConfig.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GameConfig.h; sourceTree = ""; }; + F4D0CBCE15ACD01C007C74DF /* Game.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Game.h; sourceTree = ""; }; + F4D0CBCF15ACD01C007C74DF /* Game.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Game.m; sourceTree = ""; }; + F4D0CBD015ACD01C007C74DF /* Highscores.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Highscores.h; sourceTree = ""; }; + F4D0CBD115ACD01C007C74DF /* Highscores.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Highscores.m; sourceTree = ""; }; + F4D0CBD215ACD01C007C74DF /* Main.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Main.h; sourceTree = ""; }; + F4D0CBD315ACD01C007C74DF /* Main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Main.m; sourceTree = ""; }; + F4D0CBD915ACD027007C74DF /* bitmapFont.fnt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = bitmapFont.fnt; sourceTree = ""; }; + F4D0CBDA15ACD027007C74DF /* bitmapFont.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = bitmapFont.png; sourceTree = ""; }; + F4D0CBDC15ACD027007C74DF /* changePlayerButton.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = changePlayerButton.png; sourceTree = ""; }; + F4D0CBDD15ACD027007C74DF /* playAgainButton.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = playAgainButton.png; sourceTree = ""; }; + F4D0CBDE15ACD027007C74DF /* sprites.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = sprites.png; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ - 1D60588F0D05DD3D006BFB54 /* Frameworks */ = { + F49E735415ACCF46009C8E84 /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 1D60589F0D05DD5A006BFB54 /* Foundation.framework in Frameworks */, - 1DF5F4E00D08C38300B7A737 /* UIKit.framework in Frameworks */, - 28FD15000DC6FC520079059D /* OpenGLES.framework in Frameworks */, - 28FD15080DC6FC5B0079059D /* QuartzCore.framework in Frameworks */, - 4D0631D60FC3007F008ECEEE /* CoreGraphics.framework in Frameworks */, + F49E735C15ACCF46009C8E84 /* QuartzCore.framework in Frameworks */, + F49E735E15ACCF46009C8E84 /* OpenGLES.framework in Frameworks */, + F49E736015ACCF46009C8E84 /* OpenAL.framework in Frameworks */, + F49E736215ACCF46009C8E84 /* AudioToolbox.framework in Frameworks */, + F49E736415ACCF46009C8E84 /* AVFoundation.framework in Frameworks */, + F49E736615ACCF46009C8E84 /* UIKit.framework in Frameworks */, + F49E736815ACCF46009C8E84 /* Foundation.framework in Frameworks */, + F49E736A15ACCF46009C8E84 /* CoreGraphics.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ - 080E96DDFE201D6D7F000001 /* Classes */ = { + F49E734C15ACCF46009C8E84 = { isa = PBXGroup; children = ( - 4D0631EA0FC30572008ECEEE /* AppDelegate.h */, - 4D0631E90FC30572008ECEEE /* AppDelegate.m */, - 4D5448260FD48DF30010F348 /* Main.h */, - 4D5448270FD48DF30010F348 /* Main.m */, - 4DD044C80FC918D300897B73 /* Game.h */, - 4DD044C90FC918D300897B73 /* Game.m */, - 4D5449D00FD4D67A0010F348 /* Highscores.h */, - 4D5449CF0FD4D67A0010F348 /* Highscores.m */, + F49E736B15ACCF46009C8E84 /* tweejump */, + F49E735A15ACCF46009C8E84 /* Frameworks */, + F49E735815ACCF46009C8E84 /* Products */, ); - path = Classes; sourceTree = ""; }; - 19C28FACFE9D520D11CA2CBB /* Products */ = { + F49E735815ACCF46009C8E84 /* Products */ = { isa = PBXGroup; children = ( - 1D6058910D05DD3D006BFB54 /* tweejump.app */, + F49E735715ACCF46009C8E84 /* tweejump.app */, ); name = Products; sourceTree = ""; }; - 29B97314FDCFA39411CA2CEA /* CustomTemplate */ = { + F49E735A15ACCF46009C8E84 /* Frameworks */ = { isa = PBXGroup; children = ( - 080E96DDFE201D6D7F000001 /* Classes */, - 4D0631D70FC30087008ECEEE /* Images */, - 29B97315FDCFA39411CA2CEA /* Other Sources */, - 29B97317FDCFA39411CA2CEA /* Resources */, - 4D0631D80FC30097008ECEEE /* Support */, - 29B97323FDCFA39411CA2CEA /* Frameworks */, - 19C28FACFE9D520D11CA2CBB /* Products */, + F49E735B15ACCF46009C8E84 /* QuartzCore.framework */, + F49E735D15ACCF46009C8E84 /* OpenGLES.framework */, + F49E735F15ACCF46009C8E84 /* OpenAL.framework */, + F49E736115ACCF46009C8E84 /* AudioToolbox.framework */, + F49E736315ACCF46009C8E84 /* AVFoundation.framework */, + F49E736515ACCF46009C8E84 /* UIKit.framework */, + F49E736715ACCF46009C8E84 /* Foundation.framework */, + F49E736915ACCF46009C8E84 /* CoreGraphics.framework */, ); - name = CustomTemplate; + name = Frameworks; sourceTree = ""; }; - 29B97315FDCFA39411CA2CEA /* Other Sources */ = { + F49E736B15ACCF46009C8E84 /* tweejump */ = { isa = PBXGroup; children = ( - 32CA4F630368D1EE00C91783 /* Prefix.pch */, - 29B97316FDCFA39411CA2CEA /* main.m */, + F49E74BD15ACCF4A009C8E84 /* AppDelegate.h */, + F49E74BE15ACCF4A009C8E84 /* AppDelegate.m */, + F49E74C015ACCF4A009C8E84 /* RootViewController.h */, + F49E74C115ACCF4A009C8E84 /* RootViewController.m */, + F49E74C615ACCF4A009C8E84 /* GameConfig.h */, + F4D0CBCD15ACD01C007C74DF /* Classes */, + F49E736C15ACCF46009C8E84 /* Resources */, + F49E738015ACCF47009C8E84 /* libs */, + F49E74B915ACCF4A009C8E84 /* Supporting Files */, ); - name = "Other Sources"; + path = tweejump; sourceTree = ""; }; - 29B97317FDCFA39411CA2CEA /* Resources */ = { + F49E736C15ACCF46009C8E84 /* Resources */ = { isa = PBXGroup; children = ( - 8D1107310486CEB800E47090 /* Info.plist */, + F4D0CBD815ACD027007C74DF /* Fonts */, + F4D0CBDB15ACD027007C74DF /* Images */, + F49E736D15ACCF46009C8E84 /* Default.png */, + F49E736F15ACCF46009C8E84 /* fps_images.png */, + F49E737115ACCF47009C8E84 /* Icon-72.png */, + F49E737315ACCF47009C8E84 /* Icon-Small-50.png */, + F49E737515ACCF47009C8E84 /* Icon-Small.png */, + F49E737715ACCF47009C8E84 /* Icon-Small@2x.png */, + F49E737915ACCF47009C8E84 /* Icon.png */, + F49E737B15ACCF47009C8E84 /* Icon@2x.png */, + F49E737D15ACCF47009C8E84 /* Info.plist */, + F49E737E15ACCF47009C8E84 /* iTunesArtwork */, ); name = Resources; sourceTree = ""; }; - 29B97323FDCFA39411CA2CEA /* Frameworks */ = { + F49E738015ACCF47009C8E84 /* libs */ = { isa = PBXGroup; children = ( - 4D0631D50FC3007F008ECEEE /* CoreGraphics.framework */, - 28FD15070DC6FC5B0079059D /* QuartzCore.framework */, - 28FD14FF0DC6FC520079059D /* OpenGLES.framework */, - 1DF5F4DF0D08C38300B7A737 /* UIKit.framework */, - 1D30AB110D05D00D00671497 /* Foundation.framework */, + F49E747615ACCF49009C8E84 /* LICENSE_cocos2d.txt */, + F49E74B815ACCF4A009C8E84 /* LICENSE_FontLabel.txt */, + F49E738115ACCF47009C8E84 /* cocos2d */, + F49E74A715ACCF4A009C8E84 /* FontLabel */, ); - name = Frameworks; + name = libs; sourceTree = ""; }; - 4D0631D70FC30087008ECEEE /* Images */ = { + F49E738115ACCF47009C8E84 /* cocos2d */ = { isa = PBXGroup; children = ( - 4D2C560B0FCD447F00331A7C /* sprites.png */, - 4D544A9A0FD4EEFF0010F348 /* playAgainButton.png */, - 4D544A9B0FD4EEFF0010F348 /* changePlayerButton.png */, - 4D74D76F0FD6B36900C364B4 /* bitmapFont.fnt */, - 4D74D7710FD6B36D00C364B4 /* bitmapFont.png */, - 4D857DE00FD740E200B350BA /* icon.png */, - 4D5555010FDE56B0004554D7 /* Default.png */, + F49E738215ACCF47009C8E84 /* CCAction.h */, + F49E738315ACCF47009C8E84 /* CCAction.m */, + F49E738515ACCF47009C8E84 /* CCActionCamera.h */, + F49E738615ACCF47009C8E84 /* CCActionCamera.m */, + F49E738815ACCF47009C8E84 /* CCActionEase.h */, + F49E738915ACCF47009C8E84 /* CCActionEase.m */, + F49E738B15ACCF47009C8E84 /* CCActionGrid.h */, + F49E738C15ACCF47009C8E84 /* CCActionGrid.m */, + F49E738E15ACCF47009C8E84 /* CCActionGrid3D.h */, + F49E738F15ACCF47009C8E84 /* CCActionGrid3D.m */, + F49E739115ACCF47009C8E84 /* CCActionInstant.h */, + F49E739215ACCF47009C8E84 /* CCActionInstant.m */, + F49E739415ACCF47009C8E84 /* CCActionInterval.h */, + F49E739515ACCF47009C8E84 /* CCActionInterval.m */, + F49E739715ACCF47009C8E84 /* CCActionManager.h */, + F49E739815ACCF47009C8E84 /* CCActionManager.m */, + F49E739A15ACCF47009C8E84 /* CCActionPageTurn3D.h */, + F49E739B15ACCF47009C8E84 /* CCActionPageTurn3D.m */, + F49E739D15ACCF47009C8E84 /* CCActionProgressTimer.h */, + F49E739E15ACCF47009C8E84 /* CCActionProgressTimer.m */, + F49E73A015ACCF47009C8E84 /* CCActionTiledGrid.h */, + F49E73A115ACCF47009C8E84 /* CCActionTiledGrid.m */, + F49E73A315ACCF47009C8E84 /* CCActionTween.h */, + F49E73A415ACCF47009C8E84 /* CCActionTween.m */, + F49E73A615ACCF47009C8E84 /* CCAnimation.h */, + F49E73A715ACCF47009C8E84 /* CCAnimation.m */, + F49E73A915ACCF47009C8E84 /* CCAnimationCache.h */, + F49E73AA15ACCF47009C8E84 /* CCAnimationCache.m */, + F49E73AC15ACCF47009C8E84 /* CCAtlasNode.h */, + F49E73AD15ACCF47009C8E84 /* CCAtlasNode.m */, + F49E73AF15ACCF47009C8E84 /* CCBlockSupport.h */, + F49E73B015ACCF47009C8E84 /* CCBlockSupport.m */, + F49E73B215ACCF47009C8E84 /* CCCamera.h */, + F49E73B315ACCF47009C8E84 /* CCCamera.m */, + F49E73B515ACCF47009C8E84 /* ccConfig.h */, + F49E73B615ACCF47009C8E84 /* CCConfiguration.h */, + F49E73B715ACCF47009C8E84 /* CCConfiguration.m */, + F49E73B915ACCF47009C8E84 /* CCDirector.h */, + F49E73BA15ACCF47009C8E84 /* CCDirector.m */, + F49E73BC15ACCF47009C8E84 /* CCDrawingPrimitives.h */, + F49E73BD15ACCF47009C8E84 /* CCDrawingPrimitives.m */, + F49E73BF15ACCF47009C8E84 /* CCGrabber.h */, + F49E73C015ACCF47009C8E84 /* CCGrabber.m */, + F49E73C215ACCF47009C8E84 /* CCGrid.h */, + F49E73C315ACCF47009C8E84 /* CCGrid.m */, + F49E73C515ACCF47009C8E84 /* CCLabelAtlas.h */, + F49E73C615ACCF47009C8E84 /* CCLabelAtlas.m */, + F49E73C815ACCF47009C8E84 /* CCLabelBMFont.h */, + F49E73C915ACCF47009C8E84 /* CCLabelBMFont.m */, + F49E73CB15ACCF47009C8E84 /* CCLabelTTF.h */, + F49E73CC15ACCF47009C8E84 /* CCLabelTTF.m */, + F49E73CE15ACCF47009C8E84 /* CCLayer.h */, + F49E73CF15ACCF47009C8E84 /* CCLayer.m */, + F49E73D115ACCF47009C8E84 /* ccMacros.h */, + F49E73D215ACCF47009C8E84 /* CCMenu.h */, + F49E73D315ACCF47009C8E84 /* CCMenu.m */, + F49E73D515ACCF47009C8E84 /* CCMenuItem.h */, + F49E73D615ACCF47009C8E84 /* CCMenuItem.m */, + F49E73D815ACCF47009C8E84 /* CCMotionStreak.h */, + F49E73D915ACCF47009C8E84 /* CCMotionStreak.m */, + F49E73DB15ACCF47009C8E84 /* CCNode.h */, + F49E73DC15ACCF47009C8E84 /* CCNode.m */, + F49E73DE15ACCF47009C8E84 /* CCParallaxNode.h */, + F49E73DF15ACCF48009C8E84 /* CCParallaxNode.m */, + F49E73E115ACCF48009C8E84 /* CCParticleExamples.h */, + F49E73E215ACCF48009C8E84 /* CCParticleExamples.m */, + F49E73E415ACCF48009C8E84 /* CCParticleSystem.h */, + F49E73E515ACCF48009C8E84 /* CCParticleSystem.m */, + F49E73E715ACCF48009C8E84 /* CCParticleSystemPoint.h */, + F49E73E815ACCF48009C8E84 /* CCParticleSystemPoint.m */, + F49E73EA15ACCF48009C8E84 /* CCParticleSystemQuad.h */, + F49E73EB15ACCF48009C8E84 /* CCParticleSystemQuad.m */, + F49E73ED15ACCF48009C8E84 /* CCProgressTimer.h */, + F49E73EE15ACCF48009C8E84 /* CCProgressTimer.m */, + F49E73F015ACCF48009C8E84 /* CCProtocols.h */, + F49E73F115ACCF48009C8E84 /* CCRenderTexture.h */, + F49E73F215ACCF48009C8E84 /* CCRenderTexture.m */, + F49E73F415ACCF48009C8E84 /* CCRibbon.h */, + F49E73F515ACCF48009C8E84 /* CCRibbon.m */, + F49E73F715ACCF48009C8E84 /* CCScene.h */, + F49E73F815ACCF48009C8E84 /* CCScene.m */, + F49E73FA15ACCF48009C8E84 /* CCScheduler.h */, + F49E73FB15ACCF48009C8E84 /* CCScheduler.m */, + F49E73FD15ACCF48009C8E84 /* CCSprite.h */, + F49E73FE15ACCF48009C8E84 /* CCSprite.m */, + F49E740015ACCF48009C8E84 /* CCSpriteBatchNode.h */, + F49E740115ACCF48009C8E84 /* CCSpriteBatchNode.m */, + F49E740315ACCF48009C8E84 /* CCSpriteFrame.h */, + F49E740415ACCF48009C8E84 /* CCSpriteFrame.m */, + F49E740615ACCF48009C8E84 /* CCSpriteFrameCache.h */, + F49E740715ACCF48009C8E84 /* CCSpriteFrameCache.m */, + F49E740915ACCF48009C8E84 /* CCTexture2D.h */, + F49E740A15ACCF48009C8E84 /* CCTexture2D.m */, + F49E740C15ACCF48009C8E84 /* CCTextureAtlas.h */, + F49E740D15ACCF48009C8E84 /* CCTextureAtlas.m */, + F49E740F15ACCF48009C8E84 /* CCTextureCache.h */, + F49E741015ACCF48009C8E84 /* CCTextureCache.m */, + F49E741215ACCF48009C8E84 /* CCTexturePVR.h */, + F49E741315ACCF48009C8E84 /* CCTexturePVR.m */, + F49E741515ACCF48009C8E84 /* CCTileMapAtlas.h */, + F49E741615ACCF48009C8E84 /* CCTileMapAtlas.m */, + F49E741815ACCF48009C8E84 /* CCTMXLayer.h */, + F49E741915ACCF48009C8E84 /* CCTMXLayer.m */, + F49E741B15ACCF48009C8E84 /* CCTMXObjectGroup.h */, + F49E741C15ACCF48009C8E84 /* CCTMXObjectGroup.m */, + F49E741E15ACCF48009C8E84 /* CCTMXTiledMap.h */, + F49E741F15ACCF48009C8E84 /* CCTMXTiledMap.m */, + F49E742115ACCF48009C8E84 /* CCTMXXMLParser.h */, + F49E742215ACCF48009C8E84 /* CCTMXXMLParser.m */, + F49E742415ACCF48009C8E84 /* CCTransition.h */, + F49E742515ACCF48009C8E84 /* CCTransition.m */, + F49E742715ACCF48009C8E84 /* CCTransitionPageTurn.h */, + F49E742815ACCF48009C8E84 /* CCTransitionPageTurn.m */, + F49E742A15ACCF48009C8E84 /* CCTransitionRadial.h */, + F49E742B15ACCF48009C8E84 /* CCTransitionRadial.m */, + F49E742D15ACCF48009C8E84 /* ccTypes.h */, + F49E742E15ACCF48009C8E84 /* cocos2d.h */, + F49E742F15ACCF48009C8E84 /* cocos2d.m */, + F49E743115ACCF48009C8E84 /* Platforms */, + F49E745615ACCF49009C8E84 /* Support */, ); - name = Images; + name = cocos2d; + sourceTree = ""; + }; + F49E743115ACCF48009C8E84 /* Platforms */ = { + isa = PBXGroup; + children = ( + F49E743215ACCF48009C8E84 /* CCGL.h */, + F49E743315ACCF48009C8E84 /* CCNS.h */, + F49E743415ACCF48009C8E84 /* iOS */, + F49E744915ACCF49009C8E84 /* Mac */, + ); + name = Platforms; sourceTree = ""; }; - 4D0631D80FC30097008ECEEE /* Support */ = { + F49E743415ACCF48009C8E84 /* iOS */ = { isa = PBXGroup; children = ( - 4DD043590FC9081800897B73 /* cocos2d */, + F49E743515ACCF48009C8E84 /* CCDirectorIOS.h */, + F49E743615ACCF48009C8E84 /* CCDirectorIOS.m */, + F49E743815ACCF48009C8E84 /* CCTouchDelegateProtocol.h */, + F49E743915ACCF48009C8E84 /* CCTouchDispatcher.h */, + F49E743A15ACCF48009C8E84 /* CCTouchDispatcher.m */, + F49E743C15ACCF48009C8E84 /* CCTouchHandler.h */, + F49E743D15ACCF48009C8E84 /* CCTouchHandler.m */, + F49E743F15ACCF49009C8E84 /* EAGLView.h */, + F49E744015ACCF49009C8E84 /* EAGLView.m */, + F49E744215ACCF49009C8E84 /* ES1Renderer.h */, + F49E744315ACCF49009C8E84 /* ES1Renderer.m */, + F49E744515ACCF49009C8E84 /* ESRenderer.h */, + F49E744615ACCF49009C8E84 /* glu.c */, + F49E744815ACCF49009C8E84 /* glu.h */, + ); + name = iOS; + sourceTree = ""; + }; + F49E744915ACCF49009C8E84 /* Mac */ = { + isa = PBXGroup; + children = ( + F49E744A15ACCF49009C8E84 /* CCDirectorMac.h */, + F49E744B15ACCF49009C8E84 /* CCDirectorMac.m */, + F49E744D15ACCF49009C8E84 /* CCEventDispatcher.h */, + F49E744E15ACCF49009C8E84 /* CCEventDispatcher.m */, + F49E745015ACCF49009C8E84 /* MacGLView.h */, + F49E745115ACCF49009C8E84 /* MacGLView.m */, + F49E745315ACCF49009C8E84 /* MacWindow.h */, + F49E745415ACCF49009C8E84 /* MacWindow.m */, + ); + name = Mac; + sourceTree = ""; + }; + F49E745615ACCF49009C8E84 /* Support */ = { + isa = PBXGroup; + children = ( + F49E745715ACCF49009C8E84 /* base64.c */, + F49E745915ACCF49009C8E84 /* base64.h */, + F49E745A15ACCF49009C8E84 /* CCArray.h */, + F49E745B15ACCF49009C8E84 /* CCArray.m */, + F49E745D15ACCF49009C8E84 /* ccCArray.h */, + F49E745E15ACCF49009C8E84 /* CCFileUtils.h */, + F49E745F15ACCF49009C8E84 /* CCFileUtils.m */, + F49E746115ACCF49009C8E84 /* CCProfiling.h */, + F49E746215ACCF49009C8E84 /* CCProfiling.m */, + F49E746415ACCF49009C8E84 /* ccUtils.c */, + F49E746615ACCF49009C8E84 /* ccUtils.h */, + F49E746715ACCF49009C8E84 /* CGPointExtension.h */, + F49E746815ACCF49009C8E84 /* CGPointExtension.m */, + F49E746A15ACCF49009C8E84 /* OpenGL_Internal.h */, + F49E746B15ACCF49009C8E84 /* TGAlib.h */, + F49E746C15ACCF49009C8E84 /* TGAlib.m */, + F49E746E15ACCF49009C8E84 /* TransformUtils.h */, + F49E746F15ACCF49009C8E84 /* TransformUtils.m */, + F49E747115ACCF49009C8E84 /* uthash.h */, + F49E747215ACCF49009C8E84 /* utlist.h */, + F49E747315ACCF49009C8E84 /* ZipUtils.h */, + F49E747415ACCF49009C8E84 /* ZipUtils.m */, ); name = Support; sourceTree = ""; }; - 4DD043590FC9081800897B73 /* cocos2d */ = { + F49E74A715ACCF4A009C8E84 /* FontLabel */ = { isa = PBXGroup; children = ( - 4DD0435A0FC9081800897B73 /* Action.h */, - 4DD0435B0FC9081800897B73 /* Action.m */, - 4DD0435C0FC9081800897B73 /* AtlasNode.h */, - 4DD0435D0FC9081800897B73 /* AtlasNode.m */, - 4DD0435E0FC9081800897B73 /* AtlasSprite.h */, - 4DD0435F0FC9081800897B73 /* AtlasSprite.m */, - 4DD043600FC9081800897B73 /* AtlasSpriteManager.h */, - 4DD043610FC9081800897B73 /* AtlasSpriteManager.m */, - 4DD043620FC9081800897B73 /* BitmapFontAtlas.h */, - 4DD043630FC9081800897B73 /* BitmapFontAtlas.m */, - 4DD043640FC9081800897B73 /* Camera.h */, - 4DD043650FC9081800897B73 /* Camera.m */, - 4DD043660FC9081800897B73 /* CameraAction.h */, - 4DD043670FC9081800897B73 /* CameraAction.m */, - 4DD043680FC9081800897B73 /* ccExceptions.h */, - 4DD043690FC9081800897B73 /* ccMacros.h */, - 4DD0436A0FC9081800897B73 /* ccTypes.h */, - 4DD0436B0FC9081800897B73 /* cocos2d.h */, - 4DD0436C0FC9081800897B73 /* cocos2d.m */, - 4DD0436D0FC9081800897B73 /* CocosNode.h */, - 4DD0436E0FC9081800897B73 /* CocosNode.m */, - 4DD0436F0FC9081800897B73 /* Director.h */, - 4DD043700FC9081800897B73 /* Director.m */, - 4DD043710FC9081800897B73 /* EaseAction.h */, - 4DD043720FC9081800897B73 /* EaseAction.m */, - 4DD043730FC9081800897B73 /* Grabber.h */, - 4DD043740FC9081800897B73 /* Grabber.m */, - 4DD043750FC9081800897B73 /* Grid.h */, - 4DD043760FC9081800897B73 /* Grid.m */, - 4DD043770FC9081800897B73 /* Grid3DAction.h */, - 4DD043780FC9081800897B73 /* Grid3DAction.m */, - 4DD043790FC9081800897B73 /* GridAction.h */, - 4DD0437A0FC9081800897B73 /* GridAction.m */, - 4DD0437B0FC9081800897B73 /* InstantAction.h */, - 4DD0437C0FC9081800897B73 /* InstantAction.m */, - 4DD0437D0FC9081800897B73 /* IntervalAction.h */, - 4DD0437E0FC9081800897B73 /* IntervalAction.m */, - 4DD0437F0FC9081800897B73 /* Label.h */, - 4DD043800FC9081800897B73 /* Label.m */, - 4DD043810FC9081800897B73 /* LabelAtlas.h */, - 4DD043820FC9081800897B73 /* LabelAtlas.m */, - 4DD043830FC9081800897B73 /* Layer.h */, - 4DD043840FC9081800897B73 /* Layer.m */, - 4DD043850FC9081800897B73 /* Menu.h */, - 4DD043860FC9081800897B73 /* Menu.m */, - 4DD043870FC9081800897B73 /* MenuItem.h */, - 4DD043880FC9081800897B73 /* MenuItem.m */, - 4DD043890FC9081800897B73 /* ParallaxNode.h */, - 4DD0438A0FC9081800897B73 /* ParallaxNode.m */, - 4DD0438B0FC9081800897B73 /* ParticleExamples.h */, - 4DD0438C0FC9081800897B73 /* ParticleExamples.m */, - 4DD0438D0FC9081800897B73 /* ParticleSystem.h */, - 4DD0438E0FC9081800897B73 /* ParticleSystem.m */, - 4DD0438F0FC9081800897B73 /* PointParticleSystem.h */, - 4DD043900FC9081800897B73 /* PointParticleSystem.m */, - 4DD043910FC9081800897B73 /* Primitives.h */, - 4DD043920FC9081800897B73 /* Primitives.m */, - 4DD043930FC9081800897B73 /* QuadParticleSystem.h */, - 4DD043940FC9081800897B73 /* QuadParticleSystem.m */, - 4DD043950FC9081800897B73 /* Scene.h */, - 4DD043960FC9081800897B73 /* Scene.m */, - 4DD043970FC9081800897B73 /* Scheduler.h */, - 4DD043980FC9081800897B73 /* Scheduler.m */, - 4DD043990FC9081800897B73 /* Sprite.h */, - 4DD0439A0FC9081800897B73 /* Sprite.m */, - 4DD0439B0FC9081800897B73 /* Support */, - 4DD043B00FC9081800897B73 /* TargetedTouchDelegate.h */, - 4DD043B10FC9081800897B73 /* TextureAtlas.h */, - 4DD043B20FC9081800897B73 /* TextureAtlas.m */, - 4DD043B30FC9081800897B73 /* TextureMgr.h */, - 4DD043B40FC9081800897B73 /* TextureMgr.m */, - 4DD043B50FC9081800897B73 /* TextureNode.h */, - 4DD043B60FC9081800897B73 /* TextureNode.m */, - 4DD043B70FC9081800897B73 /* TiledGridAction.h */, - 4DD043B80FC9081800897B73 /* TiledGridAction.m */, - 4DD043B90FC9081800897B73 /* TileMapAtlas.h */, - 4DD043BA0FC9081800897B73 /* TileMapAtlas.m */, - 4DD043BB0FC9081800897B73 /* TouchDispatcher.h */, - 4DD043BC0FC9081800897B73 /* TouchDispatcher.m */, - 4DD043BD0FC9081800897B73 /* TouchHandler.h */, - 4DD043BE0FC9081800897B73 /* TouchHandler.m */, - 4DD043BF0FC9081800897B73 /* Transition.h */, - 4DD043C00FC9081800897B73 /* Transition.m */, + F49E74A815ACCF4A009C8E84 /* FontLabel.h */, + F49E74A915ACCF4A009C8E84 /* FontLabel.m */, + F49E74AB15ACCF4A009C8E84 /* FontLabelStringDrawing.h */, + F49E74AC15ACCF4A009C8E84 /* FontLabelStringDrawing.m */, + F49E74AE15ACCF4A009C8E84 /* FontManager.h */, + F49E74AF15ACCF4A009C8E84 /* FontManager.m */, + F49E74B115ACCF4A009C8E84 /* ZAttributedString.h */, + F49E74B215ACCF4A009C8E84 /* ZAttributedString.m */, + F49E74B415ACCF4A009C8E84 /* ZAttributedStringPrivate.h */, + F49E74B515ACCF4A009C8E84 /* ZFont.h */, + F49E74B615ACCF4A009C8E84 /* ZFont.m */, ); - name = cocos2d; - path = Support/cocos2d; + name = FontLabel; sourceTree = ""; }; - 4DD0439B0FC9081800897B73 /* Support */ = { + F49E74B915ACCF4A009C8E84 /* Supporting Files */ = { isa = PBXGroup; children = ( - 4DD0439C0FC9081800897B73 /* ccArray.h */, - 4DD0439D0FC9081800897B73 /* CGPointExtension.h */, - 4DD0439E0FC9081800897B73 /* CGPointExtension.m */, - 4DD0439F0FC9081800897B73 /* EAGLView.h */, - 4DD043A00FC9081800897B73 /* EAGLView.m */, - 4DD043A10FC9081800897B73 /* FileUtils.h */, - 4DD043A20FC9081800897B73 /* FileUtils.m */, - 4DD043A30FC9081800897B73 /* glu.c */, - 4DD043A40FC9081800897B73 /* glu.h */, - 4DD043A50FC9081800897B73 /* OpenGL_Internal.h */, - 4DD043A60FC9081800897B73 /* PVRTexture.h */, - 4DD043A70FC9081800897B73 /* PVRTexture.m */, - 4DD043A80FC9081800897B73 /* Texture2D.h */, - 4DD043A90FC9081800897B73 /* Texture2D.m */, - 4DD043AA0FC9081800897B73 /* TGAlib.h */, - 4DD043AB0FC9081800897B73 /* TGAlib.m */, - 4DD043AC0FC9081800897B73 /* TransformUtils.h */, - 4DD043AD0FC9081800897B73 /* TransformUtils.m */, - 4DD043AE0FC9081800897B73 /* UIColor-OpenGL.h */, - 4DD043AF0FC9081800897B73 /* UIColor-OpenGL.m */, + F49E74BA15ACCF4A009C8E84 /* Prefix.pch */, + F49E74BB15ACCF4A009C8E84 /* main.m */, ); - path = Support; + name = "Supporting Files"; + sourceTree = ""; + }; + F4D0CBCD15ACD01C007C74DF /* Classes */ = { + isa = PBXGroup; + children = ( + F4D0CBCE15ACD01C007C74DF /* Game.h */, + F4D0CBCF15ACD01C007C74DF /* Game.m */, + F4D0CBD015ACD01C007C74DF /* Highscores.h */, + F4D0CBD115ACD01C007C74DF /* Highscores.m */, + F4D0CBD215ACD01C007C74DF /* Main.h */, + F4D0CBD315ACD01C007C74DF /* Main.m */, + ); + path = Classes; + sourceTree = ""; + }; + F4D0CBD815ACD027007C74DF /* Fonts */ = { + isa = PBXGroup; + children = ( + F4D0CBD915ACD027007C74DF /* bitmapFont.fnt */, + F4D0CBDA15ACD027007C74DF /* bitmapFont.png */, + ); + name = Fonts; + path = Resources/Fonts; + sourceTree = ""; + }; + F4D0CBDB15ACD027007C74DF /* Images */ = { + isa = PBXGroup; + children = ( + F4D0CBDC15ACD027007C74DF /* changePlayerButton.png */, + F4D0CBDD15ACD027007C74DF /* playAgainButton.png */, + F4D0CBDE15ACD027007C74DF /* sprites.png */, + ); + name = Images; + path = Resources/Images; sourceTree = ""; }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ - 1D6058900D05DD3D006BFB54 /* tweejump */ = { + F49E735615ACCF46009C8E84 /* tweejump */ = { isa = PBXNativeTarget; - buildConfigurationList = 1D6058960D05DD3E006BFB54 /* Build configuration list for PBXNativeTarget "tweejump" */; + buildConfigurationList = F49E74C915ACCF4A009C8E84 /* Build configuration list for PBXNativeTarget "tweejump" */; buildPhases = ( - 1D60588D0D05DD3D006BFB54 /* Resources */, - 1D60588E0D05DD3D006BFB54 /* Sources */, - 1D60588F0D05DD3D006BFB54 /* Frameworks */, + F49E735315ACCF46009C8E84 /* Sources */, + F49E735415ACCF46009C8E84 /* Frameworks */, + F49E735515ACCF46009C8E84 /* Resources */, ); buildRules = ( ); @@ -442,221 +712,252 @@ ); name = tweejump; productName = tweejump; - productReference = 1D6058910D05DD3D006BFB54 /* tweejump.app */; + productReference = F49E735715ACCF46009C8E84 /* tweejump.app */; productType = "com.apple.product-type.application"; }; /* End PBXNativeTarget section */ /* Begin PBXProject section */ - 29B97313FDCFA39411CA2CEA /* Project object */ = { + F49E734E15ACCF46009C8E84 /* Project object */ = { isa = PBXProject; - buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "tweejump" */; - compatibilityVersion = "Xcode 3.1"; - hasScannedForEncodings = 1; - mainGroup = 29B97314FDCFA39411CA2CEA /* CustomTemplate */; + attributes = { + LastUpgradeCheck = 0430; + ORGANIZATIONNAME = Symetrix; + }; + buildConfigurationList = F49E735115ACCF46009C8E84 /* Build configuration list for PBXProject "tweejump" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + ); + mainGroup = F49E734C15ACCF46009C8E84; + productRefGroup = F49E735815ACCF46009C8E84 /* Products */; projectDirPath = ""; projectRoot = ""; targets = ( - 1D6058900D05DD3D006BFB54 /* tweejump */, + F49E735615ACCF46009C8E84 /* tweejump */, ); }; /* End PBXProject section */ /* Begin PBXResourcesBuildPhase section */ - 1D60588D0D05DD3D006BFB54 /* Resources */ = { + F49E735515ACCF46009C8E84 /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( - 4D2C560C0FCD447F00331A7C /* sprites.png in Resources */, - 4D544A9C0FD4EEFF0010F348 /* playAgainButton.png in Resources */, - 4D544A9D0FD4EEFF0010F348 /* changePlayerButton.png in Resources */, - 4D74D7700FD6B36900C364B4 /* bitmapFont.fnt in Resources */, - 4D74D7720FD6B36D00C364B4 /* bitmapFont.png in Resources */, - 4D857DE10FD740E200B350BA /* icon.png in Resources */, - 4D5555020FDE56B0004554D7 /* Default.png in Resources */, + F49E736E15ACCF46009C8E84 /* Default.png in Resources */, + F49E737015ACCF46009C8E84 /* fps_images.png in Resources */, + F49E737215ACCF47009C8E84 /* Icon-72.png in Resources */, + F49E737415ACCF47009C8E84 /* Icon-Small-50.png in Resources */, + F49E737615ACCF47009C8E84 /* Icon-Small.png in Resources */, + F49E737815ACCF47009C8E84 /* Icon-Small@2x.png in Resources */, + F49E737A15ACCF47009C8E84 /* Icon.png in Resources */, + F49E737F15ACCF47009C8E84 /* iTunesArtwork in Resources */, + F4D0CBDF15ACD027007C74DF /* bitmapFont.fnt in Resources */, + F4D0CBE015ACD027007C74DF /* bitmapFont.png in Resources */, + F4D0CBE115ACD027007C74DF /* changePlayerButton.png in Resources */, + F4D0CBE215ACD027007C74DF /* playAgainButton.png in Resources */, + F4D0CBE315ACD027007C74DF /* sprites.png in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXResourcesBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ - 1D60588E0D05DD3D006BFB54 /* Sources */ = { + F49E735315ACCF46009C8E84 /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 1D60589B0D05DD56006BFB54 /* main.m in Sources */, - 4D0631EB0FC30572008ECEEE /* AppDelegate.m in Sources */, - 4DD043C10FC9081800897B73 /* Action.m in Sources */, - 4DD043C20FC9081800897B73 /* AtlasNode.m in Sources */, - 4DD043C30FC9081800897B73 /* AtlasSprite.m in Sources */, - 4DD043C40FC9081800897B73 /* AtlasSpriteManager.m in Sources */, - 4DD043C50FC9081800897B73 /* BitmapFontAtlas.m in Sources */, - 4DD043C60FC9081800897B73 /* Camera.m in Sources */, - 4DD043C70FC9081800897B73 /* CameraAction.m in Sources */, - 4DD043C80FC9081800897B73 /* cocos2d.m in Sources */, - 4DD043C90FC9081800897B73 /* CocosNode.m in Sources */, - 4DD043CA0FC9081800897B73 /* Director.m in Sources */, - 4DD043CB0FC9081800897B73 /* EaseAction.m in Sources */, - 4DD043CC0FC9081800897B73 /* Grabber.m in Sources */, - 4DD043CD0FC9081800897B73 /* Grid.m in Sources */, - 4DD043CE0FC9081800897B73 /* Grid3DAction.m in Sources */, - 4DD043CF0FC9081800897B73 /* GridAction.m in Sources */, - 4DD043D00FC9081800897B73 /* InstantAction.m in Sources */, - 4DD043D10FC9081800897B73 /* IntervalAction.m in Sources */, - 4DD043D20FC9081800897B73 /* Label.m in Sources */, - 4DD043D30FC9081800897B73 /* LabelAtlas.m in Sources */, - 4DD043D40FC9081800897B73 /* Layer.m in Sources */, - 4DD043D50FC9081800897B73 /* Menu.m in Sources */, - 4DD043D60FC9081800897B73 /* MenuItem.m in Sources */, - 4DD043D70FC9081800897B73 /* ParallaxNode.m in Sources */, - 4DD043D80FC9081800897B73 /* ParticleExamples.m in Sources */, - 4DD043D90FC9081800897B73 /* ParticleSystem.m in Sources */, - 4DD043DA0FC9081800897B73 /* PointParticleSystem.m in Sources */, - 4DD043DB0FC9081800897B73 /* Primitives.m in Sources */, - 4DD043DC0FC9081800897B73 /* QuadParticleSystem.m in Sources */, - 4DD043DD0FC9081800897B73 /* Scene.m in Sources */, - 4DD043DE0FC9081800897B73 /* Scheduler.m in Sources */, - 4DD043DF0FC9081800897B73 /* Sprite.m in Sources */, - 4DD043E00FC9081800897B73 /* CGPointExtension.m in Sources */, - 4DD043E10FC9081800897B73 /* EAGLView.m in Sources */, - 4DD043E20FC9081800897B73 /* FileUtils.m in Sources */, - 4DD043E30FC9081800897B73 /* glu.c in Sources */, - 4DD043E40FC9081800897B73 /* PVRTexture.m in Sources */, - 4DD043E50FC9081800897B73 /* Texture2D.m in Sources */, - 4DD043E60FC9081800897B73 /* TGAlib.m in Sources */, - 4DD043E70FC9081800897B73 /* TransformUtils.m in Sources */, - 4DD043E80FC9081800897B73 /* UIColor-OpenGL.m in Sources */, - 4DD043E90FC9081800897B73 /* TextureAtlas.m in Sources */, - 4DD043EA0FC9081800897B73 /* TextureMgr.m in Sources */, - 4DD043EB0FC9081800897B73 /* TextureNode.m in Sources */, - 4DD043EC0FC9081800897B73 /* TiledGridAction.m in Sources */, - 4DD043ED0FC9081800897B73 /* TileMapAtlas.m in Sources */, - 4DD043EE0FC9081800897B73 /* TouchDispatcher.m in Sources */, - 4DD043EF0FC9081800897B73 /* TouchHandler.m in Sources */, - 4DD043F00FC9081800897B73 /* Transition.m in Sources */, - 4DD044CA0FC918D300897B73 /* Game.m in Sources */, - 4D5448280FD48DF30010F348 /* Main.m in Sources */, - 4D5449D10FD4D67A0010F348 /* Highscores.m in Sources */, + F49E738415ACCF47009C8E84 /* CCAction.m in Sources */, + F49E738715ACCF47009C8E84 /* CCActionCamera.m in Sources */, + F49E738A15ACCF47009C8E84 /* CCActionEase.m in Sources */, + F49E738D15ACCF47009C8E84 /* CCActionGrid.m in Sources */, + F49E739015ACCF47009C8E84 /* CCActionGrid3D.m in Sources */, + F49E739315ACCF47009C8E84 /* CCActionInstant.m in Sources */, + F49E739615ACCF47009C8E84 /* CCActionInterval.m in Sources */, + F49E739915ACCF47009C8E84 /* CCActionManager.m in Sources */, + F49E739C15ACCF47009C8E84 /* CCActionPageTurn3D.m in Sources */, + F49E739F15ACCF47009C8E84 /* CCActionProgressTimer.m in Sources */, + F49E73A215ACCF47009C8E84 /* CCActionTiledGrid.m in Sources */, + F49E73A515ACCF47009C8E84 /* CCActionTween.m in Sources */, + F49E73A815ACCF47009C8E84 /* CCAnimation.m in Sources */, + F49E73AB15ACCF47009C8E84 /* CCAnimationCache.m in Sources */, + F49E73AE15ACCF47009C8E84 /* CCAtlasNode.m in Sources */, + F49E73B115ACCF47009C8E84 /* CCBlockSupport.m in Sources */, + F49E73B415ACCF47009C8E84 /* CCCamera.m in Sources */, + F49E73B815ACCF47009C8E84 /* CCConfiguration.m in Sources */, + F49E73BB15ACCF47009C8E84 /* CCDirector.m in Sources */, + F49E73BE15ACCF47009C8E84 /* CCDrawingPrimitives.m in Sources */, + F49E73C115ACCF47009C8E84 /* CCGrabber.m in Sources */, + F49E73C415ACCF47009C8E84 /* CCGrid.m in Sources */, + F49E73C715ACCF47009C8E84 /* CCLabelAtlas.m in Sources */, + F49E73CA15ACCF47009C8E84 /* CCLabelBMFont.m in Sources */, + F49E73CD15ACCF47009C8E84 /* CCLabelTTF.m in Sources */, + F49E73D015ACCF47009C8E84 /* CCLayer.m in Sources */, + F49E73D415ACCF47009C8E84 /* CCMenu.m in Sources */, + F49E73D715ACCF47009C8E84 /* CCMenuItem.m in Sources */, + F49E73DA15ACCF47009C8E84 /* CCMotionStreak.m in Sources */, + F49E73DD15ACCF47009C8E84 /* CCNode.m in Sources */, + F49E73E015ACCF48009C8E84 /* CCParallaxNode.m in Sources */, + F49E73E315ACCF48009C8E84 /* CCParticleExamples.m in Sources */, + F49E73E615ACCF48009C8E84 /* CCParticleSystem.m in Sources */, + F49E73E915ACCF48009C8E84 /* CCParticleSystemPoint.m in Sources */, + F49E73EC15ACCF48009C8E84 /* CCParticleSystemQuad.m in Sources */, + F49E73EF15ACCF48009C8E84 /* CCProgressTimer.m in Sources */, + F49E73F315ACCF48009C8E84 /* CCRenderTexture.m in Sources */, + F49E73F615ACCF48009C8E84 /* CCRibbon.m in Sources */, + F49E73F915ACCF48009C8E84 /* CCScene.m in Sources */, + F49E73FC15ACCF48009C8E84 /* CCScheduler.m in Sources */, + F49E73FF15ACCF48009C8E84 /* CCSprite.m in Sources */, + F49E740215ACCF48009C8E84 /* CCSpriteBatchNode.m in Sources */, + F49E740515ACCF48009C8E84 /* CCSpriteFrame.m in Sources */, + F49E740815ACCF48009C8E84 /* CCSpriteFrameCache.m in Sources */, + F49E740B15ACCF48009C8E84 /* CCTexture2D.m in Sources */, + F49E740E15ACCF48009C8E84 /* CCTextureAtlas.m in Sources */, + F49E741115ACCF48009C8E84 /* CCTextureCache.m in Sources */, + F49E741415ACCF48009C8E84 /* CCTexturePVR.m in Sources */, + F49E741715ACCF48009C8E84 /* CCTileMapAtlas.m in Sources */, + F49E741A15ACCF48009C8E84 /* CCTMXLayer.m in Sources */, + F49E741D15ACCF48009C8E84 /* CCTMXObjectGroup.m in Sources */, + F49E742015ACCF48009C8E84 /* CCTMXTiledMap.m in Sources */, + F49E742315ACCF48009C8E84 /* CCTMXXMLParser.m in Sources */, + F49E742615ACCF48009C8E84 /* CCTransition.m in Sources */, + F49E742915ACCF48009C8E84 /* CCTransitionPageTurn.m in Sources */, + F49E742C15ACCF48009C8E84 /* CCTransitionRadial.m in Sources */, + F49E743015ACCF48009C8E84 /* cocos2d.m in Sources */, + F49E743715ACCF48009C8E84 /* CCDirectorIOS.m in Sources */, + F49E743B15ACCF48009C8E84 /* CCTouchDispatcher.m in Sources */, + F49E743E15ACCF48009C8E84 /* CCTouchHandler.m in Sources */, + F49E744115ACCF49009C8E84 /* EAGLView.m in Sources */, + F49E744415ACCF49009C8E84 /* ES1Renderer.m in Sources */, + F49E744715ACCF49009C8E84 /* glu.c in Sources */, + F49E744C15ACCF49009C8E84 /* CCDirectorMac.m in Sources */, + F49E744F15ACCF49009C8E84 /* CCEventDispatcher.m in Sources */, + F49E745215ACCF49009C8E84 /* MacGLView.m in Sources */, + F49E745515ACCF49009C8E84 /* MacWindow.m in Sources */, + F49E745815ACCF49009C8E84 /* base64.c in Sources */, + F49E745C15ACCF49009C8E84 /* CCArray.m in Sources */, + F49E746015ACCF49009C8E84 /* CCFileUtils.m in Sources */, + F49E746315ACCF49009C8E84 /* CCProfiling.m in Sources */, + F49E746515ACCF49009C8E84 /* ccUtils.c in Sources */, + F49E746915ACCF49009C8E84 /* CGPointExtension.m in Sources */, + F49E746D15ACCF49009C8E84 /* TGAlib.m in Sources */, + F49E747015ACCF49009C8E84 /* TransformUtils.m in Sources */, + F49E747515ACCF49009C8E84 /* ZipUtils.m in Sources */, + F49E74AA15ACCF4A009C8E84 /* FontLabel.m in Sources */, + F49E74AD15ACCF4A009C8E84 /* FontLabelStringDrawing.m in Sources */, + F49E74B015ACCF4A009C8E84 /* FontManager.m in Sources */, + F49E74B315ACCF4A009C8E84 /* ZAttributedString.m in Sources */, + F49E74B715ACCF4A009C8E84 /* ZFont.m in Sources */, + F49E74BC15ACCF4A009C8E84 /* main.m in Sources */, + F49E74BF15ACCF4A009C8E84 /* AppDelegate.m in Sources */, + F49E74C215ACCF4A009C8E84 /* RootViewController.m in Sources */, + F4D0CBD415ACD01C007C74DF /* Game.m in Sources */, + F4D0CBD515ACD01C007C74DF /* Highscores.m in Sources */, + F4D0CBD615ACD01C007C74DF /* Main.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXSourcesBuildPhase section */ /* Begin XCBuildConfiguration section */ - 1D6058940D05DD3E006BFB54 /* Debug */ = { + F49E74C715ACCF4A009C8E84 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - COPY_PHASE_STRIP = NO; - GCC_DYNAMIC_NO_PIC = NO; + ARCHS = ( + "$(ARCHS_STANDARD_32_BIT)", + armv6, + ); + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + GCC_C_LANGUAGE_STANDARD = gnu99; GCC_OPTIMIZATION_LEVEL = 0; - GCC_PRECOMPILE_PREFIX_HEADER = YES; - GCC_PREFIX_HEADER = tweejump_Prefix.pch; - INFOPLIST_FILE = Info.plist; - PRODUCT_NAME = tweejump; + GCC_PREPROCESSOR_DEFINITIONS = ( + DEBUG, + "COCOS2D_DEBUG=1", + ); + GCC_SYMBOLS_PRIVATE_EXTERN = NO; + GCC_VERSION = com.apple.compilers.llvmgcc42; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 3.0; + SDKROOT = iphoneos; }; name = Debug; }; - 1D6058950D05DD3E006BFB54 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - COPY_PHASE_STRIP = YES; - GCC_PRECOMPILE_PREFIX_HEADER = YES; - GCC_PREFIX_HEADER = tweejump_Prefix.pch; - INFOPLIST_FILE = Info.plist; - PRODUCT_NAME = tweejump; - }; - name = Release; - }; - 4D857E280FD74EA800B350BA /* Distribution */ = { + F49E74C815ACCF4A009C8E84 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { - ARCHS = "$(ARCHS_STANDARD_32_BIT)"; - CODE_SIGN_IDENTITY = "iPhone Distribution: iPlayful, Inc."; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution: iPlayful, Inc."; - COMPRESS_PNG_FILES = YES; - GCC_C_LANGUAGE_STANDARD = c99; + ARCHS = ( + "$(ARCHS_STANDARD_32_BIT)", + armv6, + ); + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_PREPROCESSOR_DEFINITIONS = NDEBUG; + GCC_VERSION = com.apple.compilers.llvmgcc42; GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNUSED_VARIABLE = YES; - PREBINDING = NO; - PROVISIONING_PROFILE = "B4813197-4338-4D66-884C-0725800A8093"; - "PROVISIONING_PROFILE[sdk=iphoneos*]" = "B4813197-4338-4D66-884C-0725800A8093"; - SDKROOT = iphoneos2.2.1; + IPHONEOS_DEPLOYMENT_TARGET = 3.0; + OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1"; + SDKROOT = iphoneos; }; - name = Distribution; + name = Release; }; - 4D857E290FD74EA800B350BA /* Distribution */ = { + F49E74CA15ACCF4A009C8E84 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - COPY_PHASE_STRIP = YES; + COPY_PHASE_STRIP = NO; + GCC_DYNAMIC_NO_PIC = NO; GCC_PRECOMPILE_PREFIX_HEADER = YES; - GCC_PREFIX_HEADER = tweejump_Prefix.pch; - INFOPLIST_FILE = Info.plist; - PRODUCT_NAME = tweejump; - }; - name = Distribution; - }; - C01FCF4F08A954540054247B /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ARCHS = "$(ARCHS_STANDARD_32_BIT)"; - CODE_SIGN_IDENTITY = "iPhone Developer: Sergey Tikhonov"; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer: Sergey Tikhonov"; - COMPRESS_PNG_FILES = YES; - GCC_C_LANGUAGE_STANDARD = c99; - GCC_WARN_ABOUT_RETURN_TYPE = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - ONLY_ACTIVE_ARCH = YES; - PREBINDING = NO; - PROVISIONING_PROFILE = "06B7245C-09BD-443A-B272-815CF0AC70AA"; - "PROVISIONING_PROFILE[sdk=iphoneos*]" = "06B7245C-09BD-443A-B272-815CF0AC70AA"; - SDKROOT = iphoneos2.2.1; + GCC_PREFIX_HEADER = tweejump/Prefix.pch; + "GCC_THUMB_SUPPORT[arch=armv6]" = ""; + INFOPLIST_FILE = tweejump/Resources/Info.plist; + OTHER_LDFLAGS = "-lz"; + PRODUCT_NAME = "$(TARGET_NAME)"; + WRAPPER_EXTENSION = app; }; name = Debug; }; - C01FCF5008A954540054247B /* Release */ = { + F49E74CB15ACCF4A009C8E84 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { - ARCHS = "$(ARCHS_STANDARD_32_BIT)"; - CODE_SIGN_IDENTITY = "iPhone Developer: Sergey Tikhonov"; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer: Sergey Tikhonov"; - COMPRESS_PNG_FILES = YES; - GCC_C_LANGUAGE_STANDARD = c99; - GCC_WARN_ABOUT_RETURN_TYPE = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - PREBINDING = NO; - PROVISIONING_PROFILE = "06B7245C-09BD-443A-B272-815CF0AC70AA"; - "PROVISIONING_PROFILE[sdk=iphoneos*]" = "06B7245C-09BD-443A-B272-815CF0AC70AA"; - SDKROOT = iphoneos2.2.1; + ALWAYS_SEARCH_USER_PATHS = NO; + COPY_PHASE_STRIP = YES; + GCC_PRECOMPILE_PREFIX_HEADER = YES; + GCC_PREFIX_HEADER = tweejump/Prefix.pch; + "GCC_THUMB_SUPPORT[arch=armv6]" = ""; + INFOPLIST_FILE = tweejump/Resources/Info.plist; + OTHER_LDFLAGS = "-lz"; + PRODUCT_NAME = "$(TARGET_NAME)"; + VALIDATE_PRODUCT = YES; + WRAPPER_EXTENSION = app; }; name = Release; }; /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ - 1D6058960D05DD3E006BFB54 /* Build configuration list for PBXNativeTarget "tweejump" */ = { + F49E735115ACCF46009C8E84 /* Build configuration list for PBXProject "tweejump" */ = { isa = XCConfigurationList; buildConfigurations = ( - 1D6058940D05DD3E006BFB54 /* Debug */, - 1D6058950D05DD3E006BFB54 /* Release */, - 4D857E290FD74EA800B350BA /* Distribution */, + F49E74C715ACCF4A009C8E84 /* Debug */, + F49E74C815ACCF4A009C8E84 /* Release */, ); defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; - C01FCF4E08A954540054247B /* Build configuration list for PBXProject "tweejump" */ = { + F49E74C915ACCF4A009C8E84 /* Build configuration list for PBXNativeTarget "tweejump" */ = { isa = XCConfigurationList; buildConfigurations = ( - C01FCF4F08A954540054247B /* Debug */, - C01FCF5008A954540054247B /* Release */, - 4D857E280FD74EA800B350BA /* Distribution */, + F49E74CA15ACCF4A009C8E84 /* Debug */, + F49E74CB15ACCF4A009C8E84 /* Release */, ); defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; - rootObject = 29B97313FDCFA39411CA2CEA /* Project object */; + rootObject = F49E734E15ACCF46009C8E84 /* Project object */; } diff --git a/tweejump.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/tweejump.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..969fb4e --- /dev/null +++ b/tweejump.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/tweejump.xcodeproj/xcuserdata/YannickL.xcuserdatad/xcschemes/tweejump.xcscheme b/tweejump.xcodeproj/xcuserdata/YannickL.xcuserdatad/xcschemes/tweejump.xcscheme new file mode 100644 index 0000000..dc046b9 --- /dev/null +++ b/tweejump.xcodeproj/xcuserdata/YannickL.xcuserdatad/xcschemes/tweejump.xcscheme @@ -0,0 +1,85 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tweejump.xcodeproj/xcuserdata/YannickL.xcuserdatad/xcschemes/xcschememanagement.plist b/tweejump.xcodeproj/xcuserdata/YannickL.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..9c553b0 --- /dev/null +++ b/tweejump.xcodeproj/xcuserdata/YannickL.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,22 @@ + + + + + SchemeUserState + + tweejump.xcscheme + + orderHint + 0 + + + SuppressBuildableAutocreation + + F49E735615ACCF46009C8E84 + + primary + + + + + diff --git a/tweejump/AppDelegate.h b/tweejump/AppDelegate.h new file mode 100755 index 0000000..1a33d8c --- /dev/null +++ b/tweejump/AppDelegate.h @@ -0,0 +1,20 @@ +// +// AppDelegate.h +// tweejump +// +// Created by Yannick Loriot on 10/07/12. +// Copyright Yannick Loriot 2012. All rights reserved. +// + +#import + +@class RootViewController; + +@interface AppDelegate : NSObject { + UIWindow *window; + RootViewController *viewController; +} + +@property (nonatomic, retain) UIWindow *window; + +@end diff --git a/tweejump/AppDelegate.m b/tweejump/AppDelegate.m new file mode 100755 index 0000000..39ef0a4 --- /dev/null +++ b/tweejump/AppDelegate.m @@ -0,0 +1,159 @@ +// +// AppDelegate.m +// tweejump +// +// Created by Yannick Loriot on 10/07/12. +// Copyright Yannick Loriot 2012. All rights reserved. +// + +#import "cocos2d.h" + +#import "AppDelegate.h" +#import "GameConfig.h" +#import "RootViewController.h" +#import "Game.h" + +@implementation AppDelegate + +@synthesize window; + +- (void) removeStartupFlicker +{ + // + // THIS CODE REMOVES THE STARTUP FLICKER + // + // Uncomment the following code if you Application only supports landscape mode + // +#if GAME_AUTOROTATION == kGameAutorotationUIViewController + +// CC_ENABLE_DEFAULT_GL_STATES(); +// CCDirector *director = [CCDirector sharedDirector]; +// CGSize size = [director winSize]; +// CCSprite *sprite = [CCSprite spriteWithFile:@"Default.png"]; +// sprite.position = ccp(size.width/2, size.height/2); +// sprite.rotation = -90; +// [sprite visit]; +// [[director openGLView] swapBuffers]; +// CC_ENABLE_DEFAULT_GL_STATES(); + +#endif // GAME_AUTOROTATION == kGameAutorotationUIViewController +} +- (void) applicationDidFinishLaunching:(UIApplication*)application +{ + // Init the window + window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; + + // Try to use CADisplayLink director + // if it fails (SDK < 3.1) use the default director + if( ! [CCDirector setDirectorType:kCCDirectorTypeDisplayLink] ) + [CCDirector setDirectorType:kCCDirectorTypeDefault]; + + + CCDirector *director = [CCDirector sharedDirector]; + + // Init the View Controller + viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil]; + viewController.wantsFullScreenLayout = YES; + + // + // Create the EAGLView manually + // 1. Create a RGB565 format. Alternative: RGBA8 + // 2. depth format of 0 bit. Use 16 or 24 bit for 3d effects, like CCPageTurnTransition + // + // + EAGLView *glView = [EAGLView viewWithFrame:[window bounds] + pixelFormat:kEAGLColorFormatRGB565 // kEAGLColorFormatRGBA8 + depthFormat:0 // GL_DEPTH_COMPONENT16_OES + ]; + + // attach the openglView to the director + [director setOpenGLView:glView]; + +// // Enables High Res mode (Retina Display) on iPhone 4 and maintains low res on all other devices +// if( ! [director enableRetinaDisplay:YES] ) +// CCLOG(@"Retina Display Not supported"); + + // + // VERY IMPORTANT: + // If the rotation is going to be controlled by a UIViewController + // then the device orientation should be "Portrait". + // + // IMPORTANT: + // By default, this template only supports Landscape orientations. + // Edit the RootViewController.m file to edit the supported orientations. + // +#if GAME_AUTOROTATION == kGameAutorotationNone + [director setDeviceOrientation:kCCDeviceOrientationPortrait]; +#else + [director setDeviceOrientation:kCCDeviceOrientationLandscapeLeft]; +#endif + + [director setAnimationInterval:1.0/60]; + //[director setDisplayFPS:YES]; + + + // make the OpenGLView a child of the view controller + [viewController setView:glView]; + + // make the View Controller a child of the main window + [window addSubview: viewController.view]; + + [window makeKeyAndVisible]; + + // Default texture format for PNG/BMP/TIFF/JPEG/GIF images + // It can be RGBA8888, RGBA4444, RGB5_A1, RGB565 + // You can change anytime. + [CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888]; + + + // Removes the startup flicker + [self removeStartupFlicker]; + + // Run the intro Scene + [[CCDirector sharedDirector] runWithScene: [Game scene]]; +} + + +- (void)applicationWillResignActive:(UIApplication *)application { + [[CCDirector sharedDirector] pause]; +} + +- (void)applicationDidBecomeActive:(UIApplication *)application { + [[CCDirector sharedDirector] resume]; +} + +- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application { + [[CCDirector sharedDirector] purgeCachedData]; +} + +-(void) applicationDidEnterBackground:(UIApplication*)application { + [[CCDirector sharedDirector] stopAnimation]; +} + +-(void) applicationWillEnterForeground:(UIApplication*)application { + [[CCDirector sharedDirector] startAnimation]; +} + +- (void)applicationWillTerminate:(UIApplication *)application { + CCDirector *director = [CCDirector sharedDirector]; + + [[director openGLView] removeFromSuperview]; + + [viewController release]; + + [window release]; + + [director end]; +} + +- (void)applicationSignificantTimeChange:(UIApplication *)application { + [[CCDirector sharedDirector] setNextDeltaTimeZero:YES]; +} + +- (void)dealloc { + [[CCDirector sharedDirector] end]; + [window release]; + [super dealloc]; +} + +@end diff --git a/Classes/Game.h b/tweejump/Classes/Game.h similarity index 89% rename from Classes/Game.h rename to tweejump/Classes/Game.h index 61d9bec..5c77876 100644 --- a/Classes/Game.h +++ b/tweejump/Classes/Game.h @@ -3,7 +3,7 @@ @interface Game : Main { - ccVertex2F bird_pos; + CGPoint bird_pos; ccVertex2F bird_vel; ccVertex2F bird_acc; @@ -19,4 +19,7 @@ int score; } + ++ (CCScene *)scene; + @end diff --git a/Classes/Game.m b/tweejump/Classes/Game.m similarity index 75% rename from Classes/Game.m rename to tweejump/Classes/Game.m index 8cb9fe0..354b270 100644 --- a/Classes/Game.m +++ b/tweejump/Classes/Game.m @@ -18,6 +18,16 @@ - (void)showHighscores; @implementation Game ++ (CCScene *)scene +{ + CCScene *game = [CCScene node]; + + Game *layer = [Game node]; + [game addChild:layer]; + + return game; +} + - (id)init { // NSLog(@"Game::init"); @@ -25,32 +35,32 @@ - (id)init { gameSuspended = YES; - AtlasSpriteManager *spriteManager = (AtlasSpriteManager*)[self getChildByTag:kSpriteManager]; + CCSpriteBatchNode *batchNode = (CCSpriteBatchNode *)[self getChildByTag:kSpriteManager]; [self initPlatforms]; - AtlasSprite *bird = [AtlasSprite spriteWithRect:CGRectMake(608,16,44,32) spriteManager:spriteManager]; - [spriteManager addChild:bird z:4 tag:kBird]; + CCSprite *bird = [CCSprite spriteWithTexture:[batchNode texture] rect:CGRectMake(608,16,44,32)]; + [batchNode addChild:bird z:4 tag:kBird]; - AtlasSprite *bonus; + CCSprite *bonus; for(int i=0; i + +#ifndef __IPHONE_3_0 +#warning "This project uses features only available in iPhone SDK 3.0 and later." +#endif + +#ifdef __OBJC__ +#import +#import +#endif diff --git a/Images/Default.png b/tweejump/Resources/Default.png similarity index 100% rename from Images/Default.png rename to tweejump/Resources/Default.png diff --git a/Images/bitmapFont.fnt b/tweejump/Resources/Fonts/bitmapFont.fnt similarity index 100% rename from Images/bitmapFont.fnt rename to tweejump/Resources/Fonts/bitmapFont.fnt diff --git a/Images/bitmapFont.png b/tweejump/Resources/Fonts/bitmapFont.png similarity index 100% rename from Images/bitmapFont.png rename to tweejump/Resources/Fonts/bitmapFont.png diff --git a/tweejump/Resources/Icon-72.png b/tweejump/Resources/Icon-72.png new file mode 100755 index 0000000..5b1ce47 Binary files /dev/null and b/tweejump/Resources/Icon-72.png differ diff --git a/tweejump/Resources/Icon-Small-50.png b/tweejump/Resources/Icon-Small-50.png new file mode 100755 index 0000000..bf1f0c5 Binary files /dev/null and b/tweejump/Resources/Icon-Small-50.png differ diff --git a/tweejump/Resources/Icon-Small.png b/tweejump/Resources/Icon-Small.png new file mode 100755 index 0000000..1f11669 Binary files /dev/null and b/tweejump/Resources/Icon-Small.png differ diff --git a/tweejump/Resources/Icon-Small@2x.png b/tweejump/Resources/Icon-Small@2x.png new file mode 100755 index 0000000..8d8ece4 Binary files /dev/null and b/tweejump/Resources/Icon-Small@2x.png differ diff --git a/Images/icon.png b/tweejump/Resources/Icon.png similarity index 100% rename from Images/icon.png rename to tweejump/Resources/Icon.png diff --git a/tweejump/Resources/Icon@2x.png b/tweejump/Resources/Icon@2x.png new file mode 100755 index 0000000..05be6c6 Binary files /dev/null and b/tweejump/Resources/Icon@2x.png differ diff --git a/Images/changePlayerButton.png b/tweejump/Resources/Images/changePlayerButton.png similarity index 100% rename from Images/changePlayerButton.png rename to tweejump/Resources/Images/changePlayerButton.png diff --git a/Images/playAgainButton.png b/tweejump/Resources/Images/playAgainButton.png similarity index 100% rename from Images/playAgainButton.png rename to tweejump/Resources/Images/playAgainButton.png diff --git a/Images/sprites.png b/tweejump/Resources/Images/sprites.png similarity index 100% rename from Images/sprites.png rename to tweejump/Resources/Images/sprites.png diff --git a/Info.plist b/tweejump/Resources/Info.plist old mode 100644 new mode 100755 similarity index 56% rename from Info.plist rename to tweejump/Resources/Info.plist index 03b471c..7bcd075 --- a/Info.plist +++ b/tweejump/Resources/Info.plist @@ -9,7 +9,23 @@ CFBundleExecutable ${EXECUTABLE_NAME} CFBundleIconFile - icon.png + Icon.png + CFBundleIconFiles + + Icon.png + + CFBundleIcons + + CFBundlePrimaryIcon + + CFBundleIconFiles + + Icon.png + + UIPrerenderedIcon + + + CFBundleIdentifier com.iplayful.tweejump CFBundleInfoDictionaryVersion @@ -21,10 +37,23 @@ CFBundleSignature ???? CFBundleVersion - 1.1 + 1.0 LSRequiresIPhoneOS UIPrerenderedIcon + UIRequiredDeviceCapabilities + + accelerometer + + opengles-1 + + + UIStatusBarHidden + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + diff --git a/tweejump/Resources/fps_images.png b/tweejump/Resources/fps_images.png new file mode 100755 index 0000000..e91d0af Binary files /dev/null and b/tweejump/Resources/fps_images.png differ diff --git a/tweejump/Resources/iTunesArtwork b/tweejump/Resources/iTunesArtwork new file mode 100755 index 0000000..b1cc056 Binary files /dev/null and b/tweejump/Resources/iTunesArtwork differ diff --git a/tweejump/RootViewController.h b/tweejump/RootViewController.h new file mode 100755 index 0000000..257bc63 --- /dev/null +++ b/tweejump/RootViewController.h @@ -0,0 +1,16 @@ +// +// RootViewController.h +// tweejump +// +// Created by Yannick Loriot on 10/07/12. +// Copyright Yannick Loriot 2012. All rights reserved. +// + +#import + + +@interface RootViewController : UIViewController { + +} + +@end diff --git a/tweejump/RootViewController.m b/tweejump/RootViewController.m new file mode 100755 index 0000000..ecb758d --- /dev/null +++ b/tweejump/RootViewController.m @@ -0,0 +1,153 @@ +// +// RootViewController.m +// tweejump +// +// Created by Yannick Loriot on 10/07/12. +// Copyright Yannick Loriot 2012. All rights reserved. +// + +// +// RootViewController + iAd +// If you want to support iAd, use this class as the controller of your iAd +// + +#import "cocos2d.h" + +#import "RootViewController.h" +#import "GameConfig.h" + +@implementation RootViewController + +/* + // The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad. + - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { + if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) { + // Custom initialization + } + return self; + } + */ + +/* + // Implement loadView to create a view hierarchy programmatically, without using a nib. + - (void)loadView { + } + */ + +/* + // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. + - (void)viewDidLoad { + [super viewDidLoad]; + } + */ + + +// Override to allow orientations other than the default portrait orientation. +- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { + + // + // There are 2 ways to support auto-rotation: + // - The OpenGL / cocos2d way + // - Faster, but doesn't rotate the UIKit objects + // - The ViewController way + // - A bit slower, but the UiKit objects are placed in the right place + // + +#if GAME_AUTOROTATION==kGameAutorotationNone + // + // EAGLView won't be autorotated. + // Since this method should return YES in at least 1 orientation, + // we return YES only in the Portrait orientation + // + return ( interfaceOrientation == UIInterfaceOrientationPortrait ); + +#elif GAME_AUTOROTATION==kGameAutorotationCCDirector + // + // EAGLView will be rotated by cocos2d + // + // Sample: Autorotate only in landscape mode + // + if( interfaceOrientation == UIInterfaceOrientationLandscapeLeft ) { + [[CCDirector sharedDirector] setDeviceOrientation: kCCDeviceOrientationLandscapeRight]; + } else if( interfaceOrientation == UIInterfaceOrientationLandscapeRight) { + [[CCDirector sharedDirector] setDeviceOrientation: kCCDeviceOrientationLandscapeLeft]; + } + + // Since this method should return YES in at least 1 orientation, + // we return YES only in the Portrait orientation + return ( interfaceOrientation == UIInterfaceOrientationPortrait ); + +#elif GAME_AUTOROTATION == kGameAutorotationUIViewController + // + // EAGLView will be rotated by the UIViewController + // + // Sample: Autorotate only in landscpe mode + // + // return YES for the supported orientations + + return ( UIInterfaceOrientationIsLandscape( interfaceOrientation ) ); + +#else +#error Unknown value in GAME_AUTOROTATION + +#endif // GAME_AUTOROTATION + + + // Shold not happen + return NO; +} + +// +// This callback only will be called when GAME_AUTOROTATION == kGameAutorotationUIViewController +// +#if GAME_AUTOROTATION == kGameAutorotationUIViewController +-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration +{ + // + // Assuming that the main window has the size of the screen + // BUG: This won't work if the EAGLView is not fullscreen + /// + CGRect screenRect = [[UIScreen mainScreen] bounds]; + CGRect rect = CGRectZero; + + + if(toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) + rect = screenRect; + + else if(toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) + rect.size = CGSizeMake( screenRect.size.height, screenRect.size.width ); + + CCDirector *director = [CCDirector sharedDirector]; + EAGLView *glView = [director openGLView]; + float contentScaleFactor = [director contentScaleFactor]; + + if( contentScaleFactor != 1 ) { + rect.size.width *= contentScaleFactor; + rect.size.height *= contentScaleFactor; + } + glView.frame = rect; +} +#endif // GAME_AUTOROTATION == kGameAutorotationUIViewController + + +- (void)didReceiveMemoryWarning { + // Releases the view if it doesn't have a superview. + [super didReceiveMemoryWarning]; + + // Release any cached data, images, etc that aren't in use. +} + +- (void)viewDidUnload { + [super viewDidUnload]; + // Release any retained subviews of the main view. + // e.g. self.myOutlet = nil; +} + + +- (void)dealloc { + [super dealloc]; +} + + +@end + diff --git a/tweejump/libs/FontLabel/FontLabel.h b/tweejump/libs/FontLabel/FontLabel.h new file mode 100755 index 0000000..6de9c2c --- /dev/null +++ b/tweejump/libs/FontLabel/FontLabel.h @@ -0,0 +1,44 @@ +// +// FontLabel.h +// FontLabel +// +// Created by Kevin Ballard on 5/8/09. +// Copyright © 2009 Zynga Game Networks +// +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#import +#import + +@class ZFont; +@class ZAttributedString; + +@interface FontLabel : UILabel { + void *reserved; // works around a bug in UILabel + ZFont *zFont; + ZAttributedString *zAttributedText; +} +@property (nonatomic, setter=setCGFont:) CGFontRef cgFont __AVAILABILITY_INTERNAL_DEPRECATED; +@property (nonatomic, assign) CGFloat pointSize __AVAILABILITY_INTERNAL_DEPRECATED; +@property (nonatomic, retain, setter=setZFont:) ZFont *zFont; +// if attributedText is nil, fall back on using the inherited UILabel properties +// if attributedText is non-nil, the font/text/textColor +// in addition, adjustsFontSizeToFitWidth does not work with attributed text +@property (nonatomic, copy) ZAttributedString *zAttributedText; +// -initWithFrame:fontName:pointSize: uses FontManager to look up the font name +- (id)initWithFrame:(CGRect)frame fontName:(NSString *)fontName pointSize:(CGFloat)pointSize; +- (id)initWithFrame:(CGRect)frame zFont:(ZFont *)font; +- (id)initWithFrame:(CGRect)frame font:(CGFontRef)font pointSize:(CGFloat)pointSize __AVAILABILITY_INTERNAL_DEPRECATED; +@end diff --git a/tweejump/libs/FontLabel/FontLabel.m b/tweejump/libs/FontLabel/FontLabel.m new file mode 100755 index 0000000..58975b1 --- /dev/null +++ b/tweejump/libs/FontLabel/FontLabel.m @@ -0,0 +1,195 @@ +// +// FontLabel.m +// FontLabel +// +// Created by Kevin Ballard on 5/8/09. +// Copyright © 2009 Zynga Game Networks +// +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#import "FontLabel.h" +#import "FontManager.h" +#import "FontLabelStringDrawing.h" +#import "ZFont.h" + +@interface ZFont (ZFontPrivate) +@property (nonatomic, readonly) CGFloat ratio; +@end + +@implementation FontLabel +@synthesize zFont; +@synthesize zAttributedText; + +- (id)initWithFrame:(CGRect)frame fontName:(NSString *)fontName pointSize:(CGFloat)pointSize { + return [self initWithFrame:frame zFont:[[FontManager sharedManager] zFontWithName:fontName pointSize:pointSize]]; +} + +- (id)initWithFrame:(CGRect)frame zFont:(ZFont *)font { + if ((self = [super initWithFrame:frame])) { + zFont = [font retain]; + } + return self; +} + +- (id)initWithFrame:(CGRect)frame font:(CGFontRef)font pointSize:(CGFloat)pointSize { + return [self initWithFrame:frame zFont:[ZFont fontWithCGFont:font size:pointSize]]; +} + +- (CGFontRef)cgFont { + return self.zFont.cgFont; +} + +- (void)setCGFont:(CGFontRef)font { + if (self.zFont.cgFont != font) { + self.zFont = [ZFont fontWithCGFont:font size:self.zFont.pointSize]; + } +} + +- (CGFloat)pointSize { + return self.zFont.pointSize; +} + +- (void)setPointSize:(CGFloat)pointSize { + if (self.zFont.pointSize != pointSize) { + self.zFont = [ZFont fontWithCGFont:self.zFont.cgFont size:pointSize]; + } +} + +- (void)setZAttributedText:(ZAttributedString *)attStr { + if (zAttributedText != attStr) { + [zAttributedText release]; + zAttributedText = [attStr copy]; + [self setNeedsDisplay]; + } +} + +- (void)drawTextInRect:(CGRect)rect { + if (self.zFont == NULL && self.zAttributedText == nil) { + [super drawTextInRect:rect]; + return; + } + + if (self.zAttributedText == nil) { + // this method is documented as setting the text color for us, but that doesn't appear to be the case + if (self.highlighted) { + [(self.highlightedTextColor ?: [UIColor whiteColor]) setFill]; + } else { + [(self.textColor ?: [UIColor blackColor]) setFill]; + } + + ZFont *actualFont = self.zFont; + CGSize origSize = rect.size; + if (self.numberOfLines == 1) { + origSize.height = actualFont.leading; + CGPoint point = CGPointMake(rect.origin.x, + rect.origin.y + roundf(((rect.size.height - actualFont.leading) / 2.0f))); + CGSize size = [self.text sizeWithZFont:actualFont]; + if (self.adjustsFontSizeToFitWidth && self.minimumFontSize < actualFont.pointSize) { + if (size.width > origSize.width) { + CGFloat desiredRatio = (origSize.width * actualFont.ratio) / size.width; + CGFloat desiredPointSize = desiredRatio * actualFont.pointSize / actualFont.ratio; + actualFont = [actualFont fontWithSize:MAX(MAX(desiredPointSize, self.minimumFontSize), 1.0f)]; + size = [self.text sizeWithZFont:actualFont]; + } + if (!CGSizeEqualToSize(origSize, size)) { + switch (self.baselineAdjustment) { + case UIBaselineAdjustmentAlignCenters: + point.y += roundf((origSize.height - size.height) / 2.0f); + break; + case UIBaselineAdjustmentAlignBaselines: + point.y += (self.zFont.ascender - actualFont.ascender); + break; + case UIBaselineAdjustmentNone: + break; + } + } + } + size.width = MIN(size.width, origSize.width); + // adjust the point for alignment + switch (self.textAlignment) { + case UITextAlignmentLeft: + break; + case UITextAlignmentCenter: + point.x += (origSize.width - size.width) / 2.0f; + break; + case UITextAlignmentRight: + point.x += origSize.width - size.width; + break; + } + [self.text drawAtPoint:point forWidth:size.width withZFont:actualFont lineBreakMode:self.lineBreakMode]; + } else { + CGSize size = [self.text sizeWithZFont:actualFont constrainedToSize:origSize lineBreakMode:self.lineBreakMode numberOfLines:self.numberOfLines]; + CGPoint point = rect.origin; + point.y += roundf((rect.size.height - size.height) / 2.0f); + rect = (CGRect){point, CGSizeMake(rect.size.width, size.height)}; + [self.text drawInRect:rect withZFont:actualFont lineBreakMode:self.lineBreakMode alignment:self.textAlignment numberOfLines:self.numberOfLines]; + } + } else { + ZAttributedString *attStr = self.zAttributedText; + if (self.highlighted) { + // modify the string to change the base color + ZMutableAttributedString *mutStr = [[attStr mutableCopy] autorelease]; + NSRange activeRange = NSMakeRange(0, attStr.length); + while (activeRange.length > 0) { + NSRange effective; + UIColor *color = [attStr attribute:ZForegroundColorAttributeName atIndex:activeRange.location + longestEffectiveRange:&effective inRange:activeRange]; + if (color == nil) { + [mutStr addAttribute:ZForegroundColorAttributeName value:[UIColor whiteColor] range:effective]; + } + activeRange.location += effective.length, activeRange.length -= effective.length; + } + attStr = mutStr; + } + CGSize size = [attStr sizeConstrainedToSize:rect.size lineBreakMode:self.lineBreakMode numberOfLines:self.numberOfLines]; + CGPoint point = rect.origin; + point.y += roundf((rect.size.height - size.height) / 2.0f); + rect = (CGRect){point, CGSizeMake(rect.size.width, size.height)}; + [attStr drawInRect:rect withLineBreakMode:self.lineBreakMode alignment:self.textAlignment numberOfLines:self.numberOfLines]; + } +} + +- (CGRect)textRectForBounds:(CGRect)bounds limitedToNumberOfLines:(NSInteger)numberOfLines { + if (self.zFont == NULL && self.zAttributedText == nil) { + return [super textRectForBounds:bounds limitedToNumberOfLines:numberOfLines]; + } + + if (numberOfLines == 1) { + // if numberOfLines == 1 we need to use the version that converts spaces + CGSize size; + if (self.zAttributedText == nil) { + size = [self.text sizeWithZFont:self.zFont]; + } else { + size = [self.zAttributedText size]; + } + bounds.size.width = MIN(bounds.size.width, size.width); + bounds.size.height = MIN(bounds.size.height, size.height); + } else { + if (numberOfLines > 0) bounds.size.height = MIN(bounds.size.height, self.zFont.leading * numberOfLines); + if (self.zAttributedText == nil) { + bounds.size = [self.text sizeWithZFont:self.zFont constrainedToSize:bounds.size lineBreakMode:self.lineBreakMode]; + } else { + bounds.size = [self.zAttributedText sizeConstrainedToSize:bounds.size lineBreakMode:self.lineBreakMode]; + } + } + return bounds; +} + +- (void)dealloc { + [zFont release]; + [zAttributedText release]; + [super dealloc]; +} +@end diff --git a/tweejump/libs/FontLabel/FontLabelStringDrawing.h b/tweejump/libs/FontLabel/FontLabelStringDrawing.h new file mode 100755 index 0000000..821da22 --- /dev/null +++ b/tweejump/libs/FontLabel/FontLabelStringDrawing.h @@ -0,0 +1,69 @@ +// +// FontLabelStringDrawing.h +// FontLabel +// +// Created by Kevin Ballard on 5/5/09. +// Copyright © 2009 Zynga Game Networks +// +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#import +#import "ZAttributedString.h" + +@class ZFont; + +@interface NSString (FontLabelStringDrawing) +// CGFontRef-based methods +- (CGSize)sizeWithCGFont:(CGFontRef)font pointSize:(CGFloat)pointSize __AVAILABILITY_INTERNAL_DEPRECATED; +- (CGSize)sizeWithCGFont:(CGFontRef)font pointSize:(CGFloat)pointSize constrainedToSize:(CGSize)size __AVAILABILITY_INTERNAL_DEPRECATED; +- (CGSize)sizeWithCGFont:(CGFontRef)font pointSize:(CGFloat)pointSize constrainedToSize:(CGSize)size + lineBreakMode:(UILineBreakMode)lineBreakMode __AVAILABILITY_INTERNAL_DEPRECATED; +- (CGSize)drawAtPoint:(CGPoint)point withCGFont:(CGFontRef)font pointSize:(CGFloat)pointSize __AVAILABILITY_INTERNAL_DEPRECATED; +- (CGSize)drawInRect:(CGRect)rect withCGFont:(CGFontRef)font pointSize:(CGFloat)pointSize __AVAILABILITY_INTERNAL_DEPRECATED; +- (CGSize)drawInRect:(CGRect)rect withCGFont:(CGFontRef)font pointSize:(CGFloat)pointSize + lineBreakMode:(UILineBreakMode)lineBreakMode __AVAILABILITY_INTERNAL_DEPRECATED; +- (CGSize)drawInRect:(CGRect)rect withCGFont:(CGFontRef)font pointSize:(CGFloat)pointSize + lineBreakMode:(UILineBreakMode)lineBreakMode alignment:(UITextAlignment)alignment __AVAILABILITY_INTERNAL_DEPRECATED; + +// ZFont-based methods +- (CGSize)sizeWithZFont:(ZFont *)font; +- (CGSize)sizeWithZFont:(ZFont *)font constrainedToSize:(CGSize)size; +- (CGSize)sizeWithZFont:(ZFont *)font constrainedToSize:(CGSize)size lineBreakMode:(UILineBreakMode)lineBreakMode; +- (CGSize)sizeWithZFont:(ZFont *)font constrainedToSize:(CGSize)size lineBreakMode:(UILineBreakMode)lineBreakMode + numberOfLines:(NSUInteger)numberOfLines; +- (CGSize)drawAtPoint:(CGPoint)point withZFont:(ZFont *)font; +- (CGSize)drawAtPoint:(CGPoint)point forWidth:(CGFloat)width withZFont:(ZFont *)font lineBreakMode:(UILineBreakMode)lineBreakMode; +- (CGSize)drawInRect:(CGRect)rect withZFont:(ZFont *)font; +- (CGSize)drawInRect:(CGRect)rect withZFont:(ZFont *)font lineBreakMode:(UILineBreakMode)lineBreakMode; +- (CGSize)drawInRect:(CGRect)rect withZFont:(ZFont *)font lineBreakMode:(UILineBreakMode)lineBreakMode + alignment:(UITextAlignment)alignment; +- (CGSize)drawInRect:(CGRect)rect withZFont:(ZFont *)font lineBreakMode:(UILineBreakMode)lineBreakMode + alignment:(UITextAlignment)alignment numberOfLines:(NSUInteger)numberOfLines; +@end + +@interface ZAttributedString (ZAttributedStringDrawing) +- (CGSize)size; +- (CGSize)sizeConstrainedToSize:(CGSize)size; +- (CGSize)sizeConstrainedToSize:(CGSize)size lineBreakMode:(UILineBreakMode)lineBreakMode; +- (CGSize)sizeConstrainedToSize:(CGSize)size lineBreakMode:(UILineBreakMode)lineBreakMode + numberOfLines:(NSUInteger)numberOfLines; +- (CGSize)drawAtPoint:(CGPoint)point; +- (CGSize)drawAtPoint:(CGPoint)point forWidth:(CGFloat)width lineBreakMode:(UILineBreakMode)lineBreakMode; +- (CGSize)drawInRect:(CGRect)rect; +- (CGSize)drawInRect:(CGRect)rect withLineBreakMode:(UILineBreakMode)lineBreakMode; +- (CGSize)drawInRect:(CGRect)rect withLineBreakMode:(UILineBreakMode)lineBreakMode alignment:(UITextAlignment)alignment; +- (CGSize)drawInRect:(CGRect)rect withLineBreakMode:(UILineBreakMode)lineBreakMode alignment:(UITextAlignment)alignment + numberOfLines:(NSUInteger)numberOfLines; +@end diff --git a/tweejump/libs/FontLabel/FontLabelStringDrawing.m b/tweejump/libs/FontLabel/FontLabelStringDrawing.m new file mode 100755 index 0000000..2907372 --- /dev/null +++ b/tweejump/libs/FontLabel/FontLabelStringDrawing.m @@ -0,0 +1,892 @@ +// +// FontLabelStringDrawing.m +// FontLabel +// +// Created by Kevin Ballard on 5/5/09. +// Copyright © 2009 Zynga Game Networks +// +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#import "FontLabelStringDrawing.h" +#import "ZFont.h" +#import "ZAttributedStringPrivate.h" + +@interface ZFont (ZFontPrivate) +@property (nonatomic, readonly) CGFloat ratio; +@end + +#define kUnicodeHighSurrogateStart 0xD800 +#define kUnicodeHighSurrogateEnd 0xDBFF +#define kUnicodeHighSurrogateMask kUnicodeHighSurrogateStart +#define kUnicodeLowSurrogateStart 0xDC00 +#define kUnicodeLowSurrogateEnd 0xDFFF +#define kUnicodeLowSurrogateMask kUnicodeLowSurrogateStart +#define kUnicodeSurrogateTypeMask 0xFC00 +#define UnicharIsHighSurrogate(c) ((c & kUnicodeSurrogateTypeMask) == kUnicodeHighSurrogateMask) +#define UnicharIsLowSurrogate(c) ((c & kUnicodeSurrogateTypeMask) == kUnicodeLowSurrogateMask) +#define ConvertSurrogatePairToUTF32(high, low) ((UInt32)((high - 0xD800) * 0x400 + (low - 0xDC00) + 0x10000)) + +typedef enum { + kFontTableFormat4 = 4, + kFontTableFormat12 = 12, +} FontTableFormat; + +typedef struct fontTable { + NSUInteger retainCount; + CFDataRef cmapTable; + FontTableFormat format; + union { + struct { + UInt16 segCountX2; + UInt16 *endCodes; + UInt16 *startCodes; + UInt16 *idDeltas; + UInt16 *idRangeOffsets; + } format4; + struct { + UInt32 nGroups; + struct { + UInt32 startCharCode; + UInt32 endCharCode; + UInt32 startGlyphCode; + } *groups; + } format12; + } cmap; +} fontTable; + +static FontTableFormat supportedFormats[] = { kFontTableFormat4, kFontTableFormat12 }; +static size_t supportedFormatsCount = sizeof(supportedFormats) / sizeof(FontTableFormat); + +static fontTable *newFontTable(CFDataRef cmapTable, FontTableFormat format) { + fontTable *table = (struct fontTable *)malloc(sizeof(struct fontTable)); + table->retainCount = 1; + table->cmapTable = CFRetain(cmapTable); + table->format = format; + return table; +} + +static fontTable *retainFontTable(fontTable *table) { + if (table != NULL) { + table->retainCount++; + } + return table; +} + +static void releaseFontTable(fontTable *table) { + if (table != NULL) { + if (table->retainCount <= 1) { + CFRelease(table->cmapTable); + free(table); + } else { + table->retainCount--; + } + } +} + +static const void *fontTableRetainCallback(CFAllocatorRef allocator, const void *value) { + return retainFontTable((fontTable *)value); +} + +static void fontTableReleaseCallback(CFAllocatorRef allocator, const void *value) { + releaseFontTable((fontTable *)value); +} + +static const CFDictionaryValueCallBacks kFontTableDictionaryValueCallBacks = { + .version = 0, + .retain = &fontTableRetainCallback, + .release = &fontTableReleaseCallback, + .copyDescription = NULL, + .equal = NULL +}; + +// read the cmap table from the font +// we only know how to understand some of the table formats at the moment +static fontTable *readFontTableFromCGFont(CGFontRef font) { + CFDataRef cmapTable = CGFontCopyTableForTag(font, 'cmap'); + NSCAssert1(cmapTable != NULL, @"CGFontCopyTableForTag returned NULL for 'cmap' tag in font %@", + (font ? [(id)CFCopyDescription(font) autorelease] : @"(null)")); + const UInt8 * const bytes = CFDataGetBytePtr(cmapTable); + NSCAssert1(OSReadBigInt16(bytes, 0) == 0, @"cmap table for font %@ has bad version number", + (font ? [(id)CFCopyDescription(font) autorelease] : @"(null)")); + UInt16 numberOfSubtables = OSReadBigInt16(bytes, 2); + const UInt8 *unicodeSubtable = NULL; + //UInt16 unicodeSubtablePlatformID; + UInt16 unicodeSubtablePlatformSpecificID; + FontTableFormat unicodeSubtableFormat; + const UInt8 * const encodingSubtables = &bytes[4]; + for (UInt16 i = 0; i < numberOfSubtables; i++) { + const UInt8 * const encodingSubtable = &encodingSubtables[8 * i]; + UInt16 platformID = OSReadBigInt16(encodingSubtable, 0); + UInt16 platformSpecificID = OSReadBigInt16(encodingSubtable, 2); + // find the best subtable + // best is defined by a combination of encoding and format + // At the moment we only support format 4, so ignore all other format tables + // We prefer platformID == 0, but we will also accept Microsoft's unicode format + if (platformID == 0 || (platformID == 3 && platformSpecificID == 1)) { + BOOL preferred = NO; + if (unicodeSubtable == NULL) { + preferred = YES; + } else if (platformID == 0 && platformSpecificID > unicodeSubtablePlatformSpecificID) { + preferred = YES; + } + if (preferred) { + UInt32 offset = OSReadBigInt32(encodingSubtable, 4); + const UInt8 *subtable = &bytes[offset]; + UInt16 format = OSReadBigInt16(subtable, 0); + for (size_t i = 0; i < supportedFormatsCount; i++) { + if (format == supportedFormats[i]) { + if (format >= 8) { + // the version is a fixed-point + UInt16 formatFrac = OSReadBigInt16(subtable, 2); + if (formatFrac != 0) { + // all the current formats with a Fixed version are always *.0 + continue; + } + } + unicodeSubtable = subtable; + //unicodeSubtablePlatformID = platformID; + unicodeSubtablePlatformSpecificID = platformSpecificID; + unicodeSubtableFormat = format; + break; + } + } + } + } + } + fontTable *table = NULL; + if (unicodeSubtable != NULL) { + table = newFontTable(cmapTable, unicodeSubtableFormat); + switch (unicodeSubtableFormat) { + case kFontTableFormat4: + // subtable format 4 + //UInt16 length = OSReadBigInt16(unicodeSubtable, 2); + //UInt16 language = OSReadBigInt16(unicodeSubtable, 4); + table->cmap.format4.segCountX2 = OSReadBigInt16(unicodeSubtable, 6); + //UInt16 searchRange = OSReadBigInt16(unicodeSubtable, 8); + //UInt16 entrySelector = OSReadBigInt16(unicodeSubtable, 10); + //UInt16 rangeShift = OSReadBigInt16(unicodeSubtable, 12); + table->cmap.format4.endCodes = (UInt16*)&unicodeSubtable[14]; + table->cmap.format4.startCodes = (UInt16*)&((UInt8*)table->cmap.format4.endCodes)[table->cmap.format4.segCountX2+2]; + table->cmap.format4.idDeltas = (UInt16*)&((UInt8*)table->cmap.format4.startCodes)[table->cmap.format4.segCountX2]; + table->cmap.format4.idRangeOffsets = (UInt16*)&((UInt8*)table->cmap.format4.idDeltas)[table->cmap.format4.segCountX2]; + //UInt16 *glyphIndexArray = &idRangeOffsets[segCountX2]; + break; + case kFontTableFormat12: + table->cmap.format12.nGroups = OSReadBigInt32(unicodeSubtable, 12); + table->cmap.format12.groups = (void *)&unicodeSubtable[16]; + break; + default: + releaseFontTable(table); + table = NULL; + } + } + CFRelease(cmapTable); + return table; +} + +// outGlyphs must be at least size n +static void mapCharactersToGlyphsInFont(const fontTable *table, unichar characters[], size_t charLen, CGGlyph outGlyphs[], size_t *outGlyphLen) { + if (table != NULL) { + NSUInteger j = 0; + switch (table->format) { + case kFontTableFormat4: { + for (NSUInteger i = 0; i < charLen; i++, j++) { + unichar c = characters[i]; + UInt16 segOffset; + BOOL foundSegment = NO; + for (segOffset = 0; segOffset < table->cmap.format4.segCountX2; segOffset += 2) { + UInt16 endCode = OSReadBigInt16(table->cmap.format4.endCodes, segOffset); + if (endCode >= c) { + foundSegment = YES; + break; + } + } + if (!foundSegment) { + // no segment + // this is an invalid font + outGlyphs[j] = 0; + } else { + UInt16 startCode = OSReadBigInt16(table->cmap.format4.startCodes, segOffset); + if (!(startCode <= c)) { + // the code falls in a hole between segments + outGlyphs[j] = 0; + } else { + UInt16 idRangeOffset = OSReadBigInt16(table->cmap.format4.idRangeOffsets, segOffset); + if (idRangeOffset == 0) { + UInt16 idDelta = OSReadBigInt16(table->cmap.format4.idDeltas, segOffset); + outGlyphs[j] = (c + idDelta) % 65536; + } else { + // use the glyphIndexArray + UInt16 glyphOffset = idRangeOffset + 2 * (c - startCode); + outGlyphs[j] = OSReadBigInt16(&((UInt8*)table->cmap.format4.idRangeOffsets)[segOffset], glyphOffset); + } + } + } + } + break; + } + case kFontTableFormat12: { + UInt32 lastSegment = UINT32_MAX; + for (NSUInteger i = 0; i < charLen; i++, j++) { + unichar c = characters[i]; + UInt32 c32 = c; + if (UnicharIsHighSurrogate(c)) { + if (i+1 < charLen) { // do we have another character after this one? + unichar cc = characters[i+1]; + if (UnicharIsLowSurrogate(cc)) { + c32 = ConvertSurrogatePairToUTF32(c, cc); + i++; + } + } + } + // Start the heuristic search + // If this is an ASCII char, just do a linear search + // Otherwise do a hinted, modified binary search + // Start the first pivot at the last range found + // And when moving the pivot, limit the movement by increasing + // powers of two. This should help with locality + __typeof__(table->cmap.format12.groups[0]) *foundGroup = NULL; + if (c32 <= 0x7F) { + // ASCII + for (UInt32 idx = 0; idx < table->cmap.format12.nGroups; idx++) { + __typeof__(table->cmap.format12.groups[idx]) *group = &table->cmap.format12.groups[idx]; + if (c32 < OSSwapBigToHostInt32(group->startCharCode)) { + // we've fallen into a hole + break; + } else if (c32 <= OSSwapBigToHostInt32(group->endCharCode)) { + // this is the range + foundGroup = group; + break; + } + } + } else { + // heuristic search + UInt32 maxJump = (lastSegment == UINT32_MAX ? UINT32_MAX / 2 : 8); + UInt32 lowIdx = 0, highIdx = table->cmap.format12.nGroups; // highIdx is the first invalid idx + UInt32 pivot = (lastSegment == UINT32_MAX ? lowIdx + (highIdx - lowIdx) / 2 : lastSegment); + while (highIdx > lowIdx) { + __typeof__(table->cmap.format12.groups[pivot]) *group = &table->cmap.format12.groups[pivot]; + if (c32 < OSSwapBigToHostInt32(group->startCharCode)) { + highIdx = pivot; + } else if (c32 > OSSwapBigToHostInt32(group->endCharCode)) { + lowIdx = pivot + 1; + } else { + // we've hit the range + foundGroup = group; + break; + } + if (highIdx - lowIdx > maxJump * 2) { + if (highIdx == pivot) { + pivot -= maxJump; + } else { + pivot += maxJump; + } + maxJump *= 2; + } else { + pivot = lowIdx + (highIdx - lowIdx) / 2; + } + } + if (foundGroup != NULL) lastSegment = pivot; + } + if (foundGroup == NULL) { + outGlyphs[j] = 0; + } else { + outGlyphs[j] = (CGGlyph)(OSSwapBigToHostInt32(foundGroup->startGlyphCode) + + (c32 - OSSwapBigToHostInt32(foundGroup->startCharCode))); + } + } + break; + } + } + if (outGlyphLen != NULL) *outGlyphLen = j; + } else { + // we have no table, so just null out the glyphs + bzero(outGlyphs, charLen*sizeof(CGGlyph)); + if (outGlyphLen != NULL) *outGlyphLen = 0; + } +} + +static BOOL mapGlyphsToAdvancesInFont(ZFont *font, size_t n, CGGlyph glyphs[], CGFloat outAdvances[]) { + int advances[n]; + if (CGFontGetGlyphAdvances(font.cgFont, glyphs, n, advances)) { + CGFloat ratio = font.ratio; + + for (size_t i = 0; i < n; i++) { + outAdvances[i] = advances[i]*ratio; + } + return YES; + } else { + bzero(outAdvances, n*sizeof(CGFloat)); + } + return NO; +} + +static id getValueOrDefaultForRun(ZAttributeRun *run, NSString *key) { + id value = [run.attributes objectForKey:key]; + if (value == nil) { + static NSDictionary *defaultValues = nil; + if (defaultValues == nil) { + defaultValues = [[NSDictionary alloc] initWithObjectsAndKeys: + [ZFont fontWithUIFont:[UIFont systemFontOfSize:12]], ZFontAttributeName, + [UIColor blackColor], ZForegroundColorAttributeName, + [UIColor clearColor], ZBackgroundColorAttributeName, + [NSNumber numberWithInt:ZUnderlineStyleNone], ZUnderlineStyleAttributeName, + nil]; + } + value = [defaultValues objectForKey:key]; + } + return value; +} + +static void readRunInformation(NSArray *attributes, NSUInteger len, CFMutableDictionaryRef fontTableMap, + NSUInteger index, ZAttributeRun **currentRun, NSUInteger *nextRunStart, + ZFont **currentFont, fontTable **currentTable) { + *currentRun = [attributes objectAtIndex:index]; + *nextRunStart = ([attributes count] > index+1 ? [[attributes objectAtIndex:index+1] index] : len); + *currentFont = getValueOrDefaultForRun(*currentRun, ZFontAttributeName); + if (!CFDictionaryGetValueIfPresent(fontTableMap, (*currentFont).cgFont, (const void **)currentTable)) { + *currentTable = readFontTableFromCGFont((*currentFont).cgFont); + CFDictionarySetValue(fontTableMap, (*currentFont).cgFont, *currentTable); + releaseFontTable(*currentTable); + } +} + +static CGSize drawOrSizeTextConstrainedToSize(BOOL performDraw, NSString *string, NSArray *attributes, CGSize constrainedSize, NSUInteger maxLines, + UILineBreakMode lineBreakMode, UITextAlignment alignment, BOOL ignoreColor) { + NSUInteger len = [string length]; + NSUInteger idx = 0; + CGPoint drawPoint = CGPointZero; + CGSize retValue = CGSizeZero; + CGContextRef ctx = (performDraw ? UIGraphicsGetCurrentContext() : NULL); + + BOOL convertNewlines = (maxLines == 1); + + // Extract the characters from the string + // Convert newlines to spaces if necessary + unichar *characters = (unichar *)malloc(sizeof(unichar) * len); + if (convertNewlines) { + NSCharacterSet *charset = [NSCharacterSet newlineCharacterSet]; + NSRange range = NSMakeRange(0, len); + size_t cIdx = 0; + while (range.length > 0) { + NSRange newlineRange = [string rangeOfCharacterFromSet:charset options:0 range:range]; + if (newlineRange.location == NSNotFound) { + [string getCharacters:&characters[cIdx] range:range]; + cIdx += range.length; + break; + } else { + NSUInteger delta = newlineRange.location - range.location; + if (newlineRange.location > range.location) { + [string getCharacters:&characters[cIdx] range:NSMakeRange(range.location, delta)]; + } + cIdx += delta; + characters[cIdx] = (unichar)' '; + cIdx++; + delta += newlineRange.length; + range.location += delta, range.length -= delta; + if (newlineRange.length == 1 && range.length >= 1 && + [string characterAtIndex:newlineRange.location] == (unichar)'\r' && + [string characterAtIndex:range.location] == (unichar)'\n') { + // CRLF sequence, skip the LF + range.location += 1, range.length -= 1; + } + } + } + len = cIdx; + } else { + [string getCharacters:characters range:NSMakeRange(0, len)]; + } + + // Create storage for glyphs and advances + CGGlyph *glyphs; + CGFloat *advances; + { + NSUInteger maxRunLength = 0; + ZAttributeRun *a = [attributes objectAtIndex:0]; + for (NSUInteger i = 1; i < [attributes count]; i++) { + ZAttributeRun *b = [attributes objectAtIndex:i]; + maxRunLength = MAX(maxRunLength, b.index - a.index); + a = b; + } + maxRunLength = MAX(maxRunLength, len - a.index); + maxRunLength++; // for a potential ellipsis + glyphs = (CGGlyph *)malloc(sizeof(CGGlyph) * maxRunLength); + advances = (CGFloat *)malloc(sizeof(CGFloat) * maxRunLength); + } + + // Use this table to cache all fontTable objects + CFMutableDictionaryRef fontTableMap = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, + &kFontTableDictionaryValueCallBacks); + + // Fetch initial style values + NSUInteger currentRunIdx = 0; + ZAttributeRun *currentRun; + NSUInteger nextRunStart; + ZFont *currentFont; + fontTable *currentTable; + +#define READ_RUN() readRunInformation(attributes, len, fontTableMap, \ + currentRunIdx, ¤tRun, &nextRunStart, \ + ¤tFont, ¤tTable) + + READ_RUN(); + + // fetch the glyphs for the first run + size_t glyphCount; + NSUInteger glyphIdx; + +#define READ_GLYPHS() do { \ + mapCharactersToGlyphsInFont(currentTable, &characters[currentRun.index], (nextRunStart - currentRun.index), glyphs, &glyphCount); \ + mapGlyphsToAdvancesInFont(currentFont, (nextRunStart - currentRun.index), glyphs, advances); \ + glyphIdx = 0; \ + } while (0) + + READ_GLYPHS(); + + NSMutableCharacterSet *alphaCharset = [NSMutableCharacterSet alphanumericCharacterSet]; + [alphaCharset addCharactersInString:@"([{'\"\u2019\u02BC"]; + + // scan left-to-right looking for newlines or until we hit the width constraint + // When we hit a wrapping point, calculate truncation as follows: + // If we have room to draw at least one more character on the next line, no truncation + // Otherwise apply the truncation algorithm to the current line. + // After calculating any truncation, draw. + // Each time we hit the end of an attribute run, calculate the new font and make sure + // it fits (vertically) within the size constraint. If not, truncate this line. + // When we draw, iterate over the attribute runs for this line and draw each run separately + BOOL lastLine = NO; // used to indicate truncation and to stop the iterating + NSUInteger lineCount = 1; + while (idx < len && !lastLine) { + if (maxLines > 0 && lineCount == maxLines) { + lastLine = YES; + } + // scan left-to-right + struct { + NSUInteger index; + NSUInteger glyphIndex; + NSUInteger currentRunIdx; + } indexCache = { idx, glyphIdx, currentRunIdx }; + CGSize lineSize = CGSizeMake(0, currentFont.leading); + CGFloat lineAscender = currentFont.ascender; + struct { + NSUInteger index; + NSUInteger glyphIndex; + NSUInteger currentRunIdx; + CGSize lineSize; + } lastWrapCache = {0, 0, 0, CGSizeZero}; + BOOL inAlpha = NO; // used for calculating wrap points + + BOOL finishLine = NO; + for (;idx <= len && !finishLine;) { + NSUInteger skipCount = 0; + if (idx == len) { + finishLine = YES; + lastLine = YES; + } else { + if (idx >= nextRunStart) { + // cycle the font and table and grab the next set of glyphs + do { + currentRunIdx++; + READ_RUN(); + } while (idx >= nextRunStart); + READ_GLYPHS(); + // re-scan the characters to synchronize the glyph index + for (NSUInteger j = currentRun.index; j < idx; j++) { + if (UnicharIsHighSurrogate(characters[j]) && j+1 lineSize.height) { + lineSize.height = currentFont.leading; + if (retValue.height + currentFont.ascender > constrainedSize.height) { + lastLine = YES; + finishLine = YES; + } + } + lineAscender = MAX(lineAscender, currentFont.ascender); + } + unichar c = characters[idx]; + // Mark a wrap point before spaces and after any stretch of non-alpha characters + BOOL markWrap = NO; + if (c == (unichar)' ') { + markWrap = YES; + } else if ([alphaCharset characterIsMember:c]) { + if (!inAlpha) { + markWrap = YES; + inAlpha = YES; + } + } else { + inAlpha = NO; + } + if (markWrap) { + lastWrapCache = (__typeof__(lastWrapCache)){ + .index = idx, + .glyphIndex = glyphIdx, + .currentRunIdx = currentRunIdx, + .lineSize = lineSize + }; + } + // process the line + if (c == (unichar)'\n' || c == 0x0085) { // U+0085 is the NEXT_LINE unicode character + finishLine = YES; + skipCount = 1; + } else if (c == (unichar)'\r') { + finishLine = YES; + // check for CRLF + if (idx+1 < len && characters[idx+1] == (unichar)'\n') { + skipCount = 2; + } else { + skipCount = 1; + } + } else if (lineSize.width + advances[glyphIdx] > constrainedSize.width) { + finishLine = YES; + if (retValue.height + lineSize.height + currentFont.ascender > constrainedSize.height) { + lastLine = YES; + } + // walk backwards if wrapping is necessary + if (lastWrapCache.index > indexCache.index && lineBreakMode != UILineBreakModeCharacterWrap && + (!lastLine || lineBreakMode != UILineBreakModeClip)) { + // we're doing some sort of word wrapping + idx = lastWrapCache.index; + lineSize = lastWrapCache.lineSize; + if (!lastLine) { + // re-check if this is the last line + if (lastWrapCache.currentRunIdx != currentRunIdx) { + currentRunIdx = lastWrapCache.currentRunIdx; + READ_RUN(); + READ_GLYPHS(); + } + if (retValue.height + lineSize.height + currentFont.ascender > constrainedSize.height) { + lastLine = YES; + } + } + glyphIdx = lastWrapCache.glyphIndex; + // skip any spaces + for (NSUInteger j = idx; j < len && characters[j] == (unichar)' '; j++) { + skipCount++; + } + } + } + } + if (finishLine) { + // TODO: support head/middle truncation + if (lastLine && idx < len && lineBreakMode == UILineBreakModeTailTruncation) { + // truncate + unichar ellipsis = 0x2026; // ellipsis (…) + CGGlyph ellipsisGlyph; + mapCharactersToGlyphsInFont(currentTable, &ellipsis, 1, &ellipsisGlyph, NULL); + CGFloat ellipsisWidth; + mapGlyphsToAdvancesInFont(currentFont, 1, &ellipsisGlyph, &ellipsisWidth); + while ((idx - indexCache.index) > 1 && lineSize.width + ellipsisWidth > constrainedSize.width) { + // we have more than 1 character and we're too wide, so back up + idx--; + if (UnicharIsHighSurrogate(characters[idx]) && UnicharIsLowSurrogate(characters[idx+1])) { + idx--; + } + if (idx < currentRun.index) { + ZFont *oldFont = currentFont; + do { + currentRunIdx--; + READ_RUN(); + } while (idx < currentRun.index); + READ_GLYPHS(); + glyphIdx = glyphCount-1; + if (oldFont != currentFont) { + mapCharactersToGlyphsInFont(currentTable, &ellipsis, 1, &ellipsisGlyph, NULL); + mapGlyphsToAdvancesInFont(currentFont, 1, &ellipsisGlyph, &ellipsisWidth); + } + } else { + glyphIdx--; + } + lineSize.width -= advances[glyphIdx]; + } + // skip any spaces before truncating + while ((idx - indexCache.index) > 1 && characters[idx-1] == (unichar)' ') { + idx--; + if (idx < currentRun.index) { + currentRunIdx--; + READ_RUN(); + READ_GLYPHS(); + glyphIdx = glyphCount-1; + } else { + glyphIdx--; + } + lineSize.width -= advances[glyphIdx]; + } + lineSize.width += ellipsisWidth; + glyphs[glyphIdx] = ellipsisGlyph; + idx++; + glyphIdx++; + } + retValue.width = MAX(retValue.width, lineSize.width); + retValue.height += lineSize.height; + + // draw + if (performDraw) { + switch (alignment) { + case UITextAlignmentLeft: + drawPoint.x = 0; + break; + case UITextAlignmentCenter: + drawPoint.x = (constrainedSize.width - lineSize.width) / 2.0f; + break; + case UITextAlignmentRight: + drawPoint.x = constrainedSize.width - lineSize.width; + break; + } + NSUInteger stopGlyphIdx = glyphIdx; + NSUInteger lastRunIdx = currentRunIdx; + NSUInteger stopCharIdx = idx; + idx = indexCache.index; + if (currentRunIdx != indexCache.currentRunIdx) { + currentRunIdx = indexCache.currentRunIdx; + READ_RUN(); + READ_GLYPHS(); + } + glyphIdx = indexCache.glyphIndex; + for (NSUInteger drawIdx = currentRunIdx; drawIdx <= lastRunIdx; drawIdx++) { + if (drawIdx != currentRunIdx) { + currentRunIdx = drawIdx; + READ_RUN(); + READ_GLYPHS(); + } + NSUInteger numGlyphs; + if (drawIdx == lastRunIdx) { + numGlyphs = stopGlyphIdx - glyphIdx; + idx = stopCharIdx; + } else { + numGlyphs = glyphCount - glyphIdx; + idx = nextRunStart; + } + CGContextSetFont(ctx, currentFont.cgFont); + CGContextSetFontSize(ctx, currentFont.pointSize); + // calculate the fragment size + CGFloat fragmentWidth = 0; + for (NSUInteger g = 0; g < numGlyphs; g++) { + fragmentWidth += advances[glyphIdx + g]; + } + + if (!ignoreColor) { + UIColor *foregroundColor = getValueOrDefaultForRun(currentRun, ZForegroundColorAttributeName); + UIColor *backgroundColor = getValueOrDefaultForRun(currentRun, ZBackgroundColorAttributeName); + if (backgroundColor != nil && ![backgroundColor isEqual:[UIColor clearColor]]) { + [backgroundColor setFill]; + UIRectFillUsingBlendMode((CGRect){ drawPoint, { fragmentWidth, lineSize.height } }, kCGBlendModeNormal); + } + [foregroundColor setFill]; + } + + CGContextShowGlyphsAtPoint(ctx, drawPoint.x, drawPoint.y + lineAscender, &glyphs[glyphIdx], numGlyphs); + NSNumber *underlineStyle = getValueOrDefaultForRun(currentRun, ZUnderlineStyleAttributeName); + if ([underlineStyle integerValue] & ZUnderlineStyleMask) { + // we only support single for the time being + UIRectFill(CGRectMake(drawPoint.x, drawPoint.y + lineAscender, fragmentWidth, 1)); + } + drawPoint.x += fragmentWidth; + glyphIdx += numGlyphs; + } + drawPoint.y += lineSize.height; + } + idx += skipCount; + glyphIdx += skipCount; + lineCount++; + } else { + lineSize.width += advances[glyphIdx]; + glyphIdx++; + idx++; + if (idx < len && UnicharIsHighSurrogate(characters[idx-1]) && UnicharIsLowSurrogate(characters[idx])) { + // skip the second half of the surrogate pair + idx++; + } + } + } + } + CFRelease(fontTableMap); + free(glyphs); + free(advances); + free(characters); + +#undef READ_GLYPHS +#undef READ_RUN + + return retValue; +} + +static NSArray *attributeRunForFont(ZFont *font) { + return [NSArray arrayWithObject:[ZAttributeRun attributeRunWithIndex:0 + attributes:[NSDictionary dictionaryWithObject:font + forKey:ZFontAttributeName]]]; +} + +static CGSize drawTextInRect(CGRect rect, NSString *text, NSArray *attributes, UILineBreakMode lineBreakMode, + UITextAlignment alignment, NSUInteger numberOfLines, BOOL ignoreColor) { + CGContextRef ctx = UIGraphicsGetCurrentContext(); + + CGContextSaveGState(ctx); + + // flip it upside-down because our 0,0 is upper-left, whereas ttfs are for screens where 0,0 is lower-left + CGAffineTransform textTransform = CGAffineTransformMake(1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f); + CGContextSetTextMatrix(ctx, textTransform); + + CGContextTranslateCTM(ctx, rect.origin.x, rect.origin.y); + + CGContextSetTextDrawingMode(ctx, kCGTextFill); + CGSize size = drawOrSizeTextConstrainedToSize(YES, text, attributes, rect.size, numberOfLines, lineBreakMode, alignment, ignoreColor); + + CGContextRestoreGState(ctx); + + return size; +} + +@implementation NSString (FontLabelStringDrawing) +// CGFontRef-based methods +- (CGSize)sizeWithCGFont:(CGFontRef)font pointSize:(CGFloat)pointSize { + return [self sizeWithZFont:[ZFont fontWithCGFont:font size:pointSize]]; +} + +- (CGSize)sizeWithCGFont:(CGFontRef)font pointSize:(CGFloat)pointSize constrainedToSize:(CGSize)size { + return [self sizeWithZFont:[ZFont fontWithCGFont:font size:pointSize] constrainedToSize:size]; +} + +- (CGSize)sizeWithCGFont:(CGFontRef)font pointSize:(CGFloat)pointSize constrainedToSize:(CGSize)size + lineBreakMode:(UILineBreakMode)lineBreakMode { + return [self sizeWithZFont:[ZFont fontWithCGFont:font size:pointSize] constrainedToSize:size lineBreakMode:lineBreakMode]; +} + +- (CGSize)drawAtPoint:(CGPoint)point withCGFont:(CGFontRef)font pointSize:(CGFloat)pointSize { + return [self drawAtPoint:point withZFont:[ZFont fontWithCGFont:font size:pointSize]]; +} + +- (CGSize)drawInRect:(CGRect)rect withCGFont:(CGFontRef)font pointSize:(CGFloat)pointSize { + return [self drawInRect:rect withZFont:[ZFont fontWithCGFont:font size:pointSize]]; +} + +- (CGSize)drawInRect:(CGRect)rect withCGFont:(CGFontRef)font pointSize:(CGFloat)pointSize lineBreakMode:(UILineBreakMode)lineBreakMode { + return [self drawInRect:rect withZFont:[ZFont fontWithCGFont:font size:pointSize] lineBreakMode:lineBreakMode]; +} + +- (CGSize)drawInRect:(CGRect)rect withCGFont:(CGFontRef)font pointSize:(CGFloat)pointSize + lineBreakMode:(UILineBreakMode)lineBreakMode alignment:(UITextAlignment)alignment { + return [self drawInRect:rect withZFont:[ZFont fontWithCGFont:font size:pointSize] lineBreakMode:lineBreakMode alignment:alignment]; +} + +// ZFont-based methods +- (CGSize)sizeWithZFont:(ZFont *)font { + CGSize size = drawOrSizeTextConstrainedToSize(NO, self, attributeRunForFont(font), CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX), 1, + UILineBreakModeClip, UITextAlignmentLeft, YES); + return CGSizeMake(ceilf(size.width), ceilf(size.height)); +} + +- (CGSize)sizeWithZFont:(ZFont *)font constrainedToSize:(CGSize)size { + return [self sizeWithZFont:font constrainedToSize:size lineBreakMode:UILineBreakModeWordWrap]; +} + +/* + According to experimentation with UIStringDrawing, this can actually return a CGSize whose height is greater + than the one passed in. The two cases are as follows: + 1. If the given size parameter's height is smaller than a single line, the returned value will + be the height of one line. + 2. If the given size parameter's height falls between multiples of a line height, and the wrapped string + actually extends past the size.height, and the difference between size.height and the previous multiple + of a line height is >= the font's ascender, then the returned size's height is extended to the next line. + To put it simply, if the baseline point of a given line falls in the given size, the entire line will + be present in the output size. + */ +- (CGSize)sizeWithZFont:(ZFont *)font constrainedToSize:(CGSize)size lineBreakMode:(UILineBreakMode)lineBreakMode { + size = drawOrSizeTextConstrainedToSize(NO, self, attributeRunForFont(font), size, 0, lineBreakMode, UITextAlignmentLeft, YES); + return CGSizeMake(ceilf(size.width), ceilf(size.height)); +} + +- (CGSize)sizeWithZFont:(ZFont *)font constrainedToSize:(CGSize)size lineBreakMode:(UILineBreakMode)lineBreakMode + numberOfLines:(NSUInteger)numberOfLines { + size = drawOrSizeTextConstrainedToSize(NO, self, attributeRunForFont(font), size, numberOfLines, lineBreakMode, UITextAlignmentLeft, YES); + return CGSizeMake(ceilf(size.width), ceilf(size.height)); +} + +- (CGSize)drawAtPoint:(CGPoint)point withZFont:(ZFont *)font { + return [self drawAtPoint:point forWidth:CGFLOAT_MAX withZFont:font lineBreakMode:UILineBreakModeClip]; +} + +- (CGSize)drawAtPoint:(CGPoint)point forWidth:(CGFloat)width withZFont:(ZFont *)font lineBreakMode:(UILineBreakMode)lineBreakMode { + return drawTextInRect((CGRect){ point, { width, CGFLOAT_MAX } }, self, attributeRunForFont(font), lineBreakMode, UITextAlignmentLeft, 1, YES); +} + +- (CGSize)drawInRect:(CGRect)rect withZFont:(ZFont *)font { + return [self drawInRect:rect withZFont:font lineBreakMode:UILineBreakModeWordWrap]; +} + +- (CGSize)drawInRect:(CGRect)rect withZFont:(ZFont *)font lineBreakMode:(UILineBreakMode)lineBreakMode { + return [self drawInRect:rect withZFont:font lineBreakMode:lineBreakMode alignment:UITextAlignmentLeft]; +} + +- (CGSize)drawInRect:(CGRect)rect withZFont:(ZFont *)font lineBreakMode:(UILineBreakMode)lineBreakMode + alignment:(UITextAlignment)alignment { + return drawTextInRect(rect, self, attributeRunForFont(font), lineBreakMode, alignment, 0, YES); +} + +- (CGSize)drawInRect:(CGRect)rect withZFont:(ZFont *)font lineBreakMode:(UILineBreakMode)lineBreakMode + alignment:(UITextAlignment)alignment numberOfLines:(NSUInteger)numberOfLines { + return drawTextInRect(rect, self, attributeRunForFont(font), lineBreakMode, alignment, numberOfLines, YES); +} +@end + +@implementation ZAttributedString (ZAttributedStringDrawing) +- (CGSize)size { + CGSize size = drawOrSizeTextConstrainedToSize(NO, self.string, self.attributes, CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX), 1, + UILineBreakModeClip, UITextAlignmentLeft, NO); + return CGSizeMake(ceilf(size.width), ceilf(size.height)); +} + +- (CGSize)sizeConstrainedToSize:(CGSize)size { + return [self sizeConstrainedToSize:size lineBreakMode:UILineBreakModeWordWrap]; +} + +- (CGSize)sizeConstrainedToSize:(CGSize)size lineBreakMode:(UILineBreakMode)lineBreakMode { + size = drawOrSizeTextConstrainedToSize(NO, self.string, self.attributes, size, 0, lineBreakMode, UITextAlignmentLeft, NO); + return CGSizeMake(ceilf(size.width), ceilf(size.height)); +} + +- (CGSize)sizeConstrainedToSize:(CGSize)size lineBreakMode:(UILineBreakMode)lineBreakMode + numberOfLines:(NSUInteger)numberOfLines { + size = drawOrSizeTextConstrainedToSize(NO, self.string, self.attributes, size, numberOfLines, lineBreakMode, UITextAlignmentLeft, NO); + return CGSizeMake(ceilf(size.width), ceilf(size.height)); +} + +- (CGSize)drawAtPoint:(CGPoint)point { + return [self drawAtPoint:point forWidth:CGFLOAT_MAX lineBreakMode:UILineBreakModeClip]; +} + +- (CGSize)drawAtPoint:(CGPoint)point forWidth:(CGFloat)width lineBreakMode:(UILineBreakMode)lineBreakMode { + return drawTextInRect((CGRect){ point, { width, CGFLOAT_MAX } }, self.string, self.attributes, lineBreakMode, UITextAlignmentLeft, 1, NO); +} + +- (CGSize)drawInRect:(CGRect)rect { + return [self drawInRect:rect withLineBreakMode:UILineBreakModeWordWrap]; +} + +- (CGSize)drawInRect:(CGRect)rect withLineBreakMode:(UILineBreakMode)lineBreakMode { + return [self drawInRect:rect withLineBreakMode:lineBreakMode alignment:UITextAlignmentLeft]; +} + +- (CGSize)drawInRect:(CGRect)rect withLineBreakMode:(UILineBreakMode)lineBreakMode alignment:(UITextAlignment)alignment { + return drawTextInRect(rect, self.string, self.attributes, lineBreakMode, alignment, 0, NO); +} + +- (CGSize)drawInRect:(CGRect)rect withLineBreakMode:(UILineBreakMode)lineBreakMode alignment:(UITextAlignment)alignment + numberOfLines:(NSUInteger)numberOfLines { + return drawTextInRect(rect, self.string, self.attributes, lineBreakMode, alignment, numberOfLines, NO); +} +@end diff --git a/tweejump/libs/FontLabel/FontManager.h b/tweejump/libs/FontLabel/FontManager.h new file mode 100755 index 0000000..1592b8a --- /dev/null +++ b/tweejump/libs/FontLabel/FontManager.h @@ -0,0 +1,85 @@ +// +// FontManager.h +// FontLabel +// +// Created by Kevin Ballard on 5/5/09. +// Copyright © 2009 Zynga Game Networks +// +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#import +#import + +@class ZFont; + +@interface FontManager : NSObject { + CFMutableDictionaryRef fonts; + NSMutableDictionary *urls; +} ++ (FontManager *)sharedManager; +/*! + @method + @abstract Loads a TTF font from the main bundle + @param filename The name of the font file to load (with or without extension). + @return YES if the font was loaded, NO if an error occurred + @discussion If the font has already been loaded, this method does nothing and returns YES. + This method first attempts to load the font by appending .ttf to the filename. + If that file does not exist, it tries the filename exactly as given. +*/ +- (BOOL)loadFont:(NSString *)filename; +/*! + @method + @abstract Loads a font from the given file URL + @param url A file URL that points to a font file + @return YES if the font was loaded, NO if an error occurred + @discussion If the font has already been loaded, this method does nothing and returns YES. +*/ +- (BOOL)loadFontURL:(NSURL *)url; +/*! + @method + @abstract Returns the loaded font with the given filename + @param filename The name of the font file that was given to -loadFont: + @return A CGFontRef, or NULL if the specified font cannot be found + @discussion If the font has not been loaded yet, -loadFont: will be + called with the given name first. +*/ +- (CGFontRef)fontWithName:(NSString *)filename __AVAILABILITY_INTERNAL_DEPRECATED; +/*! + @method + @abstract Returns a ZFont object corresponding to the loaded font with the given filename and point size + @param filename The name of the font file that was given to -loadFont: + @param pointSize The point size of the font + @return A ZFont, or NULL if the specified font cannot be found + @discussion If the font has not been loaded yet, -loadFont: will be + called with the given name first. +*/ +- (ZFont *)zFontWithName:(NSString *)filename pointSize:(CGFloat)pointSize; +/*! + @method + @abstract Returns a ZFont object corresponding to the loaded font with the given file URL and point size + @param url A file URL that points to a font file + @param pointSize The point size of the font + @return A ZFont, or NULL if the specified font cannot be loaded + @discussion If the font has not been loaded yet, -loadFontURL: will be called with the given URL first. +*/ +- (ZFont *)zFontWithURL:(NSURL *)url pointSize:(CGFloat)pointSize; +/*! + @method + @abstract Returns a CFArrayRef of all loaded CGFont objects + @return A CFArrayRef of all loaded CGFont objects + @description You are responsible for releasing the CFArrayRef +*/ +- (CFArrayRef)copyAllFonts; +@end diff --git a/tweejump/libs/FontLabel/FontManager.m b/tweejump/libs/FontLabel/FontManager.m new file mode 100755 index 0000000..12eac2d --- /dev/null +++ b/tweejump/libs/FontLabel/FontManager.m @@ -0,0 +1,123 @@ +// +// FontManager.m +// FontLabel +// +// Created by Kevin Ballard on 5/5/09. +// Copyright © 2009 Zynga Game Networks +// +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#import "FontManager.h" +#import "ZFont.h" + +static FontManager *sharedFontManager = nil; + +@implementation FontManager ++ (FontManager *)sharedManager { + @synchronized(self) { + if (sharedFontManager == nil) { + sharedFontManager = [[self alloc] init]; + } + } + return sharedFontManager; +} + +- (id)init { + if ((self = [super init])) { + fonts = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); + urls = [[NSMutableDictionary alloc] init]; + } + return self; +} + +- (BOOL)loadFont:(NSString *)filename { + NSString *fontPath = [[NSBundle mainBundle] pathForResource:filename ofType:@"ttf"]; + if (fontPath == nil) { + fontPath = [[NSBundle mainBundle] pathForResource:filename ofType:nil]; + } + if (fontPath == nil) return NO; + + NSURL *url = [NSURL fileURLWithPath:fontPath]; + if ([self loadFontURL:url]) { + [urls setObject:url forKey:filename]; + return YES; + } + return NO; +} + +- (BOOL)loadFontURL:(NSURL *)url { + CGDataProviderRef fontDataProvider = CGDataProviderCreateWithURL((CFURLRef)url); + if (fontDataProvider == NULL) return NO; + CGFontRef newFont = CGFontCreateWithDataProvider(fontDataProvider); + CGDataProviderRelease(fontDataProvider); + if (newFont == NULL) return NO; + + CFDictionarySetValue(fonts, url, newFont); + CGFontRelease(newFont); + return YES; +} + +- (CGFontRef)fontWithName:(NSString *)filename { + CGFontRef font = NULL; + NSURL *url = [urls objectForKey:filename]; + if (url == nil && [self loadFont:filename]) { + url = [urls objectForKey:filename]; + } + if (url != nil) { + font = (CGFontRef)CFDictionaryGetValue(fonts, url); + } + return font; +} + +- (ZFont *)zFontWithName:(NSString *)filename pointSize:(CGFloat)pointSize { + NSURL *url = [urls objectForKey:filename]; + if (url == nil && [self loadFont:filename]) { + url = [urls objectForKey:filename]; + } + if (url != nil) { + CGFontRef cgFont = (CGFontRef)CFDictionaryGetValue(fonts, url); + if (cgFont != NULL) { + return [ZFont fontWithCGFont:cgFont size:pointSize]; + } + } + return nil; +} + +- (ZFont *)zFontWithURL:(NSURL *)url pointSize:(CGFloat)pointSize { + CGFontRef cgFont = (CGFontRef)CFDictionaryGetValue(fonts, url); + if (cgFont == NULL && [self loadFontURL:url]) { + cgFont = (CGFontRef)CFDictionaryGetValue(fonts, url); + } + if (cgFont != NULL) { + return [ZFont fontWithCGFont:cgFont size:pointSize]; + } + return nil; +} + +- (CFArrayRef)copyAllFonts { + CFIndex count = CFDictionaryGetCount(fonts); + CGFontRef *values = (CGFontRef *)malloc(sizeof(CGFontRef) * count); + CFDictionaryGetKeysAndValues(fonts, NULL, (const void **)values); + CFArrayRef array = CFArrayCreate(NULL, (const void **)values, count, &kCFTypeArrayCallBacks); + free(values); + return array; +} + +- (void)dealloc { + CFRelease(fonts); + [urls release]; + [super dealloc]; +} +@end diff --git a/tweejump/libs/FontLabel/ZAttributedString.h b/tweejump/libs/FontLabel/ZAttributedString.h new file mode 100755 index 0000000..e194c81 --- /dev/null +++ b/tweejump/libs/FontLabel/ZAttributedString.h @@ -0,0 +1,77 @@ +// +// ZAttributedString.h +// FontLabel +// +// Created by Kevin Ballard on 9/22/09. +// Copyright 2009 Zynga Game Networks. All rights reserved. +// + +#import + +#if NS_BLOCKS_AVAILABLE +#define Z_BLOCKS 1 +#else +// set this to 1 if you are using PLBlocks +#define Z_BLOCKS 0 +#endif + +#if Z_BLOCKS +enum { + ZAttributedStringEnumerationReverse = (1UL << 1), + ZAttributedStringEnumerationLongestEffectiveRangeNotRequired = (1UL << 20) +}; +typedef NSUInteger ZAttributedStringEnumerationOptions; +#endif + +@interface ZAttributedString : NSObject { + NSMutableString *_buffer; + NSMutableArray *_attributes; +} +@property (nonatomic, readonly) NSUInteger length; +@property (nonatomic, readonly) NSString *string; +- (id)initWithAttributedString:(ZAttributedString *)attr; +- (id)initWithString:(NSString *)str; +- (id)initWithString:(NSString *)str attributes:(NSDictionary *)attributes; +- (id)attribute:(NSString *)attributeName atIndex:(NSUInteger)index effectiveRange:(NSRangePointer)aRange; +- (id)attribute:(NSString *)attributeName atIndex:(NSUInteger)index longestEffectiveRange:(NSRangePointer)aRange inRange:(NSRange)rangeLimit; +- (ZAttributedString *)attributedSubstringFromRange:(NSRange)aRange; +- (NSDictionary *)attributesAtIndex:(NSUInteger)index effectiveRange:(NSRangePointer)aRange; +- (NSDictionary *)attributesAtIndex:(NSUInteger)index longestEffectiveRange:(NSRangePointer)aRange inRange:(NSRange)rangeLimit; +#if Z_BLOCKS +- (void)enumerateAttribute:(NSString *)attrName inRange:(NSRange)enumerationRange options:(ZAttributedStringEnumerationOptions)opts + usingBlock:(void (^)(id value, NSRange range, BOOL *stop))block; +- (void)enumerateAttributesInRange:(NSRange)enumerationRange options:(ZAttributedStringEnumerationOptions)opts + usingBlock:(void (^)(NSDictionary *attrs, NSRange range, BOOL *stop))block; +#endif +- (BOOL)isEqualToAttributedString:(ZAttributedString *)otherString; +@end + +@interface ZMutableAttributedString : ZAttributedString { +} +- (void)addAttribute:(NSString *)name value:(id)value range:(NSRange)range; +- (void)addAttributes:(NSDictionary *)attributes range:(NSRange)range; +- (void)appendAttributedString:(ZAttributedString *)str; +- (void)deleteCharactersInRange:(NSRange)range; +- (void)insertAttributedString:(ZAttributedString *)str atIndex:(NSUInteger)idx; +- (void)removeAttribute:(NSString *)name range:(NSRange)range; +- (void)replaceCharactersInRange:(NSRange)range withAttributedString:(ZAttributedString *)str; +- (void)replaceCharactersInRange:(NSRange)range withString:(NSString *)str; +- (void)setAttributedString:(ZAttributedString *)str; +- (void)setAttributes:(NSDictionary *)attributes range:(NSRange)range; +@end + +extern NSString * const ZFontAttributeName; +extern NSString * const ZForegroundColorAttributeName; +extern NSString * const ZBackgroundColorAttributeName; +extern NSString * const ZUnderlineStyleAttributeName; + +enum { + ZUnderlineStyleNone = 0x00, + ZUnderlineStyleSingle = 0x01 +}; +#define ZUnderlineStyleMask 0x00FF + +enum { + ZUnderlinePatternSolid = 0x0000 +}; +#define ZUnderlinePatternMask 0xFF00 diff --git a/tweejump/libs/FontLabel/ZAttributedString.m b/tweejump/libs/FontLabel/ZAttributedString.m new file mode 100755 index 0000000..a4163bc --- /dev/null +++ b/tweejump/libs/FontLabel/ZAttributedString.m @@ -0,0 +1,597 @@ +// +// ZAttributedString.m +// FontLabel +// +// Created by Kevin Ballard on 9/22/09. +// Copyright 2009 Zynga Game Networks. All rights reserved. +// + +#import "ZAttributedString.h" +#import "ZAttributedStringPrivate.h" + +@interface ZAttributedString () +- (NSUInteger)indexOfEffectiveAttributeRunForIndex:(NSUInteger)index; +- (NSDictionary *)attributesAtIndex:(NSUInteger)index effectiveRange:(NSRangePointer)aRange uniquingOnName:(NSString *)attributeName; +- (NSDictionary *)attributesAtIndex:(NSUInteger)index longestEffectiveRange:(NSRangePointer)aRange + inRange:(NSRange)rangeLimit uniquingOnName:(NSString *)attributeName; +@end + +@interface ZAttributedString () +@property (nonatomic, readonly) NSArray *attributes; +@end + +@implementation ZAttributedString +@synthesize string = _buffer; +@synthesize attributes = _attributes; + +- (id)initWithAttributedString:(ZAttributedString *)attr { + NSParameterAssert(attr != nil); + if ((self = [super init])) { + _buffer = [attr->_buffer mutableCopy]; + _attributes = [[NSMutableArray alloc] initWithArray:attr->_attributes copyItems:YES]; + } + return self; +} + +- (id)initWithString:(NSString *)str { + return [self initWithString:str attributes:nil]; +} + +- (id)initWithString:(NSString *)str attributes:(NSDictionary *)attributes { + if ((self = [super init])) { + _buffer = [str mutableCopy]; + _attributes = [[NSMutableArray alloc] initWithObjects:[ZAttributeRun attributeRunWithIndex:0 attributes:attributes], nil]; + } + return self; +} + +- (id)init { + return [self initWithString:@"" attributes:nil]; +} + +- (id)initWithCoder:(NSCoder *)decoder { + if ((self = [super init])) { + _buffer = [[decoder decodeObjectForKey:@"buffer"] mutableCopy]; + _attributes = [[decoder decodeObjectForKey:@"attributes"] mutableCopy]; + } + return self; +} + +- (void)encodeWithCoder:(NSCoder *)aCoder { + [aCoder encodeObject:_buffer forKey:@"buffer"]; + [aCoder encodeObject:_attributes forKey:@"attributes"]; +} + +- (id)copyWithZone:(NSZone *)zone { + return [self retain]; +} + +- (id)mutableCopyWithZone:(NSZone *)zone { + return [(ZMutableAttributedString *)[ZMutableAttributedString allocWithZone:zone] initWithAttributedString:self]; +} + +- (NSUInteger)length { + return [_buffer length]; +} + +- (NSString *)description { + NSMutableArray *components = [NSMutableArray arrayWithCapacity:[_attributes count]*2]; + NSRange range = NSMakeRange(0, 0); + for (NSUInteger i = 0; i <= [_attributes count]; i++) { + range.location = NSMaxRange(range); + ZAttributeRun *run; + if (i < [_attributes count]) { + run = [_attributes objectAtIndex:i]; + range.length = run.index - range.location; + } else { + run = nil; + range.length = [_buffer length] - range.location; + } + if (range.length > 0) { + [components addObject:[NSString stringWithFormat:@"\"%@\"", [_buffer substringWithRange:range]]]; + } + if (run != nil) { + NSMutableArray *attrDesc = [NSMutableArray arrayWithCapacity:[run.attributes count]]; + for (id key in run.attributes) { + [attrDesc addObject:[NSString stringWithFormat:@"%@: %@", key, [run.attributes objectForKey:key]]]; + } + [components addObject:[NSString stringWithFormat:@"{%@}", [attrDesc componentsJoinedByString:@", "]]]; + } + } + return [NSString stringWithFormat:@"%@", [components componentsJoinedByString:@" "]]; +} + +- (id)attribute:(NSString *)attributeName atIndex:(NSUInteger)index effectiveRange:(NSRangePointer)aRange { + NSParameterAssert(attributeName != nil); + return [[self attributesAtIndex:index effectiveRange:aRange uniquingOnName:attributeName] objectForKey:attributeName]; +} + +- (id)attribute:(NSString *)attributeName atIndex:(NSUInteger)index longestEffectiveRange:(NSRangePointer)aRange inRange:(NSRange)rangeLimit { + NSParameterAssert(attributeName != nil); + return [[self attributesAtIndex:index longestEffectiveRange:aRange inRange:rangeLimit uniquingOnName:attributeName] objectForKey:attributeName]; +} + +- (ZAttributedString *)attributedSubstringFromRange:(NSRange)aRange { + if (NSMaxRange(aRange) > [_buffer length]) { + @throw [NSException exceptionWithName:NSRangeException reason:@"range was outisde of the attributed string" userInfo:nil]; + } + ZMutableAttributedString *newStr = [self mutableCopy]; + if (aRange.location > 0) { + [newStr deleteCharactersInRange:NSMakeRange(0, aRange.location)]; + } + if (NSMaxRange(aRange) < [_buffer length]) { + [newStr deleteCharactersInRange:NSMakeRange(aRange.length, [_buffer length] - NSMaxRange(aRange))]; + } + return [newStr autorelease]; +} + +- (NSDictionary *)attributesAtIndex:(NSUInteger)index effectiveRange:(NSRangePointer)aRange { + return [NSDictionary dictionaryWithDictionary:[self attributesAtIndex:index effectiveRange:aRange uniquingOnName:nil]]; +} + +- (NSDictionary *)attributesAtIndex:(NSUInteger)index longestEffectiveRange:(NSRangePointer)aRange inRange:(NSRange)rangeLimit { + return [NSDictionary dictionaryWithDictionary:[self attributesAtIndex:index longestEffectiveRange:aRange inRange:rangeLimit uniquingOnName:nil]]; +} + +#if Z_BLOCKS +// Warning: this code has not been tested. The only guarantee is that it compiles. +- (void)enumerateAttribute:(NSString *)attrName inRange:(NSRange)enumerationRange options:(ZAttributedStringEnumerationOptions)opts + usingBlock:(void (^)(id, NSRange, BOOL*))block { + if (opts & ZAttributedStringEnumerationLongestEffectiveRangeNotRequired) { + [self enumerateAttributesInRange:enumerationRange options:opts usingBlock:^(NSDictionary *attrs, NSRange range, BOOL *stop) { + id value = [attrs objectForKey:attrName]; + if (value != nil) { + block(value, range, stop); + } + }]; + } else { + __block id oldValue = nil; + __block NSRange effectiveRange = NSMakeRange(0, 0); + [self enumerateAttributesInRange:enumerationRange options:opts usingBlock:^(NSDictionary *attrs, NSRange range, BOOL *stop) { + id value = [attrs objectForKey:attrName]; + if (oldValue == nil) { + oldValue = value; + effectiveRange = range; + } else if (value != nil && [oldValue isEqual:value]) { + // combine the attributes + effectiveRange = NSUnionRange(effectiveRange, range); + } else { + BOOL innerStop = NO; + block(oldValue, effectiveRange, &innerStop); + if (innerStop) { + *stop = YES; + oldValue = nil; + } else { + oldValue = value; + } + } + }]; + if (oldValue != nil) { + BOOL innerStop = NO; // necessary for the block, but unused + block(oldValue, effectiveRange, &innerStop); + } + } +} + +- (void)enumerateAttributesInRange:(NSRange)enumerationRange options:(ZAttributedStringEnumerationOptions)opts + usingBlock:(void (^)(NSDictionary*, NSRange, BOOL*))block { + // copy the attributes so we can mutate the string if necessary during enumeration + // also clip the array during copy to only the subarray of attributes that cover the requested range + NSArray *attrs; + if (NSEqualRanges(enumerationRange, NSMakeRange(0, 0))) { + attrs = [NSArray arrayWithArray:_attributes]; + } else { + // in this binary search, last is the first run after the range + NSUInteger first = 0, last = [_attributes count]; + while (last > first+1) { + NSUInteger pivot = (last + first) / 2; + ZAttributeRun *run = [_attributes objectAtIndex:pivot]; + if (run.index < enumerationRange.location) { + first = pivot; + } else if (run.index >= NSMaxRange(enumerationRange)) { + last = pivot; + } + } + attrs = [_attributes subarrayWithRange:NSMakeRange(first, last-first)]; + } + if (opts & ZAttributedStringEnumerationReverse) { + NSUInteger end = [_buffer length]; + for (ZAttributeRun *run in [attrs reverseObjectEnumerator]) { + BOOL stop = NO; + NSUInteger start = run.index; + // clip to enumerationRange + start = MAX(start, enumerationRange.location); + end = MIN(end, NSMaxRange(enumerationRange)); + block(run.attributes, NSMakeRange(start, end - start), &stop); + if (stop) break; + end = run.index; + } + } else { + NSUInteger start = 0; + ZAttributeRun *run = [attrs objectAtIndex:0]; + NSInteger offset = 0; + NSInteger oldLength = [_buffer length]; + for (NSUInteger i = 1;;i++) { + NSUInteger end; + if (i >= [attrs count]) { + end = oldLength; + } else { + end = [[attrs objectAtIndex:i] index]; + } + BOOL stop = NO; + NSUInteger clippedStart = MAX(start, enumerationRange.location); + NSUInteger clippedEnd = MIN(end, NSMaxRange(enumerationRange)); + block(run.attributes, NSMakeRange(clippedStart + offset, clippedEnd - start), &stop); + if (stop || i >= [attrs count]) break; + start = end; + NSUInteger newLength = [_buffer length]; + offset += (newLength - oldLength); + oldLength = newLength; + } + } +} +#endif + +- (BOOL)isEqualToAttributedString:(ZAttributedString *)otherString { + return ([_buffer isEqualToString:otherString->_buffer] && [_attributes isEqualToArray:otherString->_attributes]); +} + +- (BOOL)isEqual:(id)object { + return [object isKindOfClass:[ZAttributedString class]] && [self isEqualToAttributedString:(ZAttributedString *)object]; +} + +#pragma mark - + +- (NSUInteger)indexOfEffectiveAttributeRunForIndex:(NSUInteger)index { + NSUInteger first = 0, last = [_attributes count]; + while (last > first + 1) { + NSUInteger pivot = (last + first) / 2; + ZAttributeRun *run = [_attributes objectAtIndex:pivot]; + if (run.index > index) { + last = pivot; + } else if (run.index < index) { + first = pivot; + } else { + first = pivot; + break; + } + } + return first; +} + +- (NSDictionary *)attributesAtIndex:(NSUInteger)index effectiveRange:(NSRangePointer)aRange uniquingOnName:(NSString *)attributeName { + if (index >= [_buffer length]) { + @throw [NSException exceptionWithName:NSRangeException reason:@"index beyond range of attributed string" userInfo:nil]; + } + NSUInteger runIndex = [self indexOfEffectiveAttributeRunForIndex:index]; + ZAttributeRun *run = [_attributes objectAtIndex:runIndex]; + if (aRange != NULL) { + aRange->location = run.index; + runIndex++; + if (runIndex < [_attributes count]) { + aRange->length = [[_attributes objectAtIndex:runIndex] index] - aRange->location; + } else { + aRange->length = [_buffer length] - aRange->location; + } + } + return run.attributes; +} +- (NSDictionary *)attributesAtIndex:(NSUInteger)index longestEffectiveRange:(NSRangePointer)aRange + inRange:(NSRange)rangeLimit uniquingOnName:(NSString *)attributeName { + if (index >= [_buffer length]) { + @throw [NSException exceptionWithName:NSRangeException reason:@"index beyond range of attributed string" userInfo:nil]; + } else if (NSMaxRange(rangeLimit) > [_buffer length]) { + @throw [NSException exceptionWithName:NSRangeException reason:@"rangeLimit beyond range of attributed string" userInfo:nil]; + } + NSUInteger runIndex = [self indexOfEffectiveAttributeRunForIndex:index]; + ZAttributeRun *run = [_attributes objectAtIndex:runIndex]; + if (aRange != NULL) { + if (attributeName != nil) { + id value = [run.attributes objectForKey:attributeName]; + NSUInteger endRunIndex = runIndex+1; + runIndex--; + // search backwards + while (1) { + if (run.index <= rangeLimit.location) { + break; + } + ZAttributeRun *prevRun = [_attributes objectAtIndex:runIndex]; + id prevValue = [prevRun.attributes objectForKey:attributeName]; + if (prevValue == value || (value != nil && [prevValue isEqual:value])) { + runIndex--; + run = prevRun; + } else { + break; + } + } + // search forwards + ZAttributeRun *endRun = nil; + while (endRunIndex < [_attributes count]) { + ZAttributeRun *nextRun = [_attributes objectAtIndex:endRunIndex]; + if (nextRun.index >= NSMaxRange(rangeLimit)) { + endRun = nextRun; + break; + } + id nextValue = [nextRun.attributes objectForKey:attributeName]; + if (nextValue == value || (value != nil && [nextValue isEqual:value])) { + endRunIndex++; + } else { + endRun = nextRun; + break; + } + } + aRange->location = MAX(run.index, rangeLimit.location); + aRange->length = MIN((endRun ? endRun.index : [_buffer length]), NSMaxRange(rangeLimit)) - aRange->location; + } else { + // with no attribute name, we don't need to do any real searching, + // as we already guarantee each run has unique attributes. + // just make sure to clip the range to the rangeLimit + aRange->location = MAX(run.index, rangeLimit.location); + ZAttributeRun *endRun = (runIndex+1 < [_attributes count] ? [_attributes objectAtIndex:runIndex+1] : nil); + aRange->length = MIN((endRun ? endRun.index : [_buffer length]), NSMaxRange(rangeLimit)) - aRange->location; + } + } + return run.attributes; +} + +- (void)dealloc { + [_buffer release]; + [_attributes release]; + [super dealloc]; +} +@end + +@interface ZMutableAttributedString () +- (void)cleanupAttributesInRange:(NSRange)range; +- (NSRange)rangeOfAttributeRunsForRange:(NSRange)range; +- (void)offsetRunsInRange:(NSRange )range byOffset:(NSInteger)offset; +@end + +@implementation ZMutableAttributedString +- (id)copyWithZone:(NSZone *)zone { + return [(ZAttributedString *)[ZAttributedString allocWithZone:zone] initWithAttributedString:self]; +} + +- (void)addAttribute:(NSString *)name value:(id)value range:(NSRange)range { + range = [self rangeOfAttributeRunsForRange:range]; + for (ZAttributeRun *run in [_attributes subarrayWithRange:range]) { + [run.attributes setObject:value forKey:name]; + } + [self cleanupAttributesInRange:range]; +} + +- (void)addAttributes:(NSDictionary *)attributes range:(NSRange)range { + range = [self rangeOfAttributeRunsForRange:range]; + for (ZAttributeRun *run in [_attributes subarrayWithRange:range]) { + [run.attributes addEntriesFromDictionary:attributes]; + } + [self cleanupAttributesInRange:range]; +} + +- (void)appendAttributedString:(ZAttributedString *)str { + [self insertAttributedString:str atIndex:[_buffer length]]; +} + +- (void)deleteCharactersInRange:(NSRange)range { + NSRange runRange = [self rangeOfAttributeRunsForRange:range]; + [_buffer replaceCharactersInRange:range withString:@""]; + [_attributes removeObjectsInRange:runRange]; + for (NSUInteger i = runRange.location; i < [_attributes count]; i++) { + ZAttributeRun *run = [_attributes objectAtIndex:i]; + ZAttributeRun *newRun = [[ZAttributeRun alloc] initWithIndex:(run.index - range.length) attributes:run.attributes]; + [_attributes replaceObjectAtIndex:i withObject:newRun]; + [newRun release]; + } + [self cleanupAttributesInRange:NSMakeRange(runRange.location, 0)]; +} + +- (void)insertAttributedString:(ZAttributedString *)str atIndex:(NSUInteger)idx { + [self replaceCharactersInRange:NSMakeRange(idx, 0) withAttributedString:str]; +} + +- (void)removeAttribute:(NSString *)name range:(NSRange)range { + range = [self rangeOfAttributeRunsForRange:range]; + for (ZAttributeRun *run in [_attributes subarrayWithRange:range]) { + [run.attributes removeObjectForKey:name]; + } + [self cleanupAttributesInRange:range]; +} + +- (void)replaceCharactersInRange:(NSRange)range withAttributedString:(ZAttributedString *)str { + NSRange replaceRange = [self rangeOfAttributeRunsForRange:range]; + NSInteger offset = [str->_buffer length] - range.length; + [_buffer replaceCharactersInRange:range withString:str->_buffer]; + [_attributes replaceObjectsInRange:replaceRange withObjectsFromArray:str->_attributes]; + NSRange newRange = NSMakeRange(replaceRange.location, [str->_attributes count]); + [self offsetRunsInRange:newRange byOffset:range.location]; + [self offsetRunsInRange:NSMakeRange(NSMaxRange(newRange), [_attributes count] - NSMaxRange(newRange)) byOffset:offset]; + [self cleanupAttributesInRange:NSMakeRange(newRange.location, 0)]; + [self cleanupAttributesInRange:NSMakeRange(NSMaxRange(newRange), 0)]; +} + +- (void)replaceCharactersInRange:(NSRange)range withString:(NSString *)str { + [self replaceCharactersInRange:range withAttributedString:[[[ZAttributedString alloc] initWithString:str] autorelease]]; +} + +- (void)setAttributedString:(ZAttributedString *)str { + [_buffer release], _buffer = [str->_buffer mutableCopy]; + [_attributes release], _attributes = [str->_attributes mutableCopy]; +} + +- (void)setAttributes:(NSDictionary *)attributes range:(NSRange)range { + range = [self rangeOfAttributeRunsForRange:range]; + for (ZAttributeRun *run in [_attributes subarrayWithRange:range]) { + [run.attributes setDictionary:attributes]; + } + [self cleanupAttributesInRange:range]; +} + +#pragma mark - + +// splits the existing runs to provide one or more new runs for the given range +- (NSRange)rangeOfAttributeRunsForRange:(NSRange)range { + NSParameterAssert(NSMaxRange(range) <= [_buffer length]); + + // find (or create) the first run + NSUInteger first = 0; + ZAttributeRun *lastRun = nil; + for (;;first++) { + if (first >= [_attributes count]) { + // we didn't find a run + first = [_attributes count]; + ZAttributeRun *newRun = [[ZAttributeRun alloc] initWithIndex:range.location attributes:lastRun.attributes]; + [_attributes addObject:newRun]; + [newRun release]; + break; + } + ZAttributeRun *run = [_attributes objectAtIndex:first]; + if (run.index == range.location) { + break; + } else if (run.index > range.location) { + ZAttributeRun *newRun = [[ZAttributeRun alloc] initWithIndex:range.location attributes:lastRun.attributes]; + [_attributes insertObject:newRun atIndex:first]; + [newRun release]; + break; + } + lastRun = run; + } + + if (((ZAttributeRun *)[_attributes lastObject]).index < NSMaxRange(range)) { + NSRange subrange = NSMakeRange(first, [_attributes count] - first); + if (NSMaxRange(range) < [_buffer length]) { + ZAttributeRun *newRun = [[ZAttributeRun alloc] initWithIndex:NSMaxRange(range) + attributes:(NSDictionary*)[(ZAttributeRun *)[_attributes lastObject] attributes]]; + [_attributes addObject:newRun]; + [newRun release]; + } + return subrange; + } else { + // find the last run within and the first run after the range + NSUInteger lastIn = first, firstAfter = [_attributes count]-1; + while (firstAfter > lastIn + 1) { + NSUInteger idx = (firstAfter + lastIn) / 2; + ZAttributeRun *run = [_attributes objectAtIndex:idx]; + if (run.index < range.location) { + lastIn = idx; + } else if (run.index > range.location) { + firstAfter = idx; + } else { + // this is definitively the first run after the range + firstAfter = idx; + break; + } + } + if ([[_attributes objectAtIndex:firstAfter] index] > NSMaxRange(range)) { + // the first after is too far after, insert another run! + ZAttributeRun *newRun = [[ZAttributeRun alloc] initWithIndex:NSMaxRange(range) + attributes:[(ZAttributeRun *)[_attributes objectAtIndex:firstAfter-1] attributes]]; + [_attributes insertObject:newRun atIndex:firstAfter]; + [newRun release]; + } + return NSMakeRange(lastIn, firstAfter - lastIn); + } +} + +- (void)cleanupAttributesInRange:(NSRange)range { + // expand the range to include one surrounding attribute on each side + if (range.location > 0) { + range.location -= 1; + range.length += 1; + } + if (NSMaxRange(range) < [_attributes count]) { + range.length += 1; + } else { + // make sure the range is capped to the attributes count + range.length = [_attributes count] - range.location; + } + if (range.length == 0) return; + ZAttributeRun *lastRun = [_attributes objectAtIndex:range.location]; + for (NSUInteger i = range.location+1; i < NSMaxRange(range);) { + ZAttributeRun *run = [_attributes objectAtIndex:i]; + if ([lastRun.attributes isEqualToDictionary:run.attributes]) { + [_attributes removeObjectAtIndex:i]; + range.length -= 1; + } else { + lastRun = run; + i++; + } + } +} + +- (void)offsetRunsInRange:(NSRange)range byOffset:(NSInteger)offset { + for (NSUInteger i = range.location; i < NSMaxRange(range); i++) { + ZAttributeRun *run = [_attributes objectAtIndex:i]; + ZAttributeRun *newRun = [[ZAttributeRun alloc] initWithIndex:run.index + offset attributes:run.attributes]; + [_attributes replaceObjectAtIndex:i withObject:newRun]; + [newRun release]; + } +} +@end + +@implementation ZAttributeRun +@synthesize index = _index; +@synthesize attributes = _attributes; + ++ (id)attributeRunWithIndex:(NSUInteger)idx attributes:(NSDictionary *)attrs { + return [[[self alloc] initWithIndex:idx attributes:attrs] autorelease]; +} + +- (id)initWithIndex:(NSUInteger)idx attributes:(NSDictionary *)attrs { + NSParameterAssert(idx >= 0); + if ((self = [super init])) { + _index = idx; + if (attrs == nil) { + _attributes = [[NSMutableDictionary alloc] init]; + } else { + _attributes = [attrs mutableCopy]; + } + } + return self; +} + +- (id)initWithCoder:(NSCoder *)decoder { + if ((self = [super init])) { + _index = [[decoder decodeObjectForKey:@"index"] unsignedIntegerValue]; + _attributes = [[decoder decodeObjectForKey:@"attributes"] mutableCopy]; + } + return self; +} + +- (id)init { + return [self initWithIndex:0 attributes:[NSDictionary dictionary]]; +} + +- (id)copyWithZone:(NSZone *)zone { + return [[ZAttributeRun allocWithZone:zone] initWithIndex:_index attributes:_attributes]; +} + +- (void)encodeWithCoder:(NSCoder *)aCoder { + [aCoder encodeObject:[NSNumber numberWithUnsignedInteger:_index] forKey:@"index"]; + [aCoder encodeObject:_attributes forKey:@"attributes"]; +} + +- (NSString *)description { + NSMutableArray *components = [NSMutableArray arrayWithCapacity:[_attributes count]]; + for (id key in _attributes) { + [components addObject:[NSString stringWithFormat:@"%@=%@", key, [_attributes objectForKey:key]]]; + } + return [NSString stringWithFormat:@"<%@: %p index=%lu attributes={%@}>", + NSStringFromClass([self class]), self, (unsigned long)_index, [components componentsJoinedByString:@" "]]; +} + +- (BOOL)isEqual:(id)object { + if (![object isKindOfClass:[ZAttributeRun class]]) return NO; + ZAttributeRun *other = (ZAttributeRun *)object; + return _index == other->_index && [_attributes isEqualToDictionary:other->_attributes]; +} + +- (void)dealloc { + [_attributes release]; + [super dealloc]; +} +@end + +NSString * const ZFontAttributeName = @"ZFontAttributeName"; +NSString * const ZForegroundColorAttributeName = @"ZForegroundColorAttributeName"; +NSString * const ZBackgroundColorAttributeName = @"ZBackgroundColorAttributeName"; +NSString * const ZUnderlineStyleAttributeName = @"ZUnderlineStyleAttributeName"; diff --git a/tweejump/libs/FontLabel/ZAttributedStringPrivate.h b/tweejump/libs/FontLabel/ZAttributedStringPrivate.h new file mode 100755 index 0000000..1021d7b --- /dev/null +++ b/tweejump/libs/FontLabel/ZAttributedStringPrivate.h @@ -0,0 +1,24 @@ +// +// ZAttributedStringPrivate.h +// FontLabel +// +// Created by Kevin Ballard on 9/23/09. +// Copyright 2009 Zynga Game Networks. All rights reserved. +// + +#import +#import "ZAttributedString.h" + +@interface ZAttributeRun : NSObject { + NSUInteger _index; + NSMutableDictionary *_attributes; +} +@property (nonatomic, readonly) NSUInteger index; +@property (nonatomic, readonly) NSMutableDictionary *attributes; ++ (id)attributeRunWithIndex:(NSUInteger)idx attributes:(NSDictionary *)attrs; +- (id)initWithIndex:(NSUInteger)idx attributes:(NSDictionary *)attrs; +@end + +@interface ZAttributedString (ZAttributedStringPrivate) +@property (nonatomic, readonly) NSArray *attributes; +@end diff --git a/tweejump/libs/FontLabel/ZFont.h b/tweejump/libs/FontLabel/ZFont.h new file mode 100755 index 0000000..05ae823 --- /dev/null +++ b/tweejump/libs/FontLabel/ZFont.h @@ -0,0 +1,47 @@ +// +// ZFont.h +// FontLabel +// +// Created by Kevin Ballard on 7/2/09. +// Copyright © 2009 Zynga Game Networks +// +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#import +#import + +@interface ZFont : NSObject { + CGFontRef _cgFont; + CGFloat _pointSize; + CGFloat _ratio; + NSString *_familyName; + NSString *_fontName; + NSString *_postScriptName; +} +@property (nonatomic, readonly) CGFontRef cgFont; +@property (nonatomic, readonly) CGFloat pointSize; +@property (nonatomic, readonly) CGFloat ascender; +@property (nonatomic, readonly) CGFloat descender; +@property (nonatomic, readonly) CGFloat leading; +@property (nonatomic, readonly) CGFloat xHeight; +@property (nonatomic, readonly) CGFloat capHeight; +@property (nonatomic, readonly) NSString *familyName; +@property (nonatomic, readonly) NSString *fontName; +@property (nonatomic, readonly) NSString *postScriptName; ++ (ZFont *)fontWithCGFont:(CGFontRef)cgFont size:(CGFloat)fontSize; ++ (ZFont *)fontWithUIFont:(UIFont *)uiFont; +- (id)initWithCGFont:(CGFontRef)cgFont size:(CGFloat)fontSize; +- (ZFont *)fontWithSize:(CGFloat)fontSize; +@end diff --git a/tweejump/libs/FontLabel/ZFont.m b/tweejump/libs/FontLabel/ZFont.m new file mode 100755 index 0000000..793b13a --- /dev/null +++ b/tweejump/libs/FontLabel/ZFont.m @@ -0,0 +1,170 @@ +// +// ZFont.m +// FontLabel +// +// Created by Kevin Ballard on 7/2/09. +// Copyright © 2009 Zynga Game Networks +// +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#import "ZFont.h" + +@interface ZFont () +@property (nonatomic, readonly) CGFloat ratio; +- (NSString *)copyNameTableEntryForID:(UInt16)nameID; +@end + +@implementation ZFont +@synthesize cgFont=_cgFont, pointSize=_pointSize, ratio=_ratio; + ++ (ZFont *)fontWithCGFont:(CGFontRef)cgFont size:(CGFloat)fontSize { + return [[[self alloc] initWithCGFont:cgFont size:fontSize] autorelease]; +} + ++ (ZFont *)fontWithUIFont:(UIFont *)uiFont { + NSParameterAssert(uiFont != nil); + CGFontRef cgFont = CGFontCreateWithFontName((CFStringRef)uiFont.fontName); + ZFont *zFont = [[self alloc] initWithCGFont:cgFont size:uiFont.pointSize]; + CGFontRelease(cgFont); + return [zFont autorelease]; +} + +- (id)initWithCGFont:(CGFontRef)cgFont size:(CGFloat)fontSize { + if ((self = [super init])) { + _cgFont = CGFontRetain(cgFont); + _pointSize = fontSize; + _ratio = fontSize/CGFontGetUnitsPerEm(cgFont); + } + return self; +} + +- (id)init { + NSAssert(NO, @"-init is not valid for ZFont"); + return nil; +} + +- (CGFloat)ascender { + return ceilf(self.ratio * CGFontGetAscent(self.cgFont)); +} + +- (CGFloat)descender { + return floorf(self.ratio * CGFontGetDescent(self.cgFont)); +} + +- (CGFloat)leading { + return (self.ascender - self.descender); +} + +- (CGFloat)capHeight { + return ceilf(self.ratio * CGFontGetCapHeight(self.cgFont)); +} + +- (CGFloat)xHeight { + return ceilf(self.ratio * CGFontGetXHeight(self.cgFont)); +} + +- (NSString *)familyName { + if (_familyName == nil) { + _familyName = [self copyNameTableEntryForID:1]; + } + return _familyName; +} + +- (NSString *)fontName { + if (_fontName == nil) { + _fontName = [self copyNameTableEntryForID:4]; + } + return _fontName; +} + +- (NSString *)postScriptName { + if (_postScriptName == nil) { + _postScriptName = [self copyNameTableEntryForID:6]; + } + return _postScriptName; +} + +- (ZFont *)fontWithSize:(CGFloat)fontSize { + if (fontSize == self.pointSize) return self; + NSParameterAssert(fontSize > 0.0); + return [[[ZFont alloc] initWithCGFont:self.cgFont size:fontSize] autorelease]; +} + +- (BOOL)isEqual:(id)object { + if (![object isKindOfClass:[ZFont class]]) return NO; + ZFont *font = (ZFont *)object; + return (font.cgFont == self.cgFont && font.pointSize == self.pointSize); +} + +- (NSString *)copyNameTableEntryForID:(UInt16)aNameID { + CFDataRef nameTable = CGFontCopyTableForTag(self.cgFont, 'name'); + NSAssert1(nameTable != NULL, @"CGFontCopyTableForTag returned NULL for 'name' tag in font %@", + [(id)CFCopyDescription(self.cgFont) autorelease]); + const UInt8 * const bytes = CFDataGetBytePtr(nameTable); + NSAssert1(OSReadBigInt16(bytes, 0) == 0, @"name table for font %@ has bad version number", + [(id)CFCopyDescription(self.cgFont) autorelease]); + const UInt16 count = OSReadBigInt16(bytes, 2); + const UInt16 stringOffset = OSReadBigInt16(bytes, 4); + const UInt8 * const nameRecords = &bytes[6]; + UInt16 nameLength = 0; + UInt16 nameOffset = 0; + NSStringEncoding encoding = 0; + for (UInt16 idx = 0; idx < count; idx++) { + const uintptr_t recordOffset = 12 * idx; + const UInt16 nameID = OSReadBigInt16(nameRecords, recordOffset + 6); + if (nameID != aNameID) continue; + const UInt16 platformID = OSReadBigInt16(nameRecords, recordOffset + 0); + const UInt16 platformSpecificID = OSReadBigInt16(nameRecords, recordOffset + 2); + encoding = 0; + // for now, we only support a subset of encodings + switch (platformID) { + case 0: // Unicode + encoding = NSUTF16StringEncoding; + break; + case 1: // Macintosh + switch (platformSpecificID) { + case 0: + encoding = NSMacOSRomanStringEncoding; + break; + } + case 3: // Microsoft + switch (platformSpecificID) { + case 1: + encoding = NSUTF16StringEncoding; + break; + } + } + if (encoding == 0) continue; + nameLength = OSReadBigInt16(nameRecords, recordOffset + 8); + nameOffset = OSReadBigInt16(nameRecords, recordOffset + 10); + break; + } + NSString *result = nil; + if (nameOffset > 0) { + const UInt8 *nameBytes = &bytes[stringOffset + nameOffset]; + result = [[NSString alloc] initWithBytes:nameBytes length:nameLength encoding:encoding]; + } + CFRelease(nameTable); + return result; +} + +- (void)dealloc { + CGFontRelease(_cgFont); + [_familyName release]; + [_fontName release]; + [_postScriptName release]; + [super dealloc]; +} +@end diff --git a/tweejump/libs/LICENSE_FontLabel.txt b/tweejump/libs/LICENSE_FontLabel.txt new file mode 100755 index 0000000..a45b29a --- /dev/null +++ b/tweejump/libs/LICENSE_FontLabel.txt @@ -0,0 +1,79 @@ +FontLabel +--------- + +Copyright © 2009 Zynga Game Networks. + + +License +------- + +Apache License, Version 2.0 + +Apache License +Version 2.0, January 2004 +http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + +"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. + +"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. + +"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. + +"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. + +"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. + +"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. + +"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). + +"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. + +"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." + +"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. + +2. Grant of Copyright License. + +Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. + +Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. + +4. Redistribution. + +You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: + + 1. You must give any other recipients of the Work or Derivative Works a copy of this License; and + 2. You must cause any modified files to carry prominent notices stating that You changed the files; and + 3. You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and + 4. If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. + +You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. + +5. Submission of Contributions. + +Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. + +6. Trademarks. + +This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. + +Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. + +In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. + +While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS diff --git a/tweejump/libs/LICENSE_cocos2d.txt b/tweejump/libs/LICENSE_cocos2d.txt new file mode 100755 index 0000000..badd4e4 --- /dev/null +++ b/tweejump/libs/LICENSE_cocos2d.txt @@ -0,0 +1,23 @@ +cocos2d for iPhone: http://www.cocos2d-iphone.org + +Copyright (c) 2011 - Zynga Inc. and contributors +(see each file to see the different copyright owners) + + +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. diff --git a/tweejump/libs/cocos2d/CCAction.h b/tweejump/libs/cocos2d/CCAction.h new file mode 100755 index 0000000..51bad8e --- /dev/null +++ b/tweejump/libs/cocos2d/CCAction.h @@ -0,0 +1,195 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-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. + * + */ + + +#include +#import + +#import "ccTypes.h" + +enum { + //! Default tag + kCCActionTagInvalid = -1, +}; + +/** Base class for CCAction objects. + */ +@interface CCAction : NSObject +{ + id originalTarget_; + id target_; + NSInteger tag_; +} + +/** The "target". The action will modify the target properties. + The target will be set with the 'startWithTarget' method. + When the 'stop' method is called, target will be set to nil. + The target is 'assigned', it is not 'retained'. + */ +@property (nonatomic,readonly,assign) id target; + +/** The original target, since target can be nil. + Is the target that were used to run the action. Unless you are doing something complex, like CCActionManager, you should NOT call this method. + @since v0.8.2 +*/ +@property (nonatomic,readonly,assign) id originalTarget; + + +/** The action tag. An identifier of the action */ +@property (nonatomic,readwrite,assign) NSInteger tag; + +/** Allocates and initializes the action */ ++(id) action; + +/** Initializes the action */ +-(id) init; + +-(id) copyWithZone: (NSZone*) zone; + +//! return YES if the action has finished +-(BOOL) isDone; +//! called before the action start. It will also set the target. +-(void) startWithTarget:(id)target; +//! called after the action has finished. It will set the 'target' to nil. +//! IMPORTANT: You should never call "[action stop]" manually. Instead, use: "[target stopAction:action];" +-(void) stop; +//! called every frame with it's delta time. DON'T override unless you know what you are doing. +-(void) step: (ccTime) dt; +//! called once per frame. time a value between 0 and 1 +//! For example: +//! * 0 means that the action just started +//! * 0.5 means that the action is in the middle +//! * 1 means that the action is over +-(void) update: (ccTime) time; + +@end + +/** Base class actions that do have a finite time duration. + Possible actions: + - An action with a duration of 0 seconds + - An action with a duration of 35.5 seconds + Infitite time actions are valid + */ +@interface CCFiniteTimeAction : CCAction +{ + //! duration in seconds + ccTime duration_; +} +//! duration in seconds of the action +@property (nonatomic,readwrite) ccTime duration; + +/** returns a reversed action */ +- (CCFiniteTimeAction*) reverse; +@end + + +@class CCActionInterval; +/** Repeats an action for ever. + To repeat the an action for a limited number of times use the Repeat action. + @warning This action can't be Sequenceable because it is not an IntervalAction + */ +@interface CCRepeatForever : CCAction +{ + CCActionInterval *innerAction_; +} +/** Inner action */ +@property (nonatomic, readwrite, retain) CCActionInterval *innerAction; + +/** creates the action */ ++(id) actionWithAction: (CCActionInterval*) action; +/** initializes the action */ +-(id) initWithAction: (CCActionInterval*) action; +@end + +/** Changes the speed of an action, making it take longer (speed>1) + or less (speed<1) time. + Useful to simulate 'slow motion' or 'fast forward' effect. + @warning This action can't be Sequenceable because it is not an CCIntervalAction + */ +@interface CCSpeed : CCAction +{ + CCActionInterval *innerAction_; + float speed_; +} +/** alter the speed of the inner function in runtime */ +@property (nonatomic,readwrite) float speed; +/** Inner action of CCSpeed */ +@property (nonatomic, readwrite, retain) CCActionInterval *innerAction; + +/** creates the action */ ++(id) actionWithAction: (CCActionInterval*) action speed:(float)rate; +/** initializes the action */ +-(id) initWithAction: (CCActionInterval*) action speed:(float)rate; +@end + +@class CCNode; +/** CCFollow is an action that "follows" a node. + + Eg: + [layer runAction: [CCFollow actionWithTarget:hero]]; + + Instead of using CCCamera as a "follower", use this action instead. + @since v0.99.2 + */ +@interface CCFollow : CCAction +{ + /* node to follow */ + CCNode *followedNode_; + + /* whether camera should be limited to certain area */ + BOOL boundarySet; + + /* if screensize is bigger than the boundary - update not needed */ + BOOL boundaryFullyCovered; + + /* fast access to the screen dimensions */ + CGPoint halfScreenSize; + CGPoint fullScreenSize; + + /* world boundaries */ + float leftBoundary; + float rightBoundary; + float topBoundary; + float bottomBoundary; +} + +/** alter behavior - turn on/off boundary */ +@property (nonatomic,readwrite) BOOL boundarySet; + +/** creates the action with no boundary set */ ++(id) actionWithTarget:(CCNode *)followedNode; + +/** creates the action with a set boundary */ ++(id) actionWithTarget:(CCNode *)followedNode worldBoundary:(CGRect)rect; + +/** initializes the action */ +-(id) initWithTarget:(CCNode *)followedNode; + +/** initializes the action with a set boundary */ +-(id) initWithTarget:(CCNode *)followedNode worldBoundary:(CGRect)rect; + +@end + diff --git a/tweejump/libs/cocos2d/CCAction.m b/tweejump/libs/cocos2d/CCAction.m new file mode 100755 index 0000000..27db20b --- /dev/null +++ b/tweejump/libs/cocos2d/CCAction.m @@ -0,0 +1,360 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-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. + * + */ + + + +#import +#import "CCDirector.h" +#import "ccMacros.h" +#import "CCAction.h" +#import "CCActionInterval.h" +#import "Support/CGPointExtension.h" + +// +// Action Base Class +// +#pragma mark - +#pragma mark Action +@implementation CCAction + +@synthesize tag = tag_, target = target_, originalTarget = originalTarget_; + ++(id) action +{ + return [[[self alloc] init] autorelease]; +} + +-(id) init +{ + if( (self=[super init]) ) { + originalTarget_ = target_ = nil; + tag_ = kCCActionTagInvalid; + } + return self; +} + +-(void) dealloc +{ + CCLOGINFO(@"cocos2d: deallocing %@", self); + [super dealloc]; +} + +-(NSString*) description +{ + return [NSString stringWithFormat:@"<%@ = %08X | Tag = %i>", [self class], self, tag_]; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCAction *copy = [[[self class] allocWithZone: zone] init]; + copy.tag = tag_; + return copy; +} + +-(void) startWithTarget:(id)aTarget +{ + originalTarget_ = target_ = aTarget; +} + +-(void) stop +{ + target_ = nil; +} + +-(BOOL) isDone +{ + return YES; +} + +-(void) step: (ccTime) dt +{ + NSLog(@"[Action step]. override me"); +} + +-(void) update: (ccTime) time +{ + NSLog(@"[Action update]. override me"); +} +@end + +// +// FiniteTimeAction +// +#pragma mark - +#pragma mark FiniteTimeAction +@implementation CCFiniteTimeAction +@synthesize duration = duration_; + +- (CCFiniteTimeAction*) reverse +{ + CCLOG(@"cocos2d: FiniteTimeAction#reverse: Implement me"); + return nil; +} +@end + + +// +// RepeatForever +// +#pragma mark - +#pragma mark RepeatForever +@implementation CCRepeatForever +@synthesize innerAction=innerAction_; ++(id) actionWithAction: (CCActionInterval*) action +{ + return [[[self alloc] initWithAction: action] autorelease]; +} + +-(id) initWithAction: (CCActionInterval*) action +{ + if( (self=[super init]) ) + self.innerAction = action; + + return self; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCAction *copy = [[[self class] allocWithZone: zone] initWithAction:[[innerAction_ copy] autorelease] ]; + return copy; +} + +-(void) dealloc +{ + [innerAction_ release]; + [super dealloc]; +} + +-(void) startWithTarget:(id)aTarget +{ + [super startWithTarget:aTarget]; + [innerAction_ startWithTarget:target_]; +} + +-(void) step:(ccTime) dt +{ + [innerAction_ step: dt]; + if( [innerAction_ isDone] ) { + ccTime diff = dt + innerAction_.duration - innerAction_.elapsed; + [innerAction_ startWithTarget:target_]; + + // to prevent jerk. issue #390 + [innerAction_ step: diff]; + } +} + + +-(BOOL) isDone +{ + return NO; +} + +- (CCActionInterval *) reverse +{ + return [CCRepeatForever actionWithAction:[innerAction_ reverse]]; +} +@end + +// +// Speed +// +#pragma mark - +#pragma mark Speed +@implementation CCSpeed +@synthesize speed=speed_; +@synthesize innerAction=innerAction_; + ++(id) actionWithAction: (CCActionInterval*) action speed:(float)r +{ + return [[[self alloc] initWithAction: action speed:r] autorelease]; +} + +-(id) initWithAction: (CCActionInterval*) action speed:(float)r +{ + if( (self=[super init]) ) { + self.innerAction = action; + speed_ = r; + } + return self; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCAction *copy = [[[self class] allocWithZone: zone] initWithAction:[[innerAction_ copy] autorelease] speed:speed_]; + return copy; +} + +-(void) dealloc +{ + [innerAction_ release]; + [super dealloc]; +} + +-(void) startWithTarget:(id)aTarget +{ + [super startWithTarget:aTarget]; + [innerAction_ startWithTarget:target_]; +} + +-(void) stop +{ + [innerAction_ stop]; + [super stop]; +} + +-(void) step:(ccTime) dt +{ + [innerAction_ step: dt * speed_]; +} + +-(BOOL) isDone +{ + return [innerAction_ isDone]; +} + +- (CCActionInterval *) reverse +{ + return [CCSpeed actionWithAction:[innerAction_ reverse] speed:speed_]; +} +@end + +// +// Follow +// +#pragma mark - +#pragma mark Follow +@implementation CCFollow + +@synthesize boundarySet; + ++(id) actionWithTarget:(CCNode *) fNode +{ + return [[[self alloc] initWithTarget:fNode] autorelease]; +} + ++(id) actionWithTarget:(CCNode *) fNode worldBoundary:(CGRect)rect +{ + return [[[self alloc] initWithTarget:fNode worldBoundary:rect] autorelease]; +} + +-(id) initWithTarget:(CCNode *)fNode +{ + if( (self=[super init]) ) { + + followedNode_ = [fNode retain]; + boundarySet = FALSE; + boundaryFullyCovered = FALSE; + + CGSize s = [[CCDirector sharedDirector] winSize]; + fullScreenSize = CGPointMake(s.width, s.height); + halfScreenSize = ccpMult(fullScreenSize, .5f); + } + + return self; +} + +-(id) initWithTarget:(CCNode *)fNode worldBoundary:(CGRect)rect +{ + if( (self=[super init]) ) { + + followedNode_ = [fNode retain]; + boundarySet = TRUE; + boundaryFullyCovered = FALSE; + + CGSize winSize = [[CCDirector sharedDirector] winSize]; + fullScreenSize = CGPointMake(winSize.width, winSize.height); + halfScreenSize = ccpMult(fullScreenSize, .5f); + + leftBoundary = -((rect.origin.x+rect.size.width) - fullScreenSize.x); + rightBoundary = -rect.origin.x ; + topBoundary = -rect.origin.y; + bottomBoundary = -((rect.origin.y+rect.size.height) - fullScreenSize.y); + + if(rightBoundary < leftBoundary) + { + // screen width is larger than world's boundary width + //set both in the middle of the world + rightBoundary = leftBoundary = (leftBoundary + rightBoundary) / 2; + } + if(topBoundary < bottomBoundary) + { + // screen width is larger than world's boundary width + //set both in the middle of the world + topBoundary = bottomBoundary = (topBoundary + bottomBoundary) / 2; + } + + if( (topBoundary == bottomBoundary) && (leftBoundary == rightBoundary) ) + boundaryFullyCovered = TRUE; + } + + return self; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCAction *copy = [[[self class] allocWithZone: zone] init]; + copy.tag = tag_; + return copy; +} + +-(void) step:(ccTime) dt +{ + if(boundarySet) + { + // whole map fits inside a single screen, no need to modify the position - unless map boundaries are increased + if(boundaryFullyCovered) + return; + + CGPoint tempPos = ccpSub( halfScreenSize, followedNode_.position); + [target_ setPosition:ccp(clampf(tempPos.x,leftBoundary,rightBoundary), clampf(tempPos.y,bottomBoundary,topBoundary))]; + } + else + [target_ setPosition:ccpSub( halfScreenSize, followedNode_.position )]; + +#undef CLAMP +} + + +-(BOOL) isDone +{ + return !followedNode_.isRunning; +} + +-(void) stop +{ + target_ = nil; + [super stop]; +} + +-(void) dealloc +{ + [followedNode_ release]; + [super dealloc]; +} + +@end + + diff --git a/tweejump/libs/cocos2d/CCActionCamera.h b/tweejump/libs/cocos2d/CCActionCamera.h new file mode 100755 index 0000000..1ea83a7 --- /dev/null +++ b/tweejump/libs/cocos2d/CCActionCamera.h @@ -0,0 +1,73 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-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. + * + */ + +#import "CCActionInterval.h" + +@class CCCamera; + +/** Base class for CCCamera actions + */ +@interface CCActionCamera : CCActionInterval +{ + float centerXOrig_; + float centerYOrig_; + float centerZOrig_; + + float eyeXOrig_; + float eyeYOrig_; + float eyeZOrig_; + + float upXOrig_; + float upYOrig_; + float upZOrig_; +} +@end + +/** CCOrbitCamera action + Orbits the camera around the center of the screen using spherical coordinates + */ +@interface CCOrbitCamera : CCActionCamera +{ + float radius_; + float deltaRadius_; + float angleZ_; + float deltaAngleZ_; + float angleX_; + float deltaAngleX_; + + float radZ_; + float radDeltaZ_; + float radX_; + float radDeltaX_; + +} +/** creates a CCOrbitCamera action with radius, delta-radius, z, deltaZ, x, deltaX */ ++(id) actionWithDuration:(float) t radius:(float)r deltaRadius:(float) dr angleZ:(float)z deltaAngleZ:(float)dz angleX:(float)x deltaAngleX:(float)dx; +/** initializes a CCOrbitCamera action with radius, delta-radius, z, deltaZ, x, deltaX */ +-(id) initWithDuration:(float) t radius:(float)r deltaRadius:(float) dr angleZ:(float)z deltaAngleZ:(float)dz angleX:(float)x deltaAngleX:(float)dx; +/** positions the camera according to spherical coordinates */ +-(void) sphericalRadius:(float*) r zenith:(float*) zenith azimuth:(float*) azimuth; +@end diff --git a/tweejump/libs/cocos2d/CCActionCamera.m b/tweejump/libs/cocos2d/CCActionCamera.m new file mode 100755 index 0000000..4dafc4e --- /dev/null +++ b/tweejump/libs/cocos2d/CCActionCamera.m @@ -0,0 +1,147 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-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. + * + */ + + + +#import "CCActionCamera.h" +#import "CCNode.h" +#import "CCCamera.h" +#import "ccMacros.h" + +// +// CameraAction +// +@implementation CCActionCamera +-(void) startWithTarget:(id)aTarget +{ + [super startWithTarget:aTarget]; + CCCamera *camera = [target_ camera]; + [camera centerX:¢erXOrig_ centerY:¢erYOrig_ centerZ:¢erZOrig_]; + [camera eyeX:&eyeXOrig_ eyeY:&eyeYOrig_ eyeZ:&eyeZOrig_]; + [camera upX:&upXOrig_ upY:&upYOrig_ upZ: &upZOrig_]; +} + +-(id) reverse +{ + return [CCReverseTime actionWithAction:self]; +} +@end + +@implementation CCOrbitCamera ++(id) actionWithDuration:(float)t radius:(float)r deltaRadius:(float) dr angleZ:(float)z deltaAngleZ:(float)dz angleX:(float)x deltaAngleX:(float)dx +{ + return [[[self alloc] initWithDuration:t radius:r deltaRadius:dr angleZ:z deltaAngleZ:dz angleX:x deltaAngleX:dx] autorelease]; +} + +-(id) copyWithZone: (NSZone*) zone +{ + return [[[self class] allocWithZone: zone] initWithDuration:duration_ radius:radius_ deltaRadius:deltaRadius_ angleZ:angleZ_ deltaAngleZ:deltaAngleZ_ angleX:angleX_ deltaAngleX:deltaAngleX_]; +} + + +-(id) initWithDuration:(float)t radius:(float)r deltaRadius:(float) dr angleZ:(float)z deltaAngleZ:(float)dz angleX:(float)x deltaAngleX:(float)dx +{ + if((self=[super initWithDuration:t]) ) { + + radius_ = r; + deltaRadius_ = dr; + angleZ_ = z; + deltaAngleZ_ = dz; + angleX_ = x; + deltaAngleX_ = dx; + + radDeltaZ_ = (CGFloat)CC_DEGREES_TO_RADIANS(dz); + radDeltaX_ = (CGFloat)CC_DEGREES_TO_RADIANS(dx); + } + + return self; +} + +-(void) startWithTarget:(id)aTarget +{ + [super startWithTarget:aTarget]; + float r, zenith, azimuth; + + [self sphericalRadius: &r zenith:&zenith azimuth:&azimuth]; + +#if 0 // isnan() is not supported on the simulator, and isnan() always returns false. + if( isnan(radius_) ) + radius_ = r; + + if( isnan( angleZ_) ) + angleZ_ = (CGFloat)CC_RADIANS_TO_DEGREES(zenith); + + if( isnan( angleX_ ) ) + angleX_ = (CGFloat)CC_RADIANS_TO_DEGREES(azimuth); +#endif + + radZ_ = (CGFloat)CC_DEGREES_TO_RADIANS(angleZ_); + radX_ = (CGFloat)CC_DEGREES_TO_RADIANS(angleX_); +} + +-(void) update: (ccTime) dt +{ + float r = (radius_ + deltaRadius_ * dt) *[CCCamera getZEye]; + float za = radZ_ + radDeltaZ_ * dt; + float xa = radX_ + radDeltaX_ * dt; + + float i = sinf(za) * cosf(xa) * r + centerXOrig_; + float j = sinf(za) * sinf(xa) * r + centerYOrig_; + float k = cosf(za) * r + centerZOrig_; + + [[target_ camera] setEyeX:i eyeY:j eyeZ:k]; +} + +-(void) sphericalRadius:(float*) newRadius zenith:(float*) zenith azimuth:(float*) azimuth +{ + float ex, ey, ez, cx, cy, cz, x, y, z; + float r; // radius + float s; + + CCCamera *camera = [target_ camera]; + [camera eyeX:&ex eyeY:&ey eyeZ:&ez]; + [camera centerX:&cx centerY:&cy centerZ:&cz]; + + x = ex-cx; + y = ey-cy; + z = ez-cz; + + r = sqrtf( x*x + y*y + z*z); + s = sqrtf( x*x + y*y); + if(s==0.0f) + s = FLT_EPSILON; + if(r==0.0f) + r = FLT_EPSILON; + + *zenith = acosf( z/r); + if( x < 0 ) + *azimuth = (float)M_PI - asinf(y/s); + else + *azimuth = asinf(y/s); + + *newRadius = r / [CCCamera getZEye]; +} +@end diff --git a/tweejump/libs/cocos2d/CCActionEase.h b/tweejump/libs/cocos2d/CCActionEase.h new file mode 100755 index 0000000..fced701 --- /dev/null +++ b/tweejump/libs/cocos2d/CCActionEase.h @@ -0,0 +1,159 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-2009 Jason Booth + * + * 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. + * + */ + + +#import "CCActionInterval.h" + +/** Base class for Easing actions + */ +@interface CCActionEase : CCActionInterval +{ + CCActionInterval * other; +} +/** creates the action */ ++(id) actionWithAction: (CCActionInterval*) action; +/** initializes the action */ +-(id) initWithAction: (CCActionInterval*) action; +@end + +/** Base class for Easing actions with rate parameters + */ +@interface CCEaseRateAction : CCActionEase +{ + float rate; +} +/** rate value for the actions */ +@property (nonatomic,readwrite,assign) float rate; +/** Creates the action with the inner action and the rate parameter */ ++(id) actionWithAction: (CCActionInterval*) action rate:(float)rate; +/** Initializes the action with the inner action and the rate parameter */ +-(id) initWithAction: (CCActionInterval*) action rate:(float)rate; +@end + +/** CCEaseIn action with a rate + */ +@interface CCEaseIn : CCEaseRateAction {} @end + +/** CCEaseOut action with a rate + */ +@interface CCEaseOut : CCEaseRateAction {} @end + +/** CCEaseInOut action with a rate + */ +@interface CCEaseInOut : CCEaseRateAction {} @end + +/** CCEase Exponential In + */ +@interface CCEaseExponentialIn : CCActionEase {} @end +/** Ease Exponential Out + */ +@interface CCEaseExponentialOut : CCActionEase {} @end +/** Ease Exponential InOut + */ +@interface CCEaseExponentialInOut : CCActionEase {} @end +/** Ease Sine In + */ +@interface CCEaseSineIn : CCActionEase {} @end +/** Ease Sine Out + */ +@interface CCEaseSineOut : CCActionEase {} @end +/** Ease Sine InOut + */ +@interface CCEaseSineInOut : CCActionEase {} @end + +/** Ease Elastic abstract class + @since v0.8.2 + */ +@interface CCEaseElastic : CCActionEase +{ + float period_; +} + +/** period of the wave in radians. default is 0.3 */ +@property (nonatomic,readwrite) float period; + +/** Creates the action with the inner action and the period in radians (default is 0.3) */ ++(id) actionWithAction: (CCActionInterval*) action period:(float)period; +/** Initializes the action with the inner action and the period in radians (default is 0.3) */ +-(id) initWithAction: (CCActionInterval*) action period:(float)period; +@end + +/** Ease Elastic In action. + @warning This action doesn't use a bijective fucntion. Actions like Sequence might have an unexpected result when used with this action. + @since v0.8.2 + */ +@interface CCEaseElasticIn : CCEaseElastic {} @end +/** Ease Elastic Out action. + @warning This action doesn't use a bijective fucntion. Actions like Sequence might have an unexpected result when used with this action. + @since v0.8.2 + */ +@interface CCEaseElasticOut : CCEaseElastic {} @end +/** Ease Elastic InOut action. + @warning This action doesn't use a bijective fucntion. Actions like Sequence might have an unexpected result when used with this action. + @since v0.8.2 + */ +@interface CCEaseElasticInOut : CCEaseElastic {} @end + +/** CCEaseBounce abstract class. + @since v0.8.2 +*/ +@interface CCEaseBounce : CCActionEase {} @end + +/** CCEaseBounceIn action. + @warning This action doesn't use a bijective fucntion. Actions like Sequence might have an unexpected result when used with this action. + @since v0.8.2 +*/ +@interface CCEaseBounceIn : CCEaseBounce {} @end + +/** EaseBounceOut action. + @warning This action doesn't use a bijective fucntion. Actions like Sequence might have an unexpected result when used with this action. + @since v0.8.2 + */ +@interface CCEaseBounceOut : CCEaseBounce {} @end + +/** CCEaseBounceInOut action. + @warning This action doesn't use a bijective fucntion. Actions like Sequence might have an unexpected result when used with this action. + @since v0.8.2 + */ +@interface CCEaseBounceInOut : CCEaseBounce {} @end + +/** CCEaseBackIn action. + @warning This action doesn't use a bijective fucntion. Actions like Sequence might have an unexpected result when used with this action. + @since v0.8.2 + */ +@interface CCEaseBackIn : CCActionEase {} @end + +/** CCEaseBackOut action. + @warning This action doesn't use a bijective fucntion. Actions like Sequence might have an unexpected result when used with this action. + @since v0.8.2 + */ +@interface CCEaseBackOut : CCActionEase {} @end + +/** CCEaseBackInOut action. + @warning This action doesn't use a bijective fucntion. Actions like Sequence might have an unexpected result when used with this action. + @since v0.8.2 + */ +@interface CCEaseBackInOut : CCActionEase {} @end + diff --git a/tweejump/libs/cocos2d/CCActionEase.m b/tweejump/libs/cocos2d/CCActionEase.m new file mode 100755 index 0000000..f28be11 --- /dev/null +++ b/tweejump/libs/cocos2d/CCActionEase.m @@ -0,0 +1,534 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-2009 Jason Booth + * + * 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. + * + */ + + +/* + * Elastic, Back and Bounce actions based on code from: + * http://github.com/NikhilK/silverlightfx/ + * + * by http://github.com/NikhilK + */ + +#import "CCActionEase.h" + +#ifndef M_PI_X_2 +#define M_PI_X_2 (float)M_PI * 2.0f +#endif + +#pragma mark EaseAction + +// +// EaseAction +// +@implementation CCActionEase + ++(id) actionWithAction: (CCActionInterval*) action +{ + return [[[self alloc] initWithAction: action] autorelease ]; +} + +-(id) initWithAction: (CCActionInterval*) action +{ + NSAssert( action!=nil, @"Ease: arguments must be non-nil"); + + if( (self=[super initWithDuration: action.duration]) ) + other = [action retain]; + + return self; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCAction *copy = [[[self class] allocWithZone:zone] initWithAction:[[other copy] autorelease]]; + return copy; +} + +-(void) dealloc +{ + [other release]; + [super dealloc]; +} + +-(void) startWithTarget:(id)aTarget +{ + [super startWithTarget:aTarget]; + [other startWithTarget:target_]; +} + +-(void) stop +{ + [other stop]; + [super stop]; +} + +-(void) update: (ccTime) t +{ + [other update: t]; +} + +-(CCActionInterval*) reverse +{ + return [[self class] actionWithAction: [other reverse]]; +} +@end + + +#pragma mark - +#pragma mark EaseRate + +// +// EaseRateAction +// +@implementation CCEaseRateAction +@synthesize rate; ++(id) actionWithAction: (CCActionInterval*) action rate:(float)aRate +{ + return [[[self alloc] initWithAction: action rate:aRate] autorelease ]; +} + +-(id) initWithAction: (CCActionInterval*) action rate:(float)aRate +{ + if( (self=[super initWithAction:action ]) ) + self.rate = aRate; + + return self; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCAction *copy = [[[self class] allocWithZone:zone] initWithAction:[[other copy] autorelease] rate:rate]; + return copy; +} + +-(void) dealloc +{ + [super dealloc]; +} + +-(CCActionInterval*) reverse +{ + return [[self class] actionWithAction: [other reverse] rate:1/rate]; +} +@end + +// +// EeseIn +// +@implementation CCEaseIn +-(void) update: (ccTime) t +{ + [other update: powf(t,rate)]; +} +@end + +// +// EaseOut +// +@implementation CCEaseOut +-(void) update: (ccTime) t +{ + [other update: powf(t,1/rate)]; +} +@end + +// +// EaseInOut +// +@implementation CCEaseInOut +-(void) update: (ccTime) t +{ + int sign =1; + int r = (int) rate; + if (r % 2 == 0) + sign = -1; + t *= 2; + if (t < 1) + [other update: 0.5f * powf (t, rate)]; + else + [other update: sign*0.5f * (powf (t-2, rate) + sign*2)]; +} + +// InOut and OutIn are symmetrical +-(CCActionInterval*) reverse +{ + return [[self class] actionWithAction: [other reverse] rate:rate]; +} + +@end + +#pragma mark - +#pragma mark EaseExponential + +// +// EaseExponentialIn +// +@implementation CCEaseExponentialIn +-(void) update: (ccTime) t +{ + [other update: (t==0) ? 0 : powf(2, 10 * (t/1 - 1)) - 1 * 0.001f]; +} + +- (CCActionInterval*) reverse +{ + return [CCEaseExponentialOut actionWithAction: [other reverse]]; +} +@end + +// +// EaseExponentialOut +// +@implementation CCEaseExponentialOut +-(void) update: (ccTime) t +{ + [other update: (t==1) ? 1 : (-powf(2, -10 * t/1) + 1)]; +} + +- (CCActionInterval*) reverse +{ + return [CCEaseExponentialIn actionWithAction: [other reverse]]; +} +@end + +// +// EaseExponentialInOut +// +@implementation CCEaseExponentialInOut +-(void) update: (ccTime) t +{ + t /= 0.5f; + if (t < 1) + t = 0.5f * powf(2, 10 * (t - 1)); + else + t = 0.5f * (-powf(2, -10 * (t -1) ) + 2); + + [other update:t]; +} +@end + + +#pragma mark - +#pragma mark EaseSin actions + +// +// EaseSineIn +// +@implementation CCEaseSineIn +-(void) update: (ccTime) t +{ + [other update:-1*cosf(t * (float)M_PI_2) +1]; +} + +- (CCActionInterval*) reverse +{ + return [CCEaseSineOut actionWithAction: [other reverse]]; +} +@end + +// +// EaseSineOut +// +@implementation CCEaseSineOut +-(void) update: (ccTime) t +{ + [other update:sinf(t * (float)M_PI_2)]; +} + +- (CCActionInterval*) reverse +{ + return [CCEaseSineIn actionWithAction: [other reverse]]; +} +@end + +// +// EaseSineInOut +// +@implementation CCEaseSineInOut +-(void) update: (ccTime) t +{ + [other update:-0.5f*(cosf( (float)M_PI*t) - 1)]; +} +@end + +#pragma mark - +#pragma mark EaseElastic actions + +// +// EaseElastic +// +@implementation CCEaseElastic + +@synthesize period = period_; + ++(id) actionWithAction: (CCActionInterval*) action +{ + return [[[self alloc] initWithAction:action period:0.3f] autorelease]; +} + ++(id) actionWithAction: (CCActionInterval*) action period:(float)period +{ + return [[[self alloc] initWithAction:action period:period] autorelease]; +} + +-(id) initWithAction: (CCActionInterval*) action +{ + return [self initWithAction:action period:0.3f]; +} + +-(id) initWithAction: (CCActionInterval*) action period:(float)period +{ + if( (self=[super initWithAction:action]) ) + period_ = period; + + return self; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCAction *copy = [[[self class] allocWithZone:zone] initWithAction:[[other copy] autorelease] period:period_]; + return copy; +} + +-(CCActionInterval*) reverse +{ + NSAssert(NO,@"Override me"); + return nil; +} + +@end + +// +// EaseElasticIn +// + +@implementation CCEaseElasticIn +-(void) update: (ccTime) t +{ + ccTime newT = 0; + if (t == 0 || t == 1) + newT = t; + + else { + float s = period_ / 4; + t = t - 1; + newT = -powf(2, 10 * t) * sinf( (t-s) *M_PI_X_2 / period_); + } + [other update:newT]; +} + +- (CCActionInterval*) reverse +{ + return [CCEaseElasticOut actionWithAction: [other reverse] period:period_]; +} + +@end + +// +// EaseElasticOut +// +@implementation CCEaseElasticOut + +-(void) update: (ccTime) t +{ + ccTime newT = 0; + if (t == 0 || t == 1) { + newT = t; + + } else { + float s = period_ / 4; + newT = powf(2, -10 * t) * sinf( (t-s) *M_PI_X_2 / period_) + 1; + } + [other update:newT]; +} + +- (CCActionInterval*) reverse +{ + return [CCEaseElasticIn actionWithAction: [other reverse] period:period_]; +} + +@end + +// +// EaseElasticInOut +// +@implementation CCEaseElasticInOut +-(void) update: (ccTime) t +{ + ccTime newT = 0; + + if( t == 0 || t == 1 ) + newT = t; + else { + t = t * 2; + if(! period_ ) + period_ = 0.3f * 1.5f; + ccTime s = period_ / 4; + + t = t -1; + if( t < 0 ) + newT = -0.5f * powf(2, 10 * t) * sinf((t - s) * M_PI_X_2 / period_); + else + newT = powf(2, -10 * t) * sinf((t - s) * M_PI_X_2 / period_) * 0.5f + 1; + } + [other update:newT]; +} + +- (CCActionInterval*) reverse +{ + return [CCEaseElasticInOut actionWithAction: [other reverse] period:period_]; +} + +@end + +#pragma mark - +#pragma mark EaseBounce actions + +// +// EaseBounce +// +@implementation CCEaseBounce +-(ccTime) bounceTime:(ccTime) t +{ + if (t < 1 / 2.75) { + return 7.5625f * t * t; + } + else if (t < 2 / 2.75) { + t -= 1.5f / 2.75f; + return 7.5625f * t * t + 0.75f; + } + else if (t < 2.5 / 2.75) { + t -= 2.25f / 2.75f; + return 7.5625f * t * t + 0.9375f; + } + + t -= 2.625f / 2.75f; + return 7.5625f * t * t + 0.984375f; +} +@end + +// +// EaseBounceIn +// + +@implementation CCEaseBounceIn + +-(void) update: (ccTime) t +{ + ccTime newT = 1 - [self bounceTime:1-t]; + [other update:newT]; +} + +- (CCActionInterval*) reverse +{ + return [CCEaseBounceOut actionWithAction: [other reverse]]; +} + +@end + +@implementation CCEaseBounceOut + +-(void) update: (ccTime) t +{ + ccTime newT = [self bounceTime:t]; + [other update:newT]; +} + +- (CCActionInterval*) reverse +{ + return [CCEaseBounceIn actionWithAction: [other reverse]]; +} + +@end + +@implementation CCEaseBounceInOut + +-(void) update: (ccTime) t +{ + ccTime newT = 0; + if (t < 0.5) { + t = t * 2; + newT = (1 - [self bounceTime:1-t] ) * 0.5f; + } else + newT = [self bounceTime:t * 2 - 1] * 0.5f + 0.5f; + + [other update:newT]; +} +@end + +#pragma mark - +#pragma mark Ease Back actions + +// +// EaseBackIn +// +@implementation CCEaseBackIn + +-(void) update: (ccTime) t +{ + ccTime overshoot = 1.70158f; + [other update: t * t * ((overshoot + 1) * t - overshoot)]; +} + +- (CCActionInterval*) reverse +{ + return [CCEaseBackOut actionWithAction: [other reverse]]; +} +@end + +// +// EaseBackOut +// +@implementation CCEaseBackOut +-(void) update: (ccTime) t +{ + ccTime overshoot = 1.70158f; + + t = t - 1; + [other update: t * t * ((overshoot + 1) * t + overshoot) + 1]; +} + +- (CCActionInterval*) reverse +{ + return [CCEaseBackIn actionWithAction: [other reverse]]; +} +@end + +// +// EaseBackInOut +// +@implementation CCEaseBackInOut + +-(void) update: (ccTime) t +{ + ccTime overshoot = 1.70158f * 1.525f; + + t = t * 2; + if (t < 1) + [other update: (t * t * ((overshoot + 1) * t - overshoot)) / 2]; + else { + t = t - 2; + [other update: (t * t * ((overshoot + 1) * t + overshoot)) / 2 + 1]; + } +} +@end diff --git a/Support/cocos2d/GridAction.h b/tweejump/libs/cocos2d/CCActionGrid.h old mode 100644 new mode 100755 similarity index 50% rename from Support/cocos2d/GridAction.h rename to tweejump/libs/cocos2d/CCActionGrid.h index 10673eb..6b31179 --- a/Support/cocos2d/GridAction.h +++ b/tweejump/libs/cocos2d/CCActionGrid.h @@ -1,50 +1,60 @@ -/* cocos2d for iPhone +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org * - * http://code.google.com/p/cocos2d-iphone + * Copyright (c) 2009 On-Core * - * Copyright (C) 2009 On-Core - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. + * 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. * */ -#import -#import "IntervalAction.h" -#import "InstantAction.h" -#import "Grid.h" +#import "CCActionInterval.h" +#import "CCActionInstant.h" +#import "CCGrid.h" -@class GridBase; +@class CCGridBase; /** Base class for Grid actions */ -@interface GridAction : IntervalAction +@interface CCGridAction : CCActionInterval { - ccGridSize gridSize; + ccGridSize gridSize_; } -@property ccGridSize gridSize; +/** size of the grid */ +@property (nonatomic,readwrite) ccGridSize gridSize; /** creates the action with size and duration */ +(id) actionWithSize:(ccGridSize)size duration:(ccTime)d; /** initializes the action with size and duration */ -(id) initWithSize:(ccGridSize)gridSize duration:(ccTime)d; /** returns the grid */ --(GridBase *)grid; +-(CCGridBase *)grid; @end //////////////////////////////////////////////////////////// -/** Base class for Grid3D actions. +/** Base class for CCGrid3D actions. Grid3D actions can modify a non-tiled grid. */ -@interface Grid3DAction : GridAction +@interface CCGrid3DAction : CCGridAction { - } /** returns the vertex than belongs to certain position in the grid */ @@ -58,10 +68,9 @@ //////////////////////////////////////////////////////////// -/** Base class for TiledGrid3D actions */ -@interface TiledGrid3DAction : GridAction +/** Base class for CCTiledGrid3D actions */ +@interface CCTiledGrid3DAction : CCGridAction { - } /** returns the tile that belongs to a certain position of the grid */ @@ -75,79 +84,79 @@ //////////////////////////////////////////////////////////// -/** AccelDeccelAmplitude action */ -@interface AccelDeccelAmplitude : IntervalAction +/** CCAccelDeccelAmplitude action */ +@interface CCAccelDeccelAmplitude : CCActionInterval { - float rate; - IntervalAction *other; + float rate_; + CCActionInterval *other_; } /** amplitude rate */ -@property float rate; +@property (nonatomic,readwrite) float rate; /** creates the action with an inner action that has the amplitude property, and a duration time */ -+(id)actionWithAction:(Action*)action duration:(ccTime)d; ++(id)actionWithAction:(CCAction*)action duration:(ccTime)d; /** initializes the action with an inner action that has the amplitude property, and a duration time */ --(id)initWithAction:(Action*)action duration:(ccTime)d; +-(id)initWithAction:(CCAction*)action duration:(ccTime)d; @end //////////////////////////////////////////////////////////// -/** AccelAmplitude action */ -@interface AccelAmplitude : IntervalAction +/** CCAccelAmplitude action */ +@interface CCAccelAmplitude : CCActionInterval { - float rate; - IntervalAction *other; + float rate_; + CCActionInterval *other_; } /** amplitude rate */ -@property float rate; +@property (nonatomic,readwrite) float rate; /** creates the action with an inner action that has the amplitude property, and a duration time */ -+(id)actionWithAction:(Action*)action duration:(ccTime)d; ++(id)actionWithAction:(CCAction*)action duration:(ccTime)d; /** initializes the action with an inner action that has the amplitude property, and a duration time */ --(id)initWithAction:(Action*)action duration:(ccTime)d; +-(id)initWithAction:(CCAction*)action duration:(ccTime)d; @end //////////////////////////////////////////////////////////// -/** DeccelAmplitude action */ -@interface DeccelAmplitude : IntervalAction +/** CCDeccelAmplitude action */ +@interface CCDeccelAmplitude : CCActionInterval { - float rate; - IntervalAction *other; + float rate_; + CCActionInterval *other_; } /** amplitude rate */ -@property float rate; +@property (nonatomic,readwrite) float rate; /** creates the action with an inner action that has the amplitude property, and a duration time */ -+(id)actionWithAction:(Action*)action duration:(ccTime)d; ++(id)actionWithAction:(CCAction*)action duration:(ccTime)d; /** initializes the action with an inner action that has the amplitude property, and a duration time */ --(id)initWithAction:(Action*)action duration:(ccTime)d; +-(id)initWithAction:(CCAction*)action duration:(ccTime)d; @end //////////////////////////////////////////////////////////// -/** StopGrid action. +/** CCStopGrid action. Don't call this action if another grid action is active. Call if you want to remove the the grid effect. Example: [Sequence actions:[Lens ...], [StopGrid action], nil]; */ -@interface StopGrid : InstantAction +@interface CCStopGrid : CCActionInstant { } @end //////////////////////////////////////////////////////////// -/** ReuseGrid action */ -@interface ReuseGrid : InstantAction +/** CCReuseGrid action */ +@interface CCReuseGrid : CCActionInstant { - int t; + int t_; } /** creates an action with the number of times that the current grid will be reused */ +(id) actionWithTimes: (int) times; diff --git a/tweejump/libs/cocos2d/CCActionGrid.m b/tweejump/libs/cocos2d/CCActionGrid.m new file mode 100755 index 0000000..638e27d --- /dev/null +++ b/tweejump/libs/cocos2d/CCActionGrid.m @@ -0,0 +1,386 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2009 On-Core + * + * 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. + * + */ + + +#import "CCActionGrid.h" +#import "CCDirector.h" + +#pragma mark - +#pragma mark GridAction + +@implementation CCGridAction + +@synthesize gridSize = gridSize_; + ++(id) actionWithSize:(ccGridSize)size duration:(ccTime)d +{ + return [[[self alloc] initWithSize:size duration:d ] autorelease]; +} + +-(id) initWithSize:(ccGridSize)gSize duration:(ccTime)d +{ + if ( (self = [super initWithDuration:d]) ) + { + gridSize_ = gSize; + } + + return self; +} + +-(void)startWithTarget:(id)aTarget +{ + [super startWithTarget:aTarget]; + + CCGridBase *newgrid = [self grid]; + + CCNode *t = (CCNode*) target_; + CCGridBase *targetGrid = [t grid]; + + if ( targetGrid && targetGrid.reuseGrid > 0 ) + { + if ( targetGrid.active && targetGrid.gridSize.x == gridSize_.x && targetGrid.gridSize.y == gridSize_.y && [targetGrid isKindOfClass:[newgrid class]] ) + [targetGrid reuse]; + else + [NSException raise:@"GridBase" format:@"Cannot reuse grid"]; + } + else + { + if ( targetGrid && targetGrid.active ) + targetGrid.active = NO; + + t.grid = newgrid; + t.grid.active = YES; + } +} + +-(CCGridBase *)grid +{ + [NSException raise:@"GridBase" format:@"Abstract class needs implementation"]; + return nil; +} + +- (CCActionInterval*) reverse +{ + return [CCReverseTime actionWithAction:self]; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCGridAction *copy = [[[self class] allocWithZone:zone] initWithSize:gridSize_ duration:duration_]; + return copy; +} +@end + +//////////////////////////////////////////////////////////// + +#pragma mark - +#pragma mark Grid3DAction + +@implementation CCGrid3DAction + +-(CCGridBase *)grid +{ + return [CCGrid3D gridWithSize:gridSize_]; +} + +-(ccVertex3F)vertex:(ccGridSize)pos +{ + CCGrid3D *g = (CCGrid3D *)[target_ grid]; + return [g vertex:pos]; +} + +-(ccVertex3F)originalVertex:(ccGridSize)pos +{ + CCGrid3D *g = (CCGrid3D *)[target_ grid]; + return [g originalVertex:pos]; +} + +-(void)setVertex:(ccGridSize)pos vertex:(ccVertex3F)vertex +{ + CCGrid3D *g = (CCGrid3D *)[target_ grid]; + [g setVertex:pos vertex:vertex]; +} +@end + +//////////////////////////////////////////////////////////// + +#pragma mark - +#pragma mark TiledGrid3DAction + +@implementation CCTiledGrid3DAction + +-(CCGridBase *)grid +{ + return [CCTiledGrid3D gridWithSize:gridSize_]; +} + +-(ccQuad3)tile:(ccGridSize)pos +{ + CCTiledGrid3D *g = (CCTiledGrid3D *)[target_ grid]; + return [g tile:pos]; +} + +-(ccQuad3)originalTile:(ccGridSize)pos +{ + CCTiledGrid3D *g = (CCTiledGrid3D *)[target_ grid]; + return [g originalTile:pos]; +} + +-(void)setTile:(ccGridSize)pos coords:(ccQuad3)coords +{ + CCTiledGrid3D *g = (CCTiledGrid3D *)[target_ grid]; + [g setTile:pos coords:coords]; +} + +@end + +//////////////////////////////////////////////////////////// + +@interface CCActionInterval (Amplitude) +-(void)setAmplitudeRate:(CGFloat)amp; +-(CGFloat)getAmplitudeRate; +@end + +@implementation CCActionInterval (Amplitude) +-(void)setAmplitudeRate:(CGFloat)amp +{ + [NSException raise:@"IntervalAction (Amplitude)" format:@"Abstract class needs implementation"]; +} + +-(CGFloat)getAmplitudeRate +{ + [NSException raise:@"IntervalAction (Amplitude)" format:@"Abstract class needs implementation"]; + return 0; +} +@end + +//////////////////////////////////////////////////////////// + +#pragma mark - +#pragma mark AccelDeccelAmplitude + +@implementation CCAccelDeccelAmplitude + +@synthesize rate=rate_; + ++(id)actionWithAction:(CCAction*)action duration:(ccTime)d +{ + return [[[self alloc] initWithAction:action duration:d ] autorelease]; +} + +-(id)initWithAction:(CCAction *)action duration:(ccTime)d +{ + if ( (self = [super initWithDuration:d]) ) + { + rate_ = 1.0f; + other_ = (CCActionInterval*)[action retain]; + } + + return self; +} + +-(void)dealloc +{ + [other_ release]; + [super dealloc]; +} + +-(void)startWithTarget:(id)aTarget +{ + [super startWithTarget:aTarget]; + [other_ startWithTarget:target_]; +} + +-(void) update: (ccTime) time +{ + float f = time*2; + + if (f > 1) + { + f -= 1; + f = 1 - f; + } + + [other_ setAmplitudeRate:powf(f, rate_)]; + [other_ update:time]; +} + +- (CCActionInterval*) reverse +{ + return [CCAccelDeccelAmplitude actionWithAction:[other_ reverse] duration:duration_]; +} + +@end + +//////////////////////////////////////////////////////////// + +#pragma mark - +#pragma mark AccelAmplitude + +@implementation CCAccelAmplitude + +@synthesize rate=rate_; + ++(id)actionWithAction:(CCAction*)action duration:(ccTime)d +{ + return [[[self alloc] initWithAction:action duration:d ] autorelease]; +} + +-(id)initWithAction:(CCAction *)action duration:(ccTime)d +{ + if ( (self = [super initWithDuration:d]) ) + { + rate_ = 1.0f; + other_ = (CCActionInterval*)[action retain]; + } + + return self; +} + +-(void)dealloc +{ + [other_ release]; + [super dealloc]; +} + +-(void)startWithTarget:(id)aTarget +{ + [super startWithTarget:aTarget]; + [other_ startWithTarget:target_]; +} + +-(void) update: (ccTime) time +{ + [other_ setAmplitudeRate:powf(time, rate_)]; + [other_ update:time]; +} + +- (CCActionInterval*) reverse +{ + return [CCAccelAmplitude actionWithAction:[other_ reverse] duration:self.duration]; +} + +@end + +//////////////////////////////////////////////////////////// + +#pragma mark - +#pragma mark DeccelAmplitude + +@implementation CCDeccelAmplitude + +@synthesize rate=rate_; + ++(id)actionWithAction:(CCAction*)action duration:(ccTime)d +{ + return [[[self alloc] initWithAction:action duration:d ] autorelease]; +} + +-(id)initWithAction:(CCAction *)action duration:(ccTime)d +{ + if ( (self = [super initWithDuration:d]) ) + { + rate_ = 1.0f; + other_ = (CCActionInterval*)[action retain]; + } + + return self; +} + +-(void)dealloc +{ + [other_ release]; + [super dealloc]; +} + +-(void)startWithTarget:(id)aTarget +{ + [super startWithTarget:aTarget]; + [other_ startWithTarget:target_]; +} + +-(void) update: (ccTime) time +{ + [other_ setAmplitudeRate:powf((1-time), rate_)]; + [other_ update:time]; +} + +- (CCActionInterval*) reverse +{ + return [CCDeccelAmplitude actionWithAction:[other_ reverse] duration:self.duration]; +} + +@end + +//////////////////////////////////////////////////////////// + +#pragma mark - +#pragma mark StopGrid + +@implementation CCStopGrid + +-(void)startWithTarget:(id)aTarget +{ + [super startWithTarget:aTarget]; + + if ( [[self target] grid] && [[[self target] grid] active] ) { + [[[self target] grid] setActive: NO]; + +// [[self target] setGrid: nil]; + } +} + +@end + +//////////////////////////////////////////////////////////// + +#pragma mark - +#pragma mark ReuseGrid + +@implementation CCReuseGrid + ++(id)actionWithTimes:(int)times +{ + return [[[self alloc] initWithTimes:times ] autorelease]; +} + +-(id)initWithTimes:(int)times +{ + if ( (self = [super init]) ) + t_ = times; + + return self; +} + +-(void)startWithTarget:(id)aTarget +{ + [super startWithTarget:aTarget]; + + CCNode *myTarget = (CCNode*) [self target]; + if ( myTarget.grid && myTarget.grid.active ) + myTarget.grid.reuseGrid += t_; +} + +@end diff --git a/Support/cocos2d/Grid3DAction.h b/tweejump/libs/cocos2d/CCActionGrid3D.h old mode 100644 new mode 100755 similarity index 51% rename from Support/cocos2d/Grid3DAction.h rename to tweejump/libs/cocos2d/CCActionGrid3D.h index 972057f..a8003f4 --- a/Support/cocos2d/Grid3DAction.h +++ b/tweejump/libs/cocos2d/CCActionGrid3D.h @@ -1,29 +1,43 @@ -/* cocos2d for iPhone +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org * - * http://code.google.com/p/cocos2d-iphone + * Copyright (c) 2009 On-Core * - * Copyright (C) 2009 On-Core - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. + * 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. * */ -#import "GridAction.h" -/** Waves3D action */ -@interface Waves3D : Grid3DAction +#import "CCActionGrid.h" + +/** CCWaves3D action */ +@interface CCWaves3D : CCGrid3DAction { int waves; float amplitude; float amplitudeRate; } -@property float amplitude; -@property float amplitudeRate; +/** amplitude of the wave */ +@property (nonatomic,readwrite) float amplitude; +/** amplitude rate of the wave */ +@property (nonatomic,readwrite) float amplitudeRate; +(id)actionWithWaves:(int)wav amplitude:(float)amp grid:(ccGridSize)gridSize duration:(ccTime)d; -(id)initWithWaves:(int)wav amplitude:(float)amp grid:(ccGridSize)gridSize duration:(ccTime)d; @@ -32,8 +46,8 @@ //////////////////////////////////////////////////////////// -/** FlipX3D action */ -@interface FlipX3D : Grid3DAction +/** CCFlipX3D action */ +@interface CCFlipX3D : CCGrid3DAction { } @@ -46,8 +60,8 @@ //////////////////////////////////////////////////////////// -/** FlipY3D action */ -@interface FlipY3D : FlipX3D +/** CCFlipY3D action */ +@interface CCFlipY3D : CCFlipX3D { } @@ -55,57 +69,59 @@ //////////////////////////////////////////////////////////// -/** Lens3D action */ -@interface Lens3D : Grid3DAction +/** CCLens3D action */ +@interface CCLens3D : CCGrid3DAction { - CGPoint position; - float radius; - float lensEffect; - CGPoint lastPosition; + CGPoint position_; + CGPoint positionInPixels_; + float radius_; + float lensEffect_; + BOOL dirty_; } /** lens effect. Defaults to 0.7 - 0 means no effect, 1 is very strong effect */ -@property float lensEffect; -/** lens center position */ -@property CGPoint position; +@property (nonatomic,readwrite) float lensEffect; +/** lens center position in Points */ +@property (nonatomic,readwrite) CGPoint position; -/** creates the action with center position, radius, a grid size and duration */ +/** creates the action with center position in Points, radius, a grid size and duration */ +(id)actionWithPosition:(CGPoint)pos radius:(float)r grid:(ccGridSize)gridSize duration:(ccTime)d; -/** initializes the action with center position, radius, a grid size and duration */ +/** initializes the action with center position in Points, radius, a grid size and duration */ -(id)initWithPosition:(CGPoint)pos radius:(float)r grid:(ccGridSize)gridSize duration:(ccTime)d; @end //////////////////////////////////////////////////////////// -/** Ripple3D action */ -@interface Ripple3D : Grid3DAction +/** CCRipple3D action */ +@interface CCRipple3D : CCGrid3DAction { - CGPoint position; - float radius; - int waves; - float amplitude; - float amplitudeRate; + CGPoint position_; + CGPoint positionInPixels_; + float radius_; + int waves_; + float amplitude_; + float amplitudeRate_; } -/** center position */ -@property CGPoint position; +/** center position in Points */ +@property (nonatomic,readwrite) CGPoint position; /** amplitude */ -@property float amplitude; +@property (nonatomic,readwrite) float amplitude; /** amplitude rate */ -@property float amplitudeRate; +@property (nonatomic,readwrite) float amplitudeRate; -/** creates the action with radius, number of waves, amplitude, a grid size and duration */ +/** creates the action with a position in points, radius, number of waves, amplitude, a grid size and duration */ +(id)actionWithPosition:(CGPoint)pos radius:(float)r waves:(int)wav amplitude:(float)amp grid:(ccGridSize)gridSize duration:(ccTime)d; -/** initializes the action with radius, number of waves, amplitude, a grid size and duration */ +/** initializes the action with a position in points, radius, number of waves, amplitude, a grid size and duration */ -(id)initWithPosition:(CGPoint)pos radius:(float)r waves:(int)wav amplitude:(float)amp grid:(ccGridSize)gridSize duration:(ccTime)d; @end //////////////////////////////////////////////////////////// -/** Shaky3D action */ -@interface Shaky3D : Grid3DAction +/** CCShaky3D action */ +@interface CCShaky3D : CCGrid3DAction { int randrange; BOOL shakeZ; @@ -120,8 +136,8 @@ //////////////////////////////////////////////////////////// -/** Liquid action */ -@interface Liquid : Grid3DAction +/** CCLiquid action */ +@interface CCLiquid : CCGrid3DAction { int waves; float amplitude; @@ -130,9 +146,9 @@ } /** amplitude */ -@property float amplitude; +@property (nonatomic,readwrite) float amplitude; /** amplitude rate */ -@property float amplitudeRate; +@property (nonatomic,readwrite) float amplitudeRate; /** creates the action with amplitude, a grid and duration */ +(id)actionWithWaves:(int)wav amplitude:(float)amp grid:(ccGridSize)gridSize duration:(ccTime)d; @@ -143,8 +159,8 @@ //////////////////////////////////////////////////////////// -/** Waves action */ -@interface Waves : Grid3DAction +/** CCWaves action */ +@interface CCWaves : CCGrid3DAction { int waves; float amplitude; @@ -154,9 +170,9 @@ } /** amplitude */ -@property float amplitude; +@property (nonatomic,readwrite) float amplitude; /** amplitude rate */ -@property float amplitudeRate; +@property (nonatomic,readwrite) float amplitudeRate; /** initializes the action with amplitude, horizontal sin, vertical sin, a grid and duration */ +(id)actionWithWaves:(int)wav amplitude:(float)amp horizontal:(BOOL)h vertical:(BOOL)v grid:(ccGridSize)gridSize duration:(ccTime)d; @@ -167,21 +183,22 @@ //////////////////////////////////////////////////////////// -/** Twirl action */ -@interface Twirl : Grid3DAction +/** CCTwirl action */ +@interface CCTwirl : CCGrid3DAction { - CGPoint position; - int twirls; - float amplitude; - float amplitudeRate; + CGPoint position_; + CGPoint positionInPixels_; + int twirls_; + float amplitude_; + float amplitudeRate_; } /** twirl center */ -@property CGPoint position; +@property (nonatomic,readwrite) CGPoint position; /** amplitude */ -@property float amplitude; +@property (nonatomic,readwrite) float amplitude; /** amplitude rate */ -@property float amplitudeRate; +@property (nonatomic,readwrite) float amplitudeRate; /** creates the action with center position, number of twirls, amplitude, a grid size and duration */ +(id)actionWithPosition:(CGPoint)pos twirls:(int)t amplitude:(float)amp grid:(ccGridSize)gridSize duration:(ccTime)d; diff --git a/Support/cocos2d/Grid3DAction.m b/tweejump/libs/cocos2d/CCActionGrid3D.m old mode 100644 new mode 100755 similarity index 59% rename from Support/cocos2d/Grid3DAction.m rename to tweejump/libs/cocos2d/CCActionGrid3D.m index 194a72e..1d4a783 --- a/Support/cocos2d/Grid3DAction.m +++ b/tweejump/libs/cocos2d/CCActionGrid3D.m @@ -1,21 +1,37 @@ -/* cocos2d for iPhone +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org * - * http://code.google.com/p/cocos2d-iphone + * Copyright (c) 2009 On-Core * - * Copyright (C) 2009 On-Core - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. + * 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. * */ -#import "Grid3DAction.h" + +#import "CCActionGrid3D.h" +#import "ccMacros.h" #import "Support/CGPointExtension.h" -@implementation Waves3D +#pragma mark - +#pragma mark Waves3D + +@implementation CCWaves3D @synthesize amplitude; @synthesize amplitudeRate; @@ -37,13 +53,20 @@ -(id)initWithWaves:(int)wav amplitude:(float)amp grid:(ccGridSize)gSize duration return self; } +-(id) copyWithZone: (NSZone*) zone +{ + CCGridAction *copy = [[[self class] allocWithZone:zone] initWithWaves:waves amplitude:amplitude grid:gridSize_ duration:duration_]; + return copy; +} + + -(void)update:(ccTime)time { int i, j; - for( i = 0; i < (gridSize.x+1); i++ ) + for( i = 0; i < (gridSize_.x+1); i++ ) { - for( j = 0; j < (gridSize.y+1); j++ ) + for( j = 0; j < (gridSize_.y+1); j++ ) { ccVertex3F v = [self originalVertex:ccg(i,j)]; v.z += (sinf((CGFloat)M_PI*time*waves*2 + (v.y+v.x) * .01f) * amplitude * amplitudeRate); @@ -55,7 +78,10 @@ -(void)update:(ccTime)time //////////////////////////////////////////////////////////// -@implementation FlipX3D +#pragma mark - +#pragma mark FlipX3D + +@implementation CCFlipX3D +(id) actionWithDuration:(ccTime)d { @@ -77,6 +103,13 @@ -(id)initWithSize:(ccGridSize)gSize duration:(ccTime)d return [super initWithSize:gSize duration:d]; } +-(id) copyWithZone: (NSZone*) zone +{ + CCGridAction *copy = [[[self class] allocWithZone:zone] initWithSize:gridSize_ duration:duration_]; + return copy; +} + + -(void)update:(ccTime)time { CGFloat angle = (CGFloat)M_PI * time; // 180 degrees @@ -145,7 +178,10 @@ -(void)update:(ccTime)time //////////////////////////////////////////////////////////// -@implementation FlipY3D +#pragma mark - +#pragma mark FlipY3D + +@implementation CCFlipY3D -(void)update:(ccTime)time { @@ -215,10 +251,12 @@ -(void)update:(ccTime)time //////////////////////////////////////////////////////////// -@implementation Lens3D +#pragma mark - +#pragma mark Lens3D -@synthesize lensEffect; -@synthesize position; +@implementation CCLens3D + +@synthesize lensEffect=lensEffect_; +(id)actionWithPosition:(CGPoint)pos radius:(float)r grid:(ccGridSize)gridSize duration:(ccTime)d { @@ -229,42 +267,65 @@ -(id)initWithPosition:(CGPoint)pos radius:(float)r grid:(ccGridSize)gSize durati { if ( (self = [super initWithSize:gSize duration:d]) ) { + position_ = ccp(-1,-1); self.position = pos; - radius = r; - lensEffect = 0.7f; - lastPosition = ccp(-1,-1); + radius_ = r; + lensEffect_ = 0.7f; + dirty_ = YES; } return self; } +-(id) copyWithZone: (NSZone*) zone +{ + CCGridAction *copy = [[[self class] allocWithZone:zone] initWithPosition:position_ radius:radius_ grid:gridSize_ duration:duration_]; + return copy; +} + +-(void) setPosition:(CGPoint)pos +{ + if( ! CGPointEqualToPoint(pos, position_) ) { + position_ = pos; + positionInPixels_.x = pos.x * CC_CONTENT_SCALE_FACTOR(); + positionInPixels_.y = pos.y * CC_CONTENT_SCALE_FACTOR(); + + dirty_ = YES; + } +} + +-(CGPoint) position +{ + return position_; +} + -(void)update:(ccTime)time { - if ( position.x != lastPosition.x || position.y != lastPosition.y ) + if ( dirty_ ) { int i, j; - for( i = 0; i < gridSize.x+1; i++ ) + for( i = 0; i < gridSize_.x+1; i++ ) { - for( j = 0; j < gridSize.y+1; j++ ) + for( j = 0; j < gridSize_.y+1; j++ ) { ccVertex3F v = [self originalVertex:ccg(i,j)]; - CGPoint vect = ccpSub(position, ccp(v.x,v.y)); + CGPoint vect = ccpSub(positionInPixels_, ccp(v.x,v.y)); CGFloat r = ccpLength(vect); - if ( r < radius ) + if ( r < radius_ ) { - r = radius - r; - CGFloat pre_log = r / radius; + r = radius_ - r; + CGFloat pre_log = r / radius_; if ( pre_log == 0 ) pre_log = 0.001f; - float l = logf(pre_log) * lensEffect; - float new_r = expf( l ) * radius; + float l = logf(pre_log) * lensEffect_; + float new_r = expf( l ) * radius_; if ( ccpLength(vect) > 0 ) { vect = ccpNormalize(vect); CGPoint new_vect = ccpMult(vect, new_r); - v.z += ccpLength(new_vect) * lensEffect; + v.z += ccpLength(new_vect) * lensEffect_; } } @@ -272,7 +333,7 @@ -(void)update:(ccTime)time } } - lastPosition = position; + dirty_ = NO; } } @@ -280,11 +341,13 @@ -(void)update:(ccTime)time //////////////////////////////////////////////////////////// -@implementation Ripple3D +#pragma mark - +#pragma mark Ripple3D -@synthesize position; -@synthesize amplitude; -@synthesize amplitudeRate; +@implementation CCRipple3D + +@synthesize amplitude = amplitude_; +@synthesize amplitudeRate = amplitudeRate_; +(id)actionWithPosition:(CGPoint)pos radius:(float)r waves:(int)wav amplitude:(float)amp grid:(ccGridSize)gridSize duration:(ccTime)d { @@ -296,32 +359,51 @@ -(id)initWithPosition:(CGPoint)pos radius:(float)r waves:(int)wav amplitude:(flo if ( (self = [super initWithSize:gSize duration:d]) ) { self.position = pos; - radius = r; - waves = wav; - amplitude = amp; - amplitudeRate = 1.0f; + radius_ = r; + waves_ = wav; + amplitude_ = amp; + amplitudeRate_ = 1.0f; } return self; } +-(CGPoint) position +{ + return position_; +} + +-(void) setPosition:(CGPoint)pos +{ + position_ = pos; + positionInPixels_.x = pos.x * CC_CONTENT_SCALE_FACTOR(); + positionInPixels_.y = pos.y * CC_CONTENT_SCALE_FACTOR(); +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCGridAction *copy = [[[self class] allocWithZone:zone] initWithPosition:position_ radius:radius_ waves:waves_ amplitude:amplitude_ grid:gridSize_ duration:duration_]; + return copy; +} + + -(void)update:(ccTime)time { int i, j; - for( i = 0; i < (gridSize.x+1); i++ ) + for( i = 0; i < (gridSize_.x+1); i++ ) { - for( j = 0; j < (gridSize.y+1); j++ ) + for( j = 0; j < (gridSize_.y+1); j++ ) { ccVertex3F v = [self originalVertex:ccg(i,j)]; - CGPoint vect = ccpSub(position, ccp(v.x,v.y)); + CGPoint vect = ccpSub(positionInPixels_, ccp(v.x,v.y)); CGFloat r = ccpLength(vect); - if ( r < radius ) + if ( r < radius_ ) { - r = radius - r; - CGFloat rate = powf( r / radius, 2); - v.z += (sinf( time*(CGFloat)M_PI*waves*2 + r * 0.1f) * amplitude * amplitudeRate * rate ); + r = radius_ - r; + CGFloat rate = powf( r / radius_, 2); + v.z += (sinf( time*(CGFloat)M_PI*waves_*2 + r * 0.1f) * amplitude_ * amplitudeRate_ * rate ); } [self setVertex:ccg(i,j) vertex:v]; @@ -333,7 +415,10 @@ -(void)update:(ccTime)time //////////////////////////////////////////////////////////// -@implementation Shaky3D +#pragma mark - +#pragma mark Shaky3D + +@implementation CCShaky3D +(id)actionWithRange:(int)range shakeZ:(BOOL)sz grid:(ccGridSize)gridSize duration:(ccTime)d { @@ -351,13 +436,19 @@ -(id)initWithRange:(int)range shakeZ:(BOOL)sz grid:(ccGridSize)gSize duration:(c return self; } +-(id) copyWithZone: (NSZone*) zone +{ + CCGridAction *copy = [[[self class] allocWithZone:zone] initWithRange:randrange shakeZ:shakeZ grid:gridSize_ duration:duration_]; + return copy; +} + -(void)update:(ccTime)time { int i, j; - for( i = 0; i < (gridSize.x+1); i++ ) + for( i = 0; i < (gridSize_.x+1); i++ ) { - for( j = 0; j < (gridSize.y+1); j++ ) + for( j = 0; j < (gridSize_.y+1); j++ ) { ccVertex3F v = [self originalVertex:ccg(i,j)]; v.x += ( rand() % (randrange*2) ) - randrange; @@ -374,7 +465,10 @@ -(void)update:(ccTime)time //////////////////////////////////////////////////////////// -@implementation Liquid +#pragma mark - +#pragma mark Liquid + +@implementation CCLiquid @synthesize amplitude; @synthesize amplitudeRate; @@ -400,9 +494,9 @@ -(void)update:(ccTime)time { int i, j; - for( i = 1; i < gridSize.x; i++ ) + for( i = 1; i < gridSize_.x; i++ ) { - for( j = 1; j < gridSize.y; j++ ) + for( j = 1; j < gridSize_.y; j++ ) { ccVertex3F v = [self originalVertex:ccg(i,j)]; v.x = (v.x + (sinf(time*(CGFloat)M_PI*waves*2 + v.x * .01f) * amplitude * amplitudeRate)); @@ -412,11 +506,20 @@ -(void)update:(ccTime)time } } +-(id) copyWithZone: (NSZone*) zone +{ + CCGridAction *copy = [[[self class] allocWithZone:zone] initWithWaves:waves amplitude:amplitude grid:gridSize_ duration:duration_]; + return copy; +} + @end //////////////////////////////////////////////////////////// -@implementation Waves +#pragma mark - +#pragma mark Waves + +@implementation CCWaves @synthesize amplitude; @synthesize amplitudeRate; @@ -444,9 +547,9 @@ -(void)update:(ccTime)time { int i, j; - for( i = 0; i < (gridSize.x+1); i++ ) + for( i = 0; i < (gridSize_.x+1); i++ ) { - for( j = 0; j < (gridSize.y+1); j++ ) + for( j = 0; j < (gridSize_.y+1); j++ ) { ccVertex3F v = [self originalVertex:ccg(i,j)]; @@ -459,17 +562,25 @@ -(void)update:(ccTime)time [self setVertex:ccg(i,j) vertex:v]; } } -} +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCGridAction *copy = [[[self class] allocWithZone:zone] initWithWaves:waves amplitude:amplitude horizontal:horizontal vertical:vertical grid:gridSize_ duration:duration_]; + return copy; +} @end //////////////////////////////////////////////////////////// -@implementation Twirl +#pragma mark - +#pragma mark Twirl -@synthesize position; -@synthesize amplitude; -@synthesize amplitudeRate; +@implementation CCTwirl + +@synthesize amplitude = amplitude_; +@synthesize amplitudeRate = amplitudeRate_; +(id)actionWithPosition:(CGPoint)pos twirls:(int)t amplitude:(float)amp grid:(ccGridSize)gridSize duration:(ccTime)d { @@ -481,35 +592,50 @@ -(id)initWithPosition:(CGPoint)pos twirls:(int)t amplitude:(float)amp grid:(ccGr if ( (self = [super initWithSize:gSize duration:d]) ) { self.position = pos; - twirls = t; - amplitude = amp; - amplitudeRate = 1.0f; + twirls_ = t; + amplitude_ = amp; + amplitudeRate_ = 1.0f; } return self; } +-(void) setPosition:(CGPoint)pos +{ + position_ = pos; + positionInPixels_.x = pos.x * CC_CONTENT_SCALE_FACTOR(); + positionInPixels_.y = pos.y * CC_CONTENT_SCALE_FACTOR(); +} + +-(CGPoint) position +{ + return position_; +} + -(void)update:(ccTime)time { int i, j; - CGPoint c = position; + CGPoint c = positionInPixels_; - for( i = 0; i < (gridSize.x+1); i++ ) + for( i = 0; i < (gridSize_.x+1); i++ ) { - for( j = 0; j < (gridSize.y+1); j++ ) + for( j = 0; j < (gridSize_.y+1); j++ ) { - ccVertex3F v = [self originalVertex:ccg(i,j)]; + ccVertex3F v = [self originalVertex:ccg(i,j)]; - CGPoint avg = ccp(i-(gridSize.x/2.0f), j-(gridSize.y/2.0f)); + CGPoint avg = ccp(i-(gridSize_.x/2.0f), j-(gridSize_.y/2.0f)); CGFloat r = ccpLength( avg ); - CGFloat amp = 0.1f * amplitude * amplitudeRate; - CGFloat a = r * cosf( (CGFloat)M_PI/2.0f + time * (CGFloat)M_PI * twirls * 2 ) * amp; + CGFloat amp = 0.1f * amplitude_ * amplitudeRate_; + CGFloat a = r * cosf( (CGFloat)M_PI/2.0f + time * (CGFloat)M_PI * twirls_ * 2 ) * amp; - CGPoint d; + float cosA = cosf(a); + float sinA = sinf(a); - d.x = sinf(a) * (v.y-c.y) + cosf(a) * (v.x-c.x); - d.y = cosf(a) * (v.y-c.y) - sinf(a) * (v.x-c.x); + CGPoint d = { + sinA * (v.y-c.y) + cosA * (v.x-c.x), + cosA * (v.y-c.y) - sinA * (v.x-c.x) + }; v.x = c.x + d.x; v.y = c.y + d.y; @@ -519,4 +645,15 @@ -(void)update:(ccTime)time } } +-(id) copyWithZone: (NSZone*) zone +{ + CCGridAction *copy = [[[self class] allocWithZone:zone] initWithPosition:position_ + twirls:twirls_ + amplitude:amplitude_ + grid:gridSize_ + duration:duration_]; + return copy; +} + + @end diff --git a/tweejump/libs/cocos2d/CCActionInstant.h b/tweejump/libs/cocos2d/CCActionInstant.h new file mode 100755 index 0000000..5a1bc2d --- /dev/null +++ b/tweejump/libs/cocos2d/CCActionInstant.h @@ -0,0 +1,205 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-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. + * + */ + + +#import "CCAction.h" + +/** Instant actions are immediate actions. They don't have a duration like + the CCIntervalAction actions. +*/ +@interface CCActionInstant : CCFiniteTimeAction +{ +} +@end + +/** Show the node + */ + @interface CCShow : CCActionInstant +{ +} +@end + +/** Hide the node + */ +@interface CCHide : CCActionInstant +{ +} +@end + +/** Toggles the visibility of a node + */ +@interface CCToggleVisibility : CCActionInstant +{ +} +@end + +/** Flips the sprite horizontally + @since v0.99.0 + */ +@interface CCFlipX : CCActionInstant +{ + BOOL flipX; +} ++(id) actionWithFlipX:(BOOL)x; +-(id) initWithFlipX:(BOOL)x; +@end + +/** Flips the sprite vertically + @since v0.99.0 + */ +@interface CCFlipY : CCActionInstant +{ + BOOL flipY; +} ++(id) actionWithFlipY:(BOOL)y; +-(id) initWithFlipY:(BOOL)y; +@end + +/** Places the node in a certain position + */ +@interface CCPlace : CCActionInstant +{ + CGPoint position; +} +/** creates a Place action with a position */ ++(id) actionWithPosition: (CGPoint) pos; +/** Initializes a Place action with a position */ +-(id) initWithPosition: (CGPoint) pos; +@end + +/** Calls a 'callback' + */ +@interface CCCallFunc : CCActionInstant +{ + id targetCallback_; + SEL selector_; +} + +/** Target that will be called */ +@property (nonatomic, readwrite, retain) id targetCallback; + +/** creates the action with the callback */ ++(id) actionWithTarget: (id) t selector:(SEL) s; +/** initializes the action with the callback */ +-(id) initWithTarget: (id) t selector:(SEL) s; +/** exeuctes the callback */ +-(void) execute; +@end + +/** Calls a 'callback' with the node as the first argument. + N means Node + */ +@interface CCCallFuncN : CCCallFunc +{ +} +@end + +typedef void (*CC_CALLBACK_ND)(id, SEL, id, void *); +/** Calls a 'callback' with the node as the first argument and the 2nd argument is data. + * ND means: Node and Data. Data is void *, so it could be anything. + */ +@interface CCCallFuncND : CCCallFuncN +{ + void *data_; + CC_CALLBACK_ND callbackMethod_; +} + +/** Invocation object that has the target#selector and the parameters */ +@property (nonatomic,readwrite) CC_CALLBACK_ND callbackMethod; + +/** creates the action with the callback and the data to pass as an argument */ ++(id) actionWithTarget: (id) t selector:(SEL) s data:(void*)d; +/** initializes the action with the callback and the data to pass as an argument */ +-(id) initWithTarget:(id) t selector:(SEL) s data:(void*) d; +@end + +/** Calls a 'callback' with an object as the first argument. + O means Object. + @since v0.99.5 + */ +@interface CCCallFuncO : CCCallFunc +{ + id object_; +} +/** object to be passed as argument */ +@property (nonatomic, readwrite, retain) id object; + +/** creates the action with the callback and the object to pass as an argument */ ++(id) actionWithTarget: (id) t selector:(SEL) s object:(id)object; +/** initializes the action with the callback and the object to pass as an argument */ +-(id) initWithTarget:(id) t selector:(SEL) s object:(id)object; + +@end + +#pragma mark Blocks Support + +#if NS_BLOCKS_AVAILABLE + +/** Executes a callback using a block. + */ +@interface CCCallBlock : CCActionInstant +{ + void (^block_)(); +} + +/** creates the action with the specified block, to be used as a callback. + The block will be "copied". + */ ++(id) actionWithBlock:(void(^)())block; + +/** initialized the action with the specified block, to be used as a callback. + The block will be "copied". + */ +-(id) initWithBlock:(void(^)())block; + +/** executes the callback */ +-(void) execute; +@end + +@class CCNode; + +/** Executes a callback using a block with a single CCNode parameter. + */ +@interface CCCallBlockN : CCActionInstant +{ + void (^block_)(CCNode *); +} + +/** creates the action with the specified block, to be used as a callback. + The block will be "copied". + */ ++(id) actionWithBlock:(void(^)(CCNode *node))block; + +/** initialized the action with the specified block, to be used as a callback. + The block will be "copied". + */ +-(id) initWithBlock:(void(^)(CCNode *node))block; + +/** executes the callback */ +-(void) execute; +@end + +#endif diff --git a/tweejump/libs/cocos2d/CCActionInstant.m b/tweejump/libs/cocos2d/CCActionInstant.m new file mode 100755 index 0000000..e7f6fad --- /dev/null +++ b/tweejump/libs/cocos2d/CCActionInstant.m @@ -0,0 +1,477 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-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. + * + */ + + +#import "CCBlockSupport.h" +#import "CCActionInstant.h" +#import "CCNode.h" +#import "CCSprite.h" + + +// +// InstantAction +// +#pragma mark CCActionInstant + +@implementation CCActionInstant + +-(id) init +{ + if( (self=[super init]) ) + duration_ = 0; + + return self; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCActionInstant *copy = [[[self class] allocWithZone: zone] init]; + return copy; +} + +- (BOOL) isDone +{ + return YES; +} + +-(void) step: (ccTime) dt +{ + [self update: 1]; +} + +-(void) update: (ccTime) t +{ + // ignore +} + +-(CCFiniteTimeAction*) reverse +{ + return [[self copy] autorelease]; +} +@end + +// +// Show +// +#pragma mark CCShow + +@implementation CCShow +-(void) startWithTarget:(id)aTarget +{ + [super startWithTarget:aTarget]; + ((CCNode *)target_).visible = YES; +} + +-(CCFiniteTimeAction*) reverse +{ + return [CCHide action]; +} +@end + +// +// Hide +// +#pragma mark CCHide + +@implementation CCHide +-(void) startWithTarget:(id)aTarget +{ + [super startWithTarget:aTarget]; + ((CCNode *)target_).visible = NO; +} + +-(CCFiniteTimeAction*) reverse +{ + return [CCShow action]; +} +@end + +// +// ToggleVisibility +// +#pragma mark CCToggleVisibility + +@implementation CCToggleVisibility +-(void) startWithTarget:(id)aTarget +{ + [super startWithTarget:aTarget]; + ((CCNode *)target_).visible = !((CCNode *)target_).visible; +} +@end + +// +// FlipX +// +#pragma mark CCFlipX + +@implementation CCFlipX ++(id) actionWithFlipX:(BOOL)x +{ + return [[[self alloc] initWithFlipX:x] autorelease]; +} + +-(id) initWithFlipX:(BOOL)x +{ + if(( self=[super init])) + flipX = x; + + return self; +} + +-(void) startWithTarget:(id)aTarget +{ + [super startWithTarget:aTarget]; + [(CCSprite*)aTarget setFlipX:flipX]; +} + +-(CCFiniteTimeAction*) reverse +{ + return [CCFlipX actionWithFlipX:!flipX]; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCActionInstant *copy = [[[self class] allocWithZone: zone] initWithFlipX:flipX]; + return copy; +} +@end + +// +// FlipY +// +#pragma mark CCFlipY + +@implementation CCFlipY ++(id) actionWithFlipY:(BOOL)y +{ + return [[[self alloc] initWithFlipY:y] autorelease]; +} + +-(id) initWithFlipY:(BOOL)y +{ + if(( self=[super init])) + flipY = y; + + return self; +} + +-(void) startWithTarget:(id)aTarget +{ + [super startWithTarget:aTarget]; + [(CCSprite*)aTarget setFlipY:flipY]; +} + +-(CCFiniteTimeAction*) reverse +{ + return [CCFlipY actionWithFlipY:!flipY]; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCActionInstant *copy = [[[self class] allocWithZone: zone] initWithFlipY:flipY]; + return copy; +} +@end + + +// +// Place +// +#pragma mark CCPlace + +@implementation CCPlace ++(id) actionWithPosition: (CGPoint) pos +{ + return [[[self alloc]initWithPosition:pos]autorelease]; +} + +-(id) initWithPosition: (CGPoint) pos +{ + if( (self=[super init]) ) + position = pos; + + return self; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCActionInstant *copy = [[[self class] allocWithZone: zone] initWithPosition: position]; + return copy; +} + +-(void) startWithTarget:(id)aTarget +{ + [super startWithTarget:aTarget]; + ((CCNode *)target_).position = position; +} + +@end + +// +// CallFunc +// +#pragma mark CCCallFunc + +@implementation CCCallFunc + +@synthesize targetCallback = targetCallback_; + ++(id) actionWithTarget: (id) t selector:(SEL) s +{ + return [[[self alloc] initWithTarget: t selector: s] autorelease]; +} + +-(id) initWithTarget: (id) t selector:(SEL) s +{ + if( (self=[super init]) ) { + self.targetCallback = t; + selector_ = s; + } + return self; +} + +-(NSString*) description +{ + return [NSString stringWithFormat:@"<%@ = %08X | Tag = %i | target = %@ | selector = %@>", + [self class], + self, + tag_, + [targetCallback_ class], + NSStringFromSelector(selector_) + ]; +} + +-(void) dealloc +{ + [targetCallback_ release]; + [super dealloc]; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCActionInstant *copy = [[[self class] allocWithZone: zone] initWithTarget:targetCallback_ selector:selector_]; + return copy; +} + +-(void) startWithTarget:(id)aTarget +{ + [super startWithTarget:aTarget]; + [self execute]; +} + +-(void) execute +{ + [targetCallback_ performSelector:selector_]; +} +@end + +// +// CallFuncN +// +#pragma mark CCCallFuncN + +@implementation CCCallFuncN + +-(void) execute +{ + [targetCallback_ performSelector:selector_ withObject:target_]; +} +@end + +// +// CallFuncND +// +#pragma mark CCCallFuncND + +@implementation CCCallFuncND + +@synthesize callbackMethod = callbackMethod_; + ++(id) actionWithTarget:(id)t selector:(SEL)s data:(void*)d +{ + return [[[self alloc] initWithTarget:t selector:s data:d] autorelease]; +} + +-(id) initWithTarget:(id)t selector:(SEL)s data:(void*)d +{ + if( (self=[super initWithTarget:t selector:s]) ) { + data_ = d; + +#if COCOS2D_DEBUG + NSMethodSignature * sig = [t methodSignatureForSelector:s]; // added + NSAssert(sig !=0 , @"Signature not found for selector - does it have the following form? -(void)name:(id)sender data:(void*)data"); +#endif + callbackMethod_ = (CC_CALLBACK_ND) [t methodForSelector:s]; + } + return self; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCActionInstant *copy = [[[self class] allocWithZone: zone] initWithTarget:targetCallback_ selector:selector_ data:data_]; + return copy; +} + +-(void) dealloc +{ + // nothing to dealloc really. Everything is dealloc on super (CCCallFuncN) + [super dealloc]; +} + +-(void) execute +{ + callbackMethod_(targetCallback_,selector_,target_, data_); +} +@end + +@implementation CCCallFuncO +@synthesize object = object_; + ++(id) actionWithTarget: (id) t selector:(SEL) s object:(id)object +{ + return [[[self alloc] initWithTarget:t selector:s object:object] autorelease]; +} + +-(id) initWithTarget:(id) t selector:(SEL) s object:(id)object +{ + if( (self=[super initWithTarget:t selector:s] ) ) + self.object = object; + + return self; +} + +- (void) dealloc +{ + [object_ release]; + [super dealloc]; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCActionInstant *copy = [[[self class] allocWithZone: zone] initWithTarget:targetCallback_ selector:selector_ object:object_]; + return copy; +} + + +-(void) execute +{ + [targetCallback_ performSelector:selector_ withObject:object_]; +} + +@end + + +#pragma mark - +#pragma mark Blocks + +#if NS_BLOCKS_AVAILABLE + +#pragma mark CCCallBlock + +@implementation CCCallBlock + ++(id) actionWithBlock:(void(^)())block +{ + return [[[self alloc] initWithBlock:block] autorelease]; +} + +-(id) initWithBlock:(void(^)())block +{ + if ((self = [super init])) + block_ = [block copy]; + + return self; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCActionInstant *copy = [[[self class] allocWithZone: zone] initWithBlock:block_]; + return copy; +} + +-(void) startWithTarget:(id)aTarget +{ + [super startWithTarget:aTarget]; + [self execute]; +} + +-(void) execute +{ + block_(); +} + +-(void) dealloc +{ + [block_ release]; + [super dealloc]; +} + +@end + +#pragma mark CCCallBlockN + +@implementation CCCallBlockN + ++(id) actionWithBlock:(void(^)(CCNode *node))block +{ + return [[[self alloc] initWithBlock:block] autorelease]; +} + +-(id) initWithBlock:(void(^)(CCNode *node))block +{ + if ((self = [super init])) + block_ = [block copy]; + + return self; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCActionInstant *copy = [[[self class] allocWithZone: zone] initWithBlock:block_]; + return copy; +} + +-(void) startWithTarget:(id)aTarget +{ + [super startWithTarget:aTarget]; + [self execute]; +} + +-(void) execute +{ + block_(target_); +} + +-(void) dealloc +{ + [block_ release]; + [super dealloc]; +} + +@end + + +#endif // NS_BLOCKS_AVAILABLE diff --git a/tweejump/libs/cocos2d/CCActionInterval.h b/tweejump/libs/cocos2d/CCActionInterval.h new file mode 100755 index 0000000..c667963 --- /dev/null +++ b/tweejump/libs/cocos2d/CCActionInterval.h @@ -0,0 +1,421 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-2011 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. + * + */ + + +#import "CCNode.h" +#import "CCAction.h" +#import "CCProtocols.h" + +#include + +/** An interval action is an action that takes place within a certain period of time. +It has an start time, and a finish time. The finish time is the parameter +duration plus the start time. + +These CCActionInterval actions have some interesting properties, like: + - They can run normally (default) + - They can run reversed with the reverse method + - They can run with the time altered with the Accelerate, AccelDeccel and Speed actions. + +For example, you can simulate a Ping Pong effect running the action normally and +then running it again in Reverse mode. + +Example: + + CCAction * pingPongAction = [CCSequence actions: action, [action reverse], nil]; +*/ +@interface CCActionInterval: CCFiniteTimeAction +{ + ccTime elapsed_; + BOOL firstTick_; +} + +/** how many seconds had elapsed since the actions started to run. */ +@property (nonatomic,readonly) ccTime elapsed; + +/** creates the action */ ++(id) actionWithDuration: (ccTime) d; +/** initializes the action */ +-(id) initWithDuration: (ccTime) d; +/** returns YES if the action has finished */ +-(BOOL) isDone; +/** returns a reversed action */ +- (CCActionInterval*) reverse; +@end + +/** Runs actions sequentially, one after another + */ +@interface CCSequence : CCActionInterval +{ + CCFiniteTimeAction *actions_[2]; + ccTime split_; + int last_; +} +/** helper contructor to create an array of sequenceable actions */ ++(id) actions: (CCFiniteTimeAction*) action1, ... NS_REQUIRES_NIL_TERMINATION; +/** helper contructor to create an array of sequenceable actions given an array */ ++(id) actionsWithArray: (NSArray*) actions; +/** creates the action */ ++(id) actionOne:(CCFiniteTimeAction*)actionOne two:(CCFiniteTimeAction*)actionTwo; +/** initializes the action */ +-(id) initOne:(CCFiniteTimeAction*)actionOne two:(CCFiniteTimeAction*)actionTwo; +@end + + +/** Repeats an action a number of times. + * To repeat an action forever use the CCRepeatForever action. + */ +@interface CCRepeat : CCActionInterval +{ + NSUInteger times_; + NSUInteger total_; + CCFiniteTimeAction *innerAction_; +} + +/** Inner action */ +@property (nonatomic,readwrite,retain) CCFiniteTimeAction *innerAction; + +/** creates a CCRepeat action. Times is an unsigned integer between 1 and MAX_UINT */ ++(id) actionWithAction:(CCFiniteTimeAction*)action times: (NSUInteger)times; +/** initializes a CCRepeat action. Times is an unsigned integer between 1 and MAX_UINT */ +-(id) initWithAction:(CCFiniteTimeAction*)action times: (NSUInteger)times; +@end + +/** Spawn a new action immediately + */ +@interface CCSpawn : CCActionInterval +{ + CCFiniteTimeAction *one_; + CCFiniteTimeAction *two_; +} +/** helper constructor to create an array of spawned actions */ ++(id) actions: (CCFiniteTimeAction*) action1, ... NS_REQUIRES_NIL_TERMINATION; +/** helper contructor to create an array of spawned actions given an array */ ++(id) actionsWithArray: (NSArray*) actions; +/** creates the Spawn action */ ++(id) actionOne: (CCFiniteTimeAction*) one two:(CCFiniteTimeAction*) two; +/** initializes the Spawn action with the 2 actions to spawn */ +-(id) initOne: (CCFiniteTimeAction*) one two:(CCFiniteTimeAction*) two; +@end + +/** Rotates a CCNode object to a certain angle by modifying it's + rotation attribute. + The direction will be decided by the shortest angle. +*/ +@interface CCRotateTo : CCActionInterval +{ + float dstAngle_; + float startAngle_; + float diffAngle_; +} +/** creates the action */ ++(id) actionWithDuration:(ccTime)duration angle:(float)angle; +/** initializes the action */ +-(id) initWithDuration:(ccTime)duration angle:(float)angle; +@end + +/** Rotates a CCNode object clockwise a number of degrees by modiying it's rotation attribute. +*/ +@interface CCRotateBy : CCActionInterval +{ + float angle_; + float startAngle_; +} +/** creates the action */ ++(id) actionWithDuration:(ccTime)duration angle:(float)deltaAngle; +/** initializes the action */ +-(id) initWithDuration:(ccTime)duration angle:(float)deltaAngle; +@end + +/** Moves a CCNode object to the position x,y. x and y are absolute coordinates by modifying it's position attribute. +*/ +@interface CCMoveTo : CCActionInterval +{ + CGPoint endPosition_; + CGPoint startPosition_; + CGPoint delta_; +} +/** creates the action */ ++(id) actionWithDuration:(ccTime)duration position:(CGPoint)position; +/** initializes the action */ +-(id) initWithDuration:(ccTime)duration position:(CGPoint)position; +@end + +/** Moves a CCNode object x,y pixels by modifying it's position attribute. + x and y are relative to the position of the object. + Duration is is seconds. +*/ +@interface CCMoveBy : CCMoveTo +{ +} +/** creates the action */ ++(id) actionWithDuration: (ccTime)duration position:(CGPoint)deltaPosition; +/** initializes the action */ +-(id) initWithDuration: (ccTime)duration position:(CGPoint)deltaPosition; +@end + +/** Skews a CCNode object to given angles by modifying it's skewX and skewY attributes + @since v1.0 + */ +@interface CCSkewTo : CCActionInterval +{ + float skewX_; + float skewY_; + float startSkewX_; + float startSkewY_; + float endSkewX_; + float endSkewY_; + float deltaX_; + float deltaY_; +} +/** creates the action */ ++(id) actionWithDuration:(ccTime)t skewX:(float)sx skewY:(float)sy; +/** initializes the action */ +-(id) initWithDuration:(ccTime)t skewX:(float)sx skewY:(float)sy; +@end + +/** Skews a CCNode object by skewX and skewY degrees + @since v1.0 + */ +@interface CCSkewBy : CCSkewTo +{ +} +@end + +/** Moves a CCNode object simulating a parabolic jump movement by modifying it's position attribute. +*/ + @interface CCJumpBy : CCActionInterval +{ + CGPoint startPosition_; + CGPoint delta_; + ccTime height_; + NSUInteger jumps_; +} +/** creates the action */ ++(id) actionWithDuration: (ccTime)duration position:(CGPoint)position height:(ccTime)height jumps:(NSUInteger)jumps; +/** initializes the action */ +-(id) initWithDuration: (ccTime)duration position:(CGPoint)position height:(ccTime)height jumps:(NSUInteger)jumps; +@end + +/** Moves a CCNode object to a parabolic position simulating a jump movement by modifying it's position attribute. +*/ + @interface CCJumpTo : CCJumpBy +{ +} +@end + +/** bezier configuration structure + */ +typedef struct _ccBezierConfig { + //! end position of the bezier + CGPoint endPosition; + //! Bezier control point 1 + CGPoint controlPoint_1; + //! Bezier control point 2 + CGPoint controlPoint_2; +} ccBezierConfig; + +/** An action that moves the target with a cubic Bezier curve by a certain distance. + */ +@interface CCBezierBy : CCActionInterval +{ + ccBezierConfig config_; + CGPoint startPosition_; +} + +/** creates the action with a duration and a bezier configuration */ ++(id) actionWithDuration: (ccTime) t bezier:(ccBezierConfig) c; + +/** initializes the action with a duration and a bezier configuration */ +-(id) initWithDuration: (ccTime) t bezier:(ccBezierConfig) c; +@end + +/** An action that moves the target with a cubic Bezier curve to a destination point. + @since v0.8.2 + */ +@interface CCBezierTo : CCBezierBy +{ +} +@end + +/** Scales a CCNode object to a zoom factor by modifying it's scale attribute. + @warning This action doesn't support "reverse" + */ +@interface CCScaleTo : CCActionInterval +{ + float scaleX_; + float scaleY_; + float startScaleX_; + float startScaleY_; + float endScaleX_; + float endScaleY_; + float deltaX_; + float deltaY_; +} +/** creates the action with the same scale factor for X and Y */ ++(id) actionWithDuration: (ccTime)duration scale:(float) s; +/** initializes the action with the same scale factor for X and Y */ +-(id) initWithDuration: (ccTime)duration scale:(float) s; +/** creates the action with and X factor and a Y factor */ ++(id) actionWithDuration: (ccTime)duration scaleX:(float) sx scaleY:(float)sy; +/** initializes the action with and X factor and a Y factor */ +-(id) initWithDuration: (ccTime)duration scaleX:(float) sx scaleY:(float)sy; +@end + +/** Scales a CCNode object a zoom factor by modifying it's scale attribute. +*/ +@interface CCScaleBy : CCScaleTo +{ +} +@end + +/** Blinks a CCNode object by modifying it's visible attribute +*/ +@interface CCBlink : CCActionInterval +{ + NSUInteger times_; +} +/** creates the action */ ++(id) actionWithDuration: (ccTime)duration blinks:(NSUInteger)blinks; +/** initilizes the action */ +-(id) initWithDuration: (ccTime)duration blinks:(NSUInteger)blinks; +@end + +/** Fades In an object that implements the CCRGBAProtocol protocol. It modifies the opacity from 0 to 255. + The "reverse" of this action is FadeOut + */ +@interface CCFadeIn : CCActionInterval +{ +} +@end + +/** Fades Out an object that implements the CCRGBAProtocol protocol. It modifies the opacity from 255 to 0. + The "reverse" of this action is FadeIn +*/ +@interface CCFadeOut : CCActionInterval +{ +} +@end + +/** Fades an object that implements the CCRGBAProtocol protocol. It modifies the opacity from the current value to a custom one. + @warning This action doesn't support "reverse" + */ +@interface CCFadeTo : CCActionInterval +{ + GLubyte toOpacity_; + GLubyte fromOpacity_; +} +/** creates an action with duration and opactiy */ ++(id) actionWithDuration:(ccTime)duration opacity:(GLubyte)opactiy; +/** initializes the action with duration and opacity */ +-(id) initWithDuration:(ccTime)duration opacity:(GLubyte)opacity; +@end + +/** Tints a CCNode that implements the CCNodeRGB protocol from current tint to a custom one. + @warning This action doesn't support "reverse" + @since v0.7.2 +*/ +@interface CCTintTo : CCActionInterval +{ + ccColor3B to_; + ccColor3B from_; +} +/** creates an action with duration and color */ ++(id) actionWithDuration:(ccTime)duration red:(GLubyte)red green:(GLubyte)green blue:(GLubyte)blue; +/** initializes the action with duration and color */ +-(id) initWithDuration:(ccTime)duration red:(GLubyte)red green:(GLubyte)green blue:(GLubyte)blue; +@end + +/** Tints a CCNode that implements the CCNodeRGB protocol from current tint to a custom one. + @since v0.7.2 + */ +@interface CCTintBy : CCActionInterval +{ + GLshort deltaR_, deltaG_, deltaB_; + GLshort fromR_, fromG_, fromB_; +} +/** creates an action with duration and color */ ++(id) actionWithDuration:(ccTime)duration red:(GLshort)deltaRed green:(GLshort)deltaGreen blue:(GLshort)deltaBlue; +/** initializes the action with duration and color */ +-(id) initWithDuration:(ccTime)duration red:(GLshort)deltaRed green:(GLshort)deltaGreen blue:(GLshort)deltaBlue; +@end + +/** Delays the action a certain amount of seconds +*/ +@interface CCDelayTime : CCActionInterval +{ +} +@end + +/** Executes an action in reverse order, from time=duration to time=0 + + @warning Use this action carefully. This action is not + sequenceable. Use it as the default "reversed" method + of your own actions, but using it outside the "reversed" + scope is not recommended. +*/ +@interface CCReverseTime : CCActionInterval +{ + CCFiniteTimeAction * other_; +} +/** creates the action */ ++(id) actionWithAction: (CCFiniteTimeAction*) action; +/** initializes the action */ +-(id) initWithAction: (CCFiniteTimeAction*) action; +@end + + +@class CCAnimation; +@class CCTexture2D; +/** Animates a sprite given the name of an Animation */ +@interface CCAnimate : CCActionInterval +{ + CCAnimation *animation_; + id origFrame_; + BOOL restoreOriginalFrame_; +} +/** animation used for the animage */ +@property (readwrite,nonatomic,retain) CCAnimation * animation; + +/** creates the action with an Animation and will restore the original frame when the animation is over */ ++(id) actionWithAnimation:(CCAnimation*) a; +/** initializes the action with an Animation and will restore the original frame when the animtion is over */ +-(id) initWithAnimation:(CCAnimation*) a; +/** creates the action with an Animation */ ++(id) actionWithAnimation:(CCAnimation*) a restoreOriginalFrame:(BOOL)b; +/** initializes the action with an Animation */ +-(id) initWithAnimation:(CCAnimation*) a restoreOriginalFrame:(BOOL)b; +/** creates an action with a duration, animation and depending of the restoreOriginalFrame, it will restore the original frame or not. + The 'delay' parameter of the animation will be overrided by the duration parameter. + @since v0.99.0 + */ ++(id) actionWithDuration:(ccTime)duration animation:(CCAnimation*)animation restoreOriginalFrame:(BOOL)b; +/** initializes an action with a duration, animation and depending of the restoreOriginalFrame, it will restore the original frame or not. + The 'delay' parameter of the animation will be overrided by the duration parameter. + @since v0.99.0 + */ +-(id) initWithDuration:(ccTime)duration animation:(CCAnimation*)animation restoreOriginalFrame:(BOOL)b; +@end diff --git a/tweejump/libs/cocos2d/CCActionInterval.m b/tweejump/libs/cocos2d/CCActionInterval.m new file mode 100755 index 0000000..17bef40 --- /dev/null +++ b/tweejump/libs/cocos2d/CCActionInterval.m @@ -0,0 +1,1355 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-2011 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. + * + */ + + + +#import "CCActionInterval.h" +#import "CCSprite.h" +#import "CCSpriteFrame.h" +#import "CCAnimation.h" +#import "CCNode.h" +#import "Support/CGPointExtension.h" + +// +// IntervalAction +// +#pragma mark - +#pragma mark IntervalAction +@implementation CCActionInterval + +@synthesize elapsed = elapsed_; + +-(id) init +{ + NSAssert(NO, @"IntervalActionInit: Init not supported. Use InitWithDuration"); + [self release]; + return nil; +} + ++(id) actionWithDuration: (ccTime) d +{ + return [[[self alloc] initWithDuration:d ] autorelease]; +} + +-(id) initWithDuration: (ccTime) d +{ + if( (self=[super init]) ) { + duration_ = d; + + // prevent division by 0 + // This comparison could be in step:, but it might decrease the performance + // by 3% in heavy based action games. + if( duration_ == 0 ) + duration_ = FLT_EPSILON; + elapsed_ = 0; + firstTick_ = YES; + } + return self; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCAction *copy = [[[self class] allocWithZone: zone] initWithDuration: [self duration] ]; + return copy; +} + +- (BOOL) isDone +{ + return (elapsed_ >= duration_); +} + +-(void) step: (ccTime) dt +{ + if( firstTick_ ) { + firstTick_ = NO; + elapsed_ = 0; + } else + elapsed_ += dt; + + [self update: MIN(1, elapsed_/duration_)]; +} + +-(void) startWithTarget:(id)aTarget +{ + [super startWithTarget:aTarget]; + elapsed_ = 0.0f; + firstTick_ = YES; +} + +- (CCActionInterval*) reverse +{ + NSAssert(NO, @"CCIntervalAction: reverse not implemented."); + return nil; +} +@end + +// +// Sequence +// +#pragma mark - +#pragma mark Sequence +@implementation CCSequence ++(id) actions: (CCFiniteTimeAction*) action1, ... +{ + va_list params; + va_start(params,action1); + + CCFiniteTimeAction *now; + CCFiniteTimeAction *prev = action1; + + while( action1 ) { + now = va_arg(params,CCFiniteTimeAction*); + if ( now ) + prev = [self actionOne: prev two: now]; + else + break; + } + va_end(params); + return prev; +} + ++(id) actionsWithArray: (NSArray*) actions +{ + CCFiniteTimeAction *prev = [actions objectAtIndex:0]; + + for (NSUInteger i = 1; i < [actions count]; i++) + prev = [self actionOne:prev two:[actions objectAtIndex:i]]; + + return prev; +} + ++(id) actionOne: (CCFiniteTimeAction*) one two: (CCFiniteTimeAction*) two +{ + return [[[self alloc] initOne:one two:two ] autorelease]; +} + +-(id) initOne: (CCFiniteTimeAction*) one two: (CCFiniteTimeAction*) two +{ + NSAssert( one!=nil && two!=nil, @"Sequence: arguments must be non-nil"); + NSAssert( one!=actions_[0] && one!=actions_[1], @"Sequence: re-init using the same parameters is not supported"); + NSAssert( two!=actions_[1] && two!=actions_[0], @"Sequence: re-init using the same parameters is not supported"); + + ccTime d = [one duration] + [two duration]; + + if( (self=[super initWithDuration: d]) ) { + + // XXX: Supports re-init without leaking. Fails if one==one_ || two==two_ + [actions_[0] release]; + [actions_[1] release]; + + actions_[0] = [one retain]; + actions_[1] = [two retain]; + } + + return self; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCAction *copy = [[[self class] allocWithZone:zone] initOne:[[actions_[0] copy] autorelease] two:[[actions_[1] copy] autorelease] ]; + return copy; +} + +-(void) dealloc +{ + [actions_[0] release]; + [actions_[1] release]; + [super dealloc]; +} + +-(void) startWithTarget:(id)aTarget +{ + [super startWithTarget:aTarget]; + split_ = [actions_[0] duration] / duration_; + last_ = -1; +} + +-(void) stop +{ + [actions_[0] stop]; + [actions_[1] stop]; + [super stop]; +} + +-(void) update: (ccTime) t +{ + int found = 0; + ccTime new_t = 0.0f; + + if( t >= split_ ) { + found = 1; + if ( split_ == 1 ) + new_t = 1; + else + new_t = (t-split_) / (1 - split_ ); + } else { + found = 0; + if( split_ != 0 ) + new_t = t / split_; + else + new_t = 1; + } + + if (last_ == -1 && found==1) { + [actions_[0] startWithTarget:target_]; + [actions_[0] update:1.0f]; + [actions_[0] stop]; + } + + if (last_ != found ) { + if( last_ != -1 ) { + [actions_[last_] update: 1.0f]; + [actions_[last_] stop]; + } + [actions_[found] startWithTarget:target_]; + } + [actions_[found] update: new_t]; + last_ = found; +} + +- (CCActionInterval *) reverse +{ + return [[self class] actionOne: [actions_[1] reverse] two: [actions_[0] reverse ] ]; +} +@end + +// +// Repeat +// +#pragma mark - +#pragma mark CCRepeat +@implementation CCRepeat +@synthesize innerAction=innerAction_; + ++(id) actionWithAction:(CCFiniteTimeAction*)action times:(NSUInteger)times +{ + return [[[self alloc] initWithAction:action times:times] autorelease]; +} + +-(id) initWithAction:(CCFiniteTimeAction*)action times:(NSUInteger)times +{ + ccTime d = [action duration] * times; + + if( (self=[super initWithDuration: d ]) ) { + times_ = times; + self.innerAction = action; + + total_ = 0; + } + return self; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCAction *copy = [[[self class] allocWithZone:zone] initWithAction:[[innerAction_ copy] autorelease] times:times_]; + return copy; +} + +-(void) dealloc +{ + [innerAction_ release]; + [super dealloc]; +} + +-(void) startWithTarget:(id)aTarget +{ + total_ = 0; + [super startWithTarget:aTarget]; + [innerAction_ startWithTarget:aTarget]; +} + +-(void) stop +{ + [innerAction_ stop]; + [super stop]; +} + + +// issue #80. Instead of hooking step:, hook update: since it can be called by any +// container action like Repeat, Sequence, AccelDeccel, etc.. +-(void) update:(ccTime) dt +{ + ccTime t = dt * times_; + if( t > total_+1 ) { + [innerAction_ update:1.0f]; + total_++; + [innerAction_ stop]; + [innerAction_ startWithTarget:target_]; + + // repeat is over ? + if( total_== times_ ) + // so, set it in the original position + [innerAction_ update:0]; + else { + // no ? start next repeat with the right update + // to prevent jerk (issue #390) + [innerAction_ update: t-total_]; + } + + } else { + + float r = fmodf(t, 1.0f); + + // fix last repeat position + // else it could be 0. + if( dt== 1.0f) { + r = 1.0f; + total_++; // this is the added line + } + [innerAction_ update: MIN(r,1)]; + } +} + +-(BOOL) isDone +{ + return ( total_ == times_ ); +} + +- (CCActionInterval *) reverse +{ + return [[self class] actionWithAction:[innerAction_ reverse] times:times_]; +} +@end + +// +// Spawn +// +#pragma mark - +#pragma mark Spawn + +@implementation CCSpawn ++(id) actions: (CCFiniteTimeAction*) action1, ... +{ + va_list params; + va_start(params,action1); + + CCFiniteTimeAction *now; + CCFiniteTimeAction *prev = action1; + + while( action1 ) { + now = va_arg(params,CCFiniteTimeAction*); + if ( now ) + prev = [self actionOne: prev two: now]; + else + break; + } + va_end(params); + return prev; +} + ++(id) actionsWithArray: (NSArray*) actions +{ + CCFiniteTimeAction *prev = [actions objectAtIndex:0]; + + for (NSUInteger i = 1; i < [actions count]; i++) + prev = [self actionOne:prev two:[actions objectAtIndex:i]]; + + return prev; +} + ++(id) actionOne: (CCFiniteTimeAction*) one two: (CCFiniteTimeAction*) two +{ + return [[[self alloc] initOne:one two:two ] autorelease]; +} + +-(id) initOne: (CCFiniteTimeAction*) one two: (CCFiniteTimeAction*) two +{ + NSAssert( one!=nil && two!=nil, @"Spawn: arguments must be non-nil"); + NSAssert( one!=one_ && one!=two_, @"Spawn: reinit using same parameters is not supported"); + NSAssert( two!=two_ && two!=one_, @"Spawn: reinit using same parameters is not supported"); + + ccTime d1 = [one duration]; + ccTime d2 = [two duration]; + + if( (self=[super initWithDuration: MAX(d1,d2)] ) ) { + + // XXX: Supports re-init without leaking. Fails if one==one_ || two==two_ + [one_ release]; + [two_ release]; + + one_ = one; + two_ = two; + + if( d1 > d2 ) + two_ = [CCSequence actionOne:two two:[CCDelayTime actionWithDuration: (d1-d2)] ]; + else if( d1 < d2) + one_ = [CCSequence actionOne:one two: [CCDelayTime actionWithDuration: (d2-d1)] ]; + + [one_ retain]; + [two_ retain]; + } + return self; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCAction *copy = [[[self class] allocWithZone: zone] initOne: [[one_ copy] autorelease] two: [[two_ copy] autorelease] ]; + return copy; +} + +-(void) dealloc +{ + [one_ release]; + [two_ release]; + [super dealloc]; +} + +-(void) startWithTarget:(id)aTarget +{ + [super startWithTarget:aTarget]; + [one_ startWithTarget:target_]; + [two_ startWithTarget:target_]; +} + +-(void) stop +{ + [one_ stop]; + [two_ stop]; + [super stop]; +} + +-(void) update: (ccTime) t +{ + [one_ update:t]; + [two_ update:t]; +} + +- (CCActionInterval *) reverse +{ + return [[self class] actionOne: [one_ reverse] two: [two_ reverse ] ]; +} +@end + +// +// RotateTo +// +#pragma mark - +#pragma mark RotateTo + +@implementation CCRotateTo ++(id) actionWithDuration: (ccTime) t angle:(float) a +{ + return [[[self alloc] initWithDuration:t angle:a ] autorelease]; +} + +-(id) initWithDuration: (ccTime) t angle:(float) a +{ + if( (self=[super initWithDuration: t]) ) + dstAngle_ = a; + + return self; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCAction *copy = [[[self class] allocWithZone: zone] initWithDuration:[self duration] angle:dstAngle_]; + return copy; +} + +-(void) startWithTarget:(CCNode *)aTarget +{ + [super startWithTarget:aTarget]; + + startAngle_ = [target_ rotation]; + if (startAngle_ > 0) + startAngle_ = fmodf(startAngle_, 360.0f); + else + startAngle_ = fmodf(startAngle_, -360.0f); + + diffAngle_ =dstAngle_ - startAngle_; + if (diffAngle_ > 180) + diffAngle_ -= 360; + if (diffAngle_ < -180) + diffAngle_ += 360; +} +-(void) update: (ccTime) t +{ + [target_ setRotation: startAngle_ + diffAngle_ * t]; +} +@end + + +// +// RotateBy +// +#pragma mark - +#pragma mark RotateBy + +@implementation CCRotateBy ++(id) actionWithDuration: (ccTime) t angle:(float) a +{ + return [[[self alloc] initWithDuration:t angle:a ] autorelease]; +} + +-(id) initWithDuration: (ccTime) t angle:(float) a +{ + if( (self=[super initWithDuration: t]) ) + angle_ = a; + + return self; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCAction *copy = [[[self class] allocWithZone: zone] initWithDuration: [self duration] angle: angle_]; + return copy; +} + +-(void) startWithTarget:(id)aTarget +{ + [super startWithTarget:aTarget]; + startAngle_ = [target_ rotation]; +} + +-(void) update: (ccTime) t +{ + // XXX: shall I add % 360 + [target_ setRotation: (startAngle_ +angle_ * t )]; +} + +-(CCActionInterval*) reverse +{ + return [[self class] actionWithDuration:duration_ angle:-angle_]; +} + +@end + +// +// MoveTo +// +#pragma mark - +#pragma mark MoveTo + +@implementation CCMoveTo ++(id) actionWithDuration: (ccTime) t position: (CGPoint) p +{ + return [[[self alloc] initWithDuration:t position:p ] autorelease]; +} + +-(id) initWithDuration: (ccTime) t position: (CGPoint) p +{ + if( (self=[super initWithDuration: t]) ) + endPosition_ = p; + + return self; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCAction *copy = [[[self class] allocWithZone: zone] initWithDuration: [self duration] position: endPosition_]; + return copy; +} + +-(void) startWithTarget:(CCNode *)aTarget +{ + [super startWithTarget:aTarget]; + startPosition_ = [(CCNode*)target_ position]; + delta_ = ccpSub( endPosition_, startPosition_ ); +} + +-(void) update: (ccTime) t +{ + [target_ setPosition: ccp( (startPosition_.x + delta_.x * t ), (startPosition_.y + delta_.y * t ) )]; +} +@end + +// +// MoveBy +// +#pragma mark - +#pragma mark MoveBy + +@implementation CCMoveBy ++(id) actionWithDuration: (ccTime) t position: (CGPoint) p +{ + return [[[self alloc] initWithDuration:t position:p ] autorelease]; +} + +-(id) initWithDuration: (ccTime) t position: (CGPoint) p +{ + if( (self=[super initWithDuration: t]) ) + delta_ = p; + + return self; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCAction *copy = [[[self class] allocWithZone: zone] initWithDuration: [self duration] position: delta_]; + return copy; +} + +-(void) startWithTarget:(CCNode *)aTarget +{ + CGPoint dTmp = delta_; + [super startWithTarget:aTarget]; + delta_ = dTmp; +} + +-(CCActionInterval*) reverse +{ + return [[self class] actionWithDuration:duration_ position:ccp( -delta_.x, -delta_.y)]; +} +@end + + +// +// SkewTo +// +#pragma mark - +#pragma mark SkewTo + +@implementation CCSkewTo ++(id) actionWithDuration:(ccTime)t skewX:(float)sx skewY:(float)sy +{ + return [[[self alloc] initWithDuration: t skewX:sx skewY:sy] autorelease]; +} + +-(id) initWithDuration:(ccTime)t skewX:(float)sx skewY:(float)sy +{ + if( (self=[super initWithDuration:t]) ) { + endSkewX_ = sx; + endSkewY_ = sy; + } + return self; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCAction *copy = [[[self class] allocWithZone: zone] initWithDuration:[self duration] skewX:endSkewX_ skewY:endSkewY_]; + return copy; +} + +-(void) startWithTarget:(CCNode *)aTarget +{ + [super startWithTarget:aTarget]; + + startSkewX_ = [target_ skewX]; + + if (startSkewX_ > 0) + startSkewX_ = fmodf(startSkewX_, 180.0f); + else + startSkewX_ = fmodf(startSkewX_, -180.0f); + + deltaX_ = endSkewX_ - startSkewX_; + + if ( deltaX_ > 180 ) { + deltaX_ -= 360; + } + if ( deltaX_ < -180 ) { + deltaX_ += 360; + } + + startSkewY_ = [target_ skewY]; + + if (startSkewY_ > 0) + startSkewY_ = fmodf(startSkewY_, 360.0f); + else + startSkewY_ = fmodf(startSkewY_, -360.0f); + + deltaY_ = endSkewY_ - startSkewY_; + + if ( deltaY_ > 180 ) { + deltaY_ -= 360; + } + if ( deltaY_ < -180 ) { + deltaY_ += 360; + } +} + +-(void) update: (ccTime) t +{ + [target_ setSkewX: (startSkewX_ + deltaX_ * t ) ]; + [target_ setSkewY: (startSkewY_ + deltaY_ * t ) ]; +} + +@end + +// +// CCSkewBy +// +@implementation CCSkewBy + +-(id) initWithDuration:(ccTime)t skewX:(float)deltaSkewX skewY:(float)deltaSkewY +{ + if( (self=[super initWithDuration:t skewX:deltaSkewX skewY:deltaSkewY]) ) { + skewX_ = deltaSkewX; + skewY_ = deltaSkewY; + } + return self; +} + +-(void) startWithTarget:(CCNode *)aTarget +{ + [super startWithTarget:aTarget]; + deltaX_ = skewX_; + deltaY_ = skewY_; + endSkewX_ = startSkewX_ + deltaX_; + endSkewY_ = startSkewY_ + deltaY_; +} + +-(CCActionInterval*) reverse +{ + return [[self class] actionWithDuration:duration_ skewX:-skewX_ skewY:-skewY_]; +} +@end + + +// +// JumpBy +// +#pragma mark - +#pragma mark JumpBy + +@implementation CCJumpBy ++(id) actionWithDuration: (ccTime) t position: (CGPoint) pos height: (ccTime) h jumps:(NSUInteger)j +{ + return [[[self alloc] initWithDuration: t position: pos height: h jumps:j] autorelease]; +} + +-(id) initWithDuration: (ccTime) t position: (CGPoint) pos height: (ccTime) h jumps:(NSUInteger)j +{ + if( (self=[super initWithDuration:t]) ) { + delta_ = pos; + height_ = h; + jumps_ = j; + } + return self; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCAction *copy = [[[self class] allocWithZone: zone] initWithDuration:[self duration] position:delta_ height:height_ jumps:jumps_]; + return copy; +} + +-(void) startWithTarget:(id)aTarget +{ + [super startWithTarget:aTarget]; + startPosition_ = [(CCNode*)target_ position]; +} + +-(void) update: (ccTime) t +{ + // Sin jump. Less realistic +// ccTime y = height * fabsf( sinf(t * (CGFloat)M_PI * jumps ) ); +// y += delta.y * t; +// ccTime x = delta.x * t; +// [target setPosition: ccp( startPosition.x + x, startPosition.y + y )]; + + // parabolic jump (since v0.8.2) + ccTime frac = fmodf( t * jumps_, 1.0f ); + ccTime y = height_ * 4 * frac * (1 - frac); + y += delta_.y * t; + ccTime x = delta_.x * t; + [target_ setPosition: ccp( startPosition_.x + x, startPosition_.y + y )]; + +} + +-(CCActionInterval*) reverse +{ + return [[self class] actionWithDuration:duration_ position: ccp(-delta_.x,-delta_.y) height:height_ jumps:jumps_]; +} +@end + +// +// JumpTo +// +#pragma mark - +#pragma mark JumpTo + +@implementation CCJumpTo +-(void) startWithTarget:(CCNode *)aTarget +{ + [super startWithTarget:aTarget]; + delta_ = ccp( delta_.x - startPosition_.x, delta_.y - startPosition_.y ); +} +@end + + +#pragma mark - +#pragma mark BezierBy + +// Bezier cubic formula: +// ((1 - t) + t)3 = 1 +// Expands to… +// (1 - t)3 + 3t(1-t)2 + 3t2(1 - t) + t3 = 1 +static inline float bezierat( float a, float b, float c, float d, ccTime t ) +{ + return (powf(1-t,3) * a + + 3*t*(powf(1-t,2))*b + + 3*powf(t,2)*(1-t)*c + + powf(t,3)*d ); +} + +// +// BezierBy +// +@implementation CCBezierBy ++(id) actionWithDuration: (ccTime) t bezier:(ccBezierConfig) c +{ + return [[[self alloc] initWithDuration:t bezier:c ] autorelease]; +} + +-(id) initWithDuration: (ccTime) t bezier:(ccBezierConfig) c +{ + if( (self=[super initWithDuration: t]) ) { + config_ = c; + } + return self; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCAction *copy = [[[self class] allocWithZone: zone] initWithDuration:[self duration] bezier:config_]; + return copy; +} + +-(void) startWithTarget:(id)aTarget +{ + [super startWithTarget:aTarget]; + startPosition_ = [(CCNode*)target_ position]; +} + +-(void) update: (ccTime) t +{ + float xa = 0; + float xb = config_.controlPoint_1.x; + float xc = config_.controlPoint_2.x; + float xd = config_.endPosition.x; + + float ya = 0; + float yb = config_.controlPoint_1.y; + float yc = config_.controlPoint_2.y; + float yd = config_.endPosition.y; + + float x = bezierat(xa, xb, xc, xd, t); + float y = bezierat(ya, yb, yc, yd, t); + [target_ setPosition: ccpAdd( startPosition_, ccp(x,y))]; +} + +- (CCActionInterval*) reverse +{ + ccBezierConfig r; + + r.endPosition = ccpNeg(config_.endPosition); + r.controlPoint_1 = ccpAdd(config_.controlPoint_2, ccpNeg(config_.endPosition)); + r.controlPoint_2 = ccpAdd(config_.controlPoint_1, ccpNeg(config_.endPosition)); + + CCBezierBy *action = [[self class] actionWithDuration:[self duration] bezier:r]; + return action; +} +@end + +// +// BezierTo +// +#pragma mark - +#pragma mark BezierTo +@implementation CCBezierTo +-(void) startWithTarget:(id)aTarget +{ + [super startWithTarget:aTarget]; + config_.controlPoint_1 = ccpSub(config_.controlPoint_1, startPosition_); + config_.controlPoint_2 = ccpSub(config_.controlPoint_2, startPosition_); + config_.endPosition = ccpSub(config_.endPosition, startPosition_); +} +@end + + +// +// ScaleTo +// +#pragma mark - +#pragma mark ScaleTo +@implementation CCScaleTo ++(id) actionWithDuration: (ccTime) t scale:(float) s +{ + return [[[self alloc] initWithDuration: t scale:s] autorelease]; +} + +-(id) initWithDuration: (ccTime) t scale:(float) s +{ + if( (self=[super initWithDuration: t]) ) { + endScaleX_ = s; + endScaleY_ = s; + } + return self; +} + ++(id) actionWithDuration: (ccTime) t scaleX:(float)sx scaleY:(float)sy +{ + return [[[self alloc] initWithDuration: t scaleX:sx scaleY:sy] autorelease]; +} + +-(id) initWithDuration: (ccTime) t scaleX:(float)sx scaleY:(float)sy +{ + if( (self=[super initWithDuration: t]) ) { + endScaleX_ = sx; + endScaleY_ = sy; + } + return self; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCAction *copy = [[[self class] allocWithZone: zone] initWithDuration:[self duration] scaleX:endScaleX_ scaleY:endScaleY_]; + return copy; +} + +-(void) startWithTarget:(CCNode *)aTarget +{ + [super startWithTarget:aTarget]; + startScaleX_ = [target_ scaleX]; + startScaleY_ = [target_ scaleY]; + deltaX_ = endScaleX_ - startScaleX_; + deltaY_ = endScaleY_ - startScaleY_; +} + +-(void) update: (ccTime) t +{ + [target_ setScaleX: (startScaleX_ + deltaX_ * t ) ]; + [target_ setScaleY: (startScaleY_ + deltaY_ * t ) ]; +} +@end + +// +// ScaleBy +// +#pragma mark - +#pragma mark ScaleBy +@implementation CCScaleBy +-(void) startWithTarget:(CCNode *)aTarget +{ + [super startWithTarget:aTarget]; + deltaX_ = startScaleX_ * endScaleX_ - startScaleX_; + deltaY_ = startScaleY_ * endScaleY_ - startScaleY_; +} + +-(CCActionInterval*) reverse +{ + return [[self class] actionWithDuration:duration_ scaleX:1/endScaleX_ scaleY:1/endScaleY_]; +} +@end + +// +// Blink +// +#pragma mark - +#pragma mark Blink +@implementation CCBlink ++(id) actionWithDuration: (ccTime) t blinks: (NSUInteger) b +{ + return [[[ self alloc] initWithDuration: t blinks: b] autorelease]; +} + +-(id) initWithDuration: (ccTime) t blinks: (NSUInteger) b +{ + if( (self=[super initWithDuration: t] ) ) + times_ = b; + + return self; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCAction *copy = [[[self class] allocWithZone: zone] initWithDuration: [self duration] blinks: times_]; + return copy; +} + +-(void) update: (ccTime) t +{ + if( ! [self isDone] ) { + ccTime slice = 1.0f / times_; + ccTime m = fmodf(t, slice); + [target_ setVisible: (m > slice/2) ? YES : NO]; + } +} + +-(CCActionInterval*) reverse +{ + // return 'self' + return [[self class] actionWithDuration:duration_ blinks: times_]; +} +@end + +// +// FadeIn +// +#pragma mark - +#pragma mark FadeIn +@implementation CCFadeIn +-(void) update: (ccTime) t +{ + [(id) target_ setOpacity: 255 *t]; +} + +-(CCActionInterval*) reverse +{ + return [CCFadeOut actionWithDuration:duration_]; +} +@end + +// +// FadeOut +// +#pragma mark - +#pragma mark FadeOut +@implementation CCFadeOut +-(void) update: (ccTime) t +{ + [(id) target_ setOpacity: 255 *(1-t)]; +} + +-(CCActionInterval*) reverse +{ + return [CCFadeIn actionWithDuration:duration_]; +} +@end + +// +// FadeTo +// +#pragma mark - +#pragma mark FadeTo +@implementation CCFadeTo ++(id) actionWithDuration: (ccTime) t opacity: (GLubyte) o +{ + return [[[ self alloc] initWithDuration: t opacity: o] autorelease]; +} + +-(id) initWithDuration: (ccTime) t opacity: (GLubyte) o +{ + if( (self=[super initWithDuration: t] ) ) + toOpacity_ = o; + + return self; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCAction *copy = [[[self class] allocWithZone: zone] initWithDuration:[self duration] opacity:toOpacity_]; + return copy; +} + +-(void) startWithTarget:(CCNode *)aTarget +{ + [super startWithTarget:aTarget]; + fromOpacity_ = [(id)target_ opacity]; +} + +-(void) update: (ccTime) t +{ + [(id)target_ setOpacity:fromOpacity_ + ( toOpacity_ - fromOpacity_ ) * t]; +} +@end + +// +// TintTo +// +#pragma mark - +#pragma mark TintTo +@implementation CCTintTo ++(id) actionWithDuration:(ccTime)t red:(GLubyte)r green:(GLubyte)g blue:(GLubyte)b +{ + return [[(CCTintTo*)[ self alloc] initWithDuration:t red:r green:g blue:b] autorelease]; +} + +-(id) initWithDuration: (ccTime) t red:(GLubyte)r green:(GLubyte)g blue:(GLubyte)b +{ + if( (self=[super initWithDuration:t] ) ) + to_ = ccc3(r,g,b); + + return self; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCAction *copy = [(CCTintTo*)[[self class] allocWithZone: zone] initWithDuration:[self duration] red:to_.r green:to_.g blue:to_.b]; + return copy; +} + +-(void) startWithTarget:(id)aTarget +{ + [super startWithTarget:aTarget]; + + id tn = (id) target_; + from_ = [tn color]; +} + +-(void) update: (ccTime) t +{ + id tn = (id) target_; + [tn setColor:ccc3(from_.r + (to_.r - from_.r) * t, from_.g + (to_.g - from_.g) * t, from_.b + (to_.b - from_.b) * t)]; +} +@end + +// +// TintBy +// +#pragma mark - +#pragma mark TintBy +@implementation CCTintBy ++(id) actionWithDuration:(ccTime)t red:(GLshort)r green:(GLshort)g blue:(GLshort)b +{ + return [[(CCTintBy*)[ self alloc] initWithDuration:t red:r green:g blue:b] autorelease]; +} + +-(id) initWithDuration:(ccTime)t red:(GLshort)r green:(GLshort)g blue:(GLshort)b +{ + if( (self=[super initWithDuration: t] ) ) { + deltaR_ = r; + deltaG_ = g; + deltaB_ = b; + } + return self; +} + +-(id) copyWithZone: (NSZone*) zone +{ + return[(CCTintBy*)[[self class] allocWithZone: zone] initWithDuration: [self duration] red:deltaR_ green:deltaG_ blue:deltaB_]; +} + +-(void) startWithTarget:(id)aTarget +{ + [super startWithTarget:aTarget]; + + id tn = (id) target_; + ccColor3B color = [tn color]; + fromR_ = color.r; + fromG_ = color.g; + fromB_ = color.b; +} + +-(void) update: (ccTime) t +{ + id tn = (id) target_; + [tn setColor:ccc3( fromR_ + deltaR_ * t, fromG_ + deltaG_ * t, fromB_ + deltaB_ * t)]; +} + +- (CCActionInterval*) reverse +{ + return [CCTintBy actionWithDuration:duration_ red:-deltaR_ green:-deltaG_ blue:-deltaB_]; +} +@end + +// +// DelayTime +// +#pragma mark - +#pragma mark DelayTime +@implementation CCDelayTime +-(void) update: (ccTime) t +{ + return; +} + +-(id)reverse +{ + return [[self class] actionWithDuration:duration_]; +} +@end + +// +// ReverseTime +// +#pragma mark - +#pragma mark ReverseTime +@implementation CCReverseTime ++(id) actionWithAction: (CCFiniteTimeAction*) action +{ + // casting to prevent warnings + CCReverseTime *a = [super alloc]; + return [[a initWithAction:action] autorelease]; +} + +-(id) initWithAction: (CCFiniteTimeAction*) action +{ + NSAssert(action != nil, @"CCReverseTime: action should not be nil"); + NSAssert(action != other_, @"CCReverseTime: re-init doesn't support using the same arguments"); + + if( (self=[super initWithDuration: [action duration]]) ) { + // Don't leak if action is reused + [other_ release]; + other_ = [action retain]; + } + + return self; +} + +-(id) copyWithZone: (NSZone*) zone +{ + return [[[self class] allocWithZone: zone] initWithAction:[[other_ copy] autorelease] ]; +} + +-(void) dealloc +{ + [other_ release]; + [super dealloc]; +} + +-(void) startWithTarget:(id)aTarget +{ + [super startWithTarget:aTarget]; + [other_ startWithTarget:target_]; +} + +-(void) stop +{ + [other_ stop]; + [super stop]; +} + +-(void) update:(ccTime)t +{ + [other_ update:1-t]; +} + +-(CCActionInterval*) reverse +{ + return [[other_ copy] autorelease]; +} +@end + +// +// Animate +// + +#pragma mark - +#pragma mark Animate +@implementation CCAnimate + +@synthesize animation = animation_; + ++(id) actionWithAnimation: (CCAnimation*)anim +{ + return [[[self alloc] initWithAnimation:anim restoreOriginalFrame:YES] autorelease]; +} + ++(id) actionWithAnimation: (CCAnimation*)anim restoreOriginalFrame:(BOOL)b +{ + return [[[self alloc] initWithAnimation:anim restoreOriginalFrame:b] autorelease]; +} + ++(id) actionWithDuration:(ccTime)duration animation: (CCAnimation*)anim restoreOriginalFrame:(BOOL)b +{ + return [[[self alloc] initWithDuration:duration animation:anim restoreOriginalFrame:b] autorelease]; +} + +-(id) initWithAnimation: (CCAnimation*)anim +{ + NSAssert( anim!=nil, @"Animate: argument Animation must be non-nil"); + return [self initWithAnimation:anim restoreOriginalFrame:YES]; +} + +-(id) initWithAnimation: (CCAnimation*)anim restoreOriginalFrame:(BOOL) b +{ + NSAssert( anim!=nil, @"Animate: argument Animation must be non-nil"); + + if( (self=[super initWithDuration: [[anim frames] count] * [anim delay]]) ) { + + restoreOriginalFrame_ = b; + self.animation = anim; + origFrame_ = nil; + } + return self; +} + +-(id) initWithDuration:(ccTime)aDuration animation: (CCAnimation*)anim restoreOriginalFrame:(BOOL) b +{ + NSAssert( anim!=nil, @"Animate: argument Animation must be non-nil"); + + if( (self=[super initWithDuration:aDuration] ) ) { + + restoreOriginalFrame_ = b; + self.animation = anim; + origFrame_ = nil; + } + return self; +} + + +-(id) copyWithZone: (NSZone*) zone +{ + return [[[self class] allocWithZone: zone] initWithDuration:duration_ animation:animation_ restoreOriginalFrame:restoreOriginalFrame_]; +} + +-(void) dealloc +{ + [animation_ release]; + [origFrame_ release]; + [super dealloc]; +} + +-(void) startWithTarget:(id)aTarget +{ + [super startWithTarget:aTarget]; + CCSprite *sprite = target_; + + [origFrame_ release]; + + if( restoreOriginalFrame_ ) + origFrame_ = [[sprite displayedFrame] retain]; +} + +-(void) stop +{ + if( restoreOriginalFrame_ ) { + CCSprite *sprite = target_; + [sprite setDisplayFrame:origFrame_]; + } + + [super stop]; +} + +-(void) update: (ccTime) t +{ + NSArray *frames = [animation_ frames]; + NSUInteger numberOfFrames = [frames count]; + + NSUInteger idx = t * numberOfFrames; + + if( idx >= numberOfFrames ) + idx = numberOfFrames -1; + + CCSprite *sprite = target_; + if (! [sprite isFrameDisplayed: [frames objectAtIndex: idx]] ) + [sprite setDisplayFrame: [frames objectAtIndex:idx]]; +} + +- (CCActionInterval *) reverse +{ + NSArray *oldArray = [animation_ frames]; + NSMutableArray *newArray = [NSMutableArray arrayWithCapacity:[oldArray count]]; + NSEnumerator *enumerator = [oldArray reverseObjectEnumerator]; + for (id element in enumerator) + [newArray addObject:[[element copy] autorelease]]; + + CCAnimation *newAnim = [CCAnimation animationWithFrames:newArray delay:animation_.delay]; + return [[self class] actionWithDuration:duration_ animation:newAnim restoreOriginalFrame:restoreOriginalFrame_]; +} + +@end diff --git a/tweejump/libs/cocos2d/CCActionManager.h b/tweejump/libs/cocos2d/CCActionManager.h new file mode 100755 index 0000000..0eeda91 --- /dev/null +++ b/tweejump/libs/cocos2d/CCActionManager.h @@ -0,0 +1,111 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2009 Valentin Milea + * + * Copyright (c) 2008-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. + * + */ + + +#import "CCAction.h" +#import "Support/ccCArray.h" +#import "Support/uthash.h" + +typedef struct _hashElement +{ + struct ccArray *actions; + id target; + NSUInteger actionIndex; + CCAction *currentAction; + BOOL currentActionSalvaged; + BOOL paused; + UT_hash_handle hh; +} tHashElement; + + +/** CCActionManager is a singleton that manages all the actions. + Normally you won't need to use this singleton directly. 99% of the cases you will use the CCNode interface, + which uses this singleton. + But there are some cases where you might need to use this singleton. + Examples: + - When you want to run an action where the target is different from a CCNode. + - When you want to pause / resume the actions + + @since v0.8 + */ +@interface CCActionManager : NSObject +{ + tHashElement *targets; + tHashElement *currentTarget; + BOOL currentTargetSalvaged; +} + +/** returns a shared instance of the CCActionManager */ ++ (CCActionManager *)sharedManager; + +/** purges the shared action manager. It releases the retained instance. + @since v0.99.0 + */ ++(void)purgeSharedManager; + +// actions + +/** Adds an action with a target. + If the target is already present, then the action will be added to the existing target. + If the target is not present, a new instance of this target will be created either paused or paused, and the action will be added to the newly created target. + When the target is paused, the queued actions won't be 'ticked'. + */ +-(void) addAction: (CCAction*) action target:(id)target paused:(BOOL)paused; +/** Removes all actions from all the targers. + */ +-(void) removeAllActions; + +/** Removes all actions from a certain target. + All the actions that belongs to the target will be removed. + */ +-(void) removeAllActionsFromTarget:(id)target; +/** Removes an action given an action reference. + */ +-(void) removeAction: (CCAction*) action; +/** Removes an action given its tag and the target */ +-(void) removeActionByTag:(NSInteger)tag target:(id)target; +/** Gets an action given its tag an a target + @return the Action the with the given tag + */ +-(CCAction*) getActionByTag:(NSInteger) tag target:(id)target; +/** Returns the numbers of actions that are running in a certain target + * Composable actions are counted as 1 action. Example: + * If you are running 1 Sequence of 7 actions, it will return 1. + * If you are running 7 Sequences of 2 actions, it will return 7. + */ +-(NSUInteger) numberOfRunningActionsInTarget:(id)target; + +/** Pauses the target: all running actions and newly added actions will be paused. + */ +-(void) pauseTarget:(id)target; +/** Resumes the target. All queued actions will be resumed. + */ +-(void) resumeTarget:(id)target; + +@end + diff --git a/tweejump/libs/cocos2d/CCActionManager.m b/tweejump/libs/cocos2d/CCActionManager.m new file mode 100755 index 0000000..8bdfbb7 --- /dev/null +++ b/tweejump/libs/cocos2d/CCActionManager.m @@ -0,0 +1,345 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2009 Valentin Milea + * + * Copyright (c) 2008-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. + * + */ + + +#import "CCActionManager.h" +#import "CCScheduler.h" +#import "ccMacros.h" + + +// +// singleton stuff +// +static CCActionManager *sharedManager_ = nil; + +@interface CCActionManager (Private) +-(void) removeActionAtIndex:(NSUInteger)index hashElement:(tHashElement*)element; +-(void) deleteHashElement:(tHashElement*)element; +-(void) actionAllocWithHashElement:(tHashElement*)element; +@end + + +@implementation CCActionManager + +#pragma mark ActionManager - init ++ (CCActionManager *)sharedManager +{ + if (!sharedManager_) + sharedManager_ = [[self alloc] init]; + + return sharedManager_; +} + ++(id)alloc +{ + NSAssert(sharedManager_ == nil, @"Attempted to allocate a second instance of a singleton."); + return [super alloc]; +} + ++(void)purgeSharedManager +{ + [[CCScheduler sharedScheduler] unscheduleUpdateForTarget:self]; + [sharedManager_ release]; + sharedManager_ = nil; +} + +-(id) init +{ + if ((self=[super init]) ) { + [[CCScheduler sharedScheduler] scheduleUpdateForTarget:self priority:0 paused:NO]; + targets = NULL; + } + + return self; +} + +- (void) dealloc +{ + CCLOGINFO( @"cocos2d: deallocing %@", self); + + [self removeAllActions]; + + sharedManager_ = nil; + + [super dealloc]; +} + +#pragma mark ActionManager - Private + +-(void) deleteHashElement:(tHashElement*)element +{ + ccArrayFree(element->actions); + HASH_DEL(targets, element); +// CCLOG(@"cocos2d: ---- buckets: %d/%d - %@", targets->entries, targets->size, element->target); + [element->target release]; + free(element); +} + +-(void) actionAllocWithHashElement:(tHashElement*)element +{ + // 4 actions per Node by default + if( element->actions == nil ) + element->actions = ccArrayNew(4); + else if( element->actions->num == element->actions->max ) + ccArrayDoubleCapacity(element->actions); +} + +-(void) removeActionAtIndex:(NSUInteger)index hashElement:(tHashElement*)element +{ + id action = element->actions->arr[index]; + + if( action == element->currentAction && !element->currentActionSalvaged ) { + [element->currentAction retain]; + element->currentActionSalvaged = YES; + } + + ccArrayRemoveObjectAtIndex(element->actions, index); + + // update actionIndex in case we are in tick:, looping over the actions + if( element->actionIndex >= index ) + element->actionIndex--; + + if( element->actions->num == 0 ) { + if( currentTarget == element ) + currentTargetSalvaged = YES; + else + [self deleteHashElement: element]; + } +} + +#pragma mark ActionManager - Pause / Resume + +-(void) pauseTarget:(id)target +{ + tHashElement *element = NULL; + HASH_FIND_INT(targets, &target, element); + if( element ) + element->paused = YES; +// else +// CCLOG(@"cocos2d: pauseAllActions: Target not found"); +} + +-(void) resumeTarget:(id)target +{ + tHashElement *element = NULL; + HASH_FIND_INT(targets, &target, element); + if( element ) + element->paused = NO; +// else +// CCLOG(@"cocos2d: resumeAllActions: Target not found"); +} + +#pragma mark ActionManager - run + +-(void) addAction:(CCAction*)action target:(id)target paused:(BOOL)paused +{ + NSAssert( action != nil, @"Argument action must be non-nil"); + NSAssert( target != nil, @"Argument target must be non-nil"); + + tHashElement *element = NULL; + HASH_FIND_INT(targets, &target, element); + if( ! element ) { + element = calloc( sizeof( *element ), 1 ); + element->paused = paused; + element->target = [target retain]; + HASH_ADD_INT(targets, target, element); +// CCLOG(@"cocos2d: ---- buckets: %d/%d - %@", targets->entries, targets->size, element->target); + + } + + [self actionAllocWithHashElement:element]; + + NSAssert( !ccArrayContainsObject(element->actions, action), @"runAction: Action already running"); + ccArrayAppendObject(element->actions, action); + + [action startWithTarget:target]; +} + +#pragma mark ActionManager - remove + +-(void) removeAllActions +{ + for(tHashElement *element=targets; element != NULL; ) { + id target = element->target; + element = element->hh.next; + [self removeAllActionsFromTarget:target]; + } +} +-(void) removeAllActionsFromTarget:(id)target +{ + // explicit nil handling + if( target == nil ) + return; + + tHashElement *element = NULL; + HASH_FIND_INT(targets, &target, element); + if( element ) { + if( ccArrayContainsObject(element->actions, element->currentAction) && !element->currentActionSalvaged ) { + [element->currentAction retain]; + element->currentActionSalvaged = YES; + } + ccArrayRemoveAllObjects(element->actions); + if( currentTarget == element ) + currentTargetSalvaged = YES; + else + [self deleteHashElement:element]; + } +// else { +// CCLOG(@"cocos2d: removeAllActionsFromTarget: Target not found"); +// } +} + +-(void) removeAction: (CCAction*) action +{ + // explicit nil handling + if (action == nil) + return; + + tHashElement *element = NULL; + id target = [action originalTarget]; + HASH_FIND_INT(targets, &target, element ); + if( element ) { + NSUInteger i = ccArrayGetIndexOfObject(element->actions, action); + if( i != NSNotFound ) + [self removeActionAtIndex:i hashElement:element]; + } +// else { +// CCLOG(@"cocos2d: removeAction: Target not found"); +// } +} + +-(void) removeActionByTag:(NSInteger)aTag target:(id)target +{ + NSAssert( aTag != kCCActionTagInvalid, @"Invalid tag"); + NSAssert( target != nil, @"Target should be ! nil"); + + tHashElement *element = NULL; + HASH_FIND_INT(targets, &target, element); + + if( element ) { + NSUInteger limit = element->actions->num; + for( NSUInteger i = 0; i < limit; i++) { + CCAction *a = element->actions->arr[i]; + + if( a.tag == aTag && [a originalTarget]==target) { + [self removeActionAtIndex:i hashElement:element]; + break; + } + } + + } +} + +#pragma mark ActionManager - get + +-(CCAction*) getActionByTag:(NSInteger)aTag target:(id)target +{ + NSAssert( aTag != kCCActionTagInvalid, @"Invalid tag"); + + tHashElement *element = NULL; + HASH_FIND_INT(targets, &target, element); + + if( element ) { + if( element->actions != nil ) { + NSUInteger limit = element->actions->num; + for( NSUInteger i = 0; i < limit; i++) { + CCAction *a = element->actions->arr[i]; + + if( a.tag == aTag ) + return a; + } + } +// CCLOG(@"cocos2d: getActionByTag: Action not found"); + } +// else { +// CCLOG(@"cocos2d: getActionByTag: Target not found"); +// } + return nil; +} + +-(NSUInteger) numberOfRunningActionsInTarget:(id) target +{ + tHashElement *element = NULL; + HASH_FIND_INT(targets, &target, element); + if( element ) + return element->actions ? element->actions->num : 0; + +// CCLOG(@"cocos2d: numberOfRunningActionsInTarget: Target not found"); + return 0; +} + +#pragma mark ActionManager - main loop + +-(void) update: (ccTime) dt +{ + for(tHashElement *elt = targets; elt != NULL; ) { + + currentTarget = elt; + currentTargetSalvaged = NO; + + if( ! currentTarget->paused ) { + + // The 'actions' ccArray may change while inside this loop. + for( currentTarget->actionIndex = 0; currentTarget->actionIndex < currentTarget->actions->num; currentTarget->actionIndex++) { + currentTarget->currentAction = currentTarget->actions->arr[currentTarget->actionIndex]; + currentTarget->currentActionSalvaged = NO; + + [currentTarget->currentAction step: dt]; + + if( currentTarget->currentActionSalvaged ) { + // The currentAction told the node to remove it. To prevent the action from + // accidentally deallocating itself before finishing its step, we retained + // it. Now that step is done, it's safe to release it. + [currentTarget->currentAction release]; + + } else if( [currentTarget->currentAction isDone] ) { + [currentTarget->currentAction stop]; + + CCAction *a = currentTarget->currentAction; + // Make currentAction nil to prevent removeAction from salvaging it. + currentTarget->currentAction = nil; + [self removeAction:a]; + } + + currentTarget->currentAction = nil; + } + } + + // elt, at this moment, is still valid + // so it is safe to ask this here (issue #490) + elt = elt->hh.next; + + // only delete currentTarget if no actions were scheduled during the cycle (issue #481) + if( currentTargetSalvaged && currentTarget->actions->num == 0 ) + [self deleteHashElement:currentTarget]; + } + + // issue #635 + currentTarget = nil; +} +@end diff --git a/tweejump/libs/cocos2d/CCActionPageTurn3D.h b/tweejump/libs/cocos2d/CCActionPageTurn3D.h new file mode 100755 index 0000000..39eb31d --- /dev/null +++ b/tweejump/libs/cocos2d/CCActionPageTurn3D.h @@ -0,0 +1,42 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2009 Sindesso Pty Ltd http://www.sindesso.com/ + * + * 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. + * + */ + + +#import "CCActionGrid3D.h" + +/** + * This action simulates a page turn from the bottom right hand corner of the screen + * It's not much use by itself but is used by the PageTurnTransition. + * + * Based on an original paper by L Hong et al. + * http://www.parc.com/publication/1638/turning-pages-of-3d-electronic-books.html + * + * @since v0.8.2 + */ +@interface CCPageTurn3D : CCGrid3DAction +{ +} + +@end diff --git a/tweejump/libs/cocos2d/CCActionPageTurn3D.m b/tweejump/libs/cocos2d/CCActionPageTurn3D.m new file mode 100755 index 0000000..ee59500 --- /dev/null +++ b/tweejump/libs/cocos2d/CCActionPageTurn3D.m @@ -0,0 +1,86 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2009 Sindesso Pty Ltd http://www.sindesso.com/ + * + * 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. + * + */ + +#import "CCActionPageTurn3D.h" + +@implementation CCPageTurn3D + +/* + * Update each tick + * Time is the percentage of the way through the duration + */ +-(void)update:(ccTime)time +{ + float tt = MAX( 0, time - 0.25f ); + float deltaAy = ( tt * tt * 500); + float ay = -100 - deltaAy; + + float deltaTheta = - (float) M_PI_2 * sqrtf( time) ; + float theta = /*0.01f*/ + (float) M_PI_2 +deltaTheta; + + float sinTheta = sinf(theta); + float cosTheta = cosf(theta); + + for( int i = 0; i <=gridSize_.x; i++ ) + { + for( int j = 0; j <= gridSize_.y; j++ ) + { + // Get original vertex + ccVertex3F p = [self originalVertex:ccg(i,j)]; + + float R = sqrtf(p.x*p.x + (p.y - ay) * (p.y - ay)); + float r = R * sinTheta; + float alpha = asinf( p.x / R ); + float beta = alpha / sinTheta; + float cosBeta = cosf( beta ); + + // If beta > PI then we've wrapped around the cone + // Reduce the radius to stop these points interfering with others + if( beta <= M_PI) + p.x = ( r * sinf(beta)); + else + { + // Force X = 0 to stop wrapped + // points + p.x = 0; + } + + p.y = ( R + ay - ( r*(1 - cosBeta)*sinTheta)); + + // We scale z here to avoid the animation being + // too much bigger than the screen due to perspectve transform + p.z = (r * ( 1 - cosBeta ) * cosTheta) / 7; // "100" didn't work for + + // Stop z coord from dropping beneath underlying page in a transition + // issue #751 + if( p.z<0.5f ) + p.z = 0.5f; + + // Set new coords + [self setVertex:ccg(i,j) vertex:p]; + } + } +} +@end diff --git a/tweejump/libs/cocos2d/CCActionProgressTimer.h b/tweejump/libs/cocos2d/CCActionProgressTimer.h new file mode 100755 index 0000000..500631b --- /dev/null +++ b/tweejump/libs/cocos2d/CCActionProgressTimer.h @@ -0,0 +1,59 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (C) 2010 Lam Pham + * + * 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. + * + */ + + +#import +#import "CCProgressTimer.h" +#import "CCActionInterval.h" + +/** + Progress to percentage +@since v0.99.1 +*/ +@interface CCProgressTo : CCActionInterval +{ + float to_; + float from_; +} +/** Creates and initializes with a duration and a percent */ ++(id) actionWithDuration:(ccTime)duration percent:(float)percent; +/** Initializes with a duration and a percent */ +-(id) initWithDuration:(ccTime)duration percent:(float)percent; +@end + +/** + Progress from a percentage to another percentage + @since v0.99.1 + */ +@interface CCProgressFromTo : CCActionInterval +{ + float to_; + float from_; +} +/** Creates and initializes the action with a duration, a "from" percentage and a "to" percentage */ ++(id) actionWithDuration:(ccTime)duration from:(float)fromPercentage to:(float) toPercentage; +/** Initializes the action with a duration, a "from" percentage and a "to" percentage */ +-(id) initWithDuration:(ccTime)duration from:(float)fromPercentage to:(float) toPercentage; +@end diff --git a/tweejump/libs/cocos2d/CCActionProgressTimer.m b/tweejump/libs/cocos2d/CCActionProgressTimer.m new file mode 100755 index 0000000..c242570 --- /dev/null +++ b/tweejump/libs/cocos2d/CCActionProgressTimer.m @@ -0,0 +1,103 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (C) 2010 Lam Pham + * + * 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. + * + */ + + +#import "CCActionProgressTimer.h" + +#define kProgressTimerCast CCProgressTimer* + +@implementation CCProgressTo ++(id) actionWithDuration: (ccTime) t percent: (float) v +{ + return [[[ self alloc] initWithDuration: t percent: v] autorelease]; +} + +-(id) initWithDuration: (ccTime) t percent: (float) v +{ + if( (self=[super initWithDuration: t] ) ) + to_ = v; + + return self; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCAction *copy = [[[self class] allocWithZone: zone] initWithDuration:duration_ percent:to_]; + return copy; +} + +-(void) startWithTarget:(id) aTarget; +{ + [super startWithTarget:aTarget]; + from_ = [(kProgressTimerCast)target_ percentage]; + + // XXX: Is this correct ? + // Adding it to support CCRepeat + if( from_ == 100) + from_ = 0; +} + +-(void) update: (ccTime) t +{ + [(kProgressTimerCast)target_ setPercentage: from_ + ( to_ - from_ ) * t]; +} +@end + +@implementation CCProgressFromTo ++(id) actionWithDuration: (ccTime) t from:(float)fromPercentage to:(float) toPercentage +{ + return [[[self alloc] initWithDuration: t from: fromPercentage to: toPercentage] autorelease]; +} + +-(id) initWithDuration: (ccTime) t from:(float)fromPercentage to:(float) toPercentage +{ + if( (self=[super initWithDuration: t] ) ){ + to_ = toPercentage; + from_ = fromPercentage; + } + return self; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCAction *copy = [[[self class] allocWithZone: zone] initWithDuration:duration_ from:from_ to:to_]; + return copy; +} + +- (CCActionInterval *) reverse +{ + return [[self class] actionWithDuration:duration_ from:to_ to:from_]; +} + +-(void) startWithTarget:(id) aTarget; +{ + [super startWithTarget:aTarget]; +} + +-(void) update: (ccTime) t +{ + [(kProgressTimerCast)target_ setPercentage: from_ + ( to_ - from_ ) * t]; +} +@end diff --git a/Support/cocos2d/TiledGridAction.h b/tweejump/libs/cocos2d/CCActionTiledGrid.h old mode 100644 new mode 100755 similarity index 61% rename from Support/cocos2d/TiledGridAction.h rename to tweejump/libs/cocos2d/CCActionTiledGrid.h index a205e8f..d66132d --- a/Support/cocos2d/TiledGridAction.h +++ b/tweejump/libs/cocos2d/CCActionTiledGrid.h @@ -1,21 +1,32 @@ -/* cocos2d for iPhone +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org * - * http://code.google.com/p/cocos2d-iphone + * Copyright (c) 2009 On-Core * - * Copyright (C) 2009 On-Core - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. + * 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. * */ -#import "GridAction.h" +#import "CCActionGrid.h" -/** ShakyTiles3D action */ -@interface ShakyTiles3D : TiledGrid3DAction +/** CCShakyTiles3D action */ +@interface CCShakyTiles3D : CCTiledGrid3DAction { int randrange; BOOL shakeZ; @@ -30,8 +41,8 @@ //////////////////////////////////////////////////////////// -/** ShatteredTiles3D action */ -@interface ShatteredTiles3D : TiledGrid3DAction +/** CCShatteredTiles3D action */ +@interface CCShatteredTiles3D : CCTiledGrid3DAction { int randrange; BOOL once; @@ -47,13 +58,13 @@ //////////////////////////////////////////////////////////// -/** ShuffleTiles action +/** CCShuffleTiles action Shuffle the tiles in random order */ -@interface ShuffleTiles : TiledGrid3DAction +@interface CCShuffleTiles : CCTiledGrid3DAction { int seed; - int tilesCount; + NSUInteger tilesCount; int *tilesOrder; void *tiles; } @@ -67,53 +78,53 @@ //////////////////////////////////////////////////////////// -/** FadeOutTRTiles action +/** CCFadeOutTRTiles action Fades out the tiles in a Top-Right direction */ -@interface FadeOutTRTiles : TiledGrid3DAction +@interface CCFadeOutTRTiles : CCTiledGrid3DAction { } @end //////////////////////////////////////////////////////////// -/** FadeOutBLTiles action. +/** CCFadeOutBLTiles action. Fades out the tiles in a Bottom-Left direction */ -@interface FadeOutBLTiles : FadeOutTRTiles +@interface CCFadeOutBLTiles : CCFadeOutTRTiles { } @end //////////////////////////////////////////////////////////// -/** FadeOutUpTiles action. +/** CCFadeOutUpTiles action. Fades out the tiles in upwards direction */ -@interface FadeOutUpTiles : FadeOutTRTiles +@interface CCFadeOutUpTiles : CCFadeOutTRTiles { } @end //////////////////////////////////////////////////////////// -/** FadeOutDownTiles action. +/** CCFadeOutDownTiles action. Fades out the tiles in downwards direction */ -@interface FadeOutDownTiles : FadeOutUpTiles +@interface CCFadeOutDownTiles : CCFadeOutUpTiles { } @end //////////////////////////////////////////////////////////// -/** TurnOffTiles action. +/** CCTurnOffTiles action. Turn off the files in random order */ -@interface TurnOffTiles : TiledGrid3DAction +@interface CCTurnOffTiles : CCTiledGrid3DAction { int seed; - int tilesCount; + NSUInteger tilesCount; int *tilesOrder; } @@ -125,8 +136,8 @@ //////////////////////////////////////////////////////////// -/** WavesTiles3D action. */ -@interface WavesTiles3D : TiledGrid3DAction +/** CCWavesTiles3D action. */ +@interface CCWavesTiles3D : CCTiledGrid3DAction { int waves; float amplitude; @@ -134,9 +145,9 @@ } /** waves amplitude */ -@property float amplitude; +@property (nonatomic,readwrite) float amplitude; /** waves amplitude rate */ -@property float amplitudeRate; +@property (nonatomic,readwrite) float amplitudeRate; /** creates the action with a number of waves, the waves amplitude, the grid size and the duration */ +(id)actionWithWaves:(int)wav amplitude:(float)amp grid:(ccGridSize)gridSize duration:(ccTime)d; @@ -147,10 +158,10 @@ //////////////////////////////////////////////////////////// -/** JumpTiles3D action. +/** CCJumpTiles3D action. A sin function is executed to move the tiles across the Z axis */ -@interface JumpTiles3D : TiledGrid3DAction +@interface CCJumpTiles3D : CCTiledGrid3DAction { int jumps; float amplitude; @@ -158,9 +169,9 @@ } /** amplitude of the sin*/ -@property float amplitude; +@property (nonatomic,readwrite) float amplitude; /** amplitude rate */ -@property float amplitudeRate; +@property (nonatomic,readwrite) float amplitudeRate; /** creates the action with the number of jumps, the sin amplitude, the grid size and the duration */ +(id)actionWithJumps:(int)j amplitude:(float)amp grid:(ccGridSize)gridSize duration:(ccTime)d; @@ -171,28 +182,30 @@ //////////////////////////////////////////////////////////// -/** SplitRows action */ -@interface SplitRows : TiledGrid3DAction +/** CCSplitRows action */ +@interface CCSplitRows : CCTiledGrid3DAction { + int rows; CGSize winSize; } /** creates the action with the number of rows to split and the duration */ -+(id)actionWithRows:(int)r duration:(ccTime)d; ++(id)actionWithRows:(int)rows duration:(ccTime)duration; /** initializes the action with the number of rows to split and the duration */ --(id)initWithRows:(int)r duration:(ccTime)d; +-(id)initWithRows:(int)rows duration:(ccTime)duration; @end //////////////////////////////////////////////////////////// -/** SplitCols action */ -@interface SplitCols : TiledGrid3DAction +/** CCSplitCols action */ +@interface CCSplitCols : CCTiledGrid3DAction { + int cols; CGSize winSize; } /** creates the action with the number of columns to split and the duration */ -+(id)actionWithCols:(int)c duration:(ccTime)d; ++(id)actionWithCols:(int)cols duration:(ccTime)duration; /** initializes the action with the number of columns to split and the duration */ --(id)initWithCols:(int)c duration:(ccTime)d; +-(id)initWithCols:(int)cols duration:(ccTime)duration; @end diff --git a/Support/cocos2d/TiledGridAction.m b/tweejump/libs/cocos2d/CCActionTiledGrid.m old mode 100644 new mode 100755 similarity index 63% rename from Support/cocos2d/TiledGridAction.m rename to tweejump/libs/cocos2d/CCActionTiledGrid.m index 3adf220..75965ec --- a/Support/cocos2d/TiledGridAction.m +++ b/tweejump/libs/cocos2d/CCActionTiledGrid.m @@ -1,19 +1,31 @@ -/* cocos2d for iPhone +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org * - * http://code.google.com/p/cocos2d-iphone + * Copyright (c) 2009 On-Core * - * Copyright (C) 2009 On-Core - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. + * 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. * */ -#import "TiledGridAction.h" -#import "Director.h" + +#import "CCActionTiledGrid.h" +#import "CCDirector.h" #import "ccMacros.h" #import "Support/CGPointExtension.h" @@ -24,8 +36,10 @@ ccGridSize delta; } Tile; +#pragma mark - +#pragma mark ShakyTiles3D -@implementation ShakyTiles3D +@implementation CCShakyTiles3D +(id)actionWithRange:(int)range shakeZ:(BOOL)shakeZ grid:(ccGridSize)gridSize duration:(ccTime)d { @@ -43,13 +57,20 @@ -(id)initWithRange:(int)range shakeZ:(BOOL)sz grid:(ccGridSize)gSize duration:(c return self; } +-(id) copyWithZone: (NSZone*) zone +{ + CCGridAction *copy = [[[self class] allocWithZone:zone] initWithRange:randrange shakeZ:shakeZ grid:gridSize_ duration:duration_]; + return copy; +} + + -(void)update:(ccTime)time { int i, j; - for( i = 0; i < gridSize.x; i++ ) + for( i = 0; i < gridSize_.x; i++ ) { - for( j = 0; j < gridSize.y; j++ ) + for( j = 0; j < gridSize_.y; j++ ) { ccQuad3 coords = [self originalTile:ccg(i,j)]; @@ -81,7 +102,10 @@ -(void)update:(ccTime)time //////////////////////////////////////////////////////////// -@implementation ShatteredTiles3D +#pragma mark - +#pragma mark CCShatteredTiles3D + +@implementation CCShatteredTiles3D +(id)actionWithRange:(int)range shatterZ:(BOOL)sz grid:(ccGridSize)gridSize duration:(ccTime)d { @@ -100,15 +124,22 @@ -(id)initWithRange:(int)range shatterZ:(BOOL)sz grid:(ccGridSize)gSize duration: return self; } +-(id) copyWithZone: (NSZone*) zone +{ + CCGridAction *copy = [[[self class] allocWithZone:zone] initWithRange:randrange shatterZ:shatterZ grid:gridSize_ duration:duration_]; + return copy; +} + + -(void)update:(ccTime)time { int i, j; if ( once == NO ) { - for( i = 0; i < gridSize.x; i++ ) + for( i = 0; i < gridSize_.x; i++ ) { - for( j = 0; j < gridSize.y; j++ ) + for( j = 0; j < gridSize_.y; j++ ) { ccQuad3 coords = [self originalTile:ccg(i,j)]; @@ -143,7 +174,10 @@ -(void)update:(ccTime)time //////////////////////////////////////////////////////////// -@implementation ShuffleTiles +#pragma mark - +#pragma mark CCShuffleTiles + +@implementation CCShuffleTiles +(id)actionWithSeed:(int)s grid:(ccGridSize)gridSize duration:(ccTime)d { @@ -162,6 +196,13 @@ -(id)initWithSeed:(int)s grid:(ccGridSize)gSize duration:(ccTime)d return self; } +-(id) copyWithZone: (NSZone*) zone +{ + CCGridAction *copy = [[[self class] allocWithZone:zone] initWithSeed:seed grid:gridSize_ duration:duration_]; + return copy; +} + + -(void)dealloc { if ( tilesOrder ) free(tilesOrder); @@ -169,12 +210,12 @@ -(void)dealloc [super dealloc]; } --(void)shuffle:(int*)array count:(int)len +-(void)shuffle:(int*)array count:(NSUInteger)len { - int i; + NSInteger i; for( i = len - 1; i >= 0; i-- ) { - int j = rand() % (i+1); + NSInteger j = rand() % (i+1); int v = array[i]; array[i] = array[j]; array[j] = v; @@ -185,10 +226,10 @@ -(ccGridSize)getDelta:(ccGridSize)pos { CGPoint pos2; - int idx = pos.x * gridSize.y + pos.y; + NSInteger idx = pos.x * gridSize_.y + pos.y; - pos2.x = tilesOrder[idx] / (int)gridSize.y; - pos2.y = tilesOrder[idx] % (int)gridSize.y; + pos2.x = tilesOrder[idx] / (int)gridSize_.y; + pos2.y = tilesOrder[idx] % (int)gridSize_.y; return ccg(pos2.x - pos.x, pos2.y - pos.y); } @@ -197,29 +238,30 @@ -(void)placeTile:(ccGridSize)pos tile:(Tile)t { ccQuad3 coords = [self originalTile:pos]; - coords.bl.x += (int)(t.position.x * target.grid.step.x); - coords.bl.y += (int)(t.position.y * target.grid.step.y); + CGPoint step = [[target_ grid] step]; + coords.bl.x += (int)(t.position.x * step.x); + coords.bl.y += (int)(t.position.y * step.y); - coords.br.x += (int)(t.position.x * target.grid.step.x); - coords.br.y += (int)(t.position.y * target.grid.step.y); + coords.br.x += (int)(t.position.x * step.x); + coords.br.y += (int)(t.position.y * step.y); - coords.tl.x += (int)(t.position.x * target.grid.step.x); - coords.tl.y += (int)(t.position.y * target.grid.step.y); + coords.tl.x += (int)(t.position.x * step.x); + coords.tl.y += (int)(t.position.y * step.y); - coords.tr.x += (int)(t.position.x * target.grid.step.x); - coords.tr.y += (int)(t.position.y * target.grid.step.y); + coords.tr.x += (int)(t.position.x * step.x); + coords.tr.y += (int)(t.position.y * step.y); [self setTile:pos coords:coords]; } --(void)start +-(void)startWithTarget:(id)aTarget { - [super start]; + [super startWithTarget:aTarget]; if ( seed != -1 ) srand(seed); - tilesCount = gridSize.x * gridSize.y; + tilesCount = gridSize_.x * gridSize_.y; tilesOrder = (int*)malloc(tilesCount*sizeof(int)); int i, j; @@ -231,9 +273,9 @@ -(void)start tiles = malloc(tilesCount*sizeof(Tile)); Tile *tileArray = (Tile*)tiles; - for( i = 0; i < gridSize.x; i++ ) + for( i = 0; i < gridSize_.x; i++ ) { - for( j = 0; j < gridSize.y; j++ ) + for( j = 0; j < gridSize_.y; j++ ) { tileArray->position = ccp(i,j); tileArray->startPosition = ccp(i,j); @@ -249,9 +291,9 @@ -(void)update:(ccTime)time Tile *tileArray = (Tile*)tiles; - for( i = 0; i < gridSize.x; i++ ) + for( i = 0; i < gridSize_.x; i++ ) { - for( j = 0; j < gridSize.y; j++ ) + for( j = 0; j < gridSize_.y; j++ ) { tileArray->position = ccpMult( ccp(tileArray->delta.x, tileArray->delta.y), time); [self placeTile:ccg(i,j) tile:*tileArray]; @@ -264,13 +306,17 @@ -(void)update:(ccTime)time //////////////////////////////////////////////////////////// -@implementation FadeOutTRTiles +#pragma mark - +#pragma mark CCFadeOutTRTiles + +@implementation CCFadeOutTRTiles -(float)testFunc:(ccGridSize)pos time:(ccTime)time { - CGPoint n = ccpMult( ccp(gridSize.x,gridSize.y), time); + CGPoint n = ccpMult( ccp(gridSize_.x,gridSize_.y), time); if ( (n.x+n.y) == 0.0f ) return 1.0f; + return powf( (pos.x+pos.y) / (n.x+n.y), 6 ); } @@ -289,18 +335,19 @@ -(void)turnOffTile:(ccGridSize)pos -(void)transformTile:(ccGridSize)pos distance:(float)distance { ccQuad3 coords = [self originalTile:pos]; + CGPoint step = [[target_ grid] step]; - coords.bl.x += (target.grid.step.x / 2) * (1.0f - distance); - coords.bl.y += (target.grid.step.y / 2) * (1.0f - distance); + coords.bl.x += (step.x / 2) * (1.0f - distance); + coords.bl.y += (step.y / 2) * (1.0f - distance); - coords.br.x -= (target.grid.step.x / 2) * (1.0f - distance); - coords.br.y += (target.grid.step.y / 2) * (1.0f - distance); + coords.br.x -= (step.x / 2) * (1.0f - distance); + coords.br.y += (step.y / 2) * (1.0f - distance); - coords.tl.x += (target.grid.step.x / 2) * (1.0f - distance); - coords.tl.y -= (target.grid.step.y / 2) * (1.0f - distance); + coords.tl.x += (step.x / 2) * (1.0f - distance); + coords.tl.y -= (step.y / 2) * (1.0f - distance); - coords.tr.x -= (target.grid.step.x / 2) * (1.0f - distance); - coords.tr.y -= (target.grid.step.y / 2) * (1.0f - distance); + coords.tr.x -= (step.x / 2) * (1.0f - distance); + coords.tr.y -= (step.y / 2) * (1.0f - distance); [self setTile:pos coords:coords]; } @@ -309,9 +356,9 @@ -(void)update:(ccTime)time { int i, j; - for( i = 0; i < gridSize.x; i++ ) + for( i = 0; i < gridSize_.x; i++ ) { - for( j = 0; j < gridSize.y; j++ ) + for( j = 0; j < gridSize_.y; j++ ) { float distance = [self testFunc:ccg(i,j) time:time]; if ( distance == 0 ) @@ -328,14 +375,17 @@ -(void)update:(ccTime)time //////////////////////////////////////////////////////////// -@implementation FadeOutBLTiles +#pragma mark - +#pragma mark CCFadeOutBLTiles + +@implementation CCFadeOutBLTiles -(float)testFunc:(ccGridSize)pos time:(ccTime)time { - CGPoint n = ccpMult(ccp(gridSize.x, gridSize.y), (1.0f-time)); - + CGPoint n = ccpMult(ccp(gridSize_.x, gridSize_.y), (1.0f-time)); if ( (pos.x+pos.y) == 0 ) return 1.0f; + return powf( (n.x+n.y) / (pos.x+pos.y), 6 ); } @@ -343,24 +393,29 @@ -(float)testFunc:(ccGridSize)pos time:(ccTime)time //////////////////////////////////////////////////////////// -@implementation FadeOutUpTiles +#pragma mark - +#pragma mark CCFadeOutUpTiles + +@implementation CCFadeOutUpTiles -(float)testFunc:(ccGridSize)pos time:(ccTime)time { - CGPoint n = ccpMult(ccp(gridSize.x, gridSize.y), time); + CGPoint n = ccpMult(ccp(gridSize_.x, gridSize_.y), time); if ( n.y == 0 ) return 1.0f; + return powf( pos.y / n.y, 6 ); } -(void)transformTile:(ccGridSize)pos distance:(float)distance { ccQuad3 coords = [self originalTile:pos]; + CGPoint step = [[target_ grid] step]; - coords.bl.y += (target.grid.step.y / 2) * (1.0f - distance); - coords.br.y += (target.grid.step.y / 2) * (1.0f - distance); - coords.tl.y -= (target.grid.step.y / 2) * (1.0f - distance); - coords.tr.y -= (target.grid.step.y / 2) * (1.0f - distance); + coords.bl.y += (step.y / 2) * (1.0f - distance); + coords.br.y += (step.y / 2) * (1.0f - distance); + coords.tl.y -= (step.y / 2) * (1.0f - distance); + coords.tr.y -= (step.y / 2) * (1.0f - distance); [self setTile:pos coords:coords]; } @@ -369,13 +424,17 @@ -(void)transformTile:(ccGridSize)pos distance:(float)distance //////////////////////////////////////////////////////////// -@implementation FadeOutDownTiles +#pragma mark - +#pragma mark CCFadeOutDownTiles + +@implementation CCFadeOutDownTiles -(float)testFunc:(ccGridSize)pos time:(ccTime)time { - CGPoint n = ccpMult(ccp(gridSize.x,gridSize.y), (1.0f - time)); + CGPoint n = ccpMult(ccp(gridSize_.x,gridSize_.y), (1.0f - time)); if ( pos.y == 0 ) return 1.0f; + return powf( n.y / pos.y, 6 ); } @@ -383,7 +442,10 @@ -(float)testFunc:(ccGridSize)pos time:(ccTime)time //////////////////////////////////////////////////////////// -@implementation TurnOffTiles +#pragma mark - +#pragma mark TurnOffTiles + +@implementation CCTurnOffTiles +(id)actionWithSeed:(int)s grid:(ccGridSize)gridSize duration:(ccTime)d { @@ -401,18 +463,24 @@ -(id)initWithSeed:(int)s grid:(ccGridSize)gSize duration:(ccTime)d return self; } +-(id) copyWithZone: (NSZone*) zone +{ + CCGridAction *copy = [[[self class] allocWithZone:zone] initWithSeed:seed grid:gridSize_ duration:duration_]; + return copy; +} + -(void)dealloc { if ( tilesOrder ) free(tilesOrder); [super dealloc]; } --(void)shuffle:(int*)array count:(int)len +-(void)shuffle:(int*)array count:(NSUInteger)len { - int i; + NSInteger i; for( i = len - 1; i >= 0; i-- ) { - int j = rand() % (i+1); + NSInteger j = rand() % (i+1); int v = array[i]; array[i] = array[j]; array[j] = v; @@ -432,16 +500,16 @@ -(void)turnOffTile:(ccGridSize)pos [self setTile:pos coords:coords]; } --(void)start +-(void)startWithTarget:(id)aTarget { int i; - [super start]; + [super startWithTarget:aTarget]; if ( seed != -1 ) srand(seed); - tilesCount = gridSize.x * gridSize.y; + tilesCount = gridSize_.x * gridSize_.y; tilesOrder = (int*)malloc(tilesCount*sizeof(int)); for( i = 0; i < tilesCount; i++ ) @@ -459,7 +527,7 @@ -(void)update:(ccTime)time for( i = 0; i < tilesCount; i++ ) { t = tilesOrder[i]; - ccGridSize tilePos = ccg( t / gridSize.y, t % gridSize.y ); + ccGridSize tilePos = ccg( t / gridSize_.y, t % gridSize_.y ); if ( i < l ) [self turnOffTile:tilePos]; @@ -472,7 +540,10 @@ -(void)update:(ccTime)time //////////////////////////////////////////////////////////// -@implementation WavesTiles3D +#pragma mark - +#pragma mark CCWavesTiles3D + +@implementation CCWavesTiles3D @synthesize amplitude; @synthesize amplitudeRate; @@ -494,13 +565,20 @@ -(id)initWithWaves:(int)wav amplitude:(float)amp grid:(ccGridSize)gSize duration return self; } +-(id) copyWithZone: (NSZone*) zone +{ + CCGridAction *copy = [[[self class] allocWithZone:zone] initWithWaves:waves amplitude:amplitude grid:gridSize_ duration:duration_]; + return copy; +} + + -(void)update:(ccTime)time { int i, j; - for( i = 0; i < gridSize.x; i++ ) + for( i = 0; i < gridSize_.x; i++ ) { - for( j = 0; j < gridSize.y; j++ ) + for( j = 0; j < gridSize_.y; j++ ) { ccQuad3 coords = [self originalTile:ccg(i,j)]; @@ -517,7 +595,10 @@ -(void)update:(ccTime)time //////////////////////////////////////////////////////////// -@implementation JumpTiles3D +#pragma mark - +#pragma mark CCJumpTiles3D + +@implementation CCJumpTiles3D @synthesize amplitude; @synthesize amplitudeRate; @@ -539,6 +620,13 @@ -(id)initWithJumps:(int)j amplitude:(float)amp grid:(ccGridSize)gSize duration:( return self; } +-(id) copyWithZone: (NSZone*) zone +{ + CCGridAction *copy = [[[self class] allocWithZone:zone] initWithJumps:jumps amplitude:amplitude grid:gridSize_ duration:duration_]; + return copy; +} + + -(void)update:(ccTime)time { int i, j; @@ -546,9 +634,9 @@ -(void)update:(ccTime)time float sinz = (sinf((CGFloat)M_PI*time*jumps*2) * amplitude * amplitudeRate ); float sinz2 = (sinf((CGFloat)M_PI*(time*jumps*2 + 1)) * amplitude * amplitudeRate ); - for( i = 0; i < gridSize.x; i++ ) + for( i = 0; i < gridSize_.x; i++ ) { - for( j = 0; j < gridSize.y; j++ ) + for( j = 0; j < gridSize_.y; j++ ) { ccQuad3 coords = [self originalTile:ccg(i,j)]; @@ -575,7 +663,10 @@ -(void)update:(ccTime)time //////////////////////////////////////////////////////////// -@implementation SplitRows +#pragma mark - +#pragma mark SplitRows + +@implementation CCSplitRows +(id)actionWithRows:(int)r duration:(ccTime)d { @@ -584,20 +675,27 @@ +(id)actionWithRows:(int)r duration:(ccTime)d -(id)initWithRows:(int)r duration:(ccTime)d { + rows = r; return [super initWithSize:ccg(1,r) duration:d]; } --(void)start +-(id) copyWithZone: (NSZone*) zone +{ + CCGridAction *copy = [[[self class] allocWithZone:zone] initWithRows:rows duration:duration_]; + return copy; +} + +-(void)startWithTarget:(id)aTarget { - [super start]; - winSize = [[Director sharedDirector] winSize]; + [super startWithTarget:aTarget]; + winSize = [[CCDirector sharedDirector] winSizeInPixels]; } -(void)update:(ccTime)time { int j; - for( j = 0; j < gridSize.y; j++ ) + for( j = 0; j < gridSize_.y; j++ ) { ccQuad3 coords = [self originalTile:ccg(0,j)]; float direction = 1; @@ -618,7 +716,10 @@ -(void)update:(ccTime)time //////////////////////////////////////////////////////////// -@implementation SplitCols +#pragma mark - +#pragma mark CCSplitCols + +@implementation CCSplitCols +(id)actionWithCols:(int)c duration:(ccTime)d { @@ -627,20 +728,27 @@ +(id)actionWithCols:(int)c duration:(ccTime)d -(id)initWithCols:(int)c duration:(ccTime)d { + cols = c; return [super initWithSize:ccg(c,1) duration:d]; } --(void)start +-(id) copyWithZone: (NSZone*) zone +{ + CCGridAction *copy = [[[self class] allocWithZone:zone] initWithCols:cols duration:duration_]; + return copy; +} + +-(void)startWithTarget:(id)aTarget { - [super start]; - winSize = [[Director sharedDirector] winSize]; + [super startWithTarget:aTarget]; + winSize = [[CCDirector sharedDirector] winSizeInPixels]; } -(void)update:(ccTime)time { int i; - for( i = 0; i < gridSize.x; i++ ) + for( i = 0; i < gridSize_.x; i++ ) { ccQuad3 coords = [self originalTile:ccg(i,0)]; float direction = 1; diff --git a/tweejump/libs/cocos2d/CCActionTween.h b/tweejump/libs/cocos2d/CCActionTween.h new file mode 100755 index 0000000..69fdea5 --- /dev/null +++ b/tweejump/libs/cocos2d/CCActionTween.h @@ -0,0 +1,62 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright 2009 lhunath (Maarten Billemont) + * + * 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. + * + */ + + +#import +#import "CCActionInterval.h" + +/** CCActionTween + + CCActionTween is an action that lets you update any property of an object. + For example, if you want to modify the "width" property of a target from 200 to 300 in 2 senconds, then: + + id modifyWidth = [CCActionTween actionWithDuration:2 key:@"width" from:200 to:300]; + [target runAction:modifyWidth]; + + + Another example: CCScaleTo action could be rewriten using CCPropertyAction: + + // scaleA and scaleB are equivalents + id scaleA = [CCScaleTo actionWithDuration:2 scale:3]; + id scaleB = [CCActionTween actionWithDuration:2 key:@"scale" from:1 to:3]; + + + @since v0.99.2 + */ +@interface CCActionTween : CCActionInterval +{ + NSString *key_; + + float from_, to_; + float delta_; +} + +/** creates an initializes the action with the property name (key), and the from and to parameters. */ ++ (id)actionWithDuration:(ccTime)aDuration key:(NSString *)key from:(float)from to:(float)to; + +/** initializes the action with the property name (key), and the from and to parameters. */ +- (id)initWithDuration:(ccTime)aDuration key:(NSString *)key from:(float)from to:(float)to; + +@end diff --git a/tweejump/libs/cocos2d/CCActionTween.m b/tweejump/libs/cocos2d/CCActionTween.m new file mode 100755 index 0000000..95ae572 --- /dev/null +++ b/tweejump/libs/cocos2d/CCActionTween.m @@ -0,0 +1,72 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright 2009 lhunath (Maarten Billemont) + * + * 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. + * + */ + +#import "CCActionTween.h" + + +@implementation CCActionTween + ++ (id)actionWithDuration:(ccTime)aDuration key:(NSString *)aKey from:(float)aFrom to:(float)aTo { + + return [[[[self class] alloc] initWithDuration:aDuration key:aKey from:aFrom to:aTo] autorelease]; +} + +- (id)initWithDuration:(ccTime)aDuration key:(NSString *)key from:(float)from to:(float)to { + + if ((self = [super initWithDuration:aDuration])) { + + key_ = [key copy]; + to_ = to; + from_ = from; + + } + + return self; +} + +- (void) dealloc +{ + [key_ release]; + [super dealloc]; +} + +- (void)startWithTarget:aTarget +{ + [super startWithTarget:aTarget]; + delta_ = to_ - from_; +} + +- (void) update:(ccTime) dt +{ + [target_ setValue:[NSNumber numberWithFloat:to_ - delta_ * (1 - dt)] forKey:key_]; +} + +- (CCActionInterval *) reverse +{ + return [[self class] actionWithDuration:duration_ key:key_ from:to_ to:from_]; +} + + +@end diff --git a/tweejump/libs/cocos2d/CCAnimation.h b/tweejump/libs/cocos2d/CCAnimation.h new file mode 100755 index 0000000..622bc47 --- /dev/null +++ b/tweejump/libs/cocos2d/CCAnimation.h @@ -0,0 +1,95 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-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. + * + */ + +#import +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED +#import +#endif // IPHONE + +@class CCSpriteFrame; +@class CCTexture2D; + +/** A CCAnimation object is used to perform animations on the CCSprite objects. + + The CCAnimation object contains CCSpriteFrame objects, and a possible delay between the frames. + You can animate a CCAnimation object by using the CCAnimate action. Example: + + [sprite runAction:[CCAnimate actionWithAnimation:animation]]; + + */ +@interface CCAnimation : NSObject +{ + NSString *name_; + float delay_; + NSMutableArray *frames_; +} + +/** name of the animation */ +@property (nonatomic,readwrite,retain) NSString *name; +/** delay between frames in seconds. */ +@property (nonatomic,readwrite,assign) float delay; +/** array of frames */ +@property (nonatomic,readwrite,retain) NSMutableArray *frames; + +/** Creates an animation + @since v0.99.5 + */ ++(id) animation; + +/** Creates an animation with frames. + @since v0.99.5 + */ ++(id) animationWithFrames:(NSArray*)frames; + +/* Creates an animation with frames and a delay between frames. + @since v0.99.5 + */ ++(id) animationWithFrames:(NSArray*)frames delay:(float)delay; + +/** Initializes a CCAnimation with frames. + @since v0.99.5 +*/ +-(id) initWithFrames:(NSArray*)frames; + +/** Initializes a CCAnimation with frames and a delay between frames + @since v0.99.5 + */ +-(id) initWithFrames:(NSArray *)frames delay:(float)delay; + +/** Adds a frame to a CCAnimation. */ +-(void) addFrame:(CCSpriteFrame*)frame; + +/** Adds a frame with an image filename. Internally it will create a CCSpriteFrame and it will add it. + Added to facilitate the migration from v0.8 to v0.9. + */ +-(void) addFrameWithFilename:(NSString*)filename; + +/** Adds a frame with a texture and a rect. Internally it will create a CCSpriteFrame and it will add it. + Added to facilitate the migration from v0.8 to v0.9. + */ +-(void) addFrameWithTexture:(CCTexture2D*)texture rect:(CGRect)rect; + +@end diff --git a/tweejump/libs/cocos2d/CCAnimation.m b/tweejump/libs/cocos2d/CCAnimation.m new file mode 100755 index 0000000..d98cdac --- /dev/null +++ b/tweejump/libs/cocos2d/CCAnimation.m @@ -0,0 +1,107 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-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. + * + */ + +#import "ccMacros.h" +#import "CCAnimation.h" +#import "CCSpriteFrame.h" +#import "CCTexture2D.h" +#import "CCTextureCache.h" + +@implementation CCAnimation +@synthesize name = name_, delay = delay_, frames = frames_; + ++(id) animation +{ + return [[[self alloc] init] autorelease]; +} + ++(id) animationWithFrames:(NSArray*)frames +{ + return [[[self alloc] initWithFrames:frames] autorelease]; +} + ++(id) animationWithFrames:(NSArray*)frames delay:(float)delay +{ + return [[[self alloc] initWithFrames:frames delay:delay] autorelease]; +} + +-(id) init +{ + return [self initWithFrames:nil delay:0]; +} + +-(id) initWithFrames:(NSArray*)frames +{ + return [self initWithFrames:frames delay:0]; +} + +-(id) initWithFrames:(NSArray*)array delay:(float)delay +{ + if( (self=[super init]) ) { + + delay_ = delay; + self.frames = [NSMutableArray arrayWithArray:array]; + } + return self; +} + +- (NSString*) description +{ + return [NSString stringWithFormat:@"<%@ = %08X | frames=%d, delay:%f>", [self class], self, + [frames_ count], + delay_ + ]; +} + +-(void) dealloc +{ + CCLOGINFO( @"cocos2d: deallocing %@",self); + [name_ release]; + [frames_ release]; + [super dealloc]; +} + +-(void) addFrame:(CCSpriteFrame*)frame +{ + [frames_ addObject:frame]; +} + +-(void) addFrameWithFilename:(NSString*)filename +{ + CCTexture2D *texture = [[CCTextureCache sharedTextureCache] addImage:filename]; + CGRect rect = CGRectZero; + rect.size = texture.contentSize; + CCSpriteFrame *frame = [CCSpriteFrame frameWithTexture:texture rect:rect]; + [frames_ addObject:frame]; +} + +-(void) addFrameWithTexture:(CCTexture2D*)texture rect:(CGRect)rect +{ + CCSpriteFrame *frame = [CCSpriteFrame frameWithTexture:texture rect:rect]; + [frames_ addObject:frame]; +} + +@end diff --git a/tweejump/libs/cocos2d/CCAnimationCache.h b/tweejump/libs/cocos2d/CCAnimationCache.h new file mode 100755 index 0000000..075c836 --- /dev/null +++ b/tweejump/libs/cocos2d/CCAnimationCache.h @@ -0,0 +1,64 @@ +/* + * 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. + * + */ + +#import + +@class CCAnimation; + +/** Singleton that manages the Animations. + It saves in a cache the animations. You should use this class if you want to save your animations in a cache. + + Before v0.99.5, the recommend way was to save them on the CCSprite. Since v0.99.5, you should use this class instead. + + @since v0.99.5 + */ +@interface CCAnimationCache : NSObject +{ + NSMutableDictionary *animations_; +} + +/** Retruns ths shared instance of the Animation cache */ ++ (CCAnimationCache *) sharedAnimationCache; + +/** Purges the cache. It releases all the CCAnimation objects and the shared instance. + */ ++(void)purgeSharedAnimationCache; + +/** Adds a CCAnimation with a name. + */ +-(void) addAnimation:(CCAnimation*)animation name:(NSString*)name; + +/** Deletes a CCAnimation from the cache. + */ +-(void) removeAnimationByName:(NSString*)name; + +/** Returns a CCAnimation that was previously added. + If the name is not found it will return nil. + You should retain the returned copy if you are going to use it. + */ +-(CCAnimation*) animationByName:(NSString*)name; + +@end diff --git a/tweejump/libs/cocos2d/CCAnimationCache.m b/tweejump/libs/cocos2d/CCAnimationCache.m new file mode 100755 index 0000000..f508227 --- /dev/null +++ b/tweejump/libs/cocos2d/CCAnimationCache.m @@ -0,0 +1,101 @@ +/* + * 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. + * + */ + +#import "ccMacros.h" +#import "CCAnimationCache.h" +#import "CCAnimation.h" +#import "CCSprite.h" + + +@implementation CCAnimationCache + +#pragma mark CCAnimationCache - Alloc, Init & Dealloc + +static CCAnimationCache *sharedAnimationCache_=nil; + ++ (CCAnimationCache *)sharedAnimationCache +{ + if (!sharedAnimationCache_) + sharedAnimationCache_ = [[CCAnimationCache alloc] init]; + + return sharedAnimationCache_; +} + ++(id)alloc +{ + NSAssert(sharedAnimationCache_ == nil, @"Attempted to allocate a second instance of a singleton."); + return [super alloc]; +} + ++(void)purgeSharedAnimationCache +{ + [sharedAnimationCache_ release]; + sharedAnimationCache_ = nil; +} + +-(id) init +{ + if( (self=[super init]) ) { + animations_ = [[NSMutableDictionary alloc] initWithCapacity: 20]; + } + + return self; +} + +- (NSString*) description +{ + return [NSString stringWithFormat:@"<%@ = %08X | num of animations = %i>", [self class], self, [animations_ count]]; +} + +-(void) dealloc +{ + CCLOGINFO(@"cocos2d: deallocing %@", self); + + [animations_ release]; + [super dealloc]; +} + +#pragma mark CCAnimationCache - load/get/del + +-(void) addAnimation:(CCAnimation*)animation name:(NSString*)name +{ + [animations_ setObject:animation forKey:name]; +} + +-(void) removeAnimationByName:(NSString*)name +{ + if( ! name ) + return; + + [animations_ removeObjectForKey:name]; +} + +-(CCAnimation*) animationByName:(NSString*)name +{ + return [animations_ objectForKey:name]; +} + +@end diff --git a/tweejump/libs/cocos2d/CCAtlasNode.h b/tweejump/libs/cocos2d/CCAtlasNode.h new file mode 100755 index 0000000..c805812 --- /dev/null +++ b/tweejump/libs/cocos2d/CCAtlasNode.h @@ -0,0 +1,93 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-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. + */ + + +#import "CCTextureAtlas.h" +#import "CCNode.h" +#import "CCProtocols.h" + +/** CCAtlasNode is a subclass of CCNode that implements the CCRGBAProtocol and + CCTextureProtocol protocol + + It knows how to render a TextureAtlas object. + If you are going to render a TextureAtlas consider subclassing CCAtlasNode (or a subclass of CCAtlasNode) + + All features from CCNode are valid, plus the following features: + - opacity and RGB colors + */ +@interface CCAtlasNode : CCNode +{ + // texture atlas + CCTextureAtlas *textureAtlas_; + + // chars per row + NSUInteger itemsPerRow_; + // chars per column + NSUInteger itemsPerColumn_; + + // width of each char + NSUInteger itemWidth_; + // height of each char + NSUInteger itemHeight_; + + // quads to draw + NSUInteger quadsToDraw_; + + // blend function + ccBlendFunc blendFunc_; + + // texture RGBA. + GLubyte opacity_; + ccColor3B color_; + ccColor3B colorUnmodified_; + BOOL opacityModifyRGB_; +} + +/** conforms to CCTextureProtocol protocol */ +@property (nonatomic,readwrite,retain) CCTextureAtlas *textureAtlas; + +/** conforms to CCTextureProtocol protocol */ +@property (nonatomic,readwrite) ccBlendFunc blendFunc; + +/** conforms to CCRGBAProtocol protocol */ +@property (nonatomic,readwrite) GLubyte opacity; +/** conforms to CCRGBAProtocol protocol */ +@property (nonatomic,readwrite) ccColor3B color; + +/** how many quads to draw */ +@property (nonatomic,readwrite) NSUInteger quadsToDraw; + +/** creates a CCAtlasNode with an Atlas file the width and height of each item measured in points and the quantity of items to render*/ ++(id) atlasWithTileFile:(NSString*)tile tileWidth:(NSUInteger)w tileHeight:(NSUInteger)h itemsToRender: (NSUInteger) c; + +/** initializes an CCAtlasNode with an Atlas file the width and height of each item measured in points and the quantity of items to render*/ +-(id) initWithTileFile:(NSString*)tile tileWidth:(NSUInteger)w tileHeight:(NSUInteger)h itemsToRender: (NSUInteger) c; + +/** updates the Atlas (indexed vertex array). + * Shall be overriden in subclasses + */ +-(void) updateAtlasValues; +@end diff --git a/tweejump/libs/cocos2d/CCAtlasNode.m b/tweejump/libs/cocos2d/CCAtlasNode.m new file mode 100755 index 0000000..3f44633 --- /dev/null +++ b/tweejump/libs/cocos2d/CCAtlasNode.m @@ -0,0 +1,211 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-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. + */ + + +#import "CCAtlasNode.h" +#import "ccMacros.h" + + +@interface CCAtlasNode () +-(void) calculateMaxItems; +-(void) updateBlendFunc; +-(void) updateOpacityModifyRGB; +@end + +@implementation CCAtlasNode + +@synthesize textureAtlas = textureAtlas_; +@synthesize blendFunc = blendFunc_; +@synthesize quadsToDraw = quadsToDraw_; + +#pragma mark CCAtlasNode - Creation & Init ++(id) atlasWithTileFile:(NSString*)tile tileWidth:(NSUInteger)w tileHeight:(NSUInteger)h itemsToRender: (NSUInteger) c +{ + return [[[self alloc] initWithTileFile:tile tileWidth:w tileHeight:h itemsToRender:c] autorelease]; +} + +-(id) initWithTileFile:(NSString*)tile tileWidth:(NSUInteger)w tileHeight:(NSUInteger)h itemsToRender: (NSUInteger) c +{ + if( (self=[super init]) ) { + + itemWidth_ = w * CC_CONTENT_SCALE_FACTOR(); + itemHeight_ = h * CC_CONTENT_SCALE_FACTOR(); + + opacity_ = 255; + color_ = colorUnmodified_ = ccWHITE; + opacityModifyRGB_ = YES; + + blendFunc_.src = CC_BLEND_SRC; + blendFunc_.dst = CC_BLEND_DST; + + // double retain to avoid the autorelease pool + // also, using: self.textureAtlas supports re-initialization without leaking + self.textureAtlas = [[CCTextureAtlas alloc] initWithFile:tile capacity:c]; + [textureAtlas_ release]; + + if( ! textureAtlas_ ) { + CCLOG(@"cocos2d: Could not initialize CCAtlasNode. Invalid Texture"); + [self release]; + return nil; + } + + [self updateBlendFunc]; + [self updateOpacityModifyRGB]; + + [self calculateMaxItems]; + + self.quadsToDraw = c; + + } + return self; +} + +-(void) dealloc +{ + [textureAtlas_ release]; + + [super dealloc]; +} + +#pragma mark CCAtlasNode - Atlas generation + +-(void) calculateMaxItems +{ + CGSize s = [[textureAtlas_ texture] contentSizeInPixels]; + itemsPerColumn_ = s.height / itemHeight_; + itemsPerRow_ = s.width / itemWidth_; +} + +-(void) updateAtlasValues +{ + [NSException raise:@"CCAtlasNode:Abstract" format:@"updateAtlasValue not overriden"]; +} + +#pragma mark CCAtlasNode - draw +- (void) draw +{ + [super draw]; + + // Default GL states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY + // Needed states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_TEXTURE_COORD_ARRAY + // Unneeded states: GL_COLOR_ARRAY + glDisableClientState(GL_COLOR_ARRAY); + + glColor4ub( color_.r, color_.g, color_.b, opacity_); + + BOOL newBlend = blendFunc_.src != CC_BLEND_SRC || blendFunc_.dst != CC_BLEND_DST; + if( newBlend ) + glBlendFunc( blendFunc_.src, blendFunc_.dst ); + + [textureAtlas_ drawNumberOfQuads:quadsToDraw_ fromIndex:0]; + + if( newBlend ) + glBlendFunc(CC_BLEND_SRC, CC_BLEND_DST); + + // is this chepear than saving/restoring color state ? + // XXX: There is no need to restore the color to (255,255,255,255). Objects should use the color + // XXX: that they need +// glColor4ub( 255, 255, 255, 255); + + // restore default GL state + glEnableClientState(GL_COLOR_ARRAY); + +} + +#pragma mark CCAtlasNode - RGBA protocol + +- (ccColor3B) color +{ + if(opacityModifyRGB_) + return colorUnmodified_; + + return color_; +} + +-(void) setColor:(ccColor3B)color3 +{ + color_ = colorUnmodified_ = color3; + + if( opacityModifyRGB_ ){ + color_.r = color3.r * opacity_/255; + color_.g = color3.g * opacity_/255; + color_.b = color3.b * opacity_/255; + } +} + +-(GLubyte) opacity +{ + return opacity_; +} + +-(void) setOpacity:(GLubyte) anOpacity +{ + opacity_ = anOpacity; + + // special opacity for premultiplied textures + if( opacityModifyRGB_ ) + [self setColor: colorUnmodified_]; +} + +-(void) setOpacityModifyRGB:(BOOL)modify +{ + ccColor3B oldColor = self.color; + opacityModifyRGB_ = modify; + self.color = oldColor; +} + +-(BOOL) doesOpacityModifyRGB +{ + return opacityModifyRGB_; +} + +-(void) updateOpacityModifyRGB +{ + opacityModifyRGB_ = [textureAtlas_.texture hasPremultipliedAlpha]; +} + +#pragma mark CCAtlasNode - CocosNodeTexture protocol + +-(void) updateBlendFunc +{ + if( ! [textureAtlas_.texture hasPremultipliedAlpha] ) { + blendFunc_.src = GL_SRC_ALPHA; + blendFunc_.dst = GL_ONE_MINUS_SRC_ALPHA; + } +} + +-(void) setTexture:(CCTexture2D*)texture +{ + textureAtlas_.texture = texture; + [self updateBlendFunc]; + [self updateOpacityModifyRGB]; +} + +-(CCTexture2D*) texture +{ + return textureAtlas_.texture; +} + +@end diff --git a/tweejump/libs/cocos2d/CCBlockSupport.h b/tweejump/libs/cocos2d/CCBlockSupport.h new file mode 100755 index 0000000..339d5aa --- /dev/null +++ b/tweejump/libs/cocos2d/CCBlockSupport.h @@ -0,0 +1,51 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2010 Stuart Carnie + * + * 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. + * + */ + + +#import + +/** @file + cocos2d blocks support + */ + +// To comply with Apple Objective C runtime (this is defined in NSObjCRuntime.h) +#if !defined(NS_BLOCKS_AVAILABLE) + #if __BLOCKS__ + #define NS_BLOCKS_AVAILABLE 1 + #else + #define NS_BLOCKS_AVAILABLE 0 + #endif +#endif + +#if NS_BLOCKS_AVAILABLE + +@interface NSObject(CCBlocksAdditions) + +- (void)ccCallbackBlock; +- (void)ccCallbackBlockWithSender:(id)sender; + +@end + +#endif // NS_BLOCKS_AVAILABLE diff --git a/Support/cocos2d/Support/CGPointExtension.m b/tweejump/libs/cocos2d/CCBlockSupport.m old mode 100644 new mode 100755 similarity index 67% rename from Support/cocos2d/Support/CGPointExtension.m rename to tweejump/libs/cocos2d/CCBlockSupport.m index d1ebcc5..9ac99b3 --- a/Support/cocos2d/Support/CGPointExtension.m +++ b/tweejump/libs/cocos2d/CCBlockSupport.m @@ -1,4 +1,7 @@ -/* Copyright (c) 2007 Scott Lembcke +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2010 Stuart Carnie * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -15,41 +18,29 @@ * 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. + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * */ -#include "stdio.h" -#include "math.h" -#include "CGPointExtension.h" +#import "CCBlockSupport.h" -CGFloat -ccpLength(const CGPoint v) -{ - return sqrtf(ccpLengthSQ(v)); -} +#if NS_BLOCKS_AVAILABLE -CGFloat -ccpDistance(const CGPoint v1, const CGPoint v2) -{ - return ccpLength(ccpSub(v1, v2)); -} +@implementation NSObject(CCBlocksAdditions) -CGPoint -ccpNormalize(const CGPoint v) -{ - return ccpMult(v, 1.0f/ccpLength(v)); +- (void)ccCallbackBlock { + void (^block)(void) = (id)self; + block(); } -CGPoint -ccpForAngle(const CGFloat a) -{ - return ccp(cosf(a), sinf(a)); +- (void)ccCallbackBlockWithSender:(id)sender { + void (^block)(id) = (id)self; + block(sender); } -CGFloat -ccpToAngle(const CGPoint v) -{ - return atan2f(v.y, v.x); -} + +@end + +#endif diff --git a/tweejump/libs/cocos2d/CCCamera.h b/tweejump/libs/cocos2d/CCCamera.h new file mode 100755 index 0000000..19a7712 --- /dev/null +++ b/tweejump/libs/cocos2d/CCCamera.h @@ -0,0 +1,95 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-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. + */ + + + +#import "CCNode.h" + +/** + A CCCamera is used in every CCNode. + Useful to look at the object from different views. + The OpenGL gluLookAt() function is used to locate the + camera. + + If the object is transformed by any of the scale, rotation or + position attributes, then they will override the camera. + + IMPORTANT: Either your use the camera or the rotation/scale/position properties. You can't use both. + World coordinates won't work if you use the camera. + + Limitations: + + - Some nodes, like CCParallaxNode, CCParticle uses world node coordinates, and they won't work properly if you move them (or any of their ancestors) + using the camera. + + - It doesn't work on batched nodes like CCSprite objects when they are parented to a CCSpriteBatchNode object. + + - It is recommended to use it ONLY if you are going to create 3D effects. For 2D effecs, use the action CCFollow or position/scale/rotate. + +*/ + +@interface CCCamera : NSObject +{ + float eyeX_; + float eyeY_; + float eyeZ_; + + float centerX_; + float centerY_; + float centerZ_; + + float upX_; + float upY_; + float upZ_; + + BOOL dirty_; +} + +/** whether of not the camera is dirty */ +@property (nonatomic,readwrite) BOOL dirty; + +/** returns the Z eye */ ++(float) getZEye; + +/** sets the camera in the defaul position */ +-(void) restore; +/** Sets the camera using gluLookAt using its eye, center and up_vector */ +-(void) locate; +/** sets the eye values in points */ +-(void) setEyeX: (float)x eyeY:(float)y eyeZ:(float)z; +/** sets the center values in points */ +-(void) setCenterX: (float)x centerY:(float)y centerZ:(float)z; +/** sets the up values */ +-(void) setUpX: (float)x upY:(float)y upZ:(float)z; + +/** get the eye vector values in points */ +-(void) eyeX:(float*)x eyeY:(float*)y eyeZ:(float*)z; +/** get the center vector values in points */ +-(void) centerX:(float*)x centerY:(float*)y centerZ:(float*)z; +/** get the up vector values */ +-(void) upX:(float*)x upY:(float*)y upZ:(float*)z; + + +@end diff --git a/tweejump/libs/cocos2d/CCCamera.m b/tweejump/libs/cocos2d/CCCamera.m new file mode 100755 index 0000000..1ef6655 --- /dev/null +++ b/tweejump/libs/cocos2d/CCCamera.m @@ -0,0 +1,131 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-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. + */ + + +#import "Platforms/CCGL.h" +#import "CCCamera.h" +#import "ccMacros.h" +#import "CCDrawingPrimitives.h" + +@implementation CCCamera + +@synthesize dirty = dirty_; + +-(id) init +{ + if( (self=[super init]) ) + [self restore]; + + return self; +} + +- (NSString*) description +{ + return [NSString stringWithFormat:@"<%@ = %08X | center = (%.2f,%.2f,%.2f)>", [self class], self, centerX_, centerY_, centerZ_]; +} + + +- (void) dealloc +{ + CCLOGINFO(@"cocos2d: deallocing %@", self); + [super dealloc]; +} + +-(void) restore +{ + eyeX_ = eyeY_ = 0; + eyeZ_ = [CCCamera getZEye]; + + centerX_ = centerY_ = centerZ_ = 0; + + upX_ = 0.0f; + upY_ = 1.0f; + upZ_ = 0.0f; + + dirty_ = NO; +} + +-(void) locate +{ + if( dirty_ ) + gluLookAt( eyeX_, eyeY_, eyeZ_, + centerX_, centerY_, centerZ_, + upX_, upY_, upZ_ + ); +} + ++(float) getZEye +{ + return FLT_EPSILON; +// CGSize s = [[CCDirector sharedDirector] displaySize]; +// return ( s.height / 1.1566f ); +} + +-(void) setEyeX: (float)x eyeY:(float)y eyeZ:(float)z +{ + eyeX_ = x * CC_CONTENT_SCALE_FACTOR(); + eyeY_ = y * CC_CONTENT_SCALE_FACTOR(); + eyeZ_ = z * CC_CONTENT_SCALE_FACTOR(); + dirty_ = YES; +} + +-(void) setCenterX: (float)x centerY:(float)y centerZ:(float)z +{ + centerX_ = x * CC_CONTENT_SCALE_FACTOR(); + centerY_ = y * CC_CONTENT_SCALE_FACTOR(); + centerZ_ = z * CC_CONTENT_SCALE_FACTOR(); + dirty_ = YES; +} + +-(void) setUpX: (float)x upY:(float)y upZ:(float)z +{ + upX_ = x; + upY_ = y; + upZ_ = z; + dirty_ = YES; +} + +-(void) eyeX: (float*)x eyeY:(float*)y eyeZ:(float*)z +{ + *x = eyeX_ / CC_CONTENT_SCALE_FACTOR(); + *y = eyeY_ / CC_CONTENT_SCALE_FACTOR(); + *z = eyeZ_ / CC_CONTENT_SCALE_FACTOR(); +} + +-(void) centerX: (float*)x centerY:(float*)y centerZ:(float*)z +{ + *x = centerX_ / CC_CONTENT_SCALE_FACTOR(); + *y = centerY_ / CC_CONTENT_SCALE_FACTOR(); + *z = centerZ_ / CC_CONTENT_SCALE_FACTOR(); +} + +-(void) upX: (float*)x upY:(float*)y upZ:(float*)z +{ + *x = upX_; + *y = upY_; + *z = upZ_; +} + +@end diff --git a/tweejump/libs/cocos2d/CCConfiguration.h b/tweejump/libs/cocos2d/CCConfiguration.h new file mode 100755 index 0000000..04e1b55 --- /dev/null +++ b/tweejump/libs/cocos2d/CCConfiguration.h @@ -0,0 +1,116 @@ +/* + * 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. + */ + +#import + +#import "Platforms/CCGL.h" + +/** OS version definitions. Includes both iOS and Mac OS versions + */ +enum { + kCCiOSVersion_3_0 = 0x03000000, + kCCiOSVersion_3_1 = 0x03010000, + kCCiOSVersion_3_1_1 = 0x03010100, + kCCiOSVersion_3_1_2 = 0x03010200, + kCCiOSVersion_3_1_3 = 0x03010300, + kCCiOSVersion_3_2 = 0x03020000, + kCCiOSVersion_3_2_1 = 0x03020100, + kCCiOSVersion_4_0 = 0x04000000, + kCCiOSVersion_4_0_1 = 0x04000100, + kCCiOSVersion_4_1 = 0x04010000, + kCCiOSVersion_4_2 = 0x04020000, + kCCiOSVersion_4_3 = 0x04030000, + kCCiOSVersion_4_3_1 = 0x04030100, + kCCiOSVersion_4_3_2 = 0x04030200, + kCCiOSVersion_4_3_3 = 0x04030300, + + kCCMacVersion_10_5 = 0x0a050000, + kCCMacVersion_10_6 = 0x0a060000, + kCCMacVersion_10_7 = 0x0a070000, +}; + +/** + CCConfiguration contains some openGL variables + @since v0.99.0 + */ +@interface CCConfiguration : NSObject { + + GLint maxTextureSize_; + GLint maxModelviewStackDepth_; + BOOL supportsPVRTC_; + BOOL supportsNPOT_; + BOOL supportsBGRA8888_; + BOOL supportsDiscardFramebuffer_; + unsigned int OSVersion_; + GLint maxSamplesAllowed_; +} + +/** OpenGL Max texture size. */ +@property (nonatomic, readonly) GLint maxTextureSize; + +/** OpenGL Max Modelview Stack Depth. */ +@property (nonatomic, readonly) GLint maxModelviewStackDepth; + +/** Whether or not the GPU supports NPOT (Non Power Of Two) textures. + NPOT textures have the following limitations: + - They can't have mipmaps + - They only accept GL_CLAMP_TO_EDGE in GL_TEXTURE_WRAP_{S,T} + + @since v0.99.2 + */ +@property (nonatomic, readonly) BOOL supportsNPOT; + +/** Whether or not PVR Texture Compressed is supported */ +@property (nonatomic, readonly) BOOL supportsPVRTC; + +/** Whether or not BGRA8888 textures are supported. + + @since v0.99.2 + */ +@property (nonatomic, readonly) BOOL supportsBGRA8888; + +/** Whether or not glDiscardFramebufferEXT is supported + + @since v0.99.2 + */ +@property (nonatomic, readonly) BOOL supportsDiscardFramebuffer; + +/** returns the OS version. + - On iOS devices it returns the firmware version. + - On Mac returns the OS version + + @since v0.99.5 + */ +@property (nonatomic, readonly) unsigned int OSVersion; + +/** returns a shared instance of the CCConfiguration */ ++(CCConfiguration *) sharedConfiguration; + +/** returns whether or not an OpenGL is supported */ +- (BOOL) checkForGLExtension:(NSString *)searchName; + + + +@end diff --git a/tweejump/libs/cocos2d/CCConfiguration.m b/tweejump/libs/cocos2d/CCConfiguration.m new file mode 100755 index 0000000..d51cd58 --- /dev/null +++ b/tweejump/libs/cocos2d/CCConfiguration.m @@ -0,0 +1,193 @@ +/* + * 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. + */ + +#import + +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED +#import // Needed for UIDevice +#endif + +#import "Platforms/CCGL.h" +#import "CCBlockSupport.h" +#import "CCConfiguration.h" +#import "ccMacros.h" +#import "ccConfig.h" +#import "Support/OpenGL_Internal.h" + +@implementation CCConfiguration + +@synthesize maxTextureSize = maxTextureSize_; +@synthesize supportsPVRTC = supportsPVRTC_; +@synthesize maxModelviewStackDepth = maxModelviewStackDepth_; +@synthesize supportsNPOT = supportsNPOT_; +@synthesize supportsBGRA8888 = supportsBGRA8888_; +@synthesize supportsDiscardFramebuffer = supportsDiscardFramebuffer_; +@synthesize OSVersion = OSVersion_; + +// +// singleton stuff +// +static CCConfiguration *_sharedConfiguration = nil; + +static char * glExtensions; + ++ (CCConfiguration *)sharedConfiguration +{ + if (!_sharedConfiguration) + _sharedConfiguration = [[self alloc] init]; + + return _sharedConfiguration; +} + ++(id)alloc +{ + NSAssert(_sharedConfiguration == nil, @"Attempted to allocate a second instance of a singleton."); + return [super alloc]; +} + + +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED +#elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED) +- (NSString*)getMacVersion +{ + SInt32 versionMajor, versionMinor, versionBugFix; + Gestalt(gestaltSystemVersionMajor, &versionMajor); + Gestalt(gestaltSystemVersionMinor, &versionMinor); + Gestalt(gestaltSystemVersionBugFix, &versionBugFix); + + return [NSString stringWithFormat:@"%d.%d.%d", versionMajor, versionMinor, versionBugFix]; +} +#endif // __MAC_OS_X_VERSION_MAX_ALLOWED + +-(id) init +{ + if( (self=[super init])) { + + // Obtain iOS version + OSVersion_ = 0; +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED + NSString *OSVer = [[UIDevice currentDevice] systemVersion]; +#elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED) + NSString *OSVer = [self getMacVersion]; +#endif + NSArray *arr = [OSVer componentsSeparatedByString:@"."]; + int idx=0x01000000; + for( NSString *str in arr ) { + int value = [str intValue]; + OSVersion_ += value * idx; + idx = idx >> 8; + } + CCLOG(@"cocos2d: OS version: %@ (0x%08x)", OSVer, OSVersion_); + + CCLOG(@"cocos2d: GL_VENDOR: %s", glGetString(GL_VENDOR) ); + CCLOG(@"cocos2d: GL_RENDERER: %s", glGetString ( GL_RENDERER ) ); + CCLOG(@"cocos2d: GL_VERSION: %s", glGetString ( GL_VERSION ) ); + + glExtensions = (char*) glGetString(GL_EXTENSIONS); + + glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize_); + glGetIntegerv(GL_MAX_MODELVIEW_STACK_DEPTH, &maxModelviewStackDepth_); +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED + if( OSVersion_ >= kCCiOSVersion_4_0 ) + glGetIntegerv(GL_MAX_SAMPLES_APPLE, &maxSamplesAllowed_); + else + maxSamplesAllowed_ = 0; +#elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED) + glGetIntegerv(GL_MAX_SAMPLES, &maxSamplesAllowed_); +#endif + + supportsPVRTC_ = [self checkForGLExtension:@"GL_IMG_texture_compression_pvrtc"]; +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED + supportsNPOT_ = [self checkForGLExtension:@"GL_APPLE_texture_2D_limited_npot"]; +#elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED) + supportsNPOT_ = [self checkForGLExtension:@"GL_ARB_texture_non_power_of_two"]; +#endif + // It seems that somewhere between firmware iOS 3.0 and 4.2 Apple renamed + // GL_IMG_... to GL_APPLE.... So we should check both names + +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED + BOOL bgra8a = [self checkForGLExtension:@"GL_IMG_texture_format_BGRA8888"]; + BOOL bgra8b = [self checkForGLExtension:@"GL_APPLE_texture_format_BGRA8888"]; + supportsBGRA8888_ = bgra8a | bgra8b; +#elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED) + supportsBGRA8888_ = [self checkForGLExtension:@"GL_EXT_bgra"]; +#endif + + supportsDiscardFramebuffer_ = [self checkForGLExtension:@"GL_EXT_discard_framebuffer"]; + + CCLOG(@"cocos2d: GL_MAX_TEXTURE_SIZE: %d", maxTextureSize_); + CCLOG(@"cocos2d: GL_MAX_MODELVIEW_STACK_DEPTH: %d",maxModelviewStackDepth_); + CCLOG(@"cocos2d: GL_MAX_SAMPLES: %d", maxSamplesAllowed_); + CCLOG(@"cocos2d: GL supports PVRTC: %s", (supportsPVRTC_ ? "YES" : "NO") ); + CCLOG(@"cocos2d: GL supports BGRA8888 textures: %s", (supportsBGRA8888_ ? "YES" : "NO") ); + CCLOG(@"cocos2d: GL supports NPOT textures: %s", (supportsNPOT_ ? "YES" : "NO") ); + CCLOG(@"cocos2d: GL supports discard_framebuffer: %s", (supportsDiscardFramebuffer_ ? "YES" : "NO") ); + CCLOG(@"cocos2d: compiled with NPOT support: %s", +#if CC_TEXTURE_NPOT_SUPPORT + "YES" +#else + "NO" +#endif + ); + CCLOG(@"cocos2d: compiled with VBO support in TextureAtlas : %s", +#if CC_USES_VBO + "YES" +#else + "NO" +#endif + ); + + CCLOG(@"cocos2d: compiled with Affine Matrix transformation in CCNode : %s", +#if CC_NODE_TRANSFORM_USING_AFFINE_MATRIX + "YES" +#else + "NO" +#endif + ); + + CCLOG(@"cocos2d: compiled with Profiling Support: %s", +#if CC_ENABLE_PROFILERS + + "YES - *** Disable it when you finish profiling ***" +#else + "NO" +#endif + ); + + CHECK_GL_ERROR(); + } + + return self; +} + +- (BOOL) checkForGLExtension:(NSString *)searchName +{ + // For best results, extensionsNames should be stored in your renderer so that it does not + // need to be recreated on each invocation. + NSString *extensionsString = [NSString stringWithCString:glExtensions encoding: NSASCIIStringEncoding]; + NSArray *extensionsNames = [extensionsString componentsSeparatedByString:@" "]; + return [extensionsNames containsObject: searchName]; +} +@end diff --git a/tweejump/libs/cocos2d/CCDirector.h b/tweejump/libs/cocos2d/CCDirector.h new file mode 100755 index 0000000..5a4424f --- /dev/null +++ b/tweejump/libs/cocos2d/CCDirector.h @@ -0,0 +1,309 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-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. + */ + + +#import "ccConfig.h" +#import "ccTypes.h" + +// OpenGL related +#import "Platforms/CCGL.h" +#import "CCProtocols.h" + +/** @typedef ccDirectorProjection + Possible OpenGL projections used by director + */ +typedef enum { + /// sets a 2D projection (orthogonal projection). + kCCDirectorProjection2D, + + /// sets a 3D projection with a fovy=60, znear=0.5f and zfar=1500. + kCCDirectorProjection3D, + + /// it calls "updateProjection" on the projection delegate. + kCCDirectorProjectionCustom, + + /// Detault projection is 3D projection + kCCDirectorProjectionDefault = kCCDirectorProjection3D, + + // backward compatibility stuff + CCDirectorProjection2D = kCCDirectorProjection2D, + CCDirectorProjection3D = kCCDirectorProjection3D, + CCDirectorProjectionCustom = kCCDirectorProjectionCustom, + +} ccDirectorProjection; + + +@class CCLabelAtlas; +@class CCScene; + +/**Class that creates and handle the main Window and manages how +and when to execute the Scenes. + + The CCDirector is also resposible for: + - initializing the OpenGL ES context + - setting the OpenGL pixel format (default on is RGB565) + - setting the OpenGL buffer depth (default one is 0-bit) + - setting the projection (default one is 3D) + - setting the orientation (default one is Protrait) + + Since the CCDirector is a singleton, the standard way to use it is by calling: + - [[CCDirector sharedDirector] methodName]; + + The CCDirector also sets the default OpenGL context: + - GL_TEXTURE_2D is enabled + - GL_VERTEX_ARRAY is enabled + - GL_COLOR_ARRAY is enabled + - GL_TEXTURE_COORD_ARRAY is enabled +*/ +@interface CCDirector : NSObject +{ + CC_GLVIEW *openGLView_; + + // internal timer + NSTimeInterval animationInterval_; + NSTimeInterval oldAnimationInterval_; + + /* display FPS ? */ + BOOL displayFPS_; + + NSUInteger frames_; + NSUInteger totalFrames_; + + ccTime accumDt_; + ccTime frameRate_; +#if CC_DIRECTOR_FAST_FPS + CCLabelAtlas *FPSLabel_; +#endif + + /* is the running scene paused */ + BOOL isPaused_; + + /* The running scene */ + CCScene *runningScene_; + + /* This object will be visited after the scene. Useful to hook a notification node */ + id notificationNode_; + + /* will be the next 'runningScene' in the next frame + nextScene is a weak reference. */ + CCScene *nextScene_; + + /* If YES, then "old" scene will receive the cleanup message */ + BOOL sendCleanupToScene_; + + /* scheduled scenes */ + NSMutableArray *scenesStack_; + + /* last time the main loop was updated */ + struct timeval lastUpdate_; + /* delta time since last tick to main loop */ + ccTime dt; + /* whether or not the next delta time will be zero */ + BOOL nextDeltaTimeZero_; + + /* projection used */ + ccDirectorProjection projection_; + + /* Projection protocol delegate */ + id projectionDelegate_; + + /* window size in points */ + CGSize winSizeInPoints_; + + /* window size in pixels */ + CGSize winSizeInPixels_; + + /* the cocos2d running thread */ + NSThread *runningThread_; + + // profiler +#if CC_ENABLE_PROFILERS + ccTime accumDtForProfiler_; +#endif +} + +/** returns the cocos2d thread. + If you want to run any cocos2d task, run it in this thread. + On iOS usually it is the main thread. + @since v0.99.5 + */ +@property (readonly, nonatomic ) NSThread *runningThread; +/** The current running Scene. Director can only run one Scene at the time */ +@property (nonatomic,readonly) CCScene* runningScene; +/** The FPS value */ +@property (nonatomic,readwrite, assign) NSTimeInterval animationInterval; +/** Whether or not to display the FPS on the bottom-left corner */ +@property (nonatomic,readwrite, assign) BOOL displayFPS; +/** The OpenGLView, where everything is rendered */ +@property (nonatomic,readwrite,retain) CC_GLVIEW *openGLView; +/** whether or not the next delta time will be zero */ +@property (nonatomic,readwrite,assign) BOOL nextDeltaTimeZero; +/** Whether or not the Director is paused */ +@property (nonatomic,readonly) BOOL isPaused; +/** Sets an OpenGL projection + @since v0.8.2 + */ +@property (nonatomic,readwrite) ccDirectorProjection projection; +/** How many frames were called since the director started */ +@property (nonatomic,readonly) NSUInteger totalFrames; + +/** Whether or not the replaced scene will receive the cleanup message. + If the new scene is pushed, then the old scene won't receive the "cleanup" message. + If the new scene replaces the old one, the it will receive the "cleanup" message. + @since v0.99.0 + */ +@property (nonatomic, readonly) BOOL sendCleanupToScene; + +/** This object will be visited after the main scene is visited. + This object MUST implement the "visit" selector. + Useful to hook a notification object, like CCNotifications (http://github.com/manucorporat/CCNotifications) + @since v0.99.5 + */ +@property (nonatomic, readwrite, retain) id notificationNode; + +/** This object will be called when the OpenGL projection is udpated and only when the kCCDirectorProjectionCustom projection is used. + @since v0.99.5 + */ +@property (nonatomic, readwrite, retain) id projectionDelegate; + +/** returns a shared instance of the director */ ++(CCDirector *)sharedDirector; + + + +// Window size + +/** returns the size of the OpenGL view in points. + It takes into account any possible rotation (device orientation) of the window + */ +- (CGSize) winSize; + +/** returns the size of the OpenGL view in pixels. + It takes into account any possible rotation (device orientation) of the window. + On Mac winSize and winSizeInPixels return the same value. + */ +- (CGSize) winSizeInPixels; +/** returns the display size of the OpenGL view in pixels. + It doesn't take into account any possible rotation of the window. + */ +-(CGSize) displaySizeInPixels; +/** changes the projection size */ +-(void) reshapeProjection:(CGSize)newWindowSize; + +/** converts a UIKit coordinate to an OpenGL coordinate + Useful to convert (multi) touchs coordinates to the current layout (portrait or landscape) + */ +-(CGPoint) convertToGL: (CGPoint) p; +/** converts an OpenGL coordinate to a UIKit coordinate + Useful to convert node points to window points for calls such as glScissor + */ +-(CGPoint) convertToUI:(CGPoint)p; + +/// XXX: missing description +-(float) getZEye; + +// Scene Management + +/**Enters the Director's main loop with the given Scene. + * Call it to run only your FIRST scene. + * Don't call it if there is already a running scene. + */ +- (void) runWithScene:(CCScene*) scene; + +/**Suspends the execution of the running scene, pushing it on the stack of suspended scenes. + * The new scene will be executed. + * Try to avoid big stacks of pushed scenes to reduce memory allocation. + * ONLY call it if there is a running scene. + */ +- (void) pushScene:(CCScene*) scene; + +/**Pops out a scene from the queue. + * This scene will replace the running one. + * The running scene will be deleted. If there are no more scenes in the stack the execution is terminated. + * ONLY call it if there is a running scene. + */ +- (void) popScene; + +/** Replaces the running scene with a new one. The running scene is terminated. + * ONLY call it if there is a running scene. + */ +-(void) replaceScene: (CCScene*) scene; + +/** Ends the execution, releases the running scene. + It doesn't remove the OpenGL view from its parent. You have to do it manually. + */ +-(void) end; + +/** Pauses the running scene. + The running scene will be _drawed_ but all scheduled timers will be paused + While paused, the draw rate will be 4 FPS to reduce CPU consuption + */ +-(void) pause; + +/** Resumes the paused scene + The scheduled timers will be activated again. + The "delta time" will be 0 (as if the game wasn't paused) + */ +-(void) resume; + +/** Stops the animation. Nothing will be drawn. The main loop won't be triggered anymore. + If you wan't to pause your animation call [pause] instead. + */ +-(void) stopAnimation; + +/** The main loop is triggered again. + Call this function only if [stopAnimation] was called earlier + @warning Dont' call this function to start the main loop. To run the main loop call runWithScene + */ +-(void) startAnimation; + +/** Draw the scene. + This method is called every frame. Don't call it manually. + */ +-(void) drawScene; + +// Memory Helper + +/** Removes all the cocos2d data that was cached automatically. + It will purge the CCTextureCache, CCLabelBMFont cache. + IMPORTANT: The CCSpriteFrameCache won't be purged. If you want to purge it, you have to purge it manually. + @since v0.99.3 + */ +-(void) purgeCachedData; + +// OpenGL Helper + +/** sets the OpenGL default values */ +-(void) setGLDefaultValues; + +/** enables/disables OpenGL alpha blending */ +- (void) setAlphaBlending: (BOOL) on; +/** enables/disables OpenGL depth test */ +- (void) setDepthTest: (BOOL) on; + +// Profiler +-(void) showProfilers; + +@end diff --git a/tweejump/libs/cocos2d/CCDirector.m b/tweejump/libs/cocos2d/CCDirector.m new file mode 100755 index 0000000..6640f37 --- /dev/null +++ b/tweejump/libs/cocos2d/CCDirector.m @@ -0,0 +1,565 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-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. + */ + + +/* Idea of decoupling Window from Director taken from OC3D project: http://code.google.com/p/oc3d/ + */ + +#import +#import + +// cocos2d imports +#import "CCDirector.h" +#import "CCScheduler.h" +#import "CCActionManager.h" +#import "CCTextureCache.h" +#import "CCAnimationCache.h" +#import "CCLabelAtlas.h" +#import "ccMacros.h" +#import "CCTransition.h" +#import "CCScene.h" +#import "CCSpriteFrameCache.h" +#import "CCTexture2D.h" +#import "CCLabelBMFont.h" +#import "CCLayer.h" + +// support imports +#import "Platforms/CCGL.h" +#import "Platforms/CCNS.h" + +#import "Support/OpenGL_Internal.h" +#import "Support/CGPointExtension.h" + +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED +#import "Platforms/iOS/CCDirectorIOS.h" +#define CC_DIRECTOR_DEFAULT CCDirectorTimer +#elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED) +#import "Platforms/Mac/CCDirectorMac.h" +#define CC_DIRECTOR_DEFAULT CCDirectorDisplayLink +#endif + +#import "Support/CCProfiling.h" + +#define kDefaultFPS 60.0 // 60 frames per second + +extern NSString * cocos2dVersion(void); + + +@interface CCDirector (Private) +-(void) setNextScene; +// shows the FPS in the screen +-(void) showFPS; +// calculates delta time since last time it was called +-(void) calculateDeltaTime; +@end + +@implementation CCDirector + +@synthesize animationInterval = animationInterval_; +@synthesize runningScene = runningScene_; +@synthesize displayFPS = displayFPS_; +@synthesize nextDeltaTimeZero = nextDeltaTimeZero_; +@synthesize isPaused = isPaused_; +@synthesize sendCleanupToScene = sendCleanupToScene_; +@synthesize runningThread = runningThread_; +@synthesize notificationNode = notificationNode_; +@synthesize projectionDelegate = projectionDelegate_; +@synthesize totalFrames = totalFrames_; +// +// singleton stuff +// +static CCDirector *_sharedDirector = nil; + ++ (CCDirector *)sharedDirector +{ + if (!_sharedDirector) { + + // + // Default Director is TimerDirector + // + if( [ [CCDirector class] isEqual:[self class]] ) + _sharedDirector = [[CC_DIRECTOR_DEFAULT alloc] init]; + else + _sharedDirector = [[self alloc] init]; + } + + return _sharedDirector; +} + ++(id)alloc +{ + NSAssert(_sharedDirector == nil, @"Attempted to allocate a second instance of a singleton."); + return [super alloc]; +} + +- (id) init +{ + CCLOG(@"cocos2d: %@", cocos2dVersion() ); + + if( (self=[super init]) ) { + + CCLOG(@"cocos2d: Using Director Type:%@", [self class]); + + // scenes + runningScene_ = nil; + nextScene_ = nil; + + notificationNode_ = nil; + + oldAnimationInterval_ = animationInterval_ = 1.0 / kDefaultFPS; + scenesStack_ = [[NSMutableArray alloc] initWithCapacity:10]; + + // Set default projection (3D) + projection_ = kCCDirectorProjectionDefault; + + // projection delegate if "Custom" projection is used + projectionDelegate_ = nil; + + // FPS + displayFPS_ = NO; + totalFrames_ = frames_ = 0; + + // paused ? + isPaused_ = NO; + + // running thread + runningThread_ = nil; + + winSizeInPixels_ = winSizeInPoints_ = CGSizeZero; + } + + return self; +} + +- (void) dealloc +{ + CCLOGINFO(@"cocos2d: deallocing %@", self); + +#if CC_DIRECTOR_FAST_FPS + [FPSLabel_ release]; +#endif + [runningScene_ release]; + [notificationNode_ release]; + [scenesStack_ release]; + + [projectionDelegate_ release]; + + _sharedDirector = nil; + + [super dealloc]; +} + +-(void) setGLDefaultValues +{ + // This method SHOULD be called only after openGLView_ was initialized + NSAssert( openGLView_, @"openGLView_ must be initialized"); + + [self setAlphaBlending: YES]; + [self setDepthTest: YES]; + [self setProjection: projection_]; + + // set other opengl default values + glClearColor(0.0f, 0.0f, 0.0f, 1.0f); + +#if CC_DIRECTOR_FAST_FPS + if (!FPSLabel_) { + CCTexture2DPixelFormat currentFormat = [CCTexture2D defaultAlphaPixelFormat]; + [CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA4444]; + FPSLabel_ = [[CCLabelAtlas labelWithString:@"00.0" charMapFile:@"fps_images.png" itemWidth:16 itemHeight:24 startCharMap:'.'] retain]; + [CCTexture2D setDefaultAlphaPixelFormat:currentFormat]; + } +#endif // CC_DIRECTOR_FAST_FPS +} + +// +// Draw the Scene +// +- (void) drawScene +{ + // Override me +} + +-(void) calculateDeltaTime +{ + struct timeval now; + + if( gettimeofday( &now, NULL) != 0 ) { + CCLOG(@"cocos2d: error in gettimeofday"); + dt = 0; + return; + } + + // new delta time + if( nextDeltaTimeZero_ ) { + dt = 0; + nextDeltaTimeZero_ = NO; + } else { + dt = (now.tv_sec - lastUpdate_.tv_sec) + (now.tv_usec - lastUpdate_.tv_usec) / 1000000.0f; + dt = MAX(0,dt); + } + +#ifdef DEBUG + // If we are debugging our code, prevent big delta time + if( dt > 0.2f ) + dt = 1/60.0f; +#endif + + lastUpdate_ = now; +} + +#pragma mark Director - Memory Helper + +-(void) purgeCachedData +{ + [CCLabelBMFont purgeCachedData]; + [[CCTextureCache sharedTextureCache] removeUnusedTextures]; +} + +#pragma mark Director - Scene OpenGL Helper + +-(ccDirectorProjection) projection +{ + return projection_; +} + +-(float) getZEye +{ + return ( winSizeInPixels_.height / 1.1566f ); +} + +-(void) setProjection:(ccDirectorProjection)projection +{ + CCLOG(@"cocos2d: override me"); +} + +- (void) setAlphaBlending: (BOOL) on +{ + if (on) { + glEnable(GL_BLEND); + glBlendFunc(CC_BLEND_SRC, CC_BLEND_DST); + + } else + glDisable(GL_BLEND); +} + +- (void) setDepthTest: (BOOL) on +{ + if (on) { + ccglClearDepth(1.0f); + glEnable(GL_DEPTH_TEST); + glDepthFunc(GL_LEQUAL); +// glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); + } else + glDisable( GL_DEPTH_TEST ); +} + +#pragma mark Director Integration with a UIKit view + +-(CC_GLVIEW*) openGLView +{ + return openGLView_; +} + +-(void) setOpenGLView:(CC_GLVIEW *)view +{ + NSAssert( view, @"OpenGLView must be non-nil"); + + if( view != openGLView_ ) { + [openGLView_ release]; + openGLView_ = [view retain]; + + // set size + winSizeInPixels_ = winSizeInPoints_ = CCNSSizeToCGSize( [view bounds].size ); + + [self setGLDefaultValues]; + } +} + +#pragma mark Director Scene Landscape + +-(CGPoint)convertToGL:(CGPoint)uiPoint +{ + CCLOG(@"CCDirector#convertToGL: OVERRIDE ME."); + return CGPointZero; +} + +-(CGPoint)convertToUI:(CGPoint)glPoint +{ + CCLOG(@"CCDirector#convertToUI: OVERRIDE ME."); + return CGPointZero; +} + +-(CGSize)winSize +{ + return winSizeInPoints_; +} + +-(CGSize)winSizeInPixels +{ + return winSizeInPixels_; +} + +-(CGSize)displaySizeInPixels +{ + return winSizeInPixels_; +} + +-(void) reshapeProjection:(CGSize)newWindowSize +{ + winSizeInPixels_ = winSizeInPoints_ = newWindowSize; + [self setProjection:projection_]; +} + +#pragma mark Director Scene Management + +- (void)runWithScene:(CCScene*) scene +{ + NSAssert( scene != nil, @"Argument must be non-nil"); + NSAssert( runningScene_ == nil, @"You can't run an scene if another Scene is running. Use replaceScene or pushScene instead"); + + [self pushScene:scene]; + [self startAnimation]; +} + +-(void) replaceScene: (CCScene*) scene +{ + NSAssert( scene != nil, @"Argument must be non-nil"); + + NSUInteger index = [scenesStack_ count]; + + sendCleanupToScene_ = YES; + [scenesStack_ replaceObjectAtIndex:index-1 withObject:scene]; + nextScene_ = scene; // nextScene_ is a weak ref +} + +- (void) pushScene: (CCScene*) scene +{ + NSAssert( scene != nil, @"Argument must be non-nil"); + + sendCleanupToScene_ = NO; + + [scenesStack_ addObject: scene]; + nextScene_ = scene; // nextScene_ is a weak ref +} + +-(void) popScene +{ + NSAssert( runningScene_ != nil, @"A running Scene is needed"); + + [scenesStack_ removeLastObject]; + NSUInteger c = [scenesStack_ count]; + + if( c == 0 ) + [self end]; + else { + sendCleanupToScene_ = YES; + nextScene_ = [scenesStack_ objectAtIndex:c-1]; + } +} + +-(void) end +{ + [runningScene_ onExit]; + [runningScene_ cleanup]; + [runningScene_ release]; + + runningScene_ = nil; + nextScene_ = nil; + + // remove all objects, but don't release it. + // runWithScene might be executed after 'end'. + [scenesStack_ removeAllObjects]; + + [self stopAnimation]; + +#if CC_DIRECTOR_FAST_FPS + [FPSLabel_ release]; + FPSLabel_ = nil; +#endif + + [projectionDelegate_ release]; + projectionDelegate_ = nil; + + // Purge bitmap cache + [CCLabelBMFont purgeCachedData]; + + // Purge all managers + [CCAnimationCache purgeSharedAnimationCache]; + [CCSpriteFrameCache purgeSharedSpriteFrameCache]; + [CCScheduler purgeSharedScheduler]; + [CCActionManager purgeSharedManager]; + [CCTextureCache purgeSharedTextureCache]; + + + // OpenGL view + + // Since the director doesn't attach the openglview to the window + // it shouldn't remove it from the window too. +// [openGLView_ removeFromSuperview]; + + [openGLView_ release]; + openGLView_ = nil; +} + +-(void) setNextScene +{ + Class transClass = [CCTransitionScene class]; + BOOL runningIsTransition = [runningScene_ isKindOfClass:transClass]; + BOOL newIsTransition = [nextScene_ isKindOfClass:transClass]; + + // If it is not a transition, call onExit/cleanup + if( ! newIsTransition ) { + [runningScene_ onExit]; + + // issue #709. the root node (scene) should receive the cleanup message too + // otherwise it might be leaked. + if( sendCleanupToScene_) + [runningScene_ cleanup]; + } + + [runningScene_ release]; + + runningScene_ = [nextScene_ retain]; + nextScene_ = nil; + + if( ! runningIsTransition ) { + [runningScene_ onEnter]; + [runningScene_ onEnterTransitionDidFinish]; + } +} + +-(void) pause +{ + if( isPaused_ ) + return; + + oldAnimationInterval_ = animationInterval_; + + // when paused, don't consume CPU + [self setAnimationInterval:1/4.0]; + isPaused_ = YES; +} + +-(void) resume +{ + if( ! isPaused_ ) + return; + + [self setAnimationInterval: oldAnimationInterval_]; + + if( gettimeofday( &lastUpdate_, NULL) != 0 ) { + CCLOG(@"cocos2d: Director: Error in gettimeofday"); + } + + isPaused_ = NO; + dt = 0; +} + +- (void)startAnimation +{ + CCLOG(@"cocos2d: Director#startAnimation. Override me"); +} + +- (void)stopAnimation +{ + CCLOG(@"cocos2d: Director#stopAnimation. Override me"); +} + +- (void)setAnimationInterval:(NSTimeInterval)interval +{ + CCLOG(@"cocos2d: Director#setAnimationInterval. Override me"); +} + +#if CC_DIRECTOR_FAST_FPS + +// display the FPS using a LabelAtlas +// updates the FPS every frame +-(void) showFPS +{ + frames_++; + accumDt_ += dt; + + if ( accumDt_ > CC_DIRECTOR_FPS_INTERVAL) { + frameRate_ = frames_/accumDt_; + frames_ = 0; + accumDt_ = 0; + +// sprintf(format,"%.1f",frameRate); +// [FPSLabel setCString:format]; + + NSString *str = [[NSString alloc] initWithFormat:@"%.1f", frameRate_]; + [FPSLabel_ setString:str]; + [str release]; + } + + [FPSLabel_ draw]; +} +#else +// display the FPS using a manually generated Texture (very slow) +// updates the FPS 3 times per second aprox. +-(void) showFPS +{ + frames_++; + accumDt_ += dt; + + if ( accumDt_ > CC_DIRECTOR_FPS_INTERVAL) { + frameRate_ = frames_/accumDt_; + frames_ = 0; + accumDt_ = 0; + } + + NSString *str = [NSString stringWithFormat:@"%.2f",frameRate_]; + CCTexture2D *texture = [[CCTexture2D alloc] initWithString:str dimensions:CGSizeMake(100,30) alignment:CCTextAlignmentLeft fontName:@"Arial" fontSize:24]; + + // Default GL states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY + // Needed states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_TEXTURE_COORD_ARRAY + // Unneeded states: GL_COLOR_ARRAY + glDisableClientState(GL_COLOR_ARRAY); + + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + glColor4ub(224,224,244,200); + [texture drawAtPoint: ccp(5,2)]; + [texture release]; + + glBlendFunc(CC_BLEND_SRC, CC_BLEND_DST); + + // restore default GL state + glEnableClientState(GL_COLOR_ARRAY); +} +#endif + +- (void) showProfilers { +#if CC_ENABLE_PROFILERS + accumDtForProfiler_ += dt; + if (accumDtForProfiler_ > 1.0f) { + accumDtForProfiler_ = 0; + [[CCProfiler sharedProfiler] displayTimers]; + } +#endif // CC_ENABLE_PROFILERS +} + +@end + diff --git a/tweejump/libs/cocos2d/CCDrawingPrimitives.h b/tweejump/libs/cocos2d/CCDrawingPrimitives.h new file mode 100755 index 0000000..8d1dbe5 --- /dev/null +++ b/tweejump/libs/cocos2d/CCDrawingPrimitives.h @@ -0,0 +1,92 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-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. + */ + + +#ifndef __CC_DRAWING_PRIMITIVES_H +#define __CC_DRAWING_PRIMITIVES_H + +#import +#import + +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED +#import // for CGPoint +#endif + + +#ifdef __cplusplus +extern "C" { +#endif + +/** + @file + Drawing OpenGL ES primitives. + - ccDrawPoint + - ccDrawLine + - ccDrawPoly + - ccDrawCircle + - ccDrawQuadBezier + - ccDrawCubicBezier + + You can change the color, width and other property by calling the + glColor4ub(), glLineWidth(), glPointSize(). + + @warning These functions draws the Line, Point, Polygon, immediately. They aren't batched. If you are going to make a game that depends on these primitives, I suggest creating a batch. + */ + + +/** draws a point given x and y coordinate measured in points. */ +void ccDrawPoint( CGPoint point ); + +/** draws an array of points. + @since v0.7.2 + */ +void ccDrawPoints( const CGPoint *points, NSUInteger numberOfPoints ); + +/** draws a line given the origin and destination point measured in points. */ +void ccDrawLine( CGPoint origin, CGPoint destination ); + +/** draws a poligon given a pointer to CGPoint coordiantes and the number of vertices measured in points. + The polygon can be closed or open + */ +void ccDrawPoly( const CGPoint *vertices, NSUInteger numOfVertices, BOOL closePolygon ); + +/** draws a circle given the center, radius and number of segments measured in points */ +void ccDrawCircle( CGPoint center, float radius, float angle, NSUInteger segments, BOOL drawLineToCenter); + +/** draws a quad bezier path measured in points. + @since v0.8 + */ +void ccDrawQuadBezier(CGPoint origin, CGPoint control, CGPoint destination, NSUInteger segments); + +/** draws a cubic bezier path measured in points. + @since v0.8 + */ +void ccDrawCubicBezier(CGPoint origin, CGPoint control1, CGPoint control2, CGPoint destination, NSUInteger segments); + +#ifdef __cplusplus +} +#endif + +#endif // __CC_DRAWING_PRIMITIVES_H diff --git a/tweejump/libs/cocos2d/CCDrawingPrimitives.m b/tweejump/libs/cocos2d/CCDrawingPrimitives.m new file mode 100755 index 0000000..f7df2b6 --- /dev/null +++ b/tweejump/libs/cocos2d/CCDrawingPrimitives.m @@ -0,0 +1,272 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-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. + */ + +#import +#import +#import + +#import "CCDrawingPrimitives.h" +#import "ccTypes.h" +#import "ccMacros.h" +#import "Platforms/CCGL.h" + +void ccDrawPoint( CGPoint point ) +{ + ccVertex2F p = (ccVertex2F) {point.x * CC_CONTENT_SCALE_FACTOR(), point.y * CC_CONTENT_SCALE_FACTOR() }; + + // Default GL states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY + // Needed states: GL_VERTEX_ARRAY, + // Unneeded states: GL_TEXTURE_2D, GL_TEXTURE_COORD_ARRAY, GL_COLOR_ARRAY + glDisable(GL_TEXTURE_2D); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + glDisableClientState(GL_COLOR_ARRAY); + + glVertexPointer(2, GL_FLOAT, 0, &p); + glDrawArrays(GL_POINTS, 0, 1); + + // restore default state + glEnableClientState(GL_COLOR_ARRAY); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glEnable(GL_TEXTURE_2D); +} + +void ccDrawPoints( const CGPoint *points, NSUInteger numberOfPoints ) +{ + // Default GL states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY + // Needed states: GL_VERTEX_ARRAY, + // Unneeded states: GL_TEXTURE_2D, GL_TEXTURE_COORD_ARRAY, GL_COLOR_ARRAY + glDisable(GL_TEXTURE_2D); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + glDisableClientState(GL_COLOR_ARRAY); + + ccVertex2F newPoints[numberOfPoints]; + + // iPhone and 32-bit machines optimization + if( sizeof(CGPoint) == sizeof(ccVertex2F) ) { + + // points ? + if( CC_CONTENT_SCALE_FACTOR() != 1 ) { + for( NSUInteger i=0; i + +@class CCTexture2D; + +/** FBO class that grabs the the contents of the screen */ +@interface CCGrabber : NSObject +{ + GLuint fbo; + GLint oldFBO; +} + +-(void)grab:(CCTexture2D*)texture; +-(void)beforeRender:(CCTexture2D*)texture; +-(void)afterRender:(CCTexture2D*)texture; + +@end diff --git a/tweejump/libs/cocos2d/CCGrabber.m b/tweejump/libs/cocos2d/CCGrabber.m new file mode 100755 index 0000000..a259091 --- /dev/null +++ b/tweejump/libs/cocos2d/CCGrabber.m @@ -0,0 +1,95 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2009 On-Core + * + * 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. + * + */ + + +#import "Platforms/CCGL.h" +#import "CCGrabber.h" +#import "ccMacros.h" +#import "CCTexture2D.h" +#import "Support/OpenGL_Internal.h" + +@implementation CCGrabber + +-(id) init +{ + if(( self = [super init] )) { + // generate FBO + ccglGenFramebuffers(1, &fbo); + } + return self; +} + +-(void)grab:(CCTexture2D*)texture +{ + glGetIntegerv(CC_GL_FRAMEBUFFER_BINDING, &oldFBO); + + // bind + ccglBindFramebuffer(CC_GL_FRAMEBUFFER, fbo); + + // associate texture with FBO + ccglFramebufferTexture2D(CC_GL_FRAMEBUFFER, CC_GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.name, 0); + + // check if it worked (probably worth doing :) ) + GLuint status = ccglCheckFramebufferStatus(CC_GL_FRAMEBUFFER); + if (status != CC_GL_FRAMEBUFFER_COMPLETE) + [NSException raise:@"Frame Grabber" format:@"Could not attach texture to framebuffer"]; + + ccglBindFramebuffer(CC_GL_FRAMEBUFFER, oldFBO); +} + +-(void)beforeRender:(CCTexture2D*)texture +{ + glGetIntegerv(CC_GL_FRAMEBUFFER_BINDING, &oldFBO); + ccglBindFramebuffer(CC_GL_FRAMEBUFFER, fbo); + + // BUG XXX: doesn't work with RGB565. + + + glClearColor(0,0,0,0); + + // BUG #631: To fix #631, uncomment the lines with #631 + // Warning: But it CCGrabber won't work with 2 effects at the same time +// glClearColor(0.0f,0.0f,0.0f,1.0f); // #631 + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + +// glColorMask(TRUE, TRUE, TRUE, FALSE); // #631 + +} + +-(void)afterRender:(CCTexture2D*)texture +{ + ccglBindFramebuffer(CC_GL_FRAMEBUFFER, oldFBO); +// glColorMask(TRUE, TRUE, TRUE, TRUE); // #631 +} + +- (void) dealloc +{ + CCLOGINFO(@"cocos2d: deallocing %@", self); + ccglDeleteFramebuffers(1, &fbo); + [super dealloc]; +} + +@end diff --git a/tweejump/libs/cocos2d/CCGrid.h b/tweejump/libs/cocos2d/CCGrid.h new file mode 100755 index 0000000..e5e77e8 --- /dev/null +++ b/tweejump/libs/cocos2d/CCGrid.h @@ -0,0 +1,121 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2009 On-Core + * + * 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. + * + */ + + +#import + +#import "CCNode.h" +#import "CCCamera.h" +#import "ccTypes.h" + +@class CCTexture2D; +@class CCGrabber; + +/** Base class for other + */ +@interface CCGridBase : NSObject +{ + BOOL active_; + int reuseGrid_; + ccGridSize gridSize_; + CCTexture2D *texture_; + CGPoint step_; + CCGrabber *grabber_; + BOOL isTextureFlipped_; +} + +/** wheter or not the grid is active */ +@property (nonatomic,readwrite) BOOL active; +/** number of times that the grid will be reused */ +@property (nonatomic,readwrite) int reuseGrid; +/** size of the grid */ +@property (nonatomic,readonly) ccGridSize gridSize; +/** pixels between the grids */ +@property (nonatomic,readwrite) CGPoint step; +/** texture used */ +@property (nonatomic, retain) CCTexture2D *texture; +/** grabber used */ +@property (nonatomic, retain) CCGrabber *grabber; +/** is texture flipped */ +@property (nonatomic, readwrite) BOOL isTextureFlipped; + ++(id) gridWithSize:(ccGridSize)gridSize texture:(CCTexture2D*)texture flippedTexture:(BOOL)flipped; ++(id) gridWithSize:(ccGridSize)gridSize; + +-(id) initWithSize:(ccGridSize)gridSize texture:(CCTexture2D*)texture flippedTexture:(BOOL)flipped; +-(id)initWithSize:(ccGridSize)gridSize; +-(void)beforeDraw; +-(void)afterDraw:(CCNode*)target; +-(void)blit; +-(void)reuse; + +-(void)calculateVertexPoints; + +@end + +//////////////////////////////////////////////////////////// + +/** + CCGrid3D is a 3D grid implementation. Each vertex has 3 dimensions: x,y,z + */ +@interface CCGrid3D : CCGridBase +{ + GLvoid *texCoordinates; + GLvoid *vertices; + GLvoid *originalVertices; + GLushort *indices; +} + +/** returns the vertex at a given position */ +-(ccVertex3F)vertex:(ccGridSize)pos; +/** returns the original (non-transformed) vertex at a given position */ +-(ccVertex3F)originalVertex:(ccGridSize)pos; +/** sets a new vertex at a given position */ +-(void)setVertex:(ccGridSize)pos vertex:(ccVertex3F)vertex; + +@end + +//////////////////////////////////////////////////////////// + +/** + CCTiledGrid3D is a 3D grid implementation. It differs from Grid3D in that + the tiles can be separated from the grid. +*/ +@interface CCTiledGrid3D : CCGridBase +{ + GLvoid *texCoordinates; + GLvoid *vertices; + GLvoid *originalVertices; + GLushort *indices; +} + +/** returns the tile at the given position */ +-(ccQuad3)tile:(ccGridSize)pos; +/** returns the original tile (untransformed) at the given position */ +-(ccQuad3)originalTile:(ccGridSize)pos; +/** sets a new tile */ +-(void)setTile:(ccGridSize)pos coords:(ccQuad3)coords; + +@end diff --git a/tweejump/libs/cocos2d/CCGrid.m b/tweejump/libs/cocos2d/CCGrid.m new file mode 100755 index 0000000..c2ed19d --- /dev/null +++ b/tweejump/libs/cocos2d/CCGrid.m @@ -0,0 +1,571 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2009 On-Core + * + * 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. + * + */ + + +#import + +#import "ccMacros.h" +#import "CCGrid.h" +#import "CCTexture2D.h" +#import "CCDirector.h" +#import "CCGrabber.h" + +#import "Platforms/CCGL.h" +#import "Support/CGPointExtension.h" +#import "Support/ccUtils.h" + +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED +#import "Platforms/iOS/CCDirectorIOS.h" +#endif // __IPHONE_OS_VERSION_MAX_ALLOWED + +#pragma mark - +#pragma mark CCGridBase + +@implementation CCGridBase + +@synthesize reuseGrid = reuseGrid_; +@synthesize texture = texture_; +@synthesize grabber = grabber_; +@synthesize gridSize = gridSize_; +@synthesize step = step_; + ++(id) gridWithSize:(ccGridSize)gridSize texture:(CCTexture2D*)texture flippedTexture:(BOOL)flipped +{ + return [[[self alloc] initWithSize:gridSize texture:texture flippedTexture:flipped] autorelease]; +} + ++(id) gridWithSize:(ccGridSize)gridSize +{ + return [[(CCGridBase*)[self alloc] initWithSize:gridSize] autorelease]; +} + +-(id) initWithSize:(ccGridSize)gridSize texture:(CCTexture2D*)texture flippedTexture:(BOOL)flipped +{ + if( (self=[super init]) ) { + + active_ = NO; + reuseGrid_ = 0; + gridSize_ = gridSize; + + self.texture = texture; + isTextureFlipped_ = flipped; + + CGSize texSize = [texture_ contentSizeInPixels]; + step_.x = texSize.width / gridSize_.x; + step_.y = texSize.height / gridSize_.y; + + grabber_ = [[CCGrabber alloc] init]; + [grabber_ grab:texture_]; + + [self calculateVertexPoints]; + } + return self; +} + +-(id)initWithSize:(ccGridSize)gSize +{ + CCDirector *director = [CCDirector sharedDirector]; + CGSize s = [director winSizeInPixels]; + + unsigned long POTWide = ccNextPOT(s.width); + unsigned long POTHigh = ccNextPOT(s.height); + +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED + EAGLView *glview = [[CCDirector sharedDirector] openGLView]; + NSString *pixelFormat = [glview pixelFormat]; + + CCTexture2DPixelFormat format = [pixelFormat isEqualToString: kEAGLColorFormatRGB565] ? kCCTexture2DPixelFormat_RGB565 : kCCTexture2DPixelFormat_RGBA8888; +#else + CCTexture2DPixelFormat format = kCCTexture2DPixelFormat_RGBA8888; +#endif + + void *data = calloc((int)(POTWide * POTHigh * 4), 1); + if( ! data ) { + CCLOG(@"cocos2d: CCGrid: not enough memory"); + [self release]; + return nil; + } + + CCTexture2D *texture = [[CCTexture2D alloc] initWithData:data pixelFormat:format pixelsWide:POTWide pixelsHigh:POTHigh contentSize:s]; + free( data ); + + if( ! texture ) { + CCLOG(@"cocos2d: CCGrid: error creating texture"); + [self release]; + return nil; + } + + self = [self initWithSize:gSize texture:texture flippedTexture:NO]; + + [texture release]; + + return self; +} +- (NSString*) description +{ + return [NSString stringWithFormat:@"<%@ = %08X | Dimensions = %ix%i>", [self class], self, gridSize_.x, gridSize_.y]; +} + +- (void) dealloc +{ + CCLOGINFO(@"cocos2d: deallocing %@", self); + + [self setActive: NO]; + + [texture_ release]; + [grabber_ release]; + [super dealloc]; +} + +// properties +-(BOOL) active +{ + return active_; +} + +-(void) setActive:(BOOL)active +{ + active_ = active; + if( ! active ) { + CCDirector *director = [CCDirector sharedDirector]; + ccDirectorProjection proj = [director projection]; + [director setProjection:proj]; + } +} + +-(BOOL) isTextureFlipped +{ + return isTextureFlipped_; +} + +-(void) setIsTextureFlipped:(BOOL)flipped +{ + if( isTextureFlipped_ != flipped ) { + isTextureFlipped_ = flipped; + [self calculateVertexPoints]; + } +} + +// This routine can be merged with Director +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED +-(void)applyLandscape +{ + CCDirector *director = [CCDirector sharedDirector]; + + CGSize winSize = [director displaySizeInPixels]; + float w = winSize.width / 2; + float h = winSize.height / 2; + + ccDeviceOrientation orientation = [director deviceOrientation]; + + switch (orientation) { + case CCDeviceOrientationLandscapeLeft: + glTranslatef(w,h,0); + glRotatef(-90,0,0,1); + glTranslatef(-h,-w,0); + break; + case CCDeviceOrientationLandscapeRight: + glTranslatef(w,h,0); + glRotatef(90,0,0,1); + glTranslatef(-h,-w,0); + break; + case CCDeviceOrientationPortraitUpsideDown: + glTranslatef(w,h,0); + glRotatef(180,0,0,1); + glTranslatef(-w,-h,0); + break; + default: + break; + } +} +#endif + +-(void)set2DProjection +{ + CGSize winSize = [[CCDirector sharedDirector] winSizeInPixels]; + + glLoadIdentity(); + glViewport(0, 0, winSize.width, winSize.height); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + ccglOrtho(0, winSize.width, 0, winSize.height, -1024, 1024); + glMatrixMode(GL_MODELVIEW); +} + +// This routine can be merged with Director +-(void)set3DProjection +{ + CCDirector *director = [CCDirector sharedDirector]; + + CGSize winSize = [director displaySizeInPixels]; + + glViewport(0, 0, winSize.width, winSize.height); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPerspective(60, (GLfloat)winSize.width/winSize.height, 0.5f, 1500.0f); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + gluLookAt( winSize.width/2, winSize.height/2, [director getZEye], + winSize.width/2, winSize.height/2, 0, + 0.0f, 1.0f, 0.0f + ); +} + +-(void)beforeDraw +{ + [self set2DProjection]; + [grabber_ beforeRender:texture_]; +} + +-(void)afterDraw:(CCNode *)target +{ + [grabber_ afterRender:texture_]; + + [self set3DProjection]; +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED + [self applyLandscape]; +#endif + + if( target.camera.dirty ) { + + CGPoint offset = [target anchorPointInPixels]; + + // + // XXX: Camera should be applied in the AnchorPoint + // + ccglTranslate(offset.x, offset.y, 0); + [target.camera locate]; + ccglTranslate(-offset.x, -offset.y, 0); + } + + glBindTexture(GL_TEXTURE_2D, texture_.name); + + [self blit]; +} + +-(void)blit +{ + [NSException raise:@"GridBase" format:@"Abstract class needs implementation"]; +} + +-(void)reuse +{ + [NSException raise:@"GridBase" format:@"Abstract class needs implementation"]; +} + +-(void)calculateVertexPoints +{ + [NSException raise:@"GridBase" format:@"Abstract class needs implementation"]; +} + +@end + +//////////////////////////////////////////////////////////// + +#pragma mark - +#pragma mark CCGrid3D +@implementation CCGrid3D + +-(void)dealloc +{ + free(texCoordinates); + free(vertices); + free(indices); + free(originalVertices); + [super dealloc]; +} + +-(void)blit +{ + NSInteger n = gridSize_.x * gridSize_.y; + + // Default GL states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY + // Needed states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_TEXTURE_COORD_ARRAY + // Unneeded states: GL_COLOR_ARRAY + glDisableClientState(GL_COLOR_ARRAY); + + glVertexPointer(3, GL_FLOAT, 0, vertices); + glTexCoordPointer(2, GL_FLOAT, 0, texCoordinates); + glDrawElements(GL_TRIANGLES, (GLsizei) n*6, GL_UNSIGNED_SHORT, indices); + + // restore GL default state + glEnableClientState(GL_COLOR_ARRAY); +} + +-(void)calculateVertexPoints +{ + float width = (float)texture_.pixelsWide; + float height = (float)texture_.pixelsHigh; + float imageH = texture_.contentSizeInPixels.height; + + int x, y, i; + + vertices = malloc((gridSize_.x+1)*(gridSize_.y+1)*sizeof(ccVertex3F)); + originalVertices = malloc((gridSize_.x+1)*(gridSize_.y+1)*sizeof(ccVertex3F)); + texCoordinates = malloc((gridSize_.x+1)*(gridSize_.y+1)*sizeof(CGPoint)); + indices = malloc(gridSize_.x*gridSize_.y*sizeof(GLushort)*6); + + float *vertArray = (float*)vertices; + float *texArray = (float*)texCoordinates; + GLushort *idxArray = (GLushort *)indices; + + for( x = 0; x < gridSize_.x; x++ ) + { + for( y = 0; y < gridSize_.y; y++ ) + { + NSInteger idx = (y * gridSize_.x) + x; + + float x1 = x * step_.x; + float x2 = x1 + step_.x; + float y1 = y * step_.y; + float y2 = y1 + step_.y; + + GLushort a = x * (gridSize_.y+1) + y; + GLushort b = (x+1) * (gridSize_.y+1) + y; + GLushort c = (x+1) * (gridSize_.y+1) + (y+1); + GLushort d = x * (gridSize_.y+1) + (y+1); + + GLushort tempidx[6] = { a, b, d, b, c, d }; + + memcpy(&idxArray[6*idx], tempidx, 6*sizeof(GLushort)); + + int l1[4] = { a*3, b*3, c*3, d*3 }; + ccVertex3F e = {x1,y1,0}; + ccVertex3F f = {x2,y1,0}; + ccVertex3F g = {x2,y2,0}; + ccVertex3F h = {x1,y2,0}; + + ccVertex3F l2[4] = { e, f, g, h }; + + int tex1[4] = { a*2, b*2, c*2, d*2 }; + CGPoint tex2[4] = { ccp(x1, y1), ccp(x2, y1), ccp(x2, y2), ccp(x1, y2) }; + + for( i = 0; i < 4; i++ ) + { + vertArray[ l1[i] ] = l2[i].x; + vertArray[ l1[i] + 1 ] = l2[i].y; + vertArray[ l1[i] + 2 ] = l2[i].z; + + texArray[ tex1[i] ] = tex2[i].x / width; + if( isTextureFlipped_ ) + texArray[ tex1[i] + 1 ] = (imageH - tex2[i].y) / height; + else + texArray[ tex1[i] + 1 ] = tex2[i].y / height; + } + } + } + + memcpy(originalVertices, vertices, (gridSize_.x+1)*(gridSize_.y+1)*sizeof(ccVertex3F)); +} + +-(ccVertex3F)vertex:(ccGridSize)pos +{ + NSInteger index = (pos.x * (gridSize_.y+1) + pos.y) * 3; + float *vertArray = (float *)vertices; + + ccVertex3F vert = { vertArray[index], vertArray[index+1], vertArray[index+2] }; + + return vert; +} + +-(ccVertex3F)originalVertex:(ccGridSize)pos +{ + NSInteger index = (pos.x * (gridSize_.y+1) + pos.y) * 3; + float *vertArray = (float *)originalVertices; + + ccVertex3F vert = { vertArray[index], vertArray[index+1], vertArray[index+2] }; + + return vert; +} + +-(void)setVertex:(ccGridSize)pos vertex:(ccVertex3F)vertex +{ + NSInteger index = (pos.x * (gridSize_.y+1) + pos.y) * 3; + float *vertArray = (float *)vertices; + vertArray[index] = vertex.x; + vertArray[index+1] = vertex.y; + vertArray[index+2] = vertex.z; +} + +-(void)reuse +{ + if ( reuseGrid_ > 0 ) + { + memcpy(originalVertices, vertices, (gridSize_.x+1)*(gridSize_.y+1)*sizeof(ccVertex3F)); + reuseGrid_--; + } +} + +@end + +//////////////////////////////////////////////////////////// + +#pragma mark - +#pragma mark CCTiledGrid3D + +@implementation CCTiledGrid3D + +-(void)dealloc +{ + free(texCoordinates); + free(vertices); + free(indices); + free(originalVertices); + [super dealloc]; +} + +-(void)blit +{ + NSInteger n = gridSize_.x * gridSize_.y; + + // Default GL states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY + // Needed states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_TEXTURE_COORD_ARRAY + // Unneeded states: GL_COLOR_ARRAY + glDisableClientState(GL_COLOR_ARRAY); + + glVertexPointer(3, GL_FLOAT, 0, vertices); + glTexCoordPointer(2, GL_FLOAT, 0, texCoordinates); + glDrawElements(GL_TRIANGLES, (GLsizei) n*6, GL_UNSIGNED_SHORT, indices); + + // restore default GL state + glEnableClientState(GL_COLOR_ARRAY); +} + +-(void)calculateVertexPoints +{ + float width = (float)texture_.pixelsWide; + float height = (float)texture_.pixelsHigh; + float imageH = texture_.contentSizeInPixels.height; + + NSInteger numQuads = gridSize_.x * gridSize_.y; + + vertices = malloc(numQuads*12*sizeof(GLfloat)); + originalVertices = malloc(numQuads*12*sizeof(GLfloat)); + texCoordinates = malloc(numQuads*8*sizeof(GLfloat)); + indices = malloc(numQuads*6*sizeof(GLushort)); + + float *vertArray = (float*)vertices; + float *texArray = (float*)texCoordinates; + GLushort *idxArray = (GLushort *)indices; + + int x, y; + + for( x = 0; x < gridSize_.x; x++ ) + { + for( y = 0; y < gridSize_.y; y++ ) + { + float x1 = x * step_.x; + float x2 = x1 + step_.x; + float y1 = y * step_.y; + float y2 = y1 + step_.y; + + *vertArray++ = x1; + *vertArray++ = y1; + *vertArray++ = 0; + *vertArray++ = x2; + *vertArray++ = y1; + *vertArray++ = 0; + *vertArray++ = x1; + *vertArray++ = y2; + *vertArray++ = 0; + *vertArray++ = x2; + *vertArray++ = y2; + *vertArray++ = 0; + + float newY1 = y1; + float newY2 = y2; + + if( isTextureFlipped_ ) { + newY1 = imageH - y1; + newY2 = imageH - y2; + } + + *texArray++ = x1 / width; + *texArray++ = newY1 / height; + *texArray++ = x2 / width; + *texArray++ = newY1 / height; + *texArray++ = x1 / width; + *texArray++ = newY2 / height; + *texArray++ = x2 / width; + *texArray++ = newY2 / height; + } + } + + for( x = 0; x < numQuads; x++) + { + idxArray[x*6+0] = x*4+0; + idxArray[x*6+1] = x*4+1; + idxArray[x*6+2] = x*4+2; + + idxArray[x*6+3] = x*4+1; + idxArray[x*6+4] = x*4+2; + idxArray[x*6+5] = x*4+3; + } + + memcpy(originalVertices, vertices, numQuads*12*sizeof(GLfloat)); +} + +-(void)setTile:(ccGridSize)pos coords:(ccQuad3)coords +{ + NSInteger idx = (gridSize_.y * pos.x + pos.y) * 4 * 3; + float *vertArray = (float*)vertices; + memcpy(&vertArray[idx], &coords, sizeof(ccQuad3)); +} + +-(ccQuad3)originalTile:(ccGridSize)pos +{ + NSInteger idx = (gridSize_.y * pos.x + pos.y) * 4 * 3; + float *vertArray = (float*)originalVertices; + + ccQuad3 ret; + memcpy(&ret, &vertArray[idx], sizeof(ccQuad3)); + + return ret; +} + +-(ccQuad3)tile:(ccGridSize)pos +{ + NSInteger idx = (gridSize_.y * pos.x + pos.y) * 4 * 3; + float *vertArray = (float*)vertices; + + ccQuad3 ret; + memcpy(&ret, &vertArray[idx], sizeof(ccQuad3)); + + return ret; +} + +-(void)reuse +{ + if ( reuseGrid_ > 0 ) + { + NSInteger numQuads = gridSize_.x * gridSize_.y; + + memcpy(originalVertices, vertices, numQuads*12*sizeof(GLfloat)); + reuseGrid_--; + } +} + +@end diff --git a/tweejump/libs/cocos2d/CCLabelAtlas.h b/tweejump/libs/cocos2d/CCLabelAtlas.h new file mode 100755 index 0000000..7a1fe9a --- /dev/null +++ b/tweejump/libs/cocos2d/CCLabelAtlas.h @@ -0,0 +1,57 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-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. + * + */ + + +#import "CCAtlasNode.h" +#import "CCTextureAtlas.h" + +/** CCLabelAtlas is a subclass of CCAtlasNode. + + It can be as a replacement of CCLabel since it is MUCH faster. + + CCLabelAtlas versus CCLabel: + - CCLabelAtlas is MUCH faster than CCLabel + - CCLabelAtlas "characters" have a fixed height and width + - CCLabelAtlas "characters" can be anything you want since they are taken from an image file + + A more flexible class is CCLabelBMFont. It supports variable width characters and it also has a nice editor. + */ +@interface CCLabelAtlas : CCAtlasNode +{ + // string to render + NSString *string_; + + // the first char in the charmap + unsigned char mapStartChar_; +} + + +/** creates the CCLabelAtlas with a string, a char map file(the atlas), the width and height of each element in points and the starting char of the atlas */ ++(id) labelWithString:(NSString*) string charMapFile: (NSString*) charmapfile itemWidth:(NSUInteger)w itemHeight:(NSUInteger)h startCharMap:(unsigned char)c; + +/** initializes the CCLabelAtlas with a string, a char map file(the atlas), the width and height in points of each element and the starting char of the atlas */ +-(id) initWithString:(NSString*) string charMapFile: (NSString*) charmapfile itemWidth:(NSUInteger)w itemHeight:(NSUInteger)h startCharMap:(unsigned char)c; +@end diff --git a/tweejump/libs/cocos2d/CCLabelAtlas.m b/tweejump/libs/cocos2d/CCLabelAtlas.m new file mode 100755 index 0000000..a8d4f43 --- /dev/null +++ b/tweejump/libs/cocos2d/CCLabelAtlas.m @@ -0,0 +1,163 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-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. + * + */ + + +#import "ccConfig.h" +#import "ccMacros.h" +#import "CCDrawingPrimitives.h" +#import "CCLabelAtlas.h" +#import "Support/CGPointExtension.h" + + + +@implementation CCLabelAtlas + +#pragma mark CCLabelAtlas - Creation & Init ++(id) labelWithString:(NSString*)string charMapFile:(NSString*)charmapfile itemWidth:(NSUInteger)w itemHeight:(NSUInteger)h startCharMap:(unsigned char)c +{ + return [[[self alloc] initWithString:string charMapFile:charmapfile itemWidth:w itemHeight:h startCharMap:c] autorelease]; +} + +-(id) initWithString:(NSString*) theString charMapFile: (NSString*) charmapfile itemWidth:(NSUInteger)w itemHeight:(NSUInteger)h startCharMap:(unsigned char)c +{ + + if ((self=[super initWithTileFile:charmapfile tileWidth:w tileHeight:h itemsToRender:[theString length] ]) ) { + + mapStartChar_ = c; + [self setString: theString]; + } + + return self; +} + +-(void) dealloc +{ + [string_ release]; + + [super dealloc]; +} + +#pragma mark CCLabelAtlas - Atlas generation + +-(void) updateAtlasValues +{ + NSUInteger n = [string_ length]; + + ccV3F_C4B_T2F_Quad quad; + + const unsigned char *s = (unsigned char*) [string_ UTF8String]; + + CCTexture2D *texture = [textureAtlas_ texture]; + float textureWide = [texture pixelsWide]; + float textureHigh = [texture pixelsHigh]; + + for( NSUInteger i=0; i textureAtlas_.capacity ) + [textureAtlas_ resizeCapacity:len]; + + [string_ release]; + string_ = [newString copy]; + [self updateAtlasValues]; + + CGSize s; + s.width = len * itemWidth_; + s.height = itemHeight_; + [self setContentSizeInPixels:s]; + + self.quadsToDraw = len; +} + +-(NSString*) string +{ + return string_; +} + +#pragma mark CCLabelAtlas - DebugDraw + +#if CC_LABELATLAS_DEBUG_DRAW +- (void) draw +{ + [super draw]; + + CGSize s = [self contentSize]; + CGPoint vertices[4]={ + ccp(0,0),ccp(s.width,0), + ccp(s.width,s.height),ccp(0,s.height), + }; + ccDrawPoly(vertices, 4, YES); + +} +#endif // CC_LABELATLAS_DEBUG_DRAW + +@end diff --git a/tweejump/libs/cocos2d/CCLabelBMFont.h b/tweejump/libs/cocos2d/CCLabelBMFont.h new file mode 100755 index 0000000..2570bc0 --- /dev/null +++ b/tweejump/libs/cocos2d/CCLabelBMFont.h @@ -0,0 +1,178 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-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. + * + * Portions of this code are based and inspired on: + * http://www.71squared.co.uk/2009/04/iphone-game-programming-tutorial-4-bitmap-font-class + * by Michael Daley + * + * Use any of these editors to generate BMFonts: + * http://glyphdesigner.71squared.com/ (Commercial, Mac OS X) + * http://www.n4te.com/hiero/hiero.jnlp (Free, Java) + * http://slick.cokeandcode.com/demos/hiero.jnlp (Free, Java) + * http://www.angelcode.com/products/bmfont/ (Free, Windows only) + */ + +#import "CCSpriteBatchNode.h" +#import "Support/uthash.h" + +struct _KerningHashElement; + +/** @struct ccBMFontDef + BMFont definition + */ +typedef struct _BMFontDef { + //! ID of the character + unsigned int charID; + //! origin and size of the font + CGRect rect; + //! The X amount the image should be offset when drawing the image (in pixels) + int xOffset; + //! The Y amount the image should be offset when drawing the image (in pixels) + int yOffset; + //! The amount to move the current position after drawing the character (in pixels) + int xAdvance; +} ccBMFontDef; + +/** @struct ccBMFontPadding + BMFont padding + @since v0.8.2 + */ +typedef struct _BMFontPadding { + /// padding left + int left; + /// padding top + int top; + /// padding right + int right; + /// padding bottom + int bottom; +} ccBMFontPadding; + +enum { + // how many characters are supported + kCCBMFontMaxChars = 2048, //256, +}; + +/** CCBMFontConfiguration has parsed configuration of the the .fnt file + @since v0.8 + */ +@interface CCBMFontConfiguration : NSObject +{ +// XXX: Creating a public interface so that the bitmapFontArray[] is accesible +@public + // The characters building up the font + ccBMFontDef BMFontArray_[kCCBMFontMaxChars]; + + // FNTConfig: Common Height + NSUInteger commonHeight_; + + // Padding + ccBMFontPadding padding_; + + // atlas name + NSString *atlasName_; + + // values for kerning + struct _KerningHashElement *kerningDictionary_; +} + +/** allocates a CCBMFontConfiguration with a FNT file */ ++(id) configurationWithFNTFile:(NSString*)FNTfile; +/** initializes a CCBMFontConfiguration with a FNT file */ +-(id) initWithFNTfile:(NSString*)FNTfile; +@end + + +/** CCLabelBMFont is a subclass of CCSpriteBatchNode + + Features: + - Treats each character like a CCSprite. This means that each individual character can be: + - rotated + - scaled + - translated + - tinted + - chage the opacity + - It can be used as part of a menu item. + - anchorPoint can be used to align the "label" + - Supports AngelCode text format + + Limitations: + - All inner characters are using an anchorPoint of (0.5f, 0.5f) and it is not recommend to change it + because it might affect the rendering + + CCLabelBMFont implements the protocol CCLabelProtocol, like CCLabel and CCLabelAtlas. + CCLabelBMFont has the flexibility of CCLabel, the speed of CCLabelAtlas and all the features of CCSprite. + If in doubt, use CCLabelBMFont instead of CCLabelAtlas / CCLabel. + + Supported editors: + - http://www.n4te.com/hiero/hiero.jnlp + - http://slick.cokeandcode.com/demos/hiero.jnlp + - http://www.angelcode.com/products/bmfont/ + + @since v0.8 + */ + +@interface CCLabelBMFont : CCSpriteBatchNode +{ + // string to render + NSString *string_; + + CCBMFontConfiguration *configuration_; + + // texture RGBA + GLubyte opacity_; + ccColor3B color_; + BOOL opacityModifyRGB_; +} + +/** Purges the cached data. + Removes from memory the cached configurations and the atlas name dictionary. + @since v0.99.3 + */ ++(void) purgeCachedData; + +/** conforms to CCRGBAProtocol protocol */ +@property (nonatomic,readwrite) GLubyte opacity; +/** conforms to CCRGBAProtocol protocol */ +@property (nonatomic,readwrite) ccColor3B color; + + +/** creates a BMFont label with an initial string and the FNT file */ ++(id) labelWithString:(NSString*)string fntFile:(NSString*)fntFile; + +/** init a BMFont label with an initial string and the FNT file */ +-(id) initWithString:(NSString*)string fntFile:(NSString*)fntFile; + +/** updates the font chars based on the string to render */ +-(void) createFontChars; +@end + +/** Free function that parses a FNT file a place it on the cache +*/ +CCBMFontConfiguration * FNTConfigLoadFile( NSString *file ); +/** Purges the FNT config cache + */ +void FNTConfigRemoveCache( void ); + + diff --git a/tweejump/libs/cocos2d/CCLabelBMFont.m b/tweejump/libs/cocos2d/CCLabelBMFont.m new file mode 100755 index 0000000..4313840 --- /dev/null +++ b/tweejump/libs/cocos2d/CCLabelBMFont.m @@ -0,0 +1,669 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-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. + * + * Portions of this code are based and inspired on: + * http://www.71squared.co.uk/2009/04/iphone-game-programming-tutorial-4-bitmap-font-class + * by Michael Daley + * + * + * Use any of these editors to generate BMFonts: + * http://glyphdesigner.71squared.com/ (Commercial, Mac OS X) + * http://www.n4te.com/hiero/hiero.jnlp (Free, Java) + * http://slick.cokeandcode.com/demos/hiero.jnlp (Free, Java) + * http://www.angelcode.com/products/bmfont/ (Free, Windows only) + */ + +#import "ccConfig.h" +#import "CCLabelBMFont.h" +#import "CCSprite.h" +#import "CCDrawingPrimitives.h" +#import "CCConfiguration.h" +#import "Support/CCFileUtils.h" +#import "Support/CGPointExtension.h" +#import "Support/uthash.h" + +#pragma mark - +#pragma mark FNTConfig Cache - free functions + +NSMutableDictionary *configurations = nil; +CCBMFontConfiguration* FNTConfigLoadFile( NSString *fntFile) +{ + CCBMFontConfiguration *ret = nil; + + if( configurations == nil ) + configurations = [[NSMutableDictionary dictionaryWithCapacity:3] retain]; + + ret = [configurations objectForKey:fntFile]; + if( ret == nil ) { + ret = [CCBMFontConfiguration configurationWithFNTFile:fntFile]; + [configurations setObject:ret forKey:fntFile]; + } + + return ret; +} + +void FNTConfigRemoveCache( void ) +{ + [configurations removeAllObjects]; +} + +#pragma mark - Hash Element + +// Equal function for targetSet. +typedef struct _KerningHashElement +{ + int key; // key for the hash. 16-bit for 1st element, 16-bit for 2nd element + int amount; + UT_hash_handle hh; +} tKerningHashElement; + +#pragma mark - +#pragma mark BitmapFontConfiguration + + +@interface CCBMFontConfiguration (Private) +-(void) parseConfigFile:(NSString*)controlFile; +-(void) parseCharacterDefinition:(NSString*)line charDef:(ccBMFontDef*)characterDefinition; +-(void) parseInfoArguments:(NSString*)line; +-(void) parseCommonArguments:(NSString*)line; +-(void) parseImageFileName:(NSString*)line fntFile:(NSString*)fntFile; +-(void) parseKerningCapacity:(NSString*)line; +-(void) parseKerningEntry:(NSString*)line; +-(void) purgeKerningDictionary; +@end + +@implementation CCBMFontConfiguration + ++(id) configurationWithFNTFile:(NSString*)FNTfile +{ + return [[[self alloc] initWithFNTfile:FNTfile] autorelease]; +} + +-(id) initWithFNTfile:(NSString*)fntFile +{ + if((self=[super init])) { + + kerningDictionary_ = NULL; + + [self parseConfigFile:fntFile]; + } + return self; +} + +- (void) dealloc +{ + CCLOGINFO( @"cocos2d: deallocing %@", self); + [self purgeKerningDictionary]; + [atlasName_ release]; + [super dealloc]; +} + +- (NSString*) description +{ + return [NSString stringWithFormat:@"<%@ = %08X | Kernings:%d | Image = %@>", [self class], self, + HASH_COUNT(kerningDictionary_), + atlasName_]; +} + + +-(void) purgeKerningDictionary +{ + tKerningHashElement *current; + + while(kerningDictionary_) { + current = kerningDictionary_; + HASH_DEL(kerningDictionary_,current); + free(current); + } +} + +- (void)parseConfigFile:(NSString*)fntFile +{ + NSString *fullpath = [CCFileUtils fullPathFromRelativePath:fntFile]; + NSError *error; + NSString *contents = [NSString stringWithContentsOfFile:fullpath encoding:NSUTF8StringEncoding error:&error]; + + NSAssert1( contents, @"cocos2d: Error parsing FNTfile: %@", error); + + + // Move all lines in the string, which are denoted by \n, into an array + NSArray *lines = [[NSArray alloc] initWithArray:[contents componentsSeparatedByString:@"\n"]]; + + // Create an enumerator which we can use to move through the lines read from the control file + NSEnumerator *nse = [lines objectEnumerator]; + + // Create a holder for each line we are going to work with + NSString *line; + + // Loop through all the lines in the lines array processing each one + while( (line = [nse nextObject]) ) { + // parse spacing / padding + if([line hasPrefix:@"info face"]) { + // XXX: info parsing is incomplete + // Not needed for the Hiero editors, but needed for the AngelCode editor +// [self parseInfoArguments:line]; + } + // Check to see if the start of the line is something we are interested in + else if([line hasPrefix:@"common lineHeight"]) { + [self parseCommonArguments:line]; + } + else if([line hasPrefix:@"page id"]) { + [self parseImageFileName:line fntFile:fntFile]; + } + else if([line hasPrefix:@"chars c"]) { + // Ignore this line + } + else if([line hasPrefix:@"char"]) { + // Parse the current line and create a new CharDef + ccBMFontDef characterDefinition; + [self parseCharacterDefinition:line charDef:&characterDefinition]; + + // Add the CharDef returned to the charArray + BMFontArray_[ characterDefinition.charID ] = characterDefinition; + } + else if([line hasPrefix:@"kernings count"]) { + [self parseKerningCapacity:line]; + } + else if([line hasPrefix:@"kerning first"]) { + [self parseKerningEntry:line]; + } + } + // Finished with lines so release it + [lines release]; +} + +-(void) parseImageFileName:(NSString*)line fntFile:(NSString*)fntFile +{ + NSString *propertyValue = nil; + + // Break the values for this line up using = + NSArray *values = [line componentsSeparatedByString:@"="]; + + // Get the enumerator for the array of components which has been created + NSEnumerator *nse = [values objectEnumerator]; + + // We need to move past the first entry in the array before we start assigning values + [nse nextObject]; + + // page ID. Sanity check + propertyValue = [nse nextObject]; + NSAssert( [propertyValue intValue] == 0, @"XXX: LabelBMFont only supports 1 page"); + + // file + propertyValue = [nse nextObject]; + NSArray *array = [propertyValue componentsSeparatedByString:@"\""]; + propertyValue = [array objectAtIndex:1]; + NSAssert(propertyValue,@"LabelBMFont file could not be found"); + + // Supports subdirectories + NSString *dir = [fntFile stringByDeletingLastPathComponent]; + atlasName_ = [dir stringByAppendingPathComponent:propertyValue]; + + [atlasName_ retain]; +} + +-(void) parseInfoArguments:(NSString*)line +{ + // + // possible lines to parse: + // info face="Script" size=32 bold=0 italic=0 charset="" unicode=1 stretchH=100 smooth=1 aa=1 padding=1,4,3,2 spacing=0,0 outline=0 + // info face="Cracked" size=36 bold=0 italic=0 charset="" unicode=0 stretchH=100 smooth=1 aa=1 padding=0,0,0,0 spacing=1,1 + // + NSArray *values = [line componentsSeparatedByString:@"="]; + NSEnumerator *nse = [values objectEnumerator]; + NSString *propertyValue = nil; + + // We need to move past the first entry in the array before we start assigning values + [nse nextObject]; + + // face (ignore) + [nse nextObject]; + + // size (ignore) + [nse nextObject]; + + // bold (ignore) + [nse nextObject]; + + // italic (ignore) + [nse nextObject]; + + // charset (ignore) + [nse nextObject]; + + // unicode (ignore) + [nse nextObject]; + + // strechH (ignore) + [nse nextObject]; + + // smooth (ignore) + [nse nextObject]; + + // aa (ignore) + [nse nextObject]; + + // padding (ignore) + propertyValue = [nse nextObject]; + { + + NSArray *paddingValues = [propertyValue componentsSeparatedByString:@","]; + NSEnumerator *paddingEnum = [paddingValues objectEnumerator]; + // padding top + propertyValue = [paddingEnum nextObject]; + padding_.top = [propertyValue intValue]; + + // padding right + propertyValue = [paddingEnum nextObject]; + padding_.right = [propertyValue intValue]; + + // padding bottom + propertyValue = [paddingEnum nextObject]; + padding_.bottom = [propertyValue intValue]; + + // padding left + propertyValue = [paddingEnum nextObject]; + padding_.left = [propertyValue intValue]; + + CCLOG(@"cocos2d: padding: %d,%d,%d,%d", padding_.left, padding_.top, padding_.right, padding_.bottom); + } + + // spacing (ignore) + [nse nextObject]; +} + +-(void) parseCommonArguments:(NSString*)line +{ + // + // line to parse: + // common lineHeight=104 base=26 scaleW=1024 scaleH=512 pages=1 packed=0 + // + NSArray *values = [line componentsSeparatedByString:@"="]; + NSEnumerator *nse = [values objectEnumerator]; + NSString *propertyValue = nil; + + // We need to move past the first entry in the array before we start assigning values + [nse nextObject]; + + // Character ID + propertyValue = [nse nextObject]; + commonHeight_ = [propertyValue intValue]; + + // base (ignore) + [nse nextObject]; + + + // scaleW. sanity check + propertyValue = [nse nextObject]; + NSAssert( [propertyValue intValue] <= [[CCConfiguration sharedConfiguration] maxTextureSize], @"CCLabelBMFont: page can't be larger than supported"); + + // scaleH. sanity check + propertyValue = [nse nextObject]; + NSAssert( [propertyValue intValue] <= [[CCConfiguration sharedConfiguration] maxTextureSize], @"CCLabelBMFont: page can't be larger than supported"); + + // pages. sanity check + propertyValue = [nse nextObject]; + NSAssert( [propertyValue intValue] == 1, @"CCBitfontAtlas: only supports 1 page"); + + // packed (ignore) What does this mean ?? +} +- (void)parseCharacterDefinition:(NSString*)line charDef:(ccBMFontDef*)characterDefinition +{ + // Break the values for this line up using = + NSArray *values = [line componentsSeparatedByString:@"="]; + NSEnumerator *nse = [values objectEnumerator]; + NSString *propertyValue; + + // We need to move past the first entry in the array before we start assigning values + [nse nextObject]; + + // Character ID + propertyValue = [nse nextObject]; + propertyValue = [propertyValue substringToIndex: [propertyValue rangeOfString: @" "].location]; + characterDefinition->charID = [propertyValue intValue]; + NSAssert(characterDefinition->charID < kCCBMFontMaxChars, @"BitmpaFontAtlas: CharID bigger than supported"); + + // Character x + propertyValue = [nse nextObject]; + characterDefinition->rect.origin.x = [propertyValue intValue]; + // Character y + propertyValue = [nse nextObject]; + characterDefinition->rect.origin.y = [propertyValue intValue]; + // Character width + propertyValue = [nse nextObject]; + characterDefinition->rect.size.width = [propertyValue intValue]; + // Character height + propertyValue = [nse nextObject]; + characterDefinition->rect.size.height = [propertyValue intValue]; + // Character xoffset + propertyValue = [nse nextObject]; + characterDefinition->xOffset = [propertyValue intValue]; + // Character yoffset + propertyValue = [nse nextObject]; + characterDefinition->yOffset = [propertyValue intValue]; + // Character xadvance + propertyValue = [nse nextObject]; + characterDefinition->xAdvance = [propertyValue intValue]; +} + +-(void) parseKerningCapacity:(NSString*) line +{ + // When using uthash there is not need to parse the capacity. + +// NSAssert(!kerningDictionary, @"dictionary already initialized"); +// +// // Break the values for this line up using = +// NSArray *values = [line componentsSeparatedByString:@"="]; +// NSEnumerator *nse = [values objectEnumerator]; +// NSString *propertyValue; +// +// // We need to move past the first entry in the array before we start assigning values +// [nse nextObject]; +// +// // count +// propertyValue = [nse nextObject]; +// int capacity = [propertyValue intValue]; +// +// if( capacity != -1 ) +// kerningDictionary = ccHashSetNew(capacity, targetSetEql); +} + +-(void) parseKerningEntry:(NSString*) line +{ + NSArray *values = [line componentsSeparatedByString:@"="]; + NSEnumerator *nse = [values objectEnumerator]; + NSString *propertyValue; + + // We need to move past the first entry in the array before we start assigning values + [nse nextObject]; + + // first + propertyValue = [nse nextObject]; + int first = [propertyValue intValue]; + + // second + propertyValue = [nse nextObject]; + int second = [propertyValue intValue]; + + // second + propertyValue = [nse nextObject]; + int amount = [propertyValue intValue]; + + tKerningHashElement *element = calloc( sizeof( *element ), 1 ); + element->amount = amount; + element->key = (first<<16) | (second&0xffff); + HASH_ADD_INT(kerningDictionary_,key, element); +} + +@end + +#pragma mark - +#pragma mark CCLabelBMFont + +@interface CCLabelBMFont (Private) +-(NSString*) atlasNameFromFntFile:(NSString*)fntFile; + +-(int) kerningAmountForFirst:(unichar)first second:(unichar)second; + +@end + +@implementation CCLabelBMFont + +@synthesize opacity = opacity_, color = color_; + +#pragma mark LabelBMFont - Purge Cache ++(void) purgeCachedData +{ + FNTConfigRemoveCache(); +} + +#pragma mark LabelBMFont - Creation & Init + ++(id) labelWithString:(NSString *)string fntFile:(NSString *)fntFile +{ + return [[[self alloc] initWithString:string fntFile:fntFile] autorelease]; +} + +-(id) initWithString:(NSString*)theString fntFile:(NSString*)fntFile +{ + + [configuration_ release]; // allow re-init + + configuration_ = FNTConfigLoadFile(fntFile); + [configuration_ retain]; + + NSAssert( configuration_, @"Error creating config for LabelBMFont"); + + + if ((self=[super initWithFile:configuration_->atlasName_ capacity:[theString length]])) { + + opacity_ = 255; + color_ = ccWHITE; + + contentSize_ = CGSizeZero; + + opacityModifyRGB_ = [[textureAtlas_ texture] hasPremultipliedAlpha]; + + anchorPoint_ = ccp(0.5f, 0.5f); + + [self setString:theString]; + } + + return self; +} + +-(void) dealloc +{ + [string_ release]; + [configuration_ release]; + [super dealloc]; +} + +#pragma mark LabelBMFont - Atlas generation + +-(int) kerningAmountForFirst:(unichar)first second:(unichar)second +{ + int ret = 0; + unsigned int key = (first<<16) | (second & 0xffff); + + if( configuration_->kerningDictionary_ ) { + tKerningHashElement *element = NULL; + HASH_FIND_INT(configuration_->kerningDictionary_, &key, element); + if(element) + ret = element->amount; + } + + return ret; +} + +-(void) createFontChars +{ + NSInteger nextFontPositionX = 0; + NSInteger nextFontPositionY = 0; + unichar prev = -1; + NSInteger kerningAmount = 0; + + CGSize tmpSize = CGSizeZero; + + NSInteger longestLine = 0; + NSUInteger totalHeight = 0; + + NSUInteger quantityOfLines = 1; + + NSUInteger stringLen = [string_ length]; + if( ! stringLen ) + return; + + // quantity of lines NEEDS to be calculated before parsing the lines, + // since the Y position needs to be calcualted before hand + for(NSUInteger i=0; i < stringLen-1;i++) { + unichar c = [string_ characterAtIndex:i]; + if( c=='\n') + quantityOfLines++; + } + + totalHeight = configuration_->commonHeight_ * quantityOfLines; + nextFontPositionY = -(configuration_->commonHeight_ - configuration_->commonHeight_*quantityOfLines); + + for(NSUInteger i=0; icommonHeight_; + continue; + } + + kerningAmount = [self kerningAmountForFirst:prev second:c]; + + ccBMFontDef fontDef = configuration_->BMFontArray_[c]; + + CGRect rect = fontDef.rect; + + CCSprite *fontChar; + + fontChar = (CCSprite*) [self getChildByTag:i]; + if( ! fontChar ) { + fontChar = [[CCSprite alloc] initWithBatchNode:self rectInPixels:rect]; + [self addChild:fontChar z:0 tag:i]; + [fontChar release]; + } + else { + // reusing fonts + [fontChar setTextureRectInPixels:rect rotated:NO untrimmedSize:rect.size]; + + // restore to default in case they were modified + fontChar.visible = YES; + fontChar.opacity = 255; + } + + float yOffset = configuration_->commonHeight_ - fontDef.yOffset; + fontChar.positionInPixels = ccp( (float)nextFontPositionX + fontDef.xOffset + fontDef.rect.size.width*0.5f + kerningAmount, + (float)nextFontPositionY + yOffset - rect.size.height*0.5f ); + + // update kerning + nextFontPositionX += configuration_->BMFontArray_[c].xAdvance + kerningAmount; + prev = c; + + // Apply label properties + [fontChar setOpacityModifyRGB:opacityModifyRGB_]; + // Color MUST be set before opacity, since opacity might change color if OpacityModifyRGB is on + [fontChar setColor:color_]; + + // only apply opacity if it is different than 255 ) + // to prevent modifying the color too (issue #610) + if( opacity_ != 255 ) + [fontChar setOpacity: opacity_]; + + if (longestLine < nextFontPositionX) + longestLine = nextFontPositionX; + } + + tmpSize.width = longestLine; + tmpSize.height = totalHeight; + + [self setContentSizeInPixels:tmpSize]; +} + +#pragma mark LabelBMFont - CCLabelProtocol protocol +- (void) setString:(NSString*) newString +{ + [string_ release]; + string_ = [newString copy]; + + CCNode *child; + CCARRAY_FOREACH(children_, child) + child.visible = NO; + + [self createFontChars]; +} + +-(NSString*) string +{ + return string_; +} + +-(void) setCString:(char*)label +{ + [self setString:[NSString stringWithUTF8String:label]]; +} + +#pragma mark LabelBMFont - CCRGBAProtocol protocol + +-(void) setColor:(ccColor3B)color +{ + color_ = color; + + CCSprite *child; + CCARRAY_FOREACH(children_, child) + [child setColor:color_]; +} + +-(void) setOpacity:(GLubyte)opacity +{ + opacity_ = opacity; + + id child; + CCARRAY_FOREACH(children_, child) + [child setOpacity:opacity_]; +} +-(void) setOpacityModifyRGB:(BOOL)modify +{ + opacityModifyRGB_ = modify; + + id child; + CCARRAY_FOREACH(children_, child) + [child setOpacityModifyRGB:modify]; +} + +-(BOOL) doesOpacityModifyRGB +{ + return opacityModifyRGB_; +} + +#pragma mark LabelBMFont - AnchorPoint +-(void) setAnchorPoint:(CGPoint)point +{ + if( ! CGPointEqualToPoint(point, anchorPoint_) ) { + [super setAnchorPoint:point]; + [self createFontChars]; + } +} + +#pragma mark LabelBMFont - Debug draw +#if CC_LABELBMFONT_DEBUG_DRAW +-(void) draw +{ + [super draw]; + + CGSize s = [self contentSize]; + CGPoint vertices[4]={ + ccp(0,0),ccp(s.width,0), + ccp(s.width,s.height),ccp(0,s.height), + }; + ccDrawPoly(vertices, 4, YES); +} +#endif // CC_LABELBMFONT_DEBUG_DRAW +@end diff --git a/tweejump/libs/cocos2d/CCLabelTTF.h b/tweejump/libs/cocos2d/CCLabelTTF.h new file mode 100755 index 0000000..8e48ce1 --- /dev/null +++ b/tweejump/libs/cocos2d/CCLabelTTF.h @@ -0,0 +1,78 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-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. + * + */ + + +#import "CCTexture2D.h" +#import "CCSprite.h" +#import "Platforms/CCNS.h" + + +/** CCLabel is a subclass of CCTextureNode that knows how to render text labels + * + * All features from CCTextureNode are valid in CCLabel + * + * CCLabel objects are slow. Consider using CCLabelAtlas or CCLabelBMFont instead. + */ + +@interface CCLabelTTF : CCSprite +{ + CGSize dimensions_; + CCTextAlignment alignment_; + NSString * fontName_; + CGFloat fontSize_; + CCLineBreakMode lineBreakMode_; + NSString *string_; +} + +/** creates a CCLabel from a fontname, alignment, dimension in points, line break mode, and font size in points. + Supported lineBreakModes: + - iOS: all UILineBreakMode supported modes + - Mac: Only NSLineBreakByWordWrapping is supported. + @since v1.0 + */ ++ (id) labelWithString:(NSString*)string dimensions:(CGSize)dimensions alignment:(CCTextAlignment)alignment lineBreakMode:(CCLineBreakMode)lineBreakMode fontName:(NSString*)name fontSize:(CGFloat)size; +/** creates a CCLabel from a fontname, alignment, dimension in points and font size in points*/ ++ (id) labelWithString:(NSString*)string dimensions:(CGSize)dimensions alignment:(CCTextAlignment)alignment fontName:(NSString*)name fontSize:(CGFloat)size; +/** creates a CCLabel from a fontname and font size in points*/ ++ (id) labelWithString:(NSString*)string fontName:(NSString*)name fontSize:(CGFloat)size; +/** initializes the CCLabel with a font name, alignment, dimension in points, line brea mode and font size in points. + Supported lineBreakModes: + - iOS: all UILineBreakMode supported modes + - Mac: Only NSLineBreakByWordWrapping is supported. + @since v1.0 + */ +- (id) initWithString:(NSString*)str dimensions:(CGSize)dimensions alignment:(CCTextAlignment)alignment lineBreakMode:(CCLineBreakMode)lineBreakMode fontName:(NSString*)name fontSize:(CGFloat)size; +/** initializes the CCLabel with a font name, alignment, dimension in points and font size in points */ +- (id) initWithString:(NSString*)string dimensions:(CGSize)dimensions alignment:(CCTextAlignment)alignment fontName:(NSString*)name fontSize:(CGFloat)size; +/** initializes the CCLabel with a font name and font size in points */ +- (id) initWithString:(NSString*)string fontName:(NSString*)name fontSize:(CGFloat)size; + +/** changes the string to render + * @warning Changing the string is as expensive as creating a new CCLabel. To obtain better performance use CCLabelAtlas + */ +- (void) setString:(NSString*)str; + +@end diff --git a/tweejump/libs/cocos2d/CCLabelTTF.m b/tweejump/libs/cocos2d/CCLabelTTF.m new file mode 100755 index 0000000..18689fd --- /dev/null +++ b/tweejump/libs/cocos2d/CCLabelTTF.m @@ -0,0 +1,141 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-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. + * + */ + + +#import + +#import "CCLabelTTF.h" +#import "Support/CGPointExtension.h" +#import "ccMacros.h" + +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED +#import "Platforms/iOS/CCDirectorIOS.h" +#endif + +@implementation CCLabelTTF + +- (id) init +{ + NSAssert(NO, @"CCLabelTTF: Init not supported. Use initWithString"); + [self release]; + return nil; +} + ++ (id) labelWithString:(NSString*)string dimensions:(CGSize)dimensions alignment:(CCTextAlignment)alignment lineBreakMode:(CCLineBreakMode)lineBreakMode fontName:(NSString*)name fontSize:(CGFloat)size; +{ + return [[[self alloc] initWithString: string dimensions:dimensions alignment:alignment lineBreakMode:lineBreakMode fontName:name fontSize:size]autorelease]; +} + ++ (id) labelWithString:(NSString*)string dimensions:(CGSize)dimensions alignment:(CCTextAlignment)alignment fontName:(NSString*)name fontSize:(CGFloat)size +{ + return [[[self alloc] initWithString: string dimensions:dimensions alignment:alignment fontName:name fontSize:size]autorelease]; +} + ++ (id) labelWithString:(NSString*)string fontName:(NSString*)name fontSize:(CGFloat)size +{ + return [[[self alloc] initWithString: string fontName:name fontSize:size]autorelease]; +} + + +- (id) initWithString:(NSString*)str dimensions:(CGSize)dimensions alignment:(CCTextAlignment)alignment lineBreakMode:(CCLineBreakMode)lineBreakMode fontName:(NSString*)name fontSize:(CGFloat)size +{ + if( (self=[super init]) ) { + + dimensions_ = CGSizeMake( dimensions.width * CC_CONTENT_SCALE_FACTOR(), dimensions.height * CC_CONTENT_SCALE_FACTOR() ); + alignment_ = alignment; + fontName_ = [name retain]; + fontSize_ = size * CC_CONTENT_SCALE_FACTOR(); + lineBreakMode_ = lineBreakMode; + + [self setString:str]; + } + return self; +} + +- (id) initWithString:(NSString*)str dimensions:(CGSize)dimensions alignment:(CCTextAlignment)alignment fontName:(NSString*)name fontSize:(CGFloat)size +{ + return [self initWithString:str dimensions:dimensions alignment:alignment lineBreakMode:CCLineBreakModeWordWrap fontName:name fontSize:size]; +} + +- (id) initWithString:(NSString*)str fontName:(NSString*)name fontSize:(CGFloat)size +{ + if( (self=[super init]) ) { + + dimensions_ = CGSizeZero; + fontName_ = [name retain]; + fontSize_ = size * CC_CONTENT_SCALE_FACTOR(); + + [self setString:str]; + } + return self; +} + +- (void) setString:(NSString*)str +{ + [string_ release]; + string_ = [str copy]; + + CCTexture2D *tex; + if( CGSizeEqualToSize( dimensions_, CGSizeZero ) ) + tex = [[CCTexture2D alloc] initWithString:str + fontName:fontName_ + fontSize:fontSize_]; + else + tex = [[CCTexture2D alloc] initWithString:str + dimensions:dimensions_ + alignment:alignment_ + lineBreakMode:lineBreakMode_ + fontName:fontName_ + fontSize:fontSize_]; + + [self setTexture:tex]; + [tex release]; + + CGRect rect = CGRectZero; + rect.size = [texture_ contentSize]; + [self setTextureRect: rect]; +} + +-(NSString*) string +{ + return string_; +} + +- (void) dealloc +{ + [string_ release]; + [fontName_ release]; + + [super dealloc]; +} + +- (NSString*) description +{ + // XXX: string_, fontName_ can't be displayed here, since they might be already released + + return [NSString stringWithFormat:@"<%@ = %08X | FontSize = %.1f>", [self class], self, fontSize_]; +} +@end diff --git a/tweejump/libs/cocos2d/CCLayer.h b/tweejump/libs/cocos2d/CCLayer.h new file mode 100755 index 0000000..b456088 --- /dev/null +++ b/tweejump/libs/cocos2d/CCLayer.h @@ -0,0 +1,277 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-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. + * + */ + + + +#import +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED +#import // Needed for UIAccelerometerDelegate +#import "Platforms/iOS/CCTouchDelegateProtocol.h" // Touches only supported on iOS +#elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED) +#import "Platforms/Mac/CCEventDispatcher.h" +#endif + +#import "CCProtocols.h" +#import "CCNode.h" + +#pragma mark - +#pragma mark CCLayer + +/** CCLayer is a subclass of CCNode that implements the TouchEventsDelegate protocol. + + All features from CCNode are valid, plus the following new features: + - It can receive iPhone Touches + - It can receive Accelerometer input +*/ +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED +@interface CCLayer : CCNode +{ + BOOL isTouchEnabled_; + BOOL isAccelerometerEnabled_; +} +/** If isTouchEnabled, this method is called onEnter. Override it to change the + way CCLayer receives touch events. + ( Default: [[TouchDispatcher sharedDispatcher] addStandardDelegate:self priority:0] ) + Example: + -(void) registerWithTouchDispatcher + { + [[TouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:INT_MIN+1 swallowsTouches:YES]; + } + + Valid only on iOS. Not valid on Mac. + + @since v0.8.0 + */ +-(void) registerWithTouchDispatcher; + +/** whether or not it will receive Touch events. + You can enable / disable touch events with this property. + Only the touches of this node will be affected. This "method" is not propagated to it's children. + + Valid on iOS and Mac OS X v10.6 and later. + + @since v0.8.1 + */ +@property(nonatomic,assign) BOOL isTouchEnabled; +/** whether or not it will receive Accelerometer events + You can enable / disable accelerometer events with this property. + + Valid only on iOS. Not valid on Mac. + + @since v0.8.1 + */ +@property(nonatomic,assign) BOOL isAccelerometerEnabled; + +#elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED) + + +@interface CCLayer : CCNode +{ + BOOL isMouseEnabled_; + BOOL isKeyboardEnabled_; + BOOL isTouchEnabled_; +} + +/** whether or not it will receive mouse events. + + Valind only Mac. Not valid on iOS + */ +@property (nonatomic, readwrite) BOOL isMouseEnabled; + +/** whether or not it will receive keyboard events. + + Valind only Mac. Not valid on iOS + */ +@property (nonatomic, readwrite) BOOL isKeyboardEnabled; + +/** whether or not it will receive touch events. + + Valid on iOS and Mac OS X v10.6 and later. + */ +@property (nonatomic, readwrite) BOOL isTouchEnabled; + +/** priority of the mouse event delegate. + Default 0. + Override this method to set another priority. + + Valind only Mac. Not valid on iOS + */ +-(NSInteger) mouseDelegatePriority; + +/** priority of the keyboard event delegate. + Default 0. + Override this method to set another priority. + + Valind only Mac. Not valid on iOS + */ +-(NSInteger) keyboardDelegatePriority; + +/** priority of the touch event delegate. + Default 0. + Override this method to set another priority. + + Valind only Mac. Not valid on iOS + */ +-(NSInteger) touchDelegatePriority; + +#endif // mac + + +@end + +#pragma mark - +#pragma mark CCLayerColor + +/** CCLayerColor is a subclass of CCLayer that implements the CCRGBAProtocol protocol. + + All features from CCLayer are valid, plus the following new features: + - opacity + - RGB colors + */ +@interface CCLayerColor : CCLayer +{ + GLubyte opacity_; + ccColor3B color_; + ccVertex2F squareVertices_[4]; + ccColor4B squareColors_[4]; + + ccBlendFunc blendFunc_; +} + +/** creates a CCLayer with color, width and height in Points*/ ++ (id) layerWithColor: (ccColor4B)color width:(GLfloat)w height:(GLfloat)h; +/** creates a CCLayer with color. Width and height are the window size. */ ++ (id) layerWithColor: (ccColor4B)color; + +/** initializes a CCLayer with color, width and height in Points */ +- (id) initWithColor:(ccColor4B)color width:(GLfloat)w height:(GLfloat)h; +/** initializes a CCLayer with color. Width and height are the window size. */ +- (id) initWithColor:(ccColor4B)color; + +/** change width in Points */ +-(void) changeWidth: (GLfloat)w; +/** change height in Points */ +-(void) changeHeight: (GLfloat)h; +/** change width and height in Points + @since v0.8 + */ +-(void) changeWidth:(GLfloat)w height:(GLfloat)h; + +/** Opacity: conforms to CCRGBAProtocol protocol */ +@property (nonatomic,readonly) GLubyte opacity; +/** Opacity: conforms to CCRGBAProtocol protocol */ +@property (nonatomic,readonly) ccColor3B color; +/** BlendFunction. Conforms to CCBlendProtocol protocol */ +@property (nonatomic,readwrite) ccBlendFunc blendFunc; +@end + +#pragma mark - +#pragma mark CCLayerGradient + +/** CCLayerGradient is a subclass of CCLayerColor that draws gradients across +the background. + + All features from CCLayerColor are valid, plus the following new features: + - direction + - final color + - interpolation mode + + Color is interpolated between the startColor and endColor along the given + vector (starting at the origin, ending at the terminus). If no vector is + supplied, it defaults to (0, -1) -- a fade from top to bottom. + + If 'compressedInterpolation' is disabled, you will not see either the start or end color for + non-cardinal vectors; a smooth gradient implying both end points will be still + be drawn, however. + + If ' compressedInterpolation' is enabled (default mode) you will see both the start and end colors of the gradient. + + @since v0.99.5 + */ +@interface CCLayerGradient : CCLayerColor +{ + ccColor3B endColor_; + GLubyte startOpacity_; + GLubyte endOpacity_; + CGPoint vector_; + BOOL compressedInterpolation_; +} + +/** Creates a full-screen CCLayer with a gradient between start and end. */ ++ (id) layerWithColor: (ccColor4B) start fadingTo: (ccColor4B) end; +/** Creates a full-screen CCLayer with a gradient between start and end in the direction of v. */ ++ (id) layerWithColor: (ccColor4B) start fadingTo: (ccColor4B) end alongVector: (CGPoint) v; + +/** Initializes the CCLayer with a gradient between start and end. */ +- (id) initWithColor: (ccColor4B) start fadingTo: (ccColor4B) end; +/** Initializes the CCLayer with a gradient between start and end in the direction of v. */ +- (id) initWithColor: (ccColor4B) start fadingTo: (ccColor4B) end alongVector: (CGPoint) v; + +/** The starting color. */ +@property (nonatomic, readwrite) ccColor3B startColor; +/** The ending color. */ +@property (nonatomic, readwrite) ccColor3B endColor; +/** The starting opacity. */ +@property (nonatomic, readwrite) GLubyte startOpacity; +/** The ending color. */ +@property (nonatomic, readwrite) GLubyte endOpacity; +/** The vector along which to fade color. */ +@property (nonatomic, readwrite) CGPoint vector; +/** Whether or not the interpolation will be compressed in order to display all the colors of the gradient both in canonical and non canonical vectors + Default: YES + */ +@property (nonatomic, readwrite) BOOL compressedInterpolation; + +@end + +#pragma mark - +#pragma mark CCLayerMultiplex + +/** CCLayerMultiplex is a CCLayer with the ability to multiplex it's children. + Features: + - It supports one or more children + - Only one children will be active a time + */ +@interface CCLayerMultiplex : CCLayer +{ + unsigned int enabledLayer_; + NSMutableArray *layers_; +} + +/** creates a CCMultiplexLayer with one or more layers using a variable argument list. */ ++(id) layerWithLayers: (CCLayer*) layer, ... NS_REQUIRES_NIL_TERMINATION; +/** initializes a MultiplexLayer with one or more layers using a variable argument list. */ +-(id) initWithLayers: (CCLayer*) layer vaList:(va_list) params; +/** switches to a certain layer indexed by n. + The current (old) layer will be removed from it's parent with 'cleanup:YES'. + */ +-(void) switchTo: (unsigned int) n; +/** release the current layer and switches to another layer indexed by n. + The current (old) layer will be removed from it's parent with 'cleanup:YES'. + */ +-(void) switchToAndReleaseMe: (unsigned int) n; +@end + diff --git a/tweejump/libs/cocos2d/CCLayer.m b/tweejump/libs/cocos2d/CCLayer.m new file mode 100755 index 0000000..80eede8 --- /dev/null +++ b/tweejump/libs/cocos2d/CCLayer.m @@ -0,0 +1,614 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-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. + * + */ + + +#import + +#import "Platforms/CCGL.h" + +#import "CCLayer.h" +#import "CCDirector.h" +#import "ccMacros.h" +#import "Support/CGPointExtension.h" + +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED +#import "Platforms/iOS/CCTouchDispatcher.h" +#import "Platforms/iOS/CCDirectorIOS.h" +#elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED) +#import "Platforms/Mac/CCEventDispatcher.h" +#endif + +#pragma mark - +#pragma mark Layer + +@implementation CCLayer + +#pragma mark Layer - Init +-(id) init +{ + if( (self=[super init]) ) { + + CGSize s = [[CCDirector sharedDirector] winSize]; + anchorPoint_ = ccp(0.5f, 0.5f); + [self setContentSize:s]; + self.isRelativeAnchorPoint = NO; + + isTouchEnabled_ = NO; + +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED + isAccelerometerEnabled_ = NO; +#elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED) + isMouseEnabled_ = NO; + isKeyboardEnabled_ = NO; +#endif + } + + return self; +} + +#pragma mark Layer - Touch and Accelerometer related + +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED +-(void) registerWithTouchDispatcher +{ + [[CCTouchDispatcher sharedDispatcher] addStandardDelegate:self priority:0]; +} + +-(BOOL) isAccelerometerEnabled +{ + return isAccelerometerEnabled_; +} + +-(void) setIsAccelerometerEnabled:(BOOL)enabled +{ + if( enabled != isAccelerometerEnabled_ ) { + isAccelerometerEnabled_ = enabled; + if( isRunning_ ) { + if( enabled ) + [[UIAccelerometer sharedAccelerometer] setDelegate:self]; + else + [[UIAccelerometer sharedAccelerometer] setDelegate:nil]; + } + } +} + +-(BOOL) isTouchEnabled +{ + return isTouchEnabled_; +} + +-(void) setIsTouchEnabled:(BOOL)enabled +{ + if( isTouchEnabled_ != enabled ) { + isTouchEnabled_ = enabled; + if( isRunning_ ) { + if( enabled ) + [self registerWithTouchDispatcher]; + else + [[CCTouchDispatcher sharedDispatcher] removeDelegate:self]; + } + } +} + +#elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED) + +#pragma mark CCLayer - Mouse, Keyboard & Touch events + +-(NSInteger) mouseDelegatePriority +{ + return 0; +} + +-(BOOL) isMouseEnabled +{ + return isMouseEnabled_; +} + +-(void) setIsMouseEnabled:(BOOL)enabled +{ + if( isMouseEnabled_ != enabled ) { + isMouseEnabled_ = enabled; + + if( isRunning_ ) { + if( enabled ) + [[CCEventDispatcher sharedDispatcher] addMouseDelegate:self priority:[self mouseDelegatePriority]]; + else + [[CCEventDispatcher sharedDispatcher] removeMouseDelegate:self]; + } + } +} + +-(NSInteger) keyboardDelegatePriority +{ + return 0; +} + +-(BOOL) isKeyboardEnabled +{ + return isKeyboardEnabled_; +} + +-(void) setIsKeyboardEnabled:(BOOL)enabled +{ + if( isKeyboardEnabled_ != enabled ) { + isKeyboardEnabled_ = enabled; + + if( isRunning_ ) { + if( enabled ) + [[CCEventDispatcher sharedDispatcher] addKeyboardDelegate:self priority:[self keyboardDelegatePriority] ]; + else + [[CCEventDispatcher sharedDispatcher] removeKeyboardDelegate:self]; + } + } +} + +-(NSInteger) touchDelegatePriority +{ + return 0; +} + +-(BOOL) isTouchEnabled +{ + return isTouchEnabled_; +} + +-(void) setIsTouchEnabled:(BOOL)enabled +{ + if( isTouchEnabled_ != enabled ) { + isTouchEnabled_ = enabled; + if( isRunning_ ) { + if( enabled ) + [[CCEventDispatcher sharedDispatcher] addTouchDelegate:self priority:[self touchDelegatePriority]]; + else + [[CCEventDispatcher sharedDispatcher] removeTouchDelegate:self]; + } + } +} + + +#endif // Mac + + +#pragma mark Layer - Callbacks +-(void) onEnter +{ +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED + // register 'parent' nodes first + // since events are propagated in reverse order + if (isTouchEnabled_) + [self registerWithTouchDispatcher]; + +#elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED) + if( isMouseEnabled_ ) + [[CCEventDispatcher sharedDispatcher] addMouseDelegate:self priority:[self mouseDelegatePriority]]; + + if( isKeyboardEnabled_) + [[CCEventDispatcher sharedDispatcher] addKeyboardDelegate:self priority:[self keyboardDelegatePriority]]; + + if( isTouchEnabled_) + [[CCEventDispatcher sharedDispatcher] addTouchDelegate:self priority:[self touchDelegatePriority]]; + +#endif + + // then iterate over all the children + [super onEnter]; +} + +// issue #624. +// Can't register mouse, touches here because of #issue #1018, and #1021 +-(void) onEnterTransitionDidFinish +{ +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED + if( isAccelerometerEnabled_ ) + [[UIAccelerometer sharedAccelerometer] setDelegate:self]; +#endif + + [super onEnterTransitionDidFinish]; +} + + +-(void) onExit +{ +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED + if( isTouchEnabled_ ) + [[CCTouchDispatcher sharedDispatcher] removeDelegate:self]; + + if( isAccelerometerEnabled_ ) + [[UIAccelerometer sharedAccelerometer] setDelegate:nil]; + +#elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED) + if( isMouseEnabled_ ) + [[CCEventDispatcher sharedDispatcher] removeMouseDelegate:self]; + + if( isKeyboardEnabled_ ) + [[CCEventDispatcher sharedDispatcher] removeKeyboardDelegate:self]; + + if( isTouchEnabled_ ) + [[CCEventDispatcher sharedDispatcher] removeTouchDelegate:self]; + +#endif + + [super onExit]; +} + +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED +-(BOOL) ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event +{ + NSAssert(NO, @"Layer#ccTouchBegan override me"); + return YES; +} +#endif +@end + +#pragma mark - +#pragma mark LayerColor + +@interface CCLayerColor (Private) +-(void) updateColor; +@end + +@implementation CCLayerColor + +// Opacity and RGB color protocol +@synthesize opacity = opacity_, color = color_; +@synthesize blendFunc = blendFunc_; + + ++ (id) layerWithColor:(ccColor4B)color width:(GLfloat)w height:(GLfloat) h +{ + return [[[self alloc] initWithColor:color width:w height:h] autorelease]; +} + ++ (id) layerWithColor:(ccColor4B)color +{ + return [[(CCLayerColor*)[self alloc] initWithColor:color] autorelease]; +} + +- (id) initWithColor:(ccColor4B)color width:(GLfloat)w height:(GLfloat) h +{ + if( (self=[super init]) ) { + + // default blend function + blendFunc_ = (ccBlendFunc) { CC_BLEND_SRC, CC_BLEND_DST }; + + color_.r = color.r; + color_.g = color.g; + color_.b = color.b; + opacity_ = color.a; + + for (NSUInteger i = 0; i +{ + tCCMenuState state_; + CCMenuItem *selectedItem_; + GLubyte opacity_; + ccColor3B color_; +} + +/** creates a CCMenu with it's items */ ++ (id) menuWithItems: (CCMenuItem*) item, ... NS_REQUIRES_NIL_TERMINATION; + +/** initializes a CCMenu with it's items */ +- (id) initWithItems: (CCMenuItem*) item vaList: (va_list) args; + +/** align items vertically */ +-(void) alignItemsVertically; +/** align items vertically with padding + @since v0.7.2 + */ +-(void) alignItemsVerticallyWithPadding:(float) padding; + +/** align items horizontally */ +-(void) alignItemsHorizontally; +/** align items horizontally with padding + @since v0.7.2 + */ +-(void) alignItemsHorizontallyWithPadding: (float) padding; + + +/** align items in rows of columns */ +-(void) alignItemsInColumns: (NSNumber *) columns, ... NS_REQUIRES_NIL_TERMINATION; +-(void) alignItemsInColumns: (NSNumber *) columns vaList: (va_list) args; + +/** align items in columns of rows */ +-(void) alignItemsInRows: (NSNumber *) rows, ... NS_REQUIRES_NIL_TERMINATION; +-(void) alignItemsInRows: (NSNumber *) rows vaList: (va_list) args; + + +/** conforms to CCRGBAProtocol protocol */ +@property (nonatomic,readonly) GLubyte opacity; +/** conforms to CCRGBAProtocol protocol */ +@property (nonatomic,readonly) ccColor3B color; + +@end diff --git a/tweejump/libs/cocos2d/CCMenu.m b/tweejump/libs/cocos2d/CCMenu.m new file mode 100755 index 0000000..d47e7c9 --- /dev/null +++ b/tweejump/libs/cocos2d/CCMenu.m @@ -0,0 +1,527 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-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. + * + */ + + + +#import "CCMenu.h" +#import "CCDirector.h" +#import "Support/CGPointExtension.h" +#import "ccMacros.h" + +#import +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED +#import "Platforms/iOS/CCDirectorIOS.h" +#import "Platforms/iOS/CCTouchDispatcher.h" +#elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED) +#import "Platforms/Mac/MacGLView.h" +#import "Platforms/Mac/CCDirectorMac.h" +#endif + +enum { + kDefaultPadding = 5, +}; + +@implementation CCMenu + +@synthesize opacity = opacity_, color = color_; + +- (id) init +{ + NSAssert(NO, @"CCMenu: Init not supported."); + [self release]; + return nil; +} + ++(id) menuWithItems: (CCMenuItem*) item, ... +{ + va_list args; + va_start(args,item); + + id s = [[[self alloc] initWithItems: item vaList:args] autorelease]; + + va_end(args); + return s; +} + +-(id) initWithItems: (CCMenuItem*) item vaList: (va_list) args +{ + if( (self=[super init]) ) { + +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED + self.isTouchEnabled = YES; +#elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED) + self.isMouseEnabled = YES; +#endif + + // menu in the center of the screen + CGSize s = [[CCDirector sharedDirector] winSize]; + + self.isRelativeAnchorPoint = NO; + anchorPoint_ = ccp(0.5f, 0.5f); + [self setContentSize:s]; + + // XXX: in v0.7, winSize should return the visible size + // XXX: so the bar calculation should be done there +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED + CGRect r = [[UIApplication sharedApplication] statusBarFrame]; + ccDeviceOrientation orientation = [[CCDirector sharedDirector] deviceOrientation]; + if( orientation == CCDeviceOrientationLandscapeLeft || orientation == CCDeviceOrientationLandscapeRight ) + s.height -= r.size.width; + else + s.height -= r.size.height; +#endif + self.position = ccp(s.width/2, s.height/2); + + int z=0; + + if (item) { + [self addChild: item z:z]; + CCMenuItem *i = va_arg(args, CCMenuItem*); + while(i) { + z++; + [self addChild: i z:z]; + i = va_arg(args, CCMenuItem*); + } + } + // [self alignItemsVertically]; + + selectedItem_ = nil; + state_ = kCCMenuStateWaiting; + } + + return self; +} + +-(void) dealloc +{ + [super dealloc]; +} + +/* + * override add: + */ +-(void) addChild:(CCMenuItem*)child z:(NSInteger)z tag:(NSInteger) aTag +{ + NSAssert( [child isKindOfClass:[CCMenuItem class]], @"Menu only supports MenuItem objects as children"); + [super addChild:child z:z tag:aTag]; +} + +- (void) onExit +{ + if(state_ == kCCMenuStateTrackingTouch) + { + [selectedItem_ unselected]; + state_ = kCCMenuStateWaiting; + selectedItem_ = nil; + } + [super onExit]; +} + +#pragma mark Menu - Touches + +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED +-(void) registerWithTouchDispatcher +{ + [[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:kCCMenuTouchPriority swallowsTouches:YES]; +} + +-(CCMenuItem *) itemForTouch: (UITouch *) touch +{ + CGPoint touchLocation = [touch locationInView: [touch view]]; + touchLocation = [[CCDirector sharedDirector] convertToGL: touchLocation]; + + CCMenuItem* item; + CCARRAY_FOREACH(children_, item){ + // ignore invisible and disabled items: issue #779, #866 + if ( [item visible] && [item isEnabled] ) { + + CGPoint local = [item convertToNodeSpace:touchLocation]; + CGRect r = [item rect]; + r.origin = CGPointZero; + + if( CGRectContainsPoint( r, local ) ) + return item; + } + } + return nil; +} + +-(BOOL) ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event +{ + if( state_ != kCCMenuStateWaiting || !visible_ ) + return NO; + + for( CCNode *c = self.parent; c != nil; c = c.parent ) + if( c.visible == NO ) + return NO; + + selectedItem_ = [self itemForTouch:touch]; + [selectedItem_ selected]; + + if( selectedItem_ ) { + state_ = kCCMenuStateTrackingTouch; + return YES; + } + return NO; +} + +-(void) ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event +{ + NSAssert(state_ == kCCMenuStateTrackingTouch, @"[Menu ccTouchEnded] -- invalid state"); + + [selectedItem_ unselected]; + [selectedItem_ activate]; + + state_ = kCCMenuStateWaiting; +} + +-(void) ccTouchCancelled:(UITouch *)touch withEvent:(UIEvent *)event +{ + NSAssert(state_ == kCCMenuStateTrackingTouch, @"[Menu ccTouchCancelled] -- invalid state"); + + [selectedItem_ unselected]; + + state_ = kCCMenuStateWaiting; +} + +-(void) ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event +{ + NSAssert(state_ == kCCMenuStateTrackingTouch, @"[Menu ccTouchMoved] -- invalid state"); + + CCMenuItem *currentItem = [self itemForTouch:touch]; + + if (currentItem != selectedItem_) { + [selectedItem_ unselected]; + selectedItem_ = currentItem; + [selectedItem_ selected]; + } +} + +#pragma mark Menu - Mouse + +#elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED) + +-(NSInteger) mouseDelegatePriority +{ + return kCCMenuMousePriority+1; +} + +-(CCMenuItem *) itemForMouseEvent: (NSEvent *) event +{ + CGPoint location = [(CCDirectorMac*)[CCDirector sharedDirector] convertEventToGL:event]; + + CCMenuItem* item; + CCARRAY_FOREACH(children_, item){ + // ignore invisible and disabled items: issue #779, #866 + if ( [item visible] && [item isEnabled] ) { + + CGPoint local = [item convertToNodeSpace:location]; + + CGRect r = [item rect]; + r.origin = CGPointZero; + + if( CGRectContainsPoint( r, local ) ) + return item; + } + } + return nil; +} + +-(BOOL) ccMouseUp:(NSEvent *)event +{ + if( ! visible_ ) + return NO; + + if(state_ == kCCMenuStateTrackingTouch) { + if( selectedItem_ ) { + [selectedItem_ unselected]; + [selectedItem_ activate]; + } + state_ = kCCMenuStateWaiting; + + return YES; + } + return NO; +} + +-(BOOL) ccMouseDown:(NSEvent *)event +{ + if( ! visible_ ) + return NO; + + selectedItem_ = [self itemForMouseEvent:event]; + [selectedItem_ selected]; + + if( selectedItem_ ) { + state_ = kCCMenuStateTrackingTouch; + return YES; + } + + return NO; +} + +-(BOOL) ccMouseDragged:(NSEvent *)event +{ + if( ! visible_ ) + return NO; + + if(state_ == kCCMenuStateTrackingTouch) { + CCMenuItem *currentItem = [self itemForMouseEvent:event]; + + if (currentItem != selectedItem_) { + [selectedItem_ unselected]; + selectedItem_ = currentItem; + [selectedItem_ selected]; + } + + return YES; + } + return NO; +} + +#endif // Mac Mouse support + +#pragma mark Menu - Alignment +-(void) alignItemsVertically +{ + [self alignItemsVerticallyWithPadding:kDefaultPadding]; +} +-(void) alignItemsVerticallyWithPadding:(float)padding +{ + float height = -padding; + + CCMenuItem *item; + CCARRAY_FOREACH(children_, item) + height += item.contentSize.height * item.scaleY + padding; + + float y = height / 2.0f; + + CCARRAY_FOREACH(children_, item) { + CGSize itemSize = item.contentSize; + [item setPosition:ccp(0, y - itemSize.height * item.scaleY / 2.0f)]; + y -= itemSize.height * item.scaleY + padding; + } +} + +-(void) alignItemsHorizontally +{ + [self alignItemsHorizontallyWithPadding:kDefaultPadding]; +} + +-(void) alignItemsHorizontallyWithPadding:(float)padding +{ + + float width = -padding; + CCMenuItem *item; + CCARRAY_FOREACH(children_, item) + width += item.contentSize.width * item.scaleX + padding; + + float x = -width / 2.0f; + + CCARRAY_FOREACH(children_, item){ + CGSize itemSize = item.contentSize; + [item setPosition:ccp(x + itemSize.width * item.scaleX / 2.0f, 0)]; + x += itemSize.width * item.scaleX + padding; + } +} + +-(void) alignItemsInColumns: (NSNumber *) columns, ... +{ + va_list args; + va_start(args, columns); + + [self alignItemsInColumns:columns vaList:args]; + + va_end(args); +} + +-(void) alignItemsInColumns: (NSNumber *) columns vaList: (va_list) args +{ + NSMutableArray *rows = [[NSMutableArray alloc] initWithObjects:columns, nil]; + columns = va_arg(args, NSNumber*); + while(columns) { + [rows addObject:columns]; + columns = va_arg(args, NSNumber*); + } + + int height = -5; + NSUInteger row = 0, rowHeight = 0, columnsOccupied = 0, rowColumns; + CCMenuItem *item; + CCARRAY_FOREACH(children_, item){ + NSAssert( row < [rows count], @"Too many menu items for the amount of rows/columns."); + + rowColumns = [(NSNumber *) [rows objectAtIndex:row] unsignedIntegerValue]; + NSAssert( rowColumns, @"Can't have zero columns on a row"); + + rowHeight = fmaxf(rowHeight, item.contentSize.height); + ++columnsOccupied; + + if(columnsOccupied >= rowColumns) { + height += rowHeight + 5; + + columnsOccupied = 0; + rowHeight = 0; + ++row; + } + } + NSAssert( !columnsOccupied, @"Too many rows/columns for available menu items." ); + + CGSize winSize = [[CCDirector sharedDirector] winSize]; + + row = 0; rowHeight = 0; rowColumns = 0; + float w, x, y = height / 2; + CCARRAY_FOREACH(children_, item) { + if(rowColumns == 0) { + rowColumns = [(NSNumber *) [rows objectAtIndex:row] unsignedIntegerValue]; + w = winSize.width / (1 + rowColumns); + x = w; + } + + CGSize itemSize = item.contentSize; + rowHeight = fmaxf(rowHeight, itemSize.height); + [item setPosition:ccp(x - winSize.width / 2, + y - itemSize.height / 2)]; + + x += w; + ++columnsOccupied; + + if(columnsOccupied >= rowColumns) { + y -= rowHeight + 5; + + columnsOccupied = 0; + rowColumns = 0; + rowHeight = 0; + ++row; + } + } + + [rows release]; +} + +-(void) alignItemsInRows: (NSNumber *) rows, ... +{ + va_list args; + va_start(args, rows); + + [self alignItemsInRows:rows vaList:args]; + + va_end(args); +} + +-(void) alignItemsInRows: (NSNumber *) rows vaList: (va_list) args +{ + NSMutableArray *columns = [[NSMutableArray alloc] initWithObjects:rows, nil]; + rows = va_arg(args, NSNumber*); + while(rows) { + [columns addObject:rows]; + rows = va_arg(args, NSNumber*); + } + + NSMutableArray *columnWidths = [[NSMutableArray alloc] init]; + NSMutableArray *columnHeights = [[NSMutableArray alloc] init]; + + int width = -10, columnHeight = -5; + NSUInteger column = 0, columnWidth = 0, rowsOccupied = 0, columnRows; + CCMenuItem *item; + CCARRAY_FOREACH(children_, item){ + NSAssert( column < [columns count], @"Too many menu items for the amount of rows/columns."); + + columnRows = [(NSNumber *) [columns objectAtIndex:column] unsignedIntegerValue]; + NSAssert( columnRows, @"Can't have zero rows on a column"); + + CGSize itemSize = item.contentSize; + columnWidth = fmaxf(columnWidth, itemSize.width); + columnHeight += itemSize.height + 5; + ++rowsOccupied; + + if(rowsOccupied >= columnRows) { + [columnWidths addObject:[NSNumber numberWithUnsignedInteger:columnWidth]]; + [columnHeights addObject:[NSNumber numberWithUnsignedInteger:columnHeight]]; + width += columnWidth + 10; + + rowsOccupied = 0; + columnWidth = 0; + columnHeight = -5; + ++column; + } + } + NSAssert( !rowsOccupied, @"Too many rows/columns for available menu items."); + + CGSize winSize = [[CCDirector sharedDirector] winSize]; + + column = 0; columnWidth = 0; columnRows = 0; + float x = -width / 2, y; + + CCARRAY_FOREACH(children_, item){ + if(columnRows == 0) { + columnRows = [(NSNumber *) [columns objectAtIndex:column] unsignedIntegerValue]; + y = ([(NSNumber *) [columnHeights objectAtIndex:column] intValue] + winSize.height) / 2; + } + + CGSize itemSize = item.contentSize; + columnWidth = fmaxf(columnWidth, itemSize.width); + [item setPosition:ccp(x + [(NSNumber *) [columnWidths objectAtIndex:column] unsignedIntegerValue] / 2, + y - winSize.height / 2)]; + + y -= itemSize.height + 10; + ++rowsOccupied; + + if(rowsOccupied >= columnRows) { + x += columnWidth + 5; + + rowsOccupied = 0; + columnRows = 0; + columnWidth = 0; + ++column; + } + } + + [columns release]; + [columnWidths release]; + [columnHeights release]; +} + +#pragma mark Menu - Opacity Protocol + +/** Override synthesized setOpacity to recurse items */ +- (void) setOpacity:(GLubyte)newOpacity +{ + opacity_ = newOpacity; + + id item; + CCARRAY_FOREACH(children_, item) + [item setOpacity:opacity_]; +} + +-(void) setColor:(ccColor3B)color +{ + color_ = color; + + id item; + CCARRAY_FOREACH(children_, item) + [item setColor:color_]; +} +@end diff --git a/tweejump/libs/cocos2d/CCMenuItem.h b/tweejump/libs/cocos2d/CCMenuItem.h new file mode 100755 index 0000000..2437394 --- /dev/null +++ b/tweejump/libs/cocos2d/CCMenuItem.h @@ -0,0 +1,377 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-2011 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. + * + */ + +#import "CCBlockSupport.h" + +#import "CCNode.h" +#import "CCProtocols.h" + +@class CCSprite; + +#define kCCItemSize 32 + +#pragma mark - +#pragma mark CCMenuItem +/** CCMenuItem base class + * + * Subclass CCMenuItem (or any subclass) to create your custom CCMenuItem objects. + */ +@interface CCMenuItem : CCNode +{ + NSInvocation *invocation_; +#if NS_BLOCKS_AVAILABLE + // used for menu items using a block + void (^block_)(id sender); +#endif + + BOOL isEnabled_; + BOOL isSelected_; +} + +/** returns whether or not the item is selected +@since v0.8.2 +*/ +@property (nonatomic,readonly) BOOL isSelected; + +/** Creates a CCMenuItem with a target/selector */ ++(id) itemWithTarget:(id)target selector:(SEL)selector; + +/** Initializes a CCMenuItem with a target/selector */ +-(id) initWithTarget:(id)target selector:(SEL)selector; + +#if NS_BLOCKS_AVAILABLE +/** Creates a CCMenuItem with the specified block. + The block will be "copied". + */ ++(id) itemWithBlock:(void(^)(id sender))block; + +/** Initializes a CCMenuItem with the specified block. + The block will be "copied". +*/ +-(id) initWithBlock:(void(^)(id sender))block; +#endif + +/** Returns the outside box in points */ +-(CGRect) rect; + +/** Activate the item */ +-(void) activate; + +/** The item was selected (not activated), similar to "mouse-over" */ +-(void) selected; + +/** The item was unselected */ +-(void) unselected; + +/** Enable or disabled the CCMenuItem */ +-(void) setIsEnabled:(BOOL)enabled; +/** Returns whether or not the CCMenuItem is enabled */ +-(BOOL) isEnabled; +@end + +#pragma mark - +#pragma mark CCMenuItemLabel + +/** An abstract class for "label" CCMenuItemLabel items + Any CCNode that supports the CCLabelProtocol protocol can be added. + Supported nodes: + - CCLabelBMFont + - CCLabelAtlas + - CCLabelTTF + */ +@interface CCMenuItemLabel : CCMenuItem +{ + CCNode *label_; + ccColor3B colorBackup; + ccColor3B disabledColor_; + float originalScale_; +} + +/** the color that will be used to disable the item */ +@property (nonatomic,readwrite) ccColor3B disabledColor; + +/** Label that is rendered. It can be any CCNode that implements the CCLabelProtocol */ +@property (nonatomic,readwrite,assign) CCNode* label; + +/** creates a CCMenuItemLabel with a Label. Target and selector will be nill */ ++(id) itemWithLabel:(CCNode*)label; + +/** creates a CCMenuItemLabel with a Label, target and selector */ ++(id) itemWithLabel:(CCNode*)label target:(id)target selector:(SEL)selector; + +/** initializes a CCMenuItemLabel with a Label, target and selector */ +-(id) initWithLabel:(CCNode*)label target:(id)target selector:(SEL)selector; + +#if NS_BLOCKS_AVAILABLE +/** creates a CCMenuItemLabel with a Label and a block to execute. + The block will be "copied". + */ ++(id) itemWithLabel:(CCNode*)label block:(void(^)(id sender))block; + +/** initializes a CCMenuItemLabel with a Label and a block to execute. + The block will be "copied". + */ +-(id) initWithLabel:(CCNode*)label block:(void(^)(id sender))block; +#endif + +/** sets a new string to the inner label */ +-(void) setString:(NSString*)label; + +/** Enable or disabled the CCMenuItemFont + @warning setIsEnabled changes the RGB color of the font + */ +-(void) setIsEnabled: (BOOL)enabled; +@end + +#pragma mark - +#pragma mark CCMenuItemAtlasFont + +/** A CCMenuItemAtlasFont + Helper class that creates a MenuItemLabel class with a LabelAtlas + */ +@interface CCMenuItemAtlasFont : CCMenuItemLabel +{ +} + +/** creates a menu item from a string and atlas with a target/selector */ ++(id) itemFromString: (NSString*) value charMapFile:(NSString*) charMapFile itemWidth:(int)itemWidth itemHeight:(int)itemHeight startCharMap:(char)startCharMap; + +/** creates a menu item from a string and atlas. Use it with MenuItemToggle */ ++(id) itemFromString: (NSString*) value charMapFile:(NSString*) charMapFile itemWidth:(int)itemWidth itemHeight:(int)itemHeight startCharMap:(char)startCharMap target:(id) rec selector:(SEL) cb; + +/** initializes a menu item from a string and atlas with a target/selector */ +-(id) initFromString: (NSString*) value charMapFile:(NSString*) charMapFile itemWidth:(int)itemWidth itemHeight:(int)itemHeight startCharMap:(char)startCharMap target:(id) rec selector:(SEL) cb; + +#if NS_BLOCKS_AVAILABLE +/** creates a menu item from a string and atlas. Use it with MenuItemToggle. + The block will be "copied". + */ ++(id) itemFromString: (NSString*) value charMapFile:(NSString*) charMapFile itemWidth:(int)itemWidth itemHeight:(int)itemHeight startCharMap:(char)startCharMap block:(void(^)(id sender))block; + +/** initializes a menu item from a string and atlas with a block. + The block will be "copied". + */ +-(id) initFromString: (NSString*) value charMapFile:(NSString*) charMapFile itemWidth:(int)itemWidth itemHeight:(int)itemHeight startCharMap:(char)startCharMap block:(void(^)(id sender))block; +#endif + +@end + +#pragma mark - +#pragma mark CCMenuItemFont + +/** A CCMenuItemFont + Helper class that creates a CCMenuItemLabel class with a Label + */ +@interface CCMenuItemFont : CCMenuItemLabel +{ + NSUInteger fontSize_; + NSString *fontName_; +} +/** set default font size */ ++(void) setFontSize: (NSUInteger) s; + +/** get default font size */ ++(NSUInteger) fontSize; + +/** set default font name */ ++(void) setFontName: (NSString*) n; + +/** get default font name */ ++(NSString*) fontName; + +/** creates a menu item from a string without target/selector. To be used with CCMenuItemToggle */ ++(id) itemFromString: (NSString*) value; + +/** creates a menu item from a string with a target/selector */ ++(id) itemFromString: (NSString*) value target:(id) r selector:(SEL) s; + +/** initializes a menu item from a string with a target/selector */ +-(id) initFromString: (NSString*) value target:(id) r selector:(SEL) s; + +/** set font size */ +-(void) setFontSize: (NSUInteger) s; + +/** get font size */ +-(NSUInteger) fontSize; + +/** set the font name */ +-(void) setFontName: (NSString*) n; + +/** get the font name */ +-(NSString*) fontName; + +#if NS_BLOCKS_AVAILABLE +/** creates a menu item from a string with the specified block. + The block will be "copied". + */ ++(id) itemFromString: (NSString*) value block:(void(^)(id sender))block; + +/** initializes a menu item from a string with the specified block. + The block will be "copied". + */ +-(id) initFromString: (NSString*) value block:(void(^)(id sender))block; +#endif +@end + +#pragma mark - +#pragma mark CCMenuItemSprite + +/** CCMenuItemSprite accepts CCNode objects as items. + The images has 3 different states: + - unselected image + - selected image + - disabled image + + @since v0.8.0 + */ +@interface CCMenuItemSprite : CCMenuItem +{ + CCNode *normalImage_, *selectedImage_, *disabledImage_; +} + +// weak references + +/** the image used when the item is not selected */ +@property (nonatomic,readwrite,assign) CCNode *normalImage; +/** the image used when the item is selected */ +@property (nonatomic,readwrite,assign) CCNode *selectedImage; +/** the image used when the item is disabled */ +@property (nonatomic,readwrite,assign) CCNode *disabledImage; + +/** creates a menu item with a normal and selected image*/ ++(id) itemFromNormalSprite:(CCNode*)normalSprite selectedSprite:(CCNode*)selectedSprite; +/** creates a menu item with a normal and selected image with target/selector */ ++(id) itemFromNormalSprite:(CCNode*)normalSprite selectedSprite:(CCNode*)selectedSprite target:(id)target selector:(SEL)selector; +/** creates a menu item with a normal,selected and disabled image with target/selector */ ++(id) itemFromNormalSprite:(CCNode*)normalSprite selectedSprite:(CCNode*)selectedSprite disabledSprite:(CCNode*)disabledSprite target:(id)target selector:(SEL)selector; +/** initializes a menu item with a normal, selected and disabled image with target/selector */ +-(id) initFromNormalSprite:(CCNode*)normalSprite selectedSprite:(CCNode*)selectedSprite disabledSprite:(CCNode*)disabledSprite target:(id)target selector:(SEL)selector; + +#if NS_BLOCKS_AVAILABLE +/** creates a menu item with a normal and selected image with a block. + The block will be "copied". + */ ++(id) itemFromNormalSprite:(CCNode*)normalSprite selectedSprite:(CCNode*)selectedSprite block:(void(^)(id sender))block; +/** creates a menu item with a normal,selected and disabled image with a block. + The block will be "copied". + */ ++(id) itemFromNormalSprite:(CCNode*)normalSprite selectedSprite:(CCNode*)selectedSprite disabledSprite:(CCNode*)disabledSprite block:(void(^)(id sender))block; +/** initializes a menu item with a normal, selected and disabled image with a block. + The block will be "copied". + */ +-(id) initFromNormalSprite:(CCNode*)normalSprite selectedSprite:(CCNode*)selectedSprite disabledSprite:(CCNode*)disabledSprite block:(void(^)(id sender))block; +#endif + +@end + +#pragma mark - +#pragma mark CCMenuItemImage + +/** CCMenuItemImage accepts images as items. + The images has 3 different states: + - unselected image + - selected image + - disabled image + + For best results try that all images are of the same size + */ +@interface CCMenuItemImage : CCMenuItemSprite +{ +} + +/** creates a menu item with a normal and selected image*/ ++(id) itemFromNormalImage: (NSString*)value selectedImage:(NSString*) value2; +/** creates a menu item with a normal and selected image with target/selector */ ++(id) itemFromNormalImage: (NSString*)value selectedImage:(NSString*) value2 target:(id) r selector:(SEL) s; +/** creates a menu item with a normal,selected and disabled image with target/selector */ ++(id) itemFromNormalImage: (NSString*)value selectedImage:(NSString*) value2 disabledImage:(NSString*) value3 target:(id) r selector:(SEL) s; +/** initializes a menu item with a normal, selected and disabled image with target/selector */ +-(id) initFromNormalImage: (NSString*) value selectedImage:(NSString*)value2 disabledImage:(NSString*) value3 target:(id) r selector:(SEL) s; +#if NS_BLOCKS_AVAILABLE +/** creates a menu item with a normal and selected image with a block. + The block will be "copied". + */ ++(id) itemFromNormalImage: (NSString*)value selectedImage:(NSString*) value2 block:(void(^)(id sender))block; +/** creates a menu item with a normal,selected and disabled image with a block. + The block will be "copied". +*/ ++(id) itemFromNormalImage: (NSString*)value selectedImage:(NSString*) value2 disabledImage:(NSString*) value3 block:(void(^)(id sender))block; +/** initializes a menu item with a normal, selected and disabled image with a block. + The block will be "copied". +*/ +-(id) initFromNormalImage: (NSString*) value selectedImage:(NSString*)value2 disabledImage:(NSString*) value3 block:(void(^)(id sender))block; +#endif +@end + +#pragma mark - +#pragma mark CCMenuItemToggle + +/** A CCMenuItemToggle + A simple container class that "toggles" it's inner items + The inner itmes can be any MenuItem + */ +@interface CCMenuItemToggle : CCMenuItem +{ + NSUInteger selectedIndex_; + NSMutableArray* subItems_; + GLubyte opacity_; + ccColor3B color_; +} + +/** conforms with CCRGBAProtocol protocol */ +@property (nonatomic,readonly) GLubyte opacity; +/** conforms with CCRGBAProtocol protocol */ +@property (nonatomic,readonly) ccColor3B color; + +/** returns the selected item */ +@property (nonatomic,readwrite) NSUInteger selectedIndex; +/** NSMutableArray that contains the subitems. You can add/remove items in runtime, and you can replace the array with a new one. + @since v0.7.2 + */ +@property (nonatomic,readwrite,retain) NSMutableArray *subItems; + +/** creates a menu item from a list of items with a target/selector */ ++(id) itemWithTarget:(id)t selector:(SEL)s items:(CCMenuItem*) item, ... NS_REQUIRES_NIL_TERMINATION; + +/** initializes a menu item from a list of items with a target selector */ +-(id) initWithTarget:(id)t selector:(SEL)s items:(CCMenuItem*) item vaList:(va_list) args; + +#if NS_BLOCKS_AVAILABLE +/** creates a menu item from a list of items and executes the given block when the item is selected. + The block will be "copied". + */ ++(id) itemWithBlock:(void(^)(id sender))block items:(CCMenuItem*)item, ... NS_REQUIRES_NIL_TERMINATION; + +/** initializes a menu item from a list of items with a block. + The block will be "copied". + */ +-(id) initWithBlock:(void (^)(id))block items:(CCMenuItem*)item vaList:(va_list)args; +#endif + +/** return the selected item */ +-(CCMenuItem*) selectedItem; +@end + diff --git a/tweejump/libs/cocos2d/CCMenuItem.m b/tweejump/libs/cocos2d/CCMenuItem.m new file mode 100755 index 0000000..f88c0e0 --- /dev/null +++ b/tweejump/libs/cocos2d/CCMenuItem.m @@ -0,0 +1,795 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-2011 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. + * + */ + +#import "CCMenuItem.h" +#import "CCLabelTTF.h" +#import "CCLabelAtlas.h" +#import "CCActionInterval.h" +#import "CCSprite.h" +#import "Support/CGPointExtension.h" +#import "CCBlockSupport.h" + + static NSUInteger _fontSize = kCCItemSize; +static NSString *_fontName = @"Marker Felt"; +static BOOL _fontNameRelease = NO; + + +const uint32_t kCurrentItem = 0xc0c05001; +const uint32_t kZoomActionTag = 0xc0c05002; + + +#pragma mark - +#pragma mark CCMenuItem + +@implementation CCMenuItem + +@synthesize isSelected=isSelected_; +-(id) init +{ + NSAssert(NO, @"MenuItemInit: Init not supported."); + [self release]; + return nil; +} + ++(id) itemWithTarget:(id) r selector:(SEL) s +{ + return [[[self alloc] initWithTarget:r selector:s] autorelease]; +} + +-(id) initWithTarget:(id) rec selector:(SEL) cb +{ + if((self=[super init]) ) { + + anchorPoint_ = ccp(0.5f, 0.5f); + NSMethodSignature * sig = nil; + + if( rec && cb ) { + sig = [rec methodSignatureForSelector:cb]; + + invocation_ = nil; + invocation_ = [NSInvocation invocationWithMethodSignature:sig]; + [invocation_ setTarget:rec]; + [invocation_ setSelector:cb]; +#if NS_BLOCKS_AVAILABLE + if ([sig numberOfArguments] == 3) +#endif + [invocation_ setArgument:&self atIndex:2]; + + [invocation_ retain]; + } + + isEnabled_ = YES; + isSelected_ = NO; + } + + return self; +} + +#if NS_BLOCKS_AVAILABLE + ++(id) itemWithBlock:(void(^)(id sender))block { + return [[[self alloc] initWithBlock:block] autorelease]; +} + +-(id) initWithBlock:(void(^)(id sender))block { + block_ = [block copy]; + return [self initWithTarget:block_ selector:@selector(ccCallbackBlockWithSender:)]; +} + +#endif // NS_BLOCKS_AVAILABLE + +-(void) dealloc +{ + [invocation_ release]; + +#if NS_BLOCKS_AVAILABLE + [block_ release]; +#endif + + [super dealloc]; +} + +-(void) selected +{ + isSelected_ = YES; +} + +-(void) unselected +{ + isSelected_ = NO; +} + +-(void) activate +{ + if(isEnabled_) + [invocation_ invoke]; +} + +-(void) setIsEnabled: (BOOL)enabled +{ + isEnabled_ = enabled; +} + +-(BOOL) isEnabled +{ + return isEnabled_; +} + +-(CGRect) rect +{ + return CGRectMake( position_.x - contentSize_.width*anchorPoint_.x, + position_.y - contentSize_.height*anchorPoint_.y, + contentSize_.width, contentSize_.height); +} + +@end + + +#pragma mark - +#pragma mark CCMenuItemLabel + +@implementation CCMenuItemLabel + +@synthesize disabledColor = disabledColor_; + ++(id) itemWithLabel:(CCNode*)label target:(id)target selector:(SEL)selector +{ + return [[[self alloc] initWithLabel:label target:target selector:selector] autorelease]; +} + ++(id) itemWithLabel:(CCNode*)label +{ + return [[[self alloc] initWithLabel:label target:nil selector:NULL] autorelease]; +} + +-(id) initWithLabel:(CCNode*)label target:(id)target selector:(SEL)selector +{ + if( (self=[super initWithTarget:target selector:selector]) ) { + originalScale_ = 1; + colorBackup = ccWHITE; + disabledColor_ = ccc3( 126,126,126); + self.label = label; + + } + return self; +} + +#if NS_BLOCKS_AVAILABLE + ++(id) itemWithLabel:(CCNode*)label block:(void(^)(id sender))block { + return [[[self alloc] initWithLabel:label block:block] autorelease]; +} + +-(id) initWithLabel:(CCNode*)label block:(void(^)(id sender))block { + block_ = [block copy]; + return [self initWithLabel:label target:block_ selector:@selector(ccCallbackBlockWithSender:)]; +} + +#endif // NS_BLOCKS_AVAILABLE + +-(CCNode*) label +{ + return label_; +} +-(void) setLabel:(CCNode*) label +{ + if( label != label_ ) { + [self removeChild:label_ cleanup:YES]; + [self addChild:label]; + + label_ = label; + label_.anchorPoint = ccp(0,0); + + [self setContentSize:[label_ contentSize]]; + } +} + +-(void) setString:(NSString *)string +{ + [label_ setString:string]; + [self setContentSize: [label_ contentSize]]; +} + +-(void) activate { + if(isEnabled_) { + [self stopAllActions]; + + self.scale = originalScale_; + + [super activate]; + } +} + +-(void) selected +{ + // subclass to change the default action + if(isEnabled_) { + [super selected]; + + CCAction *action = [self getActionByTag:kZoomActionTag]; + if( action ) + [self stopAction:action]; + else + originalScale_ = self.scale; + + CCAction *zoomAction = [CCScaleTo actionWithDuration:0.1f scale:originalScale_ * 1.2f]; + zoomAction.tag = kZoomActionTag; + [self runAction:zoomAction]; + } +} + +-(void) unselected +{ + // subclass to change the default action + if(isEnabled_) { + [super unselected]; + [self stopActionByTag:kZoomActionTag]; + CCAction *zoomAction = [CCScaleTo actionWithDuration:0.1f scale:originalScale_]; + zoomAction.tag = kZoomActionTag; + [self runAction:zoomAction]; + } +} + +-(void) setIsEnabled: (BOOL)enabled +{ + if( isEnabled_ != enabled ) { + if(enabled == NO) { + colorBackup = [label_ color]; + [label_ setColor: disabledColor_]; + } + else + [label_ setColor:colorBackup]; + } + + [super setIsEnabled:enabled]; +} + +- (void) setOpacity: (GLubyte)opacity +{ + [label_ setOpacity:opacity]; +} +-(GLubyte) opacity +{ + return [label_ opacity]; +} +-(void) setColor:(ccColor3B)color +{ + [label_ setColor:color]; +} +-(ccColor3B) color +{ + return [label_ color]; +} +@end + +#pragma mark - +#pragma mark CCMenuItemAtlasFont + +@implementation CCMenuItemAtlasFont + ++(id) itemFromString: (NSString*) value charMapFile:(NSString*) charMapFile itemWidth:(int)itemWidth itemHeight:(int)itemHeight startCharMap:(char)startCharMap +{ + return [CCMenuItemAtlasFont itemFromString:value charMapFile:charMapFile itemWidth:itemWidth itemHeight:itemHeight startCharMap:startCharMap target:nil selector:nil]; +} + ++(id) itemFromString: (NSString*) value charMapFile:(NSString*) charMapFile itemWidth:(int)itemWidth itemHeight:(int)itemHeight startCharMap:(char)startCharMap target:(id) rec selector:(SEL) cb +{ + return [[[self alloc] initFromString:value charMapFile:charMapFile itemWidth:itemWidth itemHeight:itemHeight startCharMap:startCharMap target:rec selector:cb] autorelease]; +} + +-(id) initFromString: (NSString*) value charMapFile:(NSString*) charMapFile itemWidth:(int)itemWidth itemHeight:(int)itemHeight startCharMap:(char)startCharMap target:(id) rec selector:(SEL) cb +{ + NSAssert( [value length] != 0, @"value length must be greater than 0"); + + CCLabelAtlas *label = [[CCLabelAtlas alloc] initWithString:value charMapFile:charMapFile itemWidth:itemWidth itemHeight:itemHeight startCharMap:startCharMap]; + [label autorelease]; + + if((self=[super initWithLabel:label target:rec selector:cb]) ) { + // do something ? + } + + return self; +} + +#if NS_BLOCKS_AVAILABLE ++(id) itemFromString:(NSString*)value charMapFile:(NSString*)charMapFile itemWidth:(int)itemWidth itemHeight:(int)itemHeight startCharMap:(char)startCharMap block:(void(^)(id sender))block { + return [[[self alloc] initFromString:value charMapFile:charMapFile itemWidth:itemWidth itemHeight:itemHeight startCharMap:startCharMap block:block] autorelease]; +} + +-(id) initFromString:(NSString*)value charMapFile:(NSString*)charMapFile itemWidth:(int)itemWidth itemHeight:(int)itemHeight startCharMap:(char)startCharMap block:(void(^)(id sender))block { + block_ = [block copy]; + return [self initFromString:value charMapFile:charMapFile itemWidth:itemWidth itemHeight:itemHeight startCharMap:startCharMap target:block_ selector:@selector(ccCallbackBlockWithSender:)]; +} +#endif // NS_BLOCKS_AVAILABLE + +-(void) dealloc +{ + [super dealloc]; +} +@end + + +#pragma mark - +#pragma mark CCMenuItemFont + +@implementation CCMenuItemFont + ++(void) setFontSize: (NSUInteger) s +{ + _fontSize = s; +} + ++(NSUInteger) fontSize +{ + return _fontSize; +} + ++(void) setFontName: (NSString*) n +{ + if( _fontNameRelease ) + [_fontName release]; + + _fontName = [n retain]; + _fontNameRelease = YES; +} + ++(NSString*) fontName +{ + return _fontName; +} + ++(id) itemFromString: (NSString*) value target:(id) r selector:(SEL) s +{ + return [[[self alloc] initFromString: value target:r selector:s] autorelease]; +} + ++(id) itemFromString: (NSString*) value +{ + return [[[self alloc] initFromString: value target:nil selector:nil] autorelease]; +} + +-(id) initFromString: (NSString*) value target:(id) rec selector:(SEL) cb +{ + NSAssert( [value length] != 0, @"Value length must be greater than 0"); + + fontName_ = [_fontName copy]; + fontSize_ = _fontSize; + + CCLabelTTF *label = [CCLabelTTF labelWithString:value fontName:fontName_ fontSize:fontSize_]; + + if((self=[super initWithLabel:label target:rec selector:cb]) ) { + // do something ? + } + + return self; +} + +-(void) recreateLabel +{ + CCLabelTTF *label = [CCLabelTTF labelWithString:[label_ string] fontName:fontName_ fontSize:fontSize_]; + self.label = label; +} + +-(void) setFontSize: (NSUInteger) size +{ + fontSize_ = size; + [self recreateLabel]; +} + +-(NSUInteger) fontSize +{ + return fontSize_; +} + +-(void) setFontName: (NSString*) fontName +{ + if (fontName_) + [fontName_ release]; + + fontName_ = [fontName copy]; + [self recreateLabel]; +} + +-(NSString*) fontName +{ + return fontName_; +} + +#if NS_BLOCKS_AVAILABLE ++(id) itemFromString: (NSString*) value block:(void(^)(id sender))block +{ + return [[[self alloc] initFromString:value block:block] autorelease]; +} + +-(id) initFromString: (NSString*) value block:(void(^)(id sender))block +{ + block_ = [block copy]; + return [self initFromString:value target:block_ selector:@selector(ccCallbackBlockWithSender:)]; +} +#endif // NS_BLOCKS_AVAILABLE + +@end + +#pragma mark - +#pragma mark CCMenuItemSprite +@implementation CCMenuItemSprite + +@synthesize normalImage=normalImage_, selectedImage=selectedImage_, disabledImage=disabledImage_; + ++(id) itemFromNormalSprite:(CCNode*)normalSprite selectedSprite:(CCNode*)selectedSprite +{ + return [self itemFromNormalSprite:normalSprite selectedSprite:selectedSprite disabledSprite:nil target:nil selector:nil]; +} ++(id) itemFromNormalSprite:(CCNode*)normalSprite selectedSprite:(CCNode*)selectedSprite target:(id)target selector:(SEL)selector +{ + return [self itemFromNormalSprite:normalSprite selectedSprite:selectedSprite disabledSprite:nil target:target selector:selector]; +} ++(id) itemFromNormalSprite:(CCNode*)normalSprite selectedSprite:(CCNode*)selectedSprite disabledSprite:(CCNode*)disabledSprite target:(id)target selector:(SEL)selector +{ + return [[[self alloc] initFromNormalSprite:normalSprite selectedSprite:selectedSprite disabledSprite:disabledSprite target:target selector:selector] autorelease]; +} +-(id) initFromNormalSprite:(CCNode*)normalSprite selectedSprite:(CCNode*)selectedSprite disabledSprite:(CCNode*)disabledSprite target:(id)target selector:(SEL)selector +{ + if( (self=[super initWithTarget:target selector:selector]) ) { + + self.normalImage = normalSprite; + self.selectedImage = selectedSprite; + self.disabledImage = disabledSprite; + + [self setContentSize: [normalImage_ contentSize]]; + } + return self; +} + +#if NS_BLOCKS_AVAILABLE ++(id) itemFromNormalSprite:(CCNode*)normalSprite selectedSprite:(CCNode*)selectedSprite block:(void(^)(id sender))block { + return [self itemFromNormalSprite:normalSprite selectedSprite:selectedSprite disabledSprite:nil block:block]; +} + ++(id) itemFromNormalSprite:(CCNode*)normalSprite selectedSprite:(CCNode*)selectedSprite disabledSprite:(CCNode*)disabledSprite block:(void(^)(id sender))block { + return [[[self alloc] initFromNormalSprite:normalSprite selectedSprite:selectedSprite disabledSprite:disabledSprite block:block] autorelease]; +} + +-(id) initFromNormalSprite:(CCNode*)normalSprite selectedSprite:(CCNode*)selectedSprite disabledSprite:(CCNode*)disabledSprite block:(void(^)(id sender))block { + block_ = [block copy]; + return [self initFromNormalSprite:normalSprite selectedSprite:selectedSprite disabledSprite:disabledSprite target:block_ selector:@selector(ccCallbackBlockWithSender:)]; +} +#endif // NS_BLOCKS_AVAILABLE + + +-(void) setNormalImage:(CCNode *)image +{ + if( image != normalImage_ ) { + image.anchorPoint = ccp(0,0); + image.visible = YES; + + [self removeChild:normalImage_ cleanup:YES]; + [self addChild:image]; + + normalImage_ = image; + } +} + +-(void) setSelectedImage:(CCNode *)image +{ + if( image != selectedImage_ ) { + image.anchorPoint = ccp(0,0); + image.visible = NO; + + [self removeChild:selectedImage_ cleanup:YES]; + [self addChild:image]; + + selectedImage_ = image; + } +} + +-(void) setDisabledImage:(CCNode *)image +{ + if( image != disabledImage_ ) { + image.anchorPoint = ccp(0,0); + image.visible = NO; + + [self removeChild:disabledImage_ cleanup:YES]; + [self addChild:image]; + + disabledImage_ = image; + } +} + +#pragma mark CCMenuItemImage - CCRGBAProtocol protocol +- (void) setOpacity: (GLubyte)opacity +{ + [normalImage_ setOpacity:opacity]; + [selectedImage_ setOpacity:opacity]; + [disabledImage_ setOpacity:opacity]; +} + +-(void) setColor:(ccColor3B)color +{ + [normalImage_ setColor:color]; + [selectedImage_ setColor:color]; + [disabledImage_ setColor:color]; +} + +-(GLubyte) opacity +{ + return [normalImage_ opacity]; +} + +-(ccColor3B) color +{ + return [normalImage_ color]; +} + +-(void) selected +{ + [super selected]; + + if( selectedImage_ ) { + [normalImage_ setVisible:NO]; + [selectedImage_ setVisible:YES]; + [disabledImage_ setVisible:NO]; + + } else { // there is not selected image + + [normalImage_ setVisible:YES]; + [selectedImage_ setVisible:NO]; + [disabledImage_ setVisible:NO]; + } +} + +-(void) unselected +{ + [super unselected]; + [normalImage_ setVisible:YES]; + [selectedImage_ setVisible:NO]; + [disabledImage_ setVisible:NO]; +} + +-(void) setIsEnabled:(BOOL)enabled +{ + [super setIsEnabled:enabled]; + + if( enabled ) { + [normalImage_ setVisible:YES]; + [selectedImage_ setVisible:NO]; + [disabledImage_ setVisible:NO]; + + } else { + if( disabledImage_ ) { + [normalImage_ setVisible:NO]; + [selectedImage_ setVisible:NO]; + [disabledImage_ setVisible:YES]; + } else { + [normalImage_ setVisible:YES]; + [selectedImage_ setVisible:NO]; + [disabledImage_ setVisible:NO]; + } + } +} + +@end + +#pragma mark - +#pragma mark CCMenuItemImage + +@implementation CCMenuItemImage + ++(id) itemFromNormalImage: (NSString*)value selectedImage:(NSString*) value2 +{ + return [self itemFromNormalImage:value selectedImage:value2 disabledImage: nil target:nil selector:nil]; +} + ++(id) itemFromNormalImage: (NSString*)value selectedImage:(NSString*) value2 target:(id) t selector:(SEL) s +{ + return [self itemFromNormalImage:value selectedImage:value2 disabledImage: nil target:t selector:s]; +} + ++(id) itemFromNormalImage: (NSString*)value selectedImage:(NSString*) value2 disabledImage: (NSString*) value3 +{ + return [[[self alloc] initFromNormalImage:value selectedImage:value2 disabledImage:value3 target:nil selector:nil] autorelease]; +} + ++(id) itemFromNormalImage: (NSString*)value selectedImage:(NSString*) value2 disabledImage: (NSString*) value3 target:(id) t selector:(SEL) s +{ + return [[[self alloc] initFromNormalImage:value selectedImage:value2 disabledImage:value3 target:t selector:s] autorelease]; +} + +-(id) initFromNormalImage: (NSString*) normalI selectedImage:(NSString*)selectedI disabledImage: (NSString*) disabledI target:(id)t selector:(SEL)sel +{ + CCNode *normalImage = [CCSprite spriteWithFile:normalI]; + CCNode *selectedImage = nil; + CCNode *disabledImage = nil; + + if( selectedI ) + selectedImage = [CCSprite spriteWithFile:selectedI]; + if(disabledI) + disabledImage = [CCSprite spriteWithFile:disabledI]; + + return [self initFromNormalSprite:normalImage selectedSprite:selectedImage disabledSprite:disabledImage target:t selector:sel]; +} + +#if NS_BLOCKS_AVAILABLE + ++(id) itemFromNormalImage: (NSString*)value selectedImage:(NSString*) value2 block:(void(^)(id sender))block { + return [self itemFromNormalImage:value selectedImage:value2 disabledImage:nil block:block]; +} + ++(id) itemFromNormalImage: (NSString*)value selectedImage:(NSString*) value2 disabledImage:(NSString*) value3 block:(void(^)(id sender))block { + return [[[self alloc] initFromNormalImage:value selectedImage:value2 disabledImage:value3 block:block] autorelease]; +} + +-(id) initFromNormalImage: (NSString*) value selectedImage:(NSString*)value2 disabledImage:(NSString*) value3 block:(void(^)(id sender))block { + block_ = [block copy]; + return [self initFromNormalImage:value selectedImage:value2 disabledImage:value3 target:block_ selector:@selector(ccCallbackBlockWithSender:)]; +} + +#endif // NS_BLOCKS_AVAILABLE + +@end + +#pragma mark - +#pragma mark CCMenuItemToggle + +// +// MenuItemToggle +// +@implementation CCMenuItemToggle + +@synthesize subItems = subItems_; +@synthesize opacity = opacity_, color = color_; + ++(id) itemWithTarget: (id)t selector: (SEL)sel items: (CCMenuItem*) item, ... +{ + va_list args; + va_start(args, item); + + id s = [[[self alloc] initWithTarget: t selector:sel items: item vaList:args] autorelease]; + + va_end(args); + return s; +} + +-(id) initWithTarget: (id)t selector: (SEL)sel items:(CCMenuItem*) item vaList: (va_list) args +{ + if( (self=[super initWithTarget:t selector:sel]) ) { + + self.subItems = [NSMutableArray arrayWithCapacity:2]; + + int z = 0; + CCMenuItem *i = item; + while(i) { + z++; + [subItems_ addObject:i]; + i = va_arg(args, CCMenuItem*); + } + + selectedIndex_ = NSUIntegerMax; + [self setSelectedIndex:0]; + } + + return self; +} + +#if NS_BLOCKS_AVAILABLE + ++(id) itemWithBlock:(void(^)(id sender))block items:(CCMenuItem*)item, ... { + va_list args; + va_start(args, item); + + id s = [[[self alloc] initWithBlock:block items:item vaList:args] autorelease]; + + va_end(args); + return s; +} + +-(id) initWithBlock:(void (^)(id))block items:(CCMenuItem*)item vaList:(va_list)args { + block_ = [block copy]; + return [self initWithTarget:block_ selector:@selector(ccCallbackBlockWithSender:) items:item vaList:args]; +} + +#endif // NS_BLOCKS_AVAILABLE + +-(void) dealloc +{ + [subItems_ release]; + [super dealloc]; +} + +-(void)setSelectedIndex:(NSUInteger)index +{ + if( index != selectedIndex_ ) { + selectedIndex_=index; + [self removeChildByTag:kCurrentItem cleanup:NO]; + + CCMenuItem *item = [subItems_ objectAtIndex:selectedIndex_]; + [self addChild:item z:0 tag:kCurrentItem]; + + CGSize s = [item contentSize]; + [self setContentSize: s]; + item.position = ccp( s.width/2, s.height/2 ); + } +} + +-(NSUInteger) selectedIndex +{ + return selectedIndex_; +} + + +-(void) selected +{ + [super selected]; + [[subItems_ objectAtIndex:selectedIndex_] selected]; +} + +-(void) unselected +{ + [super unselected]; + [[subItems_ objectAtIndex:selectedIndex_] unselected]; +} + +-(void) activate +{ + // update index + if( isEnabled_ ) { + NSUInteger newIndex = (selectedIndex_ + 1) % [subItems_ count]; + [self setSelectedIndex:newIndex]; + + } + + [super activate]; +} + +-(void) setIsEnabled: (BOOL)enabled +{ + [super setIsEnabled:enabled]; + for(CCMenuItem* item in subItems_) + [item setIsEnabled:enabled]; +} + +-(CCMenuItem*) selectedItem +{ + return [subItems_ objectAtIndex:selectedIndex_]; +} + +#pragma mark CCMenuItemToggle - CCRGBAProtocol protocol + +- (void) setOpacity: (GLubyte)opacity +{ + opacity_ = opacity; + for(CCMenuItem* item in subItems_) + [item setOpacity:opacity]; +} + +- (void) setColor:(ccColor3B)color +{ + color_ = color; + for(CCMenuItem* item in subItems_) + [item setColor:color]; +} + +@end diff --git a/tweejump/libs/cocos2d/CCMotionStreak.h b/tweejump/libs/cocos2d/CCMotionStreak.h new file mode 100755 index 0000000..e017124 --- /dev/null +++ b/tweejump/libs/cocos2d/CCMotionStreak.h @@ -0,0 +1,67 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008, 2009 Jason Booth + * + * 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. + * + */ + +#import +#import "CCNode.h" +#import "CCRibbon.h" + +/** + * CCMotionStreak manages a Ribbon based on it's motion in absolute space. + * You construct it with a fadeTime, minimum segment size, texture path, texture + * length and color. The fadeTime controls how long it takes each vertex in + * the streak to fade out, the minimum segment size it how many pixels the + * streak will move before adding a new ribbon segement, and the texture + * length is the how many pixels the texture is stretched across. The texture + * is vertically aligned along the streak segemnts. + * + * Limitations: + * CCMotionStreak, by default, will use the GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA blending function. + * This blending function might not be the correct one for certain textures. + * But you can change it by using: + * [obj setBlendFunc: (ccBlendfunc) {new_src_blend_func, new_dst_blend_func}]; + * + * @since v0.8.1 + */ +@interface CCMotionStreak : CCNode +{ + CCRibbon* ribbon_; + float segThreshold_; + float width_; + CGPoint lastLocation_; +} + +/** Ribbon used by MotionStreak (weak reference) */ +@property (nonatomic,readonly) CCRibbon *ribbon; + +/** creates the a MotionStreak. The image will be loaded using the TextureMgr. */ ++(id)streakWithFade:(float)fade minSeg:(float)seg image:(NSString*)path width:(float)width length:(float)length color:(ccColor4B)color; + +/** initializes a MotionStreak. The file will be loaded using the TextureMgr. */ +-(id)initWithFade:(float)fade minSeg:(float)seg image:(NSString*)path width:(float)width length:(float)length color:(ccColor4B)color; + +/** polling function */ +-(void)update:(ccTime)delta; + +@end diff --git a/tweejump/libs/cocos2d/CCMotionStreak.m b/tweejump/libs/cocos2d/CCMotionStreak.m new file mode 100755 index 0000000..42737b9 --- /dev/null +++ b/tweejump/libs/cocos2d/CCMotionStreak.m @@ -0,0 +1,104 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008, 2009 Jason Booth + * + * 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. + * + * + ********************************************************* + * + * Motion Streak manages a Ribbon based on it's motion in absolute space. + * You construct it with a fadeTime, minimum segment size, texture path, texture + * length and color. The fadeTime controls how long it takes each vertex in + * the streak to fade out, the minimum segment size it how many pixels the + * streak will move before adding a new ribbon segement, and the texture + * length is the how many pixels the texture is stretched across. The texture + * is vertically aligned along the streak segemnts. + */ + +#import "CCMotionStreak.h" +#import "Support/CGPointExtension.h" + +@implementation CCMotionStreak + +@synthesize ribbon = ribbon_; + ++(id)streakWithFade:(float)fade minSeg:(float)seg image:(NSString*)path width:(float)width length:(float)length color:(ccColor4B)color +{ + return [[[self alloc] initWithFade:(float)fade minSeg:seg image:path width:width length:length color:color] autorelease]; +} + +-(id)initWithFade:(float)fade minSeg:(float)seg image:(NSString*)path width:(float)width length:(float)length color:(ccColor4B)color +{ + if( (self=[super init])) { + segThreshold_ = seg; + width_ = width; + lastLocation_ = CGPointZero; + ribbon_ = [CCRibbon ribbonWithWidth:width_ image:path length:length color:color fade:fade]; + [self addChild:ribbon_]; + + // update ribbon position. Use schedule:interval and not scheduleUpdated. issue #1075 + [self schedule:@selector(update:) interval:0]; + } + return self; +} + +-(void)update:(ccTime)delta +{ + CGPoint location = [self convertToWorldSpace:CGPointZero]; + [ribbon_ setPosition:ccp(-1*location.x, -1*location.y)]; + float len = ccpLength(ccpSub(lastLocation_, location)); + if (len > segThreshold_) + { + [ribbon_ addPointAt:location width:width_]; + lastLocation_ = location; + } + [ribbon_ update:delta]; +} + + +-(void)dealloc +{ + [super dealloc]; +} + +#pragma mark MotionStreak - CocosNodeTexture protocol + +-(void) setTexture:(CCTexture2D*) texture +{ + [ribbon_ setTexture: texture]; +} + +-(CCTexture2D*) texture +{ + return [ribbon_ texture]; +} + +-(ccBlendFunc) blendFunc +{ + return [ribbon_ blendFunc]; +} + +-(void) setBlendFunc:(ccBlendFunc)blendFunc +{ + [ribbon_ setBlendFunc:blendFunc]; +} + +@end diff --git a/tweejump/libs/cocos2d/CCNode.h b/tweejump/libs/cocos2d/CCNode.h new file mode 100755 index 0000000..64acdc5 --- /dev/null +++ b/tweejump/libs/cocos2d/CCNode.h @@ -0,0 +1,529 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2009 Valentin Milea + * + * Copyright (c) 2008-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. + */ + +#import + +#import "Platforms/CCGL.h" +#import "CCAction.h" +#import "ccTypes.h" +#import "CCTexture2D.h" +#import "CCProtocols.h" +#import "ccConfig.h" +#import "Support/CCArray.h" + +enum { + kCCNodeTagInvalid = -1, +}; + +@class CCCamera; +@class CCGridBase; + +/** CCNode is the main element. Anything thats gets drawn or contains things that get drawn is a CCNode. + The most popular CCNodes are: CCScene, CCLayer, CCSprite, CCMenu. + + The main features of a CCNode are: + - They can contain other CCNode nodes (addChild, getChildByTag, removeChild, etc) + - They can schedule periodic callback (schedule, unschedule, etc) + - They can execute actions (runAction, stopAction, etc) + + Some CCNode nodes provide extra functionality for them or their children. + + Subclassing a CCNode usually means (one/all) of: + - overriding init to initialize resources and schedule callbacks + - create callbacks to handle the advancement of time + - overriding draw to render the node + + Features of CCNode: + - position + - scale (x, y) + - rotation (in degrees, clockwise) + - CCCamera (an interface to gluLookAt ) + - CCGridBase (to do mesh transformations) + - anchor point + - size + - visible + - z-order + - openGL z position + + Default values: + - rotation: 0 + - position: (x=0,y=0) + - scale: (x=1,y=1) + - contentSize: (x=0,y=0) + - anchorPoint: (x=0,y=0) + + Limitations: + - A CCNode is a "void" object. It doesn't have a texture + + Order in transformations with grid disabled + -# The node will be translated (position) + -# The node will be rotated (rotation) + -# The node will be scaled (scale) + -# The node will be moved according to the camera values (camera) + + Order in transformations with grid enabled + -# The node will be translated (position) + -# The node will be rotated (rotation) + -# The node will be scaled (scale) + -# The grid will capture the screen + -# The node will be moved according to the camera values (camera) + -# The grid will render the captured screen + + Camera: + - Each node has a camera. By default it points to the center of the CCNode. + */ +@interface CCNode : NSObject +{ + // rotation angle + float rotation_; + + // scaling factors + float scaleX_, scaleY_; + + // position of the node + CGPoint position_; + CGPoint positionInPixels_; + + // skew angles + float skewX_, skewY_; + + // is visible + BOOL visible_; + + // anchor point in pixels + CGPoint anchorPointInPixels_; + // anchor point normalized + CGPoint anchorPoint_; + // If YES the transformtions will be relative to (-transform.x, -transform.y). + // Sprites, Labels and any other "small" object uses it. + // Scenes, Layers and other "whole screen" object don't use it. + BOOL isRelativeAnchorPoint_; + + // untransformed size of the node + CGSize contentSize_; + CGSize contentSizeInPixels_; + + // transform + CGAffineTransform transform_, inverse_; +#if CC_NODE_TRANSFORM_USING_AFFINE_MATRIX + GLfloat transformGL_[16]; +#endif + + // openGL real Z vertex + float vertexZ_; + + // a Camera + CCCamera *camera_; + + // a Grid + CCGridBase *grid_; + + // z-order value + NSInteger zOrder_; + + // array of children + CCArray *children_; + + // weakref to parent + CCNode *parent_; + + // a tag. any number you want to assign to the node + NSInteger tag_; + + // user data field + void *userData_; + + // Is running + BOOL isRunning_; + + // To reduce memory, place BOOLs that are not properties here: + BOOL isTransformDirty_:1; + BOOL isInverseDirty_:1; +#if CC_NODE_TRANSFORM_USING_AFFINE_MATRIX + BOOL isTransformGLDirty_:1; +#endif +} + +/** The z order of the node relative to it's "brothers": children of the same parent */ +@property(nonatomic,readonly) NSInteger zOrder; +/** The real openGL Z vertex. + Differences between openGL Z vertex and cocos2d Z order: + - OpenGL Z modifies the Z vertex, and not the Z order in the relation between parent-children + - OpenGL Z might require to set 2D projection + - cocos2d Z order works OK if all the nodes uses the same openGL Z vertex. eg: vertexZ = 0 + @warning: Use it at your own risk since it might break the cocos2d parent-children z order + @since v0.8 + */ +@property (nonatomic,readwrite) float vertexZ; + +/** The X skew angle of the node in degrees. + This angle describes the shear distortion in the X direction. + Thus, it is the angle between the Y axis and the left edge of the shape + The default skewX angle is 0. Positive values distort the node in a CW direction. + */ +@property(nonatomic,readwrite,assign) float skewX; + +/** The Y skew angle of the node in degrees. + This angle describes the shear distortion in the Y direction. + Thus, it is the angle between the X axis and the bottom edge of the shape + The default skewY angle is 0. Positive values distort the node in a CCW direction. + */ +@property(nonatomic,readwrite,assign) float skewY; +/** The rotation (angle) of the node in degrees. 0 is the default rotation angle. Positive values rotate node CW. */ +@property(nonatomic,readwrite,assign) float rotation; +/** The scale factor of the node. 1.0 is the default scale factor. It modifies the X and Y scale at the same time. */ +@property(nonatomic,readwrite,assign) float scale; +/** The scale factor of the node. 1.0 is the default scale factor. It only modifies the X scale factor. */ +@property(nonatomic,readwrite,assign) float scaleX; +/** The scale factor of the node. 1.0 is the default scale factor. It only modifies the Y scale factor. */ +@property(nonatomic,readwrite,assign) float scaleY; +/** Position (x,y) of the node in points. (0,0) is the left-bottom corner. */ +@property(nonatomic,readwrite,assign) CGPoint position; +/** Position (x,y) of the node in points. (0,0) is the left-bottom corner. */ +@property(nonatomic,readwrite,assign) CGPoint positionInPixels; +/** A CCCamera object that lets you move the node using a gluLookAt +*/ +@property(nonatomic,readonly) CCCamera* camera; +/** Array of children */ +@property(nonatomic,readonly) CCArray *children; +/** A CCGrid object that is used when applying effects */ +@property(nonatomic,readwrite,retain) CCGridBase* grid; +/** Whether of not the node is visible. Default is YES */ +@property(nonatomic,readwrite,assign) BOOL visible; +/** anchorPoint is the point around which all transformations and positioning manipulations take place. + It's like a pin in the node where it is "attached" to its parent. + The anchorPoint is normalized, like a percentage. (0,0) means the bottom-left corner and (1,1) means the top-right corner. + But you can use values higher than (1,1) and lower than (0,0) too. + The default anchorPoint is (0,0). It starts in the bottom-left corner. CCSprite and other subclasses have a different default anchorPoint. + @since v0.8 + */ +@property(nonatomic,readwrite) CGPoint anchorPoint; +/** The anchorPoint in absolute pixels. + Since v0.8 you can only read it. If you wish to modify it, use anchorPoint instead + */ +@property(nonatomic,readonly) CGPoint anchorPointInPixels; + +/** The untransformed size of the node in Points + The contentSize remains the same no matter the node is scaled or rotated. + All nodes has a size. Layer and Scene has the same size of the screen. + @since v0.8 + */ +@property (nonatomic,readwrite) CGSize contentSize; + +/** The untransformed size of the node in Pixels + The contentSize remains the same no matter the node is scaled or rotated. + All nodes has a size. Layer and Scene has the same size of the screen. + @since v0.8 + */ +@property (nonatomic,readwrite) CGSize contentSizeInPixels; + +/** whether or not the node is running */ +@property(nonatomic,readonly) BOOL isRunning; +/** A weak reference to the parent */ +@property(nonatomic,readwrite,assign) CCNode* parent; +/** If YES the transformtions will be relative to it's anchor point. + * Sprites, Labels and any other sizeble object use it have it enabled by default. + * Scenes, Layers and other "whole screen" object don't use it, have it disabled by default. + */ +@property(nonatomic,readwrite,assign) BOOL isRelativeAnchorPoint; +/** A tag used to identify the node easily */ +@property(nonatomic,readwrite,assign) NSInteger tag; +/** A custom user data pointer */ +@property(nonatomic,readwrite,assign) void *userData; + +// initializators +/** allocates and initializes a node. + The node will be created as "autorelease". + */ ++(id) node; +/** initializes the node */ +-(id) init; + + +// scene managment + +/** callback that is called every time the CCNode enters the 'stage'. + If the CCNode enters the 'stage' with a transition, this callback is called when the transition starts. + During onEnter you can't a "sister/brother" node. + */ +-(void) onEnter; +/** callback that is called when the CCNode enters in the 'stage'. + If the CCNode enters the 'stage' with a transition, this callback is called when the transition finishes. + @since v0.8 + */ +-(void) onEnterTransitionDidFinish; +/** callback that is called every time the CCNode leaves the 'stage'. + If the CCNode leaves the 'stage' with a transition, this callback is called when the transition finishes. + During onExit you can't access a sibling node. + */ +-(void) onExit; + + +// composition: ADD + +/** Adds a child to the container with z-order as 0. + If the child is added to a 'running' node, then 'onEnter' and 'onEnterTransitionDidFinish' will be called immediately. + @since v0.7.1 + */ +-(void) addChild: (CCNode*)node; + +/** Adds a child to the container with a z-order. + If the child is added to a 'running' node, then 'onEnter' and 'onEnterTransitionDidFinish' will be called immediately. + @since v0.7.1 + */ +-(void) addChild: (CCNode*)node z:(NSInteger)z; + +/** Adds a child to the container with z order and tag. + If the child is added to a 'running' node, then 'onEnter' and 'onEnterTransitionDidFinish' will be called immediately. + @since v0.7.1 + */ +-(void) addChild: (CCNode*)node z:(NSInteger)z tag:(NSInteger)tag; + +// composition: REMOVE + +/** Remove itself from its parent node. If cleanup is YES, then also remove all actions and callbacks. + If the node orphan, then nothing happens. + @since v0.99.3 + */ +-(void) removeFromParentAndCleanup:(BOOL)cleanup; + +/** Removes a child from the container. It will also cleanup all running actions depending on the cleanup parameter. + @since v0.7.1 + */ +-(void) removeChild: (CCNode*)node cleanup:(BOOL)cleanup; + +/** Removes a child from the container by tag value. It will also cleanup all running actions depending on the cleanup parameter + @since v0.7.1 + */ +-(void) removeChildByTag:(NSInteger) tag cleanup:(BOOL)cleanup; + +/** Removes all children from the container and do a cleanup all running actions depending on the cleanup parameter. + @since v0.7.1 + */ +-(void) removeAllChildrenWithCleanup:(BOOL)cleanup; + +// composition: GET +/** Gets a child from the container given its tag + @return returns a CCNode object + @since v0.7.1 + */ +-(CCNode*) getChildByTag:(NSInteger) tag; + +/** Reorders a child according to a new z value. + * The child MUST be already added. + */ +-(void) reorderChild:(CCNode*)child z:(NSInteger)zOrder; + +/** Stops all running actions and schedulers + @since v0.8 + */ +-(void) cleanup; + +// draw + +/** Override this method to draw your own node. + The following GL states will be enabled by default: + - glEnableClientState(GL_VERTEX_ARRAY); + - glEnableClientState(GL_COLOR_ARRAY); + - glEnableClientState(GL_TEXTURE_COORD_ARRAY); + - glEnable(GL_TEXTURE_2D); + + AND YOU SHOULD NOT DISABLE THEM AFTER DRAWING YOUR NODE + + But if you enable any other GL state, you should disable it after drawing your node. + */ +-(void) draw; +/** recursive method that visit its children and draw them */ +-(void) visit; + +// transformations + +/** performs OpenGL view-matrix transformation based on position, scale, rotation and other attributes. */ +-(void) transform; + +/** performs OpenGL view-matrix transformation of it's ancestors. + Generally the ancestors are already transformed, but in certain cases (eg: attaching a FBO) + it's necessary to transform the ancestors again. + @since v0.7.2 + */ +-(void) transformAncestors; + +/** returns a "local" axis aligned bounding box of the node in points. + The returned box is relative only to its parent. + The returned box is in Points. + + @since v0.8.2 + */ +- (CGRect) boundingBox; + +/** returns a "local" axis aligned bounding box of the node in pixels. + The returned box is relative only to its parent. + The returned box is in Points. + + @since v0.99.5 + */ +- (CGRect) boundingBoxInPixels; + + +// actions + +/** Executes an action, and returns the action that is executed. + The node becomes the action's target. + @warning Starting from v0.8 actions don't retain their target anymore. + @since v0.7.1 + @return An Action pointer + */ +-(CCAction*) runAction: (CCAction*) action; +/** Removes all actions from the running action list */ +-(void) stopAllActions; +/** Removes an action from the running action list */ +-(void) stopAction: (CCAction*) action; +/** Removes an action from the running action list given its tag + @since v0.7.1 +*/ +-(void) stopActionByTag:(NSInteger) tag; +/** Gets an action from the running action list given its tag + @since v0.7.1 + @return the Action the with the given tag + */ +-(CCAction*) getActionByTag:(NSInteger) tag; +/** Returns the numbers of actions that are running plus the ones that are schedule to run (actions in actionsToAdd and actions arrays). + * Composable actions are counted as 1 action. Example: + * If you are running 1 Sequence of 7 actions, it will return 1. + * If you are running 7 Sequences of 2 actions, it will return 7. + */ +-(NSUInteger) numberOfRunningActions; + +// timers + +/** check whether a selector is scheduled. */ +//-(BOOL) isScheduled: (SEL) selector; + +/** schedules the "update" method. It will use the order number 0. This method will be called every frame. + Scheduled methods with a lower order value will be called before the ones that have a higher order value. + Only one "udpate" method could be scheduled per node. + + @since v0.99.3 + */ +-(void) scheduleUpdate; + +/** schedules the "update" selector with a custom priority. This selector will be called every frame. + Scheduled selectors with a lower priority will be called before the ones that have a higher value. + Only one "udpate" selector could be scheduled per node (You can't have 2 'update' selectors). + + @since v0.99.3 + */ +-(void) scheduleUpdateWithPriority:(NSInteger)priority; + +/* unschedules the "update" method. + + @since v0.99.3 + */ +-(void) unscheduleUpdate; + + +/** schedules a selector. + The scheduled selector will be ticked every frame + */ +-(void) schedule: (SEL) s; +/** schedules a custom selector with an interval time in seconds. + If time is 0 it will be ticked every frame. + If time is 0, it is recommended to use 'scheduleUpdate' instead. + + If the selector is already scheduled, then the interval parameter will be updated without scheduling it again. + */ +-(void) schedule: (SEL) s interval:(ccTime)seconds; +/** unschedules a custom selector.*/ +-(void) unschedule: (SEL) s; + +/** unschedule all scheduled selectors: custom selectors, and the 'update' selector. + Actions are not affected by this method. +@since v0.99.3 + */ +-(void) unscheduleAllSelectors; + +/** resumes all scheduled selectors and actions. + Called internally by onEnter + */ +-(void) resumeSchedulerAndActions; +/** pauses all scheduled selectors and actions. + Called internally by onExit + */ +-(void) pauseSchedulerAndActions; + + +// transformation methods + +/** Returns the matrix that transform the node's (local) space coordinates into the parent's space coordinates. + The matrix is in Pixels. + @since v0.7.1 + */ +- (CGAffineTransform)nodeToParentTransform; +/** Returns the matrix that transform parent's space coordinates to the node's (local) space coordinates. + The matrix is in Pixels. + @since v0.7.1 + */ +- (CGAffineTransform)parentToNodeTransform; +/** Retrusn the world affine transform matrix. The matrix is in Pixels. + @since v0.7.1 + */ +- (CGAffineTransform)nodeToWorldTransform; +/** Returns the inverse world affine transform matrix. The matrix is in Pixels. + @since v0.7.1 + */ +- (CGAffineTransform)worldToNodeTransform; +/** Converts a Point to node (local) space coordinates. The result is in Points. + @since v0.7.1 + */ +- (CGPoint)convertToNodeSpace:(CGPoint)worldPoint; +/** Converts a Point to world space coordinates. The result is in Points. + @since v0.7.1 + */ +- (CGPoint)convertToWorldSpace:(CGPoint)nodePoint; +/** Converts a Point to node (local) space coordinates. The result is in Points. + treating the returned/received node point as anchor relative. + @since v0.7.1 + */ +- (CGPoint)convertToNodeSpaceAR:(CGPoint)worldPoint; +/** Converts a local Point to world space coordinates.The result is in Points. + treating the returned/received node point as anchor relative. + @since v0.7.1 + */ +- (CGPoint)convertToWorldSpaceAR:(CGPoint)nodePoint; + +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED +/** Converts a UITouch to node (local) space coordinates. The result is in Points. + @since v0.7.1 + */ +- (CGPoint)convertTouchToNodeSpace:(UITouch *)touch; +/** Converts a UITouch to node (local) space coordinates. The result is in Points. + This method is AR (Anchor Relative).. + @since v0.7.1 + */ +- (CGPoint)convertTouchToNodeSpaceAR:(UITouch *)touch; +#endif // __IPHONE_OS_VERSION_MAX_ALLOWED +@end diff --git a/tweejump/libs/cocos2d/CCNode.m b/tweejump/libs/cocos2d/CCNode.m new file mode 100755 index 0000000..495ad22 --- /dev/null +++ b/tweejump/libs/cocos2d/CCNode.m @@ -0,0 +1,926 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2009 Valentin Milea + * + * Copyright (c) 2008-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. + */ + +#import "CCNode.h" +#import "CCGrid.h" +#import "CCDirector.h" +#import "CCActionManager.h" +#import "CCCamera.h" +#import "CCScheduler.h" +#import "ccConfig.h" +#import "ccMacros.h" +#import "Support/CGPointExtension.h" +#import "Support/ccCArray.h" +#import "Support/TransformUtils.h" +#import "ccMacros.h" + +#import +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED +#import "Platforms/iOS/CCDirectorIOS.h" +#endif + + +#if CC_COCOSNODE_RENDER_SUBPIXEL +#define RENDER_IN_SUBPIXEL +#else +#define RENDER_IN_SUBPIXEL (NSInteger) +#endif + +@interface CCNode () +// lazy allocs +-(void) childrenAlloc; +// helper that reorder a child +-(void) insertChild:(CCNode*)child z:(NSInteger)z; +// used internally to alter the zOrder variable. DON'T call this method manually +-(void) _setZOrder:(NSInteger) z; +-(void) detachChild:(CCNode *)child cleanup:(BOOL)doCleanup; +@end + +@implementation CCNode + +@synthesize children = children_; +@synthesize visible = visible_; +@synthesize parent = parent_; +@synthesize grid = grid_; +@synthesize zOrder = zOrder_; +@synthesize tag = tag_; +@synthesize vertexZ = vertexZ_; +@synthesize isRunning = isRunning_; +@synthesize userData = userData_; + +#pragma mark CCNode - Transform related properties + +@synthesize rotation = rotation_, scaleX = scaleX_, scaleY = scaleY_; +@synthesize skewX = skewX_, skewY = skewY_; +@synthesize position = position_, positionInPixels = positionInPixels_; +@synthesize anchorPoint = anchorPoint_, anchorPointInPixels = anchorPointInPixels_; +@synthesize contentSize = contentSize_, contentSizeInPixels = contentSizeInPixels_; +@synthesize isRelativeAnchorPoint = isRelativeAnchorPoint_; + +// getters synthesized, setters explicit + +-(void) setSkewX:(float)newSkewX +{ + skewX_ = newSkewX; + isTransformDirty_ = isInverseDirty_ = YES; +#if CC_NODE_TRANSFORM_USING_AFFINE_MATRIX + isTransformGLDirty_ = YES; +#endif +} + +-(void) setSkewY:(float)newSkewY +{ + skewY_ = newSkewY; + isTransformDirty_ = isInverseDirty_ = YES; +#if CC_NODE_TRANSFORM_USING_AFFINE_MATRIX + isTransformGLDirty_ = YES; +#endif +} + +-(void) setRotation: (float)newRotation +{ + rotation_ = newRotation; + isTransformDirty_ = isInverseDirty_ = YES; +#if CC_NODE_TRANSFORM_USING_AFFINE_MATRIX + isTransformGLDirty_ = YES; +#endif +} + +-(void) setScaleX: (float)newScaleX +{ + scaleX_ = newScaleX; + isTransformDirty_ = isInverseDirty_ = YES; +#if CC_NODE_TRANSFORM_USING_AFFINE_MATRIX + isTransformGLDirty_ = YES; +#endif +} + +-(void) setScaleY: (float)newScaleY +{ + scaleY_ = newScaleY; + isTransformDirty_ = isInverseDirty_ = YES; +#if CC_NODE_TRANSFORM_USING_AFFINE_MATRIX + isTransformGLDirty_ = YES; +#endif +} + +-(void) setPosition: (CGPoint)newPosition +{ + position_ = newPosition; + if( CC_CONTENT_SCALE_FACTOR() == 1 ) + positionInPixels_ = position_; + else + positionInPixels_ = ccpMult( newPosition, CC_CONTENT_SCALE_FACTOR() ); + + isTransformDirty_ = isInverseDirty_ = YES; +#if CC_NODE_TRANSFORM_USING_AFFINE_MATRIX + isTransformGLDirty_ = YES; +#endif +} + +-(void) setPositionInPixels:(CGPoint)newPosition +{ + positionInPixels_ = newPosition; + + if( CC_CONTENT_SCALE_FACTOR() == 1 ) + position_ = positionInPixels_; + else + position_ = ccpMult( newPosition, 1/CC_CONTENT_SCALE_FACTOR() ); + + isTransformDirty_ = isInverseDirty_ = YES; +#if CC_NODE_TRANSFORM_USING_AFFINE_MATRIX + isTransformGLDirty_ = YES; +#endif +} + +-(void) setIsRelativeAnchorPoint: (BOOL)newValue +{ + isRelativeAnchorPoint_ = newValue; + isTransformDirty_ = isInverseDirty_ = YES; +#if CC_NODE_TRANSFORM_USING_AFFINE_MATRIX + isTransformGLDirty_ = YES; +#endif +} + +-(void) setAnchorPoint:(CGPoint)point +{ + if( ! CGPointEqualToPoint(point, anchorPoint_) ) { + anchorPoint_ = point; + anchorPointInPixels_ = ccp( contentSizeInPixels_.width * anchorPoint_.x, contentSizeInPixels_.height * anchorPoint_.y ); + isTransformDirty_ = isInverseDirty_ = YES; +#if CC_NODE_TRANSFORM_USING_AFFINE_MATRIX + isTransformGLDirty_ = YES; +#endif + } +} + +-(void) setContentSize:(CGSize)size +{ + if( ! CGSizeEqualToSize(size, contentSize_) ) { + contentSize_ = size; + + if( CC_CONTENT_SCALE_FACTOR() == 1 ) + contentSizeInPixels_ = contentSize_; + else + contentSizeInPixels_ = CGSizeMake( size.width * CC_CONTENT_SCALE_FACTOR(), size.height * CC_CONTENT_SCALE_FACTOR() ); + + anchorPointInPixels_ = ccp( contentSizeInPixels_.width * anchorPoint_.x, contentSizeInPixels_.height * anchorPoint_.y ); + isTransformDirty_ = isInverseDirty_ = YES; +#if CC_NODE_TRANSFORM_USING_AFFINE_MATRIX + isTransformGLDirty_ = YES; +#endif + } +} + +-(void) setContentSizeInPixels:(CGSize)size +{ + if( ! CGSizeEqualToSize(size, contentSizeInPixels_) ) { + contentSizeInPixels_ = size; + + if( CC_CONTENT_SCALE_FACTOR() == 1 ) + contentSize_ = contentSizeInPixels_; + else + contentSize_ = CGSizeMake( size.width / CC_CONTENT_SCALE_FACTOR(), size.height / CC_CONTENT_SCALE_FACTOR() ); + + anchorPointInPixels_ = ccp( contentSizeInPixels_.width * anchorPoint_.x, contentSizeInPixels_.height * anchorPoint_.y ); + isTransformDirty_ = isInverseDirty_ = YES; +#if CC_NODE_TRANSFORM_USING_AFFINE_MATRIX + isTransformGLDirty_ = YES; +#endif + } +} + +- (CGRect) boundingBox +{ + CGRect ret = [self boundingBoxInPixels]; + return CC_RECT_PIXELS_TO_POINTS( ret ); +} + +- (CGRect) boundingBoxInPixels +{ + CGRect rect = CGRectMake(0, 0, contentSizeInPixels_.width, contentSizeInPixels_.height); + return CGRectApplyAffineTransform(rect, [self nodeToParentTransform]); +} + +-(void) setVertexZ:(float)vertexZ +{ + vertexZ_ = vertexZ * CC_CONTENT_SCALE_FACTOR(); +} + +-(float) vertexZ +{ + return vertexZ_ / CC_CONTENT_SCALE_FACTOR(); +} + +-(float) scale +{ + NSAssert( scaleX_ == scaleY_, @"CCNode#scale. ScaleX != ScaleY. Don't know which one to return"); + return scaleX_; +} + +-(void) setScale:(float) s +{ + scaleX_ = scaleY_ = s; + isTransformDirty_ = isInverseDirty_ = YES; +#if CC_NODE_TRANSFORM_USING_AFFINE_MATRIX + isTransformGLDirty_ = YES; +#endif +} + +#pragma mark CCNode - Init & cleanup + ++(id) node +{ + return [[[self alloc] init] autorelease]; +} + +-(id) init +{ + if ((self=[super init]) ) { + + isRunning_ = NO; + + skewX_ = skewY_ = 0.0f; + rotation_ = 0.0f; + scaleX_ = scaleY_ = 1.0f; + positionInPixels_ = position_ = CGPointZero; + anchorPointInPixels_ = anchorPoint_ = CGPointZero; + contentSizeInPixels_ = contentSize_ = CGSizeZero; + + + // "whole screen" objects. like Scenes and Layers, should set isRelativeAnchorPoint to NO + isRelativeAnchorPoint_ = YES; + + isTransformDirty_ = isInverseDirty_ = YES; +#if CC_NODE_TRANSFORM_USING_AFFINE_MATRIX + isTransformGLDirty_ = YES; +#endif + + vertexZ_ = 0; + + grid_ = nil; + + visible_ = YES; + + tag_ = kCCNodeTagInvalid; + + zOrder_ = 0; + + // lazy alloc + camera_ = nil; + + // children (lazy allocs) + children_ = nil; + + // userData is always inited as nil + userData_ = nil; + + //initialize parent to nil + parent_ = nil; + } + + return self; +} + +- (void)cleanup +{ + // actions + [self stopAllActions]; + [self unscheduleAllSelectors]; + + // timers + [children_ makeObjectsPerformSelector:@selector(cleanup)]; +} + +- (NSString*) description +{ + return [NSString stringWithFormat:@"<%@ = %08X | Tag = %i>", [self class], self, tag_]; +} + +- (void) dealloc +{ + CCLOGINFO( @"cocos2d: deallocing %@", self); + + // attributes + [camera_ release]; + + [grid_ release]; + + // children + CCNode *child; + CCARRAY_FOREACH(children_, child) + child.parent = nil; + + [children_ release]; + + [super dealloc]; +} + +#pragma mark CCNode Composition + +-(void) childrenAlloc +{ + children_ = [[CCArray alloc] initWithCapacity:4]; +} + +// camera: lazy alloc +-(CCCamera*) camera +{ + if( ! camera_ ) { + camera_ = [[CCCamera alloc] init]; + + // by default, center camera at the Sprite's anchor point + // [camera_ setCenterX:anchorPointInPixels_.x centerY:anchorPointInPixels_.y centerZ:0]; + // [camera_ setEyeX:anchorPointInPixels_.x eyeY:anchorPointInPixels_.y eyeZ:1]; + + // [camera_ setCenterX:0 centerY:0 centerZ:0]; + // [camera_ setEyeX:0 eyeY:0 eyeZ:1]; + + } + + return camera_; +} + +-(CCNode*) getChildByTag:(NSInteger) aTag +{ + NSAssert( aTag != kCCNodeTagInvalid, @"Invalid tag"); + + CCNode *node; + CCARRAY_FOREACH(children_, node){ + if( node.tag == aTag ) + return node; + } + // not found + return nil; +} + +/* "add" logic MUST only be on this method + * If a class want's to extend the 'addChild' behaviour it only needs + * to override this method + */ +-(void) addChild: (CCNode*) child z:(NSInteger)z tag:(NSInteger) aTag +{ + NSAssert( child != nil, @"Argument must be non-nil"); + NSAssert( child.parent == nil, @"child already added. It can't be added again"); + + if( ! children_ ) + [self childrenAlloc]; + + [self insertChild:child z:z]; + + child.tag = aTag; + + [child setParent: self]; + + if( isRunning_ ) { + [child onEnter]; + [child onEnterTransitionDidFinish]; + } +} + +-(void) addChild: (CCNode*) child z:(NSInteger)z +{ + NSAssert( child != nil, @"Argument must be non-nil"); + [self addChild:child z:z tag:child.tag]; +} + +-(void) addChild: (CCNode*) child +{ + NSAssert( child != nil, @"Argument must be non-nil"); + [self addChild:child z:child.zOrder tag:child.tag]; +} + +-(void) removeFromParentAndCleanup:(BOOL)cleanup +{ + [parent_ removeChild:self cleanup:cleanup]; +} + +/* "remove" logic MUST only be on this method + * If a class want's to extend the 'removeChild' behavior it only needs + * to override this method + */ +-(void) removeChild: (CCNode*)child cleanup:(BOOL)cleanup +{ + // explicit nil handling + if (child == nil) + return; + + if ( [children_ containsObject:child] ) + [self detachChild:child cleanup:cleanup]; +} + +-(void) removeChildByTag:(NSInteger)aTag cleanup:(BOOL)cleanup +{ + NSAssert( aTag != kCCNodeTagInvalid, @"Invalid tag"); + + CCNode *child = [self getChildByTag:aTag]; + + if (child == nil) + CCLOG(@"cocos2d: removeChildByTag: child not found!"); + else + [self removeChild:child cleanup:cleanup]; +} + +-(void) removeAllChildrenWithCleanup:(BOOL)cleanup +{ + // not using detachChild improves speed here + CCNode *c; + CCARRAY_FOREACH(children_, c) + { + // IMPORTANT: + // -1st do onExit + // -2nd cleanup + if (isRunning_) + [c onExit]; + + if (cleanup) + [c cleanup]; + + // set parent nil at the end (issue #476) + [c setParent:nil]; + } + + [children_ removeAllObjects]; +} + +-(void) detachChild:(CCNode *)child cleanup:(BOOL)doCleanup +{ + // IMPORTANT: + // -1st do onExit + // -2nd cleanup + if (isRunning_) + [child onExit]; + + // If you don't do cleanup, the child's actions will not get removed and the + // its scheduledSelectors_ dict will not get released! + if (doCleanup) + [child cleanup]; + + // set parent nil at the end (issue #476) + [child setParent:nil]; + + [children_ removeObject:child]; +} + +// used internally to alter the zOrder variable. DON'T call this method manually +-(void) _setZOrder:(NSInteger) z +{ + zOrder_ = z; +} + +// helper used by reorderChild & add +-(void) insertChild:(CCNode*)child z:(NSInteger)z +{ + NSUInteger index=0; + CCNode *a = [children_ lastObject]; + + // quick comparison to improve performance + if (!a || a.zOrder <= z) + [children_ addObject:child]; + + else + { + CCARRAY_FOREACH(children_, a) { + if ( a.zOrder > z ) { + [children_ insertObject:child atIndex:index]; + break; + } + index++; + } + } + + [child _setZOrder:z]; +} + +-(void) reorderChild:(CCNode*) child z:(NSInteger)z +{ + NSAssert( child != nil, @"Child must be non-nil"); + + [child retain]; + [children_ removeObject:child]; + + [self insertChild:child z:z]; + + [child release]; +} + +#pragma mark CCNode Draw + +-(void) draw +{ + // override me + // Only use this function to draw your staff. + // DON'T draw your stuff outside this method +} + +-(void) visit +{ + // quick return if not visible + if (!visible_) + return; + + glPushMatrix(); + + if ( grid_ && grid_.active) { + [grid_ beforeDraw]; + [self transformAncestors]; + } + + [self transform]; + + if(children_) { + ccArray *arrayData = children_->data; + NSUInteger i = 0; + + // draw children zOrder < 0 + for( ; i < arrayData->num; i++ ) { + CCNode *child = arrayData->arr[i]; + if ( [child zOrder] < 0 ) + [child visit]; + else + break; + } + + // self draw + [self draw]; + + // draw children zOrder >= 0 + for( ; i < arrayData->num; i++ ) { + CCNode *child = arrayData->arr[i]; + [child visit]; + } + + } else + [self draw]; + + if ( grid_ && grid_.active) + [grid_ afterDraw:self]; + + glPopMatrix(); +} + +#pragma mark CCNode - Transformations + +-(void) transformAncestors +{ + if( parent_ ) { + [parent_ transformAncestors]; + [parent_ transform]; + } +} + +-(void) transform +{ + // transformations + +#if CC_NODE_TRANSFORM_USING_AFFINE_MATRIX + // BEGIN alternative -- using cached transform + // + if( isTransformGLDirty_ ) { + CGAffineTransform t = [self nodeToParentTransform]; + CGAffineToGL(&t, transformGL_); + isTransformGLDirty_ = NO; + } + + glMultMatrixf(transformGL_); + if( vertexZ_ ) + glTranslatef(0, 0, vertexZ_); + + // XXX: Expensive calls. Camera should be integrated into the cached affine matrix + if ( camera_ && !(grid_ && grid_.active) ) + { + BOOL translate = (anchorPointInPixels_.x != 0.0f || anchorPointInPixels_.y != 0.0f); + + if( translate ) + ccglTranslate(RENDER_IN_SUBPIXEL(anchorPointInPixels_.x), RENDER_IN_SUBPIXEL(anchorPointInPixels_.y), 0); + + [camera_ locate]; + + if( translate ) + ccglTranslate(RENDER_IN_SUBPIXEL(-anchorPointInPixels_.x), RENDER_IN_SUBPIXEL(-anchorPointInPixels_.y), 0); + } + + + // END alternative + +#else + // BEGIN original implementation + // + // translate + if ( isRelativeAnchorPoint_ && (anchorPointInPixels_.x != 0 || anchorPointInPixels_.y != 0 ) ) + glTranslatef( RENDER_IN_SUBPIXEL(-anchorPointInPixels_.x), RENDER_IN_SUBPIXEL(-anchorPointInPixels_.y), 0); + + if (anchorPointInPixels_.x != 0 || anchorPointInPixels_.y != 0) + glTranslatef( RENDER_IN_SUBPIXEL(positionInPixels_.x + anchorPointInPixels_.x), RENDER_IN_SUBPIXEL(positionInPixels_.y + anchorPointInPixels_.y), vertexZ_); + else if ( positionInPixels_.x !=0 || positionInPixels_.y !=0 || vertexZ_ != 0) + glTranslatef( RENDER_IN_SUBPIXEL(positionInPixels_.x), RENDER_IN_SUBPIXEL(positionInPixels_.y), vertexZ_ ); + + // rotate + if (rotation_ != 0.0f ) + glRotatef( -rotation_, 0.0f, 0.0f, 1.0f ); + + // skew + if ( (skewX_ != 0.0f) || (skewY_ != 0.0f) ) { + CGAffineTransform skewMatrix = CGAffineTransformMake( 1.0f, tanf(CC_DEGREES_TO_RADIANS(skewY_)), tanf(CC_DEGREES_TO_RADIANS(skewX_)), 1.0f, 0.0f, 0.0f ); + GLfloat glMatrix[16]; + CGAffineToGL(&skewMatrix, glMatrix); + glMultMatrixf(glMatrix); + } + + // scale + if (scaleX_ != 1.0f || scaleY_ != 1.0f) + glScalef( scaleX_, scaleY_, 1.0f ); + + if ( camera_ && !(grid_ && grid_.active) ) + [camera_ locate]; + + // restore and re-position point + if (anchorPointInPixels_.x != 0.0f || anchorPointInPixels_.y != 0.0f) + glTranslatef(RENDER_IN_SUBPIXEL(-anchorPointInPixels_.x), RENDER_IN_SUBPIXEL(-anchorPointInPixels_.y), 0); + + // + // END original implementation +#endif + +} + +#pragma mark CCNode SceneManagement + +-(void) onEnter +{ + [children_ makeObjectsPerformSelector:@selector(onEnter)]; + [self resumeSchedulerAndActions]; + + isRunning_ = YES; +} + +-(void) onEnterTransitionDidFinish +{ + [children_ makeObjectsPerformSelector:@selector(onEnterTransitionDidFinish)]; +} + +-(void) onExit +{ + [self pauseSchedulerAndActions]; + isRunning_ = NO; + + [children_ makeObjectsPerformSelector:@selector(onExit)]; +} + +#pragma mark CCNode Actions + +-(CCAction*) runAction:(CCAction*) action +{ + NSAssert( action != nil, @"Argument must be non-nil"); + + [[CCActionManager sharedManager] addAction:action target:self paused:!isRunning_]; + return action; +} + +-(void) stopAllActions +{ + [[CCActionManager sharedManager] removeAllActionsFromTarget:self]; +} + +-(void) stopAction: (CCAction*) action +{ + [[CCActionManager sharedManager] removeAction:action]; +} + +-(void) stopActionByTag:(NSInteger)aTag +{ + NSAssert( aTag != kCCActionTagInvalid, @"Invalid tag"); + [[CCActionManager sharedManager] removeActionByTag:aTag target:self]; +} + +-(CCAction*) getActionByTag:(NSInteger) aTag +{ + NSAssert( aTag != kCCActionTagInvalid, @"Invalid tag"); + return [[CCActionManager sharedManager] getActionByTag:aTag target:self]; +} + +-(NSUInteger) numberOfRunningActions +{ + return [[CCActionManager sharedManager] numberOfRunningActionsInTarget:self]; +} + +#pragma mark CCNode - Scheduler + +-(void) scheduleUpdate +{ + [self scheduleUpdateWithPriority:0]; +} + +-(void) scheduleUpdateWithPriority:(NSInteger)priority +{ + [[CCScheduler sharedScheduler] scheduleUpdateForTarget:self priority:priority paused:!isRunning_]; +} + +-(void) unscheduleUpdate +{ + [[CCScheduler sharedScheduler] unscheduleUpdateForTarget:self]; +} + +-(void) schedule:(SEL)selector +{ + [self schedule:selector interval:0]; +} + +-(void) schedule:(SEL)selector interval:(ccTime)interval +{ + NSAssert( selector != nil, @"Argument must be non-nil"); + NSAssert( interval >=0, @"Arguemnt must be positive"); + + [[CCScheduler sharedScheduler] scheduleSelector:selector forTarget:self interval:interval paused:!isRunning_]; +} + +-(void) unschedule:(SEL)selector +{ + // explicit nil handling + if (selector == nil) + return; + + [[CCScheduler sharedScheduler] unscheduleSelector:selector forTarget:self]; +} + +-(void) unscheduleAllSelectors +{ + [[CCScheduler sharedScheduler] unscheduleAllSelectorsForTarget:self]; +} +- (void) resumeSchedulerAndActions +{ + [[CCScheduler sharedScheduler] resumeTarget:self]; + [[CCActionManager sharedManager] resumeTarget:self]; +} + +- (void) pauseSchedulerAndActions +{ + [[CCScheduler sharedScheduler] pauseTarget:self]; + [[CCActionManager sharedManager] pauseTarget:self]; +} + +#pragma mark CCNode Transform + +- (CGAffineTransform)nodeToParentTransform +{ + if ( isTransformDirty_ ) { + + transform_ = CGAffineTransformIdentity; + + if ( !isRelativeAnchorPoint_ && !CGPointEqualToPoint(anchorPointInPixels_, CGPointZero) ) + transform_ = CGAffineTransformTranslate(transform_, anchorPointInPixels_.x, anchorPointInPixels_.y); + + if( ! CGPointEqualToPoint(positionInPixels_, CGPointZero) ) + transform_ = CGAffineTransformTranslate(transform_, positionInPixels_.x, positionInPixels_.y); + + if( rotation_ != 0 ) + transform_ = CGAffineTransformRotate(transform_, -CC_DEGREES_TO_RADIANS(rotation_)); + + if( skewX_ != 0 || skewY_ != 0 ) { + // create a skewed coordinate system + CGAffineTransform skew = CGAffineTransformMake(1.0f, tanf(CC_DEGREES_TO_RADIANS(skewY_)), tanf(CC_DEGREES_TO_RADIANS(skewX_)), 1.0f, 0.0f, 0.0f); + // apply the skew to the transform + transform_ = CGAffineTransformConcat(skew, transform_); + } + + if( ! (scaleX_ == 1 && scaleY_ == 1) ) + transform_ = CGAffineTransformScale(transform_, scaleX_, scaleY_); + + if( ! CGPointEqualToPoint(anchorPointInPixels_, CGPointZero) ) + transform_ = CGAffineTransformTranslate(transform_, -anchorPointInPixels_.x, -anchorPointInPixels_.y); + + isTransformDirty_ = NO; + } + + return transform_; +} + +- (CGAffineTransform)parentToNodeTransform +{ + if ( isInverseDirty_ ) { + inverse_ = CGAffineTransformInvert([self nodeToParentTransform]); + isInverseDirty_ = NO; + } + + return inverse_; +} + +- (CGAffineTransform)nodeToWorldTransform +{ + CGAffineTransform t = [self nodeToParentTransform]; + + for (CCNode *p = parent_; p != nil; p = p.parent) + t = CGAffineTransformConcat(t, [p nodeToParentTransform]); + + return t; +} + +- (CGAffineTransform)worldToNodeTransform +{ + return CGAffineTransformInvert([self nodeToWorldTransform]); +} + +- (CGPoint)convertToNodeSpace:(CGPoint)worldPoint +{ + CGPoint ret; + if( CC_CONTENT_SCALE_FACTOR() == 1 ) + ret = CGPointApplyAffineTransform(worldPoint, [self worldToNodeTransform]); + else { + ret = ccpMult( worldPoint, CC_CONTENT_SCALE_FACTOR() ); + ret = CGPointApplyAffineTransform(ret, [self worldToNodeTransform]); + ret = ccpMult( ret, 1/CC_CONTENT_SCALE_FACTOR() ); + } + + return ret; +} + +- (CGPoint)convertToWorldSpace:(CGPoint)nodePoint +{ + CGPoint ret; + if( CC_CONTENT_SCALE_FACTOR() == 1 ) + ret = CGPointApplyAffineTransform(nodePoint, [self nodeToWorldTransform]); + else { + ret = ccpMult( nodePoint, CC_CONTENT_SCALE_FACTOR() ); + ret = CGPointApplyAffineTransform(ret, [self nodeToWorldTransform]); + ret = ccpMult( ret, 1/CC_CONTENT_SCALE_FACTOR() ); + } + + return ret; +} + +- (CGPoint)convertToNodeSpaceAR:(CGPoint)worldPoint +{ + CGPoint nodePoint = [self convertToNodeSpace:worldPoint]; + CGPoint anchorInPoints; + if( CC_CONTENT_SCALE_FACTOR() == 1 ) + anchorInPoints = anchorPointInPixels_; + else + anchorInPoints = ccpMult( anchorPointInPixels_, 1/CC_CONTENT_SCALE_FACTOR() ); + + return ccpSub(nodePoint, anchorInPoints); +} + +- (CGPoint)convertToWorldSpaceAR:(CGPoint)nodePoint +{ + CGPoint anchorInPoints; + if( CC_CONTENT_SCALE_FACTOR() == 1 ) + anchorInPoints = anchorPointInPixels_; + else + anchorInPoints = ccpMult( anchorPointInPixels_, 1/CC_CONTENT_SCALE_FACTOR() ); + + nodePoint = ccpAdd(nodePoint, anchorInPoints); + return [self convertToWorldSpace:nodePoint]; +} + +- (CGPoint)convertToWindowSpace:(CGPoint)nodePoint +{ + CGPoint worldPoint = [self convertToWorldSpace:nodePoint]; + return [[CCDirector sharedDirector] convertToUI:worldPoint]; +} + +// convenience methods which take a UITouch instead of CGPoint + +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED + +- (CGPoint)convertTouchToNodeSpace:(UITouch *)touch +{ + CGPoint point = [touch locationInView: [touch view]]; + point = [[CCDirector sharedDirector] convertToGL: point]; + return [self convertToNodeSpace:point]; +} + +- (CGPoint)convertTouchToNodeSpaceAR:(UITouch *)touch +{ + CGPoint point = [touch locationInView: [touch view]]; + point = [[CCDirector sharedDirector] convertToGL: point]; + return [self convertToNodeSpaceAR:point]; +} + +#endif // __IPHONE_OS_VERSION_MAX_ALLOWED + + +@end diff --git a/tweejump/libs/cocos2d/CCParallaxNode.h b/tweejump/libs/cocos2d/CCParallaxNode.h new file mode 100755 index 0000000..5728eb1 --- /dev/null +++ b/tweejump/libs/cocos2d/CCParallaxNode.h @@ -0,0 +1,50 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2009-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. + * + */ + +#import "CCNode.h" +#import "Support/ccCArray.h" + +/** CCParallaxNode: A node that simulates a parallax scroller + + The children will be moved faster / slower than the parent according the the parallax ratio. + + */ +@interface CCParallaxNode : CCNode +{ + ccArray *parallaxArray_; + CGPoint lastPosition; +} + +/** array that holds the offset / ratio of the children */ +@property (nonatomic,readwrite) ccArray * parallaxArray; + +/** Adds a child to the container with a z-order, a parallax ratio and a position offset + It returns self, so you can chain several addChilds. + @since v0.8 + */ +-(void) addChild: (CCNode*)node z:(NSInteger)z parallaxRatio:(CGPoint)c positionOffset:(CGPoint)positionOffset; + +@end diff --git a/tweejump/libs/cocos2d/CCParallaxNode.m b/tweejump/libs/cocos2d/CCParallaxNode.m new file mode 100755 index 0000000..d4cda39 --- /dev/null +++ b/tweejump/libs/cocos2d/CCParallaxNode.m @@ -0,0 +1,161 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2009-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. + * + */ + +#import "CCParallaxNode.h" +#import "Support/CGPointExtension.h" +#import "Support/ccCArray.h" + +@interface CGPointObject : NSObject +{ + CGPoint ratio_; + CGPoint offset_; + CCNode *child_; // weak ref +} +@property (nonatomic,readwrite) CGPoint ratio; +@property (nonatomic,readwrite) CGPoint offset; +@property (nonatomic,readwrite,assign) CCNode *child; ++(id) pointWithCGPoint:(CGPoint)point offset:(CGPoint)offset; +-(id) initWithCGPoint:(CGPoint)point offset:(CGPoint)offset; +@end +@implementation CGPointObject +@synthesize ratio = ratio_; +@synthesize offset = offset_; +@synthesize child=child_; + ++(id) pointWithCGPoint:(CGPoint)ratio offset:(CGPoint)offset +{ + return [[[self alloc] initWithCGPoint:ratio offset:offset] autorelease]; +} +-(id) initWithCGPoint:(CGPoint)ratio offset:(CGPoint)offset +{ + if( (self=[super init])) { + ratio_ = ratio; + offset_ = offset; + } + return self; +} +@end + +@implementation CCParallaxNode + +@synthesize parallaxArray = parallaxArray_; + +-(id) init +{ + if( (self=[super init]) ) { + parallaxArray_ = ccArrayNew(5); + lastPosition = CGPointMake(-100,-100); + } + return self; +} + +- (void) dealloc +{ + if( parallaxArray_ ) { + ccArrayFree(parallaxArray_); + parallaxArray_ = nil; + } + [super dealloc]; +} + +-(void) addChild:(CCNode*)child z:(NSInteger)z tag:(NSInteger)tag +{ + NSAssert(NO,@"ParallaxNode: use addChild:z:parallaxRatio:positionOffset instead"); +} + +-(void) addChild: (CCNode*) child z:(NSInteger)z parallaxRatio:(CGPoint)ratio positionOffset:(CGPoint)offset +{ + NSAssert( child != nil, @"Argument must be non-nil"); + CGPointObject *obj = [CGPointObject pointWithCGPoint:ratio offset:offset]; + obj.child = child; + ccArrayAppendObjectWithResize(parallaxArray_, obj); + + CGPoint pos = self.position; + pos.x = pos.x * ratio.x + offset.x; + pos.y = pos.y * ratio.y + offset.y; + child.position = pos; + + [super addChild: child z:z tag:child.tag]; +} + +-(void) removeChild:(CCNode*)node cleanup:(BOOL)cleanup +{ + for( unsigned int i=0;i < parallaxArray_->num;i++) { + CGPointObject *point = parallaxArray_->arr[i]; + if( [point.child isEqual:node] ) { + ccArrayRemoveObjectAtIndex(parallaxArray_, i); + break; + } + } + [super removeChild:node cleanup:cleanup]; +} + +-(void) removeAllChildrenWithCleanup:(BOOL)cleanup +{ + ccArrayRemoveAllObjects(parallaxArray_); + [super removeAllChildrenWithCleanup:cleanup]; +} + +-(CGPoint) absolutePosition_ +{ + CGPoint ret = position_; + + CCNode *cn = self; + + while (cn.parent != nil) { + cn = cn.parent; + ret = ccpAdd( ret, cn.position ); + } + + return ret; +} + +/* + The positions are updated at visit because: + - using a timer is not guaranteed that it will called after all the positions were updated + - overriding "draw" will only precise if the children have a z > 0 +*/ +-(void) visit +{ +// CGPoint pos = position_; +// CGPoint pos = [self convertToWorldSpace:CGPointZero]; + CGPoint pos = [self absolutePosition_]; + if( ! CGPointEqualToPoint(pos, lastPosition) ) { + + for(unsigned int i=0; i < parallaxArray_->num; i++ ) { + + CGPointObject *point = parallaxArray_->arr[i]; + float x = -pos.x + pos.x * point.ratio.x + point.offset.x; + float y = -pos.y + pos.y * point.ratio.y + point.offset.y; + point.child.position = ccp(x,y); + } + + lastPosition = pos; + } + + [super visit]; +} +@end diff --git a/tweejump/libs/cocos2d/CCParticleExamples.h b/tweejump/libs/cocos2d/CCParticleExamples.h new file mode 100755 index 0000000..cd382c4 --- /dev/null +++ b/tweejump/libs/cocos2d/CCParticleExamples.h @@ -0,0 +1,111 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-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. + * + */ + + +#import + +#import "CCParticleSystemPoint.h" +#import "CCParticleSystemQuad.h" + +// build each architecture with the optimal particle system + +// ARMv7, Mac or Simulator use "Quad" particle +#if defined(__ARM_NEON__) || defined(__MAC_OS_X_VERSION_MAX_ALLOWED) || TARGET_IPHONE_SIMULATOR + #define ARCH_OPTIMAL_PARTICLE_SYSTEM CCParticleSystemQuad + +// ARMv6 use "Point" particle +#elif __arm__ + #define ARCH_OPTIMAL_PARTICLE_SYSTEM CCParticleSystemPoint +#else + #error(unknown architecture) +#endif + + +//! A fire particle system +@interface CCParticleFire: ARCH_OPTIMAL_PARTICLE_SYSTEM +{ +} +@end + +//! A fireworks particle system +@interface CCParticleFireworks : ARCH_OPTIMAL_PARTICLE_SYSTEM +{ +} +@end + +//! A sun particle system +@interface CCParticleSun : ARCH_OPTIMAL_PARTICLE_SYSTEM +{ +} +@end + +//! A galaxy particle system +@interface CCParticleGalaxy : ARCH_OPTIMAL_PARTICLE_SYSTEM +{ +} +@end + +//! A flower particle system +@interface CCParticleFlower : ARCH_OPTIMAL_PARTICLE_SYSTEM +{ +} +@end + +//! A meteor particle system +@interface CCParticleMeteor : ARCH_OPTIMAL_PARTICLE_SYSTEM +{ +} +@end + +//! An spiral particle system +@interface CCParticleSpiral : ARCH_OPTIMAL_PARTICLE_SYSTEM +{ +} +@end + +//! An explosion particle system +@interface CCParticleExplosion : ARCH_OPTIMAL_PARTICLE_SYSTEM +{ +} +@end + +//! An smoke particle system +@interface CCParticleSmoke : ARCH_OPTIMAL_PARTICLE_SYSTEM +{ +} +@end + +//! An snow particle system +@interface CCParticleSnow : ARCH_OPTIMAL_PARTICLE_SYSTEM +{ +} +@end + +//! A rain particle system +@interface CCParticleRain : ARCH_OPTIMAL_PARTICLE_SYSTEM +{ +} +@end diff --git a/tweejump/libs/cocos2d/CCParticleExamples.m b/tweejump/libs/cocos2d/CCParticleExamples.m new file mode 100755 index 0000000..38c8b46 --- /dev/null +++ b/tweejump/libs/cocos2d/CCParticleExamples.m @@ -0,0 +1,926 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-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. + * + */ + + +// cocos2d +#import "CCParticleExamples.h" +#import "CCTextureCache.h" +#import "CCDirector.h" +#import "Support/CGPointExtension.h" + +// +// ParticleFireworks +// +@implementation CCParticleFireworks +-(id) init +{ + return [self initWithTotalParticles:1500]; +} + +-(id) initWithTotalParticles:(NSUInteger)p +{ + if( (self=[super initWithTotalParticles:p]) ) { + // duration + duration = kCCParticleDurationInfinity; + + // Gravity Mode + self.emitterMode = kCCParticleModeGravity; + + // Gravity Mode: gravity + self.gravity = ccp(0,-90); + + // Gravity Mode: radial + self.radialAccel = 0; + self.radialAccelVar = 0; + + // Gravity Mode: speed of particles + self.speed = 180; + self.speedVar = 50; + + // emitter position + CGSize winSize = [[CCDirector sharedDirector] winSize]; + self.position = ccp(winSize.width/2, winSize.height/2); + + // angle + angle = 90; + angleVar = 20; + + // life of particles + life = 3.5f; + lifeVar = 1; + + // emits per frame + emissionRate = totalParticles/life; + + // color of particles + startColor.r = 0.5f; + startColor.g = 0.5f; + startColor.b = 0.5f; + startColor.a = 1.0f; + startColorVar.r = 0.5f; + startColorVar.g = 0.5f; + startColorVar.b = 0.5f; + startColorVar.a = 0.1f; + endColor.r = 0.1f; + endColor.g = 0.1f; + endColor.b = 0.1f; + endColor.a = 0.2f; + endColorVar.r = 0.1f; + endColorVar.g = 0.1f; + endColorVar.b = 0.1f; + endColorVar.a = 0.2f; + + // size, in pixels + startSize = 8.0f; + startSizeVar = 2.0f; + endSize = kCCParticleStartSizeEqualToEndSize; + + self.texture = [[CCTextureCache sharedTextureCache] addImage: @"fire.png"]; + + // additive + self.blendAdditive = NO; + } + + return self; +} +@end + +// +// ParticleFire +// +@implementation CCParticleFire +-(id) init +{ + return [self initWithTotalParticles:250]; +} + +-(id) initWithTotalParticles:(NSUInteger) p +{ + if( (self=[super initWithTotalParticles:p]) ) { + + // duration + duration = kCCParticleDurationInfinity; + + // Gravity Mode + self.emitterMode = kCCParticleModeGravity; + + // Gravity Mode: gravity + self.gravity = ccp(0,0); + + // Gravity Mode: radial acceleration + self.radialAccel = 0; + self.radialAccelVar = 0; + + // Gravity Mode: speed of particles + self.speed = 60; + self.speedVar = 20; + + // starting angle + angle = 90; + angleVar = 10; + + // emitter position + CGSize winSize = [[CCDirector sharedDirector] winSize]; + self.position = ccp(winSize.width/2, 60); + posVar = ccp(40, 20); + + // life of particles + life = 3; + lifeVar = 0.25f; + + + // size, in pixels + startSize = 54.0f; + startSizeVar = 10.0f; + endSize = kCCParticleStartSizeEqualToEndSize; + + // emits per frame + emissionRate = totalParticles/life; + + // color of particles + startColor.r = 0.76f; + startColor.g = 0.25f; + startColor.b = 0.12f; + startColor.a = 1.0f; + startColorVar.r = 0.0f; + startColorVar.g = 0.0f; + startColorVar.b = 0.0f; + startColorVar.a = 0.0f; + endColor.r = 0.0f; + endColor.g = 0.0f; + endColor.b = 0.0f; + endColor.a = 1.0f; + endColorVar.r = 0.0f; + endColorVar.g = 0.0f; + endColorVar.b = 0.0f; + endColorVar.a = 0.0f; + + self.texture = [[CCTextureCache sharedTextureCache] addImage: @"fire.png"]; + + // additive + self.blendAdditive = YES; + } + + return self; +} +@end + +// +// ParticleSun +// +@implementation CCParticleSun +-(id) init +{ + return [self initWithTotalParticles:350]; +} + +-(id) initWithTotalParticles:(NSUInteger) p +{ + if( (self=[super initWithTotalParticles:p]) ) { + + // additive + self.blendAdditive = YES; + + // duration + duration = kCCParticleDurationInfinity; + + // Gravity Mode + self.emitterMode = kCCParticleModeGravity; + + // Gravity Mode: gravity + self.gravity = ccp(0,0); + + // Gravity mode: radial acceleration + self.radialAccel = 0; + self.radialAccelVar = 0; + + // Gravity mode: speed of particles + self.speed = 20; + self.speedVar = 5; + + + // angle + angle = 90; + angleVar = 360; + + // emitter position + CGSize winSize = [[CCDirector sharedDirector] winSize]; + self.position = ccp(winSize.width/2, winSize.height/2); + posVar = CGPointZero; + + // life of particles + life = 1; + lifeVar = 0.5f; + + // size, in pixels + startSize = 30.0f; + startSizeVar = 10.0f; + endSize = kCCParticleStartSizeEqualToEndSize; + + // emits per seconds + emissionRate = totalParticles/life; + + // color of particles + startColor.r = 0.76f; + startColor.g = 0.25f; + startColor.b = 0.12f; + startColor.a = 1.0f; + startColorVar.r = 0.0f; + startColorVar.g = 0.0f; + startColorVar.b = 0.0f; + startColorVar.a = 0.0f; + endColor.r = 0.0f; + endColor.g = 0.0f; + endColor.b = 0.0f; + endColor.a = 1.0f; + endColorVar.r = 0.0f; + endColorVar.g = 0.0f; + endColorVar.b = 0.0f; + endColorVar.a = 0.0f; + + self.texture = [[CCTextureCache sharedTextureCache] addImage: @"fire.png"]; + } + + return self; +} +@end + +// +// ParticleGalaxy +// +@implementation CCParticleGalaxy +-(id) init +{ + return [self initWithTotalParticles:200]; +} + +-(id) initWithTotalParticles:(NSUInteger)p +{ + if( (self=[super initWithTotalParticles:p]) ) { + + // duration + duration = kCCParticleDurationInfinity; + + // Gravity Mode + self.emitterMode = kCCParticleModeGravity; + + // Gravity Mode: gravity + self.gravity = ccp(0,0); + + // Gravity Mode: speed of particles + self.speed = 60; + self.speedVar = 10; + + // Gravity Mode: radial + self.radialAccel = -80; + self.radialAccelVar = 0; + + // Gravity Mode: tagential + self.tangentialAccel = 80; + self.tangentialAccelVar = 0; + + // angle + angle = 90; + angleVar = 360; + + // emitter position + CGSize winSize = [[CCDirector sharedDirector] winSize]; + self.position = ccp(winSize.width/2, winSize.height/2); + posVar = CGPointZero; + + // life of particles + life = 4; + lifeVar = 1; + + // size, in pixels + startSize = 37.0f; + startSizeVar = 10.0f; + endSize = kCCParticleStartSizeEqualToEndSize; + + // emits per second + emissionRate = totalParticles/life; + + // color of particles + startColor.r = 0.12f; + startColor.g = 0.25f; + startColor.b = 0.76f; + startColor.a = 1.0f; + startColorVar.r = 0.0f; + startColorVar.g = 0.0f; + startColorVar.b = 0.0f; + startColorVar.a = 0.0f; + endColor.r = 0.0f; + endColor.g = 0.0f; + endColor.b = 0.0f; + endColor.a = 1.0f; + endColorVar.r = 0.0f; + endColorVar.g = 0.0f; + endColorVar.b = 0.0f; + endColorVar.a = 0.0f; + + self.texture = [[CCTextureCache sharedTextureCache] addImage: @"fire.png"]; + + // additive + self.blendAdditive = YES; + } + + return self; +} +@end + +// +// ParticleFlower +// +@implementation CCParticleFlower +-(id) init +{ + return [self initWithTotalParticles:250]; +} + +-(id) initWithTotalParticles:(NSUInteger) p +{ + if( (self=[super initWithTotalParticles:p]) ) { + + // duration + duration = kCCParticleDurationInfinity; + + // Gravity Mode + self.emitterMode = kCCParticleModeGravity; + + // Gravity Mode: gravity + self.gravity = ccp(0,0); + + // Gravity Mode: speed of particles + self.speed = 80; + self.speedVar = 10; + + // Gravity Mode: radial + self.radialAccel = -60; + self.radialAccelVar = 0; + + // Gravity Mode: tagential + self.tangentialAccel = 15; + self.tangentialAccelVar = 0; + + // angle + angle = 90; + angleVar = 360; + + // emitter position + CGSize winSize = [[CCDirector sharedDirector] winSize]; + self.position = ccp(winSize.width/2, winSize.height/2); + posVar = CGPointZero; + + // life of particles + life = 4; + lifeVar = 1; + + // size, in pixels + startSize = 30.0f; + startSizeVar = 10.0f; + endSize = kCCParticleStartSizeEqualToEndSize; + + // emits per second + emissionRate = totalParticles/life; + + // color of particles + startColor.r = 0.50f; + startColor.g = 0.50f; + startColor.b = 0.50f; + startColor.a = 1.0f; + startColorVar.r = 0.5f; + startColorVar.g = 0.5f; + startColorVar.b = 0.5f; + startColorVar.a = 0.5f; + endColor.r = 0.0f; + endColor.g = 0.0f; + endColor.b = 0.0f; + endColor.a = 1.0f; + endColorVar.r = 0.0f; + endColorVar.g = 0.0f; + endColorVar.b = 0.0f; + endColorVar.a = 0.0f; + + self.texture = [[CCTextureCache sharedTextureCache] addImage: @"fire.png"]; + + // additive + self.blendAdditive = YES; + } + + return self; +} +@end + +// +// ParticleMeteor +// +@implementation CCParticleMeteor +-(id) init +{ + return [self initWithTotalParticles:150]; +} + +-(id) initWithTotalParticles:(NSUInteger) p +{ + if( (self=[super initWithTotalParticles:p]) ) { + + // duration + duration = kCCParticleDurationInfinity; + + // Gravity Mode + self.emitterMode = kCCParticleModeGravity; + + // Gravity Mode: gravity + self.gravity = ccp(-200,200); + + // Gravity Mode: speed of particles + self.speed = 15; + self.speedVar = 5; + + // Gravity Mode: radial + self.radialAccel = 0; + self.radialAccelVar = 0; + + // Gravity Mode: tagential + self.tangentialAccel = 0; + self.tangentialAccelVar = 0; + + // angle + angle = 90; + angleVar = 360; + + // emitter position + CGSize winSize = [[CCDirector sharedDirector] winSize]; + self.position = ccp(winSize.width/2, winSize.height/2); + posVar = CGPointZero; + + // life of particles + life = 2; + lifeVar = 1; + + // size, in pixels + startSize = 60.0f; + startSizeVar = 10.0f; + endSize = kCCParticleStartSizeEqualToEndSize; + + // emits per second + emissionRate = totalParticles/life; + + // color of particles + startColor.r = 0.2f; + startColor.g = 0.4f; + startColor.b = 0.7f; + startColor.a = 1.0f; + startColorVar.r = 0.0f; + startColorVar.g = 0.0f; + startColorVar.b = 0.2f; + startColorVar.a = 0.1f; + endColor.r = 0.0f; + endColor.g = 0.0f; + endColor.b = 0.0f; + endColor.a = 1.0f; + endColorVar.r = 0.0f; + endColorVar.g = 0.0f; + endColorVar.b = 0.0f; + endColorVar.a = 0.0f; + + self.texture = [[CCTextureCache sharedTextureCache] addImage: @"fire.png"]; + + // additive + self.blendAdditive = YES; + } + + return self; +} +@end + +// +// ParticleSpiral +// +@implementation CCParticleSpiral +-(id) init +{ + return [self initWithTotalParticles:500]; +} + +-(id) initWithTotalParticles:(NSUInteger) p +{ + if( (self=[super initWithTotalParticles:p]) ) { + + // duration + duration = kCCParticleDurationInfinity; + + // Gravity Mode + self.emitterMode = kCCParticleModeGravity; + + // Gravity Mode: gravity + self.gravity = ccp(0,0); + + // Gravity Mode: speed of particles + self.speed = 150; + self.speedVar = 0; + + // Gravity Mode: radial + self.radialAccel = -380; + self.radialAccelVar = 0; + + // Gravity Mode: tagential + self.tangentialAccel = 45; + self.tangentialAccelVar = 0; + + // angle + angle = 90; + angleVar = 0; + + // emitter position + CGSize winSize = [[CCDirector sharedDirector] winSize]; + self.position = ccp(winSize.width/2, winSize.height/2); + posVar = CGPointZero; + + // life of particles + life = 12; + lifeVar = 0; + + // size, in pixels + startSize = 20.0f; + startSizeVar = 0.0f; + endSize = kCCParticleStartSizeEqualToEndSize; + + // emits per second + emissionRate = totalParticles/life; + + // color of particles + startColor.r = 0.5f; + startColor.g = 0.5f; + startColor.b = 0.5f; + startColor.a = 1.0f; + startColorVar.r = 0.5f; + startColorVar.g = 0.5f; + startColorVar.b = 0.5f; + startColorVar.a = 0.0f; + endColor.r = 0.5f; + endColor.g = 0.5f; + endColor.b = 0.5f; + endColor.a = 1.0f; + endColorVar.r = 0.5f; + endColorVar.g = 0.5f; + endColorVar.b = 0.5f; + endColorVar.a = 0.0f; + + self.texture = [[CCTextureCache sharedTextureCache] addImage: @"fire.png"]; + + // additive + self.blendAdditive = NO; + } + + return self; +} +@end + +// +// ParticleExplosion +// +@implementation CCParticleExplosion +-(id) init +{ + return [self initWithTotalParticles:700]; +} + +-(id) initWithTotalParticles:(NSUInteger)p +{ + if( (self=[super initWithTotalParticles:p]) ) { + + // duration + duration = 0.1f; + + self.emitterMode = kCCParticleModeGravity; + + // Gravity Mode: gravity + self.gravity = ccp(0,0); + + // Gravity Mode: speed of particles + self.speed = 70; + self.speedVar = 40; + + // Gravity Mode: radial + self.radialAccel = 0; + self.radialAccelVar = 0; + + // Gravity Mode: tagential + self.tangentialAccel = 0; + self.tangentialAccelVar = 0; + + // angle + angle = 90; + angleVar = 360; + + // emitter position + CGSize winSize = [[CCDirector sharedDirector] winSize]; + self.position = ccp(winSize.width/2, winSize.height/2); + posVar = CGPointZero; + + // life of particles + life = 5.0f; + lifeVar = 2; + + // size, in pixels + startSize = 15.0f; + startSizeVar = 10.0f; + endSize = kCCParticleStartSizeEqualToEndSize; + + // emits per second + emissionRate = totalParticles/duration; + + // color of particles + startColor.r = 0.7f; + startColor.g = 0.1f; + startColor.b = 0.2f; + startColor.a = 1.0f; + startColorVar.r = 0.5f; + startColorVar.g = 0.5f; + startColorVar.b = 0.5f; + startColorVar.a = 0.0f; + endColor.r = 0.5f; + endColor.g = 0.5f; + endColor.b = 0.5f; + endColor.a = 0.0f; + endColorVar.r = 0.5f; + endColorVar.g = 0.5f; + endColorVar.b = 0.5f; + endColorVar.a = 0.0f; + + self.texture = [[CCTextureCache sharedTextureCache] addImage: @"fire.png"]; + + // additive + self.blendAdditive = NO; + } + + return self; +} +@end + +// +// ParticleSmoke +// +@implementation CCParticleSmoke +-(id) init +{ + return [self initWithTotalParticles:200]; +} + +-(id) initWithTotalParticles:(NSUInteger) p +{ + if( (self=[super initWithTotalParticles:p]) ) { + + // duration + duration = kCCParticleDurationInfinity; + + // Emitter mode: Gravity Mode + self.emitterMode = kCCParticleModeGravity; + + // Gravity Mode: gravity + self.gravity = ccp(0,0); + + // Gravity Mode: radial acceleration + self.radialAccel = 0; + self.radialAccelVar = 0; + + // Gravity Mode: speed of particles + self.speed = 25; + self.speedVar = 10; + + // angle + angle = 90; + angleVar = 5; + + // emitter position + CGSize winSize = [[CCDirector sharedDirector] winSize]; + self.position = ccp(winSize.width/2, 0); + posVar = ccp(20, 0); + + // life of particles + life = 4; + lifeVar = 1; + + // size, in pixels + startSize = 60.0f; + startSizeVar = 10.0f; + endSize = kCCParticleStartSizeEqualToEndSize; + + // emits per frame + emissionRate = totalParticles/life; + + // color of particles + startColor.r = 0.8f; + startColor.g = 0.8f; + startColor.b = 0.8f; + startColor.a = 1.0f; + startColorVar.r = 0.02f; + startColorVar.g = 0.02f; + startColorVar.b = 0.02f; + startColorVar.a = 0.0f; + endColor.r = 0.0f; + endColor.g = 0.0f; + endColor.b = 0.0f; + endColor.a = 1.0f; + endColorVar.r = 0.0f; + endColorVar.g = 0.0f; + endColorVar.b = 0.0f; + endColorVar.a = 0.0f; + + self.texture = [[CCTextureCache sharedTextureCache] addImage: @"fire.png"]; + + // additive + self.blendAdditive = NO; + } + + return self; +} +@end + +@implementation CCParticleSnow +-(id) init +{ + return [self initWithTotalParticles:700]; +} + +-(id) initWithTotalParticles:(NSUInteger)p +{ + if( (self=[super initWithTotalParticles:p]) ) { + + // duration + duration = kCCParticleDurationInfinity; + + // set gravity mode. + self.emitterMode = kCCParticleModeGravity; + + // Gravity Mode: gravity + self.gravity = ccp(0,-1); + + // Gravity Mode: speed of particles + self.speed = 5; + self.speedVar = 1; + + // Gravity Mode: radial + self.radialAccel = 0; + self.radialAccelVar = 1; + + // Gravity mode: tagential + self.tangentialAccel = 0; + self.tangentialAccelVar = 1; + + // emitter position + self.position = (CGPoint) { + [[CCDirector sharedDirector] winSize].width / 2, + [[CCDirector sharedDirector] winSize].height + 10 + }; + posVar = ccp( [[CCDirector sharedDirector] winSize].width / 2, 0 ); + + // angle + angle = -90; + angleVar = 5; + + // life of particles + life = 45; + lifeVar = 15; + + // size, in pixels + startSize = 10.0f; + startSizeVar = 5.0f; + endSize = kCCParticleStartSizeEqualToEndSize; + + // emits per second + emissionRate = 10; + + // color of particles + startColor.r = 1.0f; + startColor.g = 1.0f; + startColor.b = 1.0f; + startColor.a = 1.0f; + startColorVar.r = 0.0f; + startColorVar.g = 0.0f; + startColorVar.b = 0.0f; + startColorVar.a = 0.0f; + endColor.r = 1.0f; + endColor.g = 1.0f; + endColor.b = 1.0f; + endColor.a = 0.0f; + endColorVar.r = 0.0f; + endColorVar.g = 0.0f; + endColorVar.b = 0.0f; + endColorVar.a = 0.0f; + + self.texture = [[CCTextureCache sharedTextureCache] addImage: @"fire.png"]; + + // additive + self.blendAdditive = NO; + } + + return self; +} +@end + +@implementation CCParticleRain +-(id) init +{ + return [self initWithTotalParticles:1000]; +} + +-(id) initWithTotalParticles:(NSUInteger)p +{ + if( (self=[super initWithTotalParticles:p]) ) { + + // duration + duration = kCCParticleDurationInfinity; + + self.emitterMode = kCCParticleModeGravity; + + // Gravity Mode: gravity + self.gravity = ccp(10,-10); + + // Gravity Mode: radial + self.radialAccel = 0; + self.radialAccelVar = 1; + + // Gravity Mode: tagential + self.tangentialAccel = 0; + self.tangentialAccelVar = 1; + + // Gravity Mode: speed of particles + self.speed = 130; + self.speedVar = 30; + + // angle + angle = -90; + angleVar = 5; + + + // emitter position + self.position = (CGPoint) { + [[CCDirector sharedDirector] winSize].width / 2, + [[CCDirector sharedDirector] winSize].height + }; + posVar = ccp( [[CCDirector sharedDirector] winSize].width / 2, 0 ); + + // life of particles + life = 4.5f; + lifeVar = 0; + + // size, in pixels + startSize = 4.0f; + startSizeVar = 2.0f; + endSize = kCCParticleStartSizeEqualToEndSize; + + // emits per second + emissionRate = 20; + + // color of particles + startColor.r = 0.7f; + startColor.g = 0.8f; + startColor.b = 1.0f; + startColor.a = 1.0f; + startColorVar.r = 0.0f; + startColorVar.g = 0.0f; + startColorVar.b = 0.0f; + startColorVar.a = 0.0f; + endColor.r = 0.7f; + endColor.g = 0.8f; + endColor.b = 1.0f; + endColor.a = 0.5f; + endColorVar.r = 0.0f; + endColorVar.g = 0.0f; + endColorVar.b = 0.0f; + endColorVar.a = 0.0f; + + self.texture = [[CCTextureCache sharedTextureCache] addImage: @"fire.png"]; + + // additive + self.blendAdditive = NO; + } + + return self; +} +@end diff --git a/tweejump/libs/cocos2d/CCParticleSystem.h b/tweejump/libs/cocos2d/CCParticleSystem.h new file mode 100755 index 0000000..429e814 --- /dev/null +++ b/tweejump/libs/cocos2d/CCParticleSystem.h @@ -0,0 +1,445 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-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. + * + */ + + +#import "CCProtocols.h" +#import "CCNode.h" +#import "ccTypes.h" +#import "ccConfig.h" + +#if CC_ENABLE_PROFILERS +@class CCProfilingTimer; +#endif + +//* @enum +enum { + /** The Particle emitter lives forever */ + kCCParticleDurationInfinity = -1, + + /** The starting size of the particle is equal to the ending size */ + kCCParticleStartSizeEqualToEndSize = -1, + + /** The starting radius of the particle is equal to the ending radius */ + kCCParticleStartRadiusEqualToEndRadius = -1, + + // backward compatible + kParticleStartSizeEqualToEndSize = kCCParticleStartSizeEqualToEndSize, + kParticleDurationInfinity = kCCParticleDurationInfinity, +}; + +//* @enum +enum { + /** Gravity mode (A mode) */ + kCCParticleModeGravity, + + /** Radius mode (B mode) */ + kCCParticleModeRadius, +}; + + +/** @typedef tCCPositionType + possible types of particle positions + */ +typedef enum { + /** Living particles are attached to the world and are unaffected by emitter repositioning. */ + kCCPositionTypeFree, + + /** Living particles are attached to the world but will follow the emitter repositioning. + Use case: Attach an emitter to an sprite, and you want that the emitter follows the sprite. + */ + kCCPositionTypeRelative, + + /** Living particles are attached to the emitter and are translated along with it. */ + kCCPositionTypeGrouped, +}tCCPositionType; + +// backward compatible +enum { + kPositionTypeFree = kCCPositionTypeFree, + kPositionTypeGrouped = kCCPositionTypeGrouped, +}; + +/** @struct tCCParticle + Structure that contains the values of each particle + */ +typedef struct sCCParticle { + CGPoint pos; + CGPoint startPos; + + ccColor4F color; + ccColor4F deltaColor; + + float size; + float deltaSize; + + float rotation; + float deltaRotation; + + ccTime timeToLive; + + union { + // Mode A: gravity, direction, radial accel, tangential accel + struct { + CGPoint dir; + float radialAccel; + float tangentialAccel; + } A; + + // Mode B: radius mode + struct { + float angle; + float degreesPerSecond; + float radius; + float deltaRadius; + } B; + } mode; + +}tCCParticle; + +typedef void (*CC_UPDATE_PARTICLE_IMP)(id, SEL, tCCParticle*, CGPoint); + +@class CCTexture2D; + +/** Particle System base class + Attributes of a Particle System: + - emmision rate of the particles + - Gravity Mode (Mode A): + - gravity + - direction + - speed +- variance + - tangential acceleration +- variance + - radial acceleration +- variance + - Radius Mode (Mode B): + - startRadius +- variance + - endRadius +- variance + - rotate +- variance + - Properties common to all modes: + - life +- life variance + - start spin +- variance + - end spin +- variance + - start size +- variance + - end size +- variance + - start color +- variance + - end color +- variance + - life +- variance + - blending function + - texture + + cocos2d also supports particles generated by Particle Designer (http://particledesigner.71squared.com/). + 'Radius Mode' in Particle Designer uses a fixed emit rate of 30 hz. Since that can't be guarateed in cocos2d, + cocos2d uses a another approach, but the results are almost identical. + + cocos2d supports all the variables used by Particle Designer plus a bit more: + - spinning particles (supported when using CCParticleSystemQuad) + - tangential acceleration (Gravity mode) + - radial acceleration (Gravity mode) + - radius direction (Radius mode) (Particle Designer supports outwards to inwards direction only) + + It is possible to customize any of the above mentioned properties in runtime. Example: + + @code + emitter.radialAccel = 15; + emitter.startSpin = 0; + @endcode + + */ +@interface CCParticleSystem : CCNode +{ + // is the particle system active ? + BOOL active; + // duration in seconds of the system. -1 is infinity + float duration; + // time elapsed since the start of the system (in seconds) + float elapsed; + + // position is from "superclass" CocosNode + CGPoint sourcePosition; + // Position variance + CGPoint posVar; + + // The angle (direction) of the particles measured in degrees + float angle; + // Angle variance measured in degrees; + float angleVar; + + // Different modes + + NSInteger emitterMode_; + union { + // Mode A:Gravity + Tangential Accel + Radial Accel + struct { + // gravity of the particles + CGPoint gravity; + + // The speed the particles will have. + float speed; + // The speed variance + float speedVar; + + // Tangential acceleration + float tangentialAccel; + // Tangential acceleration variance + float tangentialAccelVar; + + // Radial acceleration + float radialAccel; + // Radial acceleration variance + float radialAccelVar; + } A; + + // Mode B: circular movement (gravity, radial accel and tangential accel don't are not used in this mode) + struct { + + // The starting radius of the particles + float startRadius; + // The starting radius variance of the particles + float startRadiusVar; + // The ending radius of the particles + float endRadius; + // The ending radius variance of the particles + float endRadiusVar; + // Number of degress to rotate a particle around the source pos per second + float rotatePerSecond; + // Variance in degrees for rotatePerSecond + float rotatePerSecondVar; + } B; + } mode; + + // start ize of the particles + float startSize; + // start Size variance + float startSizeVar; + // End size of the particle + float endSize; + // end size of variance + float endSizeVar; + + // How many seconds will the particle live + float life; + // Life variance + float lifeVar; + + // Start color of the particles + ccColor4F startColor; + // Start color variance + ccColor4F startColorVar; + // End color of the particles + ccColor4F endColor; + // End color variance + ccColor4F endColorVar; + + // start angle of the particles + float startSpin; + // start angle variance + float startSpinVar; + // End angle of the particle + float endSpin; + // end angle ariance + float endSpinVar; + + + // Array of particles + tCCParticle *particles; + // Maximum particles + NSUInteger totalParticles; + // Count of active particles + NSUInteger particleCount; + + // color modulate +// BOOL colorModulate; + + // How many particles can be emitted per second + float emissionRate; + float emitCounter; + + // Texture of the particles + CCTexture2D *texture_; + // blend function + ccBlendFunc blendFunc_; + + // movment type: free or grouped + tCCPositionType positionType_; + + // Whether or not the node will be auto-removed when there are not particles + BOOL autoRemoveOnFinish_; + + // particle idx + NSUInteger particleIdx; + + // Optimization + CC_UPDATE_PARTICLE_IMP updateParticleImp; + SEL updateParticleSel; + +// profiling +#if CC_ENABLE_PROFILERS + CCProfilingTimer* _profilingTimer; +#endif +} + +/** Is the emitter active */ +@property (nonatomic,readonly) BOOL active; +/** Quantity of particles that are being simulated at the moment */ +@property (nonatomic,readonly) NSUInteger particleCount; +/** How many seconds the emitter wil run. -1 means 'forever' */ +@property (nonatomic,readwrite,assign) float duration; +/** sourcePosition of the emitter */ +@property (nonatomic,readwrite,assign) CGPoint sourcePosition; +/** Position variance of the emitter */ +@property (nonatomic,readwrite,assign) CGPoint posVar; +/** life, and life variation of each particle */ +@property (nonatomic,readwrite,assign) float life; +/** life variance of each particle */ +@property (nonatomic,readwrite,assign) float lifeVar; +/** angle and angle variation of each particle */ +@property (nonatomic,readwrite,assign) float angle; +/** angle variance of each particle */ +@property (nonatomic,readwrite,assign) float angleVar; + +/** Gravity value. Only available in 'Gravity' mode. */ +@property (nonatomic,readwrite,assign) CGPoint gravity; +/** speed of each particle. Only available in 'Gravity' mode. */ +@property (nonatomic,readwrite,assign) float speed; +/** speed variance of each particle. Only available in 'Gravity' mode. */ +@property (nonatomic,readwrite,assign) float speedVar; +/** tangential acceleration of each particle. Only available in 'Gravity' mode. */ +@property (nonatomic,readwrite,assign) float tangentialAccel; +/** tangential acceleration variance of each particle. Only available in 'Gravity' mode. */ +@property (nonatomic,readwrite,assign) float tangentialAccelVar; +/** radial acceleration of each particle. Only available in 'Gravity' mode. */ +@property (nonatomic,readwrite,assign) float radialAccel; +/** radial acceleration variance of each particle. Only available in 'Gravity' mode. */ +@property (nonatomic,readwrite,assign) float radialAccelVar; + +/** The starting radius of the particles. Only available in 'Radius' mode. */ +@property (nonatomic,readwrite,assign) float startRadius; +/** The starting radius variance of the particles. Only available in 'Radius' mode. */ +@property (nonatomic,readwrite,assign) float startRadiusVar; +/** The ending radius of the particles. Only available in 'Radius' mode. */ +@property (nonatomic,readwrite,assign) float endRadius; +/** The ending radius variance of the particles. Only available in 'Radius' mode. */ +@property (nonatomic,readwrite,assign) float endRadiusVar; +/** Number of degress to rotate a particle around the source pos per second. Only available in 'Radius' mode. */ +@property (nonatomic,readwrite,assign) float rotatePerSecond; +/** Variance in degrees for rotatePerSecond. Only available in 'Radius' mode. */ +@property (nonatomic,readwrite,assign) float rotatePerSecondVar; + +/** start size in pixels of each particle */ +@property (nonatomic,readwrite,assign) float startSize; +/** size variance in pixels of each particle */ +@property (nonatomic,readwrite,assign) float startSizeVar; +/** end size in pixels of each particle */ +@property (nonatomic,readwrite,assign) float endSize; +/** end size variance in pixels of each particle */ +@property (nonatomic,readwrite,assign) float endSizeVar; +/** start color of each particle */ +@property (nonatomic,readwrite,assign) ccColor4F startColor; +/** start color variance of each particle */ +@property (nonatomic,readwrite,assign) ccColor4F startColorVar; +/** end color and end color variation of each particle */ +@property (nonatomic,readwrite,assign) ccColor4F endColor; +/** end color variance of each particle */ +@property (nonatomic,readwrite,assign) ccColor4F endColorVar; +//* initial angle of each particle +@property (nonatomic,readwrite,assign) float startSpin; +//* initial angle of each particle +@property (nonatomic,readwrite,assign) float startSpinVar; +//* initial angle of each particle +@property (nonatomic,readwrite,assign) float endSpin; +//* initial angle of each particle +@property (nonatomic,readwrite,assign) float endSpinVar; +/** emission rate of the particles */ +@property (nonatomic,readwrite,assign) float emissionRate; +/** maximum particles of the system */ +@property (nonatomic,readwrite,assign) NSUInteger totalParticles; +/** conforms to CocosNodeTexture protocol */ +@property (nonatomic,readwrite, retain) CCTexture2D * texture; +/** conforms to CocosNodeTexture protocol */ +@property (nonatomic,readwrite) ccBlendFunc blendFunc; +/** whether or not the particles are using blend additive. + If enabled, the following blending function will be used. + @code + source blend function = GL_SRC_ALPHA; + dest blend function = GL_ONE; + @endcode + */ +@property (nonatomic,readwrite) BOOL blendAdditive; +/** particles movement type: Free or Grouped + @since v0.8 + */ +@property (nonatomic,readwrite) tCCPositionType positionType; +/** whether or not the node will be auto-removed when it has no particles left. + By default it is NO. + @since v0.8 + */ +@property (nonatomic,readwrite) BOOL autoRemoveOnFinish; +/** Switch between different kind of emitter modes: + - kCCParticleModeGravity: uses gravity, speed, radial and tangential acceleration + - kCCParticleModeRadius: uses radius movement + rotation + */ +@property (nonatomic,readwrite) NSInteger emitterMode; + +/** creates an initializes a CCParticleSystem from a plist file. + This plist files can be creted manually or with Particle Designer: + http://particledesigner.71squared.com/ + @since v0.99.3 + */ ++(id) particleWithFile:(NSString*)plistFile; + +/** initializes a CCParticleSystem from a plist file. + This plist files can be creted manually or with Particle Designer: + http://particledesigner.71squared.com/ + @since v0.99.3 + */ +-(id) initWithFile:(NSString*) plistFile; + +/** initializes a CCQuadParticleSystem from a NSDictionary. + @since v0.99.3 + */ +-(id) initWithDictionary:(NSDictionary*)dictionary; + +//! Initializes a system with a fixed number of particles +-(id) initWithTotalParticles:(NSUInteger) numberOfParticles; +//! Add a particle to the emitter +-(BOOL) addParticle; +//! Initializes a particle +-(void) initParticle: (tCCParticle*) particle; +//! stop emitting particles. Running particles will continue to run until they die +-(void) stopSystem; +//! Kill all living particles. +-(void) resetSystem; +//! whether or not the system is full +-(BOOL) isFull; + +//! should be overriden by subclasses +-(void) updateQuadWithParticle:(tCCParticle*)particle newPosition:(CGPoint)pos; +//! should be overriden by subclasses +-(void) postStep; + +//! called in every loop. +-(void) update: (ccTime) dt; + +@end + diff --git a/tweejump/libs/cocos2d/CCParticleSystem.m b/tweejump/libs/cocos2d/CCParticleSystem.m new file mode 100755 index 0000000..742676e --- /dev/null +++ b/tweejump/libs/cocos2d/CCParticleSystem.m @@ -0,0 +1,808 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-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. + * + */ + + +// ideas taken from: +// . The ocean spray in your face [Jeff Lander] +// http://www.double.co.nz/dust/col0798.pdf +// . Building an Advanced Particle System [John van der Burg] +// http://www.gamasutra.com/features/20000623/vanderburg_01.htm +// . LOVE game engine +// http://love2d.org/ +// +// +// Radius mode support, from 71 squared +// http://particledesigner.71squared.com/ +// +// IMPORTANT: Particle Designer is supported by cocos2d, but +// 'Radius Mode' in Particle Designer uses a fixed emit rate of 30 hz. Since that can't be guarateed in cocos2d, +// cocos2d uses a another approach, but the results are almost identical. +// + +// opengl +#import "Platforms/CCGL.h" + +// cocos2d +#import "ccConfig.h" +#if CC_ENABLE_PROFILERS +#import "Support/CCProfiling.h" +#endif +#import "CCParticleSystem.h" +#import "CCTextureCache.h" +#import "ccMacros.h" + +// support +#import "Support/OpenGL_Internal.h" +#import "Support/CGPointExtension.h" +#import "Support/base64.h" +#import "Support/ZipUtils.h" +#import "Support/CCFileUtils.h" + +@implementation CCParticleSystem +@synthesize active, duration; +@synthesize sourcePosition, posVar; +@synthesize particleCount; +@synthesize life, lifeVar; +@synthesize angle, angleVar; +@synthesize startColor, startColorVar, endColor, endColorVar; +@synthesize startSpin, startSpinVar, endSpin, endSpinVar; +@synthesize emissionRate; +@synthesize totalParticles; +@synthesize startSize, startSizeVar; +@synthesize endSize, endSizeVar; +@synthesize blendFunc = blendFunc_; +@synthesize positionType = positionType_; +@synthesize autoRemoveOnFinish = autoRemoveOnFinish_; +@synthesize emitterMode = emitterMode_; + + ++(id) particleWithFile:(NSString*) plistFile +{ + return [[[self alloc] initWithFile:plistFile] autorelease]; +} + +-(id) init { + NSAssert(NO, @"CCParticleSystem: Init not supported."); + [self release]; + return nil; +} + +-(id) initWithFile:(NSString *)plistFile +{ + NSString *path = [CCFileUtils fullPathFromRelativePath:plistFile]; + NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:path]; + + NSAssert( dict != nil, @"Particles: file not found"); + return [self initWithDictionary:dict]; +} + +-(id) initWithDictionary:(NSDictionary *)dictionary +{ + NSUInteger maxParticles = [[dictionary valueForKey:@"maxParticles"] intValue]; + // self, not super + if ((self=[self initWithTotalParticles:maxParticles] ) ) { + + // angle + angle = [[dictionary valueForKey:@"angle"] floatValue]; + angleVar = [[dictionary valueForKey:@"angleVariance"] floatValue]; + + // duration + duration = [[dictionary valueForKey:@"duration"] floatValue]; + + // blend function + blendFunc_.src = [[dictionary valueForKey:@"blendFuncSource"] intValue]; + blendFunc_.dst = [[dictionary valueForKey:@"blendFuncDestination"] intValue]; + + // color + float r,g,b,a; + + r = [[dictionary valueForKey:@"startColorRed"] floatValue]; + g = [[dictionary valueForKey:@"startColorGreen"] floatValue]; + b = [[dictionary valueForKey:@"startColorBlue"] floatValue]; + a = [[dictionary valueForKey:@"startColorAlpha"] floatValue]; + startColor = (ccColor4F) {r,g,b,a}; + + r = [[dictionary valueForKey:@"startColorVarianceRed"] floatValue]; + g = [[dictionary valueForKey:@"startColorVarianceGreen"] floatValue]; + b = [[dictionary valueForKey:@"startColorVarianceBlue"] floatValue]; + a = [[dictionary valueForKey:@"startColorVarianceAlpha"] floatValue]; + startColorVar = (ccColor4F) {r,g,b,a}; + + r = [[dictionary valueForKey:@"finishColorRed"] floatValue]; + g = [[dictionary valueForKey:@"finishColorGreen"] floatValue]; + b = [[dictionary valueForKey:@"finishColorBlue"] floatValue]; + a = [[dictionary valueForKey:@"finishColorAlpha"] floatValue]; + endColor = (ccColor4F) {r,g,b,a}; + + r = [[dictionary valueForKey:@"finishColorVarianceRed"] floatValue]; + g = [[dictionary valueForKey:@"finishColorVarianceGreen"] floatValue]; + b = [[dictionary valueForKey:@"finishColorVarianceBlue"] floatValue]; + a = [[dictionary valueForKey:@"finishColorVarianceAlpha"] floatValue]; + endColorVar = (ccColor4F) {r,g,b,a}; + + // particle size + startSize = [[dictionary valueForKey:@"startParticleSize"] floatValue]; + startSizeVar = [[dictionary valueForKey:@"startParticleSizeVariance"] floatValue]; + endSize = [[dictionary valueForKey:@"finishParticleSize"] floatValue]; + endSizeVar = [[dictionary valueForKey:@"finishParticleSizeVariance"] floatValue]; + + + // position + float x = [[dictionary valueForKey:@"sourcePositionx"] floatValue]; + float y = [[dictionary valueForKey:@"sourcePositiony"] floatValue]; + self.position = ccp(x,y); + posVar.x = [[dictionary valueForKey:@"sourcePositionVariancex"] floatValue]; + posVar.y = [[dictionary valueForKey:@"sourcePositionVariancey"] floatValue]; + + + // Spinning + startSpin = [[dictionary valueForKey:@"rotationStart"] floatValue]; + startSpinVar = [[dictionary valueForKey:@"rotationStartVariance"] floatValue]; + endSpin = [[dictionary valueForKey:@"rotationEnd"] floatValue]; + endSpinVar = [[dictionary valueForKey:@"rotationEndVariance"] floatValue]; + + emitterMode_ = [[dictionary valueForKey:@"emitterType"] intValue]; + + // Mode A: Gravity + tangential accel + radial accel + if( emitterMode_ == kCCParticleModeGravity ) { + // gravity + mode.A.gravity.x = [[dictionary valueForKey:@"gravityx"] floatValue]; + mode.A.gravity.y = [[dictionary valueForKey:@"gravityy"] floatValue]; + + // + // speed + mode.A.speed = [[dictionary valueForKey:@"speed"] floatValue]; + mode.A.speedVar = [[dictionary valueForKey:@"speedVariance"] floatValue]; + + // radial acceleration + NSString *tmp = [dictionary valueForKey:@"radialAcceleration"]; + mode.A.radialAccel = tmp ? [tmp floatValue] : 0; + + tmp = [dictionary valueForKey:@"radialAccelVariance"]; + mode.A.radialAccelVar = tmp ? [tmp floatValue] : 0; + + // tangential acceleration + tmp = [dictionary valueForKey:@"tangentialAcceleration"]; + mode.A.tangentialAccel = tmp ? [tmp floatValue] : 0; + + tmp = [dictionary valueForKey:@"tangentialAccelVariance"]; + mode.A.tangentialAccelVar = tmp ? [tmp floatValue] : 0; + } + + + // or Mode B: radius movement + else if( emitterMode_ == kCCParticleModeRadius ) { + float maxRadius = [[dictionary valueForKey:@"maxRadius"] floatValue]; + float maxRadiusVar = [[dictionary valueForKey:@"maxRadiusVariance"] floatValue]; + float minRadius = [[dictionary valueForKey:@"minRadius"] floatValue]; + + mode.B.startRadius = maxRadius; + mode.B.startRadiusVar = maxRadiusVar; + mode.B.endRadius = minRadius; + mode.B.endRadiusVar = 0; + mode.B.rotatePerSecond = [[dictionary valueForKey:@"rotatePerSecond"] floatValue]; + mode.B.rotatePerSecondVar = [[dictionary valueForKey:@"rotatePerSecondVariance"] floatValue]; + + } else { + NSAssert( NO, @"Invalid emitterType in config file"); + } + + // life span + life = [[dictionary valueForKey:@"particleLifespan"] floatValue]; + lifeVar = [[dictionary valueForKey:@"particleLifespanVariance"] floatValue]; + + // emission Rate + emissionRate = totalParticles/life; + + // texture + // Try to get the texture from the cache + NSString *textureName = [dictionary valueForKey:@"textureFileName"]; + + CCTexture2D *tex = [[CCTextureCache sharedTextureCache] addImage:textureName]; + + if( tex ) + self.texture = tex; + + else { + + NSString *textureData = [dictionary valueForKey:@"textureImageData"]; + NSAssert( textureData, @"CCParticleSystem: Couldn't load texture"); + + // if it fails, try to get it from the base64-gzipped data + unsigned char *buffer = NULL; + int len = base64Decode((unsigned char*)[textureData UTF8String], (unsigned int)[textureData length], &buffer); + NSAssert( buffer != NULL, @"CCParticleSystem: error decoding textureImageData"); + + unsigned char *deflated = NULL; + NSUInteger deflatedLen = ccInflateMemory(buffer, len, &deflated); + free( buffer ); + + NSAssert( deflated != NULL, @"CCParticleSystem: error ungzipping textureImageData"); + NSData *data = [[NSData alloc] initWithBytes:deflated length:deflatedLen]; + +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED + UIImage *image = [[UIImage alloc] initWithData:data]; +#elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED) + NSBitmapImageRep *image = [[NSBitmapImageRep alloc] initWithData:data]; +#endif + + free(deflated); deflated = NULL; + + self.texture = [[CCTextureCache sharedTextureCache] addCGImage:[image CGImage] forKey:textureName]; + [data release]; + [image release]; + } + + NSAssert( [self texture] != NULL, @"CCParticleSystem: error loading the texture"); + + } + + return self; +} + +-(id) initWithTotalParticles:(NSUInteger) numberOfParticles +{ + if( (self=[super init]) ) { + + totalParticles = numberOfParticles; + + particles = calloc( totalParticles, sizeof(tCCParticle) ); + + if( ! particles ) { + NSLog(@"Particle system: not enough memory"); + [self release]; + return nil; + } + + // default, active + active = YES; + + // default blend function + blendFunc_ = (ccBlendFunc) { CC_BLEND_SRC, CC_BLEND_DST }; + + // default movement type; + positionType_ = kCCPositionTypeFree; + + // by default be in mode A: + emitterMode_ = kCCParticleModeGravity; + + // default: modulate + // XXX: not used + // colorModulate = YES; + + autoRemoveOnFinish_ = NO; + + // profiling +#if CC_ENABLE_PROFILERS + _profilingTimer = [[CCProfiler timerWithName:@"particle system" andInstance:self] retain]; +#endif + + // Optimization: compile udpateParticle method + updateParticleSel = @selector(updateQuadWithParticle:newPosition:); + updateParticleImp = (CC_UPDATE_PARTICLE_IMP) [self methodForSelector:updateParticleSel]; + + // udpate after action in run! + [self scheduleUpdateWithPriority:1]; + + } + + return self; +} + +-(void) dealloc +{ + free( particles ); + + [texture_ release]; + // profiling +#if CC_ENABLE_PROFILERS + [CCProfiler releaseTimer:_profilingTimer]; +#endif + + [super dealloc]; +} + +-(BOOL) addParticle +{ + if( [self isFull] ) + return NO; + + tCCParticle * particle = &particles[ particleCount ]; + + [self initParticle: particle]; + particleCount++; + + return YES; +} + +-(void) initParticle: (tCCParticle*) particle +{ + + // timeToLive + // no negative life. prevent division by 0 + particle->timeToLive = life + lifeVar * CCRANDOM_MINUS1_1(); + particle->timeToLive = MAX(0, particle->timeToLive); + + // position + particle->pos.x = sourcePosition.x + posVar.x * CCRANDOM_MINUS1_1(); + particle->pos.x *= CC_CONTENT_SCALE_FACTOR(); + particle->pos.y = sourcePosition.y + posVar.y * CCRANDOM_MINUS1_1(); + particle->pos.y *= CC_CONTENT_SCALE_FACTOR(); + + // Color + ccColor4F start; + start.r = clampf( startColor.r + startColorVar.r * CCRANDOM_MINUS1_1(), 0, 1); + start.g = clampf( startColor.g + startColorVar.g * CCRANDOM_MINUS1_1(), 0, 1); + start.b = clampf( startColor.b + startColorVar.b * CCRANDOM_MINUS1_1(), 0, 1); + start.a = clampf( startColor.a + startColorVar.a * CCRANDOM_MINUS1_1(), 0, 1); + + ccColor4F end; + end.r = clampf( endColor.r + endColorVar.r * CCRANDOM_MINUS1_1(), 0, 1); + end.g = clampf( endColor.g + endColorVar.g * CCRANDOM_MINUS1_1(), 0, 1); + end.b = clampf( endColor.b + endColorVar.b * CCRANDOM_MINUS1_1(), 0, 1); + end.a = clampf( endColor.a + endColorVar.a * CCRANDOM_MINUS1_1(), 0, 1); + + particle->color = start; + particle->deltaColor.r = (end.r - start.r) / particle->timeToLive; + particle->deltaColor.g = (end.g - start.g) / particle->timeToLive; + particle->deltaColor.b = (end.b - start.b) / particle->timeToLive; + particle->deltaColor.a = (end.a - start.a) / particle->timeToLive; + + // size + float startS = startSize + startSizeVar * CCRANDOM_MINUS1_1(); + startS = MAX(0, startS); // No negative value + startS *= CC_CONTENT_SCALE_FACTOR(); + + particle->size = startS; + if( endSize == kCCParticleStartSizeEqualToEndSize ) + particle->deltaSize = 0; + else { + float endS = endSize + endSizeVar * CCRANDOM_MINUS1_1(); + endS = MAX(0, endS); // No negative values + endS *= CC_CONTENT_SCALE_FACTOR(); + particle->deltaSize = (endS - startS) / particle->timeToLive; + } + + // rotation + float startA = startSpin + startSpinVar * CCRANDOM_MINUS1_1(); + float endA = endSpin + endSpinVar * CCRANDOM_MINUS1_1(); + particle->rotation = startA; + particle->deltaRotation = (endA - startA) / particle->timeToLive; + + // position + if( positionType_ == kCCPositionTypeFree ) { + CGPoint p = [self convertToWorldSpace:CGPointZero]; + particle->startPos = ccpMult( p, CC_CONTENT_SCALE_FACTOR() ); + } + else if( positionType_ == kCCPositionTypeRelative ) { + particle->startPos = ccpMult( position_, CC_CONTENT_SCALE_FACTOR() ); + } + + // direction + float a = CC_DEGREES_TO_RADIANS( angle + angleVar * CCRANDOM_MINUS1_1() ); + + // Mode Gravity: A + if( emitterMode_ == kCCParticleModeGravity ) { + + CGPoint v = {cosf( a ), sinf( a )}; + float s = mode.A.speed + mode.A.speedVar * CCRANDOM_MINUS1_1(); + s *= CC_CONTENT_SCALE_FACTOR(); + + // direction + particle->mode.A.dir = ccpMult( v, s ); + + // radial accel + particle->mode.A.radialAccel = mode.A.radialAccel + mode.A.radialAccelVar * CCRANDOM_MINUS1_1(); + particle->mode.A.radialAccel *= CC_CONTENT_SCALE_FACTOR(); + + // tangential accel + particle->mode.A.tangentialAccel = mode.A.tangentialAccel + mode.A.tangentialAccelVar * CCRANDOM_MINUS1_1(); + particle->mode.A.tangentialAccel *= CC_CONTENT_SCALE_FACTOR(); + + } + + // Mode Radius: B + else { + // Set the default diameter of the particle from the source position + float startRadius = mode.B.startRadius + mode.B.startRadiusVar * CCRANDOM_MINUS1_1(); + float endRadius = mode.B.endRadius + mode.B.endRadiusVar * CCRANDOM_MINUS1_1(); + + startRadius *= CC_CONTENT_SCALE_FACTOR(); + endRadius *= CC_CONTENT_SCALE_FACTOR(); + + particle->mode.B.radius = startRadius; + + if( mode.B.endRadius == kCCParticleStartRadiusEqualToEndRadius ) + particle->mode.B.deltaRadius = 0; + else + particle->mode.B.deltaRadius = (endRadius - startRadius) / particle->timeToLive; + + particle->mode.B.angle = a; + particle->mode.B.degreesPerSecond = CC_DEGREES_TO_RADIANS(mode.B.rotatePerSecond + mode.B.rotatePerSecondVar * CCRANDOM_MINUS1_1()); + } +} + +-(void) stopSystem +{ + active = NO; + elapsed = duration; + emitCounter = 0; +} + +-(void) resetSystem +{ + active = YES; + elapsed = 0; + for(particleIdx = 0; particleIdx < particleCount; ++particleIdx) { + tCCParticle *p = &particles[particleIdx]; + p->timeToLive = 0; + } +} + +-(BOOL) isFull +{ + return (particleCount == totalParticles); +} + +#pragma mark ParticleSystem - MainLoop +-(void) update: (ccTime) dt +{ + if( active && emissionRate ) { + float rate = 1.0f / emissionRate; + emitCounter += dt; + while( particleCount < totalParticles && emitCounter > rate ) { + [self addParticle]; + emitCounter -= rate; + } + + elapsed += dt; + if(duration != -1 && duration < elapsed) + [self stopSystem]; + } + + particleIdx = 0; + + +#if CC_ENABLE_PROFILERS + CCProfilingBeginTimingBlock(_profilingTimer); +#endif + + + CGPoint currentPosition = CGPointZero; + if( positionType_ == kCCPositionTypeFree ) { + currentPosition = [self convertToWorldSpace:CGPointZero]; + currentPosition.x *= CC_CONTENT_SCALE_FACTOR(); + currentPosition.y *= CC_CONTENT_SCALE_FACTOR(); + } + else if( positionType_ == kCCPositionTypeRelative ) { + currentPosition = position_; + currentPosition.x *= CC_CONTENT_SCALE_FACTOR(); + currentPosition.y *= CC_CONTENT_SCALE_FACTOR(); + } + + while( particleIdx < particleCount ) + { + tCCParticle *p = &particles[particleIdx]; + + // life + p->timeToLive -= dt; + + if( p->timeToLive > 0 ) { + + // Mode A: gravity, direction, tangential accel & radial accel + if( emitterMode_ == kCCParticleModeGravity ) { + CGPoint tmp, radial, tangential; + + radial = CGPointZero; + // radial acceleration + if(p->pos.x || p->pos.y) + radial = ccpNormalize(p->pos); + + tangential = radial; + radial = ccpMult(radial, p->mode.A.radialAccel); + + // tangential acceleration + float newy = tangential.x; + tangential.x = -tangential.y; + tangential.y = newy; + tangential = ccpMult(tangential, p->mode.A.tangentialAccel); + + // (gravity + radial + tangential) * dt + tmp = ccpAdd( ccpAdd( radial, tangential), mode.A.gravity); + tmp = ccpMult( tmp, dt); + p->mode.A.dir = ccpAdd( p->mode.A.dir, tmp); + tmp = ccpMult(p->mode.A.dir, dt); + p->pos = ccpAdd( p->pos, tmp ); + } + + // Mode B: radius movement + else { + // Update the angle and radius of the particle. + p->mode.B.angle += p->mode.B.degreesPerSecond * dt; + p->mode.B.radius += p->mode.B.deltaRadius * dt; + + p->pos.x = - cosf(p->mode.B.angle) * p->mode.B.radius; + p->pos.y = - sinf(p->mode.B.angle) * p->mode.B.radius; + } + + // color + p->color.r += (p->deltaColor.r * dt); + p->color.g += (p->deltaColor.g * dt); + p->color.b += (p->deltaColor.b * dt); + p->color.a += (p->deltaColor.a * dt); + + // size + p->size += (p->deltaSize * dt); + p->size = MAX( 0, p->size ); + + // angle + p->rotation += (p->deltaRotation * dt); + + // + // update values in quad + // + + CGPoint newPos; + + if( positionType_ == kCCPositionTypeFree || positionType_ == kCCPositionTypeRelative ) { + CGPoint diff = ccpSub( currentPosition, p->startPos ); + newPos = ccpSub(p->pos, diff); + + } else + newPos = p->pos; + + + updateParticleImp(self, updateParticleSel, p, newPos); + + // update particle counter + particleIdx++; + + } else { + // life < 0 + if( particleIdx != particleCount-1 ) + particles[particleIdx] = particles[particleCount-1]; + particleCount--; + + if( particleCount == 0 && autoRemoveOnFinish_ ) { + [self unscheduleUpdate]; + [parent_ removeChild:self cleanup:YES]; + return; + } + } + } + +#if CC_ENABLE_PROFILERS + CCProfilingEndTimingBlock(_profilingTimer); +#endif + +#ifdef CC_USES_VBO + [self postStep]; +#endif +} + +-(void) updateQuadWithParticle:(tCCParticle*)particle newPosition:(CGPoint)pos; +{ + // should be overriden +} + +-(void) postStep +{ + // should be overriden +} + +#pragma mark ParticleSystem - CCTexture protocol + +-(void) setTexture:(CCTexture2D*) texture +{ + [texture_ release]; + texture_ = [texture retain]; + + // If the new texture has No premultiplied alpha, AND the blendFunc hasn't been changed, then update it + if( texture_ && ! [texture hasPremultipliedAlpha] && + ( blendFunc_.src == CC_BLEND_SRC && blendFunc_.dst == CC_BLEND_DST ) ) { + + blendFunc_.src = GL_SRC_ALPHA; + blendFunc_.dst = GL_ONE_MINUS_SRC_ALPHA; + } +} + +-(CCTexture2D*) texture +{ + return texture_; +} + +#pragma mark ParticleSystem - Additive Blending +-(void) setBlendAdditive:(BOOL)additive +{ + if( additive ) { + blendFunc_.src = GL_SRC_ALPHA; + blendFunc_.dst = GL_ONE; + + } else { + + if( texture_ && ! [texture_ hasPremultipliedAlpha] ) { + blendFunc_.src = GL_SRC_ALPHA; + blendFunc_.dst = GL_ONE_MINUS_SRC_ALPHA; + } else { + blendFunc_.src = CC_BLEND_SRC; + blendFunc_.dst = CC_BLEND_DST; + } + } +} + +-(BOOL) blendAdditive +{ + return( blendFunc_.src == GL_SRC_ALPHA && blendFunc_.dst == GL_ONE); +} + +#pragma mark ParticleSystem - Properties of Gravity Mode +-(void) setTangentialAccel:(float)t +{ + NSAssert( emitterMode_ == kCCParticleModeGravity, @"Particle Mode should be Gravity"); + mode.A.tangentialAccel = t; +} +-(float) tangentialAccel +{ + NSAssert( emitterMode_ == kCCParticleModeGravity, @"Particle Mode should be Gravity"); + return mode.A.tangentialAccel; +} + +-(void) setTangentialAccelVar:(float)t +{ + NSAssert( emitterMode_ == kCCParticleModeGravity, @"Particle Mode should be Gravity"); + mode.A.tangentialAccelVar = t; +} +-(float) tangentialAccelVar +{ + NSAssert( emitterMode_ == kCCParticleModeGravity, @"Particle Mode should be Gravity"); + return mode.A.tangentialAccelVar; +} + +-(void) setRadialAccel:(float)t +{ + NSAssert( emitterMode_ == kCCParticleModeGravity, @"Particle Mode should be Gravity"); + mode.A.radialAccel = t; +} +-(float) radialAccel +{ + NSAssert( emitterMode_ == kCCParticleModeGravity, @"Particle Mode should be Gravity"); + return mode.A.radialAccel; +} + +-(void) setRadialAccelVar:(float)t +{ + NSAssert( emitterMode_ == kCCParticleModeGravity, @"Particle Mode should be Gravity"); + mode.A.radialAccelVar = t; +} +-(float) radialAccelVar +{ + NSAssert( emitterMode_ == kCCParticleModeGravity, @"Particle Mode should be Gravity"); + return mode.A.radialAccelVar; +} + +-(void) setGravity:(CGPoint)g +{ + NSAssert( emitterMode_ == kCCParticleModeGravity, @"Particle Mode should be Gravity"); + mode.A.gravity = g; +} +-(CGPoint) gravity +{ + NSAssert( emitterMode_ == kCCParticleModeGravity, @"Particle Mode should be Gravity"); + return mode.A.gravity; +} + +-(void) setSpeed:(float)speed +{ + NSAssert( emitterMode_ == kCCParticleModeGravity, @"Particle Mode should be Gravity"); + mode.A.speed = speed; +} +-(float) speed +{ + NSAssert( emitterMode_ == kCCParticleModeGravity, @"Particle Mode should be Gravity"); + return mode.A.speed; +} + +-(void) setSpeedVar:(float)speedVar +{ + NSAssert( emitterMode_ == kCCParticleModeGravity, @"Particle Mode should be Gravity"); + mode.A.speedVar = speedVar; +} +-(float) speedVar +{ + NSAssert( emitterMode_ == kCCParticleModeGravity, @"Particle Mode should be Gravity"); + return mode.A.speedVar; +} + +#pragma mark ParticleSystem - Properties of Radius Mode + +-(void) setStartRadius:(float)startRadius +{ + NSAssert( emitterMode_ == kCCParticleModeRadius, @"Particle Mode should be Radius"); + mode.B.startRadius = startRadius; +} +-(float) startRadius +{ + NSAssert( emitterMode_ == kCCParticleModeRadius, @"Particle Mode should be Radius"); + return mode.B.startRadius; +} + +-(void) setStartRadiusVar:(float)startRadiusVar +{ + NSAssert( emitterMode_ == kCCParticleModeRadius, @"Particle Mode should be Radius"); + mode.B.startRadiusVar = startRadiusVar; +} +-(float) startRadiusVar +{ + NSAssert( emitterMode_ == kCCParticleModeRadius, @"Particle Mode should be Radius"); + return mode.B.startRadiusVar; +} + +-(void) setEndRadius:(float)endRadius +{ + NSAssert( emitterMode_ == kCCParticleModeRadius, @"Particle Mode should be Radius"); + mode.B.endRadius = endRadius; +} +-(float) endRadius +{ + NSAssert( emitterMode_ == kCCParticleModeRadius, @"Particle Mode should be Radius"); + return mode.B.endRadius; +} + +-(void) setEndRadiusVar:(float)endRadiusVar +{ + NSAssert( emitterMode_ == kCCParticleModeRadius, @"Particle Mode should be Radius"); + mode.B.endRadiusVar = endRadiusVar; +} +-(float) endRadiusVar +{ + NSAssert( emitterMode_ == kCCParticleModeRadius, @"Particle Mode should be Radius"); + return mode.B.endRadiusVar; +} + +-(void) setRotatePerSecond:(float)degrees +{ + NSAssert( emitterMode_ == kCCParticleModeRadius, @"Particle Mode should be Radius"); + mode.B.rotatePerSecond = degrees; +} +-(float) rotatePerSecond +{ + NSAssert( emitterMode_ == kCCParticleModeRadius, @"Particle Mode should be Radius"); + return mode.B.rotatePerSecond; +} + +-(void) setRotatePerSecondVar:(float)degrees +{ + NSAssert( emitterMode_ == kCCParticleModeRadius, @"Particle Mode should be Radius"); + mode.B.rotatePerSecondVar = degrees; +} +-(float) rotatePerSecondVar +{ + NSAssert( emitterMode_ == kCCParticleModeRadius, @"Particle Mode should be Radius"); + return mode.B.rotatePerSecondVar; +} +@end + + diff --git a/tweejump/libs/cocos2d/CCParticleSystemPoint.h b/tweejump/libs/cocos2d/CCParticleSystemPoint.h new file mode 100755 index 0000000..f0918fe --- /dev/null +++ b/tweejump/libs/cocos2d/CCParticleSystemPoint.h @@ -0,0 +1,65 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-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. + * + */ + + +#import +#import "CCParticleSystem.h" + +#define CC_MAX_PARTICLE_SIZE 64 + +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED + +/** CCParticleSystemPoint is a subclass of CCParticleSystem + Attributes of a Particle System: + * All the attributes of Particle System + + Features: + * consumes small memory: uses 1 vertex (x,y) per particle, no need to assign tex coordinates + * size can't be bigger than 64 + * the system can't be scaled since the particles are rendered using GL_POINT_SPRITE + + Limitations: + * On 3rd gen iPhone devices and iPads, this node performs MUCH slower than CCParticleSystemQuad. + */ +@interface CCParticleSystemPoint : CCParticleSystem +{ + // Array of (x,y,size) + ccPointSprite *vertices; + // vertices buffer id +#if CC_USES_VBO + GLuint verticesID; +#endif +} +@end + +#elif __MAC_OS_X_VERSION_MAX_ALLOWED + +#import "CCParticleSystemQuad.h" + +@interface CCParticleSystemPoint : CCParticleSystemQuad +@end + +#endif diff --git a/tweejump/libs/cocos2d/CCParticleSystemPoint.m b/tweejump/libs/cocos2d/CCParticleSystemPoint.m new file mode 100755 index 0000000..0894d2b --- /dev/null +++ b/tweejump/libs/cocos2d/CCParticleSystemPoint.m @@ -0,0 +1,211 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-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. + * + */ + +#import +#import "CCParticleSystemPoint.h" + +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED + +// opengl +#import "Platforms/CCGL.h" + +// cocos2d +#import "CCTextureCache.h" +#import "ccMacros.h" + +// support +#import "Support/OpenGL_Internal.h" +#import "Support/CGPointExtension.h" + +@implementation CCParticleSystemPoint + +-(id) initWithTotalParticles:(NSUInteger) numberOfParticles +{ + if( (self=[super initWithTotalParticles:numberOfParticles]) ) { + + vertices = malloc( sizeof(ccPointSprite) * totalParticles ); + + if( ! vertices ) { + NSLog(@"cocos2d: Particle system: not enough memory"); + [self release]; + return nil; + } + +#if CC_USES_VBO + glGenBuffers(1, &verticesID); + + // initial binding + glBindBuffer(GL_ARRAY_BUFFER, verticesID); + glBufferData(GL_ARRAY_BUFFER, sizeof(ccPointSprite)*totalParticles, vertices, GL_DYNAMIC_DRAW); + glBindBuffer(GL_ARRAY_BUFFER, 0); +#endif + } + + return self; +} + +-(void) dealloc +{ + free(vertices); +#if CC_USES_VBO + glDeleteBuffers(1, &verticesID); +#endif + + [super dealloc]; +} + +-(void) updateQuadWithParticle:(tCCParticle*)p newPosition:(CGPoint)newPos +{ + // place vertices and colos in array + vertices[particleIdx].pos = (ccVertex2F) {newPos.x, newPos.y}; + vertices[particleIdx].size = p->size; + ccColor4B color = { p->color.r*255, p->color.g*255, p->color.b*255, p->color.a*255 }; + vertices[particleIdx].color = color; +} + +-(void) postStep +{ +#if CC_USES_VBO + glBindBuffer(GL_ARRAY_BUFFER, verticesID); + glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(ccPointSprite)*particleCount, vertices); + glBindBuffer(GL_ARRAY_BUFFER, 0); +#endif +} + +-(void) draw +{ + [super draw]; + + if (particleIdx==0) + return; + + // Default GL states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY + // Needed states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY + // Unneeded states: GL_TEXTURE_COORD_ARRAY + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + + glBindTexture(GL_TEXTURE_2D, texture_.name); + + glEnable(GL_POINT_SPRITE_OES); + glTexEnvi( GL_POINT_SPRITE_OES, GL_COORD_REPLACE_OES, GL_TRUE ); + +#define kPointSize sizeof(vertices[0]) + +#if CC_USES_VBO + glBindBuffer(GL_ARRAY_BUFFER, verticesID); + + glVertexPointer(2,GL_FLOAT, kPointSize, 0); + + glColorPointer(4, GL_UNSIGNED_BYTE, kPointSize, (GLvoid*) offsetof(ccPointSprite, color) ); + + glEnableClientState(GL_POINT_SIZE_ARRAY_OES); + glPointSizePointerOES(GL_FLOAT, kPointSize, (GLvoid*) offsetof(ccPointSprite, size) ); +#else // Uses Vertex Array List + int offset = (int)vertices; + glVertexPointer(2,GL_FLOAT, kPointSize, (GLvoid*) offset); + + int diff = offsetof(ccPointSprite, color); + glColorPointer(4, GL_UNSIGNED_BYTE, kPointSize, (GLvoid*) (offset+diff)); + + glEnableClientState(GL_POINT_SIZE_ARRAY_OES); + diff = offsetof(ccPointSprite, size); + glPointSizePointerOES(GL_FLOAT, kPointSize, (GLvoid*) (offset+diff)); +#endif + + BOOL newBlend = blendFunc_.src != CC_BLEND_SRC || blendFunc_.dst != CC_BLEND_DST; + if( newBlend ) + glBlendFunc( blendFunc_.src, blendFunc_.dst ); + + + glDrawArrays(GL_POINTS, 0, particleIdx); + + // restore blend state + if( newBlend ) + glBlendFunc( CC_BLEND_SRC, CC_BLEND_DST); + + +#if CC_USES_VBO + // unbind VBO buffer + glBindBuffer(GL_ARRAY_BUFFER, 0); +#endif + + glDisableClientState(GL_POINT_SIZE_ARRAY_OES); + glDisable(GL_POINT_SPRITE_OES); + + // restore GL default state + glEnableClientState(GL_TEXTURE_COORD_ARRAY); +} + +#pragma mark Non supported properties + +// +// SPIN IS NOT SUPPORTED +// +-(void) setStartSpin:(float)a +{ + NSAssert(a == 0, @"PointParticleSystem doesn't support spinning"); + [super setStartSpin:a]; +} +-(void) setStartSpinVar:(float)a +{ + NSAssert(a == 0, @"PointParticleSystem doesn't support spinning"); + [super setStartSpin:a]; +} +-(void) setEndSpin:(float)a +{ + NSAssert(a == 0, @"PointParticleSystem doesn't support spinning"); + [super setStartSpin:a]; +} +-(void) setEndSpinVar:(float)a +{ + NSAssert(a == 0, @"PointParticleSystem doesn't support spinning"); + [super setStartSpin:a]; +} + +// +// SIZE > 64 IS NOT SUPPORTED +// +-(void) setStartSize:(float)size +{ + NSAssert(size >= 0 && size <= CC_MAX_PARTICLE_SIZE, @"PointParticleSystem only supports 0 <= size <= 64"); + [super setStartSize:size]; +} + +-(void) setEndSize:(float)size +{ + NSAssert( (size == kCCParticleStartSizeEqualToEndSize) || + ( size >= 0 && size <= CC_MAX_PARTICLE_SIZE), @"PointParticleSystem only supports 0 <= size <= 64"); + [super setEndSize:size]; +} +@end + +#elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED) +@implementation CCParticleSystemPoint +@end + +#endif // __MAC_OS_X_VERSION_MAX_ALLOWED + + diff --git a/tweejump/libs/cocos2d/CCParticleSystemQuad.h b/tweejump/libs/cocos2d/CCParticleSystemQuad.h new file mode 100755 index 0000000..74a9d93 --- /dev/null +++ b/tweejump/libs/cocos2d/CCParticleSystemQuad.h @@ -0,0 +1,76 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2009 Leonardo Kasperavičius + * + * Copyright (c) 2008-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. + * + */ + + +#import "CCParticleSystem.h" +#import "ccConfig.h" + +@class CCSpriteFrame; + +/** CCParticleSystemQuad is a subclass of CCParticleSystem + + It includes all the features of ParticleSystem. + + Special features and Limitations: + - Particle size can be any float number. + - The system can be scaled + - The particles can be rotated + - On 1st and 2nd gen iPhones: It is only a bit slower that CCParticleSystemPoint + - On 3rd gen iPhone and iPads: It is MUCH faster than CCParticleSystemPoint + - It consumes more RAM and more GPU memory than CCParticleSystemPoint + - It supports subrects + @since v0.8 + */ +@interface CCParticleSystemQuad : CCParticleSystem +{ + ccV2F_C4B_T2F_Quad *quads_; // quads to be rendered + GLushort *indices_; // indices +#if CC_USES_VBO + GLuint quadsID_; // VBO id +#endif +} + +/** initialices the indices for the vertices */ +-(void) initIndices; + +/** initilizes the texture with a rectangle measured Points */ +-(void) initTexCoordsWithRect:(CGRect)rect; + +/** Sets a new CCSpriteFrame as particle. + WARNING: this method is experimental. Use setTexture:withRect instead. + @since v0.99.4 + */ +-(void)setDisplayFrame:(CCSpriteFrame*)spriteFrame; + +/** Sets a new texture with a rect. The rect is in Points. + @since v0.99.4 + */ +-(void) setTexture:(CCTexture2D *)texture withRect:(CGRect)rect; + +@end + diff --git a/tweejump/libs/cocos2d/CCParticleSystemQuad.m b/tweejump/libs/cocos2d/CCParticleSystemQuad.m new file mode 100755 index 0000000..4916964 --- /dev/null +++ b/tweejump/libs/cocos2d/CCParticleSystemQuad.m @@ -0,0 +1,318 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2009 Leonardo Kasperavičius + * + * Copyright (c) 2008-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. + * + */ + + +// opengl +#import "Platforms/CCGL.h" + +// cocos2d +#import "ccConfig.h" +#import "CCParticleSystemQuad.h" +#import "CCTextureCache.h" +#import "ccMacros.h" +#import "CCSpriteFrame.h" + +// support +#import "Support/OpenGL_Internal.h" +#import "Support/CGPointExtension.h" + +@implementation CCParticleSystemQuad + + +// overriding the init method +-(id) initWithTotalParticles:(NSUInteger) numberOfParticles +{ + // base initialization + if( (self=[super initWithTotalParticles:numberOfParticles]) ) { + + // allocating data space + quads_ = calloc( sizeof(quads_[0]) * totalParticles, 1 ); + indices_ = calloc( sizeof(indices_[0]) * totalParticles * 6, 1 ); + + if( !quads_ || !indices_) { + NSLog(@"cocos2d: Particle system: not enough memory"); + if( quads_ ) + free( quads_ ); + if(indices_) + free(indices_); + + [self release]; + return nil; + } + + // initialize only once the texCoords and the indices + [self initTexCoordsWithRect:CGRectMake(0, 0, [texture_ pixelsWide], [texture_ pixelsHigh])]; + [self initIndices]; + +#if CC_USES_VBO + // create the VBO buffer + glGenBuffers(1, &quadsID_); + + // initial binding + glBindBuffer(GL_ARRAY_BUFFER, quadsID_); + glBufferData(GL_ARRAY_BUFFER, sizeof(quads_[0])*totalParticles, quads_,GL_DYNAMIC_DRAW); + glBindBuffer(GL_ARRAY_BUFFER, 0); +#endif + } + + return self; +} + +-(void) dealloc +{ + free(quads_); + free(indices_); +#if CC_USES_VBO + glDeleteBuffers(1, &quadsID_); +#endif + + [super dealloc]; +} + +// pointRect is in Points coordinates. +-(void) initTexCoordsWithRect:(CGRect)pointRect +{ + // convert to pixels coords + CGRect rect = CGRectMake( + pointRect.origin.x * CC_CONTENT_SCALE_FACTOR(), + pointRect.origin.y * CC_CONTENT_SCALE_FACTOR(), + pointRect.size.width * CC_CONTENT_SCALE_FACTOR(), + pointRect.size.height * CC_CONTENT_SCALE_FACTOR() ); + + GLfloat wide = [texture_ pixelsWide]; + GLfloat high = [texture_ pixelsHigh]; + +#if CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL + GLfloat left = (rect.origin.x*2+1) / (wide*2); + GLfloat bottom = (rect.origin.y*2+1) / (high*2); + GLfloat right = left + (rect.size.width*2-2) / (wide*2); + GLfloat top = bottom + (rect.size.height*2-2) / (high*2); +#else + GLfloat left = rect.origin.x / wide; + GLfloat bottom = rect.origin.y / high; + GLfloat right = left + rect.size.width / wide; + GLfloat top = bottom + rect.size.height / high; +#endif // ! CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL + + // Important. Texture in cocos2d are inverted, so the Y component should be inverted + CC_SWAP( top, bottom); + + for(NSUInteger i=0; icolor.r*255, p->color.g*255, p->color.b*255, p->color.a*255}; + quad->bl.colors = color; + quad->br.colors = color; + quad->tl.colors = color; + quad->tr.colors = color; + + // vertices + GLfloat size_2 = p->size/2; + if( p->rotation ) { + GLfloat x1 = -size_2; + GLfloat y1 = -size_2; + + GLfloat x2 = size_2; + GLfloat y2 = size_2; + GLfloat x = newPos.x; + GLfloat y = newPos.y; + + GLfloat r = (GLfloat)-CC_DEGREES_TO_RADIANS(p->rotation); + GLfloat cr = cosf(r); + GLfloat sr = sinf(r); + GLfloat ax = x1 * cr - y1 * sr + x; + GLfloat ay = x1 * sr + y1 * cr + y; + GLfloat bx = x2 * cr - y1 * sr + x; + GLfloat by = x2 * sr + y1 * cr + y; + GLfloat cx = x2 * cr - y2 * sr + x; + GLfloat cy = x2 * sr + y2 * cr + y; + GLfloat dx = x1 * cr - y2 * sr + x; + GLfloat dy = x1 * sr + y2 * cr + y; + + // bottom-left + quad->bl.vertices.x = ax; + quad->bl.vertices.y = ay; + + // bottom-right vertex: + quad->br.vertices.x = bx; + quad->br.vertices.y = by; + + // top-left vertex: + quad->tl.vertices.x = dx; + quad->tl.vertices.y = dy; + + // top-right vertex: + quad->tr.vertices.x = cx; + quad->tr.vertices.y = cy; + } else { + // bottom-left vertex: + quad->bl.vertices.x = newPos.x - size_2; + quad->bl.vertices.y = newPos.y - size_2; + + // bottom-right vertex: + quad->br.vertices.x = newPos.x + size_2; + quad->br.vertices.y = newPos.y - size_2; + + // top-left vertex: + quad->tl.vertices.x = newPos.x - size_2; + quad->tl.vertices.y = newPos.y + size_2; + + // top-right vertex: + quad->tr.vertices.x = newPos.x + size_2; + quad->tr.vertices.y = newPos.y + size_2; + } +} + +-(void) postStep +{ +#if CC_USES_VBO + glBindBuffer(GL_ARRAY_BUFFER, quadsID_); + glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(quads_[0])*particleCount, quads_); + glBindBuffer(GL_ARRAY_BUFFER, 0); +#endif +} + +// overriding draw method +-(void) draw +{ + [super draw]; + + // Default GL states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY + // Needed states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY + // Unneeded states: - + + glBindTexture(GL_TEXTURE_2D, [texture_ name]); + +#define kQuadSize sizeof(quads_[0].bl) + +#if CC_USES_VBO + glBindBuffer(GL_ARRAY_BUFFER, quadsID_); + + glVertexPointer(2,GL_FLOAT, kQuadSize, 0); + + glColorPointer(4, GL_UNSIGNED_BYTE, kQuadSize, (GLvoid*) offsetof(ccV2F_C4B_T2F,colors) ); + + glTexCoordPointer(2, GL_FLOAT, kQuadSize, (GLvoid*) offsetof(ccV2F_C4B_T2F,texCoords) ); +#else // vertex array list + + NSUInteger offset = (NSUInteger) quads_; + + // vertex + NSUInteger diff = offsetof( ccV2F_C4B_T2F, vertices); + glVertexPointer(2,GL_FLOAT, kQuadSize, (GLvoid*) (offset+diff) ); + + // color + diff = offsetof( ccV2F_C4B_T2F, colors); + glColorPointer(4, GL_UNSIGNED_BYTE, kQuadSize, (GLvoid*)(offset + diff)); + + // tex coords + diff = offsetof( ccV2F_C4B_T2F, texCoords); + glTexCoordPointer(2, GL_FLOAT, kQuadSize, (GLvoid*)(offset + diff)); + +#endif // ! CC_USES_VBO + + BOOL newBlend = blendFunc_.src != CC_BLEND_SRC || blendFunc_.dst != CC_BLEND_DST; + if( newBlend ) + glBlendFunc( blendFunc_.src, blendFunc_.dst ); + + NSAssert( particleIdx == particleCount, @"Abnormal error in particle quad"); + glDrawElements(GL_TRIANGLES, (GLsizei) particleIdx*6, GL_UNSIGNED_SHORT, indices_); + + // restore blend state + if( newBlend ) + glBlendFunc( CC_BLEND_SRC, CC_BLEND_DST ); + +#if CC_USES_VBO + glBindBuffer(GL_ARRAY_BUFFER, 0); +#endif + + // restore GL default state + // - +} + +@end + + diff --git a/tweejump/libs/cocos2d/CCProgressTimer.h b/tweejump/libs/cocos2d/CCProgressTimer.h new file mode 100755 index 0000000..9a07f2f --- /dev/null +++ b/tweejump/libs/cocos2d/CCProgressTimer.h @@ -0,0 +1,83 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2010 Lam Pham + * + * 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. + * + */ + +#import +#import "CCSprite.h" + +/** Types of progress + @since v0.99.1 + */ +typedef enum { + /// Radial Counter-Clockwise + kCCProgressTimerTypeRadialCCW, + /// Radial ClockWise + kCCProgressTimerTypeRadialCW, + /// Horizontal Left-Right + kCCProgressTimerTypeHorizontalBarLR, + /// Horizontal Right-Left + kCCProgressTimerTypeHorizontalBarRL, + /// Vertical Bottom-top + kCCProgressTimerTypeVerticalBarBT, + /// Vertical Top-Bottom + kCCProgressTimerTypeVerticalBarTB, +} CCProgressTimerType; + +/** + CCProgresstimer is a subclass of CCNode. + It renders the inner sprite according to the percentage. + The progress can be Radial, Horizontal or vertical. + @since v0.99.1 + */ +@interface CCProgressTimer : CCNode +{ + CCProgressTimerType type_; + float percentage_; + CCSprite *sprite_; + + int vertexDataCount_; + ccV2F_C4B_T2F *vertexData_; +} + +/** Change the percentage to change progress. */ +@property (nonatomic, readwrite) CCProgressTimerType type; + +/** Percentages are from 0 to 100 */ +@property (nonatomic, readwrite) float percentage; + +/** The image to show the progress percentage */ +@property (nonatomic, readwrite, retain) CCSprite *sprite; + + +/** Creates a progress timer with an image filename as the shape the timer goes through */ ++ (id) progressWithFile:(NSString*) filename; +/** Initializes a progress timer with an image filename as the shape the timer goes through */ +- (id) initWithFile:(NSString*) filename; + +/** Creates a progress timer with the texture as the shape the timer goes through */ ++ (id) progressWithTexture:(CCTexture2D*) texture; +/** Creates a progress timer with the texture as the shape the timer goes through */ +- (id) initWithTexture:(CCTexture2D*) texture; + +@end diff --git a/tweejump/libs/cocos2d/CCProgressTimer.m b/tweejump/libs/cocos2d/CCProgressTimer.m new file mode 100755 index 0000000..4e697b2 --- /dev/null +++ b/tweejump/libs/cocos2d/CCProgressTimer.m @@ -0,0 +1,493 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2010 Lam Pham + * + * 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. + * + */ + +#import "CCProgressTimer.h" + +#import "ccMacros.h" +#import "CCTextureCache.h" +#import "Support/CGPointExtension.h" + + + +#define kProgressTextureCoordsCount 4 +// kProgressTextureCoords holds points {0,0} {0,1} {1,1} {1,0} we can represent it as bits +const char kProgressTextureCoords = 0x1e; + +@interface CCProgressTimer (Internal) + +-(void)updateProgress; +-(void)updateBar; +-(void)updateRadial; +-(void)updateColor; +-(CGPoint)boundaryTexCoord:(char)index; +@end + + +@implementation CCProgressTimer +@synthesize percentage = percentage_; +@synthesize sprite = sprite_; +@synthesize type = type_; + ++(id)progressWithFile:(NSString*) filename +{ + return [[[self alloc]initWithFile:filename] autorelease]; +} +-(id)initWithFile:(NSString*) filename +{ + return [self initWithTexture:[[CCTextureCache sharedTextureCache] addImage: filename]]; +} + ++(id)progressWithTexture:(CCTexture2D*) texture +{ + return [[[self alloc]initWithTexture:texture] autorelease]; +} +-(id)initWithTexture:(CCTexture2D*) texture +{ + if(( self = [super init] )){ + self.sprite = [CCSprite spriteWithTexture:texture]; + percentage_ = 0.f; + vertexData_ = NULL; + vertexDataCount_ = 0; + self.anchorPoint = ccp(.5f,.5f); + self.contentSize = sprite_.contentSize; + self.type = kCCProgressTimerTypeRadialCCW; + } + return self; +} +-(void)dealloc +{ + if(vertexData_) + free(vertexData_); + + [sprite_ release]; + [super dealloc]; +} + +-(void)setPercentage:(float) percentage +{ + if(percentage_ != percentage) { + percentage_ = clampf( percentage, 0, 100); + [self updateProgress]; + } +} +-(void)setSprite:(CCSprite *)newSprite +{ + if(sprite_ != newSprite){ + [sprite_ release]; + sprite_ = [newSprite retain]; + + // Everytime we set a new sprite, we free the current vertex data + if(vertexData_){ + free(vertexData_); + vertexData_ = NULL; + vertexDataCount_ = 0; + } + } +} +-(void)setType:(CCProgressTimerType)newType +{ + if (newType != type_) { + + // release all previous information + if(vertexData_){ + free(vertexData_); + vertexData_ = NULL; + vertexDataCount_ = 0; + } + type_ = newType; + } +} +@end + +@implementation CCProgressTimer(Internal) + +/// +// @returns the vertex position from the texture coordinate +/// +-(ccVertex2F)vertexFromTexCoord:(CGPoint) texCoord +{ + CGPoint tmp; + ccVertex2F ret; + if (sprite_.texture) { + CCTexture2D *texture = [sprite_ texture]; + CGSize texSize = [texture contentSizeInPixels]; + tmp = ccp(texSize.width * texCoord.x/texture.maxS, + texSize.height * (1 - (texCoord.y/texture.maxT))); + } else + tmp = CGPointZero; + + ret.x = tmp.x; + ret.y = tmp.y; + return ret; +} + +-(void)updateColor +{ + GLubyte op = sprite_.opacity; + ccColor3B c3b = sprite_.color; + + ccColor4B color = { c3b.r, c3b.g, c3b.b, op }; + if([sprite_.texture hasPremultipliedAlpha]){ + color.r *= op/255; + color.g *= op/255; + color.b *= op/255; + } + + if(vertexData_){ + for (int i=0; i < vertexDataCount_; ++i) { + vertexData_[i].colors = color; + } + } +} + +-(void)updateProgress +{ + switch (type_) { + case kCCProgressTimerTypeRadialCW: + case kCCProgressTimerTypeRadialCCW: + [self updateRadial]; + break; + case kCCProgressTimerTypeHorizontalBarLR: + case kCCProgressTimerTypeHorizontalBarRL: + case kCCProgressTimerTypeVerticalBarBT: + case kCCProgressTimerTypeVerticalBarTB: + [self updateBar]; + break; + default: + break; + } +} + +/// +// Update does the work of mapping the texture onto the triangles +// It now doesn't occur the cost of free/alloc data every update cycle. +// It also only changes the percentage point but no other points if they have not +// been modified. +// +// It now deals with flipped texture. If you run into this problem, just use the +// sprite property and enable the methods flipX, flipY. +/// +-(void)updateRadial +{ + // Texture Max is the actual max coordinates to deal with non-power of 2 textures + CGPoint tMax = ccp(sprite_.texture.maxS,sprite_.texture.maxT); + + // Grab the midpoint + CGPoint midpoint = ccpCompMult(self.anchorPoint, tMax); + + float alpha = percentage_ / 100.f; + + // Otherwise we can get the angle from the alpha + float angle = 2.f*((float)M_PI) * ( type_ == kCCProgressTimerTypeRadialCW? alpha : 1.f - alpha); + + // We find the vector to do a hit detection based on the percentage + // We know the first vector is the one @ 12 o'clock (top,mid) so we rotate + // from that by the progress angle around the midpoint pivot + CGPoint topMid = ccp(midpoint.x, 0.f); + CGPoint percentagePt = ccpRotateByAngle(topMid, midpoint, angle); + + + int index = 0; + CGPoint hit = CGPointZero; + + if (alpha == 0.f) { + // More efficient since we don't always need to check intersection + // If the alpha is zero then the hit point is top mid and the index is 0. + hit = topMid; + index = 0; + } else if (alpha == 1.f) { + // More efficient since we don't always need to check intersection + // If the alpha is one then the hit point is top mid and the index is 4. + hit = topMid; + index = 4; + } else { + // We run a for loop checking the edges of the texture to find the + // intersection point + // We loop through five points since the top is split in half + + float min_t = FLT_MAX; + + for (int i = 0; i <= kProgressTextureCoordsCount; ++i) { + int pIndex = (i + (kProgressTextureCoordsCount - 1))%kProgressTextureCoordsCount; + + CGPoint edgePtA = ccpCompMult([self boundaryTexCoord:i % kProgressTextureCoordsCount],tMax); + CGPoint edgePtB = ccpCompMult([self boundaryTexCoord:pIndex],tMax); + + // Remember that the top edge is split in half for the 12 o'clock position + // Let's deal with that here by finding the correct endpoints + if(i == 0){ + edgePtB = ccpLerp(edgePtA,edgePtB,.5f); + } else if(i == 4){ + edgePtA = ccpLerp(edgePtA,edgePtB,.5f); + } + + // s and t are returned by ccpLineIntersect + float s = 0, t = 0; + if(ccpLineIntersect(edgePtA, edgePtB, midpoint, percentagePt, &s, &t)) + { + + // Since our hit test is on rays we have to deal with the top edge + // being in split in half so we have to test as a segment + if ((i == 0 || i == 4)) { + // s represents the point between edgePtA--edgePtB + if (!(0.f <= s && s <= 1.f)) { + continue; + } + } + // As long as our t isn't negative we are at least finding a + // correct hitpoint from midpoint to percentagePt. + if (t >= 0.f) { + // Because the percentage line and all the texture edges are + // rays we should only account for the shortest intersection + if (t < min_t) { + min_t = t; + index = i; + } + } + } + } + + // Now that we have the minimum magnitude we can use that to find our intersection + hit = ccpAdd(midpoint, ccpMult(ccpSub(percentagePt, midpoint),min_t)); + + } + + + // The size of the vertex data is the index from the hitpoint + // the 3 is for the midpoint, 12 o'clock point and hitpoint position. + + BOOL sameIndexCount = YES; + if(vertexDataCount_ != index + 3){ + sameIndexCount = NO; + if(vertexData_){ + free(vertexData_); + vertexData_ = NULL; + vertexDataCount_ = 0; + } + } + + + if(!vertexData_) { + vertexDataCount_ = index + 3; + vertexData_ = malloc(vertexDataCount_ * sizeof(ccV2F_C4B_T2F)); + NSAssert( vertexData_, @"CCProgressTimer. Not enough memory"); + + [self updateColor]; + } + + if (!sameIndexCount) { + + // First we populate the array with the midpoint, then all + // vertices/texcoords/colors of the 12 'o clock start and edges and the hitpoint + vertexData_[0].texCoords = (ccTex2F){midpoint.x, midpoint.y}; + vertexData_[0].vertices = [self vertexFromTexCoord:midpoint]; + + vertexData_[1].texCoords = (ccTex2F){midpoint.x, 0.f}; + vertexData_[1].vertices = [self vertexFromTexCoord:ccp(midpoint.x, 0.f)]; + + for(int i = 0; i < index; ++i){ + CGPoint texCoords = ccpCompMult([self boundaryTexCoord:i], tMax); + + vertexData_[i+2].texCoords = (ccTex2F){texCoords.x, texCoords.y}; + vertexData_[i+2].vertices = [self vertexFromTexCoord:texCoords]; + } + + // Flip the texture coordinates if set + if (sprite_.flipY || sprite_.flipX) { + for(int i = 0; i < vertexDataCount_ - 1; ++i){ + if (sprite_.flipX) { + vertexData_[i].texCoords.u = tMax.x - vertexData_[i].texCoords.u; + } + if(sprite_.flipY){ + vertexData_[i].texCoords.v = tMax.y - vertexData_[i].texCoords.v; + } + } + } + } + + // hitpoint will go last + vertexData_[vertexDataCount_ - 1].texCoords = (ccTex2F){hit.x, hit.y}; + vertexData_[vertexDataCount_ - 1].vertices = [self vertexFromTexCoord:hit]; + + if (sprite_.flipY || sprite_.flipX) { + if (sprite_.flipX) { + vertexData_[vertexDataCount_ - 1].texCoords.u = tMax.x - vertexData_[vertexDataCount_ - 1].texCoords.u; + } + if(sprite_.flipY){ + vertexData_[vertexDataCount_ - 1].texCoords.v = tMax.y - vertexData_[vertexDataCount_ - 1].texCoords.v; + } + } +} + +/// +// Update does the work of mapping the texture onto the triangles for the bar +// It now doesn't occur the cost of free/alloc data every update cycle. +// It also only changes the percentage point but no other points if they have not +// been modified. +// +// It now deals with flipped texture. If you run into this problem, just use the +// sprite property and enable the methods flipX, flipY. +/// +-(void)updateBar +{ + + float alpha = percentage_ / 100.f; + + CGPoint tMax = ccp(sprite_.texture.maxS,sprite_.texture.maxT); + + unsigned char vIndexes[2] = {0,0}; + unsigned char index = 0; + + // We know vertex data is always equal to the 4 corners + // If we don't have vertex data then we create it here and populate + // the side of the bar vertices that won't ever change. + if (!vertexData_) { + vertexDataCount_ = kProgressTextureCoordsCount; + vertexData_ = malloc(vertexDataCount_ * sizeof(ccV2F_C4B_T2F)); + NSAssert( vertexData_, @"CCProgressTimer. Not enough memory"); + + if(type_ == kCCProgressTimerTypeHorizontalBarLR){ + vertexData_[vIndexes[0] = 0].texCoords = (ccTex2F){0,0}; + vertexData_[vIndexes[1] = 1].texCoords = (ccTex2F){0, tMax.y}; + }else if (type_ == kCCProgressTimerTypeHorizontalBarRL) { + vertexData_[vIndexes[0] = 2].texCoords = (ccTex2F){tMax.x, tMax.y}; + vertexData_[vIndexes[1] = 3].texCoords = (ccTex2F){tMax.x, 0.f}; + }else if (type_ == kCCProgressTimerTypeVerticalBarBT) { + vertexData_[vIndexes[0] = 1].texCoords = (ccTex2F){0, tMax.y}; + vertexData_[vIndexes[1] = 3].texCoords = (ccTex2F){tMax.x, tMax.y}; + }else if (type_ == kCCProgressTimerTypeVerticalBarTB) { + vertexData_[vIndexes[0] = 0].texCoords = (ccTex2F){0, 0}; + vertexData_[vIndexes[1] = 2].texCoords = (ccTex2F){tMax.x, 0}; + } + + index = vIndexes[0]; + vertexData_[index].vertices = [self vertexFromTexCoord:ccp(vertexData_[index].texCoords.u, vertexData_[index].texCoords.v)]; + + index = vIndexes[1]; + vertexData_[index].vertices = [self vertexFromTexCoord:ccp(vertexData_[index].texCoords.u, vertexData_[index].texCoords.v)]; + + if (sprite_.flipY || sprite_.flipX) { + if (sprite_.flipX) { + index = vIndexes[0]; + vertexData_[index].texCoords.u = tMax.x - vertexData_[index].texCoords.u; + index = vIndexes[1]; + vertexData_[index].texCoords.u = tMax.x - vertexData_[index].texCoords.u; + } + if(sprite_.flipY){ + index = vIndexes[0]; + vertexData_[index].texCoords.v = tMax.y - vertexData_[index].texCoords.v; + index = vIndexes[1]; + vertexData_[index].texCoords.v = tMax.y - vertexData_[index].texCoords.v; + } + } + + [self updateColor]; + } + + if(type_ == kCCProgressTimerTypeHorizontalBarLR){ + vertexData_[vIndexes[0] = 3].texCoords = (ccTex2F){tMax.x*alpha, tMax.y}; + vertexData_[vIndexes[1] = 2].texCoords = (ccTex2F){tMax.x*alpha, 0}; + }else if (type_ == kCCProgressTimerTypeHorizontalBarRL) { + vertexData_[vIndexes[0] = 1].texCoords = (ccTex2F){tMax.x*(1.f - alpha), 0}; + vertexData_[vIndexes[1] = 0].texCoords = (ccTex2F){tMax.x*(1.f - alpha), tMax.y}; + }else if (type_ == kCCProgressTimerTypeVerticalBarBT) { + vertexData_[vIndexes[0] = 0].texCoords = (ccTex2F){0, tMax.y*(1.f - alpha)}; + vertexData_[vIndexes[1] = 2].texCoords = (ccTex2F){tMax.x, tMax.y*(1.f - alpha)}; + }else if (type_ == kCCProgressTimerTypeVerticalBarTB) { + vertexData_[vIndexes[0] = 1].texCoords = (ccTex2F){0, tMax.y*alpha}; + vertexData_[vIndexes[1] = 3].texCoords = (ccTex2F){tMax.x, tMax.y*alpha}; + } + + index = vIndexes[0]; + vertexData_[index].vertices = [self vertexFromTexCoord:ccp(vertexData_[index].texCoords.u, vertexData_[index].texCoords.v)]; + index = vIndexes[1]; + vertexData_[index].vertices = [self vertexFromTexCoord:ccp(vertexData_[index].texCoords.u, vertexData_[index].texCoords.v)]; + + if (sprite_.flipY || sprite_.flipX) { + if (sprite_.flipX) { + index = vIndexes[0]; + vertexData_[index].texCoords.u = tMax.x - vertexData_[index].texCoords.u; + index = vIndexes[1]; + vertexData_[index].texCoords.u = tMax.x - vertexData_[index].texCoords.u; + } + if(sprite_.flipY){ + index = vIndexes[0]; + vertexData_[index].texCoords.v = tMax.y - vertexData_[index].texCoords.v; + index = vIndexes[1]; + vertexData_[index].texCoords.v = tMax.y - vertexData_[index].texCoords.v; + } + } + +} + +-(CGPoint)boundaryTexCoord:(char)index +{ + if (index < kProgressTextureCoordsCount) { + switch (type_) { + case kCCProgressTimerTypeRadialCW: + return ccp((kProgressTextureCoords>>((index<<1)+1))&1,(kProgressTextureCoords>>(index<<1))&1); + case kCCProgressTimerTypeRadialCCW: + return ccp((kProgressTextureCoords>>(7-(index<<1)))&1,(kProgressTextureCoords>>(7-((index<<1)+1)))&1); + default: + break; + } + } + return CGPointZero; +} + +-(void)draw +{ + [super draw]; + + if(!vertexData_)return; + if(!sprite_)return; + ccBlendFunc blendFunc = sprite_.blendFunc; + BOOL newBlend = blendFunc.src != CC_BLEND_SRC || blendFunc.dst != CC_BLEND_DST; + if( newBlend ) + glBlendFunc( blendFunc.src, blendFunc.dst ); + + /// ======================================================================== + // Replaced [texture_ drawAtPoint:CGPointZero] with my own vertexData + // Everything above me and below me is copied from CCTextureNode's draw + glBindTexture(GL_TEXTURE_2D, sprite_.texture.name); + glVertexPointer(2, GL_FLOAT, sizeof(ccV2F_C4B_T2F), &vertexData_[0].vertices); + glTexCoordPointer(2, GL_FLOAT, sizeof(ccV2F_C4B_T2F), &vertexData_[0].texCoords); + glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(ccV2F_C4B_T2F), &vertexData_[0].colors); + if(type_ == kCCProgressTimerTypeRadialCCW || type_ == kCCProgressTimerTypeRadialCW){ + glDrawArrays(GL_TRIANGLE_FAN, 0, vertexDataCount_); + } else if (type_ == kCCProgressTimerTypeHorizontalBarLR || + type_ == kCCProgressTimerTypeHorizontalBarRL || + type_ == kCCProgressTimerTypeVerticalBarBT || + type_ == kCCProgressTimerTypeVerticalBarTB) { + glDrawArrays(GL_TRIANGLE_STRIP, 0, vertexDataCount_); + } + //glDrawElements(GL_TRIANGLES, indicesCount_, GL_UNSIGNED_BYTE, indices_); + /// ======================================================================== + + if( newBlend ) + glBlendFunc(CC_BLEND_SRC, CC_BLEND_DST); +} + +@end diff --git a/tweejump/libs/cocos2d/CCProtocols.h b/tweejump/libs/cocos2d/CCProtocols.h new file mode 100755 index 0000000..f7043fc --- /dev/null +++ b/tweejump/libs/cocos2d/CCProtocols.h @@ -0,0 +1,125 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-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. + */ + + +#import "ccTypes.h" +#import "CCTexture2D.h" + +#pragma mark - +#pragma mark CCRGBAProtocol + +/// CC RGBA protocol +@protocol CCRGBAProtocol +/** sets Color + @since v0.8 + */ +-(void) setColor:(ccColor3B)color; +/** returns the color + @since v0.8 + */ +-(ccColor3B) color; + +/// returns the opacity +-(GLubyte) opacity; +/** sets the opacity. + @warning If the the texture has premultiplied alpha then, the R, G and B channels will be modifed. + Values goes from 0 to 255, where 255 means fully opaque. + */ +-(void) setOpacity: (GLubyte) opacity; +@optional +/** sets the premultipliedAlphaOpacity property. + If set to NO then opacity will be applied as: glColor(R,G,B,opacity); + If set to YES then oapcity will be applied as: glColor(opacity, opacity, opacity, opacity ); + Textures with premultiplied alpha will have this property by default on YES. Otherwise the default value is NO + @since v0.8 + */ +-(void) setOpacityModifyRGB:(BOOL)boolean; +/** returns whether or not the opacity will be applied using glColor(R,G,B,opacity) or glColor(opacity, opacity, opacity, opacity); + @since v0.8 + */ + -(BOOL) doesOpacityModifyRGB; +@end + +#pragma mark - +#pragma mark CCBlendProtocol +/** + You can specify the blending fuction. + @since v0.99.0 + */ +@protocol CCBlendProtocol +/** set the source blending function for the texture */ +-(void) setBlendFunc:(ccBlendFunc)blendFunc; +/** returns the blending function used for the texture */ +-(ccBlendFunc) blendFunc; +@end + + +#pragma mark - +#pragma mark CCTextureProtocol + +/** CCNode objects that uses a Texture2D to render the images. + The texture can have a blending function. + If the texture has alpha premultiplied the default blending function is: + src=GL_ONE dst= GL_ONE_MINUS_SRC_ALPHA + else + src=GL_SRC_ALPHA dst= GL_ONE_MINUS_SRC_ALPHA + But you can change the blending funtion at any time. + @since v0.8.0 + */ +@protocol CCTextureProtocol +/** returns the used texture */ +-(CCTexture2D*) texture; +/** sets a new texture. it will be retained */ +-(void) setTexture:(CCTexture2D*)texture; +@end + +#pragma mark - +#pragma mark CCLabelProtocol +/** Common interface for Labels */ +@protocol CCLabelProtocol +/** sets a new label using an NSString. + The string will be copied. + */ +-(void) setString:(NSString*)label; +/** returns the string that is rendered */ +-(NSString*) string; +@optional +/** sets a new label using a CString. + It is faster than setString since it doesn't require to alloc/retain/release an NString object. + @since v0.99.0 + */ +-(void) setCString:(char*)label; +@end + + +#pragma mark - +#pragma mark CCProjectionProtocol +/** OpenGL projection protocol */ +@protocol CCProjectionProtocol +/** Called by CCDirector when the porjection is updated, and "custom" projection is used + @since v0.99.5 + */ +-(void) updateProjection; +@end diff --git a/tweejump/libs/cocos2d/CCRenderTexture.h b/tweejump/libs/cocos2d/CCRenderTexture.h new file mode 100755 index 0000000..d5e39cc --- /dev/null +++ b/tweejump/libs/cocos2d/CCRenderTexture.h @@ -0,0 +1,108 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2009 Jason Booth + * + * 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. + * + */ + +#import +#import "CCNode.h" +#import "CCSprite.h" +#import "Support/OpenGL_Internal.h" + +#import +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED +#import +#endif // iPHone + +enum +{ + kCCImageFormatJPG = 0, + kCCImageFormatPNG = 1, + kCCImageFormatRawData =2 +}; + + +/** + CCRenderTexture is a generic rendering target. To render things into it, + simply construct a render target, call begin on it, call visit on any cocos + scenes or objects to render them, and call end. For convienience, render texture + adds a sprite as it's display child with the results, so you can simply add + the render texture to your scene and treat it like any other CocosNode. + There are also functions for saving the render texture to disk in PNG or JPG format. + + @since v0.8.1 + */ +@interface CCRenderTexture : CCNode +{ + GLuint fbo_; + GLint oldFBO_; + CCTexture2D* texture_; + CCSprite* sprite_; + + GLenum pixelFormat_; +} + +/** The CCSprite being used. + The sprite, by default, will use the following blending function: GL_ONE, GL_ONE_MINUS_SRC_ALPHA. + The blending function can be changed in runtime by calling: + - [[renderTexture sprite] setBlendFunc:(ccBlendFunc){GL_ONE, GL_ONE_MINUS_SRC_ALPHA}]; +*/ +@property (nonatomic,readwrite, assign) CCSprite* sprite; + +/** creates a RenderTexture object with width and height in Points and a pixel format, only RGB and RGBA formats are valid */ ++(id)renderTextureWithWidth:(int)w height:(int)h pixelFormat:(CCTexture2DPixelFormat) format; + +/** creates a RenderTexture object with width and height in Points, pixel format is RGBA8888 */ ++(id)renderTextureWithWidth:(int)w height:(int)h; + +/** initializes a RenderTexture object with width and height in Points and a pixel format, only RGB and RGBA formats are valid */ +-(id)initWithWidth:(int)w height:(int)h pixelFormat:(CCTexture2DPixelFormat) format; + +/** starts grabbing */ +-(void)begin; + +/** starts rendering to the texture while clearing the texture first. + This is more efficient then calling -clear first and then -begin */ +-(void)beginWithClear:(float)r g:(float)g b:(float)b a:(float)a; + +/** ends grabbing */ +-(void)end; + +/** clears the texture with a color */ +-(void)clear:(float)r g:(float)g b:(float)b a:(float)a; + +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED + +/** saves the texture into a file */ +-(BOOL)saveBuffer:(NSString*)name; +/** saves the texture into a file. The format can be JPG or PNG */ +-(BOOL)saveBuffer:(NSString*)name format:(int)format; +/* get buffer as UIImage, can only save a render buffer which has a RGBA8888 pixel format */ +-(NSData*)getUIImageAsDataFromBuffer:(int) format; +/* get buffer as UIImage */ +-(UIImage *)getUIImageFromBuffer; + +#endif // __IPHONE_OS_VERSION_MAX_ALLOWED + +@end + + diff --git a/tweejump/libs/cocos2d/CCRenderTexture.m b/tweejump/libs/cocos2d/CCRenderTexture.m new file mode 100755 index 0000000..4a4768e --- /dev/null +++ b/tweejump/libs/cocos2d/CCRenderTexture.m @@ -0,0 +1,340 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2009 Jason Booth + * + * 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. + * + */ + +#import +#import "CCRenderTexture.h" +#import "CCDirector.h" +#import "ccMacros.h" +#import "Support/ccUtils.h" +#import "Support/CCFileUtils.h" + +@implementation CCRenderTexture + +@synthesize sprite=sprite_; + +// issue #994 ++(id)renderTextureWithWidth:(int)w height:(int)h pixelFormat:(CCTexture2DPixelFormat) format +{ + return [[[self alloc] initWithWidth:w height:h pixelFormat:format] autorelease]; +} + ++(id)renderTextureWithWidth:(int)w height:(int)h +{ + return [[[self alloc] initWithWidth:w height:h pixelFormat:kCCTexture2DPixelFormat_RGBA8888] autorelease]; +} + +-(id)initWithWidth:(int)w height:(int)h +{ + return [self initWithWidth:w height:h pixelFormat:kCCTexture2DPixelFormat_RGBA8888]; +} + +-(id)initWithWidth:(int)w height:(int)h pixelFormat:(CCTexture2DPixelFormat) format +{ + if ((self = [super init])) + { + NSAssert(format != kCCTexture2DPixelFormat_A8,@"only RGB and RGBA formats are valid for a render texture"); + + w *= CC_CONTENT_SCALE_FACTOR(); + h *= CC_CONTENT_SCALE_FACTOR(); + + glGetIntegerv(CC_GL_FRAMEBUFFER_BINDING, &oldFBO_); + + // textures must be power of two + NSUInteger powW = ccNextPOT(w); + NSUInteger powH = ccNextPOT(h); + + void *data = malloc((int)(powW * powH * 4)); + memset(data, 0, (int)(powW * powH * 4)); + pixelFormat_=format; + + texture_ = [[CCTexture2D alloc] initWithData:data pixelFormat:pixelFormat_ pixelsWide:powW pixelsHigh:powH contentSize:CGSizeMake(w, h)]; + free( data ); + + // generate FBO + ccglGenFramebuffers(1, &fbo_); + ccglBindFramebuffer(CC_GL_FRAMEBUFFER, fbo_); + + // associate texture with FBO + ccglFramebufferTexture2D(CC_GL_FRAMEBUFFER, CC_GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture_.name, 0); + + // check if it worked (probably worth doing :) ) + GLuint status = ccglCheckFramebufferStatus(CC_GL_FRAMEBUFFER); + if (status != CC_GL_FRAMEBUFFER_COMPLETE) + { + [NSException raise:@"Render Texture" format:@"Could not attach texture to framebuffer"]; + } + [texture_ setAliasTexParameters]; + + sprite_ = [CCSprite spriteWithTexture:texture_]; + + [texture_ release]; + [sprite_ setScaleY:-1]; + [self addChild:sprite_]; + + // issue #937 + [sprite_ setBlendFunc:(ccBlendFunc){GL_ONE, GL_ONE_MINUS_SRC_ALPHA}]; + + ccglBindFramebuffer(CC_GL_FRAMEBUFFER, oldFBO_); + } + return self; +} + +-(void)dealloc +{ +// [self removeAllChildrenWithCleanup:YES]; + ccglDeleteFramebuffers(1, &fbo_); + [super dealloc]; +} + +-(void)begin +{ + // Save the current matrix + glPushMatrix(); + + CGSize texSize = [texture_ contentSizeInPixels]; + + + // Calculate the adjustment ratios based on the old and new projections + CGSize size = [[CCDirector sharedDirector] displaySizeInPixels]; + float widthRatio = size.width / texSize.width; + float heightRatio = size.height / texSize.height; + + + // Adjust the orthographic propjection and viewport + ccglOrtho((float)-1.0 / widthRatio, (float)1.0 / widthRatio, (float)-1.0 / heightRatio, (float)1.0 / heightRatio, -1,1); + glViewport(0, 0, texSize.width, texSize.height); + + + glGetIntegerv(CC_GL_FRAMEBUFFER_BINDING, &oldFBO_); + ccglBindFramebuffer(CC_GL_FRAMEBUFFER, fbo_);//Will direct drawing to the frame buffer created above + + // Issue #1145 + // There is no need to enable the default GL states here + // but since CCRenderTexture is mostly used outside the "render" loop + // these states needs to be enabled. + // Since this bug was discovered in API-freeze (very close of 1.0 release) + // This bug won't be fixed to prevent incompatibilities with code. + // + // If you understand the above mentioned message, then you can comment the following line + // and enable the gl states manually, in case you need them. + CC_ENABLE_DEFAULT_GL_STATES(); +} + +-(void)beginWithClear:(float)r g:(float)g b:(float)b a:(float)a +{ + [self begin]; + + // save clear color + GLfloat clearColor[4]; + glGetFloatv(GL_COLOR_CLEAR_VALUE,clearColor); + + glClearColor(r, g, b, a); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + // restore clear color + glClearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]); +} + +-(void)end +{ + ccglBindFramebuffer(CC_GL_FRAMEBUFFER, oldFBO_); + // Restore the original matrix and viewport + glPopMatrix(); + CGSize size = [[CCDirector sharedDirector] displaySizeInPixels]; + glViewport(0, 0, size.width, size.height); +} + +-(void)clear:(float)r g:(float)g b:(float)b a:(float)a +{ + [self beginWithClear:r g:g b:b a:a]; + [self end]; +} + +#pragma mark RenderTexture - Save Image + +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED +-(BOOL)saveBuffer:(NSString*)name +{ + return [self saveBuffer:name format:kCCImageFormatJPG]; +} + +-(BOOL)saveBuffer:(NSString*)fileName format:(int)format +{ + NSString *fullPath = [CCFileUtils fullPathFromRelativePath:fileName]; + + NSData *data = [self getUIImageAsDataFromBuffer:format]; + + return [data writeToFile:fullPath atomically:YES]; +} + +/* get buffer as UIImage */ +-(UIImage *)getUIImageFromBuffer +{ + NSAssert(pixelFormat_ == kCCTexture2DPixelFormat_RGBA8888,@"only RGBA8888 can be saved as image"); + + CGSize s = [texture_ contentSizeInPixels]; + int tx = s.width; + int ty = s.height; + + int bitsPerComponent = 8; + int bitsPerPixel = 32; + int bytesPerPixel = (bitsPerComponent * 4)/8; + int bytesPerRow = bytesPerPixel * tx; + NSInteger myDataLength = bytesPerRow * ty; + + NSMutableData *buffer = [[NSMutableData alloc] initWithCapacity:myDataLength]; + NSMutableData *pixels = [[NSMutableData alloc] initWithCapacity:myDataLength]; + + if( ! (buffer && pixels) ) { + CCLOG(@"cocos2d: CCRenderTexture#getUIImageFromBuffer: not enough memory"); + [buffer release]; + [pixels release]; + return nil; + } + + [self begin]; + glReadPixels(0,0,tx,ty,GL_RGBA,GL_UNSIGNED_BYTE, [buffer mutableBytes]); + [self end]; + + // make data provider with data. + + CGBitmapInfo bitmapInfo = kCGImageAlphaPremultipliedLast | kCGBitmapByteOrderDefault; + CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, [buffer mutableBytes], myDataLength, NULL); + CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB(); + CGImageRef iref = CGImageCreate(tx, ty, + bitsPerComponent, bitsPerPixel, bytesPerRow, + colorSpaceRef, bitmapInfo, provider, + NULL, false, + kCGRenderingIntentDefault); + + CGContextRef context = CGBitmapContextCreate([pixels mutableBytes], tx, + ty, CGImageGetBitsPerComponent(iref), + CGImageGetBytesPerRow(iref), CGImageGetColorSpace(iref), + bitmapInfo); + CGContextTranslateCTM(context, 0.0f, ty); + CGContextScaleCTM(context, 1.0f, -1.0f); + CGContextDrawImage(context, CGRectMake(0.0f, 0.0f, tx, ty), iref); + CGImageRef outputRef = CGBitmapContextCreateImage(context); + UIImage* image = [[UIImage alloc] initWithCGImage:outputRef]; + + CGImageRelease(iref); + CGContextRelease(context); + CGColorSpaceRelease(colorSpaceRef); + CGDataProviderRelease(provider); + CGImageRelease(outputRef); + + [pixels release]; + [buffer release]; + + return [image autorelease]; +} + +-(NSData*)getUIImageAsDataFromBuffer:(int) format +{ + NSAssert(pixelFormat_ == kCCTexture2DPixelFormat_RGBA8888,@"only RGBA8888 can be saved as image"); + + CGSize s = [texture_ contentSizeInPixels]; + int tx = s.width; + int ty = s.height; + + int bitsPerComponent=8; + int bitsPerPixel=32; + + int bytesPerRow = (bitsPerPixel/8) * tx; + NSInteger myDataLength = bytesPerRow * ty; + + GLubyte *buffer = malloc(sizeof(GLubyte)*myDataLength); + GLubyte *pixels = malloc(sizeof(GLubyte)*myDataLength); + + if( ! (buffer && pixels) ) { + CCLOG(@"cocos2d: CCRenderTexture#getUIImageFromBuffer: not enough memory"); + free(buffer); + free(pixels); + return nil; + } + + [self begin]; + glReadPixels(0,0,tx,ty,GL_RGBA,GL_UNSIGNED_BYTE, buffer); + [self end]; + + int x,y; + + for(y = 0; y +{ + NSMutableArray* segments_; + NSMutableArray* deletedSegments_; + + CGPoint lastPoint1_; + CGPoint lastPoint2_; + CGPoint lastLocation_; + int vertCount_; + float texVPos_; + float curTime_; + float fadeTime_; + float delta_; + float lastWidth_; + float lastSign_; + BOOL pastFirstPoint_; + + // Texture used + CCTexture2D* texture_; + + // texture length + float textureLength_; + + // RGBA protocol + ccColor4B color_; + + // blend func + ccBlendFunc blendFunc_; +} + +/** Texture used by the ribbon. Conforms to CCTextureProtocol protocol */ +@property (nonatomic,readwrite,retain) CCTexture2D* texture; + +/** Texture lengths in pixels */ +@property (nonatomic,readwrite) float textureLength; + +/** GL blendind function */ +@property (nonatomic,readwrite,assign) ccBlendFunc blendFunc; + +/** color used by the Ribbon (RGBA) */ +@property (nonatomic,readwrite) ccColor4B color; + +/** creates the ribbon */ ++(id)ribbonWithWidth:(float)w image:(NSString*)path length:(float)l color:(ccColor4B)color fade:(float)fade; +/** init the ribbon */ +-(id)initWithWidth:(float)w image:(NSString*)path length:(float)l color:(ccColor4B)color fade:(float)fade; +/** add a point to the ribbon */ +-(void)addPointAt:(CGPoint)location width:(float)w; +/** polling function */ +-(void)update:(ccTime)delta; +/** determine side of line */ +-(float)sideOfLine:(CGPoint)p l1:(CGPoint)l1 l2:(CGPoint)l2; + +@end + +/** object to hold ribbon segment data */ +@interface CCRibbonSegment : NSObject +{ +@public + GLfloat verts[50*6]; + GLfloat coords[50*4]; + GLubyte colors[50*8]; + float creationTime[50]; + BOOL finished; + NSUInteger end; + NSUInteger begin; +} +-(id)init; +-(void)reset; +-(void)draw:(float)curTime fadeTime:(float)fadeTime color:(ccColor4B)color; +@end diff --git a/tweejump/libs/cocos2d/CCRibbon.m b/tweejump/libs/cocos2d/CCRibbon.m new file mode 100755 index 0000000..1e0d10a --- /dev/null +++ b/tweejump/libs/cocos2d/CCRibbon.m @@ -0,0 +1,383 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008, 2009 Jason Booth + * + * 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. + */ + +/* + * A ribbon is a dynamically generated list of polygons drawn as a single or series + * of triangle strips. The primary use of Ribbon is as the drawing class of Motion Streak, + * but it is quite useful on it's own. When manually drawing a ribbon, you can call addPointAt + * and pass in the parameters for the next location in the ribbon. The system will automatically + * generate new polygons, texture them accourding to your texture width, etc, etc. + * + * Ribbon data is stored in a RibbonSegment class. This class statically allocates enough verticies and + * texture coordinates for 50 locations (100 verts or 48 triangles). The ribbon class will allocate + * new segments when they are needed, and reuse old ones if available. The idea is to avoid constantly + * allocating new memory and prefer a more static method. However, since there is no way to determine + * the maximum size of some ribbons (motion streaks), a truely static allocation is not possible. + * + */ + + +#import "CCRibbon.h" +#import "CCTextureCache.h" +#import "Support/CGPointExtension.h" +#import "ccMacros.h" + +// +// Ribbon +// +@implementation CCRibbon +@synthesize blendFunc=blendFunc_; +@synthesize color=color_; +@synthesize textureLength = textureLength_; + ++(id)ribbonWithWidth:(float)w image:(NSString*)path length:(float)l color:(ccColor4B)color fade:(float)fade +{ + self = [[[self alloc] initWithWidth:w image:path length:l color:color fade:fade] autorelease]; + return self; +} + +-(id)initWithWidth:(float)w image:(NSString*)path length:(float)l color:(ccColor4B)color fade:(float)fade +{ + self = [super init]; + if (self) + { + + segments_ = [[NSMutableArray alloc] init]; + deletedSegments_ = [[NSMutableArray alloc] init]; + + /* 1 initial segment */ + CCRibbonSegment* seg = [[CCRibbonSegment alloc] init]; + [segments_ addObject:seg]; + [seg release]; + + textureLength_ = l; + + color_ = color; + fadeTime_ = fade; + lastLocation_ = CGPointZero; + lastWidth_ = w/2; + texVPos_ = 0.0f; + + curTime_ = 0; + pastFirstPoint_ = NO; + + /* XXX: + Ribbon, by default uses this blend function, which might not be correct + if you are using premultiplied alpha images, + but 99% you might want to use this blending function regarding of the texture + */ + blendFunc_.src = GL_SRC_ALPHA; + blendFunc_.dst = GL_ONE_MINUS_SRC_ALPHA; + + self.texture = [[CCTextureCache sharedTextureCache] addImage:path]; + + /* default texture parameter */ + ccTexParams params = { GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT }; + [texture_ setTexParameters:¶ms]; + } + return self; +} + +-(void)dealloc +{ + [segments_ release]; + [deletedSegments_ release]; + [texture_ release]; + [super dealloc]; +} + +// rotates a point around 0, 0 +-(CGPoint)rotatePoint:(CGPoint)vec rotation:(float)a +{ + float xtemp = (vec.x * cosf(a)) - (vec.y * sinf(a)); + vec.y = (vec.x * sinf(a)) + (vec.y * cosf(a)); + vec.x = xtemp; + return vec; +} + +-(void)update:(ccTime)delta +{ + curTime_+= delta; + delta_ = delta; +} + +-(float)sideOfLine:(CGPoint)p l1:(CGPoint)l1 l2:(CGPoint)l2 +{ + CGPoint vp = ccpPerp(ccpSub(l1, l2)); + CGPoint vx = ccpSub(p, l1); + return ccpDot(vx, vp); +} + +// adds a new segment to the ribbon +-(void)addPointAt:(CGPoint)location width:(float)w +{ + location.x *= CC_CONTENT_SCALE_FACTOR(); + location.y *= CC_CONTENT_SCALE_FACTOR(); + + w = w*0.5f; + // if this is the first point added, cache it and return + if (!pastFirstPoint_) + { + lastWidth_ = w; + lastLocation_ = location; + pastFirstPoint_ = YES; + return; + } + + CGPoint sub = ccpSub(lastLocation_, location); + float r = ccpToAngle(sub) + (float)M_PI_2; + CGPoint p1 = ccpAdd([self rotatePoint:ccp(-w, 0) rotation:r], location); + CGPoint p2 = ccpAdd([self rotatePoint:ccp(w, 0) rotation:r], location); + float len = sqrtf(powf(lastLocation_.x - location.x, 2) + powf(lastLocation_.y - location.y, 2)); + float tend = texVPos_ + len/textureLength_; + CCRibbonSegment* seg; + // grab last segment + seg = [segments_ lastObject]; + // lets kill old segments + for (CCRibbonSegment* seg2 in segments_) + { + if (seg2 != seg && seg2->finished) + { + [deletedSegments_ addObject:seg2]; + } + } + [segments_ removeObjectsInArray:deletedSegments_]; + // is the segment full? + if (seg->end >= 50) + [segments_ removeObjectsInArray:deletedSegments_]; + // grab last segment and append to it if it's not full + seg = [segments_ lastObject]; + // is the segment full? + if (seg->end >= 50) + { + CCRibbonSegment* newSeg; + // grab it from the cache if we can + if ([deletedSegments_ count] > 0) + { + newSeg = [deletedSegments_ objectAtIndex:0]; + [newSeg retain]; // will be released later + [deletedSegments_ removeObject:newSeg]; + [newSeg reset]; + } + else + { + newSeg = [[CCRibbonSegment alloc] init]; // will be released later + } + + newSeg->creationTime[0] = seg->creationTime[seg->end - 1]; + int v = (seg->end-1)*6; + int c = (seg->end-1)*4; + newSeg->verts[0] = seg->verts[v]; + newSeg->verts[1] = seg->verts[v+1]; + newSeg->verts[2] = seg->verts[v+2]; + newSeg->verts[3] = seg->verts[v+3]; + newSeg->verts[4] = seg->verts[v+4]; + newSeg->verts[5] = seg->verts[v+5]; + + newSeg->coords[0] = seg->coords[c]; + newSeg->coords[1] = seg->coords[c+1]; + newSeg->coords[2] = seg->coords[c+2]; + newSeg->coords[3] = seg->coords[c+3]; + newSeg->end++; + seg = newSeg; + [segments_ addObject:seg]; + [newSeg release]; // it was retained before + + } + if (seg->end == 0) + { + // first edge has to get rotation from the first real polygon + CGPoint lp1 = ccpAdd([self rotatePoint:ccp(-lastWidth_, 0) rotation:r], lastLocation_); + CGPoint lp2 = ccpAdd([self rotatePoint:ccp(+lastWidth_, 0) rotation:r], lastLocation_); + seg->creationTime[0] = curTime_ - delta_; + seg->verts[0] = lp1.x; + seg->verts[1] = lp1.y; + seg->verts[2] = 0.0f; + seg->verts[3] = lp2.x; + seg->verts[4] = lp2.y; + seg->verts[5] = 0.0f; + seg->coords[0] = 0.0f; + seg->coords[1] = texVPos_; + seg->coords[2] = 1.0f; + seg->coords[3] = texVPos_; + seg->end++; + } + + int v = seg->end*6; + int c = seg->end*4; + // add new vertex + seg->creationTime[seg->end] = curTime_; + seg->verts[v] = p1.x; + seg->verts[v+1] = p1.y; + seg->verts[v+2] = 0.0f; + seg->verts[v+3] = p2.x; + seg->verts[v+4] = p2.y; + seg->verts[v+5] = 0.0f; + + + seg->coords[c] = 0.0f; + seg->coords[c+1] = tend; + seg->coords[c+2] = 1.0f; + seg->coords[c+3] = tend; + + texVPos_ = tend; + lastLocation_ = location; + lastPoint1_ = p1; + lastPoint2_ = p2; + lastWidth_ = w; + seg->end++; +} + +-(void) draw +{ + [super draw]; + + if ([segments_ count] > 0) + { + // Default GL states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY + // Needed states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_TEXTURE_COORD_ARRAY + // Unneeded states: GL_COLOR_ARRAY + glDisableClientState(GL_COLOR_ARRAY); + + glBindTexture(GL_TEXTURE_2D, [texture_ name]); + + BOOL newBlend = blendFunc_.src != CC_BLEND_SRC || blendFunc_.dst != CC_BLEND_DST; + if( newBlend ) + glBlendFunc( blendFunc_.src, blendFunc_.dst ); + + for (CCRibbonSegment* seg in segments_) + [seg draw:curTime_ fadeTime:fadeTime_ color:color_]; + + if( newBlend ) + glBlendFunc(CC_BLEND_SRC, CC_BLEND_DST); + + // restore default GL state + glEnableClientState( GL_COLOR_ARRAY ); + } +} + +#pragma mark Ribbon - CocosNodeTexture protocol +-(void) setTexture:(CCTexture2D*) texture +{ + [texture_ release]; + texture_ = [texture retain]; + [self setContentSizeInPixels: texture.contentSizeInPixels]; + /* XXX Don't update blending function in Ribbons */ +} + +-(CCTexture2D*) texture +{ + return texture_; +} + +@end + + +#pragma mark - +#pragma mark RibbonSegment + +@implementation CCRibbonSegment + +-(id)init +{ + self = [super init]; + if (self) + { + [self reset]; + } + return self; +} + +- (NSString*) description +{ + return [NSString stringWithFormat:@"<%@ = %08X | end = %i, begin = %i>", [self class], self, end, begin]; +} + +- (void) dealloc +{ + CCLOGINFO(@"cocos2d: deallocing %@", self); + [super dealloc]; +} + +-(void)reset +{ + end = 0; + begin = 0; + finished = NO; +} + +-(void)draw:(float)curTime fadeTime:(float)fadeTime color:(ccColor4B)color +{ + GLubyte r = color.r; + GLubyte g = color.g; + GLubyte b = color.b; + GLubyte a = color.a; + + if (begin < 50) + { + // the motion streak class will call update and cause time to change, thus, if curTime_ != 0 + // we have to generate alpha for the ribbon each frame. + if (curTime == 0) + { + // no alpha over time, so just set the color + glColor4ub(r,g,b,a); + } + else + { + // generate alpha/color for each point + glEnableClientState(GL_COLOR_ARRAY); + NSUInteger i = begin; + for (; i < end; ++i) + { + int idx = i*8; + colors[idx] = r; + colors[idx+1] = g; + colors[idx+2] = b; + colors[idx+4] = r; + colors[idx+5] = g; + colors[idx+6] = b; + float alive = ((curTime - creationTime[i]) / fadeTime); + if (alive > 1) + { + begin++; + colors[idx+3] = 0; + colors[idx+7] = 0; + } + else + { + colors[idx+3] = (GLubyte)(255.f - (alive * 255.f)); + colors[idx+7] = colors[idx+3]; + } + } + glColorPointer(4, GL_UNSIGNED_BYTE, 0, &colors[begin*8]); + } + glVertexPointer(3, GL_FLOAT, 0, &verts[begin*6]); + glTexCoordPointer(2, GL_FLOAT, 0, &coords[begin*4]); + glDrawArrays(GL_TRIANGLE_STRIP, 0, (end - begin) * 2); + } + else + finished = YES; +} +@end + diff --git a/tweejump/libs/cocos2d/CCScene.h b/tweejump/libs/cocos2d/CCScene.h new file mode 100755 index 0000000..1d104bc --- /dev/null +++ b/tweejump/libs/cocos2d/CCScene.h @@ -0,0 +1,43 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-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. + * + */ + + +#import "CCNode.h" + +/** CCScene is a subclass of CCNode that is used only as an abstract concept. + + CCScene an CCNode are almost identical with the difference that CCScene has it's + anchor point (by default) at the center of the screen. + + For the moment CCScene has no other logic than that, but in future releases it might have + additional logic. + + It is a good practice to use and CCScene as the parent of all your nodes. +*/ +@interface CCScene : CCNode +{ +} +@end diff --git a/tweejump/libs/cocos2d/CCScene.m b/tweejump/libs/cocos2d/CCScene.m new file mode 100755 index 0000000..e991d6e --- /dev/null +++ b/tweejump/libs/cocos2d/CCScene.m @@ -0,0 +1,45 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-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. + * + */ + + +#import "CCScene.h" +#import "Support/CGPointExtension.h" +#import "CCDirector.h" + + +@implementation CCScene +-(id) init +{ + if( (self=[super init]) ) { + CGSize s = [[CCDirector sharedDirector] winSize]; + self.isRelativeAnchorPoint = NO; + anchorPoint_ = ccp(0.5f, 0.5f); + [self setContentSize:s]; + } + + return self; +} +@end diff --git a/tweejump/libs/cocos2d/CCScheduler.h b/tweejump/libs/cocos2d/CCScheduler.h new file mode 100755 index 0000000..122b8fe --- /dev/null +++ b/tweejump/libs/cocos2d/CCScheduler.h @@ -0,0 +1,199 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-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. + */ + + + +#import "Support/uthash.h" +#import "ccTypes.h" + +typedef void (*TICK_IMP)(id, SEL, ccTime); + +// +// CCTimer +// +/** Light weight timer */ +@interface CCTimer : NSObject +{ + id target; + TICK_IMP impMethod; + + ccTime elapsed; + +@public // optimization + ccTime interval; + SEL selector; +} + +/** interval in seconds */ +@property (nonatomic,readwrite,assign) ccTime interval; + +/** Allocates a timer with a target and a selector. +*/ ++(id) timerWithTarget:(id) t selector:(SEL)s; + +/** Allocates a timer with a target, a selector and an interval in seconds. +*/ ++(id) timerWithTarget:(id) t selector:(SEL)s interval:(ccTime)seconds; + +/** Initializes a timer with a target and a selector. +*/ + -(id) initWithTarget:(id) t selector:(SEL)s; + +/** Initializes a timer with a target, a selector and an interval in seconds. +*/ +-(id) initWithTarget:(id) t selector:(SEL)s interval:(ccTime)seconds; + + +/** triggers the timer */ +-(void) update: (ccTime) dt; +@end + + + +// +// CCScheduler +// +/** Scheduler is responsible of triggering the scheduled callbacks. + You should not use NSTimer. Instead use this class. + + There are 2 different types of callbacks (selectors): + + - update selector: the 'update' selector will be called every frame. You can customize the priority. + - custom selector: A custom selector will be called every frame, or with a custom interval of time + + The 'custom selectors' should be avoided when possible. It is faster, and consumes less memory to use the 'update selector'. + +*/ + +struct _listEntry; +struct _hashSelectorEntry; +struct _hashUpdateEntry; + +@interface CCScheduler : NSObject +{ + ccTime timeScale_; + + // + // "updates with priority" stuff + // + struct _listEntry *updatesNeg; // list of priority < 0 + struct _listEntry *updates0; // list priority == 0 + struct _listEntry *updatesPos; // list priority > 0 + struct _hashUpdateEntry *hashForUpdates; // hash used to fetch quickly the list entries for pause,delete,etc. + + // Used for "selectors with interval" + struct _hashSelectorEntry *hashForSelectors; + struct _hashSelectorEntry *currentTarget; + BOOL currentTargetSalvaged; + + // Optimization + TICK_IMP impMethod; + SEL updateSelector; + + BOOL updateHashLocked; // If true unschedule will not remove anything from a hash. Elements will only be marked for deletion. +} + +/** Modifies the time of all scheduled callbacks. + You can use this property to create a 'slow motion' or 'fast fordward' effect. + Default is 1.0. To create a 'slow motion' effect, use values below 1.0. + To create a 'fast fordward' effect, use values higher than 1.0. + @since v0.8 + @warning It will affect EVERY scheduled selector / action. + */ +@property (nonatomic,readwrite) ccTime timeScale; + +/** returns a shared instance of the Scheduler */ ++(CCScheduler *)sharedScheduler; + +/** purges the shared scheduler. It releases the retained instance. + @since v0.99.0 + */ ++(void)purgeSharedScheduler; + +/** 'tick' the scheduler. + You should NEVER call this method, unless you know what you are doing. + */ +-(void) tick:(ccTime)dt; + +/** The scheduled method will be called every 'interval' seconds. + If paused is YES, then it won't be called until it is resumed. + If 'interval' is 0, it will be called every frame, but if so, it recommened to use 'scheduleUpdateForTarget:' instead. + If the selector is already scheduled, then only the interval parameter will be updated without re-scheduling it again. + + @since v0.99.3 + */ +-(void) scheduleSelector:(SEL)selector forTarget:(id)target interval:(ccTime)interval paused:(BOOL)paused; + +/** Schedules the 'update' selector for a given target with a given priority. + The 'update' selector will be called every frame. + The lower the priority, the earlier it is called. + @since v0.99.3 + */ +-(void) scheduleUpdateForTarget:(id)target priority:(NSInteger)priority paused:(BOOL)paused; + +/** Unshedules a selector for a given target. + If you want to unschedule the "update", use unscheudleUpdateForTarget. + @since v0.99.3 + */ +-(void) unscheduleSelector:(SEL)selector forTarget:(id)target; + +/** Unschedules the update selector for a given target + @since v0.99.3 + */ +-(void) unscheduleUpdateForTarget:(id)target; + +/** Unschedules all selectors for a given target. + This also includes the "update" selector. + @since v0.99.3 + */ +-(void) unscheduleAllSelectorsForTarget:(id)target; + +/** Unschedules all selectors from all targets. + You should NEVER call this method, unless you know what you are doing. + + @since v0.99.3 + */ +-(void) unscheduleAllSelectors; + +/** Pauses the target. + All scheduled selectors/update for a given target won't be 'ticked' until the target is resumed. + If the target is not present, nothing happens. + @since v0.99.3 + */ +-(void) pauseTarget:(id)target; + +/** Resumes the target. + The 'target' will be unpaused, so all schedule selectors/update will be 'ticked' again. + If the target is not present, nothing happens. + @since v0.99.3 + */ +-(void) resumeTarget:(id)target; + +/** Returns whether or not the target is paused + @since v1.0.0 + */ +-(BOOL) isTargetPaused:(id)target; + +@end diff --git a/tweejump/libs/cocos2d/CCScheduler.m b/tweejump/libs/cocos2d/CCScheduler.m new file mode 100755 index 0000000..a14ca10 --- /dev/null +++ b/tweejump/libs/cocos2d/CCScheduler.m @@ -0,0 +1,657 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-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. + */ + + +// cocos2d imports +#import "CCScheduler.h" +#import "ccMacros.h" +#import "Support/uthash.h" +#import "Support/utlist.h" +#import "Support/ccCArray.h" + +// +// Data structures +// +#pragma mark - +#pragma mark Data Structures + +// A list double-linked list used for "updates with priority" +typedef struct _listEntry +{ + struct _listEntry *prev, *next; + TICK_IMP impMethod; + id target; // not retained (retained by hashUpdateEntry) + NSInteger priority; + BOOL paused; + BOOL markedForDeletion; // selector will no longer be called and entry will be removed at end of the next tick +} tListEntry; + +typedef struct _hashUpdateEntry +{ + tListEntry **list; // Which list does it belong to ? + tListEntry *entry; // entry in the list + id target; // hash key (retained) + UT_hash_handle hh; +} tHashUpdateEntry; + +// Hash Element used for "selectors with interval" +typedef struct _hashSelectorEntry +{ + struct ccArray *timers; + id target; // hash key (retained) + unsigned int timerIndex; + CCTimer *currentTimer; + BOOL currentTimerSalvaged; + BOOL paused; + UT_hash_handle hh; +} tHashSelectorEntry; + + + +// +// CCTimer +// +#pragma mark - +#pragma mark - CCTimer + +@implementation CCTimer + +@synthesize interval; + +-(id) init +{ + NSAssert(NO, @"CCTimer: Init not supported."); + [self release]; + return nil; +} + ++(id) timerWithTarget:(id)t selector:(SEL)s +{ + return [[[self alloc] initWithTarget:t selector:s] autorelease]; +} + ++(id) timerWithTarget:(id)t selector:(SEL)s interval:(ccTime) i +{ + return [[[self alloc] initWithTarget:t selector:s interval:i] autorelease]; +} + +-(id) initWithTarget:(id)t selector:(SEL)s +{ + return [self initWithTarget:t selector:s interval:0]; +} + +-(id) initWithTarget:(id)t selector:(SEL)s interval:(ccTime) seconds +{ + if( (self=[super init]) ) { +#if COCOS2D_DEBUG + NSMethodSignature *sig = [t methodSignatureForSelector:s]; + NSAssert(sig !=0 , @"Signature not found for selector - does it have the following form? -(void) name: (ccTime) dt"); +#endif + + // target is not retained. It is retained in the hash structure + target = t; + selector = s; + impMethod = (TICK_IMP) [t methodForSelector:s]; + elapsed = -1; + interval = seconds; + } + return self; +} + +- (NSString*) description +{ + return [NSString stringWithFormat:@"<%@ = %08X | target:%@ selector:(%@)>", [self class], self, [target class], NSStringFromSelector(selector)]; +} + +-(void) dealloc +{ + CCLOGINFO(@"cocos2d: deallocing %@", self); + [super dealloc]; +} + +-(void) update: (ccTime) dt +{ + if( elapsed == - 1) + elapsed = 0; + else + elapsed += dt; + if( elapsed >= interval ) { + impMethod(target, selector, elapsed); + elapsed = 0; + } +} +@end + +// +// CCScheduler +// +#pragma mark - +#pragma mark - CCScheduler + +@interface CCScheduler (Private) +-(void) removeHashElement:(tHashSelectorEntry*)element; +@end + +@implementation CCScheduler + +static CCScheduler *sharedScheduler; + +@synthesize timeScale = timeScale_; + ++ (CCScheduler *)sharedScheduler +{ + if (!sharedScheduler) + sharedScheduler = [[CCScheduler alloc] init]; + + return sharedScheduler; +} + ++(id)alloc +{ + NSAssert(sharedScheduler == nil, @"Attempted to allocate a second instance of a singleton."); + return [super alloc]; +} + ++(void)purgeSharedScheduler +{ + [sharedScheduler release]; + sharedScheduler = nil; +} + +- (id) init +{ + if( (self=[super init]) ) { + timeScale_ = 1.0f; + + // used to trigger CCTimer#update + updateSelector = @selector(update:); + impMethod = (TICK_IMP) [CCTimer instanceMethodForSelector:updateSelector]; + + // updates with priority + updates0 = NULL; + updatesNeg = NULL; + updatesPos = NULL; + hashForUpdates = NULL; + + // selectors with interval + currentTarget = nil; + currentTargetSalvaged = NO; + hashForSelectors = nil; + updateHashLocked = NO; + } + + return self; +} + +- (void) dealloc +{ + CCLOG(@"cocos2d: deallocing %@", self); + + [self unscheduleAllSelectors]; + + sharedScheduler = nil; + + [super dealloc]; +} + + +#pragma mark CCScheduler - Custom Selectors + +-(void) removeHashElement:(tHashSelectorEntry*)element +{ + ccArrayFree(element->timers); + [element->target release]; + HASH_DEL(hashForSelectors, element); + free(element); +} + +-(void) scheduleSelector:(SEL)selector forTarget:(id)target interval:(ccTime)interval paused:(BOOL)paused +{ + NSAssert( selector != nil, @"Argument selector must be non-nil"); + NSAssert( target != nil, @"Argument target must be non-nil"); + + tHashSelectorEntry *element = NULL; + HASH_FIND_INT(hashForSelectors, &target, element); + + if( ! element ) { + element = calloc( sizeof( *element ), 1 ); + element->target = [target retain]; + HASH_ADD_INT( hashForSelectors, target, element ); + + // Is this the 1st element ? Then set the pause level to all the selectors of this target + element->paused = paused; + + } else + NSAssert( element->paused == paused, @"CCScheduler. Trying to schedule a selector with a pause value different than the target"); + + + if( element->timers == nil ) + element->timers = ccArrayNew(10); + else + { + for( unsigned int i=0; i< element->timers->num; i++ ) { + CCTimer *timer = element->timers->arr[i]; + if( selector == timer->selector ) { + CCLOG(@"CCScheduler#scheduleSelector. Selector already scheduled. Updating interval from: %.2f to %.2f", timer->interval, interval); + timer->interval = interval; + return; + } + } + ccArrayEnsureExtraCapacity(element->timers, 1); + } + + CCTimer *timer = [[CCTimer alloc] initWithTarget:target selector:selector interval:interval]; + ccArrayAppendObject(element->timers, timer); + [timer release]; +} + +-(void) unscheduleSelector:(SEL)selector forTarget:(id)target +{ + // explicity handle nil arguments when removing an object + if( target==nil && selector==NULL) + return; + + NSAssert( target != nil, @"Target MUST not be nil"); + NSAssert( selector != NULL, @"Selector MUST not be NULL"); + + tHashSelectorEntry *element = NULL; + HASH_FIND_INT(hashForSelectors, &target, element); + + if( element ) { + + for( unsigned int i=0; i< element->timers->num; i++ ) { + CCTimer *timer = element->timers->arr[i]; + + + if( selector == timer->selector ) { + + if( timer == element->currentTimer && !element->currentTimerSalvaged ) { + [element->currentTimer retain]; + element->currentTimerSalvaged = YES; + } + + ccArrayRemoveObjectAtIndex(element->timers, i ); + + // update timerIndex in case we are in tick:, looping over the actions + if( element->timerIndex >= i ) + element->timerIndex--; + + if( element->timers->num == 0 ) { + if( currentTarget == element ) + currentTargetSalvaged = YES; + else + [self removeHashElement: element]; + } + return; + } + } + } + + // Not Found +// NSLog(@"CCScheduler#unscheduleSelector:forTarget: selector not found: %@", selString); + +} + +#pragma mark CCScheduler - Update Specific + +-(void) priorityIn:(tListEntry**)list target:(id)target priority:(NSInteger)priority paused:(BOOL)paused +{ + tListEntry *listElement = malloc( sizeof(*listElement) ); + + listElement->target = target; + listElement->priority = priority; + listElement->paused = paused; + listElement->impMethod = (TICK_IMP) [target methodForSelector:updateSelector]; + listElement->next = listElement->prev = NULL; + listElement->markedForDeletion = NO; + + // empty list ? + if( ! *list ) { + DL_APPEND( *list, listElement ); + + } else { + BOOL added = NO; + + for( tListEntry *elem = *list; elem ; elem = elem->next ) { + if( priority < elem->priority ) { + + if( elem == *list ) + DL_PREPEND(*list, listElement); + else { + listElement->next = elem; + listElement->prev = elem->prev; + + elem->prev->next = listElement; + elem->prev = listElement; + } + + added = YES; + break; + } + } + + // Not added? priority has the higher value. Append it. + if( !added ) + DL_APPEND(*list, listElement); + } + + // update hash entry for quicker access + tHashUpdateEntry *hashElement = calloc( sizeof(*hashElement), 1 ); + hashElement->target = [target retain]; + hashElement->list = list; + hashElement->entry = listElement; + HASH_ADD_INT(hashForUpdates, target, hashElement ); +} + +-(void) appendIn:(tListEntry**)list target:(id)target paused:(BOOL)paused +{ + tListEntry *listElement = malloc( sizeof( * listElement ) ); + + listElement->target = target; + listElement->paused = paused; + listElement->markedForDeletion = NO; + listElement->impMethod = (TICK_IMP) [target methodForSelector:updateSelector]; + + DL_APPEND(*list, listElement); + + + // update hash entry for quicker access + tHashUpdateEntry *hashElement = calloc( sizeof(*hashElement), 1 ); + hashElement->target = [target retain]; + hashElement->list = list; + hashElement->entry = listElement; + HASH_ADD_INT(hashForUpdates, target, hashElement ); +} + +-(void) scheduleUpdateForTarget:(id)target priority:(NSInteger)priority paused:(BOOL)paused +{ + tHashUpdateEntry * hashElement = NULL; + HASH_FIND_INT(hashForUpdates, &target, hashElement); + if(hashElement) + { +#if COCOS2D_DEBUG >= 1 + NSAssert( hashElement->entry->markedForDeletion, @"CCScheduler: You can't re-schedule an 'update' selector'. Unschedule it first"); +#endif + // TODO : check if priority has changed! + + hashElement->entry->markedForDeletion = NO; + return; + } + + // most of the updates are going to be 0, that's way there + // is an special list for updates with priority 0 + if( priority == 0 ) + [self appendIn:&updates0 target:target paused:paused]; + + else if( priority < 0 ) + [self priorityIn:&updatesNeg target:target priority:priority paused:paused]; + + else // priority > 0 + [self priorityIn:&updatesPos target:target priority:priority paused:paused]; +} + +- (void) removeUpdateFromHash:(tListEntry*)entry +{ + tHashUpdateEntry * element = NULL; + + HASH_FIND_INT(hashForUpdates, &entry->target, element); + if( element ) { + // list entry + DL_DELETE( *element->list, element->entry ); + free( element->entry ); + + // hash entry + [element->target release]; + HASH_DEL( hashForUpdates, element); + free(element); + } +} + +-(void) unscheduleUpdateForTarget:(id)target +{ + if( target == nil ) + return; + + tHashUpdateEntry * element = NULL; + HASH_FIND_INT(hashForUpdates, &target, element); + if( element ) { + if(updateHashLocked) + element->entry->markedForDeletion = YES; + else + [self removeUpdateFromHash:element->entry]; + +// // list entry +// DL_DELETE( *element->list, element->entry ); +// free( element->entry ); +// +// // hash entry +// [element->target release]; +// HASH_DEL( hashForUpdates, element); +// free(element); + } +} + +#pragma mark CCScheduler - Common for Update selector & Custom Selectors + +-(void) unscheduleAllSelectors +{ + // Custom Selectors + for(tHashSelectorEntry *element=hashForSelectors; element != NULL; ) { + id target = element->target; + element=element->hh.next; + [self unscheduleAllSelectorsForTarget:target]; + } + + // Updates selectors + tListEntry *entry, *tmp; + DL_FOREACH_SAFE( updates0, entry, tmp ) { + [self unscheduleUpdateForTarget:entry->target]; + } + DL_FOREACH_SAFE( updatesNeg, entry, tmp ) { + [self unscheduleUpdateForTarget:entry->target]; + } + DL_FOREACH_SAFE( updatesPos, entry, tmp ) { + [self unscheduleUpdateForTarget:entry->target]; + } + +} + +-(void) unscheduleAllSelectorsForTarget:(id)target +{ + // explicit nil handling + if( target == nil ) + return; + + // Custom Selectors + tHashSelectorEntry *element = NULL; + HASH_FIND_INT(hashForSelectors, &target, element); + + if( element ) { + if( ccArrayContainsObject(element->timers, element->currentTimer) && !element->currentTimerSalvaged ) { + [element->currentTimer retain]; + element->currentTimerSalvaged = YES; + } + ccArrayRemoveAllObjects(element->timers); + if( currentTarget == element ) + currentTargetSalvaged = YES; + else + [self removeHashElement:element]; + } + + // Update Selector + [self unscheduleUpdateForTarget:target]; +} + +-(void) resumeTarget:(id)target +{ + NSAssert( target != nil, @"target must be non nil" ); + + // Custom Selectors + tHashSelectorEntry *element = NULL; + HASH_FIND_INT(hashForSelectors, &target, element); + if( element ) + element->paused = NO; + + // Update selector + tHashUpdateEntry * elementUpdate = NULL; + HASH_FIND_INT(hashForUpdates, &target, elementUpdate); + if( elementUpdate ) { + NSAssert( elementUpdate->entry != NULL, @"resumeTarget: unknown error"); + elementUpdate->entry->paused = NO; + } +} + +-(void) pauseTarget:(id)target +{ + NSAssert( target != nil, @"target must be non nil" ); + + // Custom selectors + tHashSelectorEntry *element = NULL; + HASH_FIND_INT(hashForSelectors, &target, element); + if( element ) + element->paused = YES; + + // Update selector + tHashUpdateEntry * elementUpdate = NULL; + HASH_FIND_INT(hashForUpdates, &target, elementUpdate); + if( elementUpdate ) { + NSAssert( elementUpdate->entry != NULL, @"pauseTarget: unknown error"); + elementUpdate->entry->paused = YES; + } + +} + +-(BOOL) isTargetPaused:(id)target +{ + NSAssert( target != nil, @"target must be non nil" ); + + // Custom selectors + tHashSelectorEntry *element = NULL; + HASH_FIND_INT(hashForSelectors, &target, element); + if( element ) + { + return element->paused; + } + return NO; // should never get here + +} + +#pragma mark CCScheduler - Main Loop + +-(void) tick: (ccTime) dt +{ + updateHashLocked = YES; + + if( timeScale_ != 1.0f ) + dt *= timeScale_; + + // Iterate all over the Updates selectors + tListEntry *entry, *tmp; + + // updates with priority < 0 + DL_FOREACH_SAFE( updatesNeg, entry, tmp ) { + if( ! entry->paused && !entry->markedForDeletion ) + entry->impMethod( entry->target, updateSelector, dt ); + } + + // updates with priority == 0 + DL_FOREACH_SAFE( updates0, entry, tmp ) { + if( ! entry->paused && !entry->markedForDeletion ) + { + entry->impMethod( entry->target, updateSelector, dt ); + } + } + + // updates with priority > 0 + DL_FOREACH_SAFE( updatesPos, entry, tmp ) { + if( ! entry->paused && !entry->markedForDeletion ) + entry->impMethod( entry->target, updateSelector, dt ); + } + + // Iterate all over the custome selectors + for(tHashSelectorEntry *elt=hashForSelectors; elt != NULL; ) { + + currentTarget = elt; + currentTargetSalvaged = NO; + + if( ! currentTarget->paused ) { + + // The 'timers' ccArray may change while inside this loop. + for( elt->timerIndex = 0; elt->timerIndex < elt->timers->num; elt->timerIndex++) { + elt->currentTimer = elt->timers->arr[elt->timerIndex]; + elt->currentTimerSalvaged = NO; + + impMethod( elt->currentTimer, updateSelector, dt); + + if( elt->currentTimerSalvaged ) { + // The currentTimer told the remove itself. To prevent the timer from + // accidentally deallocating itself before finishing its step, we retained + // it. Now that step is done, it's safe to release it. + [elt->currentTimer release]; + } + + elt->currentTimer = nil; + } + } + + // elt, at this moment, is still valid + // so it is safe to ask this here (issue #490) + elt = elt->hh.next; + + // only delete currentTarget if no actions were scheduled during the cycle (issue #481) + if( currentTargetSalvaged && currentTarget->timers->num == 0 ) + [self removeHashElement:currentTarget]; + } + + // delete all updates that are morked for deletion + // updates with priority < 0 + DL_FOREACH_SAFE( updatesNeg, entry, tmp ) { + if(entry->markedForDeletion ) + { + [self removeUpdateFromHash:entry]; + } + } + + // updates with priority == 0 + DL_FOREACH_SAFE( updates0, entry, tmp ) { + if(entry->markedForDeletion ) + { + [self removeUpdateFromHash:entry]; + } + } + + // updates with priority > 0 + DL_FOREACH_SAFE( updatesPos, entry, tmp ) { + if(entry->markedForDeletion ) + { + [self removeUpdateFromHash:entry]; + } + } + + updateHashLocked = NO; + currentTarget = nil; +} +@end + diff --git a/tweejump/libs/cocos2d/CCSprite.h b/tweejump/libs/cocos2d/CCSprite.h new file mode 100755 index 0000000..d48bdfe --- /dev/null +++ b/tweejump/libs/cocos2d/CCSprite.h @@ -0,0 +1,330 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-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. + * + */ + + +#import "CCNode.h" +#import "CCProtocols.h" +#import "CCTextureAtlas.h" + +@class CCSpriteBatchNode; +@class CCSpriteFrame; +@class CCAnimation; + +#pragma mark CCSprite + +#define CCSpriteIndexNotInitialized 0xffffffff /// CCSprite invalid index on the CCSpriteBatchode + +/** + Whether or not an CCSprite will rotate, scale or translate with it's parent. + Useful in health bars, when you want that the health bar translates with it's parent but you don't + want it to rotate with its parent. + @since v0.99.0 + */ +typedef enum { + //! Translate with it's parent + CC_HONOR_PARENT_TRANSFORM_TRANSLATE = 1 << 0, + //! Rotate with it's parent + CC_HONOR_PARENT_TRANSFORM_ROTATE = 1 << 1, + //! Scale with it's parent + CC_HONOR_PARENT_TRANSFORM_SCALE = 1 << 2, + //! Skew with it's parent + CC_HONOR_PARENT_TRANSFORM_SKEW = 1 << 3, + + //! All possible transformation enabled. Default value. + CC_HONOR_PARENT_TRANSFORM_ALL = CC_HONOR_PARENT_TRANSFORM_TRANSLATE | CC_HONOR_PARENT_TRANSFORM_ROTATE | CC_HONOR_PARENT_TRANSFORM_SCALE | CC_HONOR_PARENT_TRANSFORM_SKEW, + +} ccHonorParentTransform; + +/** CCSprite is a 2d image ( http://en.wikipedia.org/wiki/Sprite_(computer_graphics) ) + * + * CCSprite can be created with an image, or with a sub-rectangle of an image. + * + * If the parent or any of its ancestors is a CCSpriteBatchNode then the following features/limitations are valid + * - Features when the parent is a CCBatchNode: + * - MUCH faster rendering, specially if the CCSpriteBatchNode has many children. All the children will be drawn in a single batch. + * + * - Limitations + * - Camera is not supported yet (eg: CCOrbitCamera action doesn't work) + * - GridBase actions are not supported (eg: CCLens, CCRipple, CCTwirl) + * - The Alias/Antialias property belongs to CCSpriteBatchNode, so you can't individually set the aliased property. + * - The Blending function property belongs to CCSpriteBatchNode, so you can't individually set the blending function property. + * - Parallax scroller is not supported, but can be simulated with a "proxy" sprite. + * + * If the parent is an standard CCNode, then CCSprite behaves like any other CCNode: + * - It supports blending functions + * - It supports aliasing / antialiasing + * - But the rendering will be slower: 1 draw per children. + * + * The default anchorPoint in CCSprite is (0.5, 0.5). + */ +@interface CCSprite : CCNode +{ + + // + // Data used when the sprite is rendered using a CCSpriteBatchNode + // + CCTextureAtlas *textureAtlas_; // Sprite Sheet texture atlas (weak reference) + NSUInteger atlasIndex_; // Absolute (real) Index on the batch node + CCSpriteBatchNode *batchNode_; // Used batch node (weak reference) + ccHonorParentTransform honorParentTransform_; // whether or not to transform according to its parent transformations + BOOL dirty_; // Sprite needs to be updated + BOOL recursiveDirty_; // Subchildren needs to be updated + BOOL hasChildren_; // optimization to check if it contain children + + // + // Data used when the sprite is self-rendered + // + ccBlendFunc blendFunc_; // Needed for the texture protocol + CCTexture2D *texture_; // Texture used to render the sprite + + // + // Shared data + // + + // whether or not it's parent is a CCSpriteBatchNode + BOOL usesBatchNode_; + + // texture + CGRect rect_; + CGRect rectInPixels_; + BOOL rectRotated_; + + // Offset Position (used by Zwoptex) + CGPoint offsetPositionInPixels_; + CGPoint unflippedOffsetPositionFromCenter_; + + // vertex coords, texture coords and color info + ccV3F_C4B_T2F_Quad quad_; + + // opacity and RGB protocol + GLubyte opacity_; + ccColor3B color_; + ccColor3B colorUnmodified_; + BOOL opacityModifyRGB_; + + // image is flipped + BOOL flipX_; + BOOL flipY_; + +@public + // used internally. + void (*updateMethod)(id, SEL); +} + +/** whether or not the Sprite needs to be updated in the Atlas */ +@property (nonatomic,readwrite) BOOL dirty; +/** the quad (tex coords, vertex coords and color) information */ +@property (nonatomic,readonly) ccV3F_C4B_T2F_Quad quad; +/** The index used on the TextureAtlas. Don't modify this value unless you know what you are doing */ +@property (nonatomic,readwrite) NSUInteger atlasIndex; +/** returns the rect of the CCSprite in points */ +@property (nonatomic,readonly) CGRect textureRect; +/** returns whether or not the texture rectangle is rotated */ +@property (nonatomic,readonly) BOOL textureRectRotated; +/** whether or not the sprite is flipped horizontally. + It only flips the texture of the sprite, and not the texture of the sprite's children. + Also, flipping the texture doesn't alter the anchorPoint. + If you want to flip the anchorPoint too, and/or to flip the children too use: + + sprite.scaleX *= -1; + */ +@property (nonatomic,readwrite) BOOL flipX; +/** whether or not the sprite is flipped vertically. + It only flips the texture of the sprite, and not the texture of the sprite's children. + Also, flipping the texture doesn't alter the anchorPoint. + If you want to flip the anchorPoint too, and/or to flip the children too use: + + sprite.scaleY *= -1; + */ +@property (nonatomic,readwrite) BOOL flipY; +/** opacity: conforms to CCRGBAProtocol protocol */ +@property (nonatomic,readwrite) GLubyte opacity; +/** RGB colors: conforms to CCRGBAProtocol protocol */ +@property (nonatomic,readwrite) ccColor3B color; +/** whether or not the Sprite is rendered using a CCSpriteBatchNode */ +@property (nonatomic,readwrite) BOOL usesBatchNode; +/** weak reference of the CCTextureAtlas used when the sprite is rendered using a CCSpriteBatchNode */ +@property (nonatomic,readwrite,assign) CCTextureAtlas *textureAtlas; +/** weak reference to the CCSpriteBatchNode that renders the CCSprite */ +@property (nonatomic,readwrite,assign) CCSpriteBatchNode *batchNode; +/** whether or not to transform according to its parent transfomrations. + Useful for health bars. eg: Don't rotate the health bar, even if the parent rotates. + IMPORTANT: Only valid if it is rendered using an CCSpriteBatchNode. + @since v0.99.0 + */ +@property (nonatomic,readwrite) ccHonorParentTransform honorParentTransform; +/** offset position in pixels of the sprite in points. Calculated automatically by editors like Zwoptex. + @since v0.99.0 + */ +@property (nonatomic,readonly) CGPoint offsetPositionInPixels; +/** conforms to CCTextureProtocol protocol */ +@property (nonatomic,readwrite) ccBlendFunc blendFunc; + +#pragma mark CCSprite - Initializers + +/** Creates an sprite with a texture. + The rect used will be the size of the texture. + The offset will be (0,0). + */ ++(id) spriteWithTexture:(CCTexture2D*)texture; + +/** Creates an sprite with a texture and a rect. + The offset will be (0,0). + */ ++(id) spriteWithTexture:(CCTexture2D*)texture rect:(CGRect)rect; + +/** Creates an sprite with an sprite frame. + */ ++(id) spriteWithSpriteFrame:(CCSpriteFrame*)spriteFrame; + +/** Creates an sprite with an sprite frame name. + An CCSpriteFrame will be fetched from the CCSpriteFrameCache by name. + If the CCSpriteFrame doesn't exist it will raise an exception. + @since v0.9 + */ ++(id) spriteWithSpriteFrameName:(NSString*)spriteFrameName; + +/** Creates an sprite with an image filename. + The rect used will be the size of the image. + The offset will be (0,0). + */ ++(id) spriteWithFile:(NSString*)filename; + +/** Creates an sprite with an image filename and a rect. + The offset will be (0,0). + */ ++(id) spriteWithFile:(NSString*)filename rect:(CGRect)rect; + +/** Creates an sprite with a CGImageRef and a key. + The key is used by the CCTextureCache to know if a texture was already created with this CGImage. + For example, a valid key is: @"sprite_frame_01". + If key is nil, then a new texture will be created each time by the CCTextureCache. + @since v0.99.0 + */ ++(id) spriteWithCGImage: (CGImageRef)image key:(NSString*)key; + + +/** Creates an sprite with an CCBatchNode and a rect + */ ++(id) spriteWithBatchNode:(CCSpriteBatchNode*)batchNode rect:(CGRect)rect; + + +/** Initializes an sprite with a texture. + The rect used will be the size of the texture. + The offset will be (0,0). + */ +-(id) initWithTexture:(CCTexture2D*)texture; + +/** Initializes an sprite with a texture and a rect in points. + The offset will be (0,0). + */ +-(id) initWithTexture:(CCTexture2D*)texture rect:(CGRect)rect; + +/** Initializes an sprite with an sprite frame. + */ +-(id) initWithSpriteFrame:(CCSpriteFrame*)spriteFrame; + +/** Initializes an sprite with an sprite frame name. + An CCSpriteFrame will be fetched from the CCSpriteFrameCache by name. + If the CCSpriteFrame doesn't exist it will raise an exception. + @since v0.9 + */ +-(id) initWithSpriteFrameName:(NSString*)spriteFrameName; + +/** Initializes an sprite with an image filename. + The rect used will be the size of the image. + The offset will be (0,0). + */ +-(id) initWithFile:(NSString*)filename; + +/** Initializes an sprite with an image filename, and a rect. + The offset will be (0,0). + */ +-(id) initWithFile:(NSString*)filename rect:(CGRect)rect; + +/** Initializes an sprite with a CGImageRef and a key + The key is used by the CCTextureCache to know if a texture was already created with this CGImage. + For example, a valid key is: @"sprite_frame_01". + If key is nil, then a new texture will be created each time by the CCTextureCache. + @since v0.99.0 + */ +-(id) initWithCGImage:(CGImageRef)image key:(NSString*)key; + +/** Initializes an sprite with an CCSpriteBatchNode and a rect in points + */ +-(id) initWithBatchNode:(CCSpriteBatchNode*)batchNode rect:(CGRect)rect; + +/** Initializes an sprite with an CCSpriteBatchNode and a rect in pixels + @since v0.99.5 + */ +-(id) initWithBatchNode:(CCSpriteBatchNode*)batchNode rectInPixels:(CGRect)rect; + + + +#pragma mark CCSprite - BatchNode methods + +/** updates the quad according the the rotation, position, scale values. + */ +-(void)updateTransform; + +/** updates the texture rect of the CCSprite in points. + */ +-(void) setTextureRect:(CGRect) rect; +/** updates the texture rect, rectRotated and untrimmed size of the CCSprite in pixels + */ +-(void) setTextureRectInPixels:(CGRect)rect rotated:(BOOL)rotated untrimmedSize:(CGSize)size; + +/** tell the sprite to use self-render. + @since v0.99.0 + */ +-(void) useSelfRender; + +/** tell the sprite to use sprite batch node + @since v0.99.0 + */ +-(void) useBatchNode:(CCSpriteBatchNode*)batchNode; + + +#pragma mark CCSprite - Frames + +/** sets a new display frame to the CCSprite. */ +-(void) setDisplayFrame:(CCSpriteFrame*)newFrame; + +/** returns whether or not a CCSpriteFrame is being displayed */ +-(BOOL) isFrameDisplayed:(CCSpriteFrame*)frame; + +/** returns the current displayed frame. */ +-(CCSpriteFrame*) displayedFrame; + +#pragma mark CCSprite - Animation + +/** changes the display frame with animation name and index. + The animation name will be get from the CCAnimationCache + @since v0.99.5 + */ +-(void) setDisplayFrameWithAnimationName:(NSString*)animationName index:(int) frameIndex; + +@end diff --git a/tweejump/libs/cocos2d/CCSprite.m b/tweejump/libs/cocos2d/CCSprite.m new file mode 100755 index 0000000..413e708 --- /dev/null +++ b/tweejump/libs/cocos2d/CCSprite.m @@ -0,0 +1,976 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-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. + * + */ + +#import + +#import "ccConfig.h" +#import "CCSpriteBatchNode.h" +#import "CCSprite.h" +#import "CCSpriteFrame.h" +#import "CCSpriteFrameCache.h" +#import "CCAnimation.h" +#import "CCAnimationCache.h" +#import "CCTextureCache.h" +#import "Support/CGPointExtension.h" +#import "CCDrawingPrimitives.h" + +#pragma mark - +#pragma mark CCSprite + +#if CC_SPRITEBATCHNODE_RENDER_SUBPIXEL +#define RENDER_IN_SUBPIXEL +#else +#define RENDER_IN_SUBPIXEL(__A__) ( (int)(__A__)) +#endif + +// XXX: Optmization +struct transformValues_ { + CGPoint pos; // position x and y + CGPoint scale; // scale x and y + float rotation; + CGPoint skew; // skew x and y + CGPoint ap; // anchor point in pixels + BOOL visible; +}; + +@interface CCSprite (Private) +-(void)updateTextureCoords:(CGRect)rect; +-(void)updateBlendFunc; +-(void) initAnimationDictionary; +-(void) getTransformValues:(struct transformValues_*)tv; // optimization +@end + +@implementation CCSprite + +@synthesize dirty = dirty_; +@synthesize quad = quad_; +@synthesize atlasIndex = atlasIndex_; +@synthesize textureRect = rect_; +@synthesize textureRectRotated = rectRotated_; +@synthesize blendFunc = blendFunc_; +@synthesize usesBatchNode = usesBatchNode_; +@synthesize textureAtlas = textureAtlas_; +@synthesize batchNode = batchNode_; +@synthesize honorParentTransform = honorParentTransform_; +@synthesize offsetPositionInPixels = offsetPositionInPixels_; + + ++(id)spriteWithTexture:(CCTexture2D*)texture +{ + return [[[self alloc] initWithTexture:texture] autorelease]; +} + ++(id)spriteWithTexture:(CCTexture2D*)texture rect:(CGRect)rect +{ + return [[[self alloc] initWithTexture:texture rect:rect] autorelease]; +} + ++(id)spriteWithFile:(NSString*)filename +{ + return [[[self alloc] initWithFile:filename] autorelease]; +} + ++(id)spriteWithFile:(NSString*)filename rect:(CGRect)rect +{ + return [[[self alloc] initWithFile:filename rect:rect] autorelease]; +} + ++(id)spriteWithSpriteFrame:(CCSpriteFrame*)spriteFrame +{ + return [[[self alloc] initWithSpriteFrame:spriteFrame] autorelease]; +} + ++(id)spriteWithSpriteFrameName:(NSString*)spriteFrameName +{ + CCSpriteFrame *frame = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:spriteFrameName]; + + NSAssert1(frame!=nil, @"Invalid spriteFrameName: %@", spriteFrameName); + return [self spriteWithSpriteFrame:frame]; +} + ++(id)spriteWithCGImage:(CGImageRef)image key:(NSString*)key +{ + return [[[self alloc] initWithCGImage:image key:key] autorelease]; +} + ++(id) spriteWithBatchNode:(CCSpriteBatchNode*)batchNode rect:(CGRect)rect +{ + return [[[self alloc] initWithBatchNode:batchNode rect:rect] autorelease]; +} + +-(id) init +{ + if( (self=[super init]) ) { + dirty_ = recursiveDirty_ = NO; + + // by default use "Self Render". + // if the sprite is added to a batchnode, then it will automatically switch to "batchnode Render" + [self useSelfRender]; + + opacityModifyRGB_ = YES; + opacity_ = 255; + color_ = colorUnmodified_ = ccWHITE; + + blendFunc_.src = CC_BLEND_SRC; + blendFunc_.dst = CC_BLEND_DST; + + // update texture (calls updateBlendFunc) + [self setTexture:nil]; + + // clean the Quad + bzero(&quad_, sizeof(quad_)); + + flipY_ = flipX_ = NO; + + // default transform anchor: center + anchorPoint_ = ccp(0.5f, 0.5f); + + // zwoptex default values + offsetPositionInPixels_ = CGPointZero; + + honorParentTransform_ = CC_HONOR_PARENT_TRANSFORM_ALL; + hasChildren_ = NO; + + // Atlas: Color + ccColor4B tmpColor = {255,255,255,255}; + quad_.bl.colors = tmpColor; + quad_.br.colors = tmpColor; + quad_.tl.colors = tmpColor; + quad_.tr.colors = tmpColor; + + // Atlas: Vertex + + // updated in "useSelfRender" + + // Atlas: TexCoords + [self setTextureRectInPixels:CGRectZero rotated:NO untrimmedSize:CGSizeZero]; + + // updateMethod selector + updateMethod = (__typeof__(updateMethod))[self methodForSelector:@selector(updateTransform)]; + } + + return self; +} + +-(id) initWithTexture:(CCTexture2D*)texture rect:(CGRect)rect +{ + NSAssert(texture!=nil, @"Invalid texture for sprite"); + // IMPORTANT: [self init] and not [super init]; + if( (self = [self init]) ) + { + [self setTexture:texture]; + [self setTextureRect:rect]; + } + return self; +} + +-(id) initWithTexture:(CCTexture2D*)texture +{ + NSAssert(texture!=nil, @"Invalid texture for sprite"); + + CGRect rect = CGRectZero; + rect.size = texture.contentSize; + return [self initWithTexture:texture rect:rect]; +} + +-(id) initWithFile:(NSString*)filename +{ + NSAssert(filename!=nil, @"Invalid filename for sprite"); + + CCTexture2D *texture = [[CCTextureCache sharedTextureCache] addImage: filename]; + if( texture ) { + CGRect rect = CGRectZero; + rect.size = texture.contentSize; + return [self initWithTexture:texture rect:rect]; + } + + [self release]; + return nil; +} + +-(id) initWithFile:(NSString*)filename rect:(CGRect)rect +{ + NSAssert(filename!=nil, @"Invalid filename for sprite"); + + CCTexture2D *texture = [[CCTextureCache sharedTextureCache] addImage: filename]; + if( texture ) + return [self initWithTexture:texture rect:rect]; + + [self release]; + return nil; +} + +- (id) initWithSpriteFrame:(CCSpriteFrame*)spriteFrame +{ + NSAssert(spriteFrame!=nil, @"Invalid spriteFrame for sprite"); + + id ret = [self initWithTexture:spriteFrame.texture rect:spriteFrame.rect]; + [self setDisplayFrame:spriteFrame]; + return ret; +} + +-(id)initWithSpriteFrameName:(NSString*)spriteFrameName +{ + NSAssert(spriteFrameName!=nil, @"Invalid spriteFrameName for sprite"); + + CCSpriteFrame *frame = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:spriteFrameName]; + return [self initWithSpriteFrame:frame]; +} + +- (id) initWithCGImage:(CGImageRef)image key:(NSString*)key +{ + NSAssert(image!=nil, @"Invalid CGImageRef for sprite"); + + // XXX: possible bug. See issue #349. New API should be added + CCTexture2D *texture = [[CCTextureCache sharedTextureCache] addCGImage:image forKey:key]; + + CGRect rect = CGRectZero; + rect.size = texture.contentSize; + + return [self initWithTexture:texture rect:rect]; +} + +-(id) initWithBatchNode:(CCSpriteBatchNode*)batchNode rect:(CGRect)rect +{ + id ret = [self initWithTexture:batchNode.texture rect:rect]; + [self useBatchNode:batchNode]; + + return ret; +} + +-(id) initWithBatchNode:(CCSpriteBatchNode*)batchNode rectInPixels:(CGRect)rect +{ + id ret = [self initWithTexture:batchNode.texture]; + [self setTextureRectInPixels:rect rotated:NO untrimmedSize:rect.size]; + [self useBatchNode:batchNode]; + + return ret; +} + +- (NSString*) description +{ + return [NSString stringWithFormat:@"<%@ = %08X | Rect = (%.2f,%.2f,%.2f,%.2f) | tag = %i | atlasIndex = %i>", [self class], self, + rect_.origin.x, rect_.origin.y, rect_.size.width, rect_.size.height, + tag_, + atlasIndex_ + ]; +} + +- (void) dealloc +{ + [texture_ release]; + [super dealloc]; +} + +-(void) useSelfRender +{ + atlasIndex_ = CCSpriteIndexNotInitialized; + usesBatchNode_ = NO; + textureAtlas_ = nil; + batchNode_ = nil; + dirty_ = recursiveDirty_ = NO; + + float x1 = 0 + offsetPositionInPixels_.x; + float y1 = 0 + offsetPositionInPixels_.y; + float x2 = x1 + rectInPixels_.size.width; + float y2 = y1 + rectInPixels_.size.height; + quad_.bl.vertices = (ccVertex3F) { x1, y1, 0 }; + quad_.br.vertices = (ccVertex3F) { x2, y1, 0 }; + quad_.tl.vertices = (ccVertex3F) { x1, y2, 0 }; + quad_.tr.vertices = (ccVertex3F) { x2, y2, 0 }; +} + +-(void) useBatchNode:(CCSpriteBatchNode*)batchNode +{ + usesBatchNode_ = YES; + textureAtlas_ = [batchNode textureAtlas]; // weak ref + batchNode_ = batchNode; // weak ref +} + +-(void)setTextureRect:(CGRect)rect +{ + CGRect rectInPixels = CC_RECT_POINTS_TO_PIXELS( rect ); + [self setTextureRectInPixels:rectInPixels rotated:NO untrimmedSize:rectInPixels.size]; +} + +-(void)setTextureRectInPixels:(CGRect)rect rotated:(BOOL)rotated untrimmedSize:(CGSize)untrimmedSize +{ + rectInPixels_ = rect; + rect_ = CC_RECT_PIXELS_TO_POINTS( rect ); + rectRotated_ = rotated; + + [self setContentSizeInPixels:untrimmedSize]; + [self updateTextureCoords:rectInPixels_]; + + CGPoint relativeOffsetInPixels = unflippedOffsetPositionFromCenter_; + + // issue #732 + if( flipX_ ) + relativeOffsetInPixels.x = -relativeOffsetInPixels.x; + if( flipY_ ) + relativeOffsetInPixels.y = -relativeOffsetInPixels.y; + + offsetPositionInPixels_.x = relativeOffsetInPixels.x + (contentSizeInPixels_.width - rectInPixels_.size.width) / 2; + offsetPositionInPixels_.y = relativeOffsetInPixels.y + (contentSizeInPixels_.height - rectInPixels_.size.height) / 2; + + + // rendering using batch node + if( usesBatchNode_ ) { + // update dirty_, don't update recursiveDirty_ + dirty_ = YES; + } + + // self rendering + else + { + // Atlas: Vertex + float x1 = 0 + offsetPositionInPixels_.x; + float y1 = 0 + offsetPositionInPixels_.y; + float x2 = x1 + rectInPixels_.size.width; + float y2 = y1 + rectInPixels_.size.height; + + // Don't update Z. + quad_.bl.vertices = (ccVertex3F) { x1, y1, 0 }; + quad_.br.vertices = (ccVertex3F) { x2, y1, 0 }; + quad_.tl.vertices = (ccVertex3F) { x1, y2, 0 }; + quad_.tr.vertices = (ccVertex3F) { x2, y2, 0 }; + } +} + +-(void)updateTextureCoords:(CGRect)rect +{ + CCTexture2D *tex = (usesBatchNode_)?[textureAtlas_ texture]:texture_; + if(!tex) + return; + + float atlasWidth = (float)tex.pixelsWide; + float atlasHeight = (float)tex.pixelsHigh; + + float left,right,top,bottom; + + if(rectRotated_){ +#if CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL + left = (2*rect.origin.x+1)/(2*atlasWidth); + right = left+(rect.size.height*2-2)/(2*atlasWidth); + top = (2*rect.origin.y+1)/(2*atlasHeight); + bottom = top+(rect.size.width*2-2)/(2*atlasHeight); +#else + left = rect.origin.x/atlasWidth; + right = left+(rect.size.height/atlasWidth); + top = rect.origin.y/atlasHeight; + bottom = top+(rect.size.width/atlasHeight); +#endif // ! CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL + + if( flipX_) + CC_SWAP(top,bottom); + if( flipY_) + CC_SWAP(left,right); + + quad_.bl.texCoords.u = left; + quad_.bl.texCoords.v = top; + quad_.br.texCoords.u = left; + quad_.br.texCoords.v = bottom; + quad_.tl.texCoords.u = right; + quad_.tl.texCoords.v = top; + quad_.tr.texCoords.u = right; + quad_.tr.texCoords.v = bottom; + } else { +#if CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL + left = (2*rect.origin.x+1)/(2*atlasWidth); + right = left + (rect.size.width*2-2)/(2*atlasWidth); + top = (2*rect.origin.y+1)/(2*atlasHeight); + bottom = top + (rect.size.height*2-2)/(2*atlasHeight); +#else + left = rect.origin.x/atlasWidth; + right = left + rect.size.width/atlasWidth; + top = rect.origin.y/atlasHeight; + bottom = top + rect.size.height/atlasHeight; +#endif // ! CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL + + if( flipX_) + CC_SWAP(left,right); + if( flipY_) + CC_SWAP(top,bottom); + + quad_.bl.texCoords.u = left; + quad_.bl.texCoords.v = bottom; + quad_.br.texCoords.u = right; + quad_.br.texCoords.v = bottom; + quad_.tl.texCoords.u = left; + quad_.tl.texCoords.v = top; + quad_.tr.texCoords.u = right; + quad_.tr.texCoords.v = top; + } +} + +-(void)updateTransform +{ + NSAssert( usesBatchNode_, @"updateTransform is only valid when CCSprite is being renderd using an CCSpriteBatchNode"); + + // optimization. Quick return if not dirty + if( ! dirty_ ) + return; + + CGAffineTransform matrix; + + // Optimization: if it is not visible, then do nothing + if( ! visible_ ) { + quad_.br.vertices = quad_.tl.vertices = quad_.tr.vertices = quad_.bl.vertices = (ccVertex3F){0,0,0}; + [textureAtlas_ updateQuad:&quad_ atIndex:atlasIndex_]; + dirty_ = recursiveDirty_ = NO; + return ; + } + + + // Optimization: If parent is batchnode, or parent is nil + // build Affine transform manually + if( ! parent_ || parent_ == batchNode_ ) { + + float radians = -CC_DEGREES_TO_RADIANS(rotation_); + float c = cosf(radians); + float s = sinf(radians); + + matrix = CGAffineTransformMake( c * scaleX_, s * scaleX_, + -s * scaleY_, c * scaleY_, + positionInPixels_.x, positionInPixels_.y); + if( skewX_ || skewY_ ) { + CGAffineTransform skewMatrix = CGAffineTransformMake(1.0f, tanf(CC_DEGREES_TO_RADIANS(skewY_)), + tanf(CC_DEGREES_TO_RADIANS(skewX_)), 1.0f, + 0.0f, 0.0f); + matrix = CGAffineTransformConcat(skewMatrix, matrix); + } + matrix = CGAffineTransformTranslate(matrix, -anchorPointInPixels_.x, -anchorPointInPixels_.y); + + + } else { // parent_ != batchNode_ + + // else do affine transformation according to the HonorParentTransform + + matrix = CGAffineTransformIdentity; + ccHonorParentTransform prevHonor = CC_HONOR_PARENT_TRANSFORM_ALL; + + for (CCNode *p = self ; p && p != batchNode_ ; p = p.parent) { + + // Might happen. Issue #1053 + NSAssert( [p isKindOfClass:[CCSprite class]], @"CCSprite should be a CCSprite subclass. Probably you initialized an sprite with a batchnode, but you didn't add it to the batch node." ); + + struct transformValues_ tv; + [(CCSprite*)p getTransformValues: &tv]; + + // If any of the parents are not visible, then don't draw this node + if( ! tv.visible ) { + quad_.br.vertices = quad_.tl.vertices = quad_.tr.vertices = quad_.bl.vertices = (ccVertex3F){0,0,0}; + [textureAtlas_ updateQuad:&quad_ atIndex:atlasIndex_]; + dirty_ = recursiveDirty_ = NO; + return; + } + CGAffineTransform newMatrix = CGAffineTransformIdentity; + + // 2nd: Translate, Skew, Rotate, Scale + if( prevHonor & CC_HONOR_PARENT_TRANSFORM_TRANSLATE ) + newMatrix = CGAffineTransformTranslate(newMatrix, tv.pos.x, tv.pos.y); + if( prevHonor & CC_HONOR_PARENT_TRANSFORM_ROTATE ) + newMatrix = CGAffineTransformRotate(newMatrix, -CC_DEGREES_TO_RADIANS(tv.rotation)); + if ( prevHonor & CC_HONOR_PARENT_TRANSFORM_SKEW ) { + CGAffineTransform skew = CGAffineTransformMake(1.0f, tanf(CC_DEGREES_TO_RADIANS(tv.skew.y)), tanf(CC_DEGREES_TO_RADIANS(tv.skew.x)), 1.0f, 0.0f, 0.0f); + // apply the skew to the transform + newMatrix = CGAffineTransformConcat(skew, newMatrix); + } + if( prevHonor & CC_HONOR_PARENT_TRANSFORM_SCALE ) { + newMatrix = CGAffineTransformScale(newMatrix, tv.scale.x, tv.scale.y); + } + + // 3rd: Translate anchor point + newMatrix = CGAffineTransformTranslate(newMatrix, -tv.ap.x, -tv.ap.y); + + // 4th: Matrix multiplication + matrix = CGAffineTransformConcat( matrix, newMatrix); + + prevHonor = [(CCSprite*)p honorParentTransform]; + } + } + + + // + // calculate the Quad based on the Affine Matrix + // + + CGSize size = rectInPixels_.size; + + float x1 = offsetPositionInPixels_.x; + float y1 = offsetPositionInPixels_.y; + + float x2 = x1 + size.width; + float y2 = y1 + size.height; + float x = matrix.tx; + float y = matrix.ty; + + float cr = matrix.a; + float sr = matrix.b; + float cr2 = matrix.d; + float sr2 = -matrix.c; + float ax = x1 * cr - y1 * sr2 + x; + float ay = x1 * sr + y1 * cr2 + y; + + float bx = x2 * cr - y1 * sr2 + x; + float by = x2 * sr + y1 * cr2 + y; + + float cx = x2 * cr - y2 * sr2 + x; + float cy = x2 * sr + y2 * cr2 + y; + + float dx = x1 * cr - y2 * sr2 + x; + float dy = x1 * sr + y2 * cr2 + y; + + quad_.bl.vertices = (ccVertex3F) { RENDER_IN_SUBPIXEL(ax), RENDER_IN_SUBPIXEL(ay), vertexZ_ }; + quad_.br.vertices = (ccVertex3F) { RENDER_IN_SUBPIXEL(bx), RENDER_IN_SUBPIXEL(by), vertexZ_ }; + quad_.tl.vertices = (ccVertex3F) { RENDER_IN_SUBPIXEL(dx), RENDER_IN_SUBPIXEL(dy), vertexZ_ }; + quad_.tr.vertices = (ccVertex3F) { RENDER_IN_SUBPIXEL(cx), RENDER_IN_SUBPIXEL(cy), vertexZ_ }; + + [textureAtlas_ updateQuad:&quad_ atIndex:atlasIndex_]; + dirty_ = recursiveDirty_ = NO; +} + +// XXX: Optimization: instead of calling 5 times the parent sprite to obtain: position, scale.x, scale.y, anchorpoint and rotation, +// this fuction return the 5 values in 1 single call +-(void) getTransformValues:(struct transformValues_*) tv +{ + tv->pos = positionInPixels_; + tv->scale.x = scaleX_; + tv->scale.y = scaleY_; + tv->rotation = rotation_; + tv->skew.x = skewX_; + tv->skew.y = skewY_; + tv->ap = anchorPointInPixels_; + tv->visible = visible_; +} + +#pragma mark CCSprite - draw + +-(void) draw +{ + [super draw]; + + NSAssert(!usesBatchNode_, @"If CCSprite is being rendered by CCSpriteBatchNode, CCSprite#draw SHOULD NOT be called"); + + // Default GL states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY + // Needed states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY + // Unneeded states: - + + BOOL newBlend = blendFunc_.src != CC_BLEND_SRC || blendFunc_.dst != CC_BLEND_DST; + if( newBlend ) + glBlendFunc( blendFunc_.src, blendFunc_.dst ); + +#define kQuadSize sizeof(quad_.bl) + glBindTexture(GL_TEXTURE_2D, [texture_ name]); + + long offset = (long)&quad_; + + // vertex + NSInteger diff = offsetof( ccV3F_C4B_T2F, vertices); + glVertexPointer(3, GL_FLOAT, kQuadSize, (void*) (offset + diff) ); + + // color + diff = offsetof( ccV3F_C4B_T2F, colors); + glColorPointer(4, GL_UNSIGNED_BYTE, kQuadSize, (void*)(offset + diff)); + + // tex coords + diff = offsetof( ccV3F_C4B_T2F, texCoords); + glTexCoordPointer(2, GL_FLOAT, kQuadSize, (void*)(offset + diff)); + + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + + if( newBlend ) + glBlendFunc(CC_BLEND_SRC, CC_BLEND_DST); + +#if CC_SPRITE_DEBUG_DRAW == 1 + // draw bounding box + CGSize s = self.contentSize; + CGPoint vertices[4] = { + ccp(0,0), ccp(s.width,0), + ccp(s.width,s.height), ccp(0,s.height) + }; + ccDrawPoly(vertices, 4, YES); +#elif CC_SPRITE_DEBUG_DRAW == 2 + // draw texture box + CGSize s = self.textureRect.size; + CGPoint offsetPix = self.offsetPositionInPixels; + CGPoint vertices[4] = { + ccp(offsetPix.x,offsetPix.y), ccp(offsetPix.x+s.width,offsetPix.y), + ccp(offsetPix.x+s.width,offsetPix.y+s.height), ccp(offsetPix.x,offsetPix.y+s.height) + }; + ccDrawPoly(vertices, 4, YES); +#endif // CC_SPRITE_DEBUG_DRAW + +} + +#pragma mark CCSprite - CCNode overrides + +-(void) addChild:(CCSprite*)child z:(NSInteger)z tag:(NSInteger) aTag +{ + NSAssert( child != nil, @"Argument must be non-nil"); + + [super addChild:child z:z tag:aTag]; + + if( usesBatchNode_ ) { + NSAssert( [child isKindOfClass:[CCSprite class]], @"CCSprite only supports CCSprites as children when using CCSpriteBatchNode"); + NSAssert( child.texture.name == textureAtlas_.texture.name, @"CCSprite is not using the same texture id"); + + NSUInteger index = [batchNode_ atlasIndexForChild:child atZ:z]; + [batchNode_ insertChild:child inAtlasAtIndex:index]; + } + + hasChildren_ = YES; +} + +-(void) reorderChild:(CCSprite*)child z:(NSInteger)z +{ + NSAssert( child != nil, @"Child must be non-nil"); + NSAssert( [children_ containsObject:child], @"Child doesn't belong to Sprite" ); + + if( z == child.zOrder ) + return; + + if( usesBatchNode_ ) { + // XXX: Instead of removing/adding, it is more efficient to reorder manually + [child retain]; + [self removeChild:child cleanup:NO]; + [self addChild:child z:z]; + [child release]; + } + + else + [super reorderChild:child z:z]; +} + +-(void)removeChild: (CCSprite *)sprite cleanup:(BOOL)doCleanup +{ + if( usesBatchNode_ ) + [batchNode_ removeSpriteFromAtlas:sprite]; + + [super removeChild:sprite cleanup:doCleanup]; + + hasChildren_ = ( [children_ count] > 0 ); +} + +-(void)removeAllChildrenWithCleanup:(BOOL)doCleanup +{ + if( usesBatchNode_ ) { + CCSprite *child; + CCARRAY_FOREACH(children_, child) + [batchNode_ removeSpriteFromAtlas:child]; + } + + [super removeAllChildrenWithCleanup:doCleanup]; + + hasChildren_ = NO; +} + +// +// CCNode property overloads +// used only when parent is CCSpriteBatchNode +// +#pragma mark CCSprite - property overloads + + +-(void) setDirtyRecursively:(BOOL)b +{ + dirty_ = recursiveDirty_ = b; + // recursively set dirty + if( hasChildren_ ) { + CCSprite *child; + CCARRAY_FOREACH(children_, child) + [child setDirtyRecursively:YES]; + } +} + +// XXX HACK: optimization +#define SET_DIRTY_RECURSIVELY() { \ + if( usesBatchNode_ && ! recursiveDirty_ ) { \ + dirty_ = recursiveDirty_ = YES; \ + if( hasChildren_) \ + [self setDirtyRecursively:YES]; \ + } \ + } + +-(void)setPosition:(CGPoint)pos +{ + [super setPosition:pos]; + SET_DIRTY_RECURSIVELY(); +} + +-(void)setPositionInPixels:(CGPoint)pos +{ + [super setPositionInPixels:pos]; + SET_DIRTY_RECURSIVELY(); +} + +-(void)setRotation:(float)rot +{ + [super setRotation:rot]; + SET_DIRTY_RECURSIVELY(); +} + +-(void)setSkewX:(float)sx +{ + [super setSkewX:sx]; + SET_DIRTY_RECURSIVELY(); +} + +-(void)setSkewY:(float)sy +{ + [super setSkewY:sy]; + SET_DIRTY_RECURSIVELY(); +} + +-(void)setScaleX:(float) sx +{ + [super setScaleX:sx]; + SET_DIRTY_RECURSIVELY(); +} + +-(void)setScaleY:(float) sy +{ + [super setScaleY:sy]; + SET_DIRTY_RECURSIVELY(); +} + +-(void)setScale:(float) s +{ + [super setScale:s]; + SET_DIRTY_RECURSIVELY(); +} + +-(void) setVertexZ:(float)z +{ + [super setVertexZ:z]; + SET_DIRTY_RECURSIVELY(); +} + +-(void)setAnchorPoint:(CGPoint)anchor +{ + [super setAnchorPoint:anchor]; + SET_DIRTY_RECURSIVELY(); +} + +-(void)setIsRelativeAnchorPoint:(BOOL)relative +{ + NSAssert( ! usesBatchNode_, @"relativeTransformAnchor is invalid in CCSprite"); + [super setIsRelativeAnchorPoint:relative]; +} + +-(void)setVisible:(BOOL)v +{ + [super setVisible:v]; + SET_DIRTY_RECURSIVELY(); +} + +-(void)setFlipX:(BOOL)b +{ + if( flipX_ != b ) { + flipX_ = b; + [self setTextureRectInPixels:rectInPixels_ rotated:rectRotated_ untrimmedSize:contentSizeInPixels_]; + } +} +-(BOOL) flipX +{ + return flipX_; +} + +-(void) setFlipY:(BOOL)b +{ + if( flipY_ != b ) { + flipY_ = b; + [self setTextureRectInPixels:rectInPixels_ rotated:rectRotated_ untrimmedSize:contentSizeInPixels_]; + } +} +-(BOOL) flipY +{ + return flipY_; +} + +// +// RGBA protocol +// +#pragma mark CCSprite - RGBA protocol +-(void) updateColor +{ + ccColor4B color4 = {color_.r, color_.g, color_.b, opacity_ }; + + quad_.bl.colors = color4; + quad_.br.colors = color4; + quad_.tl.colors = color4; + quad_.tr.colors = color4; + + // renders using Sprite Manager + if( usesBatchNode_ ) { + if( atlasIndex_ != CCSpriteIndexNotInitialized) + [textureAtlas_ updateQuad:&quad_ atIndex:atlasIndex_]; + else + // no need to set it recursively + // update dirty_, don't update recursiveDirty_ + dirty_ = YES; + } + // self render + // do nothing +} + +-(GLubyte) opacity +{ + return opacity_; +} + +-(void) setOpacity:(GLubyte) anOpacity +{ + opacity_ = anOpacity; + + // special opacity for premultiplied textures + if( opacityModifyRGB_ ) + [self setColor: colorUnmodified_]; + + [self updateColor]; +} + +- (ccColor3B) color +{ + if(opacityModifyRGB_) + return colorUnmodified_; + + return color_; +} + +-(void) setColor:(ccColor3B)color3 +{ + color_ = colorUnmodified_ = color3; + + if( opacityModifyRGB_ ){ + color_.r = color3.r * opacity_/255; + color_.g = color3.g * opacity_/255; + color_.b = color3.b * opacity_/255; + } + + [self updateColor]; +} + +-(void) setOpacityModifyRGB:(BOOL)modify +{ + ccColor3B oldColor = self.color; + opacityModifyRGB_ = modify; + self.color = oldColor; +} + +-(BOOL) doesOpacityModifyRGB +{ + return opacityModifyRGB_; +} + +// +// Frames +// +#pragma mark CCSprite - Frames + +-(void) setDisplayFrame:(CCSpriteFrame*)frame +{ + unflippedOffsetPositionFromCenter_ = frame.offsetInPixels; + + CCTexture2D *newTexture = [frame texture]; + // update texture before updating texture rect + if ( newTexture.name != texture_.name ) + [self setTexture: newTexture]; + + // update rect + rectRotated_ = frame.rotated; + [self setTextureRectInPixels:frame.rectInPixels rotated:frame.rotated untrimmedSize:frame.originalSizeInPixels]; +} + +-(void) setDisplayFrameWithAnimationName: (NSString*) animationName index:(int) frameIndex +{ + NSAssert( animationName, @"CCSprite#setDisplayFrameWithAnimationName. animationName must not be nil"); + + CCAnimation *a = [[CCAnimationCache sharedAnimationCache] animationByName:animationName]; + + NSAssert( a, @"CCSprite#setDisplayFrameWithAnimationName: Frame not found"); + + CCSpriteFrame *frame = [[a frames] objectAtIndex:frameIndex]; + + NSAssert( frame, @"CCSprite#setDisplayFrame. Invalid frame"); + + [self setDisplayFrame:frame]; +} + + +-(BOOL) isFrameDisplayed:(CCSpriteFrame*)frame +{ + CGRect r = [frame rect]; + return ( CGRectEqualToRect(r, rect_) && + frame.texture.name == self.texture.name ); +} + +-(CCSpriteFrame*) displayedFrame +{ + return [CCSpriteFrame frameWithTexture:texture_ + rectInPixels:rectInPixels_ + rotated:rectRotated_ + offset:unflippedOffsetPositionFromCenter_ + originalSize:contentSizeInPixels_]; +} + +#pragma mark CCSprite - CocosNodeTexture protocol + +-(void) updateBlendFunc +{ + NSAssert( ! usesBatchNode_, @"CCSprite: updateBlendFunc doesn't work when the sprite is rendered using a CCSpriteBatchNode"); + + // it's possible to have an untextured sprite + if( !texture_ || ! [texture_ hasPremultipliedAlpha] ) { + blendFunc_.src = GL_SRC_ALPHA; + blendFunc_.dst = GL_ONE_MINUS_SRC_ALPHA; + [self setOpacityModifyRGB:NO]; + } else { + blendFunc_.src = CC_BLEND_SRC; + blendFunc_.dst = CC_BLEND_DST; + [self setOpacityModifyRGB:YES]; + } +} + +-(void) setTexture:(CCTexture2D*)texture +{ + NSAssert( ! usesBatchNode_, @"CCSprite: setTexture doesn't work when the sprite is rendered using a CCSpriteBatchNode"); + + // accept texture==nil as argument + NSAssert( !texture || [texture isKindOfClass:[CCTexture2D class]], @"setTexture expects a CCTexture2D. Invalid argument"); + + [texture_ release]; + texture_ = [texture retain]; + + [self updateBlendFunc]; +} + +-(CCTexture2D*) texture +{ + return texture_; +} + +@end diff --git a/tweejump/libs/cocos2d/CCSpriteBatchNode.h b/tweejump/libs/cocos2d/CCSpriteBatchNode.h new file mode 100755 index 0000000..2e6ae97 --- /dev/null +++ b/tweejump/libs/cocos2d/CCSpriteBatchNode.h @@ -0,0 +1,122 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (C) 2009 Matt Oswald + * + * Copyright (c) 2009-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. + * + */ + + +#import "CCNode.h" +#import "CCProtocols.h" +#import "CCTextureAtlas.h" +#import "ccMacros.h" + +#pragma mark CCSpriteBatchNode + +@class CCSprite; + +/** CCSpriteBatchNode is like a batch node: if it contains children, it will draw them in 1 single OpenGL call + * (often known as "batch draw"). + * + * A CCSpriteBatchNode can reference one and only one texture (one image file, one texture atlas). + * Only the CCSprites that are contained in that texture can be added to the CCSpriteBatchNode. + * All CCSprites added to a CCSpriteBatchNode are drawn in one OpenGL ES draw call. + * If the CCSprites are not added to a CCSpriteBatchNode then an OpenGL ES draw call will be needed for each one, which is less efficient. + * + * + * Limitations: + * - The only object that is accepted as child (or grandchild, grand-grandchild, etc...) is CCSprite or any subclass of CCSprite. eg: particles, labels and layer can't be added to a CCSpriteBatchNode. + * - Either all its children are Aliased or Antialiased. It can't be a mix. This is because "alias" is a property of the texture, and all the sprites share the same texture. + * + * @since v0.7.1 + */ +@interface CCSpriteBatchNode : CCNode +{ + CCTextureAtlas *textureAtlas_; + ccBlendFunc blendFunc_; + + // all descendants: chlidren, gran children, etc... + CCArray *descendants_; +} + +/** returns the TextureAtlas that is used */ +@property (nonatomic,readwrite,retain) CCTextureAtlas * textureAtlas; + +/** conforms to CCTextureProtocol protocol */ +@property (nonatomic,readwrite) ccBlendFunc blendFunc; + +/** descendants (children, gran children, etc) */ +@property (nonatomic,readonly) CCArray *descendants; + +/** creates a CCSpriteBatchNode with a texture2d and a default capacity of 29 children. + The capacity will be increased in 33% in runtime if it run out of space. + */ ++(id)batchNodeWithTexture:(CCTexture2D *)tex; + +/** creates a CCSpriteBatchNode with a texture2d and capacity of children. + The capacity will be increased in 33% in runtime if it run out of space. + */ ++(id)batchNodeWithTexture:(CCTexture2D *)tex capacity:(NSUInteger)capacity; + +/** creates a CCSpriteBatchNode with a file image (.png, .jpeg, .pvr, etc) with a default capacity of 29 children. + The capacity will be increased in 33% in runtime if it run out of space. + The file will be loaded using the TextureMgr. + */ ++(id)batchNodeWithFile:(NSString*) fileImage; + +/** creates a CCSpriteBatchNode with a file image (.png, .jpeg, .pvr, etc) and capacity of children. + The capacity will be increased in 33% in runtime if it run out of space. + The file will be loaded using the TextureMgr. +*/ ++(id)batchNodeWithFile:(NSString*)fileImage capacity:(NSUInteger)capacity; + +/** initializes a CCSpriteBatchNode with a texture2d and capacity of children. + The capacity will be increased in 33% in runtime if it run out of space. + */ +-(id)initWithTexture:(CCTexture2D *)tex capacity:(NSUInteger)capacity; +/** initializes a CCSpriteBatchNode with a file image (.png, .jpeg, .pvr, etc) and a capacity of children. + The capacity will be increased in 33% in runtime if it run out of space. + The file will be loaded using the TextureMgr. + */ +-(id)initWithFile:(NSString*)fileImage capacity:(NSUInteger)capacity; + +-(void) increaseAtlasCapacity; + +/** removes a child given a certain index. It will also cleanup the running actions depending on the cleanup parameter. + @warning Removing a child from a CCSpriteBatchNode is very slow + */ +-(void)removeChildAtIndex:(NSUInteger)index cleanup:(BOOL)doCleanup; + +/** removes a child given a reference. It will also cleanup the running actions depending on the cleanup parameter. + @warning Removing a child from a CCSpriteBatchNode is very slow + */ +-(void)removeChild: (CCSprite *)sprite cleanup:(BOOL)doCleanup; + +-(void) insertChild:(CCSprite*)child inAtlasAtIndex:(NSUInteger)index; +-(void) removeSpriteFromAtlas:(CCSprite*)sprite; + +-(NSUInteger) rebuildIndexInOrder:(CCSprite*)parent atlasIndex:(NSUInteger)index; +-(NSUInteger) atlasIndexForChild:(CCSprite*)sprite atZ:(NSInteger)z; + +@end diff --git a/tweejump/libs/cocos2d/CCSpriteBatchNode.m b/tweejump/libs/cocos2d/CCSpriteBatchNode.m new file mode 100755 index 0000000..921d892 --- /dev/null +++ b/tweejump/libs/cocos2d/CCSpriteBatchNode.m @@ -0,0 +1,471 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (C) 2009 Matt Oswald + * + * Copyright (c) 2009-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. + * + */ + + +#import "ccConfig.h" +#import "CCSprite.h" +#import "CCSpriteBatchNode.h" +#import "CCGrid.h" +#import "CCDrawingPrimitives.h" +#import "CCTextureCache.h" +#import "Support/CGPointExtension.h" + +const NSUInteger defaultCapacity = 29; + +#pragma mark - +#pragma mark CCSpriteBatchNode + +static SEL selUpdate = NULL; + +@interface CCSpriteBatchNode (private) +-(void) updateBlendFunc; +@end + +@implementation CCSpriteBatchNode + +@synthesize textureAtlas = textureAtlas_; +@synthesize blendFunc = blendFunc_; +@synthesize descendants = descendants_; + + ++(void) initialize +{ + if ( self == [CCSpriteBatchNode class] ) { + selUpdate = @selector(updateTransform); + } +} +/* + * creation with CCTexture2D + */ ++(id)batchNodeWithTexture:(CCTexture2D *)tex +{ + return [[[self alloc] initWithTexture:tex capacity:defaultCapacity] autorelease]; +} + ++(id)batchNodeWithTexture:(CCTexture2D *)tex capacity:(NSUInteger)capacity +{ + return [[[self alloc] initWithTexture:tex capacity:capacity] autorelease]; +} + +/* + * creation with File Image + */ ++(id)batchNodeWithFile:(NSString*)fileImage capacity:(NSUInteger)capacity +{ + return [[[self alloc] initWithFile:fileImage capacity:capacity] autorelease]; +} + ++(id)batchNodeWithFile:(NSString*) imageFile +{ + return [[[self alloc] initWithFile:imageFile capacity:defaultCapacity] autorelease]; +} + +/* + * init with CCTexture2D + */ +-(id)initWithTexture:(CCTexture2D *)tex capacity:(NSUInteger)capacity +{ + if( (self=[super init])) { + + blendFunc_.src = CC_BLEND_SRC; + blendFunc_.dst = CC_BLEND_DST; + textureAtlas_ = [[CCTextureAtlas alloc] initWithTexture:tex capacity:capacity]; + + [self updateBlendFunc]; + + // no lazy alloc in this node + children_ = [[CCArray alloc] initWithCapacity:capacity]; + descendants_ = [[CCArray alloc] initWithCapacity:capacity]; + } + + return self; +} + +/* + * init with FileImage + */ +-(id)initWithFile:(NSString *)fileImage capacity:(NSUInteger)capacity +{ + CCTexture2D *tex = [[CCTextureCache sharedTextureCache] addImage:fileImage]; + return [self initWithTexture:tex capacity:capacity]; +} + +- (NSString*) description +{ + return [NSString stringWithFormat:@"<%@ = %08X | Tag = %i>", [self class], self, tag_ ]; +} + +-(void)dealloc +{ + [textureAtlas_ release]; + [descendants_ release]; + + [super dealloc]; +} + +#pragma mark CCSpriteBatchNode - composition + +// override visit. +// Don't call visit on it's children +-(void) visit +{ + + // CAREFUL: + // This visit is almost identical to CocosNode#visit + // with the exception that it doesn't call visit on it's children + // + // The alternative is to have a void CCSprite#visit, but + // although this is less mantainable, is faster + // + if (!visible_) + return; + + glPushMatrix(); + + if ( grid_ && grid_.active) { + [grid_ beforeDraw]; + [self transformAncestors]; + } + + [self transform]; + + [self draw]; + + if ( grid_ && grid_.active) + [grid_ afterDraw:self]; + + glPopMatrix(); +} + + +// override addChild: +-(void) addChild:(CCSprite*)child z:(NSInteger)z tag:(NSInteger) aTag +{ + NSAssert( child != nil, @"Argument must be non-nil"); + NSAssert( [child isKindOfClass:[CCSprite class]], @"CCSpriteBatchNode only supports CCSprites as children"); + NSAssert( child.texture.name == textureAtlas_.texture.name, @"CCSprite is not using the same texture id"); + + [super addChild:child z:z tag:aTag]; + + NSUInteger index = [self atlasIndexForChild:child atZ:z]; + [self insertChild:child inAtlasAtIndex:index]; +} + +// override reorderChild +-(void) reorderChild:(CCSprite*)child z:(NSInteger)z +{ + NSAssert( child != nil, @"Child must be non-nil"); + NSAssert( [children_ containsObject:child], @"Child doesn't belong to Sprite" ); + + if( z == child.zOrder ) + return; + + // XXX: Instead of removing/adding, it is more efficient to reorder manually + [child retain]; + [self removeChild:child cleanup:NO]; + [self addChild:child z:z]; + [child release]; +} + +// override removeChild: +-(void)removeChild: (CCSprite *)sprite cleanup:(BOOL)doCleanup +{ + // explicit nil handling + if (sprite == nil) + return; + + NSAssert([children_ containsObject:sprite], @"CCSpriteBatchNode doesn't contain the sprite. Can't remove it"); + + // cleanup before removing + [self removeSpriteFromAtlas:sprite]; + + [super removeChild:sprite cleanup:doCleanup]; +} + +-(void)removeChildAtIndex:(NSUInteger)index cleanup:(BOOL)doCleanup +{ + [self removeChild:(CCSprite *)[children_ objectAtIndex:index] cleanup:doCleanup]; +} + +-(void)removeAllChildrenWithCleanup:(BOOL)doCleanup +{ + // Invalidate atlas index. issue #569 + [children_ makeObjectsPerformSelector:@selector(useSelfRender)]; + + [super removeAllChildrenWithCleanup:doCleanup]; + + [descendants_ removeAllObjects]; + [textureAtlas_ removeAllQuads]; +} + +#pragma mark CCSpriteBatchNode - draw +-(void) draw +{ + [super draw]; + + // Optimization: Fast Dispatch + if( textureAtlas_.totalQuads == 0 ) + return; + + CCSprite *child; + ccArray *array = descendants_->data; + + NSUInteger i = array->num; + id *arr = array->arr; + + if( i > 0 ) { + + while (i-- > 0) { + child = *arr++; + + // fast dispatch + child->updateMethod(child, selUpdate); + +#if CC_SPRITEBATCHNODE_DEBUG_DRAW + //Issue #528 + CGRect rect = [child boundingBox]; + CGPoint vertices[4]={ + ccp(rect.origin.x,rect.origin.y), + ccp(rect.origin.x+rect.size.width,rect.origin.y), + ccp(rect.origin.x+rect.size.width,rect.origin.y+rect.size.height), + ccp(rect.origin.x,rect.origin.y+rect.size.height), + }; + ccDrawPoly(vertices, 4, YES); +#endif // CC_SPRITEBATCHNODE_DEBUG_DRAW + } + } + + // Default GL states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY + // Needed states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY + // Unneeded states: - + + BOOL newBlend = blendFunc_.src != CC_BLEND_SRC || blendFunc_.dst != CC_BLEND_DST; + if( newBlend ) + glBlendFunc( blendFunc_.src, blendFunc_.dst ); + + [textureAtlas_ drawQuads]; + if( newBlend ) + glBlendFunc(CC_BLEND_SRC, CC_BLEND_DST); +} + +#pragma mark CCSpriteBatchNode - private +-(void) increaseAtlasCapacity +{ + // if we're going beyond the current TextureAtlas's capacity, + // all the previously initialized sprites will need to redo their texture coords + // this is likely computationally expensive + NSUInteger quantity = (textureAtlas_.capacity + 1) * 4 / 3; + + CCLOG(@"cocos2d: CCSpriteBatchNode: resizing TextureAtlas capacity from [%lu] to [%lu].", + (long)textureAtlas_.capacity, + (long)quantity); + + + if( ! [textureAtlas_ resizeCapacity:quantity] ) { + // serious problems + CCLOG(@"cocos2d: WARNING: Not enough memory to resize the atlas"); + NSAssert(NO,@"XXX: CCSpriteBatchNode#increaseAtlasCapacity SHALL handle this assert"); + } +} + + +#pragma mark CCSpriteBatchNode - Atlas Index Stuff + +-(NSUInteger) rebuildIndexInOrder:(CCSprite*)node atlasIndex:(NSUInteger)index +{ + CCSprite *sprite; + CCARRAY_FOREACH(node.children, sprite){ + if( sprite.zOrder < 0 ) + index = [self rebuildIndexInOrder:sprite atlasIndex:index]; + } + + // ignore self (batch node) + if( ! [node isEqual:self]) { + node.atlasIndex = index; + index++; + } + + CCARRAY_FOREACH(node.children, sprite){ + if( sprite.zOrder >= 0 ) + index = [self rebuildIndexInOrder:sprite atlasIndex:index]; + } + + return index; +} + +-(NSUInteger) highestAtlasIndexInChild:(CCSprite*)sprite +{ + CCArray *array = [sprite children]; + NSUInteger count = [array count]; + if( count == 0 ) + return sprite.atlasIndex; + else + return [self highestAtlasIndexInChild:[array lastObject]]; +} + +-(NSUInteger) lowestAtlasIndexInChild:(CCSprite*)sprite +{ + CCArray *array = [sprite children]; + NSUInteger count = [array count]; + if( count == 0 ) + return sprite.atlasIndex; + else + return [self lowestAtlasIndexInChild:[array objectAtIndex:0] ]; +} + + +-(NSUInteger)atlasIndexForChild:(CCSprite*)sprite atZ:(NSInteger)z +{ + CCArray *brothers = [[sprite parent] children]; + NSUInteger childIndex = [brothers indexOfObject:sprite]; + + // ignore parent Z if parent is batchnode + BOOL ignoreParent = ( sprite.parent == self ); + CCSprite *previous = nil; + if( childIndex > 0 ) + previous = [brothers objectAtIndex:childIndex-1]; + + // first child of the sprite sheet + if( ignoreParent ) { + if( childIndex == 0 ) + return 0; + // else + return [self highestAtlasIndexInChild: previous] + 1; + } + + // parent is a CCSprite, so, it must be taken into account + + // first child of an CCSprite ? + if( childIndex == 0 ) + { + CCSprite *p = (CCSprite*) sprite.parent; + + // less than parent and brothers + if( z < 0 ) + return p.atlasIndex; + else + return p.atlasIndex+1; + + } else { + // previous & sprite belong to the same branch + if( ( previous.zOrder < 0 && z < 0 )|| (previous.zOrder >= 0 && z >= 0) ) + return [self highestAtlasIndexInChild:previous] + 1; + + // else (previous < 0 and sprite >= 0 ) + CCSprite *p = (CCSprite*) sprite.parent; + return p.atlasIndex + 1; + } + + NSAssert( NO, @"Should not happen. Error calculating Z on Batch Node"); + return 0; +} + +#pragma mark CCSpriteBatchNode - add / remove / reorder helper methods +// add child helper +-(void) insertChild:(CCSprite*)sprite inAtlasAtIndex:(NSUInteger)index +{ + [sprite useBatchNode:self]; + [sprite setAtlasIndex:index]; + [sprite setDirty: YES]; + + if(textureAtlas_.totalQuads == textureAtlas_.capacity) + [self increaseAtlasCapacity]; + + ccV3F_C4B_T2F_Quad quad = [sprite quad]; + [textureAtlas_ insertQuad:&quad atIndex:index]; + + ccArray *descendantsData = descendants_->data; + + ccArrayInsertObjectAtIndex(descendantsData, sprite, index); + + // update indices + NSUInteger i = index+1; + CCSprite *child; + for(; inum; i++){ + child = descendantsData->arr[i]; + child.atlasIndex = child.atlasIndex + 1; + } + + // add children recursively + CCARRAY_FOREACH(sprite.children, child){ + NSUInteger idx = [self atlasIndexForChild:child atZ: child.zOrder]; + [self insertChild:child inAtlasAtIndex:idx]; + } +} + +// remove child helper +-(void) removeSpriteFromAtlas:(CCSprite*)sprite +{ + // remove from TextureAtlas + [textureAtlas_ removeQuadAtIndex:sprite.atlasIndex]; + + // Cleanup sprite. It might be reused (issue #569) + [sprite useSelfRender]; + + ccArray *descendantsData = descendants_->data; + NSUInteger index = ccArrayGetIndexOfObject(descendantsData, sprite); + if( index != NSNotFound ) { + ccArrayRemoveObjectAtIndex(descendantsData, index); + + // update all sprites beyond this one + NSUInteger count = descendantsData->num; + + for(; index < count; index++) + { + CCSprite *s = descendantsData->arr[index]; + s.atlasIndex = s.atlasIndex - 1; + } + } + + // remove children recursively + CCSprite *child; + CCARRAY_FOREACH(sprite.children, child) + [self removeSpriteFromAtlas:child]; +} + +#pragma mark CCSpriteBatchNode - CocosNodeTexture protocol + +-(void) updateBlendFunc +{ + if( ! [textureAtlas_.texture hasPremultipliedAlpha] ) { + blendFunc_.src = GL_SRC_ALPHA; + blendFunc_.dst = GL_ONE_MINUS_SRC_ALPHA; + } +} + +-(void) setTexture:(CCTexture2D*)texture +{ + textureAtlas_.texture = texture; + [self updateBlendFunc]; +} + +-(CCTexture2D*) texture +{ + return textureAtlas_.texture; +} +@end diff --git a/tweejump/libs/cocos2d/CCSpriteFrame.h b/tweejump/libs/cocos2d/CCSpriteFrame.h new file mode 100755 index 0000000..983aeed --- /dev/null +++ b/tweejump/libs/cocos2d/CCSpriteFrame.h @@ -0,0 +1,90 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-2011 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. + * + */ + +#import +#import "CCNode.h" +#import "CCProtocols.h" + +/** A CCSpriteFrame has: + - texture: A CCTexture2D that will be used by the CCSprite + - rectangle: A rectangle of the texture + + + You can modify the frame of a CCSprite by doing: + + CCSpriteFrame *frame = [CCSpriteFrame frameWithTexture:texture rect:rect offset:offset]; + [sprite setDisplayFrame:frame]; + */ +@interface CCSpriteFrame : NSObject +{ + CGRect rect_; + CGRect rectInPixels_; + BOOL rotated_; + CGPoint offsetInPixels_; + CGSize originalSizeInPixels_; + CCTexture2D *texture_; +} +/** rect of the frame in points. If it is updated, then rectInPixels will be updated too. */ +@property (nonatomic,readwrite) CGRect rect; + +/** rect of the frame in pixels. If it is updated, then rect (points) will be udpated too. */ +@property (nonatomic,readwrite) CGRect rectInPixels; + +/** whether or not the rect of the frame is rotated ( x = x+width, y = y+height, width = height, height = width ) */ +@property (nonatomic,readwrite) BOOL rotated; + +/** offset of the frame in pixels */ +@property (nonatomic,readwrite) CGPoint offsetInPixels; + +/** original size of the trimmed image in pixels */ +@property (nonatomic,readwrite) CGSize originalSizeInPixels; + +/** texture of the frame */ +@property (nonatomic, retain, readwrite) CCTexture2D *texture; + +/** Create a CCSpriteFrame with a texture, rect in points. + It is assumed that the frame was not trimmed. + */ ++(id) frameWithTexture:(CCTexture2D*)texture rect:(CGRect)rect; + +/** Create a CCSpriteFrame with a texture, rect, rotated, offset and originalSize in pixels. + The originalSize is the size in points of the frame before being trimmed. + */ ++(id) frameWithTexture:(CCTexture2D*)texture rectInPixels:(CGRect)rect rotated:(BOOL)rotated offset:(CGPoint)offset originalSize:(CGSize)originalSize; + + +/** Initializes a CCSpriteFrame with a texture, rect in points; + It is assumed that the frame was not trimmed. + */ +-(id) initWithTexture:(CCTexture2D*)texture rect:(CGRect)rect; + +/** Initializes a CCSpriteFrame with a texture, rect, rotated, offset and originalSize in pixels. + The originalSize is the size in points of the frame before being trimmed. + */ +-(id) initWithTexture:(CCTexture2D*)texture rectInPixels:(CGRect)rect rotated:(BOOL)rotated offset:(CGPoint)offset originalSize:(CGSize)originalSize; + +@end + diff --git a/tweejump/libs/cocos2d/CCSpriteFrame.m b/tweejump/libs/cocos2d/CCSpriteFrame.m new file mode 100755 index 0000000..e9ebd04 --- /dev/null +++ b/tweejump/libs/cocos2d/CCSpriteFrame.m @@ -0,0 +1,111 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-2011 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. + * + */ + + +#import "CCTextureCache.h" +#import "CCSpriteFrame.h" +#import "ccMacros.h" + +@implementation CCSpriteFrame +@synthesize rotated = rotated_, offsetInPixels = offsetInPixels_, texture = texture_; +@synthesize originalSizeInPixels=originalSizeInPixels_; + ++(id) frameWithTexture:(CCTexture2D*)texture rect:(CGRect)rect +{ + return [[[self alloc] initWithTexture:texture rect:rect] autorelease]; +} + ++(id) frameWithTexture:(CCTexture2D*)texture rectInPixels:(CGRect)rect rotated:(BOOL)rotated offset:(CGPoint)offset originalSize:(CGSize)originalSize +{ + return [[[self alloc] initWithTexture:texture rectInPixels:rect rotated:rotated offset:offset originalSize:originalSize] autorelease]; +} + +-(id) initWithTexture:(CCTexture2D*)texture rect:(CGRect)rect +{ + CGRect rectInPixels = CC_RECT_POINTS_TO_PIXELS( rect ); + return [self initWithTexture:texture rectInPixels:rectInPixels rotated:NO offset:CGPointZero originalSize:rectInPixels.size]; +} + +-(id) initWithTexture:(CCTexture2D*)texture rectInPixels:(CGRect)rect rotated:(BOOL)rotated offset:(CGPoint)offset originalSize:(CGSize)originalSize +{ + if( (self=[super init]) ) { + self.texture = texture; + rectInPixels_ = rect; + rect_ = CC_RECT_PIXELS_TO_POINTS( rect ); + rotated_ = rotated; + offsetInPixels_ = offset; + originalSizeInPixels_ = originalSize; + } + return self; +} + +- (NSString*) description +{ + return [NSString stringWithFormat:@"<%@ = %08X | TextureName=%d, Rect = (%.2f,%.2f,%.2f,%.2f)> rotated:%d", [self class], self, + texture_.name, + rect_.origin.x, + rect_.origin.y, + rect_.size.width, + rect_.size.height, + rotated_ + ]; +} + +- (void) dealloc +{ + CCLOGINFO( @"cocos2d: deallocing %@",self); + [texture_ release]; + [super dealloc]; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCSpriteFrame *copy = [[[self class] allocWithZone: zone] initWithTexture:texture_ rectInPixels:rectInPixels_ rotated:rotated_ offset:offsetInPixels_ originalSize:originalSizeInPixels_]; + return copy; +} + +-(CGRect) rect +{ + return rect_; +} + +-(CGRect) rectInPixels +{ + return rectInPixels_; +} + +-(void) setRect:(CGRect)rect +{ + rect_ = rect; + rectInPixels_ = CC_RECT_POINTS_TO_PIXELS( rect_ ); +} + +-(void) setRectInPixels:(CGRect)rectInPixels +{ + rectInPixels_ = rectInPixels; + rect_ = CC_RECT_PIXELS_TO_POINTS(rectInPixels); +} +@end diff --git a/tweejump/libs/cocos2d/CCSpriteFrameCache.h b/tweejump/libs/cocos2d/CCSpriteFrameCache.h new file mode 100755 index 0000000..67504d8 --- /dev/null +++ b/tweejump/libs/cocos2d/CCSpriteFrameCache.h @@ -0,0 +1,130 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2009 Jason Booth + * + * Copyright (c) 2009 Robert J Payne + * + * Copyright (c) 2008-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. + * + */ + + +/* + * To create sprite frames and texture atlas, use this tool: + * http://zwoptex.zwopple.com/ + */ + +#import + +#import "CCSpriteFrame.h" +#import "CCTexture2D.h" + +@class CCSprite; + +/** Singleton that handles the loading of the sprite frames. + It saves in a cache the sprite frames. + @since v0.9 + */ +@interface CCSpriteFrameCache : NSObject +{ + NSMutableDictionary *spriteFrames_; + NSMutableDictionary *spriteFramesAliases_; +} + +/** Retruns ths shared instance of the Sprite Frame cache */ ++ (CCSpriteFrameCache *) sharedSpriteFrameCache; + +/** Purges the cache. It releases all the Sprite Frames and the retained instance. + */ ++(void)purgeSharedSpriteFrameCache; + + +/** Adds multiple Sprite Frames with a dictionary. The texture will be associated with the created sprite frames. + */ +-(void) addSpriteFramesWithDictionary:(NSDictionary*)dictionary texture:(CCTexture2D*)texture; + +/** 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 + * If you want to use another texture, you should use the addSpriteFramesWithFile:texture method. + */ +-(void) addSpriteFramesWithFile:(NSString*)plist; + +/** Adds multiple Sprite Frames from a plist file. The texture will be associated with the created sprite frames. + */ +-(void) addSpriteFramesWithFile:(NSString*)plist texture:(CCTexture2D*)texture; + +/** Adds multiple Sprite Frames from a plist file. The texture will be associated with the created sprite frames. + @since v0.99.5 + */ +-(void) addSpriteFramesWithFile:(NSString*)plist textureFile:(NSString*)textureFileName; + +/** Adds an sprite frame with a given name. + If the name already exists, then the contents of the old name will be replaced with the new one. + */ +-(void) addSpriteFrame:(CCSpriteFrame*)frame name:(NSString*)frameName; + + +/** Purges the dictionary of loaded sprite frames. + * Call this method if you receive the "Memory Warning". + * In the short term: it will free some resources preventing your app from being killed. + * In the medium term: it will allocate more resources. + * In the long term: it will be the same. + */ +-(void) removeSpriteFrames; + +/** Removes unused sprite frames. + * Sprite Frames that have a retain count of 1 will be deleted. + * It is convinient to call this method after when starting a new Scene. + */ +-(void) removeUnusedSpriteFrames; + +/** Deletes an sprite frame from the sprite frame cache. + */ +-(void) removeSpriteFrameByName:(NSString*)name; + +/** Removes multiple Sprite Frames from a plist file. +* Sprite Frames stored in this file will be removed. +* It is convinient to call this method when a specific texture needs to be removed. +* @since v0.99.5 +*/ +- (void) removeSpriteFramesFromFile:(NSString*) plist; + +/** Removes multiple Sprite Frames from NSDictionary. + * @since v0.99.5 + */ +- (void) removeSpriteFramesFromDictionary:(NSDictionary*) dictionary; + +/** Removes all Sprite Frames associated with the specified textures. + * It is convinient to call this method when a specific texture needs to be removed. + * @since v0.995. + */ +- (void) removeSpriteFramesFromTexture:(CCTexture2D*) texture; + +/** Returns an Sprite Frame that was previously added. + If the name is not found it will return nil. + You should retain the returned copy if you are going to use it. + */ +-(CCSpriteFrame*) spriteFrameByName:(NSString*)name; + +@end diff --git a/tweejump/libs/cocos2d/CCSpriteFrameCache.m b/tweejump/libs/cocos2d/CCSpriteFrameCache.m new file mode 100755 index 0000000..ebed2cf --- /dev/null +++ b/tweejump/libs/cocos2d/CCSpriteFrameCache.m @@ -0,0 +1,340 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2009 Jason Booth + * + * Copyright (c) 2009 Robert J Payne + * + * Copyright (c) 2008-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. + * + */ + +/* + * To create sprite frames and texture atlas, use this tool: + * http://zwoptex.zwopple.com/ + */ + +#import "Platforms/CCNS.h" +#import "ccMacros.h" +#import "CCTextureCache.h" +#import "CCSpriteFrameCache.h" +#import "CCSpriteFrame.h" +#import "CCSprite.h" +#import "Support/CCFileUtils.h" + + +@implementation CCSpriteFrameCache + +#pragma mark CCSpriteFrameCache - Alloc, Init & Dealloc + +static CCSpriteFrameCache *sharedSpriteFrameCache_=nil; + ++ (CCSpriteFrameCache *)sharedSpriteFrameCache +{ + if (!sharedSpriteFrameCache_) + sharedSpriteFrameCache_ = [[CCSpriteFrameCache alloc] init]; + + return sharedSpriteFrameCache_; +} + ++(id)alloc +{ + NSAssert(sharedSpriteFrameCache_ == nil, @"Attempted to allocate a second instance of a singleton."); + return [super alloc]; +} + ++(void)purgeSharedSpriteFrameCache +{ + [sharedSpriteFrameCache_ release]; + sharedSpriteFrameCache_ = nil; +} + +-(id) init +{ + if( (self=[super init]) ) { + spriteFrames_ = [[NSMutableDictionary alloc] initWithCapacity: 100]; + spriteFramesAliases_ = [[NSMutableDictionary alloc] initWithCapacity:10]; + } + + return self; +} + +- (NSString*) description +{ + return [NSString stringWithFormat:@"<%@ = %08X | num of sprite frames = %i>", [self class], self, [spriteFrames_ count]]; +} + +-(void) dealloc +{ + CCLOGINFO(@"cocos2d: deallocing %@", self); + + [spriteFrames_ release]; + [spriteFramesAliases_ release]; + [super dealloc]; +} + +#pragma mark CCSpriteFrameCache - loading sprite frames + +-(void) addSpriteFramesWithDictionary:(NSDictionary*)dictionary texture:(CCTexture2D*)texture +{ + /* + Supported Zwoptex Formats: + ZWTCoordinatesFormatOptionXMLLegacy = 0, // Flash Version + ZWTCoordinatesFormatOptionXML1_0 = 1, // Desktop Version 0.0 - 0.4b + ZWTCoordinatesFormatOptionXML1_1 = 2, // Desktop Version 1.0.0 - 1.0.1 + ZWTCoordinatesFormatOptionXML1_2 = 3, // Desktop Version 1.0.2+ + */ + NSDictionary *metadataDict = [dictionary objectForKey:@"metadata"]; + NSDictionary *framesDict = [dictionary objectForKey:@"frames"]; + + int format = 0; + + // get the format + if(metadataDict != nil) + format = [[metadataDict objectForKey:@"format"] intValue]; + + // check the format + NSAssert( format >= 0 && format <= 3, @"cocos2d: WARNING: format is not supported for CCSpriteFrameCache addSpriteFramesWithDictionary:texture:"); + + + // add real frames + for(NSString *frameDictKey in framesDict) { + NSDictionary *frameDict = [framesDict objectForKey:frameDictKey]; + CCSpriteFrame *spriteFrame; + if(format == 0) { + float x = [[frameDict objectForKey:@"x"] floatValue]; + float y = [[frameDict objectForKey:@"y"] floatValue]; + float w = [[frameDict objectForKey:@"width"] floatValue]; + float h = [[frameDict objectForKey:@"height"] floatValue]; + float ox = [[frameDict objectForKey:@"offsetX"] floatValue]; + float oy = [[frameDict objectForKey:@"offsetY"] floatValue]; + int ow = [[frameDict objectForKey:@"originalWidth"] intValue]; + int oh = [[frameDict objectForKey:@"originalHeight"] intValue]; + // check ow/oh + if(!ow || !oh) + CCLOG(@"cocos2d: WARNING: originalWidth/Height not found on the CCSpriteFrame. AnchorPoint won't work as expected. Regenerate the .plist"); + + // abs ow/oh + ow = abs(ow); + oh = abs(oh); + // create frame + + spriteFrame = [[CCSpriteFrame alloc] initWithTexture:texture + rectInPixels:CGRectMake(x, y, w, h) + rotated:NO + offset:CGPointMake(ox, oy) + originalSize:CGSizeMake(ow, oh)]; + } else if(format == 1 || format == 2) { + CGRect frame = CCRectFromString([frameDict objectForKey:@"frame"]); + BOOL rotated = NO; + + // rotation + if(format == 2) + rotated = [[frameDict objectForKey:@"rotated"] boolValue]; + + CGPoint offset = CCPointFromString([frameDict objectForKey:@"offset"]); + CGSize sourceSize = CCSizeFromString([frameDict objectForKey:@"sourceSize"]); + + // create frame + spriteFrame = [[CCSpriteFrame alloc] initWithTexture:texture + rectInPixels:frame + rotated:rotated + offset:offset + originalSize:sourceSize]; + } else if(format == 3) { + // get values + CGSize spriteSize = CCSizeFromString([frameDict objectForKey:@"spriteSize"]); + CGPoint spriteOffset = CCPointFromString([frameDict objectForKey:@"spriteOffset"]); + CGSize spriteSourceSize = CCSizeFromString([frameDict objectForKey:@"spriteSourceSize"]); + CGRect textureRect = CCRectFromString([frameDict objectForKey:@"textureRect"]); + BOOL textureRotated = [[frameDict objectForKey:@"textureRotated"] boolValue]; + + // get aliases + NSArray *aliases = [frameDict objectForKey:@"aliases"]; + for(NSString *alias in aliases) { + if( [spriteFramesAliases_ objectForKey:alias] ) + CCLOG(@"cocos2d: WARNING: an alias with name %@ already exists",alias); + + [spriteFramesAliases_ setObject:frameDictKey forKey:alias]; + } + + // create frame + spriteFrame = [[CCSpriteFrame alloc] initWithTexture:texture + rectInPixels:CGRectMake(textureRect.origin.x, textureRect.origin.y, spriteSize.width, spriteSize.height) + rotated:textureRotated + offset:spriteOffset + originalSize:spriteSourceSize]; + } + + // add sprite frame + [spriteFrames_ setObject:spriteFrame forKey:frameDictKey]; + [spriteFrame release]; + } +} + +-(void) addSpriteFramesWithFile:(NSString*)plist texture:(CCTexture2D*)texture +{ + NSString *path = [CCFileUtils fullPathFromRelativePath:plist]; + NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:path]; + + [self addSpriteFramesWithDictionary:dict texture:texture]; +} + +-(void) addSpriteFramesWithFile:(NSString*)plist textureFile:(NSString*)textureFileName +{ + NSAssert( textureFileName, @"Invalid texture file name"); + CCTexture2D *texture = [[CCTextureCache sharedTextureCache] addImage:textureFileName]; + + if( texture ) + [self addSpriteFramesWithFile:plist texture:texture]; + else + CCLOG(@"cocos2d: CCSpriteFrameCache: couldn't load texture file. File not found: %@", textureFileName); +} + +-(void) addSpriteFramesWithFile:(NSString*)plist +{ + NSString *path = [CCFileUtils fullPathFromRelativePath:plist]; + NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:path]; + + NSString *texturePath = nil; + NSDictionary *metadataDict = [dict objectForKey:@"metadata"]; + if( metadataDict ) + // try to read texture file name from meta data + texturePath = [metadataDict objectForKey:@"textureFileName"]; + + + if( texturePath ) + { + // build texture path relative to plist file + NSString *textureBase = [plist stringByDeletingLastPathComponent]; + texturePath = [textureBase stringByAppendingPathComponent:texturePath]; + } else { + // build texture path by replacing file extension + texturePath = [plist stringByDeletingPathExtension]; + texturePath = [texturePath stringByAppendingPathExtension:@"png"]; + + CCLOG(@"cocos2d: CCSpriteFrameCache: Trying to use file '%@' as texture", texturePath); + } + + CCTexture2D *texture = [[CCTextureCache sharedTextureCache] addImage:texturePath]; + + if( texture ) + [self addSpriteFramesWithDictionary:dict texture:texture]; + + else + CCLOG(@"cocos2d: CCSpriteFrameCache: Couldn't load texture"); +} + +-(void) addSpriteFrame:(CCSpriteFrame*)frame name:(NSString*)frameName +{ + [spriteFrames_ setObject:frame forKey:frameName]; +} + +#pragma mark CCSpriteFrameCache - removing + +-(void) removeSpriteFrames +{ + [spriteFrames_ removeAllObjects]; + [spriteFramesAliases_ removeAllObjects]; +} + +-(void) removeUnusedSpriteFrames +{ + NSArray *keys = [spriteFrames_ allKeys]; + for( id key in keys ) { + id value = [spriteFrames_ objectForKey:key]; + if( [value retainCount] == 1 ) { + CCLOG(@"cocos2d: CCSpriteFrameCache: removing unused frame: %@", key); + [spriteFrames_ removeObjectForKey:key]; + } + } +} + +-(void) removeSpriteFrameByName:(NSString*)name +{ + // explicit nil handling + if( ! name ) + return; + + // Is this an alias ? + NSString *key = [spriteFramesAliases_ objectForKey:name]; + + if( key ) { + [spriteFrames_ removeObjectForKey:key]; + [spriteFramesAliases_ removeObjectForKey:name]; + + } else + [spriteFrames_ removeObjectForKey:name]; +} + +- (void) removeSpriteFramesFromFile:(NSString*) plist +{ + NSString *path = [CCFileUtils fullPathFromRelativePath:plist]; + NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:path]; + + [self removeSpriteFramesFromDictionary:dict]; +} + +- (void) removeSpriteFramesFromDictionary:(NSDictionary*) dictionary +{ + NSDictionary *framesDict = [dictionary objectForKey:@"frames"]; + NSMutableArray *keysToRemove=[NSMutableArray array]; + + for(NSString *frameDictKey in framesDict) + { + if ([spriteFrames_ objectForKey:frameDictKey]!=nil) + [keysToRemove addObject:frameDictKey]; + } + [spriteFrames_ removeObjectsForKeys:keysToRemove]; +} + +- (void) removeSpriteFramesFromTexture:(CCTexture2D*) texture +{ + NSMutableArray *keysToRemove=[NSMutableArray array]; + + for (NSString *spriteFrameKey in spriteFrames_) + { + if ([[spriteFrames_ valueForKey:spriteFrameKey] texture] == texture) + [keysToRemove addObject:spriteFrameKey]; + + } + [spriteFrames_ removeObjectsForKeys:keysToRemove]; +} + +#pragma mark CCSpriteFrameCache - getting + +-(CCSpriteFrame*) spriteFrameByName:(NSString*)name +{ + CCSpriteFrame *frame = [spriteFrames_ objectForKey:name]; + if( ! frame ) { + // try alias dictionary + NSString *key = [spriteFramesAliases_ objectForKey:name]; + frame = [spriteFrames_ objectForKey:key]; + + if( ! frame ) + CCLOG(@"cocos2d: CCSpriteFrameCache: Frame '%@' not found", name); + } + + return frame; +} + +@end diff --git a/tweejump/libs/cocos2d/CCTMXLayer.h b/tweejump/libs/cocos2d/CCTMXLayer.h new file mode 100755 index 0000000..477a380 --- /dev/null +++ b/tweejump/libs/cocos2d/CCTMXLayer.h @@ -0,0 +1,152 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2009-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. + * + * + * TMX Tiled Map support: + * http://www.mapeditor.org + * + */ + + +#import "CCAtlasNode.h" +#import "CCSpriteBatchNode.h" + + +@class CCTMXMapInfo; +@class CCTMXLayerInfo; +@class CCTMXTilesetInfo; + +/** CCTMXLayer represents the TMX layer. + + It is a subclass of CCSpriteBatchNode. By default the tiles are rendered using a CCTextureAtlas. + If you mofify a tile on runtime, then, that tile will become a CCSprite, otherwise no CCSprite objects are created. + The benefits of using CCSprite objects as tiles are: + - tiles (CCSprite) can be rotated/scaled/moved with a nice API + + If the layer contains a property named "cc_vertexz" with an integer (in can be positive or negative), + then all the tiles belonging to the layer will use that value as their OpenGL vertex Z for depth. + + On the other hand, if the "cc_vertexz" property has the "automatic" value, then the tiles will use an automatic vertex Z value. + Also before drawing the tiles, GL_ALPHA_TEST will be enabled, and disabled after drawing them. The used alpha func will be: + + glAlphaFunc( GL_GREATER, value ) + + "value" by default is 0, but you can change it from Tiled by adding the "cc_alpha_func" property to the layer. + The value 0 should work for most cases, but if you have tiles that are semi-transparent, then you might want to use a differnt + value, like 0.5. + + For further information, please see the programming guide: + + http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:tiled_maps + + @since v0.8.1 + */ +@interface CCTMXLayer : CCSpriteBatchNode +{ + CCTMXTilesetInfo *tileset_; + NSString *layerName_; + CGSize layerSize_; + CGSize mapTileSize_; + uint32_t *tiles_; // GID are 32 bit + NSUInteger layerOrientation_; + NSMutableArray *properties_; + + unsigned char opacity_; // TMX Layer supports opacity + + NSUInteger minGID_; + NSUInteger maxGID_; + + // Only used when vertexZ is used + NSInteger vertexZvalue_; + BOOL useAutomaticVertexZ_; + float alphaFuncValue_; + + // used for optimization + CCSprite *reusedTile_; + ccCArray *atlasIndexArray_; +} +/** name of the layer */ +@property (nonatomic,readwrite,retain) NSString *layerName; +/** size of the layer in tiles */ +@property (nonatomic,readwrite) CGSize layerSize; +/** size of the map's tile (could be differnt from the tile's size) */ +@property (nonatomic,readwrite) CGSize mapTileSize; +/** pointer to the map of tiles */ +@property (nonatomic,readwrite) uint32_t *tiles; +/** Tilset information for the layer */ +@property (nonatomic,readwrite,retain) CCTMXTilesetInfo *tileset; +/** Layer orientation, which is the same as the map orientation */ +@property (nonatomic,readwrite) NSUInteger layerOrientation; +/** properties from the layer. They can be added using Tiled */ +@property (nonatomic,readwrite,retain) NSMutableArray *properties; + +/** creates a CCTMXLayer with an tileset info, a layer info and a map info */ ++(id) layerWithTilesetInfo:(CCTMXTilesetInfo*)tilesetInfo layerInfo:(CCTMXLayerInfo*)layerInfo mapInfo:(CCTMXMapInfo*)mapInfo; +/** initializes a CCTMXLayer with a tileset info, a layer info and a map info */ +-(id) initWithTilesetInfo:(CCTMXTilesetInfo*)tilesetInfo layerInfo:(CCTMXLayerInfo*)layerInfo mapInfo:(CCTMXMapInfo*)mapInfo; + +/** dealloc the map that contains the tile position from memory. + Unless you want to know at runtime the tiles positions, you can safely call this method. + If you are going to call [layer tileGIDAt:] then, don't release the map + */ +-(void) releaseMap; + +/** returns the tile (CCSprite) at a given a tile coordinate. + The returned CCSprite will be already added to the CCTMXLayer. Don't add it again. + The CCSprite can be treated like any other CCSprite: rotated, scaled, translated, opacity, color, etc. + You can remove either by calling: + - [layer removeChild:sprite cleanup:cleanup]; + - or [layer removeTileAt:ccp(x,y)]; + */ +-(CCSprite*) tileAt:(CGPoint)tileCoordinate; + +/** returns the tile gid at a given tile coordinate. + if it returns 0, it means that the tile is empty. + This method requires the the tile map has not been previously released (eg. don't call [layer releaseMap]) + */ +-(uint32_t) tileGIDAt:(CGPoint)tileCoordinate; + +/** sets the tile gid (gid = tile global id) at a given tile coordinate. + The Tile GID can be obtained by using the method "tileGIDAt" or by using the TMX editor -> Tileset Mgr +1. + If a tile is already placed at that position, then it will be removed. + */ +-(void) setTileGID:(uint32_t)gid at:(CGPoint)tileCoordinate; + +/** removes a tile at given tile coordinate */ +-(void) removeTileAt:(CGPoint)tileCoordinate; + +/** returns the position in pixels of a given tile coordinate */ +-(CGPoint) positionAt:(CGPoint)tileCoordinate; + +/** return the value for the specific property name */ +-(id) propertyNamed:(NSString *)propertyName; + +/** Creates the tiles */ +-(void) setupTiles; + +/** CCTMXLayer doesn't support adding a CCSprite manually. + @warning addchild:z:tag: is not supported on CCTMXLayer. Instead of setTileGID:at:/tileAt: + */ +-(void) addChild: (CCNode*)node z:(NSInteger)z tag:(NSInteger)tag; +@end diff --git a/tweejump/libs/cocos2d/CCTMXLayer.m b/tweejump/libs/cocos2d/CCTMXLayer.m new file mode 100755 index 0000000..bb2ba60 --- /dev/null +++ b/tweejump/libs/cocos2d/CCTMXLayer.m @@ -0,0 +1,670 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2009-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. + * + * + * TMX Tiled Map support: + * http://www.mapeditor.org + * + */ + +#import "CCTMXLayer.h" +#import "CCTMXTiledMap.h" +#import "CCTMXXMLParser.h" +#import "CCSprite.h" +#import "CCSpriteBatchNode.h" +#import "CCTextureCache.h" +#import "Support/CGPointExtension.h" + +#pragma mark - +#pragma mark CCSpriteBatchNode Extension + +@interface CCSpriteBatchNode (TMXTiledMapExtensions) +-(id) addSpriteWithoutQuad:(CCSprite*)child z:(NSUInteger)z tag:(NSInteger)aTag; +-(void) addQuadFromSprite:(CCSprite*)sprite quadIndex:(NSUInteger)index; +@end + +/* IMPORTANT XXX IMPORTNAT: + * These 2 methods can't be part of CCTMXLayer since they call [super add...], and CCSpriteBatchNode#add SHALL not be called + */ +@implementation CCSpriteBatchNode (TMXTiledMapExtension) + +/* Adds a quad into the texture atlas but it won't be added into the children array. + This method should be called only when you are dealing with very big AtlasSrite and when most of the CCSprite won't be updated. + For example: a tile map (CCTMXMap) or a label with lots of characgers (CCLabelBMFont) + */ +-(void) addQuadFromSprite:(CCSprite*)sprite quadIndex:(NSUInteger)index +{ + NSAssert( sprite != nil, @"Argument must be non-nil"); + NSAssert( [sprite isKindOfClass:[CCSprite class]], @"CCSpriteBatchNode only supports CCSprites as children"); + + + while(index >= textureAtlas_.capacity || textureAtlas_.capacity == textureAtlas_.totalQuads ) + [self increaseAtlasCapacity]; + + // + // update the quad directly. Don't add the sprite to the scene graph + // + + [sprite useBatchNode:self]; + [sprite setAtlasIndex:index]; + + ccV3F_C4B_T2F_Quad quad = [sprite quad]; + [textureAtlas_ insertQuad:&quad atIndex:index]; + + // XXX: updateTransform will update the textureAtlas too using updateQuad. + // XXX: so, it should be AFTER the insertQuad + [sprite setDirty:YES]; + [sprite updateTransform]; +} + +/* This is the opposite of "addQuadFromSprite. + It add the sprite to the children and descendants array, but it doesn't update add it to the texture atlas + */ +-(id) addSpriteWithoutQuad:(CCSprite*)child z:(NSUInteger)z tag:(NSInteger)aTag +{ + NSAssert( child != nil, @"Argument must be non-nil"); + NSAssert( [child isKindOfClass:[CCSprite class]], @"CCSpriteBatchNode only supports CCSprites as children"); + + // quad index is Z + [child setAtlasIndex:z]; + + // XXX: optimize with a binary search + int i=0; + for( CCSprite *c in descendants_ ) { + if( c.atlasIndex >= z ) + break; + i++; + } + [descendants_ insertObject:child atIndex:i]; + + + // IMPORTANT: Call super, and not self. Avoid adding it to the texture atlas array + [super addChild:child z:z tag:aTag]; + return self; +} +@end + + +#pragma mark - +#pragma mark CCTMXLayer + +int compareInts (const void * a, const void * b); + + +@interface CCTMXLayer () +-(CGPoint) positionForIsoAt:(CGPoint)pos; +-(CGPoint) positionForOrthoAt:(CGPoint)pos; +-(CGPoint) positionForHexAt:(CGPoint)pos; + +-(CGPoint) calculateLayerOffset:(CGPoint)offset; + +/* optimization methos */ +-(CCSprite*) appendTileForGID:(uint32_t)gid at:(CGPoint)pos; +-(CCSprite*) insertTileForGID:(uint32_t)gid at:(CGPoint)pos; +-(CCSprite*) updateTileForGID:(uint32_t)gid at:(CGPoint)pos; + +/* The layer recognizes some special properties, like cc_vertez */ +-(void) parseInternalProperties; + +-(NSInteger) vertexZForPos:(CGPoint)pos; + +// index +-(NSUInteger) atlasIndexForExistantZ:(NSUInteger)z; +-(NSUInteger) atlasIndexForNewZ:(NSUInteger)z; +@end + +@implementation CCTMXLayer +@synthesize layerSize = layerSize_, layerName = layerName_, tiles = tiles_; +@synthesize tileset = tileset_; +@synthesize layerOrientation = layerOrientation_; +@synthesize mapTileSize = mapTileSize_; +@synthesize properties = properties_; + +#pragma mark CCTMXLayer - init & alloc & dealloc + ++(id) layerWithTilesetInfo:(CCTMXTilesetInfo*)tilesetInfo layerInfo:(CCTMXLayerInfo*)layerInfo mapInfo:(CCTMXMapInfo*)mapInfo +{ + return [[[self alloc] initWithTilesetInfo:tilesetInfo layerInfo:layerInfo mapInfo:mapInfo] autorelease]; +} + +-(id) initWithTilesetInfo:(CCTMXTilesetInfo*)tilesetInfo layerInfo:(CCTMXLayerInfo*)layerInfo mapInfo:(CCTMXMapInfo*)mapInfo +{ + // XXX: is 35% a good estimate ? + CGSize size = layerInfo.layerSize; + float totalNumberOfTiles = size.width * size.height; + float capacity = totalNumberOfTiles * 0.35f + 1; // 35 percent is occupied ? + + CCTexture2D *tex = nil; + if( tilesetInfo ) + tex = [[CCTextureCache sharedTextureCache] addImage:tilesetInfo.sourceImage]; + + if((self = [super initWithTexture:tex capacity:capacity])) { + + // layerInfo + self.layerName = layerInfo.name; + layerSize_ = layerInfo.layerSize; + tiles_ = layerInfo.tiles; + minGID_ = layerInfo.minGID; + maxGID_ = layerInfo.maxGID; + opacity_ = layerInfo.opacity; + self.properties = [NSMutableDictionary dictionaryWithDictionary:layerInfo.properties]; + + // tilesetInfo + self.tileset = tilesetInfo; + + // mapInfo + mapTileSize_ = mapInfo.tileSize; + layerOrientation_ = mapInfo.orientation; + + // offset (after layer orientation is set); + CGPoint offset = [self calculateLayerOffset:layerInfo.offset]; + [self setPositionInPixels:offset]; + + atlasIndexArray_ = ccCArrayNew(totalNumberOfTiles); + + [self setContentSizeInPixels: CGSizeMake( layerSize_.width * mapTileSize_.width, layerSize_.height * mapTileSize_.height )]; + + useAutomaticVertexZ_= NO; + vertexZvalue_ = 0; + alphaFuncValue_ = 0; + + } + return self; +} + +- (void) dealloc +{ + [layerName_ release]; + [tileset_ release]; + [reusedTile_ release]; + [properties_ release]; + + if( atlasIndexArray_ ) { + ccCArrayFree(atlasIndexArray_); + atlasIndexArray_ = NULL; + } + + if( tiles_ ) { + free(tiles_); + tiles_ = NULL; + } + + [super dealloc]; +} + +-(void) releaseMap +{ + if( tiles_) { + free( tiles_); + tiles_ = NULL; + } + + if( atlasIndexArray_ ) { + ccCArrayFree(atlasIndexArray_); + atlasIndexArray_ = NULL; + } +} + +#pragma mark CCTMXLayer - setup Tiles + +-(void) setupTiles +{ + // Optimization: quick hack that sets the image size on the tileset + tileset_.imageSize = [textureAtlas_.texture contentSizeInPixels]; + + // By default all the tiles are aliased + // pros: + // - easier to render + // cons: + // - difficult to scale / rotate / etc. + [textureAtlas_.texture setAliasTexParameters]; + + CFByteOrder o = CFByteOrderGetCurrent(); + + // Parse cocos2d properties + [self parseInternalProperties]; + + for( NSUInteger y=0; y < layerSize_.height; y++ ) { + for( NSUInteger x=0; x < layerSize_.width; x++ ) { + + NSUInteger pos = x + layerSize_.width * y; + uint32_t gid = tiles_[ pos ]; + + // gid are stored in little endian. + // if host is big endian, then swap + if( o == CFByteOrderBigEndian ) + gid = CFSwapInt32( gid ); + + // XXX: gid == 0 --> empty tile + if( gid != 0 ) { + [self appendTileForGID:gid at:ccp(x,y)]; + + // Optimization: update min and max GID rendered by the layer + minGID_ = MIN(gid, minGID_); + maxGID_ = MAX(gid, maxGID_); + } + } + } + + NSAssert( maxGID_ >= tileset_.firstGid && + minGID_ >= tileset_.firstGid, @"TMX: Only 1 tilset per layer is supported"); +} + +#pragma mark CCTMXLayer - Properties + +-(id) propertyNamed:(NSString *)propertyName +{ + return [properties_ valueForKey:propertyName]; +} + +-(void) parseInternalProperties +{ + // if cc_vertex=automatic, then tiles will be rendered using vertexz + + NSString *vertexz = [self propertyNamed:@"cc_vertexz"]; + if( vertexz ) { + if( [vertexz isEqualToString:@"automatic"] ) + useAutomaticVertexZ_ = YES; + else + vertexZvalue_ = [vertexz intValue]; + } + + NSString *alphaFuncVal = [self propertyNamed:@"cc_alpha_func"]; + alphaFuncValue_ = [alphaFuncVal floatValue]; +} + +#pragma mark CCTMXLayer - obtaining tiles/gids + +-(CCSprite*) tileAt:(CGPoint)pos +{ + NSAssert( pos.x < layerSize_.width && pos.y < layerSize_.height && pos.x >=0 && pos.y >=0, @"TMXLayer: invalid position"); + NSAssert( tiles_ && atlasIndexArray_, @"TMXLayer: the tiles map has been released"); + + CCSprite *tile = nil; + uint32_t gid = [self tileGIDAt:pos]; + + // if GID == 0, then no tile is present + if( gid ) { + int z = pos.x + pos.y * layerSize_.width; + tile = (CCSprite*) [self getChildByTag:z]; + + // tile not created yet. create it + if( ! tile ) { + CGRect rect = [tileset_ rectForGID:gid]; + tile = [[CCSprite alloc] initWithBatchNode:self rectInPixels:rect]; + [tile setPositionInPixels: [self positionAt:pos]]; + [tile setVertexZ: [self vertexZForPos:pos]]; + tile.anchorPoint = CGPointZero; + [tile setOpacity:opacity_]; + + NSUInteger indexForZ = [self atlasIndexForExistantZ:z]; + [self addSpriteWithoutQuad:tile z:indexForZ tag:z]; + [tile release]; + } + } + return tile; +} + +-(uint32_t) tileGIDAt:(CGPoint)pos +{ + NSAssert( pos.x < layerSize_.width && pos.y < layerSize_.height && pos.x >=0 && pos.y >=0, @"TMXLayer: invalid position"); + NSAssert( tiles_ && atlasIndexArray_, @"TMXLayer: the tiles map has been released"); + + NSInteger idx = pos.x + pos.y * layerSize_.width; + return tiles_[ idx ]; +} + +#pragma mark CCTMXLayer - adding helper methods + +-(CCSprite*) insertTileForGID:(uint32_t)gid at:(CGPoint)pos +{ + CGRect rect = [tileset_ rectForGID:gid]; + + NSInteger z = pos.x + pos.y * layerSize_.width; + + if( ! reusedTile_ ) + reusedTile_ = [[CCSprite alloc] initWithBatchNode:self rectInPixels:rect]; + else + [reusedTile_ initWithBatchNode:self rectInPixels:rect]; + + [reusedTile_ setPositionInPixels: [self positionAt:pos]]; + [reusedTile_ setVertexZ: [self vertexZForPos:pos]]; + reusedTile_.anchorPoint = CGPointZero; + [reusedTile_ setOpacity:opacity_]; + + // get atlas index + NSUInteger indexForZ = [self atlasIndexForNewZ:z]; + + // Optimization: add the quad without adding a child + [self addQuadFromSprite:reusedTile_ quadIndex:indexForZ]; + + // insert it into the local atlasindex array + ccCArrayInsertValueAtIndex(atlasIndexArray_, (void*)z, indexForZ); + + // update possible children + CCSprite *sprite; + CCARRAY_FOREACH(children_, sprite) { + NSUInteger ai = [sprite atlasIndex]; + if( ai >= indexForZ) + [sprite setAtlasIndex: ai+1]; + } + + tiles_[z] = gid; + + return reusedTile_; +} + +-(CCSprite*) updateTileForGID:(uint32_t)gid at:(CGPoint)pos +{ + CGRect rect = [tileset_ rectForGID:gid]; + + int z = pos.x + pos.y * layerSize_.width; + + if( ! reusedTile_ ) + reusedTile_ = [[CCSprite alloc] initWithBatchNode:self rectInPixels:rect]; + else + [reusedTile_ initWithBatchNode:self rectInPixels:rect]; + + [reusedTile_ setPositionInPixels: [self positionAt:pos]]; + [reusedTile_ setVertexZ: [self vertexZForPos:pos]]; + reusedTile_.anchorPoint = CGPointZero; + [reusedTile_ setOpacity:opacity_]; + + // get atlas index + NSUInteger indexForZ = [self atlasIndexForExistantZ:z]; + + [reusedTile_ setAtlasIndex:indexForZ]; + [reusedTile_ setDirty:YES]; + [reusedTile_ updateTransform]; + tiles_[z] = gid; + + return reusedTile_; +} + + +// used only when parsing the map. useless after the map was parsed +// since lot's of assumptions are no longer true +-(CCSprite*) appendTileForGID:(uint32_t)gid at:(CGPoint)pos +{ + CGRect rect = [tileset_ rectForGID:gid]; + + NSInteger z = pos.x + pos.y * layerSize_.width; + + if( ! reusedTile_ ) + reusedTile_ = [[CCSprite alloc] initWithBatchNode:self rectInPixels:rect]; + else + [reusedTile_ initWithBatchNode:self rectInPixels:rect]; + + [reusedTile_ setPositionInPixels: [self positionAt:pos]]; + [reusedTile_ setVertexZ: [self vertexZForPos:pos]]; + reusedTile_.anchorPoint = CGPointZero; + [reusedTile_ setOpacity:opacity_]; + + // optimization: + // The difference between appendTileForGID and insertTileforGID is that append is faster, since + // it appends the tile at the end of the texture atlas + NSUInteger indexForZ = atlasIndexArray_->num; + + + // don't add it using the "standard" way. + [self addQuadFromSprite:reusedTile_ quadIndex:indexForZ]; + + + // append should be after addQuadFromSprite since it modifies the quantity values + ccCArrayInsertValueAtIndex(atlasIndexArray_, (void*)z, indexForZ); + + return reusedTile_; +} + +#pragma mark CCTMXLayer - atlasIndex and Z + +int compareInts (const void * a, const void * b) +{ + return ( *(int*)a - *(int*)b ); +} + +-(NSUInteger) atlasIndexForExistantZ:(NSUInteger)z +{ + NSInteger key = z; + NSInteger *item = bsearch((void*)&key, (void*)&atlasIndexArray_->arr[0], atlasIndexArray_->num, sizeof(void*), compareInts); + + NSAssert( item, @"TMX atlas index not found. Shall not happen"); + + NSUInteger index = ((NSInteger)item - (NSInteger)atlasIndexArray_->arr) / sizeof(void*); + return index; +} + +-(NSUInteger)atlasIndexForNewZ:(NSUInteger)z +{ + // XXX: This can be improved with a sort of binary search + NSUInteger i = 0; + for(i = 0; i< atlasIndexArray_->num; i++) { + NSUInteger val = (NSUInteger) atlasIndexArray_->arr[i]; + if( z < val ) + break; + } + return i; +} + +#pragma mark CCTMXLayer - adding / remove tiles + +-(void) setTileGID:(uint32_t)gid at:(CGPoint)pos +{ + NSAssert( pos.x < layerSize_.width && pos.y < layerSize_.height && pos.x >=0 && pos.y >=0, @"TMXLayer: invalid position"); + NSAssert( tiles_ && atlasIndexArray_, @"TMXLayer: the tiles map has been released"); + NSAssert( gid == 0 || gid >= tileset_.firstGid, @"TMXLayer: invalid gid" ); + + uint32_t currentGID = [self tileGIDAt:pos]; + + if( currentGID != gid ) { + + // setting gid=0 is equal to remove the tile + if( gid == 0 ) + [self removeTileAt:pos]; + + // empty tile. create a new one + else if( currentGID == 0 ) + [self insertTileForGID:gid at:pos]; + + // modifying an existing tile with a non-empty tile + else { + + NSUInteger z = pos.x + pos.y * layerSize_.width; + id sprite = [self getChildByTag:z]; + if( sprite ) { + CGRect rect = [tileset_ rectForGID:gid]; + [sprite setTextureRectInPixels:rect rotated:NO untrimmedSize:rect.size]; + tiles_[z] = gid; + } else + [self updateTileForGID:gid at:pos]; + } + } +} + +-(void) addChild: (CCNode*)node z:(NSInteger)z tag:(NSInteger)tag +{ + NSAssert(NO, @"addChild: is not supported on CCTMXLayer. Instead use setTileGID:at:/tileAt:"); +} + +-(void) removeChild:(CCSprite*)sprite cleanup:(BOOL)cleanup +{ + // allows removing nil objects + if( ! sprite ) + return; + + NSAssert( [children_ containsObject:sprite], @"Tile does not belong to TMXLayer"); + + NSUInteger atlasIndex = [sprite atlasIndex]; + NSUInteger zz = (NSUInteger) atlasIndexArray_->arr[atlasIndex]; + tiles_[zz] = 0; + ccCArrayRemoveValueAtIndex(atlasIndexArray_, atlasIndex); + [super removeChild:sprite cleanup:cleanup]; +} + +-(void) removeTileAt:(CGPoint)pos +{ + NSAssert( pos.x < layerSize_.width && pos.y < layerSize_.height && pos.x >=0 && pos.y >=0, @"TMXLayer: invalid position"); + NSAssert( tiles_ && atlasIndexArray_, @"TMXLayer: the tiles map has been released"); + + uint32_t gid = [self tileGIDAt:pos]; + + if( gid ) { + + NSUInteger z = pos.x + pos.y * layerSize_.width; + NSUInteger atlasIndex = [self atlasIndexForExistantZ:z]; + + // remove tile from GID map + tiles_[z] = 0; + + // remove tile from atlas position array + ccCArrayRemoveValueAtIndex(atlasIndexArray_, atlasIndex); + + // remove it from sprites and/or texture atlas + id sprite = [self getChildByTag:z]; + if( sprite ) + [super removeChild:sprite cleanup:YES]; + else { + [textureAtlas_ removeQuadAtIndex:atlasIndex]; + + // update possible children + CCARRAY_FOREACH(children_, sprite) { + NSUInteger ai = [sprite atlasIndex]; + if( ai >= atlasIndex) { + [sprite setAtlasIndex: ai-1]; + } + } + } + } +} + +#pragma mark CCTMXLayer - obtaining positions, offset + +-(CGPoint) calculateLayerOffset:(CGPoint)pos +{ + CGPoint ret = CGPointZero; + switch( layerOrientation_ ) { + case CCTMXOrientationOrtho: + ret = ccp( pos.x * mapTileSize_.width, -pos.y *mapTileSize_.height); + break; + case CCTMXOrientationIso: + ret = ccp( (mapTileSize_.width /2) * (pos.x - pos.y), + (mapTileSize_.height /2 ) * (-pos.x - pos.y) ); + break; + case CCTMXOrientationHex: + NSAssert(CGPointEqualToPoint(pos, CGPointZero), @"offset for hexagonal map not implemented yet"); + break; + } + return ret; +} + +-(CGPoint) positionAt:(CGPoint)pos +{ + CGPoint ret = CGPointZero; + switch( layerOrientation_ ) { + case CCTMXOrientationOrtho: + ret = [self positionForOrthoAt:pos]; + break; + case CCTMXOrientationIso: + ret = [self positionForIsoAt:pos]; + break; + case CCTMXOrientationHex: + ret = [self positionForHexAt:pos]; + break; + } + return ret; +} + +-(CGPoint) positionForOrthoAt:(CGPoint)pos +{ + CGPoint xy = { + pos.x * mapTileSize_.width, + (layerSize_.height - pos.y - 1) * mapTileSize_.height, + }; + return xy; +} + +-(CGPoint) positionForIsoAt:(CGPoint)pos +{ + CGPoint xy = { + mapTileSize_.width /2 * ( layerSize_.width + pos.x - pos.y - 1), + mapTileSize_.height /2 * (( layerSize_.height * 2 - pos.x - pos.y) - 2), + }; + return xy; +} + +-(CGPoint) positionForHexAt:(CGPoint)pos +{ + float diffY = 0; + if( (int)pos.x % 2 == 1 ) + diffY = -mapTileSize_.height/2 ; + + CGPoint xy = { + pos.x * mapTileSize_.width*3/4, + (layerSize_.height - pos.y - 1) * mapTileSize_.height + diffY + }; + return xy; +} + +-(NSInteger) vertexZForPos:(CGPoint)pos +{ + NSInteger ret = 0; + NSUInteger maxVal = 0; + if( useAutomaticVertexZ_ ) { + switch( layerOrientation_ ) { + case CCTMXOrientationIso: + maxVal = layerSize_.width + layerSize_.height; + ret = -(maxVal - (pos.x + pos.y)); + break; + case CCTMXOrientationOrtho: + ret = -(layerSize_.height-pos.y); + break; + case CCTMXOrientationHex: + NSAssert(NO,@"TMX Hexa zOrder not supported"); + break; + default: + NSAssert(NO,@"TMX invalid value"); + break; + } + } else + ret = vertexZvalue_; + + return ret; +} + +#pragma mark CCTMXLayer - draw + +-(void) draw +{ + if( useAutomaticVertexZ_ ) { + glEnable(GL_ALPHA_TEST); + glAlphaFunc(GL_GREATER, alphaFuncValue_); + } + + [super draw]; + + if( useAutomaticVertexZ_ ) + glDisable(GL_ALPHA_TEST); +} +@end + diff --git a/tweejump/libs/cocos2d/CCTMXObjectGroup.h b/tweejump/libs/cocos2d/CCTMXObjectGroup.h new file mode 100755 index 0000000..02feadf --- /dev/null +++ b/tweejump/libs/cocos2d/CCTMXObjectGroup.h @@ -0,0 +1,67 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2010 Neophit + * + * 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. + * + * + * TMX Tiled Map support: + * http://www.mapeditor.org + * + */ + +#import "CCNode.h" + + +@class CCTMXObjectGroup; + + +/** CCTMXObjectGroup represents the TMX object group. +@since v0.99.0 +*/ +@interface CCTMXObjectGroup : NSObject +{ + NSString *groupName_; + CGPoint positionOffset_; + NSMutableArray *objects_; + NSMutableDictionary *properties_; +} + +/** name of the group */ +@property (nonatomic,readwrite,retain) NSString *groupName; +/** offset position of child objects */ +@property (nonatomic,readwrite,assign) CGPoint positionOffset; +/** array of the objects */ +@property (nonatomic,readwrite,retain) NSMutableArray *objects; +/** list of properties stored in a dictionary */ +@property (nonatomic,readwrite,retain) NSMutableDictionary *properties; + +/** return the value for the specific property name */ +-(id) propertyNamed:(NSString *)propertyName; + +/** return the dictionary for the specific object name. + It will return the 1st object found on the array for the given name. + */ +-(NSMutableDictionary*) objectNamed:(NSString *)objectName; + +@end diff --git a/tweejump/libs/cocos2d/CCTMXObjectGroup.m b/tweejump/libs/cocos2d/CCTMXObjectGroup.m new file mode 100755 index 0000000..648cda4 --- /dev/null +++ b/tweejump/libs/cocos2d/CCTMXObjectGroup.m @@ -0,0 +1,86 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2010 Neophit + * + * 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. + * + * + * TMX Tiled Map support: + * http://www.mapeditor.org + * + */ + +#import "CCTMXObjectGroup.h" +#import "CCTMXXMLParser.h" +#import "ccMacros.h" +#import "Support/CGPointExtension.h" + + +#pragma mark - +#pragma mark TMXObjectGroup + +@implementation CCTMXObjectGroup + +@synthesize groupName = groupName_; +@synthesize objects = objects_; +@synthesize positionOffset = positionOffset_; +@synthesize properties = properties_; + +-(id) init +{ + if (( self=[super init] )) { + self.groupName = nil; + self.positionOffset = CGPointZero; + self.objects = [NSMutableArray arrayWithCapacity:10]; + self.properties = [NSMutableDictionary dictionaryWithCapacity:5]; + } + return self; +} + +-(void) dealloc +{ + CCLOGINFO( @"cocos2d: deallocing %@", self ); + + [groupName_ release]; + [objects_ release]; + [properties_ release]; + [super dealloc]; +} + +-(NSMutableDictionary*) objectNamed:(NSString *)objectName +{ + for( id object in objects_ ) { + if( [[object valueForKey:@"name"] isEqual:objectName] ) + return object; + } + + // object not found + return nil; +} + +-(id) propertyNamed:(NSString *)propertyName +{ + return [properties_ valueForKey:propertyName]; +} + +@end diff --git a/tweejump/libs/cocos2d/CCTMXTiledMap.h b/tweejump/libs/cocos2d/CCTMXTiledMap.h new file mode 100755 index 0000000..4f4641a --- /dev/null +++ b/tweejump/libs/cocos2d/CCTMXTiledMap.h @@ -0,0 +1,140 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2009-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. + * + * + * TMX Tiled Map support: + * http://www.mapeditor.org + * + */ + +#import "CCNode.h" + + +@class CCTMXLayer; +@class CCTMXObjectGroup; + +/** Possible oritentations of the TMX map */ +enum +{ + /** Orthogonal orientation */ + CCTMXOrientationOrtho, + + /** Hexagonal orientation */ + CCTMXOrientationHex, + + /** Isometric orientation */ + CCTMXOrientationIso, +}; + +/** CCTMXTiledMap knows how to parse and render a TMX map. + + It adds support for the TMX tiled map format used by http://www.mapeditor.org + It supports isometric, hexagonal and orthogonal tiles. + It also supports object groups, objects, and properties. + + Features: + - Each tile will be treated as an CCSprite + - The sprites are created on demand. They will be created only when you call "[layer tileAt:]" + - Each tile can be rotated / moved / scaled / tinted / "opacitied", since each tile is a CCSprite + - Tiles can be added/removed in runtime + - The z-order of the tiles can be modified in runtime + - Each tile has an anchorPoint of (0,0) + - The anchorPoint of the TMXTileMap is (0,0) + - The TMX layers will be added as a child + - The TMX layers will be aliased by default + - The tileset image will be loaded using the CCTextureCache + - Each tile will have a unique tag + - Each tile will have a unique z value. top-left: z=1, bottom-right: z=max z + - Each object group will be treated as an NSMutableArray + - Object class which will contain all the properties in a dictionary + - Properties can be assigned to the Map, Layer, Object Group, and Object + + Limitations: + - It only supports one tileset per layer. + - Embeded images are not supported + - It only supports the XML format (the JSON format is not supported) + + Technical description: + Each layer is created using an CCTMXLayer (subclass of CCSpriteBatchNode). If you have 5 layers, then 5 CCTMXLayer will be created, + unless the layer visibility is off. In that case, the layer won't be created at all. + You can obtain the layers (CCTMXLayer objects) at runtime by: + - [map getChildByTag: tag_number]; // 0=1st layer, 1=2nd layer, 2=3rd layer, etc... + - [map layerNamed: name_of_the_layer]; + + Each object group is created using a CCTMXObjectGroup which is a subclass of NSMutableArray. + You can obtain the object groups at runtime by: + - [map objectGroupNamed: name_of_the_object_group]; + + Each object is a CCTMXObject. + + Each property is stored as a key-value pair in an NSMutableDictionary. + You can obtain the properties at runtime by: + + [map propertyNamed: name_of_the_property]; + [layer propertyNamed: name_of_the_property]; + [objectGroup propertyNamed: name_of_the_property]; + [object propertyNamed: name_of_the_property]; + + @since v0.8.1 + */ +@interface CCTMXTiledMap : CCNode +{ + CGSize mapSize_; + CGSize tileSize_; + int mapOrientation_; + NSMutableArray *objectGroups_; + NSMutableDictionary *properties_; + NSMutableDictionary *tileProperties_; +} + +/** the map's size property measured in tiles */ +@property (nonatomic,readonly) CGSize mapSize; +/** the tiles's size property measured in pixels */ +@property (nonatomic,readonly) CGSize tileSize; +/** map orientation */ +@property (nonatomic,readonly) int mapOrientation; +/** object groups */ +@property (nonatomic,readwrite,retain) NSMutableArray *objectGroups; +/** properties */ +@property (nonatomic,readwrite,retain) NSMutableDictionary *properties; + +/** creates a TMX Tiled Map with a TMX file.*/ ++(id) tiledMapWithTMXFile:(NSString*)tmxFile; + +/** initializes a TMX Tiled Map with a TMX file */ +-(id) initWithTMXFile:(NSString*)tmxFile; + +/** return the TMXLayer for the specific layer */ +-(CCTMXLayer*) layerNamed:(NSString *)layerName; + +/** return the TMXObjectGroup for the secific group */ +-(CCTMXObjectGroup*) objectGroupNamed:(NSString *)groupName; + +/** return the value for the specific property name */ +-(id) propertyNamed:(NSString *)propertyName; + +/** return properties dictionary for tile GID */ +-(NSDictionary*)propertiesForGID:(unsigned int)GID; +@end + diff --git a/tweejump/libs/cocos2d/CCTMXTiledMap.m b/tweejump/libs/cocos2d/CCTMXTiledMap.m new file mode 100755 index 0000000..3afba49 --- /dev/null +++ b/tweejump/libs/cocos2d/CCTMXTiledMap.m @@ -0,0 +1,195 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2009-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. + * + * + * TMX Tiled Map support: + * http://www.mapeditor.org + * + */ + +#import "CCTMXTiledMap.h" +#import "CCTMXXMLParser.h" +#import "CCTMXLayer.h" +#import "CCTMXObjectGroup.h" +#import "CCSprite.h" +#import "CCTextureCache.h" +#import "Support/CGPointExtension.h" + + +#pragma mark - +#pragma mark CCTMXTiledMap + +@interface CCTMXTiledMap (Private) +-(id) parseLayer:(CCTMXLayerInfo*)layer map:(CCTMXMapInfo*)mapInfo; +-(CCTMXTilesetInfo*) tilesetForLayer:(CCTMXLayerInfo*)layerInfo map:(CCTMXMapInfo*)mapInfo; +@end + +@implementation CCTMXTiledMap +@synthesize mapSize = mapSize_; +@synthesize tileSize = tileSize_; +@synthesize mapOrientation = mapOrientation_; +@synthesize objectGroups = objectGroups_; +@synthesize properties = properties_; + ++(id) tiledMapWithTMXFile:(NSString*)tmxFile +{ + return [[[self alloc] initWithTMXFile:tmxFile] autorelease]; +} + +-(id) initWithTMXFile:(NSString*)tmxFile +{ + NSAssert(tmxFile != nil, @"TMXTiledMap: tmx file should not bi nil"); + + if ((self=[super init])) { + + [self setContentSize:CGSizeZero]; + + CCTMXMapInfo *mapInfo = [CCTMXMapInfo formatWithTMXFile:tmxFile]; + + NSAssert( [mapInfo.tilesets count] != 0, @"TMXTiledMap: Map not found. Please check the filename."); + + mapSize_ = mapInfo.mapSize; + tileSize_ = mapInfo.tileSize; + mapOrientation_ = mapInfo.orientation; + objectGroups_ = [mapInfo.objectGroups retain]; + properties_ = [mapInfo.properties retain]; + tileProperties_ = [mapInfo.tileProperties retain]; + + int idx=0; + + for( CCTMXLayerInfo *layerInfo in mapInfo.layers ) { + + if( layerInfo.visible ) { + CCNode *child = [self parseLayer:layerInfo map:mapInfo]; + [self addChild:child z:idx tag:idx]; + + // update content size with the max size + CGSize childSize = [child contentSize]; + CGSize currentSize = [self contentSize]; + currentSize.width = MAX( currentSize.width, childSize.width ); + currentSize.height = MAX( currentSize.height, childSize.height ); + [self setContentSize:currentSize]; + + idx++; + } + } + } + + return self; +} + +-(void) dealloc +{ + [objectGroups_ release]; + [properties_ release]; + [tileProperties_ release]; + [super dealloc]; +} + +// private +-(id) parseLayer:(CCTMXLayerInfo*)layerInfo map:(CCTMXMapInfo*)mapInfo +{ + CCTMXTilesetInfo *tileset = [self tilesetForLayer:layerInfo map:mapInfo]; + CCTMXLayer *layer = [CCTMXLayer layerWithTilesetInfo:tileset layerInfo:layerInfo mapInfo:mapInfo]; + + // tell the layerinfo to release the ownership of the tiles map. + layerInfo.ownTiles = NO; + + [layer setupTiles]; + + return layer; +} + +-(CCTMXTilesetInfo*) tilesetForLayer:(CCTMXLayerInfo*)layerInfo map:(CCTMXMapInfo*)mapInfo +{ + CFByteOrder o = CFByteOrderGetCurrent(); + + CGSize size = layerInfo.layerSize; + + id iter = [mapInfo.tilesets reverseObjectEnumerator]; + for( CCTMXTilesetInfo* tileset in iter) { + for( unsigned int y = 0; y < size.height; y++ ) { + for( unsigned int x = 0; x < size.width; x++ ) { + + unsigned int pos = x + size.width * y; + unsigned int gid = layerInfo.tiles[ pos ]; + + // gid are stored in little endian. + // if host is big endian, then swap + if( o == CFByteOrderBigEndian ) + gid = CFSwapInt32( gid ); + + // XXX: gid == 0 --> empty tile + if( gid != 0 ) { + + // Optimization: quick return + // if the layer is invalid (more than 1 tileset per layer) an assert will be thrown later + if( gid >= tileset.firstGid ) + return tileset; + } + } + } + } + + // If all the tiles are 0, return empty tileset + CCLOG(@"cocos2d: Warning: TMX Layer '%@' has no tiles", layerInfo.name); + return nil; +} + + +// public + +-(CCTMXLayer*) layerNamed:(NSString *)layerName +{ + CCTMXLayer *layer; + CCARRAY_FOREACH(children_, layer) { + if([layer isKindOfClass:[CCTMXLayer class]]) + if([layer.layerName isEqual:layerName]) + return layer; + } + + // layer not found + return nil; +} + +-(CCTMXObjectGroup*) objectGroupNamed:(NSString *)groupName +{ + for( CCTMXObjectGroup *objectGroup in objectGroups_ ) { + if( [objectGroup.groupName isEqual:groupName] ) + return objectGroup; + } + + // objectGroup not found + return nil; +} + +-(id) propertyNamed:(NSString *)propertyName +{ + return [properties_ valueForKey:propertyName]; +} +-(NSDictionary*)propertiesForGID:(unsigned int)GID{ + return [tileProperties_ objectForKey:[NSNumber numberWithInt:GID]]; +} +@end + diff --git a/tweejump/libs/cocos2d/CCTMXXMLParser.h b/tweejump/libs/cocos2d/CCTMXXMLParser.h new file mode 100755 index 0000000..18d7a8a --- /dev/null +++ b/tweejump/libs/cocos2d/CCTMXXMLParser.h @@ -0,0 +1,202 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2009-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. + * + * + * TMX Tiled Map support: + * http://www.mapeditor.org + * + */ + +/* + * Internal TMX parser + * + * IMPORTANT: These classed should not be documented using doxygen strings + * since the user should not use them. + * + */ + + +#import +#import + +enum { + TMXLayerAttribNone = 1 << 0, + TMXLayerAttribBase64 = 1 << 1, + TMXLayerAttribGzip = 1 << 2, + TMXLayerAttribZlib = 1 << 3, +}; + +enum { + TMXPropertyNone, + TMXPropertyMap, + TMXPropertyLayer, + TMXPropertyObjectGroup, + TMXPropertyObject, + TMXPropertyTile +}; + +/* CCTMXLayerInfo contains the information about the layers like: + - Layer name + - Layer size + - Layer opacity at creation time (it can be modified at runtime) + - Whether the layer is visible (if it's not visible, then the CocosNode won't be created) + + This information is obtained from the TMX file. + */ +@interface CCTMXLayerInfo : NSObject +{ + NSString *name_; + CGSize layerSize_; + unsigned int *tiles_; + BOOL visible_; + unsigned char opacity_; + BOOL ownTiles_; + unsigned int minGID_; + unsigned int maxGID_; + NSMutableDictionary *properties_; + CGPoint offset_; +} + +@property (nonatomic,readwrite,retain) NSString *name; +@property (nonatomic,readwrite) CGSize layerSize; +@property (nonatomic,readwrite) unsigned int *tiles; +@property (nonatomic,readwrite) BOOL visible; +@property (nonatomic,readwrite) unsigned char opacity; +@property (nonatomic,readwrite) BOOL ownTiles; +@property (nonatomic,readwrite) unsigned int minGID; +@property (nonatomic,readwrite) unsigned int maxGID; +@property (nonatomic,readwrite,retain) NSMutableDictionary *properties; +@property (nonatomic,readwrite) CGPoint offset; +@end + +/* CCTMXTilesetInfo contains the information about the tilesets like: + - Tileset name + - Tilset spacing + - Tileset margin + - size of the tiles + - Image used for the tiles + - Image size + + This information is obtained from the TMX file. + */ +@interface CCTMXTilesetInfo : NSObject +{ + NSString *name_; + unsigned int firstGid_; + CGSize tileSize_; + unsigned int spacing_; + unsigned int margin_; + + // filename containing the tiles (should be spritesheet / texture atlas) + NSString *sourceImage_; + + // size in pixels of the image + CGSize imageSize_; +} +@property (nonatomic,readwrite,retain) NSString *name; +@property (nonatomic,readwrite,assign) unsigned int firstGid; +@property (nonatomic,readwrite,assign) CGSize tileSize; +@property (nonatomic,readwrite,assign) unsigned int spacing; +@property (nonatomic,readwrite,assign) unsigned int margin; +@property (nonatomic,readwrite,retain) NSString *sourceImage; +@property (nonatomic,readwrite,assign) CGSize imageSize; + +-(CGRect) rectForGID:(unsigned int)gid; +@end + +/* CCTMXMapInfo contains the information about the map like: + - Map orientation (hexagonal, isometric or orthogonal) + - Tile size + - Map size + + And it also contains: + - Layers (an array of TMXLayerInfo objects) + - Tilesets (an array of TMXTilesetInfo objects) + - ObjectGroups (an array of TMXObjectGroupInfo objects) + + This information is obtained from the TMX file. + + */ +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED +#if defined(__IPHONE_4_0) +@interface CCTMXMapInfo : NSObject +#else +@interface CCTMXMapInfo : NSObject +#endif + +#elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED) +@interface CCTMXMapInfo : NSObject +#endif +{ + NSMutableString *currentString; + BOOL storingCharacters; + int layerAttribs; + int parentElement; + unsigned int parentGID_; + + + // tmx filename + NSString *filename_; + + // map orientation + int orientation_; + + // map width & height + CGSize mapSize_; + + // tiles width & height + CGSize tileSize_; + + // Layers + NSMutableArray *layers_; + + // tilesets + NSMutableArray *tilesets_; + + // ObjectGroups + NSMutableArray *objectGroups_; + + // properties + NSMutableDictionary *properties_; + + // tile properties + NSMutableDictionary *tileProperties_; +} + +@property (nonatomic,readwrite,assign) int orientation; +@property (nonatomic,readwrite,assign) CGSize mapSize; +@property (nonatomic,readwrite,assign) CGSize tileSize; +@property (nonatomic,readwrite,retain) NSMutableArray *layers; +@property (nonatomic,readwrite,retain) NSMutableArray *tilesets; +@property (nonatomic,readwrite,retain) NSString *filename; +@property (nonatomic,readwrite,retain) NSMutableArray *objectGroups; +@property (nonatomic,readwrite,retain) NSMutableDictionary *properties; +@property (nonatomic,readwrite,retain) NSMutableDictionary *tileProperties; + +/** creates a TMX Format with a tmx file */ ++(id) formatWithTMXFile:(NSString*)tmxFile; +/** initializes a TMX format witha tmx file */ +-(id) initWithTMXFile:(NSString*)tmxFile; +@end + diff --git a/tweejump/libs/cocos2d/CCTMXXMLParser.m b/tweejump/libs/cocos2d/CCTMXXMLParser.m new file mode 100755 index 0000000..77cea0e --- /dev/null +++ b/tweejump/libs/cocos2d/CCTMXXMLParser.m @@ -0,0 +1,456 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2009-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. + * + * + * TMX Tiled Map support: + * http://www.mapeditor.org + * + */ + + +#import +#include + +#import "ccMacros.h" +#import "Support/CGPointExtension.h" +#import "CCTMXXMLParser.h" +#import "CCTMXTiledMap.h" +#import "CCTMXObjectGroup.h" +#import "Support/base64.h" +#import "Support/ZipUtils.h" +#import "Support/CCFileUtils.h" + +#pragma mark - +#pragma mark TMXLayerInfo + + +@implementation CCTMXLayerInfo + +@synthesize name = name_, layerSize = layerSize_, tiles = tiles_, visible = visible_, opacity = opacity_, ownTiles = ownTiles_, minGID = minGID_, maxGID = maxGID_, properties = properties_; +@synthesize offset = offset_; +-(id) init +{ + if( (self=[super init])) { + ownTiles_ = YES; + minGID_ = 100000; + maxGID_ = 0; + self.name = nil; + tiles_ = NULL; + offset_ = CGPointZero; + self.properties = [NSMutableDictionary dictionaryWithCapacity:5]; + } + return self; +} +- (void) dealloc +{ + CCLOGINFO(@"cocos2d: deallocing %@",self); + + [name_ release]; + [properties_ release]; + + if( ownTiles_ && tiles_ ) { + free( tiles_ ); + tiles_ = NULL; + } + [super dealloc]; +} + +@end + +#pragma mark - +#pragma mark TMXTilesetInfo +@implementation CCTMXTilesetInfo + +@synthesize name = name_, firstGid = firstGid_, tileSize = tileSize_, spacing = spacing_, margin = margin_, sourceImage = sourceImage_, imageSize = imageSize_; + +- (void) dealloc +{ + CCLOGINFO(@"cocos2d: deallocing %@", self); + [sourceImage_ release]; + [name_ release]; + [super dealloc]; +} + +-(CGRect) rectForGID:(unsigned int)gid +{ + CGRect rect; + rect.size = tileSize_; + + gid = gid - firstGid_; + + int max_x = (imageSize_.width - margin_*2 + spacing_) / (tileSize_.width + spacing_); + // int max_y = (imageSize.height - margin*2 + spacing) / (tileSize.height + spacing); + + rect.origin.x = (gid % max_x) * (tileSize_.width + spacing_) + margin_; + rect.origin.y = (gid / max_x) * (tileSize_.height + spacing_) + margin_; + + return rect; +} +@end + +#pragma mark - +#pragma mark CCTMXMapInfo + +@interface CCTMXMapInfo (Private) +/* initalises parsing of an XML file, either a tmx (Map) file or tsx (Tileset) file */ +-(void) parseXMLFile:(NSString *)xmlFilename; +@end + + +@implementation CCTMXMapInfo + +@synthesize orientation = orientation_, mapSize = mapSize_, layers = layers_, tilesets = tilesets_, tileSize = tileSize_, filename = filename_, objectGroups = objectGroups_, properties = properties_; +@synthesize tileProperties = tileProperties_; + ++(id) formatWithTMXFile:(NSString*)tmxFile +{ + return [[[self alloc] initWithTMXFile:tmxFile] autorelease]; +} + +-(id) initWithTMXFile:(NSString*)tmxFile +{ + if( (self=[super init])) { + + self.tilesets = [NSMutableArray arrayWithCapacity:4]; + self.layers = [NSMutableArray arrayWithCapacity:4]; + self.filename = tmxFile; + self.objectGroups = [NSMutableArray arrayWithCapacity:4]; + self.properties = [NSMutableDictionary dictionaryWithCapacity:5]; + self.tileProperties = [NSMutableDictionary dictionaryWithCapacity:5]; + + // tmp vars + currentString = [[NSMutableString alloc] initWithCapacity:1024]; + storingCharacters = NO; + layerAttribs = TMXLayerAttribNone; + parentElement = TMXPropertyNone; + + [self parseXMLFile:filename_]; + } + return self; +} +- (void) dealloc +{ + CCLOGINFO(@"cocos2d: deallocing %@", self); + [tilesets_ release]; + [layers_ release]; + [filename_ release]; + [currentString release]; + [objectGroups_ release]; + [properties_ release]; + [tileProperties_ release]; + [super dealloc]; +} + +- (void) parseXMLFile:(NSString *)xmlFilename +{ + NSURL *url = [NSURL fileURLWithPath:[CCFileUtils fullPathFromRelativePath:xmlFilename] ]; + NSData *data = [NSData dataWithContentsOfURL:url]; + NSXMLParser *parser = [[NSXMLParser alloc] initWithData:data]; + + // we'll do the parsing + [parser setDelegate:self]; + [parser setShouldProcessNamespaces:NO]; + [parser setShouldReportNamespacePrefixes:NO]; + [parser setShouldResolveExternalEntities:NO]; + [parser parse]; + + NSAssert1( ! [parser parserError], @"Error parsing file: %@.", xmlFilename ); + + [parser release]; +} + +// the XML parser calls here with all the elements +-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict +{ + if([elementName isEqualToString:@"map"]) { + NSString *version = [attributeDict valueForKey:@"version"]; + if( ! [version isEqualToString:@"1.0"] ) + CCLOG(@"cocos2d: TMXFormat: Unsupported TMX version: %@", version); + NSString *orientationStr = [attributeDict valueForKey:@"orientation"]; + if( [orientationStr isEqualToString:@"orthogonal"]) + orientation_ = CCTMXOrientationOrtho; + else if ( [orientationStr isEqualToString:@"isometric"]) + orientation_ = CCTMXOrientationIso; + else if( [orientationStr isEqualToString:@"hexagonal"]) + orientation_ = CCTMXOrientationHex; + else + CCLOG(@"cocos2d: TMXFomat: Unsupported orientation: %@", orientation_); + + mapSize_.width = [[attributeDict valueForKey:@"width"] intValue]; + mapSize_.height = [[attributeDict valueForKey:@"height"] intValue]; + tileSize_.width = [[attributeDict valueForKey:@"tilewidth"] intValue]; + tileSize_.height = [[attributeDict valueForKey:@"tileheight"] intValue]; + + // The parent element is now "map" + parentElement = TMXPropertyMap; + } else if([elementName isEqualToString:@"tileset"]) { + + // If this is an external tileset then start parsing that + NSString *externalTilesetFilename = [attributeDict valueForKey:@"source"]; + if (externalTilesetFilename) { + // Tileset file will be relative to the map file. So we need to convert it to an absolute path + NSString *dir = [filename_ stringByDeletingLastPathComponent]; // Directory of map file + externalTilesetFilename = [dir stringByAppendingPathComponent:externalTilesetFilename]; // Append path to tileset file + + [self parseXMLFile:externalTilesetFilename]; + } else { + + CCTMXTilesetInfo *tileset = [CCTMXTilesetInfo new]; + tileset.name = [attributeDict valueForKey:@"name"]; + tileset.firstGid = [[attributeDict valueForKey:@"firstgid"] intValue]; + tileset.spacing = [[attributeDict valueForKey:@"spacing"] intValue]; + tileset.margin = [[attributeDict valueForKey:@"margin"] intValue]; + CGSize s; + s.width = [[attributeDict valueForKey:@"tilewidth"] intValue]; + s.height = [[attributeDict valueForKey:@"tileheight"] intValue]; + tileset.tileSize = s; + + [tilesets_ addObject:tileset]; + [tileset release]; + } + + }else if([elementName isEqualToString:@"tile"]){ + CCTMXTilesetInfo* info = [tilesets_ lastObject]; + NSMutableDictionary* dict = [NSMutableDictionary dictionaryWithCapacity:3]; + parentGID_ = [info firstGid] + [[attributeDict valueForKey:@"id"] intValue]; + [tileProperties_ setObject:dict forKey:[NSNumber numberWithInt:parentGID_]]; + + parentElement = TMXPropertyTile; + + }else if([elementName isEqualToString:@"layer"]) { + CCTMXLayerInfo *layer = [CCTMXLayerInfo new]; + layer.name = [attributeDict valueForKey:@"name"]; + + CGSize s; + s.width = [[attributeDict valueForKey:@"width"] intValue]; + s.height = [[attributeDict valueForKey:@"height"] intValue]; + layer.layerSize = s; + + layer.visible = ![[attributeDict valueForKey:@"visible"] isEqualToString:@"0"]; + + if( [attributeDict valueForKey:@"opacity"] ) + layer.opacity = 255 * [[attributeDict valueForKey:@"opacity"] floatValue]; + else + layer.opacity = 255; + + int x = [[attributeDict valueForKey:@"x"] intValue]; + int y = [[attributeDict valueForKey:@"y"] intValue]; + layer.offset = ccp(x,y); + + [layers_ addObject:layer]; + [layer release]; + + // The parent element is now "layer" + parentElement = TMXPropertyLayer; + + } else if([elementName isEqualToString:@"objectgroup"]) { + + CCTMXObjectGroup *objectGroup = [[CCTMXObjectGroup alloc] init]; + objectGroup.groupName = [attributeDict valueForKey:@"name"]; + CGPoint positionOffset; + positionOffset.x = [[attributeDict valueForKey:@"x"] intValue] * tileSize_.width; + positionOffset.y = [[attributeDict valueForKey:@"y"] intValue] * tileSize_.height; + objectGroup.positionOffset = positionOffset; + + [objectGroups_ addObject:objectGroup]; + [objectGroup release]; + + // The parent element is now "objectgroup" + parentElement = TMXPropertyObjectGroup; + + } else if([elementName isEqualToString:@"image"]) { + + CCTMXTilesetInfo *tileset = [tilesets_ lastObject]; + + // build full path + NSString *imagename = [attributeDict valueForKey:@"source"]; + NSString *path = [filename_ stringByDeletingLastPathComponent]; + tileset.sourceImage = [path stringByAppendingPathComponent:imagename]; + + } else if([elementName isEqualToString:@"data"]) { + NSString *encoding = [attributeDict valueForKey:@"encoding"]; + NSString *compression = [attributeDict valueForKey:@"compression"]; + + if( [encoding isEqualToString:@"base64"] ) { + layerAttribs |= TMXLayerAttribBase64; + storingCharacters = YES; + + if( [compression isEqualToString:@"gzip"] ) + layerAttribs |= TMXLayerAttribGzip; + + else if( [compression isEqualToString:@"zlib"] ) + layerAttribs |= TMXLayerAttribZlib; + + NSAssert( !compression || [compression isEqualToString:@"gzip"] || [compression isEqualToString:@"zlib"], @"TMX: unsupported compression method" ); + } + + NSAssert( layerAttribs != TMXLayerAttribNone, @"TMX tile map: Only base64 and/or gzip/zlib maps are supported" ); + + } else if([elementName isEqualToString:@"object"]) { + + CCTMXObjectGroup *objectGroup = [objectGroups_ lastObject]; + + // The value for "type" was blank or not a valid class name + // Create an instance of TMXObjectInfo to store the object and its properties + NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithCapacity:5]; + + // Set the name of the object to the value for "name" + [dict setValue:[attributeDict valueForKey:@"name"] forKey:@"name"]; + + // Assign all the attributes as key/name pairs in the properties dictionary + [dict setValue:[attributeDict valueForKey:@"type"] forKey:@"type"]; + int x = [[attributeDict valueForKey:@"x"] intValue] + objectGroup.positionOffset.x; + [dict setValue:[NSNumber numberWithInt:x] forKey:@"x"]; + int y = [[attributeDict valueForKey:@"y"] intValue] + objectGroup.positionOffset.y; + // Correct y position. (Tiled uses Flipped, cocos2d uses Standard) + y = (mapSize_.height * tileSize_.height) - y - [[attributeDict valueForKey:@"height"] intValue]; + [dict setValue:[NSNumber numberWithInt:y] forKey:@"y"]; + [dict setValue:[attributeDict valueForKey:@"width"] forKey:@"width"]; + [dict setValue:[attributeDict valueForKey:@"height"] forKey:@"height"]; + + // Add the object to the objectGroup + [[objectGroup objects] addObject:dict]; + [dict release]; + + // The parent element is now "object" + parentElement = TMXPropertyObject; + + } else if([elementName isEqualToString:@"property"]) { + + if ( parentElement == TMXPropertyNone ) { + + CCLOG( @"TMX tile map: Parent element is unsupported. Cannot add property named '%@' with value '%@'", + [attributeDict valueForKey:@"name"], [attributeDict valueForKey:@"value"] ); + + } else if ( parentElement == TMXPropertyMap ) { + + // The parent element is the map + [properties_ setValue:[attributeDict valueForKey:@"value"] forKey:[attributeDict valueForKey:@"name"]]; + + } else if ( parentElement == TMXPropertyLayer ) { + + // The parent element is the last layer + CCTMXLayerInfo *layer = [layers_ lastObject]; + // Add the property to the layer + [[layer properties] setValue:[attributeDict valueForKey:@"value"] forKey:[attributeDict valueForKey:@"name"]]; + + } else if ( parentElement == TMXPropertyObjectGroup ) { + + // The parent element is the last object group + CCTMXObjectGroup *objectGroup = [objectGroups_ lastObject]; + [[objectGroup properties] setValue:[attributeDict valueForKey:@"value"] forKey:[attributeDict valueForKey:@"name"]]; + + } else if ( parentElement == TMXPropertyObject ) { + + // The parent element is the last object + CCTMXObjectGroup *objectGroup = [objectGroups_ lastObject]; + NSMutableDictionary *dict = [[objectGroup objects] lastObject]; + + NSString *propertyName = [attributeDict valueForKey:@"name"]; + NSString *propertyValue = [attributeDict valueForKey:@"value"]; + + [dict setValue:propertyValue forKey:propertyName]; + } else if ( parentElement == TMXPropertyTile ) { + + NSMutableDictionary* dict = [tileProperties_ objectForKey:[NSNumber numberWithInt:parentGID_]]; + NSString *propertyName = [attributeDict valueForKey:@"name"]; + NSString *propertyValue = [attributeDict valueForKey:@"value"]; + [dict setObject:propertyValue forKey:propertyName]; + + } + } +} + +- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName +{ + int len = 0; + + if([elementName isEqualToString:@"data"] && layerAttribs&TMXLayerAttribBase64) { + storingCharacters = NO; + + CCTMXLayerInfo *layer = [layers_ lastObject]; + + unsigned char *buffer; + len = base64Decode((unsigned char*)[currentString UTF8String], (unsigned int) [currentString length], &buffer); + if( ! buffer ) { + CCLOG(@"cocos2d: TiledMap: decode data error"); + return; + } + + if( layerAttribs & (TMXLayerAttribGzip | TMXLayerAttribZlib) ) { + unsigned char *deflated; + CGSize s = [layer layerSize]; + int sizeHint = s.width * s.height * sizeof(uint32_t); + + int inflatedLen = ccInflateMemoryWithHint(buffer, len, &deflated, sizeHint); + NSAssert( inflatedLen == sizeHint, @"CCTMXXMLParser: Hint failed!"); + + inflatedLen = (int)&inflatedLen; // XXX: to avoid warings in compiler + + free( buffer ); + + if( ! deflated ) { + CCLOG(@"cocos2d: TiledMap: inflate data error"); + return; + } + + layer.tiles = (unsigned int*) deflated; + } else + layer.tiles = (unsigned int*) buffer; + + [currentString setString:@""]; + + } else if ([elementName isEqualToString:@"map"]) { + // The map element has ended + parentElement = TMXPropertyNone; + + } else if ([elementName isEqualToString:@"layer"]) { + // The layer element has ended + parentElement = TMXPropertyNone; + + } else if ([elementName isEqualToString:@"objectgroup"]) { + // The objectgroup element has ended + parentElement = TMXPropertyNone; + + } else if ([elementName isEqualToString:@"object"]) { + // The object element has ended + parentElement = TMXPropertyNone; + } +} + +- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string +{ + if (storingCharacters) + [currentString appendString:string]; +} + + +// +// the level did not load, file not found, etc. +// +-(void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError{ + CCLOG(@"cocos2d: Error on XML Parse: %@", [parseError localizedDescription] ); +} + +@end diff --git a/tweejump/libs/cocos2d/CCTexture2D.h b/tweejump/libs/cocos2d/CCTexture2D.h new file mode 100755 index 0000000..45eea9c --- /dev/null +++ b/tweejump/libs/cocos2d/CCTexture2D.h @@ -0,0 +1,328 @@ +/* + +===== IMPORTANT ===== + +This is sample code demonstrating API, technology or techniques in development. +Although this sample code has been reviewed for technical accuracy, it is not +final. Apple is supplying this information to help you plan for the adoption of +the technologies and programming interfaces described herein. This information +is subject to change, and software implemented based on this sample code should +be tested with final operating system software and final documentation. Newer +versions of this sample code may be provided with future seeds of the API or +technology. For information about updates to this and other developer +documentation, view the New & Updated sidebars in subsequent documentation +seeds. + +===================== + +File: Texture2D.h +Abstract: Creates OpenGL 2D textures from images or text. + +Version: 1.6 + +Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc. +("Apple") in consideration of your agreement to the following terms, and your +use, installation, modification or redistribution of this Apple software +constitutes acceptance of these terms. If you do not agree with these terms, +please do not use, install, modify or redistribute this Apple software. + +In consideration of your agreement to abide by the following terms, and subject +to these terms, Apple grants you a personal, non-exclusive license, under +Apple's copyrights in this original Apple software (the "Apple Software"), to +use, reproduce, modify and redistribute the Apple Software, with or without +modifications, in source and/or binary forms; provided that if you redistribute +the Apple Software in its entirety and without modifications, you must retain +this notice and the following text and disclaimers in all such redistributions +of the Apple Software. +Neither the name, trademarks, service marks or logos of Apple Inc. may be used +to endorse or promote products derived from the Apple Software without specific +prior written permission from Apple. Except as expressly stated in this notice, +no other rights or licenses, express or implied, are granted by Apple herein, +including but not limited to any patent rights that may be infringed by your +derivative works or by other works in which the Apple Software may be +incorporated. + +The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO +WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED +WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN +COMBINATION WITH YOUR PRODUCTS. + +IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE +GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR +DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF +CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF +APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +Copyright (C) 2008 Apple Inc. All Rights Reserved. + +*/ + +#import + +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED +#import // for UIImage +#endif + +#import // for NSObject + +#import "Platforms/CCGL.h" // OpenGL stuff +#import "Platforms/CCNS.h" // Next-Step stuff + +//CONSTANTS: + +/** @typedef CCTexture2DPixelFormat + Possible texture pixel formats + */ +typedef enum { + kCCTexture2DPixelFormat_Automatic = 0, + //! 32-bit texture: RGBA8888 + kCCTexture2DPixelFormat_RGBA8888, + //! 16-bit texture without Alpha channel + kCCTexture2DPixelFormat_RGB565, + //! 8-bit textures used as masks + kCCTexture2DPixelFormat_A8, + //! 8-bit intensity texture + kCCTexture2DPixelFormat_I8, + //! 16-bit textures used as masks + kCCTexture2DPixelFormat_AI88, + //! 16-bit textures: RGBA4444 + kCCTexture2DPixelFormat_RGBA4444, + //! 16-bit textures: RGB5A1 + kCCTexture2DPixelFormat_RGB5A1, + //! 4-bit PVRTC-compressed texture: PVRTC4 + kCCTexture2DPixelFormat_PVRTC4, + //! 2-bit PVRTC-compressed texture: PVRTC2 + kCCTexture2DPixelFormat_PVRTC2, + + //! Default texture format: RGBA8888 + kCCTexture2DPixelFormat_Default = kCCTexture2DPixelFormat_RGBA8888, + + // backward compatibility stuff + kTexture2DPixelFormat_Automatic = kCCTexture2DPixelFormat_Automatic, + kTexture2DPixelFormat_RGBA8888 = kCCTexture2DPixelFormat_RGBA8888, + kTexture2DPixelFormat_RGB565 = kCCTexture2DPixelFormat_RGB565, + kTexture2DPixelFormat_A8 = kCCTexture2DPixelFormat_A8, + kTexture2DPixelFormat_RGBA4444 = kCCTexture2DPixelFormat_RGBA4444, + kTexture2DPixelFormat_RGB5A1 = kCCTexture2DPixelFormat_RGB5A1, + kTexture2DPixelFormat_Default = kCCTexture2DPixelFormat_Default + +} CCTexture2DPixelFormat; + +//CLASS INTERFACES: + +/** CCTexture2D class. + * This class allows to easily create OpenGL 2D textures from images, text or raw data. + * The created CCTexture2D object will always have power-of-two dimensions. + * Depending on how you create the CCTexture2D object, the actual image area of the texture might be smaller than the texture dimensions i.e. "contentSize" != (pixelsWide, pixelsHigh) and (maxS, maxT) != (1.0, 1.0). + * Be aware that the content of the generated textures will be upside-down! + */ +@interface CCTexture2D : NSObject +{ + GLuint name_; + CGSize size_; + NSUInteger width_, + height_; + CCTexture2DPixelFormat format_; + GLfloat maxS_, + maxT_; + BOOL hasPremultipliedAlpha_; +} +/** Intializes with a texture2d with data */ +- (id) initWithData:(const void*)data pixelFormat:(CCTexture2DPixelFormat)pixelFormat pixelsWide:(NSUInteger)width pixelsHigh:(NSUInteger)height contentSize:(CGSize)size; + +/** These functions are needed to create mutable textures */ +- (void) releaseData:(void*)data; +- (void*) keepData:(void*)data length:(NSUInteger)length; + +/** pixel format of the texture */ +@property(nonatomic,readonly) CCTexture2DPixelFormat pixelFormat; +/** width in pixels */ +@property(nonatomic,readonly) NSUInteger pixelsWide; +/** hight in pixels */ +@property(nonatomic,readonly) NSUInteger pixelsHigh; + +/** texture name */ +@property(nonatomic,readonly) GLuint name; + +/** returns content size of the texture in pixels */ +@property(nonatomic,readonly, nonatomic) CGSize contentSizeInPixels; + +/** texture max S */ +@property(nonatomic,readwrite) GLfloat maxS; +/** texture max T */ +@property(nonatomic,readwrite) GLfloat maxT; +/** whether or not the texture has their Alpha premultiplied */ +@property(nonatomic,readonly) BOOL hasPremultipliedAlpha; + +/** returns the content size of the texture in points */ +-(CGSize) contentSize; +@end + +/** +Drawing extensions to make it easy to draw basic quads using a CCTexture2D object. +These functions require GL_TEXTURE_2D and both GL_VERTEX_ARRAY and GL_TEXTURE_COORD_ARRAY client states to be enabled. +*/ +@interface CCTexture2D (Drawing) +/** draws a texture at a given point */ +- (void) drawAtPoint:(CGPoint)point; +/** draws a texture inside a rect */ +- (void) drawInRect:(CGRect)rect; +@end + +/** +Extensions to make it easy to create a CCTexture2D object from an image file. +Note that RGBA type textures will have their alpha premultiplied - use the blending mode (GL_ONE, GL_ONE_MINUS_SRC_ALPHA). +*/ +@interface CCTexture2D (Image) +/** Initializes a texture from a UIImage object */ +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED +- (id) initWithImage:(UIImage *)uiImage; +#elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED) +- (id) initWithImage:(CGImageRef)cgImage; +#endif +@end + +/** +Extensions to make it easy to create a CCTexture2D object from a string of text. +Note that the generated textures are of type A8 - use the blending mode (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA). +*/ +@interface CCTexture2D (Text) +/** Initializes a texture from a string with dimensions, alignment, line break mode, font name and font size + Supported lineBreakModes: + - iOS: all UILineBreakMode supported modes + - Mac: Only NSLineBreakByWordWrapping is supported. + @since v1.0 + */ +- (id) initWithString:(NSString*)string dimensions:(CGSize)dimensions alignment:(CCTextAlignment)alignment lineBreakMode:(CCLineBreakMode)lineBreakMode fontName:(NSString*)name fontSize:(CGFloat)size; +/** Initializes a texture from a string with dimensions, alignment, font name and font size */ +- (id) initWithString:(NSString*)string dimensions:(CGSize)dimensions alignment:(CCTextAlignment)alignment fontName:(NSString*)name fontSize:(CGFloat)size; +/** Initializes a texture from a string with font name and font size */ +- (id) initWithString:(NSString*)string fontName:(NSString*)name fontSize:(CGFloat)size; +@end + + +/** + Extensions to make it easy to create a CCTexture2D object from a PVRTC file + Note that the generated textures don't have their alpha premultiplied - use the blending mode (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA). + */ +@interface CCTexture2D (PVRSupport) +/** Initializes a texture from a PVR Texture Compressed (PVRTC) buffer + * + * IMPORTANT: This method is only defined on iOS. It is not supported on the Mac version. + */ +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED +-(id) initWithPVRTCData: (const void*)data level:(int)level bpp:(int)bpp hasAlpha:(BOOL)hasAlpha length:(int)length pixelFormat:(CCTexture2DPixelFormat)pixelFormat; +#endif // __IPHONE_OS_VERSION_MAX_ALLOWED +/** Initializes a texture from a PVR file. + + Supported PVR formats: + - BGRA 8888 + - RGBA 8888 + - RGBA 4444 + - RGBA 5551 + - RBG 565 + - A 8 + - I 8 + - AI 8 + - PVRTC 2BPP + - PVRTC 4BPP + + By default PVR images are treated as if they alpha channel is NOT premultiplied. You can override this behavior with this class method: + - PVRImagesHavePremultipliedAlpha:(BOOL)haveAlphaPremultiplied; + + IMPORTANT: This method is only defined on iOS. It is not supported on the Mac version. + + */ +-(id) initWithPVRFile: (NSString*) file; + +/** treats (or not) PVR files as if they have alpha premultiplied. + Since it is impossible to know at runtime if the PVR images have the alpha channel premultiplied, it is + possible load them as if they have (or not) the alpha channel premultiplied. + + By default it is disabled. + + @since v0.99.5 + */ ++(void) PVRImagesHavePremultipliedAlpha:(BOOL)haveAlphaPremultiplied; +@end + +/** + Extension to set the Min / Mag filter + */ +typedef struct _ccTexParams { + GLuint minFilter; + GLuint magFilter; + GLuint wrapS; + GLuint wrapT; +} ccTexParams; + +@interface CCTexture2D (GLFilter) +/** sets the min filter, mag filter, wrap s and wrap t texture parameters. + If the texture size is NPOT (non power of 2), then in can only use GL_CLAMP_TO_EDGE in GL_TEXTURE_WRAP_{S,T}. + @since v0.8 + */ +-(void) setTexParameters: (ccTexParams*) texParams; + +/** sets antialias texture parameters: + - GL_TEXTURE_MIN_FILTER = GL_LINEAR + - GL_TEXTURE_MAG_FILTER = GL_LINEAR + + @since v0.8 + */ +- (void) setAntiAliasTexParameters; + +/** sets alias texture parameters: + - GL_TEXTURE_MIN_FILTER = GL_NEAREST + - GL_TEXTURE_MAG_FILTER = GL_NEAREST + + @since v0.8 + */ +- (void) setAliasTexParameters; + + +/** Generates mipmap images for the texture. + It only works if the texture size is POT (power of 2). + @since v0.99.0 + */ +-(void) generateMipmap; + + +@end + +@interface CCTexture2D (PixelFormat) +/** sets the default pixel format for UIImages that contains alpha channel. + If the UIImage contains alpha channel, then the options are: + - generate 32-bit textures: kCCTexture2DPixelFormat_RGBA8888 (default one) + - generate 16-bit textures: kCCTexture2DPixelFormat_RGBA4444 + - generate 16-bit textures: kCCTexture2DPixelFormat_RGB5A1 + - generate 16-bit textures: kCCTexture2DPixelFormat_RGB565 + - generate 8-bit textures: kCCTexture2DPixelFormat_A8 (only use it if you use just 1 color) + + How does it work ? + - If the image is an RGBA (with Alpha) then the default pixel format will be used (it can be a 8-bit, 16-bit or 32-bit texture) + - If the image is an RGB (without Alpha) then an RGB565 texture will be used (16-bit texture) + + This parameter is not valid for PVR images. + + @since v0.8 + */ ++(void) setDefaultAlphaPixelFormat:(CCTexture2DPixelFormat)format; + +/** returns the alpha pixel format + @since v0.8 + */ ++(CCTexture2DPixelFormat) defaultAlphaPixelFormat; + +/** returns the bits-per-pixel of the in-memory OpenGL texture + @since v1.0 + */ +-(NSUInteger) bitsPerPixelForFormat; +@end + + + + + diff --git a/tweejump/libs/cocos2d/CCTexture2D.m b/tweejump/libs/cocos2d/CCTexture2D.m new file mode 100755 index 0000000..afa64e2 --- /dev/null +++ b/tweejump/libs/cocos2d/CCTexture2D.m @@ -0,0 +1,814 @@ +/* + +===== IMPORTANT ===== + +This is sample code demonstrating API, technology or techniques in development. +Although this sample code has been reviewed for technical accuracy, it is not +final. Apple is supplying this information to help you plan for the adoption of +the technologies and programming interfaces described herein. This information +is subject to change, and software implemented based on this sample code should +be tested with final operating system software and final documentation. Newer +versions of this sample code may be provided with future seeds of the API or +technology. For information about updates to this and other developer +documentation, view the New & Updated sidebars in subsequent documentationd +seeds. + +===================== + +File: Texture2D.m +Abstract: Creates OpenGL 2D textures from images or text. + +Version: 1.6 + +Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc. +("Apple") in consideration of your agreement to the following terms, and your +use, installation, modification or redistribution of this Apple software +constitutes acceptance of these terms. If you do not agree with these terms, +please do not use, install, modify or redistribute this Apple software. + +In consideration of your agreement to abide by the following terms, and subject +to these terms, Apple grants you a personal, non-exclusive license, under +Apple's copyrights in this original Apple software (the "Apple Software"), to +use, reproduce, modify and redistribute the Apple Software, with or without +modifications, in source and/or binary forms; provided that if you redistribute +the Apple Software in its entirety and without modifications, you must retain +this notice and the following text and disclaimers in all such redistributions +of the Apple Software. +Neither the name, trademarks, service marks or logos of Apple Inc. may be used +to endorse or promote products derived from the Apple Software without specific +prior written permission from Apple. Except as expressly stated in this notice, +no other rights or licenses, express or implied, are granted by Apple herein, +including but not limited to any patent rights that may be infringed by your +derivative works or by other works in which the Apple Software may be +incorporated. + +The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO +WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED +WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN +COMBINATION WITH YOUR PRODUCTS. + +IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE +GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR +DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF +CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF +APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +Copyright (C) 2008 Apple Inc. All Rights Reserved. + +*/ + +/* + * Support for RGBA_4_4_4_4 and RGBA_5_5_5_1 was copied from: + * https://devforums.apple.com/message/37855#37855 by a1studmuffin + */ + + +#import + +#import "Platforms/CCGL.h" +#import "Platforms/CCNS.h" + + +#import "CCTexture2D.h" +#import "ccConfig.h" +#import "ccMacros.h" +#import "CCConfiguration.h" +#import "Support/ccUtils.h" +#import "CCTexturePVR.h" + +#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && CC_FONT_LABEL_SUPPORT +// FontLabel support +#import "FontManager.h" +#import "FontLabelStringDrawing.h" +#endif// CC_FONT_LABEL_SUPPORT + + +// For Labels use 16-bit textures on iPhone 3GS / iPads since A8 textures are very slow +#if (defined(__ARM_NEON__) || TARGET_IPHONE_SIMULATOR) && CC_USE_LA88_LABELS_ON_NEON_ARCH +#define USE_TEXT_WITH_A8_TEXTURES 0 + +#else +#define USE_TEXT_WITH_A8_TEXTURES 1 +#endif + +//CLASS IMPLEMENTATIONS: + + +// If the image has alpha, you can create RGBA8 (32-bit) or RGBA4 (16-bit) or RGB5A1 (16-bit) +// Default is: RGBA8888 (32-bit textures) +static CCTexture2DPixelFormat defaultAlphaPixelFormat_ = kCCTexture2DPixelFormat_Default; + +#pragma mark - +#pragma mark CCTexture2D - Main + +@implementation CCTexture2D + +@synthesize contentSizeInPixels = size_, pixelFormat = format_, pixelsWide = width_, pixelsHigh = height_, name = name_, maxS = maxS_, maxT = maxT_; +@synthesize hasPremultipliedAlpha = hasPremultipliedAlpha_; + +- (id) initWithData:(const void*)data pixelFormat:(CCTexture2DPixelFormat)pixelFormat pixelsWide:(NSUInteger)width pixelsHigh:(NSUInteger)height contentSize:(CGSize)size +{ + if((self = [super init])) { + glPixelStorei(GL_UNPACK_ALIGNMENT,1); + glGenTextures(1, &name_); + glBindTexture(GL_TEXTURE_2D, name_); + + [self setAntiAliasTexParameters]; + + // Specify OpenGL texture image + + switch(pixelFormat) + { + case kCCTexture2DPixelFormat_RGBA8888: + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (GLsizei) width, (GLsizei) height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); + break; + case kCCTexture2DPixelFormat_RGBA4444: + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (GLsizei) width, (GLsizei) height, 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, data); + break; + case kCCTexture2DPixelFormat_RGB5A1: + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (GLsizei) width, (GLsizei) height, 0, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, data); + break; + case kCCTexture2DPixelFormat_RGB565: + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, (GLsizei) width, (GLsizei) height, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, data); + break; + case kCCTexture2DPixelFormat_AI88: + glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, (GLsizei) width, (GLsizei) height, 0, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, data); + break; + case kCCTexture2DPixelFormat_A8: + glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, (GLsizei) width, (GLsizei) height, 0, GL_ALPHA, GL_UNSIGNED_BYTE, data); + break; + default: + [NSException raise:NSInternalInconsistencyException format:@""]; + + } + + size_ = size; + width_ = width; + height_ = height; + format_ = pixelFormat; + maxS_ = size.width / (float)width; + maxT_ = size.height / (float)height; + + hasPremultipliedAlpha_ = NO; + } + return self; +} + +- (void) releaseData:(void*)data +{ + //Free data + free(data); +} + +- (void*) keepData:(void*)data length:(NSUInteger)length +{ + //The texture data mustn't be saved becuase it isn't a mutable texture. + return data; +} + +- (void) dealloc +{ + CCLOGINFO(@"cocos2d: deallocing %@", self); + if(name_) + glDeleteTextures(1, &name_); + + [super dealloc]; +} + +- (NSString*) description +{ + return [NSString stringWithFormat:@"<%@ = %08X | Name = %i | Dimensions = %ix%i | Coordinates = (%.2f, %.2f)>", [self class], self, name_, width_, height_, maxS_, maxT_]; +} + +-(CGSize) contentSize +{ + CGSize ret; + ret.width = size_.width / CC_CONTENT_SCALE_FACTOR(); + ret.height = size_.height / CC_CONTENT_SCALE_FACTOR(); + + return ret; +} +@end + +#pragma mark - +#pragma mark CCTexture2D - Image + +@implementation CCTexture2D (Image) +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED +- (id) initWithImage:(UIImage *)uiImage +#elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED) +- (id) initWithImage:(CGImageRef)CGImage +#endif +{ + NSUInteger POTWide, POTHigh; + CGContextRef context = nil; + void* data = nil;; + CGColorSpaceRef colorSpace; + void* tempData; + unsigned int* inPixel32; + unsigned short* outPixel16; + BOOL hasAlpha; + CGImageAlphaInfo info; + CGSize imageSize; + CCTexture2DPixelFormat pixelFormat; + +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED + CGImageRef CGImage = uiImage.CGImage; +#endif + + if(CGImage == NULL) { + CCLOG(@"cocos2d: CCTexture2D. Can't create Texture. UIImage is nil"); + [self release]; + return nil; + } + + CCConfiguration *conf = [CCConfiguration sharedConfiguration]; + +#if CC_TEXTURE_NPOT_SUPPORT + if( [conf supportsNPOT] ) { + POTWide = CGImageGetWidth(CGImage); + POTHigh = CGImageGetHeight(CGImage); + + } else +#endif + { + POTWide = ccNextPOT(CGImageGetWidth(CGImage)); + POTHigh = ccNextPOT(CGImageGetHeight(CGImage)); + } + + NSUInteger maxTextureSize = [conf maxTextureSize]; + if( POTHigh > maxTextureSize || POTWide > maxTextureSize ) { + CCLOG(@"cocos2d: WARNING: Image (%lu x %lu) is bigger than the supported %ld x %ld", + (long)POTWide, (long)POTHigh, + (long)maxTextureSize, (long)maxTextureSize); + [self release]; + return nil; + } + + info = CGImageGetAlphaInfo(CGImage); + hasAlpha = ((info == kCGImageAlphaPremultipliedLast) || (info == kCGImageAlphaPremultipliedFirst) || (info == kCGImageAlphaLast) || (info == kCGImageAlphaFirst) ? YES : NO); + + size_t bpp = CGImageGetBitsPerComponent(CGImage); + colorSpace = CGImageGetColorSpace(CGImage); + + if(colorSpace) { + if(hasAlpha || bpp >= 8) + pixelFormat = defaultAlphaPixelFormat_; + else { + CCLOG(@"cocos2d: CCTexture2D: Using RGB565 texture since image has no alpha"); + pixelFormat = kCCTexture2DPixelFormat_RGB565; + } + } else { + // NOTE: No colorspace means a mask image + CCLOG(@"cocos2d: CCTexture2D: Using A8 texture since image is a mask"); + pixelFormat = kCCTexture2DPixelFormat_A8; + } + + imageSize = CGSizeMake(CGImageGetWidth(CGImage), CGImageGetHeight(CGImage)); + + // Create the bitmap graphics context + + switch(pixelFormat) { + case kCCTexture2DPixelFormat_RGBA8888: + case kCCTexture2DPixelFormat_RGBA4444: + case kCCTexture2DPixelFormat_RGB5A1: + colorSpace = CGColorSpaceCreateDeviceRGB(); + data = malloc(POTHigh * POTWide * 4); + info = hasAlpha ? kCGImageAlphaPremultipliedLast : kCGImageAlphaNoneSkipLast; +// info = kCGImageAlphaPremultipliedLast; // issue #886. This patch breaks BMP images. + context = CGBitmapContextCreate(data, POTWide, POTHigh, 8, 4 * POTWide, colorSpace, info | kCGBitmapByteOrder32Big); + CGColorSpaceRelease(colorSpace); + break; + + case kCCTexture2DPixelFormat_RGB565: + colorSpace = CGColorSpaceCreateDeviceRGB(); + data = malloc(POTHigh * POTWide * 4); + info = kCGImageAlphaNoneSkipLast; + context = CGBitmapContextCreate(data, POTWide, POTHigh, 8, 4 * POTWide, colorSpace, info | kCGBitmapByteOrder32Big); + CGColorSpaceRelease(colorSpace); + break; + case kCCTexture2DPixelFormat_A8: + data = malloc(POTHigh * POTWide); + info = kCGImageAlphaOnly; + context = CGBitmapContextCreate(data, POTWide, POTHigh, 8, POTWide, NULL, info); + break; + default: + [NSException raise:NSInternalInconsistencyException format:@"Invalid pixel format"]; + } + + + CGContextClearRect(context, CGRectMake(0, 0, POTWide, POTHigh)); + CGContextTranslateCTM(context, 0, POTHigh - imageSize.height); + CGContextDrawImage(context, CGRectMake(0, 0, CGImageGetWidth(CGImage), CGImageGetHeight(CGImage)), CGImage); + + // Repack the pixel data into the right format + + if(pixelFormat == kCCTexture2DPixelFormat_RGB565) { + //Convert "RRRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA" to "RRRRRGGGGGGBBBBB" + tempData = malloc(POTHigh * POTWide * 2); + inPixel32 = (unsigned int*)data; + outPixel16 = (unsigned short*)tempData; + for(unsigned int i = 0; i < POTWide * POTHigh; ++i, ++inPixel32) + *outPixel16++ = ((((*inPixel32 >> 0) & 0xFF) >> 3) << 11) | ((((*inPixel32 >> 8) & 0xFF) >> 2) << 5) | ((((*inPixel32 >> 16) & 0xFF) >> 3) << 0); + free(data); + data = tempData; + + } + else if (pixelFormat == kCCTexture2DPixelFormat_RGBA4444) { + //Convert "RRRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA" to "RRRRGGGGBBBBAAAA" + tempData = malloc(POTHigh * POTWide * 2); + inPixel32 = (unsigned int*)data; + outPixel16 = (unsigned short*)tempData; + for(unsigned int i = 0; i < POTWide * POTHigh; ++i, ++inPixel32) + *outPixel16++ = + ((((*inPixel32 >> 0) & 0xFF) >> 4) << 12) | // R + ((((*inPixel32 >> 8) & 0xFF) >> 4) << 8) | // G + ((((*inPixel32 >> 16) & 0xFF) >> 4) << 4) | // B + ((((*inPixel32 >> 24) & 0xFF) >> 4) << 0); // A + + + free(data); + data = tempData; + + } + else if (pixelFormat == kCCTexture2DPixelFormat_RGB5A1) { + //Convert "RRRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA" to "RRRRRGGGGGBBBBBA" + tempData = malloc(POTHigh * POTWide * 2); + inPixel32 = (unsigned int*)data; + outPixel16 = (unsigned short*)tempData; + for(unsigned int i = 0; i < POTWide * POTHigh; ++i, ++inPixel32) + *outPixel16++ = + ((((*inPixel32 >> 0) & 0xFF) >> 3) << 11) | // R + ((((*inPixel32 >> 8) & 0xFF) >> 3) << 6) | // G + ((((*inPixel32 >> 16) & 0xFF) >> 3) << 1) | // B + ((((*inPixel32 >> 24) & 0xFF) >> 7) << 0); // A + + + free(data); + data = tempData; + } + self = [self initWithData:data pixelFormat:pixelFormat pixelsWide:POTWide pixelsHigh:POTHigh contentSize:imageSize]; + + // should be after calling super init + hasPremultipliedAlpha_ = (info == kCGImageAlphaPremultipliedLast || info == kCGImageAlphaPremultipliedFirst); + + CGContextRelease(context); + [self releaseData:data]; + + return self; +} +@end + +#pragma mark - +#pragma mark CCTexture2D - Text + +@implementation CCTexture2D (Text) + +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED + +- (id) initWithString:(NSString*)string dimensions:(CGSize)dimensions alignment:(CCTextAlignment)alignment lineBreakMode:(CCLineBreakMode)lineBreakMode font:(id)uifont +{ + NSAssert( uifont, @"Invalid font"); + + NSUInteger POTWide = ccNextPOT(dimensions.width); + NSUInteger POTHigh = ccNextPOT(dimensions.height); + unsigned char* data; + + CGContextRef context; + CGColorSpaceRef colorSpace; + +#if USE_TEXT_WITH_A8_TEXTURES + data = calloc(POTHigh, POTWide); +#else + data = calloc(POTHigh, POTWide * 2); +#endif + + colorSpace = CGColorSpaceCreateDeviceGray(); + context = CGBitmapContextCreate(data, POTWide, POTHigh, 8, POTWide, colorSpace, kCGImageAlphaNone); + CGColorSpaceRelease(colorSpace); + + if( ! context ) { + free(data); + [self release]; + return nil; + } + + CGContextSetGrayFillColor(context, 1.0f, 1.0f); + CGContextTranslateCTM(context, 0.0f, POTHigh); + CGContextScaleCTM(context, 1.0f, -1.0f); //NOTE: NSString draws in UIKit referential i.e. renders upside-down compared to CGBitmapContext referential + + UIGraphicsPushContext(context); + + // normal fonts + if( [uifont isKindOfClass:[UIFont class] ] ) + [string drawInRect:CGRectMake(0, 0, dimensions.width, dimensions.height) withFont:uifont lineBreakMode:lineBreakMode alignment:alignment]; + +#if CC_FONT_LABEL_SUPPORT + else // ZFont class + [string drawInRect:CGRectMake(0, 0, dimensions.width, dimensions.height) withZFont:uifont lineBreakMode:lineBreakMode alignment:alignment]; +#endif + + UIGraphicsPopContext(); + +#if USE_TEXT_WITH_A8_TEXTURES + self = [self initWithData:data pixelFormat:kCCTexture2DPixelFormat_A8 pixelsWide:POTWide pixelsHigh:POTHigh contentSize:dimensions]; + +#else // ! USE_TEXT_WITH_A8_TEXTURES + NSUInteger textureSize = POTWide*POTHigh; + unsigned short *la88_data = (unsigned short*)data; + for(int i = textureSize-1; i>=0; i--) //Convert A8 to AI88 + la88_data[i] = (data[i] << 8) | 0xff; + + self = [self initWithData:data pixelFormat:kCCTexture2DPixelFormat_AI88 pixelsWide:POTWide pixelsHigh:POTHigh contentSize:dimensions]; +#endif // ! USE_TEXT_WITH_A8_TEXTURES + + CGContextRelease(context); + [self releaseData:data]; + + return self; +} + + + +#elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED) + +- (id) initWithString:(NSString*)string dimensions:(CGSize)dimensions alignment:(CCTextAlignment)alignment attributedString:(NSAttributedString*)stringWithAttributes +{ + NSAssert( stringWithAttributes, @"Invalid stringWithAttributes"); + + NSUInteger POTWide = ccNextPOT(dimensions.width); + NSUInteger POTHigh = ccNextPOT(dimensions.height); + unsigned char* data; + + NSSize realDimensions = [stringWithAttributes size]; + + //Alignment + float xPadding = 0; + + // Mac crashes if the width or height is 0 + if( realDimensions.width > 0 && realDimensions.height > 0 ) { + switch (alignment) { + case CCTextAlignmentLeft: xPadding = 0; break; + case CCTextAlignmentCenter: xPadding = (dimensions.width-realDimensions.width)/2.0f; break; + case CCTextAlignmentRight: xPadding = dimensions.width-realDimensions.width; break; + default: break; + } + + //Disable antialias + [[NSGraphicsContext currentContext] setShouldAntialias:NO]; + + NSImage *image = [[NSImage alloc] initWithSize:NSMakeSize(POTWide, POTHigh)]; + [image lockFocus]; + + [stringWithAttributes drawAtPoint:NSMakePoint(xPadding, POTHigh-dimensions.height)]; // draw at offset position + + NSBitmapImageRep *bitmap = [[NSBitmapImageRep alloc] initWithFocusedViewRect:NSMakeRect (0.0f, 0.0f, POTWide, POTHigh)]; + [image unlockFocus]; + + data = (unsigned char*) [bitmap bitmapData]; //Use the same buffer to improve the performance. + + NSUInteger textureSize = POTWide*POTHigh; + for(int i = 0; iwrapS == GL_CLAMP_TO_EDGE && texParams->wrapT == GL_CLAMP_TO_EDGE), + @"GL_CLAMP_TO_EDGE should be used in NPOT textures"); + glBindTexture( GL_TEXTURE_2D, name_ ); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, texParams->minFilter ); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, texParams->magFilter ); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, texParams->wrapS ); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, texParams->wrapT ); +} + +-(void) setAliasTexParameters +{ + ccTexParams texParams = { GL_NEAREST, GL_NEAREST, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE }; + [self setTexParameters: &texParams]; +} + +-(void) setAntiAliasTexParameters +{ + ccTexParams texParams = { GL_LINEAR, GL_LINEAR, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE }; + [self setTexParameters: &texParams]; +} +@end + + +#pragma mark - +#pragma mark CCTexture2D - Pixel Format + +// +// Texture options for images that contains alpha +// +@implementation CCTexture2D (PixelFormat) ++(void) setDefaultAlphaPixelFormat:(CCTexture2DPixelFormat)format +{ + defaultAlphaPixelFormat_ = format; +} + ++(CCTexture2DPixelFormat) defaultAlphaPixelFormat +{ + return defaultAlphaPixelFormat_; +} + +-(NSUInteger) bitsPerPixelForFormat +{ + NSUInteger ret=0; + + switch (format_) { + case kCCTexture2DPixelFormat_RGBA8888: + ret = 32; + break; + case kCCTexture2DPixelFormat_RGB565: + ret = 16; + break; + case kCCTexture2DPixelFormat_A8: + ret = 8; + break; + case kCCTexture2DPixelFormat_RGBA4444: + ret = 16; + break; + case kCCTexture2DPixelFormat_RGB5A1: + ret = 16; + break; + case kCCTexture2DPixelFormat_PVRTC4: + ret = 4; + break; + case kCCTexture2DPixelFormat_PVRTC2: + ret = 2; + break; + case kCCTexture2DPixelFormat_I8: + ret = 8; + break; + case kCCTexture2DPixelFormat_AI88: + ret = 16; + break; + default: + ret = -1; + NSAssert1(NO , @"bitsPerPixelForFormat: %ld, unrecognised pixel format", (long)format_); + CCLOG(@"bitsPerPixelForFormat: %ld, cannot give useful result", (long)format_); + break; + } + return ret; +} +@end + diff --git a/Support/cocos2d/TextureAtlas.h b/tweejump/libs/cocos2d/CCTextureAtlas.h old mode 100644 new mode 100755 similarity index 52% rename from Support/cocos2d/TextureAtlas.h rename to tweejump/libs/cocos2d/CCTextureAtlas.h index 071c966..f70bb54 --- a/Support/cocos2d/TextureAtlas.h +++ b/tweejump/libs/cocos2d/CCTextureAtlas.h @@ -1,19 +1,32 @@ -/* cocos2d for iPhone +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2008,2009 Ricardo Quesada - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. + * Copyright (c) 2008-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. * */ -#import "Texture2D.h" +#import "CCTexture2D.h" #import "ccTypes.h" +#import "ccConfig.h" /** A class that implements a Texture Atlas. Supported features: @@ -24,22 +37,30 @@ * Quads can be re-ordered in runtime * The TextureAtlas capacity can be increased or decreased in runtime * OpenGL component: V3F, C4B, T2F. - The quads are rendered using an OpenGL ES an interleaved vertex array list + The quads are rendered using an OpenGL ES VBO. + To render the quads using an interleaved vertex array list, you should modify the ccConfig.h file */ -@interface TextureAtlas : NSObject { +@interface CCTextureAtlas : NSObject +{ NSUInteger totalQuads_; NSUInteger capacity_; - ccV3F_C4B_T2F_Quad *quads; // quads to be rendered - GLushort *indices; - Texture2D *texture_; + ccV3F_C4B_T2F_Quad *quads_; // quads to be rendered + GLushort *indices_; + CCTexture2D *texture_; +#if CC_USES_VBO + GLuint buffersVBO_[2]; //0: vertex 1: indices + BOOL dirty_; //indicates whether or not the array buffer of the VBO needs to be updated +#endif // CC_USES_VBO } /** quantity of quads that are going to be drawn */ -@property (readonly) NSUInteger totalQuads; +@property (nonatomic,readonly) NSUInteger totalQuads; /** quantity of quads that can be stored with the current texture atlas size */ -@property (readonly) NSUInteger capacity; +@property (nonatomic,readonly) NSUInteger capacity; /** Texture of the texture atlas */ -@property (nonatomic,retain) Texture2D *texture; +@property (nonatomic,retain) CCTexture2D *texture; +/** Quads that are going to be rendered */ +@property (nonatomic,readwrite) ccV3F_C4B_T2F_Quad *quads; /** creates a TextureAtlas with an filename and with an initial capacity for Quads. * The TextureAtlas capacity can be increased in runtime. @@ -48,6 +69,8 @@ /** initializes a TextureAtlas with a filename and with a certain capacity for Quads. * The TextureAtlas capacity can be increased in runtime. + * + * WARNING: Do not reinitialize the TextureAtlas because it will leak memory (issue #706) */ -(id) initWithFile: (NSString*) file capacity:(NSUInteger)capacity; @@ -55,13 +78,15 @@ * with an initial capacity for n Quads. * The TextureAtlas capacity can be increased in runtime. */ -+(id) textureAtlasWithTexture:(Texture2D *)tex capacity:(NSUInteger)capacity; ++(id) textureAtlasWithTexture:(CCTexture2D *)tex capacity:(NSUInteger)capacity; /** initializes a TextureAtlas with a previously initialized Texture2D object, and * with an initial capacity for Quads. * The TextureAtlas capacity can be increased in runtime. + * + * WARNING: Do not reinitialize the TextureAtlas because it will leak memory (issue #706) */ --(id) initWithTexture:(Texture2D *)tex capacity:(NSUInteger)capacity; +-(id) initWithTexture:(CCTexture2D *)tex capacity:(NSUInteger)capacity; /** updates a Quad (texture, vertex and color) at a certain index * index must be between 0 and the atlas capacity - 1 @@ -76,7 +101,7 @@ -(void) insertQuad:(ccV3F_C4B_T2F_Quad*)quad atIndex:(NSUInteger)index; /** Removes the quad that is located at a certain index and inserts it at a new index - This operation is faster than remove and insert in 2 different steps. + This operation is faster than removing and inserting in a quad in 2 different steps @since v0.7.2 */ -(void) insertQuadFromIndex:(NSUInteger)fromIndex atIndex:(NSUInteger)newIndex; @@ -93,9 +118,8 @@ @since v0.7.2 */ -(void) removeAllQuads; - -/** resize the capacity of the Texture Atlas. +/** resize the capacity of the CCTextureAtlas. * The new capacity can be lower or higher than the current one * It returns YES if the resize was successful. * If it fails to resize the capacity it will return NO with a new capacity of 0. @@ -108,6 +132,14 @@ */ -(void) drawNumberOfQuads: (NSUInteger) n; + +/** draws n quads from an index (offset). + n + start can't be greater than the capacity of the atlas + + @since v1.0 + */ +-(void) drawNumberOfQuads: (NSUInteger) n fromIndex: (NSUInteger) start; + /** draws all the Atlas's Quads */ -(void) drawQuads; diff --git a/tweejump/libs/cocos2d/CCTextureAtlas.m b/tweejump/libs/cocos2d/CCTextureAtlas.m new file mode 100755 index 0000000..7c7df75 --- /dev/null +++ b/tweejump/libs/cocos2d/CCTextureAtlas.m @@ -0,0 +1,369 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-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. + * + */ + + +// cocos2d +#import "CCTextureAtlas.h" +#import "ccMacros.h" +#import "CCTexture2D.h" +#import "CCTextureCache.h" + + +@interface CCTextureAtlas (Private) +-(void) initIndices; +@end + +//According to some tests GL_TRIANGLE_STRIP is slower, MUCH slower. Probably I'm doing something very wrong + +@implementation CCTextureAtlas + +@synthesize totalQuads = totalQuads_, capacity = capacity_; +@synthesize texture = texture_; +@synthesize quads = quads_; + +#pragma mark TextureAtlas - alloc & init + ++(id) textureAtlasWithFile:(NSString*) file capacity: (NSUInteger) n +{ + return [[[self alloc] initWithFile:file capacity:n] autorelease]; +} + ++(id) textureAtlasWithTexture:(CCTexture2D *)tex capacity:(NSUInteger)n +{ + return [[[self alloc] initWithTexture:tex capacity:n] autorelease]; +} + +-(id) initWithFile:(NSString*)file capacity:(NSUInteger)n +{ + // retained in property + CCTexture2D *tex = [[CCTextureCache sharedTextureCache] addImage:file]; + if( tex ) + return [self initWithTexture:tex capacity:n]; + + // else + { + CCLOG(@"cocos2d: Could not open file: %@", file); + [self release]; + return nil; + } +} + +-(id) initWithTexture:(CCTexture2D*)tex capacity:(NSUInteger)n +{ + if( (self=[super init]) ) { + + capacity_ = n; + totalQuads_ = 0; + + // retained in property + self.texture = tex; + + // Re-initialization is not allowed + NSAssert(quads_==nil && indices_==nil, @"CCTextureAtlas re-initialization is not allowed"); + + quads_ = calloc( sizeof(quads_[0]) * capacity_, 1 ); + indices_ = calloc( sizeof(indices_[0]) * capacity_ * 6, 1 ); + + if( ! ( quads_ && indices_) ) { + CCLOG(@"cocos2d: CCTextureAtlas: not enough memory"); + if( quads_ ) + free(quads_); + if( indices_ ) + free(indices_); + return nil; + } + +#if CC_USES_VBO + // initial binding + glGenBuffers(2, &buffersVBO_[0]); + dirty_ = YES; +#endif // CC_USES_VBO + + [self initIndices]; + } + + return self; +} + +- (NSString*) description +{ + return [NSString stringWithFormat:@"<%@ = %08X | totalQuads = %i>", [self class], self, totalQuads_]; +} + +-(void) dealloc +{ + CCLOGINFO(@"cocos2d: deallocing %@",self); + + free(quads_); + free(indices_); + +#if CC_USES_VBO + glDeleteBuffers(2, buffersVBO_); +#endif // CC_USES_VBO + + + [texture_ release]; + + [super dealloc]; +} + +-(void) initIndices +{ + for( NSUInteger i=0;i< capacity_;i++) { +#if CC_TEXTURE_ATLAS_USE_TRIANGLE_STRIP + indices_[i*6+0] = i*4+0; + indices_[i*6+1] = i*4+0; + indices_[i*6+2] = i*4+2; + indices_[i*6+3] = i*4+1; + indices_[i*6+4] = i*4+3; + indices_[i*6+5] = i*4+3; +#else + indices_[i*6+0] = i*4+0; + indices_[i*6+1] = i*4+1; + indices_[i*6+2] = i*4+2; + + // inverted index. issue #179 + indices_[i*6+3] = i*4+3; + indices_[i*6+4] = i*4+2; + indices_[i*6+5] = i*4+1; +// indices_[i*6+3] = i*4+2; +// indices_[i*6+4] = i*4+3; +// indices_[i*6+5] = i*4+1; +#endif + } + +#if CC_USES_VBO + glBindBuffer(GL_ARRAY_BUFFER, buffersVBO_[0]); + glBufferData(GL_ARRAY_BUFFER, sizeof(quads_[0]) * capacity_, quads_, GL_DYNAMIC_DRAW); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffersVBO_[1]); + glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices_[0]) * capacity_ * 6, indices_, GL_STATIC_DRAW); + glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); +#endif // CC_USES_VBO +} + +#pragma mark TextureAtlas - Update, Insert, Move & Remove + +-(void) updateQuad:(ccV3F_C4B_T2F_Quad*)quad atIndex:(NSUInteger) n +{ + NSAssert(n < capacity_, @"updateQuadWithTexture: Invalid index"); + + totalQuads_ = MAX( n+1, totalQuads_); + + quads_[n] = *quad; + +#if CC_USES_VBO + dirty_ = YES; +#endif +} + + +-(void) insertQuad:(ccV3F_C4B_T2F_Quad*)quad atIndex:(NSUInteger)index +{ + NSAssert(index < capacity_, @"insertQuadWithTexture: Invalid index"); + + totalQuads_++; + NSAssert( totalQuads_ <= capacity_, @"invalid totalQuads"); + + // issue #575. index can be > totalQuads + NSInteger remaining = (totalQuads_-1) - index; + + // last object doesn't need to be moved + if( remaining > 0) + // tex coordinates + memmove( &quads_[index+1],&quads_[index], sizeof(quads_[0]) * remaining ); + + quads_[index] = *quad; + +#if CC_USES_VBO + dirty_ = YES; +#endif +} + + +-(void) insertQuadFromIndex:(NSUInteger)oldIndex atIndex:(NSUInteger)newIndex +{ + NSAssert(newIndex < totalQuads_, @"insertQuadFromIndex:atIndex: Invalid index"); + NSAssert(oldIndex < totalQuads_, @"insertQuadFromIndex:atIndex: Invalid index"); + + if( oldIndex == newIndex ) + return; + + NSUInteger howMany = labs( oldIndex - newIndex); + NSUInteger dst = oldIndex; + NSUInteger src = oldIndex + 1; + if( oldIndex > newIndex) { + dst = newIndex+1; + src = newIndex; + } + + // tex coordinates + ccV3F_C4B_T2F_Quad quadsBackup = quads_[oldIndex]; + memmove( &quads_[dst],&quads_[src], sizeof(quads_[0]) * howMany ); + quads_[newIndex] = quadsBackup; + +#if CC_USES_VBO + dirty_ = YES; +#endif +} + +-(void) removeQuadAtIndex:(NSUInteger) index +{ + NSAssert(index < totalQuads_, @"removeQuadAtIndex: Invalid index"); + + NSUInteger remaining = (totalQuads_-1) - index; + + + // last object doesn't need to be moved + if( remaining ) + // tex coordinates + memmove( &quads_[index],&quads_[index+1], sizeof(quads_[0]) * remaining ); + + totalQuads_--; + +#if CC_USES_VBO + dirty_ = YES; +#endif +} + +-(void) removeAllQuads +{ + totalQuads_ = 0; +} + +#pragma mark TextureAtlas - Resize + +-(BOOL) resizeCapacity: (NSUInteger) newCapacity +{ + if( newCapacity == capacity_ ) + return YES; + + // update capacity and totolQuads + totalQuads_ = MIN(totalQuads_,newCapacity); + capacity_ = newCapacity; + + void * tmpQuads = realloc( quads_, sizeof(quads_[0]) * capacity_ ); + void * tmpIndices = realloc( indices_, sizeof(indices_[0]) * capacity_ * 6 ); + + if( ! ( tmpQuads && tmpIndices) ) { + CCLOG(@"cocos2d: CCTextureAtlas: not enough memory"); + if( tmpQuads ) + free(tmpQuads); + else + free(quads_); + + if( tmpIndices ) + free(tmpIndices); + else + free(indices_); + + indices_ = nil; + quads_ = nil; + capacity_ = totalQuads_ = 0; + return NO; + } + + quads_ = tmpQuads; + indices_ = tmpIndices; + + [self initIndices]; + +#if CC_USES_VBO + dirty_ = YES; +#endif + return YES; +} + +#pragma mark TextureAtlas - Drawing + +-(void) drawQuads +{ + [self drawNumberOfQuads: totalQuads_ fromIndex:0]; +} + +-(void) drawNumberOfQuads: (NSUInteger) n +{ + [self drawNumberOfQuads:n fromIndex:0]; +} + +-(void) drawNumberOfQuads: (NSUInteger) n fromIndex: (NSUInteger) start +{ + // Default GL states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY + // Needed states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY + // Unneeded states: - + + glBindTexture(GL_TEXTURE_2D, [texture_ name]); +#define kQuadSize sizeof(quads_[0].bl) +#if CC_USES_VBO + glBindBuffer(GL_ARRAY_BUFFER, buffersVBO_[0]); + + // XXX: update is done in draw... perhaps it should be done in a timer + if (dirty_) { + glBufferSubData(GL_ARRAY_BUFFER, sizeof(quads_[0])*start, sizeof(quads_[0]) * n , &quads_[start] ); + dirty_ = NO; + } + + // vertices + glVertexPointer(3, GL_FLOAT, kQuadSize, (GLvoid*) offsetof( ccV3F_C4B_T2F, vertices)); + + // colors + glColorPointer(4, GL_UNSIGNED_BYTE, kQuadSize, (GLvoid*) offsetof( ccV3F_C4B_T2F, colors)); + + // tex coords + glTexCoordPointer(2, GL_FLOAT, kQuadSize, (GLvoid*) offsetof( ccV3F_C4B_T2F, texCoords)); + + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffersVBO_[1]); +#if CC_TEXTURE_ATLAS_USE_TRIANGLE_STRIP + glDrawElements(GL_TRIANGLE_STRIP, (GLsizei) n*6, GL_UNSIGNED_SHORT, (GLvoid*) (start*6*sizeof(indices_[0])) ); +#else + glDrawElements(GL_TRIANGLES, (GLsizei) n*6, GL_UNSIGNED_SHORT, (GLvoid*) (start*6*sizeof(indices_[0])) ); +#endif // CC_TEXTURE_ATLAS_USE_TRIANGLE_STRIP + + glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); +#else // ! CC_USES_VBO + + NSUInteger offset = (NSUInteger)quads_; + // vertex + NSUInteger diff = offsetof( ccV3F_C4B_T2F, vertices); + glVertexPointer(3, GL_FLOAT, kQuadSize, (GLvoid*) (offset + diff) ); + // color + diff = offsetof( ccV3F_C4B_T2F, colors); + glColorPointer(4, GL_UNSIGNED_BYTE, kQuadSize, (GLvoid*)(offset + diff)); + + // tex coords + diff = offsetof( ccV3F_C4B_T2F, texCoords); + glTexCoordPointer(2, GL_FLOAT, kQuadSize, (GLvoid*)(offset + diff)); + +#if CC_TEXTURE_ATLAS_USE_TRIANGLE_STRIP + glDrawElements(GL_TRIANGLE_STRIP, n*6, GL_UNSIGNED_SHORT, indices_ + start * 6 ); +#else + glDrawElements(GL_TRIANGLES, n*6, GL_UNSIGNED_SHORT, indices_ + start * 6 ); +#endif + +#endif // CC_USES_VBO +} +@end diff --git a/tweejump/libs/cocos2d/CCTextureCache.h b/tweejump/libs/cocos2d/CCTextureCache.h new file mode 100755 index 0000000..7084793 --- /dev/null +++ b/tweejump/libs/cocos2d/CCTextureCache.h @@ -0,0 +1,149 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-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. + * + */ + +#import + +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED +#import +#endif + +#import + +@class CCTexture2D; + +/** Singleton that handles the loading of textures + * Once the texture is loaded, the next time it will return + * a reference of the previously loaded texture reducing GPU & CPU memory + */ +@interface CCTextureCache : NSObject +{ + NSMutableDictionary *textures_; + NSLock *dictLock_; + NSLock *contextLock_; +} + +/** Retruns ths shared instance of the cache */ ++ (CCTextureCache *) sharedTextureCache; + +/** purges the cache. It releases the retained instance. + @since v0.99.0 + */ ++(void)purgeSharedTextureCache; + + +/** Returns a Texture2D object given an file image + * If the file image was not previously loaded, it will create a new CCTexture2D + * object and it will return it. It will use the filename as a key. + * Otherwise it will return a reference of a previosly loaded image. + * Supported image extensions: .png, .bmp, .tiff, .jpeg, .pvr, .gif + */ +-(CCTexture2D*) addImage: (NSString*) fileimage; + +/** Returns a Texture2D object given a file image + * If the file image was not previously loaded, it will create a new CCTexture2D object and it will return it. + * Otherwise it will load a texture in a new thread, and when the image is loaded, the callback will be called with the Texture2D as a parameter. + * The callback will be called from the main thread, so it is safe to create any cocos2d object from the callback. + * Supported image extensions: .png, .bmp, .tiff, .jpeg, .pvr, .gif + * @since v0.8 + */ +-(void) addImageAsync:(NSString*) filename target:(id)target selector:(SEL)selector; + +/** Returns a Texture2D object given an CGImageRef image + * If the image was not previously loaded, it will create a new CCTexture2D object and it will return it. + * Otherwise it will return a reference of a previously loaded image + * The "key" parameter will be used as the "key" for the cache. + * If "key" is nil, then a new texture will be created each time. + * @since v0.8 + */ +-(CCTexture2D*) addCGImage: (CGImageRef) image forKey: (NSString *)key; + +/** Returns an already created texture. Returns nil if the texture doesn't exist. + @since v0.99.5 + */ +-(CCTexture2D *) textureForKey:(NSString *)key; + +/** Purges the dictionary of loaded textures. + * Call this method if you receive the "Memory Warning" + * In the short term: it will free some resources preventing your app from being killed + * In the medium term: it will allocate more resources + * In the long term: it will be the same + */ +-(void) removeAllTextures; + +/** Removes unused textures + * Textures that have a retain count of 1 will be deleted + * It is convinient to call this method after when starting a new Scene + * @since v0.8 + */ +-(void) removeUnusedTextures; + +/** Deletes a texture from the cache given a texture + */ +-(void) removeTexture: (CCTexture2D*) tex; + +/** Deletes a texture from the cache given a its key name + @since v0.99.4 + */ +-(void) removeTextureForKey: (NSString*) textureKeyName; + +@end + + +@interface CCTextureCache (PVRSupport) + +/** Returns a Texture2D object given an PVRTC RAW filename + * If the file image was not previously loaded, it will create a new CCTexture2D + * object and it will return it. Otherwise it will return a reference of a previosly loaded image + * + * It can only load square images: width == height, and it must be a power of 2 (128,256,512...) + * bpp can only be 2 or 4. 2 means more compression but lower quality. + * hasAlpha: whether or not the image contains alpha channel + * + * IMPORTANT: This method is only defined on iOS. It is not supported on the Mac version. + */ +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED +-(CCTexture2D*) addPVRTCImage:(NSString*)fileimage bpp:(int)bpp hasAlpha:(BOOL)alpha width:(int)w; +#endif // __IPHONE_OS_VERSION_MAX_ALLOWED + +/** Returns a Texture2D object given an PVR filename. + * If the file image was not previously loaded, it will create a new CCTexture2D + * object and it will return it. Otherwise it will return a reference of a previosly loaded image + * + */ +-(CCTexture2D*) addPVRImage:(NSString*) filename; + +@end + + +@interface CCTextureCache (Debug) +/** Output to CCLOG the current contents of this CCTextureCache + * This will attempt to calculate the size of each texture, and the total texture memory in use + * + * @since v1.0 + */ +-(void) dumpCachedTextureInfo; + +@end diff --git a/tweejump/libs/cocos2d/CCTextureCache.m b/tweejump/libs/cocos2d/CCTextureCache.m new file mode 100755 index 0000000..2f59514 --- /dev/null +++ b/tweejump/libs/cocos2d/CCTextureCache.m @@ -0,0 +1,498 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-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. + * + */ + +#import + +#import "Platforms/CCGL.h" +#import "CCTextureCache.h" +#import "CCTexture2D.h" +#import "CCTexturePVR.h" +#import "ccMacros.h" +#import "CCConfiguration.h" +#import "Support/CCFileUtils.h" +#import "CCDirector.h" +#import "ccConfig.h" + +// needed for CCCallFuncO in Mac-display_link version +#import "CCActionManager.h" +#import "CCActionInstant.h" + +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED +static EAGLContext *auxGLcontext = nil; +#elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED) +static NSOpenGLContext *auxGLcontext = nil; +#endif + + +@interface CCAsyncObject : NSObject +{ + SEL selector_; + id target_; + id data_; +} +@property (nonatomic,readwrite,assign) SEL selector; +@property (nonatomic,readwrite,retain) id target; +@property (nonatomic,readwrite,retain) id data; +@end + +@implementation CCAsyncObject +@synthesize selector = selector_; +@synthesize target = target_; +@synthesize data = data_; +- (void) dealloc +{ + CCLOGINFO(@"cocos2d: deallocing %@", self); + [target_ release]; + [data_ release]; + [super dealloc]; +} +@end + + +@implementation CCTextureCache + +#pragma mark TextureCache - Alloc, Init & Dealloc +static CCTextureCache *sharedTextureCache; + ++ (CCTextureCache *)sharedTextureCache +{ + if (!sharedTextureCache) + sharedTextureCache = [[CCTextureCache alloc] init]; + + return sharedTextureCache; +} + ++(id)alloc +{ + NSAssert(sharedTextureCache == nil, @"Attempted to allocate a second instance of a singleton."); + return [super alloc]; +} + ++(void)purgeSharedTextureCache +{ + [sharedTextureCache release]; + sharedTextureCache = nil; +} + +-(id) init +{ + if( (self=[super init]) ) { + textures_ = [[NSMutableDictionary dictionaryWithCapacity: 10] retain]; + dictLock_ = [[NSLock alloc] init]; + contextLock_ = [[NSLock alloc] init]; + } + + return self; +} + +- (NSString*) description +{ + return [NSString stringWithFormat:@"<%@ = %08X | num of textures = %i | keys: %@>", + [self class], + self, + [textures_ count], + [textures_ allKeys] + ]; + +} + +-(void) dealloc +{ + CCLOGINFO(@"cocos2d: deallocing %@", self); + + [textures_ release]; + [dictLock_ release]; + [contextLock_ release]; + [auxGLcontext release]; + auxGLcontext = nil; + sharedTextureCache = nil; + [super dealloc]; +} + +#pragma mark TextureCache - Add Images + +-(void) addImageWithAsyncObject:(CCAsyncObject*)async +{ + NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init]; + +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED + // textures will be created on the main OpenGL context + // it seems that in SDK 2.2.x there can't be 2 threads creating textures at the same time + // the lock is used for this purpose: issue #472 + [contextLock_ lock]; + if( auxGLcontext == nil ) { + auxGLcontext = [[EAGLContext alloc] + initWithAPI:kEAGLRenderingAPIOpenGLES1 + sharegroup:[[[[CCDirector sharedDirector] openGLView] context] sharegroup]]; + + if( ! auxGLcontext ) + CCLOG(@"cocos2d: TextureCache: Could not create EAGL context"); + } + + if( [EAGLContext setCurrentContext:auxGLcontext] ) { + + // load / create the texture + CCTexture2D *tex = [self addImage:async.data]; + + // The callback will be executed on the main thread + [async.target performSelectorOnMainThread:async.selector withObject:tex waitUntilDone:NO]; + + [EAGLContext setCurrentContext:nil]; + } else { + CCLOG(@"cocos2d: TetureCache: EAGLContext error"); + } + [contextLock_ unlock]; + + [autoreleasepool release]; + +#elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED) + + [contextLock_ lock]; + if( auxGLcontext == nil ) { + + MacGLView *view = [[CCDirector sharedDirector] openGLView]; + + NSOpenGLPixelFormat *pf = [view pixelFormat]; + NSOpenGLContext *share = [view openGLContext]; + + auxGLcontext = [[NSOpenGLContext alloc] initWithFormat:pf shareContext:share]; + + if( ! auxGLcontext ) + CCLOG(@"cocos2d: TextureCache: Could not create NSOpenGLContext"); + } + + [auxGLcontext makeCurrentContext]; + + // load / create the texture + CCTexture2D *tex = [self addImage:async.data]; + +#if CC_DIRECTOR_MAC_USE_DISPLAY_LINK_THREAD + id action = [CCCallFuncO actionWithTarget:async.target selector:async.selector object:tex]; + [[CCActionManager sharedManager] addAction:action target:async.target paused:NO]; +#else + // The callback will be executed on the main thread + [async.target performSelector:async.selector + onThread:[[CCDirector sharedDirector] runningThread] + withObject:tex + waitUntilDone:NO]; +#endif + + + [NSOpenGLContext clearCurrentContext]; + + [contextLock_ unlock]; + + [autoreleasepool release]; + +#endif // __MAC_OS_X_VERSION_MAX_ALLOWED +} + +-(void) addImageAsync: (NSString*)path target:(id)target selector:(SEL)selector +{ + NSAssert(path != nil, @"TextureCache: fileimage MUST not be nill"); + + // optimization + + CCTexture2D * tex; + + path = ccRemoveHDSuffixFromFile(path); + + if( (tex=[textures_ objectForKey: path] ) ) { + [target performSelector:selector withObject:tex]; + return; + } + + // schedule the load + + CCAsyncObject *asyncObject = [[CCAsyncObject alloc] init]; + asyncObject.selector = selector; + asyncObject.target = target; + asyncObject.data = path; + + [NSThread detachNewThreadSelector:@selector(addImageWithAsyncObject:) toTarget:self withObject:asyncObject]; + [asyncObject release]; +} + +-(CCTexture2D*) addImage: (NSString*) path +{ + NSAssert(path != nil, @"TextureCache: fileimage MUST not be nill"); + + CCTexture2D * tex = nil; + + // MUTEX: + // Needed since addImageAsync calls this method from a different thread + [dictLock_ lock]; + + // remove possible -HD suffix to prevent caching the same image twice (issue #1040) + path = ccRemoveHDSuffixFromFile( path ); + + tex=[textures_ objectForKey: path]; + + if( ! tex ) { + + NSString *lowerCase = [path lowercaseString]; + // all images are handled by UIImage except PVR extension that is handled by our own handler + + if ( [lowerCase hasSuffix:@".pvr"] || [lowerCase hasSuffix:@".pvr.gz"] || [lowerCase hasSuffix:@".pvr.ccz"] ) + tex = [self addPVRImage:path]; + + // Only iPhone +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED + + // Issue #886: TEMPORARY FIX FOR TRANSPARENT JPEGS IN IOS4 + else if ( ( [[CCConfiguration sharedConfiguration] OSVersion] >= kCCiOSVersion_4_0) && + ( [lowerCase hasSuffix:@".jpg"] || [lowerCase hasSuffix:@".jpeg"] ) + ) { + // convert jpg to png before loading the texture + + NSString *fullpath = [CCFileUtils fullPathFromRelativePath: path ]; + + UIImage *jpg = [[UIImage alloc] initWithContentsOfFile:fullpath]; + UIImage *png = [[UIImage alloc] initWithData:UIImagePNGRepresentation(jpg)]; + tex = [ [CCTexture2D alloc] initWithImage: png ]; + [png release]; + [jpg release]; + + if( tex ) + [textures_ setObject: tex forKey:path]; + else + CCLOG(@"cocos2d: Couldn't add image:%@ in CCTextureCache", path); + + // autorelease prevents possible crash in multithreaded environments + [tex autorelease]; + } + + else { + + // prevents overloading the autorelease pool + NSString *fullpath = [CCFileUtils fullPathFromRelativePath: path ]; + + UIImage *image = [ [UIImage alloc] initWithContentsOfFile: fullpath ]; + tex = [ [CCTexture2D alloc] initWithImage: image ]; + [image release]; + + if( tex ) + [textures_ setObject: tex forKey:path]; + else + CCLOG(@"cocos2d: Couldn't add image:%@ in CCTextureCache", path); + + // autorelease prevents possible crash in multithreaded environments + [tex autorelease]; + } + + // Only in Mac +#elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED) + else { + NSString *fullpath = [CCFileUtils fullPathFromRelativePath: path ]; + + NSData *data = [[NSData alloc] initWithContentsOfFile:fullpath]; + NSBitmapImageRep *image = [[NSBitmapImageRep alloc] initWithData:data]; + tex = [ [CCTexture2D alloc] initWithImage:[image CGImage]]; + + [data release]; + [image release]; + + if( tex ) + [textures_ setObject: tex forKey:path]; + else + CCLOG(@"cocos2d: Couldn't add image:%@ in CCTextureCache", path); + + // autorelease prevents possible crash in multithreaded environments + [tex autorelease]; + } +#endif // __MAC_OS_X_VERSION_MAX_ALLOWED + + } + + [dictLock_ unlock]; + + return tex; +} + + +-(CCTexture2D*) addCGImage: (CGImageRef) imageref forKey: (NSString *)key +{ + NSAssert(imageref != nil, @"TextureCache: image MUST not be nill"); + + CCTexture2D * tex = nil; + + // If key is nil, then create a new texture each time + if( key && (tex=[textures_ objectForKey: key] ) ) { + return tex; + } + +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED + // prevents overloading the autorelease pool + UIImage *image = [[UIImage alloc] initWithCGImage:imageref]; + tex = [[CCTexture2D alloc] initWithImage: image]; + [image release]; + +#elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED) + tex = [[CCTexture2D alloc] initWithImage: imageref]; +#endif + + if(tex && key) + [textures_ setObject: tex forKey:key]; + else + CCLOG(@"cocos2d: Couldn't add CGImage in CCTextureCache"); + + return [tex autorelease]; +} + +#pragma mark TextureCache - Remove + +-(void) removeAllTextures +{ + [textures_ removeAllObjects]; +} + +-(void) removeUnusedTextures +{ + NSArray *keys = [textures_ allKeys]; + for( id key in keys ) { + id value = [textures_ objectForKey:key]; + if( [value retainCount] == 1 ) { + CCLOG(@"cocos2d: CCTextureCache: removing unused texture: %@", key); + [textures_ removeObjectForKey:key]; + } + } +} + +-(void) removeTexture: (CCTexture2D*) tex +{ + if( ! tex ) + return; + + NSArray *keys = [textures_ allKeysForObject:tex]; + + for( NSUInteger i = 0; i < [keys count]; i++ ) + [textures_ removeObjectForKey:[keys objectAtIndex:i]]; +} + +-(void) removeTextureForKey:(NSString*)name +{ + if( ! name ) + return; + + [textures_ removeObjectForKey:name]; +} + +#pragma mark TextureCache - Get +- (CCTexture2D *)textureForKey:(NSString *)key +{ + return [textures_ objectForKey:key]; +} + +@end + + +@implementation CCTextureCache (PVRSupport) + +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED +-(CCTexture2D*) addPVRTCImage:(NSString*)path bpp:(int)bpp hasAlpha:(BOOL)alpha width:(int)w +{ + NSAssert(path != nil, @"TextureCache: fileimage MUST not be nill"); + NSAssert( bpp==2 || bpp==4, @"TextureCache: bpp must be either 2 or 4"); + + CCTexture2D * tex; + + // remove possible -HD suffix to prevent caching the same image twice (issue #1040) + path = ccRemoveHDSuffixFromFile( path ); + + if( (tex=[textures_ objectForKey: path] ) ) { + return tex; + } + + // Split up directory and filename + NSString *fullpath = [CCFileUtils fullPathFromRelativePath:path]; + + NSData *nsdata = [[NSData alloc] initWithContentsOfFile:fullpath]; + tex = [[CCTexture2D alloc] initWithPVRTCData:[nsdata bytes] level:0 bpp:bpp hasAlpha:alpha length:w pixelFormat:bpp==2?kCCTexture2DPixelFormat_PVRTC2:kCCTexture2DPixelFormat_PVRTC4]; + if( tex ) + [textures_ setObject: tex forKey:path]; + else + CCLOG(@"cocos2d: Couldn't add PVRTCImage:%@ in CCTextureCache",path); + + [nsdata release]; + + return [tex autorelease]; +} +#endif // __IPHONE_OS_VERSION_MAX_ALLOWED + +-(CCTexture2D*) addPVRImage:(NSString*)path +{ + NSAssert(path != nil, @"TextureCache: fileimage MUST not be nill"); + + CCTexture2D * tex; + + // remove possible -HD suffix to prevent caching the same image twice (issue #1040) + path = ccRemoveHDSuffixFromFile( path ); + + if( (tex=[textures_ objectForKey: path] ) ) { + return tex; + } + + // Split up directory and filename + NSString *fullpath = [CCFileUtils fullPathFromRelativePath:path]; + + tex = [[CCTexture2D alloc] initWithPVRFile: fullpath]; + if( tex ) + [textures_ setObject: tex forKey:path]; + else + CCLOG(@"cocos2d: Couldn't add PVRImage:%@ in CCTextureCache",path); + + return [tex autorelease]; +} + +@end + + +@implementation CCTextureCache (Debug) + +-(void) dumpCachedTextureInfo +{ + NSUInteger count = 0; + NSUInteger totalBytes = 0; + for (NSString* texKey in textures_) { + CCTexture2D* tex = [textures_ objectForKey:texKey]; + NSUInteger bpp = [tex bitsPerPixelForFormat]; + // Each texture takes up width * height * bytesPerPixel bytes. + NSUInteger bytes = tex.pixelsWide * tex.pixelsHigh * bpp / 8; + totalBytes += bytes; + count++; + CCLOG( @"cocos2d: \"%@\" rc=%lu id=%lu %lu x %lu @ %ld bpp => %lu KB", + texKey, + (long)[tex retainCount], + (long)tex.name, + (long)tex.pixelsWide, + (long)tex.pixelsHigh, + (long)bpp, + (long)bytes / 1024 ); + } + CCLOG( @"cocos2d: CCTextureCache dumpDebugInfo: %ld textures, for %lu KB (%.2f MB)", (long)count, (long)totalBytes / 1024, totalBytes / (1024.0f*1024.0f)); +} + +@end diff --git a/Support/cocos2d/Support/PVRTexture.h b/tweejump/libs/cocos2d/CCTexturePVR.h similarity index 61% rename from Support/cocos2d/Support/PVRTexture.h rename to tweejump/libs/cocos2d/CCTexturePVR.h index 4d52062..66f8286 100755 --- a/Support/cocos2d/Support/PVRTexture.h +++ b/tweejump/libs/cocos2d/CCTexturePVR.h @@ -45,36 +45,82 @@ Copyright (C) 2008 Apple Inc. All Rights Reserved. */ -#import -#import -#import - -@interface PVRTexture : NSObject +#import + +#import "Platforms/CCGL.h" +#import "CCTexture2D.h" + + +#pragma mark - +#pragma mark CCTexturePVR + +struct CCPVRMipmap { + unsigned char *address; + unsigned int len; +}; + +enum { + CC_PVRMIPMAP_MAX = 16, +}; + +/** CCTexturePVR + + Object that loads PVR images. + + Supported PVR formats: + - RGBA8888 + - BGRA8888 + - RGBA4444 + - RGBA5551 + - RGB565 + - A8 + - I8 + - AI88 + - PVRTC 4BPP + - PVRTC 2BPP + + Limitations: + Pre-generated mipmaps, such as PVR textures with mipmap levels embedded in file, + are only supported if all individual sprites are of _square_ size. + To use mipmaps with non-square textures, instead call CCTexture2D#generateMipmap on the sheet texture itself + (and to save space, save the PVR sprite sheet without mip maps included). + */ +@interface CCTexturePVR : NSObject { - NSMutableArray *_imageData; + struct CCPVRMipmap mipmaps_[CC_PVRMIPMAP_MAX]; // pointer to mipmap images + int numberOfMipmaps_; // number of mipmap used - GLuint _name; - uint32_t _width, _height; - GLenum _internalFormat; - BOOL _hasAlpha; + unsigned int tableFormatIndex_; + uint32_t width_, height_; + GLuint name_; + BOOL hasAlpha_; // cocos2d integration - BOOL _retainName; + BOOL retainName_; + CCTexture2DPixelFormat format_; } +/** initializes a CCTexturePVR with a path */ - (id)initWithContentsOfFile:(NSString *)path; +/** initializes a CCTexturePVR with an URL */ - (id)initWithContentsOfURL:(NSURL *)url; +/** creates and initializes a CCTexturePVR with a path */ + (id)pvrTextureWithContentsOfFile:(NSString *)path; +/** creates and initializes a CCTexturePVR with an URL */ + (id)pvrTextureWithContentsOfURL:(NSURL *)url; -@property (readonly) GLuint name; -@property (readonly) uint32_t width; -@property (readonly) uint32_t height; -@property (readonly) GLenum internalFormat; -@property (readonly) BOOL hasAlpha; +/** texture id name */ +@property (nonatomic,readonly) GLuint name; +/** texture width */ +@property (nonatomic,readonly) uint32_t width; +/** texture height */ +@property (nonatomic,readonly) uint32_t height; +/** whether or not the texture has alpha */ +@property (nonatomic,readonly) BOOL hasAlpha; // cocos2d integration -@property (readwrite) BOOL retainName; +@property (nonatomic,readwrite) BOOL retainName; +@property (nonatomic,readonly) CCTexture2DPixelFormat format; @end diff --git a/tweejump/libs/cocos2d/CCTexturePVR.m b/tweejump/libs/cocos2d/CCTexturePVR.m new file mode 100755 index 0000000..692d5f9 --- /dev/null +++ b/tweejump/libs/cocos2d/CCTexturePVR.m @@ -0,0 +1,428 @@ +/* + +File: PVRTexture.m +Abstract: The PVRTexture class is responsible for loading .pvr files. + +Version: 1.0 + +Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc. +("Apple") in consideration of your agreement to the following terms, and your +use, installation, modification or redistribution of this Apple software +constitutes acceptance of these terms. If you do not agree with these terms, +please do not use, install, modify or redistribute this Apple software. + +In consideration of your agreement to abide by the following terms, and subject +to these terms, Apple grants you a personal, non-exclusive license, under +Apple's copyrights in this original Apple software (the "Apple Software"), to +use, reproduce, modify and redistribute the Apple Software, with or without +modifications, in source and/or binary forms; provided that if you redistribute +the Apple Software in its entirety and without modifications, you must retain +this notice and the following text and disclaimers in all such redistributions +of the Apple Software. +Neither the name, trademarks, service marks or logos of Apple Inc. may be used +to endorse or promote products derived from the Apple Software without specific +prior written permission from Apple. Except as expressly stated in this notice, +no other rights or licenses, express or implied, are granted by Apple herein, +including but not limited to any patent rights that may be infringed by your +derivative works or by other works in which the Apple Software may be +incorporated. + +The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO +WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED +WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN +COMBINATION WITH YOUR PRODUCTS. + +IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE +GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR +DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF +CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF +APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +Copyright (C) 2008 Apple Inc. All Rights Reserved. + +*/ + +/* + * Extended PVR formats for cocos2d project ( http://www.cocos2d-iphone.org ) + * - RGBA8888 + * - BGRA8888 + * - RGBA4444 + * - RGBA5551 + * - RGB565 + * - A8 + * - I8 + * - AI88 + */ + +#import + +#import + +#import "CCTexturePVR.h" +#import "ccMacros.h" +#import "CCConfiguration.h" +#import "Support/ccUtils.h" +#import "Support/CCFileUtils.h" +#import "Support/ZipUtils.h" +#import "Support/OpenGL_Internal.h" + +#pragma mark - +#pragma mark CCTexturePVR + +#define PVR_TEXTURE_FLAG_TYPE_MASK 0xff + +// Values taken from PVRTexture.h from http://www.imgtec.com +enum { + kPVRTextureFlagMipmap = (1<<8), // has mip map levels + kPVRTextureFlagTwiddle = (1<<9), // is twiddled + kPVRTextureFlagBumpmap = (1<<10), // has normals encoded for a bump map + kPVRTextureFlagTiling = (1<<11), // is bordered for tiled pvr + kPVRTextureFlagCubemap = (1<<12), // is a cubemap/skybox + kPVRTextureFlagFalseMipCol = (1<<13), // are there false coloured MIP levels + kPVRTextureFlagVolume = (1<<14), // is this a volume texture + kPVRTextureFlagAlpha = (1<<15), // v2.1 is there transparency info in the texture + kPVRTextureFlagVerticalFlip = (1<<16), // v2.1 is the texture vertically flipped +}; + + +static char gPVRTexIdentifier[4] = "PVR!"; + +enum +{ + kPVRTexturePixelTypeRGBA_4444= 0x10, + kPVRTexturePixelTypeRGBA_5551, + kPVRTexturePixelTypeRGBA_8888, + kPVRTexturePixelTypeRGB_565, + kPVRTexturePixelTypeRGB_555, // unsupported + kPVRTexturePixelTypeRGB_888, // unsupported + kPVRTexturePixelTypeI_8, + kPVRTexturePixelTypeAI_88, + kPVRTexturePixelTypePVRTC_2, + kPVRTexturePixelTypePVRTC_4, + kPVRTexturePixelTypeBGRA_8888, + kPVRTexturePixelTypeA_8, +}; + +static const uint32_t tableFormats[][7] = { + + // - PVR texture format + // - OpenGL internal format + // - OpenGL format + // - OpenGL type + // - bpp + // - compressed + // - Cocos2d texture format constant + { kPVRTexturePixelTypeRGBA_4444, GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, 16, NO, kCCTexture2DPixelFormat_RGBA4444 }, + { kPVRTexturePixelTypeRGBA_5551, GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, 16, NO, kCCTexture2DPixelFormat_RGB5A1 }, + { kPVRTexturePixelTypeRGBA_8888, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, 32, NO, kCCTexture2DPixelFormat_RGBA8888 }, + { kPVRTexturePixelTypeRGB_565, GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, 16, NO, kCCTexture2DPixelFormat_RGB565 }, + { kPVRTexturePixelTypeA_8, GL_ALPHA, GL_ALPHA, GL_UNSIGNED_BYTE, 8, NO, kCCTexture2DPixelFormat_A8 }, + { kPVRTexturePixelTypeI_8, GL_LUMINANCE, GL_LUMINANCE, GL_UNSIGNED_BYTE, 8, NO, kCCTexture2DPixelFormat_I8 }, + { kPVRTexturePixelTypeAI_88, GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, 16, NO, kCCTexture2DPixelFormat_AI88 }, +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED + { kPVRTexturePixelTypePVRTC_2, GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG, -1, -1, 2, YES, kCCTexture2DPixelFormat_PVRTC2 }, + { kPVRTexturePixelTypePVRTC_4, GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG, -1, -1, 4, YES, kCCTexture2DPixelFormat_PVRTC4 }, +#endif // iphone only + { kPVRTexturePixelTypeBGRA_8888, GL_RGBA, GL_BGRA, GL_UNSIGNED_BYTE, 32, NO, kCCTexture2DPixelFormat_RGBA8888 }, +}; +#define MAX_TABLE_ELEMENTS (sizeof(tableFormats) / sizeof(tableFormats[0])) + +enum { + kCCInternalPVRTextureFormat, + kCCInternalOpenGLInternalFormat, + kCCInternalOpenGLFormat, + kCCInternalOpenGLType, + kCCInternalBPP, + kCCInternalCompressedImage, + kCCInternalCCTexture2DPixelFormat, +}; + +typedef struct _PVRTexHeader +{ + uint32_t headerLength; + uint32_t height; + uint32_t width; + uint32_t numMipmaps; + uint32_t flags; + uint32_t dataLength; + uint32_t bpp; + uint32_t bitmaskRed; + uint32_t bitmaskGreen; + uint32_t bitmaskBlue; + uint32_t bitmaskAlpha; + uint32_t pvrTag; + uint32_t numSurfs; +} PVRTexHeader; + + +@implementation CCTexturePVR + +@synthesize name = name_; +@synthesize width = width_; +@synthesize height = height_; +@synthesize hasAlpha = hasAlpha_; + +// cocos2d integration +@synthesize retainName = retainName_; +@synthesize format = format_; + + +- (BOOL)unpackPVRData:(unsigned char*)data PVRLen:(NSUInteger)len +{ + BOOL success = FALSE; + PVRTexHeader *header = NULL; + uint32_t flags, pvrTag; + uint32_t dataLength = 0, dataOffset = 0, dataSize = 0; + uint32_t blockSize = 0, widthBlocks = 0, heightBlocks = 0; + uint32_t width = 0, height = 0, bpp = 4; + uint8_t *bytes = NULL; + uint32_t formatFlags; + + header = (PVRTexHeader *)data; + + pvrTag = CFSwapInt32LittleToHost(header->pvrTag); + + if ((uint32_t)gPVRTexIdentifier[0] != ((pvrTag >> 0) & 0xff) || + (uint32_t)gPVRTexIdentifier[1] != ((pvrTag >> 8) & 0xff) || + (uint32_t)gPVRTexIdentifier[2] != ((pvrTag >> 16) & 0xff) || + (uint32_t)gPVRTexIdentifier[3] != ((pvrTag >> 24) & 0xff)) + { + return FALSE; + } + + CCConfiguration *configuration = [CCConfiguration sharedConfiguration]; + + flags = CFSwapInt32LittleToHost(header->flags); + formatFlags = flags & PVR_TEXTURE_FLAG_TYPE_MASK; + BOOL flipped = flags & kPVRTextureFlagVerticalFlip; + if( flipped ) + CCLOG(@"cocos2d: WARNING: Image is flipped. Regenerate it using PVRTexTool"); + + if( ! [configuration supportsNPOT] && + ( header->width != ccNextPOT(header->width) || header->height != ccNextPOT(header->height ) ) ) { + CCLOG(@"cocos2d: ERROR: Loding an NPOT texture (%dx%d) but is not supported on this device", header->width, header->height); + return FALSE; + } + + for( tableFormatIndex_=0; tableFormatIndex_ < (unsigned int)MAX_TABLE_ELEMENTS ; tableFormatIndex_++) { + if( tableFormats[tableFormatIndex_][kCCInternalPVRTextureFormat] == formatFlags ) { + + numberOfMipmaps_ = 0; + + width_ = width = CFSwapInt32LittleToHost(header->width); + height_ = height = CFSwapInt32LittleToHost(header->height); + + if (CFSwapInt32LittleToHost(header->bitmaskAlpha)) + hasAlpha_ = TRUE; + else + hasAlpha_ = FALSE; + + dataLength = CFSwapInt32LittleToHost(header->dataLength); + bytes = ((uint8_t *)data) + sizeof(PVRTexHeader); + format_ = tableFormats[tableFormatIndex_][kCCInternalCCTexture2DPixelFormat]; + bpp = tableFormats[tableFormatIndex_][kCCInternalBPP]; + + // Calculate the data size for each texture level and respect the minimum number of blocks + while (dataOffset < dataLength) + { + switch (formatFlags) { + case kPVRTexturePixelTypePVRTC_2: + blockSize = 8 * 4; // Pixel by pixel block size for 2bpp + widthBlocks = width / 8; + heightBlocks = height / 4; + break; + case kPVRTexturePixelTypePVRTC_4: + blockSize = 4 * 4; // Pixel by pixel block size for 4bpp + widthBlocks = width / 4; + heightBlocks = height / 4; + break; + case kPVRTexturePixelTypeBGRA_8888: + if( ! [[CCConfiguration sharedConfiguration] supportsBGRA8888] ) { + CCLOG(@"cocos2d: TexturePVR. BGRA8888 not supported on this device"); + return FALSE; + } + default: + blockSize = 1; + widthBlocks = width; + heightBlocks = height; + break; + } + + // Clamp to minimum number of blocks + if (widthBlocks < 2) + widthBlocks = 2; + if (heightBlocks < 2) + heightBlocks = 2; + + dataSize = widthBlocks * heightBlocks * ((blockSize * bpp) / 8); + float packetLength = (dataLength-dataOffset); + packetLength = packetLength > dataSize ? dataSize : packetLength; + + mipmaps_[numberOfMipmaps_].address = bytes+dataOffset; + mipmaps_[numberOfMipmaps_].len = packetLength; + numberOfMipmaps_++; + + NSAssert( numberOfMipmaps_ < CC_PVRMIPMAP_MAX, @"TexturePVR: Maximum number of mimpaps reached. Increate the CC_PVRMIPMAP_MAX value"); + + dataOffset += packetLength; + + width = MAX(width >> 1, 1); + height = MAX(height >> 1, 1); + } + + success = TRUE; + break; + } + } + + if( ! success ) + CCLOG(@"cocos2d: WARNING: Unsupported PVR Pixel Format: 0x%2x. Re-encode it with a OpenGL pixel format variant", formatFlags); + + return success; +} + + +- (BOOL)createGLTexture +{ + GLsizei width = width_; + GLsizei height = height_; + GLenum err; + + if (numberOfMipmaps_ > 0) + { + if (name_ != 0) + glDeleteTextures(1, &name_); + + glPixelStorei(GL_UNPACK_ALIGNMENT,1); + glGenTextures(1, &name_); + glBindTexture(GL_TEXTURE_2D, name_); + } + + CHECK_GL_ERROR(); // clean possible GL error + + // Generate textures with mipmaps + for (GLint i=0; i < numberOfMipmaps_; i++) + { + GLenum internalFormat = tableFormats[tableFormatIndex_][kCCInternalOpenGLInternalFormat]; + GLenum format = tableFormats[tableFormatIndex_][kCCInternalOpenGLFormat]; + GLenum type = tableFormats[tableFormatIndex_][kCCInternalOpenGLType]; + BOOL compressed = tableFormats[tableFormatIndex_][kCCInternalCompressedImage]; + + if( compressed && ! [[CCConfiguration sharedConfiguration] supportsPVRTC] ) { + CCLOG(@"cocos2d: WARNING: PVRTC images are not supported"); + return FALSE; + } + + unsigned char *data = mipmaps_[i].address; + unsigned int datalen = mipmaps_[i].len; + + if( compressed) + glCompressedTexImage2D(GL_TEXTURE_2D, i, internalFormat, width, height, 0, datalen, data); + else + glTexImage2D(GL_TEXTURE_2D, i, internalFormat, width, height, 0, format, type, data); + + if( i > 0 && (width != height || ccNextPOT(width) != width ) ) + CCLOG(@"cocos2d: TexturePVR. WARNING. Mipmap level %u is not squared. Texture won't render correctly. width=%u != height=%u", i, width, height); + + err = glGetError(); + if (err != GL_NO_ERROR) + { + CCLOG(@"cocos2d: TexturePVR: Error uploading compressed texture level: %u . glError: 0x%04X", i, err); + return FALSE; + } + + width = MAX(width >> 1, 1); + height = MAX(height >> 1, 1); + } + + return TRUE; +} + + +- (id)initWithContentsOfFile:(NSString *)path +{ + if((self = [super init])) + { + unsigned char *pvrdata = NULL; + NSInteger pvrlen = 0; + NSString *lowerCase = [path lowercaseString]; + + if ( [lowerCase hasSuffix:@".ccz"]) + pvrlen = ccInflateCCZFile( [path UTF8String], &pvrdata ); + + else if( [lowerCase hasSuffix:@".gz"] ) + pvrlen = ccInflateGZipFile( [path UTF8String], &pvrdata ); + + else + pvrlen = ccLoadFileIntoMemory( [path UTF8String], &pvrdata ); + + if( pvrlen < 0 ) { + [self release]; + return nil; + } + + + numberOfMipmaps_ = 0; + + name_ = 0; + width_ = height_ = 0; + tableFormatIndex_ = -1; + hasAlpha_ = FALSE; + + retainName_ = NO; // cocos2d integration + + if( ! [self unpackPVRData:pvrdata PVRLen:pvrlen] || ![self createGLTexture] ) { + free(pvrdata); + [self release]; + return nil; + } + + free(pvrdata); + } + + return self; +} + +- (id)initWithContentsOfURL:(NSURL *)url +{ + if (![url isFileURL]) + { + CCLOG(@"cocos2d: CCPVRTexture: Only files are supported"); + [self release]; + return nil; + } + + return [self initWithContentsOfFile:[url path]]; +} + + ++ (id)pvrTextureWithContentsOfFile:(NSString *)path +{ + return [[[self alloc] initWithContentsOfFile:path] autorelease]; +} + + ++ (id)pvrTextureWithContentsOfURL:(NSURL *)url +{ + if (![url isFileURL]) + return nil; + + return [CCTexturePVR pvrTextureWithContentsOfFile:[url path]]; +} + + +- (void)dealloc +{ + CCLOGINFO( @"cocos2d: deallocing %@", self); + + if (name_ != 0 && ! retainName_ ) + glDeleteTextures(1, &name_); + + [super dealloc]; +} + +@end + diff --git a/tweejump/libs/cocos2d/CCTileMapAtlas.h b/tweejump/libs/cocos2d/CCTileMapAtlas.h new file mode 100755 index 0000000..102ae46 --- /dev/null +++ b/tweejump/libs/cocos2d/CCTileMapAtlas.h @@ -0,0 +1,83 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-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. + * + */ + +#import "CCTextureAtlas.h" +#import "CCAtlasNode.h" +#import "Support/TGAlib.h" + +/** CCTileMapAtlas is a subclass of CCAtlasNode. + + It knows how to render a map based of tiles. + The tiles must be in a .PNG format while the map must be a .TGA file. + + For more information regarding the format, please see this post: + http://www.cocos2d-iphone.org/archives/27 + + All features from CCAtlasNode are valid in CCTileMapAtlas + + IMPORTANT: + This class is deprecated. It is maintained for compatibility reasons only. + You SHOULD not use this class. + Instead, use the newer TMX file format: CCTMXTiledMap + */ +@interface CCTileMapAtlas : CCAtlasNode +{ + + /// info about the map file + tImageTGA *tgaInfo; + + /// x,y to altas dicctionary + NSMutableDictionary *posToAtlasIndex; + + /// numbers of tiles to render + int itemsToRender; +} + +/** TileMap info */ +@property (nonatomic,readonly) tImageTGA *tgaInfo; + +/** creates a CCTileMap with a tile file (atlas) with a map file and the width and height of each tile in points. + The tile file will be loaded using the TextureMgr. + */ ++(id) tileMapAtlasWithTileFile:(NSString*)tile mapFile:(NSString*)map tileWidth:(int)w tileHeight:(int)h; + +/** initializes a CCTileMap with a tile file (atlas) with a map file and the width and height of each tile in points. + The file will be loaded using the TextureMgr. + */ +-(id) initWithTileFile:(NSString*)tile mapFile:(NSString*)map tileWidth:(int)w tileHeight:(int)h; + +/** returns a tile from position x,y. + For the moment only channel R is used + */ +-(ccColor3B) tileAt: (ccGridSize) position; + +/** sets a tile at position x,y. + For the moment only channel R is used + */ +-(void) setTile:(ccColor3B)tile at:(ccGridSize)position; +/** dealloc the map from memory */ +-(void) releaseMap; +@end diff --git a/Support/cocos2d/TileMapAtlas.m b/tweejump/libs/cocos2d/CCTileMapAtlas.m old mode 100644 new mode 100755 similarity index 52% rename from Support/cocos2d/TileMapAtlas.m rename to tweejump/libs/cocos2d/CCTileMapAtlas.m index f970fe1..aef6fe0 --- a/Support/cocos2d/TileMapAtlas.m +++ b/tweejump/libs/cocos2d/CCTileMapAtlas.m @@ -1,33 +1,46 @@ -/* cocos2d for iPhone +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org * - * http://code.google.com/p/cocos2d-iphone - * - * Copyright (C) 2008,2009 Ricardo Quesada - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the 'cocos2d for iPhone' license. - * - * You will find a copy of this license within the cocos2d for iPhone - * distribution inside the "LICENSE" file. + * Copyright (c) 2008-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. * */ -#import "TileMapAtlas.h" +#import "ccConfig.h" +#import "CCTileMapAtlas.h" #import "ccMacros.h" -#import "Support/FileUtils.h" +#import "Support/CCFileUtils.h" -@interface TileMapAtlas (Private) +@interface CCTileMapAtlas (Private) -(void) loadTGAfile:(NSString*)file; -(void) calculateItemsToRender; --(void) updateAtlasValueAt:(ccGridSize)pos withValue:(ccColor3B)value withIndex:(int)idx; +-(void) updateAtlasValueAt:(ccGridSize)pos withValue:(ccColor3B)value withIndex:(NSUInteger)idx; @end -@implementation TileMapAtlas +@implementation CCTileMapAtlas @synthesize tgaInfo; -#pragma mark TileMapAtlas - Creation & Init +#pragma mark CCTileMapAtlas - Creation & Init +(id) tileMapAtlasWithTileFile:(NSString*)tile mapFile:(NSString*)map tileWidth:(int)w tileHeight:(int)h { return [[[self alloc] initWithTileFile:tile mapFile:map tileWidth:w tileHeight:h] autorelease]; @@ -45,7 +58,7 @@ -(id) initWithTileFile:(NSString*)tile mapFile:(NSString*)map tileWidth:(int)w t [self updateAtlasValues]; - [self setContentSize: CGSizeMake(tgaInfo->width*itemWidth, tgaInfo->height*itemHeight)]; + [self setContentSize: CGSizeMake(tgaInfo->width*itemWidth_, tgaInfo->height*itemHeight_)]; } return self; @@ -65,6 +78,7 @@ -(void) releaseMap { if( tgaInfo ) tgaDestroy(tgaInfo); + tgaInfo = nil; [posToAtlasIndex release]; @@ -76,8 +90,8 @@ -(void) calculateItemsToRender NSAssert( tgaInfo != nil, @"tgaInfo must be non-nil"); itemsToRender = 0; - for(int x=0;x < tgaInfo->width; x++ ) { - for( int y=0; y < tgaInfo->height; y++ ) { + for(int x = 0;x < tgaInfo->width; x++ ) { + for(int y = 0; y < tgaInfo->height; y++ ) { ccColor3B *ptr = (ccColor3B*) tgaInfo->imageData; ccColor3B value = ptr[x + y * tgaInfo->width]; if( value.r ) @@ -90,22 +104,22 @@ -(void) loadTGAfile:(NSString*)file { NSAssert( file != nil, @"file must be non-nil"); - NSString *path = [FileUtils fullPathFromRelativePath:file ]; + NSString *path = [CCFileUtils fullPathFromRelativePath:file ]; // //Find the path of the file -// NSBundle *mainBndl = [NSBundle mainBundle]; +// NSBundle *mainBndl = [CCDirector sharedDirector].loadingBundle; // NSString *resourcePath = [mainBndl resourcePath]; // NSString * path = [resourcePath stringByAppendingPathComponent:file]; tgaInfo = tgaLoad( [path UTF8String] ); #if 1 - if( tgaInfo->status != TGA_OK ) { + if( tgaInfo->status != TGA_OK ) [NSException raise:@"TileMapAtlasLoadTGA" format:@"TileMapAtas cannot load TGA file"]; - } + #endif } -#pragma mark TileMapAtlas - Atlas generation / updates +#pragma mark CCTileMapAtlas - Atlas generation / updates -(void) setTile:(ccColor3B) tile at:(ccGridSize) pos { @@ -117,9 +131,9 @@ -(void) setTile:(ccColor3B) tile at:(ccGridSize) pos ccColor3B *ptr = (ccColor3B*) tgaInfo->imageData; ccColor3B value = ptr[pos.x + pos.y * tgaInfo->width]; - if( value.r == 0 ) { - CCLOG(@"Value.r must be non 0."); - } else { + if( value.r == 0 ) + CCLOG(@"cocos2d: Value.r must be non 0."); + else { ptr[pos.x + pos.y * tgaInfo->width] = tile; // XXX: this method consumes a lot of memory @@ -141,35 +155,51 @@ -(ccColor3B) tileAt:(ccGridSize) pos return value; } --(void) updateAtlasValueAt:(ccGridSize)pos withValue:(ccColor3B)value withIndex:(int)idx +-(void) updateAtlasValueAt:(ccGridSize)pos withValue:(ccColor3B)value withIndex:(NSUInteger)idx { ccV3F_C4B_T2F_Quad quad; - int x = pos.x; - int y = pos.y; - float row = (value.r % itemsPerRow) * texStepX; - float col = (value.r / itemsPerRow) * texStepY; - - quad.tl.texCoords.u = row; - quad.tl.texCoords.v = col; - quad.tr.texCoords.u = row + texStepX; - quad.tr.texCoords.v = col; - quad.bl.texCoords.u = row; - quad.bl.texCoords.v = col + texStepY; - quad.br.texCoords.u = row + texStepX; - quad.br.texCoords.v = col + texStepY; - - quad.bl.vertices.x = (int) (x * itemWidth); - quad.bl.vertices.y = (int) (y * itemHeight); + NSInteger x = pos.x; + NSInteger y = pos.y; + float row = (value.r % itemsPerRow_); + float col = (value.r / itemsPerRow_); + + float textureWide = [[textureAtlas_ texture] pixelsWide]; + float textureHigh = [[textureAtlas_ texture] pixelsHigh]; + +#if CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL + float left = (2*row*itemWidth_+1)/(2*textureWide); + float right = left+(itemWidth_*2-2)/(2*textureWide); + float top = (2*col*itemHeight_+1)/(2*textureHigh); + float bottom = top+(itemHeight_*2-2)/(2*textureHigh); +#else + float left = (row*itemWidth_)/textureWide; + float right = left+itemWidth_/textureWide; + float top = (col*itemHeight_)/textureHigh; + float bottom = top+itemHeight_/textureHigh; +#endif + + + quad.tl.texCoords.u = left; + quad.tl.texCoords.v = top; + quad.tr.texCoords.u = right; + quad.tr.texCoords.v = top; + quad.bl.texCoords.u = left; + quad.bl.texCoords.v = bottom; + quad.br.texCoords.u = right; + quad.br.texCoords.v = bottom; + + quad.bl.vertices.x = (int) (x * itemWidth_); + quad.bl.vertices.y = (int) (y * itemHeight_); quad.bl.vertices.z = 0.0f; - quad.br.vertices.x = (int)(x * itemWidth + itemWidth); - quad.br.vertices.y = (int)(y * itemHeight); + quad.br.vertices.x = (int)(x * itemWidth_ + itemWidth_); + quad.br.vertices.y = (int)(y * itemHeight_); quad.br.vertices.z = 0.0f; - quad.tl.vertices.x = (int)(x * itemWidth); - quad.tl.vertices.y = (int)(y * itemHeight + itemHeight); + quad.tl.vertices.x = (int)(x * itemWidth_); + quad.tl.vertices.y = (int)(y * itemHeight_ + itemHeight_); quad.tl.vertices.z = 0.0f; - quad.tr.vertices.x = (int)(x * itemWidth + itemWidth); - quad.tr.vertices.y = (int)(y * itemHeight + itemHeight); + quad.tr.vertices.x = (int)(x * itemWidth_ + itemWidth_); + quad.tr.vertices.y = (int)(y * itemHeight_ + itemHeight_); quad.tr.vertices.z = 0.0f; [textureAtlas_ updateQuad:&quad atIndex:idx]; @@ -182,8 +212,8 @@ -(void) updateAtlasValues int total = 0; - for(int x=0;x < tgaInfo->width; x++ ) { - for( int y=0; y < tgaInfo->height; y++ ) { + for(int x = 0;x < tgaInfo->width; x++ ) { + for(int y = 0; y < tgaInfo->height; y++ ) { if( total < itemsToRender ) { ccColor3B *ptr = (ccColor3B*) tgaInfo->imageData; ccColor3B value = ptr[x + y * tgaInfo->width]; diff --git a/tweejump/libs/cocos2d/CCTransition.h b/tweejump/libs/cocos2d/CCTransition.h new file mode 100755 index 0000000..e37d3e8 --- /dev/null +++ b/tweejump/libs/cocos2d/CCTransition.h @@ -0,0 +1,296 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-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. + * + */ + + +#import "CCScene.h" +@class CCActionInterval; +@class CCNode; + +/** CCTransitionEaseScene can ease the actions of the scene protocol. + @since v0.8.2 + */ +@protocol CCTransitionEaseScene +/** returns the Ease action that will be performed on a linear action. + @since v0.8.2 + */ +-(CCActionInterval*) easeActionWithAction:(CCActionInterval*)action; +@end + +/** Orientation Type used by some transitions + */ +typedef enum { + /// An horizontal orientation where the Left is nearer + kOrientationLeftOver = 0, + /// An horizontal orientation where the Right is nearer + kOrientationRightOver = 1, + /// A vertical orientation where the Up is nearer + kOrientationUpOver = 0, + /// A vertical orientation where the Bottom is nearer + kOrientationDownOver = 1, +} tOrientation; + +/** Base class for CCTransition scenes + */ +@interface CCTransitionScene : CCScene +{ + CCScene *inScene_; + CCScene *outScene_; + ccTime duration_; + BOOL inSceneOnTop_; + BOOL sendCleanupToScene_; +} +/** creates a base transition with duration and incoming scene */ ++(id) transitionWithDuration:(ccTime) t scene:(CCScene*)s; +/** initializes a transition with duration and incoming scene */ +-(id) initWithDuration:(ccTime) t scene:(CCScene*)s; +/** called after the transition finishes */ +-(void) finish; +/** used by some transitions to hide the outter scene */ +-(void) hideOutShowIn; +@end + +/** A CCTransition that supports orientation like. + * Possible orientation: LeftOver, RightOver, UpOver, DownOver + */ +@interface CCTransitionSceneOriented : CCTransitionScene +{ + tOrientation orientation; +} +/** creates a base transition with duration and incoming scene */ ++(id) transitionWithDuration:(ccTime) t scene:(CCScene*)s orientation:(tOrientation)o; +/** initializes a transition with duration and incoming scene */ +-(id) initWithDuration:(ccTime) t scene:(CCScene*)s orientation:(tOrientation)o; +@end + + +/** CCTransitionRotoZoom: + Rotate and zoom out the outgoing scene, and then rotate and zoom in the incoming + */ +@interface CCTransitionRotoZoom : CCTransitionScene +{} +@end + +/** CCTransitionJumpZoom: + Zoom out and jump the outgoing scene, and then jump and zoom in the incoming +*/ +@interface CCTransitionJumpZoom : CCTransitionScene +{} +@end + +/** CCTransitionMoveInL: + Move in from to the left the incoming scene. +*/ +@interface CCTransitionMoveInL : CCTransitionScene +{} +/** initializes the scenes */ +-(void) initScenes; +/** returns the action that will be performed */ +-(CCActionInterval*) action; +@end + +/** CCTransitionMoveInR: + Move in from to the right the incoming scene. + */ +@interface CCTransitionMoveInR : CCTransitionMoveInL +{} +@end + +/** CCTransitionMoveInT: + Move in from to the top the incoming scene. + */ +@interface CCTransitionMoveInT : CCTransitionMoveInL +{} +@end + +/** CCTransitionMoveInB: + Move in from to the bottom the incoming scene. + */ +@interface CCTransitionMoveInB : CCTransitionMoveInL +{} +@end + +/** CCTransitionSlideInL: + Slide in the incoming scene from the left border. + */ +@interface CCTransitionSlideInL : CCTransitionScene +{} +/** initializes the scenes */ +-(void) initScenes; +/** returns the action that will be performed by the incomming and outgoing scene */ +-(CCActionInterval*) action; +@end + +/** CCTransitionSlideInR: + Slide in the incoming scene from the right border. + */ +@interface CCTransitionSlideInR : CCTransitionSlideInL +{} +@end + +/** CCTransitionSlideInB: + Slide in the incoming scene from the bottom border. + */ +@interface CCTransitionSlideInB : CCTransitionSlideInL +{} +@end + +/** CCTransitionSlideInT: + Slide in the incoming scene from the top border. + */ +@interface CCTransitionSlideInT : CCTransitionSlideInL +{} +@end + +/** + Shrink the outgoing scene while grow the incoming scene + */ +@interface CCTransitionShrinkGrow : CCTransitionScene +{} +@end + +/** CCTransitionFlipX: + Flips the screen horizontally. + The front face is the outgoing scene and the back face is the incoming scene. + */ +@interface CCTransitionFlipX : CCTransitionSceneOriented +{} +@end + +/** CCTransitionFlipY: + Flips the screen vertically. + The front face is the outgoing scene and the back face is the incoming scene. + */ +@interface CCTransitionFlipY : CCTransitionSceneOriented +{} +@end + +/** CCTransitionFlipAngular: + Flips the screen half horizontally and half vertically. + The front face is the outgoing scene and the back face is the incoming scene. + */ +@interface CCTransitionFlipAngular : CCTransitionSceneOriented +{} +@end + +/** CCTransitionZoomFlipX: + Flips the screen horizontally doing a zoom out/in + The front face is the outgoing scene and the back face is the incoming scene. + */ +@interface CCTransitionZoomFlipX : CCTransitionSceneOriented +{} +@end + +/** CCTransitionZoomFlipY: + Flips the screen vertically doing a little zooming out/in + The front face is the outgoing scene and the back face is the incoming scene. + */ +@interface CCTransitionZoomFlipY : CCTransitionSceneOriented +{} +@end + +/** CCTransitionZoomFlipAngular: + Flips the screen half horizontally and half vertically doing a little zooming out/in. + The front face is the outgoing scene and the back face is the incoming scene. + */ +@interface CCTransitionZoomFlipAngular : CCTransitionSceneOriented +{} +@end + +/** CCTransitionFade: + Fade out the outgoing scene and then fade in the incoming scene.''' + */ +@interface CCTransitionFade : CCTransitionScene +{ + ccColor4B color; +} +/** creates the transition with a duration and with an RGB color + * Example: [FadeTransition transitionWithDuration:2 scene:s withColor:ccc3(255,0,0)]; // red color + */ ++(id) transitionWithDuration:(ccTime)duration scene:(CCScene*)scene withColor:(ccColor3B)color; +/** initializes the transition with a duration and with an RGB color */ +-(id) initWithDuration:(ccTime)duration scene:(CCScene*)scene withColor:(ccColor3B)color; +@end + + +/** + CCTransitionCrossFade: + Cross fades two scenes using the CCRenderTexture object. + */ +@class CCRenderTexture; +@interface CCTransitionCrossFade : CCTransitionScene +{} +@end + +/** CCTransitionTurnOffTiles: + Turn off the tiles of the outgoing scene in random order + */ +@interface CCTransitionTurnOffTiles : CCTransitionScene +{} +@end + +/** CCTransitionSplitCols: + The odd columns goes upwards while the even columns goes downwards. + */ +@interface CCTransitionSplitCols : CCTransitionScene +{} +-(CCActionInterval*) action; +@end + +/** CCTransitionSplitRows: + The odd rows goes to the left while the even rows goes to the right. + */ +@interface CCTransitionSplitRows : CCTransitionSplitCols +{} +@end + +/** CCTransitionFadeTR: + Fade the tiles of the outgoing scene from the left-bottom corner the to top-right corner. + */ +@interface CCTransitionFadeTR : CCTransitionScene +{} +-(CCActionInterval*) actionWithSize:(ccGridSize) vector; +@end + +/** CCTransitionFadeBL: + Fade the tiles of the outgoing scene from the top-right corner to the bottom-left corner. + */ +@interface CCTransitionFadeBL : CCTransitionFadeTR +{} +@end + +/** CCTransitionFadeUp: + * Fade the tiles of the outgoing scene from the bottom to the top. + */ +@interface CCTransitionFadeUp : CCTransitionFadeTR +{} +@end + +/** CCTransitionFadeDown: + * Fade the tiles of the outgoing scene from the top to the bottom. + */ +@interface CCTransitionFadeDown : CCTransitionFadeTR +{} +@end diff --git a/tweejump/libs/cocos2d/CCTransition.m b/tweejump/libs/cocos2d/CCTransition.m new file mode 100755 index 0000000..22eed50 --- /dev/null +++ b/tweejump/libs/cocos2d/CCTransition.m @@ -0,0 +1,1059 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-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. + * + */ + + + +#import "CCTransition.h" +#import "CCNode.h" +#import "CCDirector.h" +#import "CCActionInterval.h" +#import "CCActionInstant.h" +#import "CCActionCamera.h" +#import "CCLayer.h" +#import "CCCamera.h" +#import "CCActionTiledGrid.h" +#import "CCActionEase.h" +#import "CCRenderTexture.h" +#import "Support/CGPointExtension.h" + +#import +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED +#import "Platforms/iOS/CCTouchDispatcher.h" +#elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED) +#import "Platforms/Mac/CCEventDispatcher.h" +#endif + +const uint32_t kSceneFade = 0xFADEFADE; + + +@interface CCTransitionScene (Private) +-(void) sceneOrder; +- (void)setNewScene:(ccTime)dt; +@end + +@implementation CCTransitionScene ++(id) transitionWithDuration:(ccTime) t scene:(CCScene*)s +{ + return [[[self alloc] initWithDuration:t scene:s] autorelease]; +} + +-(id) initWithDuration:(ccTime) t scene:(CCScene*)s +{ + NSAssert( s != nil, @"Argument scene must be non-nil"); + + if( (self=[super init]) ) { + + duration_ = t; + + // retain + inScene_ = [s retain]; + outScene_ = [[CCDirector sharedDirector] runningScene]; + [outScene_ retain]; + + NSAssert( inScene_ != outScene_, @"Incoming scene must be different from the outgoing scene" ); + + // disable events while transitions +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED + [[CCTouchDispatcher sharedDispatcher] setDispatchEvents: NO]; +#elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED) + [[CCEventDispatcher sharedDispatcher] setDispatchEvents: NO]; +#endif + + [self sceneOrder]; + } + return self; +} +-(void) sceneOrder +{ + inSceneOnTop_ = YES; +} + +-(void) draw +{ + [super draw]; + + if( inSceneOnTop_ ) { + [outScene_ visit]; + [inScene_ visit]; + } else { + [inScene_ visit]; + [outScene_ visit]; + } +} + +-(void) finish +{ + /* clean up */ + [inScene_ setVisible:YES]; + [inScene_ setPosition:ccp(0,0)]; + [inScene_ setScale:1.0f]; + [inScene_ setRotation:0.0f]; + [inScene_.camera restore]; + + [outScene_ setVisible:NO]; + [outScene_ setPosition:ccp(0,0)]; + [outScene_ setScale:1.0f]; + [outScene_ setRotation:0.0f]; + [outScene_.camera restore]; + + [self schedule:@selector(setNewScene:) interval:0]; +} + +-(void) setNewScene: (ccTime) dt +{ + [self unschedule:_cmd]; + + CCDirector *director = [CCDirector sharedDirector]; + + // Before replacing, save the "send cleanup to scene" + sendCleanupToScene_ = [director sendCleanupToScene]; + + [director replaceScene: inScene_]; + + // enable events while transitions +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED + [[CCTouchDispatcher sharedDispatcher] setDispatchEvents: YES]; +#elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED) + [[CCEventDispatcher sharedDispatcher] setDispatchEvents: YES]; +#endif + + // issue #267 + [outScene_ setVisible:YES]; +} + +-(void) hideOutShowIn +{ + [inScene_ setVisible:YES]; + [outScene_ setVisible:NO]; +} + +// custom onEnter +-(void) onEnter +{ + [super onEnter]; + [inScene_ onEnter]; + // outScene_ should not receive the onEnter callback +} + +// custom onExit +-(void) onExit +{ + [super onExit]; + [outScene_ onExit]; + + // inScene_ should not receive the onExit callback + // only the onEnterTransitionDidFinish + [inScene_ onEnterTransitionDidFinish]; +} + +// custom cleanup +-(void) cleanup +{ + [super cleanup]; + + if( sendCleanupToScene_ ) + [outScene_ cleanup]; +} + +-(void) dealloc +{ + [inScene_ release]; + [outScene_ release]; + [super dealloc]; +} +@end + +// +// Oriented Transition +// +@implementation CCTransitionSceneOriented ++(id) transitionWithDuration:(ccTime) t scene:(CCScene*)s orientation:(tOrientation)o +{ + return [[[self alloc] initWithDuration:t scene:s orientation:o] autorelease]; +} + +-(id) initWithDuration:(ccTime) t scene:(CCScene*)s orientation:(tOrientation)o +{ + if( (self=[super initWithDuration:t scene:s]) ) + orientation = o; + return self; +} +@end + + +// +// RotoZoom +// +@implementation CCTransitionRotoZoom +-(void) onEnter +{ + [super onEnter]; + + [inScene_ setScale:0.001f]; + [outScene_ setScale:1.0f]; + + [inScene_ setAnchorPoint:ccp(0.5f, 0.5f)]; + [outScene_ setAnchorPoint:ccp(0.5f, 0.5f)]; + + CCActionInterval *rotozoom = [CCSequence actions: [CCSpawn actions: + [CCScaleBy actionWithDuration:duration_/2 scale:0.001f], + [CCRotateBy actionWithDuration:duration_/2 angle:360 *2], + nil], + [CCDelayTime actionWithDuration:duration_/2], + nil]; + + + [outScene_ runAction: rotozoom]; + [inScene_ runAction: [CCSequence actions: + [rotozoom reverse], + [CCCallFunc actionWithTarget:self selector:@selector(finish)], + nil]]; +} +@end + +// +// JumpZoom +// +@implementation CCTransitionJumpZoom +-(void) onEnter +{ + [super onEnter]; + CGSize s = [[CCDirector sharedDirector] winSize]; + + [inScene_ setScale:0.5f]; + [inScene_ setPosition:ccp( s.width,0 )]; + + [inScene_ setAnchorPoint:ccp(0.5f, 0.5f)]; + [outScene_ setAnchorPoint:ccp(0.5f, 0.5f)]; + + CCActionInterval *jump = [CCJumpBy actionWithDuration:duration_/4 position:ccp(-s.width,0) height:s.width/4 jumps:2]; + CCActionInterval *scaleIn = [CCScaleTo actionWithDuration:duration_/4 scale:1.0f]; + CCActionInterval *scaleOut = [CCScaleTo actionWithDuration:duration_/4 scale:0.5f]; + + CCActionInterval *jumpZoomOut = [CCSequence actions: scaleOut, jump, nil]; + CCActionInterval *jumpZoomIn = [CCSequence actions: jump, scaleIn, nil]; + + CCActionInterval *delay = [CCDelayTime actionWithDuration:duration_/2]; + + [outScene_ runAction: jumpZoomOut]; + [inScene_ runAction: [CCSequence actions: delay, + jumpZoomIn, + [CCCallFunc actionWithTarget:self selector:@selector(finish)], + nil] ]; +} +@end + +// +// MoveInL +// +@implementation CCTransitionMoveInL +-(void) onEnter +{ + [super onEnter]; + + [self initScenes]; + + CCActionInterval *a = [self action]; + + [inScene_ runAction: [CCSequence actions: + [self easeActionWithAction:a], + [CCCallFunc actionWithTarget:self selector:@selector(finish)], + nil] + ]; + +} +-(CCActionInterval*) action +{ + return [CCMoveTo actionWithDuration:duration_ position:ccp(0,0)]; +} + +-(CCActionInterval*) easeActionWithAction:(CCActionInterval*)action +{ + return [CCEaseOut actionWithAction:action rate:2.0f]; +// return [EaseElasticOut actionWithAction:action period:0.4f]; +} + +-(void) initScenes +{ + CGSize s = [[CCDirector sharedDirector] winSize]; + [inScene_ setPosition: ccp( -s.width,0) ]; +} +@end + +// +// MoveInR +// +@implementation CCTransitionMoveInR +-(void) initScenes +{ + CGSize s = [[CCDirector sharedDirector] winSize]; + [inScene_ setPosition: ccp( s.width,0) ]; +} +@end + +// +// MoveInT +// +@implementation CCTransitionMoveInT +-(void) initScenes +{ + CGSize s = [[CCDirector sharedDirector] winSize]; + [inScene_ setPosition: ccp( 0, s.height) ]; +} +@end + +// +// MoveInB +// +@implementation CCTransitionMoveInB +-(void) initScenes +{ + CGSize s = [[CCDirector sharedDirector] winSize]; + [inScene_ setPosition: ccp( 0, -s.height) ]; +} +@end + +// +// SlideInL +// + +// The adjust factor is needed to prevent issue #442 +// One solution is to use DONT_RENDER_IN_SUBPIXELS images, but NO +// The other issue is that in some transitions (and I don't know why) +// the order should be reversed (In in top of Out or vice-versa). +#define ADJUST_FACTOR 0.5f +@implementation CCTransitionSlideInL +-(void) onEnter +{ + [super onEnter]; + + [self initScenes]; + + CCActionInterval *in = [self action]; + CCActionInterval *out = [self action]; + + id inAction = [self easeActionWithAction:in]; + id outAction = [CCSequence actions: + [self easeActionWithAction:out], + [CCCallFunc actionWithTarget:self selector:@selector(finish)], + nil]; + + [inScene_ runAction: inAction]; + [outScene_ runAction: outAction]; +} +-(void) sceneOrder +{ + inSceneOnTop_ = NO; +} +-(void) initScenes +{ + CGSize s = [[CCDirector sharedDirector] winSize]; + [inScene_ setPosition: ccp( -(s.width-ADJUST_FACTOR),0) ]; +} +-(CCActionInterval*) action +{ + CGSize s = [[CCDirector sharedDirector] winSize]; + return [CCMoveBy actionWithDuration:duration_ position:ccp(s.width-ADJUST_FACTOR,0)]; +} + +-(CCActionInterval*) easeActionWithAction:(CCActionInterval*)action +{ + return [CCEaseOut actionWithAction:action rate:2.0f]; +// return [EaseElasticOut actionWithAction:action period:0.4f]; +} + +@end + +// +// SlideInR +// +@implementation CCTransitionSlideInR +-(void) sceneOrder +{ + inSceneOnTop_ = YES; +} +-(void) initScenes +{ + CGSize s = [[CCDirector sharedDirector] winSize]; + [inScene_ setPosition: ccp( s.width-ADJUST_FACTOR,0) ]; +} + +-(CCActionInterval*) action +{ + CGSize s = [[CCDirector sharedDirector] winSize]; + return [CCMoveBy actionWithDuration:duration_ position:ccp(-(s.width-ADJUST_FACTOR),0)]; +} + +@end + +// +// SlideInT +// +@implementation CCTransitionSlideInT +-(void) sceneOrder +{ + inSceneOnTop_ = NO; +} +-(void) initScenes +{ + CGSize s = [[CCDirector sharedDirector] winSize]; + [inScene_ setPosition: ccp(0,s.height-ADJUST_FACTOR) ]; +} + +-(CCActionInterval*) action +{ + CGSize s = [[CCDirector sharedDirector] winSize]; + return [CCMoveBy actionWithDuration:duration_ position:ccp(0,-(s.height-ADJUST_FACTOR))]; +} + +@end + +// +// SlideInB +// +@implementation CCTransitionSlideInB +-(void) sceneOrder +{ + inSceneOnTop_ = YES; +} + +-(void) initScenes +{ + CGSize s = [[CCDirector sharedDirector] winSize]; + [inScene_ setPosition: ccp(0,-(s.height-ADJUST_FACTOR)) ]; +} + +-(CCActionInterval*) action +{ + CGSize s = [[CCDirector sharedDirector] winSize]; + return [CCMoveBy actionWithDuration:duration_ position:ccp(0,s.height-ADJUST_FACTOR)]; +} +@end + +// +// ShrinkGrow Transition +// +@implementation CCTransitionShrinkGrow +-(void) onEnter +{ + [super onEnter]; + + [inScene_ setScale:0.001f]; + [outScene_ setScale:1.0f]; + + [inScene_ setAnchorPoint:ccp(2/3.0f,0.5f)]; + [outScene_ setAnchorPoint:ccp(1/3.0f,0.5f)]; + + CCActionInterval *scaleOut = [CCScaleTo actionWithDuration:duration_ scale:0.01f]; + CCActionInterval *scaleIn = [CCScaleTo actionWithDuration:duration_ scale:1.0f]; + + [inScene_ runAction: [self easeActionWithAction:scaleIn]]; + [outScene_ runAction: [CCSequence actions: + [self easeActionWithAction:scaleOut], + [CCCallFunc actionWithTarget:self selector:@selector(finish)], + nil] ]; +} +-(CCActionInterval*) easeActionWithAction:(CCActionInterval*)action +{ + return [CCEaseOut actionWithAction:action rate:2.0f]; +// return [EaseElasticOut actionWithAction:action period:0.3f]; +} +@end + +// +// FlipX Transition +// +@implementation CCTransitionFlipX +-(void) onEnter +{ + [super onEnter]; + + CCActionInterval *inA, *outA; + [inScene_ setVisible: NO]; + + float inDeltaZ, inAngleZ; + float outDeltaZ, outAngleZ; + + if( orientation == kOrientationRightOver ) { + inDeltaZ = 90; + inAngleZ = 270; + outDeltaZ = 90; + outAngleZ = 0; + } else { + inDeltaZ = -90; + inAngleZ = 90; + outDeltaZ = -90; + outAngleZ = 0; + } + + inA = [CCSequence actions: + [CCDelayTime actionWithDuration:duration_/2], + [CCShow action], + [CCOrbitCamera actionWithDuration: duration_/2 radius: 1 deltaRadius:0 angleZ:inAngleZ deltaAngleZ:inDeltaZ angleX:0 deltaAngleX:0], + [CCCallFunc actionWithTarget:self selector:@selector(finish)], + nil ]; + outA = [CCSequence actions: + [CCOrbitCamera actionWithDuration: duration_/2 radius: 1 deltaRadius:0 angleZ:outAngleZ deltaAngleZ:outDeltaZ angleX:0 deltaAngleX:0], + [CCHide action], + [CCDelayTime actionWithDuration:duration_/2], + nil ]; + + [inScene_ runAction: inA]; + [outScene_ runAction: outA]; + +} +@end + +// +// FlipY Transition +// +@implementation CCTransitionFlipY +-(void) onEnter +{ + [super onEnter]; + + CCActionInterval *inA, *outA; + [inScene_ setVisible: NO]; + + float inDeltaZ, inAngleZ; + float outDeltaZ, outAngleZ; + + if( orientation == kOrientationUpOver ) { + inDeltaZ = 90; + inAngleZ = 270; + outDeltaZ = 90; + outAngleZ = 0; + } else { + inDeltaZ = -90; + inAngleZ = 90; + outDeltaZ = -90; + outAngleZ = 0; + } + inA = [CCSequence actions: + [CCDelayTime actionWithDuration:duration_/2], + [CCShow action], + [CCOrbitCamera actionWithDuration: duration_/2 radius: 1 deltaRadius:0 angleZ:inAngleZ deltaAngleZ:inDeltaZ angleX:90 deltaAngleX:0], + [CCCallFunc actionWithTarget:self selector:@selector(finish)], + nil ]; + outA = [CCSequence actions: + [CCOrbitCamera actionWithDuration: duration_/2 radius: 1 deltaRadius:0 angleZ:outAngleZ deltaAngleZ:outDeltaZ angleX:90 deltaAngleX:0], + [CCHide action], + [CCDelayTime actionWithDuration:duration_/2], + nil ]; + + [inScene_ runAction: inA]; + [outScene_ runAction: outA]; + +} +@end + +// +// FlipAngular Transition +// +@implementation CCTransitionFlipAngular +-(void) onEnter +{ + [super onEnter]; + + CCActionInterval *inA, *outA; + [inScene_ setVisible: NO]; + + float inDeltaZ, inAngleZ; + float outDeltaZ, outAngleZ; + + if( orientation == kOrientationRightOver ) { + inDeltaZ = 90; + inAngleZ = 270; + outDeltaZ = 90; + outAngleZ = 0; + } else { + inDeltaZ = -90; + inAngleZ = 90; + outDeltaZ = -90; + outAngleZ = 0; + } + inA = [CCSequence actions: + [CCDelayTime actionWithDuration:duration_/2], + [CCShow action], + [CCOrbitCamera actionWithDuration: duration_/2 radius: 1 deltaRadius:0 angleZ:inAngleZ deltaAngleZ:inDeltaZ angleX:-45 deltaAngleX:0], + [CCCallFunc actionWithTarget:self selector:@selector(finish)], + nil ]; + outA = [CCSequence actions: + [CCOrbitCamera actionWithDuration: duration_/2 radius: 1 deltaRadius:0 angleZ:outAngleZ deltaAngleZ:outDeltaZ angleX:45 deltaAngleX:0], + [CCHide action], + [CCDelayTime actionWithDuration:duration_/2], + nil ]; + + [inScene_ runAction: inA]; + [outScene_ runAction: outA]; +} +@end + +// +// ZoomFlipX Transition +// +@implementation CCTransitionZoomFlipX +-(void) onEnter +{ + [super onEnter]; + + CCActionInterval *inA, *outA; + [inScene_ setVisible: NO]; + + float inDeltaZ, inAngleZ; + float outDeltaZ, outAngleZ; + + if( orientation == kOrientationRightOver ) { + inDeltaZ = 90; + inAngleZ = 270; + outDeltaZ = 90; + outAngleZ = 0; + } else { + inDeltaZ = -90; + inAngleZ = 90; + outDeltaZ = -90; + outAngleZ = 0; + } + inA = [CCSequence actions: + [CCDelayTime actionWithDuration:duration_/2], + [CCSpawn actions: + [CCOrbitCamera actionWithDuration: duration_/2 radius: 1 deltaRadius:0 angleZ:inAngleZ deltaAngleZ:inDeltaZ angleX:0 deltaAngleX:0], + [CCScaleTo actionWithDuration:duration_/2 scale:1], + [CCShow action], + nil], + [CCCallFunc actionWithTarget:self selector:@selector(finish)], + nil ]; + outA = [CCSequence actions: + [CCSpawn actions: + [CCOrbitCamera actionWithDuration: duration_/2 radius: 1 deltaRadius:0 angleZ:outAngleZ deltaAngleZ:outDeltaZ angleX:0 deltaAngleX:0], + [CCScaleTo actionWithDuration:duration_/2 scale:0.5f], + nil], + [CCHide action], + [CCDelayTime actionWithDuration:duration_/2], + nil ]; + + inScene_.scale = 0.5f; + [inScene_ runAction: inA]; + [outScene_ runAction: outA]; +} +@end + +// +// ZoomFlipY Transition +// +@implementation CCTransitionZoomFlipY +-(void) onEnter +{ + [super onEnter]; + + CCActionInterval *inA, *outA; + [inScene_ setVisible: NO]; + + float inDeltaZ, inAngleZ; + float outDeltaZ, outAngleZ; + + if( orientation == kOrientationUpOver ) { + inDeltaZ = 90; + inAngleZ = 270; + outDeltaZ = 90; + outAngleZ = 0; + } else { + inDeltaZ = -90; + inAngleZ = 90; + outDeltaZ = -90; + outAngleZ = 0; + } + + inA = [CCSequence actions: + [CCDelayTime actionWithDuration:duration_/2], + [CCSpawn actions: + [CCOrbitCamera actionWithDuration: duration_/2 radius: 1 deltaRadius:0 angleZ:inAngleZ deltaAngleZ:inDeltaZ angleX:90 deltaAngleX:0], + [CCScaleTo actionWithDuration:duration_/2 scale:1], + [CCShow action], + nil], + [CCCallFunc actionWithTarget:self selector:@selector(finish)], + nil ]; + outA = [CCSequence actions: + [CCSpawn actions: + [CCOrbitCamera actionWithDuration: duration_/2 radius: 1 deltaRadius:0 angleZ:outAngleZ deltaAngleZ:outDeltaZ angleX:90 deltaAngleX:0], + [CCScaleTo actionWithDuration:duration_/2 scale:0.5f], + nil], + [CCHide action], + [CCDelayTime actionWithDuration:duration_/2], + nil ]; + + inScene_.scale = 0.5f; + [inScene_ runAction: inA]; + [outScene_ runAction: outA]; +} +@end + +// +// ZoomFlipAngular Transition +// +@implementation CCTransitionZoomFlipAngular +-(void) onEnter +{ + [super onEnter]; + + CCActionInterval *inA, *outA; + [inScene_ setVisible: NO]; + + float inDeltaZ, inAngleZ; + float outDeltaZ, outAngleZ; + + if( orientation == kOrientationRightOver ) { + inDeltaZ = 90; + inAngleZ = 270; + outDeltaZ = 90; + outAngleZ = 0; + } else { + inDeltaZ = -90; + inAngleZ = 90; + outDeltaZ = -90; + outAngleZ = 0; + } + + inA = [CCSequence actions: + [CCDelayTime actionWithDuration:duration_/2], + [CCSpawn actions: + [CCOrbitCamera actionWithDuration: duration_/2 radius: 1 deltaRadius:0 angleZ:inAngleZ deltaAngleZ:inDeltaZ angleX:-45 deltaAngleX:0], + [CCScaleTo actionWithDuration:duration_/2 scale:1], + [CCShow action], + nil], + [CCShow action], + [CCCallFunc actionWithTarget:self selector:@selector(finish)], + nil ]; + outA = [CCSequence actions: + [CCSpawn actions: + [CCOrbitCamera actionWithDuration: duration_/2 radius: 1 deltaRadius:0 angleZ:outAngleZ deltaAngleZ:outDeltaZ angleX:45 deltaAngleX:0], + [CCScaleTo actionWithDuration:duration_/2 scale:0.5f], + nil], + [CCHide action], + [CCDelayTime actionWithDuration:duration_/2], + nil ]; + + inScene_.scale = 0.5f; + [inScene_ runAction: inA]; + [outScene_ runAction: outA]; +} +@end + + +// +// Fade Transition +// +@implementation CCTransitionFade ++(id) transitionWithDuration:(ccTime)d scene:(CCScene*)s withColor:(ccColor3B)color +{ + return [[[self alloc] initWithDuration:d scene:s withColor:color] autorelease]; +} + +-(id) initWithDuration:(ccTime)d scene:(CCScene*)s withColor:(ccColor3B)aColor +{ + if( (self=[super initWithDuration:d scene:s]) ) { + color.r = aColor.r; + color.g = aColor.g; + color.b = aColor.b; + } + + return self; +} + +-(id) initWithDuration:(ccTime)d scene:(CCScene*)s +{ + return [self initWithDuration:d scene:s withColor:ccBLACK]; +} + +-(void) onEnter +{ + [super onEnter]; + + CCLayerColor *l = [CCLayerColor layerWithColor:color]; + [inScene_ setVisible: NO]; + + [self addChild: l z:2 tag:kSceneFade]; + + + CCNode *f = [self getChildByTag:kSceneFade]; + + CCActionInterval *a = [CCSequence actions: + [CCFadeIn actionWithDuration:duration_/2], + [CCCallFunc actionWithTarget:self selector:@selector(hideOutShowIn)], + [CCFadeOut actionWithDuration:duration_/2], + [CCCallFunc actionWithTarget:self selector:@selector(finish)], + nil ]; + [f runAction: a]; +} + +-(void) onExit +{ + [super onExit]; + [self removeChildByTag:kSceneFade cleanup:NO]; +} +@end + + +// +// Cross Fade Transition +// +@implementation CCTransitionCrossFade + +-(void) draw +{ + // override draw since both scenes (textures) are rendered in 1 scene +} + +-(void) onEnter +{ + [super onEnter]; + + // create a transparent color layer + // in which we are going to add our rendertextures + ccColor4B color = {0,0,0,0}; + CGSize size = [[CCDirector sharedDirector] winSize]; + CCLayerColor * layer = [CCLayerColor layerWithColor:color]; + + // create the first render texture for inScene_ + CCRenderTexture *inTexture = [CCRenderTexture renderTextureWithWidth:size.width height:size.height]; + inTexture.sprite.anchorPoint= ccp(0.5f,0.5f); + inTexture.position = ccp(size.width/2, size.height/2); + inTexture.anchorPoint = ccp(0.5f,0.5f); + + // render inScene_ to its texturebuffer + [inTexture begin]; + [inScene_ visit]; + [inTexture end]; + + // create the second render texture for outScene_ + CCRenderTexture *outTexture = [CCRenderTexture renderTextureWithWidth:size.width height:size.height]; + outTexture.sprite.anchorPoint= ccp(0.5f,0.5f); + outTexture.position = ccp(size.width/2, size.height/2); + outTexture.anchorPoint = ccp(0.5f,0.5f); + + // render outScene_ to its texturebuffer + [outTexture begin]; + [outScene_ visit]; + [outTexture end]; + + // create blend functions + + ccBlendFunc blend1 = {GL_ONE, GL_ONE}; // inScene_ will lay on background and will not be used with alpha + ccBlendFunc blend2 = {GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA}; // we are going to blend outScene_ via alpha + + // set blendfunctions + [inTexture.sprite setBlendFunc:blend1]; + [outTexture.sprite setBlendFunc:blend2]; + + // add render textures to the layer + [layer addChild:inTexture]; + [layer addChild:outTexture]; + + // initial opacity: + [inTexture.sprite setOpacity:255]; + [outTexture.sprite setOpacity:255]; + + // create the blend action + CCActionInterval * layerAction = [CCSequence actions: + [CCFadeTo actionWithDuration:duration_ opacity:0], + [CCCallFunc actionWithTarget:self selector:@selector(hideOutShowIn)], + [CCCallFunc actionWithTarget:self selector:@selector(finish)], + nil ]; + + + // run the blend action + [outTexture.sprite runAction: layerAction]; + + // add the layer (which contains our two rendertextures) to the scene + [self addChild: layer z:2 tag:kSceneFade]; +} + +// clean up on exit +-(void) onExit +{ + // remove our layer and release all containing objects + [self removeChildByTag:kSceneFade cleanup:NO]; + + [super onExit]; +} +@end + +// +// TurnOffTilesTransition +// +@implementation CCTransitionTurnOffTiles + +// override addScenes, and change the order +-(void) sceneOrder +{ + inSceneOnTop_ = NO; +} + +-(void) onEnter +{ + [super onEnter]; + CGSize s = [[CCDirector sharedDirector] winSize]; + float aspect = s.width / s.height; + int x = 12 * aspect; + int y = 12; + + id toff = [CCTurnOffTiles actionWithSize: ccg(x,y) duration:duration_]; + id action = [self easeActionWithAction:toff]; + [outScene_ runAction: [CCSequence actions: action, + [CCCallFunc actionWithTarget:self selector:@selector(finish)], + [CCStopGrid action], + nil] + ]; + +} +-(CCActionInterval*) easeActionWithAction:(CCActionInterval*)action +{ + return action; +// return [EaseIn actionWithAction:action rate:2.0f]; +} +@end + +#pragma mark Split Transitions + +// +// SplitCols Transition +// +@implementation CCTransitionSplitCols + +-(void) onEnter +{ + [super onEnter]; + + inScene_.visible = NO; + + id split = [self action]; + id seq = [CCSequence actions: + split, + [CCCallFunc actionWithTarget:self selector:@selector(hideOutShowIn)], + [split reverse], + nil + ]; + [self runAction: [CCSequence actions: + [self easeActionWithAction:seq], + [CCCallFunc actionWithTarget:self selector:@selector(finish)], + [CCStopGrid action], + nil] + ]; +} + +-(CCActionInterval*) action +{ + return [CCSplitCols actionWithCols:3 duration:duration_/2.0f]; +} + +-(CCActionInterval*) easeActionWithAction:(CCActionInterval*)action +{ + return [CCEaseInOut actionWithAction:action rate:3.0f]; +} +@end + +// +// SplitRows Transition +// +@implementation CCTransitionSplitRows +-(CCActionInterval*) action +{ + return [CCSplitRows actionWithRows:3 duration:duration_/2.0f]; +} +@end + + +#pragma mark Fade Grid Transitions + +// +// FadeTR Transition +// +@implementation CCTransitionFadeTR +-(void) sceneOrder +{ + inSceneOnTop_ = NO; +} + +-(void) onEnter +{ + [super onEnter]; + + CGSize s = [[CCDirector sharedDirector] winSize]; + float aspect = s.width / s.height; + int x = 12 * aspect; + int y = 12; + + id action = [self actionWithSize:ccg(x,y)]; + + [outScene_ runAction: [CCSequence actions: + [self easeActionWithAction:action], + [CCCallFunc actionWithTarget:self selector:@selector(finish)], + [CCStopGrid action], + nil] + ]; +} + +-(CCActionInterval*) actionWithSize: (ccGridSize) v +{ + return [CCFadeOutTRTiles actionWithSize:v duration:duration_]; +} + +-(CCActionInterval*) easeActionWithAction:(CCActionInterval*)action +{ + return action; +// return [EaseIn actionWithAction:action rate:2.0f]; +} +@end + +// +// FadeBL Transition +// +@implementation CCTransitionFadeBL +-(CCActionInterval*) actionWithSize: (ccGridSize) v +{ + return [CCFadeOutBLTiles actionWithSize:v duration:duration_]; +} +@end + +// +// FadeUp Transition +// +@implementation CCTransitionFadeUp +-(CCActionInterval*) actionWithSize: (ccGridSize) v +{ + return [CCFadeOutUpTiles actionWithSize:v duration:duration_]; +} +@end + +// +// FadeDown Transition +// +@implementation CCTransitionFadeDown +-(CCActionInterval*) actionWithSize: (ccGridSize) v +{ + return [CCFadeOutDownTiles actionWithSize:v duration:duration_]; +} +@end diff --git a/tweejump/libs/cocos2d/CCTransitionPageTurn.h b/tweejump/libs/cocos2d/CCTransitionPageTurn.h new file mode 100755 index 0000000..aacb7fc --- /dev/null +++ b/tweejump/libs/cocos2d/CCTransitionPageTurn.h @@ -0,0 +1,60 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2009 Sindesso Pty Ltd http://www.sindesso.com/ + * + * 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. + * + */ + + +#import "CCTransition.h" + +/** CCTransitionPageTurn transition. + * A transition which peels back the bottom right hand corner of a scene + * to transition to the scene beneath it simulating a page turn + * + * This uses a 3DAction so it's strongly recommended that depth buffering + * is turned on in CCDirector using: + * + * [[CCDirector sharedDirector] setDepthBufferFormat:kCCDepthBuffer16]; + * + * @since v0.8.2 + */ +@interface CCTransitionPageTurn : CCTransitionScene +{ + BOOL back_; +} +/** + * creates a base transition with duration and incoming scene + * if back is TRUE then the effect is reversed to appear as if the incoming + * scene is being turned from left over the outgoing scene + */ ++(id) transitionWithDuration:(ccTime) t scene:(CCScene*)s backwards:(BOOL) back; + +/** + * creates a base transition with duration and incoming scene + * if back is TRUE then the effect is reversed to appear as if the incoming + * scene is being turned from left over the outgoing scene + */ +-(id) initWithDuration:(ccTime) t scene:(CCScene*)s backwards:(BOOL) back; + +-(CCActionInterval*) actionWithSize:(ccGridSize) vector; + +@end diff --git a/tweejump/libs/cocos2d/CCTransitionPageTurn.m b/tweejump/libs/cocos2d/CCTransitionPageTurn.m new file mode 100755 index 0000000..bff43a7 --- /dev/null +++ b/tweejump/libs/cocos2d/CCTransitionPageTurn.m @@ -0,0 +1,117 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2009 Sindesso Pty Ltd http://www.sindesso.com/ + * + * 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. + * + */ + + +#import "CCTransitionPageTurn.h" +#import "CCActionPageTurn3D.h" +#import "CCDirector.h" + +@implementation CCTransitionPageTurn + +/** creates a base transition with duration and incoming scene */ ++(id) transitionWithDuration:(ccTime) t scene:(CCScene*)s backwards:(BOOL) back +{ + return [[[self alloc] initWithDuration:t scene:s backwards:back] autorelease]; +} + +/** initializes a transition with duration and incoming scene */ +-(id) initWithDuration:(ccTime) t scene:(CCScene*)s backwards:(BOOL) back +{ + // XXX: needed before [super init] + back_ = back; + + if( ( self = [super initWithDuration:t scene:s] ) ) + { + // do something + } + return self; +} + +-(void) sceneOrder +{ + inSceneOnTop_ = back_; +} + +// +-(void) onEnter +{ + [super onEnter]; + + CGSize s = [[CCDirector sharedDirector] winSize]; + int x, y; + if( s.width > s.height) + { + x = 16; + y = 12; + } + else + { + x = 12; + y = 16; + } + + id action = [self actionWithSize:ccg(x,y)]; + + if(! back_ ) + { + [outScene_ runAction: [CCSequence actions: + action, + [CCCallFunc actionWithTarget:self selector:@selector(finish)], + [CCStopGrid action], + nil] + ]; + } + else + { + // to prevent initial flicker + inScene_.visible = NO; + [inScene_ runAction: [CCSequence actions: + [CCShow action], + action, + [CCCallFunc actionWithTarget:self selector:@selector(finish)], + [CCStopGrid action], + nil] + ]; + } + +} + +-(CCActionInterval*) actionWithSize: (ccGridSize) v +{ + if( back_ ) + { + // Get hold of the PageTurn3DAction + return [CCReverseTime actionWithAction: + [CCPageTurn3D actionWithSize:v duration:duration_]]; + } + else + { + // Get hold of the PageTurn3DAction + return [CCPageTurn3D actionWithSize:v duration:duration_]; + } +} + +@end + diff --git a/tweejump/libs/cocos2d/CCTransitionRadial.h b/tweejump/libs/cocos2d/CCTransitionRadial.h new file mode 100755 index 0000000..6d4a5e0 --- /dev/null +++ b/tweejump/libs/cocos2d/CCTransitionRadial.h @@ -0,0 +1,40 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2009 Lam Pham + * + * 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. + * + */ + +#import "CCTransition.h" +#import "CCProgressTimer.h" +#import "CCActionProgressTimer.h" + +/** CCTransitionRadialCCW transition. + A counter colock-wise radial transition to the next scene + */ +@interface CCTransitionRadialCCW : CCTransitionScene +@end + +/** CCTransitionRadialCW transition. + A counter colock-wise radial transition to the next scene +*/ +@interface CCTransitionRadialCW : CCTransitionRadialCCW +@end diff --git a/tweejump/libs/cocos2d/CCTransitionRadial.m b/tweejump/libs/cocos2d/CCTransitionRadial.m new file mode 100755 index 0000000..a892f35 --- /dev/null +++ b/tweejump/libs/cocos2d/CCTransitionRadial.m @@ -0,0 +1,115 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2009 Lam Pham + * + * 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. + * + */ + + + +#import "CCDirector.h" +#import "CCTransitionRadial.h" +#import "CCRenderTexture.h" +#import "CCLayer.h" +#import "CCActionInstant.h" +#import "Support/CGPointExtension.h" + +enum { + kSceneRadial = 0xc001, +}; + +#pragma mark - +#pragma mark Transition Radial CCW + +@implementation CCTransitionRadialCCW +-(void) sceneOrder +{ + inSceneOnTop_ = NO; +} + +-(CCProgressTimerType) radialType +{ + return kCCProgressTimerTypeRadialCCW; +} + +-(void) onEnter +{ + [super onEnter]; + // create a transparent color layer + // in which we are going to add our rendertextures + CGSize size = [[CCDirector sharedDirector] winSize]; + + // create the second render texture for outScene + CCRenderTexture *outTexture = [CCRenderTexture renderTextureWithWidth:size.width height:size.height]; + outTexture.sprite.anchorPoint= ccp(0.5f,0.5f); + outTexture.position = ccp(size.width/2, size.height/2); + outTexture.anchorPoint = ccp(0.5f,0.5f); + + // render outScene to its texturebuffer + [outTexture clear:0 g:0 b:0 a:1]; + [outTexture begin]; + [outScene_ visit]; + [outTexture end]; + + // Since we've passed the outScene to the texture we don't need it. + [self hideOutShowIn]; + + // We need the texture in RenderTexture. + CCProgressTimer *outNode = [CCProgressTimer progressWithTexture:outTexture.sprite.texture]; + // but it's flipped upside down so we flip the sprite + outNode.sprite.flipY = YES; + // Return the radial type that we want to use + outNode.type = [self radialType]; + outNode.percentage = 100.f; + outNode.position = ccp(size.width/2, size.height/2); + outNode.anchorPoint = ccp(0.5f,0.5f); + + // create the blend action + CCActionInterval * layerAction = [CCSequence actions: + [CCProgressFromTo actionWithDuration:duration_ from:100.f to:0.f], + [CCCallFunc actionWithTarget:self selector:@selector(finish)], + nil ]; + // run the blend action + [outNode runAction: layerAction]; + + // add the layer (which contains our two rendertextures) to the scene + [self addChild: outNode z:2 tag:kSceneRadial]; +} + +// clean up on exit +-(void) onExit +{ + // remove our layer and release all containing objects + [self removeChildByTag:kSceneRadial cleanup:NO]; + [super onExit]; +} +@end + +#pragma mark - +#pragma mark Transition Radial CW + +@implementation CCTransitionRadialCW +-(CCProgressTimerType) radialType +{ + return kCCProgressTimerTypeRadialCW; +} +@end + diff --git a/tweejump/libs/cocos2d/Platforms/CCGL.h b/tweejump/libs/cocos2d/Platforms/CCGL.h new file mode 100755 index 0000000..0725f89 --- /dev/null +++ b/tweejump/libs/cocos2d/Platforms/CCGL.h @@ -0,0 +1,83 @@ +/* + * 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. + */ + +// +// Common layer for OpenGL stuff +// + +#import + +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED +#import +#import +#import +#import "iOS/glu.h" +#import "iOS/EAGLView.h" + +#elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED) +#import +#import +#import // needed for NSOpenGLView +#import "Mac/MacGLView.h" +#endif + + +// iOS +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED +#define CC_GLVIEW EAGLView +#define ccglOrtho glOrthof +#define ccglClearDepth glClearDepthf +#define ccglGenerateMipmap glGenerateMipmapOES +#define ccglGenFramebuffers glGenFramebuffersOES +#define ccglBindFramebuffer glBindFramebufferOES +#define ccglFramebufferTexture2D glFramebufferTexture2DOES +#define ccglDeleteFramebuffers glDeleteFramebuffersOES +#define ccglCheckFramebufferStatus glCheckFramebufferStatusOES +#define ccglTranslate glTranslatef + +#define CC_GL_FRAMEBUFFER GL_FRAMEBUFFER_OES +#define CC_GL_FRAMEBUFFER_BINDING GL_FRAMEBUFFER_BINDING_OES +#define CC_GL_COLOR_ATTACHMENT0 GL_COLOR_ATTACHMENT0_OES +#define CC_GL_FRAMEBUFFER_COMPLETE GL_FRAMEBUFFER_COMPLETE_OES + +// Mac +#elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED) +#define CC_GLVIEW MacGLView +#define ccglOrtho glOrtho +#define ccglClearDepth glClearDepth +#define ccglGenerateMipmap glGenerateMipmap +#define ccglGenFramebuffers glGenFramebuffers +#define ccglBindFramebuffer glBindFramebuffer +#define ccglFramebufferTexture2D glFramebufferTexture2D +#define ccglDeleteFramebuffers glDeleteFramebuffers +#define ccglCheckFramebufferStatus glCheckFramebufferStatus +#define ccglTranslate glTranslated + +#define CC_GL_FRAMEBUFFER GL_FRAMEBUFFER +#define CC_GL_FRAMEBUFFER_BINDING GL_FRAMEBUFFER_BINDING +#define CC_GL_COLOR_ATTACHMENT0 GL_COLOR_ATTACHMENT0 +#define CC_GL_FRAMEBUFFER_COMPLETE GL_FRAMEBUFFER_COMPLETE + +#endif diff --git a/tweejump/libs/cocos2d/Platforms/CCNS.h b/tweejump/libs/cocos2d/Platforms/CCNS.h new file mode 100755 index 0000000..c595a18 --- /dev/null +++ b/tweejump/libs/cocos2d/Platforms/CCNS.h @@ -0,0 +1,78 @@ +/* + * 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. + */ + +// +// Common layer for NS (Next-Step) stuff +// + +#import + +#import // for NSObject + +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED + +#define CCRectFromString(__r__) CGRectFromString(__r__) +#define CCPointFromString(__p__) CGPointFromString(__p__) +#define CCSizeFromString(__s__) CGSizeFromString(__s__) +#define CCNSSizeToCGSize +#define CCNSRectToCGRect +#define CCNSPointToCGPoint +#define CCTextAlignment UITextAlignment +#define CCTextAlignmentCenter UITextAlignmentCenter +#define CCTextAlignmentLeft UITextAlignmentLeft +#define CCTextAlignmentRight UITextAlignmentRight +#define CCLineBreakMode UILineBreakMode +#define CCLineBreakModeWordWrap UILineBreakModeWordWrap +#define CCLineBreakModeCharacterWrap UILineBreakModeCharacterWrap +#define CCLineBreakModeClip UILineBreakModeClip +#define CCLineBreakModeHeadTruncation UILineBreakModeHeadTruncation +#define CCLineBreakModeTailTruncation UILineBreakModeTailTruncation +#define CCLineBreakModeMiddleTruncation UILineBreakModeMiddleTruncation + + + +#elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED) + +#define CCRectFromString(__r__) NSRectToCGRect( NSRectFromString(__r__) ) +#define CCPointFromString(__p__) NSPointToCGPoint( NSPointFromString(__p__) ) +#define CCSizeFromString(__s__) NSSizeToCGSize( NSSizeFromString(__s__) ) +#define CCNSSizeToCGSize NSSizeToCGSize +#define CCNSRectToCGRect NSRectToCGRect +#define CCNSPointToCGPoint NSPointToCGPoint +#define CCTextAlignment NSTextAlignment +#define CCTextAlignmentCenter NSCenterTextAlignment +#define CCTextAlignmentLeft NSLeftTextAlignment +#define CCTextAlignmentRight NSRightTextAlignment +#define CCLineBreakMode NSLineBreakMode +#define CCLineBreakModeWordWrap NSLineBreakByWordWrapping +#define CCLineBreakModeClip -1 +#define CCLineBreakModeHeadTruncation -1 +#define CCLineBreakModeTailTruncation -1 +#define CCLineBreakModeMiddleTruncation -1 + + +#endif + + diff --git a/tweejump/libs/cocos2d/Platforms/Mac/CCDirectorMac.h b/tweejump/libs/cocos2d/Platforms/Mac/CCDirectorMac.h new file mode 100755 index 0000000..0d623b4 --- /dev/null +++ b/tweejump/libs/cocos2d/Platforms/Mac/CCDirectorMac.h @@ -0,0 +1,103 @@ +/* + * 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 Mac. These files should not be included on your iOS project. +// But in case they are included, it won't be compiled. +#import +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED +#elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED) + +#import +#import "../../CCDirector.h" + +enum { + /// If the window is resized, it won't be autoscaled + kCCDirectorResize_NoScale, + /// If the window is resized, it will be autoscaled (default behavior) + kCCDirectorResize_AutoScale, +}; + +@interface CCDirector (MacExtension) +/** converts an NSEvent to GL coordinates */ +-(CGPoint) convertEventToGL:(NSEvent*)event; +@end + +/** Base class of Mac directors + @since v0.99.5 + */ +@interface CCDirectorMac : CCDirector +{ + BOOL isFullScreen_; + int resizeMode_; + CGPoint winOffset_; + CGSize originalWinSize_; + + NSWindow *fullScreenWindow_; + + // cache + NSWindow *windowGLView_; + NSView *superViewGLView_; + NSRect originalWinRect_; // Original size and position +} + +// whether or not the view is in fullscreen mode +@property (nonatomic, readonly) BOOL isFullScreen; + +// resize mode: with or without scaling +@property (nonatomic, readwrite) int resizeMode; + +@property (nonatomic, readwrite) CGSize originalWinSize; + +/** Sets the view in fullscreen or window mode */ +- (void) setFullScreen:(BOOL)fullscreen; + +/** Converts window size coordiantes to logical coordinates. + Useful only if resizeMode is kCCDirectorResize_Scale. + If resizeMode is kCCDirectorResize_NoScale, then no conversion will be done. +*/ +- (CGPoint) convertToLogicalCoordinates:(CGPoint)coordinates; +@end + + +/** DisplayLinkDirector is a Director that synchronizes timers with the refresh rate of the display. + * + * Features and Limitations: + * - Only available on 3.1+ + * - Scheduled timers & drawing are synchronizes with the refresh rate of the display + * - Only supports animation intervals of 1/60 1/30 & 1/15 + * + * It is the recommended Director if the SDK is 3.1 or newer + * + * @since v0.8.2 + */ +@interface CCDirectorDisplayLink : CCDirectorMac +{ + CVDisplayLinkRef displayLink; +} +@end + +#endif // __MAC_OS_X_VERSION_MAX_ALLOWED + diff --git a/tweejump/libs/cocos2d/Platforms/Mac/CCDirectorMac.m b/tweejump/libs/cocos2d/Platforms/Mac/CCDirectorMac.m new file mode 100755 index 0000000..270b026 --- /dev/null +++ b/tweejump/libs/cocos2d/Platforms/Mac/CCDirectorMac.m @@ -0,0 +1,481 @@ +/* + * 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 Mac. These files should not be included on your iOS project. +// But in case they are included, it won't be compiled. +#import +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED +#elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED) + +#import + +#import "CCDirectorMac.h" +#import "CCEventDispatcher.h" +#import "MacGLView.h" + +#import "../../CCNode.h" +#import "../../CCScheduler.h" +#import "../../ccMacros.h" + +#pragma mark - +#pragma mark Director Mac extensions + + +@interface CCDirector () +-(void) setNextScene; +-(void) showFPS; +-(void) calculateDeltaTime; +@end + +@implementation CCDirector (MacExtension) +-(CGPoint) convertEventToGL:(NSEvent*)event +{ + NSPoint point = [openGLView_ convertPoint:[event locationInWindow] fromView:nil]; + CGPoint p = NSPointToCGPoint(point); + + return [(CCDirectorMac*)self convertToLogicalCoordinates:p]; +} + +@end + +#pragma mark - +#pragma mark Director Mac + +@implementation CCDirectorMac + +@synthesize isFullScreen = isFullScreen_; +@synthesize originalWinSize = originalWinSize_; + +-(id) init +{ + if( (self = [super init]) ) { + isFullScreen_ = NO; + resizeMode_ = kCCDirectorResize_AutoScale; + + originalWinSize_ = CGSizeZero; + fullScreenWindow_ = nil; + windowGLView_ = nil; + winOffset_ = CGPointZero; + } + + return self; +} + +- (void) dealloc +{ + [superViewGLView_ release]; + [fullScreenWindow_ release]; + [windowGLView_ release]; + [super dealloc]; +} + +// +// setFullScreen code taken from GLFullScreen example by Apple +// +- (void) setFullScreen:(BOOL)fullscreen +{ + // Mac OS X 10.6 and later offer a simplified mechanism to create full-screen contexts +#if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5 + + if (isFullScreen_ == fullscreen) return; + + if( fullscreen ) { + originalWinRect_ = [openGLView_ frame]; + + // Cache normal window and superview of openGLView + if(!windowGLView_) + windowGLView_ = [[openGLView_ window] retain]; + + [superViewGLView_ release]; + superViewGLView_ = [[openGLView_ superview] retain]; + + + // Get screen size + NSRect displayRect = [[NSScreen mainScreen] frame]; + + // Create a screen-sized window on the display you want to take over + fullScreenWindow_ = [[MacWindow alloc] initWithFrame:displayRect fullscreen:YES]; + + // Remove glView from window + [openGLView_ removeFromSuperview]; + + // Set new frame + [openGLView_ setFrame:displayRect]; + + // Attach glView to fullscreen window + [fullScreenWindow_ setContentView:openGLView_]; + + // Show the fullscreen window + [fullScreenWindow_ makeKeyAndOrderFront:self]; + [fullScreenWindow_ makeMainWindow]; + + } else { + + // Remove glView from fullscreen window + [openGLView_ removeFromSuperview]; + + // Release fullscreen window + [fullScreenWindow_ release]; + fullScreenWindow_ = nil; + + // Attach glView to superview + [superViewGLView_ addSubview:openGLView_]; + + // Set new frame + [openGLView_ setFrame:originalWinRect_]; + + // Show the window + [windowGLView_ makeKeyAndOrderFront:self]; + [windowGLView_ makeMainWindow]; + } + isFullScreen_ = fullscreen; + + [openGLView_ retain]; // Retain +1 + + // re-configure glView + [self setOpenGLView:openGLView_]; + + [openGLView_ release]; // Retain -1 + + [openGLView_ setNeedsDisplay:YES]; +#else +#error Full screen is not supported for Mac OS 10.5 or older yet +#error If you don't want FullScreen support, you can safely remove these 2 lines +#endif +} + +-(void) setOpenGLView:(MacGLView *)view +{ + [super setOpenGLView:view]; + + // cache the NSWindow and NSOpenGLView created from the NIB + if( !isFullScreen_ && CGSizeEqualToSize(originalWinSize_, CGSizeZero)) + { + originalWinSize_ = winSizeInPixels_; + } +} + +-(int) resizeMode +{ + return resizeMode_; +} + +-(void) setResizeMode:(int)mode +{ + if( mode != resizeMode_ ) { + + resizeMode_ = mode; + + [self setProjection:projection_]; + [openGLView_ setNeedsDisplay: YES]; + } +} + +-(void) setProjection:(ccDirectorProjection)projection +{ + CGSize size = winSizeInPixels_; + + CGPoint offset = CGPointZero; + float widthAspect = size.width; + float heightAspect = size.height; + + + if( resizeMode_ == kCCDirectorResize_AutoScale && ! CGSizeEqualToSize(originalWinSize_, CGSizeZero ) ) { + + size = originalWinSize_; + + float aspect = originalWinSize_.width / originalWinSize_.height; + widthAspect = winSizeInPixels_.width; + heightAspect = winSizeInPixels_.width / aspect; + + if( heightAspect > winSizeInPixels_.height ) { + widthAspect = winSizeInPixels_.height * aspect; + heightAspect = winSizeInPixels_.height; + } + + winOffset_.x = (winSizeInPixels_.width - widthAspect) / 2; + winOffset_.y = (winSizeInPixels_.height - heightAspect) / 2; + + offset = winOffset_; + + } + + switch (projection) { + case kCCDirectorProjection2D: + glViewport(offset.x, offset.y, widthAspect, heightAspect); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + ccglOrtho(0, size.width, 0, size.height, -1024, 1024); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + break; + + case kCCDirectorProjection3D: + glViewport(offset.x, offset.y, widthAspect, heightAspect); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPerspective(60, (GLfloat)widthAspect/heightAspect, 0.1f, 1500.0f); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + + float eyeZ = size.height * [self getZEye] / winSizeInPixels_.height; + + gluLookAt( size.width/2, size.height/2, eyeZ, + 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; +} + +// If scaling is supported, then it should always return the original size +// otherwise it should return the "real" size. +-(CGSize) winSize +{ + if( resizeMode_ == kCCDirectorResize_AutoScale ) + return originalWinSize_; + + return winSizeInPixels_; +} + +-(CGSize) winSizeInPixels +{ + return [self winSize]; +} + +- (CGPoint) convertToLogicalCoordinates:(CGPoint)coords +{ + CGPoint ret; + + if( resizeMode_ == kCCDirectorResize_NoScale ) + ret = coords; + + else { + + float x_diff = originalWinSize_.width / (winSizeInPixels_.width - winOffset_.x * 2); + float y_diff = originalWinSize_.height / (winSizeInPixels_.height - winOffset_.y * 2); + + float adjust_x = (winSizeInPixels_.width * x_diff - originalWinSize_.width ) / 2; + float adjust_y = (winSizeInPixels_.height * y_diff - originalWinSize_.height ) / 2; + + ret = CGPointMake( (x_diff * coords.x) - adjust_x, ( y_diff * coords.y ) - adjust_y ); + } + + return ret; +} +@end + + +#pragma mark - +#pragma mark DirectorDisplayLink + + +@implementation CCDirectorDisplayLink + +- (CVReturn) getFrameForTime:(const CVTimeStamp*)outputTime +{ +#if CC_DIRECTOR_MAC_USE_DISPLAY_LINK_THREAD + if( ! runningThread_ ) + runningThread_ = [NSThread currentThread]; + + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + + [self drawScene]; + [[CCEventDispatcher sharedDispatcher] dispatchQueuedEvents]; + + [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:nil]; + + [pool release]; + +#else + [self performSelector:@selector(drawScene) onThread:runningThread_ withObject:nil waitUntilDone:YES]; +#endif + + return kCVReturnSuccess; +} + +// This is the renderer output callback function +static CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeStamp* now, const CVTimeStamp* outputTime, CVOptionFlags flagsIn, CVOptionFlags* flagsOut, void* displayLinkContext) +{ + CVReturn result = [(CCDirectorDisplayLink*)displayLinkContext getFrameForTime:outputTime]; + return result; +} + +- (void) startAnimation +{ +#if ! CC_DIRECTOR_MAC_USE_DISPLAY_LINK_THREAD + runningThread_ = [[NSThread alloc] initWithTarget:self selector:@selector(mainLoop) object:nil]; + [runningThread_ start]; +#endif + + gettimeofday( &lastUpdate_, NULL); + + // Create a display link capable of being used with all active displays + CVDisplayLinkCreateWithActiveCGDisplays(&displayLink); + + // Set the renderer output callback function + CVDisplayLinkSetOutputCallback(displayLink, &MyDisplayLinkCallback, self); + + // Set the display link for the current renderer + CGLContextObj cglContext = [[openGLView_ openGLContext] CGLContextObj]; + CGLPixelFormatObj cglPixelFormat = [[openGLView_ pixelFormat] CGLPixelFormatObj]; + CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext(displayLink, cglContext, cglPixelFormat); + + // Activate the display link + CVDisplayLinkStart(displayLink); +} + +- (void) stopAnimation +{ + if( displayLink ) { + CVDisplayLinkStop(displayLink); + CVDisplayLinkRelease(displayLink); + displayLink = NULL; + +#if ! CC_DIRECTOR_MAC_USE_DISPLAY_LINK_THREAD + [runningThread_ cancel]; + [runningThread_ release]; + runningThread_ = nil; +#endif + } +} + +-(void) dealloc +{ + if( displayLink ) { + CVDisplayLinkStop(displayLink); + CVDisplayLinkRelease(displayLink); + } + [super dealloc]; +} + +// +// Mac Director has its own thread +// +-(void) mainLoop +{ + while( ![[NSThread currentThread] isCancelled] ) { + // There is no autorelease pool when this method is called because it will be called from a background thread + // It's important to create one or you will leak objects + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + + [[NSRunLoop currentRunLoop] run]; + + [pool release]; + } +} + +// +// Draw the Scene +// +- (void) drawScene +{ + // We draw on a secondary thread through the display link + // When resizing the view, -reshape is called automatically on the main thread + // Add a mutex around to avoid the threads accessing the context simultaneously when resizing + CGLLockContext([[openGLView_ openGLContext] CGLContextObj]); + [[openGLView_ openGLContext] makeCurrentContext]; + + /* 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(); + + + // 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(); + + totalFrames_++; + + [[openGLView_ openGLContext] flushBuffer]; + CGLUnlockContext([[openGLView_ openGLContext] CGLContextObj]); +} + +// set the event dispatcher +-(void) setOpenGLView:(MacGLView *)view +{ + if( view != openGLView_ ) { + + [super setOpenGLView:view]; + + CCEventDispatcher *eventDispatcher = [CCEventDispatcher sharedDispatcher]; + [openGLView_ setEventDelegate: eventDispatcher]; + [eventDispatcher setDispatchEvents: YES]; + + // Enable Touches. Default no. + [view setAcceptsTouchEvents:NO]; +// [view setAcceptsTouchEvents:YES]; + + + // Synchronize buffer swaps with vertical refresh rate + [[view openGLContext] makeCurrentContext]; + GLint swapInt = 1; + [[view openGLContext] setValues:&swapInt forParameter:NSOpenGLCPSwapInterval]; + } +} + +@end + +#endif // __MAC_OS_X_VERSION_MAX_ALLOWED diff --git a/tweejump/libs/cocos2d/Platforms/Mac/CCEventDispatcher.h b/tweejump/libs/cocos2d/Platforms/Mac/CCEventDispatcher.h new file mode 100755 index 0000000..06889e8 --- /dev/null +++ b/tweejump/libs/cocos2d/Platforms/Mac/CCEventDispatcher.h @@ -0,0 +1,277 @@ +/* + * 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 Mac. These files should not be included on your iOS project. +// But in case they are included, it won't be compiled. +#import +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED +#elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED) + +#import + +#import "MacGLView.h" +#import "../../Support/uthash.h" // hack: uthash needs to be imported before utlist to prevent warning +#import "../../Support/utlist.h" +#import "../../ccConfig.h" + +#pragma mark - +#pragma mark CCMouseEventDelegate + +/** CCMouseEventDelegate protocol. + Implement it in your node to receive any of mouse events + */ +@protocol CCMouseEventDelegate +@optional + +// +// left +// +/** called when the "mouseDown" event is received. + Return YES to avoid propagating the event to other delegates. + */ +-(BOOL) ccMouseDown:(NSEvent*)event; + +/** called when the "mouseDragged" event is received. + Return YES to avoid propagating the event to other delegates. + */ +-(BOOL) ccMouseDragged:(NSEvent*)event; + +/** called when the "mouseMoved" event is received. + Return YES to avoid propagating the event to other delegates. + By default, "mouseMoved" is disabled. To enable it, send the "setAcceptsMouseMovedEvents:YES" message to the main window. + */ +-(BOOL) ccMouseMoved:(NSEvent*)event; + +/** called when the "mouseUp" event is received. + Return YES to avoid propagating the event to other delegates. + */ +-(BOOL) ccMouseUp:(NSEvent*)event; + + +// +// right +// + +/** called when the "rightMouseDown" event is received. + Return YES to avoid propagating the event to other delegates. + */ +-(BOOL) ccRightMouseDown:(NSEvent*)event; + +/** called when the "rightMouseDragged" event is received. + Return YES to avoid propagating the event to other delegates. + */ +-(BOOL) ccRightMouseDragged:(NSEvent*)event; + +/** called when the "rightMouseUp" event is received. + Return YES to avoid propagating the event to other delegates. + */ +-(BOOL) ccRightMouseUp:(NSEvent*)event; + +// +// other +// + +/** called when the "otherMouseDown" event is received. + Return YES to avoid propagating the event to other delegates. + */ +-(BOOL) ccOtherMouseDown:(NSEvent*)event; + +/** called when the "otherMouseDragged" event is received. + Return YES to avoid propagating the event to other delegates. + */ +-(BOOL) ccOtherMouseDragged:(NSEvent*)event; + +/** called when the "otherMouseUp" event is received. + Return YES to avoid propagating the event to other delegates. + */ +-(BOOL) ccOtherMouseUp:(NSEvent*)event; + +// +// scroll wheel +// + +/** called when the "scrollWheel" event is received. + Return YES to avoid propagating the event to other delegates. + */ +- (BOOL)ccScrollWheel:(NSEvent *)theEvent; + + +// +// enter / exit +// + +/** called when the "mouseEntered" event is received. + Return YES to avoid propagating the event to other delegates. + */ +- (void)ccMouseEntered:(NSEvent *)theEvent; + +/** called when the "mouseExited" event is received. + Return YES to avoid propagating the event to other delegates. + */ +- (void)ccMouseExited:(NSEvent *)theEvent; + +@end + +#pragma mark - +#pragma mark CCKeyboardEventDelegate + +/** CCKeyboardEventDelegate protocol. + Implement it in your node to receive any of keyboard events + */ +@protocol CCKeyboardEventDelegate +@optional +/** called when the "keyUp" event is received. + Return YES to avoid propagating the event to other delegates. + */ +-(BOOL) ccKeyUp:(NSEvent*)event; + +/** called when the "keyDown" event is received. + Return YES to avoid propagating the event to other delegates. + */ +-(BOOL) ccKeyDown:(NSEvent*)event; +/** called when the "flagsChanged" event is received. + Return YES to avoid propagating the event to other delegates. + */ +-(BOOL) ccFlagsChanged:(NSEvent*)event; +@end + +#pragma mark - +#pragma mark CCTouchEventDelegate + +/** CCTouchEventDelegate protocol. + Implement it in your node to receive any of touch events + */ +@protocol CCTouchEventDelegate +@optional +/** called when the "touchesBegan" event is received. + Return YES to avoid propagating the event to other delegates. + */ +- (BOOL)ccTouchesBeganWithEvent:(NSEvent *)event; + +/** called when the "touchesMoved" event is received. + Return YES to avoid propagating the event to other delegates. + */ +- (BOOL)ccTouchesMovedWithEvent:(NSEvent *)event; + +/** called when the "touchesEnded" event is received. + Return YES to avoid propagating the event to other delegates. + */ +- (BOOL)ccTouchesEndedWithEvent:(NSEvent *)event; + +/** called when the "touchesCancelled" event is received. + Return YES to avoid propagating the event to other delegates. + */ +- (BOOL)ccTouchesCancelledWithEvent:(NSEvent *)event; + +@end + + +#pragma mark - +#pragma mark CCEventDispatcher + +struct _listEntry; + +/** CCEventDispatcher + + This is object is responsible for dispatching the events: + - Mouse events + - Keyboard events + - Touch events + + Only available on Mac + */ +@interface CCEventDispatcher : NSObject { + + BOOL dispatchEvents_; + + struct _listEntry *keyboardDelegates_; + struct _listEntry *mouseDelegates_; + struct _listEntry *touchDelegates_; +} + +@property (nonatomic, readwrite) BOOL dispatchEvents; + + +/** CCEventDispatcher singleton */ ++(CCEventDispatcher*) sharedDispatcher; + +#pragma mark CCEventDispatcher - Mouse + +/** Adds a mouse delegate to the dispatcher's list. + Delegates with a lower priority value will be called before higher priority values. + All the events will be propgated to all the delegates, unless the one delegate returns YES. + + IMPORTANT: The delegate will be retained. + */ +-(void) addMouseDelegate:(id) delegate priority:(NSInteger)priority; + +/** removes a mouse delegate */ +-(void) removeMouseDelegate:(id) delegate; + +/** Removes all mouse delegates, releasing all the delegates */ +-(void) removeAllMouseDelegates; + +#pragma mark CCEventDispatcher - Keyboard + +/** Adds a Keyboard delegate to the dispatcher's list. + Delegates with a lower priority value will be called before higher priority values. + All the events will be propgated to all the delegates, unless the one delegate returns YES. + + IMPORTANT: The delegate will be retained. + */ +-(void) addKeyboardDelegate:(id) delegate priority:(NSInteger)priority; + +/** removes a mouse delegate */ +-(void) removeKeyboardDelegate:(id) delegate; + +/** Removes all mouse delegates, releasing all the delegates */ +-(void) removeAllKeyboardDelegates; + +#pragma mark CCEventDispatcher - Touches + +/** Adds a Touch delegate to the dispatcher's list. + Delegates with a lower priority value will be called before higher priority values. + All the events will be propgated to all the delegates, unless the one delegate returns YES. + + IMPORTANT: The delegate will be retained. + */ +- (void)addTouchDelegate:(id)delegate priority:(NSInteger)priority; + +/** Removes a touch delegate */ +- (void)removeTouchDelegate:(id) delegate; + +/** Removes all touch delegates, releasing all the delegates */ +- (void)removeAllTouchDelegates; + +#pragma mark CCEventDispatcher - Dispatch Events + +#if CC_DIRECTOR_MAC_USE_DISPLAY_LINK_THREAD +-(void) dispatchQueuedEvents; +#endif + +@end + + +#endif // __MAC_OS_X_VERSION_MAX_ALLOWED diff --git a/tweejump/libs/cocos2d/Platforms/Mac/CCEventDispatcher.m b/tweejump/libs/cocos2d/Platforms/Mac/CCEventDispatcher.m new file mode 100755 index 0000000..1d1740e --- /dev/null +++ b/tweejump/libs/cocos2d/Platforms/Mac/CCEventDispatcher.m @@ -0,0 +1,645 @@ +/* + * 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 Mac. These files should not be included on your iOS project. +// But in case they are included, it won't be compiled. +#import +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED +#elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED) + +#import "CCEventDispatcher.h" +#import "../../ccConfig.h" + +static CCEventDispatcher *sharedDispatcher = nil; + +enum { + // mouse + kCCImplementsMouseDown = 1 << 0, + kCCImplementsMouseMoved = 1 << 1, + kCCImplementsMouseDragged = 1 << 2, + kCCImplementsMouseUp = 1 << 3, + kCCImplementsRightMouseDown = 1 << 4, + kCCImplementsRightMouseDragged = 1 << 5, + kCCImplementsRightMouseUp = 1 << 6, + kCCImplementsOtherMouseDown = 1 << 7, + kCCImplementsOtherMouseDragged = 1 << 8, + kCCImplementsOtherMouseUp = 1 << 9, + kCCImplementsScrollWheel = 1 << 10, + kCCImplementsMouseEntered = 1 << 11, + kCCImplementsMouseExited = 1 << 12, + + kCCImplementsTouchesBegan = 1 << 13, + kCCImplementsTouchesMoved = 1 << 14, + kCCImplementsTouchesEnded = 1 << 15, + kCCImplementsTouchesCancelled = 1 << 16, + + // keyboard + kCCImplementsKeyUp = 1 << 0, + kCCImplementsKeyDown = 1 << 1, + kCCImplementsFlagsChanged = 1 << 2, +}; + + +typedef struct _listEntry +{ + struct _listEntry *prev, *next; + id delegate; + NSInteger priority; + NSUInteger flags; +} tListEntry; + + +#if CC_DIRECTOR_MAC_USE_DISPLAY_LINK_THREAD + +#define QUEUE_EVENT_MAX 128 +struct _eventQueue { + SEL selector; + NSEvent *event; +}; + +static struct _eventQueue eventQueue[QUEUE_EVENT_MAX]; +static int eventQueueCount; + +#endif // CC_DIRECTOR_MAC_USE_DISPLAY_LINK_THREAD + + +@implementation CCEventDispatcher + +@synthesize dispatchEvents=dispatchEvents_; + + ++(CCEventDispatcher*) sharedDispatcher +{ + @synchronized(self) { + if (sharedDispatcher == nil) + sharedDispatcher = [[self alloc] init]; // assignment not done here + } + return sharedDispatcher; +} + ++(id) allocWithZone:(NSZone *)zone +{ + @synchronized(self) { + NSAssert(sharedDispatcher == nil, @"Attempted to allocate a second instance of a singleton."); + return [super allocWithZone:zone]; + } + return nil; // on subsequent allocation attempts return nil +} + +-(id) init +{ + if( (self = [super init]) ) + { + // events enabled by default + dispatchEvents_ = YES; + + // delegates + keyboardDelegates_ = NULL; + mouseDelegates_ = NULL; + touchDelegates_ = NULL; + +#if CC_DIRECTOR_MAC_USE_DISPLAY_LINK_THREAD + eventQueueCount = 0; +#endif + } + + return self; +} + +- (void) dealloc +{ + [super dealloc]; +} + +#pragma mark CCEventDispatcher - add / remove delegates + +-(void) addDelegate:(id)delegate priority:(NSInteger)priority flags:(NSUInteger)flags list:(tListEntry**)list +{ + tListEntry *listElement = malloc( sizeof(*listElement) ); + + listElement->delegate = [delegate retain]; + listElement->priority = priority; + listElement->flags = flags; + listElement->next = listElement->prev = NULL; + + // empty list ? + if( ! *list ) { + DL_APPEND( *list, listElement ); + + } else { + BOOL added = NO; + + for( tListEntry *elem = *list; elem ; elem = elem->next ) { + if( priority < elem->priority ) { + + if( elem == *list ) + DL_PREPEND(*list, listElement); + else { + listElement->next = elem; + listElement->prev = elem->prev; + + elem->prev->next = listElement; + elem->prev = listElement; + } + + added = YES; + break; + } + } + + // Not added? priority has the higher value. Append it. + if( !added ) + DL_APPEND(*list, listElement); + } +} + +-(void) removeDelegate:(id)delegate fromList:(tListEntry**)list +{ + tListEntry *entry, *tmp; + + // updates with priority < 0 + DL_FOREACH_SAFE( *list, entry, tmp ) { + if( entry->delegate == delegate ) { + DL_DELETE( *list, entry ); + [delegate release]; + free(entry); + break; + } + } +} + +-(void) removeAllDelegatesFromList:(tListEntry**)list +{ + tListEntry *entry, *tmp; + + DL_FOREACH_SAFE( *list, entry, tmp ) { + DL_DELETE( *list, entry ); + free(entry); + } +} + + +-(void) addMouseDelegate:(id) delegate priority:(NSInteger)priority +{ + NSUInteger flags = 0; + + flags |= ( [delegate respondsToSelector:@selector(ccMouseDown:)] ? kCCImplementsMouseDown : 0 ); + flags |= ( [delegate respondsToSelector:@selector(ccMouseDragged:)] ? kCCImplementsMouseDragged : 0 ); + flags |= ( [delegate respondsToSelector:@selector(ccMouseMoved:)] ? kCCImplementsMouseMoved : 0 ); + flags |= ( [delegate respondsToSelector:@selector(ccMouseUp:)] ? kCCImplementsMouseUp : 0 ); + + flags |= ( [delegate respondsToSelector:@selector(ccRightMouseDown:)] ? kCCImplementsRightMouseDown : 0 ); + flags |= ( [delegate respondsToSelector:@selector(ccRightMouseDragged:)] ? kCCImplementsRightMouseDragged : 0 ); + flags |= ( [delegate respondsToSelector:@selector(ccRightMouseUp:)] ? kCCImplementsRightMouseUp : 0 ); + + flags |= ( [delegate respondsToSelector:@selector(ccOtherMouseDown:)] ? kCCImplementsOtherMouseDown : 0 ); + flags |= ( [delegate respondsToSelector:@selector(ccOtherMouseDragged:)] ? kCCImplementsOtherMouseDragged : 0 ); + flags |= ( [delegate respondsToSelector:@selector(ccOtherMouseUp:)] ? kCCImplementsOtherMouseUp : 0 ); + + flags |= ( [delegate respondsToSelector:@selector(ccMouseEntered:)] ? kCCImplementsMouseEntered : 0 ); + flags |= ( [delegate respondsToSelector:@selector(ccMouseExited:)] ? kCCImplementsMouseExited : 0 ); + + flags |= ( [delegate respondsToSelector:@selector(ccScrollWheel:)] ? kCCImplementsScrollWheel : 0 ); + + [self addDelegate:delegate priority:priority flags:flags list:&mouseDelegates_]; +} + +-(void) removeMouseDelegate:(id) delegate +{ + [self removeDelegate:delegate fromList:&mouseDelegates_]; +} + +-(void) removeAllMouseDelegates +{ + [self removeAllDelegatesFromList:&mouseDelegates_]; +} + +-(void) addKeyboardDelegate:(id) delegate priority:(NSInteger)priority +{ + NSUInteger flags = 0; + + flags |= ( [delegate respondsToSelector:@selector(ccKeyUp:)] ? kCCImplementsKeyUp : 0 ); + flags |= ( [delegate respondsToSelector:@selector(ccKeyDown:)] ? kCCImplementsKeyDown : 0 ); + flags |= ( [delegate respondsToSelector:@selector(ccFlagsChanged:)] ? kCCImplementsFlagsChanged : 0 ); + + [self addDelegate:delegate priority:priority flags:flags list:&keyboardDelegates_]; +} + +-(void) removeKeyboardDelegate:(id) delegate +{ + [self removeDelegate:delegate fromList:&keyboardDelegates_]; +} + +-(void) removeAllKeyboardDelegates +{ + [self removeAllDelegatesFromList:&keyboardDelegates_]; +} + +-(void) addTouchDelegate:(id) delegate priority:(NSInteger)priority +{ + NSUInteger flags = 0; + + flags |= ( [delegate respondsToSelector:@selector(ccTouchesBeganWithEvent:)] ? kCCImplementsTouchesBegan : 0 ); + flags |= ( [delegate respondsToSelector:@selector(ccTouchesMovedWithEvent:)] ? kCCImplementsTouchesMoved : 0 ); + flags |= ( [delegate respondsToSelector:@selector(ccTouchesEndedWithEvent:)] ? kCCImplementsTouchesEnded : 0 ); + flags |= ( [delegate respondsToSelector:@selector(ccTouchesCancelledWithEvent:)] ? kCCImplementsTouchesCancelled : 0 ); + + [self addDelegate:delegate priority:priority flags:flags list:&touchDelegates_]; +} + +-(void) removeTouchDelegate:(id) delegate +{ + [self removeDelegate:delegate fromList:&touchDelegates_]; +} + +-(void) removeAllTouchDelegates +{ + [self removeAllDelegatesFromList:&touchDelegates_]; +} + + +#pragma mark CCEventDispatcher - Mouse events +// +// Mouse events +// + +// +// Left +// +- (void)mouseDown:(NSEvent *)event +{ + if( dispatchEvents_ ) { + tListEntry *entry, *tmp; + + DL_FOREACH_SAFE( mouseDelegates_, entry, tmp ) { + if ( entry->flags & kCCImplementsMouseDown ) { + void *swallows = [entry->delegate performSelector:@selector(ccMouseDown:) withObject:event]; + if( swallows ) + break; + } + } + } +} + +- (void)mouseMoved:(NSEvent *)event +{ + if( dispatchEvents_ ) { + tListEntry *entry, *tmp; + + DL_FOREACH_SAFE( mouseDelegates_, entry, tmp ) { + if ( entry->flags & kCCImplementsMouseMoved ) { + void *swallows = [entry->delegate performSelector:@selector(ccMouseMoved:) withObject:event]; + if( swallows ) + break; + } + } + } +} + +- (void)mouseDragged:(NSEvent *)event +{ + if( dispatchEvents_ ) { + tListEntry *entry, *tmp; + + DL_FOREACH_SAFE( mouseDelegates_, entry, tmp ) { + if ( entry->flags & kCCImplementsMouseDragged ) { + void *swallows = [entry->delegate performSelector:@selector(ccMouseDragged:) withObject:event]; + if( swallows ) + break; + } + } + } +} + +- (void)mouseUp:(NSEvent *)event +{ + if( dispatchEvents_ ) { + tListEntry *entry, *tmp; + + DL_FOREACH_SAFE( mouseDelegates_, entry, tmp ) { + if ( entry->flags & kCCImplementsMouseUp ) { + void *swallows = [entry->delegate performSelector:@selector(ccMouseUp:) withObject:event]; + if( swallows ) + break; + } + } + } +} + +// +// Mouse Right +// +- (void)rightMouseDown:(NSEvent *)event +{ + if( dispatchEvents_ ) { + tListEntry *entry, *tmp; + + DL_FOREACH_SAFE( mouseDelegates_, entry, tmp ) { + if ( entry->flags & kCCImplementsRightMouseDown ) { + void *swallows = [entry->delegate performSelector:@selector(ccRightMouseDown:) withObject:event]; + if( swallows ) + break; + } + } + } +} + +- (void)rightMouseDragged:(NSEvent *)event +{ + if( dispatchEvents_ ) { + tListEntry *entry, *tmp; + + DL_FOREACH_SAFE( mouseDelegates_, entry, tmp ) { + if ( entry->flags & kCCImplementsRightMouseDragged ) { + void *swallows = [entry->delegate performSelector:@selector(ccRightMouseDragged:) withObject:event]; + if( swallows ) + break; + } + } + } +} + +- (void)rightMouseUp:(NSEvent *)event +{ + if( dispatchEvents_ ) { + tListEntry *entry, *tmp; + + DL_FOREACH_SAFE( mouseDelegates_, entry, tmp ) { + if ( entry->flags & kCCImplementsRightMouseUp ) { + void *swallows = [entry->delegate performSelector:@selector(ccRightMouseUp:) withObject:event]; + if( swallows ) + break; + } + } + } +} + +// +// Mouse Other +// +- (void)otherMouseDown:(NSEvent *)event +{ + if( dispatchEvents_ ) { + tListEntry *entry, *tmp; + + DL_FOREACH_SAFE( mouseDelegates_, entry, tmp ) { + if ( entry->flags & kCCImplementsOtherMouseDown ) { + void *swallows = [entry->delegate performSelector:@selector(ccOtherMouseDown:) withObject:event]; + if( swallows ) + break; + } + } + } +} + +- (void)otherMouseDragged:(NSEvent *)event +{ + if( dispatchEvents_ ) { + tListEntry *entry, *tmp; + + DL_FOREACH_SAFE( mouseDelegates_, entry, tmp ) { + if ( entry->flags & kCCImplementsOtherMouseDragged ) { + void *swallows = [entry->delegate performSelector:@selector(ccOtherMouseDragged:) withObject:event]; + if( swallows ) + break; + } + } + } +} + +- (void)otherMouseUp:(NSEvent *)event +{ + if( dispatchEvents_ ) { + tListEntry *entry, *tmp; + + DL_FOREACH_SAFE( mouseDelegates_, entry, tmp ) { + if ( entry->flags & kCCImplementsOtherMouseUp ) { + void *swallows = [entry->delegate performSelector:@selector(ccOtherMouseUp:) withObject:event]; + if( swallows ) + break; + } + } + } +} + +// +// Scroll Wheel +// +- (void)scrollWheel:(NSEvent *)event +{ + if( dispatchEvents_ ) { + tListEntry *entry, *tmp; + + DL_FOREACH_SAFE( mouseDelegates_, entry, tmp ) { + if ( entry->flags & kCCImplementsScrollWheel ) { + void *swallows = [entry->delegate performSelector:@selector(ccScrollWheel:) withObject:event]; + if( swallows ) + break; + } + } + } +} + +// +// Mouse enter / exit +- (void)mouseExited:(NSEvent *)event +{ + if( dispatchEvents_ ) { + tListEntry *entry, *tmp; + + DL_FOREACH_SAFE( mouseDelegates_, entry, tmp ) { + if ( entry->flags & kCCImplementsMouseEntered ) { + void *swallows = [entry->delegate performSelector:@selector(ccMouseEntered:) withObject:event]; + if( swallows ) + break; + } + } + } +} + +- (void)mouseEntered:(NSEvent *)event +{ + if( dispatchEvents_ ) { + tListEntry *entry, *tmp; + + DL_FOREACH_SAFE( mouseDelegates_, entry, tmp ) { + if ( entry->flags & kCCImplementsMouseExited) { + void *swallows = [entry->delegate performSelector:@selector(ccMouseExited:) withObject:event]; + if( swallows ) + break; + } + } + } +} + + +#pragma mark CCEventDispatcher - Keyboard events + +// Keyboard events +- (void)keyDown:(NSEvent *)event +{ + if( dispatchEvents_ ) { + tListEntry *entry, *tmp; + + DL_FOREACH_SAFE( keyboardDelegates_, entry, tmp ) { + if ( entry->flags & kCCImplementsKeyDown ) { + void *swallows = [entry->delegate performSelector:@selector(ccKeyDown:) withObject:event]; + if( swallows ) + break; + } + } + } +} + +- (void)keyUp:(NSEvent *)event +{ + if( dispatchEvents_ ) { + tListEntry *entry, *tmp; + + DL_FOREACH_SAFE( keyboardDelegates_, entry, tmp ) { + if ( entry->flags & kCCImplementsKeyUp ) { + void *swallows = [entry->delegate performSelector:@selector(ccKeyUp:) withObject:event]; + if( swallows ) + break; + } + } + } +} + +- (void)flagsChanged:(NSEvent *)event +{ + if( dispatchEvents_ ) { + tListEntry *entry, *tmp; + + DL_FOREACH_SAFE( keyboardDelegates_, entry, tmp ) { + if ( entry->flags & kCCImplementsFlagsChanged ) { + void *swallows = [entry->delegate performSelector:@selector(ccFlagsChanged:) withObject:event]; + if( swallows ) + break; + } + } + } +} + + +#pragma mark CCEventDispatcher - Touch events + +- (void)touchesBeganWithEvent:(NSEvent *)event +{ + if( dispatchEvents_ ) { + tListEntry *entry, *tmp; + + DL_FOREACH_SAFE( touchDelegates_, entry, tmp ) { + if ( entry->flags & kCCImplementsTouchesBegan) { + void *swallows = [entry->delegate performSelector:@selector(ccTouchesBeganWithEvent:) withObject:event]; + if( swallows ) + break; + } + } + } +} + +- (void)touchesMovedWithEvent:(NSEvent *)event +{ + if( dispatchEvents_ ) { + tListEntry *entry, *tmp; + + DL_FOREACH_SAFE( touchDelegates_, entry, tmp ) { + if ( entry->flags & kCCImplementsTouchesMoved) { + void *swallows = [entry->delegate performSelector:@selector(ccTouchesMovedWithEvent:) withObject:event]; + if( swallows ) + break; + } + } + } +} + +- (void)touchesEndedWithEvent:(NSEvent *)event +{ + if( dispatchEvents_ ) { + tListEntry *entry, *tmp; + + DL_FOREACH_SAFE( touchDelegates_, entry, tmp ) { + if ( entry->flags & kCCImplementsTouchesEnded) { + void *swallows = [entry->delegate performSelector:@selector(ccTouchesEndedWithEvent:) withObject:event]; + if( swallows ) + break; + } + } + } +} + +- (void)touchesCancelledWithEvent:(NSEvent *)event +{ + if( dispatchEvents_ ) { + tListEntry *entry, *tmp; + + DL_FOREACH_SAFE( touchDelegates_, entry, tmp ) { + if ( entry->flags & kCCImplementsTouchesCancelled) { + void *swallows = [entry->delegate performSelector:@selector(ccTouchesCancelledWithEvent:) withObject:event]; + if( swallows ) + break; + } + } + } +} + + +#pragma mark CCEventDispatcher - queue events + +#if CC_DIRECTOR_MAC_USE_DISPLAY_LINK_THREAD +-(void) queueEvent:(NSEvent*)event selector:(SEL)selector +{ + NSAssert( eventQueueCount < QUEUE_EVENT_MAX, @"CCEventDispatcher: recompile. Increment QUEUE_EVENT_MAX value"); + + @synchronized (self) { + eventQueue[eventQueueCount].selector = selector; + eventQueue[eventQueueCount].event = [event copy]; + + eventQueueCount++; + } +} + +-(void) dispatchQueuedEvents +{ + @synchronized (self) { + for( int i=0; i < eventQueueCount; i++ ) { + SEL sel = eventQueue[i].selector; + NSEvent *event = eventQueue[i].event; + + [self performSelector:sel withObject:event]; + + [event release]; + } + + eventQueueCount = 0; + } +} +#endif // CC_DIRECTOR_MAC_USE_DISPLAY_LINK_THREAD + + +@end + +#endif // __MAC_OS_X_VERSION_MAX_ALLOWED diff --git a/tweejump/libs/cocos2d/Platforms/Mac/MacGLView.h b/tweejump/libs/cocos2d/Platforms/Mac/MacGLView.h new file mode 100755 index 0000000..8099273 --- /dev/null +++ b/tweejump/libs/cocos2d/Platforms/Mac/MacGLView.h @@ -0,0 +1,89 @@ +/* + * 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 Mac. These files should not be included on your iOS project. +// But in case they are included, it won't be compiled. +#import +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED +#elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED) + +#import + +#import "../../ccConfig.h" + +//PROTOCOLS: + +@protocol MacEventDelegate +// Mouse +- (void)mouseDown:(NSEvent *)theEvent; +- (void)mouseUp:(NSEvent *)theEvent; +- (void)mouseMoved:(NSEvent *)theEvent; +- (void)mouseDragged:(NSEvent *)theEvent; +- (void)rightMouseDown:(NSEvent*)event; +- (void)rightMouseDragged:(NSEvent*)event; +- (void)rightMouseUp:(NSEvent*)event; +- (void)otherMouseDown:(NSEvent*)event; +- (void)otherMouseDragged:(NSEvent*)event; +- (void)otherMouseUp:(NSEvent*)event; +- (void)scrollWheel:(NSEvent *)theEvent; +- (void)mouseEntered:(NSEvent *)theEvent; +- (void)mouseExited:(NSEvent *)theEvent; + + +// Keyboard +- (void)keyDown:(NSEvent *)theEvent; +- (void)keyUp:(NSEvent *)theEvent; +- (void)flagsChanged:(NSEvent *)theEvent; + +// Touches +- (void)touchesBeganWithEvent:(NSEvent *)event; +- (void)touchesMovedWithEvent:(NSEvent *)event; +- (void)touchesEndedWithEvent:(NSEvent *)event; +- (void)touchesCancelledWithEvent:(NSEvent *)event; + +#if CC_DIRECTOR_MAC_USE_DISPLAY_LINK_THREAD +- (void)queueEvent:(NSEvent*)event selector:(SEL)selector; +#endif + +@end + +/** MacGLView + + Only available for Mac OS X + */ +@interface MacGLView : NSOpenGLView { + id eventDelegate_; +} + +@property (nonatomic, readwrite, assign) id eventDelegate; + +// initializes the MacGLView with a frame rect and an OpenGL context +- (id) initWithFrame:(NSRect)frameRect shareContext:(NSOpenGLContext*)context; + +// private ++(void) load_; +@end + +#endif // __MAC_OS_X_VERSION_MAX_ALLOWED \ No newline at end of file diff --git a/tweejump/libs/cocos2d/Platforms/Mac/MacGLView.m b/tweejump/libs/cocos2d/Platforms/Mac/MacGLView.m new file mode 100755 index 0000000..a041dc8 --- /dev/null +++ b/tweejump/libs/cocos2d/Platforms/Mac/MacGLView.m @@ -0,0 +1,242 @@ +/* + * 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. + */ + +/* + * Idea of subclassing NSOpenGLView was taken from "TextureUpload" Apple's sample + */ + +// Only compile this code on Mac. These files should not be included on your iOS project. +// But in case they are included, it won't be compiled. +#import +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED +#elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED) + +#import "MacGLView.h" +#import + +#import "CCDirectorMac.h" +#import "../../ccConfig.h" + + +@implementation MacGLView + +@synthesize eventDelegate = eventDelegate_; + ++(void) load_ +{ + NSLog(@"%@ loaded", self); +} + +- (id) initWithFrame:(NSRect)frameRect +{ + self = [self initWithFrame:frameRect shareContext:nil]; + return self; +} + +- (id) initWithFrame:(NSRect)frameRect shareContext:(NSOpenGLContext*)context +{ + NSOpenGLPixelFormatAttribute attribs[] = + { + NSOpenGLPFAAccelerated, + NSOpenGLPFANoRecovery, + NSOpenGLPFADoubleBuffer, + NSOpenGLPFADepthSize, 24, + + 0 + }; + + NSOpenGLPixelFormat *pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attribs]; + + if (!pixelFormat) + NSLog(@"No OpenGL pixel format"); + + if( (self = [super initWithFrame:frameRect pixelFormat:[pixelFormat autorelease]]) ) { + + if( context ) + [self setOpenGLContext:context]; + + // Synchronize buffer swaps with vertical refresh rate + GLint swapInt = 1; + [[self openGLContext] setValues:&swapInt forParameter:NSOpenGLCPSwapInterval]; + +// GLint order = -1; +// [[self openGLContext] setValues:&order forParameter:NSOpenGLCPSurfaceOrder]; + + // event delegate + eventDelegate_ = nil; + } + + return self; +} + +- (void) reshape +{ + // We draw on a secondary thread through the display link + // When resizing the view, -reshape is called automatically on the main thread + // Add a mutex around to avoid the threads accessing the context simultaneously when resizing + CGLLockContext([[self openGLContext] CGLContextObj]); + + NSRect rect = [self bounds]; + + CCDirector *director = [CCDirector sharedDirector]; + [director reshapeProjection: NSSizeToCGSize(rect.size) ]; + + // avoid flicker + [director drawScene]; +// [self setNeedsDisplay:YES]; + + CGLUnlockContext([[self openGLContext] CGLContextObj]); +} + +- (void) dealloc +{ + + [super dealloc]; +} + +#if CC_DIRECTOR_MAC_USE_DISPLAY_LINK_THREAD +#define DISPATCH_EVENT(__event__, __selector__) [eventDelegate_ queueEvent:__event__ selector:__selector__]; +#else +#define DISPATCH_EVENT(__event__, __selector__) \ + id obj = eventDelegate_; \ + [obj performSelector:__selector__ \ + onThread:[(CCDirectorMac*)[CCDirector sharedDirector] runningThread] \ + withObject:__event__ \ + waitUntilDone:NO]; +#endif + +#pragma mark MacGLView - Mouse events +- (void)mouseDown:(NSEvent *)theEvent +{ + DISPATCH_EVENT(theEvent, _cmd); +} + +- (void)mouseMoved:(NSEvent *)theEvent +{ + DISPATCH_EVENT(theEvent, _cmd); +} + +- (void)mouseDragged:(NSEvent *)theEvent +{ + DISPATCH_EVENT(theEvent, _cmd); +} + +- (void)mouseUp:(NSEvent *)theEvent +{ + DISPATCH_EVENT(theEvent, _cmd); +} + +- (void)rightMouseDown:(NSEvent *)theEvent { + DISPATCH_EVENT(theEvent, _cmd); +} + +- (void)rightMouseDragged:(NSEvent *)theEvent { + DISPATCH_EVENT(theEvent, _cmd); +} + +- (void)rightMouseUp:(NSEvent *)theEvent { + DISPATCH_EVENT(theEvent, _cmd); +} + +- (void)otherMouseDown:(NSEvent *)theEvent { + DISPATCH_EVENT(theEvent, _cmd); +} + +- (void)otherMouseDragged:(NSEvent *)theEvent { + DISPATCH_EVENT(theEvent, _cmd); +} + +- (void)otherMouseUp:(NSEvent *)theEvent { + DISPATCH_EVENT(theEvent, _cmd); +} + +- (void)mouseEntered:(NSEvent *)theEvent { + DISPATCH_EVENT(theEvent, _cmd); +} + +- (void)mouseExited:(NSEvent *)theEvent { + DISPATCH_EVENT(theEvent, _cmd); +} + +-(void) scrollWheel:(NSEvent *)theEvent { + DISPATCH_EVENT(theEvent, _cmd); +} + +#pragma mark MacGLView - Key events + +-(BOOL) becomeFirstResponder +{ + return YES; +} + +-(BOOL) acceptsFirstResponder +{ + return YES; +} + +-(BOOL) resignFirstResponder +{ + return YES; +} + +- (void)keyDown:(NSEvent *)theEvent +{ + DISPATCH_EVENT(theEvent, _cmd); +} + +- (void)keyUp:(NSEvent *)theEvent +{ + DISPATCH_EVENT(theEvent, _cmd); +} + +- (void)flagsChanged:(NSEvent *)theEvent +{ + DISPATCH_EVENT(theEvent, _cmd); +} + +#pragma mark MacGLView - Touch events +- (void)touchesBeganWithEvent:(NSEvent *)theEvent +{ + DISPATCH_EVENT(theEvent, _cmd); +} + +- (void)touchesMovedWithEvent:(NSEvent *)theEvent +{ + DISPATCH_EVENT(theEvent, _cmd); +} + +- (void)touchesEndedWithEvent:(NSEvent *)theEvent +{ + DISPATCH_EVENT(theEvent, _cmd); +} + +- (void)touchesCancelledWithEvent:(NSEvent *)theEvent +{ + DISPATCH_EVENT(theEvent, _cmd); +} + +@end + +#endif // __MAC_OS_X_VERSION_MAX_ALLOWED diff --git a/tweejump/libs/cocos2d/Platforms/Mac/MacWindow.h b/tweejump/libs/cocos2d/Platforms/Mac/MacWindow.h new file mode 100755 index 0000000..716fe9b --- /dev/null +++ b/tweejump/libs/cocos2d/Platforms/Mac/MacWindow.h @@ -0,0 +1,42 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2010 Ricardo Quesada + * + * 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 Mac. These files should not be included on your iOS project. +// But in case they are included, it won't be compiled. +#import +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED +#elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED) + +#import + + +@interface MacWindow : NSWindow +{ +} +- (id) initWithFrame:(NSRect)frame fullscreen:(BOOL)fullscreen; + +@end + + +#endif // __MAC_OS_X_VERSION_MAX_ALLOWED \ No newline at end of file diff --git a/tweejump/libs/cocos2d/Platforms/Mac/MacWindow.m b/tweejump/libs/cocos2d/Platforms/Mac/MacWindow.m new file mode 100755 index 0000000..28736a3 --- /dev/null +++ b/tweejump/libs/cocos2d/Platforms/Mac/MacWindow.m @@ -0,0 +1,70 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2010 Ricardo Quesada + * + * 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 Mac. These files should not be included on your iOS project. +// But in case they are included, it won't be compiled. +#import +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED +#elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED) + +#import "MacWindow.h" + + +@implementation MacWindow + +- (id) initWithFrame:(NSRect)frame fullscreen:(BOOL)fullscreen +{ + int styleMask = fullscreen ? NSBackingStoreBuffered : ( NSTitledWindowMask | NSClosableWindowMask ); + self = [self initWithContentRect:frame + styleMask:styleMask + backing:NSBackingStoreBuffered + defer:YES]; + + if (self != nil) + { + if(fullscreen) + { + [self setLevel:NSMainMenuWindowLevel+1]; + [self setHidesOnDeactivate:YES]; + [self setHasShadow:NO]; + } + + [self setAcceptsMouseMovedEvents:NO]; + [self setOpaque:YES]; + } + return self; +} + +- (BOOL) canBecomeKeyWindow +{ + return YES; +} + +- (BOOL) canBecomeMainWindow +{ + return YES; +} +@end + +#endif // __MAC_OS_X_VERSION_MAX_ALLOWED diff --git a/tweejump/libs/cocos2d/Platforms/iOS/CCDirectorIOS.h b/tweejump/libs/cocos2d/Platforms/iOS/CCDirectorIOS.h new file mode 100755 index 0000000..1c264e4 --- /dev/null +++ b/tweejump/libs/cocos2d/Platforms/iOS/CCDirectorIOS.h @@ -0,0 +1,255 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-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 +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED + +#import "../../CCDirector.h" + +/** @typedef ccDeviceOrientation + Possible device orientations + */ +typedef enum { + /// Device oriented vertically, home button on the bottom + kCCDeviceOrientationPortrait = UIDeviceOrientationPortrait, + /// Device oriented vertically, home button on the top + kCCDeviceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown, + /// Device oriented horizontally, home button on the right + kCCDeviceOrientationLandscapeLeft = UIDeviceOrientationLandscapeLeft, + /// Device oriented horizontally, home button on the left + kCCDeviceOrientationLandscapeRight = UIDeviceOrientationLandscapeRight, + + // Backward compatibility stuff + CCDeviceOrientationPortrait = kCCDeviceOrientationPortrait, + CCDeviceOrientationPortraitUpsideDown = kCCDeviceOrientationPortraitUpsideDown, + CCDeviceOrientationLandscapeLeft = kCCDeviceOrientationLandscapeLeft, + CCDeviceOrientationLandscapeRight = kCCDeviceOrientationLandscapeRight, +} ccDeviceOrientation; + +/** @typedef ccDirectorType + Possible Director Types. + @since v0.8.2 + */ +typedef enum { + /** Will use a Director that triggers the main loop from an NSTimer object + * + * Features and Limitations: + * - Integrates OK with UIKit objects + * - It the slowest director + * - The invertal update is customizable from 1 to 60 + */ + kCCDirectorTypeNSTimer, + + /** will use a Director that triggers the main loop from a custom main loop. + * + * Features and Limitations: + * - Faster than NSTimer Director + * - It doesn't integrate well with UIKit objecgts + * - The interval update can't be customizable + */ + kCCDirectorTypeMainLoop, + + /** Will use a Director that triggers the main loop from a thread, but the main loop will be executed on the main thread. + * + * Features and Limitations: + * - Faster than NSTimer Director + * - It doesn't integrate well with UIKit objecgts + * - The interval update can't be customizable + */ + kCCDirectorTypeThreadMainLoop, + + /** Will use a Director that synchronizes timers with the refresh rate of the display. + * + * Features and Limitations: + * - Faster than NSTimer Director + * - Only available on 3.1+ + * - Scheduled timers & drawing are synchronizes with the refresh rate of the display + * - Integrates OK with UIKit objects + * - The interval update can be 1/60, 1/30, 1/15 + */ + kCCDirectorTypeDisplayLink, + + /** Default director is the NSTimer directory */ + kCCDirectorTypeDefault = kCCDirectorTypeNSTimer, + + // backward compatibility stuff + CCDirectorTypeNSTimer = kCCDirectorTypeNSTimer, + CCDirectorTypeMainLoop = kCCDirectorTypeMainLoop, + CCDirectorTypeThreadMainLoop = kCCDirectorTypeThreadMainLoop, + CCDirectorTypeDisplayLink = kCCDirectorTypeDisplayLink, + CCDirectorTypeDefault = kCCDirectorTypeDefault, + + +} ccDirectorType; + +/** CCDirector extensions for iPhone + */ +@interface CCDirector (iOSExtension) + +// rotates the screen if an orientation differnent than Portrait is used +-(void) applyOrientation; + +/** Sets the device orientation. + If the orientation is going to be controlled by an UIViewController, then the orientation should be Portrait + */ +-(void) setDeviceOrientation:(ccDeviceOrientation)orientation; + +/** returns the device orientation */ +-(ccDeviceOrientation) deviceOrientation; + +/** The size in pixels of the surface. It could be different than the screen size. + High-res devices might have a higher surface size than the screen size. + In non High-res device the contentScale will be emulated. + + The recommend way to enable Retina Display is by using the "enableRetinaDisplay:(BOOL)enabled" method. + + @since v0.99.4 + */ +-(void) setContentScaleFactor:(CGFloat)scaleFactor; + +/** Will enable Retina Display on devices that supports it. + It will enable Retina Display on iPhone4 and iPod Touch 4. + It will return YES, if it could enabled it, otherwise it will return NO. + + This is the recommened way to enable Retina Display. + @since v0.99.5 + */ +-(BOOL) enableRetinaDisplay:(BOOL)yes; + + +/** returns the content scale factor */ +-(CGFloat) contentScaleFactor; +@end + +@interface CCDirector (iOSExtensionClassMethods) + +/** There are 4 types of Director. + - kCCDirectorTypeNSTimer (default) + - kCCDirectorTypeMainLoop + - kCCDirectorTypeThreadMainLoop + - kCCDirectorTypeDisplayLink + + Each Director has it's own benefits, limitations. + If you are using SDK 3.1 or newer it is recommed to use the DisplayLink director + + This method should be called before any other call to the director. + + It will return NO if the director type is kCCDirectorTypeDisplayLink and the running SDK is < 3.1. Otherwise it will return YES. + + @since v0.8.2 + */ ++(BOOL) setDirectorType:(ccDirectorType) directorType; +@end + +#pragma mark - +#pragma mark CCDirectorIOS + +/** CCDirectorIOS: Base class of iOS directors + @since v0.99.5 + */ +@interface CCDirectorIOS : CCDirector +{ + /* orientation */ + ccDeviceOrientation deviceOrientation_; + + /* contentScaleFactor could be simulated */ + BOOL isContentScaleSupported_; + +} +@end + +/** FastDirector is a Director that triggers the main loop as fast as possible. + * + * Features and Limitations: + * - Faster than "normal" director + * - Consumes more battery than the "normal" director + * - It has some issues while using UIKit objects + */ +@interface CCDirectorFast : CCDirectorIOS +{ + BOOL isRunning; + + NSAutoreleasePool *autoreleasePool; +} +-(void) mainLoop; +@end + +/** ThreadedFastDirector is a Director that triggers the main loop from a thread. + * + * Features and Limitations: + * - Faster than "normal" director + * - Consumes more battery than the "normal" director + * - It can be used with UIKit objects + * + * @since v0.8.2 + */ +@interface CCDirectorFastThreaded : CCDirectorIOS +{ + BOOL isRunning; +} +-(void) mainLoop; +@end + +/** DisplayLinkDirector is a Director that synchronizes timers with the refresh rate of the display. + * + * Features and Limitations: + * - Only available on 3.1+ + * - Scheduled timers & drawing are synchronizes with the refresh rate of the display + * - Only supports animation intervals of 1/60 1/30 & 1/15 + * + * It is the recommended Director if the SDK is 3.1 or newer + * + * @since v0.8.2 + */ +@interface CCDirectorDisplayLink : CCDirectorIOS +{ + id displayLink; +} +-(void) mainLoop:(id)sender; +@end + +/** TimerDirector is a Director that calls the main loop from an NSTimer object + * + * Features and Limitations: + * - Integrates OK with UIKit objects + * - It the slowest director + * - The invertal update is customizable from 1 to 60 + * + * It is the default Director. + */ +@interface CCDirectorTimer : CCDirectorIOS +{ + NSTimer *animationTimer; +} +-(void) mainLoop; +@end + +// optimization. Should only be used to read it. Never to write it. +extern CGFloat __ccContentScaleFactor; + +#endif // __IPHONE_OS_VERSION_MAX_ALLOWED diff --git a/tweejump/libs/cocos2d/Platforms/iOS/CCDirectorIOS.m b/tweejump/libs/cocos2d/Platforms/iOS/CCDirectorIOS.m new file mode 100755 index 0000000..15ad5cb --- /dev/null +++ b/tweejump/libs/cocos2d/Platforms/iOS/CCDirectorIOS.m @@ -0,0 +1,737 @@ +/* + * 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 +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED + +#import + +// 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(); + + totalFrames_++; + + [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 diff --git a/tweejump/libs/cocos2d/Platforms/iOS/CCTouchDelegateProtocol.h b/tweejump/libs/cocos2d/Platforms/iOS/CCTouchDelegateProtocol.h new file mode 100755 index 0000000..20ba036 --- /dev/null +++ b/tweejump/libs/cocos2d/Platforms/iOS/CCTouchDelegateProtocol.h @@ -0,0 +1,75 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2009 Valentin Milea + * + * 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 +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED + +#import + +/** + CCTargetedTouchDelegate. + + Using this type of delegate results in two benefits: + 1. You don't need to deal with NSSets, the dispatcher does the job of splitting + them. You get exactly one UITouch per call. + 2. You can *claim* a UITouch by returning YES in ccTouchBegan. Updates of claimed + touches are sent only to the delegate(s) that claimed them. So if you get a move/ + ended/cancelled update you're sure it's your touch. This frees you from doing a + lot of checks when doing multi-touch. + + (The name TargetedTouchDelegate relates to updates "targeting" their specific + handler, without bothering the other handlers.) + @since v0.8 + */ +@protocol CCTargetedTouchDelegate + +/** Return YES to claim the touch. + @since v0.8 + */ +- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event; +@optional +// touch updates: +- (void)ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event; +- (void)ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event; +- (void)ccTouchCancelled:(UITouch *)touch withEvent:(UIEvent *)event; +@end + +/** + CCStandardTouchDelegate. + + This type of delegate is the same one used by CocoaTouch. You will receive all the events (Began,Moved,Ended,Cancelled). + @since v0.8 +*/ +@protocol CCStandardTouchDelegate +@optional +- (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event; +- (void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event; +- (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event; +- (void)ccTouchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event; +@end + +#endif // __IPHONE_OS_VERSION_MAX_ALLOWED diff --git a/tweejump/libs/cocos2d/Platforms/iOS/CCTouchDispatcher.h b/tweejump/libs/cocos2d/Platforms/iOS/CCTouchDispatcher.h new file mode 100755 index 0000000..9931189 --- /dev/null +++ b/tweejump/libs/cocos2d/Platforms/iOS/CCTouchDispatcher.h @@ -0,0 +1,123 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2009 Valentin Milea + * + * 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 +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED + +#import "CCTouchDelegateProtocol.h" +#import "EAGLView.h" + + +typedef enum +{ + kCCTouchSelectorBeganBit = 1 << 0, + kCCTouchSelectorMovedBit = 1 << 1, + kCCTouchSelectorEndedBit = 1 << 2, + kCCTouchSelectorCancelledBit = 1 << 3, + kCCTouchSelectorAllBits = ( kCCTouchSelectorBeganBit | kCCTouchSelectorMovedBit | kCCTouchSelectorEndedBit | kCCTouchSelectorCancelledBit), +} ccTouchSelectorFlag; + + +enum { + kCCTouchBegan, + kCCTouchMoved, + kCCTouchEnded, + kCCTouchCancelled, + + kCCTouchMax, +}; + +struct ccTouchHandlerHelperData { + SEL touchesSel; + SEL touchSel; + ccTouchSelectorFlag type; +}; + +/** CCTouchDispatcher. + Singleton that handles all the touch events. + The dispatcher dispatches events to the registered TouchHandlers. + There are 2 different type of touch handlers: + - Standard Touch Handlers + - Targeted Touch Handlers + + The Standard Touch Handlers work like the CocoaTouch touch handler: a set of touches is passed to the delegate. + On the other hand, the Targeted Touch Handlers only receive 1 touch at the time, and they can "swallow" touches (avoid the propagation of the event). + + Firstly, the dispatcher sends the received touches to the targeted touches. + These touches can be swallowed by the Targeted Touch Handlers. If there are still remaining touches, then the remaining touches will be sent + to the Standard Touch Handlers. + + @since v0.8.0 + */ +@interface CCTouchDispatcher : NSObject +{ + NSMutableArray *targetedHandlers; + NSMutableArray *standardHandlers; + + BOOL locked; + BOOL toAdd; + BOOL toRemove; + NSMutableArray *handlersToAdd; + NSMutableArray *handlersToRemove; + BOOL toQuit; + + BOOL dispatchEvents; + + // 4, 1 for each type of event + struct ccTouchHandlerHelperData handlerHelperData[kCCTouchMax]; +} + +/** singleton of the CCTouchDispatcher */ ++ (CCTouchDispatcher*)sharedDispatcher; + +/** Whether or not the events are going to be dispatched. Default: YES */ +@property (nonatomic,readwrite, assign) BOOL dispatchEvents; + +/** Adds a standard touch delegate to the dispatcher's list. + See StandardTouchDelegate description. + IMPORTANT: The delegate will be retained. + */ +-(void) addStandardDelegate:(id) delegate priority:(int)priority; +/** Adds a targeted touch delegate to the dispatcher's list. + See TargetedTouchDelegate description. + IMPORTANT: The delegate will be retained. + */ +-(void) addTargetedDelegate:(id) delegate priority:(int)priority swallowsTouches:(BOOL)swallowsTouches; +/** Removes a touch delegate. + The delegate will be released + */ +-(void) removeDelegate:(id) delegate; +/** Removes all touch delegates, releasing all the delegates */ +-(void) removeAllDelegates; +/** Changes the priority of a previously added delegate. The lower the number, + the higher the priority */ +-(void) setPriority:(int) priority forDelegate:(id) delegate; + +NSComparisonResult sortByPriority(id first, id second, void *context); +@end + +#endif // __IPHONE_OS_VERSION_MAX_ALLOWED diff --git a/tweejump/libs/cocos2d/Platforms/iOS/CCTouchDispatcher.m b/tweejump/libs/cocos2d/Platforms/iOS/CCTouchDispatcher.m new file mode 100755 index 0000000..1553b48 --- /dev/null +++ b/tweejump/libs/cocos2d/Platforms/iOS/CCTouchDispatcher.m @@ -0,0 +1,347 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2009 Valentin Milea + * + * 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 +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED + + +#import "CCTouchDispatcher.h" +#import "CCTouchHandler.h" + +@implementation CCTouchDispatcher + +@synthesize dispatchEvents; + +static CCTouchDispatcher *sharedDispatcher = nil; + ++(CCTouchDispatcher*) sharedDispatcher +{ + @synchronized(self) { + if (sharedDispatcher == nil) + sharedDispatcher = [[self alloc] init]; // assignment not done here + } + return sharedDispatcher; +} + ++(id) allocWithZone:(NSZone *)zone +{ + @synchronized(self) { + NSAssert(sharedDispatcher == nil, @"Attempted to allocate a second instance of a singleton."); + return [super allocWithZone:zone]; + } + return nil; // on subsequent allocation attempts return nil +} + +-(id) init +{ + if((self = [super init])) { + + dispatchEvents = YES; + targetedHandlers = [[NSMutableArray alloc] initWithCapacity:8]; + standardHandlers = [[NSMutableArray alloc] initWithCapacity:4]; + + handlersToAdd = [[NSMutableArray alloc] initWithCapacity:8]; + handlersToRemove = [[NSMutableArray alloc] initWithCapacity:8]; + + toRemove = NO; + toAdd = NO; + toQuit = NO; + locked = NO; + + handlerHelperData[kCCTouchBegan] = (struct ccTouchHandlerHelperData) {@selector(ccTouchesBegan:withEvent:),@selector(ccTouchBegan:withEvent:),kCCTouchSelectorBeganBit}; + handlerHelperData[kCCTouchMoved] = (struct ccTouchHandlerHelperData) {@selector(ccTouchesMoved:withEvent:),@selector(ccTouchMoved:withEvent:),kCCTouchSelectorMovedBit}; + handlerHelperData[kCCTouchEnded] = (struct ccTouchHandlerHelperData) {@selector(ccTouchesEnded:withEvent:),@selector(ccTouchEnded:withEvent:),kCCTouchSelectorEndedBit}; + handlerHelperData[kCCTouchCancelled] = (struct ccTouchHandlerHelperData) {@selector(ccTouchesCancelled:withEvent:),@selector(ccTouchCancelled:withEvent:),kCCTouchSelectorCancelledBit}; + + } + + return self; +} + +-(void) dealloc +{ + [targetedHandlers release]; + [standardHandlers release]; + [handlersToAdd release]; + [handlersToRemove release]; + [super dealloc]; +} + +// +// handlers management +// + +#pragma mark TouchDispatcher - Add Hanlder + +-(void) forceAddHandler:(CCTouchHandler*)handler array:(NSMutableArray*)array +{ + NSUInteger i = 0; + + for( CCTouchHandler *h in array ) { + if( h.priority < handler.priority ) + i++; + + NSAssert( h.delegate != handler.delegate, @"Delegate already added to touch dispatcher."); + } + [array insertObject:handler atIndex:i]; +} + +-(void) addStandardDelegate:(id) delegate priority:(int)priority +{ + CCTouchHandler *handler = [CCStandardTouchHandler handlerWithDelegate:delegate priority:priority]; + if( ! locked ) { + [self forceAddHandler:handler array:standardHandlers]; + } else { + [handlersToAdd addObject:handler]; + toAdd = YES; + } +} + +-(void) addTargetedDelegate:(id) delegate priority:(int)priority swallowsTouches:(BOOL)swallowsTouches +{ + CCTouchHandler *handler = [CCTargetedTouchHandler handlerWithDelegate:delegate priority:priority swallowsTouches:swallowsTouches]; + if( ! locked ) { + [self forceAddHandler:handler array:targetedHandlers]; + } else { + [handlersToAdd addObject:handler]; + toAdd = YES; + } +} + +#pragma mark TouchDispatcher - removeDelegate + +-(void) forceRemoveDelegate:(id)delegate +{ + // XXX: remove it from both handlers ??? + + for( CCTouchHandler *handler in targetedHandlers ) { + if( handler.delegate == delegate ) { + [targetedHandlers removeObject:handler]; + break; + } + } + + for( CCTouchHandler *handler in standardHandlers ) { + if( handler.delegate == delegate ) { + [standardHandlers removeObject:handler]; + break; + } + } +} + +-(void) removeDelegate:(id) delegate +{ + if( delegate == nil ) + return; + + if( ! locked ) { + [self forceRemoveDelegate:delegate]; + } else { + [handlersToRemove addObject:delegate]; + toRemove = YES; + } +} + +#pragma mark TouchDispatcher - removeAllDelegates + +-(void) forceRemoveAllDelegates +{ + [standardHandlers removeAllObjects]; + [targetedHandlers removeAllObjects]; +} +-(void) removeAllDelegates +{ + if( ! locked ) + [self forceRemoveAllDelegates]; + else + toQuit = YES; +} + +#pragma mark Changing priority of added handlers + +-(CCTouchHandler*) findHandler:(id)delegate +{ + for( CCTouchHandler *handler in targetedHandlers ) { + if( handler.delegate == delegate ) { + return handler; + } + } + + for( CCTouchHandler *handler in standardHandlers ) { + if( handler.delegate == delegate ) { + return handler; + } + } + return nil; +} + +NSComparisonResult sortByPriority(id first, id second, void *context) +{ + if (((CCTouchHandler*)first).priority < ((CCTouchHandler*)second).priority) + return NSOrderedAscending; + else if (((CCTouchHandler*)first).priority > ((CCTouchHandler*)second).priority) + return NSOrderedDescending; + else + return NSOrderedSame; +} + +-(void) rearrangeHandlers:(NSMutableArray*)array +{ + [array sortUsingFunction:sortByPriority context:nil]; +} + +-(void) setPriority:(int) priority forDelegate:(id) delegate +{ + NSAssert(delegate != nil, @"Got nil touch delegate!"); + + CCTouchHandler *handler = nil; + handler = [self findHandler:delegate]; + + NSAssert(handler != nil, @"Delegate not found!"); + + handler.priority = priority; + + [self rearrangeHandlers:targetedHandlers]; + [self rearrangeHandlers:standardHandlers]; +} + +// +// dispatch events +// +-(void) touches:(NSSet*)touches withEvent:(UIEvent*)event withTouchType:(unsigned int)idx +{ + NSAssert(idx < 4, @"Invalid idx value"); + + id mutableTouches; + locked = YES; + + // optimization to prevent a mutable copy when it is not necessary + unsigned int targetedHandlersCount = [targetedHandlers count]; + unsigned int standardHandlersCount = [standardHandlers count]; + BOOL needsMutableSet = (targetedHandlersCount && standardHandlersCount); + + mutableTouches = (needsMutableSet ? [touches mutableCopy] : touches); + + struct ccTouchHandlerHelperData helper = handlerHelperData[idx]; + // + // process the target handlers 1st + // + if( targetedHandlersCount > 0 ) { + for( UITouch *touch in touches ) { + for(CCTargetedTouchHandler *handler in targetedHandlers) { + + BOOL claimed = NO; + if( idx == kCCTouchBegan ) { + claimed = [handler.delegate ccTouchBegan:touch withEvent:event]; + if( claimed ) + [handler.claimedTouches addObject:touch]; + } + + // else (moved, ended, cancelled) + else if( [handler.claimedTouches containsObject:touch] ) { + claimed = YES; + if( handler.enabledSelectors & helper.type ) + [handler.delegate performSelector:helper.touchSel withObject:touch withObject:event]; + + if( helper.type & (kCCTouchSelectorCancelledBit | kCCTouchSelectorEndedBit) ) + [handler.claimedTouches removeObject:touch]; + } + + if( claimed && handler.swallowsTouches ) { + if( needsMutableSet ) + [mutableTouches removeObject:touch]; + break; + } + } + } + } + + // + // process standard handlers 2nd + // + if( standardHandlersCount > 0 && [mutableTouches count]>0 ) { + for( CCTouchHandler *handler in standardHandlers ) { + if( handler.enabledSelectors & helper.type ) + [handler.delegate performSelector:helper.touchesSel withObject:mutableTouches withObject:event]; + } + } + if( needsMutableSet ) + [mutableTouches release]; + + // + // Optimization. To prevent a [handlers copy] which is expensive + // the add/removes/quit is done after the iterations + // + locked = NO; + if( toRemove ) { + toRemove = NO; + for( id delegate in handlersToRemove ) + [self forceRemoveDelegate:delegate]; + [handlersToRemove removeAllObjects]; + } + if( toAdd ) { + toAdd = NO; + for( CCTouchHandler *handler in handlersToAdd ) { + Class targetedClass = [CCTargetedTouchHandler class]; + if( [handler isKindOfClass:targetedClass] ) + [self forceAddHandler:handler array:targetedHandlers]; + else + [self forceAddHandler:handler array:standardHandlers]; + } + [handlersToAdd removeAllObjects]; + } + if( toQuit ) { + toQuit = NO; + [self forceRemoveAllDelegates]; + } +} + +- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event +{ + if( dispatchEvents ) + [self touches:touches withEvent:event withTouchType:kCCTouchBegan]; +} +- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event +{ + if( dispatchEvents ) + [self touches:touches withEvent:event withTouchType:kCCTouchMoved]; +} + +- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event +{ + if( dispatchEvents ) + [self touches:touches withEvent:event withTouchType:kCCTouchEnded]; +} + +- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event +{ + if( dispatchEvents ) + [self touches:touches withEvent:event withTouchType:kCCTouchCancelled]; +} +@end + +#endif // __IPHONE_OS_VERSION_MAX_ALLOWED diff --git a/tweejump/libs/cocos2d/Platforms/iOS/CCTouchHandler.h b/tweejump/libs/cocos2d/Platforms/iOS/CCTouchHandler.h new file mode 100755 index 0000000..31a3e36 --- /dev/null +++ b/tweejump/libs/cocos2d/Platforms/iOS/CCTouchHandler.h @@ -0,0 +1,93 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2009 Valentin Milea + * + * 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 +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED + +/* + * This file contains the delegates of the touches + * There are 2 possible delegates: + * - CCStandardTouchHandler: propagates all the events at once + * - CCTargetedTouchHandler: propagates 1 event at the time + */ + +#import "CCTouchDelegateProtocol.h" +#import "CCTouchDispatcher.h" + +/** + CCTouchHandler + Object than contains the delegate and priority of the event handler. +*/ +@interface CCTouchHandler : NSObject { + id delegate; + int priority; + ccTouchSelectorFlag enabledSelectors_; +} + +/** delegate */ +@property(nonatomic, readwrite, retain) id delegate; +/** priority */ +@property(nonatomic, readwrite) int priority; // default 0 +/** enabled selectors */ +@property(nonatomic,readwrite) ccTouchSelectorFlag enabledSelectors; + +/** allocates a TouchHandler with a delegate and a priority */ ++ (id)handlerWithDelegate:(id)aDelegate priority:(int)priority; +/** initializes a TouchHandler with a delegate and a priority */ +- (id)initWithDelegate:(id)aDelegate priority:(int)priority; +@end + +/** CCStandardTouchHandler + It forwardes each event to the delegate. + */ +@interface CCStandardTouchHandler : CCTouchHandler +{ +} +@end + +/** + CCTargetedTouchHandler + Object than contains the claimed touches and if it swallos touches. + Used internally by TouchDispatcher + */ +@interface CCTargetedTouchHandler : CCTouchHandler { + BOOL swallowsTouches; + NSMutableSet *claimedTouches; +} +/** whether or not the touches are swallowed */ +@property(nonatomic, readwrite) BOOL swallowsTouches; // default NO +/** MutableSet that contains the claimed touches */ +@property(nonatomic, readonly) NSMutableSet *claimedTouches; + +/** allocates a TargetedTouchHandler with a delegate, a priority and whether or not it swallows touches or not */ ++ (id)handlerWithDelegate:(id) aDelegate priority:(int)priority swallowsTouches:(BOOL)swallowsTouches; +/** initializes a TargetedTouchHandler with a delegate, a priority and whether or not it swallows touches or not */ +- (id)initWithDelegate:(id) aDelegate priority:(int)priority swallowsTouches:(BOOL)swallowsTouches; + +@end + +#endif // __IPHONE_OS_VERSION_MAX_ALLOWED diff --git a/tweejump/libs/cocos2d/Platforms/iOS/CCTouchHandler.m b/tweejump/libs/cocos2d/Platforms/iOS/CCTouchHandler.m new file mode 100755 index 0000000..a52103b --- /dev/null +++ b/tweejump/libs/cocos2d/Platforms/iOS/CCTouchHandler.m @@ -0,0 +1,135 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2009 Valentin Milea + * + * 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 +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED + +/* + * This file contains the delegates of the touches + * There are 2 possible delegates: + * - CCStandardTouchHandler: propagates all the events at once + * - CCTargetedTouchHandler: propagates 1 event at the time + */ + +#import "CCTouchHandler.h" +#import "../../ccMacros.h" + +#pragma mark - +#pragma mark TouchHandler +@implementation CCTouchHandler + +@synthesize delegate, priority; +@synthesize enabledSelectors=enabledSelectors_; + ++ (id)handlerWithDelegate:(id) aDelegate priority:(int)aPriority +{ + return [[[self alloc] initWithDelegate:aDelegate priority:aPriority] autorelease]; +} + +- (id)initWithDelegate:(id) aDelegate priority:(int)aPriority +{ + NSAssert(aDelegate != nil, @"Touch delegate may not be nil"); + + if ((self = [super init])) { + self.delegate = aDelegate; + priority = aPriority; + enabledSelectors_ = 0; + } + + return self; +} + +- (void)dealloc { + CCLOGINFO(@"cocos2d: deallocing %@", self); + [delegate release]; + [super dealloc]; +} +@end + +#pragma mark - +#pragma mark StandardTouchHandler +@implementation CCStandardTouchHandler +-(id) initWithDelegate:(id)del priority:(int)pri +{ + if( (self=[super initWithDelegate:del priority:pri]) ) { + if( [del respondsToSelector:@selector(ccTouchesBegan:withEvent:)] ) + enabledSelectors_ |= kCCTouchSelectorBeganBit; + if( [del respondsToSelector:@selector(ccTouchesMoved:withEvent:)] ) + enabledSelectors_ |= kCCTouchSelectorMovedBit; + if( [del respondsToSelector:@selector(ccTouchesEnded:withEvent:)] ) + enabledSelectors_ |= kCCTouchSelectorEndedBit; + if( [del respondsToSelector:@selector(ccTouchesCancelled:withEvent:)] ) + enabledSelectors_ |= kCCTouchSelectorCancelledBit; + } + return self; +} +@end + +#pragma mark - +#pragma mark TargetedTouchHandler + +@interface CCTargetedTouchHandler (private) +-(void) updateKnownTouches:(NSMutableSet *)touches withEvent:(UIEvent *)event selector:(SEL)selector unclaim:(BOOL)doUnclaim; +@end + +@implementation CCTargetedTouchHandler + +@synthesize swallowsTouches, claimedTouches; + ++ (id)handlerWithDelegate:(id)aDelegate priority:(int)priority swallowsTouches:(BOOL)swallow +{ + return [[[self alloc] initWithDelegate:aDelegate priority:priority swallowsTouches:swallow] autorelease]; +} + +- (id)initWithDelegate:(id)aDelegate priority:(int)aPriority swallowsTouches:(BOOL)swallow +{ + if ((self = [super initWithDelegate:aDelegate priority:aPriority])) { + claimedTouches = [[NSMutableSet alloc] initWithCapacity:2]; + swallowsTouches = swallow; + + if( [aDelegate respondsToSelector:@selector(ccTouchBegan:withEvent:)] ) + enabledSelectors_ |= kCCTouchSelectorBeganBit; + if( [aDelegate respondsToSelector:@selector(ccTouchMoved:withEvent:)] ) + enabledSelectors_ |= kCCTouchSelectorMovedBit; + if( [aDelegate respondsToSelector:@selector(ccTouchEnded:withEvent:)] ) + enabledSelectors_ |= kCCTouchSelectorEndedBit; + if( [aDelegate respondsToSelector:@selector(ccTouchCancelled:withEvent:)] ) + enabledSelectors_ |= kCCTouchSelectorCancelledBit; + } + + return self; +} + +- (void)dealloc { + [claimedTouches release]; + [super dealloc]; +} +@end + + +#endif // __IPHONE_OS_VERSION_MAX_ALLOWED \ No newline at end of file diff --git a/Support/cocos2d/Support/EAGLView.h b/tweejump/libs/cocos2d/Platforms/iOS/EAGLView.h similarity index 62% rename from Support/cocos2d/Support/EAGLView.h rename to tweejump/libs/cocos2d/Platforms/iOS/EAGLView.h index b168301..3b6c2f3 100755 --- a/Support/cocos2d/Support/EAGLView.h +++ b/tweejump/libs/cocos2d/Platforms/iOS/EAGLView.h @@ -61,22 +61,26 @@ Copyright (C) 2008 Apple Inc. All Rights Reserved. */ +// 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 +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED + #import #import #import #import #import +#import "ESRenderer.h" + //CLASSES: @class EAGLView; +@class EAGLSharegroup; //PROTOCOLS: -@protocol EAGLViewDelegate -- (void) didResizeEAGLSurfaceForView:(EAGLView*)view; //Called whenever the EAGL surface has been resized -@end - @protocol EAGLTouchDelegate - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event; - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event; @@ -86,49 +90,66 @@ Copyright (C) 2008 Apple Inc. All Rights Reserved. //CLASS INTERFACE: -/** EAGLView Class +/** EAGLView Class. * This class wraps the CAEAGLLayer from CoreAnimation into a convenient UIView subclass. * The view content is basically an EAGL surface you render your OpenGL scene into. * Note that setting the view non-opaque will only work if the EAGL surface has an alpha channel. */ @interface EAGLView : UIView { -@private - NSString* _format; - GLuint _depthFormat; - BOOL _autoresize; - EAGLContext *_context; - GLuint _framebuffer; - GLuint _renderbuffer; - GLuint _depthBuffer; - CGSize _size; - BOOL _hasBeenCurrent; - id _delegate; - id touchDelegate; + id renderer_; + EAGLContext *context_; // weak ref + + NSString *pixelformat_; + GLuint depthFormat_; + BOOL preserveBackbuffer_; + + CGSize size_; + BOOL discardFramebufferSupported_; + id touchDelegate_; + + //fsaa addition + BOOL multisampling_; + unsigned int requestedSamples_; } + +/** creates an initializes an EAGLView with a frame and 0-bit depth buffer, and a RGB565 color buffer. */ ++ (id) viewWithFrame:(CGRect)frame; +/** creates an initializes an EAGLView with a frame, a color buffer format, and 0-bit depth buffer. */ ++ (id) viewWithFrame:(CGRect)frame pixelFormat:(NSString*)format; +/** creates an initializes an EAGLView with a frame, a color buffer format, and a depth buffer. */ ++ (id) viewWithFrame:(CGRect)frame pixelFormat:(NSString*)format depthFormat:(GLuint)depth; +/** creates an initializes an EAGLView with a frame, a color buffer format, a depth buffer format, a sharegroup, and multisamping */ ++ (id) viewWithFrame:(CGRect)frame pixelFormat:(NSString*)format depthFormat:(GLuint)depth preserveBackbuffer:(BOOL)retained sharegroup:(EAGLSharegroup*)sharegroup multiSampling:(BOOL)multisampling numberOfSamples:(unsigned int)samples; + +/** Initializes an EAGLView with a frame and 0-bit depth buffer, and a RGB565 color buffer */ - (id) initWithFrame:(CGRect)frame; //These also set the current context +/** Initializes an EAGLView with a frame, a color buffer format, and 0-bit depth buffer */ - (id) initWithFrame:(CGRect)frame pixelFormat:(NSString*)format; -- (id) initWithFrame:(CGRect)frame pixelFormat:(NSString*)format depthFormat:(GLuint)depth preserveBackbuffer:(BOOL)retained; +/** Initializes an EAGLView with a frame, a color buffer format, a depth buffer format, a sharegroup and multisampling support */ +- (id) initWithFrame:(CGRect)frame pixelFormat:(NSString*)format depthFormat:(GLuint)depth preserveBackbuffer:(BOOL)retained sharegroup:(EAGLSharegroup*)sharegroup multiSampling:(BOOL)sampling numberOfSamples:(unsigned int)nSamples; -@property(readonly) GLuint framebuffer; -@property(readonly) NSString* pixelFormat; -@property(readonly) GLuint depthFormat; -@property(readonly) EAGLContext *context; +/** pixel format: it could be RGBA8 (32-bit) or RGB565 (16-bit) */ +@property(nonatomic,readonly) NSString* pixelFormat; +/** depth format of the render buffer: 0, 16 or 24 bits*/ +@property(nonatomic,readonly) GLuint depthFormat; -@property BOOL autoresizesSurface; //NO by default - Set to YES to have the EAGL surface automatically resized when the view bounds change, otherwise the EAGL surface contents is rendered scaled -@property(readonly, nonatomic) CGSize surfaceSize; +/** returns surface size in pixels */ +@property(nonatomic,readonly) CGSize surfaceSize; -@property(assign) id delegate; -@property(assign) id touchDelegate; +/** OpenGL context */ +@property(nonatomic,readonly) EAGLContext *context; -- (void) setAutoresizesEAGLSurface:(BOOL)autoresizesEAGLSurface; +@property(nonatomic,readwrite) BOOL multiSampling; -- (void) setCurrentContext; -- (BOOL) isCurrentContext; -- (void) clearCurrentContext; +/** touch delegate */ +@property(nonatomic,readwrite,assign) id touchDelegate; -- (void) swapBuffers; //This also checks the current OpenGL error and logs an error if needed +/** EAGLView uses double-buffer. This method swaps the buffers */ +-(void) swapBuffers; - (CGPoint) convertPointFromViewToSurface:(CGPoint)point; - (CGRect) convertRectFromViewToSurface:(CGRect)rect; @end + +#endif // __IPHONE_OS_VERSION_MAX_ALLOWED diff --git a/tweejump/libs/cocos2d/Platforms/iOS/EAGLView.m b/tweejump/libs/cocos2d/Platforms/iOS/EAGLView.m new file mode 100755 index 0000000..d5ead65 --- /dev/null +++ b/tweejump/libs/cocos2d/Platforms/iOS/EAGLView.m @@ -0,0 +1,343 @@ +/* + +===== IMPORTANT ===== + +This is sample code demonstrating API, technology or techniques in development. +Although this sample code has been reviewed for technical accuracy, it is not +final. Apple is supplying this information to help you plan for the adoption of +the technologies and programming interfaces described herein. This information +is subject to change, and software implemented based on this sample code should +be tested with final operating system software and final documentation. Newer +versions of this sample code may be provided with future seeds of the API or +technology. For information about updates to this and other developer +documentation, view the New & Updated sidebars in subsequent documentation +seeds. + +===================== + +File: EAGLView.m +Abstract: Convenience class that wraps the CAEAGLLayer from CoreAnimation into a +UIView subclass. + +Version: 1.3 + +Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc. +("Apple") in consideration of your agreement to the following terms, and your +use, installation, modification or redistribution of this Apple software +constitutes acceptance of these terms. If you do not agree with these terms, +please do not use, install, modify or redistribute this Apple software. + +In consideration of your agreement to abide by the following terms, and subject +to these terms, Apple grants you a personal, non-exclusive license, under +Apple's copyrights in this original Apple software (the "Apple Software"), to +use, reproduce, modify and redistribute the Apple Software, with or without +modifications, in source and/or binary forms; provided that if you redistribute +the Apple Software in its entirety and without modifications, you must retain +this notice and the following text and disclaimers in all such redistributions +of the Apple Software. +Neither the name, trademarks, service marks or logos of Apple Inc. may be used +to endorse or promote products derived from the Apple Software without specific +prior written permission from Apple. Except as expressly stated in this notice, +no other rights or licenses, express or implied, are granted by Apple herein, +including but not limited to any patent rights that may be infringed by your +derivative works or by other works in which the Apple Software may be +incorporated. + +The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO +WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED +WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN +COMBINATION WITH YOUR PRODUCTS. + +IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE +GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR +DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF +CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF +APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +Copyright (C) 2008 Apple Inc. All Rights Reserved. + +*/ + +// 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 +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED + +#import + +#import "EAGLView.h" +#import "ES1Renderer.h" +#import "../../CCDirector.h" +#import "../../ccMacros.h" +#import "../../CCConfiguration.h" +#import "../../Support/OpenGL_Internal.h" + + +//CLASS IMPLEMENTATIONS: + +@interface EAGLView (Private) +- (BOOL) setupSurfaceWithSharegroup:(EAGLSharegroup*)sharegroup; +- (unsigned int) convertPixelFormat:(NSString*) pixelFormat; +@end + +@implementation EAGLView + +@synthesize surfaceSize=size_; +@synthesize pixelFormat=pixelformat_, depthFormat=depthFormat_; +@synthesize touchDelegate=touchDelegate_; +@synthesize context=context_; +@synthesize multiSampling=multiSampling_; + ++ (Class) layerClass +{ + return [CAEAGLLayer class]; +} + ++ (id) viewWithFrame:(CGRect)frame +{ + return [[[self alloc] initWithFrame:frame] autorelease]; +} + ++ (id) viewWithFrame:(CGRect)frame pixelFormat:(NSString*)format +{ + return [[[self alloc] initWithFrame:frame pixelFormat:format] autorelease]; +} + ++ (id) viewWithFrame:(CGRect)frame pixelFormat:(NSString*)format depthFormat:(GLuint)depth +{ + return [[[self alloc] initWithFrame:frame pixelFormat:format depthFormat:depth preserveBackbuffer:NO sharegroup:nil multiSampling:NO numberOfSamples:0] autorelease]; +} + ++ (id) viewWithFrame:(CGRect)frame pixelFormat:(NSString*)format depthFormat:(GLuint)depth preserveBackbuffer:(BOOL)retained sharegroup:(EAGLSharegroup*)sharegroup multiSampling:(BOOL)multisampling numberOfSamples:(unsigned int)samples +{ + return [[[self alloc] initWithFrame:frame pixelFormat:format depthFormat:depth preserveBackbuffer:retained sharegroup:sharegroup multiSampling:multisampling numberOfSamples:samples] autorelease]; +} + +- (id) initWithFrame:(CGRect)frame +{ + return [self initWithFrame:frame pixelFormat:kEAGLColorFormatRGB565 depthFormat:0 preserveBackbuffer:NO sharegroup:nil multiSampling:NO numberOfSamples:0]; +} + +- (id) initWithFrame:(CGRect)frame pixelFormat:(NSString*)format +{ + return [self initWithFrame:frame pixelFormat:format depthFormat:0 preserveBackbuffer:NO sharegroup:nil multiSampling:NO numberOfSamples:0]; +} + +- (id) initWithFrame:(CGRect)frame pixelFormat:(NSString*)format depthFormat:(GLuint)depth preserveBackbuffer:(BOOL)retained sharegroup:(EAGLSharegroup*)sharegroup multiSampling:(BOOL)sampling numberOfSamples:(unsigned int)nSamples +{ + if((self = [super initWithFrame:frame])) + { + pixelformat_ = format; + depthFormat_ = depth; + multiSampling_ = sampling; + requestedSamples_ = nSamples; + preserveBackbuffer_ = retained; + + if( ! [self setupSurfaceWithSharegroup:sharegroup] ) { + [self release]; + return nil; + } + } + + return self; +} + +-(id) initWithCoder:(NSCoder *)aDecoder +{ + if( (self = [super initWithCoder:aDecoder]) ) { + + CAEAGLLayer* eaglLayer = (CAEAGLLayer*)[self layer]; + + pixelformat_ = kEAGLColorFormatRGB565; + depthFormat_ = 0; // GL_DEPTH_COMPONENT24_OES; + multiSampling_= NO; + requestedSamples_ = 0; + size_ = [eaglLayer bounds].size; + + if( ! [self setupSurfaceWithSharegroup:nil] ) { + [self release]; + return nil; + } + } + + return self; +} + +-(BOOL) setupSurfaceWithSharegroup:(EAGLSharegroup*)sharegroup +{ + CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer; + + eaglLayer.opaque = YES; + eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys: + [NSNumber numberWithBool:preserveBackbuffer_], kEAGLDrawablePropertyRetainedBacking, + pixelformat_, kEAGLDrawablePropertyColorFormat, nil]; + + + renderer_ = [[ES1Renderer alloc] initWithDepthFormat:depthFormat_ + withPixelFormat:[self convertPixelFormat:pixelformat_] + withSharegroup:sharegroup + withMultiSampling:multiSampling_ + withNumberOfSamples:requestedSamples_]; + if (!renderer_) + return NO; + + context_ = [renderer_ context]; + [context_ renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:eaglLayer]; + + discardFramebufferSupported_ = [[CCConfiguration sharedConfiguration] supportsDiscardFramebuffer]; + + return YES; +} + +- (void) dealloc +{ + CCLOGINFO(@"cocos2d: deallocing %@", self); + + + [renderer_ release]; + [super dealloc]; +} + +- (void) layoutSubviews +{ + size_ = [renderer_ backingSize]; + + [renderer_ resizeFromLayer:(CAEAGLLayer*)self.layer]; + + // Issue #914 #924 + CCDirector *director = [CCDirector sharedDirector]; + [director reshapeProjection:size_]; + + // Avoid flicker. Issue #350 + [director performSelectorOnMainThread:@selector(drawScene) withObject:nil waitUntilDone:YES]; +} + +- (void) swapBuffers +{ + // IMPORTANT: + // - preconditions + // -> context_ MUST be the OpenGL context + // -> renderbuffer_ must be the the RENDER BUFFER + +#ifdef __IPHONE_4_0 + + if (multiSampling_) + { + /* Resolve from msaaFramebuffer to resolveFramebuffer */ + //glDisable(GL_SCISSOR_TEST); + glBindFramebufferOES(GL_READ_FRAMEBUFFER_APPLE, [renderer_ msaaFrameBuffer]); + glBindFramebufferOES(GL_DRAW_FRAMEBUFFER_APPLE, [renderer_ defaultFrameBuffer]); + glResolveMultisampleFramebufferAPPLE(); + } + + if( discardFramebufferSupported_) + { + if (multiSampling_) + { + if (depthFormat_) + { + GLenum attachments[] = {GL_COLOR_ATTACHMENT0_OES, GL_DEPTH_ATTACHMENT_OES}; + glDiscardFramebufferEXT(GL_READ_FRAMEBUFFER_APPLE, 2, attachments); + } + else + { + GLenum attachments[] = {GL_COLOR_ATTACHMENT0_OES}; + glDiscardFramebufferEXT(GL_READ_FRAMEBUFFER_APPLE, 1, attachments); + } + + glBindRenderbufferOES(GL_RENDERBUFFER_OES, [renderer_ colorRenderBuffer]); + + } + + // not MSAA + else if (depthFormat_ ) { + GLenum attachments[] = { GL_DEPTH_ATTACHMENT_OES}; + glDiscardFramebufferEXT(GL_FRAMEBUFFER_OES, 1, attachments); + } + } + +#endif // __IPHONE_4_0 + + if(![context_ presentRenderbuffer:GL_RENDERBUFFER_OES]) + CCLOG(@"cocos2d: Failed to swap renderbuffer in %s\n", __FUNCTION__); + +#if COCOS2D_DEBUG + CHECK_GL_ERROR(); +#endif + + // We can safely re-bind the framebuffer here, since this will be the + // 1st instruction of the new main loop + if( multiSampling_ ) + glBindFramebufferOES(GL_FRAMEBUFFER_OES, [renderer_ msaaFrameBuffer]); +} + +- (unsigned int) convertPixelFormat:(NSString*) pixelFormat +{ + // define the pixel format + GLenum pFormat; + + + if([pixelFormat isEqualToString:@"EAGLColorFormat565"]) + pFormat = GL_RGB565_OES; + else + pFormat = GL_RGBA8_OES; + + return pFormat; +} + +#pragma mark EAGLView - Point conversion + +- (CGPoint) convertPointFromViewToSurface:(CGPoint)point +{ + CGRect bounds = [self bounds]; + + return CGPointMake((point.x - bounds.origin.x) / bounds.size.width * size_.width, (point.y - bounds.origin.y) / bounds.size.height * size_.height); +} + +- (CGRect) convertRectFromViewToSurface:(CGRect)rect +{ + CGRect bounds = [self bounds]; + + return CGRectMake((rect.origin.x - bounds.origin.x) / bounds.size.width * size_.width, (rect.origin.y - bounds.origin.y) / bounds.size.height * size_.height, rect.size.width / bounds.size.width * size_.width, rect.size.height / bounds.size.height * size_.height); +} + +// Pass the touches to the superview +#pragma mark EAGLView - Touch Delegate + +- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event +{ + if(touchDelegate_) + { + [touchDelegate_ touchesBegan:touches withEvent:event]; + } +} + +- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event +{ + if(touchDelegate_) + { + [touchDelegate_ touchesMoved:touches withEvent:event]; + } +} + +- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event +{ + if(touchDelegate_) + { + [touchDelegate_ touchesEnded:touches withEvent:event]; + } +} +- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event +{ + if(touchDelegate_) + { + [touchDelegate_ touchesCancelled:touches withEvent:event]; + } +} + +@end + +#endif // __IPHONE_OS_VERSION_MAX_ALLOWED \ No newline at end of file diff --git a/tweejump/libs/cocos2d/Platforms/iOS/ES1Renderer.h b/tweejump/libs/cocos2d/Platforms/iOS/ES1Renderer.h new file mode 100755 index 0000000..fd946a7 --- /dev/null +++ b/tweejump/libs/cocos2d/Platforms/iOS/ES1Renderer.h @@ -0,0 +1,72 @@ +/* + * 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. + * + * + * File autogenerated with Xcode. Adapted for cocos2d needs. + */ + +// 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 +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED + + +#import "ESRenderer.h" + +#import +#import + +@interface ES1Renderer : NSObject +{ + // The pixel dimensions of the CAEAGLLayer + GLint backingWidth_; + GLint backingHeight_; + + unsigned int samplesToUse_; + BOOL multiSampling_; + + unsigned int depthFormat_; + unsigned int pixelFormat_; + + // The OpenGL ES names for the framebuffer and renderbuffer used to render to this view + GLuint defaultFramebuffer_; + GLuint colorRenderbuffer_; + GLuint depthBuffer_; + + + //buffers for MSAA + GLuint msaaFramebuffer_; + GLuint msaaColorbuffer_; + + EAGLContext *context_; +} + +/** EAGLContext */ +@property (nonatomic,readonly) EAGLContext* context; + +- (BOOL)resizeFromLayer:(CAEAGLLayer *)layer; + +@end + +#endif // __IPHONE_OS_VERSION_MAX_ALLOWED diff --git a/tweejump/libs/cocos2d/Platforms/iOS/ES1Renderer.m b/tweejump/libs/cocos2d/Platforms/iOS/ES1Renderer.m new file mode 100755 index 0000000..398d946 --- /dev/null +++ b/tweejump/libs/cocos2d/Platforms/iOS/ES1Renderer.m @@ -0,0 +1,259 @@ +/* + * 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. + * + * + * File autogenerated with Xcode. Adapted for cocos2d needs. + */ + +// 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 +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED + +#import "ES1Renderer.h" +#import "../../Support/OpenGL_Internal.h" +#import "../../ccMacros.h" + + +@interface ES1Renderer (private) + +- (GLenum) convertPixelFormat:(int) pixelFormat; + +@end + + +@implementation ES1Renderer + +@synthesize context=context_; + +- (id) initWithDepthFormat:(unsigned int)depthFormat withPixelFormat:(unsigned int)pixelFormat withSharegroup:(EAGLSharegroup*)sharegroup withMultiSampling:(BOOL) multiSampling withNumberOfSamples:(unsigned int) requestedSamples +{ + if ((self = [super init])) + { + if ( sharegroup == nil ) + { + context_ = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1]; + } + else + { + context_ = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1 sharegroup:sharegroup]; + } + + if (!context_ || ![EAGLContext setCurrentContext:context_]) + { + [self release]; + return nil; + } + + // Create default framebuffer object. The backing will be allocated for the current layer in -resizeFromLayer + glGenFramebuffersOES(1, &defaultFramebuffer_); + NSAssert( defaultFramebuffer_, @"Can't create default frame buffer"); + glGenRenderbuffersOES(1, &colorRenderbuffer_); + NSAssert( colorRenderbuffer_, @"Can't create default render buffer"); + + glBindFramebufferOES(GL_FRAMEBUFFER_OES, defaultFramebuffer_); + glBindRenderbufferOES(GL_RENDERBUFFER_OES, colorRenderbuffer_); + glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, colorRenderbuffer_); + + depthFormat_ = depthFormat; + + if( depthFormat_ ) { +// glGenRenderbuffersOES(1, &depthBuffer_); +// glBindRenderbufferOES(GL_RENDERBUFFER_OES, depthBuffer_); +// glRenderbufferStorageOES(GL_RENDERBUFFER_OES, depthFormat_, 100, 100); +// glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthBuffer_); + + // default buffer +// glBindRenderbufferOES(GL_RENDERBUFFER_OES, colorRenderbuffer_); + } + + pixelFormat_ = pixelFormat; + multiSampling_ = multiSampling; + if (multiSampling_) + { + GLint maxSamplesAllowed; + glGetIntegerv(GL_MAX_SAMPLES_APPLE, &maxSamplesAllowed); + samplesToUse_ = MIN(maxSamplesAllowed,requestedSamples); + + /* Create the MSAA framebuffer (offscreen) */ + glGenFramebuffersOES(1, &msaaFramebuffer_); + glBindFramebufferOES(GL_FRAMEBUFFER_OES, msaaFramebuffer_); + + } + + CHECK_GL_ERROR(); + } + + return self; +} + +- (BOOL)resizeFromLayer:(CAEAGLLayer *)layer +{ + // Allocate color buffer backing based on the current layer size + + glBindRenderbufferOES(GL_RENDERBUFFER_OES, colorRenderbuffer_); + + if (![context_ renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:layer]) + { + CCLOG(@"failed to call context"); + } + + glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &backingWidth_); + glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &backingHeight_); + + CCLOG(@"cocos2d: surface size: %dx%d", (int)backingWidth_, (int)backingHeight_); + + if (multiSampling_) + { + + if ( msaaColorbuffer_) { + glDeleteRenderbuffersOES(1, &msaaColorbuffer_); + msaaColorbuffer_ = 0; + } + + /* Create the offscreen MSAA color buffer. + After rendering, the contents of this will be blitted into ColorRenderbuffer */ + + //msaaFrameBuffer needs to be binded + glBindFramebufferOES(GL_FRAMEBUFFER_OES, msaaFramebuffer_); + glGenRenderbuffersOES(1, &msaaColorbuffer_); + glBindRenderbufferOES(GL_RENDERBUFFER_OES, msaaColorbuffer_); + glRenderbufferStorageMultisampleAPPLE(GL_RENDERBUFFER_OES, samplesToUse_,pixelFormat_ , backingWidth_, backingHeight_); + glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, msaaColorbuffer_); + + if (glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES) != GL_FRAMEBUFFER_COMPLETE_OES) + { + CCLOG(@"Failed to make complete framebuffer object %x", glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES)); + return NO; + } + } + + if (depthFormat_) + { + if( ! depthBuffer_ ) + glGenRenderbuffersOES(1, &depthBuffer_); + + glBindRenderbufferOES(GL_RENDERBUFFER_OES, depthBuffer_); + if( multiSampling_ ) + glRenderbufferStorageMultisampleAPPLE(GL_RENDERBUFFER_OES, samplesToUse_, depthFormat_,backingWidth_, backingHeight_); + else + glRenderbufferStorageOES(GL_RENDERBUFFER_OES, depthFormat_, backingWidth_, backingHeight_); + glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthBuffer_); + + // bind color buffer + glBindRenderbufferOES(GL_RENDERBUFFER_OES, colorRenderbuffer_); + } + + glBindFramebufferOES(GL_FRAMEBUFFER_OES, defaultFramebuffer_); + + if (glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES) != GL_FRAMEBUFFER_COMPLETE_OES) + { + CCLOG(@"Failed to make complete framebuffer object %x", glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES)); + return NO; + } + + CHECK_GL_ERROR(); + + return YES; +} + +-(CGSize) backingSize +{ + return CGSizeMake( backingWidth_, backingHeight_); +} + +- (NSString*) description +{ + return [NSString stringWithFormat:@"<%@ = %08X | size = %ix%i>", [self class], self, backingWidth_, backingHeight_]; +} + + +- (void)dealloc +{ + CCLOGINFO(@"cocos2d: deallocing %@", self); + + // Tear down GL + if(defaultFramebuffer_) + { + glDeleteFramebuffersOES(1, &defaultFramebuffer_); + defaultFramebuffer_ = 0; + } + + if(colorRenderbuffer_) + { + glDeleteRenderbuffersOES(1, &colorRenderbuffer_); + colorRenderbuffer_ = 0; + } + + if( depthBuffer_ ) + { + glDeleteRenderbuffersOES(1, &depthBuffer_); + depthBuffer_ = 0; + } + + if ( msaaColorbuffer_) + { + glDeleteRenderbuffersOES(1, &msaaColorbuffer_); + msaaColorbuffer_ = 0; + } + + if ( msaaFramebuffer_) + { + glDeleteRenderbuffersOES(1, &msaaFramebuffer_); + msaaFramebuffer_ = 0; + } + + // Tear down context + if ([EAGLContext currentContext] == context_) + [EAGLContext setCurrentContext:nil]; + + [context_ release]; + context_ = nil; + + [super dealloc]; +} + +- (unsigned int) colorRenderBuffer +{ + return colorRenderbuffer_; +} + +- (unsigned int) defaultFrameBuffer +{ + return defaultFramebuffer_; +} + +- (unsigned int) msaaFrameBuffer +{ + return msaaFramebuffer_; +} + +- (unsigned int) msaaColorBuffer +{ + return msaaColorbuffer_; +} + +@end + +#endif // __IPHONE_OS_VERSION_MAX_ALLOWED diff --git a/tweejump/libs/cocos2d/Platforms/iOS/ESRenderer.h b/tweejump/libs/cocos2d/Platforms/iOS/ESRenderer.h new file mode 100755 index 0000000..e612eee --- /dev/null +++ b/tweejump/libs/cocos2d/Platforms/iOS/ESRenderer.h @@ -0,0 +1,54 @@ +/* + * 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. + * + * + * File autogenerated with Xcode. Adapted for cocos2d needs. + */ + +// 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 +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED + +#import + +#import +#import + +@protocol ESRenderer + +- (id) initWithDepthFormat:(unsigned int)depthFormat withPixelFormat:(unsigned int)pixelFormat withSharegroup:(EAGLSharegroup*)sharegroup withMultiSampling:(BOOL) multiSampling withNumberOfSamples:(unsigned int) requestedSamples; + +- (BOOL) resizeFromLayer:(CAEAGLLayer *)layer; + +- (EAGLContext*) context; +- (CGSize) backingSize; + +- (unsigned int) colorRenderBuffer; +- (unsigned int) defaultFrameBuffer; +- (unsigned int) msaaFrameBuffer; +- (unsigned int) msaaColorBuffer; +@end + +#endif // __IPHONE_OS_VERSION_MAX_ALLOWED diff --git a/Support/cocos2d/Support/glu.c b/tweejump/libs/cocos2d/Platforms/iOS/glu.c similarity index 87% rename from Support/cocos2d/Support/glu.c rename to tweejump/libs/cocos2d/Platforms/iOS/glu.c index cad7139..2e00d5f 100755 --- a/Support/cocos2d/Support/glu.c +++ b/tweejump/libs/cocos2d/Platforms/iOS/glu.c @@ -6,9 +6,14 @@ // // +// 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 +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED + #import #import -#import "OpenGL_Internal.h" +#import "../../Support/OpenGL_Internal.h" #include "glu.h" void gluPerspective(GLfloat fovy, GLfloat aspect, GLfloat zNear, GLfloat zFar) @@ -97,16 +102,12 @@ void gluLookAt(GLfloat eyex, GLfloat eyey, GLfloat eyez, M(3, 2) = 0.0f; M(3, 3) = 1.0f; #undef M - { - int a; - GLfloat fixedM[16]; - for (a = 0; a < 16; ++a) - fixedM[a] = m[a]; - glMultMatrixf(fixedM); - } + + glMultMatrixf(m); + /* Translate Eye to Origin */ glTranslatef(-eyex, -eyey, -eyez); } - +#endif // __IPHONE_OS_VERSION_MAX_ALLOWED diff --git a/Support/cocos2d/Support/glu.h b/tweejump/libs/cocos2d/Platforms/iOS/glu.h similarity index 67% rename from Support/cocos2d/Support/glu.h rename to tweejump/libs/cocos2d/Platforms/iOS/glu.h index 70b3721..86dcac7 100755 --- a/Support/cocos2d/Support/glu.h +++ b/tweejump/libs/cocos2d/Platforms/iOS/glu.h @@ -6,6 +6,11 @@ #ifndef __COCOS2D_GLU_H #define __COCOS2D_GLU_H +// 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 +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED + #import /** @@ -18,4 +23,7 @@ void gluLookAt(float eyeX, float eyeY, float eyeZ, float lookAtX, float lookAtY, /** OpenGL gluPerspective implementation */ void gluPerspective(GLfloat fovy, GLfloat aspect, GLfloat zNear, GLfloat zFar); +#endif // __IPHONE_OS_VERSION_MAX_ALLOWED + #endif /* __COCOS2D_GLU_H */ + diff --git a/tweejump/libs/cocos2d/Support/CCArray.h b/tweejump/libs/cocos2d/Support/CCArray.h new file mode 100755 index 0000000..0c7b2b8 --- /dev/null +++ b/tweejump/libs/cocos2d/Support/CCArray.h @@ -0,0 +1,106 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2010 ForzeField Studios S.L. http://forzefield.com + * + * 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. + */ + + +#import "ccCArray.h" + + +/** A faster alternative of NSArray. + CCArray uses internally a c-array. + @since v0.99.4 + */ + + +/** @def CCARRAY_FOREACH + A convience macro to iterate over a CCArray using. It is faster than the "fast enumeration" interface. + @since v0.99.4 + */ + +#define CCARRAY_FOREACH(__array__, __object__) \ +if (__array__ && __array__->data->num > 0) \ +for(id *__arr__ = __array__->data->arr, *end = __array__->data->arr + __array__->data->num-1; \ + __arr__ <= end && ((__object__ = *__arr__) != nil || true); \ + __arr__++) + +@interface CCArray : NSObject +{ + @public ccArray *data; +} + ++ (id) array; ++ (id) arrayWithCapacity:(NSUInteger)capacity; ++ (id) arrayWithArray:(CCArray*)otherArray; ++ (id) arrayWithNSArray:(NSArray*)otherArray; + + +- (id) initWithCapacity:(NSUInteger)capacity; +- (id) initWithArray:(CCArray*)otherArray; +- (id) initWithNSArray:(NSArray*)otherArray; + + +// Querying an Array + +- (NSUInteger) count; +- (NSUInteger) capacity; +- (NSUInteger) indexOfObject:(id)object; +- (id) objectAtIndex:(NSUInteger)index; +- (BOOL) containsObject:(id)object; +- (id) randomObject; +- (id) lastObject; +- (NSArray*) getNSArray; + + +// Adding Objects + +- (void) addObject:(id)object; +- (void) addObjectsFromArray:(CCArray*)otherArray; +- (void) addObjectsFromNSArray:(NSArray*)otherArray; +- (void) insertObject:(id)object atIndex:(NSUInteger)index; + + +// Removing Objects + +- (void) removeLastObject; +- (void) removeObject:(id)object; +- (void) removeObjectAtIndex:(NSUInteger)index; +- (void) removeObjectsInArray:(CCArray*)otherArray; +- (void) removeAllObjects; +- (void) fastRemoveObject:(id)object; +- (void) fastRemoveObjectAtIndex:(NSUInteger)index; + + +// Rearranging Content + +- (void) exchangeObject:(id)object1 withObject:(id)object2; +- (void) exchangeObjectAtIndex:(NSUInteger)index1 withObjectAtIndex:(NSUInteger)index2; +- (void) reverseObjects; +- (void) reduceMemoryFootprint; + +// Sending Messages to Elements + +- (void) makeObjectsPerformSelector:(SEL)aSelector; +- (void) makeObjectsPerformSelector:(SEL)aSelector withObject:(id)object; + + +@end diff --git a/tweejump/libs/cocos2d/Support/CCArray.m b/tweejump/libs/cocos2d/Support/CCArray.m new file mode 100755 index 0000000..87671fb --- /dev/null +++ b/tweejump/libs/cocos2d/Support/CCArray.m @@ -0,0 +1,304 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2010 ForzeField Studios S.L. http://forzefield.com + * + * 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. + */ + +#import "CCArray.h" +#import "../ccMacros.h" + + +@implementation CCArray + ++ (id) array +{ + return [[[self alloc] init] autorelease]; +} + ++ (id) arrayWithCapacity:(NSUInteger)capacity +{ + return [[[self alloc] initWithCapacity:capacity] autorelease]; +} + ++ (id) arrayWithArray:(CCArray*)otherArray +{ + return [[(CCArray*)[self alloc] initWithArray:otherArray] autorelease]; +} + ++ (id) arrayWithNSArray:(NSArray*)otherArray +{ + return [[(CCArray*)[self alloc] initWithNSArray:otherArray] autorelease]; +} + +- (id) init +{ + self = [self initWithCapacity:2]; + return self; +} + +- (id) initWithCapacity:(NSUInteger)capacity +{ + self = [super init]; + if (self != nil) { + data = ccArrayNew(capacity); + } + return self; +} + +- (id) initWithArray:(CCArray*)otherArray +{ + self = [self initWithCapacity:otherArray->data->num]; + if (self != nil) { + [self addObjectsFromArray:otherArray]; + } + return self; +} + +- (id) initWithNSArray:(NSArray*)otherArray +{ + self = [self initWithCapacity:otherArray.count]; + if (self != nil) { + [self addObjectsFromNSArray:otherArray]; + } + return self; +} + +- (id) initWithCoder:(NSCoder*)coder +{ + self = [self initWithNSArray:[coder decodeObjectForKey:@"nsarray"]]; + return self; +} + + +#pragma mark Querying an Array + +- (NSUInteger) count +{ + return data->num; +} + +- (NSUInteger) capacity +{ + return data->max; +} + +- (NSUInteger) indexOfObject:(id)object +{ + return ccArrayGetIndexOfObject(data, object); +} + +- (id) objectAtIndex:(NSUInteger)index +{ + NSAssert2( index < data->num, @"index out of range in objectAtIndex(%d), index %i", data->num, index ); + + return data->arr[index]; +} + +- (BOOL) containsObject:(id)object +{ + return ccArrayContainsObject(data, object); +} + +- (id) lastObject +{ + if( data->num > 0 ) + return data->arr[data->num-1]; + return nil; +} + +- (id) randomObject +{ + if(data->num==0) return nil; + return data->arr[(int)(data->num*CCRANDOM_0_1())]; +} + +- (NSArray*) getNSArray +{ + return [NSArray arrayWithObjects:data->arr count:data->num]; +} + + +#pragma mark Adding Objects + +- (void) addObject:(id)object +{ + ccArrayAppendObjectWithResize(data, object); +} + +- (void) addObjectsFromArray:(CCArray*)otherArray +{ + ccArrayAppendArrayWithResize(data, otherArray->data); +} + +- (void) addObjectsFromNSArray:(NSArray*)otherArray +{ + ccArrayEnsureExtraCapacity(data, otherArray.count); + for(id object in otherArray) + ccArrayAppendObject(data, object); +} + +- (void) insertObject:(id)object atIndex:(NSUInteger)index +{ + ccArrayInsertObjectAtIndex(data, object, index); +} + + +#pragma mark Removing Objects + +- (void) removeObject:(id)object +{ + ccArrayRemoveObject(data, object); +} + +- (void) removeObjectAtIndex:(NSUInteger)index +{ + ccArrayRemoveObjectAtIndex(data, index); +} + +- (void) fastRemoveObject:(id)object +{ + ccArrayFastRemoveObject(data, object); +} + +- (void) fastRemoveObjectAtIndex:(NSUInteger)index +{ + ccArrayFastRemoveObjectAtIndex(data, index); +} + +- (void) removeObjectsInArray:(CCArray*)otherArray +{ + ccArrayRemoveArray(data, otherArray->data); +} + +- (void) removeLastObject +{ + NSAssert( data->num > 0, @"no objects added" ); + + ccArrayRemoveObjectAtIndex(data, data->num-1); +} + +- (void) removeAllObjects +{ + ccArrayRemoveAllObjects(data); +} + + +#pragma mark Rearranging Content + +- (void) exchangeObject:(id)object1 withObject:(id)object2 +{ + NSUInteger index1 = ccArrayGetIndexOfObject(data, object1); + if(index1 == NSNotFound) return; + NSUInteger index2 = ccArrayGetIndexOfObject(data, object2); + if(index2 == NSNotFound) return; + + ccArraySwapObjectsAtIndexes(data, index1, index2); +} + +- (void) exchangeObjectAtIndex:(NSUInteger)index1 withObjectAtIndex:(NSUInteger)index2 +{ + ccArraySwapObjectsAtIndexes(data, index1, index2); +} + +- (void) reverseObjects +{ + if (data->num > 1) + { + //floor it since in case of a oneven number the number of swaps stays the same + int count = (int) floorf(data->num/2.f); + NSUInteger maxIndex = data->num - 1; + + for (int i = 0; i < count ; i++) + { + ccArraySwapObjectsAtIndexes(data, i, maxIndex); + maxIndex--; + } + } +} + +- (void) reduceMemoryFootprint +{ + ccArrayShrink(data); +} + +#pragma mark Sending Messages to Elements + +- (void) makeObjectsPerformSelector:(SEL)aSelector +{ + ccArrayMakeObjectsPerformSelector(data, aSelector); +} + +- (void) makeObjectsPerformSelector:(SEL)aSelector withObject:(id)object +{ + ccArrayMakeObjectsPerformSelectorWithObject(data, aSelector, object); +} + + +#pragma mark CCArray - NSFastEnumeration protocol + +- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)stackbuf count:(NSUInteger)len +{ + if(state->state == 1) return 0; + + state->mutationsPtr = (unsigned long *)self; + state->itemsPtr = &data->arr[0]; + state->state = 1; + return data->num; +} + + +#pragma mark CCArray - NSCopying protocol + +- (id)copyWithZone:(NSZone *)zone +{ + return [(CCArray*)[[self class] allocWithZone:zone] initWithArray:self]; +} + +- (void) encodeWithCoder:(NSCoder *)coder +{ + [coder encodeObject:[self getNSArray] forKey:@"nsarray"]; +} + +#pragma mark + +- (void) dealloc +{ + CCLOGINFO(@"cocos2d: deallocing %@", self); + + ccArrayFree(data); + [super dealloc]; +} + +#pragma mark + +- (NSString*) description +{ + NSMutableString *ret = [NSMutableString stringWithFormat:@"<%@ = %08X> = ( ", [self class], self]; + + for( id obj in self) + [ret appendFormat:@"%@, ",obj]; + + [ret appendString:@")"]; + + return ret; +} + +@end diff --git a/tweejump/libs/cocos2d/Support/CCFileUtils.h b/tweejump/libs/cocos2d/Support/CCFileUtils.h new file mode 100755 index 0000000..0455202 --- /dev/null +++ b/tweejump/libs/cocos2d/Support/CCFileUtils.h @@ -0,0 +1,62 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-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. + * + */ + + +#import + + +/** Helper class to handle file operations */ +@interface CCFileUtils : NSObject +{ +} + +/** Returns the fullpath of an filename. + + If this method is when Retina Display is enabled, then the + Retina Display suffix will be appended to the file (See ccConfig.h). + + If the Retina Display image doesn't exist, then it will return the "non-Retina Display" image + + */ ++(NSString*) fullPathFromRelativePath:(NSString*) relPath; +@end + +/** loads a file into memory. + the caller should release the allocated buffer. + + @returns the size of the allocated buffer + @since v0.99.5 + */ +NSInteger ccLoadFileIntoMemory(const char *filename, unsigned char **out); + + +/** removes the HD suffix from a path + + @returns NSString * without the HD suffix + @since v0.99.5 + */ +NSString *ccRemoveHDSuffixFromFile( NSString *path ); + diff --git a/tweejump/libs/cocos2d/Support/CCFileUtils.m b/tweejump/libs/cocos2d/Support/CCFileUtils.m new file mode 100755 index 0000000..6d33799 --- /dev/null +++ b/tweejump/libs/cocos2d/Support/CCFileUtils.m @@ -0,0 +1,169 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-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. + * + */ + + +#import +#import "CCFileUtils.h" +#import "../CCConfiguration.h" +#import "../ccMacros.h" +#import "../ccConfig.h" + +static NSFileManager *__localFileManager=nil; + +// +NSInteger ccLoadFileIntoMemory(const char *filename, unsigned char **out) +{ + NSCAssert( out, @"ccLoadFileIntoMemory: invalid 'out' parameter"); + NSCAssert( &*out, @"ccLoadFileIntoMemory: invalid 'out' parameter"); + + size_t size = 0; + FILE *f = fopen(filename, "rb"); + if( !f ) { + *out = NULL; + return -1; + } + + fseek(f, 0, SEEK_END); + size = ftell(f); + fseek(f, 0, SEEK_SET); + + *out = malloc(size); + size_t read = fread(*out, 1, size, f); + if( read != size ) { + free(*out); + *out = NULL; + return -1; + } + + fclose(f); + + return size; +} + +NSString *ccRemoveHDSuffixFromFile( NSString *path ) +{ +#if CC_IS_RETINA_DISPLAY_SUPPORTED + + if( CC_CONTENT_SCALE_FACTOR() == 2 ) { + + NSString *name = [path lastPathComponent]; + + // check if path already has the suffix. + if( [name rangeOfString:CC_RETINA_DISPLAY_FILENAME_SUFFIX].location != NSNotFound ) { + + CCLOG(@"cocos2d: Filename(%@) contains %@ suffix. Removing it. See cocos2d issue #1040", path, CC_RETINA_DISPLAY_FILENAME_SUFFIX); + + NSString *newLastname = [name stringByReplacingOccurrencesOfString:CC_RETINA_DISPLAY_FILENAME_SUFFIX withString:@""]; + + NSString *pathWithoutLastname = [path stringByDeletingLastPathComponent]; + return [pathWithoutLastname stringByAppendingPathComponent:newLastname]; + } + } + +#endif // CC_IS_RETINA_DISPLAY_SUPPORTED + + return path; + +} + + +@implementation CCFileUtils + ++(void) initialize +{ + if( self == [CCFileUtils class] ) + __localFileManager = [[NSFileManager alloc] init]; +} + ++(NSString*) getDoubleResolutionImage:(NSString*)path +{ +#if CC_IS_RETINA_DISPLAY_SUPPORTED + + if( CC_CONTENT_SCALE_FACTOR() == 2 ) + { + + NSString *pathWithoutExtension = [path stringByDeletingPathExtension]; + NSString *name = [pathWithoutExtension lastPathComponent]; + + // check if path already has the suffix. + if( [name rangeOfString:CC_RETINA_DISPLAY_FILENAME_SUFFIX].location != NSNotFound ) { + + CCLOG(@"cocos2d: WARNING Filename(%@) already has the suffix %@. Using it.", name, CC_RETINA_DISPLAY_FILENAME_SUFFIX); + return path; + } + + + NSString *extension = [path pathExtension]; + + if( [extension isEqualToString:@"ccz"] || [extension isEqualToString:@"gz"] ) + { + // All ccz / gz files should be in the format filename.xxx.ccz + // so we need to pull off the .xxx part of the extension as well + extension = [NSString stringWithFormat:@"%@.%@", [pathWithoutExtension pathExtension], extension]; + pathWithoutExtension = [pathWithoutExtension stringByDeletingPathExtension]; + } + + + NSString *retinaName = [pathWithoutExtension stringByAppendingString:CC_RETINA_DISPLAY_FILENAME_SUFFIX]; + retinaName = [retinaName stringByAppendingPathExtension:extension]; + + if( [__localFileManager fileExistsAtPath:retinaName] ) + return retinaName; + + CCLOG(@"cocos2d: CCFileUtils: Warning HD file not found: %@", [retinaName lastPathComponent] ); + } + +#endif // CC_IS_RETINA_DISPLAY_SUPPORTED + + return path; +} + ++(NSString*) fullPathFromRelativePath:(NSString*) relPath +{ + NSAssert(relPath != nil, @"CCFileUtils: Invalid path"); + + NSString *fullpath = nil; + + // only if it is not an absolute path + if( ! [relPath isAbsolutePath] ) + { + NSString *file = [relPath lastPathComponent]; + NSString *imageDirectory = [relPath stringByDeletingLastPathComponent]; + + fullpath = [[NSBundle mainBundle] pathForResource:file + ofType:nil + inDirectory:imageDirectory]; + } + + if (fullpath == nil) + fullpath = relPath; + + fullpath = [self getDoubleResolutionImage:fullpath]; + + return fullpath; +} + +@end diff --git a/tweejump/libs/cocos2d/Support/CCProfiling.h b/tweejump/libs/cocos2d/Support/CCProfiling.h new file mode 100755 index 0000000..b241fb9 --- /dev/null +++ b/tweejump/libs/cocos2d/Support/CCProfiling.h @@ -0,0 +1,53 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2010 Stuart Carnie + * + * 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. + * + */ + + +#import +#import + +@class CCProfilingTimer; + +@interface CCProfiler : NSObject { + NSMutableArray* activeTimers; +} + ++ (CCProfiler*)sharedProfiler; ++ (CCProfilingTimer*)timerWithName:(NSString*)timerName andInstance:(id)instance; ++ (void)releaseTimer:(CCProfilingTimer*)timer; +- (void)displayTimers; + +@end + + +@interface CCProfilingTimer : NSObject { + NSString* name; + struct timeval startTime; + double averageTime; +} + +@end + +extern void CCProfilingBeginTimingBlock(CCProfilingTimer* timer); +extern void CCProfilingEndTimingBlock(CCProfilingTimer* timer); diff --git a/tweejump/libs/cocos2d/Support/CCProfiling.m b/tweejump/libs/cocos2d/Support/CCProfiling.m new file mode 100755 index 0000000..13c8c81 --- /dev/null +++ b/tweejump/libs/cocos2d/Support/CCProfiling.m @@ -0,0 +1,117 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2010 Stuart Carnie + * + * 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. + * + */ + +#import "../ccConfig.h" + +#if CC_ENABLE_PROFILERS + +#import "CCProfiling.h" + +@interface CCProfilingTimer() +- (id)initWithName:(NSString*)timerName andInstance:(id)instance; +@end + +@implementation CCProfiler + +static CCProfiler* g_sharedProfiler; + ++ (CCProfiler*)sharedProfiler { + if (!g_sharedProfiler) + g_sharedProfiler = [[CCProfiler alloc] init]; + + return g_sharedProfiler; +} + ++ (CCProfilingTimer*)timerWithName:(NSString*)timerName andInstance:(id)instance { + CCProfiler* p = [CCProfiler sharedProfiler]; + CCProfilingTimer* t = [[CCProfilingTimer alloc] initWithName:timerName andInstance:instance]; + [p->activeTimers addObject:t]; + [t release]; + return t; +} + ++ (void)releaseTimer:(CCProfilingTimer*)timer { + CCProfiler* p = [CCProfiler sharedProfiler]; + [p->activeTimers removeObject:timer]; +} + +- (id)init { + if (!(self = [super init])) return nil; + + activeTimers = [[NSMutableArray alloc] init]; + + return self; +} + +- (void)dealloc { + [activeTimers release]; + [super dealloc]; +} + +- (void)displayTimers { + for (id timer in activeTimers) { + printf("%s\n", [[timer description] cStringUsingEncoding:[NSString defaultCStringEncoding]]); + } +} + +@end + +@implementation CCProfilingTimer + +- (id)initWithName:(NSString*)timerName andInstance:(id)instance { + if (!(self = [super init])) return nil; + + name = [[NSString stringWithFormat:@"%@ (0x%.8x)", timerName, instance] retain]; + + return self; +} + +- (void)dealloc { + [name release]; + [super dealloc]; +} + +- (NSString*)description { + return [NSString stringWithFormat:@"%@ : avg time, %fms", name, averageTime]; +} + +void CCProfilingBeginTimingBlock(CCProfilingTimer* timer) { + gettimeofday(&timer->startTime, NULL); +} + +typedef unsigned int uint32; +void CCProfilingEndTimingBlock(CCProfilingTimer* timer) { + struct timeval currentTime; + gettimeofday(¤tTime, NULL); + timersub(¤tTime, &timer->startTime, ¤tTime); + double duration = currentTime.tv_sec * 1000.0 + currentTime.tv_usec / 1000.0; + + // return in milliseconds + timer->averageTime = (timer->averageTime + duration) / 2.0f; +} + +@end + +#endif diff --git a/Support/cocos2d/Support/CGPointExtension.h b/tweejump/libs/cocos2d/Support/CGPointExtension.h old mode 100644 new mode 100755 similarity index 60% rename from Support/cocos2d/Support/CGPointExtension.h rename to tweejump/libs/cocos2d/Support/CGPointExtension.h index dbaafd2..96edeb7 --- a/Support/cocos2d/Support/CGPointExtension.h +++ b/tweejump/libs/cocos2d/Support/CGPointExtension.h @@ -1,7 +1,9 @@ /* cocos2d for iPhone - * http://code.google.com/p/cocos2d-iphone + * http://www.cocos2d-iphone.org * * Copyright (c) 2007 Scott Lembcke + * + * Copyright (c) 2010 Lam Pham * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -23,7 +25,7 @@ */ /* - * Code based on Chipmunk's cpVect.h file + * Some of the functions were based on Chipmunk's cpVect.h. */ /** @@ -42,9 +44,16 @@ - cpvadd( CGPointMake(1,1), CGPointMake(2,2) ); // mixing chipmunk and CG (avoid) */ +#import +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED #import +#elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED) +#import +#endif + #import +#import #ifdef __cplusplus extern "C" { @@ -217,6 +226,109 @@ CGPoint ccpForAngle(const CGFloat a); */ CGFloat ccpToAngle(const CGPoint v); + +/** Clamp a value between from and to. + @since v0.99.1 + */ +float clampf(float value, float min_inclusive, float max_inclusive); + +/** Clamp a point between from and to. + @since v0.99.1 + */ +CGPoint ccpClamp(CGPoint p, CGPoint from, CGPoint to); + +/** Quickly convert CGSize to a CGPoint + @since v0.99.1 + */ +CGPoint ccpFromSize(CGSize s); + +/** Run a math operation function on each point component + * absf, fllorf, ceilf, roundf + * any function that has the signature: float func(float); + * For example: let's try to take the floor of x,y + * ccpCompOp(p,floorf); + @since v0.99.1 + */ +CGPoint ccpCompOp(CGPoint p, float (*opFunc)(float)); + +/** Linear Interpolation between two points a and b + @returns + alpha == 0 ? a + alpha == 1 ? b + otherwise a value between a..b + @since v0.99.1 + */ +CGPoint ccpLerp(CGPoint a, CGPoint b, float alpha); + + +/** @returns if points have fuzzy equality which means equal with some degree of variance. + @since v0.99.1 + */ +BOOL ccpFuzzyEqual(CGPoint a, CGPoint b, float variance); + + +/** Multiplies a nd b components, a.x*b.x, a.y*b.y + @returns a component-wise multiplication + @since v0.99.1 + */ +CGPoint ccpCompMult(CGPoint a, CGPoint b); + +/** @returns the signed angle in radians between two vector directions + @since v0.99.1 + */ +float ccpAngleSigned(CGPoint a, CGPoint b); + +/** @returns the angle in radians between two vector directions + @since v0.99.1 +*/ +float ccpAngle(CGPoint a, CGPoint b); + +/** Rotates a point counter clockwise by the angle around a pivot + @param v is the point to rotate + @param pivot is the pivot, naturally + @param angle is the angle of rotation cw in radians + @returns the rotated point + @since v0.99.1 + */ +CGPoint ccpRotateByAngle(CGPoint v, CGPoint pivot, float angle); + +/** A general line-line intersection test + @param p1 + is the startpoint for the first line P1 = (p1 - p2) + @param p2 + is the endpoint for the first line P1 = (p1 - p2) + @param p3 + is the startpoint for the second line P2 = (p3 - p4) + @param p4 + is the endpoint for the second line P2 = (p3 - p4) + @param s + is the range for a hitpoint in P1 (pa = p1 + s*(p2 - p1)) + @param t + is the range for a hitpoint in P3 (pa = p2 + t*(p4 - p3)) + @return bool + indicating successful intersection of a line + note that to truly test intersection for segments we have to make + sure that s & t lie within [0..1] and for rays, make sure s & t > 0 + the hit point is p3 + t * (p4 - p3); + the hit point also is p1 + s * (p2 - p1); + @since v0.99.1 + */ +BOOL ccpLineIntersect(CGPoint p1, CGPoint p2, + CGPoint p3, CGPoint p4, + float *s, float *t); + +/* + ccpSegmentIntersect returns YES if Segment A-B intersects with segment C-D + @since v1.0.0 + */ +BOOL ccpSegmentIntersect(CGPoint A, CGPoint B, CGPoint C, CGPoint D); + +/* + ccpIntersectPoint returns the intersection point of line A-B, C-D + @since v1.0.0 + */ +CGPoint ccpIntersectPoint(CGPoint A, CGPoint B, CGPoint C, CGPoint D); + #ifdef __cplusplus } #endif diff --git a/tweejump/libs/cocos2d/Support/CGPointExtension.m b/tweejump/libs/cocos2d/Support/CGPointExtension.m new file mode 100755 index 0000000..b06859d --- /dev/null +++ b/tweejump/libs/cocos2d/Support/CGPointExtension.m @@ -0,0 +1,196 @@ +/* cocos2d for iPhone + * http://www.cocos2d-iphone.org + * + * Copyright (c) 2007 Scott Lembcke + * + * Copyright (c) 2010 Lam Pham + * + * 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. + */ + +#include "stdio.h" +#include "math.h" + +#import "../ccMacros.h" // CC_SWAP +#include "CGPointExtension.h" + +#define kCGPointEpsilon FLT_EPSILON + +CGFloat +ccpLength(const CGPoint v) +{ + return sqrtf(ccpLengthSQ(v)); +} + +CGFloat +ccpDistance(const CGPoint v1, const CGPoint v2) +{ + return ccpLength(ccpSub(v1, v2)); +} + +CGPoint +ccpNormalize(const CGPoint v) +{ + return ccpMult(v, 1.0f/ccpLength(v)); +} + +CGPoint +ccpForAngle(const CGFloat a) +{ + return ccp(cosf(a), sinf(a)); +} + +CGFloat +ccpToAngle(const CGPoint v) +{ + return atan2f(v.y, v.x); +} + +CGPoint ccpLerp(CGPoint a, CGPoint b, float alpha) +{ + return ccpAdd(ccpMult(a, 1.f - alpha), ccpMult(b, alpha)); +} + +float clampf(float value, float min_inclusive, float max_inclusive) +{ + if (min_inclusive > max_inclusive) { + CC_SWAP(min_inclusive,max_inclusive); + } + return value < min_inclusive ? min_inclusive : value < max_inclusive? value : max_inclusive; +} + +CGPoint ccpClamp(CGPoint p, CGPoint min_inclusive, CGPoint max_inclusive) +{ + return ccp(clampf(p.x,min_inclusive.x,max_inclusive.x), clampf(p.y, min_inclusive.y, max_inclusive.y)); +} + +CGPoint ccpFromSize(CGSize s) +{ + return ccp(s.width, s.height); +} + +CGPoint ccpCompOp(CGPoint p, float (*opFunc)(float)) +{ + return ccp(opFunc(p.x), opFunc(p.y)); +} + +BOOL ccpFuzzyEqual(CGPoint a, CGPoint b, float var) +{ + if(a.x - var <= b.x && b.x <= a.x + var) + if(a.y - var <= b.y && b.y <= a.y + var) + return true; + return false; +} + +CGPoint ccpCompMult(CGPoint a, CGPoint b) +{ + return ccp(a.x * b.x, a.y * b.y); +} + +float ccpAngleSigned(CGPoint a, CGPoint b) +{ + CGPoint a2 = ccpNormalize(a); + CGPoint b2 = ccpNormalize(b); + float angle = atan2f(a2.x * b2.y - a2.y * b2.x, ccpDot(a2, b2)); + if( fabs(angle) < kCGPointEpsilon ) return 0.f; + return angle; +} + +CGPoint ccpRotateByAngle(CGPoint v, CGPoint pivot, float angle) +{ + CGPoint r = ccpSub(v, pivot); + float cosa = cosf(angle), sina = sinf(angle); + float t = r.x; + r.x = t*cosa - r.y*sina + pivot.x; + r.y = t*sina + r.y*cosa + pivot.y; + return r; +} + + +BOOL ccpSegmentIntersect(CGPoint A, CGPoint B, CGPoint C, CGPoint D) +{ + float S, T; + + if( ccpLineIntersect(A, B, C, D, &S, &T ) + && (S >= 0.0f && S <= 1.0f && T >= 0.0f && T <= 1.0f) ) + return YES; + + return NO; +} + +CGPoint ccpIntersectPoint(CGPoint A, CGPoint B, CGPoint C, CGPoint D) +{ + float S, T; + + if( ccpLineIntersect(A, B, C, D, &S, &T) ) { + // Point of intersection + CGPoint P; + P.x = A.x + S * (B.x - A.x); + P.y = A.y + S * (B.y - A.y); + return P; + } + + return CGPointZero; +} + +BOOL ccpLineIntersect(CGPoint A, CGPoint B, + CGPoint C, CGPoint D, + float *S, float *T) +{ + // FAIL: Line undefined + if ( (A.x==B.x && A.y==B.y) || (C.x==D.x && C.y==D.y) ) return NO; + + const float BAx = B.x - A.x; + const float BAy = B.y - A.y; + const float DCx = D.x - C.x; + const float DCy = D.y - C.y; + const float ACx = A.x - C.x; + const float ACy = A.y - C.y; + + const float denom = DCy*BAx - DCx*BAy; + + *S = DCx*ACy - DCy*ACx; + *T = BAx*ACy - BAy*ACx; + + if (denom == 0) { + if (*S == 0 || *T == 0) { + // Lines incident + return YES; + } + // Lines parallel and not incident + return NO; + } + + *S = *S / denom; + *T = *T / denom; + + // Point of intersection + // CGPoint P; + // P.x = A.x + *S * (B.x - A.x); + // P.y = A.y + *S * (B.y - A.y); + + return YES; +} + +float ccpAngle(CGPoint a, CGPoint b) +{ + float angle = acosf(ccpDot(ccpNormalize(a), ccpNormalize(b))); + if( fabs(angle) < kCGPointEpsilon ) return 0.f; + return angle; +} diff --git a/Support/cocos2d/Support/OpenGL_Internal.h b/tweejump/libs/cocos2d/Support/OpenGL_Internal.h similarity index 96% rename from Support/cocos2d/Support/OpenGL_Internal.h rename to tweejump/libs/cocos2d/Support/OpenGL_Internal.h index 8d875b1..4789683 100755 --- a/Support/cocos2d/Support/OpenGL_Internal.h +++ b/tweejump/libs/cocos2d/Support/OpenGL_Internal.h @@ -66,7 +66,8 @@ Copyright (C) 2008 Apple Inc. All Rights Reserved. /* EAGL and GL functions calling wrappers that log on error */ #define CALL_EAGL_FUNCTION(__FUNC__, ...) ({ EAGLError __error = __FUNC__( __VA_ARGS__ ); if(__error != kEAGLErrorSuccess) printf("%s() called from %s returned error %i\n", #__FUNC__, __FUNCTION__, __error); (__error ? NO : YES); }) -#define CHECK_GL_ERROR() ({ GLenum __error = glGetError(); if(__error) printf("OpenGL error 0x%04X in %s\n", __error, __FUNCTION__); (__error ? NO : YES); }) +//#define CHECK_GL_ERROR() ({ GLenum __error = glGetError(); if(__error) printf("OpenGL error 0x%04X in %s\n", __error, __FUNCTION__); (__error ? NO : YES); }) +#define CHECK_GL_ERROR() ({ GLenum __error = glGetError(); if(__error) printf("OpenGL error 0x%04X in %s\n", __error, __FUNCTION__); }) /* Optional delegate methods support */ #ifndef __DELEGATE_IVAR__ diff --git a/Support/cocos2d/Support/TGAlib.h b/tweejump/libs/cocos2d/Support/TGAlib.h old mode 100644 new mode 100755 similarity index 100% rename from Support/cocos2d/Support/TGAlib.h rename to tweejump/libs/cocos2d/Support/TGAlib.h diff --git a/Support/cocos2d/Support/TGAlib.m b/tweejump/libs/cocos2d/Support/TGAlib.m old mode 100644 new mode 100755 similarity index 98% rename from Support/cocos2d/Support/TGAlib.m rename to tweejump/libs/cocos2d/Support/TGAlib.m index b574d59..11303b4 --- a/Support/cocos2d/Support/TGAlib.m +++ b/tweejump/libs/cocos2d/Support/TGAlib.m @@ -11,6 +11,8 @@ #import "TGAlib.h" +void tgaLoadRLEImageData(FILE *file, tImageTGA *info); +void tgaFlipImage( tImageTGA *info ); // load the image header fields. We only keep those that matter! void tgaLoadHeader(FILE *file, tImageTGA *info) { diff --git a/tweejump/libs/cocos2d/Support/TransformUtils.h b/tweejump/libs/cocos2d/Support/TransformUtils.h new file mode 100755 index 0000000..49fde35 --- /dev/null +++ b/tweejump/libs/cocos2d/Support/TransformUtils.h @@ -0,0 +1,37 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2009 Valentin Milea + * + * 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. + * + */ + +#import + +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED +#import +#import +#elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED) +#import +#import +#endif + +void CGAffineToGL(const CGAffineTransform *t, GLfloat *m); +void GLToCGAffine(const GLfloat *m, CGAffineTransform *t); diff --git a/tweejump/libs/cocos2d/Support/TransformUtils.m b/tweejump/libs/cocos2d/Support/TransformUtils.m new file mode 100755 index 0000000..9caecf0 --- /dev/null +++ b/tweejump/libs/cocos2d/Support/TransformUtils.m @@ -0,0 +1,46 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2009 Valentin Milea + * + * 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. + * + */ + + +#import "TransformUtils.h" + +void CGAffineToGL(const CGAffineTransform *t, GLfloat *m) +{ + // | m[0] m[4] m[8] m[12] | | m11 m21 m31 m41 | | a c 0 tx | + // | m[1] m[5] m[9] m[13] | | m12 m22 m32 m42 | | b d 0 ty | + // | m[2] m[6] m[10] m[14] | <=> | m13 m23 m33 m43 | <=> | 0 0 1 0 | + // | m[3] m[7] m[11] m[15] | | m14 m24 m34 m44 | | 0 0 0 1 | + + m[2] = m[3] = m[6] = m[7] = m[8] = m[9] = m[11] = m[14] = 0.0f; + m[10] = m[15] = 1.0f; + m[0] = t->a; m[4] = t->c; m[12] = t->tx; + m[1] = t->b; m[5] = t->d; m[13] = t->ty; +} + +void GLToCGAffine(const GLfloat *m, CGAffineTransform *t) +{ + t->a = m[0]; t->c = m[4]; t->tx = m[12]; + t->b = m[1]; t->d = m[5]; t->ty = m[13]; +} diff --git a/tweejump/libs/cocos2d/Support/ZipUtils.h b/tweejump/libs/cocos2d/Support/ZipUtils.h new file mode 100755 index 0000000..363f911 --- /dev/null +++ b/tweejump/libs/cocos2d/Support/ZipUtils.h @@ -0,0 +1,91 @@ +/* cocos2d for iPhone + * + * http://www.cocos2d-iphone.org + * + * + * inflateMemory_ based on zlib example code + * http://www.zlib.net + * + * Some ideas were taken from: + * http://themanaworld.org/ + * from the mapreader.cpp file + * + */ + +#ifndef __CC_ZIP_UTILS_H +#define __CC_ZIP_UTILS_H + +#import + +#ifdef __cplusplus +extern "C" { +#endif + + /* XXX: pragma pack ??? */ + /** @struct CCZHeader + */ + struct CCZHeader { + uint8_t sig[4]; // signature. Should be 'CCZ!' 4 bytes + uint16_t compression_type; // should 0 + uint16_t version; // should be 2 (although version type==1 is also supported) + uint32_t reserved; // Reserverd for users. + uint32_t len; // size of the uncompressed file + }; + + enum { + CCZ_COMPRESSION_ZLIB, // zlib format. + CCZ_COMPRESSION_BZIP2, // bzip2 format (not supported yet) + CCZ_COMPRESSION_GZIP, // gzip format (not supported yet) + CCZ_COMPRESSION_NONE, // plain (not supported yet) + }; + +/** @file + * Zip helper functions + */ + +/** + * Inflates either zlib or gzip deflated memory. The inflated memory is + * expected to be freed by the caller. + * + * It will allocate 256k for the destination buffer. If it is not enought it will multiply the previous buffer size per 2, until there is enough memory. + * @returns the length of the deflated buffer + * + @since v0.8.1 + */ +int ccInflateMemory(unsigned char *in, unsigned int inLength, unsigned char **out); + +/** + * Inflates either zlib or gzip deflated memory. The inflated memory is + * expected to be freed by the caller. + * + * outLenghtHint is assumed to be the needed room to allocate the inflated buffer. + * + * @returns the length of the deflated buffer + * + @since v1.0.0 + */ +int ccInflateMemoryWithHint(unsigned char *in, unsigned int inLength, unsigned char **out, unsigned int outLenghtHint ); + + +/** inflates a GZip file into memory + * + * @returns the length of the deflated buffer + * + * @since v0.99.5 + */ +int ccInflateGZipFile(const char *filename, unsigned char **out); + +/** inflates a CCZ file into memory + * + * @returns the length of the deflated buffer + * + * @since v0.99.5 + */ +int ccInflateCCZFile(const char *filename, unsigned char **out); + + +#ifdef __cplusplus +} +#endif + +#endif // __CC_ZIP_UTILS_H diff --git a/tweejump/libs/cocos2d/Support/ZipUtils.m b/tweejump/libs/cocos2d/Support/ZipUtils.m new file mode 100755 index 0000000..ccd8bbc --- /dev/null +++ b/tweejump/libs/cocos2d/Support/ZipUtils.m @@ -0,0 +1,251 @@ +/* cocos2d for iPhone + * + * http://www.cocos2d-iphone.org + * + * + * Inflates either zlib or gzip deflated memory. The inflated memory is + * expected to be freed by the caller. + * + * inflateMemory_ based on zlib example code + * http://www.zlib.net + * + * Some ideas were taken from: + * http://themanaworld.org/ + * from the mapreader.cpp file + */ + +#import + +#import +#import +#import +#import + +#import "ZipUtils.h" +#import "CCFileUtils.h" +#import "../ccMacros.h" + +// memory in iPhone is precious +// Should buffer factor be 1.5 instead of 2 ? +#define BUFFER_INC_FACTOR (2) + +static int inflateMemoryWithHint(unsigned char *in, unsigned int inLength, unsigned char **out, unsigned int *outLength, unsigned int outLenghtHint ) +{ + /* ret value */ + int err = Z_OK; + + int bufferSize = outLenghtHint; + *out = (unsigned char*) malloc(bufferSize); + + z_stream d_stream; /* decompression stream */ + d_stream.zalloc = (alloc_func)0; + d_stream.zfree = (free_func)0; + d_stream.opaque = (voidpf)0; + + d_stream.next_in = in; + d_stream.avail_in = inLength; + d_stream.next_out = *out; + d_stream.avail_out = bufferSize; + + /* window size to hold 256k */ + if( (err = inflateInit2(&d_stream, 15 + 32)) != Z_OK ) + return err; + + for (;;) { + err = inflate(&d_stream, Z_NO_FLUSH); + + if (err == Z_STREAM_END) + break; + + switch (err) { + case Z_NEED_DICT: + err = Z_DATA_ERROR; + case Z_DATA_ERROR: + case Z_MEM_ERROR: + inflateEnd(&d_stream); + return err; + } + + // not enough memory ? + if (err != Z_STREAM_END) { + + unsigned char *tmp = realloc(*out, bufferSize * BUFFER_INC_FACTOR); + + /* not enough memory, ouch */ + if (! tmp ) { + CCLOG(@"cocos2d: ZipUtils: realloc failed"); + inflateEnd(&d_stream); + return Z_MEM_ERROR; + } + /* only assign to *out if tmp is valid. it's not guaranteed that realloc will reuse the memory */ + *out = tmp; + + d_stream.next_out = *out + bufferSize; + d_stream.avail_out = bufferSize; + bufferSize *= BUFFER_INC_FACTOR; + } + } + + + *outLength = bufferSize - d_stream.avail_out; + err = inflateEnd(&d_stream); + return err; +} + +int ccInflateMemoryWithHint(unsigned char *in, unsigned int inLength, unsigned char **out, unsigned int outLengthHint ) +{ + unsigned int outLength = 0; + int err = inflateMemoryWithHint(in, inLength, out, &outLength, outLengthHint ); + + if (err != Z_OK || *out == NULL) { + if (err == Z_MEM_ERROR) + CCLOG(@"cocos2d: ZipUtils: Out of memory while decompressing map data!"); + + else if (err == Z_VERSION_ERROR) + CCLOG(@"cocos2d: ZipUtils: Incompatible zlib version!"); + + else if (err == Z_DATA_ERROR) + CCLOG(@"cocos2d: ZipUtils: Incorrect zlib compressed data!"); + + else + CCLOG(@"cocos2d: ZipUtils: Unknown error while decompressing map data!"); + + free(*out); + *out = NULL; + outLength = 0; + } + + return outLength; +} + +int ccInflateMemory(unsigned char *in, unsigned int inLength, unsigned char **out) +{ + // 256k for hint + return ccInflateMemoryWithHint(in, inLength, out, 256 * 1024 ); +} + +int ccInflateGZipFile(const char *path, unsigned char **out) +{ + int len; + unsigned int offset = 0; + + NSCAssert( out, @"ccInflateGZipFile: invalid 'out' parameter"); + NSCAssert( &*out, @"ccInflateGZipFile: invalid 'out' parameter"); + + gzFile inFile = gzopen(path, "rb"); + if( inFile == NULL ) { + CCLOG(@"cocos2d: ZipUtils: error open gzip file: %s", path); + return -1; + } + + /* 512k initial decompress buffer */ + int bufferSize = 512 * 1024; + unsigned int totalBufferSize = bufferSize; + + *out = malloc( bufferSize ); + if( ! out ) { + CCLOG(@"cocos2d: ZipUtils: out of memory"); + return -1; + } + + for (;;) { + len = gzread(inFile, *out + offset, bufferSize); + if (len < 0) { + CCLOG(@"cocos2d: ZipUtils: error in gzread"); + free( *out ); + *out = NULL; + return -1; + } + if (len == 0) + break; + + offset += len; + + // finish reading the file + if( len < bufferSize ) + break; + + bufferSize *= BUFFER_INC_FACTOR; + totalBufferSize += bufferSize; + unsigned char *tmp = realloc(*out, totalBufferSize ); + + if( ! tmp ) { + CCLOG(@"cocos2d: ZipUtils: out of memory"); + free( *out ); + *out = NULL; + return -1; + } + + *out = tmp; + } + + if (gzclose(inFile) != Z_OK) + CCLOG(@"cocos2d: ZipUtils: gzclose failed"); + + return offset; +} + +int ccInflateCCZFile(const char *path, unsigned char **out) +{ + NSCAssert( out, @"ccInflateCCZFile: invalid 'out' parameter"); + NSCAssert( &*out, @"ccInflateCCZFile: invalid 'out' parameter"); + + // load file into memory + unsigned char *compressed = NULL; + NSInteger fileLen = ccLoadFileIntoMemory( path, &compressed ); + if( fileLen < 0 ) { + CCLOG(@"cocos2d: Error loading CCZ compressed file"); + } + + struct CCZHeader *header = (struct CCZHeader*) compressed; + + // verify header + if( header->sig[0] != 'C' || header->sig[1] != 'C' || header->sig[2] != 'Z' || header->sig[3] != '!' ) { + CCLOG(@"cocos2d: Invalid CCZ file"); + free(compressed); + return -1; + } + + // verify header version + uint16_t version = CFSwapInt16BigToHost( header->version ); + if( version > 2 ) { + CCLOG(@"cocos2d: Unsupported CCZ header format"); + free(compressed); + return -1; + } + + // verify compression format + if( CFSwapInt16BigToHost(header->compression_type) != CCZ_COMPRESSION_ZLIB ) { + CCLOG(@"cocos2d: CCZ Unsupported compression method"); + free(compressed); + return -1; + } + + uint32_t len = CFSwapInt32BigToHost( header->len ); + + *out = malloc( len ); + if(! *out ) + { + CCLOG(@"cocos2d: CCZ: Failed to allocate memory for texture"); + free(compressed); + return -1; + } + + + uLongf destlen = len; + uLongf source = (uLongf) compressed + sizeof(*header); + int ret = uncompress(*out, &destlen, (Bytef*)source, fileLen - sizeof(*header) ); + + free( compressed ); + + if( ret != Z_OK ) + { + CCLOG(@"cocos2d: CCZ: Failed to uncompress data"); + free( *out ); + *out = NULL; + return -1; + } + + + return len; +} diff --git a/tweejump/libs/cocos2d/Support/base64.c b/tweejump/libs/cocos2d/Support/base64.c new file mode 100755 index 0000000..9aa52a6 --- /dev/null +++ b/tweejump/libs/cocos2d/Support/base64.c @@ -0,0 +1,93 @@ +/* + public domain BASE64 code + + modified for cocos2d-iphone: http://www.cocos2d-iphone.org + */ + +#include +#include + +#include "base64.h" + +unsigned char alphabet[64] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + +int _base64Decode( unsigned char *input, unsigned int input_len, unsigned char *output, unsigned int *output_len ); + +int _base64Decode( unsigned char *input, unsigned int input_len, unsigned char *output, unsigned int *output_len ) +{ + static char inalphabet[256], decoder[256]; + int i, bits, c, char_count, errors = 0; + unsigned int input_idx = 0; + unsigned int output_idx = 0; + + for (i = (sizeof alphabet) - 1; i >= 0 ; i--) { + inalphabet[alphabet[i]] = 1; + decoder[alphabet[i]] = i; + } + + char_count = 0; + bits = 0; + for( input_idx=0; input_idx < input_len ; input_idx++ ) { + c = input[ input_idx ]; + if (c == '=') + break; + if (c > 255 || ! inalphabet[c]) + continue; + bits += decoder[c]; + char_count++; + if (char_count == 4) { + output[ output_idx++ ] = (bits >> 16); + output[ output_idx++ ] = ((bits >> 8) & 0xff); + output[ output_idx++ ] = ( bits & 0xff); + bits = 0; + char_count = 0; + } else { + bits <<= 6; + } + } + + if( c == '=' ) { + switch (char_count) { + case 1: + fprintf(stderr, "base64Decode: encoding incomplete: at least 2 bits missing"); + errors++; + break; + case 2: + output[ output_idx++ ] = ( bits >> 10 ); + break; + case 3: + output[ output_idx++ ] = ( bits >> 16 ); + output[ output_idx++ ] = (( bits >> 8 ) & 0xff); + break; + } + } else if ( input_idx < input_len ) { + if (char_count) { + fprintf(stderr, "base64 encoding incomplete: at least %d bits truncated", + ((4 - char_count) * 6)); + errors++; + } + } + + *output_len = output_idx; + return errors; +} + +int base64Decode(unsigned char *in, unsigned int inLength, unsigned char **out) +{ + unsigned int outLength = 0; + + //should be enough to store 6-bit buffers in 8-bit buffers + *out = malloc( inLength * 3.0f / 4.0f + 1 ); + if( *out ) { + int ret = _base64Decode(in, inLength, *out, &outLength); + + if (ret > 0 ) + { + printf("Base64Utils: error decoding"); + free(*out); + *out = NULL; + outLength = 0; + } + } + return outLength; +} diff --git a/tweejump/libs/cocos2d/Support/base64.h b/tweejump/libs/cocos2d/Support/base64.h new file mode 100755 index 0000000..d30878e --- /dev/null +++ b/tweejump/libs/cocos2d/Support/base64.h @@ -0,0 +1,33 @@ +/* + public domain BASE64 code + + modified for cocos2d-iphone: http://www.cocos2d-iphone.org + */ + +#ifndef __CC_BASE64_DECODE_H +#define __CC_BASE64_DECODE_H + +#ifdef __cplusplus +extern "C" { +#endif + + +/** @file + base64 helper functions + */ + +/** + * Decodes a 64base encoded memory. The decoded memory is + * expected to be freed by the caller. + * + * @returns the length of the out buffer + * + @since v0.8.1 + */ +int base64Decode(unsigned char *in, unsigned int inLength, unsigned char **out); + +#ifdef __cplusplus +} +#endif + +#endif // __CC_BASE64_DECODE_H diff --git a/tweejump/libs/cocos2d/Support/ccCArray.h b/tweejump/libs/cocos2d/Support/ccCArray.h new file mode 100755 index 0000000..20d9633 --- /dev/null +++ b/tweejump/libs/cocos2d/Support/ccCArray.h @@ -0,0 +1,447 @@ +/* Copyright (c) 2007 Scott Lembcke + * + * 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. + */ + +/** + @file + Based on Chipmunk cpArray. + ccArray is a faster alternative to NSMutableArray, it does pretty much the + same thing (stores NSObjects and retains/releases them appropriately). It's + faster because: + - it uses a plain C interface so it doesn't incur Objective-c messaging overhead + - it assumes you know what you're doing, so it doesn't spend time on safety checks + (index out of bounds, required capacity etc.) + - comparisons are done using pointer equality instead of isEqual + + There are 2 kind of functions: + - ccArray functions that manipulates objective-c objects (retain and release are performanced) + - ccCArray functions that manipulates values like if they were standard C structures (no retain/release is performed) + */ + +#ifndef CC_ARRAY_H +#define CC_ARRAY_H + +#import + +#import +#import + + +#pragma mark - +#pragma mark ccArray for Objects + +// Easy integration +#define CCARRAYDATA_FOREACH(__array__, __object__) \ +__object__=__array__->arr[0]; for(NSUInteger i=0, num=__array__->num; iarr[i]) \ + + +typedef struct ccArray { + NSUInteger num, max; + id *arr; +} ccArray; + +/** Allocates and initializes a new array with specified capacity */ +static inline ccArray* ccArrayNew(NSUInteger capacity) { + if (capacity == 0) + capacity = 1; + + ccArray *arr = (ccArray*)malloc( sizeof(ccArray) ); + arr->num = 0; + arr->arr = (id*) malloc( capacity * sizeof(id) ); + arr->max = capacity; + + return arr; +} + +static inline void ccArrayRemoveAllObjects(ccArray *arr); + +/** Frees array after removing all remaining objects. Silently ignores nil arr. */ +static inline void ccArrayFree(ccArray *arr) +{ + if( arr == nil ) return; + + ccArrayRemoveAllObjects(arr); + + free(arr->arr); + free(arr); +} + +/** Doubles array capacity */ +static inline void ccArrayDoubleCapacity(ccArray *arr) +{ + arr->max *= 2; + id *newArr = (id *)realloc( arr->arr, arr->max * sizeof(id) ); + // will fail when there's not enough memory + NSCAssert(newArr != NULL, @"ccArrayDoubleCapacity failed. Not enough memory"); + arr->arr = newArr; +} + +/** Increases array capacity such that max >= num + extra. */ +static inline void ccArrayEnsureExtraCapacity(ccArray *arr, NSUInteger extra) +{ + while (arr->max < arr->num + extra) + ccArrayDoubleCapacity(arr); +} + +/** shrinks the array so the memory footprint corresponds with the number of items */ +static inline void ccArrayShrink(ccArray *arr) +{ + NSUInteger newSize; + + //only resize when necessary + if (arr->max > arr->num && !(arr->num==0 && arr->max==1)) + { + if (arr->num!=0) + { + newSize=arr->num; + arr->max=arr->num; + } + else + {//minimum capacity of 1, with 0 elements the array would be free'd by realloc + newSize=1; + arr->max=1; + } + + arr->arr = (id*) realloc(arr->arr,newSize * sizeof(id) ); + NSCAssert(arr->arr!=NULL,@"could not reallocate the memory"); + } +} + +/** Returns index of first occurence of object, NSNotFound if object not found. */ +static inline NSUInteger ccArrayGetIndexOfObject(ccArray *arr, id object) +{ + for( NSUInteger i = 0; i < arr->num; i++) + if( arr->arr[i] == object ) return i; + + return NSNotFound; +} + +/** Returns a Boolean value that indicates whether object is present in array. */ +static inline BOOL ccArrayContainsObject(ccArray *arr, id object) +{ + return ccArrayGetIndexOfObject(arr, object) != NSNotFound; +} + +/** Appends an object. Bahaviour undefined if array doesn't have enough capacity. */ +static inline void ccArrayAppendObject(ccArray *arr, id object) +{ + arr->arr[arr->num] = [object retain]; + arr->num++; +} + +/** Appends an object. Capacity of arr is increased if needed. */ +static inline void ccArrayAppendObjectWithResize(ccArray *arr, id object) +{ + ccArrayEnsureExtraCapacity(arr, 1); + ccArrayAppendObject(arr, object); +} + +/** Appends objects from plusArr to arr. Behaviour undefined if arr doesn't have + enough capacity. */ +static inline void ccArrayAppendArray(ccArray *arr, ccArray *plusArr) +{ + for( NSUInteger i = 0; i < plusArr->num; i++) + ccArrayAppendObject(arr, plusArr->arr[i]); +} + +/** Appends objects from plusArr to arr. Capacity of arr is increased if needed. */ +static inline void ccArrayAppendArrayWithResize(ccArray *arr, ccArray *plusArr) +{ + ccArrayEnsureExtraCapacity(arr, plusArr->num); + ccArrayAppendArray(arr, plusArr); +} + +/** Inserts an object at index */ +static inline void ccArrayInsertObjectAtIndex(ccArray *arr, id object, NSUInteger index) +{ + NSCAssert(index<=arr->num, @"Invalid index. Out of bounds"); + + ccArrayEnsureExtraCapacity(arr, 1); + + NSUInteger remaining = arr->num - index; + if( remaining > 0) + memmove(&arr->arr[index+1], &arr->arr[index], sizeof(id) * remaining ); + + arr->arr[index] = [object retain]; + arr->num++; +} + +/** Swaps two objects */ +static inline void ccArraySwapObjectsAtIndexes(ccArray *arr, NSUInteger index1, NSUInteger index2) +{ + NSCAssert(index1 < arr->num, @"(1) Invalid index. Out of bounds"); + NSCAssert(index2 < arr->num, @"(2) Invalid index. Out of bounds"); + + id object1 = arr->arr[index1]; + + arr->arr[index1] = arr->arr[index2]; + arr->arr[index2] = object1; +} + +/** Removes all objects from arr */ +static inline void ccArrayRemoveAllObjects(ccArray *arr) +{ + while( arr->num > 0 ) + [arr->arr[--arr->num] release]; +} + +/** Removes object at specified index and pushes back all subsequent objects. + Behaviour undefined if index outside [0, num-1]. */ +static inline void ccArrayRemoveObjectAtIndex(ccArray *arr, NSUInteger index) +{ + [arr->arr[index] release]; + arr->num--; + + NSUInteger remaining = arr->num - index; + if(remaining>0) + memmove(&arr->arr[index], &arr->arr[index+1], remaining * sizeof(id)); +} + +/** Removes object at specified index and fills the gap with the last object, + thereby avoiding the need to push back subsequent objects. + Behaviour undefined if index outside [0, num-1]. */ +static inline void ccArrayFastRemoveObjectAtIndex(ccArray *arr, NSUInteger index) +{ + [arr->arr[index] release]; + NSUInteger last = --arr->num; + arr->arr[index] = arr->arr[last]; +} + +static inline void ccArrayFastRemoveObject(ccArray *arr, id object) +{ + NSUInteger index = ccArrayGetIndexOfObject(arr, object); + if (index != NSNotFound) + ccArrayFastRemoveObjectAtIndex(arr, index); +} + +/** Searches for the first occurance of object and removes it. If object is not + found the function has no effect. */ +static inline void ccArrayRemoveObject(ccArray *arr, id object) +{ + NSUInteger index = ccArrayGetIndexOfObject(arr, object); + if (index != NSNotFound) + ccArrayRemoveObjectAtIndex(arr, index); +} + +/** Removes from arr all objects in minusArr. For each object in minusArr, the + first matching instance in arr will be removed. */ +static inline void ccArrayRemoveArray(ccArray *arr, ccArray *minusArr) +{ + for( NSUInteger i = 0; i < minusArr->num; i++) + ccArrayRemoveObject(arr, minusArr->arr[i]); +} + +/** Removes from arr all objects in minusArr. For each object in minusArr, all + matching instances in arr will be removed. */ +static inline void ccArrayFullRemoveArray(ccArray *arr, ccArray *minusArr) +{ + NSUInteger back = 0; + + for( NSUInteger i = 0; i < arr->num; i++) { + if( ccArrayContainsObject(minusArr, arr->arr[i]) ) { + [arr->arr[i] release]; + back++; + } else + arr->arr[i - back] = arr->arr[i]; + } + + arr->num -= back; +} + +/** Sends to each object in arr the message identified by given selector. */ +static inline void ccArrayMakeObjectsPerformSelector(ccArray *arr, SEL sel) +{ + for( NSUInteger i = 0; i < arr->num; i++) + [arr->arr[i] performSelector:sel]; +} + +static inline void ccArrayMakeObjectsPerformSelectorWithObject(ccArray *arr, SEL sel, id object) +{ + for( NSUInteger i = 0; i < arr->num; i++) + [arr->arr[i] performSelector:sel withObject:object]; +} + + +#pragma mark - +#pragma mark ccCArray for Values (c structures) + +typedef ccArray ccCArray; + +static inline void ccCArrayRemoveAllValues(ccCArray *arr); + +/** Allocates and initializes a new C array with specified capacity */ +static inline ccCArray* ccCArrayNew(NSUInteger capacity) { + if (capacity == 0) + capacity = 1; + + ccCArray *arr = (ccCArray*)malloc( sizeof(ccCArray) ); + arr->num = 0; + arr->arr = (id*) malloc( capacity * sizeof(id) ); + arr->max = capacity; + + return arr; +} + +/** Frees C array after removing all remaining values. Silently ignores nil arr. */ +static inline void ccCArrayFree(ccCArray *arr) +{ + if( arr == nil ) return; + + ccCArrayRemoveAllValues(arr); + + free(arr->arr); + free(arr); +} + +/** Doubles C array capacity */ +static inline void ccCArrayDoubleCapacity(ccCArray *arr) +{ + ccArrayDoubleCapacity(arr); +} + +/** Increases array capacity such that max >= num + extra. */ +static inline void ccCArrayEnsureExtraCapacity(ccCArray *arr, NSUInteger extra) +{ + ccArrayEnsureExtraCapacity(arr,extra); +} + +/** Returns index of first occurence of value, NSNotFound if value not found. */ +static inline NSUInteger ccCArrayGetIndexOfValue(ccCArray *arr, void* value) +{ + for( NSUInteger i = 0; i < arr->num; i++) + if( arr->arr[i] == value ) return i; + return NSNotFound; +} + +/** Returns a Boolean value that indicates whether value is present in the C array. */ +static inline BOOL ccCArrayContainsValue(ccCArray *arr, void* value) +{ + return ccCArrayGetIndexOfValue(arr, value) != NSNotFound; +} + +/** Inserts a value at a certain position. Behaviour undefined if aray doesn't have enough capacity */ +static inline void ccCArrayInsertValueAtIndex( ccCArray *arr, void *value, NSUInteger index) +{ + NSCAssert( index < arr->max, @"ccCArrayInsertValueAtIndex: invalid index"); + + NSUInteger remaining = arr->num - index; + + // last Value doesn't need to be moved + if( remaining > 0) { + // tex coordinates + memmove( &arr->arr[index+1],&arr->arr[index], sizeof(void*) * remaining ); + } + + arr->num++; + arr->arr[index] = (id) value; +} + +/** Appends an value. Bahaviour undefined if array doesn't have enough capacity. */ +static inline void ccCArrayAppendValue(ccCArray *arr, void* value) +{ + arr->arr[arr->num] = (id) value; + arr->num++; +} + +/** Appends an value. Capacity of arr is increased if needed. */ +static inline void ccCArrayAppendValueWithResize(ccCArray *arr, void* value) +{ + ccCArrayEnsureExtraCapacity(arr, 1); + ccCArrayAppendValue(arr, value); +} + +/** Appends values from plusArr to arr. Behaviour undefined if arr doesn't have + enough capacity. */ +static inline void ccCArrayAppendArray(ccCArray *arr, ccCArray *plusArr) +{ + for( NSUInteger i = 0; i < plusArr->num; i++) + ccCArrayAppendValue(arr, plusArr->arr[i]); +} + +/** Appends values from plusArr to arr. Capacity of arr is increased if needed. */ +static inline void ccCArrayAppendArrayWithResize(ccCArray *arr, ccCArray *plusArr) +{ + ccCArrayEnsureExtraCapacity(arr, plusArr->num); + ccCArrayAppendArray(arr, plusArr); +} + +/** Removes all values from arr */ +static inline void ccCArrayRemoveAllValues(ccCArray *arr) +{ + arr->num = 0; +} + +/** Removes value at specified index and pushes back all subsequent values. + Behaviour undefined if index outside [0, num-1]. + @since v0.99.4 + */ +static inline void ccCArrayRemoveValueAtIndex(ccCArray *arr, NSUInteger index) +{ + for( NSUInteger last = --arr->num; index < last; index++) + arr->arr[index] = arr->arr[index + 1]; +} + +/** Removes value at specified index and fills the gap with the last value, + thereby avoiding the need to push back subsequent values. + Behaviour undefined if index outside [0, num-1]. + @since v0.99.4 + */ +static inline void ccCArrayFastRemoveValueAtIndex(ccCArray *arr, NSUInteger index) +{ + NSUInteger last = --arr->num; + arr->arr[index] = arr->arr[last]; +} + +/** Searches for the first occurance of value and removes it. If value is not found the function has no effect. + @since v0.99.4 + */ +static inline void ccCArrayRemoveValue(ccCArray *arr, void* value) +{ + NSUInteger index = ccCArrayGetIndexOfValue(arr, value); + if (index != NSNotFound) + ccCArrayRemoveValueAtIndex(arr, index); +} + +/** Removes from arr all values in minusArr. For each Value in minusArr, the first matching instance in arr will be removed. + @since v0.99.4 + */ +static inline void ccCArrayRemoveArray(ccCArray *arr, ccCArray *minusArr) +{ + for( NSUInteger i = 0; i < minusArr->num; i++) + ccCArrayRemoveValue(arr, minusArr->arr[i]); +} + +/** Removes from arr all values in minusArr. For each value in minusArr, all matching instances in arr will be removed. + @since v0.99.4 + */ +static inline void ccCArrayFullRemoveArray(ccCArray *arr, ccCArray *minusArr) +{ + NSUInteger back = 0; + + for( NSUInteger i = 0; i < arr->num; i++) { + if( ccCArrayContainsValue(minusArr, arr->arr[i]) ) { + back++; + } else + arr->arr[i - back] = arr->arr[i]; + } + + arr->num -= back; +} +#endif // CC_ARRAY_H diff --git a/tweejump/libs/cocos2d/Support/ccUtils.c b/tweejump/libs/cocos2d/Support/ccUtils.c new file mode 100755 index 0000000..39786ec --- /dev/null +++ b/tweejump/libs/cocos2d/Support/ccUtils.c @@ -0,0 +1,20 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + */ + +/* + ccNextPOT function is licensed under the same license that is used in CCTexture2D.m. + */ +#include "ccUtils.h" + +unsigned long ccNextPOT(unsigned long x) +{ + x = x - 1; + x = x | (x >> 1); + x = x | (x >> 2); + x = x | (x >> 4); + x = x | (x >> 8); + x = x | (x >>16); + return x + 1; +} \ No newline at end of file diff --git a/tweejump/libs/cocos2d/Support/ccUtils.h b/tweejump/libs/cocos2d/Support/ccUtils.h new file mode 100755 index 0000000..783fc54 --- /dev/null +++ b/tweejump/libs/cocos2d/Support/ccUtils.h @@ -0,0 +1,29 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + */ + +#ifndef __CC_UTILS_H +#define __CC_UTILS_H + +/** @file ccUtils.h + Misc free functions + */ + +/* + ccNextPOT function is licensed under the same license that is used in CCTexture2D.m. + */ + +/** returns the Next Power of Two value. + + Examples: + - If "value" is 15, it will return 16. + - If "value" is 16, it will return 16. + - If "value" is 17, it will return 32. + + @since v0.99.5 + */ + +unsigned long ccNextPOT( unsigned long value ); + +#endif // ! __CC_UTILS_H diff --git a/tweejump/libs/cocos2d/Support/uthash.h b/tweejump/libs/cocos2d/Support/uthash.h new file mode 100755 index 0000000..a4bdc18 --- /dev/null +++ b/tweejump/libs/cocos2d/Support/uthash.h @@ -0,0 +1,972 @@ +/* +Copyright (c) 2003-2010, Troy D. Hanson http://uthash.sourceforge.net +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS +IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A +PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER +OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef UTHASH_H +#define UTHASH_H + +#include /* memcmp,strlen */ +#include /* ptrdiff_t */ + +/* These macros use decltype or the earlier __typeof GNU extension. + As decltype is only available in newer compilers (VS2010 or gcc 4.3+ + when compiling c++ source) this code uses whatever method is needed + or, for VS2008 where neither is available, uses casting workarounds. */ +#ifdef _MSC_VER /* MS compiler */ +#if _MSC_VER >= 1600 && defined(__cplusplus) /* VS2010 or newer in C++ mode */ +#define DECLTYPE(x) (decltype(x)) +#else /* VS2008 or older (or VS2010 in C mode) */ +#define NO_DECLTYPE +#define DECLTYPE(x) +#endif +#else /* GNU, Sun and other compilers */ +#define DECLTYPE(x) (__typeof(x)) +#endif + +#ifdef NO_DECLTYPE +#define DECLTYPE_ASSIGN(dst,src) \ +do { \ + char **_da_dst = (char**)(&(dst)); \ + *_da_dst = (char*)(src); \ +} while(0) +#else +#define DECLTYPE_ASSIGN(dst,src) \ +do { \ + (dst) = DECLTYPE(dst)(src); \ +} while(0) +#endif + +/* a number of the hash function use uint32_t which isn't defined on win32 */ +#ifdef _MSC_VER +typedef unsigned int uint32_t; +#else +#include /* uint32_t */ +#endif + +#define UTHASH_VERSION 1.9.3 + +#define uthash_fatal(msg) exit(-1) /* fatal error (out of memory,etc) */ +#define uthash_malloc(sz) malloc(sz) /* malloc fcn */ +#define uthash_free(ptr,sz) free(ptr) /* free fcn */ + +#define uthash_noexpand_fyi(tbl) /* can be defined to log noexpand */ +#define uthash_expand_fyi(tbl) /* can be defined to log expands */ + +/* initial number of buckets */ +#define HASH_INITIAL_NUM_BUCKETS 32 /* initial number of buckets */ +#define HASH_INITIAL_NUM_BUCKETS_LOG2 5 /* lg2 of initial number of buckets */ +#define HASH_BKT_CAPACITY_THRESH 10 /* expand when bucket count reaches */ + +/* calculate the element whose hash handle address is hhe */ +#define ELMT_FROM_HH(tbl,hhp) ((void*)(((char*)(hhp)) - ((tbl)->hho))) + +#define HASH_FIND(hh,head,keyptr,keylen,out) \ +do { \ + unsigned _hf_bkt,_hf_hashv; \ + out=NULL; \ + if (head) { \ + HASH_FCN(keyptr,keylen, (head)->hh.tbl->num_buckets, _hf_hashv, _hf_bkt); \ + if (HASH_BLOOM_TEST((head)->hh.tbl, _hf_hashv)) { \ + HASH_FIND_IN_BKT((head)->hh.tbl, hh, (head)->hh.tbl->buckets[ _hf_bkt ], \ + keyptr,keylen,out); \ + } \ + } \ +} while (0) + +#ifdef HASH_BLOOM +#define HASH_BLOOM_BITLEN (1ULL << HASH_BLOOM) +#define HASH_BLOOM_BYTELEN (HASH_BLOOM_BITLEN/8) + ((HASH_BLOOM_BITLEN%8) ? 1:0) +#define HASH_BLOOM_MAKE(tbl) \ +do { \ + (tbl)->bloom_nbits = HASH_BLOOM; \ + (tbl)->bloom_bv = (uint8_t*)uthash_malloc(HASH_BLOOM_BYTELEN); \ + if (!((tbl)->bloom_bv)) { uthash_fatal( "out of memory"); } \ + memset((tbl)->bloom_bv, 0, HASH_BLOOM_BYTELEN); \ + (tbl)->bloom_sig = HASH_BLOOM_SIGNATURE; \ +} while (0); + +#define HASH_BLOOM_FREE(tbl) \ +do { \ + uthash_free((tbl)->bloom_bv, HASH_BLOOM_BYTELEN); \ +} while (0); + +#define HASH_BLOOM_BITSET(bv,idx) (bv[(idx)/8] |= (1U << ((idx)%8))) +#define HASH_BLOOM_BITTEST(bv,idx) (bv[(idx)/8] & (1U << ((idx)%8))) + +#define HASH_BLOOM_ADD(tbl,hashv) \ + HASH_BLOOM_BITSET((tbl)->bloom_bv, (hashv & (uint32_t)((1ULL << (tbl)->bloom_nbits) - 1))) + +#define HASH_BLOOM_TEST(tbl,hashv) \ + HASH_BLOOM_BITTEST((tbl)->bloom_bv, (hashv & (uint32_t)((1ULL << (tbl)->bloom_nbits) - 1))) + +#else +#define HASH_BLOOM_MAKE(tbl) +#define HASH_BLOOM_FREE(tbl) +#define HASH_BLOOM_ADD(tbl,hashv) +#define HASH_BLOOM_TEST(tbl,hashv) (1) +#endif + +#define HASH_MAKE_TABLE(hh,head) \ +do { \ + (head)->hh.tbl = (UT_hash_table*)uthash_malloc( \ + sizeof(UT_hash_table)); \ + if (!((head)->hh.tbl)) { uthash_fatal( "out of memory"); } \ + memset((head)->hh.tbl, 0, sizeof(UT_hash_table)); \ + (head)->hh.tbl->tail = &((head)->hh); \ + (head)->hh.tbl->num_buckets = HASH_INITIAL_NUM_BUCKETS; \ + (head)->hh.tbl->log2_num_buckets = HASH_INITIAL_NUM_BUCKETS_LOG2; \ + (head)->hh.tbl->hho = (char*)(&(head)->hh) - (char*)(head); \ + (head)->hh.tbl->buckets = (UT_hash_bucket*)uthash_malloc( \ + HASH_INITIAL_NUM_BUCKETS*sizeof(struct UT_hash_bucket)); \ + if (! (head)->hh.tbl->buckets) { uthash_fatal( "out of memory"); } \ + memset((head)->hh.tbl->buckets, 0, \ + HASH_INITIAL_NUM_BUCKETS*sizeof(struct UT_hash_bucket)); \ + HASH_BLOOM_MAKE((head)->hh.tbl); \ + (head)->hh.tbl->signature = HASH_SIGNATURE; \ +} while(0) + +#define HASH_ADD(hh,head,fieldname,keylen_in,add) \ + HASH_ADD_KEYPTR(hh,head,&add->fieldname,keylen_in,add) + +#define HASH_ADD_KEYPTR(hh,head,keyptr,keylen_in,add) \ +do { \ + unsigned _ha_bkt; \ + (add)->hh.next = NULL; \ + (add)->hh.key = (char*)keyptr; \ + (add)->hh.keylen = keylen_in; \ + if (!(head)) { \ + head = (add); \ + (head)->hh.prev = NULL; \ + HASH_MAKE_TABLE(hh,head); \ + } else { \ + (head)->hh.tbl->tail->next = (add); \ + (add)->hh.prev = ELMT_FROM_HH((head)->hh.tbl, (head)->hh.tbl->tail); \ + (head)->hh.tbl->tail = &((add)->hh); \ + } \ + (head)->hh.tbl->num_items++; \ + (add)->hh.tbl = (head)->hh.tbl; \ + HASH_FCN(keyptr,keylen_in, (head)->hh.tbl->num_buckets, \ + (add)->hh.hashv, _ha_bkt); \ + HASH_ADD_TO_BKT((head)->hh.tbl->buckets[_ha_bkt],&(add)->hh); \ + HASH_BLOOM_ADD((head)->hh.tbl,(add)->hh.hashv); \ + HASH_EMIT_KEY(hh,head,keyptr,keylen_in); \ + HASH_FSCK(hh,head); \ +} while(0) + +#define HASH_TO_BKT( hashv, num_bkts, bkt ) \ +do { \ + bkt = ((hashv) & ((num_bkts) - 1)); \ +} while(0) + +/* delete "delptr" from the hash table. + * "the usual" patch-up process for the app-order doubly-linked-list. + * The use of _hd_hh_del below deserves special explanation. + * These used to be expressed using (delptr) but that led to a bug + * if someone used the same symbol for the head and deletee, like + * HASH_DELETE(hh,users,users); + * We want that to work, but by changing the head (users) below + * we were forfeiting our ability to further refer to the deletee (users) + * in the patch-up process. Solution: use scratch space to + * copy the deletee pointer, then the latter references are via that + * scratch pointer rather than through the repointed (users) symbol. + */ +#define HASH_DELETE(hh,head,delptr) \ +do { \ + unsigned _hd_bkt; \ + struct UT_hash_handle *_hd_hh_del; \ + if ( ((delptr)->hh.prev == NULL) && ((delptr)->hh.next == NULL) ) { \ + uthash_free((head)->hh.tbl->buckets, \ + (head)->hh.tbl->num_buckets*sizeof(struct UT_hash_bucket) ); \ + HASH_BLOOM_FREE((head)->hh.tbl); \ + uthash_free((head)->hh.tbl, sizeof(UT_hash_table)); \ + head = NULL; \ + } else { \ + _hd_hh_del = &((delptr)->hh); \ + if ((delptr) == ELMT_FROM_HH((head)->hh.tbl,(head)->hh.tbl->tail)) { \ + (head)->hh.tbl->tail = \ + (UT_hash_handle*)((char*)((delptr)->hh.prev) + \ + (head)->hh.tbl->hho); \ + } \ + if ((delptr)->hh.prev) { \ + ((UT_hash_handle*)((char*)((delptr)->hh.prev) + \ + (head)->hh.tbl->hho))->next = (delptr)->hh.next; \ + } else { \ + DECLTYPE_ASSIGN(head,(delptr)->hh.next); \ + } \ + if (_hd_hh_del->next) { \ + ((UT_hash_handle*)((char*)_hd_hh_del->next + \ + (head)->hh.tbl->hho))->prev = \ + _hd_hh_del->prev; \ + } \ + HASH_TO_BKT( _hd_hh_del->hashv, (head)->hh.tbl->num_buckets, _hd_bkt); \ + HASH_DEL_IN_BKT(hh,(head)->hh.tbl->buckets[_hd_bkt], _hd_hh_del); \ + (head)->hh.tbl->num_items--; \ + } \ + HASH_FSCK(hh,head); \ +} while (0) + + +/* convenience forms of HASH_FIND/HASH_ADD/HASH_DEL */ +#define HASH_FIND_STR(head,findstr,out) \ + HASH_FIND(hh,head,findstr,strlen(findstr),out) +#define HASH_ADD_STR(head,strfield,add) \ + HASH_ADD(hh,head,strfield,strlen(add->strfield),add) +#define HASH_FIND_INT(head,findint,out) \ + HASH_FIND(hh,head,findint,sizeof(int),out) +#define HASH_ADD_INT(head,intfield,add) \ + HASH_ADD(hh,head,intfield,sizeof(int),add) +#define HASH_FIND_PTR(head,findptr,out) \ + HASH_FIND(hh,head,findptr,sizeof(void *),out) +#define HASH_ADD_PTR(head,ptrfield,add) \ + HASH_ADD(hh,head,ptrfield,sizeof(void *),add) +#define HASH_DEL(head,delptr) \ + HASH_DELETE(hh,head,delptr) + +/* HASH_FSCK checks hash integrity on every add/delete when HASH_DEBUG is defined. + * This is for uthash developer only; it compiles away if HASH_DEBUG isn't defined. + */ +#ifdef HASH_DEBUG +#define HASH_OOPS(...) do { fprintf(stderr,__VA_ARGS__); exit(-1); } while (0) +#define HASH_FSCK(hh,head) \ +do { \ + unsigned _bkt_i; \ + unsigned _count, _bkt_count; \ + char *_prev; \ + struct UT_hash_handle *_thh; \ + if (head) { \ + _count = 0; \ + for( _bkt_i = 0; _bkt_i < (head)->hh.tbl->num_buckets; _bkt_i++) { \ + _bkt_count = 0; \ + _thh = (head)->hh.tbl->buckets[_bkt_i].hh_head; \ + _prev = NULL; \ + while (_thh) { \ + if (_prev != (char*)(_thh->hh_prev)) { \ + HASH_OOPS("invalid hh_prev %p, actual %p\n", \ + _thh->hh_prev, _prev ); \ + } \ + _bkt_count++; \ + _prev = (char*)(_thh); \ + _thh = _thh->hh_next; \ + } \ + _count += _bkt_count; \ + if ((head)->hh.tbl->buckets[_bkt_i].count != _bkt_count) { \ + HASH_OOPS("invalid bucket count %d, actual %d\n", \ + (head)->hh.tbl->buckets[_bkt_i].count, _bkt_count); \ + } \ + } \ + if (_count != (head)->hh.tbl->num_items) { \ + HASH_OOPS("invalid hh item count %d, actual %d\n", \ + (head)->hh.tbl->num_items, _count ); \ + } \ + /* traverse hh in app order; check next/prev integrity, count */ \ + _count = 0; \ + _prev = NULL; \ + _thh = &(head)->hh; \ + while (_thh) { \ + _count++; \ + if (_prev !=(char*)(_thh->prev)) { \ + HASH_OOPS("invalid prev %p, actual %p\n", \ + _thh->prev, _prev ); \ + } \ + _prev = (char*)ELMT_FROM_HH((head)->hh.tbl, _thh); \ + _thh = ( _thh->next ? (UT_hash_handle*)((char*)(_thh->next) + \ + (head)->hh.tbl->hho) : NULL ); \ + } \ + if (_count != (head)->hh.tbl->num_items) { \ + HASH_OOPS("invalid app item count %d, actual %d\n", \ + (head)->hh.tbl->num_items, _count ); \ + } \ + } \ +} while (0) +#else +#define HASH_FSCK(hh,head) +#endif + +/* When compiled with -DHASH_EMIT_KEYS, length-prefixed keys are emitted to + * the descriptor to which this macro is defined for tuning the hash function. + * The app can #include to get the prototype for write(2). */ +#ifdef HASH_EMIT_KEYS +#define HASH_EMIT_KEY(hh,head,keyptr,fieldlen) \ +do { \ + unsigned _klen = fieldlen; \ + write(HASH_EMIT_KEYS, &_klen, sizeof(_klen)); \ + write(HASH_EMIT_KEYS, keyptr, fieldlen); \ +} while (0) +#else +#define HASH_EMIT_KEY(hh,head,keyptr,fieldlen) +#endif + +/* default to Jenkin's hash unless overridden e.g. DHASH_FUNCTION=HASH_SAX */ +#ifdef HASH_FUNCTION +#define HASH_FCN HASH_FUNCTION +#else +#define HASH_FCN HASH_JEN +#endif + +/* The Bernstein hash function, used in Perl prior to v5.6 */ +#define HASH_BER(key,keylen,num_bkts,hashv,bkt) \ +do { \ + unsigned _hb_keylen=keylen; \ + char *_hb_key=(char*)(key); \ + (hashv) = 0; \ + while (_hb_keylen--) { (hashv) = ((hashv) * 33) + *_hb_key++; } \ + bkt = (hashv) & (num_bkts-1); \ +} while (0) + + +/* SAX/FNV/OAT/JEN hash functions are macro variants of those listed at + * http://eternallyconfuzzled.com/tuts/algorithms/jsw_tut_hashing.aspx */ +#define HASH_SAX(key,keylen,num_bkts,hashv,bkt) \ +do { \ + unsigned _sx_i; \ + char *_hs_key=(char*)(key); \ + hashv = 0; \ + for(_sx_i=0; _sx_i < keylen; _sx_i++) \ + hashv ^= (hashv << 5) + (hashv >> 2) + _hs_key[_sx_i]; \ + bkt = hashv & (num_bkts-1); \ +} while (0) + +#define HASH_FNV(key,keylen,num_bkts,hashv,bkt) \ +do { \ + unsigned _fn_i; \ + char *_hf_key=(char*)(key); \ + hashv = 2166136261UL; \ + for(_fn_i=0; _fn_i < keylen; _fn_i++) \ + hashv = (hashv * 16777619) ^ _hf_key[_fn_i]; \ + bkt = hashv & (num_bkts-1); \ +} while(0); + +#define HASH_OAT(key,keylen,num_bkts,hashv,bkt) \ +do { \ + unsigned _ho_i; \ + char *_ho_key=(char*)(key); \ + hashv = 0; \ + for(_ho_i=0; _ho_i < keylen; _ho_i++) { \ + hashv += _ho_key[_ho_i]; \ + hashv += (hashv << 10); \ + hashv ^= (hashv >> 6); \ + } \ + hashv += (hashv << 3); \ + hashv ^= (hashv >> 11); \ + hashv += (hashv << 15); \ + bkt = hashv & (num_bkts-1); \ +} while(0) + +#define HASH_JEN_MIX(a,b,c) \ +do { \ + a -= b; a -= c; a ^= ( c >> 13 ); \ + b -= c; b -= a; b ^= ( a << 8 ); \ + c -= a; c -= b; c ^= ( b >> 13 ); \ + a -= b; a -= c; a ^= ( c >> 12 ); \ + b -= c; b -= a; b ^= ( a << 16 ); \ + c -= a; c -= b; c ^= ( b >> 5 ); \ + a -= b; a -= c; a ^= ( c >> 3 ); \ + b -= c; b -= a; b ^= ( a << 10 ); \ + c -= a; c -= b; c ^= ( b >> 15 ); \ +} while (0) + +#define HASH_JEN(key,keylen,num_bkts,hashv,bkt) \ +do { \ + unsigned _hj_i,_hj_j,_hj_k; \ + char *_hj_key=(char*)(key); \ + hashv = 0xfeedbeef; \ + _hj_i = _hj_j = 0x9e3779b9; \ + _hj_k = keylen; \ + while (_hj_k >= 12) { \ + _hj_i += (_hj_key[0] + ( (unsigned)_hj_key[1] << 8 ) \ + + ( (unsigned)_hj_key[2] << 16 ) \ + + ( (unsigned)_hj_key[3] << 24 ) ); \ + _hj_j += (_hj_key[4] + ( (unsigned)_hj_key[5] << 8 ) \ + + ( (unsigned)_hj_key[6] << 16 ) \ + + ( (unsigned)_hj_key[7] << 24 ) ); \ + hashv += (_hj_key[8] + ( (unsigned)_hj_key[9] << 8 ) \ + + ( (unsigned)_hj_key[10] << 16 ) \ + + ( (unsigned)_hj_key[11] << 24 ) ); \ + \ + HASH_JEN_MIX(_hj_i, _hj_j, hashv); \ + \ + _hj_key += 12; \ + _hj_k -= 12; \ + } \ + hashv += keylen; \ + switch ( _hj_k ) { \ + case 11: hashv += ( (unsigned)_hj_key[10] << 24 ); \ + case 10: hashv += ( (unsigned)_hj_key[9] << 16 ); \ + case 9: hashv += ( (unsigned)_hj_key[8] << 8 ); \ + case 8: _hj_j += ( (unsigned)_hj_key[7] << 24 ); \ + case 7: _hj_j += ( (unsigned)_hj_key[6] << 16 ); \ + case 6: _hj_j += ( (unsigned)_hj_key[5] << 8 ); \ + case 5: _hj_j += _hj_key[4]; \ + case 4: _hj_i += ( (unsigned)_hj_key[3] << 24 ); \ + case 3: _hj_i += ( (unsigned)_hj_key[2] << 16 ); \ + case 2: _hj_i += ( (unsigned)_hj_key[1] << 8 ); \ + case 1: _hj_i += _hj_key[0]; \ + } \ + HASH_JEN_MIX(_hj_i, _hj_j, hashv); \ + bkt = hashv & (num_bkts-1); \ +} while(0) + +/* The Paul Hsieh hash function */ +#undef get16bits +#if (defined(__GNUC__) && defined(__i386__)) || defined(__WATCOMC__) \ + || defined(_MSC_VER) || defined (__BORLANDC__) || defined (__TURBOC__) +#define get16bits(d) (*((const uint16_t *) (d))) +#endif + +#if !defined (get16bits) +#define get16bits(d) ((((uint32_t)(((const uint8_t *)(d))[1])) << 8) \ + +(uint32_t)(((const uint8_t *)(d))[0]) ) +#endif +#define HASH_SFH(key,keylen,num_bkts,hashv,bkt) \ +do { \ + char *_sfh_key=(char*)(key); \ + uint32_t _sfh_tmp, _sfh_len = keylen; \ + \ + int _sfh_rem = _sfh_len & 3; \ + _sfh_len >>= 2; \ + hashv = 0xcafebabe; \ + \ + /* Main loop */ \ + for (;_sfh_len > 0; _sfh_len--) { \ + hashv += get16bits (_sfh_key); \ + _sfh_tmp = (get16bits (_sfh_key+2) << 11) ^ hashv; \ + hashv = (hashv << 16) ^ _sfh_tmp; \ + _sfh_key += 2*sizeof (uint16_t); \ + hashv += hashv >> 11; \ + } \ + \ + /* Handle end cases */ \ + switch (_sfh_rem) { \ + case 3: hashv += get16bits (_sfh_key); \ + hashv ^= hashv << 16; \ + hashv ^= _sfh_key[sizeof (uint16_t)] << 18; \ + hashv += hashv >> 11; \ + break; \ + case 2: hashv += get16bits (_sfh_key); \ + hashv ^= hashv << 11; \ + hashv += hashv >> 17; \ + break; \ + case 1: hashv += *_sfh_key; \ + hashv ^= hashv << 10; \ + hashv += hashv >> 1; \ + } \ + \ + /* Force "avalanching" of final 127 bits */ \ + hashv ^= hashv << 3; \ + hashv += hashv >> 5; \ + hashv ^= hashv << 4; \ + hashv += hashv >> 17; \ + hashv ^= hashv << 25; \ + hashv += hashv >> 6; \ + bkt = hashv & (num_bkts-1); \ +} while(0); + +#ifdef HASH_USING_NO_STRICT_ALIASING +/* The MurmurHash exploits some CPU's (e.g. x86) tolerance for unaligned reads. + * For other types of CPU's (e.g. Sparc) an unaligned read causes a bus error. + * So MurmurHash comes in two versions, the faster unaligned one and the slower + * aligned one. We only use the faster one on CPU's where we know it's safe. + * + * Note the preprocessor built-in defines can be emitted using: + * + * gcc -m64 -dM -E - < /dev/null (on gcc) + * cc -## a.c (where a.c is a simple test file) (Sun Studio) + */ +#if (defined(__i386__) || defined(__x86_64__)) +#define HASH_MUR HASH_MUR_UNALIGNED +#else +#define HASH_MUR HASH_MUR_ALIGNED +#endif + +/* Appleby's MurmurHash fast version for unaligned-tolerant archs like i386 */ +#define HASH_MUR_UNALIGNED(key,keylen,num_bkts,hashv,bkt) \ +do { \ + const unsigned int _mur_m = 0x5bd1e995; \ + const int _mur_r = 24; \ + hashv = 0xcafebabe ^ keylen; \ + char *_mur_key = (char *)(key); \ + uint32_t _mur_tmp, _mur_len = keylen; \ + \ + for (;_mur_len >= 4; _mur_len-=4) { \ + _mur_tmp = *(uint32_t *)_mur_key; \ + _mur_tmp *= _mur_m; \ + _mur_tmp ^= _mur_tmp >> _mur_r; \ + _mur_tmp *= _mur_m; \ + hashv *= _mur_m; \ + hashv ^= _mur_tmp; \ + _mur_key += 4; \ + } \ + \ + switch(_mur_len) \ + { \ + case 3: hashv ^= _mur_key[2] << 16; \ + case 2: hashv ^= _mur_key[1] << 8; \ + case 1: hashv ^= _mur_key[0]; \ + hashv *= _mur_m; \ + }; \ + \ + hashv ^= hashv >> 13; \ + hashv *= _mur_m; \ + hashv ^= hashv >> 15; \ + \ + bkt = hashv & (num_bkts-1); \ +} while(0) + +/* Appleby's MurmurHash version for alignment-sensitive archs like Sparc */ +#define HASH_MUR_ALIGNED(key,keylen,num_bkts,hashv,bkt) \ +do { \ + const unsigned int _mur_m = 0x5bd1e995; \ + const int _mur_r = 24; \ + hashv = 0xcafebabe ^ (keylen); \ + char *_mur_key = (char *)(key); \ + uint32_t _mur_len = keylen; \ + int _mur_align = (int)_mur_key & 3; \ + \ + if (_mur_align && (_mur_len >= 4)) { \ + unsigned _mur_t = 0, _mur_d = 0; \ + switch(_mur_align) { \ + case 1: _mur_t |= _mur_key[2] << 16; \ + case 2: _mur_t |= _mur_key[1] << 8; \ + case 3: _mur_t |= _mur_key[0]; \ + } \ + _mur_t <<= (8 * _mur_align); \ + _mur_key += 4-_mur_align; \ + _mur_len -= 4-_mur_align; \ + int _mur_sl = 8 * (4-_mur_align); \ + int _mur_sr = 8 * _mur_align; \ + \ + for (;_mur_len >= 4; _mur_len-=4) { \ + _mur_d = *(unsigned *)_mur_key; \ + _mur_t = (_mur_t >> _mur_sr) | (_mur_d << _mur_sl); \ + unsigned _mur_k = _mur_t; \ + _mur_k *= _mur_m; \ + _mur_k ^= _mur_k >> _mur_r; \ + _mur_k *= _mur_m; \ + hashv *= _mur_m; \ + hashv ^= _mur_k; \ + _mur_t = _mur_d; \ + _mur_key += 4; \ + } \ + _mur_d = 0; \ + if(_mur_len >= _mur_align) { \ + switch(_mur_align) { \ + case 3: _mur_d |= _mur_key[2] << 16; \ + case 2: _mur_d |= _mur_key[1] << 8; \ + case 1: _mur_d |= _mur_key[0]; \ + } \ + unsigned _mur_k = (_mur_t >> _mur_sr) | (_mur_d << _mur_sl); \ + _mur_k *= _mur_m; \ + _mur_k ^= _mur_k >> _mur_r; \ + _mur_k *= _mur_m; \ + hashv *= _mur_m; \ + hashv ^= _mur_k; \ + _mur_k += _mur_align; \ + _mur_len -= _mur_align; \ + \ + switch(_mur_len) \ + { \ + case 3: hashv ^= _mur_key[2] << 16; \ + case 2: hashv ^= _mur_key[1] << 8; \ + case 1: hashv ^= _mur_key[0]; \ + hashv *= _mur_m; \ + } \ + } else { \ + switch(_mur_len) \ + { \ + case 3: _mur_d ^= _mur_key[2] << 16; \ + case 2: _mur_d ^= _mur_key[1] << 8; \ + case 1: _mur_d ^= _mur_key[0]; \ + case 0: hashv ^= (_mur_t >> _mur_sr) | (_mur_d << _mur_sl); \ + hashv *= _mur_m; \ + } \ + } \ + \ + hashv ^= hashv >> 13; \ + hashv *= _mur_m; \ + hashv ^= hashv >> 15; \ + } else { \ + for (;_mur_len >= 4; _mur_len-=4) { \ + unsigned _mur_k = *(unsigned*)_mur_key; \ + _mur_k *= _mur_m; \ + _mur_k ^= _mur_k >> _mur_r; \ + _mur_k *= _mur_m; \ + hashv *= _mur_m; \ + hashv ^= _mur_k; \ + _mur_key += 4; \ + } \ + switch(_mur_len) \ + { \ + case 3: hashv ^= _mur_key[2] << 16; \ + case 2: hashv ^= _mur_key[1] << 8; \ + case 1: hashv ^= _mur_key[0]; \ + hashv *= _mur_m; \ + } \ + \ + hashv ^= hashv >> 13; \ + hashv *= _mur_m; \ + hashv ^= hashv >> 15; \ + } \ + bkt = hashv & (num_bkts-1); \ +} while(0) +#endif /* HASH_USING_NO_STRICT_ALIASING */ + +/* key comparison function; return 0 if keys equal */ +#define HASH_KEYCMP(a,b,len) memcmp(a,b,len) + +/* iterate over items in a known bucket to find desired item */ +#define HASH_FIND_IN_BKT(tbl,hh,head,keyptr,keylen_in,out) \ +do { \ + if (head.hh_head) DECLTYPE_ASSIGN(out,ELMT_FROM_HH(tbl,head.hh_head)); \ + else out=NULL; \ + while (out) { \ + if (out->hh.keylen == keylen_in) { \ + if ((HASH_KEYCMP(out->hh.key,keyptr,keylen_in)) == 0) break; \ + } \ + if (out->hh.hh_next) DECLTYPE_ASSIGN(out,ELMT_FROM_HH(tbl,out->hh.hh_next)); \ + else out = NULL; \ + } \ +} while(0) + +/* add an item to a bucket */ +#define HASH_ADD_TO_BKT(head,addhh) \ +do { \ + head.count++; \ + (addhh)->hh_next = head.hh_head; \ + (addhh)->hh_prev = NULL; \ + if (head.hh_head) { (head).hh_head->hh_prev = (addhh); } \ + (head).hh_head=addhh; \ + if (head.count >= ((head.expand_mult+1) * HASH_BKT_CAPACITY_THRESH) \ + && (addhh)->tbl->noexpand != 1) { \ + HASH_EXPAND_BUCKETS((addhh)->tbl); \ + } \ +} while(0) + +/* remove an item from a given bucket */ +#define HASH_DEL_IN_BKT(hh,head,hh_del) \ + (head).count--; \ + if ((head).hh_head == hh_del) { \ + (head).hh_head = hh_del->hh_next; \ + } \ + if (hh_del->hh_prev) { \ + hh_del->hh_prev->hh_next = hh_del->hh_next; \ + } \ + if (hh_del->hh_next) { \ + hh_del->hh_next->hh_prev = hh_del->hh_prev; \ + } + +/* Bucket expansion has the effect of doubling the number of buckets + * and redistributing the items into the new buckets. Ideally the + * items will distribute more or less evenly into the new buckets + * (the extent to which this is true is a measure of the quality of + * the hash function as it applies to the key domain). + * + * With the items distributed into more buckets, the chain length + * (item count) in each bucket is reduced. Thus by expanding buckets + * the hash keeps a bound on the chain length. This bounded chain + * length is the essence of how a hash provides constant time lookup. + * + * The calculation of tbl->ideal_chain_maxlen below deserves some + * explanation. First, keep in mind that we're calculating the ideal + * maximum chain length based on the *new* (doubled) bucket count. + * In fractions this is just n/b (n=number of items,b=new num buckets). + * Since the ideal chain length is an integer, we want to calculate + * ceil(n/b). We don't depend on floating point arithmetic in this + * hash, so to calculate ceil(n/b) with integers we could write + * + * ceil(n/b) = (n/b) + ((n%b)?1:0) + * + * and in fact a previous version of this hash did just that. + * But now we have improved things a bit by recognizing that b is + * always a power of two. We keep its base 2 log handy (call it lb), + * so now we can write this with a bit shift and logical AND: + * + * ceil(n/b) = (n>>lb) + ( (n & (b-1)) ? 1:0) + * + */ +#define HASH_EXPAND_BUCKETS(tbl) \ +do { \ + unsigned _he_bkt; \ + unsigned _he_bkt_i; \ + struct UT_hash_handle *_he_thh, *_he_hh_nxt; \ + UT_hash_bucket *_he_new_buckets, *_he_newbkt; \ + _he_new_buckets = (UT_hash_bucket*)uthash_malloc( \ + 2 * tbl->num_buckets * sizeof(struct UT_hash_bucket)); \ + if (!_he_new_buckets) { uthash_fatal( "out of memory"); } \ + memset(_he_new_buckets, 0, \ + 2 * tbl->num_buckets * sizeof(struct UT_hash_bucket)); \ + tbl->ideal_chain_maxlen = \ + (tbl->num_items >> (tbl->log2_num_buckets+1)) + \ + ((tbl->num_items & ((tbl->num_buckets*2)-1)) ? 1 : 0); \ + tbl->nonideal_items = 0; \ + for(_he_bkt_i = 0; _he_bkt_i < tbl->num_buckets; _he_bkt_i++) \ + { \ + _he_thh = tbl->buckets[ _he_bkt_i ].hh_head; \ + while (_he_thh) { \ + _he_hh_nxt = _he_thh->hh_next; \ + HASH_TO_BKT( _he_thh->hashv, tbl->num_buckets*2, _he_bkt); \ + _he_newbkt = &(_he_new_buckets[ _he_bkt ]); \ + if (++(_he_newbkt->count) > tbl->ideal_chain_maxlen) { \ + tbl->nonideal_items++; \ + _he_newbkt->expand_mult = _he_newbkt->count / \ + tbl->ideal_chain_maxlen; \ + } \ + _he_thh->hh_prev = NULL; \ + _he_thh->hh_next = _he_newbkt->hh_head; \ + if (_he_newbkt->hh_head) _he_newbkt->hh_head->hh_prev = \ + _he_thh; \ + _he_newbkt->hh_head = _he_thh; \ + _he_thh = _he_hh_nxt; \ + } \ + } \ + uthash_free( tbl->buckets, tbl->num_buckets*sizeof(struct UT_hash_bucket) ); \ + tbl->num_buckets *= 2; \ + tbl->log2_num_buckets++; \ + tbl->buckets = _he_new_buckets; \ + tbl->ineff_expands = (tbl->nonideal_items > (tbl->num_items >> 1)) ? \ + (tbl->ineff_expands+1) : 0; \ + if (tbl->ineff_expands > 1) { \ + tbl->noexpand=1; \ + uthash_noexpand_fyi(tbl); \ + } \ + uthash_expand_fyi(tbl); \ +} while(0) + + +/* This is an adaptation of Simon Tatham's O(n log(n)) mergesort */ +/* Note that HASH_SORT assumes the hash handle name to be hh. + * HASH_SRT was added to allow the hash handle name to be passed in. */ +#define HASH_SORT(head,cmpfcn) HASH_SRT(hh,head,cmpfcn) +#define HASH_SRT(hh,head,cmpfcn) \ +do { \ + unsigned _hs_i; \ + unsigned _hs_looping,_hs_nmerges,_hs_insize,_hs_psize,_hs_qsize; \ + struct UT_hash_handle *_hs_p, *_hs_q, *_hs_e, *_hs_list, *_hs_tail; \ + if (head) { \ + _hs_insize = 1; \ + _hs_looping = 1; \ + _hs_list = &((head)->hh); \ + while (_hs_looping) { \ + _hs_p = _hs_list; \ + _hs_list = NULL; \ + _hs_tail = NULL; \ + _hs_nmerges = 0; \ + while (_hs_p) { \ + _hs_nmerges++; \ + _hs_q = _hs_p; \ + _hs_psize = 0; \ + for ( _hs_i = 0; _hs_i < _hs_insize; _hs_i++ ) { \ + _hs_psize++; \ + _hs_q = (UT_hash_handle*)((_hs_q->next) ? \ + ((void*)((char*)(_hs_q->next) + \ + (head)->hh.tbl->hho)) : NULL); \ + if (! (_hs_q) ) break; \ + } \ + _hs_qsize = _hs_insize; \ + while ((_hs_psize > 0) || ((_hs_qsize > 0) && _hs_q )) { \ + if (_hs_psize == 0) { \ + _hs_e = _hs_q; \ + _hs_q = (UT_hash_handle*)((_hs_q->next) ? \ + ((void*)((char*)(_hs_q->next) + \ + (head)->hh.tbl->hho)) : NULL); \ + _hs_qsize--; \ + } else if ( (_hs_qsize == 0) || !(_hs_q) ) { \ + _hs_e = _hs_p; \ + _hs_p = (UT_hash_handle*)((_hs_p->next) ? \ + ((void*)((char*)(_hs_p->next) + \ + (head)->hh.tbl->hho)) : NULL); \ + _hs_psize--; \ + } else if (( \ + cmpfcn(DECLTYPE(head)(ELMT_FROM_HH((head)->hh.tbl,_hs_p)), \ + DECLTYPE(head)(ELMT_FROM_HH((head)->hh.tbl,_hs_q))) \ + ) <= 0) { \ + _hs_e = _hs_p; \ + _hs_p = (UT_hash_handle*)((_hs_p->next) ? \ + ((void*)((char*)(_hs_p->next) + \ + (head)->hh.tbl->hho)) : NULL); \ + _hs_psize--; \ + } else { \ + _hs_e = _hs_q; \ + _hs_q = (UT_hash_handle*)((_hs_q->next) ? \ + ((void*)((char*)(_hs_q->next) + \ + (head)->hh.tbl->hho)) : NULL); \ + _hs_qsize--; \ + } \ + if ( _hs_tail ) { \ + _hs_tail->next = ((_hs_e) ? \ + ELMT_FROM_HH((head)->hh.tbl,_hs_e) : NULL); \ + } else { \ + _hs_list = _hs_e; \ + } \ + _hs_e->prev = ((_hs_tail) ? \ + ELMT_FROM_HH((head)->hh.tbl,_hs_tail) : NULL); \ + _hs_tail = _hs_e; \ + } \ + _hs_p = _hs_q; \ + } \ + _hs_tail->next = NULL; \ + if ( _hs_nmerges <= 1 ) { \ + _hs_looping=0; \ + (head)->hh.tbl->tail = _hs_tail; \ + DECLTYPE_ASSIGN(head,ELMT_FROM_HH((head)->hh.tbl, _hs_list)); \ + } \ + _hs_insize *= 2; \ + } \ + HASH_FSCK(hh,head); \ + } \ +} while (0) + +/* This function selects items from one hash into another hash. + * The end result is that the selected items have dual presence + * in both hashes. There is no copy of the items made; rather + * they are added into the new hash through a secondary hash + * hash handle that must be present in the structure. */ +#define HASH_SELECT(hh_dst, dst, hh_src, src, cond) \ +do { \ + unsigned _src_bkt, _dst_bkt; \ + void *_last_elt=NULL, *_elt; \ + UT_hash_handle *_src_hh, *_dst_hh, *_last_elt_hh=NULL; \ + ptrdiff_t _dst_hho = ((char*)(&(dst)->hh_dst) - (char*)(dst)); \ + if (src) { \ + for(_src_bkt=0; _src_bkt < (src)->hh_src.tbl->num_buckets; _src_bkt++) { \ + for(_src_hh = (src)->hh_src.tbl->buckets[_src_bkt].hh_head; \ + _src_hh; \ + _src_hh = _src_hh->hh_next) { \ + _elt = ELMT_FROM_HH((src)->hh_src.tbl, _src_hh); \ + if (cond(_elt)) { \ + _dst_hh = (UT_hash_handle*)(((char*)_elt) + _dst_hho); \ + _dst_hh->key = _src_hh->key; \ + _dst_hh->keylen = _src_hh->keylen; \ + _dst_hh->hashv = _src_hh->hashv; \ + _dst_hh->prev = _last_elt; \ + _dst_hh->next = NULL; \ + if (_last_elt_hh) { _last_elt_hh->next = _elt; } \ + if (!dst) { \ + DECLTYPE_ASSIGN(dst,_elt); \ + HASH_MAKE_TABLE(hh_dst,dst); \ + } else { \ + _dst_hh->tbl = (dst)->hh_dst.tbl; \ + } \ + HASH_TO_BKT(_dst_hh->hashv, _dst_hh->tbl->num_buckets, _dst_bkt); \ + HASH_ADD_TO_BKT(_dst_hh->tbl->buckets[_dst_bkt],_dst_hh); \ + (dst)->hh_dst.tbl->num_items++; \ + _last_elt = _elt; \ + _last_elt_hh = _dst_hh; \ + } \ + } \ + } \ + } \ + HASH_FSCK(hh_dst,dst); \ +} while (0) + +#define HASH_CLEAR(hh,head) \ +do { \ + if (head) { \ + uthash_free((head)->hh.tbl->buckets, \ + (head)->hh.tbl->num_buckets*sizeof(struct UT_hash_bucket)); \ + uthash_free((head)->hh.tbl, sizeof(UT_hash_table)); \ + (head)=NULL; \ + } \ +} while(0) + +#ifdef NO_DECLTYPE +#define HASH_ITER(hh,head,el,tmp) \ +for((el)=(head), (*(char**)(&(tmp)))=(char*)((head)?(head)->hh.next:NULL); \ + el; (el)=(tmp),(*(char**)(&(tmp)))=(char*)((tmp)?(tmp)->hh.next:NULL)) +#else +#define HASH_ITER(hh,head,el,tmp) \ +for((el)=(head),(tmp)=DECLTYPE(el)((head)?(head)->hh.next:NULL); \ + el; (el)=(tmp),(tmp)=DECLTYPE(el)((tmp)?(tmp)->hh.next:NULL)) +#endif + +/* obtain a count of items in the hash */ +#define HASH_COUNT(head) HASH_CNT(hh,head) +#define HASH_CNT(hh,head) ((head)?((head)->hh.tbl->num_items):0) + +typedef struct UT_hash_bucket { + struct UT_hash_handle *hh_head; + unsigned count; + + /* expand_mult is normally set to 0. In this situation, the max chain length + * threshold is enforced at its default value, HASH_BKT_CAPACITY_THRESH. (If + * the bucket's chain exceeds this length, bucket expansion is triggered). + * However, setting expand_mult to a non-zero value delays bucket expansion + * (that would be triggered by additions to this particular bucket) + * until its chain length reaches a *multiple* of HASH_BKT_CAPACITY_THRESH. + * (The multiplier is simply expand_mult+1). The whole idea of this + * multiplier is to reduce bucket expansions, since they are expensive, in + * situations where we know that a particular bucket tends to be overused. + * It is better to let its chain length grow to a longer yet-still-bounded + * value, than to do an O(n) bucket expansion too often. + */ + unsigned expand_mult; + +} UT_hash_bucket; + +/* random signature used only to find hash tables in external analysis */ +#define HASH_SIGNATURE 0xa0111fe1 +#define HASH_BLOOM_SIGNATURE 0xb12220f2 + +typedef struct UT_hash_table { + UT_hash_bucket *buckets; + unsigned num_buckets, log2_num_buckets; + unsigned num_items; + struct UT_hash_handle *tail; /* tail hh in app order, for fast append */ + ptrdiff_t hho; /* hash handle offset (byte pos of hash handle in element */ + + /* in an ideal situation (all buckets used equally), no bucket would have + * more than ceil(#items/#buckets) items. that's the ideal chain length. */ + unsigned ideal_chain_maxlen; + + /* nonideal_items is the number of items in the hash whose chain position + * exceeds the ideal chain maxlen. these items pay the penalty for an uneven + * hash distribution; reaching them in a chain traversal takes >ideal steps */ + unsigned nonideal_items; + + /* ineffective expands occur when a bucket doubling was performed, but + * afterward, more than half the items in the hash had nonideal chain + * positions. If this happens on two consecutive expansions we inhibit any + * further expansion, as it's not helping; this happens when the hash + * function isn't a good fit for the key domain. When expansion is inhibited + * the hash will still work, albeit no longer in constant time. */ + unsigned ineff_expands, noexpand; + + uint32_t signature; /* used only to find hash tables in external analysis */ +#ifdef HASH_BLOOM + uint32_t bloom_sig; /* used only to test bloom exists in external analysis */ + uint8_t *bloom_bv; + char bloom_nbits; +#endif + +} UT_hash_table; + +typedef struct UT_hash_handle { + struct UT_hash_table *tbl; + void *prev; /* prev element in app order */ + void *next; /* next element in app order */ + struct UT_hash_handle *hh_prev; /* previous hh in bucket order */ + struct UT_hash_handle *hh_next; /* next hh in bucket order */ + void *key; /* ptr to enclosing struct's key */ + unsigned keylen; /* enclosing struct's key len */ + unsigned hashv; /* result of hash-fcn(key) */ +} UT_hash_handle; + +#endif /* UTHASH_H */ diff --git a/tweejump/libs/cocos2d/Support/utlist.h b/tweejump/libs/cocos2d/Support/utlist.h new file mode 100755 index 0000000..34c725b --- /dev/null +++ b/tweejump/libs/cocos2d/Support/utlist.h @@ -0,0 +1,490 @@ +/* +Copyright (c) 2007-2010, Troy D. Hanson http://uthash.sourceforge.net +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS +IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A +PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER +OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef UTLIST_H +#define UTLIST_H + +#define UTLIST_VERSION 1.9.1 + +/* + * This file contains macros to manipulate singly and doubly-linked lists. + * + * 1. LL_ macros: singly-linked lists. + * 2. DL_ macros: doubly-linked lists. + * 3. CDL_ macros: circular doubly-linked lists. + * + * To use singly-linked lists, your structure must have a "next" pointer. + * To use doubly-linked lists, your structure must "prev" and "next" pointers. + * Either way, the pointer to the head of the list must be initialized to NULL. + * + * ----------------.EXAMPLE ------------------------- + * struct item { + * int id; + * struct item *prev, *next; + * } + * + * struct item *list = NULL: + * + * int main() { + * struct item *item; + * ... allocate and populate item ... + * DL_APPEND(list, item); + * } + * -------------------------------------------------- + * + * For doubly-linked lists, the append and delete macros are O(1) + * For singly-linked lists, append and delete are O(n) but prepend is O(1) + * The sort macro is O(n log(n)) for all types of single/double/circular lists. + */ + +/* These macros use decltype or the earlier __typeof GNU extension. + As decltype is only available in newer compilers (VS2010 or gcc 4.3+ + when compiling c++ code), this code uses whatever method is needed + or, for VS2008 where neither is available, uses casting workarounds. */ +#ifdef _MSC_VER /* MS compiler */ +#if _MSC_VER >= 1600 && defined(__cplusplus) /* VS2010 or newer in C++ mode */ +#define LDECLTYPE(x) decltype(x) +#else /* VS2008 or older (or VS2010 in C mode) */ +#define NO_DECLTYPE +#define LDECLTYPE(x) char* +#endif +#else /* GNU, Sun and other compilers */ +#define LDECLTYPE(x) __typeof(x) +#endif + +/* for VS2008 we use some workarounds to get around the lack of decltype, + * namely, we always reassign our tmp variable to the list head if we need + * to dereference its prev/next pointers, and save/restore the real head.*/ +#ifdef NO_DECLTYPE +#define _SV(elt,list) _tmp = (char*)(list); {char **_alias = (char**)&(list); *_alias = (elt); } +#define _NEXT(elt,list) ((char*)((list)->next)) +#define _NEXTASGN(elt,list,to) { char **_alias = (char**)&((list)->next); *_alias=(char*)(to); } +#define _PREV(elt,list) ((char*)((list)->prev)) +#define _PREVASGN(elt,list,to) { char **_alias = (char**)&((list)->prev); *_alias=(char*)(to); } +#define _RS(list) { char **_alias = (char**)&(list); *_alias=_tmp; } +#define _CASTASGN(a,b) { char **_alias = (char**)&(a); *_alias=(char*)(b); } +#else +#define _SV(elt,list) +#define _NEXT(elt,list) ((elt)->next) +#define _NEXTASGN(elt,list,to) ((elt)->next)=(to) +#define _PREV(elt,list) ((elt)->prev) +#define _PREVASGN(elt,list,to) ((elt)->prev)=(to) +#define _RS(list) +#define _CASTASGN(a,b) (a)=(b) +#endif + +/****************************************************************************** + * The sort macro is an adaptation of Simon Tatham's O(n log(n)) mergesort * + * Unwieldy variable names used here to avoid shadowing passed-in variables. * + *****************************************************************************/ +#define LL_SORT(list, cmp) \ +do { \ + LDECLTYPE(list) _ls_p; \ + LDECLTYPE(list) _ls_q; \ + LDECLTYPE(list) _ls_e; \ + LDECLTYPE(list) _ls_tail; \ + LDECLTYPE(list) _ls_oldhead; \ + LDECLTYPE(list) _tmp; \ + int _ls_insize, _ls_nmerges, _ls_psize, _ls_qsize, _ls_i, _ls_looping; \ + if (list) { \ + _ls_insize = 1; \ + _ls_looping = 1; \ + while (_ls_looping) { \ + _CASTASGN(_ls_p,list); \ + _CASTASGN(_ls_oldhead,list); \ + list = NULL; \ + _ls_tail = NULL; \ + _ls_nmerges = 0; \ + while (_ls_p) { \ + _ls_nmerges++; \ + _ls_q = _ls_p; \ + _ls_psize = 0; \ + for (_ls_i = 0; _ls_i < _ls_insize; _ls_i++) { \ + _ls_psize++; \ + _SV(_ls_q,list); _ls_q = _NEXT(_ls_q,list); _RS(list); \ + if (!_ls_q) break; \ + } \ + _ls_qsize = _ls_insize; \ + while (_ls_psize > 0 || (_ls_qsize > 0 && _ls_q)) { \ + if (_ls_psize == 0) { \ + _ls_e = _ls_q; _SV(_ls_q,list); _ls_q = _NEXT(_ls_q,list); _RS(list); _ls_qsize--; \ + } else if (_ls_qsize == 0 || !_ls_q) { \ + _ls_e = _ls_p; _SV(_ls_p,list); _ls_p = _NEXT(_ls_p,list); _RS(list); _ls_psize--; \ + } else if (cmp(_ls_p,_ls_q) <= 0) { \ + _ls_e = _ls_p; _SV(_ls_p,list); _ls_p = _NEXT(_ls_p,list); _RS(list); _ls_psize--; \ + } else { \ + _ls_e = _ls_q; _SV(_ls_q,list); _ls_q = _NEXT(_ls_q,list); _RS(list); _ls_qsize--; \ + } \ + if (_ls_tail) { \ + _SV(_ls_tail,list); _NEXTASGN(_ls_tail,list,_ls_e); _RS(list); \ + } else { \ + _CASTASGN(list,_ls_e); \ + } \ + _ls_tail = _ls_e; \ + } \ + _ls_p = _ls_q; \ + } \ + _SV(_ls_tail,list); _NEXTASGN(_ls_tail,list,NULL); _RS(list); \ + if (_ls_nmerges <= 1) { \ + _ls_looping=0; \ + } \ + _ls_insize *= 2; \ + } \ + } else _tmp=NULL; /* quiet gcc unused variable warning */ \ +} while (0) + +#define DL_SORT(list, cmp) \ +do { \ + LDECLTYPE(list) _ls_p; \ + LDECLTYPE(list) _ls_q; \ + LDECLTYPE(list) _ls_e; \ + LDECLTYPE(list) _ls_tail; \ + LDECLTYPE(list) _ls_oldhead; \ + LDECLTYPE(list) _tmp; \ + int _ls_insize, _ls_nmerges, _ls_psize, _ls_qsize, _ls_i, _ls_looping; \ + if (list) { \ + _ls_insize = 1; \ + _ls_looping = 1; \ + while (_ls_looping) { \ + _CASTASGN(_ls_p,list); \ + _CASTASGN(_ls_oldhead,list); \ + list = NULL; \ + _ls_tail = NULL; \ + _ls_nmerges = 0; \ + while (_ls_p) { \ + _ls_nmerges++; \ + _ls_q = _ls_p; \ + _ls_psize = 0; \ + for (_ls_i = 0; _ls_i < _ls_insize; _ls_i++) { \ + _ls_psize++; \ + _SV(_ls_q,list); _ls_q = _NEXT(_ls_q,list); _RS(list); \ + if (!_ls_q) break; \ + } \ + _ls_qsize = _ls_insize; \ + while (_ls_psize > 0 || (_ls_qsize > 0 && _ls_q)) { \ + if (_ls_psize == 0) { \ + _ls_e = _ls_q; _SV(_ls_q,list); _ls_q = _NEXT(_ls_q,list); _RS(list); _ls_qsize--; \ + } else if (_ls_qsize == 0 || !_ls_q) { \ + _ls_e = _ls_p; _SV(_ls_p,list); _ls_p = _NEXT(_ls_p,list); _RS(list); _ls_psize--; \ + } else if (cmp(_ls_p,_ls_q) <= 0) { \ + _ls_e = _ls_p; _SV(_ls_p,list); _ls_p = _NEXT(_ls_p,list); _RS(list); _ls_psize--; \ + } else { \ + _ls_e = _ls_q; _SV(_ls_q,list); _ls_q = _NEXT(_ls_q,list); _RS(list); _ls_qsize--; \ + } \ + if (_ls_tail) { \ + _SV(_ls_tail,list); _NEXTASGN(_ls_tail,list,_ls_e); _RS(list); \ + } else { \ + _CASTASGN(list,_ls_e); \ + } \ + _SV(_ls_e,list); _PREVASGN(_ls_e,list,_ls_tail); _RS(list); \ + _ls_tail = _ls_e; \ + } \ + _ls_p = _ls_q; \ + } \ + _CASTASGN(list->prev, _ls_tail); \ + _SV(_ls_tail,list); _NEXTASGN(_ls_tail,list,NULL); _RS(list); \ + if (_ls_nmerges <= 1) { \ + _ls_looping=0; \ + } \ + _ls_insize *= 2; \ + } \ + } else _tmp=NULL; /* quiet gcc unused variable warning */ \ +} while (0) + +#define CDL_SORT(list, cmp) \ +do { \ + LDECLTYPE(list) _ls_p; \ + LDECLTYPE(list) _ls_q; \ + LDECLTYPE(list) _ls_e; \ + LDECLTYPE(list) _ls_tail; \ + LDECLTYPE(list) _ls_oldhead; \ + LDECLTYPE(list) _tmp; \ + LDECLTYPE(list) _tmp2; \ + int _ls_insize, _ls_nmerges, _ls_psize, _ls_qsize, _ls_i, _ls_looping; \ + if (list) { \ + _ls_insize = 1; \ + _ls_looping = 1; \ + while (_ls_looping) { \ + _CASTASGN(_ls_p,list); \ + _CASTASGN(_ls_oldhead,list); \ + list = NULL; \ + _ls_tail = NULL; \ + _ls_nmerges = 0; \ + while (_ls_p) { \ + _ls_nmerges++; \ + _ls_q = _ls_p; \ + _ls_psize = 0; \ + for (_ls_i = 0; _ls_i < _ls_insize; _ls_i++) { \ + _ls_psize++; \ + _SV(_ls_q,list); \ + if (_NEXT(_ls_q,list) == _ls_oldhead) { \ + _ls_q = NULL; \ + } else { \ + _ls_q = _NEXT(_ls_q,list); \ + } \ + _RS(list); \ + if (!_ls_q) break; \ + } \ + _ls_qsize = _ls_insize; \ + while (_ls_psize > 0 || (_ls_qsize > 0 && _ls_q)) { \ + if (_ls_psize == 0) { \ + _ls_e = _ls_q; _SV(_ls_q,list); _ls_q = _NEXT(_ls_q,list); _RS(list); _ls_qsize--; \ + if (_ls_q == _ls_oldhead) { _ls_q = NULL; } \ + } else if (_ls_qsize == 0 || !_ls_q) { \ + _ls_e = _ls_p; _SV(_ls_p,list); _ls_p = _NEXT(_ls_p,list); _RS(list); _ls_psize--; \ + if (_ls_p == _ls_oldhead) { _ls_p = NULL; } \ + } else if (cmp(_ls_p,_ls_q) <= 0) { \ + _ls_e = _ls_p; _SV(_ls_p,list); _ls_p = _NEXT(_ls_p,list); _RS(list); _ls_psize--; \ + if (_ls_p == _ls_oldhead) { _ls_p = NULL; } \ + } else { \ + _ls_e = _ls_q; _SV(_ls_q,list); _ls_q = _NEXT(_ls_q,list); _RS(list); _ls_qsize--; \ + if (_ls_q == _ls_oldhead) { _ls_q = NULL; } \ + } \ + if (_ls_tail) { \ + _SV(_ls_tail,list); _NEXTASGN(_ls_tail,list,_ls_e); _RS(list); \ + } else { \ + _CASTASGN(list,_ls_e); \ + } \ + _SV(_ls_e,list); _PREVASGN(_ls_e,list,_ls_tail); _RS(list); \ + _ls_tail = _ls_e; \ + } \ + _ls_p = _ls_q; \ + } \ + _CASTASGN(list->prev,_ls_tail); \ + _CASTASGN(_tmp2,list); \ + _SV(_ls_tail,list); _NEXTASGN(_ls_tail,list,_tmp2); _RS(list); \ + if (_ls_nmerges <= 1) { \ + _ls_looping=0; \ + } \ + _ls_insize *= 2; \ + } \ + } else _tmp=NULL; /* quiet gcc unused variable warning */ \ +} while (0) + +/****************************************************************************** + * singly linked list macros (non-circular) * + *****************************************************************************/ +#define LL_PREPEND(head,add) \ +do { \ + (add)->next = head; \ + head = add; \ +} while (0) + +#define LL_APPEND(head,add) \ +do { \ + LDECLTYPE(head) _tmp; \ + (add)->next=NULL; \ + if (head) { \ + _tmp = head; \ + while (_tmp->next) { _tmp = _tmp->next; } \ + _tmp->next=(add); \ + } else { \ + (head)=(add); \ + } \ +} while (0) + +#define LL_DELETE(head,del) \ +do { \ + LDECLTYPE(head) _tmp; \ + if ((head) == (del)) { \ + (head)=(head)->next; \ + } else { \ + _tmp = head; \ + while (_tmp->next && (_tmp->next != (del))) { \ + _tmp = _tmp->next; \ + } \ + if (_tmp->next) { \ + _tmp->next = ((del)->next); \ + } \ + } \ +} while (0) + +/* Here are VS2008 replacements for LL_APPEND and LL_DELETE */ +#define LL_APPEND_VS2008(head,add) \ +do { \ + if (head) { \ + (add)->next = head; /* use add->next as a temp variable */ \ + while ((add)->next->next) { (add)->next = (add)->next->next; } \ + (add)->next->next=(add); \ + } else { \ + (head)=(add); \ + } \ + (add)->next=NULL; \ +} while (0) + +#define LL_DELETE_VS2008(head,del) \ +do { \ + if ((head) == (del)) { \ + (head)=(head)->next; \ + } else { \ + char *_tmp = (char*)(head); \ + while (head->next && (head->next != (del))) { \ + head = head->next; \ + } \ + if (head->next) { \ + head->next = ((del)->next); \ + } \ + { \ + char **_head_alias = (char**)&(head); \ + *_head_alias = _tmp; \ + } \ + } \ +} while (0) +#ifdef NO_DECLTYPE +#undef LL_APPEND +#define LL_APPEND LL_APPEND_VS2008 +#undef LL_DELETE +#define LL_DELETE LL_DELETE_VS2008 +#endif +/* end VS2008 replacements */ + +#define LL_FOREACH(head,el) \ + for(el=head;el;el=el->next) + +#define LL_FOREACH_SAFE(head,el,tmp) \ + for((el)=(head);(el) && (tmp = (el)->next, 1); (el) = tmp) + +#define LL_SEARCH_SCALAR(head,out,field,val) \ +do { \ + LL_FOREACH(head,out) { \ + if ((out)->field == (val)) break; \ + } \ +} while(0) + +#define LL_SEARCH(head,out,elt,cmp) \ +do { \ + LL_FOREACH(head,out) { \ + if ((cmp(out,elt))==0) break; \ + } \ +} while(0) + +/****************************************************************************** + * doubly linked list macros (non-circular) * + *****************************************************************************/ +#define DL_PREPEND(head,add) \ +do { \ + (add)->next = head; \ + if (head) { \ + (add)->prev = (head)->prev; \ + (head)->prev = (add); \ + } else { \ + (add)->prev = (add); \ + } \ + (head) = (add); \ +} while (0) + +#define DL_APPEND(head,add) \ +do { \ + if (head) { \ + (add)->prev = (head)->prev; \ + (head)->prev->next = (add); \ + (head)->prev = (add); \ + (add)->next = NULL; \ + } else { \ + (head)=(add); \ + (head)->prev = (head); \ + (head)->next = NULL; \ + } \ +} while (0); + +#define DL_DELETE(head,del) \ +do { \ + if ((del)->prev == (del)) { \ + (head)=NULL; \ + } else if ((del)==(head)) { \ + (del)->next->prev = (del)->prev; \ + (head) = (del)->next; \ + } else { \ + (del)->prev->next = (del)->next; \ + if ((del)->next) { \ + (del)->next->prev = (del)->prev; \ + } else { \ + (head)->prev = (del)->prev; \ + } \ + } \ +} while (0); + + +#define DL_FOREACH(head,el) \ + for(el=head;el;el=el->next) + +/* this version is safe for deleting the elements during iteration */ +#define DL_FOREACH_SAFE(head,el,tmp) \ + for((el)=(head);(el) && (tmp = (el)->next, 1); (el) = tmp) + +/* these are identical to their singly-linked list counterparts */ +#define DL_SEARCH_SCALAR LL_SEARCH_SCALAR +#define DL_SEARCH LL_SEARCH + +/****************************************************************************** + * circular doubly linked list macros * + *****************************************************************************/ +#define CDL_PREPEND(head,add) \ +do { \ + if (head) { \ + (add)->prev = (head)->prev; \ + (add)->next = (head); \ + (head)->prev = (add); \ + (add)->prev->next = (add); \ + } else { \ + (add)->prev = (add); \ + (add)->next = (add); \ + } \ +(head)=(add); \ +} while (0) + +#define CDL_DELETE(head,del) \ +do { \ + if ( ((head)==(del)) && ((head)->next == (head))) { \ + (head) = 0L; \ + } else { \ + (del)->next->prev = (del)->prev; \ + (del)->prev->next = (del)->next; \ + if ((del) == (head)) (head)=(del)->next; \ + } \ +} while (0); + +#define CDL_FOREACH(head,el) \ + for(el=head;el;el=(el->next==head ? 0L : el->next)) + +#define CDL_FOREACH_SAFE(head,el,tmp1,tmp2) \ + for((el)=(head), ((tmp1)=(head)?((head)->prev):NULL); \ + (el) && ((tmp2)=(el)->next, 1); \ + ((el) = (((el)==(tmp1)) ? 0L : (tmp2)))) + +#define CDL_SEARCH_SCALAR(head,out,field,val) \ +do { \ + CDL_FOREACH(head,out) { \ + if ((out)->field == (val)) break; \ + } \ +} while(0) + +#define CDL_SEARCH(head,out,elt,cmp) \ +do { \ + CDL_FOREACH(head,out) { \ + if ((cmp(out,elt))==0) break; \ + } \ +} while(0) + +#endif /* UTLIST_H */ + diff --git a/tweejump/libs/cocos2d/ccConfig.h b/tweejump/libs/cocos2d/ccConfig.h new file mode 100755 index 0000000..55b4cd8 --- /dev/null +++ b/tweejump/libs/cocos2d/ccConfig.h @@ -0,0 +1,334 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-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. + */ + + +#import + +/** + @file + cocos2d (cc) configuration file +*/ + +/** @def CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL + If enabled, the texture coordinates will be calculated by using this formula: + - texCoord.left = (rect.origin.x*2+1) / (texture.wide*2); + - texCoord.right = texCoord.left + (rect.size.width*2-2)/(texture.wide*2); + + The same for bottom and top. + + This formula prevents artifacts by using 99% of the texture. + The "correct" way to prevent artifacts is by using the spritesheet-artifact-fixer.py or a similar tool. + + Affected nodes: + - CCSprite / CCSpriteBatchNode and subclasses: CCLabelBMFont, CCTMXTiledMap + - CCLabelAtlas + - CCQuadParticleSystem + - CCTileMap + + To enabled set it to 1. Disabled by default. + + @since v0.99.5 + */ +#ifndef CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL +#define CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL 0 +#endif + + +/** @def CC_FONT_LABEL_SUPPORT + If enabled, FontLabel will be used to render .ttf files. + If the .ttf file is not found, then it will use the standard UIFont class + If disabled, the standard UIFont class will be used. + + To disable set it to 0. Enabled by default. + + Only valid for cocos2d-ios. Not supported on cocos2d-mac + */ +#ifndef CC_FONT_LABEL_SUPPORT +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED +#define CC_FONT_LABEL_SUPPORT 1 +#elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED) +#define CC_FONT_LABEL_SUPPORT 0 +#endif +#endif + +/** @def CC_DIRECTOR_FAST_FPS + If enabled, then the FPS will be drawn using CCLabelAtlas (fast rendering). + You will need to add the fps_images.png to your project. + If disabled, the FPS will be rendered using CCLabel (slow rendering) + + To enable set it to a value different than 0. Enabled by default. + */ +#ifndef CC_DIRECTOR_FAST_FPS +#define CC_DIRECTOR_FAST_FPS 1 +#endif + +/** @def CC_DIRECTOR_FPS_INTERVAL + Senconds between FPS updates. + 0.5 seconds, means that the FPS number will be updated every 0.5 seconds. + Having a bigger number means a more reliable FPS + + Default value: 0.1f + */ +#ifndef CC_DIRECTOR_FPS_INTERVAL +#define CC_DIRECTOR_FPS_INTERVAL (0.1f) +#endif + +/** @def CC_DIRECTOR_DISPATCH_FAST_EVENTS + If enabled, and only when it is used with CCFastDirector, the main loop will wait 0.04 seconds to + dispatch all the events, even if there are not events to dispatch. + If your game uses lot's of events (eg: touches) it might be a good idea to enable this feature. + Otherwise, it is safe to leave it disabled. + + To enable set it to 1. Disabled by default. + + @warning This feature is experimental + */ +#ifndef CC_DIRECTOR_DISPATCH_FAST_EVENTS +#define CC_DIRECTOR_DISPATCH_FAST_EVENTS 0 +#endif + +/** @def CC_DIRECTOR_MAC_USE_DISPLAY_LINK_THREAD + If enabled, cocos2d-mac will run on the Display Link thread. If disabled cocos2d-mac will run in its own thread. + + If enabled, the images will be drawn at the "correct" time, but the events might not be very responsive. + If disabled, some frames might be skipped, but the events will be dispatched as they arrived. + + To enable set it to a 1, to disable it set to 0. Enabled by default. + + Only valid for cocos2d-mac. Not supported on cocos2d-ios. + + */ +#ifndef CC_DIRECTOR_MAC_USE_DISPLAY_LINK_THREAD +#define CC_DIRECTOR_MAC_USE_DISPLAY_LINK_THREAD 1 +#endif + +/** @def CC_COCOSNODE_RENDER_SUBPIXEL + If enabled, the CCNode objects (CCSprite, CCLabel,etc) will be able to render in subpixels. + If disabled, integer pixels will be used. + + To enable set it to 1. Enabled by default. + */ +#ifndef CC_COCOSNODE_RENDER_SUBPIXEL +#define CC_COCOSNODE_RENDER_SUBPIXEL 1 +#endif + +/** @def CC_SPRITEBATCHNODE_RENDER_SUBPIXEL + If enabled, the CCSprite objects rendered with CCSpriteBatchNode will be able to render in subpixels. + If disabled, integer pixels will be used. + + To enable set it to 1. Enabled by default. + */ +#ifndef CC_SPRITEBATCHNODE_RENDER_SUBPIXEL +#define CC_SPRITEBATCHNODE_RENDER_SUBPIXEL 1 +#endif + +/** @def CC_USES_VBO + If enabled, batch nodes (texture atlas and particle system) will use VBO instead of vertex list (VBO is recommended by Apple) + + To enable set it to 1. + Enabled by default on iPhone with ARMv7 processors, iPhone Simulator and Mac + Disabled by default on iPhone with ARMv6 processors. + + @since v0.99.5 + */ +#ifndef CC_USES_VBO +#if defined(__ARM_NEON__) || TARGET_IPHONE_SIMULATOR || defined(__MAC_OS_X_VERSION_MAX_ALLOWED) +#define CC_USES_VBO 1 +#else +#define CC_USES_VBO 0 +#endif +#endif + +/** @def CC_NODE_TRANSFORM_USING_AFFINE_MATRIX + If enabled, CCNode will transform the nodes using a cached Affine matrix. + If disabled, the node will be transformed using glTranslate,glRotate,glScale. + Using the affine matrix only requires 2 GL calls. + Using the translate/rotate/scale requires 5 GL calls. + But computing the Affine matrix is relative expensive. + But according to performance tests, Affine matrix performs better. + This parameter doesn't affect CCSpriteBatchNode nodes. + + To enable set it to a value different than 0. Enabled by default. + + */ +#ifndef CC_NODE_TRANSFORM_USING_AFFINE_MATRIX +#define CC_NODE_TRANSFORM_USING_AFFINE_MATRIX 1 +#endif + +/** @def CC_OPTIMIZE_BLEND_FUNC_FOR_PREMULTIPLIED_ALPHA + If most of your imamges have pre-multiplied alpha, set it to 1 (if you are going to use .PNG/.JPG file images). + Only set to 0 if ALL your images by-pass Apple UIImage loading system (eg: if you use libpng or PVR images) + + To enable set it to a value different than 0. Enabled by default. + + @since v0.99.5 + */ +#ifndef CC_OPTIMIZE_BLEND_FUNC_FOR_PREMULTIPLIED_ALPHA +#define CC_OPTIMIZE_BLEND_FUNC_FOR_PREMULTIPLIED_ALPHA 1 +#endif + +/** @def CC_TEXTURE_ATLAS_USE_TRIANGLE_STRIP + Use GL_TRIANGLE_STRIP instead of GL_TRIANGLES when rendering the texture atlas. + It seems it is the recommend way, but it is much slower, so, enable it at your own risk + + To enable set it to a value different than 0. Disabled by default. + + */ +#ifndef CC_TEXTURE_ATLAS_USE_TRIANGLE_STRIP +#define CC_TEXTURE_ATLAS_USE_TRIANGLE_STRIP 0 +#endif + +/** @def CC_TEXTURE_NPOT_SUPPORT + If enabled, NPOT textures will be used where available. Only 3rd gen (and newer) devices support NPOT textures. + NPOT textures have the following limitations: + - They can't have mipmaps + - They only accept GL_CLAMP_TO_EDGE in GL_TEXTURE_WRAP_{S,T} + + To enable set it to a value different than 0. Disabled by default. + + This value governs only the PNG, GIF, BMP, images. + This value DOES NOT govern the PVR (PVR.GZ, PVR.CCZ) files. If NPOT PVR is loaded, then it will create an NPOT texture ignoring this value. + + @deprecated This value will be removed in 1.1 and NPOT textures will be loaded by default if the device supports it. + + @since v0.99.2 + */ +#ifndef CC_TEXTURE_NPOT_SUPPORT +#define CC_TEXTURE_NPOT_SUPPORT 0 +#endif + +/** @def CC_RETINA_DISPLAY_SUPPORT + If enabled, cocos2d supports retina display. + For performance reasons, it's recommended disable it in games without retina display support, like iPad only games. + + To enable set it to 1. Use 0 to disable it. Enabled by default. + + @since v0.99.5 + */ +#ifndef CC_RETINA_DISPLAY_SUPPORT +#define CC_RETINA_DISPLAY_SUPPORT 1 +#endif + +/** @def CC_RETINA_DISPLAY_FILENAME_SUFFIX + It's the suffix that will be appended to the files in order to load "retina display" images. + + On an iPhone4 with Retina Display support enabled, the file @"sprite-hd.png" will be loaded instead of @"sprite.png". + If the file doesn't exist it will use the non-retina display image. + + Platforms: Only used on Retina Display devices like iPhone 4. + + @since v0.99.5 + */ +#ifndef CC_RETINA_DISPLAY_FILENAME_SUFFIX +#define CC_RETINA_DISPLAY_FILENAME_SUFFIX @"-hd" +#endif + +/** @def CC_USE_LA88_LABELS_ON_NEON_ARCH + If enabled, it will use LA88 (16-bit textures) on Neon devices for CCLabelTTF objects. + If it is disabled, or if it is used on another architecture it will use A8 (8-bit textures). + On Neon devices, LA88 textures are 6% faster than A8 textures, but then will consume 2x memory. + + This feature is disabled by default. + + Platforms: Only used on ARM Neon architectures like iPhone 3GS or newer and iPad. + + @since v0.99.5 + */ +#ifndef CC_USE_LA88_LABELS_ON_NEON_ARCH +#define CC_USE_LA88_LABELS_ON_NEON_ARCH 0 +#endif + +/** @def CC_SPRITE_DEBUG_DRAW + If enabled, all subclasses of CCSprite will draw a bounding box + Useful for debugging purposes only. It is recommened to leave it disabled. + + To enable set it to a value different than 0. Disabled by default: + 0 -- disabled + 1 -- draw bounding box + 2 -- draw texture box + */ +#ifndef CC_SPRITE_DEBUG_DRAW +#define CC_SPRITE_DEBUG_DRAW 0 +#endif + +/** @def CC_SPRITEBATCHNODE_DEBUG_DRAW + If enabled, all subclasses of CCSprite that are rendered using an CCSpriteBatchNode draw a bounding box. + Useful for debugging purposes only. It is recommened to leave it disabled. + + To enable set it to a value different than 0. Disabled by default. + */ +#ifndef CC_SPRITEBATCHNODE_DEBUG_DRAW +#define CC_SPRITEBATCHNODE_DEBUG_DRAW 0 +#endif + +/** @def CC_LABELBMFONT_DEBUG_DRAW + If enabled, all subclasses of CCLabelBMFont will draw a bounding box + Useful for debugging purposes only. It is recommened to leave it disabled. + + To enable set it to a value different than 0. Disabled by default. + */ +#ifndef CC_LABELBMFONT_DEBUG_DRAW +#define CC_LABELBMFONT_DEBUG_DRAW 0 +#endif + +/** @def CC_LABELBMFONT_DEBUG_DRAW + If enabled, all subclasses of CCLabeltAtlas will draw a bounding box + Useful for debugging purposes only. It is recommened to leave it disabled. + + To enable set it to a value different than 0. Disabled by default. + */ +#ifndef CC_LABELATLAS_DEBUG_DRAW +#define CC_LABELATLAS_DEBUG_DRAW 0 +#endif + +/** @def CC_ENABLE_PROFILERS + If enabled, will activate various profilers withing cocos2d. This statistical data will be output to the console + once per second showing average time (in milliseconds) required to execute the specific routine(s). + Useful for debugging purposes only. It is recommened to leave it disabled. + + To enable set it to a value different than 0. Disabled by default. + */ +#ifndef CC_ENABLE_PROFILERS +#define CC_ENABLE_PROFILERS 0 +#endif + +// +// DON'T edit this macro. +// +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED + +#if CC_RETINA_DISPLAY_SUPPORT +#define CC_IS_RETINA_DISPLAY_SUPPORTED 1 +#else +#define CC_IS_RETINA_DISPLAY_SUPPORTED 0 +#endif + +#elif __MAC_OS_X_VERSION_MAX_ALLOWED + +#define CC_IS_RETINA_DISPLAY_SUPPORTED 0 + +#endif + + diff --git a/tweejump/libs/cocos2d/ccMacros.h b/tweejump/libs/cocos2d/ccMacros.h new file mode 100755 index 0000000..4e08725 --- /dev/null +++ b/tweejump/libs/cocos2d/ccMacros.h @@ -0,0 +1,253 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-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. + */ + + +#import +#import "ccConfig.h" + +#import +#import + +/** + @file + cocos2d helper macros + */ + +/* + * if COCOS2D_DEBUG is not defined, or if it is 0 then + * all CCLOGXXX macros will be disabled + * + * if COCOS2D_DEBUG==1 then: + * CCLOG() will be enabled + * CCLOGERROR() will be enabled + * CCLOGINFO() will be disabled + * + * if COCOS2D_DEBUG==2 or higher then: + * CCLOG() will be enabled + * CCLOGERROR() will be enabled + * CCLOGINFO() will be enabled + */ +#if !defined(COCOS2D_DEBUG) || COCOS2D_DEBUG == 0 +#define CCLOG(...) do {} while (0) +#define CCLOGINFO(...) do {} while (0) +#define CCLOGERROR(...) do {} while (0) + +#elif COCOS2D_DEBUG == 1 +#define CCLOG(...) NSLog(__VA_ARGS__) +#define CCLOGERROR(...) NSLog(__VA_ARGS__) +#define CCLOGINFO(...) do {} while (0) + +#elif COCOS2D_DEBUG > 1 +#define CCLOG(...) NSLog(__VA_ARGS__) +#define CCLOGERROR(...) NSLog(__VA_ARGS__) +#define CCLOGINFO(...) NSLog(__VA_ARGS__) +#endif // COCOS2D_DEBUG + +/** @def CC_SWAP +simple macro that swaps 2 variables +*/ +#define CC_SWAP( x, y ) \ +({ __typeof__(x) temp = (x); \ + x = y; y = temp; \ +}) + + +/** @def CCRANDOM_MINUS1_1 + returns a random float between -1 and 1 + */ +#define CCRANDOM_MINUS1_1() ((random() / (float)0x3fffffff )-1.0f) + +/** @def CCRANDOM_0_1 + returns a random float between 0 and 1 + */ +#define CCRANDOM_0_1() ((random() / (float)0x7fffffff )) + +/** @def CC_DEGREES_TO_RADIANS + converts degrees to radians + */ +#define CC_DEGREES_TO_RADIANS(__ANGLE__) ((__ANGLE__) * 0.01745329252f) // PI / 180 + +/** @def CC_RADIANS_TO_DEGREES + converts radians to degrees + */ +#define CC_RADIANS_TO_DEGREES(__ANGLE__) ((__ANGLE__) * 57.29577951f) // PI * 180 + +/** @def CC_BLEND_SRC +default gl blend src function. Compatible with premultiplied alpha images. +*/ +#if CC_OPTIMIZE_BLEND_FUNC_FOR_PREMULTIPLIED_ALPHA +#define CC_BLEND_SRC GL_ONE +#define CC_BLEND_DST GL_ONE_MINUS_SRC_ALPHA +#else +#define CC_BLEND_SRC GL_SRC_ALPHA +#define CC_BLEND_DST GL_ONE_MINUS_SRC_ALPHA +#endif // ! CC_OPTIMIZE_BLEND_FUNC_FOR_PREMULTIPLIED_ALPHA + +/** @def CC_ENABLE_DEFAULT_GL_STATES + GL states that are enabled: + - GL_TEXTURE_2D + - GL_VERTEX_ARRAY + - GL_TEXTURE_COORD_ARRAY + - GL_COLOR_ARRAY + */ +#define CC_ENABLE_DEFAULT_GL_STATES() { \ + glEnableClientState(GL_VERTEX_ARRAY); \ + glEnableClientState(GL_COLOR_ARRAY); \ + glEnableClientState(GL_TEXTURE_COORD_ARRAY); \ + glEnable(GL_TEXTURE_2D); \ +} + +/** @def CC_DISABLE_DEFAULT_GL_STATES + Disable default GL states: + - GL_TEXTURE_2D + - GL_VERTEX_ARRAY + - GL_TEXTURE_COORD_ARRAY + - GL_COLOR_ARRAY + */ +#define CC_DISABLE_DEFAULT_GL_STATES() { \ + glDisable(GL_TEXTURE_2D); \ + glDisableClientState(GL_TEXTURE_COORD_ARRAY); \ + glDisableClientState(GL_COLOR_ARRAY); \ + glDisableClientState(GL_VERTEX_ARRAY); \ +} + +/** @def CC_DIRECTOR_INIT + - Initializes an EAGLView with 0-bit depth format, and RGB565 render buffer. + - The EAGLView view will have multiple touches disabled. + - It will create a UIWindow and it will assign it the 'window' variable. 'window' must be declared before calling this marcro. + - It will parent the EAGLView to the created window + - If the firmware >= 3.1 it will create a Display Link Director. Else it will create an NSTimer director. + - It will try to run at 60 FPS. + - The FPS won't be displayed. + - The orientation will be portrait. + - It will connect the director with the EAGLView. + + IMPORTANT: If you want to use another type of render buffer (eg: RGBA8) + or if you want to use a 16-bit or 24-bit depth buffer, you should NOT + use this macro. Instead, you should create the EAGLView manually. + + @since v0.99.4 + */ + +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED + +#define CC_DIRECTOR_INIT() \ +do { \ + window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; \ + if( ! [CCDirector setDirectorType:kCCDirectorTypeDisplayLink] ) \ + [CCDirector setDirectorType:kCCDirectorTypeNSTimer]; \ + CCDirector *__director = [CCDirector sharedDirector]; \ + [__director setDeviceOrientation:kCCDeviceOrientationPortrait]; \ + [__director setDisplayFPS:NO]; \ + [__director setAnimationInterval:1.0/60]; \ + EAGLView *__glView = [EAGLView viewWithFrame:[window bounds] \ + pixelFormat:kEAGLColorFormatRGB565 \ + depthFormat:0 /* GL_DEPTH_COMPONENT24_OES */ \ + preserveBackbuffer:NO \ + sharegroup:nil \ + multiSampling:NO \ + numberOfSamples:0 \ + ]; \ + [__director setOpenGLView:__glView]; \ + [window addSubview:__glView]; \ + [window makeKeyAndVisible]; \ +} while(0) + + +#elif __MAC_OS_X_VERSION_MAX_ALLOWED + +#import "Platforms/Mac/MacWindow.h" + +#define CC_DIRECTOR_INIT(__WINSIZE__) \ +do { \ + NSRect frameRect = NSMakeRect(0, 0, (__WINSIZE__).width, (__WINSIZE__).height); \ + self.window = [[MacWindow alloc] initWithFrame:frameRect fullscreen:NO]; \ + self.glView = [[MacGLView alloc] initWithFrame:frameRect shareContext:nil]; \ + [self.window setContentView:self.glView]; \ + CCDirector *__director = [CCDirector sharedDirector]; \ + [__director setDisplayFPS:NO]; \ + [__director setOpenGLView:self.glView]; \ + [(CCDirectorMac*)__director setOriginalWinSize:__WINSIZE__]; \ + [self.window makeMainWindow]; \ + [self.window makeKeyAndOrderFront:self]; \ +} while(0) + +#endif + + + /** @def CC_DIRECTOR_END + Stops and removes the director from memory. + Removes the EAGLView from its parent + + @since v0.99.4 + */ +#define CC_DIRECTOR_END() \ +do { \ + CCDirector *__director = [CCDirector sharedDirector]; \ + CC_GLVIEW *__view = [__director openGLView]; \ + [__view removeFromSuperview]; \ + [__director end]; \ +} while(0) + + +#if CC_IS_RETINA_DISPLAY_SUPPORTED + +/****************************/ +/** RETINA DISPLAY ENABLED **/ +/****************************/ + +/** @def CC_CONTENT_SCALE_FACTOR + On Mac it returns 1; + On iPhone it returns 2 if RetinaDisplay is On. Otherwise it returns 1 + */ +#import "Platforms/iOS/CCDirectorIOS.h" +#define CC_CONTENT_SCALE_FACTOR() __ccContentScaleFactor + + +/** @def CC_RECT_PIXELS_TO_POINTS + Converts a rect in pixels to points + */ +#define CC_RECT_PIXELS_TO_POINTS(__pixels__) \ + CGRectMake( (__pixels__).origin.x / CC_CONTENT_SCALE_FACTOR(), (__pixels__).origin.y / CC_CONTENT_SCALE_FACTOR(), \ + (__pixels__).size.width / CC_CONTENT_SCALE_FACTOR(), (__pixels__).size.height / CC_CONTENT_SCALE_FACTOR() ) + +/** @def CC_RECT_POINTS_TO_PIXELS + Converts a rect in points to pixels + */ +#define CC_RECT_POINTS_TO_PIXELS(__points__) \ + CGRectMake( (__points__).origin.x * CC_CONTENT_SCALE_FACTOR(), (__points__).origin.y * CC_CONTENT_SCALE_FACTOR(), \ + (__points__).size.width * CC_CONTENT_SCALE_FACTOR(), (__points__).size.height * CC_CONTENT_SCALE_FACTOR() ) + +#else // retina disabled + +/*****************************/ +/** RETINA DISPLAY DISABLED **/ +/*****************************/ + +#define CC_CONTENT_SCALE_FACTOR() 1 +#define CC_RECT_PIXELS_TO_POINTS(__pixels__) __pixels__ +#define CC_RECT_POINTS_TO_PIXELS(__points__) __points__ + +#endif // CC_IS_RETINA_DISPLAY_SUPPORTED diff --git a/tweejump/libs/cocos2d/ccTypes.h b/tweejump/libs/cocos2d/ccTypes.h new file mode 100755 index 0000000..46917b3 --- /dev/null +++ b/tweejump/libs/cocos2d/ccTypes.h @@ -0,0 +1,287 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-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. + */ + + +/** + @file + cocos2d (cc) types +*/ + +#import +#import + +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED +#import // CGPoint +#endif + +#import "Platforms/CCGL.h" + +/** RGB color composed of bytes 3 bytes +@since v0.8 + */ +typedef struct _ccColor3B +{ + GLubyte r; + GLubyte g; + GLubyte b; +} ccColor3B; + +//! helper macro that creates an ccColor3B type +static inline ccColor3B +ccc3(const GLubyte r, const GLubyte g, const GLubyte b) +{ + ccColor3B c = {r, g, b}; + return c; +} +//ccColor3B predefined colors +//! White color (255,255,255) +static const ccColor3B ccWHITE = {255,255,255}; +//! Yellow color (255,255,0) +static const ccColor3B ccYELLOW = {255,255,0}; +//! Blue color (0,0,255) +static const ccColor3B ccBLUE = {0,0,255}; +//! Green Color (0,255,0) +static const ccColor3B ccGREEN = {0,255,0}; +//! Red Color (255,0,0,) +static const ccColor3B ccRED = {255,0,0}; +//! Magenta Color (255,0,255) +static const ccColor3B ccMAGENTA = {255,0,255}; +//! Black Color (0,0,0) +static const ccColor3B ccBLACK = {0,0,0}; +//! Orange Color (255,127,0) +static const ccColor3B ccORANGE = {255,127,0}; +//! Gray Color (166,166,166) +static const ccColor3B ccGRAY = {166,166,166}; + +/** RGBA color composed of 4 bytes +@since v0.8 +*/ +typedef struct _ccColor4B +{ + GLubyte r; + GLubyte g; + GLubyte b; + GLubyte a; +} ccColor4B; +//! helper macro that creates an ccColor4B type +static inline ccColor4B +ccc4(const GLubyte r, const GLubyte g, const GLubyte b, const GLubyte o) +{ + ccColor4B c = {r, g, b, o}; + return c; +} + + +/** RGBA color composed of 4 floats +@since v0.8 +*/ +typedef struct _ccColor4F { + GLfloat r; + GLfloat g; + GLfloat b; + GLfloat a; +} ccColor4F; + +/** Returns a ccColor4F from a ccColor3B. Alpha will be 1. + @since v0.99.1 + */ +static inline ccColor4F ccc4FFromccc3B(ccColor3B c) +{ + return (ccColor4F){c.r/255.f, c.g/255.f, c.b/255.f, 1.f}; +} + +/** Returns a ccColor4F from a ccColor4B. + @since v0.99.1 + */ +static inline ccColor4F ccc4FFromccc4B(ccColor4B c) +{ + return (ccColor4F){c.r/255.f, c.g/255.f, c.b/255.f, c.a/255.f}; +} + +/** returns YES if both ccColor4F are equal. Otherwise it returns NO. + @since v0.99.1 + */ +static inline BOOL ccc4FEqual(ccColor4F a, ccColor4F b) +{ + return a.r == b.r && a.g == b.g && a.b == b.b && a.a == b.a; +} + +/** A vertex composed of 2 GLfloats: x, y + @since v0.8 + */ +typedef struct _ccVertex2F +{ + GLfloat x; + GLfloat y; +} ccVertex2F; + +/** A vertex composed of 2 floats: x, y + @since v0.8 + */ +typedef struct _ccVertex3F +{ + GLfloat x; + GLfloat y; + GLfloat z; +} ccVertex3F; + +/** A texcoord composed of 2 floats: u, y + @since v0.8 + */ +typedef struct _ccTex2F { + GLfloat u; + GLfloat v; +} ccTex2F; + + +//! Point Sprite component +typedef struct _ccPointSprite +{ + ccVertex2F pos; // 8 bytes + ccColor4B color; // 4 bytes + GLfloat size; // 4 bytes +} ccPointSprite; + +//! A 2D Quad. 4 * 2 floats +typedef struct _ccQuad2 { + ccVertex2F tl; + ccVertex2F tr; + ccVertex2F bl; + ccVertex2F br; +} ccQuad2; + + +//! A 3D Quad. 4 * 3 floats +typedef struct _ccQuad3 { + ccVertex3F bl; + ccVertex3F br; + ccVertex3F tl; + ccVertex3F tr; +} ccQuad3; + +//! A 2D grid size +typedef struct _ccGridSize +{ + NSInteger x; + NSInteger y; +} ccGridSize; + +//! helper function to create a ccGridSize +static inline ccGridSize +ccg(const NSInteger x, const NSInteger y) +{ + ccGridSize v = {x, y}; + return v; +} + +//! a Point with a vertex point, a tex coord point and a color 4B +typedef struct _ccV2F_C4B_T2F +{ + //! vertices (2F) + ccVertex2F vertices; + //! colors (4B) + ccColor4B colors; + //! tex coords (2F) + ccTex2F texCoords; +} ccV2F_C4B_T2F; + +//! a Point with a vertex point, a tex coord point and a color 4F +typedef struct _ccV2F_C4F_T2F +{ + //! vertices (2F) + ccVertex2F vertices; + //! colors (4F) + ccColor4F colors; + //! tex coords (2F) + ccTex2F texCoords; +} ccV2F_C4F_T2F; + +//! a Point with a vertex point, a tex coord point and a color 4B +typedef struct _ccV3F_C4B_T2F +{ + //! vertices (3F) + ccVertex3F vertices; // 12 bytes +// char __padding__[4]; + + //! colors (4B) + ccColor4B colors; // 4 bytes +// char __padding2__[4]; + + // tex coords (2F) + ccTex2F texCoords; // 8 byts +} ccV3F_C4B_T2F; + +//! 4 ccVertex2FTex2FColor4B Quad +typedef struct _ccV2F_C4B_T2F_Quad +{ + //! bottom left + ccV2F_C4B_T2F bl; + //! bottom right + ccV2F_C4B_T2F br; + //! top left + ccV2F_C4B_T2F tl; + //! top right + ccV2F_C4B_T2F tr; +} ccV2F_C4B_T2F_Quad; + +//! 4 ccVertex3FTex2FColor4B +typedef struct _ccV3F_C4B_T2F_Quad +{ + //! top left + ccV3F_C4B_T2F tl; + //! bottom left + ccV3F_C4B_T2F bl; + //! top right + ccV3F_C4B_T2F tr; + //! bottom right + ccV3F_C4B_T2F br; +} ccV3F_C4B_T2F_Quad; + +//! 4 ccVertex2FTex2FColor4F Quad +typedef struct _ccV2F_C4F_T2F_Quad +{ + //! bottom left + ccV2F_C4F_T2F bl; + //! bottom right + ccV2F_C4F_T2F br; + //! top left + ccV2F_C4F_T2F tl; + //! top right + ccV2F_C4F_T2F tr; +} ccV2F_C4F_T2F_Quad; + +//! Blend Function used for textures +typedef struct _ccBlendFunc +{ + //! source blend function + GLenum src; + //! destination blend function + GLenum dst; +} ccBlendFunc; + +//! delta time type +//! if you want more resolution redefine it as a double +typedef float ccTime; +//typedef double ccTime; diff --git a/tweejump/libs/cocos2d/cocos2d.h b/tweejump/libs/cocos2d/cocos2d.h new file mode 100755 index 0000000..600fb00 --- /dev/null +++ b/tweejump/libs/cocos2d/cocos2d.h @@ -0,0 +1,161 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-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. + */ + +/** @mainpage cocos2d for iPhone API reference + * + * @image html Icon.png + * + * @section intro Introduction + * This is cocos2d API reference + * + * The programming guide is hosted here: http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:index + * + *
+ * + * @todo A native english speaker should check the grammar. We need your help! + * + */ + +// 0x00 HI ME LO +// 00 01 00 01 +#define COCOS2D_VERSION 0x00010001 + +#import + +// +// all cocos2d include files +// +#import "ccConfig.h" // should be included first + +#import "CCActionManager.h" +#import "CCAction.h" +#import "CCActionInstant.h" +#import "CCActionInterval.h" +#import "CCActionEase.h" +#import "CCActionCamera.h" +#import "CCActionTween.h" +#import "CCActionEase.h" +#import "CCActionTiledGrid.h" +#import "CCActionGrid3D.h" +#import "CCActionGrid.h" +#import "CCActionProgressTimer.h" +#import "CCActionPageTurn3D.h" + +#import "CCAnimation.h" +#import "CCAnimationCache.h" +#import "CCSprite.h" +#import "CCSpriteFrame.h" +#import "CCSpriteBatchNode.h" +#import "CCSpriteFrameCache.h" + +#import "CCLabelTTF.h" +#import "CCLabelBMFont.h" +#import "CCLabelAtlas.h" + +#import "CCParticleSystem.h" +#import "CCParticleSystemPoint.h" +#import "CCParticleSystemQuad.h" +#import "CCParticleExamples.h" + +#import "CCTexture2D.h" +#import "CCTexturePVR.h" +#import "CCTextureCache.h" +#import "CCTextureAtlas.h" + +#import "CCTransition.h" +#import "CCTransitionPageTurn.h" +#import "CCTransitionRadial.h" + +#import "CCTMXTiledMap.h" +#import "CCTMXLayer.h" +#import "CCTMXObjectGroup.h" +#import "CCTMXXMLParser.h" +#import "CCTileMapAtlas.h" + +#import "CCLayer.h" +#import "CCMenu.h" +#import "CCMenuItem.h" +#import "CCDrawingPrimitives.h" +#import "CCScene.h" +#import "CCScheduler.h" +#import "CCBlockSupport.h" +#import "CCCamera.h" +#import "CCProtocols.h" +#import "CCNode.h" +#import "CCDirector.h" +#import "CCAtlasNode.h" +#import "CCGrabber.h" +#import "CCGrid.h" +#import "CCParallaxNode.h" +#import "CCRenderTexture.h" +#import "CCMotionStreak.h" +#import "CCConfiguration.h" + +// +// cocos2d macros +// +#import "ccTypes.h" +#import "ccMacros.h" + + +// Platform common +#import "Platforms/CCGL.h" +#import "Platforms/CCNS.h" + +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED +#import "Platforms/iOS/CCTouchDispatcher.h" +#import "Platforms/iOS/CCTouchDelegateProtocol.h" +#import "Platforms/iOS/CCTouchHandler.h" +#import "Platforms/iOS/EAGLView.h" +#import "Platforms/iOS/CCDirectorIOS.h" + +#elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED) +#import "Platforms/Mac/MacGLView.h" +#import "Platforms/Mac/CCDirectorMac.h" +#endif + +// +// cocos2d helper files +// +#import "Support/OpenGL_Internal.h" +#import "Support/CCFileUtils.h" +#import "Support/CGPointExtension.h" +#import "Support/ccCArray.h" +#import "Support/CCArray.h" +#import "Support/ccUtils.h" + +#if CC_ENABLE_PROFILERS +#import "Support/CCProfiling.h" +#endif // CC_ENABLE_PROFILERS + + +// free functions +NSString * cocos2dVersion(void); + +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED +#ifndef __IPHONE_4_0 +#error "If you are targeting iPad, you should set BASE SDK = 4.0 (or 4.1, or 4.2), and set the 'iOS deploy target' = 3.2" +#endif +#endif diff --git a/tweejump/libs/cocos2d/cocos2d.m b/tweejump/libs/cocos2d/cocos2d.m new file mode 100755 index 0000000..2b17055 --- /dev/null +++ b/tweejump/libs/cocos2d/cocos2d.m @@ -0,0 +1,34 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-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. + */ + + +#import +#import "cocos2d.h" +static NSString *version = @"cocos2d v1.0.1"; + +NSString *cocos2dVersion() +{ + return version; +} diff --git a/main.m b/tweejump/main.m old mode 100644 new mode 100755 similarity index 64% rename from main.m rename to tweejump/main.m index 7182162..d1b05fa --- a/main.m +++ b/tweejump/main.m @@ -1,3 +1,11 @@ +// +// main.m +// tweejump +// +// Created by Yannick Loriot on 10/07/12. +// Copyright Yannick Loriot 2012. All rights reserved. +// + #import int main(int argc, char *argv[]) { diff --git a/tweejump_Prefix.pch b/tweejump_Prefix.pch deleted file mode 100644 index 858b5e4..0000000 --- a/tweejump_Prefix.pch +++ /dev/null @@ -1,4 +0,0 @@ -#ifdef __OBJC__ -#import -#import -#endif