merge with 2.5 at r18679
[blender.git] / source / gameengine / Converter / BL_ShapeActionActuator.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_SHAPEACTIONACTUATOR
31 #define BL_SHAPEACTIONACTUATOR
32
33 #include "GEN_HashedPtr.h"
34 #include "SCA_IActuator.h"
35 #include "BL_ActionActuator.h"
36 #include "MT_Point3.h"
37 #include <vector>
38
39 struct Key;
40 class BL_ShapeActionActuator : public SCA_IActuator  
41 {
42 public:
43         Py_Header;
44         BL_ShapeActionActuator(SCA_IObject* gameobj,
45                                                 const STR_String& propname,
46                                                 const STR_String& framepropname,
47                                                 float starttime,
48                                                 float endtime,
49                                                 struct bAction *action,
50                                                 short   playtype,
51                                                 short   blendin,
52                                                 short   priority,
53                                                 float   stride,
54                                                 PyTypeObject* T=&Type) 
55                 : SCA_IActuator(gameobj,T),
56                 
57                 m_lastpos(0, 0, 0),
58                 m_blendframe(0),
59                 m_flag(0),
60                 m_startframe (starttime),
61                 m_endframe(endtime) ,
62                 m_starttime(0),
63                 m_localtime(starttime),
64                 m_lastUpdate(-1),
65                 m_blendin(blendin),
66                 m_blendstart(0),
67                 m_stridelength(stride),
68                 m_playtype(playtype),
69                 m_priority(priority),
70                 m_action(action),
71                 m_framepropname(framepropname), 
72                 m_propname(propname)
73         {
74         };
75         virtual ~BL_ShapeActionActuator();
76         virtual bool Update(double curtime, bool frame);
77         virtual CValue* GetReplica();
78         virtual void ProcessReplica();
79         
80         void SetBlendTime (float newtime);
81         void BlendShape(struct Key* key, float weigth);
82
83         KX_PYMETHOD_DOC(BL_ShapeActionActuator,SetAction);
84         KX_PYMETHOD_DOC(BL_ShapeActionActuator,SetBlendin);
85         KX_PYMETHOD_DOC(BL_ShapeActionActuator,SetPriority);
86         KX_PYMETHOD_DOC(BL_ShapeActionActuator,SetStart);
87         KX_PYMETHOD_DOC(BL_ShapeActionActuator,SetEnd);
88         KX_PYMETHOD_DOC(BL_ShapeActionActuator,SetFrame);
89         KX_PYMETHOD_DOC(BL_ShapeActionActuator,SetProperty);
90         KX_PYMETHOD_DOC(BL_ShapeActionActuator,SetFrameProperty);
91         KX_PYMETHOD_DOC(BL_ShapeActionActuator,SetBlendtime);
92         KX_PYMETHOD_DOC(BL_ShapeActionActuator,SetChannel);
93
94         KX_PYMETHOD_DOC_NOARGS(BL_ShapeActionActuator,GetAction);
95         KX_PYMETHOD_DOC_NOARGS(BL_ShapeActionActuator,GetBlendin);
96         KX_PYMETHOD_DOC_NOARGS(BL_ShapeActionActuator,GetPriority);
97         KX_PYMETHOD_DOC_NOARGS(BL_ShapeActionActuator,GetStart);
98         KX_PYMETHOD_DOC_NOARGS(BL_ShapeActionActuator,GetEnd);
99         KX_PYMETHOD_DOC_NOARGS(BL_ShapeActionActuator,GetFrame);
100         KX_PYMETHOD_DOC_NOARGS(BL_ShapeActionActuator,GetProperty);
101         KX_PYMETHOD_DOC_NOARGS(BL_ShapeActionActuator,GetFrameProperty);
102 //      KX_PYMETHOD(BL_ActionActuator,GetChannel);
103         KX_PYMETHOD_DOC_NOARGS(BL_ShapeActionActuator,GetType);
104         KX_PYMETHOD_DOC(BL_ShapeActionActuator,SetType);
105
106         virtual PyObject* _getattr(const STR_String& attr);
107         virtual int _setattr(const STR_String& attr, PyObject* value);
108
109         static int CheckBlendTime(void *self, const PyAttributeDef*)
110         {
111                 BL_ShapeActionActuator* act = reinterpret_cast<BL_ShapeActionActuator*>(self);
112
113                 if (act->m_blendframe > act->m_blendin)
114                         act->m_blendframe = act->m_blendin;
115
116                 return 0;
117         }
118         static int CheckFrame(void *self, const PyAttributeDef*)
119         {
120                 BL_ShapeActionActuator* act = reinterpret_cast<BL_ShapeActionActuator*>(self);
121
122                 if (act->m_localtime < act->m_startframe)
123                         act->m_localtime = act->m_startframe;
124                 else if (act->m_localtime > act->m_endframe)
125                         act->m_localtime = act->m_endframe;
126
127                 return 0;
128         }
129         static int CheckType(void *self, const PyAttributeDef*)
130         {
131                 BL_ShapeActionActuator* act = reinterpret_cast<BL_ShapeActionActuator*>(self);
132
133                 switch (act->m_playtype) {
134                         case ACT_ACTION_PLAY:
135                         case ACT_ACTION_FLIPPER:
136                         case ACT_ACTION_LOOP_STOP:
137                         case ACT_ACTION_LOOP_END:
138                         case ACT_ACTION_FROM_PROP:
139                                 return 0;
140                         default:
141                                 PyErr_SetString(PyExc_ValueError, "invalid type supplied");
142                                 return 1;
143                 }
144
145         }
146
147 protected:
148
149         void SetStartTime(float curtime);
150         void SetLocalTime(float curtime);
151         bool ClampLocalTime();
152
153         MT_Point3       m_lastpos;
154         float   m_blendframe;
155         int             m_flag;
156         /** The frame this action starts */
157         float   m_startframe;
158         /** The frame this action ends */
159         float   m_endframe;
160         /** The time this action started */
161         float   m_starttime;
162         /** The current time of the action */
163         float   m_localtime;
164         
165         float   m_lastUpdate;
166         float   m_blendin;
167         float   m_blendstart;
168         float   m_stridelength;
169         short   m_playtype;
170         short   m_priority;
171         struct bAction *m_action;
172         STR_String      m_propname;
173         STR_String      m_framepropname;
174         vector<float> m_blendshape;
175 };
176
177 #endif
178