1 /** @file dedtypes.h Definition types and structures (DED v1). 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_TYPES_H 21 #define LIBDOOMSDAY_DEFINITION_TYPES_H 22 23 #include <vector> 24 #include <de/libcore.h> 25 #include <de/Vector> 26 #include <de/memory.h> 27 #include "../uri.h" 28 29 #include "dd_share.h" 30 #include "def_share.h" 31 #include "api_gl.h" 32 #include "dedarray.h" 33 34 #define DED_DUP_URI(u) u = (u ? new de::Uri(*u) : 0) 35 36 #define DED_SPRITEID_LEN 4 37 #define DED_STRINGID_LEN 31 38 #define DED_FUNC_LEN 255 39 40 #define DED_MAX_MATERIAL_LAYERS 1 ///< Maximum number of material layers (map renderer limitations). 41 #define DED_MAX_MATERIAL_DECORATIONS 16 ///< Maximum number of material decorations (arbitrary). 42 43 #define DED_PTCGEN_ANY_MOBJ_TYPE -2 ///< Particle generator applies to ANY mobj type. 44 45 typedef char ded_stringid_t[DED_STRINGID_LEN + 1]; 46 typedef ded_stringid_t ded_string_t; 47 typedef ded_stringid_t ded_mobjid_t; 48 typedef ded_stringid_t ded_stateid_t; 49 typedef ded_stringid_t ded_soundid_t; 50 typedef ded_stringid_t ded_funcid_t; 51 typedef char ded_func_t[DED_FUNC_LEN + 1]; 52 typedef int ded_flags_t; 53 typedef char * ded_anystring_t; 54 55 typedef struct LIBDOOMSDAY_PUBLIC ded_uri_s { 56 de::Uri *uri; 57 releaseded_uri_s58 void release() { delete uri; } reallocateded_uri_s59 void reallocate() { DED_DUP_URI(uri); } 60 } ded_uri_t; 61 62 #ifdef _MSC_VER 63 // MSVC needs some hand-holding. 64 template struct LIBDOOMSDAY_PUBLIC DEDArray<ded_uri_t>; 65 #endif 66 67 // Embedded sound information. 68 typedef struct ded_embsound_s { 69 ded_string_t name; 70 int id; // Figured out at runtime. 71 float volume; 72 } ded_embsound_t; 73 74 typedef struct LIBDOOMSDAY_PUBLIC ded_ptcstage_s { 75 ded_flags_t type; 76 int tics; 77 float variance; // Stage variance (time). 78 float color[4]; // RGBA 79 float radius; 80 float radiusVariance; 81 ded_flags_t flags; 82 float bounce; 83 float resistance; // Air resistance. 84 float gravity; 85 float vectorForce[3]; 86 float spin[2]; // Yaw and pitch. 87 float spinResistance[2]; // Yaw and pitch. 88 int model; 89 ded_string_t frameName; // For model particles. 90 ded_string_t endFrameName; 91 short frame, endFrame; 92 ded_embsound_t sound, hitSound; 93 94 void release() {} 95 void reallocate() {} 96 97 /** 98 * Takes care of consistent variance. 99 * Currently only used visually, collisions use the constant radius. 100 * The variance can be negative (results will be larger). 101 */ 102 float particleRadius(int ptcIDX) const; 103 } ded_ptcstage_t; 104 105 typedef struct { 106 char id[DED_SPRITEID_LEN + 1]; 107 108 void release() {} 109 } ded_sprid_t; 110 111 typedef struct { 112 char str[DED_STRINGID_LEN + 1]; 113 } ded_str_t; 114 115 typedef struct LIBDOOMSDAY_PUBLIC ded_light_s { 116 ded_stateid_t state; 117 char uniqueMapID[64]; 118 float offset[3]; /* Origin offset in world coords 119 Zero means automatic */ 120 float size; // Zero: automatic 121 float color[3]; // Red Green Blue (0,1) 122 float lightLevel[2]; // Min/max lightlevel for bias 123 ded_flags_t flags; 124 de::Uri * up, *down, *sides; 125 de::Uri * flare; 126 float haloRadius; // Halo radius (zero = no halo). 127 128 void release() 129 { 130 delete up; 131 delete down; 132 delete sides; 133 delete flare; 134 } 135 void reallocate() 136 { 137 DED_DUP_URI(up); 138 DED_DUP_URI(down); 139 DED_DUP_URI(sides); 140 DED_DUP_URI(flare); 141 } 142 } ded_light_t; 143 144 typedef struct LIBDOOMSDAY_PUBLIC ded_sound_s { 145 ded_soundid_t id; // ID of this sound, refered to by others. 146 ded_string_t name; // A tag name for the sound. 147 ded_string_t lumpName; // Actual lump name of the sound ("DS" not included). 148 de::Uri * ext; // External sound file (WAV). 149 ded_soundid_t link; // Link to another sound. 150 int linkPitch; 151 int linkVolume; 152 int priority; // Priority classification. 153 int channels; // Max number of channels to occupy. 154 int group; // Exclusion group. 155 ded_flags_t flags; // Flags (like chg_pitch). 156 157 void release() { delete ext; } 158 void reallocate() { DED_DUP_URI(ext); } 159 } ded_sound_t; 160 161 struct ded_text_t { 162 ded_stringid_t id; 163 char * text; 164 165 void release() { M_Free(text); } 166 167 void setText(char const *newTextToCopy) 168 { 169 release(); 170 text = M_StrDup(newTextToCopy); 171 } 172 }; 173 174 typedef struct { 175 ded_stringid_t id; 176 DEDArray<ded_uri_t> materials; 177 178 void release() { materials.clear(); } 179 } ded_tenviron_t; 180 181 typedef struct { 182 char *id; 183 char *text; 184 185 void release() 186 { 187 M_Free(id); 188 M_Free(text); 189 } 190 } ded_value_t; 191 192 typedef struct LIBDOOMSDAY_PUBLIC ded_linetype_s { 193 int id; 194 char comment[64]; 195 ded_flags_t flags[3]; 196 ded_flags_t lineClass; 197 ded_flags_t actType; 198 int actCount; 199 float actTime; 200 int actTag; 201 int aparm[9]; 202 ded_stringid_t aparm9; 203 float tickerStart; 204 float tickerEnd; 205 int tickerInterval; 206 ded_soundid_t actSound; 207 ded_soundid_t deactSound; 208 int evChain; 209 int actChain; 210 int deactChain; 211 int actLineType; 212 int deactLineType; 213 ded_flags_t wallSection; 214 de::Uri * actMaterial; 215 de::Uri * deactMaterial; 216 char actMsg[128]; 217 char deactMsg[128]; 218 float materialMoveAngle; 219 float materialMoveSpeed; 220 int iparm[20]; 221 char iparmStr[20][64]; 222 float fparm[20]; 223 char sparm[5][128]; 224 225 void release() 226 { 227 delete actMaterial; 228 delete deactMaterial; 229 } 230 void reallocate() 231 { 232 DED_DUP_URI(actMaterial); 233 DED_DUP_URI(deactMaterial); 234 } 235 } ded_linetype_t; 236 237 typedef struct LIBDOOMSDAY_PUBLIC ded_sectortype_s { 238 int id; 239 char comment[64]; 240 ded_flags_t flags; 241 int actTag; 242 int chain[5]; 243 ded_flags_t chainFlags[5]; 244 float start[5]; 245 float end[5]; 246 float interval[5][2]; 247 int count[5]; 248 ded_soundid_t ambientSound; 249 float soundInterval[2]; // min,max 250 float materialMoveAngle[2]; // floor, ceil 251 float materialMoveSpeed[2]; // floor, ceil 252 float windAngle; 253 float windSpeed; 254 float verticalWind; 255 float gravity; 256 float friction; 257 ded_func_t lightFunc; 258 int lightInterval[2]; 259 ded_func_t colFunc[3]; // RGB 260 int colInterval[3][2]; 261 ded_func_t floorFunc; 262 float floorMul, floorOff; 263 int floorInterval[2]; 264 ded_func_t ceilFunc; 265 float ceilMul, ceilOff; 266 int ceilInterval[2]; 267 268 void release() {} 269 void reallocate() {} 270 } ded_sectortype_t; 271 272 typedef struct LIBDOOMSDAY_PUBLIC ded_detail_stage_s { 273 int tics; 274 float variance; 275 de::Uri *texture; // The file/lump with the detail texture. 276 float scale; 277 float strength; 278 float maxDistance; 279 280 void release() { delete texture; } 281 void reallocate() { DED_DUP_URI(texture); } 282 } ded_detail_stage_t; 283 284 // Flags for detail texture definitions. 285 #define DTLF_NO_IWAD 0x1 // Don't use if from IWAD. 286 #define DTLF_PWAD 0x2 // Can use if from PWAD. 287 #define DTLF_EXTERNAL 0x4 // Can use if from external resource. 288 289 typedef struct LIBDOOMSDAY_PUBLIC ded_detailtexture_s { 290 de::Uri * material1; 291 de::Uri * material2; 292 ded_flags_t flags; 293 // There is only one stage. 294 ded_detail_stage_t stage; 295 296 void release() 297 { 298 delete material1; 299 delete material2; 300 stage.release(); 301 } 302 void reallocate() 303 { 304 DED_DUP_URI(material1); 305 DED_DUP_URI(material2); 306 stage.reallocate(); 307 } 308 } ded_detailtexture_t; 309 310 typedef struct LIBDOOMSDAY_PUBLIC ded_ptcgen_s { 311 struct ded_ptcgen_s * stateNext; // List of generators for a state. 312 ded_stateid_t state; // Triggered by this state (if mobj-gen). 313 de::Uri * material; 314 ded_mobjid_t type; // Triggered by this type of mobjs. 315 ded_mobjid_t type2; // Also triggered by this type. 316 int typeNum; 317 int type2Num; 318 ded_mobjid_t damage; // Triggered by mobj damage of this type. 319 int damageNum; 320 de::Uri * map; // Triggered by this map. 321 ded_flags_t flags; 322 float speed; // Particle spawn velocity. 323 float speedVariance; // Spawn speed variance (0-1). 324 float vector[3]; // Particle launch vector. 325 float vectorVariance; // Launch vector variance (0-1). 1=totally random. 326 float initVectorVariance; // Initial launch vector variance (0-1). 327 float center[3]; // Offset to the mobj (relat. to source). 328 int subModel; // Model source: origin submodel #. 329 float spawnRadius; 330 float spawnRadiusMin; // Spawn uncertainty box. 331 float maxDist; // Max visibility for particles. 332 int spawnAge; // How long until spawning stops? 333 int maxAge; // How long until generator dies? 334 int particles; // Maximum number of particles. 335 float spawnRate; // Particles spawned per tic. 336 float spawnRateVariance; 337 int preSim; // Tics to pre-simulate when spawned. 338 int altStart; 339 float altStartVariance; // Probability for alt start. 340 float force; // Radial strength of the sphere force. 341 float forceRadius; // Radius of the sphere force. 342 float forceAxis[3]; /* Rotation axis of the sphere force 343 (+ speed). */ 344 float forceOrigin[3]; // Offset for the force sphere. 345 DEDArray<ded_ptcstage_t> stages; 346 347 void release() 348 { 349 delete material; 350 delete map; 351 stages.clear(); 352 } 353 void reallocate() 354 { 355 DED_DUP_URI(map); 356 DED_DUP_URI(material); 357 stages.reallocate(); 358 } 359 } ded_ptcgen_t; 360 361 typedef struct LIBDOOMSDAY_PUBLIC ded_shine_stage_s { 362 int tics; 363 float variance; 364 de::Uri * texture; 365 de::Uri * maskTexture; 366 blendmode_t blendMode; // Blend mode flags (bm_*). 367 float shininess; 368 float minColor[3]; 369 float maskWidth; 370 float maskHeight; 371 372 void release() 373 { 374 delete texture; 375 delete maskTexture; 376 } 377 void reallocate() 378 { 379 DED_DUP_URI(texture); 380 DED_DUP_URI(maskTexture); 381 } 382 } ded_shine_stage_t; 383 384 // Flags for reflection definitions. 385 #define REFF_NO_IWAD 0x1 // Don't use if from IWAD. 386 #define REFF_PWAD 0x2 // Can use if from PWAD. 387 #define REFF_EXTERNAL 0x4 // Can use if from external resource. 388 389 typedef struct LIBDOOMSDAY_PUBLIC ded_reflection_s { 390 de::Uri * material; 391 ded_flags_t flags; 392 // There is only one stage. 393 ded_shine_stage_t stage; 394 395 void release() 396 { 397 delete material; 398 stage.release(); 399 } 400 void reallocate() 401 { 402 DED_DUP_URI(material); 403 stage.reallocate(); 404 } 405 } ded_reflection_t; 406 407 typedef struct LIBDOOMSDAY_PUBLIC ded_group_member_s { 408 de::Uri *material; 409 int tics; 410 int randomTics; 411 412 void release() { delete material; } 413 void reallocate() { DED_DUP_URI(material); } 414 } ded_group_member_t; 415 416 typedef struct LIBDOOMSDAY_PUBLIC ded_group_s { 417 ded_flags_t flags; 418 DEDArray<ded_group_member_t> members; 419 420 void release() { members.clear(); } 421 422 ded_group_member_t *tryFindFirstMemberWithMaterial(de::Uri const &materialUri) 423 { 424 if (!materialUri.isEmpty()) 425 { 426 for (int i = 0; i < members.size(); ++i) 427 { 428 if (members[i].material && *members[i].material == materialUri) 429 { 430 return &members[i]; 431 } 432 // Only animate if the first frame in the group? 433 if (flags & AGF_FIRST_ONLY) break; 434 } 435 } 436 return nullptr; // Not found. 437 } 438 } ded_group_t; 439 440 typedef struct LIBDOOMSDAY_PUBLIC ded_compositefont_mappedcharacter_s { 441 unsigned char ch; 442 de::Uri * path; 443 444 void release() { delete path; } 445 void reallocate() { DED_DUP_URI(path); } 446 } ded_compositefont_mappedcharacter_t; 447 448 typedef struct LIBDOOMSDAY_PUBLIC ded_compositefont_s { 449 de::Uri * uri; 450 DEDArray<ded_compositefont_mappedcharacter_t> charMap; 451 452 void release() 453 { 454 delete uri; 455 charMap.clear(); 456 } 457 } ded_compositefont_t; 458 459 #endif // LIBDOOMSDAY_DEFINITION_TYPES_H 460