Merge branch 'develop' of git://github.com/cocos2d/cocos2d-x into data-refactor

Conflicts:
	cocos/scripting/lua/bindings/lua_cocos2dx_manual.cpp
This commit is contained in:
James Chen 2013-12-23 11:57:29 +08:00
commit aeafe06d7f
41 changed files with 4171 additions and 555 deletions

View File

@ -12,18 +12,6 @@ LUA_SAMPLES = ['hellolua', 'testlua']
JSB_SAMPLES = ['cocosdragon', 'crystalcraze', 'moonwarriors', 'testjavascript', 'watermelonwithme']
ALL_SAMPLES = CPP_SAMPLES + LUA_SAMPLES + JSB_SAMPLES
def usage():
print """%s [-n ndk-build-parameter] [-p android-platform] [-b build-mode] target.
Valid android-platform are:[10|11|12|13|14|15|16|17]
Valid build-mode are:[debug|release]
Valid targets are: [hellocpp|testcpp|simplegame|assetsmanager|hellolua|testlua|cocosdragon
|crystalcraze|moonwarriors|testjavascript|watermelonwithme]
You can use [all|cpp|lua|jsb], to build all, or all the C++, or all the Lua, or all the JavaScript samples respectevely.""" % sys.argv[0]
def check_environment_variables():
''' Checking the environment NDK_ROOT, which will be used for building
'''
@ -253,14 +241,23 @@ def build_samples(target,ndk_build_param,android_platform,build_mode):
if __name__ == '__main__':
#parse the params
parser = OptionParser()
parser.add_option("-n", "--ndk", dest="ndk_build_param", help='parameter for ndk-build')
parser.add_option("-p", "--platform", dest="android_platform", help='parameter for android-update')
parser.add_option("-b", "--build", dest="build_mode", help='the build mode for java project,debug or release.Get more information,please refer to http://developer.android.com/tools/building/building-cmdline.html')
usage = """usage: %prog [options] target
Valid targets are: [hellocpp|testcpp|simplegame|assetsmanager|hellolua|testlua|cocosdragon|crystalcraze|moonwarriors|testjavascript|watermelonwithme]
You can use [all|cpp|lua|jsb], to build all, or all the C++, or all the Lua, or all the JavaScript samples respectevely."""
parser = OptionParser(usage=usage)
parser.add_option("-n", "--ndk", dest="ndk_build_param",
help='parameter for ndk-build')
parser.add_option("-p", "--platform", dest="android_platform",
help='parameter for android-update.Without the parameter,the script just build dynamic library for project. Valid android-platform are:[10|11|12|13|14|15|16|17|18|19]')
parser.add_option("-b", "--build", dest="build_mode",
help='the build mode for java project,debug[default] or release.Get more information,please refer to http://developer.android.com/tools/building/building-cmdline.html')
(opts, args) = parser.parse_args()
if len(args) == 0:
usage()
parser.print_help()
else:
try:
build_samples(args, opts.ndk_build_param,opts.android_platform,opts.build_mode)

View File

@ -1 +1 @@
86be6483df53eae247ab9679cc73e093e9b08f44
1df2ba5492ecdbe0c160d2429733c1371b35b21a

View File

@ -24,7 +24,6 @@ CCActionTween.cpp \
CCAnimation.cpp \
CCAnimationCache.cpp \
CCAtlasNode.cpp \
CCCamera.cpp \
ccCArray.cpp \
CCClippingNode.cpp \
CCComponent.cpp \

View File

@ -1,5 +1,5 @@
/****************************************************************************
Copyright (c) 2010-2012 cocos2d-x.org
Copyright (c) 2010-2013 cocos2d-x.org
Copyright (c) 2008-2010 Ricardo Quesada
Copyright (c) 2011 Zynga Inc.
@ -26,7 +26,6 @@ THE SOFTWARE.
#include "CCActionCamera.h"
#include "CCNode.h"
#include "CCCamera.h"
#include "CCStdC.h"
NS_CC_BEGIN
@ -36,11 +35,6 @@ NS_CC_BEGIN
void ActionCamera::startWithTarget(Node *target)
{
ActionInterval::startWithTarget(target);
Camera *camera = target->getCamera();
camera->getCenter(&_centerXOrig, &_centerYOrig, &_centerZOrig);
camera->getEye(&_eyeXOrig, &_eyeYOrig, &_eyeZOrig);
camera->getUp(&_upXOrig, &_upYOrig, &_upZOrig);
}
ActionCamera* ActionCamera::clone() const
@ -56,6 +50,88 @@ ActionCamera * ActionCamera::reverse() const
// FIXME: This conversion isn't safe.
return (ActionCamera*)ReverseTime::create(const_cast<ActionCamera*>(this));
}
void ActionCamera::restore()
{
_eyeX = _eyeY = 0.0f;
_eyeZ = FLT_EPSILON;
_centerX = _centerY = _centerZ = 0.0f;
_upX = 0.0f;
_upY = 1.0f;
_upZ = 0.0f;
}
void ActionCamera::setEye(float x, float y, float z)
{
_eyeX = x;
_eyeY = y;
_eyeZ = z;
updateTransform();
}
void ActionCamera::setCenter(float centerX, float centerY, float centerZ)
{
_centerX = centerX;
_centerY = centerY;
_centerZ = centerZ;
updateTransform();
}
void ActionCamera::setUp(float upX, float upY, float upZ)
{
_upX = upX;
_upY = upY;
_upZ = upZ;
updateTransform();
}
void ActionCamera::updateTransform()
{
kmVec3 eye, center, up;
kmVec3Fill(&eye, _eyeX, _eyeY , _eyeZ);
kmVec3Fill(&center, _centerX, _centerY, _centerZ);
kmVec3Fill(&up, _upX, _upY, _upZ);
kmMat4 lookupMatrix;
kmMat4LookAt(&lookupMatrix, &eye, &center, &up);
Point anchorPoint = _target->getAnchorPointInPoints();
bool needsTranslation = !anchorPoint.equals(Point::ZERO);
kmMat4 mv;
kmMat4Identity(&mv);
if(needsTranslation) {
kmMat4 t;
kmMat4Translation(&t, anchorPoint.x, anchorPoint.y, 0);
kmMat4Multiply(&mv, &mv, &t);
}
kmMat4Multiply(&mv, &mv, &lookupMatrix);
if(needsTranslation) {
kmMat4 t;
kmMat4Translation(&t, -anchorPoint.x, -anchorPoint.y, 0);
kmMat4Multiply(&mv, &mv, &t);
}
// XXX FIXME TODO
// Using the AdditionalTransform is a complete hack.
// This should be done by multipliying the lookup-Matrix with the Node's MV matrix
// And then setting the result as the new MV matrix
// But that operation needs to be done after all the 'updates'.
// So the Director should emit an 'director_after_update' event.
// And this object should listen to it
_target->setAdditionalTransform(mv);
}
//
// OrbitCamera
//
@ -101,7 +177,8 @@ bool OrbitCamera::initWithDuration(float t, float radius, float deltaRadius, flo
void OrbitCamera::startWithTarget(Node *target)
{
ActionInterval::startWithTarget(target);
ActionCamera::startWithTarget(target);
float r, zenith, azimuth;
this->sphericalRadius(&r, &zenith, &azimuth);
if( isnan(_radius) )
@ -117,30 +194,25 @@ void OrbitCamera::startWithTarget(Node *target)
void OrbitCamera::update(float dt)
{
float r = (_radius + _deltaRadius * dt) * Camera::getZEye();
float r = (_radius + _deltaRadius * dt) * FLT_EPSILON;
float za = _radZ + _radDeltaZ * dt;
float xa = _radX + _radDeltaX * dt;
float i = sinf(za) * cosf(xa) * r + _centerXOrig;
float j = sinf(za) * sinf(xa) * r + _centerYOrig;
float k = cosf(za) * r + _centerZOrig;
float i = sinf(za) * cosf(xa) * r + _centerX;
float j = sinf(za) * sinf(xa) * r + _centerY;
float k = cosf(za) * r + _centerZ;
_target->getCamera()->setEye(i,j,k);
setEye(i,j,k);
}
void OrbitCamera::sphericalRadius(float *newRadius, float *zenith, float *azimuth)
{
float ex, ey, ez, cx, cy, cz, x, y, z;
float r; // radius
float s;
Camera* camera = _target->getCamera();
camera->getEye(&ex, &ey, &ez);
camera->getCenter(&cx, &cy, &cz);
x = ex-cx;
y = ey-cy;
z = ez-cz;
float x = _eyeX - _centerX;
float y = _eyeY - _centerY;
float z = _eyeZ - _centerZ;
r = sqrtf( powf(x,2) + powf(y,2) + powf(z,2));
s = sqrtf( powf(x,2) + powf(y,2));
@ -155,7 +227,7 @@ void OrbitCamera::sphericalRadius(float *newRadius, float *zenith, float *azimut
else
*azimuth = asinf(y/s);
*newRadius = r / Camera::getZEye();
*newRadius = r / FLT_EPSILON;
}
NS_CC_END

View File

@ -27,6 +27,7 @@ THE SOFTWARE.
#define __CCCAMERA_ACTION_H__
#include "CCActionInterval.h"
#include "kazmath/kazmath.h"
NS_CC_BEGIN
@ -48,15 +49,15 @@ public:
* @js ctor
*/
ActionCamera()
:_centerXOrig(0)
,_centerYOrig(0)
,_centerZOrig(0)
,_eyeXOrig(0)
,_eyeYOrig(0)
,_eyeZOrig(0)
,_upXOrig(0)
,_upYOrig(0)
,_upZOrig(0)
:_centerX(0)
,_centerY(0)
,_centerZ(0)
,_eyeX(0)
,_eyeY(0)
,_eyeZ(FLT_EPSILON)
,_upX(0)
,_upY(1)
,_upZ(0)
{}
/**
* @js NA
@ -70,17 +71,22 @@ public:
virtual ActionCamera *clone() const override;
protected:
float _centerXOrig;
float _centerYOrig;
float _centerZOrig;
float _eyeXOrig;
float _eyeYOrig;
float _eyeZOrig;
void restore();
void setEye(float x, float y, float z);
void setCenter(float x, float y, float z);
void setUp(float x, float y, float z);
void updateTransform();
float _upXOrig;
float _upYOrig;
float _upZOrig;
float _centerX;
float _centerY;
float _centerZ;
float _eyeX;
float _eyeY;
float _eyeZ;
float _upX;
float _upY;
float _upZ;
};
/**
@ -112,7 +118,7 @@ public:
* @js NA
* @lua NA
*/
~OrbitCamera(){}
virtual ~OrbitCamera(){}
/** initializes a OrbitCamera action with radius, delta-radius, z, deltaZ, x, deltaX */
bool initWithDuration(float t, float radius, float deltaRadius, float angleZ, float deltaAngleZ, float angleX, float deltaAngleX);

