[2141] | 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 | |
---|
[2101] | 9 | #include "stdincl.h" |
---|
| 10 | |
---|
[2100] | 11 | class Track; |
---|
[2101] | 12 | class WorldEntity; |
---|
[2100] | 13 | |
---|
[2141] | 14 | //! The game environment |
---|
[1853] | 15 | class World { |
---|
| 16 | |
---|
| 17 | public: |
---|
| 18 | World (); |
---|
| 19 | ~World (); |
---|
| 20 | |
---|
[2101] | 21 | template<typename T> |
---|
| 22 | T* spawn(Location* loc, WorldEntity* owner); // template to be able to spawn any derivation of WorldEntity |
---|
| 23 | template<typename T> |
---|
| 24 | T* spawn(Placement* plc, WorldEntity* owner); |
---|
[1917] | 25 | |
---|
[2068] | 26 | void time_slice (Uint32 deltaT); |
---|
| 27 | void collide (); |
---|
| 28 | void draw (); |
---|
| 29 | void update (); // maps Locations to Placements |
---|
| 30 | void calc_camera_pos (Location* loc, Placement* plc); |
---|
| 31 | |
---|
[2080] | 32 | void unload (); |
---|
| 33 | |
---|
| 34 | void load_debug_level (); |
---|
| 35 | |
---|
[1883] | 36 | private: |
---|
[2068] | 37 | |
---|
| 38 | List<WorldEntity>* entities; |
---|
| 39 | |
---|
| 40 | // base level data |
---|
| 41 | Track* track; |
---|
| 42 | Uint32 tracklen; |
---|
| 43 | Vector* pathnodes; |
---|
[1855] | 44 | |
---|
[1853] | 45 | }; |
---|
| 46 | |
---|
[2141] | 47 | /** |
---|
| 48 | \brief spawn a new WorldEntity at a Location |
---|
| 49 | \param loc: the Location where the Entity should be spawned |
---|
| 50 | \param owner: a pointer to the parent of the Entity |
---|
| 51 | \return a pointer to the new WorldEntity or NULL if there was an error |
---|
| 52 | |
---|
| 53 | You can use this function to spawn any derivation of WorldEntity you want, just specify the desired |
---|
| 54 | class within the template specification brackets. Do not attempt to spawn any classes that have NOT been |
---|
| 55 | derived from WorldEntity, you won't even be able to compile the code. Note that this version of spawn() |
---|
| 56 | works with both free and bound WorldEntities. |
---|
| 57 | */ |
---|
[2101] | 58 | template<typename T> T* World::spawn(Location* loc = NULL, WorldEntity* owner = NULL) |
---|
| 59 | { |
---|
| 60 | Location zeroloc; |
---|
| 61 | T* entity = new T(); |
---|
| 62 | entities->add ((WorldEntity*)entity, LIST_ADD_NEXT); |
---|
| 63 | if( loc == NULL) |
---|
| 64 | { |
---|
| 65 | zeroloc.dist = 0; |
---|
| 66 | zeroloc.part = 0; |
---|
| 67 | zeroloc.pos = Vector(); |
---|
[2112] | 68 | zeroloc.rot = Quaternion(); |
---|
[2101] | 69 | loc = &zeroloc; |
---|
| 70 | } |
---|
| 71 | entity->init (loc, owner); |
---|
| 72 | if (entity->bFree) |
---|
| 73 | { |
---|
| 74 | track[loc->part].map_coords( loc, entity->get_placement()); |
---|
| 75 | } |
---|
| 76 | entity->post_spawn (); |
---|
| 77 | return entity; |
---|
| 78 | } |
---|
| 79 | |
---|
[2141] | 80 | /** |
---|
| 81 | \brief spawn a new WorldEntity at a Placement |
---|
| 82 | \param lplc: the placement where the Entity should be spawned |
---|
| 83 | \param owner: a pointer to the parent of the Entity |
---|
| 84 | \return a pointer to the new WorldEntity or NULL if there was an error |
---|
| 85 | |
---|
| 86 | You can use this function to spawn any FREE derivation of WorldEntity you want, just specify the desired |
---|
| 87 | class within the template specification brackets. Do not attempt to spawn any classes that have NOT been |
---|
| 88 | derived from WorldEntity, you won't even be able to compile the code. Note that this version of spawn() |
---|
| 89 | works with free WorldEntities only, you will provoke an error message if you try to spawn a bound Entity with |
---|
| 90 | a Placement. |
---|
| 91 | */ |
---|
[2101] | 92 | template<typename T> T* World::spawn(Placement* plc, WorldEntity* owner = NULL) |
---|
| 93 | { |
---|
| 94 | T* entity = new T(); |
---|
| 95 | entities->add ((WorldEntity*)entity, LIST_ADD_NEXT); |
---|
| 96 | entity->init (plc, owner); |
---|
| 97 | if (!entity->bFree) |
---|
| 98 | { |
---|
| 99 | printf("Can't spawn unfree entity with placement\n"); |
---|
| 100 | entities->remove( (WorldEntity*)entity, LIST_FIND_FW); |
---|
| 101 | return NULL; |
---|
| 102 | } |
---|
| 103 | entity->post_spawn (); |
---|
| 104 | return entity; |
---|
| 105 | } |
---|
| 106 | |
---|
[1853] | 107 | #endif |
---|