[2190] | 1 | /*! |
---|
| 2 | \file world.h |
---|
| 3 | \brief Holds and manages all game data |
---|
| 4 | */ |
---|
[1853] | 5 | |
---|
[3224] | 6 | #ifndef _WORLD_H |
---|
| 7 | #define _WORLD_H |
---|
[1853] | 8 | |
---|
[2190] | 9 | #include "stdincl.h" |
---|
[2636] | 10 | #include "story_entity.h" |
---|
[2190] | 11 | |
---|
[2636] | 12 | |
---|
| 13 | |
---|
[2190] | 14 | class Track; |
---|
[2077] | 15 | class WorldEntity; |
---|
[2636] | 16 | class Camera; |
---|
[1883] | 17 | |
---|
[2190] | 18 | //! The game environment |
---|
[2636] | 19 | class World : public StoryEntity { |
---|
[1853] | 20 | |
---|
| 21 | public: |
---|
[2636] | 22 | World (char* name); |
---|
| 23 | World (int worldID); |
---|
[3221] | 24 | virtual ~World (); |
---|
[1853] | 25 | |
---|
[2636] | 26 | template<typename T> |
---|
[3225] | 27 | T* spawn (Location* loc, WorldEntity* owner); // template to be able to spawn any derivation of WorldEntity |
---|
[2636] | 28 | template<typename T> |
---|
[3225] | 29 | T* spawn (Placement* plc, WorldEntity* owner); |
---|
[2636] | 30 | |
---|
[3225] | 31 | virtual ErrorMessage init (); |
---|
| 32 | virtual ErrorMessage start (); |
---|
| 33 | virtual ErrorMessage stop (); |
---|
| 34 | virtual ErrorMessage pause (); |
---|
| 35 | virtual ErrorMessage resume (); |
---|
[1917] | 36 | |
---|
[3225] | 37 | virtual void load (); |
---|
| 38 | virtual void destroy (); |
---|
[2636] | 39 | |
---|
[3225] | 40 | void timeSlice (Uint32 deltaT); |
---|
[2636] | 41 | void collide (); |
---|
| 42 | void draw (); |
---|
| 43 | void update (); // maps Locations to Placements |
---|
[3225] | 44 | void calcCameraPos (Location* loc, Placement* plc); |
---|
[2190] | 45 | |
---|
[2636] | 46 | void unload (); |
---|
[3225] | 47 | bool command (Command* cmd); |
---|
[2636] | 48 | |
---|
[3225] | 49 | void setTrackLen (Uint32 tracklen); |
---|
| 50 | int getTrackLen (); |
---|
[3216] | 51 | //bool system_command (Command* cmd); |
---|
[3225] | 52 | Camera* getCamera (); |
---|
[2644] | 53 | |
---|
[3225] | 54 | void spawn (WorldEntity* entity); |
---|
| 55 | void spawn (WorldEntity* entity, Location* loc); |
---|
| 56 | void spawn (WorldEntity* entity, Placement* plc); |
---|
[2644] | 57 | |
---|
[2822] | 58 | tList<WorldEntity>* entities; |
---|
[2636] | 59 | |
---|
| 60 | // base level data |
---|
| 61 | Track* track; |
---|
| 62 | Uint32 tracklen; // number of Tracks the World consist of |
---|
| 63 | Vector* pathnodes; |
---|
| 64 | Camera* localCamera; |
---|
| 65 | |
---|
[1883] | 66 | private: |
---|
[2636] | 67 | Uint32 lastFrame; //!> last time of frame |
---|
| 68 | bool bQuitOrxonox; //!> quit this application |
---|
| 69 | bool bQuitCurrentGame; //!> quit only the current game and return to menu |
---|
| 70 | bool bPause; |
---|
[1855] | 71 | |
---|
[2636] | 72 | char* worldName; |
---|
| 73 | int debugWorldNr; |
---|
[2731] | 74 | GLuint objectList; |
---|
[2636] | 75 | |
---|
[2640] | 76 | WorldEntity* localPlayer; |
---|
| 77 | |
---|
[3225] | 78 | void mainLoop (); |
---|
| 79 | void synchronize (); |
---|
[3226] | 80 | void handleInput (); |
---|
[3225] | 81 | void timeSlice (); |
---|
| 82 | void collision (); |
---|
| 83 | void display (); |
---|
| 84 | void debug (); |
---|
[2190] | 85 | }; |
---|
[1883] | 86 | |
---|
[2190] | 87 | /** |
---|
| 88 | \brief spawn a new WorldEntity at a Location |
---|
| 89 | \param loc: the Location where the Entity should be spawned |
---|
| 90 | \param owner: a pointer to the parent of the Entity |
---|
| 91 | \return a pointer to the new WorldEntity or NULL if there was an error |
---|
| 92 | |
---|
| 93 | You can use this function to spawn any derivation of WorldEntity you want, just specify the desired |
---|
| 94 | class within the template specification brackets. Do not attempt to spawn any classes that have NOT been |
---|
| 95 | derived from WorldEntity, you won't even be able to compile the code. Note that this version of spawn() |
---|
| 96 | works with both free and bound WorldEntities. |
---|
| 97 | */ |
---|
| 98 | template<typename T> T* World::spawn(Location* loc = NULL, WorldEntity* owner = NULL) |
---|
| 99 | { |
---|
[2640] | 100 | Location zeroloc; |
---|
| 101 | T* entity = new T(); |
---|
| 102 | entities->add ((WorldEntity*)entity, LIST_ADD_NEXT); |
---|
| 103 | if( loc == NULL) |
---|
| 104 | { |
---|
| 105 | zeroloc.dist = 0; |
---|
| 106 | zeroloc.part = 0; |
---|
| 107 | zeroloc.pos = Vector(); |
---|
| 108 | zeroloc.rot = Quaternion(); |
---|
| 109 | loc = &zeroloc; |
---|
| 110 | } |
---|
| 111 | entity->init (loc, owner); |
---|
| 112 | if (entity->bFree) |
---|
| 113 | { |
---|
| 114 | track[loc->part].map_coords( loc, entity->get_placement()); |
---|
| 115 | } |
---|
| 116 | entity->post_spawn (); |
---|
| 117 | return entity; |
---|
[2190] | 118 | } |
---|
[2077] | 119 | |
---|
[2190] | 120 | /** |
---|
| 121 | \brief spawn a new WorldEntity at a Placement |
---|
| 122 | \param lplc: the placement where the Entity should be spawned |
---|
| 123 | \param owner: a pointer to the parent of the Entity |
---|
| 124 | \return a pointer to the new WorldEntity or NULL if there was an error |
---|
| 125 | |
---|
| 126 | You can use this function to spawn any FREE derivation of WorldEntity you want, just specify the desired |
---|
| 127 | class within the template specification brackets. Do not attempt to spawn any classes that have NOT been |
---|
| 128 | derived from WorldEntity, you won't even be able to compile the code. Note that this version of spawn() |
---|
| 129 | works with free WorldEntities only, you will provoke an error message if you try to spawn a bound Entity with |
---|
| 130 | a Placement. |
---|
| 131 | */ |
---|
| 132 | template<typename T> T* World::spawn(Placement* plc, WorldEntity* owner = NULL) |
---|
| 133 | { |
---|
[2640] | 134 | T* entity = new T(); |
---|
| 135 | entities->add ((WorldEntity*)entity, LIST_ADD_NEXT); |
---|
| 136 | entity->init (plc, owner); |
---|
| 137 | if (!entity->bFree) |
---|
| 138 | { |
---|
| 139 | printf("Can't spawn unfree entity with placement\n"); |
---|
| 140 | entities->remove( (WorldEntity*)entity, LIST_FIND_FW); |
---|
| 141 | return NULL; |
---|
| 142 | } |
---|
| 143 | entity->post_spawn (); |
---|
| 144 | return entity; |
---|
[2190] | 145 | } |
---|
[1853] | 146 | |
---|
[3224] | 147 | #endif /* _WORLD_H */ |
---|