View File

@ -1,144 +0,0 @@
/****************************************************************************
Copyright (c) 2010-2012 cocos2d-x.org
Copyright (c) 2008-2010 Ricardo Quesada
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.
****************************************************************************/
#include "CCCamera.h"
#include "CCString.h"
#include "CCGL.h"
#include "CCDrawingPrimitives.h"
#include "CCDirector.h"
#include "kazmath/GL/matrix.h"
using namespace std;
NS_CC_BEGIN
Camera::Camera(void)
{
init();
}
Camera::~Camera(void)
{
}
std::string Camera::getDescription() const
{
return String::createWithFormat("<Camera | center = (%.2f,%.2f,%.2f)>", _centerX, _centerY, _centerZ)->getCString();
}
void Camera::init(void)
{
restore();
}
void Camera::restore(void)
{
_eyeX = _eyeY = 0.0f;
_eyeZ = getZEye();
_centerX = _centerY = _centerZ = 0.0f;
_upX = 0.0f;
_upY = 1.0f;
_upZ = 0.0f;
kmMat4Identity(&_lookupMatrix);
_dirty = false;
}
void Camera::locate(void)
{
if (_dirty)
{
kmVec3 eye, center, up;
kmVec3Fill(&eye, _eyeX, _eyeY , _eyeZ);
kmVec3Fill(&center, _centerX, _centerY, _centerZ);
kmVec3Fill(&up, _upX, _upY, _upZ);
kmMat4LookAt(&_lookupMatrix, &eye, &center, &up);
_dirty = false;
}
kmGLMultMatrix(&_lookupMatrix);
}
float Camera::getZEye(void)
{
return FLT_EPSILON;
}
void Camera::setEye(float eyeX, float eyeY, float eyeZ)
{
_eyeX = eyeX;
_eyeY = eyeY;
_eyeZ = eyeZ;
_dirty = true;
}
void Camera::setCenter(float centerX, float centerY, float centerZ)
{
_centerX = centerX;
_centerY = centerY;
_centerZ = centerZ;
_dirty = true;
}
void Camera::setUp(float upX, float upY, float upZ)
{
_upX = upX;
_upY = upY;
_upZ = upZ;
_dirty = true;
}
void Camera::getEye(float *eyeX, float *eyeY, float *eyeZ) const
{
*eyeX = _eyeX;
*eyeY = _eyeY;
*eyeZ = _eyeZ;
}
void Camera::getCenter(float *centerX, float *centerY, float *centerZ) const
{
*centerX = _centerX;
*centerY = _centerY;
*centerZ = _centerZ;
}
void Camera::getUp(float *upX, float *upY, float *upZ) const
{
*upX = _upX;
*upY = _upY;
*upZ = _upZ;
}
NS_CC_END

View File

@ -1,186 +0,0 @@
/****************************************************************************
Copyright (c) 2010-2012 cocos2d-x.org
Copyright (c) 2008-2010 Ricardo Quesada
Copyright (c) 2011 Zynga 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 __COCOS2DX_CAMERA_H__
#define __COCOS2DX_CAMERA_H__
#include <string>
#include "CCObject.h"
#include "ccMacros.h"
#include "kazmath/mat4.h"
NS_CC_BEGIN
/**
* @addtogroup base_nodes
* @{
*/
/**
A Camera is used in every Node.
Useful to look at the object from different views.
The OpenGL gluLookAt() function is used to locate the
camera.
If the object is transformed by any of the scale, rotation or
position attributes, then they will override the camera.
IMPORTANT: Either your use the camera or the rotation/scale/position properties. You can't use both.
World coordinates won't work if you use the camera.
Limitations:
- Some nodes, like ParallaxNode, Particle uses world node coordinates, and they won't work properly if you move them (or any of their ancestors)
using the camera.
- It doesn't work on batched nodes like Sprite objects when they are parented to a SpriteBatchNode object.
- It is recommended to use it ONLY if you are going to create 3D effects. For 2D effects, use the action Follow or position/scale/rotate.
*/
class CC_DLL Camera : public Object
{
public:
/** returns the Z eye */
static float getZEye();
/**
* @js ctor
*/
Camera();
/**
* @js NA
* @lua NA
*/
~Camera();
void init();
/**
* @js NA
* @lua NA
*/
virtual std::string getDescription() const;
/** sets the dirty value */
inline void setDirty(bool value) { _dirty = value; }
/** get the dirty value */
inline bool isDirty() const { return _dirty; }
/** sets the camera in the default position */
void restore();
/** Sets the camera using gluLookAt using its eye, center and up_vector */
void locate();
/** sets the eye values in points */
void setEye(float eyeX, float eyeY, float eyeZ);
/**
@deprecated. Use setEye() instead
* @js NA
* @lua NA
*/
CC_DEPRECATED_ATTRIBUTE void setEyeXYZ(float eyeX, float eyeY, float eyeZ){ setEye(eyeX, eyeY, eyeZ);}
/** sets the center values in points */
void setCenter(float centerX, float centerY, float centerZ);
/**
@deprecated. Use setCenter() instead
* @js NA
* @lua NA
*/
CC_DEPRECATED_ATTRIBUTE void setCenterXYZ(float centerX, float centerY, float centerZ){ setCenter(centerX,centerY,centerZ);}
/** sets the up values */
void setUp(float upX, float upY, float upZ);
/**
@deprecated. Use setUp() instead
* @js NA
* @lua NA
*/
CC_DEPRECATED_ATTRIBUTE void setUpXYZ(float upX, float upY, float upZ){ setUp(upX,upY,upZ); }
/** get the eye vector values in points
* @code
* when this function bound to js or lua,the input params are changed
* in js: var getEye()
* in lua:local getEye()
* @endcode
*/
void getEye(float *eyeX, float *eyeY, float *eyeZ) const;
/**
@deprecated. Use getEye() instead
* @js NA
* @lua NA
*/
CC_DEPRECATED_ATTRIBUTE void getEyeXYZ(float *eyeX, float *eyeY, float *eyeZ) const { getEye(eyeX, eyeY, eyeZ); }
/** get the center vector values int points
* when this function bound to js or lua,the input params are changed
* in js: var getCenter()
* in lua:local getCenter()
*/
void getCenter(float *centerX, float *centerY, float *centerZ) const;
/**
@deprecated. Use getCenter() instead
* @js NA
* @lua NA
*/
CC_DEPRECATED_ATTRIBUTE void getCenterXYZ(float *centerX, float *centerY, float *centerZ) const{ getCenter(centerX,centerY,centerZ); }
/** get the up vector values
* when this function bound to js or lua,the input params are changed
* in js: var getUp()
* in lua:local getUp()
*/
void getUp(float *upX, float *upY, float *upZ) const;
/**
@deprecated. Use getUp() instead
* @js NA
* @lua NA
*/
CC_DEPRECATED_ATTRIBUTE void getUpXYZ(float *upX, float *upY, float *upZ) const{ getUp(upX, upY, upZ); }
protected:
float _eyeX;
float _eyeY;
float _eyeZ;
float _centerX;
float _centerY;
float _centerZ;
float _upX;
float _upY;
float _upZ;
bool _dirty;
kmMat4 _lookupMatrix;
private:
DISALLOW_COPY_AND_ASSIGN(Camera);
};
// end of base_node group
/// @}
NS_CC_END
#endif // __COCOS2DX_CAMERA_H__

