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

GPC_Init.cpp

Go to the documentation of this file.
00001 #ifdef WIN32
00002 #pragma warning (disable:4786) // get rid of stupid stl-visual compiler debug warning
00003 #endif //WIN32
00004 
00005 #include "SCA_AlwaysEventManager.h"
00006 #include "SCA_AlwaysSensor.h"
00007 #include "SCA_ANDController.h"
00008 #include "SCA_KeyboardSensor.h"
00009 #include "SCA_KeyboardManager.h"
00010 #include "SCA_LogicManager.h"
00011 #include "SCA_ISystem.h"
00012 
00013 
00014 #include "RAS_OpenGLRasterizer.h"
00015 
00016 #include "SND_SoundObject.h"
00017 
00018 #include "NG_NetworkEventManager.h"
00019 #include "NG_NetworkDeviceInterface.h"
00020 #include "DebugActuator.h"
00021 #include "ExampleEngine.h"
00022 
00023 #include "OpenALScene.h"
00024 //#include "KX_BlenderAudioInterfaceScene.h"
00025 
00026 #include "SamplePolygonMaterial.h"
00027 #include "KX_SoundActuator.h"
00028 
00029 #include "KX_PythonInit.h"
00030 #include "SCA_PythonController.h"
00031 
00032 
00033 extern "C" void write_screendump(char *name)

00034 {
00035         
00036 }
00037 extern "C" void RE_screendump()

00038 {
00039 
00040 }
00041 
00042 
00043 SCA_LogicManager* CreateSampleLogic(SCA_IInputDevice* sca_inputdev,
00044                                                                         KX_GameObject* gameobj,
00045                                                                         SND_IScene* sndscene,
00046                                                                         PyObject* pythondictionary,
00047                                                                         NG_NetworkDeviceInterface* ng_networkdevice
00048                                                                         )

