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