-
-
Notifications
You must be signed in to change notification settings - Fork 31
/
def_main.h
181 lines (159 loc) · 5.1 KB
/
def_main.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
/** @file def_main.h Definition subsystem.
*
* @ingroup defs
*
* @authors Copyright © 2003-2014 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2006-2015 Daniel Swanson <danij@dengine.net>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA</small>
*/
#ifndef DEFINITIONS_MAIN_H
#define DEFINITIONS_MAIN_H
#ifndef __cplusplus
# error "def_main.h requires C++"
#endif
#include <vector>
#include <de/String>
#include <doomsday/defs/ded.h> // ded_t
#include <doomsday/defs/dedtypes.h>
#include <doomsday/uri.h>
template <typename PODType>
struct Array : public std::vector<PODType>
{
Array() : _elements(0) {}
bool isEmpty() const {
return !size();
}
int size() const {
return std::vector<PODType>::size();
}
void clear() {
_elements = nullptr;
std::vector<PODType>::clear();
}
PODType *append(int count = 1) {
DENG2_ASSERT(count >= 0);
for(int i = 0; i < count; ++i) {
std::vector<PODType>::push_back(PODType());
}
if(!isEmpty()) {
_elements = &(*this)[0];
return &_elements[size() - count];
}
return nullptr;
}
/// Determine the index of element @a elem. Performance is O(1).
int indexOf(PODType const *elem) const {
if(!elem) return 0;
int index = elem - elements();
DENG_ASSERT(index >= 0 && index < size());
//if(index < 0 || index >= size()) return 0;
return index;
}
PODType *elements() {
return _elements;
}
PODType const *elements() const {
return _elements;
}
PODType **elementsPtr() {
return &_elements;
}
private:
PODType *_elements;
};
extern ded_t defs; ///< Main definitions database (internal).
struct xgclass_s; ///< @note The actual classes are on game side.
struct sfxinfo_t
{
void *data; ///< Pointer to sound data.
lumpnum_t lumpNum;
char lumpName[9]; ///< Actual lump name of the sound (full name).
char id[32]; ///< Identifier name (from the def).
char name[32]; ///< Long name.
sfxinfo_t *link; ///< Link to another sound.
int linkPitch;
int linkVolume;
int priority;
int channels; ///< Max. channels for the sound to occupy.
int usefulness; ///< Used to determine when to cache out.
int flags;
int group;
ddstring_t external; ///< Path to external file.
};
struct stateinfo_t
{
mobjinfo_t *owner;
ded_light_t *light;
ded_ptcgen_t *ptcGens;
};
/**
* Definitions that have been preprocessed for runtime use. Some of these are
* visible to the games via the InternalData API.
*/
struct RuntimeDefs
{
Array<mobjinfo_t> mobjInfo; ///< Map object info database.
Array<state_t> states; ///< State list.
Array<stateinfo_t> stateInfo;
Array<sfxinfo_t> sounds; ///< Sound effect list.
Array<ddtext_t> texts; ///< Text string list.
void clear();
};
extern RuntimeDefs runtimeDefs;
/**
* Register the console commands and/or variables of this module.
*/
void Def_ConsoleRegister();
/**
* Initializes the definition databases.
*/
void Def_Init();
/**
* Destroy databases.
*/
void Def_Destroy();
/**
* Finish definition database initialization. Initialization is split into two
* phases either side of the texture manager, this being the post-phase.
*/
void Def_PostInit();
/**
* Reads the specified definition files, and creates the sprite name,
* state, mobjinfo, sound, music, text and mapinfo databases accordingly.
*/
void Def_Read();
de::String Def_GetStateName(state_t const *state);
/**
* Can we reach 'snew' if we start searching from 'sold'?
* Take a maximum of 16 steps.
*/
bool Def_SameStateSequence(state_t *snew, state_t *sold);
ded_compositefont_t *Def_GetCompositeFont(char const *uri);
ded_ptcgen_t *Def_GetGenerator(struct uri_s const *uri);
ded_ptcgen_t *Def_GetGenerator(de::Uri const &uri);
ded_ptcgen_t *Def_GetDamageGenerator(int mobjType);
ded_light_t *Def_GetLightDef(int spr, int frame);
state_t *Def_GetState(int num);
/**
* @return @c true= the definition was found.
*/
int Def_Get(int type, char const *id, void *out);
/**
* This is supposed to be the main interface for outside parties to
* modify definitions (unless they want to do it manually with dedfile.h).
*/
int Def_Set(int type, int index, int value, void const *ptr);
#endif // DEFINITIONS_MAIN_H