2010-08-02 10:58:00 +08:00
|
|
|
/****************************************************************************
|
2014-01-07 11:25:07 +08:00
|
|
|
Copyright (c) 2008-2010 Ricardo Quesada
|
|
|
|
Copyright (c) 2010-2013 cocos2d-x.org
|
|
|
|
Copyright (c) 2011 Zynga Inc.
|
2015-04-02 23:35:56 +08:00
|
|
|
Copyright (c) 2013-2015 Chukong Technologies 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__
|
|
|
|
|
2014-09-10 07:50:02 +08:00
|
|
|
#include <stack>
|
2013-07-19 13:42:45 +08:00
|
|
|
|
2014-09-10 08:17:07 +08:00
|
|
|
#include "platform/CCPlatformMacros.h"
|
2014-04-27 01:11:22 +08:00
|
|
|
#include "base/CCRef.h"
|
2014-04-27 01:35:57 +08:00
|
|
|
#include "base/CCVector.h"
|
2014-08-29 16:44:20 +08:00
|
|
|
#include "2d/CCScene.h"
|
2014-04-26 13:03:25 +08:00
|
|
|
#include "math/CCMath.h"
|
2014-09-10 07:50:02 +08:00
|
|
|
#include "platform/CCGL.h"
|
2014-08-02 16:31:16 +08:00
|
|
|
#include "platform/CCGLView.h"
|
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
|
|
|
/**
|
2015-03-24 11:15:40 +08:00
|
|
|
* @addtogroup base
|
2012-06-20 18:09:11 +08:00
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2012-05-22 08:20:47 +08:00
|
|
|
/* Forward declarations. */
|
2013-06-20 14:13:12 +08:00
|
|
|
class LabelAtlas;
|
2014-08-02 16:31:16 +08:00
|
|
|
//class GLView;
|
2013-06-20 14:13:12 +08:00
|
|
|
class DirectorDelegate;
|
|
|
|
class Node;
|
|
|
|
class Scheduler;
|
|
|
|
class ActionManager;
|
2013-10-26 15:04:01 +08:00
|
|
|
class EventDispatcher;
|
2013-12-21 16:56:28 +08:00
|
|
|
class EventCustom;
|
|
|
|
class EventListenerCustom;
|
2013-11-07 18:52:36 +08:00
|
|
|
class TextureCache;
|
2013-12-18 09:50:17 +08:00
|
|
|
class Renderer;
|
2014-08-07 15:23:31 +08:00
|
|
|
class Camera;
|
2014-03-22 20:55:08 +08:00
|
|
|
|
2014-01-11 09:11:14 +08:00
|
|
|
class Console;
|
2015-06-09 10:59:43 +08:00
|
|
|
namespace experimental
|
|
|
|
{
|
|
|
|
class FrameBuffer;
|
|
|
|
}
|
2015-06-04 15:53:13 +08:00
|
|
|
|
2010-09-28 18:27:33 +08:00
|
|
|
/**
|
2015-03-18 21:39:50 +08:00
|
|
|
* @brief Matrix stack type.
|
|
|
|
*/
|
2014-04-02 16:47:23 +08:00
|
|
|
enum class MATRIX_STACK_TYPE
|
|
|
|
{
|
2015-03-18 21:39:50 +08:00
|
|
|
/// Model view matrix stack
|
2014-04-02 16:47:23 +08:00
|
|
|
MATRIX_STACK_MODELVIEW,
|
2015-03-18 21:39:50 +08:00
|
|
|
|
|
|
|
/// projection matrix stack
|
2014-04-02 16:47:23 +08:00
|
|
|
MATRIX_STACK_PROJECTION,
|
2015-03-18 21:39:50 +08:00
|
|
|
|
|
|
|
/// texture matrix stack
|
2014-04-02 16:47:23 +08:00
|
|
|
MATRIX_STACK_TEXTURE
|
|
|
|
};
|
|
|
|
|
2015-03-18 21:39:50 +08:00
|
|
|
/**
|
|
|
|
@brief Class that creates and handles the main Window and manages how
|
|
|
|
and when to execute the Scenes.
|
|
|
|
|
|
|
|
The Director is also responsible for:
|
|
|
|
- initializing the OpenGL context
|
|
|
|
- setting the OpenGL buffer depth (default one is 0-bit)
|
|
|
|
- setting the projection (default one is 3D)
|
|
|
|
|
|
|
|
Since the Director is a singleton, the standard way to use it is by calling:
|
|
|
|
_ Director::getInstance()->methodName();
|
|
|
|
*/
|
2014-02-20 10:53:49 +08:00
|
|
|
class CC_DLL Director : public Ref
|
2010-07-12 17:03:27 +08:00
|
|
|
{
|
2012-03-21 17:35:20 +08:00
|
|
|
public:
|
2015-03-18 21:39:50 +08:00
|
|
|
/** Director will trigger an event when projection type is changed. */
|
2013-12-21 16:56:28 +08:00
|
|
|
static const char *EVENT_PROJECTION_CHANGED;
|
2015-03-18 21:39:50 +08:00
|
|
|
/** Director will trigger an event after Schedule::update() is invoked. */
|
2013-12-21 16:56:28 +08:00
|
|
|
static const char* EVENT_AFTER_UPDATE;
|
2015-03-18 21:39:50 +08:00
|
|
|
/** Director will trigger an event after Scene::render() is invoked. */
|
2013-12-21 16:56:28 +08:00
|
|
|
static const char* EVENT_AFTER_VISIT;
|
2015-03-18 21:39:50 +08:00
|
|
|
/** Director will trigger an event after a scene is drawn, the data is sent to GPU. */
|
2013-12-21 16:56:28 +08:00
|
|
|
static const char* EVENT_AFTER_DRAW;
|
|
|
|
|
2015-03-18 21:39:50 +08:00
|
|
|
/**
|
|
|
|
* @brief Possible OpenGL projections used by director
|
2013-07-25 14:39:32 +08:00
|
|
|
*/
|
2013-07-26 04:36:19 +08:00
|
|
|
enum class Projection
|
2013-07-25 14:39:32 +08:00
|
|
|
{
|
2015-03-18 21:39:50 +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
|
|
|
|
2015-03-18 21:39:50 +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
|
|
|
|
2015-03-18 21:39:50 +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
|
|
|
|
2015-03-18 21:39:50 +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
|
|
|
};
|
|
|
|
|
2015-03-18 21:39:50 +08:00
|
|
|
/**
|
2015-03-19 10:33:11 +08:00
|
|
|
* Returns a shared instance of the director.
|
|
|
|
* @js _getInstance
|
|
|
|
*/
|
2013-07-16 03:43:22 +08:00
|
|
|
static Director* getInstance();
|
|
|
|
|
2015-03-19 10:33:11 +08:00
|
|
|
/**
|
|
|
|
* @deprecated Use getInstance() instead.
|
|
|
|
* @js NA
|
|
|
|
*/
|
2013-07-18 07:56:19 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE static Director* sharedDirector() { return Director::getInstance(); }
|
2015-03-18 21:39:50 +08:00
|
|
|
|
2013-09-13 16:46:31 +08:00
|
|
|
/**
|
|
|
|
* @js ctor
|
|
|
|
*/
|
2015-03-18 21:39:50 +08:00
|
|
|
Director();
|
|
|
|
|
2013-09-13 13:52:42 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2014-02-08 11:37:44 +08:00
|
|
|
virtual ~Director();
|
|
|
|
virtual bool init();
|
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
|
|
|
|
2015-03-18 21:39:50 +08:00
|
|
|
/** Gets 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
|
|
|
|
2015-03-18 21:39:50 +08:00
|
|
|
/** Gets the FPS value. */
|
2013-08-08 16:31:44 +08:00
|
|
|
inline double getAnimationInterval() { return _animationInterval; }
|
2015-03-18 21:39:50 +08:00
|
|
|
/** Sets the FPS value. FPS = 1/internal. */
|
2013-11-16 21:08:00 +08:00
|
|
|
virtual void setAnimationInterval(double interval) = 0;
|
2010-07-12 17:03:27 +08:00
|
|
|
|
2015-03-18 21:39:50 +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; }
|
2015-03-18 21:39:50 +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
|
|
|
|
2015-03-18 21:39:50 +08:00
|
|
|
/** Get seconds per frame. */
|
2013-06-15 14:03:30 +08:00
|
|
|
inline float getSecondsPerFrame() { return _secondsPerFrame; }
|
2010-07-12 17:03:27 +08:00
|
|
|
|
2015-03-18 21:39:50 +08:00
|
|
|
/**
|
|
|
|
* Get the GLView.
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2014-01-31 07:40:56 +08:00
|
|
|
inline GLView* getOpenGLView() { return _openGLView; }
|
2015-03-18 21:39:50 +08:00
|
|
|
/**
|
|
|
|
* Sets the GLView.
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2014-01-31 07:40:56 +08:00
|
|
|
void setOpenGLView(GLView *openGLView);
|
2010-07-12 17:03:27 +08:00
|
|
|
|
2015-03-18 21:39:50 +08:00
|
|
|
/*
|
2015-03-19 10:33:11 +08:00
|
|
|
* Gets singleton of TextureCache.
|
|
|
|
* @js NA
|
|
|
|
*/
|
2013-11-07 18:52:36 +08:00
|
|
|
TextureCache* getTextureCache() const;
|
|
|
|
|
2015-03-18 21:39:50 +08:00
|
|
|
/** Whether or not `_nextDeltaTimeZero` is set to 0. */
|
2013-08-08 16:31:44 +08:00
|
|
|
inline bool isNextDeltaTimeZero() { return _nextDeltaTimeZero; }
|
2015-03-18 21:39:50 +08:00
|
|
|
/**
|
|
|
|
* Sets the detal time between current frame and next frame is 0.
|
|
|
|
* This value will be used in Schedule, and will affect all functions that are using frame detal time, such as Actions.
|
|
|
|
* This value will take effect only one time.
|
|
|
|
*/
|
2013-07-26 04:36:19 +08:00
|
|
|
void setNextDeltaTimeZero(bool nextDeltaTimeZero);
|
2010-07-12 17:03:27 +08:00
|
|
|
|
2015-03-18 21:39:50 +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
|
|
|
|
2015-03-18 21:39:50 +08:00
|
|
|
/** Gets an OpenGL projection.
|
2015-03-19 10:33:11 +08:00
|
|
|
* @since v0.8.2
|
2013-09-13 11:41:20 +08:00
|
|
|
* @lua NA
|
2012-04-19 14:35:52 +08:00
|
|
|
*/
|
2013-08-08 16:31:44 +08:00
|
|
|
inline Projection getProjection() { return _projection; }
|
2015-03-18 21:39:50 +08:00
|
|
|
/** Sets OpenGL projection. */
|
2013-07-26 04:36:19 +08:00
|
|
|
void setProjection(Projection projection);
|
2013-02-27 15:44:36 +08:00
|
|
|
|
2015-03-18 21:39:50 +08:00
|
|
|
/** Sets the glViewport.*/
|
2013-02-27 15:44:36 +08:00
|
|
|
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.
|
2015-03-18 21:39:50 +08:00
|
|
|
* 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
|
2012-04-19 14:35:52 +08:00
|
|
|
*/
|
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.
|
2015-03-18 21:39:50 +08:00
|
|
|
* This object MUST implement the "visit" function.
|
|
|
|
* Useful to hook a notification object, like Notifications (http://github.com/manucorporat/CCNotifications)
|
|
|
|
* @since v0.99.5
|
2012-04-19 14:35:52 +08:00
|
|
|
*/
|
2014-01-11 09:11:14 +08:00
|
|
|
Node* getNotificationNode() const { return _notificationNode; }
|
2015-03-18 21:39:50 +08:00
|
|
|
/**
|
|
|
|
* Sets the notification node.
|
|
|
|
* @see Director::getNotificationNode()
|
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
void setNotificationNode(Node *node);
|
2012-11-13 11:06:32 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// window size
|
2010-07-12 17:03:27 +08:00
|
|
|
|
2015-03-18 21:39:50 +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
|
|
|
|
2015-03-18 21:39:50 +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
|
|
|
|
2015-03-18 21:39:50 +08:00
|
|
|
/**
|
|
|
|
* Returns visible size of the OpenGL view in points.
|
|
|
|
* The value is equal to `Director::getWinSize()` if don't invoke `GLView::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
|
|
|
|
2015-03-18 21:39:50 +08:00
|
|
|
/** Returns visible origin coordinate of the OpenGL view in points. */
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 getVisibleOrigin() const;
|
2010-07-12 17:03:27 +08:00
|
|
|
|
2015-03-18 21:39:50 +08:00
|
|
|
/**
|
|
|
|
* Converts a screen coordinate to an OpenGL coordinate.
|
|
|
|
* Useful to convert (multi) touch coordinates to the current layout (portrait or landscape).
|
2012-04-19 14:35:52 +08:00
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 convertToGL(const Vec2& point);
|
2010-07-12 17:03:27 +08:00
|
|
|
|
2015-03-18 21:39:50 +08:00
|
|
|
/**
|
|
|
|
* Converts an OpenGL coordinate to a screen coordinate.
|
|
|
|
* Useful to convert node points to window points for calls such as glScissor.
|
2012-04-19 14:35:52 +08:00
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 convertToUI(const Vec2& point);
|
2010-07-12 17:03:27 +08:00
|
|
|
|
2015-03-18 21:39:50 +08:00
|
|
|
/**
|
|
|
|
* Gets the distance between camera and near clipping frane.
|
|
|
|
* It is correct for default camera that near clipping frane is the same as screen.
|
|
|
|
*/
|
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
|
|
|
|
2015-03-18 21:39:50 +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
|
2015-03-19 10:33:11 +08:00
|
|
|
* @js NA
|
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
|
|
|
|
2015-03-18 21:39:50 +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
|
|
|
|
2015-03-18 21:39:50 +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
|
|
|
|
2015-03-18 21:39:50 +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.
|
2015-03-18 21:39:50 +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.
|
2015-03-19 10:33:11 +08:00
|
|
|
* @js NA
|
2012-04-19 14:35:52 +08:00
|
|
|
*/
|
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.
|
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.
|
2015-03-18 21:39:50 +08:00
|
|
|
* 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.
|
2012-04-19 14:35:52 +08:00
|
|
|
*/
|
2013-08-08 16:31:44 +08:00
|
|
|
void pause();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2015-03-18 21:39:50 +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).
|
2012-04-19 14:35:52 +08:00
|
|
|
*/
|
2013-08-08 16:31:44 +08:00
|
|
|
void resume();
|
2014-12-28 11:55:06 +08:00
|
|
|
|
2015-03-18 21:39:50 +08:00
|
|
|
/*
|
2015-03-19 10:33:11 +08:00
|
|
|
* Restart the director.
|
|
|
|
* @js NA
|
|
|
|
*/
|
2014-12-28 11:55:06 +08:00
|
|
|
void restart();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
/** Stops the animation. Nothing will be drawn. The main loop won't be triggered anymore.
|
2015-03-18 21:39:50 +08:00
|
|
|
* If you don't want to pause your animation call [pause] instead.
|
2012-04-19 14:35:52 +08:00
|
|
|
*/
|
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.
|
2015-03-18 21:39:50 +08:00
|
|
|
* 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.
|
2012-04-19 14:35:52 +08:00
|
|
|
*/
|
2013-08-08 16:31:44 +08:00
|
|
|
virtual void startAnimation() = 0;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
/** Draw the scene.
|
2015-03-18 21:39:50 +08:00
|
|
|
* 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.
|
2015-03-18 21:39:50 +08:00
|
|
|
* It will purge the TextureCache, SpriteFrameCache, LabelBMFont cache
|
|
|
|
* @since v0.99.3
|
2012-04-19 14:35:52 +08:00
|
|
|
*/
|
2013-08-08 16:31:44 +08:00
|
|
|
void purgeCachedData();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2015-03-18 21:39:50 +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
|
|
|
|
|
2015-03-18 21:39:50 +08:00
|
|
|
/** Sets the OpenGL default values.
|
|
|
|
* It will enable alpha blending, disable depth test.
|
2015-03-19 10:33:11 +08:00
|
|
|
* @js NA
|
2015-03-18 21:39:50 +08:00
|
|
|
*/
|
2013-08-08 16:31:44 +08:00
|
|
|
void setGLDefaultValues();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2015-03-18 21:39:50 +08:00
|
|
|
/** Enables/disables OpenGL alpha blending. */
|
2013-08-08 16:31:44 +08:00
|
|
|
void setAlphaBlending(bool on);
|
2014-12-24 11:53:38 +08:00
|
|
|
|
2015-03-18 21:39:50 +08:00
|
|
|
/** Sets clear values for the color buffers,
|
2015-03-19 10:33:11 +08:00
|
|
|
* value range of each element is [0.0, 1.0].
|
|
|
|
* @js NA
|
|
|
|
*/
|
2014-12-24 11:53:38 +08:00
|
|
|
void setClearColor(const Color4F& clearColor);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2015-03-18 21:39:50 +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.
|
2015-03-18 21:39:50 +08:00
|
|
|
* 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
|
2015-03-19 10:33:11 +08:00
|
|
|
*/
|
2012-08-01 15:30:12 +08:00
|
|
|
void setContentScaleFactor(float scaleFactor);
|
2015-03-18 21:39:50 +08:00
|
|
|
/**
|
|
|
|
* Gets content scale factor.
|
|
|
|
* @see Director::setContentScaleFactor()
|
|
|
|
*/
|
2014-01-11 09:11:14 +08:00
|
|
|
float getContentScaleFactor() const { return _contentScaleFactor; }
|
2010-12-29 18:01:37 +08:00
|
|
|
|
2015-03-18 21:39:50 +08:00
|
|
|
/** Gets the Scheduler associated with this director.
|
|
|
|
* @since v2.0
|
2012-04-19 14:35:52 +08:00
|
|
|
*/
|
2014-01-11 09:11:14 +08:00
|
|
|
Scheduler* getScheduler() const { return _scheduler; }
|
2013-07-23 15:19:26 +08:00
|
|
|
|
2015-03-18 21:39:50 +08:00
|
|
|
/** Sets the Scheduler associated with this director.
|
|
|
|
* @since v2.0
|
2012-04-19 14:35:52 +08:00
|
|
|
*/
|
2013-07-23 15:19:26 +08:00
|
|
|
void setScheduler(Scheduler* scheduler);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2015-03-18 21:39:50 +08:00
|
|
|
/** Gets the ActionManager associated with this director.
|
|
|
|
* @since v2.0
|
2013-07-23 15:19:26 +08:00
|
|
|
*/
|
2014-01-11 09:11:14 +08:00
|
|
|
ActionManager* getActionManager() const { return _actionManager; }
|
2013-07-23 15:19:26 +08:00
|
|
|
|
2015-03-18 21:39:50 +08:00
|
|
|
/** Sets the ActionManager associated with this director.
|
|
|
|
* @since v2.0
|
2013-07-23 15:19:26 +08:00
|
|
|
*/
|
|
|
|
void setActionManager(ActionManager* actionManager);
|
2013-10-26 15:04:01 +08:00
|
|
|
|
2015-03-18 21:39:50 +08:00
|
|
|
/** Gets the EventDispatcher associated with this director.
|
|
|
|
* @since v3.0
|
2015-03-19 10:33:11 +08:00
|
|
|
* @js NA
|
2013-10-26 15:04:01 +08:00
|
|
|
*/
|
2014-01-11 09:11:14 +08:00
|
|
|
EventDispatcher* getEventDispatcher() const { return _eventDispatcher; }
|
2013-10-26 15:04:01 +08:00
|
|
|
|
2015-03-18 21:39:50 +08:00
|
|
|
/** Sets the EventDispatcher associated with this director.
|
|
|
|
* @since v3.0
|
2015-03-19 10:33:11 +08:00
|
|
|
* @js NA
|
2013-10-26 15:04:01 +08:00
|
|
|
*/
|
|
|
|
void setEventDispatcher(EventDispatcher* dispatcher);
|
2013-12-18 09:50:17 +08:00
|
|
|
|
2015-03-18 21:39:50 +08:00
|
|
|
/** Returns the Renderer associated with this director.
|
|
|
|
* @since v3.0
|
2013-12-18 09:50:17 +08:00
|
|
|
*/
|
2014-01-11 09:11:14 +08:00
|
|
|
Renderer* getRenderer() const { return _renderer; }
|
|
|
|
|
2015-03-18 21:39:50 +08:00
|
|
|
/** Returns the Console associated with this director.
|
|
|
|
* @since v3.0
|
2015-03-19 10:33:11 +08:00
|
|
|
* @js NA
|
2014-01-11 09:11:14 +08:00
|
|
|
*/
|
|
|
|
Console* getConsole() const { return _console; }
|
2013-12-18 09:50:17 +08:00
|
|
|
|
2015-03-18 21:39:50 +08:00
|
|
|
/* Gets delta time since last tick to main loop. */
|
2013-07-23 15:19:26 +08:00
|
|
|
float getDeltaTime() const;
|
2013-09-30 16:22:55 +08:00
|
|
|
|
|
|
|
/**
|
2015-03-18 21:39:50 +08:00
|
|
|
* Gets Frame Rate.
|
2015-03-19 10:33:11 +08:00
|
|
|
* @js NA
|
2013-09-30 16:22:55 +08:00
|
|
|
*/
|
|
|
|
float getFrameRate() const { return _frameRate; }
|
2010-07-12 17:03:27 +08:00
|
|
|
|
2015-03-18 21:39:50 +08:00
|
|
|
/**
|
2015-03-19 10:33:11 +08:00
|
|
|
* Clones a specified type matrix and put it to the top of specified type of matrix stack.
|
|
|
|
* @js NA
|
|
|
|
*/
|
2014-11-05 08:46:14 +08:00
|
|
|
void pushMatrix(MATRIX_STACK_TYPE type);
|
2015-03-18 21:39:50 +08:00
|
|
|
/** Pops the top matrix of the specified type of matrix stack.
|
2015-03-19 10:33:11 +08:00
|
|
|
* @js NA
|
|
|
|
*/
|
2014-11-05 08:46:14 +08:00
|
|
|
void popMatrix(MATRIX_STACK_TYPE type);
|
2015-03-18 21:39:50 +08:00
|
|
|
/** Adds an identity matrix to the top of specified type of matrxi stack.
|
2015-03-19 10:33:11 +08:00
|
|
|
* @js NA
|
|
|
|
*/
|
2014-11-05 08:46:14 +08:00
|
|
|
void loadIdentityMatrix(MATRIX_STACK_TYPE type);
|
2015-03-18 21:39:50 +08:00
|
|
|
/**
|
|
|
|
* Adds a matrix to the top of specified type of matrix stack.
|
|
|
|
*
|
|
|
|
* @param type Matrix type.
|
|
|
|
* @param mat The matrix that to be added.
|
2015-03-19 10:33:11 +08:00
|
|
|
* @js NA
|
2015-03-18 21:39:50 +08:00
|
|
|
*/
|
2014-11-05 08:46:14 +08:00
|
|
|
void loadMatrix(MATRIX_STACK_TYPE type, const Mat4& mat);
|
2015-03-18 21:39:50 +08:00
|
|
|
/**
|
|
|
|
* Multipies a matrix to the top of specified type of matrix stack.
|
|
|
|
*
|
|
|
|
* @param type Matrix type.
|
|
|
|
* @param mat The matrix that to be multipied.
|
2015-03-19 10:33:11 +08:00
|
|
|
* @js NA
|
2015-03-18 21:39:50 +08:00
|
|
|
*/
|
2014-11-05 08:46:14 +08:00
|
|
|
void multiplyMatrix(MATRIX_STACK_TYPE type, const Mat4& mat);
|
2015-03-18 21:39:50 +08:00
|
|
|
/**
|
2015-03-19 10:33:11 +08:00
|
|
|
* Gets the top matrix of specified type of matrix stack.
|
|
|
|
* @js NA
|
|
|
|
*/
|
2014-11-05 08:46:14 +08:00
|
|
|
const Mat4& getMatrix(MATRIX_STACK_TYPE type);
|
2015-03-18 21:39:50 +08:00
|
|
|
/**
|
2015-03-19 10:33:11 +08:00
|
|
|
* Cleras all types of matrix stack, and add indentity matrix to these matrix stacks.
|
|
|
|
* @js NA
|
|
|
|
*/
|
2014-11-05 08:46:14 +08:00
|
|
|
void resetMatrixStack();
|
|
|
|
|
2010-07-12 17:03:27 +08:00
|
|
|
protected:
|
2014-12-30 10:09:56 +08:00
|
|
|
void reset();
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
void purgeDirector();
|
2014-01-04 13:22:09 +08:00
|
|
|
bool _purgeDirectorInNextLoop; // this flag will be set to true in end()
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2014-12-28 11:55:06 +08:00
|
|
|
void restartDirector();
|
|
|
|
bool _restartDirectorInNextLoop; // this flag will be set to true in restart()
|
|
|
|
|
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-12-05 17:19:01 +08:00
|
|
|
void getFPSImageData(unsigned char** datapointer, ssize_t* 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();
|
|
|
|
|
2014-11-05 08:46:14 +08:00
|
|
|
void initMatrixStack();
|
|
|
|
|
|
|
|
std::stack<Mat4> _modelViewMatrixStack;
|
|
|
|
std::stack<Mat4> _projectionMatrixStack;
|
|
|
|
std::stack<Mat4> _textureMatrixStack;
|
|
|
|
|
2013-07-23 15:19:26 +08:00
|
|
|
/** Scheduler associated with this director
|
|
|
|
@since v2.0
|
|
|
|
*/
|
2013-12-18 09:50:17 +08:00
|
|
|
Scheduler *_scheduler;
|
2013-07-23 15:19:26 +08:00
|
|
|
|
|
|
|
/** ActionManager associated with this director
|
|
|
|
@since v2.0
|
|
|
|
*/
|
2013-12-18 09:50:17 +08:00
|
|
|
ActionManager *_actionManager;
|
2013-10-26 15:04:01 +08:00
|
|
|
|
|
|
|
/** EventDispatcher associated with this director
|
|
|
|
@since v3.0
|
|
|
|
*/
|
|
|
|
EventDispatcher* _eventDispatcher;
|
2013-12-21 16:56:28 +08:00
|
|
|
EventCustom *_eventProjectionChanged, *_eventAfterDraw, *_eventAfterVisit, *_eventAfterUpdate;
|
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;
|
|
|
|
|
2014-07-31 00:53:04 +08:00
|
|
|
/* The _openGLView, where everything is rendered, GLView is a abstract class,cocos2d-x provide GLViewImpl
|
|
|
|
which inherit from it as default renderer context,you can have your own by inherit from it*/
|
2014-01-31 07:40:56 +08:00
|
|
|
GLView *_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;
|
2014-02-08 11:37:44 +08:00
|
|
|
LabelAtlas *_drawnBatchesLabel;
|
|
|
|
LabelAtlas *_drawnVerticesLabel;
|
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;
|
|
|
|
float _secondsPerFrame;
|
2013-11-27 10:35:12 +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-12-18 09:50:17 +08:00
|
|
|
bool _sendCleanupToScene;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
/* scheduled scenes */
|
2013-12-07 10:48:02 +08:00
|
|
|
Vector<Scene*> _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-12-18 09:50:17 +08:00
|
|
|
Size _winSizeInPoints;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
/* content scale factor */
|
2013-12-18 09:50:17 +08:00
|
|
|
float _contentScaleFactor;
|
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
|
|
|
|
2014-01-11 09:11:14 +08:00
|
|
|
/* Renderer for the Director */
|
2013-12-18 09:50:17 +08:00
|
|
|
Renderer *_renderer;
|
2015-06-04 15:53:13 +08:00
|
|
|
|
|
|
|
/* Default FrameBufferObject*/
|
2015-06-09 10:59:43 +08:00
|
|
|
experimental::FrameBuffer* _defaultFBO;
|
2014-01-11 09:11:14 +08:00
|
|
|
|
|
|
|
/* Console for the director */
|
|
|
|
Console *_console;
|
2014-03-22 20:55:08 +08:00
|
|
|
|
2015-04-02 23:35:56 +08:00
|
|
|
bool _isStatusLabelUpdated;
|
|
|
|
|
2014-07-31 00:53:04 +08:00
|
|
|
// GLView will recreate stats labels to fit visible rect
|
2014-08-02 16:31:16 +08:00
|
|
|
friend class GLView;
|
2010-08-02 10:58:00 +08:00
|
|
|
};
|
|
|
|
|
2015-03-24 11:15:40 +08:00
|
|
|
// end of base group
|
|
|
|
/** @} */
|
|
|
|
|
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
|
|
|
{}
|
2014-05-15 01:07:09 +08:00
|
|
|
virtual ~DisplayLinkDirector(){}
|
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-04-18 18:43:45 +08:00
|
|
|
NS_CC_END
|
2010-08-02 10:58:00 +08:00
|
|
|
|
|
|
|
#endif // __CCDIRECTOR_H__
|