2010-08-02 10:58:00 +08:00
|
|
|
/****************************************************************************
|
2012-09-24 21:22:20 +08:00
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
2011-03-19 10:59:01 +08:00
|
|
|
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__
|
|
|
|
|
2013-10-14 14:01:00 +08:00
|
|
|
#include "CCPlatformMacros.h"
|
2013-07-19 13:42:45 +08:00
|
|
|
|
2013-10-14 14:01:00 +08:00
|
|
|
#include "CCObject.h"
|
2011-01-15 18:05:35 +08:00
|
|
|
#include "ccTypes.h"
|
2013-10-14 14:01:00 +08:00
|
|
|
#include "CCGeometry.h"
|
|
|
|
#include "CCArray.h"
|
2012-04-13 11:22:17 +08:00
|
|
|
#include "CCGL.h"
|
2012-03-14 14:55:17 +08:00
|
|
|
#include "kazmath/mat4.h"
|
2013-10-14 14:01:00 +08:00
|
|
|
#include "CCLabelAtlas.h"
|
2012-08-28 12:04:51 +08:00
|
|
|
|
2011-06-20 17:31:38 +08:00
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
NS_CC_BEGIN
|
2010-07-12 17:03:27 +08:00
|
|
|
|
2012-06-20 18:09:11 +08:00
|
|
|
/**
|
|
|
|
* @addtogroup base_nodes
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2012-05-22 08:20:47 +08:00
|
|
|
/* Forward declarations. */
|
2013-06-20 14:13:12 +08:00
|
|
|
class LabelAtlas;
|
|
|
|
class Scene;
|
|
|
|
class EGLView;
|
|
|
|
class DirectorDelegate;
|
|
|
|
class Node;
|
|
|
|
class Scheduler;
|
|
|
|
class ActionManager;
|
2013-10-26 15:04:01 +08:00
|
|
|
class EventDispatcher;
|
2013-11-07 18:52:36 +08:00
|
|
|
class TextureCache;
|
2013-11-27 10:35:12 +08:00
|
|
|
class Frustum;
|
2012-03-21 17:35:20 +08:00
|
|
|
|
2010-09-28 18:27:33 +08:00
|
|
|
/**
|
2013-09-23 02:39:42 +08:00
|
|
|
@brief Class that creates and handles the main Window and manages how
|
2010-07-12 17:03:27 +08:00
|
|
|
and when to execute the Scenes.
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
The Director 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)
|
2012-09-15 06:26:38 +08:00
|
|
|
- setting the orientation (default one is Portrait)
|
2010-07-12 17:03:27 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
Since the Director is a singleton, the standard way to use it is by calling:
|
2013-07-12 06:24:23 +08:00
|
|
|
_ Director::getInstance()->methodName();
|
2010-07-12 17:03:27 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
The Director 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
|
|
|
|
*/
|
2013-08-22 18:16:50 +08:00
|
|
|
class CC_DLL Director : public Object
|
2010-07-12 17:03:27 +08:00
|
|
|
{
|
2012-03-21 17:35:20 +08:00
|
|
|
public:
|
2013-07-25 14:39:32 +08:00
|
|
|
/** @typedef ccDirectorProjection
|
|
|
|
Possible OpenGL projections used by director
|
|
|
|
*/
|
2013-07-26 04:36:19 +08:00
|
|
|
enum class Projection
|
2013-07-25 14:39:32 +08:00
|
|
|
{
|
|
|
|
/// sets a 2D projection (orthogonal projection)
|
2013-07-26 04:36:19 +08:00
|
|
|
_2D,
|
2013-07-25 14:39:32 +08:00
|
|
|
|
|
|
|
/// sets a 3D projection with a fovy=60, znear=0.5f and zfar=1500.
|
2013-07-26 04:36:19 +08:00
|
|
|
_3D,
|
2013-07-25 14:39:32 +08:00
|
|
|
|
|
|
|
/// it calls "updateProjection" on the projection delegate.
|
2013-07-26 04:36:19 +08:00
|
|
|
CUSTOM,
|
2013-07-25 14:39:32 +08:00
|
|
|
|
|
|
|
/// Default projection is 3D projection
|
2013-07-26 04:36:19 +08:00
|
|
|
DEFAULT = _3D,
|
2013-07-25 14:39:32 +08:00
|
|
|
};
|
|
|
|
|
2013-07-16 03:43:22 +08:00
|
|
|
/** returns a shared instance of the director */
|
|
|
|
static Director* getInstance();
|
|
|
|
|
|
|
|
/** @deprecated Use getInstance() instead */
|
2013-07-18 07:56:19 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE static Director* sharedDirector() { return Director::getInstance(); }
|
2013-09-13 16:46:31 +08:00
|
|
|
/**
|
|
|
|
* @js ctor
|
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
Director(void);
|
2013-09-13 13:52:42 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
virtual ~Director(void);
|
2012-04-19 14:35:52 +08:00
|
|
|
virtual bool init(void);
|
2010-07-16 14:09:31 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// attribute
|
2010-07-16 14:09:31 +08:00
|
|
|
|
2013-09-23 02:39:42 +08:00
|
|
|
/** Get current running Scene. Director can only run one Scene at a time */
|
2013-08-08 16:31:44 +08:00
|
|
|
inline Scene* getRunningScene() { return _runningScene; }
|
2010-07-12 17:03:27 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
/** Get the FPS value */
|
2013-08-08 16:31:44 +08:00
|
|
|
inline double getAnimationInterval() { return _animationInterval; }
|
2012-04-19 14:35:52 +08:00
|
|
|
/** Set the FPS value. */
|
2013-11-16 21:08:00 +08:00
|
|
|
virtual void setAnimationInterval(double interval) = 0;
|
2010-07-12 17:03:27 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
/** Whether or not to display the FPS on the bottom-left corner */
|
2013-08-08 16:31:44 +08:00
|
|
|
inline bool isDisplayStats() { return _displayStats; }
|
2012-04-19 14:35:52 +08:00
|
|
|
/** Display the FPS on the bottom-left corner */
|
2013-07-26 04:36:19 +08:00
|
|
|
inline void setDisplayStats(bool displayStats) { _displayStats = displayStats; }
|
2012-04-13 11:22:17 +08:00
|
|
|
|
|
|
|
/** seconds per frame */
|
2013-06-15 14:03:30 +08:00
|
|
|
inline float getSecondsPerFrame() { return _secondsPerFrame; }
|
2010-07-12 17:03:27 +08:00
|
|
|
|
2013-09-13 11:41:20 +08:00
|
|
|
/** Get the EGLView, where everything is rendered
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-08-08 16:31:44 +08:00
|
|
|
inline EGLView* getOpenGLView() { return _openGLView; }
|
2013-11-16 21:08:00 +08:00
|
|
|
void setOpenGLView(EGLView *openGLView);
|
2010-07-12 17:03:27 +08:00
|
|
|
|
2013-11-07 18:52:36 +08:00
|
|
|
TextureCache* getTextureCache() const;
|
|
|
|
|
2013-08-08 16:31:44 +08:00
|
|
|
inline bool isNextDeltaTimeZero() { return _nextDeltaTimeZero; }
|
2013-07-26 04:36:19 +08:00
|
|
|
void setNextDeltaTimeZero(bool nextDeltaTimeZero);
|
2010-07-12 17:03:27 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
/** Whether or not the Director is paused */
|
2013-08-08 16:31:44 +08:00
|
|
|
inline bool isPaused() { return _paused; }
|
2012-06-11 10:59:57 +08:00
|
|
|
|
2011-07-08 14:48:25 +08:00
|
|
|
/** How many frames were called since the director started */
|
2013-08-08 16:31:44 +08:00
|
|
|
inline unsigned int getTotalFrames() { return _totalFrames; }
|
2011-07-08 14:48:25 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
/** Sets an OpenGL projection
|
|
|
|
@since v0.8.2
|
2013-09-13 11:41:20 +08:00
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
2012-04-19 14:35:52 +08:00
|
|
|
*/
|
2013-08-08 16:31:44 +08:00
|
|
|
inline Projection getProjection() { return _projection; }
|
2013-07-26 04:36:19 +08:00
|
|
|
void setProjection(Projection projection);
|
2013-02-27 15:44:36 +08:00
|
|
|
|
|
|
|
/** Sets the glViewport*/
|
|
|
|
void setViewport();
|
2010-07-12 17:03:27 +08:00
|
|
|
|
2011-07-08 14:48:25 +08:00
|
|
|
/** How many frames were called since the director started */
|
|
|
|
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
/** 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
|
|
|
|
*/
|
2013-08-08 16:31:44 +08:00
|
|
|
inline bool isSendCleanupToScene() { return _sendCleanupToScene; }
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
/** This object will be visited after the main scene is visited.
|
|
|
|
This object MUST implement the "visit" selector.
|
2013-06-20 14:13:12 +08:00
|
|
|
Useful to hook a notification object, like Notifications (http://github.com/manucorporat/CCNotifications)
|
2012-04-19 14:35:52 +08:00
|
|
|
@since v0.99.5
|
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
Node* getNotificationNode();
|
|
|
|
void setNotificationNode(Node *node);
|
2012-11-13 11:06:32 +08:00
|
|
|
|
2013-09-23 02:39:42 +08:00
|
|
|
/** Director delegate. It shall implement the DirectorDelegate protocol
|
2012-11-13 11:06:32 +08:00
|
|
|
@since v0.99.5
|
2013-09-13 11:41:20 +08:00
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
2012-11-13 11:06:32 +08:00
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
DirectorDelegate* getDelegate() const;
|
2013-09-13 11:41:20 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-08-08 16:31:44 +08:00
|
|
|
void setDelegate(DirectorDelegate* delegate);
|
2010-07-12 17:03:27 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// window size
|
2010-07-12 17:03:27 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
/** returns the size of the OpenGL view in points.
|
|
|
|
*/
|
2013-08-08 16:31:44 +08:00
|
|
|
const Size& getWinSize() const;
|
2010-07-12 17:03:27 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
/** returns the size of the OpenGL view in pixels.
|
|
|
|
*/
|
2013-08-08 16:31:44 +08:00
|
|
|
Size getWinSizeInPixels() const;
|
2012-08-09 10:23:39 +08:00
|
|
|
|
|
|
|
/** returns visible size of the OpenGL view in points.
|
|
|
|
* the value is equal to getWinSize if don't invoke
|
2013-06-20 14:13:12 +08:00
|
|
|
* EGLView::setDesignResolutionSize()
|
2012-08-09 10:23:39 +08:00
|
|
|
*/
|
2013-07-07 13:01:21 +08:00
|
|
|
Size getVisibleSize() const;
|
2012-08-09 10:23:39 +08:00
|
|
|
|
|
|
|
/** returns visible origin of the OpenGL view in points.
|
|
|
|
*/
|
2013-07-07 13:01:21 +08:00
|
|
|
Point getVisibleOrigin() const;
|
2010-07-12 17:03:27 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
/** converts a UIKit coordinate to an OpenGL coordinate
|
2012-11-13 11:06:32 +08:00
|
|
|
Useful to convert (multi) touch coordinates to the current layout (portrait or landscape)
|
2012-04-19 14:35:52 +08:00
|
|
|
*/
|
2013-07-26 04:36:19 +08:00
|
|
|
Point convertToGL(const Point& point);
|
2010-07-12 17:03:27 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
/** converts an OpenGL coordinate to a UIKit coordinate
|
|
|
|
Useful to convert node points to window points for calls such as glScissor
|
|
|
|
*/
|
2013-07-26 04:36:19 +08:00
|
|
|
Point convertToUI(const Point& point);
|
2010-07-12 17:03:27 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
/// XXX: missing description
|
2013-08-08 16:31:44 +08:00
|
|
|
float getZEye() const;
|
2010-07-12 17:03:27 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// Scene Management
|
2010-07-12 17:03:27 +08:00
|
|
|
|
2013-05-01 06:33:22 +08:00
|
|
|
/** Enters the Director's main loop with the given Scene.
|
2012-04-19 14:35:52 +08:00
|
|
|
* Call it to run only your FIRST scene.
|
|
|
|
* Don't call it if there is already a running scene.
|
2012-04-13 11:22:17 +08:00
|
|
|
*
|
|
|
|
* It will call pushScene: and then it will call startAnimation
|
2012-04-19 14:35:52 +08:00
|
|
|
*/
|
2013-07-26 04:36:19 +08:00
|
|
|
void runWithScene(Scene *scene);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-05-01 06:33:22 +08:00
|
|
|
/** Suspends the execution of the running scene, pushing it on the stack of suspended scenes.
|
2012-04-19 14:35:52 +08:00
|
|
|
* 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.
|
|
|
|
*/
|
2013-07-26 04:36:19 +08:00
|
|
|
void pushScene(Scene *scene);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-09-23 02:39:42 +08:00
|
|
|
/** Pops out a scene from the stack.
|
2012-04-19 14:35:52 +08:00
|
|
|
* 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.
|
|
|
|
*/
|
2013-08-08 16:31:44 +08:00
|
|
|
void popScene();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-09-23 02:39:42 +08:00
|
|
|
/** Pops out all scenes from the stack until the root scene in the queue.
|
2012-06-12 02:50:32 +08:00
|
|
|
* This scene will replace the running one.
|
2013-05-01 06:33:22 +08:00
|
|
|
* Internally it will call `popToSceneStackLevel(1)`
|
2012-06-12 02:50:32 +08:00
|
|
|
*/
|
2013-08-08 16:31:44 +08:00
|
|
|
void popToRootScene();
|
2012-06-11 10:59:57 +08:00
|
|
|
|
2013-09-23 02:39:42 +08:00
|
|
|
/** Pops out all scenes from the stack until it reaches `level`.
|
2013-05-01 06:33:22 +08:00
|
|
|
If level is 0, it will end the director.
|
|
|
|
If level is 1, it will pop all scenes until it reaches to root scene.
|
|
|
|
If level is <= than the current stack level, it won't do anything.
|
|
|
|
*/
|
|
|
|
void popToSceneStackLevel(int level);
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
/** Replaces the running scene with a new one. The running scene is terminated.
|
|
|
|
* ONLY call it if there is a running scene.
|
|
|
|
*/
|
2013-07-26 04:36:19 +08:00
|
|
|
void replaceScene(Scene *scene);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
/** Ends the execution, releases the running scene.
|
|
|
|
It doesn't remove the OpenGL view from its parent. You have to do it manually.
|
2013-09-13 11:41:20 +08:00
|
|
|
* @lua endToLua
|
2012-04-19 14:35:52 +08:00
|
|
|
*/
|
2013-08-08 16:31:44 +08:00
|
|
|
void end();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
/** 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 consumption
|
|
|
|
*/
|
2013-08-08 16:31:44 +08:00
|
|
|
void pause();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
/** Resumes the paused scene
|
|
|
|
The scheduled timers will be activated again.
|
|
|
|
The "delta time" will be 0 (as if the game wasn't paused)
|
|
|
|
*/
|
2013-08-08 16:31:44 +08:00
|
|
|
void resume();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
/** Stops the animation. Nothing will be drawn. The main loop won't be triggered anymore.
|
|
|
|
If you don't want to pause your animation call [pause] instead.
|
|
|
|
*/
|
2013-08-08 16:31:44 +08:00
|
|
|
virtual void stopAnimation() = 0;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
/** The main loop is triggered again.
|
|
|
|
Call this function only if [stopAnimation] was called earlier
|
|
|
|
@warning Don't call this function to start the main loop. To run the main loop call runWithScene
|
|
|
|
*/
|
2013-08-08 16:31:44 +08:00
|
|
|
virtual void startAnimation() = 0;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
/** Draw the scene.
|
|
|
|
This method is called every frame. Don't call it manually.
|
|
|
|
*/
|
2013-08-08 16:31:44 +08:00
|
|
|
void drawScene();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// Memory Helper
|
|
|
|
|
2013-09-23 02:39:42 +08:00
|
|
|
/** Removes all cocos2d cached data.
|
2013-06-20 14:13:12 +08:00
|
|
|
It will purge the TextureCache, SpriteFrameCache, LabelBMFont cache
|
2012-04-19 14:35:52 +08:00
|
|
|
@since v0.99.3
|
|
|
|
*/
|
2013-08-08 16:31:44 +08:00
|
|
|
void purgeCachedData();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
/** sets the default values based on the Configuration info */
|
2013-08-08 16:31:44 +08:00
|
|
|
void setDefaultValues();
|
2013-06-07 03:23:44 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// OpenGL Helper
|
|
|
|
|
|
|
|
/** sets the OpenGL default values */
|
2013-08-08 16:31:44 +08:00
|
|
|
void setGLDefaultValues();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
/** enables/disables OpenGL alpha blending */
|
2013-08-08 16:31:44 +08:00
|
|
|
void setAlphaBlending(bool on);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
/** enables/disables OpenGL depth test */
|
2013-08-08 16:31:44 +08:00
|
|
|
void setDepthTest(bool on);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-08-08 16:31:44 +08:00
|
|
|
virtual void mainLoop() = 0;
|
2012-04-19 14:35:52 +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
|
|
|
|
*/
|
2012-08-01 15:30:12 +08:00
|
|
|
void setContentScaleFactor(float scaleFactor);
|
2013-08-08 16:31:44 +08:00
|
|
|
float getContentScaleFactor() const;
|
2013-11-27 10:35:12 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
Get the Culling Frustum
|
|
|
|
*/
|
|
|
|
|
|
|
|
Frustum* getFrustum() const { return _cullingFrustum; }
|
2010-12-29 18:01:37 +08:00
|
|
|
|
|
|
|
public:
|
2013-07-23 15:19:26 +08:00
|
|
|
/** Gets the Scheduler associated with this director
|
2012-04-19 14:35:52 +08:00
|
|
|
@since v2.0
|
|
|
|
*/
|
2013-07-23 15:19:26 +08:00
|
|
|
Scheduler* getScheduler() const;
|
|
|
|
|
|
|
|
/** Sets the Scheduler associated with this director
|
2012-04-19 14:35:52 +08:00
|
|
|
@since v2.0
|
|
|
|
*/
|
2013-07-23 15:19:26 +08:00
|
|
|
void setScheduler(Scheduler* scheduler);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-07-23 15:19:26 +08:00
|
|
|
/** Gets the ActionManager associated with this director
|
|
|
|
@since v2.0
|
|
|
|
*/
|
|
|
|
ActionManager* getActionManager() const;
|
|
|
|
|
|
|
|
/** Sets the ActionManager associated with this director
|
|
|
|
@since v2.0
|
|
|
|
*/
|
|
|
|
void setActionManager(ActionManager* actionManager);
|
2013-10-26 15:04:01 +08:00
|
|
|
|
|
|
|
/** Gets the EventDispatcher associated with this director
|
|
|
|
@since v3.0
|
|
|
|
*/
|
|
|
|
EventDispatcher* getEventDispatcher() const;
|
|
|
|
|
|
|
|
/** Sets the EventDispatcher associated with this director
|
|
|
|
@since v3.0
|
|
|
|
*/
|
|
|
|
void setEventDispatcher(EventDispatcher* dispatcher);
|
|
|
|
|
2013-07-23 15:19:26 +08:00
|
|
|
/* Gets delta time since last tick to main loop */
|
|
|
|
float getDeltaTime() const;
|
2013-09-30 16:22:55 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* get Frame Rate
|
|
|
|
*/
|
|
|
|
float getFrameRate() const { return _frameRate; }
|
2010-07-12 17:03:27 +08:00
|
|
|
|
|
|
|
protected:
|
2012-04-19 14:35:52 +08:00
|
|
|
void purgeDirector();
|
2013-06-15 14:03:30 +08:00
|
|
|
bool _purgeDirecotorInNextLoop; // this flag will be set to true in end()
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-08-08 16:31:44 +08:00
|
|
|
void setNextScene();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2012-04-13 11:22:17 +08:00
|
|
|
void showStats();
|
|
|
|
void createStatsLabel();
|
|
|
|
void calculateMPF();
|
2013-11-06 09:36:44 +08:00
|
|
|
void getFPSImageData(unsigned char** datapointer, long* length);
|
2013-02-27 09:38:30 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
/** calculates delta time since last time it was called */
|
2012-04-13 11:22:17 +08:00
|
|
|
void calculateDeltaTime();
|
2013-07-16 03:43:22 +08:00
|
|
|
|
2013-11-07 18:52:36 +08:00
|
|
|
//textureCache creation or release
|
|
|
|
void initTextureCache();
|
|
|
|
void destroyTextureCache();
|
|
|
|
|
2012-04-13 11:22:17 +08:00
|
|
|
protected:
|
2013-07-23 15:19:26 +08:00
|
|
|
/** Scheduler associated with this director
|
|
|
|
@since v2.0
|
|
|
|
*/
|
|
|
|
Scheduler* _scheduler;
|
|
|
|
|
|
|
|
/** ActionManager associated with this director
|
|
|
|
@since v2.0
|
|
|
|
*/
|
|
|
|
ActionManager* _actionManager;
|
2013-10-26 15:04:01 +08:00
|
|
|
|
|
|
|
/** EventDispatcher associated with this director
|
|
|
|
@since v3.0
|
|
|
|
*/
|
|
|
|
EventDispatcher* _eventDispatcher;
|
2013-09-03 18:22:03 +08:00
|
|
|
|
2013-07-23 15:19:26 +08:00
|
|
|
/* delta time since last tick to main loop */
|
|
|
|
float _deltaTime;
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
/* The EGLView, where everything is rendered */
|
|
|
|
EGLView *_openGLView;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-11-07 18:52:36 +08:00
|
|
|
//texture cache belongs to this director
|
|
|
|
TextureCache *_textureCache;
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
double _animationInterval;
|
|
|
|
double _oldAnimationInterval;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
/* landscape mode ? */
|
2013-06-15 14:03:30 +08:00
|
|
|
bool _landscape;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
bool _displayStats;
|
|
|
|
float _accumDt;
|
|
|
|
float _frameRate;
|
2012-04-13 11:22:17 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
LabelAtlas *_FPSLabel;
|
|
|
|
LabelAtlas *_SPFLabel;
|
|
|
|
LabelAtlas *_drawsLabel;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2012-06-11 10:59:57 +08:00
|
|
|
/** Whether or not the Director is paused */
|
2013-06-15 14:03:30 +08:00
|
|
|
bool _paused;
|
2012-06-11 10:59:57 +08:00
|
|
|
|
2011-07-08 14:48:25 +08:00
|
|
|
/* How many frames were called since the director started */
|
2013-06-15 14:03:30 +08:00
|
|
|
unsigned int _totalFrames;
|
|
|
|
unsigned int _frames;
|
|
|
|
float _secondsPerFrame;
|
2013-11-27 10:35:12 +08:00
|
|
|
|
|
|
|
Frustum* _cullingFrustum;
|
2011-07-08 14:48:25 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
/* The running scene */
|
2013-06-20 14:13:12 +08:00
|
|
|
Scene *_runningScene;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
/* will be the next 'runningScene' in the next frame
|
|
|
|
nextScene is a weak reference. */
|
2013-06-20 14:13:12 +08:00
|
|
|
Scene *_nextScene;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-08-01 16:39:42 +08:00
|
|
|
/* If true, then "old" scene will receive the cleanup message */
|
2013-06-15 14:03:30 +08:00
|
|
|
bool _sendCleanupToScene;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
/* scheduled scenes */
|
2013-06-20 14:13:12 +08:00
|
|
|
Array* _scenesStack;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
/* last time the main loop was updated */
|
2013-07-19 13:42:45 +08:00
|
|
|
struct timeval *_lastUpdate;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
/* whether or not the next delta time will be zero */
|
2013-06-15 14:03:30 +08:00
|
|
|
bool _nextDeltaTimeZero;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
/* projection used */
|
2013-07-25 14:39:32 +08:00
|
|
|
Projection _projection;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
/* window size in points */
|
2013-06-20 14:13:12 +08:00
|
|
|
Size _winSizeInPoints;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
/* content scale factor */
|
2013-06-15 14:03:30 +08:00
|
|
|
float _contentScaleFactor;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
/* store the fps string */
|
2013-06-15 14:03:30 +08:00
|
|
|
char *_FPS;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
/* This object will be visited after the scene. Useful to hook a notification node */
|
2013-06-20 14:13:12 +08:00
|
|
|
Node *_notificationNode;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
/* Projection protocol delegate */
|
2013-06-20 14:13:12 +08:00
|
|
|
DirectorDelegate *_projectionDelegate;
|
2012-08-07 14:29:46 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
// EGLViewProtocol will recreate stats labels to fit visible rect
|
|
|
|
friend class EGLViewProtocol;
|
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
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
class DisplayLinkDirector : public Director
|
2010-08-02 10:58:00 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-08-08 16:31:44 +08:00
|
|
|
DisplayLinkDirector()
|
2013-06-15 14:03:30 +08:00
|
|
|
: _invalid(false)
|
2012-04-19 14:35:52 +08:00
|
|
|
{}
|
2010-08-02 10:58:00 +08:00
|
|
|
|
2013-07-16 03:43:22 +08:00
|
|
|
//
|
|
|
|
// Overrides
|
|
|
|
//
|
2013-08-08 16:31:44 +08:00
|
|
|
virtual void mainLoop() override;
|
|
|
|
virtual void setAnimationInterval(double value) override;
|
|
|
|
virtual void startAnimation() override;
|
2013-07-16 03:43:22 +08:00
|
|
|
virtual void stopAnimation() override;
|
2010-08-02 10:58:00 +08:00
|
|
|
|
|
|
|
protected:
|
2013-06-15 14:03:30 +08:00
|
|
|
bool _invalid;
|
2010-08-02 10:58:00 +08:00
|
|
|
};
|
|
|
|
|
2012-06-20 18:09:11 +08:00
|
|
|
// end of base_node group
|
|
|
|
/// @}
|
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
NS_CC_END
|
2010-08-02 10:58:00 +08:00
|
|
|
|
|
|
|
#endif // __CCDIRECTOR_H__
|