| 1 | /*! | 
|---|
| 2 |  * @file game_world.h | 
|---|
| 3 |  *  container for all game worlds (singleplayers, multiplayers..) | 
|---|
| 4 |  */ | 
|---|
| 5 |  | 
|---|
| 6 | #ifndef _GAME_WORLD_H | 
|---|
| 7 | #define _GAME_WORLD_H | 
|---|
| 8 |  | 
|---|
| 9 |  | 
|---|
| 10 | #include "story_entity.h" | 
|---|
| 11 | #include "game_world_data.h" | 
|---|
| 12 | #include "playable.h" | 
|---|
| 13 | #include "script_manager.h" | 
|---|
| 14 |  | 
|---|
| 15 | namespace OrxShell { class Shell; }; | 
|---|
| 16 | class WorldEntity; | 
|---|
| 17 | class GameRules; | 
|---|
| 18 |  | 
|---|
| 19 |  | 
|---|
| 20 | /** How many frames time values to keep | 
|---|
| 21 |  * The higher the value the smoother the result is... | 
|---|
| 22 |  * Don't make it 0 or less :) | 
|---|
| 23 |  */ | 
|---|
| 24 | #define TICK_SMOOTH_VALUE 10 | 
|---|
| 25 |  | 
|---|
| 26 | //! The game world | 
|---|
| 27 | /** | 
|---|
| 28 |  *  this class initializes everything that should be displayed inside of the current level. | 
|---|
| 29 |  *  it is the main driving factor during gameplay. | 
|---|
| 30 |  */ | 
|---|
| 31 | class GameWorld : public StoryEntity | 
|---|
| 32 | { | 
|---|
| 33 |   ObjectListDeclaration(GameWorld); | 
|---|
| 34 |  | 
|---|
| 35 | public: | 
|---|
| 36 |   GameWorld (); | 
|---|
| 37 |   virtual ~GameWorld (); | 
|---|
| 38 |  | 
|---|
| 39 |   virtual void loadParams(const TiXmlElement* root); | 
|---|
| 40 |  | 
|---|
| 41 |   /* functions from story-entity */ | 
|---|
| 42 |   virtual ErrorMessage init(); | 
|---|
| 43 |   virtual ErrorMessage loadData(); | 
|---|
| 44 |   virtual ErrorMessage unloadData(); | 
|---|
| 45 |  | 
|---|
| 46 |   virtual bool start(); | 
|---|
| 47 |   virtual bool stop(); | 
|---|
| 48 |   virtual bool pause(); | 
|---|
| 49 |   virtual bool resume(); | 
|---|
| 50 |   virtual void run(); | 
|---|
| 51 |  | 
|---|
| 52 |   void showText(const std::string& text); | 
|---|
| 53 |   void setPlaymode(Playable::Playmode playmode); | 
|---|
| 54 |   void setPlaymode(const std::string& playmode); | 
|---|
| 55 |   /**  this returns the current game time @returns elapsed game time     */ | 
|---|
| 56 |   inline double getGameTime() { return this->gameTime; } | 
|---|
| 57 |   /** sets the game speed @param speed speed of the Game */ | 
|---|
| 58 |   inline void setSpeed(float speed) { this->speed = speed; }; | 
|---|
| 59 |   /**  returns the track path of this world @returns the track path */ | 
|---|
| 60 |  | 
|---|
| 61 |  | 
|---|
| 62 |   void setSoundtrack(const std::string& soundTrack); | 
|---|
| 63 |   void togglePNodeVisibility(); | 
|---|
| 64 |   void toggleBVVisibility(int level); | 
|---|
| 65 |   inline void toggleMPVisibility() { this->showMPV = !this->showMPV; } | 
|---|
| 66 |  | 
|---|
| 67 |   inline void setSky(WorldEntity* sky) { this->dataTank->sky = sky; } | 
|---|
| 68 |  | 
|---|
| 69 |  | 
|---|
| 70 | protected: | 
|---|
| 71 |   /* world - running functions */ | 
|---|
| 72 |   virtual void synchronize(); | 
|---|
| 73 |   virtual void handleInput(); | 
|---|
| 74 |   virtual void tick(ObjectManager::EntityList worldEntity, float dt); | 
|---|
| 75 |   virtual void tick(); | 
|---|
| 76 |   virtual void update(); | 
|---|
| 77 |   virtual void checkAI(); | 
|---|
| 78 |   virtual void checkGameRules(); | 
|---|
| 79 |   virtual void collisionDetection(); | 
|---|
| 80 |   virtual void collisionReaction(); | 
|---|
| 81 |  | 
|---|
| 82 |   void applyCameraSettings(); | 
|---|
| 83 |   void drawEntityList(const ObjectManager::EntityList& drawList ) const; | 
|---|
| 84 |   virtual void renderPassReflection(); | 
|---|
| 85 |   virtual void renderPassRefraction(); | 
|---|
| 86 |   virtual void renderPassAll(); | 
|---|
| 87 |  | 
|---|
| 88 |  | 
|---|
| 89 |   virtual void display(); | 
|---|
| 90 |  | 
|---|
| 91 |  | 
|---|
| 92 | private: | 
|---|
| 93 |   void displayLoadScreen(); | 
|---|
| 94 |   void releaseLoadScreen(); | 
|---|
| 95 |  | 
|---|
| 96 |  | 
|---|
| 97 | protected: | 
|---|
| 98 |   GameWorldData*      dataTank;                     //!< reference to the GameWorld Data Tank | 
|---|
| 99 |   TiXmlElement*       dataXML;                      //!< The XML-Element this World has been loaded with. | 
|---|
| 100 |  | 
|---|
| 101 |   bool                showPNodes;                   //!< if the PNodes should be visible. | 
|---|
| 102 |   bool                showBV;                       //!< if the Bounding Volumes should be visible. | 
|---|
| 103 |   int                 showBVLevel;                  //!< the depth level of the displayed bounding volumes | 
|---|
| 104 |   bool                showMPV;                      //!< true if the mounting points should be drawn for debug purposes | 
|---|
| 105 |  | 
|---|
| 106 |   /* world timing */ | 
|---|
| 107 |   double              lastFrame;                    //!< last time of frame (in MiliSeconds) | 
|---|
| 108 |   Uint32              cycle;                        //!< The cycle we are in (starts with 0 and rises with every frame) | 
|---|
| 109 |   float               dtS;                          //!< The time needed for caluculations in seconds | 
|---|
| 110 |   float               speed;                        //!< how fast the game flows | 
|---|
| 111 |   double              gameTime;                     //!< this is where the game time is saved | 
|---|
| 112 |   double              frameTimes[TICK_SMOOTH_VALUE];//!< The time used for the last TICK_SMOOTH_VALUE's frames. | 
|---|
| 113 |  | 
|---|
| 114 |   GameRules*          gameRules;                    //!< Pointer to the data structure containig the game rules | 
|---|
| 115 |  | 
|---|
| 116 | private: | 
|---|
| 117 |   /* external modules interfaces */ | 
|---|
| 118 |   ScriptManager       scriptManager; | 
|---|
| 119 |   OrxShell::Shell*    shell; | 
|---|
| 120 | }; | 
|---|
| 121 |  | 
|---|
| 122 | #endif /* _GAME_WORLD_H */ | 
|---|