1 | /*! |
---|
2 | \file world.h |
---|
3 | \brief Holds and manages all game data |
---|
4 | */ |
---|
5 | |
---|
6 | #ifndef WORLD_H |
---|
7 | #define WORLD_H |
---|
8 | |
---|
9 | #include "stdincl.h" |
---|
10 | #include "story_entity.h" |
---|
11 | #include "track.h" |
---|
12 | |
---|
13 | |
---|
14 | |
---|
15 | class Track; |
---|
16 | class WorldEntity; |
---|
17 | class Camera; |
---|
18 | |
---|
19 | //! The game environment |
---|
20 | class World : public StoryEntity { |
---|
21 | |
---|
22 | public: |
---|
23 | World (char* name); |
---|
24 | World (int worldID); |
---|
25 | ~World (); |
---|
26 | |
---|
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(); |
---|
37 | |
---|
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); |
---|
45 | |
---|
46 | void unload (); |
---|
47 | |
---|
48 | void setTrackLen(Uint32 tracklen); |
---|
49 | int getTrackLen(); |
---|
50 | bool system_command (Command* cmd); |
---|
51 | Camera* getCamera(); |
---|
52 | |
---|
53 | void spawn(WorldEntity* entity); |
---|
54 | void spawn(WorldEntity* entity, Location* loc); |
---|
55 | void spawn(WorldEntity* entity, Placement* plc); |
---|
56 | |
---|
57 | tList<WorldEntity>* entities; |
---|
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 | |
---|
65 | private: |
---|
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; |
---|
70 | |
---|
71 | char* worldName; |
---|
72 | int debugWorldNr; |
---|
73 | GLuint objectList; |
---|
74 | |
---|
75 | WorldEntity* localPlayer; |
---|
76 | |
---|
77 | void mainLoop(); |
---|
78 | void synchronize(); |
---|
79 | void handle_input(); |
---|
80 | void time_slice(); |
---|
81 | void collision(); |
---|
82 | void display(); |
---|
83 | void debug(); |
---|
84 | }; |
---|
85 | |
---|
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 | { |
---|
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; |
---|
117 | } |
---|
118 | |
---|
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 | { |
---|
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; |
---|
144 | } |
---|
145 | |
---|
146 | #endif |
---|