2010-11-13 11:34:49 +08:00
|
|
|
/****************************************************************************
|
2011-09-05 10:12:14 +08:00
|
|
|
Copyright (c) 2008-2010 Ricardo Quesada
|
2014-01-07 11:25:07 +08:00
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
|
|
|
Copyright (c) 2011 Zynga Inc.
|
2017-02-14 14:36:57 +08:00
|
|
|
Copyright (c) 2013-2017 Chukong Technologies Inc.
|
2011-03-19 10:34:26 +08:00
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
2010-11-13 11:34:49 +08:00
|
|
|
|
2014-04-27 01:11:22 +08:00
|
|
|
#include "2d/CCActionInstant.h"
|
|
|
|
#include "2d/CCNode.h"
|
|
|
|
#include "2d/CCSprite.h"
|
2011-01-15 18:05:35 +08:00
|
|
|
|
2013-07-25 15:03:44 +08:00
|
|
|
#if defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)))
|
|
|
|
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
|
|
|
#elif _MSC_VER >= 1400 //vs 2005 or higher
|
|
|
|
#pragma warning (push)
|
|
|
|
#pragma warning (disable: 4996)
|
|
|
|
#endif
|
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
NS_CC_BEGIN
|
2011-09-05 10:12:14 +08:00
|
|
|
//
|
|
|
|
// InstantAction
|
|
|
|
//
|
2017-03-22 14:17:49 +08:00
|
|
|
void ActionInstant::startWithTarget(Node *target)
|
|
|
|
{
|
|
|
|
FiniteTimeAction::startWithTarget(target);
|
|
|
|
_done = false;
|
|
|
|
}
|
|
|
|
|
2013-07-07 13:01:21 +08:00
|
|
|
bool ActionInstant::isDone() const
|
|
|
|
{
|
2017-03-22 14:17:49 +08:00
|
|
|
return _done;
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
void ActionInstant::step(float /*dt*/)
|
2016-04-08 13:40:36 +08:00
|
|
|
{
|
2015-08-27 17:55:38 +08:00
|
|
|
float updateDt = 1;
|
|
|
|
#if CC_ENABLE_SCRIPT_BINDING
|
|
|
|
if (_scriptType == kScriptTypeJavascript)
|
|
|
|
{
|
|
|
|
if (ScriptEngineManager::sendActionEventToJS(this, kActionUpdate, (void *)&updateDt))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
update(updateDt);
|
2017-03-22 14:17:49 +08:00
|
|
|
_done = true;
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
void ActionInstant::update(float /*time*/)
|
2016-04-08 13:40:36 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
// nothing
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Show
|
|
|
|
//
|
2012-06-14 17:18:05 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
Show* Show::create()
|
2012-06-14 17:18:05 +08:00
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
Show* ret = new (std::nothrow) Show();
|
2011-09-05 10:12:14 +08:00
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
if (ret)
|
|
|
|
{
|
2013-11-16 21:08:00 +08:00
|
|
|
ret->autorelease();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2013-11-16 21:08:00 +08:00
|
|
|
return ret;
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
void Show::update(float /*time*/)
|
2016-04-08 13:40:36 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_target->setVisible(true);
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
ActionInstant* Show::reverse() const
|
2013-06-16 03:38:32 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
return Hide::create();
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
Show* Show::clone() const
|
2013-06-14 08:25:14 +08:00
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
// no copy constructor
|
2016-04-08 13:40:36 +08:00
|
|
|
return Show::create();
|
2013-06-14 08:25:14 +08:00
|
|
|
}
|
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
//
|
|
|
|
// Hide
|
|
|
|
//
|
2013-06-20 14:13:12 +08:00
|
|
|
Hide * Hide::create()
|
2012-06-14 17:18:05 +08:00
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
Hide *ret = new (std::nothrow) Hide();
|
2011-09-05 10:12:14 +08:00
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
if (ret)
|
|
|
|
{
|
2013-11-16 21:08:00 +08:00
|
|
|
ret->autorelease();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2013-11-16 21:08:00 +08:00
|
|
|
return ret;
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
void Hide::update(float /*time*/)
|
2016-04-08 13:40:36 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_target->setVisible(false);
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
ActionInstant *Hide::reverse() const
|
2013-06-16 03:38:32 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
return Show::create();
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
Hide* Hide::clone() const
|
2013-06-14 08:25:14 +08:00
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
// no copy constructor
|
2016-04-08 13:40:36 +08:00
|
|
|
return Hide::create();
|
2013-06-14 08:25:14 +08:00
|
|
|
}
|
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
//
|
|
|
|
// ToggleVisibility
|
|
|
|
//
|
2013-06-20 14:13:12 +08:00
|
|
|
ToggleVisibility * ToggleVisibility::create()
|
2012-05-30 16:34:42 +08:00
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
ToggleVisibility *ret = new (std::nothrow) ToggleVisibility();
|
2011-09-05 10:12:14 +08:00
|
|
|
|
2013-11-16 21:08:00 +08:00
|
|
|
if (ret)
|
2012-05-30 16:34:42 +08:00
|
|
|
{
|
2013-11-16 21:08:00 +08:00
|
|
|
ret->autorelease();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2010-08-05 17:22:47 +08:00
|
|
|
|
2013-11-16 21:08:00 +08:00
|
|
|
return ret;
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
void ToggleVisibility::update(float /*time*/)
|
2012-05-30 16:34:42 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_target->setVisible(!_target->isVisible());
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
ToggleVisibility * ToggleVisibility::reverse() const
|
2013-06-16 03:38:32 +08:00
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
return ToggleVisibility::create();
|
2013-06-16 03:38:32 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
ToggleVisibility * ToggleVisibility::clone() const
|
2013-06-14 08:25:14 +08:00
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
// no copy constructor
|
2016-04-08 13:40:36 +08:00
|
|
|
return ToggleVisibility::create();
|
2013-06-14 08:25:14 +08:00
|
|
|
}
|
|
|
|
|
2013-03-25 11:10:51 +08:00
|
|
|
//
|
|
|
|
// Remove Self
|
|
|
|
//
|
2013-06-20 14:13:12 +08:00
|
|
|
RemoveSelf * RemoveSelf::create(bool isNeedCleanUp /*= true*/)
|
2013-03-25 11:10:51 +08:00
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
RemoveSelf *ret = new (std::nothrow) RemoveSelf();
|
2013-03-25 11:10:51 +08:00
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
if (ret && ret->init(isNeedCleanUp))
|
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
ret->autorelease();
|
|
|
|
}
|
2013-03-25 11:10:51 +08:00
|
|
|
|
2015-01-08 10:22:45 +08:00
|
|
|
return ret;
|
2013-03-25 11:10:51 +08:00
|
|
|
}
|
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
bool RemoveSelf::init(bool isNeedCleanUp)
|
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
_isNeedCleanUp = isNeedCleanUp;
|
|
|
|
return true;
|
2013-03-25 18:18:38 +08:00
|
|
|
}
|
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
void RemoveSelf::update(float /*time*/)
|
2016-04-08 13:40:36 +08:00
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
_target->removeFromParentAndCleanup(_isNeedCleanUp);
|
2013-03-25 11:10:51 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
RemoveSelf *RemoveSelf::reverse() const
|
2013-06-16 03:38:32 +08:00
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
return RemoveSelf::create(_isNeedCleanUp);
|
2013-03-25 11:10:51 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
RemoveSelf * RemoveSelf::clone() const
|
2013-06-14 08:25:14 +08:00
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
// no copy constructor
|
2016-04-08 13:40:36 +08:00
|
|
|
return RemoveSelf::create(_isNeedCleanUp);
|
2013-06-14 08:25:14 +08:00
|
|
|
}
|
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
//
|
|
|
|
// FlipX
|
|
|
|
//
|
2012-06-14 17:18:05 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
FlipX *FlipX::create(bool x)
|
2012-06-14 17:18:05 +08:00
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
FlipX *ret = new (std::nothrow) FlipX();
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
if (ret && ret->initWithFlipX(x))
|
|
|
|
{
|
2013-11-16 21:08:00 +08:00
|
|
|
ret->autorelease();
|
|
|
|
return ret;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2013-11-16 21:08:00 +08:00
|
|
|
CC_SAFE_DELETE(ret);
|
|
|
|
return nullptr;
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
bool FlipX::initWithFlipX(bool x)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_flipX = x;
|
2012-04-19 14:35:52 +08:00
|
|
|
return true;
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
void FlipX::update(float /*time*/)
|
2016-04-08 13:40:36 +08:00
|
|
|
{
|
2013-09-16 20:38:03 +08:00
|
|
|
static_cast<Sprite*>(_target)->setFlippedX(_flipX);
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
FlipX* FlipX::reverse() const
|
2013-06-16 03:38:32 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
return FlipX::create(!_flipX);
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
FlipX * FlipX::clone() const
|
2013-06-14 08:25:14 +08:00
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
// no copy constructor
|
2016-04-08 13:40:36 +08:00
|
|
|
return FlipX::create(_flipX);
|
2013-06-14 08:25:14 +08:00
|
|
|
}
|
2011-09-05 10:12:14 +08:00
|
|
|
//
|
|
|
|
// FlipY
|
|
|
|
//
|
2012-06-14 17:18:05 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
FlipY * FlipY::create(bool y)
|
2012-06-14 17:18:05 +08:00
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
FlipY *ret = new (std::nothrow) FlipY();
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
if (ret && ret->initWithFlipY(y))
|
|
|
|
{
|
2013-11-16 21:08:00 +08:00
|
|
|
ret->autorelease();
|
|
|
|
return ret;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2013-11-16 21:08:00 +08:00
|
|
|
CC_SAFE_DELETE(ret);
|
|
|
|
return nullptr;
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
bool FlipY::initWithFlipY(bool y)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_flipY = y;
|
2012-04-19 14:35:52 +08:00
|
|
|
return true;
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
void FlipY::update(float /*time*/)
|
2016-04-08 13:40:36 +08:00
|
|
|
{
|
2013-09-16 20:38:03 +08:00
|
|
|
static_cast<Sprite*>(_target)->setFlippedY(_flipY);
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
FlipY* FlipY::reverse() const
|
2013-06-16 03:38:32 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
return FlipY::create(!_flipY);
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
FlipY * FlipY::clone() const
|
2013-06-14 08:25:14 +08:00
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
// no copy constructor
|
2016-04-08 13:40:36 +08:00
|
|
|
return FlipY::create(_flipY);
|
2013-06-14 08:25:14 +08:00
|
|
|
}
|
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
//
|
|
|
|
// Place
|
|
|
|
//
|
2012-06-14 17:18:05 +08:00
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Place* Place::create(const Vec2& pos)
|
2012-06-14 17:18:05 +08:00
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
Place *ret = new (std::nothrow) Place();
|
2011-09-05 10:12:14 +08:00
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
if (ret && ret->initWithPosition(pos))
|
|
|
|
{
|
2013-11-16 21:08:00 +08:00
|
|
|
ret->autorelease();
|
|
|
|
return ret;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2010-08-05 17:22:47 +08:00
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
delete ret;
|
2013-11-16 21:08:00 +08:00
|
|
|
return nullptr;
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
bool Place::initWithPosition(const Vec2& pos)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_position = pos;
|
2012-04-19 14:35:52 +08:00
|
|
|
return true;
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
Place * Place::clone() const
|
2013-06-14 08:25:14 +08:00
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
// no copy constructor
|
2016-04-08 13:40:36 +08:00
|
|
|
return Place::create(_position);
|
2013-06-14 08:25:14 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
Place * Place::reverse() const
|
2013-06-16 10:44:39 +08:00
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
// no reverse, just clone
|
|
|
|
return this->clone();
|
2013-06-16 10:44:39 +08:00
|
|
|
}
|
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
void Place::update(float /*time*/)
|
2016-04-08 13:40:36 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_target->setPosition(_position);
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// CallFunc
|
|
|
|
//
|
2013-06-04 03:13:24 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
CallFunc * CallFunc::create(const std::function<void()> &func)
|
2013-06-04 03:13:24 +08:00
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
CallFunc *ret = new (std::nothrow) CallFunc();
|
2013-06-04 03:13:24 +08:00
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
if (ret && ret->initWithFunction(func) )
|
|
|
|
{
|
2013-11-16 21:08:00 +08:00
|
|
|
ret->autorelease();
|
|
|
|
return ret;
|
2013-06-04 03:13:24 +08:00
|
|
|
}
|
|
|
|
|
2013-11-16 21:08:00 +08:00
|
|
|
CC_SAFE_DELETE(ret);
|
|
|
|
return nullptr;
|
2013-06-04 03:13:24 +08:00
|
|
|
}
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
CallFunc * CallFunc::create(Ref* selectorTarget, SEL_CallFunc selector)
|
2012-06-14 17:18:05 +08:00
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
CallFunc *ret = new (std::nothrow) CallFunc();
|
2011-09-05 10:12:14 +08:00
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
if (ret && ret->initWithTarget(selectorTarget))
|
|
|
|
{
|
2013-11-16 21:08:00 +08:00
|
|
|
ret->_callFunc = selector;
|
|
|
|
ret->autorelease();
|
|
|
|
return ret;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2011-08-25 19:04:29 +08:00
|
|
|
|
2013-11-16 21:08:00 +08:00
|
|
|
CC_SAFE_DELETE(ret);
|
|
|
|
return nullptr;
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool CallFunc::initWithFunction(const std::function<void()> &func)
|
2013-06-04 03:13:24 +08:00
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
_function = func;
|
2013-06-04 03:13:24 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
bool CallFunc::initWithTarget(Ref* target)
|
|
|
|
{
|
2013-11-16 21:08:00 +08:00
|
|
|
if (target)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-11-16 21:08:00 +08:00
|
|
|
target->retain();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2011-09-05 10:12:14 +08:00
|
|
|
|
2013-11-18 21:12:47 +08:00
|
|
|
if (_selectorTarget)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-11-18 21:12:47 +08:00
|
|
|
_selectorTarget->release();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2013-11-16 21:08:00 +08:00
|
|
|
_selectorTarget = target;
|
2012-04-19 14:35:52 +08:00
|
|
|
return true;
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2013-11-16 21:08:00 +08:00
|
|
|
CallFunc::~CallFunc()
|
2012-12-02 15:01:12 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
CC_SAFE_RELEASE(_selectorTarget);
|
2012-12-02 15:01:12 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
CallFunc * CallFunc::clone() const
|
2013-07-05 11:24:28 +08:00
|
|
|
{
|
|
|
|
// no copy constructor
|
2014-08-28 07:31:57 +08:00
|
|
|
auto a = new (std::nothrow) CallFunc();
|
2016-04-08 13:40:36 +08:00
|
|
|
if( _selectorTarget)
|
|
|
|
{
|
2013-07-05 11:24:28 +08:00
|
|
|
a->initWithTarget(_selectorTarget);
|
|
|
|
a->_callFunc = _callFunc;
|
|
|
|
}
|
2016-04-08 13:40:36 +08:00
|
|
|
else if( _function )
|
|
|
|
{
|
2013-07-05 11:24:28 +08:00
|
|
|
a->initWithFunction(_function);
|
2013-07-05 10:25:37 +08:00
|
|
|
}
|
2013-06-14 08:25:14 +08:00
|
|
|
|
2013-07-05 11:29:21 +08:00
|
|
|
a->autorelease();
|
|
|
|
return a;
|
2013-06-14 08:25:14 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
CallFunc * CallFunc::reverse() const
|
2013-06-16 10:44:39 +08:00
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
// no reverse here, just return a clone
|
|
|
|
return this->clone();
|
2013-06-16 10:44:39 +08:00
|
|
|
}
|
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
void CallFunc::update(float /*time*/)
|
2016-04-08 13:40:36 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
this->execute();
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
void CallFunc::execute()
|
|
|
|
{
|
|
|
|
if (_callFunc)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
(_selectorTarget->*_callFunc)();
|
2016-04-08 13:40:36 +08:00
|
|
|
}
|
|
|
|
else if( _function )
|
|
|
|
{
|
2013-07-17 14:44:28 +08:00
|
|
|
_function();
|
|
|
|
}
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
2010-08-05 17:22:47 +08:00
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
//
|
|
|
|
// CallFuncN
|
|
|
|
//
|
2013-06-22 05:58:52 +08:00
|
|
|
|
|
|
|
CallFuncN * CallFuncN::create(const std::function<void(Node*)> &func)
|
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
auto ret = new (std::nothrow) CallFuncN();
|
2013-06-22 05:58:52 +08:00
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
if (ret && ret->initWithFunction(func) )
|
|
|
|
{
|
2013-06-22 05:58:52 +08:00
|
|
|
ret->autorelease();
|
|
|
|
return ret;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2013-06-22 05:58:52 +08:00
|
|
|
|
|
|
|
CC_SAFE_DELETE(ret);
|
2013-12-18 17:47:20 +08:00
|
|
|
return nullptr;
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2014-08-30 03:54:24 +08:00
|
|
|
// FIXME: deprecated
|
2014-02-20 10:53:49 +08:00
|
|
|
CallFuncN * CallFuncN::create(Ref* selectorTarget, SEL_CallFuncN selector)
|
2012-06-14 17:18:05 +08:00
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
CallFuncN *ret = new (std::nothrow) CallFuncN();
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2013-11-16 21:08:00 +08:00
|
|
|
if (ret && ret->initWithTarget(selectorTarget, selector))
|
2012-06-14 17:18:05 +08:00
|
|
|
{
|
2013-11-16 21:08:00 +08:00
|
|
|
ret->autorelease();
|
|
|
|
return ret;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2010-08-05 17:22:47 +08:00
|
|
|
|
2013-11-16 21:08:00 +08:00
|
|
|
CC_SAFE_DELETE(ret);
|
|
|
|
return nullptr;
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
void CallFuncN::execute()
|
|
|
|
{
|
|
|
|
if (_callFuncN)
|
|
|
|
{
|
2013-06-22 05:58:52 +08:00
|
|
|
(_selectorTarget->*_callFuncN)(_target);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2016-04-08 13:40:36 +08:00
|
|
|
else if (_functionN)
|
|
|
|
{
|
2013-06-22 05:58:52 +08:00
|
|
|
_functionN(_target);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
2013-06-22 05:58:52 +08:00
|
|
|
bool CallFuncN::initWithFunction(const std::function<void (Node *)> &func)
|
2013-06-14 08:25:14 +08:00
|
|
|
{
|
2013-06-22 05:58:52 +08:00
|
|
|
_functionN = func;
|
|
|
|
return true;
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
bool CallFuncN::initWithTarget(Ref* selectorTarget, SEL_CallFuncN selector)
|
2012-06-14 17:18:05 +08:00
|
|
|
{
|
2016-04-08 13:40:36 +08:00
|
|
|
if (CallFunc::initWithTarget(selectorTarget))
|
|
|
|
{
|
2013-06-22 05:58:52 +08:00
|
|
|
_callFuncN = selector;
|
2012-04-19 14:35:52 +08:00
|
|
|
return true;
|
|
|
|
}
|
2010-08-05 17:22:47 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
return false;
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2013-06-22 05:58:52 +08:00
|
|
|
CallFuncN * CallFuncN::clone() const
|
2013-06-14 08:25:14 +08:00
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
// no copy constructor
|
|
|
|
auto a = new (std::nothrow) CallFuncN();
|
2013-07-19 07:30:19 +08:00
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
if( _selectorTarget)
|
|
|
|
{
|
2013-07-19 07:30:19 +08:00
|
|
|
a->initWithTarget(_selectorTarget, _callFuncN);
|
|
|
|
}
|
2013-11-22 11:51:07 +08:00
|
|
|
else if( _functionN ){
|
2013-07-19 07:30:19 +08:00
|
|
|
a->initWithFunction(_functionN);
|
|
|
|
}
|
|
|
|
|
2015-01-08 10:22:45 +08:00
|
|
|
a->autorelease();
|
|
|
|
return a;
|
2013-06-14 08:25:14 +08:00
|
|
|
}
|
|
|
|
|
2013-07-24 16:45:11 +08:00
|
|
|
//
|
|
|
|
// CallFuncND
|
|
|
|
//
|
2013-07-25 15:03:44 +08:00
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
__CCCallFuncND * __CCCallFuncND::create(Ref* selectorTarget, SEL_CallFuncND selector, void* d)
|
2013-07-24 16:45:11 +08:00
|
|
|
{
|
2015-12-16 14:02:55 +08:00
|
|
|
__CCCallFuncND* ret = new (std::nothrow) __CCCallFuncND();
|
2013-07-24 16:45:11 +08:00
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
if (ret && ret->initWithTarget(selectorTarget, selector, d))
|
|
|
|
{
|
2013-11-16 21:08:00 +08:00
|
|
|
ret->autorelease();
|
|
|
|
return ret;
|
2013-07-24 16:45:11 +08:00
|
|
|
}
|
|
|
|
|
2013-11-16 21:08:00 +08:00
|
|
|
CC_SAFE_DELETE(ret);
|
|
|
|
return nullptr;
|
2013-07-24 16:45:11 +08:00
|
|
|
}
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
bool __CCCallFuncND::initWithTarget(Ref* selectorTarget, SEL_CallFuncND selector, void* d)
|
2013-07-24 16:45:11 +08:00
|
|
|
{
|
|
|
|
if (CallFunc::initWithTarget(selectorTarget))
|
|
|
|
{
|
|
|
|
_data = d;
|
|
|
|
_callFuncND = selector;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-07-25 15:03:44 +08:00
|
|
|
void __CCCallFuncND::execute()
|
2013-07-24 16:45:11 +08:00
|
|
|
{
|
|
|
|
if (_callFuncND)
|
|
|
|
{
|
|
|
|
(_selectorTarget->*_callFuncND)(_target, _data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-25 15:03:44 +08:00
|
|
|
__CCCallFuncND * __CCCallFuncND::clone() const
|
2013-07-24 16:45:11 +08:00
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
// no copy constructor
|
2015-12-16 14:02:55 +08:00
|
|
|
auto a = new (std::nothrow) __CCCallFuncND();
|
2013-07-24 16:45:11 +08:00
|
|
|
|
|
|
|
if( _selectorTarget)
|
|
|
|
{
|
|
|
|
a->initWithTarget(_selectorTarget, _callFuncND, _data);
|
|
|
|
}
|
|
|
|
|
2015-01-08 10:22:45 +08:00
|
|
|
a->autorelease();
|
|
|
|
return a;
|
2013-07-24 16:45:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// CallFuncO
|
|
|
|
//
|
2013-07-25 15:03:44 +08:00
|
|
|
__CCCallFuncO::__CCCallFuncO() :
|
2013-11-16 21:08:00 +08:00
|
|
|
_object(nullptr)
|
2013-07-24 16:45:11 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-07-25 15:03:44 +08:00
|
|
|
__CCCallFuncO::~__CCCallFuncO()
|
2013-07-24 16:45:11 +08:00
|
|
|
{
|
|
|
|
CC_SAFE_RELEASE(_object);
|
|
|
|
}
|
|
|
|
|
2013-07-25 15:03:44 +08:00
|
|
|
void __CCCallFuncO::execute()
|
2013-07-24 16:45:11 +08:00
|
|
|
{
|
2016-04-08 13:40:36 +08:00
|
|
|
if (_callFuncO)
|
|
|
|
{
|
2013-07-24 16:45:11 +08:00
|
|
|
(_selectorTarget->*_callFuncO)(_object);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
__CCCallFuncO * __CCCallFuncO::create(Ref* selectorTarget, SEL_CallFuncO selector, Ref* object)
|
2013-07-24 16:45:11 +08:00
|
|
|
{
|
2015-12-16 14:02:55 +08:00
|
|
|
__CCCallFuncO *ret = new (std::nothrow) __CCCallFuncO();
|
2013-07-24 16:45:11 +08:00
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
if (ret && ret->initWithTarget(selectorTarget, selector, object))
|
|
|
|
{
|
2013-11-16 21:08:00 +08:00
|
|
|
ret->autorelease();
|
|
|
|
return ret;
|
2013-07-24 16:45:11 +08:00
|
|
|
}
|
|
|
|
|
2013-11-16 21:08:00 +08:00
|
|
|
CC_SAFE_DELETE(ret);
|
|
|
|
return nullptr;
|
2013-07-24 16:45:11 +08:00
|
|
|
}
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
bool __CCCallFuncO::initWithTarget(Ref* selectorTarget, SEL_CallFuncO selector, Ref* object)
|
2013-07-24 16:45:11 +08:00
|
|
|
{
|
|
|
|
if (CallFunc::initWithTarget(selectorTarget))
|
|
|
|
{
|
|
|
|
_object = object;
|
|
|
|
CC_SAFE_RETAIN(_object);
|
|
|
|
|
|
|
|
_callFuncO = selector;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-07-25 15:03:44 +08:00
|
|
|
__CCCallFuncO * __CCCallFuncO::clone() const
|
2013-07-24 16:45:11 +08:00
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
// no copy constructor
|
2015-12-16 14:02:55 +08:00
|
|
|
auto a = new (std::nothrow) __CCCallFuncO();
|
2013-07-24 16:45:11 +08:00
|
|
|
|
|
|
|
if( _selectorTarget)
|
|
|
|
{
|
|
|
|
a->initWithTarget(_selectorTarget, _callFuncO, _object);
|
|
|
|
}
|
|
|
|
|
2015-01-08 10:22:45 +08:00
|
|
|
a->autorelease();
|
|
|
|
return a;
|
2013-07-24 16:45:11 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
Ref* __CCCallFuncO::getObject() const
|
2013-07-25 13:45:02 +08:00
|
|
|
{
|
|
|
|
return _object;
|
|
|
|
}
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
void __CCCallFuncO::setObject(Ref* obj)
|
2013-07-25 13:45:02 +08:00
|
|
|
{
|
|
|
|
if (obj != _object)
|
|
|
|
{
|
|
|
|
CC_SAFE_RELEASE(_object);
|
|
|
|
_object = obj;
|
|
|
|
CC_SAFE_RETAIN(_object);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-25 15:03:44 +08:00
|
|
|
NS_CC_END
|
|
|
|
|
|
|
|
#if defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)))
|
|
|
|
#pragma GCC diagnostic warning "-Wdeprecated-declarations"
|
|
|
|
#elif _MSC_VER >= 1400 //vs 2005 or higher
|
2013-07-25 13:45:02 +08:00
|
|
|
#pragma warning (pop)
|
|
|
|
#endif
|