00049 {
00050         // this priority number must be unique, and defines the order in which controllers and actuators
00051         // are executed (when active).
00052 
00053         int controllerPriority=0;
00054         int actuatorPriority=0;
00055 
00056         // THE logic manager (to compare: always created in Blender)
00057         // only one per application
00058         
00059         SCA_LogicManager* logicmgr = new SCA_LogicManager();
00060         
00061         // a couple of event managers, only needed when one or more sensors of that
00062         // type is created. Otherwise, they are not needed.
00063         // in this case only a keyboard manager and an always event manager
00064 
00065         NG_NetworkEventManager* networkeventmanager = new NG_NetworkEventManager(logicmgr,ng_networkdevice);
00066         logicmgr->RegisterEventManager(networkeventmanager);
00067 
00068 
00069         // create...
00070         SCA_KeyboardManager* kbdmgr = new SCA_KeyboardManager(logicmgr, sca_inputdev);
00071         // ... and register to the logic manager
00072         logicmgr->RegisterEventManager(kbdmgr);
00073         
00074         // create...
00075         SCA_EventManager* alwayseventmgr = new SCA_AlwaysEventManager(logicmgr);
00076         // ... and register to the logic manager
00077         logicmgr->RegisterEventManager(alwayseventmgr);
00078         
00079         // setup a KeyboardSensor, an AlwaysSensor, an ANDController and a DebugActuator
00080         // set up SCA block by hand (normally done visually within Blender)
00081         SCA_ISensor *keyRsensor = new SCA_KeyboardSensor(kbdmgr, SCA_IInputDevice::KX_RKEY,
00082                 0, 0, false, NULL);
00083         keyRsensor->RegisterToManager();
00084         SCA_ISensor *keyPsensor = new SCA_KeyboardSensor(kbdmgr, SCA_IInputDevice::KX_PKEY,
00085                 0, 0, false, NULL);
00086         keyPsensor->RegisterToManager();
00087 
00088         SCA_ISensor *keyIsensor = new SCA_KeyboardSensor(kbdmgr, SCA_IInputDevice::KX_IKEY,
00089                 0, 0, false, NULL);
00090         keyIsensor->RegisterToManager();
00091         SCA_ISensor *keyJsensor = new SCA_KeyboardSensor(kbdmgr, SCA_IInputDevice::KX_JKEY,
00092                 0, 0, false, NULL);
00093         keyJsensor->RegisterToManager();
00094         SCA_ISensor *keyLsensor = new SCA_KeyboardSensor(kbdmgr, SCA_IInputDevice::KX_LKEY,
00095                 0, 0, false, NULL);
00096         keyLsensor->RegisterToManager();
00097         SCA_ISensor *keyKsensor = new SCA_KeyboardSensor(kbdmgr, SCA_IInputDevice::KX_KKEY,
00098                 0, 0, false, NULL);
00099         keyKsensor->RegisterToManager();
00100 
00101         SCA_ISensor *alwayssensor = new SCA_AlwaysSensor(alwayseventmgr, NULL);
00102         alwayssensor->SetPulseMode(true, false, 0, 0);
00103         alwayssensor->RegisterToManager();
00104         
00105         SCA_IController *andctrl = new SCA_ANDController(gameobj);
00106         andctrl->SetExecutePriority(controllerPriority++);
00107         SCA_IActuator *dbgactua = new DebugActuator(gameobj);
00108         dbgactua->SetExecutePriority(actuatorPriority++);
00109         
00110         SCA_IController *andctrl1 = new SCA_ANDController(gameobj);
00111         andctrl1->SetExecutePriority(controllerPriority++);
00112         SCA_IController *andctrl2 = new SCA_ANDController(gameobj);
00113         andctrl2->SetExecutePriority(controllerPriority++);
00114         SCA_IController *andctrl3 = new SCA_ANDController(gameobj);
00115         andctrl3->SetExecutePriority(controllerPriority++);
00116         SCA_IController *andctrl4 = new SCA_ANDController(gameobj);
00117         andctrl4->SetExecutePriority(controllerPriority++);
00118         
00119         KX_LocalFlags localflags;
00120         SCA_IActuator* motionactua = new KX_ObjectActuator(gameobj,
00121                 MT_Vector3(0.0,0.0,0.0),//force
00122                 MT_Vector3(0.0,0.0,0.0),//torque
00123                 MT_Vector3(0,0.0,0.0),//dloc
00124                 MT_Vector3(0.1,0.1,0.1),//drot
00125                 MT_Vector3(0.0,0.0,0.0),//linv
00126                 MT_Vector3(0.0,0.0,0.0),//angv
00127                 localflags);//localflag
00128         motionactua->SetExecutePriority(actuatorPriority++);
00129 
00130         SCA_IActuator* upactua = new KX_ObjectActuator(gameobj,
00131                 MT_Vector3(0.0,0.0,0.0),//force
00132                 MT_Vector3(0.0,0.0,0.0),//torque
00133                 MT_Vector3(0.0,0.0,0.1),//dloc
00134                 MT_Vector3(0.0,0.0,0.0),//drot
00135                 MT_Vector3(0.0,0.0,0.0),//linv
00136                 MT_Vector3(0.0,0.0,0.0),//angv
00137                 localflags);//localflag
00138         upactua->SetExecutePriority(actuatorPriority++);
00139         SCA_IActuator* downactua = new KX_ObjectActuator(gameobj,
00140                 MT_Vector3(0.0,0.0,0.0),//force
00141                 MT_Vector3(0.0,0.0,0.0),//torque
00142                 MT_Vector3(0.0,0.0,-0.1),//dloc
00143                 MT_Vector3(0.0,0.0,0.0),//drot
00144                 MT_Vector3(0.0,0.0,0.0),//linv
00145                 MT_Vector3(0.0,0.0,0.0),//angv
00146                 localflags);//localflag
00147         downactua->SetExecutePriority(actuatorPriority++);
00148         SCA_IActuator* leftactua = new KX_ObjectActuator(gameobj,
00149                 MT_Vector3(0.0,0.0,0.0),//force
00150                 MT_Vector3(0.0,0.0,0.0),//torque
00151                 MT_Vector3(-0.1,0.0,0.0),//dloc
00152                 MT_Vector3(0.0,0.0,0.0),//drot
00153                 MT_Vector3(0.0,0.0,0.0),//linv
00154                 MT_Vector3(0.0,0.0,0.0),//angv
00155                 localflags);//localflag
00156         leftactua->SetExecutePriority(actuatorPriority++);
00157         SCA_IActuator* rightactua = new KX_ObjectActuator(gameobj,
00158                 MT_Vector3(0.0,0.0,0.0),//force
00159                 MT_Vector3(0.0,0.0,0.0),//torque
00160                 MT_Vector3(0.1,0.0,0.0),//dloc
00161                 MT_Vector3(0.0,0.0,0.0),//drot
00162                 MT_Vector3(0.0,0.0,0.0),//linv
00163                 MT_Vector3(0.0,0.0,0.0),//angv
00164                 localflags);//localflag
00165         rightactua->SetExecutePriority(actuatorPriority++);
00166 
00167         SCA_PythonController* pythonctrl = new SCA_PythonController(gameobj);
00168         pythonctrl->SetExecutePriority(controllerPriority++);
00169         
00170         CCString pyscript="print \"hello from pythonscript\" \nimport Rasterizer\na= Rasterizer.getWindowHeight()\nprint a";
00171         CCString pyscriptname = "pythonscriptname";
00172         pythonctrl->SetDictionary(pythondictionary);
00173         pythonctrl->SetScriptText(pyscript);
00174         pythonctrl->SetScriptName(pyscriptname);
00175         
00176         // link the controller to both sensors and the actuator
00177         logicmgr->RegisterToSensor(pythonctrl, keyPsensor);
00178         logicmgr->RegisterToSensor(andctrl, keyRsensor);
00179         logicmgr->RegisterToActuator(andctrl, dbgactua);
00180         logicmgr->RegisterToActuator(andctrl, motionactua);
00181 
00182         logicmgr->RegisterToSensor(andctrl1, keyIsensor);
00183         logicmgr->RegisterToActuator(andctrl1, upactua);
00184         logicmgr->RegisterToSensor(andctrl2, keyKsensor);
00185         logicmgr->RegisterToActuator(andctrl2, downactua);
00186         logicmgr->RegisterToSensor(andctrl3, keyJsensor);
00187         logicmgr->RegisterToActuator(andctrl3, leftactua);
00188         logicmgr->RegisterToSensor(andctrl4, keyLsensor);
00189         logicmgr->RegisterToActuator(andctrl4, rightactua);
00190 
00191         /* create soundactuators (logic) */
00192         SND_SoundObject* sndobject1 = new SND_SoundObject();
00193         SND_SoundObject* sndobject2 = new SND_SoundObject();
00194 
00195         sndobject1->setSample("1.wav" /*sampleFilename*/);
00196         sndscene->addObject(sndobject1);
00197         sndobject2->setSample("2.wav" /*sampleFilename*/);
00198         sndscene->addObject(sndobject2);
00199         
00200         SCA_ISensor *noisesensor1 = new SCA_AlwaysSensor(alwayseventmgr, NULL);
00201         noisesensor1->SetPulseMode(true, false, 10, 0);
00202         noisesensor1->RegisterToManager();
00203         SCA_ISensor *noisesensor2 = new SCA_AlwaysSensor(alwayseventmgr, NULL);
00204         noisesensor2->SetPulseMode(true, false, 0, 0);
00205         noisesensor2->RegisterToManager();
00206 
00207         SCA_ISensor *keySsensor = new SCA_KeyboardSensor(kbdmgr, SCA_IInputDevice::KX_SKEY,
00208                 0, 0, false, NULL);
00209         keySsensor->RegisterToManager();
00210         keySsensor->SetPulseMode(true, false, 0, 0);
00211         SCA_ISensor *keyXsensor = new SCA_KeyboardSensor(kbdmgr, SCA_IInputDevice::KX_XKEY,
00212                 0, 0, false, NULL);
00213         keyXsensor->RegisterToManager();
00214         SCA_ISensor *keyAsensor = new SCA_KeyboardSensor(kbdmgr, SCA_IInputDevice::KX_AKEY,
00215                 0, 0, false, NULL);
00216         keyAsensor->RegisterToManager();
00217         SCA_ISensor *keyZsensor = new SCA_KeyboardSensor(kbdmgr, SCA_IInputDevice::KX_ZKEY,
00218                 0, 0, false, NULL);
00219         keyZsensor->RegisterToManager();
00220         
00221         SCA_IController *snd1ctrl = new SCA_ANDController(gameobj);
00222         snd1ctrl->SetExecutePriority(controllerPriority++);
00223         SCA_IController *snd2ctrl = new SCA_ANDController(gameobj);
00224         snd2ctrl->SetExecutePriority(controllerPriority++);
00225         SCA_IController *snd3ctrl = new SCA_ANDController(gameobj);
00226         snd3ctrl->SetExecutePriority(controllerPriority++);
00227         SCA_IController *snd4ctrl = new SCA_ANDController(gameobj);
00228         snd4ctrl->SetExecutePriority(controllerPriority++);
00229 
00230         KX_SoundActuator::KX_SOUNDACT_TYPE
00231                 soundActuatorType1 = KX_SoundActuator::KX_SOUNDACT_PLAYEND;
00232         KX_SoundActuator::KX_SOUNDACT_TYPE
00233                 soundActuatorType2 = KX_SoundActuator::KX_SOUNDACT_RAISEPITCH;
00234         KX_SoundActuator::KX_SOUNDACT_TYPE
00235                 soundActuatorType3 = KX_SoundActuator::KX_SOUNDACT_LOWERPITCH;
00236         
00237         KX_SoundActuator* soundactua1 = new KX_SoundActuator(gameobj, sndobject1, soundActuatorType1, 0, 1, 0);
00238         soundactua1->SetExecutePriority(actuatorPriority++);
00239         KX_SoundActuator* soundactua2 = new KX_SoundActuator(gameobj, sndobject2, soundActuatorType1, 0, 1, 0);
00240         soundactua2->SetExecutePriority(actuatorPriority++);
00241         KX_SoundActuator* soundactua3 = new KX_SoundActuator(gameobj, sndobject1, soundActuatorType2, 0, 1, 0);
00242         soundactua3->SetExecutePriority(actuatorPriority++);
00243         KX_SoundActuator* soundactua4 = new KX_SoundActuator(gameobj, sndobject1, soundActuatorType3, 0, 1, 0);
00244         soundactua4->SetExecutePriority(actuatorPriority++);
00245 
00246         logicmgr->RegisterToSensor(snd1ctrl, keySsensor);
00247         logicmgr->RegisterToSensor(snd2ctrl, keyXsensor);
00248         logicmgr->RegisterToSensor(snd3ctrl, keyAsensor);
00249         logicmgr->RegisterToSensor(snd4ctrl, keyZsensor);
00250 
00251         logicmgr->RegisterToActuator(snd1ctrl, soundactua1);
00252         logicmgr->RegisterToActuator(snd2ctrl, soundactua2);
00253         logicmgr->RegisterToActuator(snd3ctrl, soundactua3);
00254         logicmgr->RegisterToActuator(snd4ctrl, soundactua4);
00255 
00256         return logicmgr;
00257         
00258 }
00259 
00260 
00261 KX_GameObject* CreateGameObject(RAS_IRasterizer* rasty)

