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