//System #include "irrlicht.h" #include "irrklang.h" #include #include // #include "CEventReceiver.h" #include "CPlayerManager.h" #include "CPlayer.h" #include "CSound.h" #include "CCamera.h" #include "CWord.h" #include "GUI/GUI.h" #include "CLog.h" #ifdef _IRR_WINDOWS_ #pragma comment(lib, "libIrrlicht.a") #pragma comment(lib, "libirrKlang.a") #pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup") #endif int main() { CLog *main_log = new CLog("error.log"); main_log->Write("Intialisation ok"); //Creaton d'un device en fullscreen pour recuperer la resolution irr::IrrlichtDevice *nulldevice = irr::createDevice(irr::video::EDT_NULL); if(!nulldevice) { main_log->Write("Impossible de recuperer la resolution"); return 1; } irr::core::dimension2d deskres = nulldevice->getVideoModeList()->getDesktopResolution(); nulldevice->drop(); //Creation du device avec la resolution de l'ecran irr::IrrlichtDevice *Irr_Device = irr::createDevice(irr::video::EDT_OPENGL, deskres, 32, true, false, true); if(!Irr_Device) { main_log->Write("Impossible de creer le Device"); return 1; } //Ini de la GUI CGUI *GUI = new CGUI(Irr_Device, deskres); //Ini de l'eventreceiver CEventReceiver *EventReceiver = new CEventReceiver(Irr_Device, GUI); //Set de l'eventreceiver Irr_Device->setEventReceiver(EventReceiver); //IA srand(time(NULL)); irr::video::IVideoDriver* VideoDriver = Irr_Device->getVideoDriver(); irr::scene::ISceneManager* SceneManager = Irr_Device->getSceneManager(); irr::gui::IGUIEnvironment* GUIEnv = Irr_Device->getGUIEnvironment(); //Chargement de la police irr::gui::IGUIFont* Font = GUIEnv->getFont("./media/fontcourier.bmp"); //Corrige les probleme de transparence SceneManager->getParameters()->setAttribute(irr::scene::ALLOW_ZWRITE_ON_TRANSPARENT, true); //Def Option rendu irr::video::SMaterial m; m.Lighting = false; //m.ZBuffer = false; VideoDriver->setMaterial(m); irr::core::matrix4 mat; //VideoDriver->setTransform(irr::video::ETS_WORLD, mat); VideoDriver->setTransform(irr::video::ETS_WORLD, irr::core::IdentityMatrix); //Moteur Sond irrklang::ISoundEngine* SoundEngine = irrklang::createIrrKlangDevice(); if(!SoundEngine) { main_log->Write("Impossible de creer le SoundDevice"); return EXIT_FAILURE; } //CollisionManager irr::scene::ISceneCollisionManager* Collision_Manager = SceneManager->getSceneCollisionManager(); //Curseur desactiver Irr_Device->getCursorControl()->setVisible(false); int lastFPS = -1; irr::u32 then = Irr_Device->getTimer()->getTime(); const irr::f32 MOUV_SPEED = 5.f; CWord *Word; CPlayer *Player; //PlayerManager CPlayerManager *PlayerManager; while(Irr_Device->run()) { if(Irr_Device->isWindowActive()) { const irr::u32 now = Irr_Device->getTimer()->getTime(); const irr::f32 frameDeltaTime = (irr::f32)(now - then) / 1000.f; then = now; if(GUI->InGame) { VideoDriver->beginScene(true, true, irr::video::SColor(255,0,0,0)); } SceneManager->drawAll(); //////////////////////////////////////////// //Introduction //////////////////////////////////////////// if(GUI->Intro) { GUI->GIntro(frameDeltaTime); } //////////////////////////////////////////// //Introduction End //////////////////////////////////////////// //////////////////////////////////////////// //Menu Begin //////////////////////////////////////////// if(GUI->Menu_Principal) { GUI->GMenu_Principal(); } //////////////////////////////////////////// //Menu End //////////////////////////////////////////// if(GUI->InGame) { //Création de la GUI en InGame GUI->GInGame(); //Affichage des box GUI->Graph_FPS->draw(); GUI->Graph_Lat->draw(); //Ajout des donnees GUI->Graph_FPS->addValue(VideoDriver->getFPS()); GUI->Graph_Lat->addValue(VideoDriver->getPrimitiveCountDrawn()); if(!Monde_Created) { //Creation du word Word = new CWord(Irr_Device); if(!Word) { main_log->Write("Impossible de charger le monde"); return EXIT_FAILURE; } Monde_Created = true; main_log->Write("Monde ok"); //Playermnager PlayerManager = new CPlayerManager(Irr_Device,SoundEngine,Word); //Creation du joueur local Player = new CPlayer(Irr_Device,SoundEngine,Word,GUI->Get_Name_STRW(),0,true); PlayerManager->Add_Player(Player); main_log->Write("Joueur ok"); irr::scene::ICameraSceneNode *cam = SceneManager->addCameraSceneNodeFPS(); cam->setPosition(irr::core::vector3df(0,10,0)); irr::scene::ISceneNodeAnimator *colli_cam = SceneManager->createCollisionResponseAnimator(Word->Word_MetaSelector,cam,irr::core::vector3df(7,15,7), irr::core::vector3df(0,0,0), irr::core::vector3df(0,0,0)); cam->addAnimator(colli_cam); colli_cam->drop(); cam->setFarValue(40000.0f); cam->setNearValue(0.1f); } PlayerManager->Update(); irr::core::line3d rayon; rayon.start = Player->Get_Position(); rayon.end = rayon.start + irr::core::vector3df(0,-100,0); VideoDriver->draw3DLine(rayon.start,rayon.end,irr::video::SColor(255,255,0,0)); main_log->Write("Player P: %f,%f,%f",Player->Get_APosition().X,Player->Get_APosition().Y,Player->Get_APosition().Z); main_log->Write("Ray P: %f,%f,%f",rayon.start.X,rayon.start.Y,rayon.start.Z); } if(EventReceiver->IsKeyDown(irr::KEY_ESCAPE)) { Irr_Device->closeDevice(); } //Irr_Device->sleep(1); GUIEnv->drawAll(); VideoDriver->endScene(); } else { Irr_Device->yield(); } } VideoDriver->removeAllTextures(); SoundEngine->drop(); Irr_Device->drop(); return EXIT_SUCCESS; }