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