CDemo.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. // This is a Demo of the Irrlicht Engine (c) 2006 by N.Gebhardt.
  2. // This file is not documented.
  3. #ifndef __C_DEMO_H_INCLUDED__
  4. #define __C_DEMO_H_INCLUDED__
  5. #define USE_IRRKLANG
  6. //#define USE_SDL_MIXER
  7. // For windows 1.6 must be used for this demo unless you recompile the dlls and replace them,
  8. // however it is untested on windows with later versions
  9. // Include path in windows project by defaults assumes C:\irrlicht-1.6
  10. // 1.6 or higher may be used in linux
  11. // Get Irrlicht from http://irrlicht.sourceforge.net/ , it's a great engine
  12. #include <irrlicht.h>
  13. #define IRRLICHT_MEDIA_PATH "IrrlichtMedia/"
  14. #ifdef _WIN32__
  15. #include "WindowsIncludes.h" // Prevent 'fd_set' : 'struct' type redefinition
  16. #include <windows.h>
  17. #endif
  18. using namespace irr;
  19. // audio support
  20. // Included in RakNet download with permission by Nikolaus Gebhardt
  21. #ifdef USE_IRRKLANG
  22. #if defined(_WIN32__) || defined(WIN32) || defined(_WIN32)
  23. #include <irrKlang-1.1.3/irrKlang.h>
  24. #else
  25. #include "irrKlang.h"
  26. #endif
  27. #ifdef _IRR_WINDOWS_
  28. #pragma comment (lib, "irrKlang-1.1.3/irrKlang.lib")
  29. #endif
  30. #endif
  31. #ifdef USE_SDL_MIXER
  32. # include <SDL/SDL.h>
  33. # include <SDL/SDL_mixer.h>
  34. #endif
  35. const int CAMERA_COUNT = 7;
  36. const float CAMERA_HEIGHT=50.0f;
  37. const float SHOT_SPEED=.6f;
  38. const float BALL_DIAMETER=25.0f;
  39. // RakNet
  40. #include "RakNetStuff.h"
  41. #include "DS_Multilist.h"
  42. #include "RakString.h"
  43. #include "RakNetTime.h"
  44. class CDemo : public IEventReceiver
  45. {
  46. public:
  47. CDemo(bool fullscreen, bool music, bool shadows, bool additive, bool vsync, bool aa, video::E_DRIVER_TYPE driver, core::stringw &_playerName);
  48. ~CDemo();
  49. void run();
  50. virtual bool OnEvent(const SEvent& event);
  51. IrrlichtDevice * GetDevice(void) const {return device;}
  52. scene::ISceneManager* GetSceneManager(void) const {return device->getSceneManager();}
  53. // RakNet: Control what animation is playing by what key is pressed on the remote system
  54. bool IsKeyDown(EKEY_CODE keyCode) const;
  55. bool IsMovementKeyDown(void) const;
  56. // RakNet: Decouple the origin of the shot from the camera, so the network code can use this same graphical effect
  57. RakNet::TimeMS shootFromOrigin(core::vector3df camPosition, core::vector3df camAt);
  58. const core::aabbox3df& GetSyndeyBoundingBox(void) const;
  59. void PlayDeathSound(core::vector3df position);
  60. void EnableInput(bool enabled);
  61. private:
  62. void createLoadingScreen();
  63. void loadSceneData();
  64. void switchToNextScene();
  65. void shoot();
  66. void createParticleImpacts();
  67. bool fullscreen;
  68. bool music;
  69. bool shadows;
  70. bool additive;
  71. bool vsync;
  72. bool aa;
  73. video::E_DRIVER_TYPE driverType;
  74. core::stringw playerName;
  75. IrrlichtDevice *device;
  76. #ifdef USE_IRRKLANG
  77. void startIrrKlang();
  78. irrklang::ISoundEngine* irrKlang;
  79. irrklang::ISoundSource* ballSound;
  80. irrklang::ISoundSource* deathSound;
  81. irrklang::ISoundSource* impactSound;
  82. #endif
  83. #ifdef USE_SDL_MIXER
  84. void startSound();
  85. void playSound(Mix_Chunk *);
  86. void pollSound();
  87. Mix_Music *stream;
  88. Mix_Chunk *ballSound;
  89. Mix_Chunk *impactSound;
  90. #endif
  91. struct SParticleImpact
  92. {
  93. u32 when;
  94. core::vector3df pos;
  95. core::vector3df outVector;
  96. };
  97. int currentScene;
  98. video::SColor backColor;
  99. gui::IGUIStaticText* statusText;
  100. gui::IGUIInOutFader* inOutFader;
  101. scene::IQ3LevelMesh* quakeLevelMesh;
  102. scene::ISceneNode* quakeLevelNode;
  103. scene::ISceneNode* skyboxNode;
  104. scene::IAnimatedMeshSceneNode* model1;
  105. scene::IAnimatedMeshSceneNode* model2;
  106. scene::IParticleSystemSceneNode* campFire;
  107. scene::IMetaTriangleSelector* metaSelector;
  108. scene::ITriangleSelector* mapSelector;
  109. s32 sceneStartTime;
  110. s32 timeForThisScene;
  111. core::array<SParticleImpact> Impacts;
  112. // Per-tick game update for RakNet
  113. void UpdateRakNet(void);
  114. // Holds output messages
  115. DataStructures::Multilist<ML_QUEUE, RakNet::RakString> outputMessages;
  116. RakNet::TimeMS whenOutputMessageStarted;
  117. void PushMessage(RakNet::RakString rs);
  118. const char *GetCurrentMessage(void);
  119. // We use this array to store the current state of each key
  120. bool KeyIsDown[KEY_KEY_CODES_COUNT];
  121. // Bounding box of syndney.md2, extended by BALL_DIAMETER/2 for collision against shots
  122. core::aabbox3df syndeyBoundingBox;
  123. void CalculateSyndeyBoundingBox(void);
  124. bool isConnectedToNATPunchthroughServer;
  125. };
  126. #endif
粤ICP备19079148号