splash.h
Engine/source/T3D/fx/splash.h
More...
Classes:
Detailed Description
1
2//-----------------------------------------------------------------------------
3// Copyright (c) 2012 GarageGames, LLC
4//
5// Permission is hereby granted, free of charge, to any person obtaining a copy
6// of this software and associated documentation files (the "Software"), to
7// deal in the Software without restriction, including without limitation the
8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9// sell copies of the Software, and to permit persons to whom the Software is
10// furnished to do so, subject to the following conditions:
11//
12// The above copyright notice and this permission notice shall be included in
13// all copies or substantial portions of the Software.
14//
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21// IN THE SOFTWARE.
22//-----------------------------------------------------------------------------
23
24#ifndef _SPLASH_H_
25#define _SPLASH_H_
26
27#ifndef _GAMEBASE_H_
28#include "T3D/gameBase/gameBase.h"
29#endif
30
31#ifndef _TORQUE_LIST_
32#include "core/util/tList.h"
33#endif
34
35#include "gfx/gfxTextureHandle.h"
36
37class ParticleEmitter;
38class ParticleEmitterData;
39class AudioProfile;
40class ExplosionData;
41
42
43//--------------------------------------------------------------------------
44// Ring Point
45//--------------------------------------------------------------------------
46struct SplashRingPoint
47{
48 Point3F position;
49 Point3F velocity;
50};
51
52//--------------------------------------------------------------------------
53// Splash Ring
54//--------------------------------------------------------------------------
55struct SplashRing
56{
57 Vector <SplashRingPoint> points;
58 LinearColorF color;
59 F32 lifetime;
60 F32 elapsedTime;
61 F32 v;
62
63 SplashRing()
64 {
65 color.set( 0.0, 0.0, 0.0, 1.0 );
66 lifetime = 0.0;
67 elapsedTime = 0.0;
68 v = 0.0;
69 }
70
71 bool isActive()
72 {
73 return elapsedTime < lifetime;
74 }
75};
76
77//--------------------------------------------------------------------------
78// Splash Data
79//--------------------------------------------------------------------------
80class SplashData : public GameBaseData
81{
82 public:
83 typedef GameBaseData Parent;
84
85 enum Constants
86 {
87 NUM_EMITTERS = 3,
88 NUM_TIME_KEYS = 4,
89 NUM_TEX = 2,
90 };
91
92public:
93 AudioProfile* soundProfile;
94 S32 soundProfileId;
95
96 ParticleEmitterData* emitterList[NUM_EMITTERS];
97 S32 emitterIDList[NUM_EMITTERS];
98
99 S32 delayMS;
100 S32 delayVariance;
101 S32 lifetimeMS;
102 S32 lifetimeVariance;
103 Point3F scale;
104 F32 width;
105 F32 height;
106 U32 numSegments;
107 F32 velocity;
108 F32 acceleration;
109 F32 texWrap;
110 F32 texFactor;
111
112 F32 ejectionFreq;
113 F32 ejectionAngle;
114 F32 ringLifetime;
115 F32 startRadius;
116
117 F32 times[ NUM_TIME_KEYS ];
118 LinearColorF colors[ NUM_TIME_KEYS ];
119
120 StringTableEntry textureName[NUM_TEX];
121 GFXTexHandle textureHandle[NUM_TEX];
122
123 ExplosionData* explosion;
124 S32 explosionId;
125
126 SplashData();
127 DECLARE_CONOBJECT(SplashData);
128 bool onAdd();
129 bool preload(bool server, String &errorStr);
130 static void initPersistFields();
131 virtual void packData(BitStream* stream);
132 virtual void unpackData(BitStream* stream);
133};
134
135//--------------------------------------------------------------------------
136// Splash
137//--------------------------------------------------------------------------
138class Splash : public GameBase
139{
140 typedef GameBase Parent;
141
142private:
143 SplashData* mDataBlock;
144
145 SimObjectPtr<ParticleEmitter> mEmitterList[ SplashData::NUM_EMITTERS ];
146
147 typedef Torque::List<SplashRing> SplashRingList;
148 SplashRingList ringList;
149
150 U32 mCurrMS;
151 U32 mEndingMS;
152 F32 mRandAngle;
153 F32 mRadius;
154 F32 mVelocity;
155 F32 mHeight;
156 LinearColorF mColor;
157 F32 mTimeSinceLastRing;
158 bool mDead;
159 F32 mElapsedTime;
160
161protected:
162 Point3F mInitialPosition;
163 Point3F mInitialNormal;
164 F32 mFade;
165 F32 mFog;
166 bool mActive;
167 S32 mDelayMS;
168
169protected:
170 bool onAdd();
171 void onRemove();
172 void processTick(const Move *move);
173 void advanceTime(F32 dt);
174 void updateEmitters( F32 dt );
175 void updateWave( F32 dt );
176 void updateColor();
177 SplashRing createRing();
178 void updateRings( F32 dt );
179 void updateRing( SplashRing& ring, F32 dt );
180 void emitRings( F32 dt );
181 void spawnExplosion();
182
183public:
184 Splash();
185 ~Splash();
186 void setInitialState(const Point3F& point, const Point3F& normal, const F32 fade = 1.0);
187
188 U32 packUpdate (NetConnection *conn, U32 mask, BitStream* stream);
189 void unpackUpdate(NetConnection *conn, BitStream* stream);
190
191 bool onNewDataBlock( GameBaseData *dptr, bool reload );
192 DECLARE_CONOBJECT(Splash);
193};
194
195
196#endif // _H_SPLASH
197