BGE Animations: Various changes to make code reviewers happy:
[blender-staging.git] / source / gameengine / Ketsji / BL_ActionManager.cpp
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *
20  * Contributor(s): Mitchell Stokes.
21  *
22  * ***** END GPL LICENSE BLOCK *****
23  */
24
25 /** \file BL_ActionManager.cpp
26  *  \ingroup ketsji
27  */
28
29 #include "BL_ActionManager.h"
30
31 BL_ActionManager::BL_ActionManager(class KX_GameObject *obj)
32 {
33         for (int i=0; i<MAX_ACTION_LAYERS; ++i)
34                 m_layers[i] = new BL_Action(obj);
35 }
36
37 BL_ActionManager::~BL_ActionManager()
38 {
39         for (int i=0; i<MAX_ACTION_LAYERS; ++i)
40                 delete m_layers[i];
41 }
42
43 float BL_ActionManager::GetActionFrame(short layer)
44 {
45         return m_layers[layer]->GetFrame();
46
47         return 0.f;
48 }
49
50 void BL_ActionManager::SetActionFrame(short layer, float frame)
51 {
52         m_layers[layer]->SetFrame(frame);
53 }
54
55 struct bAction *BL_ActionManager::GetCurrentAction(short layer)
56 {
57         return m_layers[layer]->GetAction();
58         
59         return 0;
60 }
61
62 void BL_ActionManager::SetPlayMode(short layer, short mode)
63 {
64         m_layers[layer]->SetPlayMode(mode);
65 }
66
67 void BL_ActionManager::SetTimes(short layer, float start, float end)
68 {
69         m_layers[layer]->SetTimes(start, end);
70 }
71
72 bool BL_ActionManager::PlayAction(const char* name,
73                                                                 float start,
74                                                                 float end,
75                                                                 short layer,
76                                                                 short priority,
77                                                                 float blendin,
78                                                                 short play_mode,
79                                                                 float layer_weight,
80                                                                 short ipo_flags,
81                                                                 float playback_speed)
82 {
83         // Disable layer blending on the first layer
84         if (layer == 0) layer_weight = -1.f;
85
86         return m_layers[layer]->Play(name, start, end, priority, blendin, play_mode, layer_weight, ipo_flags, playback_speed);
87 }
88
89 void BL_ActionManager::StopAction(short layer)
90 {
91         m_layers[layer]->Stop();
92 }
93
94 bool BL_ActionManager::IsActionDone(short layer)
95 {
96         return m_layers[layer]->IsDone();
97
98         return true;
99 }
100
101 void BL_ActionManager::Update(float curtime)
102 {
103         for (int i=0; i<MAX_ACTION_LAYERS; ++i)
104         {
105                 if (!m_layers[i]->IsDone())
106                 {
107                         m_layers[i]->Update(curtime);
108                 }
109         }
110 }