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.
|
2021-07-15 17:32:50 +08:00
|
|
|
Copyright (c) 2021 Bytedance Inc.
|
2010-12-18 16:12:59 +08:00
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
https://axys1.github.io/
|
2010-12-18 16:12:59 +08:00
|
|
|
|
|
|
|
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
|
|
|
|
2021-11-07 16:14:31 +08:00
|
|
|
#include "xxhash.h"
|
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
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
#if AX_NODE_RENDER_SUBPIXEL
|
2021-12-25 10:04:45 +08:00
|
|
|
# define RENDER_IN_SUBPIXEL
|
2010-07-20 14:29:18 +08:00
|
|
|
#else
|
2021-12-25 10:04:45 +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
|
|
|
|
2021-11-07 16:14:31 +08:00
|
|
|
/*
|
2021-12-25 10:04:45 +08:00
|
|
|
* 4.5x faster than std::hash in release mode
|
|
|
|
*/
|
2022-07-15 19:17:01 +08:00
|
|
|
#define AX_HASH_NODE_NAME(name) (!name.empty() ? XXH3_64bits(name.data(), name.length()) : 0)
|
2014-11-24 15:27:20 +08:00
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_BEGIN
|
2010-12-18 16:12:59 +08:00
|
|
|
|
2021-12-25 10:04:45 +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;
|
2021-12-25 10:04:45 +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()
|
2021-12-25 10:04:45 +08:00
|
|
|
: _rotationX(0.0f)
|
|
|
|
, _rotationY(0.0f)
|
|
|
|
, _rotationZ_X(0.0f)
|
|
|
|
, _rotationZ_Y(0.0f)
|
|
|
|
, _scaleX(1.0f)
|
|
|
|
, _scaleY(1.0f)
|
|
|
|
, _scaleZ(1.0f)
|
|
|
|
, _positionZ(0.0f)
|
|
|
|
, _usingNormalizedPosition(false)
|
|
|
|
, _normalizedPositionDirty(false)
|
|
|
|
, _skewX(0.0f)
|
|
|
|
, _skewY(0.0f)
|
|
|
|
, _anchorPoint(0, 0)
|
|
|
|
, _contentSize(Vec2::ZERO)
|
|
|
|
, _contentSizeDirty(true)
|
|
|
|
, _transformDirty(true)
|
|
|
|
, _inverseDirty(true)
|
|
|
|
, _additionalTransform(nullptr)
|
|
|
|
, _additionalTransformDirty(false)
|
|
|
|
, _transformUpdated(true)
|
|
|
|
// children (lazy allocs)
|
|
|
|
, _childrenIndexer(nullptr)
|
|
|
|
// lazy alloc
|
|
|
|
, _localZOrder$Arrival(0LL)
|
|
|
|
, _globalZOrder(0)
|
|
|
|
, _parent(nullptr)
|
|
|
|
// "whole screen" objects. like Scenes and Layers, should set _ignoreAnchorPointForPosition to true
|
|
|
|
, _tag(Node::INVALID_TAG)
|
|
|
|
, _name()
|
|
|
|
, _hashOfName(0)
|
|
|
|
// userData is always inited as nil
|
|
|
|
, _userData(nullptr)
|
|
|
|
, _userObject(nullptr)
|
|
|
|
, _running(false)
|
|
|
|
, _visible(true)
|
|
|
|
, _ignoreAnchorPointForPosition(false)
|
|
|
|
, _reorderChildDirty(false)
|
|
|
|
, _isTransitionFinished(false)
|
2022-07-15 19:17:01 +08:00
|
|
|
#if AX_ENABLE_SCRIPT_BINDING
|
2021-12-25 10:04:45 +08:00
|
|
|
, _scriptHandler(0)
|
|
|
|
, _updateScriptHandler(0)
|
2014-02-20 16:40:46 +08:00
|
|
|
#endif
|
2021-12-25 10:04:45 +08:00
|
|
|
, _componentContainer(nullptr)
|
|
|
|
, _displayedOpacity(255)
|
|
|
|
, _realOpacity(255)
|
|
|
|
, _displayedColor(Color3B::WHITE)
|
|
|
|
, _realColor(Color3B::WHITE)
|
|
|
|
, _cascadeColorEnabled(false)
|
|
|
|
, _cascadeOpacityEnabled(false)
|
2022-04-25 09:37:41 +08:00
|
|
|
, _childFollowCameraMask(false)
|
2021-12-25 10:04:45 +08:00
|
|
|
, _cameraMask(1)
|
|
|
|
, _onEnterCallback(nullptr)
|
|
|
|
, _onExitCallback(nullptr)
|
|
|
|
, _onEnterTransitionDidFinishCallback(nullptr)
|
|
|
|
, _onExitTransitionDidStartCallback(nullptr)
|
2022-07-15 19:17:01 +08:00
|
|
|
#if AX_USE_PHYSICS
|
2021-12-25 10:04:45 +08:00
|
|
|
, _physicsBody(nullptr)
|
2018-05-14 10:34:56 +08:00
|
|
|
#endif
|
2010-12-18 16:12:59 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
// set default scheduler and actionManager
|
2021-12-25 10:04:45 +08:00
|
|
|
_director = Director::getInstance();
|
2015-01-13 10:28:25 +08:00
|
|
|
_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();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
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
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
Node* Node::create()
|
2014-08-29 05:56:15 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
Node* ret = new Node();
|
2021-12-08 00:11:53 +08:00
|
|
|
if (ret->init())
|
2014-08-29 05:56:15 +08:00
|
|
|
{
|
|
|
|
ret->autorelease();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_SAFE_DELETE(ret);
|
2014-08-29 05:56:15 +08:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-07-17 09:16:04 +08:00
|
|
|
Node::~Node()
|
2010-12-18 16:12:59 +08:00
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOGINFO("deallocing Node: %p - tag: %i", this, _tag);
|
2021-11-07 16:14:31 +08:00
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_SAFE_DELETE(_childrenIndexer);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
#if AX_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
|
2021-12-25 10:04:45 +08:00
|
|
|
// It may invoke `node->stopAllActions();` while `_actionManager` is null if the next line is after
|
2022-07-15 19:17:01 +08:00
|
|
|
// `AX_SAFE_RELEASE_NULL(_actionManager)`.
|
|
|
|
AX_SAFE_RELEASE_NULL(_userObject);
|
2010-07-14 10:36:26 +08:00
|
|
|
|
2022-07-21 19:19:08 +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();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_SAFE_DELETE(_componentContainer);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-01-21 21:01:57 +08:00
|
|
|
stopAllActions();
|
|
|
|
unscheduleAllCallbacks();
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_SAFE_RELEASE_NULL(_actionManager);
|
|
|
|
AX_SAFE_RELEASE_NULL(_scheduler);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-03-28 14:43:44 +08:00
|
|
|
_eventDispatcher->removeEventListenersForTarget(this);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
#if AX_NODE_DEBUG_VERIFY_EVENT_LISTENERS && _AX_DEBUG > 0
|
2014-03-28 03:29:28 +08:00
|
|
|
_eventDispatcher->debugCheckNodeHasNoEventListenersOnDestruction(this);
|
|
|
|
#endif
|
2014-03-27 04:12:44 +08:00
|
|
|
|
2022-07-16 10:43:05 +08:00
|
|
|
AXASSERT(!_running,
|
2021-12-25 10:04:45 +08:00
|
|
|
"Node still marked as running on node destruction! Was base class onExit() called in derived class "
|
|
|
|
"onExit() implementations?");
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_SAFE_RELEASE(_eventDispatcher);
|
2016-06-24 10:03:38 +08:00
|
|
|
|
|
|
|
delete[] _additionalTransform;
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_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;
|
|
|
|
}
|
|
|
|
|
2022-06-30 18:01:29 +08:00
|
|
|
bool Node::initLayer() {
|
|
|
|
_ignoreAnchorPointForPosition = true;
|
|
|
|
setAnchorPoint(Vec2(0.5f, 0.5f));
|
|
|
|
setContentSize(_director->getWinSize());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-08-29 05:56:15 +08:00
|
|
|
void Node::cleanup()
|
|
|
|
{
|
2022-07-15 19:17:01 +08:00
|
|
|
#if AX_ENABLE_SCRIPT_BINDING
|
2020-02-24 23:08:47 +08:00
|
|
|
ScriptEngineManager::sendNodeEventToLua(this, kNodeOnCleanup);
|
2022-07-15 19:17:01 +08:00
|
|
|
#endif // #if AX_ENABLE_SCRIPT_BINDING
|
2021-12-25 10:04:45 +08:00
|
|
|
|
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 .
|
2021-12-25 10:04:45 +08:00
|
|
|
// 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.
|
2018-01-17 11:09:23 +08:00
|
|
|
// In fact, user's code should use `node->removeFromParent(false)` in order not to do a cleanup and just remove node
|
2021-12-25 10:04:45 +08:00
|
|
|
// 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);
|
|
|
|
|
|
|
|
for (const auto& child : _children)
|
2014-08-29 05:56:15 +08:00
|
|
|
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;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
_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;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
_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;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
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
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXASSERT(_rotationZ_X == _rotationZ_Y, "CCNode#rotation. RotationX != RotationY. Don't know which one to return");
|
2014-02-23 11:16:42 +08:00
|
|
|
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;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-02-27 15:12:57 +08:00
|
|
|
_rotationZ_X = _rotationZ_Y = rotation;
|
2014-03-01 08:10:48 +08:00
|
|
|
_transformUpdated = _transformDirty = _inverseDirty = true;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
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
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
if (_rotationX == rotation.x && _rotationY == rotation.y && _rotationZ_X == rotation.z)
|
2014-02-27 15:12:57 +08:00
|
|
|
return;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
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;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
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
|
2022-07-16 10:43:05 +08:00
|
|
|
AXASSERT(_rotationZ_X == _rotationZ_Y, "_rotationZ_X != _rotationZ_Y");
|
2014-02-23 11:16:42 +08:00
|
|
|
|
2021-12-25 10:04:45 +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
|
2022-07-15 19:17:01 +08:00
|
|
|
float halfRadx = AX_DEGREES_TO_RADIANS(_rotationX / 2.f), halfRady = AX_DEGREES_TO_RADIANS(_rotationY / 2.f),
|
|
|
|
halfRadz = _rotationZ_X == _rotationZ_Y ? -AX_DEGREES_TO_RADIANS(_rotationZ_X / 2.f) : 0;
|
2021-12-25 10:04:45 +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()
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
// 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;
|
2021-12-25 10:04:45 +08:00
|
|
|
_rotationX = atan2f(2.f * (w * x + y * z), 1.f - 2.f * (x * x + y * y));
|
|
|
|
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));
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
_rotationX = AX_RADIANS_TO_DEGREES(_rotationX);
|
|
|
|
_rotationY = AX_RADIANS_TO_DEGREES(_rotationY);
|
|
|
|
_rotationZ_X = _rotationZ_Y = -AX_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;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
_rotationZ_X = rotationX;
|
2014-03-01 08:10:48 +08:00
|
|
|
_transformUpdated = _transformDirty = _inverseDirty = true;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
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;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
_rotationZ_Y = rotationY;
|
2014-03-01 08:10:48 +08:00
|
|
|
_transformUpdated = _transformDirty = _inverseDirty = true;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
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
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXASSERT(_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;
|
2021-12-25 10:04:45 +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
|
2021-12-25 10:04:45 +08:00
|
|
|
void Node::setScale(float scaleX, float scaleY)
|
2013-10-08 15:57:34 +08:00
|
|
|
{
|
2014-02-27 15:12:57 +08:00
|
|
|
if (_scaleX == scaleX && _scaleY == scaleY)
|
|
|
|
return;
|
2021-12-25 10:04:45 +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;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
_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;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
_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;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
_scaleY = scaleY;
|
2014-03-01 08:10:48 +08:00
|
|
|
_transformUpdated = _transformDirty = _inverseDirty = true;
|
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;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-08-28 11:41:18 +08:00
|
|
|
_position.x = x;
|
|
|
|
_position.y = y;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-08-28 11:41:18 +08:00
|
|
|
_transformUpdated = _transformDirty = _inverseDirty = true;
|
2021-12-25 10:04:45 +08:00
|
|
|
_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
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
return _position.y;
|
2014-02-23 11:16:42 +08:00
|
|
|
}
|
|
|
|
|
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;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
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;
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
_normalizedPosition = position;
|
2014-05-31 07:42:05 +08:00
|
|
|
_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
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
if (visible != _visible)
|
2014-03-07 10:03:34 +08:00
|
|
|
{
|
2014-05-28 17:41:34 +08:00
|
|
|
_visible = visible;
|
2021-12-25 10:04:45 +08:00
|
|
|
if (_visible)
|
2014-12-23 18:07:22 +08:00
|
|
|
_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
|
|
|
{
|
2021-12-25 10:04:45 +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
|
2021-10-23 23:27:14 +08:00
|
|
|
const Vec2& 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
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void Node::setContentSize(const Vec2& size)
|
2010-07-07 15:24:44 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +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
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
bool Node::hitTest(const Vec2& worldPoint) const
|
|
|
|
{
|
|
|
|
auto p = this->convertToNodeSpace(worldPoint);
|
2021-07-15 17:01:57 +08:00
|
|
|
auto& s = this->getContentSize();
|
|
|
|
return Rect{0.f, 0.f, s.width, s.height}.containsPoint(p);
|
|
|
|
}
|
|
|
|
|
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
|
2021-12-25 10:04:45 +08:00
|
|
|
void Node::setParent(Node* parent)
|
2010-07-07 15:24:44 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +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
|
|
|
{
|
2021-12-25 10:04:45 +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
|
|
|
{
|
2021-11-18 19:02:33 +08:00
|
|
|
updateParentChildrenIndexer(tag);
|
2021-12-25 10:04:45 +08:00
|
|
|
_tag = tag;
|
2010-12-18 16:12:59 +08:00
|
|
|
}
|
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
std::string_view Node::getName() const
|
2014-06-11 16:57:43 +08:00
|
|
|
{
|
|
|
|
return _name;
|
|
|
|
}
|
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
void Node::setName(std::string_view name)
|
2021-11-18 19:02:33 +08:00
|
|
|
{
|
|
|
|
updateParentChildrenIndexer(name);
|
|
|
|
_name = name;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Node::updateParentChildrenIndexer(int tag)
|
|
|
|
{
|
|
|
|
auto parentChildrenIndexer = getParentChildrenIndexer();
|
|
|
|
if (parentChildrenIndexer)
|
|
|
|
{
|
|
|
|
if (_tag != tag)
|
|
|
|
parentChildrenIndexer->erase(_tag);
|
|
|
|
(*parentChildrenIndexer)[tag] = this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
void Node::updateParentChildrenIndexer(std::string_view name)
|
2014-06-11 16:57:43 +08:00
|
|
|
{
|
2022-07-15 19:17:01 +08:00
|
|
|
uint64_t newHash = AX_HASH_NODE_NAME(name);
|
2021-11-07 16:14:31 +08:00
|
|
|
auto parentChildrenIndexer = getParentChildrenIndexer();
|
|
|
|
if (parentChildrenIndexer)
|
|
|
|
{
|
2022-07-15 19:17:01 +08:00
|
|
|
auto oldHash = AX_HASH_NODE_NAME(_name);
|
2021-11-07 16:14:31 +08:00
|
|
|
if (oldHash != newHash)
|
|
|
|
parentChildrenIndexer->erase(oldHash);
|
|
|
|
(*parentChildrenIndexer)[newHash] = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
_hashOfName = newHash;
|
|
|
|
}
|
|
|
|
|
|
|
|
NodeIndexerMap_t* Node::getParentChildrenIndexer()
|
|
|
|
{
|
|
|
|
if (!_director->isChildrenIndexerEnabled())
|
|
|
|
return nullptr;
|
|
|
|
auto parent = getParent();
|
2021-11-07 17:08:54 +08:00
|
|
|
if (parent)
|
|
|
|
{
|
|
|
|
auto& indexer = parent->_childrenIndexer;
|
|
|
|
if (!indexer)
|
|
|
|
indexer = new NodeIndexerMap_t();
|
|
|
|
return indexer;
|
|
|
|
}
|
|
|
|
return nullptr;
|
2014-06-11 16:57:43 +08:00
|
|
|
}
|
|
|
|
|
2010-07-12 17:56:06 +08:00
|
|
|
/// userData setter
|
2021-12-25 10:04:45 +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
|
|
|
{
|
2022-07-15 19:17:01 +08:00
|
|
|
#if AX_ENABLE_GC_FOR_NATIVE_OBJECTS
|
2015-12-17 21:55:47 +08:00
|
|
|
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);
|
|
|
|
}
|
2022-07-15 19:17:01 +08:00
|
|
|
#endif // AX_ENABLE_GC_FOR_NATIVE_OBJECTS
|
|
|
|
AX_SAFE_RETAIN(userObject);
|
|
|
|
AX_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;
|
2021-12-25 10:04:45 +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
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXASSERT(tag != Node::INVALID_TAG, "Invalid tag");
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2021-11-07 16:14:31 +08:00
|
|
|
if (_childrenIndexer)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2021-11-07 16:14:31 +08:00
|
|
|
auto it = _childrenIndexer->find(tag);
|
|
|
|
if (it != _childrenIndexer->end())
|
|
|
|
return it->second;
|
|
|
|
}
|
2021-11-18 19:47:15 +08:00
|
|
|
|
|
|
|
for (const auto child : _children)
|
2021-11-07 16:14:31 +08:00
|
|
|
{
|
2021-11-18 19:47:15 +08:00
|
|
|
if (child && child->_tag == tag)
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
Node* Node::getChildByName(std::string_view name) const
|
2014-06-11 16:57:43 +08:00
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
// AXASSERT(!name.empty(), "Invalid name");
|
2022-07-15 19:17:01 +08:00
|
|
|
auto hash = AX_HASH_NODE_NAME(name);
|
2021-11-07 16:14:31 +08:00
|
|
|
if (_childrenIndexer)
|
|
|
|
{
|
|
|
|
auto it = _childrenIndexer->find(hash);
|
|
|
|
if (it != _childrenIndexer->end())
|
|
|
|
return it->second;
|
|
|
|
}
|
2021-11-18 19:47:15 +08:00
|
|
|
|
|
|
|
for (const auto& child : _children)
|
2014-06-11 16:57:43 +08:00
|
|
|
{
|
2021-11-18 19:47:15 +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;
|
2014-06-11 16:57:43 +08:00
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
void Node::enumerateChildren(std::string_view name, std::function<bool(Node*)> callback) const
|
2014-06-12 10:41:08 +08:00
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXASSERT(!name.empty(), "Invalid name");
|
|
|
|
AXASSERT(callback != nullptr, "Invalid callback function");
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-06-17 11:43:03 +08:00
|
|
|
size_t length = name.length();
|
2021-12-25 10:04:45 +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;
|
2021-12-25 10:04:45 +08:00
|
|
|
subStrStartPos = 2;
|
2014-07-10 11:07:39 +08:00
|
|
|
subStrlength -= 2;
|
2014-06-17 11:43:03 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-06-17 11:43:03 +08:00
|
|
|
// End with '/..'?
|
2014-07-02 17:07:36 +08:00
|
|
|
bool searchFromParent = false;
|
2021-12-25 10:04:45 +08:00
|
|
|
if (length > 3 && name[length - 3] == '/' && name[length - 2] == '.' && name[length - 1] == '.')
|
2014-07-02 17:07:36 +08:00
|
|
|
{
|
|
|
|
searchFromParent = true;
|
|
|
|
subStrlength -= 3;
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-07-10 11:07:39 +08:00
|
|
|
// Remove '//', '/..' if exist
|
2021-12-26 23:26:34 +08:00
|
|
|
auto newName = name.substr(subStrStartPos, subStrlength);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-10-17 11:12:25 +08:00
|
|
|
const Node* target = this;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
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
|
|
|
}
|
2021-12-25 10:04:45 +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
|
2021-12-26 23:26:34 +08:00
|
|
|
target->doEnumerate(std::string{newName}, callback);
|
2014-06-17 11:43:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
bool Node::doEnumerateRecursive(const Node* node, std::string_view name, std::function<bool(Node*)> callback) const
|
2014-06-17 11:43:03 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
bool ret = false;
|
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
if (node->doEnumerate(std::string{name}, callback))
|
2014-06-17 11:43:03 +08:00
|
|
|
{
|
|
|
|
// 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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-06-17 11:43:03 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
bool Node::doEnumerate(std::string name, std::function<bool(Node*)> callback) const
|
2014-06-17 11:43:03 +08:00
|
|
|
{
|
|
|
|
// name may be xxx/yyy, should find its parent
|
2021-12-25 10:04:45 +08:00
|
|
|
size_t pos = name.find('/');
|
2014-06-17 11:43:03 +08:00
|
|
|
std::string searchName = name;
|
2021-12-25 10:04:45 +08:00
|
|
|
bool needRecursive = false;
|
2014-06-17 11:43:03 +08:00
|
|
|
if (pos != name.npos)
|
|
|
|
{
|
|
|
|
searchName = name.substr(0, pos);
|
2021-12-25 10:04:45 +08:00
|
|
|
name.erase(0, pos + 1);
|
2014-06-17 11:43:03 +08:00
|
|
|
needRecursive = true;
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-06-17 11:43:03 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2021-12-25 10:04:45 +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
|
2021-12-25 10:04:45 +08:00
|
|
|
* If a class want's to extend the 'addChild' behavior it only needs
|
|
|
|
* to override this method
|
|
|
|
*/
|
|
|
|
void Node::addChild(Node* child, int localZOrder, int tag)
|
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXASSERT(child != nullptr, "Argument must be non-nil");
|
|
|
|
AXASSERT(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);
|
|
|
|
}
|
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
void Node::addChild(Node* child, int localZOrder, std::string_view name)
|
2014-06-25 11:27:48 +08:00
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXASSERT(child != nullptr, "Argument must be non-nil");
|
|
|
|
AXASSERT(child->_parent == nullptr, "child already added. It can't be added again");
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-06-25 11:27:48 +08:00
|
|
|
addChildHelper(child, localZOrder, INVALID_TAG, name, false);
|
|
|
|
}
|
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
void Node::addChildHelper(Node* child, int localZOrder, int tag, std::string_view name, bool setTag)
|
2014-06-25 11:27:48 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
auto assertNotSelfChild([this, child]() -> bool {
|
|
|
|
for (Node* parent(getParent()); parent != nullptr; parent = parent->getParent())
|
|
|
|
if (parent == child)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
});
|
2017-02-08 10:02:10 +08:00
|
|
|
(void)assertNotSelfChild;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-07-16 10:43:05 +08:00
|
|
|
AXASSERT(assertNotSelfChild(), "A node cannot be the child of his own children");
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2013-11-28 18:23:06 +08:00
|
|
|
if (_children.empty())
|
2013-11-28 17:57:13 +08:00
|
|
|
{
|
|
|
|
this->childrenAlloc();
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-06-25 11:27:48 +08:00
|
|
|
this->insertChild(child, localZOrder);
|
2021-11-07 16:14:31 +08:00
|
|
|
|
|
|
|
child->setParent(this);
|
2022-04-25 09:37:41 +08:00
|
|
|
|
|
|
|
if (_childFollowCameraMask)
|
2022-04-27 16:23:57 +08:00
|
|
|
{
|
2022-04-25 09:37:41 +08:00
|
|
|
child->setCameraMask(this->getCameraMask());
|
2022-04-27 16:23:57 +08:00
|
|
|
child->applyMaskOnEnter(true);
|
|
|
|
}
|
2022-04-25 09:37:41 +08:00
|
|
|
|
2014-06-25 11:27:48 +08:00
|
|
|
if (setTag)
|
2021-11-18 19:02:33 +08:00
|
|
|
{
|
2014-06-25 11:27:48 +08:00
|
|
|
child->setTag(tag);
|
2021-11-18 19:02:33 +08:00
|
|
|
child->updateParentChildrenIndexer(child->getName());
|
|
|
|
}
|
2014-06-25 11:27:48 +08:00
|
|
|
else
|
2021-11-18 19:02:33 +08:00
|
|
|
{
|
2014-06-25 11:27:48 +08:00
|
|
|
child->setName(name);
|
2021-11-18 19:02:33 +08:00
|
|
|
child->updateParentChildrenIndexer(child->getTag());
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2016-07-31 22:44:24 +08:00
|
|
|
child->updateOrderOfArrival();
|
|
|
|
|
2021-12-25 10:04:45 +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
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2013-12-06 18:07:16 +08:00
|
|
|
if (_cascadeColorEnabled)
|
|
|
|
{
|
|
|
|
updateCascadeColor();
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2013-12-06 18:07:16 +08:00
|
|
|
if (_cascadeOpacityEnabled)
|
|
|
|
{
|
|
|
|
updateCascadeOpacity();
|
|
|
|
}
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void Node::addChild(Node* child, int zOrder)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXASSERT(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
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void Node::addChild(Node* child)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXASSERT(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
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
_parent->removeChild(this, cleanup);
|
|
|
|
}
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* "remove" logic MUST only be on this method
|
2021-12-25 10:04:45 +08:00
|
|
|
* 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);
|
2022-07-15 19:17:01 +08:00
|
|
|
if (index != AX_INVALID_INDEX)
|
2021-12-25 10:04:45 +08:00
|
|
|
this->detachChild(child, index, cleanup);
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void Node::removeChildByTag(int tag, bool cleanup /* = true */)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXASSERT(tag != Node::INVALID_TAG, "Invalid tag");
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2021-12-25 10:04:45 +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
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("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
|
|
|
}
|
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
void Node::removeChildByName(std::string_view name, bool cleanup)
|
2014-06-25 11:27:48 +08:00
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXASSERT(!name.empty(), "Invalid name");
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
Node* child = this->getChildByName(name);
|
|
|
|
|
2014-06-25 11:27:48 +08:00
|
|
|
if (child == nullptr)
|
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("cocos2d: removeChildByName(name = %s): child not found!", name.data());
|
2014-06-25 11:27:48 +08:00
|
|
|
}
|
|
|
|
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
|
|
|
{
|
2021-09-18 14:06:52 +08:00
|
|
|
resetChild(child, cleanup);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2013-12-19 08:56:59 +08:00
|
|
|
_children.clear();
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_SAFE_DELETE(_childrenIndexer);
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2021-09-18 14:06:52 +08:00
|
|
|
void Node::resetChild(Node* child, bool cleanup)
|
|
|
|
{ // IMPORTANT:
|
2012-04-19 14:35:52 +08:00
|
|
|
// -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!
|
2021-09-18 14:06:52 +08:00
|
|
|
if (cleanup)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
child->cleanup();
|
|
|
|
}
|
2021-09-18 14:06:52 +08:00
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
#if AX_ENABLE_GC_FOR_NATIVE_OBJECTS
|
2016-02-16 13:43:11 +08:00
|
|
|
auto sEngine = ScriptEngineManager::getInstance()->getScriptEngine();
|
|
|
|
if (sEngine)
|
|
|
|
{
|
|
|
|
sEngine->releaseScriptObject(this, child);
|
|
|
|
}
|
2022-07-15 19:17:01 +08:00
|
|
|
#endif // AX_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);
|
2021-09-18 14:06:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Node::detachChild(Node* child, ssize_t childIndex, bool cleanup)
|
|
|
|
{
|
2021-11-25 16:27:43 +08:00
|
|
|
if (_childrenIndexer)
|
|
|
|
{
|
|
|
|
_childrenIndexer->erase(child->_tag);
|
|
|
|
_childrenIndexer->erase(child->_hashOfName);
|
|
|
|
}
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2021-11-25 16:27:43 +08:00
|
|
|
resetChild(child, cleanup);
|
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
|
|
|
{
|
2022-07-15 19:17:01 +08:00
|
|
|
#if AX_ENABLE_GC_FOR_NATIVE_OBJECTS
|
2016-02-16 13:43:11 +08:00
|
|
|
auto sEngine = ScriptEngineManager::getInstance()->getScriptEngine();
|
|
|
|
if (sEngine)
|
|
|
|
{
|
|
|
|
sEngine->retainScriptObject(this, child);
|
|
|
|
}
|
2022-07-15 19:17:01 +08:00
|
|
|
#endif // AX_ENABLE_GC_FOR_NATIVE_OBJECTS
|
2021-12-25 10:04:45 +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
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void Node::reorderChild(Node* child, int zOrder)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXASSERT(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
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void Node::draw(Renderer* /*renderer*/, const Mat4& /*transform*/, uint32_t /*flags*/) {}
|
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
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
auto renderer = _director->getRenderer();
|
2015-01-13 10:28:25 +08:00
|
|
|
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)
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
if (_usingNormalizedPosition)
|
2014-12-23 18:07:22 +08:00
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXASSERT(_parent, "setPositionNormalized() doesn't work with orphan nodes");
|
2014-12-23 18:07:22 +08:00
|
|
|
if ((parentFlags & FLAGS_CONTENT_SIZE_DIRTY) || _normalizedPositionDirty)
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
auto& s = _parent->getContentSize();
|
|
|
|
_position.x = _normalizedPosition.x * s.width;
|
|
|
|
_position.y = _normalizedPosition.y * s.height;
|
2014-08-06 14:38:58 +08:00
|
|
|
_transformUpdated = _transformDirty = _inverseDirty = true;
|
2021-12-25 10:04:45 +08:00
|
|
|
_normalizedPositionDirty = false;
|
2014-08-06 14:38:58 +08:00
|
|
|
}
|
|
|
|
}
|
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-05-31 07:42:05 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
if (flags & FLAGS_DIRTY_MASK)
|
2014-05-31 07:42:05 +08:00
|
|
|
_modelViewTransform = this->transform(parentTransform);
|
2021-12-25 10:04: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
|
|
|
{
|
2021-12-25 10:04:45 +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;
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +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);
|
2021-12-25 10:04:45 +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
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
if (!_children.empty())
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
sortAllChildren();
|
|
|
|
// draw children zOrder < 0
|
2021-12-25 10:04:45 +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
|
|
|
|
2021-12-25 10:04:45 +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);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
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;
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-07-28 16:05:47 +08:00
|
|
|
if (_onEnterCallback)
|
|
|
|
_onEnterCallback();
|
|
|
|
|
|
|
|
if (_componentContainer && !_componentContainer->isEmpty())
|
|
|
|
{
|
|
|
|
_componentContainer->onEnter();
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-03-08 11:51:10 +08:00
|
|
|
_isTransitionFinished = false;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
for (const auto& child : _children)
|
2013-12-30 11:10:02 +08:00
|
|
|
child->onEnter();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2013-12-30 11:10:02 +08:00
|
|
|
this->resume();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2013-12-30 11:10:02 +08:00
|
|
|
_running = true;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
#if AX_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;
|
2021-12-25 10:04:45 +08:00
|
|
|
for (const auto& child : _children)
|
2013-12-30 11:10:02 +08:00
|
|
|
child->onEnterTransitionDidFinish();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
#if AX_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();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
for (const auto& child : _children)
|
2013-11-28 16:02:03 +08:00
|
|
|
child->onExitTransitionDidStart();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
#if AX_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;
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-07-28 16:05:47 +08:00
|
|
|
if (_onExitCallback)
|
|
|
|
_onExitCallback();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-07-28 16:05:47 +08:00
|
|
|
if (_componentContainer && !_componentContainer->isEmpty())
|
|
|
|
{
|
|
|
|
_componentContainer->onExit();
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2013-10-26 15:04:01 +08:00
|
|
|
this->pause();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_running = false;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
for (const auto& child : _children)
|
2013-12-30 11:10:02 +08:00
|
|
|
child->onExit();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
#if AX_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);
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_SAFE_RETAIN(dispatcher);
|
|
|
|
AX_SAFE_RELEASE(_eventDispatcher);
|
2013-10-26 15:04:01 +08:00
|
|
|
_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
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
if (actionManager != _actionManager)
|
2014-12-23 18:07:22 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
this->stopAllActions();
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_SAFE_RETAIN(actionManager);
|
|
|
|
AX_SAFE_RELEASE(_actionManager);
|
2013-06-15 14:03:30 +08:00
|
|
|
_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
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
Action* Node::runAction(Action* action)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXASSERT(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
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXASSERT(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)
|
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXASSERT(tag != Action::INVALID_TAG, "Invalid tag");
|
2014-07-22 16:04:22 +08:00
|
|
|
_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
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
Action* Node::getActionByTag(int tag)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXASSERT(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
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
if (scheduler != _scheduler)
|
2014-12-23 18:07:22 +08:00
|
|
|
{
|
2014-10-04 00:38:36 +08:00
|
|
|
this->unscheduleAllCallbacks();
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_SAFE_RETAIN(scheduler);
|
|
|
|
AX_SAFE_RELEASE(_scheduler);
|
2013-06-15 14:03:30 +08:00
|
|
|
_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
|
|
|
}
|
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
bool Node::isScheduled(std::string_view 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();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
#if AX_ENABLE_SCRIPT_BINDING
|
2013-06-15 14:03:30 +08:00
|
|
|
_updateScriptHandler = nHandler;
|
2014-02-20 16:40:46 +08:00
|
|
|
#endif
|
2021-12-25 10:04:45 +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);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
#if AX_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
|
|
|
{
|
2022-07-15 19:17:01 +08:00
|
|
|
this->schedule(selector, 0.0f, AX_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
|
|
|
{
|
2022-07-15 19:17:01 +08:00
|
|
|
this->schedule(selector, interval, AX_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
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXASSERT(selector, "Argument must be non-nil");
|
|
|
|
AXASSERT(interval >= 0, "Argument must be positive");
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
_scheduler->schedule(selector, this, interval, repeat, delay, !_running);
|
2012-03-14 14:55:17 +08:00
|
|
|
}
|
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
void Node::schedule(const std::function<void(float)>& callback, std::string_view key)
|
2014-10-04 00:38:36 +08:00
|
|
|
{
|
|
|
|
_scheduler->schedule(callback, this, 0, !_running, key);
|
|
|
|
}
|
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
void Node::schedule(const std::function<void(float)>& callback, float interval, std::string_view key)
|
2014-10-03 12:25:55 +08:00
|
|
|
{
|
|
|
|
_scheduler->schedule(callback, this, interval, !_running, key);
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void Node::schedule(const std::function<void(float)>& callback,
|
|
|
|
float interval,
|
|
|
|
unsigned int repeat,
|
|
|
|
float delay,
|
2021-12-26 23:26:34 +08:00
|
|
|
std::string_view key)
|
2014-10-03 12:25:55 +08:00
|
|
|
{
|
|
|
|
_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
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
void Node::scheduleOnce(const std::function<void(float)>& callback, float delay, std::string_view key)
|
2014-10-03 12:25:55 +08:00
|
|
|
{
|
|
|
|
_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;
|
2021-12-25 10:04:45 +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
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
void Node::unschedule(std::string_view key)
|
2014-10-03 12:25:55 +08:00
|
|
|
{
|
|
|
|
_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
|
|
|
{
|
2022-07-15 19:17:01 +08:00
|
|
|
#if AX_ENABLE_SCRIPT_BINDING
|
2013-07-02 15:23:51 +08:00
|
|
|
if (0 != _updateScriptHandler)
|
2012-12-10 13:48:27 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
// only lua use
|
|
|
|
SchedulerScriptData data(_updateScriptHandler, fDelta);
|
|
|
|
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
|
2021-12-25 10:04:45 +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());
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
for (Node* p = _parent; p != nullptr && p != ancestor; p = p->getParent())
|
2015-07-20 10:03:15 +08:00
|
|
|
{
|
|
|
|
t = p->getNodeToParentTransform() * t;
|
|
|
|
}
|
|
|
|
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
|
|
|
AffineTransform Node::getNodeToParentAffineTransform(Node* ancestor) const
|
|
|
|
{
|
|
|
|
AffineTransform t(this->getNodeToParentAffineTransform());
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
for (Node* p = _parent; p != nullptr && p != ancestor; p = p->getParent())
|
2015-07-20 10:03:15 +08:00
|
|
|
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;
|
2021-12-25 10:04:45 +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
|
|
|
}
|
2021-12-25 10:04:45 +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;
|
2021-12-25 10:04:45 +08:00
|
|
|
// move to anchor point first, then rotate
|
2016-10-31 10:29:04 +08:00
|
|
|
Mat4::createTranslation(x, y, z, &translation);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-12-24 18:12:00 +08:00
|
|
|
Mat4::createRotation(_rotationQuat, &_transform);
|
2021-12-25 10:04:45 +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
|
2022-07-15 19:17:01 +08:00
|
|
|
float radiansX = -AX_DEGREES_TO_RADIANS(_rotationZ_X);
|
|
|
|
float radiansY = -AX_DEGREES_TO_RADIANS(_rotationZ_Y);
|
2021-12-25 10:04:45 +08:00
|
|
|
float cx = cosf(radiansX);
|
|
|
|
float sx = sinf(radiansX);
|
|
|
|
float cy = cosf(radiansY);
|
|
|
|
float sy = sinf(radiansY);
|
|
|
|
|
|
|
|
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;
|
2021-12-25 10:04:45 +08:00
|
|
|
_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
|
|
|
}
|
2021-12-25 10:04:45 +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
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
float skewMatArray[16] = {1,
|
2022-07-15 19:17:01 +08:00
|
|
|
(float)tanf(AX_DEGREES_TO_RADIANS(_skewY)),
|
2021-12-25 10:04:45 +08:00
|
|
|
0,
|
|
|
|
0,
|
2022-07-15 19:17:01 +08:00
|
|
|
(float)tanf(AX_DEGREES_TO_RADIANS(_skewX)),
|
2021-12-25 10:04:45 +08:00
|
|
|
1,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
1,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
1};
|
2014-08-29 09:50:26 +08:00
|
|
|
Mat4 skewMatrix(skewMatArray);
|
2021-12-25 10:04:45 +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
|
|
|
{
|
2021-12-25 10:04:45 +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)
|
|
|
|
{
|
2021-12-25 10:04:45 +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
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
if (!_additionalTransform)
|
|
|
|
{
|
2016-06-24 10:03:38 +08:00
|
|
|
_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;
|
|
|
|
|
2021-12-25 10:04:45 +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
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
if (_inverseDirty)
|
2014-12-23 18:07:22 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +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
|
|
|
}
|
|
|
|
|
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;
|
2021-12-25 10:04:45 +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;
|
2021-12-25 10:04:45 +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::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
|
2021-12-25 10:04:45 +08:00
|
|
|
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
|
|
|
|
2021-12-25 10:04:45 +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
|
2021-12-25 10:04:45 +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
|
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
Component* Node::getComponent(std::string_view 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);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2013-09-07 07:00:24 +08:00
|
|
|
return nullptr;
|
2013-06-04 17:38:43 +08:00
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +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)
|
2021-12-08 00:11:53 +08:00
|
|
|
_componentContainer = new ComponentContainer(this);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-07-08 10:11:17 +08:00
|
|
|
// should enable schedule update, then all components can receive this call back
|
|
|
|
scheduleUpdate();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-05-28 17:41:34 +08:00
|
|
|
return _componentContainer->add(component);
|
2013-06-04 17:38:43 +08:00
|
|
|
}
|
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
bool Node::removeComponent(std::string_view 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);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2013-09-07 07:00:24 +08:00
|
|
|
return false;
|
2013-06-04 17:38:43 +08:00
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
bool Node::removeComponent(Component* component)
|
2014-07-21 17:45:56 +08:00
|
|
|
{
|
2014-12-23 18:07:22 +08:00
|
|
|
if (_componentContainer)
|
|
|
|
{
|
2014-08-06 13:51:16 +08:00
|
|
|
return _componentContainer->remove(component);
|
|
|
|
}
|
2021-12-25 10:04:45 +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;
|
2021-12-25 10:04:45 +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
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
_displayedOpacity = _realOpacity * parentOpacity / 255.0;
|
2013-12-11 15:57:20 +08:00
|
|
|
updateColor();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2013-02-27 18:21:35 +08:00
|
|
|
if (_cascadeOpacityEnabled)
|
2013-02-27 14:48:19 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
for (const auto& child : _children)
|
2014-12-23 18:07:22 +08:00
|
|
|
{
|
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;
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2013-02-27 15:30:49 +08:00
|
|
|
_cascadeOpacityEnabled = cascadeOpacityEnabled;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
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;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2013-12-06 18:07:16 +08:00
|
|
|
if (_parent != nullptr && _parent->isCascadeOpacityEnabled())
|
|
|
|
{
|
|
|
|
parentOpacity = _parent->getDisplayedOpacity();
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2013-12-06 18:07:16 +08:00
|
|
|
updateDisplayedOpacity(parentOpacity);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Node::disableCascadeOpacity()
|
|
|
|
{
|
|
|
|
_displayedOpacity = _realOpacity;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
for (const auto& child : _children)
|
2014-12-23 18:07:22 +08:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void Node::setOpacityModifyRGB(bool /*value*/) {}
|
2016-11-16 09:48:37 +08:00
|
|
|
|
|
|
|
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;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-01-08 10:22:45 +08:00
|
|
|
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
|
|
|
{
|
2021-12-25 10:04: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();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2013-02-27 14:48:19 +08:00
|
|
|
if (_cascadeColorEnabled)
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
for (const auto& child : _children)
|
2014-12-23 18:07:22 +08:00
|
|
|
{
|
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;
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2013-02-27 15:30:49 +08:00
|
|
|
_cascadeColorEnabled = cascadeColorEnabled;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
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();
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2013-12-06 18:07:16 +08:00
|
|
|
updateDisplayedColor(parentColor);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Node::disableCascadeColor()
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
for (const auto& child : _children)
|
2014-12-23 18:07:22 +08:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
bool isScreenPointInRect(const Vec2& pt, const Camera* camera, const Mat4& w2l, const Rect& rect, Vec3* p)
|
2015-06-18 10:23:52 +08:00
|
|
|
{
|
|
|
|
if (nullptr == camera || rect.size.width <= 0 || rect.size.height <= 0)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-06-18 10:23:52 +08:00
|
|
|
// 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);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-06-18 10:23:52 +08:00
|
|
|
// 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;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-06-18 10:23:52 +08:00
|
|
|
// 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;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-06-18 10:23:52 +08:00
|
|
|
// 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);
|
2021-12-25 10:04:45 +08:00
|
|
|
if (BxCdotE == 0)
|
|
|
|
{
|
2015-06-18 10:23:52 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
auto t = (BxC.dot(A) - BxC.dot(Pn)) / BxCdotE;
|
|
|
|
Vec3 P = Pn + t * E;
|
2021-12-25 10:04:45 +08:00
|
|
|
if (p)
|
|
|
|
{
|
2015-06-18 10:23:52 +08:00
|
|
|
*p = P;
|
|
|
|
}
|
|
|
|
return rect.containsPoint(Vec2(P.x, P.y));
|
|
|
|
}
|
|
|
|
|
2022-04-25 09:37:41 +08:00
|
|
|
void Node::applyMaskOnEnter(bool applyChildren)
|
|
|
|
{
|
|
|
|
_childFollowCameraMask = applyChildren;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-10-16 16:23:14 +08:00
|
|
|
void Node::setProgramStateWithRegistry(uint32_t programType, Texture2D* texture)
|
2019-11-20 18:19:24 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
auto samplerFlags = texture ? texture->getSamplerFlags() : 0;
|
2021-06-27 20:58:50 +08:00
|
|
|
auto programState = backend::ProgramStateRegistry::getInstance()->newProgramState(programType, samplerFlags);
|
2020-10-16 16:23:14 +08:00
|
|
|
setProgramState(programState, false);
|
2019-11-20 18:19:24 +08:00
|
|
|
}
|
|
|
|
|
2020-10-16 16:23:14 +08:00
|
|
|
bool Node::setProgramState(backend::ProgramState* programState, bool needsRetain)
|
2019-06-18 15:25:26 +08:00
|
|
|
{
|
|
|
|
if (_programState != programState)
|
|
|
|
{
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_SAFE_RELEASE(_programState);
|
2019-06-18 15:25:26 +08:00
|
|
|
_programState = programState;
|
2021-12-25 10:04:45 +08:00
|
|
|
if (needsRetain)
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_SAFE_RETAIN(_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;
|
|
|
|
}
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_END
|