Revision e50e7ba7
Added by Leszek Koltunski almost 4 years ago
src/main/java/org/distorted/examples/wind/WindEffectsManager.java | ||
---|---|---|
39 | 39 |
// make the flag horizontal (milliseconds) |
40 | 40 |
private static final long TIME_TO_FALL_DOWN =2000; // time it takes for the flag to |
41 | 41 |
// fall back down if no wind (milliseconds) |
42 |
private long lastTime;
|
|
42 |
private long mLastTime, mPausedTime;
|
|
43 | 43 |
private float mWind; |
44 | 44 |
private int mHeight, mWidth; |
45 | 45 |
|
... | ... | |
59 | 59 |
|
60 | 60 |
WindEffectsManager(int width, int height) |
61 | 61 |
{ |
62 |
lastTime = 0;
|
|
62 |
mLastTime = 0;
|
|
63 | 63 |
|
64 | 64 |
mWidth = width; |
65 | 65 |
mHeight= height; |
... | ... | |
149 | 149 |
windFactor42.set0(wave4); |
150 | 150 |
} |
151 | 151 |
|
152 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
153 |
|
|
154 |
void pauseWind() |
|
155 |
{ |
|
156 |
mPausedTime = System.currentTimeMillis(); |
|
157 |
} |
|
158 |
|
|
159 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
160 |
|
|
161 |
void resumeWind() |
|
162 |
{ |
|
163 |
long gap = System.currentTimeMillis() - mPausedTime; |
|
164 |
mLastTime += gap; |
|
165 |
} |
|
166 |
|
|
152 | 167 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
153 | 168 |
|
154 | 169 |
synchronized void increaseWind(long currTime) |
155 | 170 |
{ |
156 |
if( lastTime>0 )
|
|
171 |
if( mLastTime>0 )
|
|
157 | 172 |
{ |
158 |
long diff = currTime-lastTime;
|
|
173 |
long diff = currTime-mLastTime;
|
|
159 | 174 |
float diffWind = (100.0f*diff/TIME_TO_GET_UP); |
160 | 175 |
|
161 | 176 |
mWind += diffWind; |
... | ... | |
164 | 179 |
setWind( (int)mWind ); |
165 | 180 |
} |
166 | 181 |
|
167 |
lastTime = currTime;
|
|
182 |
mLastTime = currTime;
|
|
168 | 183 |
} |
169 | 184 |
|
170 | 185 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
171 | 186 |
|
172 | 187 |
synchronized void decreaseWind(long currTime) |
173 | 188 |
{ |
174 |
if( lastTime>0 )
|
|
189 |
if( mLastTime>0 )
|
|
175 | 190 |
{ |
176 |
long diff = currTime-lastTime;
|
|
191 |
long diff = currTime-mLastTime;
|
|
177 | 192 |
float diffWind = (100.0f*diff/TIME_TO_FALL_DOWN); |
178 | 193 |
|
179 | 194 |
mWind -= diffWind; |
... | ... | |
182 | 197 |
setWind( (int)mWind ); |
183 | 198 |
} |
184 | 199 |
|
185 |
lastTime = currTime;
|
|
200 |
mLastTime = currTime;
|
|
186 | 201 |
} |
187 | 202 |
|
188 | 203 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
Also available in: Unified diff
1) rename DistortedTexture's setColor to setColorARGB
2) fix the Wiind app to take into account paused time
3) fix the Dynamic so that if a single Dynamic is used more than once (in more than one effect) than it doesn't get adjusted for paused time multiple times.