2012-04-19 14:35:52 +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
|
2012-04-19 14:35:52 +08:00
|
|
|
Copyright (c) 2011 Zynga Inc.
|
2017-02-14 14:36:57 +08:00
|
|
|
Copyright (c) 2013-2017 Chukong Technologies Inc.
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __ACTION_CCACTION_MANAGER_H__
|
|
|
|
#define __ACTION_CCACTION_MANAGER_H__
|
|
|
|
|
2014-04-27 01:11:22 +08:00
|
|
|
#include "2d/CCAction.h"
|
2014-04-27 01:35:57 +08:00
|
|
|
#include "base/CCVector.h"
|
2014-04-27 01:11:22 +08:00
|
|
|
#include "base/CCRef.h"
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
2014-08-26 18:19:28 +08:00
|
|
|
class Action;
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
struct _hashElement;
|
2012-06-20 18:09:11 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @addtogroup actions
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2015-03-18 20:40:29 +08:00
|
|
|
/** @class ActionManager
|
2013-06-20 14:13:12 +08:00
|
|
|
@brief ActionManager is a singleton that manages all the actions.
|
|
|
|
Normally you won't need to use this singleton directly. 99% of the cases you will use the Node interface,
|
2010-08-05 14:37:36 +08:00
|
|
|
which uses this singleton.
|
|
|
|
But there are some cases where you might need to use this singleton.
|
|
|
|
Examples:
|
2013-06-20 14:13:12 +08:00
|
|
|
- When you want to run an action where the target is different from a Node.
|
2015-03-18 20:40:29 +08:00
|
|
|
- When you want to pause / resume the actions.
|
2010-08-05 14:37:36 +08:00
|
|
|
|
|
|
|
@since v0.8
|
2012-04-19 14:35:52 +08:00
|
|
|
*/
|
2014-02-20 10:53:49 +08:00
|
|
|
class CC_DLL ActionManager : public Ref
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-09-13 16:46:31 +08:00
|
|
|
/**
|
|
|
|
* @js ctor
|
|
|
|
*/
|
2017-03-28 09:25:48 +08:00
|
|
|
ActionManager();
|
2015-03-18 20:40:29 +08:00
|
|
|
|
2013-09-13 13:52:42 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2017-03-28 09:25:48 +08:00
|
|
|
virtual ~ActionManager();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// actions
|
|
|
|
|
|
|
|
/** Adds an action with a target.
|
|
|
|
If the target is already present, then the action will be added to the existing target.
|
|
|
|
If the target is not present, a new instance of this target will be created either paused or not, and the action will be added to the newly created target.
|
|
|
|
When the target is paused, the queued actions won't be 'ticked'.
|
2015-03-18 20:40:29 +08:00
|
|
|
*
|
|
|
|
* @param action A certain action.
|
|
|
|
* @param target The target which need to be added an action.
|
|
|
|
* @param paused Is the target paused or not.
|
2012-04-19 14:35:52 +08:00
|
|
|
*/
|
2017-03-28 09:25:48 +08:00
|
|
|
virtual void addAction(Action *action, Node *target, bool paused);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2010-09-29 17:39:45 +08:00
|
|
|
/** Removes all actions from all the targets.
|
2015-03-18 20:40:29 +08:00
|
|
|
*/
|
2017-03-28 09:25:48 +08:00
|
|
|
virtual void removeAllActions();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2010-08-05 14:37:36 +08:00
|
|
|
/** Removes all actions from a certain target.
|
2012-04-19 14:35:52 +08:00
|
|
|
All the actions that belongs to the target will be removed.
|
2015-03-18 20:40:29 +08:00
|
|
|
*
|
|
|
|
* @param target A certain target.
|
2012-04-19 14:35:52 +08:00
|
|
|
*/
|
2017-03-28 09:25:48 +08:00
|
|
|
virtual void removeAllActionsFromTarget(Node *target);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2010-08-05 14:37:36 +08:00
|
|
|
/** Removes an action given an action reference.
|
2015-03-18 20:40:29 +08:00
|
|
|
*
|
|
|
|
* @param action A certain target.
|
|
|
|
*/
|
2017-03-28 09:25:48 +08:00
|
|
|
virtual void removeAction(Action *action);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2015-03-18 20:40:29 +08:00
|
|
|
/** Removes an action given its tag and the target.
|
|
|
|
*
|
|
|
|
* @param tag The action's tag.
|
|
|
|
* @param target A certain target.
|
|
|
|
*/
|
2017-03-28 09:25:48 +08:00
|
|
|
virtual void removeActionByTag(int tag, Node *target);
|
2014-07-22 16:04:22 +08:00
|
|
|
|
2015-03-18 20:40:29 +08:00
|
|
|
/** Removes all actions given its tag and the target.
|
|
|
|
*
|
|
|
|
* @param tag The actions' tag.
|
|
|
|
* @param target A certain target.
|
2015-03-19 18:41:11 +08:00
|
|
|
* @js NA
|
2015-03-18 20:40:29 +08:00
|
|
|
*/
|
2017-03-28 09:25:48 +08:00
|
|
|
virtual void removeAllActionsByTag(int tag, Node *target);
|
2015-05-28 15:52:49 +08:00
|
|
|
|
|
|
|
/** Removes all actions matching at least one bit in flags and the target.
|
|
|
|
*
|
|
|
|
* @param flags The flag field to match the actions' flags based on bitwise AND.
|
|
|
|
* @param target A certain target.
|
|
|
|
* @js NA
|
|
|
|
*/
|
2017-03-28 09:25:48 +08:00
|
|
|
virtual void removeActionsByFlags(unsigned int flags, Node *target);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2015-03-18 20:40:29 +08:00
|
|
|
/** Gets an action given its tag an a target.
|
|
|
|
*
|
|
|
|
* @param tag The action's tag.
|
|
|
|
* @param target A certain target.
|
|
|
|
* @return The Action the with the given tag.
|
2012-04-19 14:35:52 +08:00
|
|
|
*/
|
2017-03-28 09:25:48 +08:00
|
|
|
virtual Action* getActionByTag(int tag, const Node *target) const;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2010-09-29 17:39:45 +08:00
|
|
|
/** Returns the numbers of actions that are running in a certain target.
|
2012-04-19 14:35:52 +08:00
|
|
|
* Composable actions are counted as 1 action. Example:
|
|
|
|
* - If you are running 1 Sequence of 7 actions, it will return 1.
|
|
|
|
* - If you are running 7 Sequences of 2 actions, it will return 7.
|
2015-03-18 20:40:29 +08:00
|
|
|
*
|
|
|
|
* @param target A certain target.
|
|
|
|
* @return The numbers of actions that are running in a certain target.
|
2015-03-19 18:41:11 +08:00
|
|
|
* @js NA
|
2012-04-19 14:35:52 +08:00
|
|
|
*/
|
2017-03-28 09:25:48 +08:00
|
|
|
virtual ssize_t getNumberOfRunningActionsInTarget(const Node *target) const;
|
2017-06-05 13:37:50 +08:00
|
|
|
|
|
|
|
/** Returns the numbers of actions that are running in all targets.
|
|
|
|
* @return The numbers of actions that are running in all target.
|
|
|
|
* @js NA
|
|
|
|
*/
|
|
|
|
virtual ssize_t getNumberOfRunningActions() const;
|
2013-07-18 07:56:19 +08:00
|
|
|
|
2015-03-18 20:40:29 +08:00
|
|
|
/** @deprecated Use getNumberOfRunningActionsInTarget() instead.
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE ssize_t numberOfRunningActionsInTarget(Node *target) const { return getNumberOfRunningActionsInTarget(target); }
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2016-11-04 09:41:03 +08:00
|
|
|
|
|
|
|
/** Returns the numbers of actions that are running in a
|
|
|
|
* certain target with a specific tag.
|
|
|
|
* Like getNumberOfRunningActionsInTarget Composable actions
|
|
|
|
* are counted as 1 action. Example:
|
|
|
|
* - If you are running 1 Sequence of 7 actions, it will return 1.
|
|
|
|
* - If you are running 7 Sequences of 2 actions, it will return 7.
|
|
|
|
*
|
|
|
|
* @param target A certain target.
|
|
|
|
* @param tag Tag that will be searched.
|
|
|
|
* @return The numbers of actions that are running in a certain target
|
|
|
|
* with a specific tag.
|
|
|
|
* @see getNumberOfRunningActionsInTarget
|
|
|
|
* @js NA
|
|
|
|
*/
|
2017-03-28 09:25:48 +08:00
|
|
|
virtual size_t getNumberOfRunningActionsInTargetByTag(const Node *target, int tag);
|
2016-11-04 09:41:03 +08:00
|
|
|
|
|
|
|
|
2010-08-05 14:37:36 +08:00
|
|
|
/** Pauses the target: all running actions and newly added actions will be paused.
|
2015-03-18 20:40:29 +08:00
|
|
|
*
|
|
|
|
* @param target A certain target.
|
|
|
|
*/
|
2017-03-28 09:25:48 +08:00
|
|
|
virtual void pauseTarget(Node *target);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2010-08-05 14:37:36 +08:00
|
|
|
/** Resumes the target. All queued actions will be resumed.
|
2015-03-18 20:40:29 +08:00
|
|
|
*
|
|
|
|
* @param target A certain target.
|
|
|
|
*/
|
2017-03-28 09:25:48 +08:00
|
|
|
virtual void resumeTarget(Node *target);
|
2012-06-08 13:55:28 +08:00
|
|
|
|
|
|
|
/** Pauses all running actions, returning a list of targets whose actions were paused.
|
2015-03-18 20:40:29 +08:00
|
|
|
*
|
|
|
|
* @return A list of targets whose actions were paused.
|
2012-06-08 13:55:28 +08:00
|
|
|
*/
|
2017-03-28 09:25:48 +08:00
|
|
|
virtual Vector<Node*> pauseAllRunningActions();
|
2012-06-08 13:55:28 +08:00
|
|
|
|
2015-03-18 20:40:29 +08:00
|
|
|
/** Resume a set of targets (convenience function to reverse a pauseAllRunningActions call).
|
|
|
|
*
|
|
|
|
* @param targetsToResume A set of targets need to be resumed.
|
2012-06-08 13:55:28 +08:00
|
|
|
*/
|
2017-03-28 09:25:48 +08:00
|
|
|
virtual void resumeTargets(const Vector<Node*>& targetsToResume);
|
2015-03-18 20:40:29 +08:00
|
|
|
|
|
|
|
/** Main loop of ActionManager.
|
|
|
|
* @param dt In seconds.
|
2015-01-20 15:41:59 +08:00
|
|
|
*/
|
2017-03-28 09:25:48 +08:00
|
|
|
virtual void update(float dt);
|
2014-02-20 10:53:49 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
protected:
|
2013-06-20 14:13:12 +08:00
|
|
|
// declared in ActionManager.m
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
void removeActionAtIndex(ssize_t index, struct _hashElement *element);
|
|
|
|
void deleteHashElement(struct _hashElement *element);
|
|
|
|
void actionAllocWithHashElement(struct _hashElement *element);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
protected:
|
2013-06-15 14:03:30 +08:00
|
|
|
struct _hashElement *_targets;
|
|
|
|
struct _hashElement *_currentTarget;
|
|
|
|
bool _currentTargetSalvaged;
|
2012-04-19 14:35:52 +08:00
|
|
|
};
|
|
|
|
|
2012-06-20 18:09:11 +08:00
|
|
|
// end of actions group
|
|
|
|
/// @}
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
NS_CC_END
|
|
|
|
|
|
|
|
#endif // __ACTION_CCACTION_MANAGER_H__
|