/
ieclass.h
376 lines (310 loc) · 9.72 KB
/
ieclass.h
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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
/**
* \defgroup eclass Entity class manager
* \file ieclass.h
* \brief Entity Class definition loader API.
* \ingroup eclass
*/
#pragma once
#include "ModResource.h"
#include "imodule.h"
#include "ifilesystem.h"
#include "math/Vector4.h"
#include <vector>
#include <list>
#include <map>
#include <memory>
#include <sigc++/signal.h>
/* FORWARD DECLS */
class Shader;
typedef std::shared_ptr<Shader> ShaderPtr;
class AABB;
/**
* Data structure representing a single attribute on an entity class.
*
* \ingroup eclass
*/
class EntityClassAttribute
{
private:
// Attribute type
std::string _type;
// Attribute name
std::string _name;
// Value
std::string _value;
// User-friendly description
std::string _desc;
public:
/**
* The key type (string, bool etc.).
*/
const std::string& getType() const
{
return _type;
}
void setType(const std::string& type)
{
_type = type;
}
/// The attribute key name, e.g. "model", "editor_displayFolder" etc
const std::string& getName() const
{
return _name;
}
/// Get attribute value
const std::string& getValue() const
{
return _value;
}
/// Set attribute value
void setValue(const std::string& value)
{
_value = value;
}
/// The help text associated with the key (in the DEF file).
const std::string& getDescription() const
{
return _desc;
}
void setDescription(const std::string& desc)
{
_desc = desc;
}
/// Construct an EntityClassAttribute
EntityClassAttribute(const std::string& type_,
const std::string& name_,
const std::string& value_,
const std::string& description_ = "")
: _type(type_),
_name(name_),
_value(value_),
_desc(description_)
{}
};
/**
* IEntityClass shared pointer.
*/
class IEntityClass;
typedef std::shared_ptr<IEntityClass> IEntityClassPtr;
typedef std::shared_ptr<const IEntityClass> IEntityClassConstPtr;
/**
* \brief Entity class interface.
*
* An entity class represents a single type of entity that can be created by
* the EntityCreator. Entity classes are parsed from .DEF files during startup.
*
* Entity class attribute names are compared case-insensitively, as in the
* Entity class.
*
* \ingroup eclass
*/
class IEntityClass :
public ModResource
{
public:
virtual ~IEntityClass() {}
/// Signal emitted when entity class contents are changed or reloaded
virtual sigc::signal<void>& changedSignal() = 0;
/// Get the name of this entity class
virtual const std::string& getName() const = 0;
/// Get the parent entity class or NULL if there is no parent
virtual const IEntityClass* getParent() const = 0;
/// Get the UI visibility of this entity class
virtual vfs::Visibility getVisibility() const = 0;
/// Query whether this entity class represents a light.
virtual bool isLight() const = 0;
/* ENTITY CLASS SIZE */
/// Query whether this entity has a fixed size.
virtual bool isFixedSize() const = 0;
/**
* Return an AABB representing the declared size of this entity. This is
* only valid for fixed size entities.
*
* @returns
* AABB enclosing the "editor_mins" and "editor_maxs" points defined in the
* entityDef.
*/
virtual AABB getBounds() const = 0;
/* ENTITY CLASS COLOURS */
/// Return the display colour of this entity class
virtual const Vector4& getColour() const = 0;
// Overrides the colour defined in the .def files
virtual void setColour(const Vector4& colour) = 0;
/* ENTITY CLASS ATTRIBUTES */
/**
* @brief Get the value of a specified attribute.
*
* @return std::string containing the attribute value, or an empty string if the attribute was
* not found.
*/
virtual std::string getAttributeValue(const std::string& name,
bool includeInherited = true) const = 0;
// Returns the attribute type string for the given name.
// This method will walk up the inheritance hierarchy until it encounters a type definition.
// If no type is found, an empty string will be returned.
virtual std::string getAttributeType(const std::string& name) const = 0;
// Returns the attribute description string for the given name.
// This method will walk up the inheritance hierarchy until it encounters a non-empty description.
virtual std::string getAttributeDescription(const std::string& name) const = 0;
/**
* Function that will be invoked by forEachAttribute.
*
* The function will be passed each EntityClassAttribute in turn, along
* with a bool indicating if this attribute is inherited from a parent
* entity class.
*/
using AttributeVisitor = std::function<void(const EntityClassAttribute&, bool)>;
/**
* Enumerate the EntityClassAttibutes in turn, including all inherited
* attributes.
*
* \param visitor
* Function that will be invoked for each EntityClassAttibute.
*
* \param editorKeys
* true if editor keys (those which start with "editor_") should be passed
* to the visitor, false if they should be skipped.
*/
virtual void forEachAttribute(AttributeVisitor visitor, bool editorKeys = false) const = 0;
/* MODEL AND SKIN */
/** Retrieve the model path for this entity.
*
* @returns
* The VFS model path, or the empty string if there is no model.
*/
virtual const std::string& getModelPath() const = 0;
/// Get the model skin, or the empty string if there is no skin.
virtual const std::string& getSkin() const = 0;
/**
* Returns true if this entity is of type or inherits from the
* given entity class name. className is treated case-sensitively.
*/
virtual bool isOfType(const std::string& className) = 0;
// Returns the mod-relative path to the file this DEF was declared in
virtual std::string getDefFileName() = 0;
};
/**
* Structure ontains the information of a model {} block as defined in a
* Doom3 .def file.
*
* \ingroup eclass
*/
class IModelDef :
public ModResource
{
public:
bool resolved;
std::string name;
std::string mesh;
std::string skin;
std::string parent;
typedef std::map<std::string, std::string> Anims;
Anims anims;
std::string modName;
// The mod-relative path to the file this DEF was declared in
std::string defFilename;
IModelDef() :
resolved(false),
modName("base")
{}
std::string getModName() const
{
return modName;
}
};
typedef std::shared_ptr<IModelDef> IModelDefPtr;
/**
* EntityClass visitor interface.
*
* \ingroup eclass
*/
class EntityClassVisitor
{
public:
virtual ~EntityClassVisitor() {}
virtual void visit(const IEntityClassPtr& eclass) = 0;
};
/**
* ModelDef visitor interface.
*
* \ingroup eclass
*/
class ModelDefVisitor
{
public:
virtual ~ModelDefVisitor() {}
virtual void visit(const IModelDefPtr& modelDef) = 0;
};
const char* const MODULE_ECLASSMANAGER("EntityClassManager");
/**
* EntityClassManager interface. The entity class manager is responsible for
* maintaining a list of available entity classes which the EntityCreator can
* insert into a map.
*
* \ingroup eclass
*/
class IEntityClassManager :
public RegisterableModule
{
public:
/// Signal emitted when starting to parse DEFs
virtual sigc::signal<void> defsLoadingSignal() const = 0;
/// Signal emitted when all DEFs have been loaded (after module initialisation)
virtual sigc::signal<void> defsLoadedSignal() const = 0;
/// Signal emitted when all DEFs are reloaded
virtual sigc::signal<void> defsReloadedSignal() const = 0;
/**
* Return the IEntityClass corresponding to the given name, creating it if
* necessary. If it is created, the has_brushes parameter will be used to
* determine whether the new entity class should be brush-based or not.
*
* @deprecated
* Use findClass() instead.
*/
virtual IEntityClassPtr findOrInsert(const std::string& name,
bool has_brushes) = 0;
/**
* Lookup an entity class by name. If the class is not found, a null pointer
* is returned.
*
* @param name
* Name of the entity class to look up.
*/
virtual IEntityClassPtr findClass(const std::string& name) = 0;
/**
* Iterate over all entity defs using the given visitor.
*/
virtual void forEachEntityClass(EntityClassVisitor& visitor) = 0;
virtual void realise() = 0;
virtual void unrealise() = 0;
/**
* greebo: This reloads the entityDefs and modelDefs from all files. Does not
* change the scenegraph, only the contents of the EClass objects are
* re-parsed. All IEntityClassPtrs remain valid, no entityDefs are removed.
*
* Note: This is NOT the same as unrealise + realise
*/
virtual void reloadDefs() = 0;
/**
* greebo: Finds the model def with the given name. Might return NULL if not found.
*/
virtual IModelDefPtr findModel(const std::string& name) = 0;
/**
* Iterate over each ModelDef using the given visitor class.
*/
virtual void forEachModelDef(ModelDefVisitor& visitor) = 0;
/**
* Iterate over each ModelDef using the given function object.
*/
virtual void forEachModelDef(const std::function<void(const IModelDefPtr&)>& functor) = 0;
};
/**
* Return the global EntityClassManager to the application.
*
* \ingroup eclass
*/
inline IEntityClassManager& GlobalEntityClassManager()
{
static module::InstanceReference<IEntityClassManager> _reference(MODULE_ECLASSMANAGER);
return _reference;
}