Starsector API
Loading...
Searching...
No Matches
FlickerUtilV2.java
Go to the documentation of this file.
1
package
com.fs.starfarer.api.util;
2
8
public
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) {
132
FlickerUtilV2
test =
new
FlickerUtilV2
();
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
com.fs.starfarer.api.util.FlickerUtilV2
Definition
FlickerUtilV2.java:8
com.fs.starfarer.api.util.FlickerUtilV2.getAngle
float getAngle()
Definition
FlickerUtilV2.java:36
com.fs.starfarer.api.util.FlickerUtilV2.advance
void advance(float amount)
Definition
FlickerUtilV2.java:79
com.fs.starfarer.api.util.FlickerUtilV2.getWait
float getWait()
Definition
FlickerUtilV2.java:75
com.fs.starfarer.api.util.FlickerUtilV2.UP_RATE
static final float UP_RATE
Definition
FlickerUtilV2.java:10
com.fs.starfarer.api.util.FlickerUtilV2.DOWN_RATE
static final float DOWN_RATE
Definition
FlickerUtilV2.java:11
com.fs.starfarer.api.util.FlickerUtilV2.setWait
void setWait(float wait)
Definition
FlickerUtilV2.java:61
com.fs.starfarer.api.util.FlickerUtilV2.getBrightness
float getBrightness()
Definition
FlickerUtilV2.java:127
com.fs.starfarer.api.util.FlickerUtilV2.main
static void main(String[] args)
Definition
FlickerUtilV2.java:131
com.fs.starfarer.api.util.FlickerUtilV2.FlickerUtilV2
FlickerUtilV2(float maxWait)
Definition
FlickerUtilV2.java:31
com.fs.starfarer.api.util.FlickerUtilV2.isPeakFrame
boolean isPeakFrame()
Definition
FlickerUtilV2.java:67
com.fs.starfarer.api.util.FlickerUtilV2.setNumBursts
void setNumBursts(int numBursts)
Definition
FlickerUtilV2.java:64
com.fs.starfarer.api.util.FlickerUtilV2.newWait
void newWait()
Definition
FlickerUtilV2.java:54
com.fs.starfarer.api.util.FlickerUtilV2.newBurst
void newBurst()
Definition
FlickerUtilV2.java:40
com.fs.starfarer.api.util.FlickerUtilV2.FlickerUtilV2
FlickerUtilV2()
Definition
FlickerUtilV2.java:28
com.fs.starfarer.api.util.FlickerUtilV2.getNumBursts
int getNumBursts()
Definition
FlickerUtilV2.java:71
com.fs.starfarer.api.util.FlickerUtilV2.END_PROB_PER_BURST
static final float END_PROB_PER_BURST
Definition
FlickerUtilV2.java:12
com.fs.starfarer.api.util.FlickerUtilV2.stop
void stop()
Definition
FlickerUtilV2.java:123
src
com
fs
starfarer
api
util
FlickerUtilV2.java
Generated by
1.12.0