00262 {
00263         // create a small gameobject with a mesh
00264         KX_GameObject*   gameobj = new KX_GameObject(NULL, NULL);
00265         gameobj->NodeUpdateGS(0, true);
00266         
00267         RAS_MeshObject* mesh = new RAS_MeshObject();
00268         bool visible = true;
00269         int numverts = 4;
00270         CCString texname="";
00271         bool ba = false;
00272         CCString matname="";
00273         int tile=0;
00274         int mode=0;
00275         int transparant=false;
00276         int lightlayer=0;
00277         bool bIsTriangle=false;
00278         SamplePolygonMaterial* polymat = new SamplePolygonMaterial(texname,ba,matname,tile,mode,transparant,lightlayer,bIsTriangle);
00279         RAS_MaterialBucket* bucket = RAS_BucketManagerFindBucket(polymat);
00280         int vtxarrayindex = mesh->FindVertexArray(4,polymat);
00281         RAS_Polygon* poly = new RAS_Polygon(bucket,visible,numverts,vtxarrayindex);
00282         MT_Vector3 no0(0.0,0.0,0.0),no1(0.0,0.0,0.0),no2(0.0,0.0,0.0),no3(0.0,0.0,0.0);
00283         MT_Point3 pt0(-1,1,0),pt1(1,1,0),pt2(1,-1,0),pt3(-1,-1,0);
00284         MT_Point2 uv0(0.0,0.0),uv1(0.0,0.0),uv2(0.0,0.0),uv3(0.0,0.0);
00285         unsigned int rgb0=0,rgb1=0,rgb2=0,rgb3=0;
00286         poly->SetVertex(0,mesh->FindOrAddVertex(vtxarrayindex,pt0,uv0,rgb0,no0,polymat));
00287         poly->SetVertex(1,mesh->FindOrAddVertex(vtxarrayindex,pt1,uv1,rgb1,no1,polymat));
00288         poly->SetVertex(2,mesh->FindOrAddVertex(vtxarrayindex,pt2,uv2,rgb2,no2,polymat));
00289         poly->SetVertex(3,mesh->FindOrAddVertex(vtxarrayindex,pt3,uv3,rgb3,no3,polymat));
00290         poly->SetVisibleWireframeEdges(255);
00291         mesh->AddPolygon(poly);
00292         gameobj->AddMesh(mesh);
00293         mesh->UpdateMaterialList();
00294         
00295         mesh->SchedulePolygons(rasty->GetDrawingMode(),rasty);
00296         
00297         gameobj->UpdateTransform(false);
00298         gameobj->MarkVisible(true);
00299         gameobj->Bucketize();
00300         return gameobj;
00301 }
00302 
00303 
00304 SND_IScene* CreateSoundScene(void)

