2010-08-02 10:58:00 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2010 cocos2d-x.org
|
|
|
|
|
|
|
|
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__
|
|
|
|
|
2010-07-12 17:03:27 +08:00
|
|
|
#include "ccConfig.h"
|
|
|
|
#include "ccTypes.h"
|
|
|
|
#include "Cocos2dDefine.h"
|
|
|
|
#include "cocoa/NSObject.h"
|
|
|
|
#include "cocoa/CGGeometry.h"
|
|
|
|
#include "cocoa/NSMutableArray.h"
|
|
|
|
#include "cocoa/CGGeometry.h"
|
2010-08-02 10:58:00 +08:00
|
|
|
#include "CCXEGLView.h"
|
2010-08-02 11:13:36 +08:00
|
|
|
#include "ccxCommon.h"
|
2010-08-02 12:00:06 +08:00
|
|
|
|
|
|
|
#include <assert.h>
|
2010-08-04 15:46:12 +08:00
|
|
|
namespace cocos2d {
|
2010-07-12 17:03:27 +08:00
|
|
|
|
|
|
|
// OpenGL related
|
2010-07-28 10:15:02 +08:00
|
|
|
// #include "support/CCXEGLView.h"
|
2010-07-12 17:03:27 +08:00
|
|
|
|
|
|
|
/** @typedef tPixelFormat
|
2010-07-28 10:15:02 +08:00
|
|
|
Possible Pixel Formats for the CCXEGLView
|
2010-07-12 17:03:27 +08:00
|
|
|
*/
|
|
|
|
typedef enum {
|
|
|
|
/** RGB565 pixel format. No alpha. 16-bit. (Default) */
|
|
|
|
kCCPixelFormatRGB565,
|
|
|
|
/** RGBA format. 32-bit. Needed for some 3D effects. It is not as fast as the RGB565 format. */
|
|
|
|
kCCPixelFormatRGBA8888,
|
|
|
|
/** default pixel format */
|
|
|
|
kCCPixelFormatDefault = kCCPixelFormatRGB565,
|
|
|
|
|
|
|
|
// backward compatibility stuff
|
|
|
|
kPixelFormatRGB565 = kCCPixelFormatRGB565,
|
|
|
|
kRGB565 = kCCPixelFormatRGB565,
|
|
|
|
kPixelFormatRGBA8888 = kCCPixelFormatRGBA8888,
|
|
|
|
kRGBA8 = kCCPixelFormatRGBA8888,
|
|
|
|
} tPixelFormat;
|
|
|
|
|
|
|
|
/** @typedef tDepthBufferFormat
|
2010-07-28 10:15:02 +08:00
|
|
|
Possible DepthBuffer Formats for the CCXEGLView.
|
2010-07-12 17:03:27 +08:00
|
|
|
Use 16 or 24 bit depth buffers if you are going to use real 3D objects.
|
|
|
|
*/
|
|
|
|
typedef enum {
|
|
|
|
/// A Depth Buffer of 0 bits will be used (default)
|
|
|
|
kCCDepthBufferNone,
|
|
|
|
/// A depth buffer of 16 bits will be used
|
|
|
|
kCCDepthBuffer16,
|
|
|
|
/// A depth buffer of 24 bits will be used
|
|
|
|
kCCDepthBuffer24,
|
|
|
|
|
|
|
|
// backward compatibility stuff
|
|
|
|
kDepthBuffer16 = kCCDepthBuffer16,
|
|
|
|
kDepthBuffer24 = kCCDepthBuffer24,
|
|
|
|
} tDepthBufferFormat;
|
|
|
|
|
|
|
|
/** @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 does nothing. But if you are using a custom projection set it this value.
|
|
|
|
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
|
|
|
|
* - 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,
|
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;
|
|
|
|
|
|
|
|
class CCLabelAtlas;
|
|
|
|
class CCScene;
|
2010-07-28 10:15:02 +08:00
|
|
|
class cocos2d::CCXEGLView;
|
2010-07-12 17:03:27 +08:00
|
|
|
|
|
|
|
/**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 ES pixel format (default on is RGB565)
|
|
|
|
- setting the OpenGL ES buffer depth (default one is 0-bit)
|
|
|
|
- setting the projection (default one is 2D)
|
|
|
|
- setting the orientation (default one is Protrait)
|
|
|
|
|
|
|
|
Since the CCDirector is a singleton, the standard way to use it is by calling:
|
|
|
|
- [[CCDirector sharedDirector] xxxx];
|
|
|
|
|
|
|
|
The CCDirector also sets the default OpenGL ES context:
|
|
|
|
- GL_TEXTURE_2D is enabled
|
|
|
|
- GL_VERTEX_ARRAY is enabled
|
|
|
|
- GL_COLOR_ARRAY is enabled
|
|
|
|
- GL_TEXTURE_COORD_ARRAY is enabled
|
|
|
|
*/
|
2010-08-02 11:13:36 +08:00
|
|
|
class CCX_DLL CCDirector : public NSObject
|
2010-07-12 17:03:27 +08:00
|
|
|
{
|
2010-07-16 14:09:31 +08:00
|
|
|
public:
|
|
|
|
virtual CCDirector* init(void);
|
|
|
|
virtual ~CCDirector(void);
|
2010-07-20 14:07:27 +08:00
|
|
|
CCDirector(void) {}
|
2010-07-16 14:09:31 +08:00
|
|
|
|
|
|
|
// attribute
|
|
|
|
|
2010-07-12 17:03:27 +08:00
|
|
|
// The 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
|
|
|
|
|
|
|
// The FPS value
|
2010-08-02 12:00:06 +08:00
|
|
|
inline double getAnimationInterval(void) { return m_dAnimationInterval; }
|
2010-07-16 14:09:31 +08:00
|
|
|
virtual void setAnimationInterval(double dValue);
|
2010-07-12 17:03:27 +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; }
|
|
|
|
inline void setDisplayFPS(bool bDisplayFPS) { m_bDisplayFPS = bDisplayFPS; }
|
2010-07-12 17:03:27 +08:00
|
|
|
|
2010-07-28 10:15:02 +08:00
|
|
|
// The CCXEGLView, where everything is rendered
|
2010-08-02 12:00:06 +08:00
|
|
|
inline cocos2d::CCXEGLView* getOpenGLView(void) { return m_pobOpenGLView; }
|
2010-07-28 10:15:02 +08:00
|
|
|
void setOpenGLView(cocos2d::CCXEGLView *pobOpenGLView);
|
2010-07-12 17:03:27 +08:00
|
|
|
|
|
|
|
// whether or not the next delta time will be zero
|
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);
|
|
|
|
|
|
|
|
// The device orientattion
|
2010-08-02 12:00:06 +08:00
|
|
|
inline ccDeviceOrientation getDeviceOrientation(void) { return m_eDeviceOrientation; }
|
2010-07-12 17:03:27 +08:00
|
|
|
void setDeviceOrientation(ccDeviceOrientation kDeviceOrientation);
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
/** 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
|
|
|
|
*/
|
2010-08-02 12:00:06 +08:00
|
|
|
inline void setContentScaleFactor(CGFloat obCGFloatValue)
|
|
|
|
{
|
|
|
|
assert(! isOpenGLAttached());
|
|
|
|
m_fContentScaleFactor = obCGFloatValue;
|
|
|
|
}
|
|
|
|
inline CGFloat getContentScaleFactor(void) { return m_fContentScaleFactor; }
|
2010-07-12 17:03:27 +08:00
|
|
|
|
|
|
|
// UI dependent
|
|
|
|
|
2010-07-28 10:15:02 +08:00
|
|
|
/** Uses a new pixel format for the CCXEGLView.
|
2010-07-12 17:03:27 +08:00
|
|
|
Call this class method before attaching it to a UIView
|
|
|
|
Default pixel format: kRGB565. Supported pixel formats: kRGBA8 and kRGB565
|
|
|
|
|
2010-07-28 10:15:02 +08:00
|
|
|
@deprecated Set the pixel format when creating the CCXEGLView. This method will be removed in v1.0
|
2010-07-12 17:03:27 +08:00
|
|
|
*/
|
2010-08-02 12:00:06 +08:00
|
|
|
inline void setPixelFormat(tPixelFormat kPixelFormat)
|
|
|
|
{
|
|
|
|
assert(! isOpenGLAttached());
|
|
|
|
m_ePixelFormat = kPixelFormat;
|
|
|
|
}
|
|
|
|
// Pixel format used to create the context
|
|
|
|
inline tPixelFormat getPiexFormat(void) { return m_ePixelFormat; }
|
2010-07-12 17:03:27 +08:00
|
|
|
|
|
|
|
/** Change depth buffer format of the render buffer.
|
|
|
|
Call this class method before attaching it to a UIWindow/UIView
|
|
|
|
Default depth buffer: 0 (none). Supported: kCCDepthBufferNone, kCCDepthBuffer16, and kCCDepthBuffer24
|
|
|
|
|
2010-07-28 10:15:02 +08:00
|
|
|
@deprecated Set the depth buffer format when creating the CCXEGLView. This method will be removed in v1.0
|
2010-07-12 17:03:27 +08:00
|
|
|
*/
|
2010-08-02 12:00:06 +08:00
|
|
|
inline void setDepthBufferFormat(tDepthBufferFormat kDepthBufferFormat)
|
|
|
|
{
|
|
|
|
assert(! isOpenGLAttached());
|
|
|
|
m_eDepthBufferFormat = kDepthBufferFormat;
|
|
|
|
}
|
2010-07-12 17:03:27 +08:00
|
|
|
|
|
|
|
// Integration with UI
|
|
|
|
/** detach the cocos2d view from the view/window */
|
|
|
|
bool detach(void);
|
|
|
|
|
|
|
|
/** attach in UIWindow using the full frame.
|
2010-07-28 10:15:02 +08:00
|
|
|
It will create a CCXEGLView.
|
2010-07-12 17:03:27 +08:00
|
|
|
|
|
|
|
@deprecated set setOpenGLView instead. Will be removed in v1.0
|
|
|
|
*/
|
2010-07-16 14:09:31 +08:00
|
|
|
// bool attachInWindow(UIWindow *pWindow);
|
2010-07-12 17:03:27 +08:00
|
|
|
|
|
|
|
/** attach in UIView using the full frame.
|
2010-07-28 10:15:02 +08:00
|
|
|
It will create a CCXEGLView.
|
2010-07-12 17:03:27 +08:00
|
|
|
|
|
|
|
@deprecated set setOpenGLView instead. Will be removed in v1.0
|
|
|
|
*/
|
2010-07-16 14:09:31 +08:00
|
|
|
// bool attachInView(UIView *pView);
|
2010-07-12 17:03:27 +08:00
|
|
|
|
|
|
|
/** attach in UIView using the given frame.
|
2010-07-28 10:15:02 +08:00
|
|
|
It will create a CCXEGLView and use it.
|
2010-07-12 17:03:27 +08:00
|
|
|
|
|
|
|
@deprecated set setOpenGLView instead. Will be removed in v1.0
|
|
|
|
*/
|
2010-07-16 14:09:31 +08:00
|
|
|
// bool attchInViewWithFrame(UIView *pView, CGRect frame);
|
|
|
|
|
|
|
|
|
2010-08-02 10:58:00 +08:00
|
|
|
// // set the view where opengl to draw in
|
|
|
|
// bool attachWindow(UIWindow *pVindow);
|
2010-07-12 17:03:27 +08:00
|
|
|
|
|
|
|
// Landspace
|
|
|
|
|
|
|
|
// returns the size of the OpenGL view in pixels, according to the landspace
|
|
|
|
CGSize getWinSize(void);
|
|
|
|
|
|
|
|
// returns the display size of the OpenGL view in pixels
|
|
|
|
CGSize getDisplaySize(void);
|
|
|
|
|
|
|
|
/** converts a UIKit coordinate to an OpenGL coordinate
|
|
|
|
Useful to convert (multi) touchs coordinates to the current layout (portrait or landscape)
|
|
|
|
*/
|
|
|
|
CGPoint convertToGL(CGPoint obPoint);
|
|
|
|
|
|
|
|
/** converts an OpenGL coordinate to a UIKit coordinate
|
|
|
|
Useful to convert node points to window points for calls such as glScissor
|
|
|
|
*/
|
|
|
|
CGPoint convertToUI(CGPoint obPoint);
|
|
|
|
|
|
|
|
// rotates the screen if Landscape mode is activated
|
2010-07-20 14:07:27 +08:00
|
|
|
void applyLandspace(void);
|
2010-07-12 17:03:27 +08:00
|
|
|
|
|
|
|
// XXX: missing description
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
void end(void);
|
|
|
|
|
|
|
|
/** 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(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.
|
|
|
|
If you wan't to pause your animation call [pause] instead.
|
|
|
|
*/
|
2010-07-16 14:09:31 +08:00
|
|
|
virtual void stopAnimation(void);
|
2010-07-12 17:03:27 +08:00
|
|
|
|
|
|
|
/** 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
|
|
|
|
*/
|
2010-07-16 14:09:31 +08:00
|
|
|
virtual void startAnimation(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
|
|
|
|
|
|
|
|
// sets the OpenGL default values
|
|
|
|
void setGLDefaultValues(void);
|
|
|
|
|
|
|
|
// enables/disables OpenGL alpha blending
|
|
|
|
void setAlphaBlending(bool bOn);
|
|
|
|
|
|
|
|
// enables/disables OpenGL depth test
|
|
|
|
void setDepthTest(bool bOn);
|
|
|
|
|
2010-08-02 14:40:53 +08:00
|
|
|
virtual void preMainLoop(void);
|
|
|
|
|
2010-07-12 17:03:27 +08:00
|
|
|
public:
|
|
|
|
// returns a shared instance of the director
|
|
|
|
static CCDirector* getSharedDirector(void);
|
|
|
|
|
|
|
|
/** There are 4 types of Director.
|
|
|
|
- CCDirectorTypeNSTimer (default)
|
|
|
|
- CCDirectorTypeMainLoop
|
|
|
|
- CCDirectorTypeThreadMainLoop
|
|
|
|
- CCDirectorTypeDisplayLink
|
|
|
|
|
|
|
|
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 CCDirectorTypeDisplayLink and the running SDK is < 3.1. Otherwise it will return YES.
|
|
|
|
|
|
|
|
@since v0.8.2
|
|
|
|
*/
|
|
|
|
// should we support four types???
|
2010-07-20 14:07:27 +08:00
|
|
|
static bool setDierectorType(ccDirectorType obDirectorType);
|
2010-07-12 17:03:27 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
bool isOpenGLAttached(void);
|
2010-07-16 14:09:31 +08:00
|
|
|
// bool initOpenGLViewWithViewWithFrame(UIView *pView, CGRect obRect);
|
2010-07-12 17:03:27 +08:00
|
|
|
|
|
|
|
void mainLoop(void);
|
|
|
|
void setNextScene(void);
|
|
|
|
// shows the FPS in the screen
|
|
|
|
void showFPS(void);
|
|
|
|
// calculates delta time since last time it was called
|
|
|
|
void calculateDeltaTime(void);
|
|
|
|
|
|
|
|
#if defined CC_ENABLE_PROFILERS
|
|
|
|
void showProfilers(void);
|
|
|
|
#endif // CC_ENABLE_PROFILERS
|
|
|
|
|
|
|
|
protected:
|
2010-07-28 10:15:02 +08:00
|
|
|
cocos2d::CCXEGLView *m_pobOpenGLView;
|
2010-07-12 17:03:27 +08:00
|
|
|
|
|
|
|
//NSTimeInterval animationInterval;
|
|
|
|
//NSTimeInterval oldAnimationInterval;
|
|
|
|
// NSTimeInterval -> double
|
|
|
|
double m_dAnimationInterval;
|
2010-07-16 14:09:31 +08:00
|
|
|
double m_dOldAnimationInterval;
|
2010-07-12 17:03:27 +08:00
|
|
|
|
|
|
|
tPixelFormat m_ePixelFormat;
|
|
|
|
tDepthBufferFormat m_eDepthBufferFormat;
|
|
|
|
|
|
|
|
/* landscape mode ? */
|
|
|
|
bool m_bLandscape;
|
|
|
|
|
|
|
|
/* orientation */
|
2010-07-20 14:07:27 +08:00
|
|
|
ccDeviceOrientation m_eDeviceOrientation;
|
2010-07-12 17:03:27 +08:00
|
|
|
|
|
|
|
/* display FPS ? */
|
|
|
|
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-07-20 14:07:27 +08:00
|
|
|
// todo implement CCLabelAtlas
|
|
|
|
// CCLabelAtlas *FPSLabel;
|
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 */
|
2010-07-20 14:07:27 +08:00
|
|
|
NSMutableArray<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;
|
|
|
|
|
|
|
|
/* screen, different than surface size */
|
|
|
|
CGSize m_obScreenSize;
|
|
|
|
|
|
|
|
/* screen, different than surface size */
|
|
|
|
CGSize m_obSurfaceSize;
|
|
|
|
|
|
|
|
/* content scale factor */
|
|
|
|
CGFloat m_fContentScaleFactor;
|
|
|
|
|
|
|
|
#if CC_ENABLE_PROFILERS
|
|
|
|
ccTime m_fAccumDtForProfiler;
|
|
|
|
#endif
|
2010-08-02 10:58:00 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-07-12 17:03:27 +08:00
|
|
|
/** 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
|
2010-08-02 10:58:00 +08:00
|
|
|
*/
|
|
|
|
/*
|
|
|
|
class CCFastDirector : public CCDirector
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static CCFastDirector* getSharedDirector(void);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void preMainLoop(void);
|
|
|
|
|
|
|
|
private:
|
|
|
|
CCFastDirector(void) {}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
bool isRunning;
|
|
|
|
NSAutoreleasePool *pAutoreleasePool;
|
|
|
|
};
|
|
|
|
*/
|
|
|
|
|
2010-07-12 17:03:27 +08:00
|
|
|
/** 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
|
2010-08-02 10:58:00 +08:00
|
|
|
*/
|
|
|
|
/*
|
|
|
|
class CCThreadedFastDirector : public CCDirector
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static CCThreadedFastDirector* getSharedDirector(void);
|
|
|
|
protected:
|
|
|
|
virtual void preMainLoop(void);
|
|
|
|
|
|
|
|
private:
|
|
|
|
CCThreadedFastDirector(void){}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
bool isRunning;
|
|
|
|
};
|
|
|
|
*/
|
|
|
|
|
2010-07-12 17:03:27 +08:00
|
|
|
/** 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
|
2010-08-02 10:58:00 +08:00
|
|
|
*/
|
|
|
|
class CCDisplayLinkDirector : public CCDirector
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CCDisplayLinkDirector(void) {}
|
|
|
|
|
|
|
|
//static CCDisplayLinkDirector* getSharedDirector(void);
|
|
|
|
virtual void preMainLoop(void);
|
|
|
|
virtual void setAnimationInterval(double dValue);
|
|
|
|
virtual void startAnimation(void);
|
|
|
|
virtual void stopAnimation();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
bool m_bInvalid;
|
|
|
|
};
|
|
|
|
|
2010-07-16 14:09:31 +08:00
|
|
|
/** 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.
|
2010-08-02 10:58:00 +08:00
|
|
|
*/
|
|
|
|
/*
|
|
|
|
class CCTimerDirector : public CCDirector
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static CCTimerDirector* getSharedDirector(void);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void preMain(void);
|
|
|
|
|
|
|
|
private:
|
|
|
|
CCTimerDirector(void) {}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
NSTimer *pAnimationTimer;
|
|
|
|
};
|
|
|
|
*/
|
2010-08-04 15:46:12 +08:00
|
|
|
}//namespace cocos2d
|
2010-08-02 10:58:00 +08:00
|
|
|
|
|
|
|
#endif // __CCDIRECTOR_H__
|