Advertisement
HerveM

Main

May 7th, 2012
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.98 KB | None | 0 0
  1. //System
  2. #include "irrlicht.h"
  3. #include "irrklang.h"
  4. #include <iostream>
  5. #include <time.h>
  6.  
  7. //
  8. #include "CEventReceiver.h"
  9. #include "CPlayerManager.h"
  10. #include "CPlayer.h"
  11. #include "CSound.h"
  12. #include "CCamera.h"
  13. #include "CWord.h"
  14. #include "GUI/GUI.h"
  15.  
  16. #include "CLog.h"
  17.  
  18.  
  19. #ifdef _IRR_WINDOWS_
  20. #pragma comment(lib, "libIrrlicht.a")
  21. #pragma comment(lib, "libirrKlang.a")
  22. #pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")
  23. #endif
  24.  
  25. int main()
  26. {
  27.     CLog *main_log = new CLog("error.log");
  28.     main_log->Write("Intialisation ok");
  29.  
  30.     //Creaton d'un device en fullscreen pour recuperer la resolution
  31.     irr::IrrlichtDevice *nulldevice = irr::createDevice(irr::video::EDT_NULL);
  32.     if(!nulldevice)
  33.     {
  34.         main_log->Write("Impossible de recuperer la resolution");
  35.         return 1;
  36.     }
  37.     irr::core::dimension2d<irr::u32> deskres = nulldevice->getVideoModeList()->getDesktopResolution();
  38.     nulldevice->drop();
  39.  
  40.     //Creation du device avec la resolution de l'ecran
  41.     irr::IrrlichtDevice *Irr_Device = irr::createDevice(irr::video::EDT_OPENGL, deskres, 32, true, false, true);
  42.     if(!Irr_Device)
  43.     {
  44.         main_log->Write("Impossible de creer le Device");
  45.         return 1;
  46.     }
  47.  
  48.     //Ini de la GUI
  49.     CGUI *GUI = new CGUI(Irr_Device, deskres);
  50.  
  51.     //Ini de l'eventreceiver
  52.     CEventReceiver *EventReceiver = new CEventReceiver(Irr_Device, GUI);
  53.  
  54.     //Set de l'eventreceiver
  55.     Irr_Device->setEventReceiver(EventReceiver);
  56.  
  57.     //IA
  58.     srand(time(NULL));
  59.  
  60.     irr::video::IVideoDriver* VideoDriver = Irr_Device->getVideoDriver();
  61.     irr::scene::ISceneManager* SceneManager = Irr_Device->getSceneManager();
  62.     irr::gui::IGUIEnvironment* GUIEnv = Irr_Device->getGUIEnvironment();
  63.  
  64.     //Chargement de la police
  65.     irr::gui::IGUIFont* Font = GUIEnv->getFont("./media/fontcourier.bmp");
  66.  
  67.     //Corrige les probleme de transparence
  68.     SceneManager->getParameters()->setAttribute(irr::scene::ALLOW_ZWRITE_ON_TRANSPARENT, true);
  69.  
  70.     //Def Option rendu
  71.     irr::video::SMaterial m;
  72.     m.Lighting = false;
  73.     //m.ZBuffer = false;
  74.     VideoDriver->setMaterial(m);
  75.  
  76.     irr::core::matrix4 mat;
  77.     //VideoDriver->setTransform(irr::video::ETS_WORLD, mat);
  78.     VideoDriver->setTransform(irr::video::ETS_WORLD, irr::core::IdentityMatrix);
  79.  
  80.     //Moteur Sond
  81.     irrklang::ISoundEngine* SoundEngine = irrklang::createIrrKlangDevice();
  82.  
  83.     if(!SoundEngine)
  84.     {
  85.         main_log->Write("Impossible de creer le SoundDevice");
  86.         return EXIT_FAILURE;
  87.     }
  88.  
  89.     //CollisionManager
  90.     irr::scene::ISceneCollisionManager* Collision_Manager = SceneManager->getSceneCollisionManager();
  91.  
  92.     //Curseur desactiver
  93.     Irr_Device->getCursorControl()->setVisible(false);
  94.  
  95.     int lastFPS = -1;
  96.  
  97.     irr::u32 then = Irr_Device->getTimer()->getTime();
  98.  
  99.     const irr::f32 MOUV_SPEED = 5.f;
  100.  
  101.     CWord *Word;
  102.     CPlayer *Player;
  103.  
  104.     //PlayerManager
  105.     CPlayerManager *PlayerManager;
  106.  
  107.     while(Irr_Device->run())
  108.     {
  109.         if(Irr_Device->isWindowActive())
  110.         {
  111.             const irr::u32 now = Irr_Device->getTimer()->getTime();
  112.             const irr::f32 frameDeltaTime = (irr::f32)(now - then) / 1000.f;
  113.             then = now;
  114.  
  115.  
  116.             if(GUI->InGame)
  117.             {
  118.                 VideoDriver->beginScene(true, true, irr::video::SColor(255,0,0,0));
  119.             }
  120.  
  121.             SceneManager->drawAll();
  122.  
  123.             ////////////////////////////////////////////
  124.             //Introduction
  125.             ////////////////////////////////////////////
  126.             if(GUI->Intro)
  127.             {
  128.                 GUI->GIntro(frameDeltaTime);
  129.             }
  130.  
  131.             ////////////////////////////////////////////
  132.             //Introduction End
  133.             ////////////////////////////////////////////
  134.             ////////////////////////////////////////////
  135.             //Menu Begin
  136.             ////////////////////////////////////////////
  137.  
  138.             if(GUI->Menu_Principal)
  139.             {
  140.                 GUI->GMenu_Principal();
  141.             }
  142.  
  143.             ////////////////////////////////////////////
  144.             //Menu End
  145.             ////////////////////////////////////////////
  146.  
  147.             if(GUI->InGame)
  148.             {
  149.                 //Création de la GUI en InGame
  150.                 GUI->GInGame();
  151.                 //Affichage des box
  152.                 GUI->Graph_FPS->draw();
  153.                 GUI->Graph_Lat->draw();
  154.                 //Ajout des donnees
  155.                 GUI->Graph_FPS->addValue(VideoDriver->getFPS());
  156.                 GUI->Graph_Lat->addValue(VideoDriver->getPrimitiveCountDrawn());
  157.  
  158.                 if(!Monde_Created)
  159.                 {
  160.                     //Creation du word
  161.                     Word = new CWord(Irr_Device);
  162.                     if(!Word)
  163.                     {
  164.                         main_log->Write("Impossible de charger le monde");
  165.                         return EXIT_FAILURE;
  166.                     }
  167.                     Monde_Created = true;
  168.                     main_log->Write("Monde ok");
  169.  
  170.                     //Playermnager
  171.                     PlayerManager = new CPlayerManager(Irr_Device,SoundEngine,Word);
  172.  
  173.                     //Creation du joueur local
  174.                     Player = new CPlayer(Irr_Device,SoundEngine,Word,GUI->Get_Name_STRW(),0,true);
  175.                     PlayerManager->Add_Player(Player);
  176.                     main_log->Write("Joueur ok");
  177.  
  178.  
  179.                     irr::scene::ICameraSceneNode *cam = SceneManager->addCameraSceneNodeFPS();
  180.                     cam->setPosition(irr::core::vector3df(0,10,0));
  181.                     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));
  182.                     cam->addAnimator(colli_cam);
  183.                     colli_cam->drop();
  184.                     cam->setFarValue(40000.0f);
  185.                     cam->setNearValue(0.1f);
  186.                 }
  187.                 PlayerManager->Update();
  188.  
  189.  
  190.                 irr::core::line3d<irr::f32> rayon;
  191.  
  192.                 rayon.start = Player->Get_Position();
  193.                 rayon.end = rayon.start + irr::core::vector3df(0,-100,0);
  194.                 VideoDriver->draw3DLine(rayon.start,rayon.end,irr::video::SColor(255,255,0,0));
  195.  
  196.                 main_log->Write("Player P: %f,%f,%f",Player->Get_APosition().X,Player->Get_APosition().Y,Player->Get_APosition().Z);
  197.                 main_log->Write("Ray P: %f,%f,%f",rayon.start.X,rayon.start.Y,rayon.start.Z);
  198.  
  199.  
  200.             }
  201.             if(EventReceiver->IsKeyDown(irr::KEY_ESCAPE))
  202.             {
  203.                 Irr_Device->closeDevice();
  204.             }
  205.  
  206.             //Irr_Device->sleep(1);
  207.  
  208.             GUIEnv->drawAll();
  209.             VideoDriver->endScene();
  210.         }
  211.         else
  212.         {
  213.             Irr_Device->yield();
  214.         }
  215.  
  216.     }
  217.     VideoDriver->removeAllTextures();
  218.     SoundEngine->drop();
  219.     Irr_Device->drop();
  220.  
  221.     return EXIT_SUCCESS;
  222. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement