fix memleak in BGE py api - action.channelNames
[blender.git] / source / gameengine / Converter / BL_ActionActuator.h
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19  *
20  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21  * All rights reserved.
22  *
23  * The Original Code is: all of this file.
24  *
25  * Contributor(s): none yet.
26  *
27  * ***** END GPL LICENSE BLOCK *****
28  */
29
30 #ifndef BL_ACTIONACTUATOR
31 #define BL_ACTIONACTUATOR
32
33 #include "GEN_HashedPtr.h"
34 #include "SCA_IActuator.h"
35 #include "DNA_actuator_types.h"
36 #include "MT_Point3.h"
37
38 class BL_ActionActuator : public SCA_IActuator  
39 {
40 public:
41         Py_Header;
42         BL_ActionActuator(SCA_IObject* gameobj,
43                                                 const STR_String& propname,
44                                                 const STR_String& framepropname,
45                                                 float starttime,
46                                                 float endtime,
47                                                 struct bAction *action,
48                                                 short   playtype,
49                                                 short   blendin,
50                                                 short   priority,
51                                                 short   end_reset,
52                                                 float   stride,
53                                                 PyTypeObject* T=&Type) 
54                 : SCA_IActuator(gameobj,T),
55                 
56                 m_lastpos(0, 0, 0),
57                 m_blendframe(0),
58                 m_flag(0),
59                 m_startframe (starttime),
60                 m_endframe(endtime) ,
61                 m_starttime(0),
62                 m_localtime(starttime),
63                 m_lastUpdate(-1),
64                 m_blendin(blendin),
65                 m_blendstart(0),
66                 m_stridelength(stride),
67                 m_playtype(playtype),
68                 m_priority(priority),
69                 m_end_reset(end_reset),
70                 m_pose(NULL),
71                 m_blendpose(NULL),
72                 m_userpose(NULL),
73                 m_action(action),
74                 m_propname(propname),
75                 m_framepropname(framepropname)          
76         {
77         };
78         virtual ~BL_ActionActuator();
79         virtual bool Update(double curtime, bool frame);
80         virtual CValue* GetReplica();
81         virtual void ProcessReplica();
82         
83         void SetBlendTime (float newtime);
84         
85         bAction*        GetAction() { return m_action; }
86         void            SetAction(bAction* act) { m_action= act; }
87
88         //Deprecated ----->
89         KX_PYMETHOD_DOC(BL_ActionActuator,SetAction);
90         KX_PYMETHOD_DOC(BL_ActionActuator,SetBlendin);
91         KX_PYMETHOD_DOC(BL_ActionActuator,SetPriority);
92         KX_PYMETHOD_DOC(BL_ActionActuator,SetStart);
93         KX_PYMETHOD_DOC(BL_ActionActuator,SetEnd);
94         KX_PYMETHOD_DOC(BL_ActionActuator,SetFrame);
95         KX_PYMETHOD_DOC(BL_ActionActuator,SetProperty);
96         KX_PYMETHOD_DOC(BL_ActionActuator,SetFrameProperty);
97         KX_PYMETHOD_DOC(BL_ActionActuator,SetBlendtime);
98
99         KX_PYMETHOD_DOC(BL_ActionActuator,GetAction);
100         KX_PYMETHOD_DOC(BL_ActionActuator,GetBlendin);
101         KX_PYMETHOD_DOC(BL_ActionActuator,GetPriority);
102         KX_PYMETHOD_DOC(BL_ActionActuator,GetStart);
103         KX_PYMETHOD_DOC(BL_ActionActuator,GetEnd);
104         KX_PYMETHOD_DOC(BL_ActionActuator,GetFrame);
105         KX_PYMETHOD_DOC(BL_ActionActuator,GetProperty);
106         KX_PYMETHOD_DOC(BL_ActionActuator,GetFrameProperty);
107         KX_PYMETHOD_O(BL_ActionActuator,GetChannel);
108         KX_PYMETHOD_DOC(BL_ActionActuator,GetType);
109         KX_PYMETHOD_DOC(BL_ActionActuator,SetType);
110         KX_PYMETHOD_NOARGS(BL_ActionActuator,GetContinue);
111         KX_PYMETHOD_O(BL_ActionActuator,SetContinue);
112         //<-----
113
114         KX_PYMETHOD_DOC(BL_ActionActuator,setChannel);
115
116         virtual PyObject* py_getattro(PyObject* attr);
117         virtual PyObject*               py_getattro_dict();
118         virtual int py_setattro(PyObject* attr, PyObject* value);
119
120         static PyObject*        pyattr_get_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
121         static int                      pyattr_set_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
122         static PyObject*        pyattr_get_channel_names(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
123         /* attribute check */
124         static int CheckFrame(void *self, const PyAttributeDef*)
125         {
126                 BL_ActionActuator* act = reinterpret_cast<BL_ActionActuator*>(self);
127
128                 if (act->m_localtime < act->m_startframe)
129                         act->m_localtime = act->m_startframe;
130                 else if (act->m_localtime > act->m_endframe)
131                         act->m_localtime = act->m_endframe;
132
133                 return 0;
134         }
135
136         static int CheckBlendTime(void *self, const PyAttributeDef*)
137         {
138                 BL_ActionActuator* act = reinterpret_cast<BL_ActionActuator*>(self);
139
140                 if (act->m_blendframe > act->m_blendin)
141                         act->m_blendframe = act->m_blendin;
142
143                 return 0;
144         }
145
146         static int CheckType(void *self, const PyAttributeDef*)
147         {
148                 BL_ActionActuator* act = reinterpret_cast<BL_ActionActuator*>(self);
149
150                 switch (act->m_playtype) {
151                         case ACT_ACTION_PLAY:
152                         case ACT_ACTION_FLIPPER:
153                         case ACT_ACTION_LOOP_STOP:
154                         case ACT_ACTION_LOOP_END:
155                         case ACT_ACTION_FROM_PROP:
156                                 return 0;
157                         default:
158                                 PyErr_SetString(PyExc_ValueError, "Action Actuator, invalid play type supplied");
159                                 return 1;
160                 }
161         }
162         
163 protected:
164
165         void SetStartTime(float curtime);
166         void SetLocalTime(float curtime);
167         bool ClampLocalTime();
168
169         MT_Point3       m_lastpos;
170         float   m_blendframe;
171         int             m_flag;
172         /** The frame this action starts */
173         float   m_startframe;
174         /** The frame this action ends */
175         float   m_endframe;
176         /** The time this action started */
177         float   m_starttime;
178         /** The current time of the action */
179         float   m_localtime;
180         
181         float   m_lastUpdate;
182         float   m_blendin;
183         float   m_blendstart;
184         float   m_stridelength;
185         short   m_playtype;
186         short   m_priority;
187         bool    m_end_reset;
188         struct bPose* m_pose;
189         struct bPose* m_blendpose;
190         struct bPose* m_userpose;
191         struct bAction *m_action;
192         STR_String      m_propname;
193         STR_String      m_framepropname;
194 };
195
196 enum {
197         ACT_FLAG_REVERSE        = 0x00000001,
198         ACT_FLAG_LOCKINPUT      = 0x00000002,
199         ACT_FLAG_KEYUP          = 0x00000004,
200         ACT_FLAG_ACTIVE         = 0x00000008
201 };
202
203 #endif
204