00305 {
00306         // initialize sound scene and object
00307         SND_IScene* sndscene = new OpenALScene();
00308         sndscene->init();
00309         
00310         return sndscene;
00311 }
00312 
00313 
00314 RAS_IRasterizer* CreateRasterizer(RAS_ICanvas* canvas)

00315 {
00316         RAS_IRasterizer* rasty = new RAS_OpenGLRasterizer(canvas);
00317         rasty->Init();
00318         rasty->SetBackColor(255, 0, 0, 0);
00319         rasty->SetDrawingMode(2);
00320         return rasty;
00321 }
00322 
00323 SCA_IMainLoop* CreateEngine(RAS_IRasterizer* rasty,RAS_ICanvas* canvas,RAS_IRenderTools* rendertools,SND_IScene* sndscene,SCA_LogicManager* logicmgr,KX_GameObject* gameobj)

00324 {
00325         // the engine, ie the mainloop
00326         ExampleEngine* engine = new ExampleEngine();
00327         engine->Init(rasty, canvas, rendertools, sndscene);
00328         engine->SetLogicMgr(logicmgr);
00329         
00330         // here the 'world' is loaded
00331         engine->SetGameObject(gameobj);  
00332         return engine;
00333 }
00334 
00335 PyObject* CreatePythonBindings(const CCString& progname,class RAS_ICanvas* canvas)

00336 {
00337         PyObject* pythondictionary = initGamePythonScripting(progname);
00338         initGameLogic();
00339         initGameKeys();
00340         initRasterizer(canvas);
00341         return pythondictionary;
00342 }
00343 
00344 void    DestructPythonBindings()

00345 {
00346         exitGamePythonScripting();
00347 }

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