blob: 79e4a6cf439f1fe44160a31afd4d70a494cf89dc (
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
|
/*
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;
}
/* ---- Zone class ----------------------------------------- */
/// create a new zone
Zone(std::string const & label);
/// create a zone from stream data
Zone(std::istream & is);
/// delete a zone
virtual ~Zone();
/* ---- inspectors ----------------------------------------- */
/// print the content of a zone
void print();
/// zone id
inline unsigned int id() const {
return zone_id;
}
/// 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
inline Entity *default_view() {
return zone_defaultview;
}
/// 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 ------------------------------------------- */
/// set the skybox name
inline void set_sky(std::string const & sky) {
zone_sky.assign(sky);
}
/// set the ambient light color
inline void set_ambient_color(const math::Color & ambient_color) {
zone_ambient_color.assign(ambient_color);
}
/// set the ambient light color
inline void set_ambient_color(float r, float g, float b) {
zone_ambient_color.assign(r, g, b);
}
/// 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);
/// 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;
std::string zone_sky;
math::Color zone_ambient_color;
Content zone_content;
static Registry zone_registry;
Entity *zone_defaultview;
btAxisSweep3 *zone_bullet_cache;
btDiscreteDynamicsWorld *zone_bullet_world;
btVehicleRaycaster *zone_bullet_raycaster;
math::BoundingBox3f zone_keepalive_box;
bool zone_keepalive_run;
};
}
#endif // __INCLUDED_CORE_ZONE_H__
|