b9e41d553b33075a6bc0e7e27b37f9c7eceff69f
[blender.git] / source / gameengine / Converter / KX_ConvertActuators.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 * Convert Blender actuators for use in the GameEngine
29 */
30
31 /** \file gameengine/Converter/KX_ConvertActuators.cpp
32  *  \ingroup bgeconv
33  */
34
35
36 #if defined(WIN32) && !defined(FREE_WINDOWS)
37 #pragma warning (disable : 4786) 
38 #endif //WIN32
39
40 #include "MEM_guardedalloc.h"
41
42 #include "KX_BlenderSceneConverter.h"
43 #include "KX_ConvertActuators.h"
44 #include "AUD_C-API.h"
45 // Actuators
46 //SCA logiclibrary native logicbricks
47 #include "SCA_PropertyActuator.h"
48 #include "SCA_LogicManager.h"
49 #include "SCA_RandomActuator.h"
50 #include "SCA_2DFilterActuator.h"
51
52 // Ketsji specific logicbricks
53 #include "KX_SceneActuator.h"
54 #include "KX_IpoActuator.h"
55 #include "KX_SoundActuator.h"
56 #include "KX_ObjectActuator.h"
57 #include "KX_TrackToActuator.h"
58 #include "KX_ConstraintActuator.h"
59 #include "KX_CameraActuator.h"
60 #include "KX_GameActuator.h"
61 #include "KX_StateActuator.h"
62 #include "KX_VisibilityActuator.h"
63 #include "KX_SCA_AddObjectActuator.h"
64 #include "KX_SCA_EndObjectActuator.h"
65 #include "KX_SCA_ReplaceMeshActuator.h"
66 #include "KX_ParentActuator.h"
67 #include "KX_SCA_DynamicActuator.h"
68
69 #include "KX_Scene.h"
70 #include "KX_KetsjiEngine.h"
71
72 #include "IntValue.h"
73 #include "KX_GameObject.h"
74
75 /* This little block needed for linking to Blender... */
76 #include "BKE_text.h"
77 #include "BLI_blenlib.h"
78
79 #define FILE_MAX 240 // repeated here to avoid dependency from BKE_utildefines.h
80
81 #include "KX_NetworkMessageActuator.h"
82
83 #ifdef WIN32
84 #include "BLI_winstuff.h"
85 #endif
86
87 #include "DNA_object_types.h"
88 #include "DNA_sound_types.h"
89 #include "DNA_scene_types.h"
90 #include "DNA_actuator_types.h"
91 #include "DNA_packedFile_types.h"
92 #include "BL_ActionActuator.h"
93 #include "BL_ShapeActionActuator.h"
94 #include "BL_ArmatureActuator.h"
95 /* end of blender include block */
96
97 #include "BL_BlenderDataConversion.h"
98
99 /** 
100 KX_BLENDERTRUNC needed to round 'almost' zero values to zero, else velocities etc. are incorrectly set 
101 */
102
103 #define KX_BLENDERTRUNC(x)  (( x < 0.0001 && x > -0.0001 )  ? 0.0 : x)
104
105 void BL_ConvertActuators(char* maggiename,
106                                                  struct Object* blenderobject,
107                                                  KX_GameObject* gameobj,
108                                                  SCA_LogicManager* logicmgr,
109                                                  KX_Scene* scene,
110                                                  KX_KetsjiEngine* ketsjiEngine,
111                                                  int activeLayerBitInfo,
112                                                  bool isInActiveLayer,
113                                                  RAS_IRenderTools* rendertools,
114                                                  KX_BlenderSceneConverter* converter
115                                                  )
116 {
117         
118         int uniqueint = 0;
119         int actcount = 0;
120         int executePriority = 0;
121         bActuator* bact = (bActuator*) blenderobject->actuators.first;
122         while (bact)
123         {
124                 actcount++;
125                 bact = bact->next;
126         }
127         gameobj->ReserveActuator(actcount);
128         bact = (bActuator*) blenderobject->actuators.first;
129         while(bact)
130         {
131                 STR_String uniquename = bact->name;
132                 STR_String& objectname = gameobj->GetName();
133                 
134                 SCA_IActuator* baseact = NULL;
135                 switch (bact->type)
136                 {
137                 case ACT_OBJECT:
138                         {
139                                 bObjectActuator* obact = (bObjectActuator*) bact->data;
140                                 KX_GameObject* obref = NULL;
141                                 MT_Vector3 forcevec(KX_BLENDERTRUNC(obact->forceloc[0]),
142                                         KX_BLENDERTRUNC(obact->forceloc[1]),
143                                         KX_BLENDERTRUNC(obact->forceloc[2]));
144                                 MT_Vector3 torquevec(obact->forcerot[0],obact->forcerot[1],obact->forcerot[2]);
145                                 MT_Vector3 dlocvec ( KX_BLENDERTRUNC(obact->dloc[0]),
146                                         KX_BLENDERTRUNC(obact->dloc[1]),
147                                         KX_BLENDERTRUNC(obact->dloc[2]));
148                                 MT_Vector3 drotvec ( KX_BLENDERTRUNC(obact->drot[0]),obact->drot[1],obact->drot[2]);
149                                 MT_Vector3 linvelvec ( KX_BLENDERTRUNC(obact->linearvelocity[0]),
150                                         KX_BLENDERTRUNC(obact->linearvelocity[1]),
151                                         KX_BLENDERTRUNC(obact->linearvelocity[2]));
152                                 MT_Vector3 angvelvec ( KX_BLENDERTRUNC(obact->angularvelocity[0]),
153                                         KX_BLENDERTRUNC(obact->angularvelocity[1]),
154                                         KX_BLENDERTRUNC(obact->angularvelocity[2]));
155                                 short damping = obact->damping;
156                                 
157                                 /* Blender uses a bit vector internally for the local-flags. In */
158                                 /* KX, we have four bools. The compiler should be smart enough  */
159                                 /* to do the right thing. We need to explicitly convert here!   */
160                                 
161                                 KX_LocalFlags bitLocalFlag;
162                                 
163                                 bitLocalFlag.Force = bool((obact->flag & ACT_FORCE_LOCAL)!=0);
164                                 bitLocalFlag.Torque = bool((obact->flag & ACT_TORQUE_LOCAL) !=0);//rlocal;
165                                 bitLocalFlag.DLoc = bool((obact->flag & ACT_DLOC_LOCAL)!=0);
166                                 bitLocalFlag.DRot = bool((obact->flag & ACT_DROT_LOCAL)!=0);
167                                 bitLocalFlag.LinearVelocity = bool((obact->flag & ACT_LIN_VEL_LOCAL)!=0);
168                                 bitLocalFlag.AngularVelocity = bool((obact->flag & ACT_ANG_VEL_LOCAL)!=0);
169                                 bitLocalFlag.ServoControl = bool(obact->type == ACT_OBJECT_SERVO);
170                                 bitLocalFlag.AddOrSetLinV = bool((obact->flag & ACT_ADD_LIN_VEL)!=0);
171                                 if (obact->reference && bitLocalFlag.ServoControl)
172                                 {
173                                         obref = converter->FindGameObject(obact->reference);
174                                 }
175                                 
176                                 KX_ObjectActuator* tmpbaseact = new KX_ObjectActuator(gameobj,
177                                         obref,
178                                         forcevec.getValue(),
179                                         torquevec.getValue(),
180                                         dlocvec.getValue(),
181                                         drotvec.getValue(),
182                                         linvelvec.getValue(),
183                                         angvelvec.getValue(),
184                                         damping,
185                                         bitLocalFlag
186                                         );
187                                 baseact = tmpbaseact;
188                                 break;
189                         }
190                 case ACT_ACTION:
191                         {
192                                 if (blenderobject->type==OB_ARMATURE){
193                                         bActionActuator* actact = (bActionActuator*) bact->data;
194                                         STR_String propname = (actact->name ? actact->name : "");
195                                         STR_String propframe = (actact->frameProp ? actact->frameProp : "");
196                                         
197                                         BL_ActionActuator* tmpbaseact = new BL_ActionActuator(
198                                                 gameobj,
199                                                 propname,
200                                                 propframe,
201                                                 actact->sta,
202                                                 actact->end,
203                                                 actact->act,
204                                                 actact->type, // + 1, because Blender starts to count at zero,
205                                                 actact->blendin,
206                                                 actact->priority,
207                                                 actact->end_reset,
208                                                 actact->stridelength
209                                                 // Ketsji at 1, because zero is reserved for "NoDef"
210                                                 );
211                                         baseact= tmpbaseact;
212                                         break;
213                                 }
214                                 else
215                                         printf ("Discarded action actuator from non-armature object [%s]\n", blenderobject->id.name+2);
216                         }
217                 case ACT_SHAPEACTION:
218                         {
219                                 if (blenderobject->type==OB_MESH){
220                                         bActionActuator* actact = (bActionActuator*) bact->data;
221                                         STR_String propname = (actact->name ? actact->name : "");
222                                         STR_String propframe = (actact->frameProp ? actact->frameProp : "");
223                                         
224                                         BL_ShapeActionActuator* tmpbaseact = new BL_ShapeActionActuator(
225                                                 gameobj,
226                                                 propname,
227                                                 propframe,
228                                                 actact->sta,
229                                                 actact->end,
230                                                 actact->act,
231                                                 actact->type, // + 1, because Blender starts to count at zero,
232                                                 actact->blendin,
233                                                 actact->priority,
234                                                 actact->stridelength
235                                                 // Ketsji at 1, because zero is reserved for "NoDef"
236                                                 );
237                                         baseact= tmpbaseact;
238                                         break;
239                                 }
240                                 else
241                                         printf ("Discarded shape action actuator from non-mesh object [%s]\n", blenderobject->id.name+2);
242                         }
243                 case ACT_IPO:
244                         {
245                                 bIpoActuator* ipoact = (bIpoActuator*) bact->data;
246                                 bool ipochild = (ipoact->flag & ACT_IPOCHILD) !=0;
247                                 STR_String propname = ipoact->name;
248                                 STR_String frameProp = ipoact->frameProp;
249                                 // first bit?
250                                 bool ipo_as_force = (ipoact->flag & ACT_IPOFORCE);
251                                 bool local = (ipoact->flag & ACT_IPOLOCAL);
252                                 bool ipo_add = (ipoact->flag & ACT_IPOADD);
253                                 
254                                 KX_IpoActuator* tmpbaseact = new KX_IpoActuator(
255                                         gameobj,
256                                         propname ,
257                                         frameProp,
258                                         ipoact->sta,
259                                         ipoact->end,
260                                         ipochild,
261                                         ipoact->type + 1, // + 1, because Blender starts to count at zero,
262                                         // Ketsji at 1, because zero is reserved for "NoDef"
263                                         ipo_as_force,
264                                         ipo_add,
265                                         local);
266                                 baseact = tmpbaseact;
267                                 break;
268                         }
269                 case ACT_LAMP:
270                         {
271                                 break;
272                         }
273                 case ACT_CAMERA:
274                         {
275                                 bCameraActuator *camact = (bCameraActuator *) bact->data;
276                                 if (camact->ob) {
277                                         KX_GameObject *tmpgob = converter->FindGameObject(camact->ob);
278                                         
279                                         /* visifac, fac and axis are not copied from the struct...   */ 
280                                         /* that's some internal state...                             */
281                                         KX_CameraActuator *tmpcamact
282                                                 = new KX_CameraActuator(gameobj,
283                                                 tmpgob,
284                                                 camact->height,
285                                                 camact->min,
286                                                 camact->max,
287                                                 camact->axis=='x');
288                                         baseact = tmpcamact;
289                                 }
290                                 break;
291                         }
292                 case ACT_MESSAGE:
293                         {
294                                 bMessageActuator *msgAct = (bMessageActuator *) bact->data;
295                                 
296                                 /**
297                                 * Get the name of the properties that objects must own that
298                                 * we're sending to, if present
299                                 */
300                                 STR_String toPropName = (msgAct->toPropName
301                                         ? (char*) msgAct->toPropName
302                                         : "");
303                                 
304                                 /**
305                                 * Get the Message Subject to send.
306                                 */
307                                 STR_String subject = (msgAct->subject
308                                         ? (char*) msgAct->subject
309                                         : "");
310                                 
311                                 /**
312                                 * Get the bodyType
313                                 */
314                                 int bodyType = msgAct->bodyType;
315                                 
316                                 /**
317                                 * Get the body (text message or property name whose value
318                                 * we'll be sending, might be empty
319                                 */
320                                 STR_String body = (msgAct->body
321                                         ? (char*) msgAct->body
322                                         : "");
323                                 
324                                 KX_NetworkMessageActuator *tmpmsgact = 
325                                         new KX_NetworkMessageActuator(
326                                         gameobj,                                        // actuator controlling object
327                                         scene->GetNetworkScene(),       // needed for replication
328                                         toPropName,
329                                         subject,
330                                         bodyType,
331                                         body);
332                                 baseact = tmpmsgact;
333                                 break;
334                         }
335                 case ACT_MATERIAL:
336                         {
337                                 break;
338                         }
339                 case ACT_SOUND:
340                         {
341                                 bSoundActuator* soundact = (bSoundActuator*) bact->data;
342                                 /* get type, and possibly a start and end frame */
343                                 KX_SoundActuator::KX_SOUNDACT_TYPE
344                                         soundActuatorType = KX_SoundActuator::KX_SOUNDACT_NODEF;
345                                 
346                                 switch(soundact->type) {
347                                 case ACT_SND_PLAY_STOP_SOUND:
348                                         soundActuatorType = KX_SoundActuator::KX_SOUNDACT_PLAYSTOP;
349                                         break;
350                                 case ACT_SND_PLAY_END_SOUND:
351                                         soundActuatorType = KX_SoundActuator::KX_SOUNDACT_PLAYEND;
352                                         break;
353                                 case ACT_SND_LOOP_STOP_SOUND:
354                                         soundActuatorType = KX_SoundActuator::KX_SOUNDACT_LOOPSTOP;
355                                         break;
356                                 case ACT_SND_LOOP_END_SOUND:
357                                         soundActuatorType = KX_SoundActuator::KX_SOUNDACT_LOOPEND;
358                                         break;
359                                 case ACT_SND_LOOP_BIDIRECTIONAL_SOUND:
360                                         soundActuatorType = KX_SoundActuator::KX_SOUNDACT_LOOPBIDIRECTIONAL;
361                                         break;
362                                 case ACT_SND_LOOP_BIDIRECTIONAL_STOP_SOUND:
363                                         soundActuatorType = KX_SoundActuator::KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP;
364                                         break;
365                                         
366                                 default:
367                                         /* This is an error!!! */
368                                         soundActuatorType = KX_SoundActuator::KX_SOUNDACT_NODEF;
369                                 }
370                                 
371                                 if (soundActuatorType != KX_SoundActuator::KX_SOUNDACT_NODEF) 
372                                 {
373                                         bSound* sound = soundact->sound;
374                                         bool is3d = soundact->flag & ACT_SND_3D_SOUND ? true : false;
375                                         AUD_Sound* snd_sound = NULL;
376                                         KX_3DSoundSettings settings;
377                                         settings.cone_inner_angle = soundact->sound3D.cone_inner_angle;
378                                         settings.cone_outer_angle = soundact->sound3D.cone_outer_angle;
379                                         settings.cone_outer_gain = soundact->sound3D.cone_outer_gain;
380                                         settings.max_distance = soundact->sound3D.max_distance;
381                                         settings.max_gain = soundact->sound3D.max_gain;
382                                         settings.min_gain = soundact->sound3D.min_gain;
383                                         settings.reference_distance = soundact->sound3D.reference_distance;
384                                         settings.rolloff_factor = soundact->sound3D.rolloff_factor;
385
386                                         if(!sound)
387                                         {
388                                                 std::cout <<    "WARNING: Sound actuator \"" << bact->name <<
389                                                                                 "\" from object \"" <<  blenderobject->id.name+2 <<
390                                                                                 "\" has no sound datablock." << std::endl;
391                                         }
392                                         else
393                                                 snd_sound = sound->playback_handle;
394                                         KX_SoundActuator* tmpsoundact =
395                                                 new KX_SoundActuator(gameobj,
396                                                 snd_sound,
397                                                 soundact->volume,
398                                                 exp((soundact->pitch / 12.0) * log(2.0)),
399                                                 is3d,
400                                                 settings,
401                                                 soundActuatorType);
402
403                                         tmpsoundact->SetName(bact->name);
404                                         baseact = tmpsoundact;
405                                 }
406                                 break;
407                         }
408                 case ACT_PROPERTY:
409                         {
410                                 bPropertyActuator* propact = (bPropertyActuator*) bact->data;
411                                 SCA_IObject* destinationObj = NULL;
412                                 
413                                 /*
414                                 here the destinationobject is searched. problem with multiple scenes: other scenes
415                                 have not been converted yet, so the destobj will not be found, so the prop will
416                                 not be copied.
417                                 possible solutions:
418                                 - convert everything when possible and not realtime only when needed.
419                                 - let the object-with-property report itself to the act when converted
420                                 */
421                                 if (propact->ob)
422                                         destinationObj = converter->FindGameObject(propact->ob);
423                                 
424                                 SCA_PropertyActuator* tmppropact = new SCA_PropertyActuator(
425                                         gameobj,
426                                         destinationObj,
427                                         propact->name,
428                                         propact->value,
429                                         propact->type+1); // + 1 because Ketsji Logic starts
430                                 // with 0 for KX_ACT_PROP_NODEF
431                                 baseact = tmppropact;
432                                 break;
433                         }
434                 case ACT_EDIT_OBJECT:
435                         {
436                                 bEditObjectActuator *editobact 
437                                         = (bEditObjectActuator *) bact->data;
438                                 /* There are four different kinds of 'edit object' thingies  */
439                                 /* The alternative to this lengthy conversion is packing     */
440                                 /* several actuators in one, which is not very nice design.. */
441                                 switch (editobact->type) {
442                                 case ACT_EDOB_ADD_OBJECT: 
443                                         {
444                                                 
445                                                 // does the 'original' for replication exists, and 
446                                                 // is it in a non-active layer ?
447                                                 SCA_IObject* originalval = NULL;
448                                                 if (editobact->ob)
449                                                 {
450                                                         if (editobact->ob->lay & activeLayerBitInfo)
451                                                         {
452                                                                 fprintf(stderr, "Warning, object \"%s\" from AddObject actuator \"%s\" is not in a hidden layer.\n", objectname.Ptr(), uniquename.Ptr());
453                                                         }
454                                                         else {
455                                                                 originalval = converter->FindGameObject(editobact->ob);
456                                                         }
457                                                 }
458                                                 
459                                                 KX_SCA_AddObjectActuator* tmpaddact = 
460                                                         new KX_SCA_AddObjectActuator(
461                                                                 gameobj, 
462                                                                 originalval,
463                                                                 editobact->time,
464                                                                 scene,
465                                                                 editobact->linVelocity,
466                                                                 (editobact->localflag & ACT_EDOB_LOCAL_LINV)!=0,
467                                                                 editobact->angVelocity,
468                                                                 (editobact->localflag & ACT_EDOB_LOCAL_ANGV)!=0
469                                                                 );
470                                                                 
471                                                                 //editobact->ob to gameobj
472                                                                 baseact = tmpaddact;
473                                         }
474                                         break;
475                                 case ACT_EDOB_END_OBJECT:
476                                         {
477                                                 KX_SCA_EndObjectActuator* tmpendact 
478                                                         = new KX_SCA_EndObjectActuator(gameobj,scene);
479                                                 baseact = tmpendact;
480                                         }
481                                         break;
482                                 case ACT_EDOB_REPLACE_MESH:
483                                         {
484                                                 RAS_MeshObject *tmpmesh = NULL;
485                                                 if (editobact->me)
486                                                         tmpmesh = BL_ConvertMesh(
487                                                                 editobact->me,
488                                                                 blenderobject,
489                                                                 scene,
490                                                                 converter
491                                                                 );
492
493                                                 KX_SCA_ReplaceMeshActuator* tmpreplaceact
494                                                         = new KX_SCA_ReplaceMeshActuator(
495                                                                 gameobj,
496                                                                 tmpmesh,
497                                                                 scene,
498                                                                 (editobact->flag & ACT_EDOB_REPLACE_MESH_NOGFX)==0,
499                                                                 (editobact->flag & ACT_EDOB_REPLACE_MESH_PHYS)!=0
500                                                                 
501                                                                 );
502                                                         
503                                                         baseact = tmpreplaceact;
504                                         }
505                                         break;
506                                 case ACT_EDOB_TRACK_TO:
507                                         {
508                                                 SCA_IObject* originalval = NULL;
509                                                 if (editobact->ob)
510                                                         originalval = converter->FindGameObject(editobact->ob);
511                                                         
512                                                 KX_TrackToActuator* tmptrackact 
513                                                         = new KX_TrackToActuator(gameobj, 
514                                                                 originalval,
515                                                                 editobact->time,
516                                                                 editobact->flag,
517                                                                 blenderobject->trackflag,
518                                                                 blenderobject->upflag
519                                                                 );
520                                                         baseact = tmptrackact;
521                                                 break;
522                                         }
523                                 case ACT_EDOB_DYNAMICS:
524                                         {
525                                                 KX_SCA_DynamicActuator* tmpdynact 
526                                                         = new KX_SCA_DynamicActuator(gameobj, 
527                                                                 editobact->dyn_operation,
528                                                                 editobact->mass
529                                                                 );
530                                                         baseact = tmpdynact;
531                                         }
532                                 }
533                                 break;
534                         }
535                 case ACT_CONSTRAINT:
536                         {
537                                 float min = 0.0, max = 0.0;
538                                 char *prop = NULL;
539                                 KX_ConstraintActuator::KX_CONSTRAINTTYPE locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_NODEF;
540                                 bConstraintActuator *conact 
541                                         = (bConstraintActuator*) bact->data;
542                                 /* convert settings... degrees in the ui become radians  */ 
543                                 /* internally                                            */ 
544                                 if (conact->type == ACT_CONST_TYPE_ORI) {
545                                         min = (MT_2_PI * conact->minloc[0])/360.0;
546                                         max = (MT_2_PI * conact->maxloc[0])/360.0;
547                                         switch (conact->mode) {
548                                         case ACT_CONST_DIRPX:
549                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ORIX;
550                                                 break;
551                                         case ACT_CONST_DIRPY:
552                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ORIY;
553                                                 break;
554                                         case ACT_CONST_DIRPZ:
555                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ORIZ;
556                                                 break;
557                                         }
558                                 } else if (conact->type == ACT_CONST_TYPE_DIST) {
559                                         switch (conact->mode) {
560                                         case ACT_CONST_DIRPX:
561                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRPX;
562                                                 min = conact->minloc[0];
563                                                 max = conact->maxloc[0];
564                                                 break;
565                                         case ACT_CONST_DIRPY:
566                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRPY;
567                                                 min = conact->minloc[1];
568                                                 max = conact->maxloc[1];
569                                                 break;
570                                         case ACT_CONST_DIRPZ:
571                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRPZ;
572                                                 min = conact->minloc[2];
573                                                 max = conact->maxloc[2];
574                                                 break;
575                                         case ACT_CONST_DIRNX:
576                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRNX;
577                                                 min = conact->minloc[0];
578                                                 max = conact->maxloc[0];
579                                                 break;
580                                         case ACT_CONST_DIRNY:
581                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRNY;
582                                                 min = conact->minloc[1];
583                                                 max = conact->maxloc[1];
584                                                 break;
585                                         case ACT_CONST_DIRNZ:
586                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRNZ;
587                                                 min = conact->minloc[2];
588                                                 max = conact->maxloc[2];
589                                                 break;
590                                         }
591                                         prop = conact->matprop;
592                                 } else if (conact->type == ACT_CONST_TYPE_FH) {
593                                         switch (conact->mode) {
594                                         case ACT_CONST_DIRPX:
595                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHPX;
596                                                 min = conact->minloc[0];
597                                                 max = conact->maxloc[0];
598                                                 break;
599                                         case ACT_CONST_DIRPY:
600                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHPY;
601                                                 min = conact->minloc[1];
602                                                 max = conact->maxloc[1];
603                                                 break;
604                                         case ACT_CONST_DIRPZ:
605                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHPZ;
606                                                 min = conact->minloc[2];
607                                                 max = conact->maxloc[2];
608                                                 break;
609                                         case ACT_CONST_DIRNX:
610                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHNX;
611                                                 min = conact->minloc[0];
612                                                 max = conact->maxloc[0];
613                                                 break;
614                                         case ACT_CONST_DIRNY:
615                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHNY;
616                                                 min = conact->minloc[1];
617                                                 max = conact->maxloc[1];
618                                                 break;
619                                         case ACT_CONST_DIRNZ:
620                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHNZ;
621                                                 min = conact->minloc[2];
622                                                 max = conact->maxloc[2];
623                                                 break;
624                                         }
625                                         prop = conact->matprop;
626                                 } else {
627                                         switch (conact->flag) {
628                                         case ACT_CONST_LOCX:
629                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_LOCX; 
630                                                 min = conact->minloc[0];
631                                                 max = conact->maxloc[0];
632                                                 break;
633                                         case ACT_CONST_LOCY:
634                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_LOCY; 
635                                                 min = conact->minloc[1];
636                                                 max = conact->maxloc[1];
637                                                 break;
638                                         case ACT_CONST_LOCZ:
639                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_LOCZ;
640                                                 min = conact->minloc[2];
641                                                 max = conact->maxloc[2];
642                                                 break;
643                                         case ACT_CONST_ROTX:
644                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ROTX;
645                                                 min = MT_2_PI * conact->minrot[0] / 360.0;
646                                                 max = MT_2_PI * conact->maxrot[0] / 360.0;
647                                                 break;
648                                         case ACT_CONST_ROTY:
649                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ROTY;
650                                                 min = MT_2_PI * conact->minrot[1] / 360.0;
651                                                 max = MT_2_PI * conact->maxrot[1] / 360.0;
652                                                 break;
653                                         case ACT_CONST_ROTZ:
654                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ROTZ;
655                                                 min = MT_2_PI * conact->minrot[2] / 360.0;
656                                                 max = MT_2_PI * conact->maxrot[2] / 360.0;
657                                                 break;
658                                         default:
659                                                 ; /* error */ 
660                                         }
661                                 }
662                                 KX_ConstraintActuator *tmpconact 
663                                         = new KX_ConstraintActuator(gameobj,
664                                                 conact->damp,
665                                                 conact->rotdamp,
666                                                 min,
667                                                 max,
668                                                 conact->maxrot,
669                                                 locrot,
670                                                 conact->time,
671                                                 conact->flag,
672                                                 prop);
673                                 baseact = tmpconact;
674                                 break;
675                         }
676                 case ACT_GROUP:
677                         {
678                                 // deprecated
679                         }
680                         break;
681                 case ACT_SCENE:
682                         {
683                                 bSceneActuator *sceneact = (bSceneActuator *) bact->data;
684                                 STR_String nextSceneName("");
685                                 
686                                 KX_SceneActuator* tmpsceneact;
687                                 int mode = KX_SceneActuator::KX_SCENE_NODEF;
688                                 KX_Camera *cam = NULL;
689                                 //KX_Scene* scene = NULL;
690                                 switch (sceneact->type)
691                                 {
692                                 case ACT_SCENE_RESUME:
693                                 case ACT_SCENE_SUSPEND:
694                                 case ACT_SCENE_ADD_FRONT:
695                                 case ACT_SCENE_ADD_BACK:
696                                 case ACT_SCENE_REMOVE:
697                                 case ACT_SCENE_SET:
698                                         {
699                                                 switch (sceneact->type)
700                                                 {
701                                                 case ACT_SCENE_RESUME:
702                                                         mode = KX_SceneActuator::KX_SCENE_RESUME;
703                                                         break;
704                                                 case ACT_SCENE_SUSPEND:
705                                                         mode = KX_SceneActuator::KX_SCENE_SUSPEND;
706                                                         break;
707                                                 case ACT_SCENE_ADD_FRONT:
708                                                         mode = KX_SceneActuator::KX_SCENE_ADD_FRONT_SCENE;
709                                                         break;
710                                                 case ACT_SCENE_ADD_BACK:
711                                                         mode = KX_SceneActuator::KX_SCENE_ADD_BACK_SCENE;
712                                                         break;
713                                                 case ACT_SCENE_REMOVE:
714                                                         mode = KX_SceneActuator::KX_SCENE_REMOVE_SCENE;
715                                                         break;
716                                                 case ACT_SCENE_SET:
717                                                 default:
718                                                         mode = KX_SceneActuator::KX_SCENE_SET_SCENE;
719                                                         break;
720                                                 };
721                                                 
722                                                 if (sceneact->scene)
723                                                 {
724                                                         nextSceneName = sceneact->scene->id.name + 2; // this '2' is necessary to remove prefix 'SC'
725                                                 }
726                                                 
727                                                 break;
728                                         }
729                                 case ACT_SCENE_CAMERA:
730                                         mode = KX_SceneActuator::KX_SCENE_SET_CAMERA;
731                                         if (sceneact->camera)
732                                         {
733                                                 cam = (KX_Camera*) converter->FindGameObject(sceneact->camera);
734                                         }
735                                         break;
736                                 case ACT_SCENE_RESTART:
737                                         {
738                                                 
739                                                 mode =  KX_SceneActuator::KX_SCENE_RESTART;
740                                                 break;
741                                         }
742                                 default:
743                                         ; /* flag error */
744                                 }
745                                 tmpsceneact = new KX_SceneActuator(gameobj,
746                                                 mode,
747                                                 scene,
748                                                 ketsjiEngine,
749                                                 nextSceneName,
750                                                 cam);
751                                         baseact = tmpsceneact;
752                                 break;
753                         }
754                 case ACT_GAME:
755                         {
756                                 bGameActuator *gameact = (bGameActuator *) bact->data;
757                                 KX_GameActuator* tmpgameact;
758                                 STR_String filename = maggiename;
759                                 STR_String loadinganimationname = "";
760                                 int mode = KX_GameActuator::KX_GAME_NODEF;
761                                 switch (gameact->type)
762                                 {
763                                 case ACT_GAME_LOAD:
764                                         {
765                                                 mode = KX_GameActuator::KX_GAME_LOAD;
766                                                 filename = gameact->filename;
767                                                 loadinganimationname = gameact->loadaniname;
768                                                 break;
769                                         }
770                                 case ACT_GAME_START:
771                                         {
772                                                 mode = KX_GameActuator::KX_GAME_START;
773                                                 filename = gameact->filename;
774                                                 loadinganimationname = gameact->loadaniname;
775                                                 break;
776                                         }
777                                 case ACT_GAME_RESTART:
778                                         {
779                                                 mode = KX_GameActuator::KX_GAME_RESTART;
780                                                 break;
781                                         }
782                                 case ACT_GAME_QUIT:
783                                         {
784                                                 mode = KX_GameActuator::KX_GAME_QUIT;
785                                                 break;
786                                         }
787                                 case ACT_GAME_SAVECFG:
788                                         {
789                                                 mode = KX_GameActuator::KX_GAME_SAVECFG;
790                                                 break;
791                                         }
792                                 case ACT_GAME_LOADCFG:
793                                         {
794                                                 mode = KX_GameActuator::KX_GAME_LOADCFG;
795                                                 break;
796                                         }
797                                 default:
798                                         ; /* flag error */
799                                 }
800                                         tmpgameact = new KX_GameActuator(gameobj,
801                                                 mode,
802                                                 filename,
803                                                 loadinganimationname,
804                                                 scene,
805                                                 ketsjiEngine);
806                                         baseact = tmpgameact;
807
808                                 break;
809                         }
810                 case ACT_RANDOM:
811                         {
812                                 bRandomActuator *randAct 
813                                         = (bRandomActuator *) bact->data;
814                                 
815                                 unsigned long seedArg = randAct->seed;
816                                 if (seedArg == 0)
817                                 {
818                                         seedArg = (int)(ketsjiEngine->GetRealTime()*100000.0);
819                                         seedArg ^= (intptr_t)randAct;
820                                 }
821                                 SCA_RandomActuator::KX_RANDOMACT_MODE modeArg 
822                                         = SCA_RandomActuator::KX_RANDOMACT_NODEF;
823                                 SCA_RandomActuator *tmprandomact;
824                                 float paraArg1 = 0.0;
825                                 float paraArg2 = 0.0;
826                                 
827                                 switch  (randAct->distribution) {
828                                 case ACT_RANDOM_BOOL_CONST:
829                                         modeArg = SCA_RandomActuator::KX_RANDOMACT_BOOL_CONST;
830                                         paraArg1 = (float) randAct->int_arg_1;
831                                         break;
832                                 case ACT_RANDOM_BOOL_UNIFORM:
833                                         modeArg = SCA_RandomActuator::KX_RANDOMACT_BOOL_UNIFORM;
834                                         break;
835                                 case ACT_RANDOM_BOOL_BERNOUILLI:
836                                         paraArg1 = randAct->float_arg_1;
837                                         modeArg = SCA_RandomActuator::KX_RANDOMACT_BOOL_BERNOUILLI;
838                                         break;
839                                 case ACT_RANDOM_INT_CONST:
840                                         modeArg = SCA_RandomActuator::KX_RANDOMACT_INT_CONST;
841                                         paraArg1 = (float) randAct->int_arg_1;
842                                         break;
843                                 case ACT_RANDOM_INT_UNIFORM:
844                                         paraArg1 = (float) randAct->int_arg_1;
845                                         paraArg2 = (float) randAct->int_arg_2;
846                                         modeArg = SCA_RandomActuator::KX_RANDOMACT_INT_UNIFORM;
847                                         break;
848                                 case ACT_RANDOM_INT_POISSON:
849                                         paraArg1 = randAct->float_arg_1;
850                                         modeArg = SCA_RandomActuator::KX_RANDOMACT_INT_POISSON;
851                                         break;
852                                 case ACT_RANDOM_FLOAT_CONST:
853                                         paraArg1 = randAct->float_arg_1;
854                                         modeArg = SCA_RandomActuator::KX_RANDOMACT_FLOAT_CONST;
855                                         break;
856                                 case ACT_RANDOM_FLOAT_UNIFORM:
857                                         paraArg1 = randAct->float_arg_1;
858                                         paraArg2 = randAct->float_arg_2;
859                                         modeArg = SCA_RandomActuator::KX_RANDOMACT_FLOAT_UNIFORM;
860                                         break;
861                                 case ACT_RANDOM_FLOAT_NORMAL:
862                                         paraArg1 = randAct->float_arg_1;
863                                         paraArg2 = randAct->float_arg_2;
864                                         modeArg = SCA_RandomActuator::KX_RANDOMACT_FLOAT_NORMAL;
865                                         break;
866                                 case ACT_RANDOM_FLOAT_NEGATIVE_EXPONENTIAL:
867                                         paraArg1 = randAct->float_arg_1;
868                                         modeArg = SCA_RandomActuator::KX_RANDOMACT_FLOAT_NEGATIVE_EXPONENTIAL;
869                                         break;
870                                 default:
871                                         ; /* error */                           
872                                 }
873                                 tmprandomact = new SCA_RandomActuator(gameobj,
874                                         seedArg,
875                                         modeArg, 
876                                         paraArg1,
877                                         paraArg2,
878                                         randAct->propname);
879                                 baseact = tmprandomact;
880                         }
881                         break;
882
883                 case ACT_VISIBILITY:
884                 {
885                         bVisibilityActuator *vis_act = (bVisibilityActuator *) bact->data;
886                         KX_VisibilityActuator * tmp_vis_act = NULL;
887                         bool v = ((vis_act->flag & ACT_VISIBILITY_INVISIBLE) != 0);
888                         bool o = ((vis_act->flag & ACT_VISIBILITY_OCCLUSION) != 0);
889                         bool recursive = ((vis_act->flag & ACT_VISIBILITY_RECURSIVE) != 0);
890
891                         tmp_vis_act = new KX_VisibilityActuator(gameobj, !v, o, recursive);
892                         
893                         baseact = tmp_vis_act;
894                 }
895                 break;
896
897                 case ACT_STATE:
898                 {
899                         bStateActuator *sta_act = (bStateActuator *) bact->data;
900                         KX_StateActuator * tmp_sta_act = NULL;
901
902                         tmp_sta_act = 
903                                 new KX_StateActuator(gameobj, sta_act->type, sta_act->mask);
904                         
905                         baseact = tmp_sta_act;
906                 }
907                 break;
908
909                 case ACT_2DFILTER:
910                 {
911                         bTwoDFilterActuator *_2dfilter = (bTwoDFilterActuator*) bact->data;
912             SCA_2DFilterActuator *tmp = NULL;
913
914                         RAS_2DFilterManager::RAS_2DFILTER_MODE filtermode;
915                         switch(_2dfilter->type)
916                         {
917                                 case ACT_2DFILTER_MOTIONBLUR:
918                                         filtermode = RAS_2DFilterManager::RAS_2DFILTER_MOTIONBLUR;
919                                         break;
920                                 case ACT_2DFILTER_BLUR:
921                                         filtermode = RAS_2DFilterManager::RAS_2DFILTER_BLUR;
922                                         break;
923                                 case ACT_2DFILTER_SHARPEN:
924                                         filtermode = RAS_2DFilterManager::RAS_2DFILTER_SHARPEN;
925                                         break;
926                                 case ACT_2DFILTER_DILATION:
927                                         filtermode = RAS_2DFilterManager::RAS_2DFILTER_DILATION;
928                                         break;
929                                 case ACT_2DFILTER_EROSION:
930                                         filtermode = RAS_2DFilterManager::RAS_2DFILTER_EROSION;
931                                         break;
932                                 case ACT_2DFILTER_LAPLACIAN:
933                                         filtermode = RAS_2DFilterManager::RAS_2DFILTER_LAPLACIAN;
934                                         break;
935                                 case ACT_2DFILTER_SOBEL:
936                                         filtermode = RAS_2DFilterManager::RAS_2DFILTER_SOBEL;
937                                         break;
938                                 case ACT_2DFILTER_PREWITT:
939                                         filtermode = RAS_2DFilterManager::RAS_2DFILTER_PREWITT;
940                                         break;
941                                 case ACT_2DFILTER_GRAYSCALE:
942                                         filtermode = RAS_2DFilterManager::RAS_2DFILTER_GRAYSCALE;
943                                         break;
944                                 case ACT_2DFILTER_SEPIA:
945                                         filtermode = RAS_2DFilterManager::RAS_2DFILTER_SEPIA;
946                                         break;
947                                 case ACT_2DFILTER_INVERT:
948                                         filtermode = RAS_2DFilterManager::RAS_2DFILTER_INVERT;
949                                         break;
950                                 case ACT_2DFILTER_CUSTOMFILTER:
951                                         filtermode = RAS_2DFilterManager::RAS_2DFILTER_CUSTOMFILTER;
952                                         break;
953                                 case ACT_2DFILTER_NOFILTER:
954                                         filtermode = RAS_2DFilterManager::RAS_2DFILTER_NOFILTER;
955                                         break;
956                                 case ACT_2DFILTER_DISABLED:
957                                         filtermode = RAS_2DFilterManager::RAS_2DFILTER_DISABLED;
958                                         break;
959                                 case ACT_2DFILTER_ENABLED:
960                                         filtermode = RAS_2DFilterManager::RAS_2DFILTER_ENABLED;
961                                         break;
962                                 default:
963                                         filtermode = RAS_2DFilterManager::RAS_2DFILTER_NOFILTER;
964                                         break;
965                         }
966             
967                         tmp = new SCA_2DFilterActuator(gameobj, filtermode, _2dfilter->flag,
968                                 _2dfilter->float_arg,_2dfilter->int_arg,ketsjiEngine->GetRasterizer(),scene);
969
970                         if (_2dfilter->text)
971                         {
972                                 char *buf;
973                                 // this is some blender specific code
974                                 buf = txt_to_buf(_2dfilter->text);
975                                 if (buf)
976                                 {
977                                         tmp->SetShaderText(buf);
978                                         MEM_freeN(buf);
979                                 }
980                         }
981
982             baseact = tmp;
983                         
984                 }
985                 break;
986                 case ACT_PARENT:
987                         {
988                                 bParentActuator *parAct = (bParentActuator *) bact->data;
989                                 int mode = KX_ParentActuator::KX_PARENT_NODEF;
990                                 bool addToCompound = true;
991                                 bool ghost = true;
992                                 KX_GameObject *tmpgob = NULL;
993
994                                 switch(parAct->type)
995                                 {
996                                         case ACT_PARENT_SET:
997                                                 mode = KX_ParentActuator::KX_PARENT_SET;
998                                                 tmpgob = converter->FindGameObject(parAct->ob);
999                                                 addToCompound = !(parAct->flag & ACT_PARENT_COMPOUND);
1000                                                 ghost = !(parAct->flag & ACT_PARENT_GHOST);
1001                                                 break;
1002                                         case ACT_PARENT_REMOVE:
1003                                                 mode = KX_ParentActuator::KX_PARENT_REMOVE;
1004                                                 tmpgob = NULL;
1005                                                 break;
1006                                 }
1007         
1008                                 KX_ParentActuator *tmpparact
1009                                         = new KX_ParentActuator(gameobj,
1010                                         mode,
1011                                         addToCompound,
1012                                         ghost,
1013                                         tmpgob);
1014                                 baseact = tmpparact;
1015                                 break;
1016                         }
1017                 
1018                 case ACT_ARMATURE:
1019                         {
1020                                 bArmatureActuator* armAct = (bArmatureActuator*) bact->data;
1021                                 KX_GameObject *tmpgob = converter->FindGameObject(armAct->target);
1022                                 KX_GameObject *subgob = converter->FindGameObject(armAct->subtarget);
1023                                 BL_ArmatureActuator* tmparmact = new BL_ArmatureActuator(gameobj, armAct->type, armAct->posechannel, armAct->constraint, tmpgob, subgob, armAct->weight);
1024                                 baseact = tmparmact;
1025                                 break;
1026                         }
1027                 default:
1028                         ; /* generate some error */
1029                 }
1030                 
1031                 if (baseact)
1032                 {
1033                         baseact->SetExecutePriority(executePriority++);
1034                         uniquename += "#ACT#";
1035                         uniqueint++;
1036                         CIntValue* uniqueval = new CIntValue(uniqueint);
1037                         uniquename += uniqueval->GetText();
1038                         uniqueval->Release();
1039                         baseact->SetName(bact->name);
1040                         //gameobj->SetProperty(uniquename,baseact);
1041                         gameobj->AddActuator(baseact);
1042                         
1043                         converter->RegisterGameActuator(baseact, bact);
1044                         // done with baseact, release it
1045                         baseact->Release();
1046                 }
1047                 
1048                 bact = bact->next;
1049         }
1050 }
1051
1052