2010-12-18 16:12:59 +08:00
|
|
|
/****************************************************************************
|
2011-03-19 14:45:51 +08:00
|
|
|
Copyright (c) 2008-2010 Ricardo Quesada
|
|
|
|
Copyright (c) 2009 Valentin Milea
|
2014-01-07 11:25:07 +08:00
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
2011-07-01 15:48:05 +08:00
|
|
|
Copyright (c) 2011 Zynga Inc.
|
2018-01-29 16:25:32 +08:00
|
|
|
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2010-12-18 16:12:59 +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.
|
|
|
|
****************************************************************************/
|
2013-08-26 01:50:29 +08:00
|
|
|
|
2014-04-27 01:11:22 +08:00
|
|
|
#include "2d/CCNode.h"
|
2013-08-26 01:50:29 +08:00
|
|
|
|
|
|
|
#include <algorithm>
|
2014-06-11 16:57:43 +08:00
|
|
|
#include <string>
|
2014-06-17 11:43:03 +08:00
|
|
|
#include <regex>
|
2013-08-26 01:50:29 +08:00
|
|
|
|
2014-04-30 08:37:36 +08:00
|
|
|
#include "base/CCDirector.h"
|
|
|
|
#include "base/CCScheduler.h"
|
|
|
|
#include "base/CCEventDispatcher.h"
|
2016-06-15 15:01:26 +08:00
|
|
|
#include "base/ccUTF8.h"
|
2014-10-20 16:25:24 +08:00
|
|
|
#include "2d/CCCamera.h"
|
2014-05-09 06:43:12 +08:00
|
|
|
#include "2d/CCActionManager.h"
|
2014-05-02 07:42:35 +08:00
|
|
|
#include "2d/CCScene.h"
|
2014-05-09 06:43:12 +08:00
|
|
|
#include "2d/CCComponent.h"
|
2015-05-06 04:07:32 +08:00
|
|
|
#include "renderer/CCMaterial.h"
|
2014-05-09 06:43:12 +08:00
|
|
|
#include "math/TransformUtils.h"
|
2019-11-20 18:19:24 +08:00
|
|
|
#include "renderer/backend/ProgramStateRegistry.h"
|
2013-08-27 09:04:51 +08:00
|
|
|
|
2013-09-03 18:22:03 +08:00
|
|
|
|
2012-03-23 10:26:36 +08:00
|
|
|
#if CC_NODE_RENDER_SUBPIXEL
|
2010-07-20 14:29:18 +08:00
|
|
|
#define RENDER_IN_SUBPIXEL
|
|
|
|
#else
|
2013-04-13 15:18:54 +08:00
|
|
|
#define RENDER_IN_SUBPIXEL(__ARGS__) (ceil(__ARGS__))
|
2010-07-20 14:29:18 +08:00
|
|
|
#endif
|
2010-12-18 16:12:59 +08:00
|
|
|
|
2014-11-24 15:27:20 +08:00
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
NS_CC_BEGIN
|
2010-12-18 16:12:59 +08:00
|
|
|
|
2016-07-31 22:44:24 +08:00
|
|
|
// FIXME:: Yes, nodes might have a sort problem once every 30 days if the game runs at 60 FPS and each frame sprites are reordered.
|
2017-09-25 09:27:33 +08:00
|
|
|
std::uint32_t Node::s_globalOrderOfArrival = 0;
|
2017-06-05 13:37:50 +08:00
|
|
|
int Node::__attachedNodeCount = 0;
|
2013-09-01 06:18:28 +08:00
|
|
|
|
2014-08-29 05:56:15 +08:00
|
|
|
// MARK: Constructor, Destructor, Init
|
|
|
|
|
2015-09-18 11:48:43 +08:00
|
|
|
Node::Node()
|
2013-06-15 14:03:30 +08:00
|
|
|
: _rotationX(0.0f)
|
|
|
|
, _rotationY(0.0f)
|
2014-02-23 11:16:42 +08:00
|
|
|
, _rotationZ_X(0.0f)
|
|
|
|
, _rotationZ_Y(0.0f)
|
2013-06-15 14:03:30 +08:00
|
|
|
, _scaleX(1.0f)
|
|
|
|
, _scaleY(1.0f)
|
2014-02-23 11:16:42 +08:00
|
|
|
, _scaleZ(1.0f)
|
2014-10-30 22:25:46 +08:00
|
|
|
, _positionZ(0.0f)
|
|
|
|
, _usingNormalizedPosition(false)
|
|
|
|
, _normalizedPositionDirty(false)
|
2013-06-15 14:03:30 +08:00
|
|
|
, _skewX(0.0f)
|
|
|
|
, _skewY(0.0f)
|
2018-05-14 10:34:56 +08:00
|
|
|
, _anchorPoint(0, 0)
|
2013-07-12 14:47:36 +08:00
|
|
|
, _contentSize(Size::ZERO)
|
2014-12-15 19:43:54 +08:00
|
|
|
, _contentSizeDirty(true)
|
2013-07-29 14:07:57 +08:00
|
|
|
, _transformDirty(true)
|
|
|
|
, _inverseDirty(true)
|
2016-06-24 10:03:38 +08:00
|
|
|
, _additionalTransform(nullptr)
|
|
|
|
, _additionalTransformDirty(false)
|
2014-03-01 08:10:48 +08:00
|
|
|
, _transformUpdated(true)
|
2011-06-10 17:51:37 +08:00
|
|
|
// children (lazy allocs)
|
|
|
|
// lazy alloc
|
2017-09-25 09:27:33 +08:00
|
|
|
, _localZOrder$Arrival(0LL)
|
2014-01-19 03:35:27 +08:00
|
|
|
, _globalZOrder(0)
|
2013-12-18 17:47:20 +08:00
|
|
|
, _parent(nullptr)
|
2013-06-15 14:03:30 +08:00
|
|
|
// "whole screen" objects. like Scenes and Layers, should set _ignoreAnchorPointForPosition to true
|
2013-08-29 03:42:25 +08:00
|
|
|
, _tag(Node::INVALID_TAG)
|
2014-10-30 22:25:46 +08:00
|
|
|
, _name("")
|
|
|
|
, _hashOfName(0)
|
2011-06-10 17:51:37 +08:00
|
|
|
// userData is always inited as nil
|
2013-12-18 17:47:20 +08:00
|
|
|
, _userData(nullptr)
|
|
|
|
, _userObject(nullptr)
|
2013-06-15 14:03:30 +08:00
|
|
|
, _running(false)
|
|
|
|
, _visible(true)
|
|
|
|
, _ignoreAnchorPointForPosition(false)
|
|
|
|
, _reorderChildDirty(false)
|
|
|
|
, _isTransitionFinished(false)
|
2014-02-20 16:40:46 +08:00
|
|
|
#if CC_ENABLE_SCRIPT_BINDING
|
2013-06-15 14:03:30 +08:00
|
|
|
, _updateScriptHandler(0)
|
2014-02-20 16:40:46 +08:00
|
|
|
#endif
|
2013-12-18 17:47:20 +08:00
|
|
|
, _componentContainer(nullptr)
|
2013-12-06 18:07:16 +08:00
|
|
|
, _displayedOpacity(255)
|
|
|
|
, _realOpacity(255)
|
|
|
|
, _displayedColor(Color3B::WHITE)
|
|
|
|
, _realColor(Color3B::WHITE)
|
|
|
|
, _cascadeColorEnabled(false)
|
|
|
|
, _cascadeOpacityEnabled(false)
|
2014-08-07 15:23:31 +08:00
|
|
|
, _cameraMask(1)
|
2017-06-12 10:43:45 +08:00
|
|
|
, _onEnterCallback(nullptr)
|
|
|
|
, _onExitCallback(nullptr)
|
|
|
|
, _onEnterTransitionDidFinishCallback(nullptr)
|
|
|
|
, _onExitTransitionDidStartCallback(nullptr)
|
2018-05-14 10:34:56 +08:00
|
|
|
#if CC_USE_PHYSICS
|
|
|
|
, _physicsBody(nullptr)
|
|
|
|
#endif
|
2010-12-18 16:12:59 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
// set default scheduler and actionManager
|
2015-01-13 10:28:25 +08:00
|
|
|
_director = Director::getInstance();
|
|
|
|
_actionManager = _director->getActionManager();
|
2013-06-15 14:03:30 +08:00
|
|
|
_actionManager->retain();
|
2015-01-13 10:28:25 +08:00
|
|
|
_scheduler = _director->getScheduler();
|
2013-06-15 14:03:30 +08:00
|
|
|
_scheduler->retain();
|
2015-01-13 10:28:25 +08:00
|
|
|
_eventDispatcher = _director->getEventDispatcher();
|
2013-10-26 15:04:01 +08:00
|
|
|
_eventDispatcher->retain();
|
|
|
|
|
2016-06-24 10:03:38 +08:00
|
|
|
_transform = _inverse = Mat4::IDENTITY;
|
2010-12-18 16:12:59 +08:00
|
|
|
}
|
2012-03-14 18:11:25 +08:00
|
|
|
|
2014-08-29 05:56:15 +08:00
|
|
|
Node * Node::create()
|
|
|
|
{
|
|
|
|
Node * ret = new (std::nothrow) Node();
|
|
|
|
if (ret && ret->init())
|
|
|
|
{
|
|
|
|
ret->autorelease();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CC_SAFE_DELETE(ret);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-07-17 09:16:04 +08:00
|
|
|
Node::~Node()
|
2010-12-18 16:12:59 +08:00
|
|
|
{
|
2013-08-22 11:05:06 +08:00
|
|
|
CCLOGINFO( "deallocing Node: %p - tag: %i", this, _tag );
|
2012-09-21 00:21:24 +08:00
|
|
|
|
2014-02-20 16:40:46 +08:00
|
|
|
#if CC_ENABLE_SCRIPT_BINDING
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_updateScriptHandler)
|
2012-12-10 13:48:27 +08:00
|
|
|
{
|
2013-07-22 17:24:54 +08:00
|
|
|
ScriptEngineManager::getInstance()->getScriptEngine()->removeScriptHandler(_updateScriptHandler);
|
2012-12-10 13:48:27 +08:00
|
|
|
}
|
2014-02-20 16:40:46 +08:00
|
|
|
#endif
|
2010-07-14 10:36:26 +08:00
|
|
|
|
2014-03-28 14:09:51 +08:00
|
|
|
// User object has to be released before others, since userObject may have a weak reference of this node
|
2017-06-05 10:39:25 +08:00
|
|
|
// It may invoke `node->stopAllActions();` while `_actionManager` is null if the next line is after `CC_SAFE_RELEASE_NULL(_actionManager)`.
|
2014-03-28 14:09:51 +08:00
|
|
|
CC_SAFE_RELEASE_NULL(_userObject);
|
2010-07-14 10:36:26 +08:00
|
|
|
|
2013-11-28 16:02:03 +08:00
|
|
|
for (auto& child : _children)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-12-19 09:45:21 +08:00
|
|
|
child->_parent = nullptr;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2010-07-14 10:36:26 +08:00
|
|
|
|
2013-09-03 18:22:03 +08:00
|
|
|
removeAllComponents();
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
CC_SAFE_DELETE(_componentContainer);
|
2013-09-03 18:22:03 +08:00
|
|
|
|
2015-01-21 21:01:57 +08:00
|
|
|
stopAllActions();
|
|
|
|
unscheduleAllCallbacks();
|
2014-03-28 14:43:44 +08:00
|
|
|
CC_SAFE_RELEASE_NULL(_actionManager);
|
|
|
|
CC_SAFE_RELEASE_NULL(_scheduler);
|
|
|
|
|
|
|
|
_eventDispatcher->removeEventListenersForTarget(this);
|
|
|
|
|
2014-03-28 03:29:28 +08:00
|
|
|
#if CC_NODE_DEBUG_VERIFY_EVENT_LISTENERS && COCOS2D_DEBUG > 0
|
|
|
|
_eventDispatcher->debugCheckNodeHasNoEventListenersOnDestruction(this);
|
|
|
|
#endif
|
2014-03-27 04:12:44 +08:00
|
|
|
|
2014-04-08 08:05:42 +08:00
|
|
|
CCASSERT(!_running, "Node still marked as running on node destruction! Was base class onExit() called in derived class onExit() implementations?");
|
2014-03-27 04:12:44 +08:00
|
|
|
CC_SAFE_RELEASE(_eventDispatcher);
|
2016-06-24 10:03:38 +08:00
|
|
|
|
|
|
|
delete[] _additionalTransform;
|
2019-06-18 15:25:26 +08:00
|
|
|
CC_SAFE_RELEASE(_programState);
|
2010-12-18 16:12:59 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool Node::init()
|
2013-02-27 09:38:30 +08:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-08-29 05:56:15 +08:00
|
|
|
void Node::cleanup()
|
|
|
|
{
|
|
|
|
#if CC_ENABLE_SCRIPT_BINDING
|
2020-02-24 23:08:47 +08:00
|
|
|
ScriptEngineManager::sendNodeEventToLua(this, kNodeOnCleanup);
|
2014-08-29 05:56:15 +08:00
|
|
|
#endif // #if CC_ENABLE_SCRIPT_BINDING
|
2015-07-16 14:09:26 +08:00
|
|
|
|
|
|
|
// actions
|
|
|
|
this->stopAllActions();
|
2014-08-29 05:56:15 +08:00
|
|
|
// timers
|
2015-12-17 21:55:47 +08:00
|
|
|
this->unscheduleAllCallbacks();
|
2017-05-19 14:03:51 +08:00
|
|
|
|
2018-01-17 11:09:23 +08:00
|
|
|
// NOTE: Although it was correct that removing event listeners associated with current node in Node::cleanup.
|
|
|
|
// But it broke the compatibility to the versions before v3.16 .
|
|
|
|
// User code may call `node->removeFromParent(true)` which will trigger node's cleanup method, when the node
|
|
|
|
// is added to scene again, event listeners like EventListenerTouchOneByOne will be lost.
|
|
|
|
// In fact, user's code should use `node->removeFromParent(false)` in order not to do a cleanup and just remove node
|
|
|
|
// from its parent. For more discussion about why we revert this change is at https://github.com/cocos2d/cocos2d-x/issues/18104.
|
|
|
|
// We need to consider more before we want to correct the old and wrong logic code.
|
|
|
|
// For now, compatiblity is the most important for our users.
|
|
|
|
// _eventDispatcher->removeEventListenersForTarget(this);
|
2015-12-17 21:55:47 +08:00
|
|
|
|
2014-08-29 05:56:15 +08:00
|
|
|
for( const auto &child: _children)
|
|
|
|
child->cleanup();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string Node::getDescription() const
|
|
|
|
{
|
|
|
|
return StringUtils::format("<Node | Tag = %d", _tag);
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: getters / setters
|
|
|
|
|
2013-07-04 08:22:15 +08:00
|
|
|
float Node::getSkewX() const
|
2011-07-01 15:48:05 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _skewX;
|
2011-07-01 15:48:05 +08:00
|
|
|
}
|
|
|
|
|
2014-02-27 15:12:57 +08:00
|
|
|
void Node::setSkewX(float skewX)
|
2011-07-01 15:48:05 +08:00
|
|
|
{
|
2014-02-27 15:12:57 +08:00
|
|
|
if (_skewX == skewX)
|
|
|
|
return;
|
|
|
|
|
|
|
|
_skewX = skewX;
|
2014-03-01 08:10:48 +08:00
|
|
|
_transformUpdated = _transformDirty = _inverseDirty = true;
|
2011-07-01 15:48:05 +08:00
|
|
|
}
|
|
|
|
|
2013-07-04 08:22:15 +08:00
|
|
|
float Node::getSkewY() const
|
2011-07-01 15:48:05 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _skewY;
|
2011-07-01 15:48:05 +08:00
|
|
|
}
|
|
|
|
|
2014-02-27 15:12:57 +08:00
|
|
|
void Node::setSkewY(float skewY)
|
2011-07-01 15:48:05 +08:00
|
|
|
{
|
2014-02-27 15:12:57 +08:00
|
|
|
if (_skewY == skewY)
|
|
|
|
return;
|
|
|
|
|
|
|
|
_skewY = skewY;
|
2014-03-01 08:10:48 +08:00
|
|
|
_transformUpdated = _transformDirty = _inverseDirty = true;
|
2011-07-01 15:48:05 +08:00
|
|
|
}
|
|
|
|
|
2017-09-25 09:27:33 +08:00
|
|
|
void Node::setLocalZOrder(std::int32_t z)
|
2012-03-16 13:42:53 +08:00
|
|
|
{
|
2016-07-31 22:44:24 +08:00
|
|
|
if (getLocalZOrder() == z)
|
2014-02-27 15:12:57 +08:00
|
|
|
return;
|
|
|
|
|
2016-07-31 22:44:24 +08:00
|
|
|
_setLocalZOrder(z);
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_parent)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_parent->reorderChild(this, z);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2014-01-19 03:35:27 +08:00
|
|
|
|
2013-10-26 15:04:01 +08:00
|
|
|
_eventDispatcher->setDirtyForNode(this);
|
2012-03-16 13:42:53 +08:00
|
|
|
}
|
|
|
|
|
2014-09-09 10:55:27 +08:00
|
|
|
/// zOrder setter : private method
|
|
|
|
/// used internally to alter the zOrder variable. DON'T call this method manually
|
2017-09-25 09:27:33 +08:00
|
|
|
void Node::_setLocalZOrder(std::int32_t z)
|
2014-09-09 10:55:27 +08:00
|
|
|
{
|
2016-07-29 10:58:31 +08:00
|
|
|
_localZOrder = z;
|
2014-09-09 10:55:27 +08:00
|
|
|
}
|
|
|
|
|
2016-07-31 22:44:24 +08:00
|
|
|
void Node::updateOrderOfArrival()
|
|
|
|
{
|
2017-09-25 09:27:33 +08:00
|
|
|
_orderOfArrival = (++s_globalOrderOfArrival);
|
2016-07-31 22:44:24 +08:00
|
|
|
}
|
|
|
|
|
2014-01-22 02:10:50 +08:00
|
|
|
void Node::setGlobalZOrder(float globalZOrder)
|
2014-01-21 10:23:05 +08:00
|
|
|
{
|
2014-01-22 02:10:50 +08:00
|
|
|
if (_globalZOrder != globalZOrder)
|
2014-01-21 10:23:05 +08:00
|
|
|
{
|
2014-01-22 02:10:50 +08:00
|
|
|
_globalZOrder = globalZOrder;
|
2014-01-21 10:23:05 +08:00
|
|
|
_eventDispatcher->setDirtyForNode(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-18 16:12:59 +08:00
|
|
|
/// rotation getter
|
2013-07-04 08:22:15 +08:00
|
|
|
float Node::getRotation() const
|
2010-12-18 16:12:59 +08:00
|
|
|
{
|
2014-02-23 11:16:42 +08:00
|
|
|
CCASSERT(_rotationZ_X == _rotationZ_Y, "CCNode#rotation. RotationX != RotationY. Don't know which one to return");
|
|
|
|
return _rotationZ_X;
|
2010-12-18 16:12:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// rotation setter
|
2014-02-27 15:12:57 +08:00
|
|
|
void Node::setRotation(float rotation)
|
2010-07-12 17:56:06 +08:00
|
|
|
{
|
2014-02-27 15:12:57 +08:00
|
|
|
if (_rotationZ_X == rotation)
|
|
|
|
return;
|
|
|
|
|
|
|
|
_rotationZ_X = _rotationZ_Y = rotation;
|
2014-03-01 08:10:48 +08:00
|
|
|
_transformUpdated = _transformDirty = _inverseDirty = true;
|
2014-12-24 17:07:54 +08:00
|
|
|
|
|
|
|
updateRotationQuat();
|
2012-11-14 18:05:15 +08:00
|
|
|
}
|
|
|
|
|
2014-02-23 11:16:42 +08:00
|
|
|
float Node::getRotationSkewX() const
|
|
|
|
{
|
|
|
|
return _rotationZ_X;
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
void Node::setRotation3D(const Vec3& rotation)
|
2014-02-23 11:16:42 +08:00
|
|
|
{
|
2014-02-27 15:12:57 +08:00
|
|
|
if (_rotationX == rotation.x &&
|
|
|
|
_rotationY == rotation.y &&
|
|
|
|
_rotationZ_X == rotation.z)
|
|
|
|
return;
|
|
|
|
|
2014-03-01 08:10:48 +08:00
|
|
|
_transformUpdated = _transformDirty = _inverseDirty = true;
|
2014-02-23 11:16:42 +08:00
|
|
|
|
|
|
|
_rotationX = rotation.x;
|
|
|
|
_rotationY = rotation.y;
|
|
|
|
|
|
|
|
// rotation Z is decomposed in 2 to simulate Skew for Flash animations
|
|
|
|
_rotationZ_Y = _rotationZ_X = rotation.z;
|
2014-12-22 17:23:44 +08:00
|
|
|
|
|
|
|
updateRotationQuat();
|
2014-02-23 11:16:42 +08:00
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec3 Node::getRotation3D() const
|
2012-11-14 18:05:15 +08:00
|
|
|
{
|
2014-02-23 11:16:42 +08:00
|
|
|
// rotation Z is decomposed in 2 to simulate Skew for Flash animations
|
|
|
|
CCASSERT(_rotationZ_X == _rotationZ_Y, "_rotationZ_X != _rotationZ_Y");
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
return Vec3(_rotationX,_rotationY,_rotationZ_X);
|
2012-11-14 18:05:15 +08:00
|
|
|
}
|
|
|
|
|
2014-12-22 17:23:44 +08:00
|
|
|
void Node::updateRotationQuat()
|
|
|
|
{
|
|
|
|
// convert Euler angle to quaternion
|
2014-12-24 18:12:00 +08:00
|
|
|
// when _rotationZ_X == _rotationZ_Y, _rotationQuat = RotationZ_X * RotationY * RotationX
|
|
|
|
// when _rotationZ_X != _rotationZ_Y, _rotationQuat = RotationY * RotationX
|
2014-12-24 17:07:54 +08:00
|
|
|
float halfRadx = CC_DEGREES_TO_RADIANS(_rotationX / 2.f), halfRady = CC_DEGREES_TO_RADIANS(_rotationY / 2.f), halfRadz = _rotationZ_X == _rotationZ_Y ? -CC_DEGREES_TO_RADIANS(_rotationZ_X / 2.f) : 0;
|
2014-12-25 10:33:49 +08:00
|
|
|
float coshalfRadx = cosf(halfRadx), sinhalfRadx = sinf(halfRadx), coshalfRady = cosf(halfRady), sinhalfRady = sinf(halfRady), coshalfRadz = cosf(halfRadz), sinhalfRadz = sinf(halfRadz);
|
2014-12-24 18:12:00 +08:00
|
|
|
_rotationQuat.x = sinhalfRadx * coshalfRady * coshalfRadz - coshalfRadx * sinhalfRady * sinhalfRadz;
|
|
|
|
_rotationQuat.y = coshalfRadx * sinhalfRady * coshalfRadz + sinhalfRadx * coshalfRady * sinhalfRadz;
|
|
|
|
_rotationQuat.z = coshalfRadx * coshalfRady * sinhalfRadz - sinhalfRadx * sinhalfRady * coshalfRadz;
|
|
|
|
_rotationQuat.w = coshalfRadx * coshalfRady * coshalfRadz + sinhalfRadx * sinhalfRady * sinhalfRadz;
|
2014-12-22 17:23:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Node::updateRotation3D()
|
|
|
|
{
|
|
|
|
//convert quaternion to Euler angle
|
2014-12-24 18:12:00 +08:00
|
|
|
float x = _rotationQuat.x, y = _rotationQuat.y, z = _rotationQuat.z, w = _rotationQuat.w;
|
2014-12-22 17:23:44 +08:00
|
|
|
_rotationX = atan2f(2.f * (w * x + y * z), 1.f - 2.f * (x * x + y * y));
|
2015-07-29 10:35:01 +08:00
|
|
|
float sy = 2.f * (w * y - z * x);
|
|
|
|
sy = clampf(sy, -1, 1);
|
|
|
|
_rotationY = asinf(sy);
|
2015-06-17 11:17:46 +08:00
|
|
|
_rotationZ_X = atan2f(2.f * (w * z + x * y), 1.f - 2.f * (y * y + z * z));
|
2014-12-22 17:23:44 +08:00
|
|
|
|
|
|
|
_rotationX = CC_RADIANS_TO_DEGREES(_rotationX);
|
|
|
|
_rotationY = CC_RADIANS_TO_DEGREES(_rotationY);
|
2014-12-24 17:07:54 +08:00
|
|
|
_rotationZ_X = _rotationZ_Y = -CC_RADIANS_TO_DEGREES(_rotationZ_X);
|
2014-12-22 17:23:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Node::setRotationQuat(const Quaternion& quat)
|
|
|
|
{
|
2014-12-24 18:12:00 +08:00
|
|
|
_rotationQuat = quat;
|
2014-12-22 17:23:44 +08:00
|
|
|
updateRotation3D();
|
|
|
|
_transformUpdated = _transformDirty = _inverseDirty = true;
|
|
|
|
}
|
|
|
|
|
2014-12-24 17:07:54 +08:00
|
|
|
Quaternion Node::getRotationQuat() const
|
2014-12-22 17:23:44 +08:00
|
|
|
{
|
2014-12-24 18:12:00 +08:00
|
|
|
return _rotationQuat;
|
2014-12-22 17:23:44 +08:00
|
|
|
}
|
|
|
|
|
2014-02-27 15:12:57 +08:00
|
|
|
void Node::setRotationSkewX(float rotationX)
|
2012-11-14 18:05:15 +08:00
|
|
|
{
|
2014-02-27 15:12:57 +08:00
|
|
|
if (_rotationZ_X == rotationX)
|
|
|
|
return;
|
|
|
|
|
|
|
|
_rotationZ_X = rotationX;
|
2014-03-01 08:10:48 +08:00
|
|
|
_transformUpdated = _transformDirty = _inverseDirty = true;
|
2014-12-24 17:07:54 +08:00
|
|
|
|
|
|
|
updateRotationQuat();
|
2012-11-14 18:05:15 +08:00
|
|
|
}
|
|
|
|
|
2014-02-23 11:16:42 +08:00
|
|
|
float Node::getRotationSkewY() const
|
2012-11-14 18:05:15 +08:00
|
|
|
{
|
2014-02-23 11:16:42 +08:00
|
|
|
return _rotationZ_Y;
|
2012-11-14 18:05:15 +08:00
|
|
|
}
|
|
|
|
|
2014-02-23 11:16:42 +08:00
|
|
|
void Node::setRotationSkewY(float rotationY)
|
2012-11-14 18:05:15 +08:00
|
|
|
{
|
2014-02-27 15:12:57 +08:00
|
|
|
if (_rotationZ_Y == rotationY)
|
|
|
|
return;
|
|
|
|
|
2014-02-23 11:16:42 +08:00
|
|
|
_rotationZ_Y = rotationY;
|
2014-03-01 08:10:48 +08:00
|
|
|
_transformUpdated = _transformDirty = _inverseDirty = true;
|
2014-12-24 17:07:54 +08:00
|
|
|
|
|
|
|
updateRotationQuat();
|
2010-12-18 16:12:59 +08:00
|
|
|
}
|
|
|
|
|
2010-07-12 17:56:06 +08:00
|
|
|
/// scale getter
|
2019-07-22 09:38:46 +08:00
|
|
|
float Node::getScale() const
|
2010-07-12 17:56:06 +08:00
|
|
|
{
|
2013-07-20 13:01:27 +08:00
|
|
|
CCASSERT( _scaleX == _scaleY, "CCNode#scale. ScaleX != ScaleY. Don't know which one to return");
|
2013-06-15 14:03:30 +08:00
|
|
|
return _scaleX;
|
2010-12-18 16:12:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// scale setter
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::setScale(float scale)
|
2010-07-12 17:56:06 +08:00
|
|
|
{
|
2014-06-24 10:05:52 +08:00
|
|
|
if (_scaleX == scale && _scaleY == scale && _scaleZ == scale)
|
2014-02-27 15:12:57 +08:00
|
|
|
return;
|
2014-06-23 13:55:52 +08:00
|
|
|
|
2014-03-01 05:48:00 +08:00
|
|
|
_scaleX = _scaleY = _scaleZ = scale;
|
2014-03-01 08:10:48 +08:00
|
|
|
_transformUpdated = _transformDirty = _inverseDirty = true;
|
2010-07-12 17:56:06 +08:00
|
|
|
}
|
2010-12-18 16:12:59 +08:00
|
|
|
|
|
|
|
/// scaleX getter
|
2013-07-04 08:22:15 +08:00
|
|
|
float Node::getScaleX() const
|
2010-07-07 15:24:44 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _scaleX;
|
2010-12-18 16:12:59 +08:00
|
|
|
}
|
|
|
|
|
2013-10-08 15:57:34 +08:00
|
|
|
/// scale setter
|
|
|
|
void Node::setScale(float scaleX,float scaleY)
|
|
|
|
{
|
2014-02-27 15:12:57 +08:00
|
|
|
if (_scaleX == scaleX && _scaleY == scaleY)
|
|
|
|
return;
|
|
|
|
|
2013-10-08 15:57:34 +08:00
|
|
|
_scaleX = scaleX;
|
|
|
|
_scaleY = scaleY;
|
2014-03-01 08:10:48 +08:00
|
|
|
_transformUpdated = _transformDirty = _inverseDirty = true;
|
2013-10-08 15:57:34 +08:00
|
|
|
}
|
|
|
|
|
2010-12-18 16:12:59 +08:00
|
|
|
/// scaleX setter
|
2014-02-27 15:12:57 +08:00
|
|
|
void Node::setScaleX(float scaleX)
|
2010-07-12 17:56:06 +08:00
|
|
|
{
|
2014-02-27 15:12:57 +08:00
|
|
|
if (_scaleX == scaleX)
|
|
|
|
return;
|
|
|
|
|
|
|
|
_scaleX = scaleX;
|
2014-03-01 08:10:48 +08:00
|
|
|
_transformUpdated = _transformDirty = _inverseDirty = true;
|
2010-07-07 15:24:44 +08:00
|
|
|
}
|
2010-12-18 16:12:59 +08:00
|
|
|
|
|
|
|
/// scaleY getter
|
2013-07-04 08:22:15 +08:00
|
|
|
float Node::getScaleY() const
|
2010-07-07 15:24:44 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _scaleY;
|
2010-12-18 16:12:59 +08:00
|
|
|
}
|
2010-07-12 17:56:06 +08:00
|
|
|
|
2014-02-23 11:16:42 +08:00
|
|
|
/// scaleY setter
|
2014-02-27 15:12:57 +08:00
|
|
|
void Node::setScaleZ(float scaleZ)
|
2014-02-23 11:16:42 +08:00
|
|
|
{
|
2014-02-27 15:12:57 +08:00
|
|
|
if (_scaleZ == scaleZ)
|
|
|
|
return;
|
|
|
|
|
|
|
|
_scaleZ = scaleZ;
|
2014-03-01 08:10:48 +08:00
|
|
|
_transformUpdated = _transformDirty = _inverseDirty = true;
|
2014-02-23 11:16:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// scaleY getter
|
|
|
|
float Node::getScaleZ() const
|
|
|
|
{
|
|
|
|
return _scaleZ;
|
|
|
|
}
|
|
|
|
|
2010-07-12 17:56:06 +08:00
|
|
|
/// scaleY setter
|
2014-02-27 15:12:57 +08:00
|
|
|
void Node::setScaleY(float scaleY)
|
2010-07-12 17:56:06 +08:00
|
|
|
{
|
2014-02-27 15:12:57 +08:00
|
|
|
if (_scaleY == scaleY)
|
|
|
|
return;
|
|
|
|
|
|
|
|
_scaleY = scaleY;
|
2014-03-01 08:10:48 +08:00
|
|
|
_transformUpdated = _transformDirty = _inverseDirty = true;
|
2010-12-18 16:12:59 +08:00
|
|
|
}
|
|
|
|
|
2014-02-23 11:16:42 +08:00
|
|
|
|
2010-12-18 16:12:59 +08:00
|
|
|
/// position getter
|
2014-05-15 01:07:09 +08:00
|
|
|
const Vec2& Node::getPosition() const
|
2010-12-18 16:12:59 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _position;
|
2010-12-18 16:12:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// position setter
|
2014-05-15 01:07:09 +08:00
|
|
|
void Node::setPosition(const Vec2& position)
|
2010-07-07 15:24:44 +08:00
|
|
|
{
|
2014-08-28 11:41:18 +08:00
|
|
|
setPosition(position.x, position.y);
|
2010-12-31 14:56:24 +08:00
|
|
|
}
|
|
|
|
|
2013-07-04 08:22:15 +08:00
|
|
|
void Node::getPosition(float* x, float* y) const
|
2012-02-02 10:39:19 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
*x = _position.x;
|
|
|
|
*y = _position.y;
|
2012-02-02 10:39:19 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::setPosition(float x, float y)
|
2012-02-02 10:39:19 +08:00
|
|
|
{
|
2014-08-28 11:41:18 +08:00
|
|
|
if (_position.x == x && _position.y == y)
|
|
|
|
return;
|
|
|
|
|
|
|
|
_position.x = x;
|
|
|
|
_position.y = y;
|
|
|
|
|
|
|
|
_transformUpdated = _transformDirty = _inverseDirty = true;
|
|
|
|
_usingNormalizedPosition = false;
|
2012-02-02 10:39:19 +08:00
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
void Node::setPosition3D(const Vec3& position)
|
2013-01-21 16:26:02 +08:00
|
|
|
{
|
2014-08-28 11:41:18 +08:00
|
|
|
setPositionZ(position.z);
|
|
|
|
setPosition(position.x, position.y);
|
2013-01-21 16:26:02 +08:00
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec3 Node::getPosition3D() const
|
2013-01-21 16:26:02 +08:00
|
|
|
{
|
2014-12-23 18:07:22 +08:00
|
|
|
return Vec3(_position.x, _position.y, _positionZ);
|
2014-02-23 11:16:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
float Node::getPositionX() const
|
|
|
|
{
|
|
|
|
return _position.x;
|
2013-01-21 16:26:02 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::setPositionX(float x)
|
2013-01-21 16:26:02 +08:00
|
|
|
{
|
2014-08-28 11:41:18 +08:00
|
|
|
setPosition(x, _position.y);
|
2013-01-21 16:26:02 +08:00
|
|
|
}
|
|
|
|
|
2014-02-23 11:16:42 +08:00
|
|
|
float Node::getPositionY() const
|
|
|
|
{
|
|
|
|
return _position.y;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::setPositionY(float y)
|
2013-01-21 16:26:02 +08:00
|
|
|
{
|
2014-08-28 11:41:18 +08:00
|
|
|
setPosition(_position.x, y);
|
2013-01-21 16:26:02 +08:00
|
|
|
}
|
|
|
|
|
2014-02-23 11:16:42 +08:00
|
|
|
float Node::getPositionZ() const
|
|
|
|
{
|
|
|
|
return _positionZ;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Node::setPositionZ(float positionZ)
|
|
|
|
{
|
2014-02-27 15:12:57 +08:00
|
|
|
if (_positionZ == positionZ)
|
|
|
|
return;
|
|
|
|
|
2014-03-01 08:10:48 +08:00
|
|
|
_transformUpdated = _transformDirty = _inverseDirty = true;
|
2014-02-23 11:16:42 +08:00
|
|
|
|
|
|
|
_positionZ = positionZ;
|
|
|
|
}
|
|
|
|
|
2014-05-31 07:42:05 +08:00
|
|
|
/// position getter
|
2016-10-27 09:45:40 +08:00
|
|
|
const Vec2& Node::getPositionNormalized() const
|
2014-05-31 07:42:05 +08:00
|
|
|
{
|
|
|
|
return _normalizedPosition;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// position setter
|
2016-10-27 09:45:40 +08:00
|
|
|
void Node::setPositionNormalized(const Vec2& position)
|
2014-05-31 07:42:05 +08:00
|
|
|
{
|
|
|
|
if (_normalizedPosition.equals(position))
|
|
|
|
return;
|
|
|
|
|
|
|
|
_normalizedPosition = position;
|
|
|
|
_usingNormalizedPosition = true;
|
2014-08-06 14:38:58 +08:00
|
|
|
_normalizedPositionDirty = true;
|
2014-05-31 07:42:05 +08:00
|
|
|
_transformUpdated = _transformDirty = _inverseDirty = true;
|
|
|
|
}
|
|
|
|
|
2013-12-12 12:07:20 +08:00
|
|
|
ssize_t Node::getChildrenCount() const
|
2012-02-02 10:39:19 +08:00
|
|
|
{
|
2013-12-05 10:35:10 +08:00
|
|
|
return _children.size();
|
2012-02-02 10:39:19 +08:00
|
|
|
}
|
|
|
|
|
2010-07-12 17:56:06 +08:00
|
|
|
/// isVisible getter
|
2013-07-04 08:22:15 +08:00
|
|
|
bool Node::isVisible() const
|
2010-07-07 15:24:44 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _visible;
|
2010-07-07 15:24:44 +08:00
|
|
|
}
|
|
|
|
|
2010-07-12 17:56:06 +08:00
|
|
|
/// isVisible setter
|
2014-05-28 17:41:34 +08:00
|
|
|
void Node::setVisible(bool visible)
|
2010-07-07 15:24:44 +08:00
|
|
|
{
|
2014-05-28 17:41:34 +08:00
|
|
|
if(visible != _visible)
|
2014-03-07 10:03:34 +08:00
|
|
|
{
|
2014-05-28 17:41:34 +08:00
|
|
|
_visible = visible;
|
2014-12-23 18:07:22 +08:00
|
|
|
if(_visible)
|
|
|
|
_transformUpdated = _transformDirty = _inverseDirty = true;
|
2014-03-07 10:03:34 +08:00
|
|
|
}
|
2010-07-07 15:24:44 +08:00
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
const Vec2& Node::getAnchorPointInPoints() const
|
2012-03-14 14:55:17 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _anchorPointInPoints;
|
2012-03-14 14:55:17 +08:00
|
|
|
}
|
2010-07-12 17:56:06 +08:00
|
|
|
|
|
|
|
/// anchorPoint getter
|
2014-05-15 01:07:09 +08:00
|
|
|
const Vec2& Node::getAnchorPoint() const
|
2010-07-07 15:24:44 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _anchorPoint;
|
2010-12-18 16:12:59 +08:00
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
void Node::setAnchorPoint(const Vec2& point)
|
2010-07-08 10:26:58 +08:00
|
|
|
{
|
2014-12-23 18:07:22 +08:00
|
|
|
if (! point.equals(_anchorPoint))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_anchorPoint = point;
|
2015-04-20 01:40:52 +08:00
|
|
|
_anchorPointInPoints.set(_contentSize.width * _anchorPoint.x, _contentSize.height * _anchorPoint.y);
|
2014-03-01 08:10:48 +08:00
|
|
|
_transformUpdated = _transformDirty = _inverseDirty = true;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2010-07-12 17:56:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// contentSize getter
|
2013-06-20 14:13:12 +08:00
|
|
|
const Size& Node::getContentSize() const
|
2010-07-12 17:56:06 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _contentSize;
|
2010-07-12 17:56:06 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::setContentSize(const Size & size)
|
2010-07-07 15:24:44 +08:00
|
|
|
{
|
2014-12-23 18:07:22 +08:00
|
|
|
if (! size.equals(_contentSize))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_contentSize = size;
|
2011-01-04 17:46:23 +08:00
|
|
|
|
2015-04-20 01:40:52 +08:00
|
|
|
_anchorPointInPoints.set(_contentSize.width * _anchorPoint.x, _contentSize.height * _anchorPoint.y);
|
2014-05-31 07:42:05 +08:00
|
|
|
_transformUpdated = _transformDirty = _inverseDirty = _contentSizeDirty = true;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2010-07-07 15:24:44 +08:00
|
|
|
}
|
|
|
|
|
2011-01-31 06:59:03 +08:00
|
|
|
// isRunning getter
|
2013-07-04 08:22:15 +08:00
|
|
|
bool Node::isRunning() const
|
2010-07-07 15:24:44 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _running;
|
2010-07-07 15:24:44 +08:00
|
|
|
}
|
|
|
|
|
2010-07-12 17:56:06 +08:00
|
|
|
/// parent setter
|
2014-05-28 17:41:34 +08:00
|
|
|
void Node::setParent(Node * parent)
|
2010-07-07 15:24:44 +08:00
|
|
|
{
|
2014-05-28 17:41:34 +08:00
|
|
|
_parent = parent;
|
2014-06-07 16:25:20 +08:00
|
|
|
_transformUpdated = _transformDirty = _inverseDirty = true;
|
2010-07-07 15:24:44 +08:00
|
|
|
}
|
|
|
|
|
2010-07-12 17:56:06 +08:00
|
|
|
/// isRelativeAnchorPoint getter
|
2013-07-04 08:22:15 +08:00
|
|
|
bool Node::isIgnoreAnchorPointForPosition() const
|
2010-07-07 15:24:44 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _ignoreAnchorPointForPosition;
|
2010-07-07 15:24:44 +08:00
|
|
|
}
|
2016-04-22 20:36:02 +08:00
|
|
|
|
2010-07-12 17:56:06 +08:00
|
|
|
/// isRelativeAnchorPoint setter
|
2016-04-22 20:36:02 +08:00
|
|
|
void Node::setIgnoreAnchorPointForPosition(bool newValue)
|
2010-07-07 15:24:44 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
if (newValue != _ignoreAnchorPointForPosition)
|
2012-06-08 14:17:39 +08:00
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
_ignoreAnchorPointForPosition = newValue;
|
2014-03-01 08:10:48 +08:00
|
|
|
_transformUpdated = _transformDirty = _inverseDirty = true;
|
2015-01-08 10:22:45 +08:00
|
|
|
}
|
2010-12-18 16:12:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// tag getter
|
2013-06-20 14:13:12 +08:00
|
|
|
int Node::getTag() const
|
2010-12-18 16:12:59 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _tag;
|
2010-12-18 16:12:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// tag setter
|
2014-05-28 17:41:34 +08:00
|
|
|
void Node::setTag(int tag)
|
2010-12-18 16:12:59 +08:00
|
|
|
{
|
2014-05-28 17:41:34 +08:00
|
|
|
_tag = tag ;
|
2010-12-18 16:12:59 +08:00
|
|
|
}
|
|
|
|
|
2015-10-06 03:42:07 +08:00
|
|
|
const std::string& Node::getName() const
|
2014-06-11 16:57:43 +08:00
|
|
|
{
|
|
|
|
return _name;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Node::setName(const std::string& name)
|
|
|
|
{
|
|
|
|
_name = name;
|
|
|
|
std::hash<std::string> h;
|
|
|
|
_hashOfName = h(name);
|
|
|
|
}
|
|
|
|
|
2010-07-12 17:56:06 +08:00
|
|
|
/// userData setter
|
2014-05-28 17:41:34 +08:00
|
|
|
void Node::setUserData(void *userData)
|
2010-07-07 15:24:44 +08:00
|
|
|
{
|
2014-05-28 17:41:34 +08:00
|
|
|
_userData = userData;
|
2010-07-07 15:24:44 +08:00
|
|
|
}
|
2010-12-18 16:12:59 +08:00
|
|
|
|
2015-06-03 07:56:59 +08:00
|
|
|
void Node::setUserObject(Ref* userObject)
|
2012-11-14 18:05:15 +08:00
|
|
|
{
|
2015-12-17 21:55:47 +08:00
|
|
|
#if CC_ENABLE_GC_FOR_NATIVE_OBJECTS
|
|
|
|
auto sEngine = ScriptEngineManager::getInstance()->getScriptEngine();
|
2016-02-16 13:43:11 +08:00
|
|
|
if (sEngine)
|
|
|
|
{
|
|
|
|
if (userObject)
|
|
|
|
sEngine->retainScriptObject(this, userObject);
|
|
|
|
if (_userObject)
|
|
|
|
sEngine->releaseScriptObject(this, _userObject);
|
|
|
|
}
|
2015-12-17 21:55:47 +08:00
|
|
|
#endif // CC_ENABLE_GC_FOR_NATIVE_OBJECTS
|
2014-05-28 17:41:34 +08:00
|
|
|
CC_SAFE_RETAIN(userObject);
|
2013-06-20 22:51:54 +08:00
|
|
|
CC_SAFE_RELEASE(_userObject);
|
2014-05-28 17:41:34 +08:00
|
|
|
_userObject = userObject;
|
2012-11-14 18:05:15 +08:00
|
|
|
}
|
|
|
|
|
2014-06-17 11:43:03 +08:00
|
|
|
Scene* Node::getScene() const
|
2013-12-22 04:28:49 +08:00
|
|
|
{
|
2014-12-23 18:07:22 +08:00
|
|
|
if (!_parent)
|
2013-12-22 04:28:49 +08:00
|
|
|
return nullptr;
|
2014-02-27 15:12:57 +08:00
|
|
|
|
2014-11-24 15:27:20 +08:00
|
|
|
auto sceneNode = _parent;
|
|
|
|
while (sceneNode->_parent)
|
|
|
|
{
|
|
|
|
sceneNode = sceneNode->_parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
return dynamic_cast<Scene*>(sceneNode);
|
2013-12-22 04:28:49 +08:00
|
|
|
}
|
|
|
|
|
2013-07-17 09:16:04 +08:00
|
|
|
Rect Node::getBoundingBox() const
|
2010-07-20 14:29:18 +08:00
|
|
|
{
|
2014-12-23 18:07:22 +08:00
|
|
|
Rect rect(0, 0, _contentSize.width, _contentSize.height);
|
2013-12-10 09:32:51 +08:00
|
|
|
return RectApplyAffineTransform(rect, getNodeToParentAffineTransform());
|
2010-07-20 14:29:18 +08:00
|
|
|
}
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2014-08-29 05:56:15 +08:00
|
|
|
// MARK: Children logic
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2013-11-28 17:57:13 +08:00
|
|
|
// lazy allocs
|
2014-05-28 17:41:34 +08:00
|
|
|
void Node::childrenAlloc()
|
2013-11-28 17:57:13 +08:00
|
|
|
{
|
2013-12-05 10:35:10 +08:00
|
|
|
_children.reserve(4);
|
2013-11-28 17:57:13 +08:00
|
|
|
}
|
|
|
|
|
2014-05-17 15:40:36 +08:00
|
|
|
Node* Node::getChildByTag(int tag) const
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2015-06-03 07:56:59 +08:00
|
|
|
CCASSERT(tag != Node::INVALID_TAG, "Invalid tag");
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2015-06-03 07:56:59 +08:00
|
|
|
for (const auto child : _children)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
if(child && child->_tag == tag)
|
2013-11-28 16:02:03 +08:00
|
|
|
return child;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2013-11-28 16:02:03 +08:00
|
|
|
return nullptr;
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2014-06-11 16:57:43 +08:00
|
|
|
Node* Node::getChildByName(const std::string& name) const
|
|
|
|
{
|
2015-09-01 11:26:09 +08:00
|
|
|
CCASSERT(!name.empty(), "Invalid name");
|
2014-06-11 16:57:43 +08:00
|
|
|
|
|
|
|
std::hash<std::string> h;
|
|
|
|
size_t hash = h(name);
|
|
|
|
|
2014-06-12 10:41:08 +08:00
|
|
|
for (const auto& child : _children)
|
2014-06-11 16:57:43 +08:00
|
|
|
{
|
|
|
|
// Different strings may have the same hash code, but can use it to compare first for speed
|
|
|
|
if(child->_hashOfName == hash && child->_name.compare(name) == 0)
|
|
|
|
return child;
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-06-17 11:43:03 +08:00
|
|
|
void Node::enumerateChildren(const std::string &name, std::function<bool (Node *)> callback) const
|
2014-06-12 10:41:08 +08:00
|
|
|
{
|
2015-09-01 11:26:09 +08:00
|
|
|
CCASSERT(!name.empty(), "Invalid name");
|
2014-06-17 11:43:03 +08:00
|
|
|
CCASSERT(callback != nullptr, "Invalid callback function");
|
2014-06-12 10:41:08 +08:00
|
|
|
|
2014-06-17 11:43:03 +08:00
|
|
|
size_t length = name.length();
|
2014-06-12 10:41:08 +08:00
|
|
|
|
2014-06-17 11:43:03 +08:00
|
|
|
size_t subStrStartPos = 0; // sub string start index
|
|
|
|
size_t subStrlength = length; // sub string length
|
|
|
|
|
2014-07-10 11:07:39 +08:00
|
|
|
// Starts with '//'?
|
|
|
|
bool searchRecursively = false;
|
|
|
|
if (length > 2 && name[0] == '/' && name[1] == '/')
|
2014-06-12 10:41:08 +08:00
|
|
|
{
|
2014-07-10 11:07:39 +08:00
|
|
|
searchRecursively = true;
|
|
|
|
subStrStartPos = 2;
|
|
|
|
subStrlength -= 2;
|
2014-06-17 11:43:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// End with '/..'?
|
2014-07-02 17:07:36 +08:00
|
|
|
bool searchFromParent = false;
|
|
|
|
if (length > 3 &&
|
|
|
|
name[length-3] == '/' &&
|
|
|
|
name[length-2] == '.' &&
|
|
|
|
name[length-1] == '.')
|
|
|
|
{
|
|
|
|
searchFromParent = true;
|
|
|
|
subStrlength -= 3;
|
|
|
|
}
|
|
|
|
|
2014-07-10 11:07:39 +08:00
|
|
|
// Remove '//', '/..' if exist
|
2014-06-17 11:43:03 +08:00
|
|
|
std::string newName = name.substr(subStrStartPos, subStrlength);
|
2019-10-17 11:12:25 +08:00
|
|
|
|
|
|
|
const Node* target = this;
|
|
|
|
|
2014-07-02 17:07:36 +08:00
|
|
|
if (searchFromParent)
|
|
|
|
{
|
2019-10-17 11:12:25 +08:00
|
|
|
if (nullptr == _parent)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
target = _parent;
|
2014-07-02 17:07:36 +08:00
|
|
|
}
|
2014-06-17 11:43:03 +08:00
|
|
|
|
2014-07-10 11:07:39 +08:00
|
|
|
if (searchRecursively)
|
2014-06-17 11:43:03 +08:00
|
|
|
{
|
|
|
|
// name is '//xxx'
|
2019-10-17 11:12:25 +08:00
|
|
|
target->doEnumerateRecursive(target, newName, callback);
|
2014-06-17 11:43:03 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// name is xxx
|
2019-10-17 11:12:25 +08:00
|
|
|
target->doEnumerate(newName, callback);
|
2014-06-17 11:43:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Node::doEnumerateRecursive(const Node* node, const std::string &name, std::function<bool (Node *)> callback) const
|
|
|
|
{
|
|
|
|
bool ret =false;
|
|
|
|
|
|
|
|
if (node->doEnumerate(name, callback))
|
|
|
|
{
|
|
|
|
// search itself
|
|
|
|
ret = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// search its children
|
|
|
|
for (const auto& child : node->getChildren())
|
2014-06-12 10:41:08 +08:00
|
|
|
{
|
2014-06-17 11:43:03 +08:00
|
|
|
if (doEnumerateRecursive(child, name, callback))
|
|
|
|
{
|
|
|
|
ret = true;
|
2014-06-12 10:41:08 +08:00
|
|
|
break;
|
2014-06-17 11:43:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Node::doEnumerate(std::string name, std::function<bool (Node *)> callback) const
|
|
|
|
{
|
|
|
|
// name may be xxx/yyy, should find its parent
|
|
|
|
size_t pos = name.find('/');
|
|
|
|
std::string searchName = name;
|
|
|
|
bool needRecursive = false;
|
|
|
|
if (pos != name.npos)
|
|
|
|
{
|
|
|
|
searchName = name.substr(0, pos);
|
|
|
|
name.erase(0, pos+1);
|
|
|
|
needRecursive = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ret = false;
|
2016-03-17 05:03:33 +08:00
|
|
|
for (const auto& child : getChildren())
|
2014-06-17 11:43:03 +08:00
|
|
|
{
|
2014-07-02 17:07:36 +08:00
|
|
|
if (std::regex_match(child->_name, std::regex(searchName)))
|
2014-06-17 11:43:03 +08:00
|
|
|
{
|
|
|
|
if (!needRecursive)
|
|
|
|
{
|
|
|
|
// terminate enumeration if callback return true
|
|
|
|
if (callback(child))
|
|
|
|
{
|
|
|
|
ret = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = child->doEnumerate(name, callback);
|
|
|
|
if (ret)
|
|
|
|
break;
|
|
|
|
}
|
2014-06-12 10:41:08 +08:00
|
|
|
}
|
|
|
|
}
|
2014-06-17 11:43:03 +08:00
|
|
|
|
|
|
|
return ret;
|
2014-06-12 10:41:08 +08:00
|
|
|
}
|
|
|
|
|
2010-07-09 18:24:08 +08:00
|
|
|
/* "add" logic MUST only be on this method
|
2012-09-17 15:02:24 +08:00
|
|
|
* If a class want's to extend the 'addChild' behavior it only needs
|
2010-07-09 18:24:08 +08:00
|
|
|
* to override this method
|
|
|
|
*/
|
2014-06-25 11:27:48 +08:00
|
|
|
void Node::addChild(Node *child, int localZOrder, int tag)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
CCASSERT( child != nullptr, "Argument must be non-nil");
|
|
|
|
CCASSERT( child->_parent == nullptr, "child already added. It can't be added again");
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2014-06-25 11:27:48 +08:00
|
|
|
addChildHelper(child, localZOrder, tag, "", true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Node::addChild(Node* child, int localZOrder, const std::string &name)
|
|
|
|
{
|
|
|
|
CCASSERT(child != nullptr, "Argument must be non-nil");
|
|
|
|
CCASSERT(child->_parent == nullptr, "child already added. It can't be added again");
|
|
|
|
|
|
|
|
addChildHelper(child, localZOrder, INVALID_TAG, name, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Node::addChildHelper(Node* child, int localZOrder, int tag, const std::string &name, bool setTag)
|
|
|
|
{
|
2017-02-08 10:02:10 +08:00
|
|
|
auto assertNotSelfChild
|
|
|
|
( [ this, child ]() -> bool
|
|
|
|
{
|
|
|
|
for ( Node* parent( getParent() ); parent != nullptr;
|
|
|
|
parent = parent->getParent() )
|
|
|
|
if ( parent == child )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
} );
|
|
|
|
(void)assertNotSelfChild;
|
|
|
|
|
|
|
|
CCASSERT( assertNotSelfChild(),
|
|
|
|
"A node cannot be the child of his own children" );
|
|
|
|
|
2013-11-28 18:23:06 +08:00
|
|
|
if (_children.empty())
|
2013-11-28 17:57:13 +08:00
|
|
|
{
|
|
|
|
this->childrenAlloc();
|
|
|
|
}
|
2014-06-25 11:27:48 +08:00
|
|
|
|
|
|
|
this->insertChild(child, localZOrder);
|
|
|
|
|
|
|
|
if (setTag)
|
|
|
|
child->setTag(tag);
|
|
|
|
else
|
|
|
|
child->setName(name);
|
|
|
|
|
2014-04-15 03:21:18 +08:00
|
|
|
child->setParent(this);
|
2016-07-01 10:09:25 +08:00
|
|
|
|
2016-07-31 22:44:24 +08:00
|
|
|
child->updateOrderOfArrival();
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
if( _running )
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
child->onEnter();
|
2013-05-27 20:46:15 +08:00
|
|
|
// prevent onEnterTransitionDidFinish to be called twice when a node is added in onEnter
|
2014-12-23 18:07:22 +08:00
|
|
|
if (_isTransitionFinished)
|
|
|
|
{
|
2013-05-27 20:46:15 +08:00
|
|
|
child->onEnterTransitionDidFinish();
|
|
|
|
}
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2013-12-06 18:07:16 +08:00
|
|
|
|
|
|
|
if (_cascadeColorEnabled)
|
|
|
|
{
|
|
|
|
updateCascadeColor();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_cascadeOpacityEnabled)
|
|
|
|
{
|
|
|
|
updateCascadeOpacity();
|
|
|
|
}
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::addChild(Node *child, int zOrder)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
CCASSERT( child != nullptr, "Argument must be non-nil");
|
2014-06-25 11:27:48 +08:00
|
|
|
this->addChild(child, zOrder, child->_name);
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::addChild(Node *child)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
CCASSERT( child != nullptr, "Argument must be non-nil");
|
2016-07-31 22:44:24 +08:00
|
|
|
this->addChild(child, child->getLocalZOrder(), child->_name);
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::removeFromParent()
|
2012-11-09 12:08:18 +08:00
|
|
|
{
|
|
|
|
this->removeFromParentAndCleanup(true);
|
2012-11-05 18:41:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::removeFromParentAndCleanup(bool cleanup)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
if (_parent != nullptr)
|
2012-05-02 12:04:27 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_parent->removeChild(this,cleanup);
|
2012-05-02 12:04:27 +08:00
|
|
|
}
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* "remove" logic MUST only be on this method
|
|
|
|
* If a class want's to extend the 'removeChild' behavior it only needs
|
|
|
|
* to override this method
|
|
|
|
*/
|
2013-07-19 14:57:54 +08:00
|
|
|
void Node::removeChild(Node* child, bool cleanup /* = true */)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
// explicit nil handling
|
2013-11-28 18:23:06 +08:00
|
|
|
if (_children.empty())
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2013-12-12 12:07:20 +08:00
|
|
|
ssize_t index = _children.getIndex(child);
|
2013-08-27 09:04:51 +08:00
|
|
|
if( index != CC_INVALID_INDEX )
|
|
|
|
this->detachChild( child, index, cleanup );
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2013-07-19 14:57:54 +08:00
|
|
|
void Node::removeChildByTag(int tag, bool cleanup/* = true */)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2013-08-29 03:42:25 +08:00
|
|
|
CCASSERT( tag != Node::INVALID_TAG, "Invalid tag");
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
Node *child = this->getChildByTag(tag);
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
if (child == nullptr)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-04-28 03:15:00 +08:00
|
|
|
CCLOG("cocos2d: removeChildByTag(tag = %d): child not found!", tag);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->removeChild(child, cleanup);
|
|
|
|
}
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2014-06-25 11:27:48 +08:00
|
|
|
void Node::removeChildByName(const std::string &name, bool cleanup)
|
|
|
|
{
|
2015-09-01 11:26:09 +08:00
|
|
|
CCASSERT(!name.empty(), "Invalid name");
|
2014-06-25 11:27:48 +08:00
|
|
|
|
|
|
|
Node *child = this->getChildByName(name);
|
|
|
|
|
|
|
|
if (child == nullptr)
|
|
|
|
{
|
|
|
|
CCLOG("cocos2d: removeChildByName(name = %s): child not found!", name.c_str());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->removeChild(child, cleanup);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::removeAllChildren()
|
2012-11-05 18:41:52 +08:00
|
|
|
{
|
|
|
|
this->removeAllChildrenWithCleanup(true);
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::removeAllChildrenWithCleanup(bool cleanup)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
// not using detachChild improves speed here
|
2014-12-23 18:07:22 +08:00
|
|
|
for (const auto& child : _children)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-12-19 08:56:59 +08:00
|
|
|
// IMPORTANT:
|
|
|
|
// -1st do onExit
|
|
|
|
// -2nd cleanup
|
|
|
|
if(_running)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-12-19 08:56:59 +08:00
|
|
|
child->onExitTransitionDidStart();
|
|
|
|
child->onExit();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2013-12-19 08:56:59 +08:00
|
|
|
|
|
|
|
if (cleanup)
|
|
|
|
{
|
|
|
|
child->cleanup();
|
|
|
|
}
|
2015-12-17 21:55:47 +08:00
|
|
|
#if CC_ENABLE_GC_FOR_NATIVE_OBJECTS
|
2016-02-16 13:43:11 +08:00
|
|
|
auto sEngine = ScriptEngineManager::getInstance()->getScriptEngine();
|
|
|
|
if (sEngine)
|
|
|
|
{
|
|
|
|
sEngine->releaseScriptObject(this, child);
|
|
|
|
}
|
2015-12-17 21:55:47 +08:00
|
|
|
#endif // CC_ENABLE_GC_FOR_NATIVE_OBJECTS
|
2013-12-19 08:56:59 +08:00
|
|
|
// set parent nil at the end
|
|
|
|
child->setParent(nullptr);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 08:56:59 +08:00
|
|
|
_children.clear();
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2013-12-12 12:07:20 +08:00
|
|
|
void Node::detachChild(Node *child, ssize_t childIndex, bool doCleanup)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
// IMPORTANT:
|
|
|
|
// -1st do onExit
|
|
|
|
// -2nd cleanup
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_running)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
child->onExitTransitionDidStart();
|
|
|
|
child->onExit();
|
|
|
|
}
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// If you don't do cleanup, the child's actions will not get removed and the
|
|
|
|
// its scheduledSelectors_ dict will not get released!
|
|
|
|
if (doCleanup)
|
|
|
|
{
|
|
|
|
child->cleanup();
|
|
|
|
}
|
2015-12-17 21:55:47 +08:00
|
|
|
|
|
|
|
#if CC_ENABLE_GC_FOR_NATIVE_OBJECTS
|
2016-02-16 13:43:11 +08:00
|
|
|
auto sEngine = ScriptEngineManager::getInstance()->getScriptEngine();
|
|
|
|
if (sEngine)
|
|
|
|
{
|
|
|
|
sEngine->releaseScriptObject(this, child);
|
|
|
|
}
|
2015-12-17 21:55:47 +08:00
|
|
|
#endif // CC_ENABLE_GC_FOR_NATIVE_OBJECTS
|
2012-04-19 14:35:52 +08:00
|
|
|
// set parent nil at the end
|
2013-11-28 16:02:03 +08:00
|
|
|
child->setParent(nullptr);
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2013-12-11 17:53:45 +08:00
|
|
|
_children.erase(childIndex);
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// helper used by reorderChild & add
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::insertChild(Node* child, int z)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2015-12-17 21:55:47 +08:00
|
|
|
#if CC_ENABLE_GC_FOR_NATIVE_OBJECTS
|
2016-02-16 13:43:11 +08:00
|
|
|
auto sEngine = ScriptEngineManager::getInstance()->getScriptEngine();
|
|
|
|
if (sEngine)
|
|
|
|
{
|
|
|
|
sEngine->retainScriptObject(this, child);
|
|
|
|
}
|
2015-12-17 21:55:47 +08:00
|
|
|
#endif // CC_ENABLE_GC_FOR_NATIVE_OBJECTS
|
2014-05-13 14:28:20 +08:00
|
|
|
_transformUpdated = true;
|
2013-06-15 14:03:30 +08:00
|
|
|
_reorderChildDirty = true;
|
2013-12-05 10:35:10 +08:00
|
|
|
_children.pushBack(child);
|
2016-07-31 22:44:24 +08:00
|
|
|
child->_setLocalZOrder(z);
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::reorderChild(Node *child, int zOrder)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
CCASSERT( child != nullptr, "Child must be non-nil");
|
2013-06-15 14:03:30 +08:00
|
|
|
_reorderChildDirty = true;
|
2016-07-31 22:44:24 +08:00
|
|
|
child->updateOrderOfArrival();
|
|
|
|
child->_setLocalZOrder(zOrder);
|
2012-03-14 14:55:17 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::sortAllChildren()
|
2012-04-04 21:58:04 +08:00
|
|
|
{
|
2014-12-23 18:07:22 +08:00
|
|
|
if (_reorderChildDirty)
|
|
|
|
{
|
2016-07-31 22:44:24 +08:00
|
|
|
sortNodes(_children);
|
2013-08-25 01:56:07 +08:00
|
|
|
_reorderChildDirty = false;
|
2016-12-14 14:08:00 +08:00
|
|
|
_eventDispatcher->setDirtyForNode(this);
|
2013-08-25 01:56:07 +08:00
|
|
|
}
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2014-08-29 05:56:15 +08:00
|
|
|
// MARK: draw / visit
|
|
|
|
|
2014-02-28 13:43:54 +08:00
|
|
|
void Node::draw()
|
|
|
|
{
|
2015-01-13 10:28:25 +08:00
|
|
|
auto renderer = _director->getRenderer();
|
2018-08-06 13:46:31 +08:00
|
|
|
draw(renderer, _modelViewTransform, FLAGS_TRANSFORM_DIRTY);
|
2014-02-28 13:43:54 +08:00
|
|
|
}
|
|
|
|
|
2016-11-09 10:34:50 +08:00
|
|
|
void Node::draw(Renderer* /*renderer*/, const Mat4 & /*transform*/, uint32_t /*flags*/)
|
2014-02-28 13:43:54 +08:00
|
|
|
{
|
|
|
|
}
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::visit()
|
2014-02-28 13:43:54 +08:00
|
|
|
{
|
2015-01-13 10:28:25 +08:00
|
|
|
auto renderer = _director->getRenderer();
|
|
|
|
auto& parentTransform = _director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
|
2018-08-06 13:46:31 +08:00
|
|
|
visit(renderer, parentTransform, FLAGS_TRANSFORM_DIRTY);
|
2014-02-28 13:43:54 +08:00
|
|
|
}
|
|
|
|
|
2014-05-31 07:42:05 +08:00
|
|
|
uint32_t Node::processParentFlags(const Mat4& parentTransform, uint32_t parentFlags)
|
|
|
|
{
|
2014-12-23 18:07:22 +08:00
|
|
|
if(_usingNormalizedPosition)
|
|
|
|
{
|
2016-10-27 09:45:40 +08:00
|
|
|
CCASSERT(_parent, "setPositionNormalized() doesn't work with orphan nodes");
|
2014-12-23 18:07:22 +08:00
|
|
|
if ((parentFlags & FLAGS_CONTENT_SIZE_DIRTY) || _normalizedPositionDirty)
|
|
|
|
{
|
|
|
|
auto& s = _parent->getContentSize();
|
2014-08-06 14:38:58 +08:00
|
|
|
_position.x = _normalizedPosition.x * s.width;
|
|
|
|
_position.y = _normalizedPosition.y * s.height;
|
|
|
|
_transformUpdated = _transformDirty = _inverseDirty = true;
|
|
|
|
_normalizedPositionDirty = false;
|
|
|
|
}
|
|
|
|
}
|
2015-05-22 13:59:45 +08:00
|
|
|
|
2016-07-15 05:58:04 +08:00
|
|
|
// Fixes Github issue #16100. Basically when having two cameras, one camera might set as dirty the
|
|
|
|
// node that is not visited by it, and might affect certain calculations. Besides, it is faster to do this.
|
|
|
|
if (!isVisitableByVisitingCamera())
|
|
|
|
return parentFlags;
|
|
|
|
|
2014-05-31 07:42:05 +08:00
|
|
|
uint32_t flags = parentFlags;
|
2014-05-31 12:50:39 +08:00
|
|
|
flags |= (_transformUpdated ? FLAGS_TRANSFORM_DIRTY : 0);
|
|
|
|
flags |= (_contentSizeDirty ? FLAGS_CONTENT_SIZE_DIRTY : 0);
|
2014-08-06 14:38:58 +08:00
|
|
|
|
2014-05-31 07:42:05 +08:00
|
|
|
|
2014-05-31 12:50:39 +08:00
|
|
|
if(flags & FLAGS_DIRTY_MASK)
|
2014-05-31 07:42:05 +08:00
|
|
|
_modelViewTransform = this->transform(parentTransform);
|
2015-01-27 16:13:45 +08:00
|
|
|
|
2014-05-31 07:42:05 +08:00
|
|
|
_transformUpdated = false;
|
|
|
|
_contentSizeDirty = false;
|
|
|
|
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
2014-08-14 10:26:37 +08:00
|
|
|
bool Node::isVisitableByVisitingCamera() const
|
2014-08-13 12:06:51 +08:00
|
|
|
{
|
|
|
|
auto camera = Camera::getVisitingCamera();
|
2015-01-23 09:02:33 +08:00
|
|
|
bool visibleByCamera = camera ? ((unsigned short)camera->getCameraFlag() & _cameraMask) != 0 : true;
|
2014-08-13 12:06:51 +08:00
|
|
|
return visibleByCamera;
|
|
|
|
}
|
|
|
|
|
2014-05-31 07:42:05 +08:00
|
|
|
void Node::visit(Renderer* renderer, const Mat4 &parentTransform, uint32_t parentFlags)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
// quick return if not visible. children won't be drawn.
|
2013-06-15 14:03:30 +08:00
|
|
|
if (!_visible)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2010-08-17 14:25:41 +08:00
|
|
|
|
2014-05-31 07:42:05 +08:00
|
|
|
uint32_t flags = processParentFlags(parentTransform, parentFlags);
|
2014-03-01 03:20:53 +08:00
|
|
|
|
|
|
|
// IMPORTANT:
|
2014-05-15 01:07:09 +08:00
|
|
|
// To ease the migration to v3.0, we still support the Mat4 stack,
|
2014-03-01 03:20:53 +08:00
|
|
|
// but it is deprecated and your code should not rely on it
|
2015-01-13 10:28:25 +08:00
|
|
|
_director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
|
|
|
|
_director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform);
|
2014-08-07 15:23:31 +08:00
|
|
|
|
2014-08-14 10:26:37 +08:00
|
|
|
bool visibleByCamera = isVisitableByVisitingCamera();
|
2014-02-28 13:43:54 +08:00
|
|
|
|
2013-12-05 17:19:01 +08:00
|
|
|
int i = 0;
|
2010-08-04 10:36:37 +08:00
|
|
|
|
2013-11-28 18:23:06 +08:00
|
|
|
if(!_children.empty())
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
sortAllChildren();
|
|
|
|
// draw children zOrder < 0
|
2016-10-27 15:10:24 +08:00
|
|
|
for(auto size = _children.size(); i < size; ++i)
|
2011-04-21 14:46:15 +08:00
|
|
|
{
|
2013-12-05 10:35:10 +08:00
|
|
|
auto node = _children.at(i);
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2016-07-29 10:58:31 +08:00
|
|
|
if (node && node->_localZOrder < 0)
|
2014-05-31 07:42:05 +08:00
|
|
|
node->visit(renderer, _modelViewTransform, flags);
|
2012-04-19 14:35:52 +08:00
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// self draw
|
2014-08-07 15:23:31 +08:00
|
|
|
if (visibleByCamera)
|
|
|
|
this->draw(renderer, _modelViewTransform, flags);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2016-10-27 15:10:24 +08:00
|
|
|
for(auto it=_children.cbegin()+i, itCend = _children.cend(); it != itCend; ++it)
|
2014-05-31 07:42:05 +08:00
|
|
|
(*it)->visit(renderer, _modelViewTransform, flags);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2014-08-13 12:06:51 +08:00
|
|
|
else if (visibleByCamera)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2014-08-13 12:06:51 +08:00
|
|
|
this->draw(renderer, _modelViewTransform, flags);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2015-01-13 10:28:25 +08:00
|
|
|
_director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
|
2014-06-19 15:09:27 +08:00
|
|
|
|
|
|
|
// FIX ME: Why need to set _orderOfArrival to 0??
|
|
|
|
// Please refer to https://github.com/cocos2d/cocos2d-x/pull/6920
|
|
|
|
// reset for next frame
|
|
|
|
// _orderOfArrival = 0;
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Mat4 Node::transform(const Mat4& parentTransform)
|
2013-10-18 15:34:13 +08:00
|
|
|
{
|
2014-12-23 18:07:22 +08:00
|
|
|
return parentTransform * this->getNodeToParentTransform();
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2014-08-29 05:56:15 +08:00
|
|
|
// MARK: events
|
|
|
|
|
2014-03-08 11:51:10 +08:00
|
|
|
void Node::onEnter()
|
|
|
|
{
|
2017-06-05 13:37:50 +08:00
|
|
|
if (!_running)
|
|
|
|
{
|
|
|
|
++__attachedNodeCount;
|
|
|
|
}
|
2013-12-30 11:10:02 +08:00
|
|
|
|
2015-07-28 16:05:47 +08:00
|
|
|
if (_onEnterCallback)
|
|
|
|
_onEnterCallback();
|
|
|
|
|
|
|
|
if (_componentContainer && !_componentContainer->isEmpty())
|
|
|
|
{
|
|
|
|
_componentContainer->onEnter();
|
|
|
|
}
|
|
|
|
|
2014-03-08 11:51:10 +08:00
|
|
|
_isTransitionFinished = false;
|
|
|
|
|
2013-12-30 11:10:02 +08:00
|
|
|
for( const auto &child: _children)
|
|
|
|
child->onEnter();
|
2014-03-08 11:51:10 +08:00
|
|
|
|
2013-12-30 11:10:02 +08:00
|
|
|
this->resume();
|
|
|
|
|
|
|
|
_running = true;
|
2014-03-08 11:51:10 +08:00
|
|
|
|
|
|
|
#if CC_ENABLE_SCRIPT_BINDING
|
2020-02-24 23:08:47 +08:00
|
|
|
ScriptEngineManager::sendNodeEventToLua(this, kNodeOnEnter);
|
2014-03-08 11:51:10 +08:00
|
|
|
#endif
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::onEnterTransitionDidFinish()
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2015-07-28 16:05:47 +08:00
|
|
|
if (_onEnterTransitionDidFinishCallback)
|
|
|
|
_onEnterTransitionDidFinishCallback();
|
2014-03-08 11:51:10 +08:00
|
|
|
|
|
|
|
_isTransitionFinished = true;
|
2013-12-30 11:10:02 +08:00
|
|
|
for( const auto &child: _children)
|
|
|
|
child->onEnterTransitionDidFinish();
|
2014-03-08 11:51:10 +08:00
|
|
|
|
|
|
|
#if CC_ENABLE_SCRIPT_BINDING
|
2020-02-24 23:08:47 +08:00
|
|
|
ScriptEngineManager::sendNodeEventToLua(this, kNodeOnEnterTransitionDidFinish);
|
2014-03-08 11:51:10 +08:00
|
|
|
#endif
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::onExitTransitionDidStart()
|
2012-04-04 21:58:04 +08:00
|
|
|
{
|
2015-07-28 16:05:47 +08:00
|
|
|
if (_onExitTransitionDidStartCallback)
|
|
|
|
_onExitTransitionDidStartCallback();
|
|
|
|
|
2013-12-19 08:56:59 +08:00
|
|
|
for( const auto &child: _children)
|
2013-11-28 16:02:03 +08:00
|
|
|
child->onExitTransitionDidStart();
|
2014-03-08 11:51:10 +08:00
|
|
|
|
2014-02-20 16:40:46 +08:00
|
|
|
#if CC_ENABLE_SCRIPT_BINDING
|
2020-02-24 23:08:47 +08:00
|
|
|
ScriptEngineManager::sendNodeEventToLua(this, kNodeOnExitTransitionDidStart);
|
2014-02-20 16:40:46 +08:00
|
|
|
#endif
|
2012-03-14 14:55:17 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::onExit()
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2017-06-05 13:37:50 +08:00
|
|
|
if (_running)
|
|
|
|
{
|
|
|
|
--__attachedNodeCount;
|
|
|
|
}
|
2014-03-08 11:51:10 +08:00
|
|
|
|
2015-07-28 16:05:47 +08:00
|
|
|
if (_onExitCallback)
|
|
|
|
_onExitCallback();
|
|
|
|
|
|
|
|
if (_componentContainer && !_componentContainer->isEmpty())
|
|
|
|
{
|
|
|
|
_componentContainer->onExit();
|
|
|
|
}
|
|
|
|
|
2013-10-26 15:04:01 +08:00
|
|
|
this->pause();
|
2014-03-08 11:51:10 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_running = false;
|
2014-03-08 11:51:10 +08:00
|
|
|
|
2013-12-30 11:10:02 +08:00
|
|
|
for( const auto &child: _children)
|
|
|
|
child->onExit();
|
|
|
|
|
2014-02-20 16:40:46 +08:00
|
|
|
#if CC_ENABLE_SCRIPT_BINDING
|
2020-02-24 23:08:47 +08:00
|
|
|
ScriptEngineManager::sendNodeEventToLua(this, kNodeOnExit);
|
2014-02-20 16:40:46 +08:00
|
|
|
#endif
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
2012-02-02 15:58:10 +08:00
|
|
|
|
2013-10-26 15:04:01 +08:00
|
|
|
void Node::setEventDispatcher(EventDispatcher* dispatcher)
|
|
|
|
{
|
|
|
|
if (dispatcher != _eventDispatcher)
|
|
|
|
{
|
2014-03-02 15:54:36 +08:00
|
|
|
_eventDispatcher->removeEventListenersForTarget(this);
|
2013-10-26 15:04:01 +08:00
|
|
|
CC_SAFE_RETAIN(dispatcher);
|
|
|
|
CC_SAFE_RELEASE(_eventDispatcher);
|
|
|
|
_eventDispatcher = dispatcher;
|
|
|
|
}
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
2012-02-02 15:58:10 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::setActionManager(ActionManager* actionManager)
|
2012-04-04 21:58:04 +08:00
|
|
|
{
|
2014-12-23 18:07:22 +08:00
|
|
|
if( actionManager != _actionManager )
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
this->stopAllActions();
|
|
|
|
CC_SAFE_RETAIN(actionManager);
|
2013-06-15 14:03:30 +08:00
|
|
|
CC_SAFE_RELEASE(_actionManager);
|
|
|
|
_actionManager = actionManager;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2014-08-29 05:56:15 +08:00
|
|
|
// MARK: actions
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
Action * Node::runAction(Action* action)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
CCASSERT( action != nullptr, "Argument must be non-nil");
|
2013-06-15 14:03:30 +08:00
|
|
|
_actionManager->addAction(action, this, !_running);
|
2012-04-19 14:35:52 +08:00
|
|
|
return action;
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::stopAllActions()
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_actionManager->removeAllActionsFromTarget(this);
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::stopAction(Action* action)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_actionManager->removeAction(action);
|
2010-08-06 09:46:56 +08:00
|
|
|
}
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::stopActionByTag(int tag)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2013-08-29 03:42:25 +08:00
|
|
|
CCASSERT( tag != Action::INVALID_TAG, "Invalid tag");
|
2013-06-15 14:03:30 +08:00
|
|
|
_actionManager->removeActionByTag(tag, this);
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2014-07-22 16:04:22 +08:00
|
|
|
void Node::stopAllActionsByTag(int tag)
|
|
|
|
{
|
|
|
|
CCASSERT( tag != Action::INVALID_TAG, "Invalid tag");
|
|
|
|
_actionManager->removeAllActionsByTag(tag, this);
|
|
|
|
}
|
|
|
|
|
2015-05-28 15:52:49 +08:00
|
|
|
void Node::stopActionsByFlags(unsigned int flags)
|
|
|
|
{
|
|
|
|
if (flags > 0)
|
|
|
|
{
|
|
|
|
_actionManager->removeActionsByFlags(flags, this);
|
|
|
|
}
|
2014-07-22 16:04:22 +08:00
|
|
|
}
|
|
|
|
|
2013-07-19 07:30:19 +08:00
|
|
|
Action * Node::getActionByTag(int tag)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2013-08-29 03:42:25 +08:00
|
|
|
CCASSERT( tag != Action::INVALID_TAG, "Invalid tag");
|
2013-06-15 14:03:30 +08:00
|
|
|
return _actionManager->getActionByTag(tag, this);
|
2010-08-06 09:46:56 +08:00
|
|
|
}
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2013-12-12 12:07:20 +08:00
|
|
|
ssize_t Node::getNumberOfRunningActions() const
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2013-07-18 07:56:19 +08:00
|
|
|
return _actionManager->getNumberOfRunningActionsInTarget(this);
|
2012-03-14 14:55:17 +08:00
|
|
|
}
|
|
|
|
|
2016-11-04 09:41:03 +08:00
|
|
|
ssize_t Node::getNumberOfRunningActionsByTag(int tag) const
|
|
|
|
{
|
|
|
|
return _actionManager->getNumberOfRunningActionsInTargetByTag(this, tag);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-29 05:56:15 +08:00
|
|
|
// MARK: Callbacks
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::setScheduler(Scheduler* scheduler)
|
2012-04-04 21:58:04 +08:00
|
|
|
{
|
2014-12-23 18:07:22 +08:00
|
|
|
if( scheduler != _scheduler )
|
|
|
|
{
|
2014-10-04 00:38:36 +08:00
|
|
|
this->unscheduleAllCallbacks();
|
2012-04-19 14:35:52 +08:00
|
|
|
CC_SAFE_RETAIN(scheduler);
|
2013-06-15 14:03:30 +08:00
|
|
|
CC_SAFE_RELEASE(_scheduler);
|
|
|
|
_scheduler = scheduler;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2017-05-22 09:25:18 +08:00
|
|
|
bool Node::isScheduled(SEL_SCHEDULE selector) const
|
2013-06-27 12:05:47 +08:00
|
|
|
{
|
2014-03-03 11:00:30 +08:00
|
|
|
return _scheduler->isScheduled(selector, this);
|
2013-06-27 12:05:47 +08:00
|
|
|
}
|
|
|
|
|
2017-05-22 09:25:18 +08:00
|
|
|
bool Node::isScheduled(const std::string &key) const
|
2014-10-03 12:25:55 +08:00
|
|
|
{
|
|
|
|
return _scheduler->isScheduled(key, this);
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::scheduleUpdate()
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
scheduleUpdateWithPriority(0);
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::scheduleUpdateWithPriority(int priority)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2014-03-03 11:00:30 +08:00
|
|
|
_scheduler->scheduleUpdate(this, priority, !_running);
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::scheduleUpdateWithPriorityLua(int nHandler, int priority)
|
2013-01-17 11:20:25 +08:00
|
|
|
{
|
|
|
|
unscheduleUpdate();
|
2014-02-20 16:40:46 +08:00
|
|
|
|
|
|
|
#if CC_ENABLE_SCRIPT_BINDING
|
2013-06-15 14:03:30 +08:00
|
|
|
_updateScriptHandler = nHandler;
|
2014-02-20 16:40:46 +08:00
|
|
|
#endif
|
2014-03-01 13:30:20 +08:00
|
|
|
|
2014-03-03 11:00:30 +08:00
|
|
|
_scheduler->scheduleUpdate(this, priority, !_running);
|
2013-01-17 11:20:25 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::unscheduleUpdate()
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2014-02-20 10:53:49 +08:00
|
|
|
_scheduler->unscheduleUpdate(this);
|
2014-02-20 16:40:46 +08:00
|
|
|
|
|
|
|
#if CC_ENABLE_SCRIPT_BINDING
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_updateScriptHandler)
|
2012-12-10 13:48:27 +08:00
|
|
|
{
|
2013-07-22 17:24:54 +08:00
|
|
|
ScriptEngineManager::getInstance()->getScriptEngine()->removeScriptHandler(_updateScriptHandler);
|
2013-06-15 14:03:30 +08:00
|
|
|
_updateScriptHandler = 0;
|
2012-12-10 13:48:27 +08:00
|
|
|
}
|
2014-02-20 16:40:46 +08:00
|
|
|
#endif
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::schedule(SEL_SCHEDULE selector)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2014-10-04 00:38:36 +08:00
|
|
|
this->schedule(selector, 0.0f, CC_REPEAT_FOREVER, 0.0f);
|
2012-03-14 14:55:17 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::schedule(SEL_SCHEDULE selector, float interval)
|
2012-04-04 21:58:04 +08:00
|
|
|
{
|
2014-10-04 00:38:36 +08:00
|
|
|
this->schedule(selector, interval, CC_REPEAT_FOREVER, 0.0f);
|
2010-07-14 11:52:27 +08:00
|
|
|
}
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::schedule(SEL_SCHEDULE selector, float interval, unsigned int repeat, float delay)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2013-07-20 13:01:27 +08:00
|
|
|
CCASSERT( selector, "Argument must be non-nil");
|
|
|
|
CCASSERT( interval >=0, "Argument must be positive");
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2014-03-03 11:00:30 +08:00
|
|
|
_scheduler->schedule(selector, this, interval , repeat, delay, !_running);
|
2012-03-14 14:55:17 +08:00
|
|
|
}
|
|
|
|
|
2014-10-04 00:38:36 +08:00
|
|
|
void Node::schedule(const std::function<void(float)> &callback, const std::string &key)
|
|
|
|
{
|
|
|
|
_scheduler->schedule(callback, this, 0, !_running, key);
|
|
|
|
}
|
|
|
|
|
2014-10-03 12:25:55 +08:00
|
|
|
void Node::schedule(const std::function<void(float)> &callback, float interval, const std::string &key)
|
|
|
|
{
|
|
|
|
_scheduler->schedule(callback, this, interval, !_running, key);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Node::schedule(const std::function<void(float)>& callback, float interval, unsigned int repeat, float delay, const std::string &key)
|
|
|
|
{
|
|
|
|
_scheduler->schedule(callback, this, interval, repeat, delay, !_running, key);
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::scheduleOnce(SEL_SCHEDULE selector, float delay)
|
2012-04-04 21:58:04 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
this->schedule(selector, 0.0f, 0, delay);
|
2010-07-14 11:52:27 +08:00
|
|
|
}
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2014-10-03 12:25:55 +08:00
|
|
|
void Node::scheduleOnce(const std::function<void(float)> &callback, float delay, const std::string &key)
|
|
|
|
{
|
|
|
|
_scheduler->schedule(callback, this, 0, 0, delay, !_running, key);
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::unschedule(SEL_SCHEDULE selector)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2014-02-20 10:53:49 +08:00
|
|
|
// explicit null handling
|
|
|
|
if (selector == nullptr)
|
2012-04-19 14:35:52 +08:00
|
|
|
return;
|
2014-02-20 10:53:49 +08:00
|
|
|
|
2014-03-03 11:00:30 +08:00
|
|
|
_scheduler->unschedule(selector, this);
|
2010-07-14 11:52:27 +08:00
|
|
|
}
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2014-10-03 12:25:55 +08:00
|
|
|
void Node::unschedule(const std::string &key)
|
|
|
|
{
|
|
|
|
_scheduler->unschedule(key, this);
|
|
|
|
}
|
|
|
|
|
2014-10-04 00:38:36 +08:00
|
|
|
void Node::unscheduleAllCallbacks()
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_scheduler->unscheduleAllForTarget(this);
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2013-10-26 15:04:01 +08:00
|
|
|
void Node::resume()
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_scheduler->resumeTarget(this);
|
|
|
|
_actionManager->resumeTarget(this);
|
2014-03-02 15:54:36 +08:00
|
|
|
_eventDispatcher->resumeEventListenersForTarget(this);
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2013-10-26 15:04:01 +08:00
|
|
|
void Node::pause()
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_scheduler->pauseTarget(this);
|
|
|
|
_actionManager->pauseTarget(this);
|
2014-03-02 15:54:36 +08:00
|
|
|
_eventDispatcher->pauseEventListenersForTarget(this);
|
2013-10-26 15:04:01 +08:00
|
|
|
}
|
|
|
|
|
2012-11-14 18:05:15 +08:00
|
|
|
// override me
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::update(float fDelta)
|
2012-11-14 18:05:15 +08:00
|
|
|
{
|
2014-02-20 16:40:46 +08:00
|
|
|
#if CC_ENABLE_SCRIPT_BINDING
|
2013-07-02 15:23:51 +08:00
|
|
|
if (0 != _updateScriptHandler)
|
2012-12-10 13:48:27 +08:00
|
|
|
{
|
2013-07-02 15:23:51 +08:00
|
|
|
//only lua use
|
2013-07-04 15:44:42 +08:00
|
|
|
SchedulerScriptData data(_updateScriptHandler,fDelta);
|
2013-07-02 15:23:51 +08:00
|
|
|
ScriptEvent event(kScheduleEvent,&data);
|
2020-02-24 23:08:47 +08:00
|
|
|
ScriptEngineManager::sendEventToLua(event);
|
2012-12-10 13:48:27 +08:00
|
|
|
}
|
2014-02-20 16:40:46 +08:00
|
|
|
#endif
|
2013-06-04 17:38:43 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_componentContainer && !_componentContainer->isEmpty())
|
2013-06-04 17:38:43 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_componentContainer->visit(fDelta);
|
2013-06-04 17:38:43 +08:00
|
|
|
}
|
2012-11-14 18:05:15 +08:00
|
|
|
}
|
|
|
|
|
2014-08-29 05:56:15 +08:00
|
|
|
// MARK: coordinates
|
|
|
|
|
2013-12-10 09:32:51 +08:00
|
|
|
AffineTransform Node::getNodeToParentAffineTransform() const
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2013-12-10 09:32:51 +08:00
|
|
|
AffineTransform ret;
|
2014-04-10 23:12:29 +08:00
|
|
|
GLToCGAffine(getNodeToParentTransform().m, &ret);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-12-10 09:32:51 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-07-20 10:03:15 +08:00
|
|
|
|
|
|
|
Mat4 Node::getNodeToParentTransform(Node* ancestor) const
|
|
|
|
{
|
|
|
|
Mat4 t(this->getNodeToParentTransform());
|
|
|
|
|
|
|
|
for (Node *p = _parent; p != nullptr && p != ancestor ; p = p->getParent())
|
|
|
|
{
|
|
|
|
t = p->getNodeToParentTransform() * t;
|
|
|
|
}
|
|
|
|
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
|
|
|
AffineTransform Node::getNodeToParentAffineTransform(Node* ancestor) const
|
|
|
|
{
|
|
|
|
AffineTransform t(this->getNodeToParentAffineTransform());
|
|
|
|
|
|
|
|
for (Node *p = _parent; p != nullptr && p != ancestor; p = p->getParent())
|
|
|
|
t = AffineTransformConcat(t, p->getNodeToParentAffineTransform());
|
|
|
|
|
|
|
|
return t;
|
|
|
|
}
|
2014-05-15 01:07:09 +08:00
|
|
|
const Mat4& Node::getNodeToParentTransform() const
|
2013-12-10 09:32:51 +08:00
|
|
|
{
|
|
|
|
if (_transformDirty)
|
2012-06-08 14:17:39 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
// Translate values
|
2013-06-15 14:03:30 +08:00
|
|
|
float x = _position.x;
|
|
|
|
float y = _position.y;
|
2014-02-23 11:16:42 +08:00
|
|
|
float z = _positionZ;
|
2015-01-20 14:10:11 +08:00
|
|
|
|
2013-12-10 09:32:51 +08:00
|
|
|
if (_ignoreAnchorPointForPosition)
|
2012-06-08 14:17:39 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
x += _anchorPointInPoints.x;
|
|
|
|
y += _anchorPointInPoints.y;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2015-01-20 14:10:11 +08:00
|
|
|
|
2014-12-24 17:07:54 +08:00
|
|
|
bool needsSkewMatrix = ( _skewX || _skewY );
|
2016-10-31 10:29:04 +08:00
|
|
|
|
2015-01-20 14:10:11 +08:00
|
|
|
// Build Transform Matrix = translation * rotation * scale
|
|
|
|
Mat4 translation;
|
|
|
|
//move to anchor point first, then rotate
|
2016-10-31 10:29:04 +08:00
|
|
|
Mat4::createTranslation(x, y, z, &translation);
|
2015-01-20 14:10:11 +08:00
|
|
|
|
2014-12-24 18:12:00 +08:00
|
|
|
Mat4::createRotation(_rotationQuat, &_transform);
|
2015-01-20 14:10:11 +08:00
|
|
|
|
2014-12-24 17:07:54 +08:00
|
|
|
if (_rotationZ_X != _rotationZ_Y)
|
2014-07-01 08:19:51 +08:00
|
|
|
{
|
2015-01-20 14:10:11 +08:00
|
|
|
// Rotation values
|
|
|
|
// Change rotation code to handle X and Y
|
|
|
|
// If we skew with the exact same value for both x and y then we're simply just rotating
|
|
|
|
float radiansX = -CC_DEGREES_TO_RADIANS(_rotationZ_X);
|
|
|
|
float radiansY = -CC_DEGREES_TO_RADIANS(_rotationZ_Y);
|
|
|
|
float cx = cosf(radiansX);
|
|
|
|
float sx = sinf(radiansX);
|
|
|
|
float cy = cosf(radiansY);
|
|
|
|
float sy = sinf(radiansY);
|
|
|
|
|
2014-12-24 17:07:54 +08:00
|
|
|
float m0 = _transform.m[0], m1 = _transform.m[1], m4 = _transform.m[4], m5 = _transform.m[5], m8 = _transform.m[8], m9 = _transform.m[9];
|
metal support for cocos2d-x (#19305)
* remove deprecated files
* remove some deprecated codes
* remove more deprecated codes
* remove ui deprecated codes
* remove more deprecated codes
* remove deprecated codes in ccmenuitem
* remove more deprecated codes in ui
* remove more deprecated codes in ui
* remove more deprecated codes in ui
* remove more deprecated codes
* remove more deprecated codes
* remove more deprecated codes
* remove vr related codes and ignore some modules
* remove allocator
* remove some config
* 【Feature】add back-end project file
* [Feature] add back-end file
* add pipeline descriptor and shader cache
* [Feature] support sprite for backend
* [Feature] remove unneeded code
* [Feature] according to es2.0 spec, you must use clamp-to-edge as texture wrap mode, and no mipmapping for non-power-of-two texture
* [Feature] set texture wrap mode to clamp-to-edge, and no mipmapping for non-power-of-two texture
* [Feature] remove macro define to .cpp file
* [Feature] add log info
* [Feature] add PipelineDescriptor for TriangleCommand
* [Feature] add PipelineDescriptor object as member of TriangleCommand
* [Feature] add getPipelineDescriptor method
* add renderbackend
* complete pipeline descriptor
* [Feature] add viewport in RenderCommand
* set viewport when rendrering
* [Feature] occur error when using RendererBackend, to be fixed.
* a workaround to fix black screen on macOS 10.14 (#19090)
* add rendererbackend init function
* fix typo
* [Feature] modify testFile
* [BugFix] modify shader path
* [Feature] set default viewport
* fix projection
* [Feature] modify log info
* [BugFix] change viewport data type to int
* [BugFix] add BindGroup to PipelienDescriptor
* [BugFix] change a_position to vec3 in sprite.vert
* [BugFix] set vertexLayout according to V3F_C4B_T2F structure
* [Feature] revert a_position to vec4
* [Feature] renderer should not use gl codes directly
* [Feature] it's better not use default value parameter
* fix depth test setting
* rendererbackend -> renderer
* clear color and depth at begin
* add metal backend
* metal support normalized attribute
* simplify codes
* update external
* add render pass desctriptor in pipeline descriptor
* fix warnings
* fix crash and memeory leak
* refactor Texture2D
* put pipeline descriptor into render command
* simplify codes
* [Feature] update Sprite
* fix crash when closing app
* [Feature] update SpriteBatchNode and TextureAtlas
* support render texture(not finish)
* [Feature] remove unused code
* make tests work on mac
* fix download-deps path error
* make tests work on iOS
* [Feature] support ttf under normal label effect
* refactor triangle command processing
* let renderer handle more common commands
* refactor backend
* make render texture work
* [Feature] refactor backend for GL
* [Feature]Renaming to make it easy to understand
* [Feature] change warp mode to CLAMP_TO_EDGE
* fix ghost
* simplify visit render queue logic
* support progress timer without rial mode
* support partcile system
* Feature/update label (#149)
* [BugFix] fix compile error
* [Feature] support outline effect in ios
* [Feature] add shader file
* [BugFix] fix begin and end RenderPass
* [Feature] update CustomCommand
* [Feature] revert project.pbxproj
* [Feature] simplify codes
* [BugFix] pack AI88 to RGBA8888 only when outline enable
* [Feature] support shadow effect in Label
* [Feature] support BMFont
* [Feature] support glow effect
* [Feature] simplify shader files
* LabelAtlas work
* handle blend function correctly
* support tile map
* don't share buffer in metal
* alloc buffer size as needed
* support more tilemap
* Merge branch 'minggo/metal-support' into feature/updateLabel
* minggo/metal-support:
support tile map
handle blend function correctly
LabelAtlas work
Feature/update label (#149)
support partcile system
# Conflicts:
# cocos/2d/CCLabel.cpp
# cocos/2d/CCSprite.cpp
# cocos/2d/CCSpriteBatchNode.cpp
# cocos/renderer/CCQuadCommand.cpp
# cocos/renderer/CCQuadCommand.h
* render texture work without saving file
* use global viewport
* grid3d works
* remove grabber
* tiled3d works
* [BugFix] fix label bug
* [Feature] add updateSubData for buffer
* [Feature] remove setVertexCount
* support depth test
* add callback command
* [Feature] add UITest
* [Feature] update UITest
* [Feature] remove unneeded codes
* fix custom command issue
* fix layer color blend issue
* [BugFix] fix iOS compile error
* [Feature] remove unneeded codes
* [Feature] fix updateVertexBuffer
* layerradial works
* add draw test back
* fix batch issue
* fix compiling error
* [BugFix] support ETC1
* [BugFix] get the correct pipelineDescriptor
* [BugFix] skip draw when backendTexture nullptr
* clipping node support
* [Feature] add shader files
* fix stencil issue in metal
* [Feature] update UILayoutTest
* [BugFix] skip drawing when vertexCount is zero
* refactor renderer
* add set global z order for stencil manager commands
* fix warnings caused by type
* remove viewport in render command
* [Feature] fix warnings caused by type
* [BugFix] clear vertexCount and indexCount for CustomComand when needed
* [Feature] update clear for CustomCommand
* ios use metal
* fix viewport issue
* fix LayerColorGradient crash
* [cmake] transport to android and windows (#160)
* save point 1
* compile on windows
* run on android
* revert useless change
* android set CC_ENABLE_CACHE_TEXTURE_DATA to 1
* add initGlew
* fix android crash
* add TODO new-renderer
* review update
* revert onGLFWWindowPosCallback
* fix android compiling error
* Impl progress radial (#162)
* progresstimer add radial impl
* default drawType to element
* dec invoke times of createVertexBuffer (#163)
* support depth/stencil format for gl backend
* simplify progress timer codes
* support motionstreak, effect is wrong
* fix motionstreak issue
* [Feature] update Scissor Test (#161)
* [Feature] update Scissor Test
* [Feature] update ScissorTest
* [Feature] rename function
* [Feature] get constant reference if needed
* [Feature] show render status (#164)
* improve performance
* fix depth state
* fill error that triangle vertex/index number bigger than buffer
* fix compiline error in release mode
* fix buffer conflict between CPU and GPU on iOS/macOS
* Renderer refactor (#165)
* use one vertes/index buffer with opengl
* fix error on windows
* custom command support index format config
* CCLayer: compact vertex data structure
* update comment
* fix doc
* support fast tilemap
* pass index format instead
* fix some wrong effect
* fix render texture error
* fix texture per-element size
* fix texture format error
* BlendFunc type refactor, GLenum -> backend::BlendFactor (#167)
* BlendFunc use backend::BlendFactor as inner field
* update comments
* use int to replace GLenum
* update xcode project fiel
* rename to GLBlendConst
* add ccConstants.h
* update xcode project file
* update copyright
* remove primitive command
* remove CCPrimitive.cpp/.h
* remove deprecated files
* remove unneeded files
* remove multiple view support
* remove multiple view support
* remove the usage of frame buffer in camera
* director don't use frame buffer
* remove FrameBuffer
* remove BatchCommand
* add some api reference
* add physics2d back
* fix crash when close app on mac
* improve render texture
* fix rendertexture issue
* fix rendertexture issue
* simplify codes
* CMake support for mac & ios (#169)
* update cmake
* fix compile error
* update 3rd libs version
* remove CCThread.h/.cpp
* remove ccthread
* use audio engine to implement simple audio engine
* remove unneeded codes
* remove deprecated codes
* remove winrt macro
* remove CC_USE_WIC
* set partcile blend function in more elegant way
* remove unneeded codes
* remove unneeded codes
* cmake works on windows
* update project setting
* improve performance
* GLFloat -> float
* sync v3 cmake improvements into metal-support (#172)
* pick: modern cmake, compile definitions improvement (#19139)
* modern cmake, use target_compile_definitions partly
* simplify macro define, remove USE_*
* modern cmake, macro define
* add physics 2d macro define into ccConfig.h
* remove USE_CHIPMUNK macro in build.gradle
* remove CocosSelectModule.cmake
* shrink useless define
* simplify compile options config, re-add if necessary
* update external for tmp CI test
* un-quote target_compile_options value
* add "-g" parameter only when debug mode
* keep single build type when generator Xcode & VS projecy
* update external for tmp CI tes
* add static_cast<char>(-1), fix -Wc++11-narrowing
* simplify win32 compile define
* not modify code, only improve compile options
# Conflicts:
# .gitignore
# cmake/Modules/CocosConfigDepend.cmake
# cocos/CMakeLists.txt
# external/config.json
# tests/cpp-tests/CMakeLists.txt
* modern cmake, improve cmake_compiler_flags (#19145)
* cmake_compiler_flags
* Fix typo
* Fix typo2
* Remove chanages from Android.mk
* correct lua template cmake build (#19149)
* don't add -Wno-deprecated into jsb target
* correct lua template cmake build
* fix win32 lua template compile error
* prevent cmake in-source-build friendly (#19151)
* pick: Copy resources to "Resources/" on win32 like in linux configuration
* add "/Z7" for cpp-tests on windows
* [cmake] fix iOS xcode property setting failed (#19208)
* fix iOS xcode property setting failed
* use search_depend_libs_recursive at dlls collect
* fix typo
* [cmake] add find_host_library into iOS toolchain file (#19230)
* pick: [lua android] use luajit & template cmake update (#19239)
* increase cmake stability , remove tests/CMakeLists.txt (#19261)
* cmake win32 Precompiled header (#19273)
* Precompiled header
* Fix
* Precompiled header for cocos
* Precompiled header jscocos2d
* Fix for COCOS2D_DEBUG is always 1 on Android (#19291)
Related #19289
* little build fix, tests cpp-tests works on mac
* sync v3 build related codes into metal-support (#173)
* strict initialization for std::array
* remove proj.win32 project configs
* modern cmake, cmake_cleanup_remove_unused_variables (#19146)
* Switch travis CI to xenial (#19207)
* Switch travis CI to xenial
* Remove language: android
* Set language: cpp
* Fix java problem
* Update sdkmanager
* Fix sdkmanger
* next sdkmanager fix
* Remove xenial from android
* revert to sdk-tools-{system}-3859397
* Remove linux cmake install
* Update before-install.sh
* Update .travis.yml
* Simplify install-deps-linux.sh, tested on Ubuntu 16.04 (#19212)
* Simplify install-deps-linux.sh
* Cleanup
* pick: install ninja
* update cocos2d-console submodule
* for metal-support alpha release, we only test cpp
* add HelloCpp into project(Cocos2d-x) for tmp test
* update extenal metal-support-4
* update uniform setting
* [Feature] update BindGroup
* [Feature] empty-test
* [Feature] cpp-test
* [Feature] fix GL compiler error
* [Feature] fix GL crash
* [Feature] empty-test
* [Feature] cpp-tests
* [feature] improve frameRate
* [feature] fix opengl compile error
* [feature] fix opengl compile error
* [BugFix] fix compute maxLocation error
* [Feature] update setting unifrom
* [Feature] fix namespace
* [Feature] remove unneeded code
* [Bugfix] fix project file
* [Feature] update review
* [texture2d] impl texture format support (#175)
* texture update
* update
* update texture
* commit
* compile on windows
* ddd
* rename
* rename methods
* no crash
* save gl
* save
* save
* rename
* move out pixel format convert functions
* metal crash
* update
* update android
* support gles compressed texture format
* support more compress format
* add more conversion methods
* ss
* save
* update conversion methods
* add PVRTC format support
* reformat
* add marco linux
* fix GL marcro
* pvrtc supported only by ios 8.0+
* remove unused cmake
* revert change
* refactor Texture2D::initWithData
* fix conversion log
* refactor Texture2D::initWithData
* remove some OpenGL constants for PVRTC
* add todo
* fix typo
* AutoTest works on mac/iOS by disable part cases, sync v3 bug fix (#174)
* review cpp-tests, and fix part issues on start auto test
* sync png format fix: Node:Particle3D abnormal texture effects #19204
* fix cpp-tests SpritePolygon crash, wrong png format (#19170)
* fix wrong png convert format from sRGB to Gray
* erase plist index if all frames was erased
* test_A8.png have I8 format, fix it
* [CCSpriteCache] allow re-add plist & add testcase (#19175)
* allow re-add plist & add testcase
* remove comments/rename method/update testcase
* fix isSpriteFramesWithFileLoaded & add testcase
* remove used variable
* remove unused variable
* fix double free issues when js/lua-tests exit on iOS (#19236)
* disable part cases, AutoTest works without crash on mac
* update cocos2dx files json, to test cocos new next
* fix spritecache plist parsing issue (#19269)
* [linux] Fix FileUtils::getContents with folder (#19157)
* fix FileUtils::getContents on linux/mac
* use stat.st_mode
* simplify
* [CCFileUtils] win32 getFileSize (#19176)
* win32 getFileSize
* fix stat
* [cpp test-Android]20:FileUtils/2 change title (#19197)
* sync #19200
* sync #19231
* [android lua] improve performance of lua loader (#19234)
* [lua] improve performance of lua loader
* remove cache fix
* Revert "fix spritecache plist parsing issue (#19269)"
This reverts commit f3a85ece4307a7b90816c34489d1ed2c8fd11baf.
* remove win32 project files ref in template.json
* add metal framework lnk ref into cpp template
* test on iOS, and disable part cases
* alBufferData instead of alBufferDataStatic for small audio file on Apple (#19227)
* changes AudioCache to use alBufferData instead of alBufferDataStatic
(also makes test 19 faster to trigger openal bugs faster)
The original problem: CrashIfClientProvidedBogusAudioBufferList
https://github.com/cocos2d/cocos2d-x/issues/18948
is not happening anymore, but there's still a not very frequent issue
that makes OpenAL crash with a call stack like this.
AudioCache::readDataTask > alBufferData > CleanUpDeadBufferList
It happes more frequently when the device is "cold", which means after
half an hour of not using the device (locked).
I could not find the actual source code for iOS OpenAL, so I used the
macOS versions:
https://opensource.apple.com/source/OpenAL/OpenAL-48.7/Source/OpenAL/oalImp.cpp.auto.html
They seem to use CAGuard.h to make sure the dead buffer list
has no threading issues. I'm worried because the CAGuard code I found
has macos and win32 define but no iOS, so I'm not sure. I guess the
iOS version is different and has the guard.
I could not find a place in the code that's unprotected by the locks
except the InitializeBufferMap() which should not be called more than
once from cocos, and there's a workaround in AudioEngine-impl for it.
I reduced the occurence of the CleanUpDeadBufferList crash by moving
the guard in ~AudioCache to cover the alDeleteBuffers call.
* remove hack method "setTimeout" on audio
* AutoTest works on iOS
* support set ios deployment target for root project
* enable all texture2d cases, since Jiang have fixed
* add CCTextureUtils to xcode project file (#176)
* add leak cases for SpriteFrameCache (#177)
* re-add SpriteFrameCache cases
* update template file json
* Update SpriteFrameCacheTest.cpp
* fix compiling error
2019-01-18 15:08:25 +08:00
|
|
|
_transform.m[0] = cy * m0 - sx * m1;
|
|
|
|
_transform.m[4] = cy * m4 - sx * m5;
|
|
|
|
_transform.m[8] = cy * m8 - sx * m9;
|
|
|
|
_transform.m[1] = sy * m0 + cx * m1;
|
|
|
|
_transform.m[5] = sy * m4 + cx * m5;
|
|
|
|
_transform.m[9] = sy * m8 + cx * m9;
|
2014-07-01 08:19:51 +08:00
|
|
|
}
|
2015-01-20 14:10:11 +08:00
|
|
|
_transform = translation * _transform;
|
2016-10-31 10:29:04 +08:00
|
|
|
|
2014-12-24 17:07:54 +08:00
|
|
|
if (_scaleX != 1.f)
|
|
|
|
{
|
metal support for cocos2d-x (#19305)
* remove deprecated files
* remove some deprecated codes
* remove more deprecated codes
* remove ui deprecated codes
* remove more deprecated codes
* remove deprecated codes in ccmenuitem
* remove more deprecated codes in ui
* remove more deprecated codes in ui
* remove more deprecated codes in ui
* remove more deprecated codes
* remove more deprecated codes
* remove more deprecated codes
* remove vr related codes and ignore some modules
* remove allocator
* remove some config
* 【Feature】add back-end project file
* [Feature] add back-end file
* add pipeline descriptor and shader cache
* [Feature] support sprite for backend
* [Feature] remove unneeded code
* [Feature] according to es2.0 spec, you must use clamp-to-edge as texture wrap mode, and no mipmapping for non-power-of-two texture
* [Feature] set texture wrap mode to clamp-to-edge, and no mipmapping for non-power-of-two texture
* [Feature] remove macro define to .cpp file
* [Feature] add log info
* [Feature] add PipelineDescriptor for TriangleCommand
* [Feature] add PipelineDescriptor object as member of TriangleCommand
* [Feature] add getPipelineDescriptor method
* add renderbackend
* complete pipeline descriptor
* [Feature] add viewport in RenderCommand
* set viewport when rendrering
* [Feature] occur error when using RendererBackend, to be fixed.
* a workaround to fix black screen on macOS 10.14 (#19090)
* add rendererbackend init function
* fix typo
* [Feature] modify testFile
* [BugFix] modify shader path
* [Feature] set default viewport
* fix projection
* [Feature] modify log info
* [BugFix] change viewport data type to int
* [BugFix] add BindGroup to PipelienDescriptor
* [BugFix] change a_position to vec3 in sprite.vert
* [BugFix] set vertexLayout according to V3F_C4B_T2F structure
* [Feature] revert a_position to vec4
* [Feature] renderer should not use gl codes directly
* [Feature] it's better not use default value parameter
* fix depth test setting
* rendererbackend -> renderer
* clear color and depth at begin
* add metal backend
* metal support normalized attribute
* simplify codes
* update external
* add render pass desctriptor in pipeline descriptor
* fix warnings
* fix crash and memeory leak
* refactor Texture2D
* put pipeline descriptor into render command
* simplify codes
* [Feature] update Sprite
* fix crash when closing app
* [Feature] update SpriteBatchNode and TextureAtlas
* support render texture(not finish)
* [Feature] remove unused code
* make tests work on mac
* fix download-deps path error
* make tests work on iOS
* [Feature] support ttf under normal label effect
* refactor triangle command processing
* let renderer handle more common commands
* refactor backend
* make render texture work
* [Feature] refactor backend for GL
* [Feature]Renaming to make it easy to understand
* [Feature] change warp mode to CLAMP_TO_EDGE
* fix ghost
* simplify visit render queue logic
* support progress timer without rial mode
* support partcile system
* Feature/update label (#149)
* [BugFix] fix compile error
* [Feature] support outline effect in ios
* [Feature] add shader file
* [BugFix] fix begin and end RenderPass
* [Feature] update CustomCommand
* [Feature] revert project.pbxproj
* [Feature] simplify codes
* [BugFix] pack AI88 to RGBA8888 only when outline enable
* [Feature] support shadow effect in Label
* [Feature] support BMFont
* [Feature] support glow effect
* [Feature] simplify shader files
* LabelAtlas work
* handle blend function correctly
* support tile map
* don't share buffer in metal
* alloc buffer size as needed
* support more tilemap
* Merge branch 'minggo/metal-support' into feature/updateLabel
* minggo/metal-support:
support tile map
handle blend function correctly
LabelAtlas work
Feature/update label (#149)
support partcile system
# Conflicts:
# cocos/2d/CCLabel.cpp
# cocos/2d/CCSprite.cpp
# cocos/2d/CCSpriteBatchNode.cpp
# cocos/renderer/CCQuadCommand.cpp
# cocos/renderer/CCQuadCommand.h
* render texture work without saving file
* use global viewport
* grid3d works
* remove grabber
* tiled3d works
* [BugFix] fix label bug
* [Feature] add updateSubData for buffer
* [Feature] remove setVertexCount
* support depth test
* add callback command
* [Feature] add UITest
* [Feature] update UITest
* [Feature] remove unneeded codes
* fix custom command issue
* fix layer color blend issue
* [BugFix] fix iOS compile error
* [Feature] remove unneeded codes
* [Feature] fix updateVertexBuffer
* layerradial works
* add draw test back
* fix batch issue
* fix compiling error
* [BugFix] support ETC1
* [BugFix] get the correct pipelineDescriptor
* [BugFix] skip draw when backendTexture nullptr
* clipping node support
* [Feature] add shader files
* fix stencil issue in metal
* [Feature] update UILayoutTest
* [BugFix] skip drawing when vertexCount is zero
* refactor renderer
* add set global z order for stencil manager commands
* fix warnings caused by type
* remove viewport in render command
* [Feature] fix warnings caused by type
* [BugFix] clear vertexCount and indexCount for CustomComand when needed
* [Feature] update clear for CustomCommand
* ios use metal
* fix viewport issue
* fix LayerColorGradient crash
* [cmake] transport to android and windows (#160)
* save point 1
* compile on windows
* run on android
* revert useless change
* android set CC_ENABLE_CACHE_TEXTURE_DATA to 1
* add initGlew
* fix android crash
* add TODO new-renderer
* review update
* revert onGLFWWindowPosCallback
* fix android compiling error
* Impl progress radial (#162)
* progresstimer add radial impl
* default drawType to element
* dec invoke times of createVertexBuffer (#163)
* support depth/stencil format for gl backend
* simplify progress timer codes
* support motionstreak, effect is wrong
* fix motionstreak issue
* [Feature] update Scissor Test (#161)
* [Feature] update Scissor Test
* [Feature] update ScissorTest
* [Feature] rename function
* [Feature] get constant reference if needed
* [Feature] show render status (#164)
* improve performance
* fix depth state
* fill error that triangle vertex/index number bigger than buffer
* fix compiline error in release mode
* fix buffer conflict between CPU and GPU on iOS/macOS
* Renderer refactor (#165)
* use one vertes/index buffer with opengl
* fix error on windows
* custom command support index format config
* CCLayer: compact vertex data structure
* update comment
* fix doc
* support fast tilemap
* pass index format instead
* fix some wrong effect
* fix render texture error
* fix texture per-element size
* fix texture format error
* BlendFunc type refactor, GLenum -> backend::BlendFactor (#167)
* BlendFunc use backend::BlendFactor as inner field
* update comments
* use int to replace GLenum
* update xcode project fiel
* rename to GLBlendConst
* add ccConstants.h
* update xcode project file
* update copyright
* remove primitive command
* remove CCPrimitive.cpp/.h
* remove deprecated files
* remove unneeded files
* remove multiple view support
* remove multiple view support
* remove the usage of frame buffer in camera
* director don't use frame buffer
* remove FrameBuffer
* remove BatchCommand
* add some api reference
* add physics2d back
* fix crash when close app on mac
* improve render texture
* fix rendertexture issue
* fix rendertexture issue
* simplify codes
* CMake support for mac & ios (#169)
* update cmake
* fix compile error
* update 3rd libs version
* remove CCThread.h/.cpp
* remove ccthread
* use audio engine to implement simple audio engine
* remove unneeded codes
* remove deprecated codes
* remove winrt macro
* remove CC_USE_WIC
* set partcile blend function in more elegant way
* remove unneeded codes
* remove unneeded codes
* cmake works on windows
* update project setting
* improve performance
* GLFloat -> float
* sync v3 cmake improvements into metal-support (#172)
* pick: modern cmake, compile definitions improvement (#19139)
* modern cmake, use target_compile_definitions partly
* simplify macro define, remove USE_*
* modern cmake, macro define
* add physics 2d macro define into ccConfig.h
* remove USE_CHIPMUNK macro in build.gradle
* remove CocosSelectModule.cmake
* shrink useless define
* simplify compile options config, re-add if necessary
* update external for tmp CI test
* un-quote target_compile_options value
* add "-g" parameter only when debug mode
* keep single build type when generator Xcode & VS projecy
* update external for tmp CI tes
* add static_cast<char>(-1), fix -Wc++11-narrowing
* simplify win32 compile define
* not modify code, only improve compile options
# Conflicts:
# .gitignore
# cmake/Modules/CocosConfigDepend.cmake
# cocos/CMakeLists.txt
# external/config.json
# tests/cpp-tests/CMakeLists.txt
* modern cmake, improve cmake_compiler_flags (#19145)
* cmake_compiler_flags
* Fix typo
* Fix typo2
* Remove chanages from Android.mk
* correct lua template cmake build (#19149)
* don't add -Wno-deprecated into jsb target
* correct lua template cmake build
* fix win32 lua template compile error
* prevent cmake in-source-build friendly (#19151)
* pick: Copy resources to "Resources/" on win32 like in linux configuration
* add "/Z7" for cpp-tests on windows
* [cmake] fix iOS xcode property setting failed (#19208)
* fix iOS xcode property setting failed
* use search_depend_libs_recursive at dlls collect
* fix typo
* [cmake] add find_host_library into iOS toolchain file (#19230)
* pick: [lua android] use luajit & template cmake update (#19239)
* increase cmake stability , remove tests/CMakeLists.txt (#19261)
* cmake win32 Precompiled header (#19273)
* Precompiled header
* Fix
* Precompiled header for cocos
* Precompiled header jscocos2d
* Fix for COCOS2D_DEBUG is always 1 on Android (#19291)
Related #19289
* little build fix, tests cpp-tests works on mac
* sync v3 build related codes into metal-support (#173)
* strict initialization for std::array
* remove proj.win32 project configs
* modern cmake, cmake_cleanup_remove_unused_variables (#19146)
* Switch travis CI to xenial (#19207)
* Switch travis CI to xenial
* Remove language: android
* Set language: cpp
* Fix java problem
* Update sdkmanager
* Fix sdkmanger
* next sdkmanager fix
* Remove xenial from android
* revert to sdk-tools-{system}-3859397
* Remove linux cmake install
* Update before-install.sh
* Update .travis.yml
* Simplify install-deps-linux.sh, tested on Ubuntu 16.04 (#19212)
* Simplify install-deps-linux.sh
* Cleanup
* pick: install ninja
* update cocos2d-console submodule
* for metal-support alpha release, we only test cpp
* add HelloCpp into project(Cocos2d-x) for tmp test
* update extenal metal-support-4
* update uniform setting
* [Feature] update BindGroup
* [Feature] empty-test
* [Feature] cpp-test
* [Feature] fix GL compiler error
* [Feature] fix GL crash
* [Feature] empty-test
* [Feature] cpp-tests
* [feature] improve frameRate
* [feature] fix opengl compile error
* [feature] fix opengl compile error
* [BugFix] fix compute maxLocation error
* [Feature] update setting unifrom
* [Feature] fix namespace
* [Feature] remove unneeded code
* [Bugfix] fix project file
* [Feature] update review
* [texture2d] impl texture format support (#175)
* texture update
* update
* update texture
* commit
* compile on windows
* ddd
* rename
* rename methods
* no crash
* save gl
* save
* save
* rename
* move out pixel format convert functions
* metal crash
* update
* update android
* support gles compressed texture format
* support more compress format
* add more conversion methods
* ss
* save
* update conversion methods
* add PVRTC format support
* reformat
* add marco linux
* fix GL marcro
* pvrtc supported only by ios 8.0+
* remove unused cmake
* revert change
* refactor Texture2D::initWithData
* fix conversion log
* refactor Texture2D::initWithData
* remove some OpenGL constants for PVRTC
* add todo
* fix typo
* AutoTest works on mac/iOS by disable part cases, sync v3 bug fix (#174)
* review cpp-tests, and fix part issues on start auto test
* sync png format fix: Node:Particle3D abnormal texture effects #19204
* fix cpp-tests SpritePolygon crash, wrong png format (#19170)
* fix wrong png convert format from sRGB to Gray
* erase plist index if all frames was erased
* test_A8.png have I8 format, fix it
* [CCSpriteCache] allow re-add plist & add testcase (#19175)
* allow re-add plist & add testcase
* remove comments/rename method/update testcase
* fix isSpriteFramesWithFileLoaded & add testcase
* remove used variable
* remove unused variable
* fix double free issues when js/lua-tests exit on iOS (#19236)
* disable part cases, AutoTest works without crash on mac
* update cocos2dx files json, to test cocos new next
* fix spritecache plist parsing issue (#19269)
* [linux] Fix FileUtils::getContents with folder (#19157)
* fix FileUtils::getContents on linux/mac
* use stat.st_mode
* simplify
* [CCFileUtils] win32 getFileSize (#19176)
* win32 getFileSize
* fix stat
* [cpp test-Android]20:FileUtils/2 change title (#19197)
* sync #19200
* sync #19231
* [android lua] improve performance of lua loader (#19234)
* [lua] improve performance of lua loader
* remove cache fix
* Revert "fix spritecache plist parsing issue (#19269)"
This reverts commit f3a85ece4307a7b90816c34489d1ed2c8fd11baf.
* remove win32 project files ref in template.json
* add metal framework lnk ref into cpp template
* test on iOS, and disable part cases
* alBufferData instead of alBufferDataStatic for small audio file on Apple (#19227)
* changes AudioCache to use alBufferData instead of alBufferDataStatic
(also makes test 19 faster to trigger openal bugs faster)
The original problem: CrashIfClientProvidedBogusAudioBufferList
https://github.com/cocos2d/cocos2d-x/issues/18948
is not happening anymore, but there's still a not very frequent issue
that makes OpenAL crash with a call stack like this.
AudioCache::readDataTask > alBufferData > CleanUpDeadBufferList
It happes more frequently when the device is "cold", which means after
half an hour of not using the device (locked).
I could not find the actual source code for iOS OpenAL, so I used the
macOS versions:
https://opensource.apple.com/source/OpenAL/OpenAL-48.7/Source/OpenAL/oalImp.cpp.auto.html
They seem to use CAGuard.h to make sure the dead buffer list
has no threading issues. I'm worried because the CAGuard code I found
has macos and win32 define but no iOS, so I'm not sure. I guess the
iOS version is different and has the guard.
I could not find a place in the code that's unprotected by the locks
except the InitializeBufferMap() which should not be called more than
once from cocos, and there's a workaround in AudioEngine-impl for it.
I reduced the occurence of the CleanUpDeadBufferList crash by moving
the guard in ~AudioCache to cover the alDeleteBuffers call.
* remove hack method "setTimeout" on audio
* AutoTest works on iOS
* support set ios deployment target for root project
* enable all texture2d cases, since Jiang have fixed
* add CCTextureUtils to xcode project file (#176)
* add leak cases for SpriteFrameCache (#177)
* re-add SpriteFrameCache cases
* update template file json
* Update SpriteFrameCacheTest.cpp
* fix compiling error
2019-01-18 15:08:25 +08:00
|
|
|
_transform.m[0] *= _scaleX;
|
|
|
|
_transform.m[1] *= _scaleX;
|
|
|
|
_transform.m[2] *= _scaleX;
|
2014-02-23 11:16:42 +08:00
|
|
|
}
|
2014-12-24 17:34:58 +08:00
|
|
|
if (_scaleY != 1.f)
|
2014-12-24 17:07:54 +08:00
|
|
|
{
|
metal support for cocos2d-x (#19305)
* remove deprecated files
* remove some deprecated codes
* remove more deprecated codes
* remove ui deprecated codes
* remove more deprecated codes
* remove deprecated codes in ccmenuitem
* remove more deprecated codes in ui
* remove more deprecated codes in ui
* remove more deprecated codes in ui
* remove more deprecated codes
* remove more deprecated codes
* remove more deprecated codes
* remove vr related codes and ignore some modules
* remove allocator
* remove some config
* 【Feature】add back-end project file
* [Feature] add back-end file
* add pipeline descriptor and shader cache
* [Feature] support sprite for backend
* [Feature] remove unneeded code
* [Feature] according to es2.0 spec, you must use clamp-to-edge as texture wrap mode, and no mipmapping for non-power-of-two texture
* [Feature] set texture wrap mode to clamp-to-edge, and no mipmapping for non-power-of-two texture
* [Feature] remove macro define to .cpp file
* [Feature] add log info
* [Feature] add PipelineDescriptor for TriangleCommand
* [Feature] add PipelineDescriptor object as member of TriangleCommand
* [Feature] add getPipelineDescriptor method
* add renderbackend
* complete pipeline descriptor
* [Feature] add viewport in RenderCommand
* set viewport when rendrering
* [Feature] occur error when using RendererBackend, to be fixed.
* a workaround to fix black screen on macOS 10.14 (#19090)
* add rendererbackend init function
* fix typo
* [Feature] modify testFile
* [BugFix] modify shader path
* [Feature] set default viewport
* fix projection
* [Feature] modify log info
* [BugFix] change viewport data type to int
* [BugFix] add BindGroup to PipelienDescriptor
* [BugFix] change a_position to vec3 in sprite.vert
* [BugFix] set vertexLayout according to V3F_C4B_T2F structure
* [Feature] revert a_position to vec4
* [Feature] renderer should not use gl codes directly
* [Feature] it's better not use default value parameter
* fix depth test setting
* rendererbackend -> renderer
* clear color and depth at begin
* add metal backend
* metal support normalized attribute
* simplify codes
* update external
* add render pass desctriptor in pipeline descriptor
* fix warnings
* fix crash and memeory leak
* refactor Texture2D
* put pipeline descriptor into render command
* simplify codes
* [Feature] update Sprite
* fix crash when closing app
* [Feature] update SpriteBatchNode and TextureAtlas
* support render texture(not finish)
* [Feature] remove unused code
* make tests work on mac
* fix download-deps path error
* make tests work on iOS
* [Feature] support ttf under normal label effect
* refactor triangle command processing
* let renderer handle more common commands
* refactor backend
* make render texture work
* [Feature] refactor backend for GL
* [Feature]Renaming to make it easy to understand
* [Feature] change warp mode to CLAMP_TO_EDGE
* fix ghost
* simplify visit render queue logic
* support progress timer without rial mode
* support partcile system
* Feature/update label (#149)
* [BugFix] fix compile error
* [Feature] support outline effect in ios
* [Feature] add shader file
* [BugFix] fix begin and end RenderPass
* [Feature] update CustomCommand
* [Feature] revert project.pbxproj
* [Feature] simplify codes
* [BugFix] pack AI88 to RGBA8888 only when outline enable
* [Feature] support shadow effect in Label
* [Feature] support BMFont
* [Feature] support glow effect
* [Feature] simplify shader files
* LabelAtlas work
* handle blend function correctly
* support tile map
* don't share buffer in metal
* alloc buffer size as needed
* support more tilemap
* Merge branch 'minggo/metal-support' into feature/updateLabel
* minggo/metal-support:
support tile map
handle blend function correctly
LabelAtlas work
Feature/update label (#149)
support partcile system
# Conflicts:
# cocos/2d/CCLabel.cpp
# cocos/2d/CCSprite.cpp
# cocos/2d/CCSpriteBatchNode.cpp
# cocos/renderer/CCQuadCommand.cpp
# cocos/renderer/CCQuadCommand.h
* render texture work without saving file
* use global viewport
* grid3d works
* remove grabber
* tiled3d works
* [BugFix] fix label bug
* [Feature] add updateSubData for buffer
* [Feature] remove setVertexCount
* support depth test
* add callback command
* [Feature] add UITest
* [Feature] update UITest
* [Feature] remove unneeded codes
* fix custom command issue
* fix layer color blend issue
* [BugFix] fix iOS compile error
* [Feature] remove unneeded codes
* [Feature] fix updateVertexBuffer
* layerradial works
* add draw test back
* fix batch issue
* fix compiling error
* [BugFix] support ETC1
* [BugFix] get the correct pipelineDescriptor
* [BugFix] skip draw when backendTexture nullptr
* clipping node support
* [Feature] add shader files
* fix stencil issue in metal
* [Feature] update UILayoutTest
* [BugFix] skip drawing when vertexCount is zero
* refactor renderer
* add set global z order for stencil manager commands
* fix warnings caused by type
* remove viewport in render command
* [Feature] fix warnings caused by type
* [BugFix] clear vertexCount and indexCount for CustomComand when needed
* [Feature] update clear for CustomCommand
* ios use metal
* fix viewport issue
* fix LayerColorGradient crash
* [cmake] transport to android and windows (#160)
* save point 1
* compile on windows
* run on android
* revert useless change
* android set CC_ENABLE_CACHE_TEXTURE_DATA to 1
* add initGlew
* fix android crash
* add TODO new-renderer
* review update
* revert onGLFWWindowPosCallback
* fix android compiling error
* Impl progress radial (#162)
* progresstimer add radial impl
* default drawType to element
* dec invoke times of createVertexBuffer (#163)
* support depth/stencil format for gl backend
* simplify progress timer codes
* support motionstreak, effect is wrong
* fix motionstreak issue
* [Feature] update Scissor Test (#161)
* [Feature] update Scissor Test
* [Feature] update ScissorTest
* [Feature] rename function
* [Feature] get constant reference if needed
* [Feature] show render status (#164)
* improve performance
* fix depth state
* fill error that triangle vertex/index number bigger than buffer
* fix compiline error in release mode
* fix buffer conflict between CPU and GPU on iOS/macOS
* Renderer refactor (#165)
* use one vertes/index buffer with opengl
* fix error on windows
* custom command support index format config
* CCLayer: compact vertex data structure
* update comment
* fix doc
* support fast tilemap
* pass index format instead
* fix some wrong effect
* fix render texture error
* fix texture per-element size
* fix texture format error
* BlendFunc type refactor, GLenum -> backend::BlendFactor (#167)
* BlendFunc use backend::BlendFactor as inner field
* update comments
* use int to replace GLenum
* update xcode project fiel
* rename to GLBlendConst
* add ccConstants.h
* update xcode project file
* update copyright
* remove primitive command
* remove CCPrimitive.cpp/.h
* remove deprecated files
* remove unneeded files
* remove multiple view support
* remove multiple view support
* remove the usage of frame buffer in camera
* director don't use frame buffer
* remove FrameBuffer
* remove BatchCommand
* add some api reference
* add physics2d back
* fix crash when close app on mac
* improve render texture
* fix rendertexture issue
* fix rendertexture issue
* simplify codes
* CMake support for mac & ios (#169)
* update cmake
* fix compile error
* update 3rd libs version
* remove CCThread.h/.cpp
* remove ccthread
* use audio engine to implement simple audio engine
* remove unneeded codes
* remove deprecated codes
* remove winrt macro
* remove CC_USE_WIC
* set partcile blend function in more elegant way
* remove unneeded codes
* remove unneeded codes
* cmake works on windows
* update project setting
* improve performance
* GLFloat -> float
* sync v3 cmake improvements into metal-support (#172)
* pick: modern cmake, compile definitions improvement (#19139)
* modern cmake, use target_compile_definitions partly
* simplify macro define, remove USE_*
* modern cmake, macro define
* add physics 2d macro define into ccConfig.h
* remove USE_CHIPMUNK macro in build.gradle
* remove CocosSelectModule.cmake
* shrink useless define
* simplify compile options config, re-add if necessary
* update external for tmp CI test
* un-quote target_compile_options value
* add "-g" parameter only when debug mode
* keep single build type when generator Xcode & VS projecy
* update external for tmp CI tes
* add static_cast<char>(-1), fix -Wc++11-narrowing
* simplify win32 compile define
* not modify code, only improve compile options
# Conflicts:
# .gitignore
# cmake/Modules/CocosConfigDepend.cmake
# cocos/CMakeLists.txt
# external/config.json
# tests/cpp-tests/CMakeLists.txt
* modern cmake, improve cmake_compiler_flags (#19145)
* cmake_compiler_flags
* Fix typo
* Fix typo2
* Remove chanages from Android.mk
* correct lua template cmake build (#19149)
* don't add -Wno-deprecated into jsb target
* correct lua template cmake build
* fix win32 lua template compile error
* prevent cmake in-source-build friendly (#19151)
* pick: Copy resources to "Resources/" on win32 like in linux configuration
* add "/Z7" for cpp-tests on windows
* [cmake] fix iOS xcode property setting failed (#19208)
* fix iOS xcode property setting failed
* use search_depend_libs_recursive at dlls collect
* fix typo
* [cmake] add find_host_library into iOS toolchain file (#19230)
* pick: [lua android] use luajit & template cmake update (#19239)
* increase cmake stability , remove tests/CMakeLists.txt (#19261)
* cmake win32 Precompiled header (#19273)
* Precompiled header
* Fix
* Precompiled header for cocos
* Precompiled header jscocos2d
* Fix for COCOS2D_DEBUG is always 1 on Android (#19291)
Related #19289
* little build fix, tests cpp-tests works on mac
* sync v3 build related codes into metal-support (#173)
* strict initialization for std::array
* remove proj.win32 project configs
* modern cmake, cmake_cleanup_remove_unused_variables (#19146)
* Switch travis CI to xenial (#19207)
* Switch travis CI to xenial
* Remove language: android
* Set language: cpp
* Fix java problem
* Update sdkmanager
* Fix sdkmanger
* next sdkmanager fix
* Remove xenial from android
* revert to sdk-tools-{system}-3859397
* Remove linux cmake install
* Update before-install.sh
* Update .travis.yml
* Simplify install-deps-linux.sh, tested on Ubuntu 16.04 (#19212)
* Simplify install-deps-linux.sh
* Cleanup
* pick: install ninja
* update cocos2d-console submodule
* for metal-support alpha release, we only test cpp
* add HelloCpp into project(Cocos2d-x) for tmp test
* update extenal metal-support-4
* update uniform setting
* [Feature] update BindGroup
* [Feature] empty-test
* [Feature] cpp-test
* [Feature] fix GL compiler error
* [Feature] fix GL crash
* [Feature] empty-test
* [Feature] cpp-tests
* [feature] improve frameRate
* [feature] fix opengl compile error
* [feature] fix opengl compile error
* [BugFix] fix compute maxLocation error
* [Feature] update setting unifrom
* [Feature] fix namespace
* [Feature] remove unneeded code
* [Bugfix] fix project file
* [Feature] update review
* [texture2d] impl texture format support (#175)
* texture update
* update
* update texture
* commit
* compile on windows
* ddd
* rename
* rename methods
* no crash
* save gl
* save
* save
* rename
* move out pixel format convert functions
* metal crash
* update
* update android
* support gles compressed texture format
* support more compress format
* add more conversion methods
* ss
* save
* update conversion methods
* add PVRTC format support
* reformat
* add marco linux
* fix GL marcro
* pvrtc supported only by ios 8.0+
* remove unused cmake
* revert change
* refactor Texture2D::initWithData
* fix conversion log
* refactor Texture2D::initWithData
* remove some OpenGL constants for PVRTC
* add todo
* fix typo
* AutoTest works on mac/iOS by disable part cases, sync v3 bug fix (#174)
* review cpp-tests, and fix part issues on start auto test
* sync png format fix: Node:Particle3D abnormal texture effects #19204
* fix cpp-tests SpritePolygon crash, wrong png format (#19170)
* fix wrong png convert format from sRGB to Gray
* erase plist index if all frames was erased
* test_A8.png have I8 format, fix it
* [CCSpriteCache] allow re-add plist & add testcase (#19175)
* allow re-add plist & add testcase
* remove comments/rename method/update testcase
* fix isSpriteFramesWithFileLoaded & add testcase
* remove used variable
* remove unused variable
* fix double free issues when js/lua-tests exit on iOS (#19236)
* disable part cases, AutoTest works without crash on mac
* update cocos2dx files json, to test cocos new next
* fix spritecache plist parsing issue (#19269)
* [linux] Fix FileUtils::getContents with folder (#19157)
* fix FileUtils::getContents on linux/mac
* use stat.st_mode
* simplify
* [CCFileUtils] win32 getFileSize (#19176)
* win32 getFileSize
* fix stat
* [cpp test-Android]20:FileUtils/2 change title (#19197)
* sync #19200
* sync #19231
* [android lua] improve performance of lua loader (#19234)
* [lua] improve performance of lua loader
* remove cache fix
* Revert "fix spritecache plist parsing issue (#19269)"
This reverts commit f3a85ece4307a7b90816c34489d1ed2c8fd11baf.
* remove win32 project files ref in template.json
* add metal framework lnk ref into cpp template
* test on iOS, and disable part cases
* alBufferData instead of alBufferDataStatic for small audio file on Apple (#19227)
* changes AudioCache to use alBufferData instead of alBufferDataStatic
(also makes test 19 faster to trigger openal bugs faster)
The original problem: CrashIfClientProvidedBogusAudioBufferList
https://github.com/cocos2d/cocos2d-x/issues/18948
is not happening anymore, but there's still a not very frequent issue
that makes OpenAL crash with a call stack like this.
AudioCache::readDataTask > alBufferData > CleanUpDeadBufferList
It happes more frequently when the device is "cold", which means after
half an hour of not using the device (locked).
I could not find the actual source code for iOS OpenAL, so I used the
macOS versions:
https://opensource.apple.com/source/OpenAL/OpenAL-48.7/Source/OpenAL/oalImp.cpp.auto.html
They seem to use CAGuard.h to make sure the dead buffer list
has no threading issues. I'm worried because the CAGuard code I found
has macos and win32 define but no iOS, so I'm not sure. I guess the
iOS version is different and has the guard.
I could not find a place in the code that's unprotected by the locks
except the InitializeBufferMap() which should not be called more than
once from cocos, and there's a workaround in AudioEngine-impl for it.
I reduced the occurence of the CleanUpDeadBufferList crash by moving
the guard in ~AudioCache to cover the alDeleteBuffers call.
* remove hack method "setTimeout" on audio
* AutoTest works on iOS
* support set ios deployment target for root project
* enable all texture2d cases, since Jiang have fixed
* add CCTextureUtils to xcode project file (#176)
* add leak cases for SpriteFrameCache (#177)
* re-add SpriteFrameCache cases
* update template file json
* Update SpriteFrameCacheTest.cpp
* fix compiling error
2019-01-18 15:08:25 +08:00
|
|
|
_transform.m[4] *= _scaleY;
|
|
|
|
_transform.m[5] *= _scaleY;
|
|
|
|
_transform.m[6] *= _scaleY;
|
2014-02-23 11:16:42 +08:00
|
|
|
}
|
2014-12-24 17:34:58 +08:00
|
|
|
if (_scaleZ != 1.f)
|
2014-07-01 08:19:51 +08:00
|
|
|
{
|
metal support for cocos2d-x (#19305)
* remove deprecated files
* remove some deprecated codes
* remove more deprecated codes
* remove ui deprecated codes
* remove more deprecated codes
* remove deprecated codes in ccmenuitem
* remove more deprecated codes in ui
* remove more deprecated codes in ui
* remove more deprecated codes in ui
* remove more deprecated codes
* remove more deprecated codes
* remove more deprecated codes
* remove vr related codes and ignore some modules
* remove allocator
* remove some config
* 【Feature】add back-end project file
* [Feature] add back-end file
* add pipeline descriptor and shader cache
* [Feature] support sprite for backend
* [Feature] remove unneeded code
* [Feature] according to es2.0 spec, you must use clamp-to-edge as texture wrap mode, and no mipmapping for non-power-of-two texture
* [Feature] set texture wrap mode to clamp-to-edge, and no mipmapping for non-power-of-two texture
* [Feature] remove macro define to .cpp file
* [Feature] add log info
* [Feature] add PipelineDescriptor for TriangleCommand
* [Feature] add PipelineDescriptor object as member of TriangleCommand
* [Feature] add getPipelineDescriptor method
* add renderbackend
* complete pipeline descriptor
* [Feature] add viewport in RenderCommand
* set viewport when rendrering
* [Feature] occur error when using RendererBackend, to be fixed.
* a workaround to fix black screen on macOS 10.14 (#19090)
* add rendererbackend init function
* fix typo
* [Feature] modify testFile
* [BugFix] modify shader path
* [Feature] set default viewport
* fix projection
* [Feature] modify log info
* [BugFix] change viewport data type to int
* [BugFix] add BindGroup to PipelienDescriptor
* [BugFix] change a_position to vec3 in sprite.vert
* [BugFix] set vertexLayout according to V3F_C4B_T2F structure
* [Feature] revert a_position to vec4
* [Feature] renderer should not use gl codes directly
* [Feature] it's better not use default value parameter
* fix depth test setting
* rendererbackend -> renderer
* clear color and depth at begin
* add metal backend
* metal support normalized attribute
* simplify codes
* update external
* add render pass desctriptor in pipeline descriptor
* fix warnings
* fix crash and memeory leak
* refactor Texture2D
* put pipeline descriptor into render command
* simplify codes
* [Feature] update Sprite
* fix crash when closing app
* [Feature] update SpriteBatchNode and TextureAtlas
* support render texture(not finish)
* [Feature] remove unused code
* make tests work on mac
* fix download-deps path error
* make tests work on iOS
* [Feature] support ttf under normal label effect
* refactor triangle command processing
* let renderer handle more common commands
* refactor backend
* make render texture work
* [Feature] refactor backend for GL
* [Feature]Renaming to make it easy to understand
* [Feature] change warp mode to CLAMP_TO_EDGE
* fix ghost
* simplify visit render queue logic
* support progress timer without rial mode
* support partcile system
* Feature/update label (#149)
* [BugFix] fix compile error
* [Feature] support outline effect in ios
* [Feature] add shader file
* [BugFix] fix begin and end RenderPass
* [Feature] update CustomCommand
* [Feature] revert project.pbxproj
* [Feature] simplify codes
* [BugFix] pack AI88 to RGBA8888 only when outline enable
* [Feature] support shadow effect in Label
* [Feature] support BMFont
* [Feature] support glow effect
* [Feature] simplify shader files
* LabelAtlas work
* handle blend function correctly
* support tile map
* don't share buffer in metal
* alloc buffer size as needed
* support more tilemap
* Merge branch 'minggo/metal-support' into feature/updateLabel
* minggo/metal-support:
support tile map
handle blend function correctly
LabelAtlas work
Feature/update label (#149)
support partcile system
# Conflicts:
# cocos/2d/CCLabel.cpp
# cocos/2d/CCSprite.cpp
# cocos/2d/CCSpriteBatchNode.cpp
# cocos/renderer/CCQuadCommand.cpp
# cocos/renderer/CCQuadCommand.h
* render texture work without saving file
* use global viewport
* grid3d works
* remove grabber
* tiled3d works
* [BugFix] fix label bug
* [Feature] add updateSubData for buffer
* [Feature] remove setVertexCount
* support depth test
* add callback command
* [Feature] add UITest
* [Feature] update UITest
* [Feature] remove unneeded codes
* fix custom command issue
* fix layer color blend issue
* [BugFix] fix iOS compile error
* [Feature] remove unneeded codes
* [Feature] fix updateVertexBuffer
* layerradial works
* add draw test back
* fix batch issue
* fix compiling error
* [BugFix] support ETC1
* [BugFix] get the correct pipelineDescriptor
* [BugFix] skip draw when backendTexture nullptr
* clipping node support
* [Feature] add shader files
* fix stencil issue in metal
* [Feature] update UILayoutTest
* [BugFix] skip drawing when vertexCount is zero
* refactor renderer
* add set global z order for stencil manager commands
* fix warnings caused by type
* remove viewport in render command
* [Feature] fix warnings caused by type
* [BugFix] clear vertexCount and indexCount for CustomComand when needed
* [Feature] update clear for CustomCommand
* ios use metal
* fix viewport issue
* fix LayerColorGradient crash
* [cmake] transport to android and windows (#160)
* save point 1
* compile on windows
* run on android
* revert useless change
* android set CC_ENABLE_CACHE_TEXTURE_DATA to 1
* add initGlew
* fix android crash
* add TODO new-renderer
* review update
* revert onGLFWWindowPosCallback
* fix android compiling error
* Impl progress radial (#162)
* progresstimer add radial impl
* default drawType to element
* dec invoke times of createVertexBuffer (#163)
* support depth/stencil format for gl backend
* simplify progress timer codes
* support motionstreak, effect is wrong
* fix motionstreak issue
* [Feature] update Scissor Test (#161)
* [Feature] update Scissor Test
* [Feature] update ScissorTest
* [Feature] rename function
* [Feature] get constant reference if needed
* [Feature] show render status (#164)
* improve performance
* fix depth state
* fill error that triangle vertex/index number bigger than buffer
* fix compiline error in release mode
* fix buffer conflict between CPU and GPU on iOS/macOS
* Renderer refactor (#165)
* use one vertes/index buffer with opengl
* fix error on windows
* custom command support index format config
* CCLayer: compact vertex data structure
* update comment
* fix doc
* support fast tilemap
* pass index format instead
* fix some wrong effect
* fix render texture error
* fix texture per-element size
* fix texture format error
* BlendFunc type refactor, GLenum -> backend::BlendFactor (#167)
* BlendFunc use backend::BlendFactor as inner field
* update comments
* use int to replace GLenum
* update xcode project fiel
* rename to GLBlendConst
* add ccConstants.h
* update xcode project file
* update copyright
* remove primitive command
* remove CCPrimitive.cpp/.h
* remove deprecated files
* remove unneeded files
* remove multiple view support
* remove multiple view support
* remove the usage of frame buffer in camera
* director don't use frame buffer
* remove FrameBuffer
* remove BatchCommand
* add some api reference
* add physics2d back
* fix crash when close app on mac
* improve render texture
* fix rendertexture issue
* fix rendertexture issue
* simplify codes
* CMake support for mac & ios (#169)
* update cmake
* fix compile error
* update 3rd libs version
* remove CCThread.h/.cpp
* remove ccthread
* use audio engine to implement simple audio engine
* remove unneeded codes
* remove deprecated codes
* remove winrt macro
* remove CC_USE_WIC
* set partcile blend function in more elegant way
* remove unneeded codes
* remove unneeded codes
* cmake works on windows
* update project setting
* improve performance
* GLFloat -> float
* sync v3 cmake improvements into metal-support (#172)
* pick: modern cmake, compile definitions improvement (#19139)
* modern cmake, use target_compile_definitions partly
* simplify macro define, remove USE_*
* modern cmake, macro define
* add physics 2d macro define into ccConfig.h
* remove USE_CHIPMUNK macro in build.gradle
* remove CocosSelectModule.cmake
* shrink useless define
* simplify compile options config, re-add if necessary
* update external for tmp CI test
* un-quote target_compile_options value
* add "-g" parameter only when debug mode
* keep single build type when generator Xcode & VS projecy
* update external for tmp CI tes
* add static_cast<char>(-1), fix -Wc++11-narrowing
* simplify win32 compile define
* not modify code, only improve compile options
# Conflicts:
# .gitignore
# cmake/Modules/CocosConfigDepend.cmake
# cocos/CMakeLists.txt
# external/config.json
# tests/cpp-tests/CMakeLists.txt
* modern cmake, improve cmake_compiler_flags (#19145)
* cmake_compiler_flags
* Fix typo
* Fix typo2
* Remove chanages from Android.mk
* correct lua template cmake build (#19149)
* don't add -Wno-deprecated into jsb target
* correct lua template cmake build
* fix win32 lua template compile error
* prevent cmake in-source-build friendly (#19151)
* pick: Copy resources to "Resources/" on win32 like in linux configuration
* add "/Z7" for cpp-tests on windows
* [cmake] fix iOS xcode property setting failed (#19208)
* fix iOS xcode property setting failed
* use search_depend_libs_recursive at dlls collect
* fix typo
* [cmake] add find_host_library into iOS toolchain file (#19230)
* pick: [lua android] use luajit & template cmake update (#19239)
* increase cmake stability , remove tests/CMakeLists.txt (#19261)
* cmake win32 Precompiled header (#19273)
* Precompiled header
* Fix
* Precompiled header for cocos
* Precompiled header jscocos2d
* Fix for COCOS2D_DEBUG is always 1 on Android (#19291)
Related #19289
* little build fix, tests cpp-tests works on mac
* sync v3 build related codes into metal-support (#173)
* strict initialization for std::array
* remove proj.win32 project configs
* modern cmake, cmake_cleanup_remove_unused_variables (#19146)
* Switch travis CI to xenial (#19207)
* Switch travis CI to xenial
* Remove language: android
* Set language: cpp
* Fix java problem
* Update sdkmanager
* Fix sdkmanger
* next sdkmanager fix
* Remove xenial from android
* revert to sdk-tools-{system}-3859397
* Remove linux cmake install
* Update before-install.sh
* Update .travis.yml
* Simplify install-deps-linux.sh, tested on Ubuntu 16.04 (#19212)
* Simplify install-deps-linux.sh
* Cleanup
* pick: install ninja
* update cocos2d-console submodule
* for metal-support alpha release, we only test cpp
* add HelloCpp into project(Cocos2d-x) for tmp test
* update extenal metal-support-4
* update uniform setting
* [Feature] update BindGroup
* [Feature] empty-test
* [Feature] cpp-test
* [Feature] fix GL compiler error
* [Feature] fix GL crash
* [Feature] empty-test
* [Feature] cpp-tests
* [feature] improve frameRate
* [feature] fix opengl compile error
* [feature] fix opengl compile error
* [BugFix] fix compute maxLocation error
* [Feature] update setting unifrom
* [Feature] fix namespace
* [Feature] remove unneeded code
* [Bugfix] fix project file
* [Feature] update review
* [texture2d] impl texture format support (#175)
* texture update
* update
* update texture
* commit
* compile on windows
* ddd
* rename
* rename methods
* no crash
* save gl
* save
* save
* rename
* move out pixel format convert functions
* metal crash
* update
* update android
* support gles compressed texture format
* support more compress format
* add more conversion methods
* ss
* save
* update conversion methods
* add PVRTC format support
* reformat
* add marco linux
* fix GL marcro
* pvrtc supported only by ios 8.0+
* remove unused cmake
* revert change
* refactor Texture2D::initWithData
* fix conversion log
* refactor Texture2D::initWithData
* remove some OpenGL constants for PVRTC
* add todo
* fix typo
* AutoTest works on mac/iOS by disable part cases, sync v3 bug fix (#174)
* review cpp-tests, and fix part issues on start auto test
* sync png format fix: Node:Particle3D abnormal texture effects #19204
* fix cpp-tests SpritePolygon crash, wrong png format (#19170)
* fix wrong png convert format from sRGB to Gray
* erase plist index if all frames was erased
* test_A8.png have I8 format, fix it
* [CCSpriteCache] allow re-add plist & add testcase (#19175)
* allow re-add plist & add testcase
* remove comments/rename method/update testcase
* fix isSpriteFramesWithFileLoaded & add testcase
* remove used variable
* remove unused variable
* fix double free issues when js/lua-tests exit on iOS (#19236)
* disable part cases, AutoTest works without crash on mac
* update cocos2dx files json, to test cocos new next
* fix spritecache plist parsing issue (#19269)
* [linux] Fix FileUtils::getContents with folder (#19157)
* fix FileUtils::getContents on linux/mac
* use stat.st_mode
* simplify
* [CCFileUtils] win32 getFileSize (#19176)
* win32 getFileSize
* fix stat
* [cpp test-Android]20:FileUtils/2 change title (#19197)
* sync #19200
* sync #19231
* [android lua] improve performance of lua loader (#19234)
* [lua] improve performance of lua loader
* remove cache fix
* Revert "fix spritecache plist parsing issue (#19269)"
This reverts commit f3a85ece4307a7b90816c34489d1ed2c8fd11baf.
* remove win32 project files ref in template.json
* add metal framework lnk ref into cpp template
* test on iOS, and disable part cases
* alBufferData instead of alBufferDataStatic for small audio file on Apple (#19227)
* changes AudioCache to use alBufferData instead of alBufferDataStatic
(also makes test 19 faster to trigger openal bugs faster)
The original problem: CrashIfClientProvidedBogusAudioBufferList
https://github.com/cocos2d/cocos2d-x/issues/18948
is not happening anymore, but there's still a not very frequent issue
that makes OpenAL crash with a call stack like this.
AudioCache::readDataTask > alBufferData > CleanUpDeadBufferList
It happes more frequently when the device is "cold", which means after
half an hour of not using the device (locked).
I could not find the actual source code for iOS OpenAL, so I used the
macOS versions:
https://opensource.apple.com/source/OpenAL/OpenAL-48.7/Source/OpenAL/oalImp.cpp.auto.html
They seem to use CAGuard.h to make sure the dead buffer list
has no threading issues. I'm worried because the CAGuard code I found
has macos and win32 define but no iOS, so I'm not sure. I guess the
iOS version is different and has the guard.
I could not find a place in the code that's unprotected by the locks
except the InitializeBufferMap() which should not be called more than
once from cocos, and there's a workaround in AudioEngine-impl for it.
I reduced the occurence of the CleanUpDeadBufferList crash by moving
the guard in ~AudioCache to cover the alDeleteBuffers call.
* remove hack method "setTimeout" on audio
* AutoTest works on iOS
* support set ios deployment target for root project
* enable all texture2d cases, since Jiang have fixed
* add CCTextureUtils to xcode project file (#176)
* add leak cases for SpriteFrameCache (#177)
* re-add SpriteFrameCache cases
* update template file json
* Update SpriteFrameCacheTest.cpp
* fix compiling error
2019-01-18 15:08:25 +08:00
|
|
|
_transform.m[8] *= _scaleZ;
|
|
|
|
_transform.m[9] *= _scaleZ;
|
|
|
|
_transform.m[10] *= _scaleZ;
|
2014-07-01 08:19:51 +08:00
|
|
|
}
|
|
|
|
|
2014-08-30 03:54:24 +08:00
|
|
|
// FIXME:: Try to inline skew
|
2012-04-19 14:35:52 +08:00
|
|
|
// If skew is needed, apply skew and then anchor point
|
2013-12-10 09:32:51 +08:00
|
|
|
if (needsSkewMatrix)
|
2012-06-08 14:17:39 +08:00
|
|
|
{
|
2014-08-29 09:50:26 +08:00
|
|
|
float skewMatArray[16] =
|
|
|
|
{
|
|
|
|
1, (float)tanf(CC_DEGREES_TO_RADIANS(_skewY)), 0, 0,
|
|
|
|
(float)tanf(CC_DEGREES_TO_RADIANS(_skewX)), 1, 0, 0,
|
|
|
|
0, 0, 1, 0,
|
|
|
|
0, 0, 0, 1
|
|
|
|
};
|
|
|
|
Mat4 skewMatrix(skewMatArray);
|
2015-01-20 14:10:11 +08:00
|
|
|
|
2014-04-08 23:05:33 +08:00
|
|
|
_transform = _transform * skewMatrix;
|
2016-10-31 10:29:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// adjust anchor point
|
|
|
|
if (!_anchorPointInPoints.isZero())
|
|
|
|
{
|
|
|
|
// FIXME:: Argh, Mat4 needs a "translate" method.
|
|
|
|
// FIXME:: Although this is faster than multiplying a vec4 * mat4
|
|
|
|
_transform.m[12] += _transform.m[0] * -_anchorPointInPoints.x + _transform.m[4] * -_anchorPointInPoints.y;
|
|
|
|
_transform.m[13] += _transform.m[1] * -_anchorPointInPoints.x + _transform.m[5] * -_anchorPointInPoints.y;
|
2016-11-24 11:38:37 +08:00
|
|
|
_transform.m[14] += _transform.m[2] * -_anchorPointInPoints.x + _transform.m[6] * -_anchorPointInPoints.y;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
}
|
2016-06-24 10:03:38 +08:00
|
|
|
|
|
|
|
if (_additionalTransform)
|
|
|
|
{
|
|
|
|
// This is needed to support both Node::setNodeToParentTransform() and Node::setAdditionalTransform()
|
|
|
|
// at the same time. The scenario is this:
|
|
|
|
// at some point setNodeToParentTransform() is called.
|
|
|
|
// and later setAdditionalTransform() is called every time. And since _transform
|
|
|
|
// is being overwritten everyframe, _additionalTransform[1] is used to have a copy
|
2016-07-03 23:42:10 +08:00
|
|
|
// of the last "_transform without _additionalTransform"
|
2016-06-24 10:03:38 +08:00
|
|
|
if (_transformDirty)
|
|
|
|
_additionalTransform[1] = _transform;
|
|
|
|
|
|
|
|
if (_transformUpdated)
|
|
|
|
_transform = _additionalTransform[1] * _additionalTransform[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
_transformDirty = _additionalTransformDirty = false;
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
return _transform;
|
2010-07-19 16:45:53 +08:00
|
|
|
}
|
2013-02-22 16:01:49 +08:00
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
void Node::setNodeToParentTransform(const Mat4& transform)
|
2013-12-21 08:33:31 +08:00
|
|
|
{
|
|
|
|
_transform = transform;
|
|
|
|
_transformDirty = false;
|
2014-03-01 08:10:48 +08:00
|
|
|
_transformUpdated = true;
|
2016-06-24 10:03:38 +08:00
|
|
|
|
|
|
|
if (_additionalTransform)
|
|
|
|
// _additionalTransform[1] has a copy of lastest transform
|
|
|
|
_additionalTransform[1] = transform;
|
2013-12-21 08:33:31 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::setAdditionalTransform(const AffineTransform& additionalTransform)
|
2013-12-10 09:32:51 +08:00
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
Mat4 tmp;
|
2014-04-08 23:05:33 +08:00
|
|
|
CGAffineToGL(additionalTransform, tmp.m);
|
2014-03-02 00:26:54 +08:00
|
|
|
setAdditionalTransform(&tmp);
|
2013-12-10 09:32:51 +08:00
|
|
|
}
|
|
|
|
|
2016-06-27 18:33:45 +08:00
|
|
|
void Node::setAdditionalTransform(const Mat4* additionalTransform)
|
2013-02-20 22:33:28 +08:00
|
|
|
{
|
2014-12-23 18:07:22 +08:00
|
|
|
if (additionalTransform == nullptr)
|
|
|
|
{
|
2017-03-23 11:51:51 +08:00
|
|
|
if(_additionalTransform) _transform = _additionalTransform[1];
|
2016-06-24 10:03:38 +08:00
|
|
|
delete[] _additionalTransform;
|
|
|
|
_additionalTransform = nullptr;
|
2014-12-23 18:07:22 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-06-24 10:03:38 +08:00
|
|
|
if (!_additionalTransform) {
|
|
|
|
_additionalTransform = new Mat4[2];
|
|
|
|
|
|
|
|
// _additionalTransform[1] is used as a backup for _transform
|
|
|
|
_additionalTransform[1] = _transform;
|
|
|
|
}
|
|
|
|
|
|
|
|
_additionalTransform[0] = *additionalTransform;
|
2014-03-02 00:26:54 +08:00
|
|
|
}
|
2016-06-24 10:03:38 +08:00
|
|
|
_transformUpdated = _additionalTransformDirty = _inverseDirty = true;
|
2013-02-20 22:33:28 +08:00
|
|
|
}
|
2013-02-22 16:01:49 +08:00
|
|
|
|
2016-06-16 02:33:25 +08:00
|
|
|
void Node::setAdditionalTransform(const Mat4& additionalTransform)
|
|
|
|
{
|
2016-06-27 18:33:45 +08:00
|
|
|
setAdditionalTransform(&additionalTransform);
|
2016-06-16 02:33:25 +08:00
|
|
|
}
|
2013-12-10 09:32:51 +08:00
|
|
|
|
|
|
|
AffineTransform Node::getParentToNodeAffineTransform() const
|
|
|
|
{
|
|
|
|
AffineTransform ret;
|
|
|
|
|
2014-12-23 18:07:22 +08:00
|
|
|
GLToCGAffine(getParentToNodeTransform().m,&ret);
|
2013-12-10 09:32:51 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
const Mat4& Node::getParentToNodeTransform() const
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2014-12-23 18:07:22 +08:00
|
|
|
if ( _inverseDirty )
|
|
|
|
{
|
2015-01-09 09:58:09 +08:00
|
|
|
_inverse = getNodeToParentTransform().getInversed();
|
2013-06-15 14:03:30 +08:00
|
|
|
_inverseDirty = false;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
return _inverse;
|
2010-07-19 16:45:53 +08:00
|
|
|
}
|
|
|
|
|
2013-12-10 09:32:51 +08:00
|
|
|
|
|
|
|
AffineTransform Node::getNodeToWorldAffineTransform() const
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2015-07-20 10:03:15 +08:00
|
|
|
return this->getNodeToParentAffineTransform(nullptr);
|
2010-07-19 16:45:53 +08:00
|
|
|
}
|
2010-07-21 17:40:10 +08:00
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Mat4 Node::getNodeToWorldTransform() const
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2015-07-20 10:03:15 +08:00
|
|
|
return this->getNodeToParentTransform(nullptr);
|
2010-07-19 16:45:53 +08:00
|
|
|
}
|
2010-07-21 17:40:10 +08:00
|
|
|
|
2013-12-10 09:32:51 +08:00
|
|
|
AffineTransform Node::getWorldToNodeAffineTransform() const
|
|
|
|
{
|
|
|
|
return AffineTransformInvert(this->getNodeToWorldAffineTransform());
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Mat4 Node::getWorldToNodeTransform() const
|
2013-07-17 09:16:04 +08:00
|
|
|
{
|
2014-05-01 01:59:36 +08:00
|
|
|
return getNodeToWorldTransform().getInversed();
|
2013-07-17 09:16:04 +08:00
|
|
|
}
|
|
|
|
|
2013-12-10 09:32:51 +08:00
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 Node::convertToNodeSpace(const Vec2& worldPoint) const
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
Mat4 tmp = getWorldToNodeTransform();
|
|
|
|
Vec3 vec3(worldPoint.x, worldPoint.y, 0);
|
|
|
|
Vec3 ret;
|
2014-04-10 23:12:29 +08:00
|
|
|
tmp.transformPoint(vec3,&ret);
|
2014-05-15 01:07:09 +08:00
|
|
|
return Vec2(ret.x, ret.y);
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 Node::convertToWorldSpace(const Vec2& nodePoint) const
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
Mat4 tmp = getNodeToWorldTransform();
|
|
|
|
Vec3 vec3(nodePoint.x, nodePoint.y, 0);
|
|
|
|
Vec3 ret;
|
2014-04-10 23:12:29 +08:00
|
|
|
tmp.transformPoint(vec3,&ret);
|
2014-05-15 01:07:09 +08:00
|
|
|
return Vec2(ret.x, ret.y);
|
2013-12-10 09:32:51 +08:00
|
|
|
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 Node::convertToNodeSpaceAR(const Vec2& worldPoint) const
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2014-12-23 18:07:22 +08:00
|
|
|
Vec2 nodePoint(convertToNodeSpace(worldPoint));
|
2013-07-11 16:38:58 +08:00
|
|
|
return nodePoint - _anchorPointInPoints;
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 Node::convertToWorldSpaceAR(const Vec2& nodePoint) const
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2014-12-23 18:07:22 +08:00
|
|
|
return convertToWorldSpace(nodePoint + _anchorPointInPoints);
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
2012-03-14 14:55:17 +08:00
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 Node::convertToWindowSpace(const Vec2& nodePoint) const
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2014-12-23 18:07:22 +08:00
|
|
|
Vec2 worldPoint(this->convertToWorldSpace(nodePoint));
|
2015-01-13 10:28:25 +08:00
|
|
|
return _director->convertToUI(worldPoint);
|
2010-07-20 13:49:13 +08:00
|
|
|
}
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
// convenience methods which take a Touch instead of Vec2
|
|
|
|
Vec2 Node::convertTouchToNodeSpace(Touch *touch) const
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2014-12-23 18:07:22 +08:00
|
|
|
return this->convertToNodeSpace(touch->getLocation());
|
2010-07-30 16:35:07 +08:00
|
|
|
}
|
2014-04-15 14:29:12 +08:00
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 Node::convertTouchToNodeSpaceAR(Touch *touch) const
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 point = touch->getLocation();
|
2012-04-19 14:35:52 +08:00
|
|
|
return this->convertToNodeSpaceAR(point);
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
2010-07-30 16:35:07 +08:00
|
|
|
|
2013-10-18 15:34:13 +08:00
|
|
|
void Node::updateTransform()
|
|
|
|
{
|
2012-11-09 12:08:18 +08:00
|
|
|
// Recursively iterate over children
|
2013-12-19 08:56:59 +08:00
|
|
|
for( const auto &child: _children)
|
2013-11-28 16:02:03 +08:00
|
|
|
child->updateTransform();
|
2012-10-30 10:24:28 +08:00
|
|
|
}
|
|
|
|
|
2014-08-29 05:56:15 +08:00
|
|
|
// MARK: components
|
|
|
|
|
2014-05-28 17:41:34 +08:00
|
|
|
Component* Node::getComponent(const std::string& name)
|
2013-06-04 17:38:43 +08:00
|
|
|
{
|
2014-12-23 18:07:22 +08:00
|
|
|
if (_componentContainer)
|
2014-05-28 17:41:34 +08:00
|
|
|
return _componentContainer->get(name);
|
2014-12-23 18:07:22 +08:00
|
|
|
|
2013-09-07 07:00:24 +08:00
|
|
|
return nullptr;
|
2013-06-04 17:38:43 +08:00
|
|
|
}
|
|
|
|
|
2014-05-28 17:41:34 +08:00
|
|
|
bool Node::addComponent(Component *component)
|
2013-06-04 17:38:43 +08:00
|
|
|
{
|
2013-09-07 07:00:24 +08:00
|
|
|
// lazy alloc
|
2014-12-23 18:07:22 +08:00
|
|
|
if (!_componentContainer)
|
2014-08-28 07:31:57 +08:00
|
|
|
_componentContainer = new (std::nothrow) ComponentContainer(this);
|
2014-12-23 18:07:22 +08:00
|
|
|
|
2015-07-08 10:11:17 +08:00
|
|
|
// should enable schedule update, then all components can receive this call back
|
|
|
|
scheduleUpdate();
|
|
|
|
|
2014-05-28 17:41:34 +08:00
|
|
|
return _componentContainer->add(component);
|
2013-06-04 17:38:43 +08:00
|
|
|
}
|
|
|
|
|
2014-05-28 17:41:34 +08:00
|
|
|
bool Node::removeComponent(const std::string& name)
|
2013-06-04 17:38:43 +08:00
|
|
|
{
|
2014-12-23 18:07:22 +08:00
|
|
|
if (_componentContainer)
|
2014-05-28 17:41:34 +08:00
|
|
|
return _componentContainer->remove(name);
|
2014-12-23 18:07:22 +08:00
|
|
|
|
2013-09-07 07:00:24 +08:00
|
|
|
return false;
|
2013-06-04 17:38:43 +08:00
|
|
|
}
|
|
|
|
|
2014-07-21 17:45:56 +08:00
|
|
|
bool Node::removeComponent(Component *component)
|
|
|
|
{
|
2014-12-23 18:07:22 +08:00
|
|
|
if (_componentContainer)
|
|
|
|
{
|
2014-08-06 13:51:16 +08:00
|
|
|
return _componentContainer->remove(component);
|
|
|
|
}
|
2014-12-23 18:07:22 +08:00
|
|
|
|
2014-08-06 13:51:16 +08:00
|
|
|
return false;
|
2014-07-21 17:45:56 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::removeAllComponents()
|
2013-06-04 17:38:43 +08:00
|
|
|
{
|
2014-12-23 18:07:22 +08:00
|
|
|
if (_componentContainer)
|
2013-09-07 07:00:24 +08:00
|
|
|
_componentContainer->removeAll();
|
2013-06-04 17:38:43 +08:00
|
|
|
}
|
|
|
|
|
2014-08-29 05:56:15 +08:00
|
|
|
// MARK: Opacity and Color
|
|
|
|
|
2019-07-22 09:38:46 +08:00
|
|
|
uint8_t Node::getOpacity() const
|
2013-02-27 09:38:30 +08:00
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
return _realOpacity;
|
2013-02-27 09:38:30 +08:00
|
|
|
}
|
|
|
|
|
2019-06-05 17:58:33 +08:00
|
|
|
uint8_t Node::getDisplayedOpacity() const
|
2013-02-27 09:38:30 +08:00
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
return _displayedOpacity;
|
2013-02-27 09:38:30 +08:00
|
|
|
}
|
|
|
|
|
2019-06-05 17:58:33 +08:00
|
|
|
void Node::setOpacity(uint8_t opacity)
|
2013-02-27 09:38:30 +08:00
|
|
|
{
|
2013-02-27 14:48:19 +08:00
|
|
|
_displayedOpacity = _realOpacity = opacity;
|
2013-02-27 09:38:30 +08:00
|
|
|
|
2013-12-06 18:07:16 +08:00
|
|
|
updateCascadeOpacity();
|
2013-02-27 09:38:30 +08:00
|
|
|
}
|
|
|
|
|
2019-06-05 17:58:33 +08:00
|
|
|
void Node::updateDisplayedOpacity(uint8_t parentOpacity)
|
2013-02-27 09:38:30 +08:00
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
_displayedOpacity = _realOpacity * parentOpacity/255.0;
|
2013-12-11 15:57:20 +08:00
|
|
|
updateColor();
|
|
|
|
|
2013-02-27 18:21:35 +08:00
|
|
|
if (_cascadeOpacityEnabled)
|
2013-02-27 14:48:19 +08:00
|
|
|
{
|
2014-12-23 18:07:22 +08:00
|
|
|
for(const auto& child : _children)
|
|
|
|
{
|
2013-12-06 18:07:16 +08:00
|
|
|
child->updateDisplayedOpacity(_displayedOpacity);
|
2013-12-19 10:33:04 +08:00
|
|
|
}
|
2013-02-27 09:38:30 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-22 09:38:46 +08:00
|
|
|
bool Node::isCascadeOpacityEnabled() const
|
2013-02-27 15:30:49 +08:00
|
|
|
{
|
|
|
|
return _cascadeOpacityEnabled;
|
|
|
|
}
|
|
|
|
|
2013-12-06 18:07:16 +08:00
|
|
|
void Node::setCascadeOpacityEnabled(bool cascadeOpacityEnabled)
|
2013-02-27 15:30:49 +08:00
|
|
|
{
|
2013-12-11 15:57:20 +08:00
|
|
|
if (_cascadeOpacityEnabled == cascadeOpacityEnabled)
|
2013-12-06 18:07:16 +08:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-02-27 15:30:49 +08:00
|
|
|
_cascadeOpacityEnabled = cascadeOpacityEnabled;
|
2013-12-06 18:07:16 +08:00
|
|
|
|
|
|
|
if (cascadeOpacityEnabled)
|
|
|
|
{
|
|
|
|
updateCascadeOpacity();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
disableCascadeOpacity();
|
|
|
|
}
|
2013-02-27 15:30:49 +08:00
|
|
|
}
|
|
|
|
|
2013-12-06 18:07:16 +08:00
|
|
|
void Node::updateCascadeOpacity()
|
|
|
|
{
|
2019-06-05 17:58:33 +08:00
|
|
|
uint8_t parentOpacity = 255;
|
2013-12-06 18:07:16 +08:00
|
|
|
|
|
|
|
if (_parent != nullptr && _parent->isCascadeOpacityEnabled())
|
|
|
|
{
|
|
|
|
parentOpacity = _parent->getDisplayedOpacity();
|
|
|
|
}
|
|
|
|
|
|
|
|
updateDisplayedOpacity(parentOpacity);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Node::disableCascadeOpacity()
|
|
|
|
{
|
|
|
|
_displayedOpacity = _realOpacity;
|
|
|
|
|
2014-12-23 18:07:22 +08:00
|
|
|
for(const auto& child : _children)
|
|
|
|
{
|
2013-12-11 15:57:20 +08:00
|
|
|
child->updateDisplayedOpacity(255);
|
2013-12-19 17:05:59 +08:00
|
|
|
}
|
2013-12-06 18:07:16 +08:00
|
|
|
}
|
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
void Node::setOpacityModifyRGB(bool /*value*/)
|
|
|
|
{}
|
|
|
|
|
|
|
|
bool Node::isOpacityModifyRGB() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-07-22 09:38:46 +08:00
|
|
|
const Color3B& Node::getColor() const
|
2013-02-27 09:38:30 +08:00
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
return _realColor;
|
2013-02-27 09:38:30 +08:00
|
|
|
}
|
|
|
|
|
2013-12-06 18:07:16 +08:00
|
|
|
const Color3B& Node::getDisplayedColor() const
|
2013-02-27 09:38:30 +08:00
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
return _displayedColor;
|
2013-02-27 09:38:30 +08:00
|
|
|
}
|
|
|
|
|
2013-12-06 18:07:16 +08:00
|
|
|
void Node::setColor(const Color3B& color)
|
2013-02-27 09:38:30 +08:00
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
_displayedColor = _realColor = color;
|
|
|
|
|
|
|
|
updateCascadeColor();
|
2013-02-27 09:38:30 +08:00
|
|
|
}
|
|
|
|
|
2013-12-06 18:07:16 +08:00
|
|
|
void Node::updateDisplayedColor(const Color3B& parentColor)
|
2013-02-27 09:38:30 +08:00
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
_displayedColor.r = _realColor.r * parentColor.r/255.0;
|
|
|
|
_displayedColor.g = _realColor.g * parentColor.g/255.0;
|
|
|
|
_displayedColor.b = _realColor.b * parentColor.b/255.0;
|
2013-12-11 15:57:20 +08:00
|
|
|
updateColor();
|
2013-02-27 09:38:30 +08:00
|
|
|
|
2013-02-27 14:48:19 +08:00
|
|
|
if (_cascadeColorEnabled)
|
|
|
|
{
|
2014-12-23 18:07:22 +08:00
|
|
|
for(const auto &child : _children)
|
|
|
|
{
|
2013-12-06 18:07:16 +08:00
|
|
|
child->updateDisplayedColor(_displayedColor);
|
2013-12-19 10:33:04 +08:00
|
|
|
}
|
2013-02-27 09:38:30 +08:00
|
|
|
}
|
|
|
|
}
|
2013-01-17 11:20:25 +08:00
|
|
|
|
2019-07-22 09:38:46 +08:00
|
|
|
bool Node::isCascadeColorEnabled() const
|
2013-02-27 15:30:49 +08:00
|
|
|
{
|
|
|
|
return _cascadeColorEnabled;
|
|
|
|
}
|
|
|
|
|
2013-12-06 18:07:16 +08:00
|
|
|
void Node::setCascadeColorEnabled(bool cascadeColorEnabled)
|
2013-02-27 15:30:49 +08:00
|
|
|
{
|
2013-12-06 18:07:16 +08:00
|
|
|
if (_cascadeColorEnabled == cascadeColorEnabled)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-02-27 15:30:49 +08:00
|
|
|
_cascadeColorEnabled = cascadeColorEnabled;
|
2013-12-06 18:07:16 +08:00
|
|
|
|
|
|
|
if (_cascadeColorEnabled)
|
|
|
|
{
|
|
|
|
updateCascadeColor();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
disableCascadeColor();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Node::updateCascadeColor()
|
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
Color3B parentColor = Color3B::WHITE;
|
2013-12-06 18:07:16 +08:00
|
|
|
if (_parent && _parent->isCascadeColorEnabled())
|
|
|
|
{
|
|
|
|
parentColor = _parent->getDisplayedColor();
|
|
|
|
}
|
|
|
|
|
|
|
|
updateDisplayedColor(parentColor);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Node::disableCascadeColor()
|
|
|
|
{
|
2014-12-23 18:07:22 +08:00
|
|
|
for(const auto& child : _children)
|
|
|
|
{
|
2013-12-11 15:57:20 +08:00
|
|
|
child->updateDisplayedColor(Color3B::WHITE);
|
2013-12-19 17:05:59 +08:00
|
|
|
}
|
2013-02-27 15:30:49 +08:00
|
|
|
}
|
|
|
|
|
2015-06-18 10:23:52 +08:00
|
|
|
bool isScreenPointInRect(const Vec2 &pt, const Camera* camera, const Mat4& w2l, const Rect& rect, Vec3 *p)
|
|
|
|
{
|
|
|
|
if (nullptr == camera || rect.size.width <= 0 || rect.size.height <= 0)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// first, convert pt to near/far plane, get Pn and Pf
|
|
|
|
Vec3 Pn(pt.x, pt.y, -1), Pf(pt.x, pt.y, 1);
|
|
|
|
Pn = camera->unprojectGL(Pn);
|
|
|
|
Pf = camera->unprojectGL(Pf);
|
|
|
|
|
|
|
|
// then convert Pn and Pf to node space
|
|
|
|
w2l.transformPoint(&Pn);
|
|
|
|
w2l.transformPoint(&Pf);
|
|
|
|
|
|
|
|
// Pn and Pf define a line Q(t) = D + t * E which D = Pn
|
|
|
|
auto E = Pf - Pn;
|
|
|
|
|
|
|
|
// second, get three points which define content plane
|
|
|
|
// these points define a plane P(u, w) = A + uB + wC
|
|
|
|
Vec3 A = Vec3(rect.origin.x, rect.origin.y, 0);
|
2015-07-27 16:59:35 +08:00
|
|
|
Vec3 B(rect.origin.x + rect.size.width, rect.origin.y, 0);
|
|
|
|
Vec3 C(rect.origin.x, rect.origin.y + rect.size.height, 0);
|
2015-06-18 10:23:52 +08:00
|
|
|
B = B - A;
|
|
|
|
C = C - A;
|
|
|
|
|
|
|
|
// the line Q(t) intercept with plane P(u, w)
|
|
|
|
// calculate the intercept point P = Q(t)
|
|
|
|
// (BxC).A - (BxC).D
|
|
|
|
// t = -----------------
|
|
|
|
// (BxC).E
|
|
|
|
Vec3 BxC;
|
|
|
|
Vec3::cross(B, C, &BxC);
|
|
|
|
auto BxCdotE = BxC.dot(E);
|
|
|
|
if (BxCdotE == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
auto t = (BxC.dot(A) - BxC.dot(Pn)) / BxCdotE;
|
|
|
|
Vec3 P = Pn + t * E;
|
|
|
|
if (p) {
|
|
|
|
*p = P;
|
|
|
|
}
|
|
|
|
return rect.containsPoint(Vec2(P.x, P.y));
|
|
|
|
}
|
|
|
|
|
2014-08-29 05:56:15 +08:00
|
|
|
// MARK: Camera
|
2014-08-07 15:23:31 +08:00
|
|
|
void Node::setCameraMask(unsigned short mask, bool applyChildren)
|
|
|
|
{
|
|
|
|
_cameraMask = mask;
|
|
|
|
if (applyChildren)
|
|
|
|
{
|
2014-12-23 18:07:22 +08:00
|
|
|
for (const auto& child : _children)
|
|
|
|
{
|
2014-08-07 15:23:31 +08:00
|
|
|
child->setCameraMask(mask, applyChildren);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-05 13:37:50 +08:00
|
|
|
int Node::getAttachedNodeCount()
|
|
|
|
{
|
|
|
|
return __attachedNodeCount;
|
|
|
|
}
|
|
|
|
|
2019-11-20 18:19:24 +08:00
|
|
|
void Node::setProgramStateWithRegistry(backend::ProgramType programType, Texture2D* texture)
|
|
|
|
{
|
2019-11-22 03:36:01 +08:00
|
|
|
auto formatEXT = texture ? texture->getTextureFormatEXT() : 0;
|
2020-09-08 22:13:10 +08:00
|
|
|
auto programState = backend::ProgramStateRegistry::getInstance()->newProgramState(programType, formatEXT);
|
2020-09-09 13:03:31 +08:00
|
|
|
attachProgramState(programState);
|
2019-11-20 18:19:24 +08:00
|
|
|
}
|
|
|
|
|
2019-06-18 15:25:26 +08:00
|
|
|
void Node::setProgramState(backend::ProgramState* programState)
|
2020-07-21 23:11:03 +08:00
|
|
|
{
|
|
|
|
if(attachProgramState(programState))
|
|
|
|
programState->retain();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Node::attachProgramState(backend::ProgramState* programState)
|
2019-06-18 15:25:26 +08:00
|
|
|
{
|
|
|
|
if (_programState != programState)
|
|
|
|
{
|
|
|
|
CC_SAFE_RELEASE(_programState);
|
|
|
|
_programState = programState;
|
2020-07-21 23:11:03 +08:00
|
|
|
return !!_programState;
|
2019-06-18 15:25:26 +08:00
|
|
|
}
|
2020-07-21 23:11:03 +08:00
|
|
|
return false;
|
2019-06-18 15:25:26 +08:00
|
|
|
}
|
|
|
|
|
2020-09-09 13:03:31 +08:00
|
|
|
void Node::updateProgramStateTexture(Texture2D* texture)
|
|
|
|
{
|
|
|
|
if (texture == nullptr || texture->getBackendTexture() == nullptr || _programState == nullptr)
|
|
|
|
return;
|
|
|
|
|
|
|
|
_programState->setTexture(texture->getBackendTexture());
|
|
|
|
}
|
|
|
|
|
2019-06-18 15:25:26 +08:00
|
|
|
backend::ProgramState* Node::getProgramState() const
|
|
|
|
{
|
|
|
|
return _programState;
|
|
|
|
}
|
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
NS_CC_END
|