DeclParticle.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. /*
  2. ===========================================================================
  3. Doom 3 BFG Edition GPL Source Code
  4. Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
  6. Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. #ifndef __DECLPARTICLE_H__
  21. #define __DECLPARTICLE_H__
  22. /*
  23. ===============================================================================
  24. idDeclParticle
  25. ===============================================================================
  26. */
  27. static const int MAX_PARTICLE_STAGES = 32;
  28. class idParticleParm {
  29. public:
  30. idParticleParm() { table = NULL; from = to = 0.0f; }
  31. const idDeclTable * table;
  32. float from;
  33. float to;
  34. float Eval( float frac, idRandom &rand ) const;
  35. float Integrate( float frac, idRandom &rand ) const;
  36. };
  37. typedef enum {
  38. PDIST_RECT, // ( sizeX sizeY sizeZ )
  39. PDIST_CYLINDER, // ( sizeX sizeY sizeZ )
  40. PDIST_SPHERE // ( sizeX sizeY sizeZ ringFraction )
  41. // a ringFraction of zero allows the entire sphere, 0.9 would only
  42. // allow the outer 10% of the sphere
  43. } prtDistribution_t;
  44. typedef enum {
  45. PDIR_CONE, // parm0 is the solid cone angle
  46. PDIR_OUTWARD // direction is relative to offset from origin, parm0 is an upward bias
  47. } prtDirection_t;
  48. typedef enum {
  49. PPATH_STANDARD,
  50. PPATH_HELIX, // ( sizeX sizeY sizeZ radialSpeed climbSpeed )
  51. PPATH_FLIES,
  52. PPATH_ORBIT,
  53. PPATH_DRIP
  54. } prtCustomPth_t;
  55. typedef enum {
  56. POR_VIEW,
  57. POR_AIMED, // angle and aspect are disregarded
  58. POR_X,
  59. POR_Y,
  60. POR_Z
  61. } prtOrientation_t;
  62. typedef struct renderEntity_s renderEntity_t;
  63. typedef struct renderView_s renderView_t;
  64. typedef struct {
  65. const renderEntity_t * renderEnt; // for shaderParms, etc
  66. const renderView_t * renderView;
  67. int index; // particle number in the system
  68. float frac; // 0.0 to 1.0
  69. idRandom random;
  70. idVec3 origin; // dynamic smoke particles can have individual origins and axis
  71. idMat3 axis;
  72. float age; // in seconds, calculated as fraction * stage->particleLife
  73. idRandom originalRandom; // needed so aimed particles can reset the random for another origin calculation
  74. float animationFrameFrac; // set by ParticleTexCoords, used to make the cross faded version
  75. } particleGen_t;
  76. //
  77. // single particle stage
  78. //
  79. class idParticleStage {
  80. public:
  81. idParticleStage();
  82. ~idParticleStage() {}
  83. void Default();
  84. int NumQuadsPerParticle() const; // includes trails and cross faded animations
  85. // returns the number of verts created, which will range from 0 to 4*NumQuadsPerParticle()
  86. int CreateParticle( particleGen_t *g, idDrawVert *verts ) const;
  87. void ParticleOrigin( particleGen_t *g, idVec3 &origin ) const;
  88. int ParticleVerts( particleGen_t *g, const idVec3 origin, idDrawVert *verts ) const;
  89. void ParticleTexCoords( particleGen_t *g, idDrawVert *verts ) const;
  90. void ParticleColors( particleGen_t *g, idDrawVert *verts ) const;
  91. const char * GetCustomPathName();
  92. const char * GetCustomPathDesc();
  93. int NumCustomPathParms();
  94. void SetCustomPathType( const char *p );
  95. void operator=( const idParticleStage &src );
  96. //------------------------------
  97. const idMaterial * material;
  98. int totalParticles; // total number of particles, although some may be invisible at a given time
  99. float cycles; // allows things to oneShot ( 1 cycle ) or run for a set number of cycles
  100. // on a per stage basis
  101. int cycleMsec; // ( particleLife + deadTime ) in msec
  102. float spawnBunching; // 0.0 = all come out at first instant, 1.0 = evenly spaced over cycle time
  103. float particleLife; // total seconds of life for each particle
  104. float timeOffset; // time offset from system start for the first particle to spawn
  105. float deadTime; // time after particleLife before respawning
  106. //------------------------------- // standard path parms
  107. prtDistribution_t distributionType;
  108. float distributionParms[4];
  109. prtDirection_t directionType;
  110. float directionParms[4];
  111. idParticleParm speed;
  112. float gravity; // can be negative to float up
  113. bool worldGravity; // apply gravity in world space
  114. bool randomDistribution; // randomly orient the quad on emission ( defaults to true )
  115. bool entityColor; // force color from render entity ( fadeColor is still valid )
  116. //------------------------------ // custom path will completely replace the standard path calculations
  117. prtCustomPth_t customPathType; // use custom C code routines for determining the origin
  118. float customPathParms[8];
  119. //--------------------------------
  120. idVec3 offset; // offset from origin to spawn all particles, also applies to customPath
  121. int animationFrames; // if > 1, subdivide the texture S axis into frames and crossfade
  122. float animationRate; // frames per second
  123. float initialAngle; // in degrees, random angle is used if zero ( default )
  124. idParticleParm rotationSpeed; // half the particles will have negative rotation speeds
  125. prtOrientation_t orientation; // view, aimed, or axis fixed
  126. float orientationParms[4];
  127. idParticleParm size;
  128. idParticleParm aspect; // greater than 1 makes the T axis longer
  129. idVec4 color;
  130. idVec4 fadeColor; // either 0 0 0 0 for additive, or 1 1 1 0 for blended materials
  131. float fadeInFraction; // in 0.0 to 1.0 range
  132. float fadeOutFraction; // in 0.0 to 1.0 range
  133. float fadeIndexFraction; // in 0.0 to 1.0 range, causes later index smokes to be more faded
  134. bool hidden; // for editor use
  135. //-----------------------------------
  136. float boundsExpansion; // user tweak to fix poorly calculated bounds
  137. idBounds bounds; // derived
  138. };
  139. //
  140. // group of particle stages
  141. //
  142. class idDeclParticle : public idDecl {
  143. public:
  144. virtual size_t Size() const;
  145. virtual const char * DefaultDefinition() const;
  146. virtual bool Parse( const char *text, const int textLength, bool allowBinaryVersion );
  147. virtual void FreeData();
  148. bool Save( const char *fileName = NULL );
  149. // Loaded instead of re-parsing, written if MD5 hash different
  150. bool LoadBinary( idFile * file, unsigned int checksum );
  151. void WriteBinary( idFile * file, unsigned int checksum );
  152. idList<idParticleStage *, TAG_IDLIB_LIST_DECL>stages;
  153. idBounds bounds;
  154. float depthHack;
  155. private:
  156. bool RebuildTextSource();
  157. void GetStageBounds( idParticleStage *stage );
  158. idParticleStage * ParseParticleStage( idLexer &src );
  159. void ParseParms( idLexer &src, float *parms, int maxParms );
  160. void ParseParametric( idLexer &src, idParticleParm *parm );
  161. void WriteStage( idFile *f, idParticleStage *stage );
  162. void WriteParticleParm( idFile *f, idParticleParm *parm, const char *name );
  163. };
  164. #endif /* !__DECLPARTICLE_H__ */