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"
|
2011-05-24 07:52:29 +00:00
|
|
|
|
2014-05-08 01:14:36 +00:00
|
|
|
BL_ActionManager::BL_ActionManager(class KX_GameObject *obj):
|
|
|
|
m_obj(obj)
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
BL_Action* BL_ActionManager::AddAction(short layer)
|
|
|
|
{
|
|
|
|
BL_Action *action = new BL_Action(m_obj);
|
|
|
|
m_layers[layer] = action;
|
|
|
|
|
|
|
|
return action;
|
2011-05-24 07:52:29 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
if (!action)
|
|
|
|
action = AddAction(layer);
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (action) action->Stop();
|
2011-05-24 07:52:29 +00:00
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2014-05-08 01:14:36 +00:00
|
|
|
BL_ActionMap::iterator it;
|
|
|
|
for (it = m_layers.begin(); it != m_layers.end(); )
|
2011-05-24 07:52:29 +00:00
|
|
|
{
|
2014-05-08 01:14:36 +00:00
|
|
|
if (it->second->IsDone()) {
|
|
|
|
delete it->second;
|
|
|
|
m_layers.erase(it++);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
it->second->Update(curtime);
|
|
|
|
++it;
|
2011-05-24 07:52:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-05-04 22:37:18 +00:00
|
|
|
|
|
|
|
void BL_ActionManager::UpdateIPOs()
|
|
|
|
{
|
2014-05-08 01:14:36 +00:00
|
|
|
BL_ActionMap::iterator it;
|
|
|
|
for (it = m_layers.begin(); it != m_layers.end(); ++it)
|
2014-05-04 22:37:18 +00:00
|
|
|
{
|
2014-05-08 01:14:36 +00:00
|
|
|
if (!it->second->IsDone())
|
|
|
|
it->second->UpdateIPOs();
|
2014-05-04 22:37:18 +00:00
|
|
|
}
|
|
|
|
}
|