Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
blob: 860c8714cebd67a4cce15f858943048491f76b30 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
/*
   core/zone.h
   This file is part of the Osirion project and is distributed under
   the terms of the GNU General Public License version 2
*/

#ifndef __INCLUDED_CORE_ZONE_H__
#define __INCLUDED_CORE_ZONE_H__

#include <string>
#include <list>
#include <map>

namespace core
{

class Zone;

}

#include "core/entity.h"
#include "core/physics.h"

namespace core
{

/// a Zone contains a compartment of the game universe
class Zone : public Label
{
public:
	/// type definition for the content of a zone
	typedef std::list<Entity *> Content;

	/// type definition for the zone registry
	typedef std::map<unsigned int, Zone *> Registry;

	/* ---- static functions ----------------------------------- */

	/// add a zone to the zone registry
	static void add(Zone *zone);

	/// add a zone with a specific id to the registry
	static void add(Zone *zone, unsigned int id);

	/// find a zone in the zone registry
	static Zone *find(unsigned int id);

	/// find a zone in the zone registry
	static Zone *find(std::string const & name);

	/// remove a zone from the zone registry
	static void remove(Zone *zone);

	/// list the zone registry
	static void list();

	/// search the zone registry for an id, label or name
	static Zone *search(std::string const & searchname);

	/// clear the zone registry
	static void clear();

	/// the zone registry
	static inline Registry & registry() {
		return zone_registry;
	}
	
	/// default infotype for zones
	static inline const InfoType *infotype() {
		return zone_infotype;
	}
	
	/// set the default infotype for zones
	static inline void set_infotype(const InfoType *infotype) {
		zone_infotype = infotype;
	}

	/* ---- Zone class ----------------------------------------- */
	
	enum Flags { Hidden = 1 };

	/**
	 * @brief create a new zone
	 * This is a server-side constructor
	 * */
	Zone(std::string const & label);

	/**
	 * @brief create a zone from stream data
	 * This is a client-side constructor
	 * */
	Zone(std::istream & is);

	/**
	 * @brief default destructor
	 * */
	virtual ~Zone();

	/* ---- inspectors ----------------------------------------- */

	/// print the content of a zone
	void print();

	/// zone id
	inline unsigned int id() const {
		return zone_id;
	}
	
	/// zone flags
	inline const unsigned int flags() const {
		return zone_flags;
	}

	/**
	 * @brief returns true if a specified flag is set
	 * */
	inline const bool has_flag(const Flags flag) const {
		return ((zone_flags & (unsigned int) flag) == (unsigned int) flag);
	}

	/// ambient light color
	inline math::Color const & ambient_color() {
		return zone_ambient_color;
	}
	
	/// name of the skybox
	inline std::string const & sky() const {
		return zone_sky;
	}

	/// default zone view, returns 0 if not set
	inline Entity *default_view() {
		return zone_defaultview;
	}
	
	/// zone information record, returns 0 if not set
	inline const Info *info() const {
		return zone_info;
	}
	
	/**
	 * @brief return the zone's color
	 * This is the color used to represent the zone on the galactic map
	 * */
	const math::Color & color() const {
		return zone_color;
	}
	
	/**
	 * @brief returns the galactic location of this zone
	 * */
	const math::Vector3f & location() const {
		return zone_location;
	}

	/// find an entity inside a zone
	Entity *find_entity(const Entity *entity);

	/// find an entity inside a zone
	Entity *find_entity(unsigned int id);

	/// find a labeled entity inside a zone
	Entity *find_entity(const std::string & label);

	/// search for an entity inside a zone
	Entity *search_entity(const std::string & label);

	/* ---- mutators ------------------------------------------- */
	
	/**
	 * @brief set flag
	 * */
	inline void set_flag(Flags flag) {
		zone_flags |= (unsigned int) flag;
	}

	/**
	 * @brief unset flag
	 * */
	inline void unset_flag(Flags flag) {
		zone_flags &= ~((unsigned int) flag);
	}

	/**
	 * @brief set the skybox name
	 * */
	inline void set_sky(std::string const & sky) {
		zone_sky.assign(sky);
	}

	/**
	 * @brief set the ambient light color
	 * */
	inline void set_ambient_color(const math::Color & ambient_color) {
		zone_ambient_color.assign(ambient_color);
	}
	
	/**
	 * @brief set the ambient light color
	 * @param r red value [0-1]
	 * @param g green value [0-1]
	 * @param b blue value [0-1]
	 * */
	inline void set_ambient_color(float r, float g, float b) {
		zone_ambient_color.assign(r, g, b);
	}
	
	/**
	 * @brief set the default view for this zone
	 * */	
	inline void set_default_view(Entity *entity) {
		zone_defaultview = entity;
	}
	
	/**
	 * @brief set the galactic location for this zone
	 * */
	inline void set_location(float x, float y, float z) {
		zone_location.assign(x, y, z);
	}
	
	/**
	 * @brief set the galactic location for this zone
	 * */
	inline void set_location(const math::Vector3f & location) {
		zone_location.assign(location);
	}
	
	/**
	 * @brief set the information record for this zone
	 * */
	void set_info(const Info *info);
	
	/**
	 * @brief set the zone color
	 * */
	void set_color(const math::Color & color);
	
	void set_color(float r, float g, float b);
	
	/* ---- serializers ---------------------------------------- */

	/**
	 * @brief serialize the zone's state to a server-to-client update message on a stream
	 * */
	void serialize_server_update(std::ostream & os) const;

	/**
	 * @brief deserialize the zone's state from a server-to-client update message on a stream
	 * */
	void receive_server_update(std::istream &is);

	/* ---- zone content --------------------------------------- */

	/// the entities belonging to this zone
	inline Content & content() {
		return zone_content;
	}

	/// add an entity to this zone
	void add(Entity *entity);

	/// remove an entity from this zone
	void remove(Entity *entity);

	/// physics world for this zone
	inline btDiscreteDynamicsWorld *physics() {
		return zone_bullet_world;
	}
	
	/// physics vehicle raycaster
	inline btVehicleRaycaster *raycaster() {
		return zone_bullet_raycaster;
	}
	
	math::BoundingBox3f & keepalive_box() {
		return zone_keepalive_box;
	}
	
	const bool keepalive_run() const {
		return zone_keepalive_run;
	}

	void set_keepalive_run(const bool keepalive_run) {
		zone_keepalive_run = keepalive_run;
	}
	
private:
	unsigned int		zone_id;
	unsigned int		zone_flags;
	math::Vector3f		zone_location;
	math::Color		zone_color;
	
	std::string		zone_sky;
	math::Color		zone_ambient_color;

	
	Content			zone_content;
	Entity			*zone_defaultview;
	
	btAxisSweep3		*zone_bullet_cache;
	btDiscreteDynamicsWorld *zone_bullet_world;
	btVehicleRaycaster	*zone_bullet_raycaster;
	
	math::BoundingBox3f	zone_keepalive_box;
	bool			zone_keepalive_run;
	
	const Info*		zone_info;
	
	static const InfoType 	*zone_infotype;
	static Registry		zone_registry;
};

}

#endif // __INCLUDED_CORE_ZONE_H__