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