BGE API cleanup: shape action actuator.
[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(&PyType_Type)
424                 0,
425                 "BL_ShapeActionActuator",
426                 sizeof(BL_ShapeActionActuator),
427                 0,
428                 PyDestructor,
429                 0,
430                 __getattr,
431                 __setattr,
432                 0, //&MyPyCompare,
433                 __repr,
434                 0, //&cvalue_as_number,
435                 0,
436                 0,
437                 0,
438                 0
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_SHORT_RW("priority", 0, 100, false, BL_ShapeActionActuator, m_priority),
478         KX_PYATTRIBUTE_FLOAT_RW_CHECK("frame", 0, MAXFRAMEF, BL_ShapeActionActuator, m_localtime, CheckFrame),
479         KX_PYATTRIBUTE_STRING_RW("property", 0, 31, false, BL_ShapeActionActuator, m_propname),
480         KX_PYATTRIBUTE_STRING_RW("frameProperty", 0, 31, false, BL_ShapeActionActuator, m_framepropname),
481         KX_PYATTRIBUTE_FLOAT_RW_CHECK("blendTime", 0, MAXFRAMEF, BL_ShapeActionActuator, m_blendframe, CheckBlendTime),
482         KX_PYATTRIBUTE_SHORT_RW_CHECK("type",0,100,false,BL_ShapeActionActuator,m_playtype,CheckType),
483         { NULL }        //Sentinel
484 };
485
486
487 PyObject* BL_ShapeActionActuator::_getattr(const STR_String& attr) {
488         if (attr == "action")
489                 return PyString_FromString(m_action->id.name+2);
490         PyObject* object = _getattr_self(Attributes, this, attr);
491         if (object != NULL)
492                 return object;
493         _getattr_up(SCA_IActuator);
494 }
495
496 int BL_ShapeActionActuator::_setattr(const STR_String& attr, PyObject* value) {
497         if (attr == "action")
498         {
499                 if (!PyString_Check(value))
500                 {
501                         PyErr_SetString(PyExc_ValueError, "expected a string");
502                         return 1;
503                 }
504
505                 STR_String val = PyString_AsString(value);
506                 
507                 if (val == "")
508                 {
509                         m_action = NULL;
510                         return 0;
511                 }
512
513                 bAction *action;
514                 
515                 action = (bAction*)SCA_ILogicBrick::m_sCurrentLogicManager->GetActionByName(val);
516                 
517
518                 if (!action)
519                 {
520                         PyErr_SetString(PyExc_ValueError, "action not found!");
521                         return 1;
522                 }
523
524                 m_action = action;
525                 return 0;
526         }
527         int ret = _setattr_self(Attributes, this, attr, value);
528         if (ret >= 0)
529                 return ret;
530         return SCA_IActuator::_setattr(attr, value);
531 }
532
533 /*     setStart                                                              */
534 const char BL_ShapeActionActuator::GetAction_doc[] = 
535 "getAction()\n"
536 "\tReturns a string containing the name of the current action.\n";
537
538 PyObject* BL_ShapeActionActuator::PyGetAction(PyObject* self) {
539         ShowDeprecationWarning("getAction()", "the action property");
540         if (m_action){
541                 return PyString_FromString(m_action->id.name+2);
542         }
543         Py_RETURN_NONE;
544 }
545
546 /*     getProperty                                                             */
547 const char BL_ShapeActionActuator::GetProperty_doc[] = 
548 "getProperty()\n"
549 "\tReturns the name of the property to be used in FromProp mode.\n";
550
551 PyObject* BL_ShapeActionActuator::PyGetProperty(PyObject* self) {
552         ShowDeprecationWarning("getProperty()", "the property property");
553         PyObject *result;
554         
555         result = Py_BuildValue("s", (const char *)m_propname);
556         
557         return result;
558 }
559
560 /*     getFrame                                                              */
561 const char BL_ShapeActionActuator::GetFrame_doc[] = 
562 "getFrame()\n"
563 "\tReturns the current frame number.\n";
564
565 PyObject* BL_ShapeActionActuator::PyGetFrame(PyObject* self) {
566         ShowDeprecationWarning("getFrame()", "the frame property");
567         PyObject *result;
568         
569         result = Py_BuildValue("f", m_localtime);
570         
571         return result;
572 }
573
574 /*     getEnd                                                                */
575 const char BL_ShapeActionActuator::GetEnd_doc[] = 
576 "getEnd()\n"
577 "\tReturns the last frame of the action.\n";
578
579 PyObject* BL_ShapeActionActuator::PyGetEnd(PyObject* self) {
580         ShowDeprecationWarning("getEnd()", "the end property");
581         PyObject *result;
582         
583         result = Py_BuildValue("f", m_endframe);
584         
585         return result;
586 }
587
588 /*     getStart                                                              */
589 const char BL_ShapeActionActuator::GetStart_doc[] = 
590 "getStart()\n"
591 "\tReturns the starting frame of the action.\n";
592
593 PyObject* BL_ShapeActionActuator::PyGetStart(PyObject* self) {
594         ShowDeprecationWarning("getStart()", "the start property");
595         PyObject *result;
596         
597         result = Py_BuildValue("f", m_startframe);
598         
599         return result;
600 }
601
602 /*     getBlendin                                                            */
603 const char BL_ShapeActionActuator::GetBlendin_doc[] = 
604 "getBlendin()\n"
605 "\tReturns the number of interpolation animation frames to be\n"
606 "\tgenerated when this actuator is triggered.\n";
607
608 PyObject* BL_ShapeActionActuator::PyGetBlendin(PyObject* self) {
609         ShowDeprecationWarning("getBlendin()", "the blendin property");
610         PyObject *result;
611         
612         result = Py_BuildValue("f", m_blendin);
613         
614         return result;
615 }
616
617 /*     getPriority                                                           */
618 const char BL_ShapeActionActuator::GetPriority_doc[] = 
619 "getPriority()\n"
620 "\tReturns the priority for this actuator.  Actuators with lower\n"
621 "\tPriority numbers will override actuators with higher numbers.\n";
622
623 PyObject* BL_ShapeActionActuator::PyGetPriority(PyObject* self) {
624         ShowDeprecationWarning("getPriority()", "the priority property");
625         PyObject *result;
626         
627         result = Py_BuildValue("i", m_priority);
628         
629         return result;
630 }
631
632 /*     setAction                                                             */
633 const char BL_ShapeActionActuator::SetAction_doc[] = 
634 "setAction(action, (reset))\n"
635 "\t - action    : The name of the action to set as the current action.\n"
636 "\t               Should be an action with Shape channels.\n"
637 "\t - reset     : Optional parameter indicating whether to reset the\n"
638 "\t               blend timer or not.  A value of 1 indicates that the\n"
639 "\t               timer should be reset.  A value of 0 will leave it\n"
640 "\t               unchanged.  If reset is not specified, the timer will"
641 "\t                   be reset.\n";
642
643 PyObject* BL_ShapeActionActuator::PySetAction(PyObject* self, 
644                                                                                           PyObject* args, 
645                                                                                           PyObject* kwds) {
646         ShowDeprecationWarning("setAction()", "the action property");
647         char *string;
648         int     reset = 1;
649
650         if (PyArg_ParseTuple(args,"s|i",&string, &reset))
651         {
652                 bAction *action;
653                 
654                 action = (bAction*)SCA_ILogicBrick::m_sCurrentLogicManager->GetActionByName(STR_String(string));
655                 
656                 if (!action){
657                         /* NOTE!  Throw an exception or something */
658                         //                      printf ("setAction failed: Action not found\n", string);
659                 }
660                 else{
661                         m_action=action;
662                         if (reset)
663                                 m_blendframe = 0.f;
664                 }
665         }
666         else {
667                 return NULL;
668         }
669         
670         Py_RETURN_NONE;
671 }
672
673 /*     setStart                                                              */
674 const char BL_ShapeActionActuator::SetStart_doc[] = 
675 "setStart(start)\n"
676 "\t - start     : Specifies the starting frame of the animation.\n";
677
678 PyObject* BL_ShapeActionActuator::PySetStart(PyObject* self, 
679                                                                                          PyObject* args, 
680                                                                                          PyObject* kwds) {
681         ShowDeprecationWarning("setStart()", "the start property");
682         float start;
683         
684         if (PyArg_ParseTuple(args,"f",&start))
685         {
686                 m_startframe = start;
687         }
688         else {
689                 return NULL;
690         }
691         
692         Py_RETURN_NONE;
693 }
694
695 /*     setEnd                                                                */
696 const char BL_ShapeActionActuator::SetEnd_doc[] = 
697 "setEnd(end)\n"
698 "\t - end       : Specifies the ending frame of the animation.\n";
699
700 PyObject* BL_ShapeActionActuator::PySetEnd(PyObject* self, 
701                                                                                    PyObject* args, 
702                                                                                    PyObject* kwds) {
703         ShowDeprecationWarning("setEnd()", "the end property");
704         float end;
705         
706         if (PyArg_ParseTuple(args,"f",&end))
707         {
708                 m_endframe = end;
709         }
710         else {
711                 return NULL;
712         }
713         
714         Py_RETURN_NONE;
715 }
716
717 /*     setBlendin                                                            */
718 const char BL_ShapeActionActuator::SetBlendin_doc[] = 
719 "setBlendin(blendin)\n"
720 "\t - blendin   : Specifies the number of frames of animation to generate\n"
721 "\t               when making transitions between actions.\n";
722
723 PyObject* BL_ShapeActionActuator::PySetBlendin(PyObject* self, 
724                                                                                            PyObject* args, 
725                                                                                            PyObject* kwds) {
726         ShowDeprecationWarning("setBlendin()", "the blendin property");
727         float blendin;
728         
729         if (PyArg_ParseTuple(args,"f",&blendin))
730         {
731                 m_blendin = blendin;
732         }
733         else {
734                 return NULL;
735         }
736         
737         Py_RETURN_NONE;
738 }
739
740 /*     setBlendtime                                                          */
741 const char BL_ShapeActionActuator::SetBlendtime_doc[] = 
742 "setBlendtime(blendtime)\n"
743 "\t - blendtime : Allows the script to directly modify the internal timer\n"
744 "\t               used when generating transitions between actions.  This\n"
745 "\t               parameter must be in the range from 0.0 to 1.0.\n";
746
747 PyObject* BL_ShapeActionActuator::PySetBlendtime(PyObject* self, 
748                                                                                                  PyObject* args, 
749                                                                                                    PyObject* kwds) {
750         ShowDeprecationWarning("setBlendtime()", "the blendTime property");
751         float blendframe;
752         
753         if (PyArg_ParseTuple(args,"f",&blendframe))
754         {
755                 m_blendframe = blendframe * m_blendin;
756                 if (m_blendframe<0.f)
757                         m_blendframe = 0.f;
758                 if (m_blendframe>m_blendin)
759                         m_blendframe = m_blendin;
760         }
761         else {
762                 return NULL;
763         }
764         
765         Py_RETURN_NONE;
766 }
767
768 /*     setPriority                                                           */
769 const char BL_ShapeActionActuator::SetPriority_doc[] = 
770 "setPriority(priority)\n"
771 "\t - priority  : Specifies the new priority.  Actuators will lower\n"
772 "\t               priority numbers will override actuators with higher\n"
773 "\t               numbers.\n";
774
775 PyObject* BL_ShapeActionActuator::PySetPriority(PyObject* self, 
776                                                                                                 PyObject* args, 
777                                                                                                 PyObject* kwds) {
778         ShowDeprecationWarning("setPriority()", "the priority property");
779         int priority;
780         
781         if (PyArg_ParseTuple(args,"i",&priority))
782         {
783                 m_priority = priority;
784         }
785         else {
786                 return NULL;
787         }
788         
789         Py_RETURN_NONE;
790 }
791
792 /*     getProperty                                                             */
793 const char BL_ShapeActionActuator::GetFrameProperty_doc[] = 
794 "getFrameProperty()\n"
795 "\tReturns the name of the property, that is set to the current frame number.\n";
796
797 PyObject* BL_ShapeActionActuator::PyGetFrameProperty(PyObject* self) {
798         ShowDeprecationWarning("getFrameProperty()", "the frameProperty property");
799         PyObject *result;
800         
801         result = Py_BuildValue("s", (const char *)m_framepropname);
802         
803         return result;
804 }
805
806
807 /*     setFrame                                                              */
808 const char BL_ShapeActionActuator::SetFrame_doc[] = 
809 "setFrame(frame)\n"
810 "\t - frame     : Specifies the new current frame for the animation\n";
811
812 PyObject* BL_ShapeActionActuator::PySetFrame(PyObject* self, 
813                                                                                          PyObject* args, 
814                                                                                          PyObject* kwds) {
815         ShowDeprecationWarning("setFrame()", "the frame property");
816         float frame;
817         
818         if (PyArg_ParseTuple(args,"f",&frame))
819         {
820                 m_localtime = frame;
821                 if (m_localtime<m_startframe)
822                         m_localtime=m_startframe;
823                 else if (m_localtime>m_endframe)
824                         m_localtime=m_endframe;
825         }
826         else {
827                 return NULL;
828         }
829         
830         Py_RETURN_NONE;
831 }
832
833 /*     setProperty                                                           */
834 const char BL_ShapeActionActuator::SetProperty_doc[] = 
835 "setProperty(prop)\n"
836 "\t - prop      : A string specifying the property name to be used in\n"
837 "\t               FromProp playback mode.\n";
838
839 PyObject* BL_ShapeActionActuator::PySetProperty(PyObject* self, 
840                                                                                                 PyObject* args, 
841                                                                                                 PyObject* kwds) {
842         ShowDeprecationWarning("setProperty()", "the property property");
843         char *string;
844         
845         if (PyArg_ParseTuple(args,"s",&string))
846         {
847                 m_propname = string;
848         }
849         else {
850                 return NULL;
851         }
852         
853         Py_RETURN_NONE;
854 }
855
856 /*     setFrameProperty                                                          */
857 const char BL_ShapeActionActuator::SetFrameProperty_doc[] = 
858 "setFrameProperty(prop)\n"
859 "\t - prop      : A string specifying the property of the frame set up update.\n";
860
861 PyObject* BL_ShapeActionActuator::PySetFrameProperty(PyObject* self, 
862                                                                                    PyObject* args, 
863                                                                                    PyObject* kwds) {
864         ShowDeprecationWarning("setFrameProperty()", "the frameProperty property");
865         char *string;
866         
867         if (PyArg_ParseTuple(args,"s",&string))
868         {
869                 m_framepropname = string;
870         }
871         else {
872                 return NULL;
873         }
874         
875         Py_RETURN_NONE;
876 }
877
878 /* getType */
879 const char BL_ShapeActionActuator::GetType_doc[] =
880 "getType()\n"
881 "\tReturns the operation mode of the actuator.\n";
882 PyObject* BL_ShapeActionActuator::PyGetType(PyObject* self) {
883         ShowDeprecationWarning("getType()", "the type property");
884     return Py_BuildValue("h", m_playtype);
885 }
886
887 /* setType */
888 const char BL_ShapeActionActuator::SetType_doc[] =
889 "setType(mode)\n"
890 "\t - mode: Play (0), Flipper (2), LoopStop (3), LoopEnd (4) or Property (6)\n"
891 "\tSet the operation mode of the actuator.\n";
892 PyObject* BL_ShapeActionActuator::PySetType(PyObject* self,
893                                             PyObject* args,
894                                             PyObject* kwds) {
895         ShowDeprecationWarning("setType()", "the type property");
896         short typeArg;
897                                                                                                              
898     if (!PyArg_ParseTuple(args, "h", &typeArg)) {
899         return NULL;
900     }
901
902         switch (typeArg) {
903         case ACT_ACTION_PLAY:
904         case ACT_ACTION_FLIPPER:
905         case ACT_ACTION_LOOP_STOP:
906         case ACT_ACTION_LOOP_END:
907         case ACT_ACTION_FROM_PROP:
908                 m_playtype = typeArg;
909                 break;
910         default:
911                 printf("Invalid type for action actuator: %d\n", typeArg); /* error */
912     }
913         
914     Py_Return;
915 }
916