2011-10-23 17:52:20 +00:00
|
|
|
/*
|
2011-05-24 07:52:29 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
2011-07-07 03:53:24 +00:00
|
|
|
* Contributor(s): Mitchell Stokes.
|
2011-05-24 07:52:29 +00:00
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*/
|
|
|
|
|
2011-07-07 03:53:24 +00:00
|
|
|
/** \file BL_ActionManager.cpp
|
|
|
|
* \ingroup ketsji
|
|
|
|
*/
|
|
|
|
|
2013-08-14 23:31:49 +00:00
|
|
|
#include "BL_Action.h"
|
2014-05-08 01:14:36 +00:00
|
|
|
#include "BL_ActionManager.h"
|
2015-07-01 14:38:31 +00:00
|
|
|
#include "DNA_ID.h"
|
|
|
|
|
Split id->flag in two, persistent flags and runtime tags.
This is purely internal sanitizing/cleanup, no change in behavior is expected at all.
This change was also needed because we were getting short on ID flags, and
future enhancement of 'user_one' ID behavior requires two new ones.
id->flag remains for persistent data (fakeuser only, so far!), this also allows us
100% backward & forward compatibility.
New id->tag is used for most flags. Though written in .blend files, its content
is cleared at read time.
Note that .blend file version was bumped, so that we can clear runtimeflags from
old .blends, important in case we add new persistent flags in future.
Also, behavior of tags (either status ones, or whether they need to be cleared before/after use)
has been added as comments to their declaration.
Reviewers: sergey, campbellbarton
Differential Revision: https://developer.blender.org/D1683
2015-12-27 10:53:50 +00:00
|
|
|
#define IS_TAGGED(_id) ((_id) && (((ID *)_id)->tag & LIB_TAG_DOIT))
|
2011-05-24 07:52:29 +00:00
|
|
|
|
2014-05-08 01:14:36 +00:00
|
|
|
BL_ActionManager::BL_ActionManager(class KX_GameObject *obj):
|
2015-06-22 14:44:16 +00:00
|
|
|
m_obj(obj),
|
|
|
|
m_prevUpdate(-1.0f)
|
2011-05-24 07:52:29 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
BL_ActionManager::~BL_ActionManager()
|
|
|
|
{
|
2014-05-08 01:14:36 +00:00
|
|
|
BL_ActionMap::iterator it;
|
|
|
|
|
|
|
|
for (it = m_layers.begin(); it != m_layers.end(); it++)
|
|
|
|
delete it->second;
|
|
|
|
|
|
|
|
m_layers.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
BL_Action *BL_ActionManager::GetAction(short layer)
|
|
|
|
{
|
|
|
|
BL_ActionMap::iterator it = m_layers.find(layer);
|
|
|
|
|
|
|
|
return (it != m_layers.end()) ? it->second : 0;
|
|
|
|
}
|
|
|
|
|
2011-06-01 07:42:40 +00:00
|
|
|
float BL_ActionManager::GetActionFrame(short layer)
|
|
|
|
{
|
2014-05-08 01:14:36 +00:00
|
|
|
BL_Action *action = GetAction(layer);
|
|
|
|
|
|
|
|
return action ? action->GetFrame() : 0.f;
|
2011-06-01 07:42:40 +00:00
|
|
|
}
|
|
|
|
|
BGE: Added getActionName() function to KX_GameObject()
It works similar to getActionFrame(), you have to give a layer or not (for layer 0) as the argument and it returns the name of the animation that the object is currently playing.
Example:
```
import bge
own = bge.logic.getCurrentController().owner
own.playAction("SomeAction",0,20)
print(own.getActionName())
```
>> SomeAction
Here is an example file, just open the blend file with the terminal opened
and press P, you can see how the current animation is being printed:
{F217484}
Reviewers: moguri, hg1, panzergame, campbellbarton
Reviewed By: panzergame
Subscribers: campbellbarton, hg1, #game_engine
Projects: #game_engine
Differential Revision: https://developer.blender.org/D1443
2015-08-03 21:47:46 +00:00
|
|
|
const char *BL_ActionManager::GetActionName(short layer)
|
|
|
|
{
|
|
|
|
BL_Action *action = GetAction(layer);
|
|
|
|
return action ? action->GetName() : "";
|
|
|
|
}
|
|
|
|
|
2011-06-01 07:42:40 +00:00
|
|
|
void BL_ActionManager::SetActionFrame(short layer, float frame)
|
|
|
|
{
|
2014-05-08 01:14:36 +00:00
|
|
|
BL_Action *action = GetAction(layer);
|
|
|
|
|
|
|
|
if (action) action->SetFrame(frame);
|
2011-06-01 07:42:40 +00:00
|
|
|
}
|
|
|
|
|
2011-07-05 05:22:02 +00:00
|
|
|
struct bAction *BL_ActionManager::GetCurrentAction(short layer)
|
|
|
|
{
|
2014-05-08 01:14:36 +00:00
|
|
|
BL_Action *action = GetAction(layer);
|
|
|
|
|
|
|
|
return action ? action->GetAction() : 0;
|
2011-07-05 05:22:02 +00:00
|
|
|
}
|
|
|
|
|
2011-08-08 04:28:30 +00:00
|
|
|
void BL_ActionManager::SetPlayMode(short layer, short mode)
|
|
|
|
{
|
2014-05-08 01:14:36 +00:00
|
|
|
BL_Action *action = GetAction(layer);
|
|
|
|
|
|
|
|
if (action) action->SetPlayMode(mode);
|
2011-08-08 04:28:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BL_ActionManager::SetTimes(short layer, float start, float end)
|
|
|
|
{
|
2014-05-08 01:14:36 +00:00
|
|
|
BL_Action *action = GetAction(layer);
|
|
|
|
|
|
|
|
if (action) action->SetTimes(start, end);
|
2011-08-08 04:28:30 +00:00
|
|
|
}
|
|
|
|
|
2011-06-29 01:53:17 +00:00
|
|
|
bool BL_ActionManager::PlayAction(const char* name,
|
2011-05-24 07:52:29 +00:00
|
|
|
float start,
|
|
|
|
float end,
|
|
|
|
short layer,
|
2011-06-23 22:12:49 +00:00
|
|
|
short priority,
|
2011-05-24 07:52:29 +00:00
|
|
|
float blendin,
|
|
|
|
short play_mode,
|
2011-07-03 01:59:17 +00:00
|
|
|
float layer_weight,
|
2011-06-16 01:18:52 +00:00
|
|
|
short ipo_flags,
|
2013-08-14 23:31:49 +00:00
|
|
|
float playback_speed,
|
|
|
|
short blend_mode)
|
2011-05-24 07:52:29 +00:00
|
|
|
{
|
2014-05-08 01:14:36 +00:00
|
|
|
// Only this method will create layer if non-existent
|
|
|
|
BL_Action *action = GetAction(layer);
|
2015-10-07 05:16:22 +00:00
|
|
|
if (!action) {
|
|
|
|
action = new BL_Action(m_obj);
|
|
|
|
m_layers[layer] = action;
|
|
|
|
}
|
2014-05-08 01:14:36 +00:00
|
|
|
|
2011-06-29 02:42:46 +00:00
|
|
|
// Disable layer blending on the first layer
|
2011-07-03 01:59:17 +00:00
|
|
|
if (layer == 0) layer_weight = -1.f;
|
2011-06-29 02:42:46 +00:00
|
|
|
|
2014-05-08 01:14:36 +00:00
|
|
|
return action->Play(name, start, end, priority, blendin, play_mode, layer_weight, ipo_flags, playback_speed, blend_mode);
|
2011-05-24 07:52:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BL_ActionManager::StopAction(short layer)
|
|
|
|
{
|
2014-05-08 01:14:36 +00:00
|
|
|
BL_Action *action = GetAction(layer);
|
|
|
|
|
2015-10-07 05:16:22 +00:00
|
|
|
if (action) {
|
|
|
|
m_layers.erase(layer);
|
|
|
|
delete action;
|
|
|
|
}
|
2011-05-24 07:52:29 +00:00
|
|
|
}
|
|
|
|
|
2015-07-01 14:38:31 +00:00
|
|
|
void BL_ActionManager::RemoveTaggedActions()
|
|
|
|
{
|
|
|
|
for (BL_ActionMap::iterator it = m_layers.begin(); it != m_layers.end();) {
|
|
|
|
if (IS_TAGGED(it->second->GetAction())) {
|
|
|
|
delete it->second;
|
|
|
|
m_layers.erase(it++);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-01 05:46:19 +00:00
|
|
|
bool BL_ActionManager::IsActionDone(short layer)
|
|
|
|
{
|
2014-05-08 01:14:36 +00:00
|
|
|
BL_Action *action = GetAction(layer);
|
|
|
|
|
|
|
|
return action ? action->IsDone() : true;
|
2011-06-01 05:46:19 +00:00
|
|
|
}
|
|
|
|
|
2011-05-24 07:52:29 +00:00
|
|
|
void BL_ActionManager::Update(float curtime)
|
|
|
|
{
|
2015-06-22 14:44:16 +00:00
|
|
|
if (m_prevUpdate == curtime)
|
|
|
|
return;
|
|
|
|
m_prevUpdate = curtime;
|
|
|
|
|
2014-05-08 01:14:36 +00:00
|
|
|
BL_ActionMap::iterator it;
|
2015-10-07 05:16:22 +00:00
|
|
|
for (it = m_layers.begin(); it != m_layers.end(); ++it)
|
2011-05-24 07:52:29 +00:00
|
|
|
{
|
2015-10-07 05:16:22 +00:00
|
|
|
if (!it->second->IsDone()) {
|
2014-05-08 01:14:36 +00:00
|
|
|
it->second->Update(curtime);
|
2011-05-24 07:52:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|