00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #import "ccConfig.h"
00029 #import "ccTypes.h"
00030
00031
00032 #import "Support/EAGLView.h"
00033
00037 typedef enum {
00039 kCCPixelFormatRGB565,
00041 kCCPixelFormatRGBA8888,
00043 kCCPixelFormatDefault = kCCPixelFormatRGB565,
00044
00045
00046 kPixelFormatRGB565 = kCCPixelFormatRGB565,
00047 kRGB565 = kCCPixelFormatRGB565,
00048 kPixelFormatRGBA8888 = kCCPixelFormatRGBA8888,
00049 kRGBA8 = kCCPixelFormatRGBA8888,
00050 } tPixelFormat;
00051
00056 typedef enum {
00058 kCCDepthBufferNone,
00060 kCCDepthBuffer16,
00062 kCCDepthBuffer24,
00063
00064
00065 kDepthBuffer16 = kCCDepthBuffer16,
00066 kDepthBuffer24 = kCCDepthBuffer24,
00067 } tDepthBufferFormat;
00068
00072 typedef enum {
00074 kCCDirectorProjection2D,
00075
00077 kCCDirectorProjection3D,
00078
00080 kCCDirectorProjectionCustom,
00081
00083 kCCDirectorProjectionDefault = kCCDirectorProjection3D,
00084
00085
00086 CCDirectorProjection2D = kCCDirectorProjection2D,
00087 CCDirectorProjection3D = kCCDirectorProjection3D,
00088 CCDirectorProjectionCustom = kCCDirectorProjectionCustom,
00089
00090 } ccDirectorProjection;
00091
00096 typedef enum {
00104 kCCDirectorTypeNSTimer,
00105
00113 kCCDirectorTypeMainLoop,
00114
00122 kCCDirectorTypeThreadMainLoop,
00123
00133 kCCDirectorTypeDisplayLink,
00134
00136 kCCDirectorTypeDefault = kCCDirectorTypeNSTimer,
00137
00138
00139 CCDirectorTypeNSTimer = kCCDirectorTypeNSTimer,
00140 CCDirectorTypeMainLoop = kCCDirectorTypeMainLoop,
00141 CCDirectorTypeThreadMainLoop = kCCDirectorTypeThreadMainLoop,
00142 CCDirectorTypeDisplayLink = kCCDirectorTypeDisplayLink,
00143 CCDirectorTypeDefault =kCCDirectorTypeDefault,
00144
00145
00146 } ccDirectorType;
00147
00151 typedef enum {
00153 kCCDeviceOrientationPortrait = UIDeviceOrientationPortrait,
00155 kCCDeviceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown,
00157 kCCDeviceOrientationLandscapeLeft = UIDeviceOrientationLandscapeLeft,
00159 kCCDeviceOrientationLandscapeRight = UIDeviceOrientationLandscapeRight,
00160
00161
00162 CCDeviceOrientationPortrait = kCCDeviceOrientationPortrait,
00163 CCDeviceOrientationPortraitUpsideDown = kCCDeviceOrientationPortraitUpsideDown,
00164 CCDeviceOrientationLandscapeLeft = kCCDeviceOrientationLandscapeLeft,
00165 CCDeviceOrientationLandscapeRight = kCCDeviceOrientationLandscapeRight,
00166 } ccDeviceOrientation;
00167
00168 @class CCLabelAtlas;
00169 @class CCScene;
00170
00190 @interface CCDirector : NSObject
00191 {
00192 EAGLView *openGLView_;
00193
00194
00195 NSTimeInterval animationInterval_;
00196 NSTimeInterval oldAnimationInterval_;
00197
00198 tPixelFormat pixelFormat_;
00199 tDepthBufferFormat depthBufferFormat_;
00200
00201
00202 ccDeviceOrientation deviceOrientation_;
00203
00204
00205 BOOL displayFPS_;
00206
00207 int frames_;
00208 ccTime accumDt_;
00209 ccTime frameRate_;
00210 #if CC_DIRECTOR_FAST_FPS
00211 CCLabelAtlas *FPSLabel_;
00212 #endif
00213
00214
00215 BOOL isPaused_;
00216
00217
00218 CCScene *runningScene_;
00219
00220
00221
00222 CCScene *nextScene_;
00223
00224
00225 BOOL sendCleanupToScene_;
00226
00227
00228 NSMutableArray *scenesStack_;
00229
00230
00231 struct timeval lastUpdate_;
00232
00233 ccTime dt;
00234
00235 BOOL nextDeltaTimeZero_;
00236
00237
00238 ccDirectorProjection projection_;
00239
00240
00241 CGSize screenSize_;
00242
00243
00244 CGSize surfaceSize_;
00245
00246
00247 CGFloat contentScaleFactor_;
00248
00249
00250 BOOL isContentScaleSupported_;
00251
00252 #if CC_ENABLE_PROFILERS
00253 ccTime accumDtForProfiler_;
00254 #endif
00255 }
00256
00258 @property (nonatomic,readonly) CCScene* runningScene;
00260 @property (nonatomic,readwrite, assign) NSTimeInterval animationInterval;
00262 @property (nonatomic,readwrite, assign) BOOL displayFPS;
00264 @property (nonatomic,readwrite,retain) EAGLView *openGLView;
00266 @property (nonatomic,readonly) tPixelFormat pixelFormat DEPRECATED_ATTRIBUTE;
00268 @property (nonatomic,readwrite,assign) BOOL nextDeltaTimeZero;
00270 @property (nonatomic,readwrite) ccDeviceOrientation deviceOrientation;
00272 @property (nonatomic,readonly) BOOL isPaused;
00276 @property (nonatomic,readwrite) ccDirectorProjection projection;
00277
00283 @property (nonatomic, readonly) BOOL sendCleanupToScene;
00284
00293 @property (nonatomic, readwrite) CGFloat contentScaleFactor;
00294
00296 +(CCDirector *)sharedDirector;
00297
00313 +(BOOL) setDirectorType:(ccDirectorType) directorType;
00314
00315
00316
00317
00324 -(void) setPixelFormat: (tPixelFormat)p DEPRECATED_ATTRIBUTE;
00325
00332 -(void) setDepthBufferFormat: (tDepthBufferFormat)db DEPRECATED_ATTRIBUTE;
00333
00334
00336 -(BOOL)detach DEPRECATED_ATTRIBUTE;
00337
00343 -(BOOL)attachInWindow:(UIWindow *)window DEPRECATED_ATTRIBUTE;
00344
00350 -(BOOL)attachInView:(UIView *)view DEPRECATED_ATTRIBUTE;
00351
00357 -(BOOL)attachInView:(UIView *)view withFrame:(CGRect)frame DEPRECATED_ATTRIBUTE;
00358
00359
00360
00362 - (CGSize) winSize;
00364 -(CGSize) displaySize;
00365
00369 -(CGPoint) convertToGL: (CGPoint) p;
00373 -(CGPoint) convertToUI:(CGPoint)p;
00374
00375
00376 -(void) applyOrientation;
00377
00379 -(float) getZEye;
00380
00381
00382
00387 - (void) runWithScene:(CCScene*) scene;
00388
00394 - (void) pushScene:(CCScene*) scene;
00395
00401 - (void) popScene;
00402
00406 -(void) replaceScene: (CCScene*) scene;
00407
00411 -(void) end;
00412
00417 -(void) pause;
00418
00423 -(void) resume;
00424
00428 -(void) stopAnimation;
00429
00434 -(void) startAnimation;
00435
00439 -(void) drawScene;
00440
00441
00442
00448 -(void) purgeCachedData;
00449
00450
00451
00452
00454 -(void) setGLDefaultValues;
00455
00457 - (void) setAlphaBlending: (BOOL) on;
00459 - (void) setDepthTest: (BOOL) on;
00463 - (void) recalculateProjectionAndEAGLViewSize;
00464
00465 @end
00466
00474 @interface CCFastDirector : CCDirector
00475 {
00476 BOOL isRunning;
00477
00478 NSAutoreleasePool *autoreleasePool;
00479 }
00480 -(void) preMainLoop;
00481 @end
00482
00492 @interface CCThreadedFastDirector : CCDirector
00493 {
00494 BOOL isRunning;
00495 }
00496 -(void) preMainLoop;
00497 @end
00498
00510 @interface CCDisplayLinkDirector : CCDirector
00511 {
00512 id displayLink;
00513 }
00514 -(void) preMainLoop:(id)sender;
00515 @end
00516
00526 @interface CCTimerDirector : CCDirector
00527 {
00528 NSTimer *animationTimer;
00529 }
00530 @end
00531