remove unused arguments
[blender-staging.git] / source / gameengine / Converter / BL_ActionActuator.cpp
1 /*
2 * $Id$
3 *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *
20  * 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 /** \file gameengine/Converter/BL_ActionActuator.cpp
31  *  \ingroup bgeconv
32  */
33
34
35 #include "SCA_LogicManager.h"
36 #include "BL_ActionActuator.h"
37 #include "BL_ArmatureObject.h"
38 #include "BL_SkinDeformer.h"
39 #include "KX_GameObject.h"
40 #include "STR_HashedString.h"
41 #include "MEM_guardedalloc.h"
42 #include "DNA_nla_types.h"
43 #include "DNA_action_types.h"
44 #include "DNA_armature_types.h"
45 #include "DNA_scene_types.h"
46 #include "BLI_blenlib.h"
47 #include "BLI_math.h"
48 #include "BLI_utildefines.h"
49 #include "MT_Matrix4x4.h"
50
51 #include "BKE_action.h"
52 #include "FloatValue.h"
53 #include "PyObjectPlus.h"
54 #include "KX_PyMath.h"
55
56 extern "C" {
57 #include "BKE_animsys.h"
58 #include "BKE_action.h"
59 #include "RNA_access.h"
60 #include "RNA_define.h"
61 }
62
63 BL_ActionActuator::~BL_ActionActuator()
64 {
65         if (m_pose)
66                 game_free_pose(m_pose);
67         if (m_userpose)
68                 game_free_pose(m_userpose);
69         if (m_blendpose)
70                 game_free_pose(m_blendpose);
71 }
72
73 void BL_ActionActuator::ProcessReplica()
74 {
75         SCA_IActuator::ProcessReplica();
76         
77         m_pose = NULL;
78         m_blendpose = NULL;
79         m_localtime=m_startframe;
80         m_lastUpdate=-1;
81         
82 }
83
84 void BL_ActionActuator::SetBlendTime (float newtime){
85         m_blendframe = newtime;
86 }
87
88 CValue* BL_ActionActuator::GetReplica() {
89         BL_ActionActuator* replica = new BL_ActionActuator(*this);//m_float,GetName());
90         replica->ProcessReplica();
91         return replica;
92 }
93
94 bool BL_ActionActuator::ClampLocalTime()
95 {
96         if (m_startframe < m_endframe)
97         {
98                 if (m_localtime < m_startframe)
99                 {
100                         m_localtime = m_startframe;
101                         return true;
102                 } 
103                 else if (m_localtime > m_endframe)
104                 {
105                         m_localtime = m_endframe;
106                         return true;
107                 }
108         } else {
109                 if (m_localtime > m_startframe)
110                 {
111                         m_localtime = m_startframe;
112                         return true;
113                 }
114                 else if (m_localtime < m_endframe)
115                 {
116                         m_localtime = m_endframe;
117                         return true;
118                 }
119         }
120         return false;
121 }
122
123 void BL_ActionActuator::SetStartTime(float curtime)
124 {
125         float direction = m_startframe < m_endframe ? 1.0 : -1.0;
126         
127         if (!(m_flag & ACT_FLAG_REVERSE))
128                 m_starttime = curtime - direction*(m_localtime - m_startframe)/KX_KetsjiEngine::GetAnimFrameRate();
129         else
130                 m_starttime = curtime - direction*(m_endframe - m_localtime)/KX_KetsjiEngine::GetAnimFrameRate();
131 }
132
133 void BL_ActionActuator::SetLocalTime(float curtime)
134 {
135         float delta_time = (curtime - m_starttime)*KX_KetsjiEngine::GetAnimFrameRate();
136         
137         if (m_endframe < m_startframe)
138                 delta_time = -delta_time;
139
140         if (!(m_flag & ACT_FLAG_REVERSE))
141                 m_localtime = m_startframe + delta_time;
142         else
143                 m_localtime = m_endframe - delta_time;
144 }
145
146
147 bool BL_ActionActuator::Update(double curtime, bool frame)
148 {
149         bool bNegativeEvent = false;
150         bool bPositiveEvent = false;
151         bool keepgoing = true;
152         bool wrap = false;
153         bool apply=true;
154         int     priority;
155         float newweight;
156
157         curtime -= KX_KetsjiEngine::GetSuspendedDelta();
158         
159         // result = true if animation has to be continued, false if animation stops
160         // maybe there are events for us in the queue !
161         if (frame)
162         {
163                 bNegativeEvent = m_negevent;
164                 bPositiveEvent = m_posevent;
165                 RemoveAllEvents();
166                 
167                 if (bPositiveEvent)
168                         m_flag |= ACT_FLAG_ACTIVE;
169                 
170                 if (bNegativeEvent)
171                 {
172                         // dont continue where we left off when restarting
173                         if (m_end_reset) {
174                                 m_flag &= ~ACT_FLAG_LOCKINPUT;
175                         }
176                         
177                         if (!(m_flag & ACT_FLAG_ACTIVE))
178                                 return false;
179                         m_flag &= ~ACT_FLAG_ACTIVE;
180                 }
181         }
182         
183         /*      We know that action actuators have been discarded from all non armature objects:
184         if we're being called, we're attached to a BL_ArmatureObject */
185         BL_ArmatureObject *obj = (BL_ArmatureObject*)GetParent();
186         float length = m_endframe - m_startframe;
187         
188         priority = m_priority;
189         
190         /* Determine pre-incrementation behaviour and set appropriate flags */
191         switch (m_playtype){
192         case ACT_ACTION_MOTION:
193                 if (bNegativeEvent){
194                         keepgoing=false;
195                         apply=false;
196                 };
197                 break;
198         case ACT_ACTION_FROM_PROP:
199                 if (bNegativeEvent){
200                         apply=false;
201                         keepgoing=false;
202                 }
203                 break;
204         case ACT_ACTION_LOOP_END:
205                 if (bPositiveEvent){
206                         if (!(m_flag & ACT_FLAG_LOCKINPUT)){
207                                 m_flag &= ~ACT_FLAG_KEYUP;
208                                 m_flag &= ~ACT_FLAG_REVERSE;
209                                 m_flag |= ACT_FLAG_LOCKINPUT;
210                                 m_localtime = m_startframe;
211                                 m_starttime = curtime;
212                         }
213                 }
214                 if (bNegativeEvent){
215                         m_flag |= ACT_FLAG_KEYUP;
216                 }
217                 break;
218         case ACT_ACTION_LOOP_STOP:
219                 if (bPositiveEvent){
220                         if (!(m_flag & ACT_FLAG_LOCKINPUT)){
221                                 m_flag &= ~ACT_FLAG_REVERSE;
222                                 m_flag &= ~ACT_FLAG_KEYUP;
223                                 m_flag |= ACT_FLAG_LOCKINPUT;
224                                 SetStartTime(curtime);
225                         }
226                 }
227                 if (bNegativeEvent){
228                         m_flag |= ACT_FLAG_KEYUP;
229                         m_flag &= ~ACT_FLAG_LOCKINPUT;
230                         keepgoing=false;
231                         apply=false;
232                 }
233                 break;
234         case ACT_ACTION_PINGPONG:
235                 if (bPositiveEvent){
236                         if (!(m_flag & ACT_FLAG_LOCKINPUT)){
237                                 m_flag &= ~ACT_FLAG_KEYUP;
238                                 m_localtime = m_starttime;
239                                 m_starttime = curtime;
240                                 m_flag |= ACT_FLAG_LOCKINPUT;
241                         }
242                 }
243                 break;
244         case ACT_ACTION_FLIPPER:
245                 if (bPositiveEvent){
246                         if (!(m_flag & ACT_FLAG_LOCKINPUT)){
247                                 m_flag &= ~ACT_FLAG_REVERSE;
248                                 m_flag |= ACT_FLAG_LOCKINPUT;
249                                 SetStartTime(curtime);
250                         }
251                 }
252                 else if (bNegativeEvent){
253                         m_flag |= ACT_FLAG_REVERSE;
254                         m_flag &= ~ACT_FLAG_LOCKINPUT;
255                         SetStartTime(curtime);
256                 }
257                 break;
258         case ACT_ACTION_PLAY:
259                 if (bPositiveEvent){
260                         if (!(m_flag & ACT_FLAG_LOCKINPUT)){
261                                 m_flag &= ~ACT_FLAG_REVERSE;
262                                 m_localtime = m_starttime;
263                                 m_starttime = curtime;
264                                 m_flag |= ACT_FLAG_LOCKINPUT;
265                         }
266                 }
267                 break;
268         default:
269                 break;
270         }
271         
272         /* Perform increment */
273         if (keepgoing){
274                 if (m_playtype == ACT_ACTION_MOTION){
275                         MT_Point3       newpos;
276                         MT_Point3       deltapos;
277                         
278                         newpos = obj->NodeGetWorldPosition();
279                         
280                         /* Find displacement */
281                         deltapos = newpos-m_lastpos;
282                         m_localtime += (length/m_stridelength) * deltapos.length();
283                         m_lastpos = newpos;
284                 }
285                 else{
286                         SetLocalTime(curtime);
287                 }
288         }
289         
290         /* Check if a wrapping response is needed */
291         if (length){
292                 if (m_localtime < m_startframe || m_localtime > m_endframe)
293                 {
294                         m_localtime = m_startframe + fmod(m_localtime, length);
295                         wrap = true;
296                 }
297         }
298         else
299                 m_localtime = m_startframe;
300         
301         /* Perform post-increment tasks */
302         switch (m_playtype){
303         case ACT_ACTION_FROM_PROP:
304                 {
305                         CValue* propval = GetParent()->GetProperty(m_propname);
306                         if (propval)
307                                 m_localtime = propval->GetNumber();
308                         
309                         if (bNegativeEvent){
310                                 keepgoing=false;
311                         }
312                 }
313                 break;
314         case ACT_ACTION_MOTION:
315                 break;
316         case ACT_ACTION_LOOP_STOP:
317                 break;
318         case ACT_ACTION_PINGPONG:
319                 if (wrap){
320                         if (!(m_flag & ACT_FLAG_REVERSE))
321                                 m_localtime = m_endframe;
322                         else 
323                                 m_localtime = m_startframe;
324
325                         m_flag &= ~ACT_FLAG_LOCKINPUT;
326                         m_flag ^= ACT_FLAG_REVERSE; //flip direction
327                         keepgoing = false;
328                 }
329                 break;
330         case ACT_ACTION_FLIPPER:
331                 if (wrap){
332                         if (!(m_flag & ACT_FLAG_REVERSE)){
333                                 m_localtime=m_endframe;
334                                 //keepgoing = false;
335                         }
336                         else {
337                                 m_localtime=m_startframe;
338                                 keepgoing = false;
339                         }
340                 }
341                 break;
342         case ACT_ACTION_LOOP_END:
343                 if (wrap){
344                         if (m_flag & ACT_FLAG_KEYUP){
345                                 keepgoing = false;
346                                 m_localtime = m_endframe;
347                                 m_flag &= ~ACT_FLAG_LOCKINPUT;
348                         }
349                         SetStartTime(curtime);
350                 }
351                 break;
352         case ACT_ACTION_PLAY:
353                 if (wrap){
354                         m_localtime = m_endframe;
355                         keepgoing = false;
356                         m_flag &= ~ACT_FLAG_LOCKINPUT;
357                 }
358                 break;
359         default:
360                 keepgoing = false;
361                 break;
362         }
363         
364         /* Set the property if its defined */
365         if (m_framepropname[0] != '\0') {
366                 CValue* propowner = GetParent();
367                 CValue* oldprop = propowner->GetProperty(m_framepropname);
368                 CValue* newval = new CFloatValue(m_localtime);
369                 if (oldprop) {
370                         oldprop->SetValue(newval);
371                 } else {
372                         propowner->SetProperty(m_framepropname, newval);
373                 }
374                 newval->Release();
375         }
376         
377         if (bNegativeEvent)
378                 m_blendframe=0.0;
379         
380         /* Apply the pose if necessary*/
381         if (apply){
382
383                 /* Priority test */
384                 if (obj->SetActiveAction(this, priority, curtime)){
385                         
386                         /* Get the underlying pose from the armature */
387                         obj->GetPose(&m_pose);
388
389 // 2.4x function, 
390                         /* Override the necessary channels with ones from the action */
391                         // XXX extract_pose_from_action(m_pose, m_action, m_localtime);
392                         
393                         
394 // 2.5x - replacement for extract_pose_from_action(...) above.
395                         {
396                                 struct PointerRNA id_ptr;
397                                 Object *arm= obj->GetArmatureObject();
398                                 bPose *pose_back= arm->pose;
399                                 
400                                 arm->pose= m_pose;
401                                 RNA_id_pointer_create((ID *)arm, &id_ptr);
402                                 animsys_evaluate_action(&id_ptr, m_action, NULL, m_localtime);
403                                 
404                                 arm->pose= pose_back;
405                         
406 // 2.5x - could also do this but looks too high level, constraints use this, it works ok.
407 //                              Object workob; /* evaluate using workob */
408 //                              what_does_obaction(obj->GetArmatureObject(), &workob, m_pose, m_action, NULL, m_localtime);
409                         }
410
411                         // done getting the pose from the action
412                         
413                         /* Perform the user override (if any) */
414                         if (m_userpose){
415                                 extract_pose_from_pose(m_pose, m_userpose);
416                                 game_free_pose(m_userpose); //cant use MEM_freeN(m_userpose) because the channels need freeing too.
417                                 m_userpose = NULL;
418                         }
419 #if 1
420                         /* Handle blending */
421                         if (m_blendin && (m_blendframe<m_blendin)){
422                                 /* If this is the start of a blending sequence... */
423                                 if ((m_blendframe==0.0) || (!m_blendpose)){
424                                         obj->GetMRDPose(&m_blendpose);
425                                         m_blendstart = curtime;
426                                 }
427                                 
428                                 /* Find percentages */
429                                 newweight = (m_blendframe/(float)m_blendin);
430                                 game_blend_poses(m_pose, m_blendpose, 1.0 - newweight);
431
432                                 /* Increment current blending percentage */
433                                 m_blendframe = (curtime - m_blendstart)*KX_KetsjiEngine::GetAnimFrameRate();
434                                 if (m_blendframe>m_blendin)
435                                         m_blendframe = m_blendin;
436                                 
437                         }
438 #endif
439                         m_lastUpdate = m_localtime;
440                         obj->SetPose (m_pose);
441                 }
442                 else{
443                         m_blendframe = 0.0;
444                 }
445         }
446         
447         if (!keepgoing){
448                 m_blendframe = 0.0;
449         }
450         return keepgoing;
451 };
452
453 #ifdef WITH_PYTHON
454
455 /* ------------------------------------------------------------------------- */
456 /* Python functions                                                          */
457 /* ------------------------------------------------------------------------- */
458
459 PyObject* BL_ActionActuator::PyGetChannel(PyObject* value) {
460         char *string= _PyUnicode_AsString(value);
461         
462         if (!string) {
463                 PyErr_SetString(PyExc_TypeError, "expected a single string");
464                 return NULL;
465         }
466         
467         bPoseChannel *pchan;
468         
469         if(m_userpose==NULL && m_pose==NULL) {
470                 BL_ArmatureObject *obj = (BL_ArmatureObject*)GetParent();
471                 obj->GetPose(&m_pose); /* Get the underlying pose from the armature */
472         }
473         
474         // get_pose_channel accounts for NULL pose, run on both incase one exists but
475         // the channel doesnt
476         if(             !(pchan=get_pose_channel(m_userpose, string)) &&
477                         !(pchan=get_pose_channel(m_pose, string))  )
478         {
479                 PyErr_SetString(PyExc_ValueError, "channel doesnt exist");
480                 return NULL;
481         }
482
483         PyObject *ret = PyTuple_New(3);
484         
485         PyObject *list = PyList_New(3); 
486         PyList_SET_ITEM(list, 0, PyFloat_FromDouble(pchan->loc[0]));
487         PyList_SET_ITEM(list, 1, PyFloat_FromDouble(pchan->loc[1]));
488         PyList_SET_ITEM(list, 2, PyFloat_FromDouble(pchan->loc[2]));
489         PyTuple_SET_ITEM(ret, 0, list);
490         
491         list = PyList_New(3);
492         PyList_SET_ITEM(list, 0, PyFloat_FromDouble(pchan->size[0]));
493         PyList_SET_ITEM(list, 1, PyFloat_FromDouble(pchan->size[1]));
494         PyList_SET_ITEM(list, 2, PyFloat_FromDouble(pchan->size[2]));
495         PyTuple_SET_ITEM(ret, 1, list);
496         
497         list = PyList_New(4);
498         PyList_SET_ITEM(list, 0, PyFloat_FromDouble(pchan->quat[0]));
499         PyList_SET_ITEM(list, 1, PyFloat_FromDouble(pchan->quat[1]));
500         PyList_SET_ITEM(list, 2, PyFloat_FromDouble(pchan->quat[2]));
501         PyList_SET_ITEM(list, 3, PyFloat_FromDouble(pchan->quat[3]));
502         PyTuple_SET_ITEM(ret, 2, list);
503
504         return ret;
505 /*
506         return Py_BuildValue("([fff][fff][ffff])",
507                 pchan->loc[0], pchan->loc[1], pchan->loc[2],
508                 pchan->size[0], pchan->size[1], pchan->size[2],
509                 pchan->quat[0], pchan->quat[1], pchan->quat[2], pchan->quat[3] );
510 */
511 }
512
513 /*     setChannel                                                         */
514 KX_PYMETHODDEF_DOC(BL_ActionActuator, setChannel,
515 "setChannel(channel, matrix)\n"
516 "\t - channel   : A string specifying the name of the bone channel.\n"
517 "\t - matrix    : A 4x4 matrix specifying the overriding transformation\n"
518 "\t               as an offset from the bone's rest position.\n")
519 {
520         BL_ArmatureObject *obj = (BL_ArmatureObject*)GetParent();
521         char *string;
522         PyObject *pymat= NULL;
523         PyObject *pyloc= NULL, *pysize= NULL, *pyquat= NULL;
524         bPoseChannel *pchan;
525         
526         if(PyTuple_Size(args)==2) {
527                 if (!PyArg_ParseTuple(args,"sO:setChannel", &string, &pymat)) // matrix
528                         return NULL;
529         }
530         else if(PyTuple_Size(args)==4) {
531                 if (!PyArg_ParseTuple(args,"sOOO:setChannel", &string, &pyloc, &pysize, &pyquat)) // loc/size/quat
532                         return NULL;
533         }
534         else {
535                 PyErr_SetString(PyExc_ValueError, "Expected a string and a 4x4 matrix (2 args) or a string and loc/size/quat sequences (4 args)");
536                 return NULL;
537         }
538         
539         if(pymat) {
540                 float matrix[4][4];
541                 MT_Matrix4x4 mat;
542                 
543                 if(!PyMatTo(pymat, mat))
544                         return NULL;
545                 
546                 mat.getValue((float*)matrix);
547                 
548                 BL_ArmatureObject *obj = (BL_ArmatureObject*)GetParent();
549                 
550                 if (!m_userpose) {
551                         if(!m_pose)
552                                 obj->GetPose(&m_pose); /* Get the underlying pose from the armature */
553                         game_copy_pose(&m_userpose, m_pose, 0);
554                 }
555                 // pchan= verify_pose_channel(m_userpose, string); // adds the channel if its not there.
556                 pchan= get_pose_channel(m_userpose, string); // adds the channel if its not there.
557                 
558                 if(pchan) {
559                         VECCOPY (pchan->loc, matrix[3]);
560                         mat4_to_size( pchan->size,matrix);
561                         mat4_to_quat( pchan->quat,matrix);
562                 }
563         }
564         else {
565                 MT_Vector3 loc;
566                 MT_Vector3 size;
567                 MT_Quaternion quat;
568                 
569                 if (!PyVecTo(pyloc, loc) || !PyVecTo(pysize, size) || !PyQuatTo(pyquat, quat))
570                         return NULL;
571                 
572                 // same as above
573                 if (!m_userpose) {
574                         if(!m_pose)
575                                 obj->GetPose(&m_pose); /* Get the underlying pose from the armature */
576                         game_copy_pose(&m_userpose, m_pose, 0);
577                 }
578                 // pchan= verify_pose_channel(m_userpose, string);
579                 pchan= get_pose_channel(m_userpose, string); // adds the channel if its not there.
580                 
581                 // for some reason loc.setValue(pchan->loc) fails
582                 if(pchan) {
583                         pchan->loc[0]= loc[0]; pchan->loc[1]= loc[1]; pchan->loc[2]= loc[2];
584                         pchan->size[0]= size[0]; pchan->size[1]= size[1]; pchan->size[2]= size[2];
585                         pchan->quat[0]= quat[3]; pchan->quat[1]= quat[0]; pchan->quat[2]= quat[1]; pchan->quat[3]= quat[2]; /* notice xyzw -> wxyz is intentional */
586                 }
587         }
588         
589         if(pchan==NULL) {
590                 PyErr_SetString(PyExc_ValueError, "Channel could not be found, use the 'channelNames' attribute to get a list of valid channels");
591                 return NULL;
592         }
593         
594         Py_RETURN_NONE;
595 }
596
597 /* ------------------------------------------------------------------------- */
598 /* Python Integration Hooks                                                                      */
599 /* ------------------------------------------------------------------------- */
600
601 PyTypeObject BL_ActionActuator::Type = {
602         PyVarObject_HEAD_INIT(NULL, 0)
603         "BL_ActionActuator",
604         sizeof(PyObjectPlus_Proxy),
605         0,
606         py_base_dealloc,
607         0,
608         0,
609         0,
610         0,
611         py_base_repr,
612         0,0,0,0,0,0,0,0,0,
613         Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
614         0,0,0,0,0,0,0,
615         Methods,
616         0,
617         0,
618         &SCA_IActuator::Type,
619         0,0,0,0,0,0,
620         py_base_new
621 };
622
623 PyMethodDef BL_ActionActuator::Methods[] = {
624         {"getChannel", (PyCFunction) BL_ActionActuator::sPyGetChannel, METH_O},
625         KX_PYMETHODTABLE(BL_ActionActuator, setChannel),
626         {NULL,NULL} //Sentinel
627 };
628
629 PyAttributeDef BL_ActionActuator::Attributes[] = {
630         KX_PYATTRIBUTE_FLOAT_RW("frameStart", 0, MAXFRAMEF, BL_ActionActuator, m_startframe),
631         KX_PYATTRIBUTE_FLOAT_RW("frameEnd", 0, MAXFRAMEF, BL_ActionActuator, m_endframe),
632         KX_PYATTRIBUTE_FLOAT_RW("blendIn", 0, MAXFRAMEF, BL_ActionActuator, m_blendin),
633         KX_PYATTRIBUTE_RW_FUNCTION("action", BL_ActionActuator, pyattr_get_action, pyattr_set_action),
634         KX_PYATTRIBUTE_RO_FUNCTION("channelNames", BL_ActionActuator, pyattr_get_channel_names),
635         KX_PYATTRIBUTE_SHORT_RW("priority", 0, 100, false, BL_ActionActuator, m_priority),
636         KX_PYATTRIBUTE_FLOAT_RW_CHECK("frame", 0, MAXFRAMEF, BL_ActionActuator, m_localtime, CheckFrame),
637         KX_PYATTRIBUTE_STRING_RW("propName", 0, 31, false, BL_ActionActuator, m_propname),
638         KX_PYATTRIBUTE_STRING_RW("framePropName", 0, 31, false, BL_ActionActuator, m_framepropname),
639         KX_PYATTRIBUTE_BOOL_RW("useContinue", BL_ActionActuator, m_end_reset),
640         KX_PYATTRIBUTE_FLOAT_RW_CHECK("blendTime", 0, MAXFRAMEF, BL_ActionActuator, m_blendframe, CheckBlendTime),
641         KX_PYATTRIBUTE_SHORT_RW_CHECK("mode",0,100,false,BL_ActionActuator,m_playtype,CheckType),
642         { NULL }        //Sentinel
643 };
644
645 PyObject* BL_ActionActuator::pyattr_get_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
646 {
647         BL_ActionActuator* self= static_cast<BL_ActionActuator*>(self_v);
648         return PyUnicode_FromString(self->GetAction() ? self->GetAction()->id.name+2 : "");
649 }
650
651 int BL_ActionActuator::pyattr_set_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
652 {
653         BL_ActionActuator* self= static_cast<BL_ActionActuator*>(self_v);
654         
655         if (!PyUnicode_Check(value))
656         {
657                 PyErr_SetString(PyExc_ValueError, "actuator.action = val: Action Actuator, expected the string name of the action");
658                 return PY_SET_ATTR_FAIL;
659         }
660
661         bAction *action= NULL;
662         STR_String val = _PyUnicode_AsString(value);
663         
664         if (val != "")
665         {
666                 action= (bAction*)SCA_ILogicBrick::m_sCurrentLogicManager->GetActionByName(val);
667                 if (!action)
668                 {
669                         PyErr_SetString(PyExc_ValueError, "actuator.action = val: Action Actuator, action not found!");
670                         return PY_SET_ATTR_FAIL;
671                 }
672         }
673         
674         self->SetAction(action);
675         return PY_SET_ATTR_SUCCESS;
676
677 }
678
679 PyObject* BL_ActionActuator::pyattr_get_channel_names(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
680 {
681         BL_ActionActuator* self= static_cast<BL_ActionActuator*>(self_v);
682         PyObject *ret= PyList_New(0);
683         PyObject *item;
684         
685         bPose *pose= ((BL_ArmatureObject*)self->GetParent())->GetOrigPose();
686         
687         if(pose) {
688                 bPoseChannel *pchan;
689                 for(pchan= (bPoseChannel *)pose->chanbase.first; pchan; pchan= (bPoseChannel *)pchan->next) {
690                         item= PyUnicode_FromString(pchan->name);
691                         PyList_Append(ret, item);
692                         Py_DECREF(item);
693                 }
694         }
695         
696         return ret;
697 }
698
699 #endif // WITH_PYTHON