1 /** @file def_main.h Definition subsystem. 2 * @ingroup defs 3 * 4 * @authors Copyright © 2003-2017 Jaakko Keränen <jaakko.keranen@iki.fi> 5 * @authors Copyright © 2006-2015 Daniel Swanson <danij@dengine.net> 6 * 7 * @par License 8 * GPL: http://www.gnu.org/licenses/gpl.html 9 * 10 * <small>This program is free software; you can redistribute it and/or modify 11 * it under the terms of the GNU General Public License as published by the 12 * Free Software Foundation; either version 2 of the License, or (at your 13 * option) any later version. This program is distributed in the hope that it 14 * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 15 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 16 * Public License for more details. You should have received a copy of the GNU 17 * General Public License along with this program; if not, write to the Free 18 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 19 * 02110-1301 USA</small> 20 */ 21 22 #ifndef DEFINITIONS_MAIN_H 23 #define DEFINITIONS_MAIN_H 24 25 #ifndef __cplusplus 26 # error "def_main.h requires C++" 27 #endif 28 29 #include <vector> 30 #include <de/String> 31 #include <doomsday/defs/ded.h> // ded_t 32 #include <doomsday/defs/dedtypes.h> 33 #include <doomsday/uri.h> 34 35 template <typename PODType> 36 struct Array : public std::vector<PODType> 37 { ArrayArray38 Array() : _elements(0) {} isEmptyArray39 bool isEmpty() const { 40 return !size(); 41 } sizeArray42 int size() const { 43 return (int) std::vector<PODType>::size(); 44 } clearArray45 void clear() { 46 _elements = nullptr; 47 std::vector<PODType>::clear(); 48 } 49 PODType *append(int count = 1) { 50 DENG2_ASSERT(count >= 0); 51 for(int i = 0; i < count; ++i) { 52 std::vector<PODType>::push_back(PODType()); 53 } 54 if(!isEmpty()) { 55 _elements = &(*this)[0]; 56 return &_elements[size() - count]; 57 } 58 return nullptr; 59 } 60 /// Determine the index of element @a elem. Performance is O(1). indexOfArray61 int indexOf(PODType const *elem) const { 62 if (!elem) return 0; 63 int index = elem - elements(); 64 if (index < 0 || index >= size()) return 0; // Not in this array. 65 return index; 66 } elementsArray67 PODType *elements() { 68 return _elements; 69 } elementsArray70 PODType const *elements() const { 71 return _elements; 72 } elementsPtrArray73 PODType **elementsPtr() { 74 return &_elements; 75 } 76 private: 77 PODType *_elements; 78 }; 79 80 struct xgclass_s; ///< @note The actual classes are on game side. 81 82 struct sfxinfo_t 83 { 84 void *data; ///< Pointer to sound data. 85 lumpnum_t lumpNum; 86 char lumpName[9]; ///< Actual lump name of the sound (full name). 87 char id[32]; ///< Identifier name (from the def). 88 char name[32]; ///< Long name. 89 sfxinfo_t *link; ///< Link to another sound. 90 int linkPitch; 91 int linkVolume; 92 int priority; 93 int channels; ///< Max. channels for the sound to occupy. 94 int usefulness; ///< Used to determine when to cache out. 95 int flags; 96 int group; 97 ddstring_t external; ///< Path to external file. 98 }; 99 100 struct stateinfo_t 101 { 102 mobjinfo_t *owner; 103 ded_light_t *light; 104 ded_ptcgen_t *ptcGens; 105 }; 106 107 /** 108 * Definitions that have been preprocessed for runtime use. Some of these are 109 * visible to the games via the InternalData API. 110 */ 111 struct RuntimeDefs 112 { 113 Array<mobjinfo_t> mobjInfo; ///< Map object info database. 114 Array<state_t> states; ///< State list. 115 Array<stateinfo_t> stateInfo; 116 Array<sfxinfo_t> sounds; ///< Sound effect list. 117 Array<ddtext_t> texts; ///< Text string list. 118 119 void clear(); 120 }; 121 122 extern RuntimeDefs runtimeDefs; 123 124 /** 125 * Register the console commands and/or variables of this module. 126 */ 127 void Def_ConsoleRegister(); 128 129 /** 130 * Initializes the definition databases. 131 */ 132 void Def_Init(); 133 134 /** 135 * Destroy databases. 136 */ 137 void Def_Destroy(); 138 139 /** 140 * Finish definition database initialization. Initialization is split into two 141 * phases either side of the texture manager, this being the post-phase. 142 */ 143 void Def_PostInit(); 144 145 /** 146 * Reads the specified definition files, and creates the sprite name, 147 * state, mobjinfo, sound, music, text and mapinfo databases accordingly. 148 */ 149 void Def_Read(); 150 151 de::String Def_GetStateName(state_t const *state); 152 153 /** 154 * Can we reach 'snew' if we start searching from 'sold'? 155 * Take a maximum of 16 steps. 156 */ 157 bool Def_SameStateSequence(state_t *snew, state_t *sold); 158 159 ded_compositefont_t *Def_GetCompositeFont(char const *uri); 160 ded_ptcgen_t *Def_GetGenerator(struct uri_s const *uri); 161 ded_ptcgen_t *Def_GetGenerator(de::Uri const &uri); 162 ded_ptcgen_t *Def_GetDamageGenerator(int mobjType); 163 ded_light_t *Def_GetLightDef(int spr, int frame); 164 165 state_t *Def_GetState(int num); 166 167 /** 168 * Gets information about a defined sound. Linked sounds are resolved. 169 * 170 * @param soundId ID number of the sound. 171 * @param freq Defined frequency for the sound is returned here. May be @c nullptr. 172 * @param volume Defined volume for the sound is returned here. May be @c nullptr. 173 * 174 * @return Sound info (from definitions). 175 */ 176 sfxinfo_t *Def_GetSoundInfo(int soundId, float *freq, float *volume); 177 178 /** 179 * Returns @c true if the given @a soundId is defined as a repeating sound. 180 */ 181 bool Def_SoundIsRepeating(int soundId); 182 183 /** 184 * @return @c true= the definition was found. 185 */ 186 int Def_Get(int type, char const *id, void *out); 187 188 /** 189 * This is supposed to be the main interface for outside parties to 190 * modify definitions (unless they want to do it manually with dedfile.h). 191 */ 192 int Def_Set(int type, int index, int value, void const *ptr); 193 194 #endif // DEFINITIONS_MAIN_H 195