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.
|
|
|
|
Copyright (c) 2013-2014 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
|
|
|
/**
|
|
|
|
* @addtogroup base_nodes
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
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;
|
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
|
|
|
|
*/
|
2014-04-02 16:47:23 +08:00
|
|
|
enum class MATRIX_STACK_TYPE
|
|
|
|
{
|
|
|
|
MATRIX_STACK_MODELVIEW,
|
|
|
|
MATRIX_STACK_PROJECTION,
|
|
|
|
MATRIX_STACK_TEXTURE
|
|
|
|
};
|
|
|
|
|
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:
|
2013-12-21 16:56:28 +08:00
|
|
|
static const char *EVENT_PROJECTION_CHANGED;
|
|
|
|
static const char* EVENT_AFTER_UPDATE;
|
|
|
|
static const char* EVENT_AFTER_VISIT;
|
|
|
|
static const char* EVENT_AFTER_DRAW;
|
|
|
|
|
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
|
|
|
|
*/
|
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
|
|
|
|
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
|
|
|
|
2014-01-31 07:40:56 +08:00
|
|
|
/** Get the GLView, where everything is rendered
|
2013-09-13 11:41:20 +08:00
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2014-01-31 07:40:56 +08:00
|
|
|
inline GLView* getOpenGLView() { return _openGLView; }
|
|
|
|
void setOpenGLView(GLView *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
|
|
|
|
*/
|
2014-01-11 09:11:14 +08:00
|
|
|
Node* getNotificationNode() const { return _notificationNode; }
|
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
|
|
|
|
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
|
2014-01-31 07:40:56 +08:00
|
|
|
* 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
|
|
|
|
|
|
|
/** returns visible origin 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
|
|
|
|
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
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 convertToGL(const Vec2& 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
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 convertToUI(const Vec2& point);
|
2010-07-12 17:03:27 +08:00
|
|
|
|
2014-08-30 03:54:24 +08:00
|
|
|
/// FIXME: 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();
|
2014-12-28 11:55:06 +08:00
|
|
|
|
|
|
|
/** Restart the director
|
|
|
|
*/
|
|
|
|
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.
|
|
|
|
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);
|
2014-12-24 11:53:38 +08:00
|
|
|
|
|
|
|
/** set clear values for the color buffers, value range of each element is [0.0, 1.0] */
|
|
|
|
void setClearColor(const Color4F& clearColor);
|
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);
|
2014-01-11 09:11:14 +08:00
|
|
|
float getContentScaleFactor() const { return _contentScaleFactor; }
|
2010-12-29 18:01:37 +08:00
|
|
|
|
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
|
|
|
|
*/
|
2014-01-11 09:11:14 +08:00
|
|
|
Scheduler* getScheduler() const { return _scheduler; }
|
2013-07-23 15:19:26 +08:00
|
|
|
|
|
|
|
/** 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
|
|
|
|
*/
|
2014-01-11 09:11:14 +08:00
|
|
|
ActionManager* getActionManager() const { return _actionManager; }
|
2013-07-23 15:19:26 +08:00
|
|
|
|
|
|
|
/** 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
|
|
|
|
*/
|
2014-01-11 09:11:14 +08:00
|
|
|
EventDispatcher* getEventDispatcher() const { return _eventDispatcher; }
|
2013-10-26 15:04:01 +08:00
|
|
|
|
|
|
|
/** Sets the EventDispatcher associated with this director
|
|
|
|
@since v3.0
|
|
|
|
*/
|
|
|
|
void setEventDispatcher(EventDispatcher* dispatcher);
|
2013-12-18 09:50:17 +08:00
|
|
|
|
|
|
|
/** Returns the Renderer
|
|
|
|
@since v3.0
|
|
|
|
*/
|
2014-01-11 09:11:14 +08:00
|
|
|
Renderer* getRenderer() const { return _renderer; }
|
|
|
|
|
|
|
|
/** Returns the Console
|
|
|
|
@since v3.0
|
|
|
|
*/
|
|
|
|
Console* getConsole() const { return _console; }
|
2013-12-18 09:50:17 +08:00
|
|
|
|
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
|
|
|
|
2014-11-05 08:46:14 +08:00
|
|
|
void pushMatrix(MATRIX_STACK_TYPE type);
|
|
|
|
void popMatrix(MATRIX_STACK_TYPE type);
|
|
|
|
void loadIdentityMatrix(MATRIX_STACK_TYPE type);
|
|
|
|
void loadMatrix(MATRIX_STACK_TYPE type, const Mat4& mat);
|
|
|
|
void multiplyMatrix(MATRIX_STACK_TYPE type, const Mat4& mat);
|
|
|
|
const Mat4& getMatrix(MATRIX_STACK_TYPE type);
|
|
|
|
void resetMatrixStack();
|
|
|
|
|
2010-07-12 17:03:27 +08:00
|
|
|
protected:
|
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
|
|
|
|
2014-12-24 11:53:38 +08:00
|
|
|
/* clear color set outside be used in setGLDefaultValues() */
|
|
|
|
Color4F _clearColor;
|
|
|
|
|
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;
|
2014-01-11 09:11:14 +08:00
|
|
|
|
|
|
|
/* Console for the director */
|
|
|
|
Console *_console;
|
2014-03-22 20:55:08 +08:00
|
|
|
|
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
|
|
|
};
|
|
|
|
|
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-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__
|