diff options
| author | Starla Insigna <starla4444@gmail.com> | 2011-07-30 11:19:14 -0400 |
|---|---|---|
| committer | Starla Insigna <starla4444@gmail.com> | 2011-07-30 11:19:14 -0400 |
| commit | 9cd57b731ab1c666d4a1cb725538fdc137763d12 (patch) | |
| tree | 5bac45ae5157a1cb10c6e45500cbf72789917980 /libs/cocos2d/CCDirector.h | |
| download | cartcollect-9cd57b731ab1c666d4a1cb725538fdc137763d12.tar.gz cartcollect-9cd57b731ab1c666d4a1cb725538fdc137763d12.tar.bz2 cartcollect-9cd57b731ab1c666d4a1cb725538fdc137763d12.zip | |
Initial commit (version 0.2.1)
Diffstat (limited to 'libs/cocos2d/CCDirector.h')
| -rwxr-xr-x | libs/cocos2d/CCDirector.h | 307 |
1 files changed, 307 insertions, 0 deletions
| diff --git a/libs/cocos2d/CCDirector.h b/libs/cocos2d/CCDirector.h new file mode 100755 index 0000000..9c3f3fe --- /dev/null +++ b/libs/cocos2d/CCDirector.h | |||
| @@ -0,0 +1,307 @@ | |||
| 1 | /* | ||
| 2 | * cocos2d for iPhone: http://www.cocos2d-iphone.org | ||
| 3 | * | ||
| 4 | * Copyright (c) 2008-2010 Ricardo Quesada | ||
| 5 | * Copyright (c) 2011 Zynga Inc. | ||
| 6 | * | ||
| 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| 8 | * of this software and associated documentation files (the "Software"), to deal | ||
| 9 | * in the Software without restriction, including without limitation the rights | ||
| 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| 11 | * copies of the Software, and to permit persons to whom the Software is | ||
| 12 | * furnished to do so, subject to the following conditions: | ||
| 13 | * | ||
| 14 | * The above copyright notice and this permission notice shall be included in | ||
| 15 | * all copies or substantial portions of the Software. | ||
| 16 | * | ||
| 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| 23 | * THE SOFTWARE. | ||
| 24 | */ | ||
| 25 | |||
| 26 | |||
| 27 | #import "ccConfig.h" | ||
| 28 | #import "ccTypes.h" | ||
| 29 | |||
| 30 | // OpenGL related | ||
| 31 | #import "Platforms/CCGL.h" | ||
| 32 | #import "CCProtocols.h" | ||
| 33 | |||
| 34 | /** @typedef ccDirectorProjection | ||
| 35 | Possible OpenGL projections used by director | ||
| 36 | */ | ||
| 37 | typedef enum { | ||
| 38 | /// sets a 2D projection (orthogonal projection). | ||
| 39 | kCCDirectorProjection2D, | ||
| 40 | |||
| 41 | /// sets a 3D projection with a fovy=60, znear=0.5f and zfar=1500. | ||
| 42 | kCCDirectorProjection3D, | ||
| 43 | |||
| 44 | /// it calls "updateProjection" on the projection delegate. | ||
| 45 | kCCDirectorProjectionCustom, | ||
| 46 | |||
| 47 | /// Detault projection is 3D projection | ||
| 48 | kCCDirectorProjectionDefault = kCCDirectorProjection3D, | ||
| 49 | |||
| 50 | // backward compatibility stuff | ||
| 51 | CCDirectorProjection2D = kCCDirectorProjection2D, | ||
| 52 | CCDirectorProjection3D = kCCDirectorProjection3D, | ||
| 53 | CCDirectorProjectionCustom = kCCDirectorProjectionCustom, | ||
| 54 | |||
| 55 | } ccDirectorProjection; | ||
| 56 | |||
| 57 | |||
| 58 | @class CCLabelAtlas; | ||
| 59 | @class CCScene; | ||
| 60 | |||
| 61 | /**Class that creates and handle the main Window and manages how | ||
| 62 | and when to execute the Scenes. | ||
| 63 | |||
| 64 | The CCDirector is also resposible for: | ||
| 65 | - initializing the OpenGL ES context | ||
| 66 | - setting the OpenGL pixel format (default on is RGB565) | ||
| 67 | - setting the OpenGL buffer depth (default one is 0-bit) | ||
| 68 | - setting the projection (default one is 3D) | ||
| 69 | - setting the orientation (default one is Protrait) | ||
| 70 | |||
| 71 | Since the CCDirector is a singleton, the standard way to use it is by calling: | ||
| 72 | - [[CCDirector sharedDirector] methodName]; | ||
| 73 | |||
| 74 | The CCDirector also sets the default OpenGL context: | ||
| 75 | - GL_TEXTURE_2D is enabled | ||
| 76 | - GL_VERTEX_ARRAY is enabled | ||
| 77 | - GL_COLOR_ARRAY is enabled | ||
| 78 | - GL_TEXTURE_COORD_ARRAY is enabled | ||
| 79 | */ | ||
| 80 | @interface CCDirector : NSObject | ||
| 81 | { | ||
| 82 | CC_GLVIEW *openGLView_; | ||
| 83 | |||
| 84 | // internal timer | ||
| 85 | NSTimeInterval animationInterval_; | ||
| 86 | NSTimeInterval oldAnimationInterval_; | ||
| 87 | |||
| 88 | /* display FPS ? */ | ||
| 89 | BOOL displayFPS_; | ||
| 90 | |||
| 91 | NSUInteger frames_; | ||
| 92 | ccTime accumDt_; | ||
| 93 | ccTime frameRate_; | ||
| 94 | #if CC_DIRECTOR_FAST_FPS | ||
| 95 | CCLabelAtlas *FPSLabel_; | ||
| 96 | #endif | ||
| 97 | |||
| 98 | /* is the running scene paused */ | ||
| 99 | BOOL isPaused_; | ||
| 100 | |||
| 101 | /* The running scene */ | ||
| 102 | CCScene *runningScene_; | ||
| 103 | |||
| 104 | /* This object will be visited after the scene. Useful to hook a notification node */ | ||
| 105 | id notificationNode_; | ||
| 106 | |||
| 107 | /* will be the next 'runningScene' in the next frame | ||
| 108 | nextScene is a weak reference. */ | ||
| 109 | CCScene *nextScene_; | ||
| 110 | |||
| 111 | /* If YES, then "old" scene will receive the cleanup message */ | ||
| 112 | BOOL sendCleanupToScene_; | ||
| 113 | |||
| 114 | /* scheduled scenes */ | ||
| 115 | NSMutableArray *scenesStack_; | ||
| 116 | |||
| 117 | /* last time the main loop was updated */ | ||
| 118 | struct timeval lastUpdate_; | ||
| 119 | /* delta time since last tick to main loop */ | ||
| 120 | ccTime dt; | ||
| 121 | /* whether or not the next delta time will be zero */ | ||
| 122 | BOOL nextDeltaTimeZero_; | ||
| 123 | |||
| 124 | /* projection used */ | ||
| 125 | ccDirectorProjection projection_; | ||
| 126 | |||
| 127 | /* Projection protocol delegate */ | ||
| 128 | id<CCProjectionProtocol> projectionDelegate_; | ||
| 129 | |||
| 130 | /* window size in points */ | ||
| 131 | CGSize winSizeInPoints_; | ||
| 132 | |||
| 133 | /* window size in pixels */ | ||
| 134 | CGSize winSizeInPixels_; | ||
| 135 | |||
| 136 | /* the cocos2d running thread */ | ||
| 137 | NSThread *runningThread_; | ||
| 138 | |||
| 139 | // profiler | ||
| 140 | #if CC_ENABLE_PROFILERS | ||
| 141 | ccTime accumDtForProfiler_; | ||
| 142 | #endif | ||
| 143 | } | ||
| 144 | |||
| 145 | /** returns the cocos2d thread. | ||
| 146 | If you want to run any cocos2d task, run it in this thread. | ||
| 147 | On iOS usually it is the main thread. | ||
| 148 | @since v0.99.5 | ||
| 149 | */ | ||
| 150 | @property (readonly, nonatomic ) NSThread *runningThread; | ||
| 151 | /** The current running Scene. Director can only run one Scene at the time */ | ||
| 152 | @property (nonatomic,readonly) CCScene* runningScene; | ||
| 153 | /** The FPS value */ | ||
| 154 | @property (nonatomic,readwrite, assign) NSTimeInterval animationInterval; | ||
| 155 | /** Whether or not to display the FPS on the bottom-left corner */ | ||
| 156 | @property (nonatomic,readwrite, assign) BOOL displayFPS; | ||
| 157 | /** The OpenGLView, where everything is rendered */ | ||
| 158 | @property (nonatomic,readwrite,retain) CC_GLVIEW *openGLView; | ||
| 159 | /** whether or not the next delta time will be zero */ | ||
| 160 | @property (nonatomic,readwrite,assign) BOOL nextDeltaTimeZero; | ||
| 161 | /** Whether or not the Director is paused */ | ||
| 162 | @property (nonatomic,readonly) BOOL isPaused; | ||
| 163 | /** Sets an OpenGL projection | ||
| 164 | @since v0.8.2 | ||
| 165 | */ | ||
| 166 | @property (nonatomic,readwrite) ccDirectorProjection projection; | ||
| 167 | /** How many frames were called since the director started */ | ||
| 168 | @property (readonly) NSUInteger frames; | ||
| 169 | |||
| 170 | /** Whether or not the replaced scene will receive the cleanup message. | ||
| 171 | If the new scene is pushed, then the old scene won't receive the "cleanup" message. | ||
| 172 | If the new scene replaces the old one, the it will receive the "cleanup" message. | ||
| 173 | @since v0.99.0 | ||
| 174 | */ | ||
| 175 | @property (nonatomic, readonly) BOOL sendCleanupToScene; | ||
| 176 | |||
| 177 | /** This object will be visited after the main scene is visited. | ||
| 178 | This object MUST implement the "visit" selector. | ||
| 179 | Useful to hook a notification object, like CCNotifications (http://github.com/manucorporat/CCNotifications) | ||
| 180 | @since v0.99.5 | ||
| 181 | */ | ||
| 182 | @property (nonatomic, readwrite, retain) id notificationNode; | ||
| 183 | |||
| 184 | /** This object will be called when the OpenGL projection is udpated and only when the kCCDirectorProjectionCustom projection is used. | ||
| 185 | @since v0.99.5 | ||
| 186 | */ | ||
| 187 | @property (nonatomic, readwrite, retain) id<CCProjectionProtocol> projectionDelegate; | ||
| 188 | |||
| 189 | /** returns a shared instance of the director */ | ||
| 190 | +(CCDirector *)sharedDirector; | ||
| 191 | |||
| 192 | |||
| 193 | |||
| 194 | // Window size | ||
| 195 | |||
| 196 | /** returns the size of the OpenGL view in points. | ||
| 197 | It takes into account any possible rotation (device orientation) of the window | ||
| 198 | */ | ||
| 199 | - (CGSize) winSize; | ||
| 200 | |||
| 201 | /** returns the size of the OpenGL view in pixels. | ||
| 202 | It takes into account any possible rotation (device orientation) of the window. | ||
| 203 | On Mac winSize and winSizeInPixels return the same value. | ||
| 204 | */ | ||
| 205 | - (CGSize) winSizeInPixels; | ||
| 206 | /** returns the display size of the OpenGL view in pixels. | ||
| 207 | It doesn't take into account any possible rotation of the window. | ||
| 208 | */ | ||
| 209 | -(CGSize) displaySizeInPixels; | ||
| 210 | /** changes the projection size */ | ||
| 211 | -(void) reshapeProjection:(CGSize)newWindowSize; | ||
| 212 | |||
| 213 | /** converts a UIKit coordinate to an OpenGL coordinate | ||
| 214 | Useful to convert (multi) touchs coordinates to the current layout (portrait or landscape) | ||
| 215 | */ | ||
| 216 | -(CGPoint) convertToGL: (CGPoint) p; | ||
| 217 | /** converts an OpenGL coordinate to a UIKit coordinate | ||
| 218 | Useful to convert node points to window points for calls such as glScissor | ||
| 219 | */ | ||
| 220 | -(CGPoint) convertToUI:(CGPoint)p; | ||
| 221 | |||
| 222 | /// XXX: missing description | ||
| 223 | -(float) getZEye; | ||
| 224 | |||
| 225 | // Scene Management | ||
| 226 | |||
| 227 | /**Enters the Director's main loop with the given Scene. | ||
| 228 | * Call it to run only your FIRST scene. | ||
| 229 | * Don't call it if there is already a running scene. | ||
| 230 | */ | ||
| 231 | - (void) runWithScene:(CCScene*) scene; | ||
| 232 | |||
| 233 | /**Suspends the execution of the running scene, pushing it on the stack of suspended scenes. | ||
| 234 | * The new scene will be executed. | ||
| 235 | * Try to avoid big stacks of pushed scenes to reduce memory allocation. | ||
| 236 | * ONLY call it if there is a running scene. | ||
| 237 | */ | ||
| 238 | - (void) pushScene:(CCScene*) scene; | ||
| 239 | |||
| 240 | /**Pops out a scene from the queue. | ||
| 241 | * This scene will replace the running one. | ||
| 242 | * The running scene will be deleted. If there are no more scenes in the stack the execution is terminated. | ||
| 243 | * ONLY call it if there is a running scene. | ||
| 244 | */ | ||
| 245 | - (void) popScene; | ||
| 246 | |||
| 247 | /** Replaces the running scene with a new one. The running scene is terminated. | ||
| 248 | * ONLY call it if there is a running scene. | ||
| 249 | */ | ||
| 250 | -(void) replaceScene: (CCScene*) scene; | ||
| 251 | |||
| 252 | /** Ends the execution, releases the running scene. | ||
| 253 | It doesn't remove the OpenGL view from its parent. You have to do it manually. | ||
| 254 | */ | ||
| 255 | -(void) end; | ||
| 256 | |||
| 257 | /** Pauses the running scene. | ||
| 258 | The running scene will be _drawed_ but all scheduled timers will be paused | ||
| 259 | While paused, the draw rate will be 4 FPS to reduce CPU consuption | ||
| 260 | */ | ||
| 261 | -(void) pause; | ||
| 262 | |||
| 263 | /** Resumes the paused scene | ||
| 264 | The scheduled timers will be activated again. | ||
| 265 | The "delta time" will be 0 (as if the game wasn't paused) | ||
| 266 | */ | ||
| 267 | -(void) resume; | ||
| 268 | |||
| 269 | /** Stops the animation. Nothing will be drawn. The main loop won't be triggered anymore. | ||
| 270 | If you wan't to pause your animation call [pause] instead. | ||
| 271 | */ | ||
| 272 | -(void) stopAnimation; | ||
| 273 | |||
| 274 | /** The main loop is triggered again. | ||
| 275 | Call this function only if [stopAnimation] was called earlier | ||
| 276 | @warning Dont' call this function to start the main loop. To run the main loop call runWithScene | ||
| 277 | */ | ||
| 278 | -(void) startAnimation; | ||
| 279 | |||
| 280 | /** Draw the scene. | ||
| 281 | This method is called every frame. Don't call it manually. | ||
| 282 | */ | ||
| 283 | -(void) drawScene; | ||
| 284 | |||
| 285 | // Memory Helper | ||
| 286 | |||
| 287 | /** Removes all the cocos2d data that was cached automatically. | ||
| 288 | It will purge the CCTextureCache, CCLabelBMFont cache. | ||
| 289 | IMPORTANT: The CCSpriteFrameCache won't be purged. If you want to purge it, you have to purge it manually. | ||
| 290 | @since v0.99.3 | ||
| 291 | */ | ||
| 292 | -(void) purgeCachedData; | ||
| 293 | |||
| 294 | // OpenGL Helper | ||
| 295 | |||
| 296 | /** sets the OpenGL default values */ | ||
| 297 | -(void) setGLDefaultValues; | ||
| 298 | |||
| 299 | /** enables/disables OpenGL alpha blending */ | ||
| 300 | - (void) setAlphaBlending: (BOOL) on; | ||
| 301 | /** enables/disables OpenGL depth test */ | ||
| 302 | - (void) setDepthTest: (BOOL) on; | ||
| 303 | |||
| 304 | // Profiler | ||
| 305 | -(void) showProfilers; | ||
| 306 | |||
| 307 | @end | ||
