DeclParticle.h 7.9 KB

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