1 /** @file ded.h  Definition namespace.
2  *
3  * @authors Copyright © 2003-2017 Jaakko Keränen <jaakko.keranen@iki.fi>
4  * @authors Copyright © 2006-2015 Daniel Swanson <danij@dengine.net>
5  *
6  * @par License
7  * GPL: http://www.gnu.org/licenses/gpl.html
8  *
9  * <small>This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by the
11  * Free Software Foundation; either version 2 of the License, or (at your
12  * option) any later version. This program is distributed in the hope that it
13  * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
15  * Public License for more details. You should have received a copy of the GNU
16  * General Public License along with this program; if not, see:
17  * http://www.gnu.org/licenses</small>
18  */
19 
20 #ifndef LIBDOOMSDAY_DEFINITION_DATABASE_H
21 #define LIBDOOMSDAY_DEFINITION_DATABASE_H
22 
23 #include <vector>
24 #include <de/libcore.h>
25 #include <de/Record>
26 #include <de/String>
27 #include <de/Vector>
28 #include "../uri.h"
29 
30 #include "dedtypes.h"
31 #include "dedregister.h"
32 
33 // Version 6 does not require semicolons.
34 #define DED_VERSION 6
35 
36 /**
37  * The ded_t structure encapsulates all the data one definition file can contain. This is
38  * only an internal representation of the data. An ASCII version is written and read by
39  * DED_Write() and DED_Read() routines.
40  *
41  * It is VERY important not to sort the data arrays in any way: the index numbers are
42  * important. The game plugins must be recompiled with the new constants if the order of the
43  * array items changes.
44  */
45 struct LIBDOOMSDAY_PUBLIC ded_s
46 {
47     de::Record names; ///< Namespace where definition values are stored.
48 
49     int version; // DED version number.
50 
51     ded_flags_t modelFlags; // Default values for models.
52     float       modelScale;
53     float       modelOffset;
54 
55     // Flag values (for all types of data).
56     DEDRegister flags;
57 
58     // Episodes.
59     DEDRegister episodes;
60 
61     // Map object information.
62     DEDRegister things; // DEDArray<ded_mobj_t> mobjs;
63 
64     // States.
65     DEDRegister states;
66 
67     // Sprites.
68     DEDArray<ded_sprid_t> sprites;
69 
70     // Lights.
71     DEDArray<ded_light_t> lights;
72 
73     // Materials.
74     DEDRegister materials;
75 
76     // Models.
77     DEDRegister models;
78 
79     // Skies.
80     DEDRegister skies;
81 
82     // Sounds.
83     DEDArray<ded_sound_t> sounds;
84 
85     // Music.
86     DEDRegister musics;
87 
88     // Map information.
89     DEDRegister mapInfos;
90 
91     // Text.
92     DEDArray<ded_text_t> text;
93 
94     // Aural environments for textures.
95     DEDArray<ded_tenviron_t> textureEnv;
96 
97     // Free-from string values.
98     DEDArray<ded_value_t> values;
99 
100     // Detail texture assignments.
101     DEDArray<ded_detailtexture_t> details;
102 
103     // Particle generators.
104     DEDArray<ded_ptcgen_t> ptcGens;
105 
106     // Finales.
107     DEDRegister finales;
108 
109     // Decorations.
110     DEDRegister decorations;
111 
112     // Reflections.
113     DEDArray<ded_reflection_t> reflections;
114 
115     // Animation/Precache groups for textures.
116     DEDArray<ded_group_t> groups;
117 
118     // XG line types.
119     DEDArray<ded_linetype_t> lineTypes;
120 
121     // XG sector types.
122     DEDArray<ded_sectortype_t> sectorTypes;
123 
124     // Composite fonts.
125     DEDArray<ded_compositefont_t> compositeFonts;
126 
127 public:
128     /**
129      * Constructor initializes everything to zero.
130      */
131     ded_s();
132 
133     void clear();
134 
135     int addFlag(de::String const &id, int value);
136 
137     int addEpisode();
138 
139     int addThing(de::String const &id);
140 
141     int addState(de::String const &id);
142 
143     int addDecoration();
144 
145     int addFinale();
146 
147     int addMapInfo();
148 
149     int addMaterial();
150 
151     int addModel();
152 
153     int addMusic();
154 
155     int addSky();
156 
157     int evalFlags(char const *ptr) const;
158 
159     int getEpisodeNum(de::String const &id) const;
160 
161     int getMapInfoNum(de::Uri const &uri) const;
162 
163     int getMaterialNum(de::Uri const &uri) const;
164 
165     int getMobjNum(de::String const &id) const;
166 
167     int getMobjNumForName(char const *name) const;
168 
169     de::String getMobjName(int num) const;
170 
171     int getModelNum(char const *id) const;
172 
173     int getMusicNum(char const *id) const;
174 
175     int getSkyNum(char const *id) const;
176 
177     int getSoundNum(char const *id) const;
178     int getSoundNum(de::String const &id) const;
179 
180     /**
181      * Looks up a sound using @a name key.
182      * @param name  Sound name.
183      * @return If the name is not found, returns the NULL sound index (zero).
184      */
185     int getSoundNumForName(char const *name) const;
186 
187     int getSpriteNum(char const *id) const;
188     int getSpriteNum(de::String const &id) const;
189 
190     int getStateNum(char const *id) const;
191     int getStateNum(de::String const &id) const;
192 
193     int getTextNum(char const *id) const;
194 
195     int getValueNum(char const *id) const;
196     int getValueNum(de::String const &id) const;
197 
198     ded_value_t *getValueById(char const *id) const;
199     ded_value_t *getValueById(de::String const &id) const;
200     ded_value_t *getValueByUri(de::Uri const &uri) const;
201 
202     ded_compositefont_t *findCompositeFontDef(de::Uri const &uri) const;
203     ded_compositefont_t *getCompositeFont(char const *uriCString) const;
204 
205     /**
206      * Finds the episode that has a specific map in it.
207      * @param mapId  Map identifier.
208      * @return Episode ID.
209      */
210     de::String findEpisode(de::String const &mapId) const;
211 
212 protected:
213     void release();
214 
215     DENG2_NO_ASSIGN(ded_s)
216     DENG2_NO_COPY  (ded_s)
217 };
218 
219 typedef ded_s ded_t;
220 
221 #ifdef __cplusplus
222 extern "C" {
223 #endif
224 
225 /**
226  * Returns the main definitions database.
227  */
228 LIBDOOMSDAY_PUBLIC ded_t *DED_Definitions();
229 
230 LIBDOOMSDAY_PUBLIC void DED_DestroyDefinitions();
231 
232 // Routines for managing DED files:
233 
234 int             DED_AddSprite(ded_t* ded, char const* name);
235 int             DED_AddLight(ded_t* ded, char const* stateID);
236 int             DED_AddSound(ded_t* ded, char const* id);
237 int             DED_AddText(ded_t* ded, char const* id);
238 int             DED_AddTextureEnv(ded_t* ded, char const* id);
239 int             DED_AddValue(ded_t *ded, char const* id);
240 int             DED_AddDetail(ded_t* ded, char const* lumpname);
241 int             DED_AddPtcGen(ded_t* ded, char const* state);
242 int             DED_AddPtcGenStage(ded_ptcgen_t* gen);
243 int             DED_AddReflection(ded_t* ded);
244 int             DED_AddGroup(ded_t* ded);
245 int             DED_AddGroupMember(ded_group_t* grp);
246 int             DED_AddSectorType(ded_t* ded, int id);
247 int             DED_AddLineType(ded_t* ded, int id);
248 int             DED_AddCompositeFont(ded_t* ded, char const* uri);
249 int             DED_AddCompositeFontMapCharacter(ded_compositefont_t* font);
250 
251 #ifdef __cplusplus
252 } // extern "C"
253 #endif
254 
255 #endif // LIBDOOMSDAY_DEFINITION_DATABASE_H
256