Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

KX_ConvertControllers.cpp

Go to the documentation of this file.
00001 extern "C" short freeN(void * bufje);
00002 extern "C" char*  txt_to_buf(struct Text* text);
00003 
00004 #include "KX_ConvertControllers.h"
00005 #include "Python.h"
00006 
00007 // Controller
00008 #include "SCA_ANDController.h"
00009 #include "SCA_ORController.h"
00010 #include "SCA_PythonController.h"
00011 #include "SCA_ExpressionController.h"
00012 
00013 #include "SCA_LogicManager.h"
00014 #include "KX_GameObject.h"
00015 #include "IntValue.h"
00016 
00017 #include "KX_BlenderKetsjiConversionMaps.h"
00018 
00019 #include "blender.h"
00020 #include "game.h"
00021 
00022 void BL_ConvertControllers(struct Object* blenderobject,class KX_GameObject* gameobj,SCA_LogicManager* logicmgr, PyObject* pythondictionary,int &executePriority)

00023 {
00024 
00025         
00026 
00027         int uniqueint=0,i=0;
00028         bController* bcontr = (bController*)blenderobject->controllers.first;
00029         while (bcontr)
00030         {
00031                 SCA_IController* gamecontroller = NULL;
00032                 switch(bcontr->type)
00033                 {
00034                 case CONT_LOGIC_AND:
00035                 {
00036                         gamecontroller = new SCA_ANDController(gameobj);
00037                                 
00038 
00039                         // register this controller to all it's linked sensors
00040                         // names are unique, so no need to fiddle with original blenderpointers
00041                         for (int i=0;i<bcontr->totlinks;i++)
00042                         {
00043                                 bActuator* bact = (bActuator*) bcontr->links[i];
00044                                 SCA_IActuator** gameactuator = map_blender_to_gameactuator[CHashedPtr(bact)];
00045                                 if (gameactuator)
00046                                 {
00047                                         logicmgr->RegisterToActuator(gamecontroller,*gameactuator);
00048                                 }
00049 
00050                         }
00051 
00052                         break;
00053                 }
00054                 case CONT_LOGIC_OR:
00055                 {
00056                         gamecontroller = new SCA_ORController(gameobj);
00057                                 
00058                         // register this controller to all it's linked sensors
00059                         // names are unique, so no need to fiddle with original blenderpointers
00060                         for (int i=0;i<bcontr->totlinks;i++)
00061                         {
00062                                 bActuator* bact = (bActuator*) bcontr->links[i];
00063                                 SCA_IActuator** gameactuator = map_blender_to_gameactuator[CHashedPtr(bact)];
00064                                 if (gameactuator)
00065                                 {
00066                                         logicmgr->RegisterToActuator(gamecontroller,*gameactuator);
00067                                 }
00068 
00069                         }
00070 
00071                         break;
00072                 }
00073                 case CONT_EXPRESSION:
00074                 {
00075                         bExpressionCont* bexpcont = (bExpressionCont*) bcontr->data;
00076                         CCString expressiontext = CCString(bexpcont->str);
00077                         if (expressiontext.Length() > 0)
00078                         {
00079                                 SCA_ExpressionController* exprcontroller = new SCA_ExpressionController(gameobj,
00080                                         expressiontext);
00081                                 gamecontroller = exprcontroller;
00082 
00083                                 // register this controller to all it's linked sensors
00084                                 // names are unique, so no need to fiddle with original blenderpointers
00085                                 for (int i=0;i<bcontr->totlinks;i++)
00086                                 {
00087                                         bActuator* bact = (bActuator*) bcontr->links[i];
00088                                         SCA_IActuator** gameactuator = map_blender_to_gameactuator[CHashedPtr(bact)];
00089                                         if (gameactuator)
00090                                         {
00091                                                 logicmgr->RegisterToActuator(gamecontroller,*gameactuator);
00092                                         }
00093 
00094                                 }
00095 
00096                         }
00097                         break;
00098                 }
00099                 case CONT_PYTHON:
00100                 {
00101                                 
00102                         // we should create a Python controller here
00103                         
00104                         
00105                         SCA_PythonController* pyctrl = new SCA_PythonController(gameobj);
00106                         gamecontroller = pyctrl;
00107                                 
00108                         bPythonCont* pycont = (bPythonCont*) bcontr->data;
00109                         pyctrl->SetDictionary(pythondictionary);
00110                                 
00111                         if (pycont->text)
00112                         {
00113                                 char *buf;
00114                                 // this is some blender specific code
00115                                 buf= txt_to_buf(pycont->text);
00116                                 if (buf)
00117                                 {
00118                                         strcat(buf, "\n");
00119                                         pyctrl->SetScriptText(CCString(buf));
00120                                         pyctrl->SetScriptName(pycont->text->id.name+2);
00121                                         freeN(buf);
00122                                 }
00123                                 
00124                         }
00125                                 
00126                                 
00127                         // register this controller to all it's linked actuators
00128                         // names are unique, so no need to fiddle with original blenderpointers
00129                         for (i=0;i<bcontr->totlinks;i++)
00130                         {
00131                                 bActuator* bact = (bActuator*) bcontr->links[i];
00132                                 SCA_IActuator** gameactuator = map_blender_to_gameactuator[CHashedPtr(bact)];
00133                                 if (gameactuator)
00134                                 {
00135                                         logicmgr->RegisterToActuator(gamecontroller,*gameactuator);
00136                                 }
00137 
00138                         }
00139                                 
00140                         break;
00141                 }
00142                 default:
00143                 {
00144                         
00145                 }
00146                 
00147                 
00148                 }
00149 
00150                 
00151 
00152                 if (gamecontroller)
00153                 {
00154                         gamecontroller->SetExecutePriority(executePriority++);
00155                         CCString uniquename = bcontr->name;
00156                         uniquename += "#CONTR#";
00157                         uniqueint++;
00158                         CIntValue* uniqueval = new CIntValue(uniqueint);
00159                         uniquename += uniqueval->GetText();
00160                         uniqueval->Release();
00161                         gamecontroller->SetName(uniquename);
00162                         gameobj->AddController(gamecontroller);
00163                         map_blender_to_gamecontroller.insert(CHashedPtr(bcontr),gamecontroller);
00164                 }
00165                 
00166                 bcontr = bcontr->next;
00167         }
00168 
00169 }

Generated at Thu Feb 1 13:03:04 2001 for Ketsji Game Engine by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000