Advertisement
Guest User

Untitled

a guest
Dec 1st, 2013
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.66 KB | None | 0 0
  1. [code]
  2. /* Doom Sneak
  3. Copyright Johnathan M. Morgan
  4. This program comes with ABSOLUTELY NO WARRANTY; for details look under the 'credits' menu.
  5. This is free software, and you are welcome to redistribute it
  6. under certain conditions; again, look under the 'credits' menu. */
  7.  
  8. /* A sincere thanks to the Irrlicht 3D development team and community for making this program possible */
  9.  
  10. //Include files
  11. #include <irrlicht.h>
  12. #include <iostream>
  13. #include <string>
  14. #include <vector>
  15.  
  16. //Pragma comments to link up with .dlls
  17. #ifdef _IRR_WINDOWS_
  18. #pragma comment(lib, "Irrlicht.lib")
  19. #endif
  20.  
  21. //Namespaces
  22. using namespace irr;
  23.  
  24. //Game loop
  25. void Loop(video::E_DRIVER_TYPE driverSelect, bool abort)
  26. {
  27. if(!abort)
  28. {
  29. //Device handler
  30. IrrlichtDevice* videoDevice = createDevice(driverSelect, core::dimension2d<u32>(1260,720));
  31.  
  32. //If device is invalid or failed to load
  33. if(videoDevice == 0)
  34. {
  35. abort = true;
  36. }
  37.  
  38. //Set window caption
  39. videoDevice->setWindowCaption(L"Doom Sneak");
  40.  
  41. //Setup video driver, scene manager, and gui manager
  42. video::IVideoDriver* driver = videoDevice->getVideoDriver();
  43. scene::ISceneManager* sceneManager = videoDevice->getSceneManager();
  44. gui::IGUIEnvironment* guiEvn = videoDevice->getGUIEnvironment();
  45.  
  46. //Begin gameloop
  47. while(videoDevice->run())
  48. {
  49. driver->beginScene(true,true,video::SColor(110,100,100,50));
  50. driver->endScene();
  51. }
  52.  
  53. //cleanup
  54. videoDevice->drop();
  55. }
  56. }
  57.  
  58. //Driver Picker
  59. video::E_DRIVER_TYPE PickDriver(bool validSelect, video::E_DRIVER_TYPE driverSelect, bool abort)
  60. {
  61. char userSelect;
  62.  
  63. while(!validSelect)
  64. {
  65. //Display instructions
  66. printf("Please select a video driver \n");
  67. printf("OpenGL: O \n");
  68. printf("DirectX: X \n");
  69. printf("Software Default: S \n");
  70. printf("Abort: A \n");
  71.  
  72. //Take input and send it to lowercase
  73. std::cin >> userSelect;
  74. userSelect = tolower(userSelect);
  75.  
  76. //Switch for picking driver
  77. switch(userSelect)
  78. {
  79. case 'o': driverSelect = video::EDT_OPENGL; validSelect = true; break; //OpenGL picked
  80. case 'x': driverSelect = video::EDT_DIRECT3D9; validSelect = true; break; //DirectX picked
  81. case 's': driverSelect = video::EDT_SOFTWARE; validSelect = true; break; //Default driver
  82. case 'a': printf("Process aborted... \n"); abort = true; validSelect = true; break; //Abort
  83. default: printf("Error, Input invalid.. \n \n"); //Garbage entered, retry
  84. }
  85. }
  86.  
  87. return driverSelect;
  88. }
  89.  
  90. //Main app entry point
  91. int main()
  92. {
  93. //Video Driver
  94. video::E_DRIVER_TYPE driverSelect = video::EDT_NULL;
  95. //Is the user selection valid input?
  96. bool validSelect = false;
  97. //Abort boolean
  98. bool abort = false;
  99.  
  100.  
  101. //Pick checkpoint
  102. pick:
  103. //driverSelect will equal the return of PickDriver
  104. driverSelect = PickDriver(validSelect, driverSelect, abort);
  105. //Game loop
  106. Loop(driverSelect, abort);
  107.  
  108. //Input for user
  109. std::string input;
  110. //Is the input within our bounds?
  111. bool validInput = false;
  112.  
  113. while(!validInput && !abort)
  114. {
  115. //Print instructions
  116. printf("Play again with a different driver? \n");
  117. printf("Y/N \n");
  118.  
  119. //Get input
  120. std::getline(std::cin, input);
  121.  
  122. //Sanitized input string
  123. std::string sanitized;
  124.  
  125. //Convert input string to sanitized, all lowercase string
  126. for(int i = 0; i < input.length(); i++)
  127. {
  128. sanitized += tolower(input.c_str()[i]);
  129. }
  130.  
  131. if(sanitized == "y" || sanitized == "yes")
  132. {
  133. goto pick;
  134. }
  135. else if(sanitized == "n" || sanitized == "no")
  136. {
  137. validInput = true;
  138. }
  139. else
  140. {
  141. printf("Invalid input... \n \n");
  142. }
  143. }
  144.  
  145. //clear up dat buffer
  146. std::cin.ignore();
  147. //pause console
  148. std::cin.get();
  149. return 0;
  150. }
  151. [/code]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement