BGE Python API cleanup - no functionality changes
[blender.git] / source / gameengine / Converter / BL_ShapeActionActuator.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., 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 #if defined (__sgi)
31 #include <math.h>
32 #else
33 #include <cmath>
34 #endif
35
36 #include "SCA_LogicManager.h"
37 #include "BL_ShapeActionActuator.h"
38 #include "BL_ShapeDeformer.h"
39 #include "KX_GameObject.h"
40 #include "STR_HashedString.h"
41 #include "DNA_nla_types.h"
42 #include "DNA_action_types.h"
43 #include "BKE_action.h"
44 #include "DNA_armature_types.h"
45 #include "MEM_guardedalloc.h"
46 #include "BLI_blenlib.h"
47 #include "BLI_arithb.h"
48 #include "MT_Matrix4x4.h"
49 #include "BKE_utildefines.h"
50 #include "FloatValue.h"
51 #include "PyObjectPlus.h"
52 #include "blendef.h"
53
54 #ifdef HAVE_CONFIG_H
55 #include <config.h>
56 #endif
57
58 BL_ShapeActionActuator::~BL_ShapeActionActuator()
59 {
60 }
61
62 void BL_ShapeActionActuator::ProcessReplica()
63 {
64         m_localtime=m_startframe;
65         m_lastUpdate=-1;
66 }
67
68 void BL_ShapeActionActuator::SetBlendTime (float newtime)
69 {
70         m_blendframe = newtime;
71 }
72
73 CValue* BL_ShapeActionActuator::GetReplica() 
74 {
75         BL_ShapeActionActuator* replica = new BL_ShapeActionActuator(*this);//m_float,GetName());
76         replica->ProcessReplica();
77         
78         // this will copy properties and so on...
79         CValue::AddDataToReplica(replica);
80         return replica;
81 }
82
83 bool BL_ShapeActionActuator::ClampLocalTime()
84 {
85         if (m_startframe < m_endframe)  {
86                 if (m_localtime < m_startframe)
87                 {
88                         m_localtime = m_startframe;
89                         return true;
90                 } 
91                 else if (m_localtime > m_endframe)
92                 {
93                         m_localtime = m_endframe;
94                         return true;
95                 }
96         } else {
97                 if (m_localtime > m_startframe)
98                 {
99                         m_localtime = m_startframe;
100                         return true;
101                 }
102                 else if (m_localtime < m_endframe)
103                 {
104                         m_localtime = m_endframe;
105                         return true;
106                 }
107         }
108         return false;
109 }
110
111 void BL_ShapeActionActuator::SetStartTime(float curtime)
112 {
113         float direction = m_startframe < m_endframe ? 1.0 : -1.0;
114         
115         if (!(m_flag & ACT_FLAG_REVERSE))
116                 m_starttime = curtime - direction*(m_localtime - m_startframe)/KX_KetsjiEngine::GetAnimFrameRate();
117         else
118                 m_starttime = curtime - direction*(m_endframe - m_localtime)/KX_KetsjiEngine::GetAnimFrameRate();
119 }
120
121 void BL_ShapeActionActuator::SetLocalTime(float curtime)
122 {
123         float delta_time = (curtime - m_starttime)*KX_KetsjiEngine::GetAnimFrameRate();
124         
125         if (m_endframe < m_startframe)
126                 delta_time = -delta_time;
127
128         if (!(m_flag & ACT_FLAG_REVERSE))
129                 m_localtime = m_startframe + delta_time;
130         else
131                 m_localtime = m_endframe - delta_time;
132 }
133
134 void BL_ShapeActionActuator::BlendShape(Key* key, float srcweight)
135 {
136         vector<float>::const_iterator it;
137         float dstweight;
138         KeyBlock *kb;
139         
140         dstweight = 1.0F - srcweight;
141
142         for (it=m_blendshape.begin(), kb = (KeyBlock*)key->block.first; 
143                  kb && it != m_blendshape.end(); 
144                  kb = (KeyBlock*)kb->next, it++) {
145                 kb->curval = kb->curval * dstweight + (*it) * srcweight;
146         }
147 }
148
149 bool BL_ShapeActionActuator::Update(double curtime, bool frame)
150 {
151         bool bNegativeEvent = false;
152         bool bPositiveEvent = false;
153         bool keepgoing = true;
154         bool wrap = false;
155         bool apply=true;
156         int     priority;
157         float newweight;
158
159         curtime -= KX_KetsjiEngine::GetSuspendedDelta();
160         
161         // result = true if animation has to be continued, false if animation stops
162         // maybe there are events for us in the queue !
163         if (frame)
164         {
165                 for (vector<CValue*>::iterator i=m_events.begin(); !(i==m_events.end());i++)
166                 {
167                         if ((*i)->GetNumber() == 0.0f)
168                                 bNegativeEvent = true;
169                         else
170                                 bPositiveEvent= true;
171                         (*i)->Release();
172                 
173                 }
174                 m_events.clear();
175                 
176                 if (bPositiveEvent)
177                         m_flag |= ACT_FLAG_ACTIVE;
178                 
179                 if (bNegativeEvent)
180                 {
181                         if (!(m_flag & ACT_FLAG_ACTIVE))
182                                 return false;
183                         m_flag &= ~ACT_FLAG_ACTIVE;
184                 }
185         }
186         
187         /*      This action can only be attached to a deform object */
188         BL_DeformableGameObject *obj = (BL_DeformableGameObject*)GetParent();
189         float length = m_endframe - m_startframe;
190         
191         priority = m_priority;
192         
193         /* Determine pre-incrementation behaviour and set appropriate flags */
194         switch (m_playtype){
195         case ACT_ACTION_MOTION:
196                 if (bNegativeEvent){
197                         keepgoing=false;
198                         apply=false;
199                 };
200                 break;
201         case ACT_ACTION_FROM_PROP:
202                 if (bNegativeEvent){
203                         apply=false;
204                         keepgoing=false;
205                 }
206                 break;
207         case ACT_ACTION_LOOP_END:
208                 if (bPositiveEvent){
209                         if (!(m_flag & ACT_FLAG_LOCKINPUT)){
210                                 m_flag &= ~ACT_FLAG_KEYUP;
211                                 m_flag &= ~ACT_FLAG_REVERSE;
212                                 m_flag |= ACT_FLAG_LOCKINPUT;
213                                 m_localtime = m_startframe;
214                                 m_starttime = curtime;
215                         }
216                 }
217                 if (bNegativeEvent){
218                         m_flag |= ACT_FLAG_KEYUP;
219                 }
220                 break;
221         case ACT_ACTION_LOOP_STOP:
222                 if (bPositiveEvent){
223                         if (!(m_flag & ACT_FLAG_LOCKINPUT)){
224                                 m_flag &= ~ACT_FLAG_REVERSE;
225                                 m_flag &= ~ACT_FLAG_KEYUP;
226                                 m_flag |= ACT_FLAG_LOCKINPUT;
227                                 SetStartTime(curtime);
228                         }
229                 }
230                 if (bNegativeEvent){
231                         m_flag |= ACT_FLAG_KEYUP;
232                         m_flag &= ~ACT_FLAG_LOCKINPUT;
233                         keepgoing=false;
234                         apply=false;
235                 }
236                 break;
237         case ACT_ACTION_FLIPPER:
238                 if (bPositiveEvent){
239                         if (!(m_flag & ACT_FLAG_LOCKINPUT)){
240                                 m_flag &= ~ACT_FLAG_REVERSE;
241                                 m_flag |= ACT_FLAG_LOCKINPUT;
242                                 SetStartTime(curtime);
243                         }
244                 }
245                 else if (bNegativeEvent){
246                         m_flag |= ACT_FLAG_REVERSE;
247                         m_flag &= ~ACT_FLAG_LOCKINPUT;
248                         SetStartTime(curtime);
249                 }
250                 break;
251         case ACT_ACTION_PLAY:
252                 if (bPositiveEvent){
253                         if (!(m_flag & ACT_FLAG_LOCKINPUT)){
254                                 m_flag &= ~ACT_FLAG_REVERSE;
255                                 m_localtime = m_starttime;
256                                 m_starttime = curtime;
257                                 m_flag |= ACT_FLAG_LOCKINPUT;
258                         }
259                 }
260                 break;
261         default:
262                 break;
263         }
264         
265         /* Perform increment */
266         if (keepgoing){
267                 if (m_playtype == ACT_ACTION_MOTION){
268                         MT_Point3       newpos;
269                         MT_Point3       deltapos;
270                         
271                         newpos = obj->NodeGetWorldPosition();
272                         
273                         /* Find displacement */
274                         deltapos = newpos-m_lastpos;
275                         m_localtime += (length/m_stridelength) * deltapos.length();
276                         m_lastpos = newpos;
277                 }
278                 else{
279                         SetLocalTime(curtime);
280                 }
281         }
282         
283         /* Check if a wrapping response is needed */
284         if (length){
285                 if (m_localtime < m_startframe || m_localtime > m_endframe)
286                 {
287                         m_localtime = m_startframe + fmod(m_localtime, length);
288                         wrap = true;
289                 }
290         }
291         else
292                 m_localtime = m_startframe;
293         
294         /* Perform post-increment tasks */
295         switch (m_playtype){
296         case ACT_ACTION_FROM_PROP:
297                 {
298                         CValue* propval = GetParent()->GetProperty(m_propname);
299                         if (propval)
300                                 m_localtime = propval->GetNumber();
301                         
302                         if (bNegativeEvent){
303                                 keepgoing=false;
304                         }
305                 }
306                 break;
307         case ACT_ACTION_MOTION:
308                 break;
309         case ACT_ACTION_LOOP_STOP:
310                 break;
311         case ACT_ACTION_FLIPPER:
312                 if (wrap){
313                         if (!(m_flag & ACT_FLAG_REVERSE)){
314                                 m_localtime=m_endframe;
315                                 //keepgoing = false;
316                         }
317                         else {
318                                 m_localtime=m_startframe;
319                                 keepgoing = false;
320                         }
321                 }
322                 break;
323         case ACT_ACTION_LOOP_END:
324                 if (wrap){
325                         if (m_flag & ACT_FLAG_KEYUP){
326                                 keepgoing = false;
327                                 m_localtime = m_endframe;
328                                 m_flag &= ~ACT_FLAG_LOCKINPUT;
329                         }
330                         SetStartTime(curtime);
331                 }
332                 break;
333         case ACT_ACTION_PLAY:
334                 if (wrap){
335                         m_localtime = m_endframe;
336                         keepgoing = false;
337                         m_flag &= ~ACT_FLAG_LOCKINPUT;
338                 }
339                 break;
340         default:
341                 keepgoing = false;
342                 break;
343         }
344         
345         /* Set the property if its defined */
346         if (m_framepropname[0] != '\0') {
347                 CValue* propowner = GetParent();
348                 CValue* oldprop = propowner->GetProperty(m_framepropname);
349                 CValue* newval = new CFloatValue(m_localtime);
350                 if (oldprop) {
351                         oldprop->SetValue(newval);
352                 } else {
353                         propowner->SetProperty(m_framepropname, newval);
354                 }
355                 newval->Release();
356         }
357         
358         if (bNegativeEvent)
359                 m_blendframe=0.0f;
360         
361         /* Apply the pose if necessary*/
362         if (apply) {
363
364                 /* Priority test */
365                 if (obj->SetActiveAction(this, priority, curtime)){
366                         Key *key = obj->GetKey();
367
368                         if (!key) {
369                                 // this could happen if the mesh was changed in the middle of an action
370                                 // and the new mesh has no key, stop the action
371                                 keepgoing = false;
372                         }
373                         else {
374                                 ListBase tchanbase= {NULL, NULL};
375                         
376                                 if (m_blendin && m_blendframe==0.0f){
377                                         // this is the start of the blending, remember the startup shape
378                                         obj->GetShape(m_blendshape);
379                                         m_blendstart = curtime;
380                                 }
381                                 // only interested in shape channel
382                                 extract_ipochannels_from_action(&tchanbase, &key->id, m_action, "Shape", m_localtime);
383                 
384                                 if (!execute_ipochannels(&tchanbase)) {
385                                         // no update, this is possible if action does not match the keys, stop the action
386                                         keepgoing = false;
387                                 } 
388                                 else {
389                                         // the key have changed, apply blending if needed
390                                         if (m_blendin && (m_blendframe<m_blendin)){
391                                                 newweight = (m_blendframe/(float)m_blendin);
392
393                                                 BlendShape(key, 1.0f - newweight);
394
395                                                 /* Increment current blending percentage */
396                                                 m_blendframe = (curtime - m_blendstart)*KX_KetsjiEngine::GetAnimFrameRate();
397                                                 if (m_blendframe>m_blendin)
398                                                         m_blendframe = m_blendin;
399                                         }
400                                         m_lastUpdate = m_localtime;
401                                 }
402                                 BLI_freelistN(&tchanbase);
403                         }
404                 }
405                 else{
406                         m_blendframe = 0.0f;
407                 }
408         }
409         
410         if (!keepgoing){
411                 m_blendframe = 0.0f;
412         }
413         return keepgoing;
414 };
415
416 /* ------------------------------------------------------------------------- */
417 /* Python functions                                                          */
418 /* ------------------------------------------------------------------------- */
419
420 /* Integration hooks ------------------------------------------------------- */
421
422 PyTypeObject BL_ShapeActionActuator::Type = {
423         PyObject_HEAD_INIT(NULL)
424                 0,
425                 "BL_ShapeActionActuator",
426                 sizeof(PyObjectPlus_Proxy),
427                 0,
428                 py_base_dealloc,
429                 0,
430                 0,
431                 0,
432                 0,
433                 py_base_repr,
434                 0,0,0,0,0,0,
435                 py_base_getattro,
436                 py_base_setattro,
437                 0,0,0,0,0,0,0,0,0,
438                 Methods
439 };
440
441 PyParentObject BL_ShapeActionActuator::Parents[] = {
442         &BL_ShapeActionActuator::Type,
443                 &SCA_IActuator::Type,
444                 &SCA_ILogicBrick::Type,
445                 &CValue::Type,
446                 NULL
447 };
448
449 PyMethodDef BL_ShapeActionActuator::Methods[] = {
450         {"setAction", (PyCFunction) BL_ShapeActionActuator::sPySetAction, METH_VARARGS, (PY_METHODCHAR)SetAction_doc},
451         {"setStart", (PyCFunction) BL_ShapeActionActuator::sPySetStart, METH_VARARGS, (PY_METHODCHAR)SetStart_doc},
452         {"setEnd", (PyCFunction) BL_ShapeActionActuator::sPySetEnd, METH_VARARGS, (PY_METHODCHAR)SetEnd_doc},
453         {"setBlendin", (PyCFunction) BL_ShapeActionActuator::sPySetBlendin, METH_VARARGS, (PY_METHODCHAR)SetBlendin_doc},
454         {"setPriority", (PyCFunction) BL_ShapeActionActuator::sPySetPriority, METH_VARARGS, (PY_METHODCHAR)SetPriority_doc},
455         {"setFrame", (PyCFunction) BL_ShapeActionActuator::sPySetFrame, METH_VARARGS, (PY_METHODCHAR)SetFrame_doc},
456         {"setProperty", (PyCFunction) BL_ShapeActionActuator::sPySetProperty, METH_VARARGS, (PY_METHODCHAR)SetProperty_doc},
457         {"setFrameProperty", (PyCFunction) BL_ShapeActionActuator::sPySetFrameProperty, METH_VARARGS, (PY_METHODCHAR)SetFrameProperty_doc},
458         {"setBlendtime", (PyCFunction) BL_ShapeActionActuator::sPySetBlendtime, METH_VARARGS, (PY_METHODCHAR)SetBlendtime_doc},
459
460         {"getAction", (PyCFunction) BL_ShapeActionActuator::sPyGetAction, METH_NOARGS, (PY_METHODCHAR)GetAction_doc},
461         {"getStart", (PyCFunction) BL_ShapeActionActuator::sPyGetStart, METH_NOARGS, (PY_METHODCHAR)GetStart_doc},
462         {"getEnd", (PyCFunction) BL_ShapeActionActuator::sPyGetEnd, METH_NOARGS, (PY_METHODCHAR)GetEnd_doc},
463         {"getBlendin", (PyCFunction) BL_ShapeActionActuator::sPyGetBlendin, METH_NOARGS, (PY_METHODCHAR)GetBlendin_doc},
464         {"getPriority", (PyCFunction) BL_ShapeActionActuator::sPyGetPriority, METH_NOARGS, (PY_METHODCHAR)GetPriority_doc},
465         {"getFrame", (PyCFunction) BL_ShapeActionActuator::sPyGetFrame, METH_NOARGS, (PY_METHODCHAR)GetFrame_doc},
466         {"getProperty", (PyCFunction) BL_ShapeActionActuator::sPyGetProperty, METH_NOARGS, (PY_METHODCHAR)GetProperty_doc},
467         {"getFrameProperty", (PyCFunction) BL_ShapeActionActuator::sPyGetFrameProperty, METH_NOARGS, (PY_METHODCHAR)GetFrameProperty_doc},
468         {"getType", (PyCFunction) BL_ShapeActionActuator::sPyGetType, METH_NOARGS, (PY_METHODCHAR)GetType_doc}, 
469         {"setType", (PyCFunction) BL_ShapeActionActuator::sPySetType, METH_NOARGS, (PY_METHODCHAR)SetType_doc},
470         {NULL,NULL} //Sentinel
471 };
472
473 PyAttributeDef BL_ShapeActionActuator::Attributes[] = {
474         KX_PYATTRIBUTE_FLOAT_RW("start", 0, MAXFRAMEF, BL_ShapeActionActuator, m_startframe),
475         KX_PYATTRIBUTE_FLOAT_RW("end", 0, MAXFRAMEF, BL_ShapeActionActuator, m_endframe),
476         KX_PYATTRIBUTE_FLOAT_RW("blendin", 0, MAXFRAMEF, BL_ShapeActionActuator, m_blendin),
477         KX_PYATTRIBUTE_RW_FUNCTION("action", BL_ShapeActionActuator, pyattr_get_action, pyattr_set_action),
478         KX_PYATTRIBUTE_SHORT_RW("priority", 0, 100, false, BL_ShapeActionActuator, m_priority),
479         KX_PYATTRIBUTE_FLOAT_RW_CHECK("frame", 0, MAXFRAMEF, BL_ShapeActionActuator, m_localtime, CheckFrame),
480         KX_PYATTRIBUTE_STRING_RW("property", 0, 31, false, BL_ShapeActionActuator, m_propname),
481         KX_PYATTRIBUTE_STRING_RW("frameProperty", 0, 31, false, BL_ShapeActionActuator, m_framepropname),
482         KX_PYATTRIBUTE_FLOAT_RW_CHECK("blendTime", 0, MAXFRAMEF, BL_ShapeActionActuator, m_blendframe, CheckBlendTime),
483         KX_PYATTRIBUTE_SHORT_RW_CHECK("type",0,100,false,BL_ShapeActionActuator,m_playtype,CheckType),
484         { NULL }        //Sentinel
485 };
486
487
488 PyObject* BL_ShapeActionActuator::py_getattro(PyObject* attr) {
489         py_getattro_up(SCA_IActuator);
490 }
491
492 int BL_ShapeActionActuator::py_setattro(PyObject *attr, PyObject* value) {
493         py_setattro_up(SCA_IActuator);
494 }
495
496 /*     setStart                                                              */
497 const char BL_ShapeActionActuator::GetAction_doc[] = 
498 "getAction()\n"
499 "\tReturns a string containing the name of the current action.\n";
500
501 PyObject* BL_ShapeActionActuator::PyGetAction(PyObject* self) {
502         ShowDeprecationWarning("getAction()", "the action property");
503         if (m_action){
504                 return PyString_FromString(m_action->id.name+2);
505         }
506         Py_RETURN_NONE;
507 }
508
509 /*     getProperty                                                             */
510 const char BL_ShapeActionActuator::GetProperty_doc[] = 
511 "getProperty()\n"
512 "\tReturns the name of the property to be used in FromProp mode.\n";
513
514 PyObject* BL_ShapeActionActuator::PyGetProperty(PyObject* self) {
515         ShowDeprecationWarning("getProperty()", "the property property");
516         PyObject *result;
517         
518         result = Py_BuildValue("s", (const char *)m_propname);
519         
520         return result;
521 }
522
523 /*     getFrame                                                              */
524 const char BL_ShapeActionActuator::GetFrame_doc[] = 
525 "getFrame()\n"
526 "\tReturns the current frame number.\n";
527
528 PyObject* BL_ShapeActionActuator::PyGetFrame(PyObject* self) {
529         ShowDeprecationWarning("getFrame()", "the frame property");
530         PyObject *result;
531         
532         result = Py_BuildValue("f", m_localtime);
533         
534         return result;
535 }
536
537 /*     getEnd                                                                */
538 const char BL_ShapeActionActuator::GetEnd_doc[] = 
539 "getEnd()\n"
540 "\tReturns the last frame of the action.\n";
541
542 PyObject* BL_ShapeActionActuator::PyGetEnd(PyObject* self) {
543         ShowDeprecationWarning("getEnd()", "the end property");
544         PyObject *result;
545         
546         result = Py_BuildValue("f", m_endframe);
547         
548         return result;
549 }
550
551 /*     getStart                                                              */
552 const char BL_ShapeActionActuator::GetStart_doc[] = 
553 "getStart()\n"
554 "\tReturns the starting frame of the action.\n";
555
556 PyObject* BL_ShapeActionActuator::PyGetStart(PyObject* self) {
557         ShowDeprecationWarning("getStart()", "the start property");
558         PyObject *result;
559         
560         result = Py_BuildValue("f", m_startframe);
561         
562         return result;
563 }
564
565 /*     getBlendin                                                            */
566 const char BL_ShapeActionActuator::GetBlendin_doc[] = 
567 "getBlendin()\n"
568 "\tReturns the number of interpolation animation frames to be\n"
569 "\tgenerated when this actuator is triggered.\n";
570
571 PyObject* BL_ShapeActionActuator::PyGetBlendin(PyObject* self) {
572         ShowDeprecationWarning("getBlendin()", "the blendin property");
573         PyObject *result;
574         
575         result = Py_BuildValue("f", m_blendin);
576         
577         return result;
578 }
579
580 /*     getPriority                                                           */
581 const char BL_ShapeActionActuator::GetPriority_doc[] = 
582 "getPriority()\n"
583 "\tReturns the priority for this actuator.  Actuators with lower\n"
584 "\tPriority numbers will override actuators with higher numbers.\n";
585
586 PyObject* BL_ShapeActionActuator::PyGetPriority(PyObject* self) {
587         ShowDeprecationWarning("getPriority()", "the priority property");
588         PyObject *result;
589         
590         result = Py_BuildValue("i", m_priority);
591         
592         return result;
593 }
594
595 /*     setAction                                                             */
596 const char BL_ShapeActionActuator::SetAction_doc[] = 
597 "setAction(action, (reset))\n"
598 "\t - action    : The name of the action to set as the current action.\n"
599 "\t               Should be an action with Shape channels.\n"
600 "\t - reset     : Optional parameter indicating whether to reset the\n"
601 "\t               blend timer or not.  A value of 1 indicates that the\n"
602 "\t               timer should be reset.  A value of 0 will leave it\n"
603 "\t               unchanged.  If reset is not specified, the timer will"
604 "\t                   be reset.\n";
605
606 PyObject* BL_ShapeActionActuator::PySetAction(PyObject* self, 
607                                                                                           PyObject* args, 
608                                                                                           PyObject* kwds) {
609         ShowDeprecationWarning("setAction()", "the action property");
610         char *string;
611         int     reset = 1;
612
613         if (PyArg_ParseTuple(args,"s|i:setAction",&string, &reset))
614         {
615                 bAction *action;
616                 
617                 action = (bAction*)SCA_ILogicBrick::m_sCurrentLogicManager->GetActionByName(STR_String(string));
618                 
619                 if (!action){
620                         /* NOTE!  Throw an exception or something */
621                         //                      printf ("setAction failed: Action not found\n", string);
622                 }
623                 else{
624                         m_action=action;
625                         if (reset)
626                                 m_blendframe = 0.f;
627                 }
628         }
629         else {
630                 return NULL;
631         }
632         
633         Py_RETURN_NONE;
634 }
635
636 /*     setStart                                                              */
637 const char BL_ShapeActionActuator::SetStart_doc[] = 
638 "setStart(start)\n"
639 "\t - start     : Specifies the starting frame of the animation.\n";
640
641 PyObject* BL_ShapeActionActuator::PySetStart(PyObject* self, 
642                                                                                          PyObject* args, 
643                                                                                          PyObject* kwds) {
644         ShowDeprecationWarning("setStart()", "the start property");
645         float start;
646         
647         if (PyArg_ParseTuple(args,"f:setStart",&start))
648         {
649                 m_startframe = start;
650         }
651         else {
652                 return NULL;
653         }
654         
655         Py_RETURN_NONE;
656 }
657
658 /*     setEnd                                                                */
659 const char BL_ShapeActionActuator::SetEnd_doc[] = 
660 "setEnd(end)\n"
661 "\t - end       : Specifies the ending frame of the animation.\n";
662
663 PyObject* BL_ShapeActionActuator::PySetEnd(PyObject* self, 
664                                                                                    PyObject* args, 
665                                                                                    PyObject* kwds) {
666         ShowDeprecationWarning("setEnd()", "the end property");
667         float end;
668         
669         if (PyArg_ParseTuple(args,"f:setEnd",&end))
670         {
671                 m_endframe = end;
672         }
673         else {
674                 return NULL;
675         }
676         
677         Py_RETURN_NONE;
678 }
679
680 /*     setBlendin                                                            */
681 const char BL_ShapeActionActuator::SetBlendin_doc[] = 
682 "setBlendin(blendin)\n"
683 "\t - blendin   : Specifies the number of frames of animation to generate\n"
684 "\t               when making transitions between actions.\n";
685
686 PyObject* BL_ShapeActionActuator::PySetBlendin(PyObject* self, 
687                                                                                            PyObject* args, 
688                                                                                            PyObject* kwds) {
689         ShowDeprecationWarning("setBlendin()", "the blendin property");
690         float blendin;
691         
692         if (PyArg_ParseTuple(args,"f:setBlendin",&blendin))
693         {
694                 m_blendin = blendin;
695         }
696         else {
697                 return NULL;
698         }
699         
700         Py_RETURN_NONE;
701 }
702
703 /*     setBlendtime                                                          */
704 const char BL_ShapeActionActuator::SetBlendtime_doc[] = 
705 "setBlendtime(blendtime)\n"
706 "\t - blendtime : Allows the script to directly modify the internal timer\n"
707 "\t               used when generating transitions between actions.  This\n"
708 "\t               parameter must be in the range from 0.0 to 1.0.\n";
709
710 PyObject* BL_ShapeActionActuator::PySetBlendtime(PyObject* self, 
711                                                                                                  PyObject* args, 
712                                                                                                    PyObject* kwds) {
713         ShowDeprecationWarning("setBlendtime()", "the blendTime property");
714         float blendframe;
715         
716         if (PyArg_ParseTuple(args,"f:setBlendtime",&blendframe))
717         {
718                 m_blendframe = blendframe * m_blendin;
719                 if (m_blendframe<0.f)
720                         m_blendframe = 0.f;
721                 if (m_blendframe>m_blendin)
722                         m_blendframe = m_blendin;
723         }
724         else {
725                 return NULL;
726         }
727         
728         Py_RETURN_NONE;
729 }
730
731 /*     setPriority                                                           */
732 const char BL_ShapeActionActuator::SetPriority_doc[] = 
733 "setPriority(priority)\n"
734 "\t - priority  : Specifies the new priority.  Actuators will lower\n"
735 "\t               priority numbers will override actuators with higher\n"
736 "\t               numbers.\n";
737
738 PyObject* BL_ShapeActionActuator::PySetPriority(PyObject* self, 
739                                                                                                 PyObject* args, 
740                                                                                                 PyObject* kwds) {
741         ShowDeprecationWarning("setPriority()", "the priority property");
742         int priority;
743         
744         if (PyArg_ParseTuple(args,"i:setPriority",&priority))
745         {
746                 m_priority = priority;
747         }
748         else {
749                 return NULL;
750         }
751         
752         Py_RETURN_NONE;
753 }
754
755 /*     getProperty                                                             */
756 const char BL_ShapeActionActuator::GetFrameProperty_doc[] = 
757 "getFrameProperty()\n"
758 "\tReturns the name of the property, that is set to the current frame number.\n";
759
760 PyObject* BL_ShapeActionActuator::PyGetFrameProperty(PyObject* self) {
761         ShowDeprecationWarning("getFrameProperty()", "the frameProperty property");
762         PyObject *result;
763         
764         result = Py_BuildValue("s", (const char *)m_framepropname);
765         
766         return result;
767 }
768
769
770 /*     setFrame                                                              */
771 const char BL_ShapeActionActuator::SetFrame_doc[] = 
772 "setFrame(frame)\n"
773 "\t - frame     : Specifies the new current frame for the animation\n";
774
775 PyObject* BL_ShapeActionActuator::PySetFrame(PyObject* self, 
776                                                                                          PyObject* args, 
777                                                                                          PyObject* kwds) {
778         ShowDeprecationWarning("setFrame()", "the frame property");
779         float frame;
780         
781         if (PyArg_ParseTuple(args,"f:setFrame",&frame))
782         {
783                 m_localtime = frame;
784                 if (m_localtime<m_startframe)
785                         m_localtime=m_startframe;
786                 else if (m_localtime>m_endframe)
787                         m_localtime=m_endframe;
788         }
789         else {
790                 return NULL;
791         }
792         
793         Py_RETURN_NONE;
794 }
795
796 /*     setProperty                                                           */
797 const char BL_ShapeActionActuator::SetProperty_doc[] = 
798 "setProperty(prop)\n"
799 "\t - prop      : A string specifying the property name to be used in\n"
800 "\t               FromProp playback mode.\n";
801
802 PyObject* BL_ShapeActionActuator::PySetProperty(PyObject* self, 
803                                                                                                 PyObject* args, 
804                                                                                                 PyObject* kwds) {
805         ShowDeprecationWarning("setProperty()", "the property property");
806         char *string;
807         
808         if (PyArg_ParseTuple(args,"s:setProperty",&string))
809         {
810                 m_propname = string;
811         }
812         else {
813                 return NULL;
814         }
815         
816         Py_RETURN_NONE;
817 }
818
819 /*     setFrameProperty                                                          */
820 const char BL_ShapeActionActuator::SetFrameProperty_doc[] = 
821 "setFrameProperty(prop)\n"
822 "\t - prop      : A string specifying the property of the frame set up update.\n";
823
824 PyObject* BL_ShapeActionActuator::PySetFrameProperty(PyObject* self, 
825                                                                                    PyObject* args, 
826                                                                                    PyObject* kwds) {
827         ShowDeprecationWarning("setFrameProperty()", "the frameProperty property");
828         char *string;
829         
830         if (PyArg_ParseTuple(args,"s:setFrameProperty",&string))
831         {
832                 m_framepropname = string;
833         }
834         else {
835                 return NULL;
836         }
837         
838         Py_RETURN_NONE;
839 }
840
841 /* getType */
842 const char BL_ShapeActionActuator::GetType_doc[] =
843 "getType()\n"
844 "\tReturns the operation mode of the actuator.\n";
845 PyObject* BL_ShapeActionActuator::PyGetType(PyObject* self) {
846         ShowDeprecationWarning("getType()", "the type property");
847     return Py_BuildValue("h", m_playtype);
848 }
849
850 /* setType */
851 const char BL_ShapeActionActuator::SetType_doc[] =
852 "setType(mode)\n"
853 "\t - mode: Play (0), Flipper (2), LoopStop (3), LoopEnd (4) or Property (6)\n"
854 "\tSet the operation mode of the actuator.\n";
855 PyObject* BL_ShapeActionActuator::PySetType(PyObject* self,
856                                             PyObject* args,
857                                             PyObject* kwds) {
858         ShowDeprecationWarning("setType()", "the type property");
859         short typeArg;
860                                                                                                              
861     if (!PyArg_ParseTuple(args, "h:setType", &typeArg)) {
862         return NULL;
863     }
864
865         switch (typeArg) {
866         case ACT_ACTION_PLAY:
867         case ACT_ACTION_FLIPPER:
868         case ACT_ACTION_LOOP_STOP:
869         case ACT_ACTION_LOOP_END:
870         case ACT_ACTION_FROM_PROP:
871                 m_playtype = typeArg;
872                 break;
873         default:
874                 printf("Invalid type for action actuator: %d\n", typeArg); /* error */
875     }
876         
877     Py_RETURN_NONE;
878 }
879
880 PyObject* BL_ShapeActionActuator::pyattr_get_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
881 {
882         BL_ShapeActionActuator* self= static_cast<BL_ShapeActionActuator*>(self_v);
883         return PyString_FromString(self->GetAction() ? self->GetAction()->id.name+2 : "");
884 }
885
886 int BL_ShapeActionActuator::pyattr_set_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
887 {
888         BL_ShapeActionActuator* self= static_cast<BL_ShapeActionActuator*>(self_v);
889         /* exact copy of BL_ActionActuator's function from here down */
890         if (!PyString_Check(value))
891         {
892                 PyErr_SetString(PyExc_ValueError, "expected the string name of the action");
893                 return -1;
894         }
895
896         bAction *action= NULL;
897         STR_String val = PyString_AsString(value);
898         
899         if (val != "")
900         {
901                 action= (bAction*)SCA_ILogicBrick::m_sCurrentLogicManager->GetActionByName(val);
902                 if (action==NULL)
903                 {
904                         PyErr_SetString(PyExc_ValueError, "action not found!");
905                         return 1;
906                 }
907         }
908         
909         self->SetAction(action);
910         return 0;
911
912 }