2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * Contributor(s): Mitchell Stokes.
20 * ***** END GPL LICENSE BLOCK *****
23 /** \file BL_ActionManager.cpp
27 #include "BL_Action.h"
28 #include "BL_ActionManager.h"
31 #define IS_TAGGED(_id) ((_id) && (((ID *)_id)->flag & LIB_DOIT))
33 BL_ActionManager::BL_ActionManager(class KX_GameObject *obj):
39 BL_ActionManager::~BL_ActionManager()
41 BL_ActionMap::iterator it;
43 for (it = m_layers.begin(); it != m_layers.end(); it++)
49 BL_Action *BL_ActionManager::GetAction(short layer)
51 BL_ActionMap::iterator it = m_layers.find(layer);
53 return (it != m_layers.end()) ? it->second : 0;
56 float BL_ActionManager::GetActionFrame(short layer)
58 BL_Action *action = GetAction(layer);
60 return action ? action->GetFrame() : 0.f;
63 const char *BL_ActionManager::GetActionName(short layer)
65 BL_Action *action = GetAction(layer);
66 return action ? action->GetName() : "";
69 void BL_ActionManager::SetActionFrame(short layer, float frame)
71 BL_Action *action = GetAction(layer);
73 if (action) action->SetFrame(frame);
76 struct bAction *BL_ActionManager::GetCurrentAction(short layer)
78 BL_Action *action = GetAction(layer);
80 return action ? action->GetAction() : 0;
83 void BL_ActionManager::SetPlayMode(short layer, short mode)
85 BL_Action *action = GetAction(layer);
87 if (action) action->SetPlayMode(mode);
90 void BL_ActionManager::SetTimes(short layer, float start, float end)
92 BL_Action *action = GetAction(layer);
94 if (action) action->SetTimes(start, end);
97 bool BL_ActionManager::PlayAction(const char* name,
106 float playback_speed,
109 // Only this method will create layer if non-existent
110 BL_Action *action = GetAction(layer);
112 action = new BL_Action(m_obj);
113 m_layers[layer] = action;
116 // Disable layer blending on the first layer
117 if (layer == 0) layer_weight = -1.f;
119 return action->Play(name, start, end, priority, blendin, play_mode, layer_weight, ipo_flags, playback_speed, blend_mode);
122 void BL_ActionManager::StopAction(short layer)
124 BL_Action *action = GetAction(layer);
127 m_layers.erase(layer);
132 void BL_ActionManager::RemoveTaggedActions()
134 for (BL_ActionMap::iterator it = m_layers.begin(); it != m_layers.end();) {
135 if (IS_TAGGED(it->second->GetAction())) {
137 m_layers.erase(it++);
144 bool BL_ActionManager::IsActionDone(short layer)
146 BL_Action *action = GetAction(layer);
148 return action ? action->IsDone() : true;
151 void BL_ActionManager::Update(float curtime)
153 if (m_prevUpdate == curtime)
155 m_prevUpdate = curtime;
157 BL_ActionMap::iterator it;
158 for (it = m_layers.begin(); it != m_layers.end(); ++it)
160 if (!it->second->IsDone()) {
161 it->second->Update(curtime);
166 void BL_ActionManager::UpdateIPOs()
168 BL_ActionMap::iterator it;
169 for (it = m_layers.begin(); it != m_layers.end(); ++it)
171 if (!it->second->IsDone())
172 it->second->UpdateIPOs();