axmol/cocos/base/CCDirector.h

641 lines
19 KiB
C
Raw Normal View History

/****************************************************************************
Copyright (c) 2008-2010 Ricardo Quesada
Copyright (c) 2010-2013 cocos2d-x.org
Copyright (c) 2011 Zynga Inc.
Copyright (c) 2013-2015 Chukong Technologies Inc.
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
#include "platform/CCPlatformMacros.h"
#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
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
* @{
*/
/* Forward declarations. */
class LabelAtlas;
2014-08-02 16:31:16 +08:00
//class GLView;
class DirectorDelegate;
class Node;
class Scheduler;
class ActionManager;
class EventDispatcher;
2013-12-21 16:56:28 +08:00
class EventCustom;
class EventListenerCustom;
class TextureCache;
class Renderer;
2014-08-07 15:23:31 +08:00
class Camera;
class Console;
2010-09-28 18:27:33 +08:00
/**
* @brief Matrix stack type.
*/
2014-04-02 16:47:23 +08:00
enum class MATRIX_STACK_TYPE
{
/// Model view matrix stack
2014-04-02 16:47:23 +08:00
MATRIX_STACK_MODELVIEW,
/// projection matrix stack
2014-04-02 16:47:23 +08:00
MATRIX_STACK_PROJECTION,
/// texture matrix stack
2014-04-02 16:47:23 +08:00
MATRIX_STACK_TEXTURE
};
/**
@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();
*/
class CC_DLL Director : public Ref
{
public:
/** Director will trigger an event when projection type is changed. */
2013-12-21 16:56:28 +08:00
static const char *EVENT_PROJECTION_CHANGED;
/** Director will trigger an event after Schedule::update() is invoked. */
2013-12-21 16:56:28 +08:00
static const char* EVENT_AFTER_UPDATE;
/** Director will trigger an event after Scene::render() is invoked. */
2013-12-21 16:56:28 +08:00
static const char* EVENT_AFTER_VISIT;
/** 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;
/**
* @brief Possible OpenGL projections used by director
*/
enum class Projection
{
/// Sets a 2D projection (orthogonal projection).
_2D,
/// Sets a 3D projection with a fovy=60, znear=0.5f and zfar=1500.
_3D,
/// It calls "updateProjection" on the projection delegate.
CUSTOM,
/// Default projection is 3D projection.
DEFAULT = _3D,
};
/**
2015-03-19 10:33:11 +08:00
* Returns a shared instance of the director.
* @js _getInstance
*/
static Director* getInstance();
2015-03-19 10:33:11 +08:00
/**
* @deprecated Use getInstance() instead.
* @js NA
*/
CC_DEPRECATED_ATTRIBUTE static Director* sharedDirector() { return Director::getInstance(); }
/**
* @js ctor
*/
Director();
/**
* @js NA
* @lua NA
*/
virtual ~Director();
virtual bool init();
// attribute
/** 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; }
/** Gets the FPS value. */
2013-08-08 16:31:44 +08:00
inline double getAnimationInterval() { return _animationInterval; }
/** Sets the FPS value. FPS = 1/internal. */
2013-11-16 21:08:00 +08:00
virtual void setAnimationInterval(double interval) = 0;
/** 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; }
/** Display the FPS on the bottom-left corner. */
inline void setDisplayStats(bool displayStats) { _displayStats = displayStats; }
/** Get seconds per frame. */
inline float getSecondsPerFrame() { return _secondsPerFrame; }
/**
* Get the GLView.
* @lua NA
*/
2014-01-31 07:40:56 +08:00
inline GLView* getOpenGLView() { return _openGLView; }
/**
* Sets the GLView.
* @lua NA
*/
2014-01-31 07:40:56 +08:00
void setOpenGLView(GLView *openGLView);
/*
2015-03-19 10:33:11 +08:00
* Gets singleton of TextureCache.
* @js NA
*/
TextureCache* getTextureCache() const;
/** Whether or not `_nextDeltaTimeZero` is set to 0. */
2013-08-08 16:31:44 +08:00
inline bool isNextDeltaTimeZero() { return _nextDeltaTimeZero; }
/**
* 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.
*/
void setNextDeltaTimeZero(bool nextDeltaTimeZero);
/** Whether or not the Director is paused. */
2013-08-08 16:31:44 +08:00
inline bool isPaused() { return _paused; }
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
/** Gets an OpenGL projection.
2015-03-19 10:33:11 +08:00
* @since v0.8.2
* @lua NA
*/
2013-08-08 16:31:44 +08:00
inline Projection getProjection() { return _projection; }
/** Sets OpenGL projection. */
void setProjection(Projection projection);
/** Sets the glViewport.*/
void setViewport();
2011-07-08 14:48:25 +08:00
/** How many frames were called since the director started */
/** 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; }
/** This object will be visited after the main scene is visited.
* This object MUST implement the "visit" function.
* Useful to hook a notification object, like Notifications (http://github.com/manucorporat/CCNotifications)
* @since v0.99.5
*/
Node* getNotificationNode() const { return _notificationNode; }
/**
* Sets the notification node.
* @see Director::getNotificationNode()
*/
void setNotificationNode(Node *node);
// window size
/** Returns the size of the OpenGL view in points. */
2013-08-08 16:31:44 +08:00
const Size& getWinSize() const;
/** Returns the size of the OpenGL view in pixels. */
2013-08-08 16:31:44 +08:00
Size getWinSizeInPixels() const;
/**
* Returns visible size of the OpenGL view in points.
* The value is equal to `Director::getWinSize()` if don't invoke `GLView::setDesignResolutionSize()`.
*/
Size getVisibleSize() const;
/** Returns visible origin coordinate of the OpenGL view in points. */
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
Vec2 getVisibleOrigin() const;
/**
* Converts a screen coordinate to an OpenGL coordinate.
* Useful to convert (multi) touch coordinates to the current layout (portrait or landscape).
*/
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
Vec2 convertToGL(const Vec2& point);
/**
* Converts an OpenGL coordinate to a screen coordinate.
* Useful to convert node points to window points for calls such as glScissor.
*/
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
Vec2 convertToUI(const Vec2& point);
/**
* 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;
// 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.
*
* It will call pushScene: and then it will call startAnimation
2015-03-19 10:33:11 +08:00
* @js NA
*/
void runWithScene(Scene *scene);
/**
* 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(Scene *scene);
/**
* Pops out a scene from the stack.
* 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();
/**
* 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.
* Internally it will call `popToSceneStackLevel(1)`.
2012-06-12 02:50:32 +08:00
*/
2013-08-08 16:31:44 +08:00
void popToRootScene();
2013-09-23 02:39:42 +08:00
/** Pops out all scenes from the stack until it reaches `level`.
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);
/** 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
*/
void replaceScene(Scene *scene);
/** Ends the execution, releases the running scene.
* @lua endToLua
*/
2013-08-08 16:31:44 +08:00
void end();
/** 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();
/** 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();
2014-12-28 11:55:06 +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();
/** 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;
/** 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;
/** Draw the scene.
* This method is called every frame. Don't call it manually.
*/
2013-08-08 16:31:44 +08:00
void drawScene();
// Memory Helper
2013-09-23 02:39:42 +08:00
/** Removes all cocos2d cached data.
* It will purge the TextureCache, SpriteFrameCache, LabelBMFont cache
* @since v0.99.3
*/
2013-08-08 16:31:44 +08:00
void purgeCachedData();
/** Sets the default values based on the Configuration info. */
2013-08-08 16:31:44 +08:00
void setDefaultValues();
// OpenGL Helper
/** Sets the OpenGL default values.
* It will enable alpha blending, disable depth test.
2015-03-19 10:33:11 +08:00
* @js NA
*/
2013-08-08 16:31:44 +08:00
void setGLDefaultValues();
/** 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
/** 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);
/** Enables/disables OpenGL depth test. */
2013-08-08 16:31:44 +08:00
void setDepthTest(bool on);
2013-08-08 16:31:44 +08:00
virtual void mainLoop() = 0;
/** 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
2015-03-19 10:33:11 +08:00
*/
void setContentScaleFactor(float scaleFactor);
/**
* Gets content scale factor.
* @see Director::setContentScaleFactor()
*/
float getContentScaleFactor() const { return _contentScaleFactor; }
2010-12-29 18:01:37 +08:00
/** Gets the Scheduler associated with this director.
* @since v2.0
*/
Scheduler* getScheduler() const { return _scheduler; }
/** Sets the Scheduler associated with this director.
* @since v2.0
*/
void setScheduler(Scheduler* scheduler);
/** Gets the ActionManager associated with this director.
* @since v2.0
*/
ActionManager* getActionManager() const { return _actionManager; }
/** Sets the ActionManager associated with this director.
* @since v2.0
*/
void setActionManager(ActionManager* actionManager);
/** Gets the EventDispatcher associated with this director.
* @since v3.0
2015-03-19 10:33:11 +08:00
* @js NA
*/
EventDispatcher* getEventDispatcher() const { return _eventDispatcher; }
/** Sets the EventDispatcher associated with this director.
* @since v3.0
2015-03-19 10:33:11 +08:00
* @js NA
*/
void setEventDispatcher(EventDispatcher* dispatcher);
/** Returns the Renderer associated with this director.
* @since v3.0
*/
Renderer* getRenderer() const { return _renderer; }
/** Returns the Console associated with this director.
* @since v3.0
2015-03-19 10:33:11 +08:00
* @js NA
*/
Console* getConsole() const { return _console; }
/* Gets delta time since last tick to main loop. */
float getDeltaTime() const;
/**
* Gets Frame Rate.
2015-03-19 10:33:11 +08:00
* @js NA
*/
float getFrameRate() const { return _frameRate; }
/**
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
*/
void pushMatrix(MATRIX_STACK_TYPE type);
/** Pops the top matrix of the specified type of matrix stack.
2015-03-19 10:33:11 +08:00
* @js NA
*/
void popMatrix(MATRIX_STACK_TYPE type);
/** Adds an identity matrix to the top of specified type of matrxi stack.
2015-03-19 10:33:11 +08:00
* @js NA
*/
void loadIdentityMatrix(MATRIX_STACK_TYPE type);
/**
* 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
*/
void loadMatrix(MATRIX_STACK_TYPE type, const Mat4& mat);
/**
* 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
*/
void multiplyMatrix(MATRIX_STACK_TYPE type, const Mat4& mat);
/**
2015-03-19 10:33:11 +08:00
* Gets the top matrix of specified type of matrix stack.
* @js NA
*/
const Mat4& getMatrix(MATRIX_STACK_TYPE type);
/**
2015-03-19 10:33:11 +08:00
* Cleras all types of matrix stack, and add indentity matrix to these matrix stacks.
* @js NA
*/
void resetMatrixStack();
protected:
2014-12-30 10:09:56 +08:00
void reset();
void purgeDirector();
2014-01-04 13:22:09 +08:00
bool _purgeDirectorInNextLoop; // this flag will be set to true in end()
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();
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
/** calculates delta time since last time it was called */
void calculateDeltaTime();
//textureCache creation or release
void initTextureCache();
void destroyTextureCache();
void initMatrixStack();
std::stack<Mat4> _modelViewMatrixStack;
std::stack<Mat4> _projectionMatrixStack;
std::stack<Mat4> _textureMatrixStack;
/** Scheduler associated with this director
@since v2.0
*/
Scheduler *_scheduler;
/** ActionManager associated with this director
@since v2.0
*/
ActionManager *_actionManager;
/** EventDispatcher associated with this director
@since v3.0
*/
EventDispatcher* _eventDispatcher;
2013-12-21 16:56:28 +08:00
EventCustom *_eventProjectionChanged, *_eventAfterDraw, *_eventAfterVisit, *_eventAfterUpdate;
/* 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;
//texture cache belongs to this director
TextureCache *_textureCache;
double _animationInterval;
double _oldAnimationInterval;
/* landscape mode ? */
bool _landscape;
bool _displayStats;
float _accumDt;
float _frameRate;
LabelAtlas *_FPSLabel;
LabelAtlas *_drawnBatchesLabel;
LabelAtlas *_drawnVerticesLabel;
/** Whether or not the Director is paused */
bool _paused;
2011-07-08 14:48:25 +08:00
/* How many frames were called since the director started */
unsigned int _totalFrames;
float _secondsPerFrame;
2013-11-27 10:35:12 +08:00
/* The running scene */
Scene *_runningScene;
/* will be the next 'runningScene' in the next frame
nextScene is a weak reference. */
Scene *_nextScene;
/* If true, then "old" scene will receive the cleanup message */
bool _sendCleanupToScene;
/* scheduled scenes */
2013-12-07 10:48:02 +08:00
Vector<Scene*> _scenesStack;
/* last time the main loop was updated */
2013-07-19 13:42:45 +08:00
struct timeval *_lastUpdate;
/* whether or not the next delta time will be zero */
bool _nextDeltaTimeZero;
/* projection used */
Projection _projection;
/* window size in points */
Size _winSizeInPoints;
/* content scale factor */
float _contentScaleFactor;
/* This object will be visited after the scene. Useful to hook a notification node */
Node *_notificationNode;
/* Renderer for the Director */
Renderer *_renderer;
/* Console for the director */
Console *_console;
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;
};
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
*/
class DisplayLinkDirector : public Director
{
public:
2013-08-08 16:31:44 +08:00
DisplayLinkDirector()
: _invalid(false)
{}
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
virtual ~DisplayLinkDirector(){}
//
// Overrides
//
2013-08-08 16:31:44 +08:00
virtual void mainLoop() override;
virtual void setAnimationInterval(double value) override;
virtual void startAnimation() override;
virtual void stopAnimation() override;
protected:
bool _invalid;
};
2012-04-18 18:43:45 +08:00
NS_CC_END
#endif // __CCDIRECTOR_H__