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