Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
blob: 4b64ffbb4c28a84143e754ca947412d185c4d6f5 (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
/*
   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"

namespace core
{

/// a Zone contains a compartment of the game universe
class Zone {
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);

	/// find a zone in the zone registry (searches on id and name)
	static Zone *find_zone(std::string const & searchname);

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

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

	/// list the content of a single zone
	static void list_zone(std::string const & searchname);

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

	/// the zone registry
	static inline Registry & registry() { return zone_registry; }
	
	/* ---- Zone class ----------------------------------------- */

	/// create a new zone
	Zone(std::string const & label);

	/// create a zone from stream data
	Zone(std::istream & is);

	/// delete a zone
	~Zone();

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

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

	/// zone label
	inline std::string const & label() const { return zone_label; }

	/// zone name
	inline std::string const & name() const { return zone_name; }

	/// the name of the texture to be used as sky for this zone
	inline std::string const & sky() const { return zone_sky; }

	/// texture id for the sky
	inline size_t sky_texture() const { return zone_sky_texture; }

	/// default zone view
	inline Entity *default_view() {return zone_defaultview; }

	/// find an entity inside a zone
	Entity *find_entity(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);

	/* ---- mutators ------------------------------------------- */

	/// set the Zone label
	inline void set_label(std::string const & label) { zone_label.assign(label); }

	/// set the Zone label
	inline void set_name(std::string const & name) { zone_name.assign(name); }

	/// set the sky texture name to be used for this zone
	inline void set_sky(std::string const & sky) { zone_sky.assign(sky); }

	/// set the texture id for the sky
	inline void set_sky_texture(size_t texture) { zone_sky_texture = texture; }

	///set the default view
	inline void set_default_view(Entity *entity) { zone_defaultview = entity; }

	/* ---- serializers ---------------------------------------- */

	/// serialize a server-to-client update on a stream
	void serialize_server_update(std::ostream & os) const;

	/// receive a server-to-client update from 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);

private:
	unsigned int		zone_id;

	std::string		zone_label;
	std::string		zone_name;
	std::string		zone_sky;

	size_t			zone_sky_texture;

	Content			zone_content;
	static Registry		zone_registry;

	Entity			*zone_defaultview;
};

}

#endif // __INCLUDED_CORE_ZONE_H__