View File

@ -1,5 +1,5 @@
/****************************************************************************
Copyright (c) 2010-2012 cocos2d-x.org
Copyright (c) 2010-2013 cocos2d-x.org
Copyright (c) 2008-2010 Ricardo Quesada
Copyright (c) 2011 Zynga Inc.
@ -48,7 +48,6 @@ THE SOFTWARE.
#include "CCActionManager.h"
#include "CCAnimationCache.h"
#include "CCTouch.h"
#include "CCEventDispatcher.h"
#include "CCUserDefault.h"
#include "ccGLStateCache.h"
#include "CCShaderCache.h"
@ -59,6 +58,7 @@ THE SOFTWARE.
#include "CCEGLView.h"
#include "CCConfiguration.h"
#include "CCEventDispatcher.h"
#include "CCEventCustom.h"
#include "CCFontFreeType.h"
#include "CCRenderer.h"
#include "renderer/CCFrustum.h"
@ -84,6 +84,11 @@ static DisplayLinkDirector *s_SharedDirector = nullptr;
#define kDefaultFPS 60 // 60 frames per second
extern const char* cocos2dVersion(void);
const char *Director::EVENT_PROJECTION_CHANGED = "director_projection_changed";
const char *Director::EVENT_AFTER_DRAW = "director_after_draw";
const char *Director::EVENT_AFTER_VISIT = "director_after_visit";
const char *Director::EVENT_AFTER_UPDATE = "director_after_udpate";
Director* Director::getInstance()
{
if (!s_SharedDirector)
@ -95,9 +100,8 @@ Director* Director::getInstance()
return s_SharedDirector;
}
Director::Director(void)
Director::Director()
{
}
bool Director::init(void)
@ -146,6 +150,16 @@ bool Director::init(void)
_scheduler->scheduleUpdateForTarget(_actionManager, Scheduler::PRIORITY_SYSTEM, false);
_eventDispatcher = new EventDispatcher();
_eventAfterDraw = new EventCustom(EVENT_AFTER_DRAW);
_eventAfterDraw->setUserData(this);
_eventAfterVisit = new EventCustom(EVENT_AFTER_VISIT);
_eventAfterVisit->setUserData(this);
_eventAfterUpdate = new EventCustom(EVENT_AFTER_UPDATE);
_eventAfterUpdate->setUserData(this);
_eventProjectionChanged = new EventCustom(EVENT_PROJECTION_CHANGED);
_eventProjectionChanged->setUserData(this);
//init TextureCache
initTextureCache();
@ -172,6 +186,11 @@ Director::~Director(void)
CC_SAFE_RELEASE(_actionManager);
CC_SAFE_RELEASE(_eventDispatcher);
delete _eventAfterUpdate;
delete _eventAfterDraw;
delete _eventAfterVisit;
delete _eventProjectionChanged;
delete _renderer;
// pop the autorelease pool
@ -252,6 +271,7 @@ void Director::drawScene()
if (! _paused)
{
_scheduler->update(_deltaTime);
_eventDispatcher->dispatchEvent(_eventAfterUpdate);
}
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
@ -279,6 +299,7 @@ void Director::drawScene()
if (_runningScene)
{
_runningScene->visit();
_eventDispatcher->dispatchEvent(_eventAfterVisit);
}
// draw the notifications node
@ -293,6 +314,7 @@ void Director::drawScene()
}
_renderer->render();
_eventDispatcher->dispatchEvent(_eventAfterDraw);
kmGLPopMatrix();
@ -473,6 +495,8 @@ void Director::setProjection(Projection projection)
_projection = projection;
GL::setProjectionMatrixDirty();
_eventDispatcher->dispatchEvent(_eventProjectionChanged);
}
void Director::purgeCachedData(void)

View File

@ -54,6 +54,8 @@ class Node;
class Scheduler;
class ActionManager;
class EventDispatcher;
class EventCustom;
class EventListenerCustom;
class TextureCache;
class Frustum;
class Renderer;
@ -81,6 +83,12 @@ and when to execute the Scenes.
class CC_DLL Director : public Object
{
public:
static const char *EVENT_PROJECTION_CHANGED;
static const char* EVENT_AFTER_UPDATE;
static const char* EVENT_AFTER_VISIT;
static const char* EVENT_AFTER_DRAW;
/** @typedef ccDirectorProjection
Possible OpenGL projections used by director
*/
@ -414,6 +422,7 @@ protected:
@since v3.0
*/
EventDispatcher* _eventDispatcher;
EventCustom *_eventProjectionChanged, *_eventAfterDraw, *_eventAfterVisit, *_eventAfterUpdate;
/* delta time since last tick to main loop */
float _deltaTime;

View File

