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