Blender V2.61 - r43446

KX_ConvertSensors.cpp

Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  *
00018  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
00019  * All rights reserved.
00020  *
00021  * The Original Code is: all of this file.
00022  *
00023  * Contributor(s): none yet.
00024  *
00025  * ***** END GPL LICENSE BLOCK *****
00026  * Conversion of Blender data blocks to KX sensor system
00027  */
00028 
00034 #include <stdio.h>
00035 
00036 #if defined(WIN32) && !defined(FREE_WINDOWS)
00037 #pragma warning (disable : 4786)
00038 #endif //WIN32
00039 
00040 #include "wm_event_types.h"
00041 #include "KX_BlenderSceneConverter.h"
00042 #include "KX_ConvertSensors.h"
00043 
00044 /* This little block needed for linking to Blender... */
00045 #if defined(WIN32) && !defined(FREE_WINDOWS)
00046 #include "BLI_winstuff.h"
00047 #endif
00048 
00049 #include "DNA_object_types.h"
00050 #include "DNA_material_types.h"
00051 #include "DNA_sensor_types.h"
00052 #include "DNA_actuator_types.h" /* for SENS_ALL_KEYS ? this define is
00053 probably misplaced */
00054 /* end of blender include block */
00055 
00056 #include "RAS_IPolygonMaterial.h"
00057 // Sensors
00058 #include "KX_GameObject.h"
00059 #include "RAS_MeshObject.h"
00060 #include "SCA_KeyboardSensor.h"
00061 #include "SCA_MouseSensor.h"
00062 #include "SCA_AlwaysSensor.h"
00063 #include "KX_TouchSensor.h"
00064 #include "KX_NearSensor.h"
00065 #include "KX_RadarSensor.h"
00066 #include "KX_MouseFocusSensor.h"
00067 #include "KX_ArmatureSensor.h"
00068 #include "SCA_JoystickSensor.h"
00069 #include "KX_NetworkMessageSensor.h"
00070 #include "SCA_ActuatorSensor.h"
00071 #include "SCA_DelaySensor.h"
00072 
00073 
00074 #include "SCA_PropertySensor.h"
00075 #include "SCA_RandomSensor.h"
00076 #include "KX_RaySensor.h"
00077 #include "SCA_EventManager.h"
00078 #include "SCA_LogicManager.h"
00079 #include "KX_BlenderInputDevice.h"
00080 #include "KX_Scene.h"
00081 #include "IntValue.h"
00082 #include "KX_BlenderKeyboardDevice.h"
00083 #include "KX_BlenderGL.h"
00084 #include "RAS_ICanvas.h"
00085 #include "PHY_IPhysicsEnvironment.h"
00086 
00087 #include "KX_KetsjiEngine.h"
00088 #include "KX_BlenderSceneConverter.h"
00089 #include "BL_BlenderDataConversion.h"
00090 
00091 void BL_ConvertSensors(struct Object* blenderobject,
00092                        class KX_GameObject* gameobj,
00093                        SCA_LogicManager* logicmgr,
00094                        KX_Scene* kxscene,
00095                        KX_KetsjiEngine* kxengine,
00096                        int activeLayerBitInfo,
00097                        bool isInActiveLayer,
00098                        RAS_ICanvas* canvas,
00099                        KX_BlenderSceneConverter* converter
00100                        )
00101 {
00102 
00103     int executePriority = 0;
00104     int uniqueint = 0;
00105     int count = 0;
00106     bSensor* sens = (bSensor*)blenderobject->sensors.first;
00107     bool pos_pulsemode = false;
00108     bool neg_pulsemode = false;
00109     int frequency = 0;
00110     bool invert = false;
00111     bool level = false;
00112     bool tap = false;
00113     
00114     while (sens)
00115     {
00116         sens = sens->next;
00117         count++;
00118     }
00119     gameobj->ReserveSensor(count);
00120     sens = (bSensor*)blenderobject->sensors.first;
00121     while(sens)
00122     {
00123         SCA_ISensor* gamesensor=NULL;
00124         /* All sensors have a pulse toggle, frequency, and invert field.     */
00125         /* These are extracted here, and set when the sensor is added to the */
00126         /* list.                                                             */
00127         pos_pulsemode = (sens->pulse & SENS_PULSE_REPEAT)!=0;
00128         neg_pulsemode = (sens->pulse & SENS_NEG_PULSE_MODE)!=0;
00129         
00130         frequency = sens->freq;
00131         invert    = !(sens->invert == 0);
00132         level     = !(sens->level == 0);
00133         tap       = !(sens->tap == 0);
00134 
00135         switch (sens->type)
00136         {
00137         case  SENS_ALWAYS:
00138             {
00139                 
00140                 SCA_EventManager* eventmgr = logicmgr->FindEventManager(SCA_EventManager::BASIC_EVENTMGR);
00141                 if (eventmgr)
00142                 {
00143                     gamesensor = new SCA_AlwaysSensor(eventmgr, gameobj);
00144                 }
00145                 
00146                 break;
00147             }
00148             
00149         case  SENS_DELAY:
00150             {
00151                 // we can reuse the Always event manager for the delay sensor
00152                 SCA_EventManager* eventmgr = logicmgr->FindEventManager(SCA_EventManager::BASIC_EVENTMGR);
00153                 if (eventmgr)
00154                 {
00155                     bDelaySensor* delaysensor = (bDelaySensor*)sens->data;
00156                     gamesensor = new SCA_DelaySensor(eventmgr, 
00157                         gameobj,
00158                         delaysensor->delay,
00159                         delaysensor->duration,
00160                         (delaysensor->flag & SENS_DELAY_REPEAT) != 0);
00161                 }
00162                 break;
00163             }
00164 
00165         case SENS_COLLISION:
00166             {
00167                 SCA_EventManager* eventmgr = logicmgr->FindEventManager(SCA_EventManager::TOUCH_EVENTMGR);
00168                 if (eventmgr)
00169                 {
00170                     // collision sensor can sense both materials and properties. 
00171                     
00172                     bool bFindMaterial = false, bTouchPulse = false;
00173                     
00174                     bCollisionSensor* blendertouchsensor = (bCollisionSensor*)sens->data;
00175                     
00176                     bFindMaterial = (blendertouchsensor->mode & SENS_COLLISION_MATERIAL);
00177                     bTouchPulse = (blendertouchsensor->mode & SENS_COLLISION_PULSE);
00178                     
00179                     
00180                     STR_String touchPropOrMatName = ( bFindMaterial ? 
00181                         blendertouchsensor->materialName:
00182                     (blendertouchsensor->name ? blendertouchsensor->name: ""));
00183                     
00184                     
00185                     if (gameobj->GetPhysicsController())
00186                     {   
00187                         gamesensor = new KX_TouchSensor(eventmgr,
00188                             gameobj,
00189                             bFindMaterial,
00190                             bTouchPulse,
00191                             touchPropOrMatName);
00192                     }
00193                     
00194                 }
00195                 
00196                 break;
00197             }
00198         case SENS_TOUCH:
00199             {
00200                 SCA_EventManager* eventmgr = logicmgr->FindEventManager(SCA_EventManager::TOUCH_EVENTMGR);
00201                 if (eventmgr)
00202                 {
00203                     STR_String touchpropertyname;
00204                     bTouchSensor* blendertouchsensor = (bTouchSensor*)sens->data;
00205                     
00206                     if (blendertouchsensor->ma)
00207                     {
00208                         touchpropertyname = (char*) (blendertouchsensor->ma->id.name+2);
00209                     }
00210                     bool bFindMaterial = true;
00211                     if (gameobj->GetPhysicsController())
00212                     {   
00213                         gamesensor = new KX_TouchSensor(eventmgr,
00214                             gameobj,
00215                             bFindMaterial,
00216                             false,
00217                             touchpropertyname);
00218                     }
00219                 }
00220                 break;
00221             }
00222         case SENS_MESSAGE:
00223             {
00224                 KX_NetworkEventManager* eventmgr = (KX_NetworkEventManager*)
00225                     logicmgr->FindEventManager(SCA_EventManager::NETWORK_EVENTMGR);
00226                 if (eventmgr) {
00227                     bMessageSensor* msgSens = (bMessageSensor*) sens->data; 
00228                     
00229                     /* Get our NetworkScene */
00230                     NG_NetworkScene *NetworkScene = kxscene->GetNetworkScene();
00231                     /* filter on the incoming subjects, might be empty */
00232                     STR_String subject = (msgSens->subject
00233                         ? (char*)msgSens->subject
00234                         : "");
00235                     
00236                     gamesensor = new KX_NetworkMessageSensor(
00237                         eventmgr,       // our eventmanager
00238                         NetworkScene,   // our NetworkScene
00239                         gameobj,        // the sensor controlling object
00240                         subject);       // subject to filter on
00241                 }
00242                 break;
00243             }
00244         case SENS_NEAR:
00245             {
00246                 
00247                 SCA_EventManager* eventmgr = logicmgr->FindEventManager(SCA_EventManager::TOUCH_EVENTMGR);
00248                 if (eventmgr)
00249                 {
00250                     STR_String nearpropertyname;    
00251                     bNearSensor* blendernearsensor = (bNearSensor*)sens->data;
00252                     if (blendernearsensor->name)
00253                     {
00254                         // only objects that own this property will be taken into account
00255                         nearpropertyname = (char*) blendernearsensor->name;
00256                     }
00257                     
00258                     //DT_ShapeHandle shape  =   DT_Sphere(0.0);
00259                     
00260                     // this sumoObject is not deleted by a gameobj, so delete it ourself
00261                     // later (memleaks)!
00262                     float radius = blendernearsensor->dist;
00263                     PHY__Vector3 pos;
00264                     const MT_Vector3& wpos = gameobj->NodeGetWorldPosition();
00265                     pos[0] = (float)wpos[0];
00266                     pos[1] = (float)wpos[1];
00267                     pos[2] = (float)wpos[2];
00268                     pos[3] = 0.f;
00269                     bool bFindMaterial = false;
00270                     PHY_IPhysicsController* physCtrl = kxscene->GetPhysicsEnvironment()->CreateSphereController(radius,pos);
00271 
00272                     //will be done in KX_TouchEventManager::RegisterSensor()  
00273                     //if (isInActiveLayer)
00274                     //  kxscene->GetPhysicsEnvironment()->addSensor(physCtrl);
00275 
00276                         
00277 
00278                     gamesensor = new KX_NearSensor(eventmgr,gameobj,
00279                         blendernearsensor->dist,
00280                         blendernearsensor->resetdist,
00281                         bFindMaterial,
00282                         nearpropertyname,
00283                         physCtrl);
00284                     
00285                 }
00286                 break;
00287             }
00288             
00289             
00290         case SENS_KEYBOARD:
00291             {
00292                 /* temporary input device, for converting the code for the keyboard sensor */
00293                 
00294                 bKeyboardSensor* blenderkeybdsensor = (bKeyboardSensor*)sens->data;
00295                 SCA_KeyboardManager* eventmgr = (SCA_KeyboardManager*) logicmgr->FindEventManager(SCA_EventManager::KEYBOARD_EVENTMGR);
00296                 if (eventmgr)
00297                 {
00298                     gamesensor = new SCA_KeyboardSensor(eventmgr,
00299                         ConvertKeyCode(blenderkeybdsensor->key),
00300                         ConvertKeyCode(blenderkeybdsensor->qual),
00301                         ConvertKeyCode(blenderkeybdsensor->qual2),
00302                         (blenderkeybdsensor->type == SENS_ALL_KEYS),
00303                         blenderkeybdsensor->targetName,
00304                         blenderkeybdsensor->toggleName,
00305                         gameobj); //            blenderkeybdsensor->pad);
00306                     
00307                 } 
00308                 
00309                 break;
00310             }
00311         case SENS_MOUSE:
00312             {
00313                 int keytype = SCA_MouseSensor::KX_MOUSESENSORMODE_NODEF;            
00314                 int trackfocus = 0;
00315                 bMouseSensor *bmouse = (bMouseSensor *)sens->data;
00316                 
00317                 /* There are two main types of mouse sensors. If there is
00318                 * no focus-related behaviour requested, we can make do
00319                 * with a basic sensor. This cuts down memory usage and
00320                 * gives a slight performance gain. */
00321                 
00322                 SCA_MouseManager *eventmgr 
00323                     = (SCA_MouseManager*) logicmgr->FindEventManager(SCA_EventManager::MOUSE_EVENTMGR);
00324                 if (eventmgr) {
00325                     
00326                     /* Determine key mode. There is at most one active mode. */
00327                     switch (bmouse->type) {
00328                     case BL_SENS_MOUSE_LEFT_BUTTON:
00329                         keytype = SCA_MouseSensor::KX_MOUSESENSORMODE_LEFTBUTTON;
00330                         break;
00331                     case BL_SENS_MOUSE_MIDDLE_BUTTON:
00332                         keytype = SCA_MouseSensor::KX_MOUSESENSORMODE_MIDDLEBUTTON;
00333                         break;
00334                     case BL_SENS_MOUSE_RIGHT_BUTTON:
00335                         keytype = SCA_MouseSensor::KX_MOUSESENSORMODE_RIGHTBUTTON;
00336                         break;
00337                     case BL_SENS_MOUSE_WHEEL_UP:
00338                         keytype = SCA_MouseSensor::KX_MOUSESENSORMODE_WHEELUP;
00339                         break;
00340                     case BL_SENS_MOUSE_WHEEL_DOWN:
00341                         keytype = SCA_MouseSensor::KX_MOUSESENSORMODE_WHEELDOWN;
00342                         break;
00343                     case BL_SENS_MOUSE_MOVEMENT:
00344                         keytype = SCA_MouseSensor::KX_MOUSESENSORMODE_MOVEMENT;
00345                         break;
00346                     case BL_SENS_MOUSE_MOUSEOVER:
00347                         trackfocus = 1;
00348                         break;
00349                     case BL_SENS_MOUSE_MOUSEOVER_ANY:
00350                         trackfocus = 2;
00351                         break;
00352 
00353                     default:
00354                         ; /* error */
00355                     }
00356                     
00357                     /* initial mouse position */                 
00358                     int startx  = canvas->GetWidth()/2;
00359                     int starty = canvas->GetHeight()/2;
00360                     
00361                     if (!trackfocus) {
00362                         /* plain, simple mouse sensor */
00363                         gamesensor = new SCA_MouseSensor(eventmgr,
00364                             startx,starty,
00365                             keytype,
00366                             gameobj);
00367                     } else {
00368                         /* give us a focus-aware sensor */
00369                         gamesensor = new KX_MouseFocusSensor(eventmgr,
00370                             startx,
00371                             starty,
00372                             keytype,
00373                             trackfocus,
00374                             (bmouse->flag & SENS_MOUSE_FOCUS_PULSE) ? true:false,
00375                             kxscene,
00376                             kxengine,
00377                             gameobj); 
00378                     }
00379                 } else {
00380                     //              cout << "\n Could't find mouse event manager..."; - should throw an error here... 
00381                 }
00382                 break;
00383             }
00384         case SENS_PROPERTY:
00385             {
00386                 bPropertySensor* blenderpropsensor = (bPropertySensor*) sens->data;
00387                 SCA_EventManager* eventmgr 
00388                     = logicmgr->FindEventManager(SCA_EventManager::BASIC_EVENTMGR);
00389                 if (eventmgr)
00390                 {
00391                     STR_String propname=blenderpropsensor->name;
00392                     STR_String propval=blenderpropsensor->value;
00393                     STR_String propmaxval=blenderpropsensor->maxvalue;
00394                     
00395                     SCA_PropertySensor::KX_PROPSENSOR_TYPE 
00396                         propchecktype = SCA_PropertySensor::KX_PROPSENSOR_NODEF;
00397                     
00398                     /* Better do an explicit conversion here! (was implicit      */
00399                     /* before...)                                                */
00400                     switch(blenderpropsensor->type) {
00401                     case SENS_PROP_EQUAL:
00402                         propchecktype = SCA_PropertySensor::KX_PROPSENSOR_EQUAL;
00403                         break;
00404                     case SENS_PROP_NEQUAL:
00405                         propchecktype = SCA_PropertySensor::KX_PROPSENSOR_NOTEQUAL;
00406                         break;
00407                     case SENS_PROP_INTERVAL:
00408                         propchecktype = SCA_PropertySensor::KX_PROPSENSOR_INTERVAL;
00409                         break;
00410                     case SENS_PROP_CHANGED:
00411                         propchecktype = SCA_PropertySensor::KX_PROPSENSOR_CHANGED;
00412                         break;
00413                     case SENS_PROP_EXPRESSION:
00414                         propchecktype = SCA_PropertySensor::KX_PROPSENSOR_EXPRESSION;
00415                         /* error */
00416                         break;
00417                     default:
00418                         ; /* error */
00419                     }
00420                     gamesensor = new SCA_PropertySensor(eventmgr,gameobj,propname,propval,propmaxval,propchecktype);
00421                 }
00422                 
00423                 break;
00424             }
00425         case SENS_ACTUATOR:
00426             {
00427                 bActuatorSensor* blenderactsensor = (bActuatorSensor*) sens->data;
00428                 // we will reuse the property event manager, there is nothing special with this sensor
00429                 SCA_EventManager* eventmgr 
00430                     = logicmgr->FindEventManager(SCA_EventManager::ACTUATOR_EVENTMGR);
00431                 if (eventmgr)
00432                 {
00433                     STR_String propname=blenderactsensor->name;
00434                     gamesensor = new SCA_ActuatorSensor(eventmgr,gameobj,propname);
00435                 }
00436                 break;
00437             }
00438             
00439         case SENS_ARMATURE:
00440             {
00441                 bArmatureSensor* blenderarmsensor = (bArmatureSensor*) sens->data;
00442                 // we will reuse the property event manager, there is nothing special with this sensor
00443                 SCA_EventManager* eventmgr 
00444                     = logicmgr->FindEventManager(SCA_EventManager::BASIC_EVENTMGR);
00445                 if (eventmgr)
00446                 {
00447                     STR_String bonename=blenderarmsensor->posechannel;
00448                     STR_String constraintname=blenderarmsensor->constraint;
00449                     gamesensor = new KX_ArmatureSensor(eventmgr,gameobj,bonename,constraintname, blenderarmsensor->type, blenderarmsensor->value);
00450                 }
00451                 break;
00452             }
00453 
00454         case SENS_RADAR:
00455             {
00456                 
00457                 SCA_EventManager* eventmgr = logicmgr->FindEventManager(SCA_EventManager::TOUCH_EVENTMGR);
00458                 if (eventmgr)
00459                 {
00460                     STR_String radarpropertyname;
00461                     STR_String touchpropertyname;
00462                     bRadarSensor* blenderradarsensor = (bRadarSensor*) sens->data;
00463                     
00464                     int radaraxis = blenderradarsensor->axis;
00465                     
00466                     if (blenderradarsensor->name)
00467                     {
00468                         // only objects that own this property will be taken into account
00469                         radarpropertyname = (char*) blenderradarsensor->name;
00470                     }
00471                     
00472                     MT_Scalar coneheight = blenderradarsensor->range;
00473                     
00474                     // janco: the angle was doubled, so should I divide the factor in 2
00475                     // or the blenderradarsensor->angle?
00476                     // nzc: the angle is the opening angle. We need to init with 
00477                     // the axis-hull angle,so /2.0.
00478                     MT_Scalar factor = tan(MT_radians((blenderradarsensor->angle)/2.0));
00479                     //MT_Scalar coneradius = coneheight * (factor / 2);
00480                     MT_Scalar coneradius = coneheight * factor;
00481                     
00482                     
00483                     // this sumoObject is not deleted by a gameobj, so delete it ourself
00484                     // later (memleaks)!
00485                     MT_Scalar smallmargin = 0.0;
00486                     MT_Scalar largemargin = 0.0;
00487                     
00488                     bool bFindMaterial = false;
00489                     PHY_IPhysicsController* ctrl = kxscene->GetPhysicsEnvironment()->CreateConeController((float)coneradius, (float)coneheight);
00490 
00491                     gamesensor = new KX_RadarSensor(
00492                         eventmgr,
00493                         gameobj,
00494                         ctrl,
00495                         coneradius,
00496                         coneheight,
00497                         radaraxis,
00498                         smallmargin,
00499                         largemargin,
00500                         bFindMaterial,
00501                         radarpropertyname);
00502                         
00503                 }
00504             
00505                 break;
00506             }
00507         case SENS_RAY:
00508             {
00509                 bRaySensor* blenderraysensor = (bRaySensor*) sens->data;
00510                 
00511                 //blenderradarsensor->angle;
00512                 SCA_EventManager* eventmgr = logicmgr->FindEventManager(SCA_EventManager::BASIC_EVENTMGR);
00513                 if (eventmgr)
00514                 {
00515                     bool bFindMaterial = (blenderraysensor->mode & SENS_COLLISION_MATERIAL);
00516                     bool bXRay = (blenderraysensor->mode & SENS_RAY_XRAY);
00517                     
00518                     STR_String checkname = (bFindMaterial? blenderraysensor->matname : blenderraysensor->propname);
00519 
00520                     // don't want to get rays of length 0.0 or so
00521                     double distance = (blenderraysensor->range < 0.01 ? 0.01 : blenderraysensor->range );
00522                     int axis = blenderraysensor->axisflag;
00523 
00524                     
00525                     gamesensor = new KX_RaySensor(eventmgr,
00526                                                   gameobj,
00527                                                   checkname,
00528                                                   bFindMaterial,
00529                                                   bXRay,
00530                                                   distance,
00531                                                   axis,
00532                                                   kxscene);
00533 
00534                 }
00535                 break;
00536             }
00537             
00538         case SENS_RANDOM:
00539             {
00540                 bRandomSensor* blenderrndsensor = (bRandomSensor*) sens->data;
00541                 // some files didn't write randomsensor, avoid crash now for NULL ptr's
00542                 if (blenderrndsensor)
00543                 {
00544                     SCA_EventManager* eventmgr = logicmgr->FindEventManager(SCA_EventManager::BASIC_EVENTMGR);
00545                     if (eventmgr)
00546                     {
00547                         int randomSeed = blenderrndsensor->seed;
00548                         if (randomSeed == 0)
00549                         {
00550                             randomSeed = (int)(kxengine->GetRealTime()*100000.0);
00551                             randomSeed ^= (intptr_t)blenderrndsensor;
00552                         }
00553                         gamesensor = new SCA_RandomSensor(eventmgr, gameobj, randomSeed);
00554                     }
00555                 }
00556                 break;
00557             }
00558         case SENS_JOYSTICK:
00559             {
00560                 int joysticktype = SCA_JoystickSensor::KX_JOYSENSORMODE_NODEF;
00561                 
00562                 bJoystickSensor* bjoy = (bJoystickSensor*) sens->data;
00563                 
00564                 SCA_JoystickManager *eventmgr 
00565                     = (SCA_JoystickManager*) logicmgr->FindEventManager(SCA_EventManager::JOY_EVENTMGR);
00566                 if (eventmgr) 
00567                 {
00568                     int axis    =0;
00569                     int axisf   =0;
00570                     int button  =0;
00571                     int hat     =0; 
00572                     int hatf    =0;
00573                     int prec    =0;
00574                     
00575                     switch(bjoy->type)
00576                     {
00577                     case SENS_JOY_AXIS:
00578                         axis    = bjoy->axis;
00579                         axisf   = bjoy->axisf;
00580                         prec    = bjoy->precision;
00581                         joysticktype  = SCA_JoystickSensor::KX_JOYSENSORMODE_AXIS;
00582                         break;
00583                     case SENS_JOY_BUTTON:
00584                         button  = bjoy->button;
00585                         joysticktype  = SCA_JoystickSensor::KX_JOYSENSORMODE_BUTTON;
00586                         break;
00587                     case SENS_JOY_HAT:
00588                         hat     = bjoy->hat;
00589                         hatf    = bjoy->hatf;
00590                         joysticktype  = SCA_JoystickSensor::KX_JOYSENSORMODE_HAT;
00591                         break;
00592                     case SENS_JOY_AXIS_SINGLE:
00593                         axis    = bjoy->axis_single;
00594                         prec    = bjoy->precision;
00595                         joysticktype  = SCA_JoystickSensor::KX_JOYSENSORMODE_AXIS_SINGLE;
00596                         break;
00597                     default:
00598                         printf("Error: bad case statement\n");
00599                         break;
00600                     }
00601                     gamesensor = new SCA_JoystickSensor(
00602                         eventmgr,
00603                         gameobj,
00604                         bjoy->joyindex,
00605                         joysticktype,
00606                         axis,axisf,
00607                         prec,
00608                         button,
00609                         hat,hatf,
00610                         (bjoy->flag & SENS_JOY_ANY_EVENT));
00611                 } 
00612                 else
00613                 {
00614                     printf("Error there was a problem finding the event manager\n");
00615                 }
00616 
00617                 break;
00618             }
00619         default:
00620             {
00621             }
00622         }
00623 
00624         if (gamesensor)
00625         {
00626             gamesensor->SetExecutePriority(executePriority++);
00627             STR_String uniquename = sens->name;
00628             uniquename += "#SENS#";
00629             uniqueint++;
00630             CIntValue* uniqueval = new CIntValue(uniqueint);
00631             uniquename += uniqueval->GetText();
00632             uniqueval->Release();
00633             
00634             /* Conversion succeeded, so we can set the generic props here.   */
00635             gamesensor->SetPulseMode(pos_pulsemode, 
00636                                      neg_pulsemode, 
00637                                      frequency);
00638             gamesensor->SetInvert(invert);
00639             gamesensor->SetLevel(level);
00640             gamesensor->SetTap(tap);
00641             gamesensor->SetName(sens->name);            
00642             
00643             gameobj->AddSensor(gamesensor);
00644             
00645             // only register to manager if it's in an active layer
00646             // Make registration dynamic: only when sensor is activated
00647             //if (isInActiveLayer)
00648             //  gamesensor->RegisterToManager();
00649             
00650             gamesensor->ReserveController(sens->totlinks);
00651             for (int i=0;i<sens->totlinks;i++)
00652             {
00653                 bController* linkedcont = (bController*) sens->links[i];
00654                 if (linkedcont) {
00655                     SCA_IController* gamecont = converter->FindGameController(linkedcont);
00656 
00657                     if (gamecont) {
00658                         logicmgr->RegisterToSensor(gamecont,gamesensor);
00659                     } else {
00660                         printf(
00661                             "Warning, sensor \"%s\" could not find its controller "
00662                             "(link %d of %d) from object \"%s\"\n"
00663                             "\tthere has been an error converting the blender controller for the game engine,"
00664                             "logic may be incorrect\n", sens->name, i+1, sens->totlinks, blenderobject->id.name+2);
00665                     }
00666                 } else {
00667                     printf(
00668                         "Warning, sensor \"%s\" has lost a link to a controller "
00669                         "(link %d of %d) from object \"%s\"\n"
00670                         "\tpossible causes are partially appended objects or an error reading the file,"
00671                         "logic may be incorrect\n", sens->name, i+1, sens->totlinks, blenderobject->id.name+2);
00672                 }
00673             }
00674             // special case: Keyboard sensor with no link
00675             // this combination is usually used for key logging. 
00676             if (sens->type == SENS_KEYBOARD && sens->totlinks == 0) {
00677                 // Force the registration so that the sensor runs
00678                 gamesensor->IncLink();
00679             }
00680                 
00681             // done with gamesensor
00682             gamesensor->Release();
00683             
00684         }
00685         sens=sens->next;
00686     }
00687 }
00688