@ -29,6 +29,7 @@
#include "CCEventListenerAcceleration.h"
#include "CCEventListenerMouse.h"
#include "CCEventListenerKeyboard.h"
#include "CCEventListenerCustom.h"
#include "CCNode.h"
#include "CCDirector.h"
@ -338,6 +339,8 @@ void EventDispatcher::addEventListener(EventListener* listener)
{
_toAddedListeners.push_back(listener);
}
listener->retain();
}
void EventDispatcher::addEventListenerWithSceneGraphPriority(EventListener* listener, Node* node)
@ -352,7 +355,6 @@ void EventDispatcher::addEventListenerWithSceneGraphPriority(EventListener* list
listener->setFixedPriority(0);
listener->setRegistered(true);
listener->retain();
addEventListener(listener);
associateNodeAndEventListener(node, listener);
@ -376,12 +378,17 @@ void EventDispatcher::addEventListenerWithFixedPriority(EventListener* listener,
listener->setFixedPriority(fixedPriority);
listener->setRegistered(true);
listener->setPaused(false);
listener->retain();
addEventListener(listener);
}
EventListenerCustom* EventDispatcher::addCustomEventListener(const std::string &eventName, std::function<void(EventCustom*)> callback)
{
EventListenerCustom *listener = EventListenerCustom::create(eventName, callback);
addEventListenerWithFixedPriority(listener, 1);
return listener;
}
void EventDispatcher::removeEventListener(EventListener* listener)
{
if (listener == nullptr)
@ -581,6 +588,14 @@ void EventDispatcher::dispatchEvent(Event* event)
updateListeners(event);
}
void EventDispatcher::dispatchCustomEvent(const std::string &eventName, void *optionalUserData)
{
EventCustom ev(eventName);
ev.setUserData(optionalUserData);
dispatchEvent(&ev);
}
void EventDispatcher::dispatchTouchEvent(EventTouch* event)
{
sortEventListeners(EventListenerTouchOneByOne::LISTENER_ID);

View File

@ -40,6 +40,8 @@ NS_CC_BEGIN
class Event;
class EventTouch;
class Node;
class EventCustom;
class EventListenerCustom;
/**
This class manages event listener subscriptions
@ -69,17 +71,23 @@ public:
*/
void addEventListenerWithFixedPriority(EventListener* listener, int fixedPriority);
/** Remove a listener
/** Adds a Custom event listener.
It will use a fixed priority of 1.
@return the generated event. Needed in order to remove the event from the dispather
*/
EventListenerCustom* addCustomEventListener(const std::string &eventName, std::function<void(EventCustom*)> callback);
/** Remove a listener
* @param listener The specified event listener which needs to be removed.
*/
void removeEventListener(EventListener* listener);
/** Removes all listeners with the same event listener type */
void removeEventListeners(EventListener::Type listenerType);
/** Removes all custom listeners with the same event name */
void removeCustomEventListeners(const std::string& customEventName);
/** Removes all listeners */
void removeAllEventListeners();
@ -97,13 +105,16 @@ public:
* event dispatcher list.
*/
void dispatchEvent(Event* event);
/** Dispatches a Custom Event with a event name an optional user data */
void dispatchCustomEvent(const std::string &eventName, void *optionalUserData);
/** Constructor of EventDispatcher */
EventDispatcher();
/** Destructor of EventDispatcher */
~EventDispatcher();
private:
protected:
friend class Node;
/** Sets the dirty flag for a node. */
@ -198,7 +209,6 @@ private:
/** Walks though scene graph to get the draw order for each node, it's called before sorting event listener with scene graph priority */
void visitTarget(Node* node);
private:
/** Listeners map */
std::unordered_map<EventListener::ListenerID, EventListenerVector*> _listeners;

View File

@ -216,17 +216,17 @@ void GridBase::afterDraw(cocos2d::Node *target)
Director *director = Director::getInstance();
director->setProjection(_directorProjection);
if (target->getCamera()->isDirty())
{
Point offset = target->getAnchorPointInPoints();
//
// XXX: Camera should be applied in the AnchorPoint
//
kmGLTranslatef(offset.x, offset.y, 0);
target->getCamera()->locate();
kmGLTranslatef(-offset.x, -offset.y, 0);
}
// if (target->getCamera()->isDirty())
// {
// Point offset = target->getAnchorPointInPoints();
//
// //
// // XXX: Camera should be applied in the AnchorPoint
// //
// kmGLTranslatef(offset.x, offset.y, 0);
// target->getCamera()->locate();
// kmGLTranslatef(-offset.x, -offset.y, 0);
// }
GL::bindTexture2D(_texture->getName());

View File

@ -27,7 +27,6 @@ THE SOFTWARE.
#include "CCObject.h"
#include "CCNode.h"
#include "CCCamera.h"
#include "ccTypes.h"
#include "CCTexture2D.h"
#include "CCDirector.h"

View File

@ -30,6 +30,8 @@ THE SOFTWARE.
#include "ccMacros.h"
#include "CCDirector.h"
#include "CCVertex.h"
#include "CCCustomCommand.h"
#include "CCRenderer.h"
NS_CC_BEGIN
@ -322,12 +324,10 @@ void MotionStreak::reset()
_nuPoints = 0;
}
void MotionStreak::draw()
{
if(_nuPoints <= 1)
return;
CC_NODE_DRAW_SETUP();
void MotionStreak::onDraw()
{
getShaderProgram()->use();
getShaderProgram()->setUniformsForBuiltins(_cachedMV);
GL::enableVertexAttribs(GL::VERTEX_ATTRIB_FLAG_POS_COLOR_TEX );
GL::blendFunc( _blendFunc.src, _blendFunc.dst );
@ -351,8 +351,18 @@ void MotionStreak::draw()
#endif // EMSCRIPTEN
glDrawArrays(GL_TRIANGLE_STRIP, 0, (GLsizei)_nuPoints*2);
}
void MotionStreak::draw()
{
if(_nuPoints <= 1)
return;
kmGLGetMatrix(KM_GL_MODELVIEW,&_cachedMV);
CustomCommand* cmd = CustomCommand::getCommandPool().generateCommand();
cmd->init(0,_vertexZ);
cmd->func = CC_CALLBACK_0(MotionStreak::onDraw, this);
Director::getInstance()->getRenderer()->addCommand(cmd);
CC_INCREMENT_GL_DRAWS(1);
}
NS_CC_END

View File

@ -99,6 +99,11 @@ public:
virtual void setOpacityModifyRGB(bool value) override;
virtual bool isOpacityModifyRGB() const override;
protected:
kmMat4 _cachedMV;
//renderer callback
void onDraw();
protected:
/**
* @js ctor

View File

@ -32,7 +32,6 @@ THE SOFTWARE.
#include "CCString.h"
#include "ccCArray.h"
#include "TransformUtils.h"
#include "CCCamera.h"
#include "CCGrid.h"
#include "CCDirector.h"
#include "CCScheduler.h"
@ -106,7 +105,6 @@ Node::Node(void)
, _additionalTransformDirty(false)
, _transformDirty(true)
, _inverseDirty(true)
, _camera(nullptr)
// children (lazy allocs)
// lazy alloc
, _ZOrder(0)
@ -168,8 +166,6 @@ Node::~Node()
CC_SAFE_RELEASE(_eventDispatcher);
// attributes
CC_SAFE_RELEASE(_camera);
CC_SAFE_RELEASE(_shaderProgram);
CC_SAFE_RELEASE(_userObject);
@ -402,17 +398,6 @@ ssize_t Node::getChildrenCount() const
return _children.size();
}
/// camera getter: lazy alloc
Camera* Node::getCamera()
{
if (!_camera)
{
_camera = new Camera();
}
return _camera;
}
/// isVisible getter
bool Node::isVisible() const
{
@ -533,6 +518,13 @@ void Node::setShaderProgram(GLProgram *pShaderProgram)
_shaderProgram = pShaderProgram;
}
Scene* Node::getScene()
{
if(!_parent)
return nullptr;
return _parent->getScene();
}
Rect Node::getBoundingBox() const
{
Rect rect = Rect(0, 0, _contentSize.width, _contentSize.height);
@ -869,10 +861,8 @@ void Node::transform()
kmGLMultMatrix( &transfrom4x4 );
// saves the MV matrix
kmGLGetMatrix(KM_GL_MODELVIEW, &_modelViewTransform);
}
void Node::onEnter()
{
_isTransitionFinished = false;
@ -1209,6 +1199,12 @@ const kmMat4& Node::getNodeToParentTransform() const
return _transform;
}
void Node::setNodeToParentTransform(const kmMat4& transform)
{
_transform = transform;
_transformDirty = false;
}
void Node::setAdditionalTransform(const AffineTransform& additionalTransform)
{
CGAffineToGL(additionalTransform, _additionalTransform.mat);

View File

@ -43,7 +43,6 @@
NS_CC_BEGIN
class Camera;
class GridBase;
class Point;
class Touch;
@ -54,6 +53,7 @@ class ActionManager;
class Component;
class ComponentContainer;
class EventDispatcher;
class Scene;
#ifdef CC_USE_PHYSICS
class PhysicsBody;
#endif
@ -98,7 +98,6 @@ class EventListener;
- position
- scale (x, y)
- rotation (in degrees, clockwise)
- Camera (an interface to gluLookAt )
- GridBase (to do mesh transformations)
- anchor point
- size
@ -120,18 +119,14 @@ class EventListener;
-# The node will be translated (position)
-# The node will be rotated (rotation)
-# The node will be scaled (scale)
-# The node will be moved according to the camera values (camera)
Order in transformations with grid enabled
-# The node will be translated (position)
-# The node will be rotated (rotation)
-# The node will be scaled (scale)
-# The grid will capture the screen
-# The node will be moved according to the camera values (camera)
-# The grid will render the captured screen
Camera:
- Each node has a camera. By default it points to the center of the Node.
*/
class CC_DLL Node : public Object
@ -834,19 +829,6 @@ public:
/// @} end of Shader Program
/**
* Returns a camera object that lets you move the node using a gluLookAt
*
@code
Camera* camera = node->getCamera();
camera->setEye(0, 0, 415/2);
camera->setCenter(0, 0, 0);
@endcode
*
* @return A Camera object that lets you move the node using a gluLookAt
*/
virtual Camera* getCamera();
/**
* Returns whether or not the node accepts event callbacks.
*
@ -929,6 +911,11 @@ public:
*/
virtual void visit();
/** Returns the Scene that contains the Node.
It returns `nullptr` if the node doesn't belong to any Scene.
This function recursively calls parent->getScene() until parent is a Scene object. The results are not cached. It is that the user caches the results in case this functions is being used inside a loop.
*/
virtual Scene* getScene();
/**
* Returns a "local" axis aligned bounding box of the node.
@ -1202,6 +1189,11 @@ public:
virtual const kmMat4& getNodeToParentTransform() const;
virtual AffineTransform getNodeToParentAffineTransform() const;
/**
* Sets the Transformation matrix manually.
*/
virtual void setNodeToParentTransform(const kmMat4& transform);
/** @deprecated use getNodeToParentTransform() instead */
CC_DEPRECATED_ATTRIBUTE inline virtual AffineTransform nodeToParentTransform() const { return getNodeToParentAffineTransform(); }
@ -1437,8 +1429,6 @@ protected:
mutable bool _transformDirty; ///< transform dirty flag
mutable bool _inverseDirty; ///< inverse transform dirty flag
Camera *_camera; ///< a camera
int _ZOrder; ///< z-order value that affects the draw order
Vector<Node*> _children; ///< array of children nodes

View File

@ -1,3 +1,26 @@
/****************************************************************************
Copyright (c) 2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "CCNodeGrid.h"
#include "CCGrid.h"
@ -43,11 +66,6 @@ NodeGrid::~NodeGrid()
CC_SAFE_RELEASE(_gridTarget);
}
bool NodeGrid::init()
{
return Node::init();
}
void NodeGrid::onGridBeginDraw()
{
if (_nodeGrid && _nodeGrid->isActive())
@ -77,7 +95,6 @@ void NodeGrid::visit()
GroupCommand* groupCommand = GroupCommand::getCommandPool().generateCommand();
groupCommand->init(0,_vertexZ);
renderer->addCommand(groupCommand);
renderer->pushGroup(groupCommand->getRenderQueueID());
kmGLPushMatrix();
@ -87,9 +104,7 @@ void NodeGrid::visit()
beforeProjectionType = Director::getInstance()->getProjection();
_nodeGrid->set2DProjection();
}
kmGLGetMatrix(KM_GL_MODELVIEW, &_cachedMVmat);
CustomCommand* gridBeginCmd = CustomCommand::getCommandPool().generateCommand();
gridBeginCmd->init(0,_vertexZ);
gridBeginCmd->func = CC_CALLBACK_0(NodeGrid::onGridBeginDraw, this);
@ -120,10 +135,9 @@ void NodeGrid::visit()
// self draw,currently we have nothing to draw on NodeGrid, so there is no need to add render command
this->draw();
// Uses std::for_each to improve performance.
std::for_each(_children.cbegin()+i, _children.cend(), [](Node* node){
node->visit();
});
for(auto it=_children.cbegin()+i; it != _children.cend(); ++it) {
(*it)->visit();
}
}
else
{

View File

@ -1,3 +1,27 @@
/****************************************************************************
Copyright (c) 2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __MISCNODE_CCGRID_NODE_H__
#define __MISCNODE_CCGRID_NODE_H__
@ -26,10 +50,11 @@ public:
*/
void setGrid(GridBase *grid);
virtual bool init();
virtual void visit();
void setTarget(Node *target);
// overrides
virtual void visit() override;
protected:
NodeGrid();
virtual ~NodeGrid();
@ -37,10 +62,11 @@ protected:
void onGridBeginDraw();
void onGridEndDraw();
protected:
kmMat4 _cachedMVmat;
Node* _gridTarget;
GridBase* _nodeGrid;
private:
CC_DISALLOW_COPY_AND_ASSIGN(NodeGrid);
};
NS_CC_END

View File

@ -83,6 +83,11 @@ std::string Scene::getDescription() const
return StringUtils::format("<Scene | tag = %d>", _tag);
}
Scene* Scene::getScene()
{
return this;
}
#ifdef CC_USE_PHYSICS
Scene *Scene::createWithPhysics()
{

View File

@ -56,6 +56,8 @@ public:
static Scene *createWithPhysics();
#endif
// Overrides
virtual Scene *getScene() override;
#ifdef CC_USE_PHYSICS
public:
@ -76,6 +78,7 @@ protected:
#endif // CC_USE_PHYSICS
protected:
Scene();
virtual ~Scene();

View File

@ -25,7 +25,6 @@ THE SOFTWARE.
****************************************************************************/
#include "CCTransition.h"
#include "CCCamera.h"
#include "CCDirector.h"
#include "CCActionInterval.h"
#include "CCActionInstant.h"
@ -114,22 +113,24 @@ void TransitionScene::draw()
void TransitionScene::finish()
{
// clean up
_inScene->setVisible(true);
_inScene->setPosition(Point(0,0));
_inScene->setScale(1.0f);
_inScene->setRotation(0.0f);
_inScene->getCamera()->restore();
_outScene->setVisible(false);
_outScene->setPosition(Point(0,0));
_outScene->setScale(1.0f);
_outScene->setRotation(0.0f);
_outScene->getCamera()->restore();
kmMat4 identity;
kmMat4Identity(&identity);
// clean up
_inScene->setVisible(true);
_inScene->setPosition(Point(0,0));
_inScene->setScale(1.0f);
_inScene->setRotation(0.0f);
_inScene->setAdditionalTransform(identity);
_outScene->setVisible(false);
_outScene->setPosition(Point(0,0));
_outScene->setScale(1.0f);
_outScene->setRotation(0.0f);
_outScene->setAdditionalTransform(identity);
//[self schedule:@selector(setNewScene:) interval:0];
this->schedule(schedule_selector(TransitionScene::setNewScene), 0);
}
void TransitionScene::setNewScene(float dt)

View File

@ -127,7 +127,6 @@ set(COCOS2D_SRC
ccGLStateCache.cpp
CCShaderCache.cpp
ccShaders.cpp
CCCamera.cpp
CCConfiguration.cpp
CCDirector.cpp
CCScheduler.cpp

View File

@ -254,7 +254,6 @@ THE SOFTWARE.
#include "CCEventListenerCustom.h"
// root
#include "CCCamera.h"
#include "CCConfiguration.h"
#include "CCDirector.h"
#include "CCScheduler.h"

View File

@ -222,7 +222,6 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\win32-specific\gles\prebuilt\*.*" "$(Ou
<ClCompile Include="CCAnimation.cpp" />
<ClCompile Include="CCAnimationCache.cpp" />
<ClCompile Include="CCAtlasNode.cpp" />
<ClCompile Include="CCCamera.cpp" />
<ClCompile Include="ccCArray.cpp" />
<ClCompile Include="CCClippingNode.cpp" />
<ClCompile Include="CCComponent.cpp" />
@ -406,7 +405,6 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\win32-specific\gles\prebuilt\*.*" "$(Ou
<ClInclude Include="CCAnimation.h" />
<ClInclude Include="CCAnimationCache.h" />
<ClInclude Include="CCAtlasNode.h" />
<ClInclude Include="CCCamera.h" />
<ClInclude Include="ccCArray.h" />
<ClInclude Include="CCClippingNode.h" />
<ClInclude Include="CCComponent.h" />

View File

@ -453,7 +453,6 @@
<ClCompile Include="CCParallaxNode.cpp">
<Filter>tilemap_parallax_nodes</Filter>
</ClCompile>
<ClCompile Include="CCCamera.cpp" />
<ClCompile Include="CCConfiguration.cpp" />
<ClCompile Include="CCDeprecated.cpp" />
<ClCompile Include="CCDirector.cpp" />
@ -1051,7 +1050,6 @@
<ClInclude Include="CCParallaxNode.h">
<Filter>tilemap_parallax_nodes</Filter>
</ClInclude>
<ClInclude Include="CCCamera.h" />
<ClInclude Include="CCConfiguration.h" />
<ClInclude Include="CCDirector.h" />
<ClInclude Include="ccFPSImages.h" />

@ -1 +1 @@
Subproject commit aaa97fbd16ff316f929b42ccdc9983f4a86472d8
Subproject commit 0130b23910e0fe7aa27738403c84ee259677a1b8

View File

@ -1 +1 @@
59fe47a7fc5c48bb723eb916921bb2c0e160430b
7ca5b334921bd71783d2c8fb31efc09f8dea8afd

File diff suppressed because it is too large Load Diff

View File

@ -1 +0,0 @@
e9fd4e6fbccdc826ee0232dc2ec0286821d1eb09

View File

@ -328,16 +328,17 @@ void ActionRotationalSkew::onEnter()
this->centerSprites(3);
auto actionTo = RotateTo::create(2, 37.2f, -37.2f);
auto actionTo = RotateTo::create(2, 180, 180);
auto actionToBack = RotateTo::create(2, 0, 0);
auto actionBy = RotateBy::create(2, 0.0f, -90.0f);
auto actionBy2 = RotateBy::create(2, 45.0f, 45.0f);
auto actionBy = RotateBy::create(2, 0.0f, 360);
auto actionByBack = actionBy->reverse();
_tamara->runAction( Sequence::create(actionTo, actionToBack, NULL) );
_grossini->runAction( Sequence::create(actionBy, actionByBack, NULL) );
auto actionBy2 = RotateBy::create(2, 360, 0);
auto actionBy2Back = actionBy2->reverse();
_kathia->runAction( Sequence::create(actionBy2, actionBy2->reverse(), NULL) );
_tamara->runAction( Sequence::create(actionBy, actionByBack, NULL) );
_grossini->runAction( Sequence::create(actionTo, actionToBack, NULL) );
_kathia->runAction( Sequence::create(actionBy2, actionBy2Back, NULL) );
}
std::string ActionRotationalSkew::subtitle() const
@ -1220,25 +1221,26 @@ void ActionOrbit::onEnter()
{
ActionsDemo::onEnter();
Director::getInstance()->setProjection(Director::Projection::_2D);
centerSprites(3);
auto orbit1 = OrbitCamera::create(2,1, 0, 0, 180, 0, 0);
auto action1 = Sequence::create(
auto action1 = Sequence::create(
orbit1,
orbit1->reverse(),
NULL);
nullptr);
auto orbit2 = OrbitCamera::create(2,1, 0, 0, 180, -45, 0);
auto action2 = Sequence::create(
auto action2 = Sequence::create(
orbit2,
orbit2->reverse(),
NULL);
nullptr);
auto orbit3 = OrbitCamera::create(2,1, 0, 0, 180, 90, 0);
auto action3 = Sequence::create(
auto action3 = Sequence::create(
orbit3,
orbit3->reverse(),
NULL);
nullptr);
_kathia->runAction(RepeatForever::create(action1));
_tamara->runAction(RepeatForever::create(action2));

View File

@ -20,7 +20,8 @@ std::function<Layer*()> createFunctions[] =
CL(LabelKeyboardEventTest),
CL(SpriteAccelerationEventTest),
CL(RemoveAndRetainNodeTest),
CL(RemoveListenerAfterAddingTest)
CL(RemoveListenerAfterAddingTest),
CL(DirectorEventTest),
};
unsigned int TEST_CASE_COUNT = sizeof(createFunctions) / sizeof(createFunctions[0]);
@ -745,3 +746,106 @@ std::string RemoveListenerAfterAddingTest::subtitle() const
}
//
//DirectorEventTest
//
void DirectorEventTest::onEnter()
{
EventDispatcherTestDemo::onEnter();
Size s = Director::getInstance()->getWinSize();
_label1 = Label::createWithTTF("Update: 0", "fonts/arial.ttf", 20);
_label1->setPosition(30,s.height/2 + 60);
this->addChild(_label1);
_label2 = Label::createWithTTF("Visit: 0", "fonts/arial.ttf", 20);
_label2->setPosition(30,s.height/2 + 20);
this->addChild(_label2);
_label3 = Label::createWithTTF("Draw: 0", "fonts/arial.ttf", 20);
_label3->setPosition(30,30);
_label3->setPosition(30,s.height/2 - 20);
this->addChild(_label3);
_label4 = Label::createWithTTF("Projection: 0", "fonts/arial.ttf", 20);
_label4->setPosition(30,30);
_label4->setPosition(30,s.height/2 - 60);
this->addChild(_label4);
auto dispatcher = Director::getInstance()->getEventDispatcher();
_event1 = dispatcher->addCustomEventListener(Director::EVENT_AFTER_UPDATE, std::bind(&DirectorEventTest::onEvent1, this, std::placeholders::_1));
_event2 = dispatcher->addCustomEventListener(Director::EVENT_AFTER_VISIT, std::bind(&DirectorEventTest::onEvent2, this, std::placeholders::_1));
_event3 = dispatcher->addCustomEventListener(Director::EVENT_AFTER_DRAW, [&](EventCustom *event) {
char buf[20];
snprintf(buf, sizeof(buf)-1, "Draw: %d", _count3++);
_label3->setString(buf);
});
_event4 = dispatcher->addCustomEventListener(Director::EVENT_PROJECTION_CHANGED, [&](EventCustom *event) {
char buf[20];
snprintf(buf, sizeof(buf)-1, "Projection: %d", _count4++);
_label4->setString(buf);
});
_event1->retain();
_event2->retain();
_event3->retain();
_event4->retain();
scheduleUpdate();
}
void DirectorEventTest::update(float dt)
{
static float time = 0;
time += dt;
if(time > 0.5) {
Director::getInstance()->setProjection(Director::Projection::_2D);
time = 0;
}
}
void DirectorEventTest::onExit()
{
EventDispatcherTestDemo::onExit();
auto dispatcher = Director::getInstance()->getEventDispatcher();
dispatcher->removeEventListener(_event1);
dispatcher->removeEventListener(_event2);
dispatcher->removeEventListener(_event3);
dispatcher->removeEventListener(_event4);
_event1->release();
_event2->release();
_event3->release();
_event4->release();
}
void DirectorEventTest::onEvent1(EventCustom *event)
{
char buf[20];
snprintf(buf, sizeof(buf)-1, "Update: %d", _count1++);
_label1->setString(buf);
}
void DirectorEventTest::onEvent2(EventCustom *event)
{
char buf[20];
snprintf(buf, sizeof(buf)-1, "Visit: %d", _count2++);
_label2->setString(buf);
}
std::string DirectorEventTest::title() const
{
return "Testing Director Events";
}
std::string DirectorEventTest::subtitle() const
{
return "after visit, after draw, after update, projection changed";
}

View File

@ -113,4 +113,25 @@ public:
virtual std::string subtitle() const override;
};
class DirectorEventTest : public EventDispatcherTestDemo
{
public:
CREATE_FUNC(DirectorEventTest);
virtual void onEnter() override;
virtual void onExit() override;
virtual void update(float dt) override;
void onEvent1(EventCustom *event);
void onEvent2(EventCustom *event);
virtual std::string title() const override;
virtual std::string subtitle() const override;
protected:
int _count1, _count2, _count3, _count4;
Label *_label1, *_label2, *_label3, *_label4;
EventListenerCustom *_event1, *_event2, *_event3, *_event4;
};
#endif /* defined(__samples__NewEventDispatcherTest__) */

View File

@ -604,10 +604,10 @@ CameraZoomTest::CameraZoomTest()
sprite = Sprite::create(s_pathGrossini);
addChild( sprite, 0);
sprite->setPosition( Point(s.width/4*1, s.height/2) );
cam = sprite->getCamera();
cam->setEye(0, 0, 415/2);
cam->setCenter(0, 0, 0);
// cam = sprite->getCamera();
// cam->setEye(0, 0, 415/2);
// cam->setCenter(0, 0, 0);
// CENTER
sprite = Sprite::create(s_pathGrossini);
addChild( sprite, 0, 40);
@ -625,17 +625,17 @@ CameraZoomTest::CameraZoomTest()
void CameraZoomTest::update(float dt)
{
Node *sprite;
Camera *cam;
// Camera *cam;
_z += dt * 100;
sprite = getChildByTag(20);
cam = sprite->getCamera();
cam->setEye(0, 0, _z);
// cam = sprite->getCamera();
// cam->setEye(0, 0, _z);
sprite = getChildByTag(40);
cam = sprite->getCamera();
cam->setEye(0, 0, -_z);
// cam = sprite->getCamera();
// cam->setEye(0, 0, -_z);
}
std::string CameraZoomTest::title() const

View File

@ -2,7 +2,7 @@
enum {
kMaxNodes = 200,
kNodesIncrease = 2,
kNodesIncrease = 10,
TEST_COUNT = 5,
};
@ -388,7 +388,7 @@ void LabelMainScene::nextAutoTest()
if ( LabelMainScene::_s_labelCurCase + 1 < LabelMainScene::MAX_SUB_TEST_NUMS )
{
LabelMainScene::_s_labelCurCase += 1;
autoShowLabelTests(LabelMainScene::_s_labelCurCase, LabelMainScene::AUTO_TEST_NODE_NUM);
autoShowLabelTests(LabelMainScene::_s_labelCurCase, _quantityNodes);
}
else
{
@ -422,7 +422,7 @@ void LabelMainScene::onAutoTest(Object* sender)
if (LabelMainScene::_s_autoTest)
{
menuItem->setString("Auto Test On");
autoShowLabelTests(0,AUTO_TEST_NODE_NUM);
autoShowLabelTests(0,_quantityNodes);
}
else
{

View File

@ -20,7 +20,7 @@ public:
class LabelMainScene : public Scene
{
public:
static const int AUTO_TEST_NODE_NUM = 6;
static const int AUTO_TEST_NODE_NUM = 20;
virtual ~LabelMainScene();
@ -47,7 +47,7 @@ public:
static int _s_labelCurCase;
private:
static const int MAX_AUTO_TEST_TIMES = 50;
static const int MAX_AUTO_TEST_TIMES = 35;
static const int MAX_SUB_TEST_NUMS = 5;

View File

@ -135,9 +135,9 @@ TMXOrthoTest::TMXOrthoTest()
child->getTexture()->setAntiAliasTexParameters();
}
float x, y, z;
map->getCamera()->getEye(&x, &y, &z);
map->getCamera()->setEye(x-200, y, z+300);
// float x, y, z;
// map->getCamera()->getEye(&x, &y, &z);
// map->getCamera()->setEye(x-200, y, z+300);
}
void TMXOrthoTest::onEnter()

View File

@ -117,11 +117,12 @@ xcopy /Y /Q "$(ProjectDir)..\..\..\..\external\websockets\prebuilt\win32\*.*" "$
<AdditionalDependencies>libcurl_imp.lib;websockets.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>$(OutDir)$(ProjectName).exe</OutputFile>
<AdditionalLibraryDirectories>$(OutDir);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>true</GenerateDebugInformation>
<GenerateDebugInformation>false</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<TargetMachine>MachineX86</TargetMachine>
<ProgramDatabaseFile />
</Link>
<PostBuildEvent>
<Command>

View File

@ -6,7 +6,19 @@
import sys
import os, os.path
import shutil
from optparse import OptionParser
def check_environment_variables_sdk():
''' Checking the environment ANDROID_SDK_ROOT, which will be used for building
'''
try:
SDK_ROOT = os.environ['ANDROID_SDK_ROOT']
except Exception:
print "ANDROID_SDK_ROOT not defined. Please define ANDROID_SDK_ROOT in your environment"
sys.exit(1)
return SDK_ROOT
def check_environment_variables():
''' Checking the environment NDK_ROOT, which will be used for building
@ -39,7 +51,7 @@ def select_toolchain_version():
print "Couldn't find the gcc toolchain."
exit(1)
def do_build(cocos_root, ndk_root, app_android_root):
def do_build(cocos_root, ndk_root, app_android_root,ndk_build_param,sdk_root,android_platform,build_mode):
ndk_path = os.path.join(ndk_root, "ndk-build")
@ -50,12 +62,24 @@ def do_build(cocos_root, ndk_root, app_android_root):
else:
ndk_module_path = 'NDK_MODULE_PATH=%s:%s/external:%s/cocos' % (cocos_root, cocos_root, cocos_root)
ndk_build_param = sys.argv[1:]
if len(ndk_build_param) == 0:
if ndk_build_param == None:
command = '%s -C %s %s' % (ndk_path, app_android_root, ndk_module_path)
else:
command = '%s -C %s %s %s' % (ndk_path, app_android_root, ''.join(str(e) for e in ndk_build_param), ndk_module_path)
os.system(command)
if os.system(command) != 0:
raise Exception("Build dynamic library for project [ " + app_android_root + " ] fails!")
elif android_platform is not None:
sdk_tool_path = os.path.join(sdk_root, "tools/android")
cocoslib_path = os.path.join(cocos_root, "cocos/2d/platform/android/java")
command = '%s update lib-project -t %s -p %s' % (sdk_tool_path,android_platform,cocoslib_path)
if os.system(command) != 0:
raise Exception("update cocos lib-project [ " + cocoslib_path + " ] fails!")
command = '%s update project -t %s -p %s -s' % (sdk_tool_path,android_platform,app_android_root)
if os.system(command) != 0:
raise Exception("update project [ " + app_android_root + " ] fails!")
buildfile_path = os.path.join(app_android_root, "build.xml")
command = 'ant clean %s -f %s -Dsdk.dir=%s' % (build_mode,buildfile_path,sdk_root)
os.system(command)
def copy_files(src, dst):
@ -82,9 +106,10 @@ def copy_resources(app_android_root):
if os.path.isdir(resources_dir):
copy_files(resources_dir, assets_dir)
def build():
def build(ndk_build_param,android_platform,build_mode):
ndk_root = check_environment_variables()
sdk_root = None
select_toolchain_version()
current_dir = os.path.dirname(os.path.realpath(__file__))
@ -92,9 +117,31 @@ def build():
app_android_root = current_dir
copy_resources(app_android_root)
do_build(cocos_root, ndk_root, app_android_root)
if android_platform is not None:
sdk_root = check_environment_variables_sdk()
if android_platform.isdigit():
android_platform = 'android-'+android_platform
else:
print 'please use vaild android platform'
exit(1)
if build_mode is None:
build_mode = 'debug'
elif build_mode != 'release':
build_mode = 'debug'
do_build(cocos_root, ndk_root, app_android_root,ndk_build_param,sdk_root,android_platform,build_mode)
# -------------- main --------------
if __name__ == '__main__':
build()
parser = OptionParser()
parser.add_option("-n", "--ndk", dest="ndk_build_param", help='parameter for ndk-build')
parser.add_option("-p", "--platform", dest="android_platform",
help='parameter for android-update.Without the parameter,the script just build dynamic library for project. Valid android-platform are:[10|11|12|13|14|15|16|17|18|19]')
parser.add_option("-b", "--build", dest="build_mode",
help='the build mode for java project,debug[default] or release.Get more information,please refer to http://developer.android.com/tools/building/building-cmdline.html')
(opts, args) = parser.parse_args()
build(opts.ndk_build_param,opts.android_platform,opts.build_mode)

View File

@ -6,7 +6,19 @@
import sys
import os, os.path
import shutil
from optparse import OptionParser
def check_environment_variables_sdk():
''' Checking the environment ANDROID_SDK_ROOT, which will be used for building
'''
try:
SDK_ROOT = os.environ['ANDROID_SDK_ROOT']
except Exception:
print "ANDROID_SDK_ROOT not defined. Please define ANDROID_SDK_ROOT in your environment"
sys.exit(1)
return SDK_ROOT
def check_environment_variables():
''' Checking the environment NDK_ROOT, which will be used for building
@ -39,7 +51,7 @@ def select_toolchain_version():
print "Couldn't find the gcc toolchain."
exit(1)
def do_build(cocos_root, ndk_root, app_android_root):
def do_build(cocos_root, ndk_root, app_android_root,ndk_build_param,sdk_root,android_platform,build_mode):
ndk_path = os.path.join(ndk_root, "ndk-build")
@ -50,12 +62,24 @@ def do_build(cocos_root, ndk_root, app_android_root):
else:
ndk_module_path = 'NDK_MODULE_PATH=%s:%s/external:%s/cocos' % (cocos_root, cocos_root, cocos_root)
ndk_build_param = sys.argv[1:]
if len(ndk_build_param) == 0:
if ndk_build_param == None:
command = '%s -C %s %s' % (ndk_path, app_android_root, ndk_module_path)
else:
command = '%s -C %s %s %s' % (ndk_path, app_android_root, ''.join(str(e) for e in ndk_build_param), ndk_module_path)
os.system(command)
if os.system(command) != 0:
raise Exception("Build dynamic library for project [ " + app_android_root + " ] fails!")
elif android_platform is not None:
sdk_tool_path = os.path.join(sdk_root, "tools/android")
cocoslib_path = os.path.join(cocos_root, "cocos/2d/platform/android/java")
command = '%s update lib-project -t %s -p %s' % (sdk_tool_path,android_platform,cocoslib_path)
if os.system(command) != 0:
raise Exception("update cocos lib-project [ " + cocoslib_path + " ] fails!")
command = '%s update project -t %s -p %s -s' % (sdk_tool_path,android_platform,app_android_root)
if os.system(command) != 0:
raise Exception("update project [ " + app_android_root + " ] fails!")
buildfile_path = os.path.join(app_android_root, "build.xml")
command = 'ant clean %s -f %s -Dsdk.dir=%s' % (build_mode,buildfile_path,sdk_root)
os.system(command)
def copy_files(src, dst):
@ -86,9 +110,10 @@ def copy_resources(app_android_root):
resources_dir = os.path.join(app_android_root, "../../../cocos/scripting/javascript/script")
copy_files(resources_dir, assets_dir)
def build():
def build(ndk_build_param,android_platform,build_mode):
ndk_root = check_environment_variables()
sdk_root = None
select_toolchain_version()
current_dir = os.path.dirname(os.path.realpath(__file__))
@ -96,9 +121,31 @@ def build():
app_android_root = current_dir
copy_resources(app_android_root)
do_build(cocos_root, ndk_root, app_android_root)
if android_platform is not None:
sdk_root = check_environment_variables_sdk()
if android_platform.isdigit():
android_platform = 'android-'+android_platform
else:
print 'please use vaild android platform'
exit(1)
if build_mode is None:
build_mode = 'debug'
elif build_mode != 'release':
build_mode = 'debug'
do_build(cocos_root, ndk_root, app_android_root,ndk_build_param,sdk_root,android_platform,build_mode)
# -------------- main --------------
if __name__ == '__main__':
build()
parser = OptionParser()
parser.add_option("-n", "--ndk", dest="ndk_build_param", help='parameter for ndk-build')
parser.add_option("-p", "--platform", dest="android_platform",
help='parameter for android-update.Without the parameter,the script just build dynamic library for project. Valid android-platform are:[10|11|12|13|14|15|16|17|18|19]')
parser.add_option("-b", "--build", dest="build_mode",
help='the build mode for java project,debug[default] or release.Get more information,please refer to http://developer.android.com/tools/building/building-cmdline.html')
(opts, args) = parser.parse_args()
build(opts.ndk_build_param,opts.android_platform,opts.build_mode)

View File

@ -6,7 +6,19 @@
import sys
import os, os.path
import shutil
from optparse import OptionParser
def check_environment_variables_sdk():
''' Checking the environment ANDROID_SDK_ROOT, which will be used for building
'''
try:
SDK_ROOT = os.environ['ANDROID_SDK_ROOT']
except Exception:
print "ANDROID_SDK_ROOT not defined. Please define ANDROID_SDK_ROOT in your environment"
sys.exit(1)
return SDK_ROOT
def check_environment_variables():
''' Checking the environment NDK_ROOT, which will be used for building
@ -39,7 +51,7 @@ def select_toolchain_version():
print "Couldn't find the gcc toolchain."
exit(1)
def do_build(cocos_root, ndk_root, app_android_root):
def do_build(cocos_root, ndk_root, app_android_root,ndk_build_param,sdk_root,android_platform,build_mode):
ndk_path = os.path.join(ndk_root, "ndk-build")
@ -50,12 +62,24 @@ def do_build(cocos_root, ndk_root, app_android_root):
else:
ndk_module_path = 'NDK_MODULE_PATH=%s:%s/external:%s/cocos' % (cocos_root, cocos_root, cocos_root)
ndk_build_param = sys.argv[1:]
if len(ndk_build_param) == 0:
if ndk_build_param == None:
command = '%s -C %s %s' % (ndk_path, app_android_root, ndk_module_path)
else:
command = '%s -C %s %s %s' % (ndk_path, app_android_root, ''.join(str(e) for e in ndk_build_param), ndk_module_path)
os.system(command)
if os.system(command) != 0:
raise Exception("Build dynamic library for project [ " + app_android_root + " ] fails!")
elif android_platform is not None:
sdk_tool_path = os.path.join(sdk_root, "tools/android")
cocoslib_path = os.path.join(cocos_root, "cocos/2d/platform/android/java")
command = '%s update lib-project -t %s -p %s' % (sdk_tool_path,android_platform,cocoslib_path)
if os.system(command) != 0:
raise Exception("update cocos lib-project [ " + cocoslib_path + " ] fails!")
command = '%s update project -t %s -p %s -s' % (sdk_tool_path,android_platform,app_android_root)
if os.system(command) != 0:
raise Exception("update project [ " + app_android_root + " ] fails!")
buildfile_path = os.path.join(app_android_root, "build.xml")
command = 'ant clean %s -f %s -Dsdk.dir=%s' % (build_mode,buildfile_path,sdk_root)
os.system(command)
def copy_files(src, dst):
@ -86,9 +110,10 @@ def copy_resources(app_android_root):
resources_dir = os.path.join(app_android_root, "../../../cocos/scripting/lua/script")
copy_files(resources_dir, assets_dir)
def build():
def build(ndk_build_param,android_platform,build_mode):
ndk_root = check_environment_variables()
sdk_root = None
select_toolchain_version()
current_dir = os.path.dirname(os.path.realpath(__file__))
@ -96,9 +121,31 @@ def build():
app_android_root = current_dir
copy_resources(app_android_root)
do_build(cocos_root, ndk_root, app_android_root)
if android_platform is not None:
sdk_root = check_environment_variables_sdk()
if android_platform.isdigit():
android_platform = 'android-'+android_platform
else:
print 'please use vaild android platform'
exit(1)
if build_mode is None:
build_mode = 'debug'
elif build_mode != 'release':
build_mode = 'debug'
do_build(cocos_root, ndk_root, app_android_root,ndk_build_param,sdk_root,android_platform,build_mode)
# -------------- main --------------
if __name__ == '__main__':
build()
parser = OptionParser()
parser.add_option("-n", "--ndk", dest="ndk_build_param", help='parameter for ndk-build')
parser.add_option("-p", "--platform", dest="android_platform",
help='parameter for android-update.Without the parameter,the script just build dynamic library for project. Valid android-platform are:[10|11|12|13|14|15|16|17|18|19]')
parser.add_option("-b", "--build", dest="build_mode",
help='the build mode for java project,debug[default] or release.Get more information,please refer to http://developer.android.com/tools/building/building-cmdline.html')
(opts, args) = parser.parse_args()
build(opts.ndk_build_param,opts.android_platform,opts.build_mode)