2010-08-02 10:58:00 +08:00
|
|
|
/****************************************************************************
|
2011-03-19 10:59:01 +08:00
|
|
|
Copyright (c) 2010-2011 cocos2d-x.org
|
|
|
|
Copyright (c) 2008-2010 Ricardo Quesada
|
2011-07-05 14:51:17 +08:00
|
|
|
Copyright (c) 2011 Zynga Inc.
|
2010-08-02 10:58:00 +08:00
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
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 __CCDIRECTOR_H__
|
|
|
|
#define __CCDIRECTOR_H__
|
|
|
|
|
2011-01-07 09:35:27 +08:00
|
|
|
#include "platform/CCPlatformMacros.h"
|
2011-03-07 17:11:57 +08:00
|
|
|
#include "CCObject.h"
|
2011-01-15 18:05:35 +08:00
|
|
|
#include "ccTypes.h"
|
2011-03-07 17:11:57 +08:00
|
|
|
#include "CCGeometry.h"
|
|
|
|
#include "CCMutableArray.h"
|
|
|
|
#include "CCGeometry.h"
|
|
|
|
#include "CCEGLView.h"
|
2010-12-29 18:01:37 +08:00
|
|
|
#include "CCGL.h"
|
2011-06-20 17:31:38 +08:00
|
|
|
|
2010-09-28 16:18:05 +08:00
|
|
|
namespace cocos2d {
|
2010-07-12 17:03:27 +08:00
|
|
|
|
|
|
|
/** @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,
|
|
|
|
|
2010-12-29 18:01:37 +08:00
|
|
|
/// it calls "updateProjection" on the projection delegate.
|
2010-07-12 17:03:27 +08:00
|
|
|
kCCDirectorProjectionCustom,
|
|
|
|
|
|
|
|
/// Detault projection is 3D projection
|
|
|
|
kCCDirectorProjectionDefault = kCCDirectorProjection3D,
|
2010-07-16 14:09:31 +08:00
|
|
|
|
|
|
|
// backward compatibility stuff
|
|
|
|
CCDirectorProjection2D = kCCDirectorProjection2D,
|
|
|
|
CCDirectorProjection3D = kCCDirectorProjection3D,
|
|
|
|
CCDirectorProjectionCustom = kCCDirectorProjectionCustom,
|
2010-07-12 17:03:27 +08:00
|
|
|
} ccDirectorProjection;
|
|
|
|
|
|
|
|
/** @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
|
2010-09-29 17:39:45 +08:00
|
|
|
* - The interval update is customizable from 1 to 60
|
2010-07-12 17:03:27 +08:00
|
|
|
*/
|
|
|
|
kCCDirectorTypeNSTimer,
|
|
|
|
|
|
|
|
/** will use a Director that triggers the main loop from a custom main loop.
|
|
|
|
*
|
|
|
|
* Features and Limitations:
|
|
|
|
* - Faster than NSTimer Director
|
2010-09-29 17:39:45 +08:00
|
|
|
* - It doesn't integrate well with UIKit objects
|
2010-07-12 17:03:27 +08:00
|
|
|
* - 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
|
2010-09-29 17:39:45 +08:00
|
|
|
* - It doesn't integrate well with UIKit objects
|
2010-07-12 17:03:27 +08:00
|
|
|
* - 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,
|
2010-07-16 14:09:31 +08:00
|
|
|
|
|
|
|
// backward compatibility stuff
|
|
|
|
CCDirectorTypeNSTimer = kCCDirectorTypeNSTimer,
|
|
|
|
CCDirectorTypeMainLoop = kCCDirectorTypeMainLoop,
|
|
|
|
CCDirectorTypeThreadMainLoop = kCCDirectorTypeThreadMainLoop,
|
|
|
|
CCDirectorTypeDisplayLink = kCCDirectorTypeDisplayLink,
|
|
|
|
CCDirectorTypeDefault =kCCDirectorTypeDefault,
|
2010-07-12 17:03:27 +08:00
|
|
|
} ccDirectorType;
|
|
|
|
|
|
|
|
/** @typedef ccDeviceOrientation
|
|
|
|
Possible device orientations
|
|
|
|
*/
|
|
|
|
typedef enum {
|
|
|
|
/// Device oriented vertically, home button on the bottom
|
2010-07-20 14:07:27 +08:00
|
|
|
kCCDeviceOrientationPortrait = 0, // UIDeviceOrientationPortrait,
|
2010-07-12 17:03:27 +08:00
|
|
|
/// Device oriented vertically, home button on the top
|
2010-07-20 14:07:27 +08:00
|
|
|
kCCDeviceOrientationPortraitUpsideDown = 1, // UIDeviceOrientationPortraitUpsideDown,
|
2010-07-12 17:03:27 +08:00
|
|
|
/// Device oriented horizontally, home button on the right
|
2010-07-20 14:07:27 +08:00
|
|
|
kCCDeviceOrientationLandscapeLeft = 2, // UIDeviceOrientationLandscapeLeft,
|
2010-07-12 17:03:27 +08:00
|
|
|
/// Device oriented horizontally, home button on the left
|
2010-07-20 14:07:27 +08:00
|
|
|
kCCDeviceOrientationLandscapeRight = 3, // UIDeviceOrientationLandscapeRight,
|
2010-07-16 14:09:31 +08:00
|
|
|
|
|
|
|
// Backward compatibility stuff
|
|
|
|
CCDeviceOrientationPortrait = kCCDeviceOrientationPortrait,
|
|
|
|
CCDeviceOrientationPortraitUpsideDown = kCCDeviceOrientationPortraitUpsideDown,
|
|
|
|
CCDeviceOrientationLandscapeLeft = kCCDeviceOrientationLandscapeLeft,
|
|
|
|
CCDeviceOrientationLandscapeRight = kCCDeviceOrientationLandscapeRight,
|
2010-07-12 17:03:27 +08:00
|
|
|
} ccDeviceOrientation;
|
|
|
|
|
2010-12-24 17:07:31 +08:00
|
|
|
class CCLabelTTF;
|
2010-07-12 17:03:27 +08:00
|
|
|
class CCScene;
|
2011-03-07 17:11:57 +08:00
|
|
|
class CCEGLView;
|
2010-12-30 10:28:13 +08:00
|
|
|
class CCNode;
|
|
|
|
class CCProjectionProtocol;
|
2010-07-12 17:03:27 +08:00
|
|
|
|
2010-09-28 18:27:33 +08:00
|
|
|
/**
|
|
|
|
@brief Class that creates and handle the main Window and manages how
|
2010-07-12 17:03:27 +08:00
|
|
|
and when to execute the Scenes.
|
|
|
|
|
2010-09-28 16:18:05 +08:00
|
|
|
The CCDirector is also responsible for:
|
2010-12-29 18:01:37 +08:00
|
|
|
- initializing the OpenGL 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)
|
2010-07-12 17:03:27 +08:00
|
|
|
- setting the orientation (default one is Protrait)
|
|
|
|
|
|
|
|
Since the CCDirector is a singleton, the standard way to use it is by calling:
|
2010-12-29 18:01:37 +08:00
|
|
|
_ CCDirector::sharedDirector()->methodName();
|
2010-07-12 17:03:27 +08:00
|
|
|
|
2010-12-29 18:01:37 +08:00
|
|
|
The CCDirector also sets the default OpenGL context:
|
2010-07-12 17:03:27 +08:00
|
|
|
- GL_TEXTURE_2D is enabled
|
|
|
|
- GL_VERTEX_ARRAY is enabled
|
|
|
|
- GL_COLOR_ARRAY is enabled
|
|
|
|
- GL_TEXTURE_COORD_ARRAY is enabled
|
|
|
|
*/
|
2011-03-07 17:11:57 +08:00
|
|
|
class CC_DLL CCDirector : public CCObject
|
2010-07-12 17:03:27 +08:00
|
|
|
{
|
2010-07-16 14:09:31 +08:00
|
|
|
public:
|
2010-09-04 12:02:52 +08:00
|
|
|
virtual bool init(void);
|
2010-07-16 14:09:31 +08:00
|
|
|
virtual ~CCDirector(void);
|
2010-07-20 14:07:27 +08:00
|
|
|
CCDirector(void) {}
|
2010-07-16 14:09:31 +08:00
|
|
|
|
|
|
|
// attribute
|
|
|
|
|
2010-09-29 17:39:45 +08:00
|
|
|
/** Get current running Scene. Director can only run one Scene at the time */
|
2010-08-02 12:00:06 +08:00
|
|
|
inline CCScene* getRunningScene(void) { return m_pRunningScene; }
|
2010-07-12 17:03:27 +08:00
|
|
|
|
2010-09-29 17:39:45 +08:00
|
|
|
/** Get the FPS value */
|
2010-08-02 12:00:06 +08:00
|
|
|
inline double getAnimationInterval(void) { return m_dAnimationInterval; }
|
2010-09-30 15:54:15 +08:00
|
|
|
/** Set the FPS value. */
|
2011-04-11 15:10:09 +08:00
|
|
|
virtual void setAnimationInterval(double dValue) = 0;
|
2010-07-12 17:03:27 +08:00
|
|
|
|
2010-09-28 16:18:05 +08:00
|
|
|
/** Whether or not to display the FPS on the bottom-left corner */
|
2010-08-02 12:00:06 +08:00
|
|
|
inline bool isDisplayFPS(void) { return m_bDisplayFPS; }
|
2010-09-29 17:39:45 +08:00
|
|
|
/** Display the FPS on the bottom-left corner */
|
2010-08-02 12:00:06 +08:00
|
|
|
inline void setDisplayFPS(bool bDisplayFPS) { m_bDisplayFPS = bDisplayFPS; }
|
2010-07-12 17:03:27 +08:00
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
/** Get the CCEGLView, where everything is rendered */
|
2010-12-29 18:01:37 +08:00
|
|
|
inline CC_GLVIEW* getOpenGLView(void) { return m_pobOpenGLView; }
|
|
|
|
void setOpenGLView(CC_GLVIEW *pobOpenGLView);
|
2010-07-12 17:03:27 +08:00
|
|
|
|
2010-08-02 12:00:06 +08:00
|
|
|
inline bool isNextDeltaTimeZero(void) { return m_bNextDeltaTimeZero; }
|
2010-07-12 17:03:27 +08:00
|
|
|
void setNextDeltaTimeZero(bool bNextDeltaTimeZero);
|
|
|
|
|
2010-09-28 16:18:05 +08:00
|
|
|
/** Whether or not the Director is paused */
|
2010-08-02 12:00:06 +08:00
|
|
|
inline bool isPaused(void) { return m_bPaused; }
|
2010-07-12 17:03:27 +08:00
|
|
|
|
|
|
|
/** Sets an OpenGL projection
|
|
|
|
@since v0.8.2
|
|
|
|
*/
|
2010-08-02 12:00:06 +08:00
|
|
|
inline ccDirectorProjection getProjection(void) { return m_eProjection; }
|
2010-07-12 17:03:27 +08:00
|
|
|
void setProjection(ccDirectorProjection kProjection);
|
|
|
|
|
|
|
|
/** 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
|
|
|
|
*/
|
2010-08-02 12:00:06 +08:00
|
|
|
inline bool isSendCleanupToScene(void) { return m_bSendCleanupToScene; }
|
2010-07-12 17:03:27 +08:00
|
|
|
|
|
|
|
|
2010-12-29 18:01:37 +08:00
|
|
|
// window size
|
2010-07-12 17:03:27 +08:00
|
|
|
|
2010-12-29 18:01:37 +08:00
|
|
|
/** returns the size of the OpenGL view in points.
|
|
|
|
It takes into account any possible rotation (device orientation) of the window
|
|
|
|
*/
|
2011-03-07 17:11:57 +08:00
|
|
|
CCSize getWinSize(void);
|
2010-07-12 17:03:27 +08:00
|
|
|
|
2010-12-29 18:01:37 +08:00
|
|
|
/** 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.
|
|
|
|
*/
|
2011-03-07 17:11:57 +08:00
|
|
|
CCSize getWinSizeInPixels(void);
|
2010-07-12 17:03:27 +08:00
|
|
|
|
2010-12-29 18:01:37 +08:00
|
|
|
/** returns the display size of the OpenGL view in pixels.
|
|
|
|
It doesn't take into account any possible rotation of the window.
|
|
|
|
*/
|
2011-03-07 17:11:57 +08:00
|
|
|
CCSize getDisplaySizeInPixels(void);
|
2010-07-12 17:03:27 +08:00
|
|
|
|
2011-01-07 09:35:27 +08:00
|
|
|
/** changes the projection size */
|
2011-03-07 17:11:57 +08:00
|
|
|
void reshapeProjection(CCSize newWindowSize);
|
2010-07-12 17:03:27 +08:00
|
|
|
|
|
|
|
/** converts a UIKit coordinate to an OpenGL coordinate
|
2010-09-28 16:18:05 +08:00
|
|
|
Useful to convert (multi) touches coordinates to the current layout (portrait or landscape)
|
2010-07-12 17:03:27 +08:00
|
|
|
*/
|
2011-03-07 17:11:57 +08:00
|
|
|
CCPoint convertToGL(CCPoint obPoint);
|
2010-07-12 17:03:27 +08:00
|
|
|
|
|
|
|
/** converts an OpenGL coordinate to a UIKit coordinate
|
|
|
|
Useful to convert node points to window points for calls such as glScissor
|
|
|
|
*/
|
2011-03-07 17:11:57 +08:00
|
|
|
CCPoint convertToUI(CCPoint obPoint);
|
2010-07-12 17:03:27 +08:00
|
|
|
|
2010-09-28 16:18:05 +08:00
|
|
|
/// XXX: missing description
|
2010-07-12 17:03:27 +08:00
|
|
|
float getZEye(void);
|
|
|
|
|
|
|
|
// 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 *pScene);
|
|
|
|
|
|
|
|
/**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 *pScene);
|
|
|
|
|
|
|
|
/**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(void);
|
|
|
|
|
|
|
|
/** 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 *pScene);
|
|
|
|
|
|
|
|
/** Ends the execution, releases the running scene.
|
|
|
|
It doesn't remove the OpenGL view from its parent. You have to do it manually.
|
|
|
|
*/
|
2011-06-20 17:31:38 +08:00
|
|
|
|
|
|
|
/* end is key word of lua, use other name to export to lua. */
|
2011-05-31 14:04:14 +08:00
|
|
|
inline void endToLua(void){end();}
|
2011-06-20 17:31:38 +08:00
|
|
|
|
2010-07-12 17:03:27 +08:00
|
|
|
void end(void);
|
|
|
|
|
|
|
|
/** Pauses the running scene.
|
|
|
|
The running scene will be _drawed_ but all scheduled timers will be paused
|
2010-09-30 15:54:15 +08:00
|
|
|
While paused, the draw rate will be 4 FPS to reduce CPU consumption
|
2010-07-12 17:03:27 +08:00
|
|
|
*/
|
|
|
|
void pause(void);
|
|
|
|
|
|
|
|
/** 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(void);
|
|
|
|
|
|
|
|
/** Stops the animation. Nothing will be drawn. The main loop won't be triggered anymore.
|
2010-09-30 15:54:15 +08:00
|
|
|
If you don't want to pause your animation call [pause] instead.
|
2010-07-12 17:03:27 +08:00
|
|
|
*/
|
2011-04-11 15:10:09 +08:00
|
|
|
virtual void stopAnimation(void) = 0;
|
2010-07-12 17:03:27 +08:00
|
|
|
|
|
|
|
/** The main loop is triggered again.
|
|
|
|
Call this function only if [stopAnimation] was called earlier
|
2010-09-30 15:54:15 +08:00
|
|
|
@warning Don't call this function to start the main loop. To run the main loop call runWithScene
|
2010-07-12 17:03:27 +08:00
|
|
|
*/
|
2011-04-11 15:10:09 +08:00
|
|
|
virtual void startAnimation(void) = 0;
|
2010-07-12 17:03:27 +08:00
|
|
|
|
2010-11-13 11:34:49 +08:00
|
|
|
/** Draw the scene.
|
|
|
|
This method is called every frame. Don't call it manually.
|
|
|
|
*/
|
2010-09-24 18:10:32 +08:00
|
|
|
void drawScene(void);
|
|
|
|
|
2010-07-12 17:03:27 +08:00
|
|
|
// Memory Helper
|
|
|
|
|
|
|
|
/** Removes cached all cocos2d cached data.
|
|
|
|
It will purge the CCTextureCache, CCSpriteFrameCache, CCBitmapFont cache
|
|
|
|
@since v0.99.3
|
|
|
|
*/
|
|
|
|
void purgeCachedData(void);
|
|
|
|
|
|
|
|
// OpenGL Helper
|
|
|
|
|
2010-09-28 16:18:05 +08:00
|
|
|
/** sets the OpenGL default values */
|
2010-07-12 17:03:27 +08:00
|
|
|
void setGLDefaultValues(void);
|
|
|
|
|
2010-09-28 16:18:05 +08:00
|
|
|
/** enables/disables OpenGL alpha blending */
|
2010-07-12 17:03:27 +08:00
|
|
|
void setAlphaBlending(bool bOn);
|
|
|
|
|
2010-09-28 16:18:05 +08:00
|
|
|
/** enables/disables OpenGL depth test */
|
2010-07-12 17:03:27 +08:00
|
|
|
void setDepthTest(bool bOn);
|
|
|
|
|
2011-04-11 15:10:09 +08:00
|
|
|
virtual void mainLoop(void) = 0;
|
2010-08-02 14:40:53 +08:00
|
|
|
|
2010-12-29 18:01:37 +08:00
|
|
|
// Profiler
|
|
|
|
void showProfilers(void);
|
|
|
|
|
|
|
|
/** rotates the screen if an orientation different than Portrait is used */
|
|
|
|
void applyOrientation(void);
|
|
|
|
|
|
|
|
ccDeviceOrientation getDeviceOrientation(void);
|
|
|
|
void setDeviceOrientation(ccDeviceOrientation kDeviceOrientation);
|
|
|
|
|
|
|
|
/** 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.
|
|
|
|
Only available when compiled using SDK >= 4.0.
|
|
|
|
@since v0.99.4
|
|
|
|
*/
|
|
|
|
void setContentScaleFactor(CGFloat scaleFactor);
|
|
|
|
CGFloat getContentScaleFactor(void);
|
|
|
|
|
|
|
|
/** 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 enabled);
|
2011-03-15 15:12:50 +08:00
|
|
|
bool isRetinaDisplay() { return m_bRetinaDisplay; }
|
2010-07-12 17:03:27 +08:00
|
|
|
|
|
|
|
/** There are 4 types of Director.
|
2010-12-29 18:01:37 +08:00
|
|
|
- kCCDirectorTypeNSTimer (default)
|
|
|
|
- kCCDirectorTypeMainLoop
|
|
|
|
- kCCDirectorTypeThreadMainLoop
|
|
|
|
- kCCDirectorTypeDisplayLink
|
|
|
|
|
|
|
|
Each Director has it's own benefits, limitations.
|
|
|
|
Now we only support DisplayLink director, so it has not effect.
|
|
|
|
|
|
|
|
This method should be called before any other call to the director.
|
|
|
|
|
|
|
|
@since v0.8.2
|
|
|
|
*/
|
2010-11-11 11:18:58 +08:00
|
|
|
static bool setDirectorType(ccDirectorType obDirectorType);
|
2010-12-29 18:01:37 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
/** returns a shared instance of the director */
|
|
|
|
static CCDirector* sharedDirector(void);
|
2010-07-12 17:03:27 +08:00
|
|
|
|
|
|
|
protected:
|
2011-04-11 15:10:09 +08:00
|
|
|
|
2011-01-17 21:16:25 +08:00
|
|
|
void purgeDirector();
|
2011-01-17 22:01:15 +08:00
|
|
|
bool m_bPurgeDirecotorInNextLoop; // this flag will be set to true in end()
|
|
|
|
|
2010-09-24 18:10:32 +08:00
|
|
|
void updateContentScaleFactor(void);
|
2010-12-29 18:01:37 +08:00
|
|
|
|
2010-07-12 17:03:27 +08:00
|
|
|
void setNextScene(void);
|
2010-09-28 16:18:05 +08:00
|
|
|
|
2010-08-24 09:56:09 +08:00
|
|
|
#if CC_DIRECTOR_FAST_FPS
|
2010-09-28 16:18:05 +08:00
|
|
|
/** shows the FPS in the screen */
|
2010-07-12 17:03:27 +08:00
|
|
|
void showFPS(void);
|
2010-08-24 09:56:09 +08:00
|
|
|
#else
|
|
|
|
void showFPS(void) {}
|
|
|
|
#endif // CC_DIRECTOR_FAST_FPS
|
|
|
|
|
2011-01-10 15:13:30 +08:00
|
|
|
/** calculates delta time since last time it was called */ void calculateDeltaTime();protected:
|
2011-03-07 17:11:57 +08:00
|
|
|
/* The CCEGLView, where everything is rendered */
|
2010-12-29 18:01:37 +08:00
|
|
|
CC_GLVIEW *m_pobOpenGLView;
|
2010-07-12 17:03:27 +08:00
|
|
|
|
|
|
|
double m_dAnimationInterval;
|
2010-07-16 14:09:31 +08:00
|
|
|
double m_dOldAnimationInterval;
|
2010-07-12 17:03:27 +08:00
|
|
|
|
|
|
|
/* landscape mode ? */
|
|
|
|
bool m_bLandscape;
|
|
|
|
|
2010-09-29 17:39:45 +08:00
|
|
|
bool m_bDisplayFPS;
|
2010-08-02 10:58:00 +08:00
|
|
|
int m_nFrames;
|
2010-07-12 17:03:27 +08:00
|
|
|
ccTime m_fAccumDt;
|
|
|
|
ccTime m_fFrameRate;
|
|
|
|
#if CC_DIRECTOR_FAST_FPS
|
2010-12-24 17:07:31 +08:00
|
|
|
CCLabelTTF *m_pFPSLabel;
|
2010-07-12 17:03:27 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* is the running scene paused */
|
|
|
|
bool m_bPaused;
|
|
|
|
|
|
|
|
/* The running scene */
|
|
|
|
CCScene *m_pRunningScene;
|
|
|
|
|
|
|
|
/* will be the next 'runningScene' in the next frame
|
|
|
|
nextScene is a weak reference. */
|
|
|
|
CCScene *m_pNextScene;
|
|
|
|
|
|
|
|
/* If YES, then "old" scene will receive the cleanup message */
|
|
|
|
bool m_bSendCleanupToScene;
|
|
|
|
|
|
|
|
/* scheduled scenes */
|
2011-03-07 17:11:57 +08:00
|
|
|
CCMutableArray<CCScene*> *m_pobScenesStack;
|
2010-07-12 17:03:27 +08:00
|
|
|
|
|
|
|
/* last time the main loop was updated */
|
2010-08-04 16:18:09 +08:00
|
|
|
struct cc_timeval *m_pLastUpdate;
|
2010-07-12 17:03:27 +08:00
|
|
|
|
|
|
|
/* delta time since last tick to main loop */
|
|
|
|
ccTime m_fDeltaTime;
|
|
|
|
|
|
|
|
/* whether or not the next delta time will be zero */
|
|
|
|
bool m_bNextDeltaTimeZero;
|
|
|
|
|
|
|
|
/* projection used */
|
|
|
|
ccDirectorProjection m_eProjection;
|
|
|
|
|
2010-12-29 18:01:37 +08:00
|
|
|
/* window size in points */
|
2011-03-07 17:11:57 +08:00
|
|
|
CCSize m_obWinSizeInPoints;
|
2010-12-29 18:01:37 +08:00
|
|
|
|
|
|
|
/* window size in pixels */
|
2011-03-07 17:11:57 +08:00
|
|
|
CCSize m_obWinSizeInPixels;
|
2010-07-12 17:03:27 +08:00
|
|
|
|
|
|
|
/* content scale factor */
|
|
|
|
CGFloat m_fContentScaleFactor;
|
2010-09-24 18:10:32 +08:00
|
|
|
|
2010-12-29 18:01:37 +08:00
|
|
|
/* store the fps string */
|
|
|
|
char *m_pszFPS;
|
|
|
|
|
2011-01-07 09:35:27 +08:00
|
|
|
/* This object will be visited after the scene. Useful to hook a notification node */
|
2010-12-29 18:01:37 +08:00
|
|
|
CCNode *m_pNotificationNode;
|
|
|
|
|
|
|
|
/* Projection protocol delegate */
|
|
|
|
CCProjectionProtocol *m_pProjectionDelegate;
|
|
|
|
|
|
|
|
/* The device orientation */
|
|
|
|
ccDeviceOrientation m_eDeviceOrientation;
|
2010-09-24 18:10:32 +08:00
|
|
|
/* contentScaleFactor could be simulated */
|
|
|
|
bool m_bIsContentScaleSupported;
|
2010-09-30 15:54:15 +08:00
|
|
|
|
2011-04-11 15:10:09 +08:00
|
|
|
bool m_bRetinaDisplay;
|
2010-07-12 17:03:27 +08:00
|
|
|
|
|
|
|
#if CC_ENABLE_PROFILERS
|
|
|
|
ccTime m_fAccumDtForProfiler;
|
|
|
|
#endif
|
2010-08-02 10:58:00 +08:00
|
|
|
};
|
|
|
|
|
2010-09-28 18:27:33 +08:00
|
|
|
/**
|
|
|
|
@brief DisplayLinkDirector is a Director that synchronizes timers with the refresh rate of the display.
|
|
|
|
|
|
|
|
Features and Limitations:
|
|
|
|
- Scheduled timers & drawing are synchronizes with the refresh rate of the display
|
|
|
|
- Only supports animation intervals of 1/60 1/30 & 1/15
|
|
|
|
|
|
|
|
@since v0.8.2
|
2010-08-02 10:58:00 +08:00
|
|
|
*/
|
|
|
|
class CCDisplayLinkDirector : public CCDirector
|
|
|
|
{
|
|
|
|
public:
|
2011-04-01 16:06:53 +08:00
|
|
|
CCDisplayLinkDirector(void)
|
|
|
|
: m_bInvalid(false)
|
|
|
|
{}
|
2010-08-02 10:58:00 +08:00
|
|
|
|
2010-12-29 18:01:37 +08:00
|
|
|
virtual void mainLoop(void);
|
2010-08-02 10:58:00 +08:00
|
|
|
virtual void setAnimationInterval(double dValue);
|
|
|
|
virtual void startAnimation(void);
|
|
|
|
virtual void stopAnimation();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
bool m_bInvalid;
|
|
|
|
};
|
|
|
|
|
2010-11-13 11:34:49 +08:00
|
|
|
}//namespace cocos2d
|
2010-08-02 10:58:00 +08:00
|
|
|
|
|
|
|
#endif // __CCDIRECTOR_H__
|