Revision 4f9ec5d6
Added by Leszek Koltunski over 3 years ago
src/main/java/org/distorted/library/type/Dynamic.java | ||
---|---|---|
19 | 19 |
|
20 | 20 |
package org.distorted.library.type; |
21 | 21 |
|
22 |
import org.distorted.library.main.InternalMaster; |
|
23 |
|
|
24 |
import java.util.ArrayList; |
|
22 | 25 |
import java.util.Random; |
23 | 26 |
import java.util.Vector; |
24 | 27 |
|
... | ... | |
53 | 56 |
// |
54 | 57 |
// and similarly Y(t) and Z(t). |
55 | 58 |
|
56 |
public abstract class Dynamic |
|
59 |
public abstract class Dynamic implements InternalMaster.Slave
|
|
57 | 60 |
{ |
58 | 61 |
/** |
59 | 62 |
* One revolution takes us from the first point to the last and back to first through the shortest path. |
... | ... | |
154 | 157 |
|
155 | 158 |
private float[] buf; |
156 | 159 |
private float[] old; |
157 |
private static Random mRnd = new Random(); |
|
160 |
private static final Random mRnd = new Random();
|
|
158 | 161 |
private static final int NUM_NOISE = 5; // used iff mNoise>0.0. Number of intermediary points between each pair of adjacent vectors |
159 | 162 |
// where we randomize noise factors to make the way between the two vectors not so smooth. |
160 | 163 |
private long mStartTime; |
161 | 164 |
private long mCorrectedTime; |
162 | 165 |
private static long mPausedTime; |
163 | 166 |
|
167 |
private static final int JOB_RESET = 0; |
|
168 |
|
|
169 |
private static class Job |
|
170 |
{ |
|
171 |
int type; |
|
172 |
|
|
173 |
Job(int t) |
|
174 |
{ |
|
175 |
type = t; |
|
176 |
} |
|
177 |
} |
|
178 |
|
|
179 |
private ArrayList<Job> mJobs; |
|
180 |
|
|
164 | 181 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
165 | 182 |
// hide this from Javadoc |
166 | 183 |
|
... | ... | |
523 | 540 |
} |
524 | 541 |
} |
525 | 542 |
|
543 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
544 |
|
|
545 |
private void resetToBeginningNow() |
|
546 |
{ |
|
547 |
mStartTime = -1; |
|
548 |
} |
|
549 |
|
|
526 | 550 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
527 | 551 |
|
528 | 552 |
abstract void interpolate(float[] buffer, int offset, float time); |
... | ... | |
595 | 619 |
*/ |
596 | 620 |
public void resetToBeginning() |
597 | 621 |
{ |
598 |
mStartTime = -1; |
|
622 |
if( mJobs==null ) mJobs = new ArrayList<>(); |
|
623 |
|
|
624 |
mJobs.add(new Job(JOB_RESET)); |
|
625 |
InternalMaster.newSlave(this); |
|
599 | 626 |
} |
600 | 627 |
|
601 | 628 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
733 | 760 |
return false; |
734 | 761 |
} |
735 | 762 |
|
763 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
764 |
|
|
765 |
public void doWork() |
|
766 |
{ |
|
767 |
int num = mJobs.size(); |
|
768 |
Job job; |
|
769 |
|
|
770 |
for(int i=0; i<num; i++) |
|
771 |
{ |
|
772 |
job = mJobs.remove(0); |
|
773 |
|
|
774 |
if (job.type == JOB_RESET ) |
|
775 |
{ |
|
776 |
resetToBeginningNow(); |
|
777 |
} |
|
778 |
} |
|
779 |
} |
|
780 |
|
|
736 | 781 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
737 | 782 |
} |
Also available in: Unified diff
Make Dynamic's resetToBegin() done on the next frame.
This is necessary if we want to reset many Dynamics at one go and have all of them start synchronized.
Otherwise it can happen that when we reset, we do it when some objects which the Dynamics belong to are already rendered and others are not, and then some of the Dynamics will be delayed by one frame which is visible already.