Starsector API
Loading...
Searching...
No Matches
FlickerUtilV2.java
Go to the documentation of this file.
1package com.fs.starfarer.api.util;
2
8public class FlickerUtilV2 {
9
10 public static final float UP_RATE = 25f;
11 public static final float DOWN_RATE = 5f;
12 public static final float END_PROB_PER_BURST = 0.1f;
13
14 private float brightness;
15 private float dir = 1f;
16 private float wait;
17 private float maxWait;
18 private boolean stopBursts = false;
19 private boolean stopAll = false;
20
21 private float angle;
22 private float currMax;
23 private float currDur;
24 private int numBursts = 0;
25
26 private boolean peakFrame = false;
27
28 public FlickerUtilV2() {
29 this(4f);
30 }
31 public FlickerUtilV2(float maxWait) {
32 this.maxWait = maxWait;
33 angle = (float) Math.random() * 360f;
34 }
35
36 public float getAngle() {
37 return angle;
38 }
39
40 public void newBurst() {
41 currMax = 0.75f + (float) Math.random() * 0.5f;
42 if (currMax > 1) currMax = 1;
43 if (currMax < brightness) currMax = brightness;
44 dir = 1f;
45 //currDur = 0f + (float) Math.random() * 0.5f;
46 currDur = 0f + (float) Math.random() * 0.5f;
47 currDur *= currDur;
48 currDur += 0.05f;
49 numBursts++;
50 peakFrame = true;
51 //angle = (float) Math.random() * 360f;
52 }
53
54 public void newWait() {
55 wait = (float) Math.random() * maxWait;
56 numBursts = 0;
57 stopBursts = false;
58 angle = (float) Math.random() * 360f;
59 }
60
61 public void setWait(float wait) {
62 this.wait = wait;
63 }
64 public void setNumBursts(int numBursts) {
65 this.numBursts = numBursts;
66 }
67 public boolean isPeakFrame() {
68 return peakFrame;
69 }
70
71 public int getNumBursts() {
72 return numBursts;
73 }
74
75 public float getWait() {
76 return wait;
77 }
78
79 public void advance(float amount) {
80 peakFrame = false;
81 if (wait > 0) {
82 wait -= amount;
83 if (wait > 0) {
84 return;
85 } else {
86 newBurst();
87 }
88 }
89
90 //float timeUp = Math.min(0.1f, currDur / 5f);
91 //float timeDown = currDur - timeUp;
92 if (dir > 0) {
93 //brightness += amount / timeUp;
94 brightness += amount * UP_RATE;
95 } else {
96 //brightness -= amount / timeDown;
97 brightness -= amount * DOWN_RATE;
98 }
99
100 if (brightness < 0) brightness = 0;
101
102 if (brightness >= currMax) {
103 brightness = currMax;
104 dir = -1;
105 }
106
107
108 currDur -= amount;
109 if (currDur <= 0) {
110 if (!stopBursts && !stopAll) {
111 if ((float) Math.random() < END_PROB_PER_BURST * (float) numBursts) {
112 stopBursts = true;
113 } else {
114 newBurst();
115 }
116 } else if (!stopAll && brightness <= 0) {
117 newWait();
118 }
119 }
120
121 }
122
123 public void stop() {
124 stopAll = true;
125 }
126
127 public float getBrightness() {
128 return brightness;
129 }
130
131 public static void main(String[] args) {
133
134 for (int i = 0; i < 1000; i++) {
135 test.advance(0.016f);
136 System.out.println(test.getBrightness());
137 //System.out.println(test.getAngle());
138 }
139 }
140
141}
142
143
144
145
146
147
148
149