Skip to content

Commit f5a05db

Browse files
committed
Some trail fine-tuning
1 parent cdefdf8 commit f5a05db

4 files changed

Lines changed: 57 additions & 58 deletions

File tree

main/src/unity/content/Trails.java

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,18 @@ public static TexturedTrail phantasmalExhaust(int length){
3939
}
4040

4141
public static MultiTrail phantasmal(int length){
42-
return phantasmal(length, 3.6f, 3.5f, 0f);
42+
return phantasmal(length, 3.6f, 3.5f, -1f, 0f);
4343
}
4444

4545
public static MultiTrail phantasmal(RotationHandler rot, int length){
46-
return phantasmal(rot, length, 3.6f, 3.5f, 0f);
46+
return phantasmal(rot, length, 3.6f, 3.5f, -1f, 0f);
4747
}
4848

49-
public static MultiTrail phantasmal(int length, float scale, float magnitude, float offsetY){
50-
return phantasmal(MultiTrail::calcRot, length, scale, magnitude, offsetY);
49+
public static MultiTrail phantasmal(int length, float scale, float magnitude, float speedThreshold, float offsetY){
50+
return phantasmal(MultiTrail::calcRot, length, scale, magnitude, speedThreshold, offsetY);
5151
}
5252

53-
public static MultiTrail phantasmal(RotationHandler rot, int length, float scale, float magnitude, float offsetY){
53+
public static MultiTrail phantasmal(RotationHandler rot, int length, float scale, float magnitude, float speedThreshold, float offsetY){
5454
int strandsAmount = 2;
5555

5656
TrailHold[] trails = new TrailHold[strandsAmount + 2];
@@ -62,9 +62,11 @@ public static MultiTrail phantasmal(RotationHandler rot, int length, float scale
6262
return new MultiTrail(rot, trails){
6363
@Override
6464
public void update(float x, float y, float width){
65+
float scl = speedThreshold == -1f ? 1f : Mathf.clamp(Mathf.dst(x, y, lastX, lastY) / Time.delta / speedThreshold);
6566
float angle = rotation.get(this, x, y) - 90f;
67+
6668
for(int i = 0; i < strandsAmount; i++){
67-
Tmp.v1.trns(angle, Mathf.sin((Time.time + offset + (Mathf.PI2 * scale) * ((float)i / strandsAmount)), scale, magnitude * width), offsetY);
69+
Tmp.v1.trns(angle, Mathf.sin(Time.time + offset + (Mathf.PI2 * scale) * ((float)i / strandsAmount), scale, magnitude * width * scl), offsetY);
6870

6971
TrailHold trail = trails[i];
7072
trail.trail.update(x + Tmp.v1.x, y + Tmp.v1.y, width * trail.width);
@@ -99,32 +101,43 @@ public static TexturedTrail singleSoul(int length){
99101
}
100102

101103
public static MultiTrail soul(int length){
102-
return soul(length, 6f, 2.2f);
104+
return soul(length, 6f, 2.2f, -1f);
103105
}
104106

105107
public static MultiTrail soul(RotationHandler rot, int length){
106-
return soul(rot, length, 6f, 2.2f);
108+
return soul(rot, length, 6f, 2.2f, -1f);
109+
}
110+
111+
public static MultiTrail soul(int length, float speedThreshold){
112+
return soul(length, 6f, 2.2f, speedThreshold);
113+
}
114+
115+
public static MultiTrail soul(RotationHandler rot, int length, float speedThreshold){
116+
return soul(rot, length, 6f, 2.2f, speedThreshold);
107117
}
108118

109-
public static MultiTrail soul(int length, float scale, float magnitude){
110-
return soul(MultiTrail::calcRot, length, scale, magnitude);
119+
public static MultiTrail soul(int length, float scale, float magnitude, float speedThreshold){
120+
return soul(MultiTrail::calcRot, length, scale, magnitude, speedThreshold);
111121
}
112122

113-
public static MultiTrail soul(RotationHandler rot, int length, float scale, float magnitude){
123+
public static MultiTrail soul(RotationHandler rot, int length, float scale, float magnitude, float speedThreshold){
114124
int strandsAmount = 3;
115125

116126
TrailHold[] trails = new TrailHold[strandsAmount + 1];
117127
for(int i = 0; i < strandsAmount; i++) trails[i] = new TrailHold(Utils.with(singleSoul(Mathf.round(length * 1.5f)), t -> t.mixAlpha = 0f), 0f, 0f, 0.56f);
118128
trails[strandsAmount] = new TrailHold(singlePhantasmal(length), UnityPal.monolith);
119129

120130
float dir = Mathf.sign(Mathf.chance(0.5f));
121-
float offset = Mathf.random(Mathf.PI2 * scale);
122131
return new MultiTrail(rot, trails){
132+
float time = Time.time + Mathf.random(Mathf.PI2 * scale);
133+
123134
@Override
124135
public void update(float x, float y, float width){
125136
float angle = rotation.get(this, x, y) - 90f;
137+
138+
time += (speedThreshold == -1f ? 1f : Mathf.clamp(Mathf.dst(x, y, lastX, lastY) / Time.delta / speedThreshold)) * Time.delta;
126139
for(int i = 0; i < strandsAmount; i++){
127-
float rad = (Time.time + offset + (Mathf.PI2 * scale) * ((float)i / strandsAmount)) * dir;
140+
float rad = (time + (Mathf.PI2 * scale) * ((float)i / strandsAmount)) * dir;
128141
float scl = Mathf.map(Mathf.sin(rad, scale, 1f), -1f, 1f, 0.2f, 1f);
129142
Tmp.v1.trns(angle, Mathf.cos(rad, scale, magnitude * width));
130143

@@ -136,7 +149,6 @@ public void update(float x, float y, float width){
136149
Tmp.v1.trns(angle, main.x, main.y);
137150

138151
main.trail.update(x + Tmp.v1.x, y + Tmp.v1.y, width * main.width);
139-
140152
lastX = x;
141153
lastY = y;
142154
}

main/src/unity/content/units/MonolithUnitTypes.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ public static void load(){
8383
forceWreckRegion = true;
8484

8585
trailType = unit -> new MultiTrail(MultiTrail.rot(unit),
86-
new TrailHold(Trails.soul(MultiTrail.rot(unit), 50), engineColor),
87-
new TrailHold(Trails.soul(MultiTrail.rot(unit), 64), -4.8f, 6f, 0.56f, engineColor),
88-
new TrailHold(Trails.soul(MultiTrail.rot(unit), 64), 4.8f, 6f, 0.56f, engineColor)
86+
new TrailHold(Trails.soul(MultiTrail.rot(unit), 50, speed), engineColor),
87+
new TrailHold(Trails.soul(MultiTrail.rot(unit), 64, speed), -4.8f, 6f, 0.56f, engineColor),
88+
new TrailHold(Trails.soul(MultiTrail.rot(unit), 64, speed), 4.8f, 6f, 0.56f, engineColor)
8989
);
9090
}
9191

@@ -100,7 +100,7 @@ public void update(Unit unit){
100100
copy.rotation = MultiTrail::calcRot;
101101

102102
TrailFx.trailFadeLow.at(soul.x, soul.y, width, engineColor, copy);
103-
soul.trail = new MultiTrail(new TrailHold(Trails.soul(MultiTrail.rot(unit), trailLength), engineColor));
103+
soul.trail = new MultiTrail(new TrailHold(Trails.soul(MultiTrail.rot(unit), trailLength, speed), engineColor));
104104
}else if(trail.trails.length == 1 && !soul.corporeal()){
105105
MultiTrail copy = trail.copy();
106106
copy.rotation = MultiTrail::calcRot;
@@ -1010,16 +1010,16 @@ interface EngineType{
10101010
offset = 11f;
10111011
}}.apply(this);
10121012
trailType = unit -> new MultiTrail(MultiTrail.rot(unit),
1013-
new TrailHold(Trails.phantasmal(MultiTrail.rot(unit), 16, 3.6f, 6f, 2f), engineColor),
1013+
new TrailHold(Trails.phantasmal(MultiTrail.rot(unit), 16, 3.6f, 6f, speed, 2f), engineColor),
10141014
new TrailHold(Utils.with(Trails.singlePhantasmal(24), t -> {
10151015
t.trailChance = 0f;
1016-
t.fadeInterp = e -> (1f - Interp.pow10In.apply(e)) * Interp.pow2In.apply(e);
1017-
t.sideFadeInterp = e -> (1f - Interp.pow5In.apply(e)) * Interp.pow3In.apply(e);
1016+
t.fadeInterp = e -> (1f - Interp.pow5In.apply(e)) * Interp.pow2In.apply(e);
1017+
t.sideFadeInterp = e -> (1f - Interp.pow4In.apply(e)) * Interp.pow3In.apply(e);
10181018
}), -4.5f, 2.5f, 0.44f, UnityPal.monolithLight),
10191019
new TrailHold(Utils.with(Trails.singlePhantasmal(24), t -> {
10201020
t.trailChance = 0f;
1021-
t.fadeInterp = e -> (1f - Interp.pow10In.apply(e)) * Interp.pow2In.apply(e);
1022-
t.sideFadeInterp = e -> (1f - Interp.pow5In.apply(e)) * Interp.pow3In.apply(e);
1021+
t.fadeInterp = e -> (1f - Interp.pow5In.apply(e)) * Interp.pow2In.apply(e);
1022+
t.sideFadeInterp = e -> (1f - Interp.pow4In.apply(e)) * Interp.pow3In.apply(e);
10231023
}), 4.5f, 2.5f, 0.44f, UnityPal.monolithLight)
10241024
);
10251025
trailLength = 24;
@@ -1121,8 +1121,8 @@ public void removed(Bullet b){
11211121
color = UnityPal.monolith;
11221122
}}.apply(this);
11231123
trailType = unit -> new MultiTrail(MultiTrail.rot(unit),
1124-
new TrailHold(Trails.soul(MultiTrail.rot(unit), 24), -5f, 0f, 1f, UnityPal.monolithLight),
1125-
new TrailHold(Trails.soul(MultiTrail.rot(unit), 24), 5f, 0f, 1f, UnityPal.monolithLight)
1124+
new TrailHold(Trails.soul(MultiTrail.rot(unit), 24, speed), -5f, 0f, 1f, UnityPal.monolithLight),
1125+
new TrailHold(Trails.soul(MultiTrail.rot(unit), 24, speed), 5f, 0f, 1f, UnityPal.monolithLight)
11261126
);
11271127
trailLength = 24;
11281128

@@ -1227,7 +1227,7 @@ public void draw(Bullet b){
12271227
@Override
12281228
public void updateTrail(Bullet b){
12291229
if(!headless && trailLength > 0 && b.trail == null){
1230-
b.trail = Trails.soul(trailLength, 6f, trailWidth - 0.3f);
1230+
b.trail = Utils.with(Trails.soul(trailLength, 6f, trailWidth - 0.3f, speed), t -> t.each((TexturedTrail tt) -> tt.forceCap = true));
12311231
for(int i = 0; i < b.trail.length; i++) b.trail.update(b.x, b.y, 0f); // Give a head start.
12321232
}
12331233

@@ -1279,9 +1279,9 @@ public void removed(Bullet b){
12791279
color = UnityPal.monolithLight;
12801280
}}.apply(this);
12811281
trailType = unit -> new MultiTrail(MultiTrail.rot(unit),
1282-
new TrailHold(Trails.phantasmal(MultiTrail.rot(unit), 32, 5.6f, 8f, 0f), engineColor),
1283-
new TrailHold(Trails.soul(MultiTrail.rot(unit), 48, 6f, 3.2f), -71f / 4f, (89f - 65f) / 4f, 0.75f, engineColor),
1284-
new TrailHold(Trails.soul(MultiTrail.rot(unit), 48, 6f, 3.2f), 71f / 4f, (89f - 65f) / 4f, 0.75f, engineColor)
1282+
new TrailHold(Trails.phantasmal(MultiTrail.rot(unit), 32, 5.6f, 8f, speed, 0f), engineColor),
1283+
new TrailHold(Trails.soul(MultiTrail.rot(unit), 48, 6f, 3.2f, speed), -71f / 4f, (89f - 65f) / 4f, 0.75f, engineColor),
1284+
new TrailHold(Trails.soul(MultiTrail.rot(unit), 48, 6f, 3.2f, speed), 71f / 4f, (89f - 65f) / 4f, 0.75f, engineColor)
12851285
);
12861286
trailLength = 48;
12871287

main/src/unity/graphics/MultiTrail.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package unity.graphics;
22

3+
import arc.func.*;
34
import arc.graphics.*;
45
import arc.math.*;
56
import arc.util.*;
@@ -10,6 +11,7 @@
1011
* Holds multiple trails with additional offsets, width multiplier, and color override.
1112
* @author GlennFolker
1213
*/
14+
@SuppressWarnings("unchecked")
1315
public class MultiTrail extends Trail{
1416
public TrailHold[] trails;
1517
public RotationHandler rotation = MultiTrail::calcRot;
@@ -32,6 +34,17 @@ public static RotationHandler rot(Rotc e){
3234
return (trail, x, y) -> e.isAdded() ? e.rotation() : trail.calcRot(x, y);
3335
}
3436

37+
public <T extends Trail> void each(Cons<T> cons){
38+
for(TrailHold hold : trails){
39+
Trail t = hold.trail;
40+
if(t instanceof MultiTrail m){
41+
m.each(cons);
42+
}else{
43+
cons.get((T)t);
44+
}
45+
}
46+
}
47+
3548
@Override
3649
public MultiTrail copy(){
3750
TrailHold[] mapped = new TrailHold[trails.length];

main/src/unity/graphics/TexturedTrail.java

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -134,18 +134,15 @@ public void drawCap(Color color, float widthMultiplier){
134134
int psize = points.size;
135135
if(psize > 0){
136136
float
137-
//rv = Mathf.clamp(points.items[psize - 1]),
138137
rv = psize / 4f / length,
139138
alpha = rv * fadeAlpha + (1f - fadeAlpha),
140-
//w = lastW * width / (psize / 4f) * ((psize - 4f) / 4f) * 2f,
141139
w = Mathf.map(rv, 1f - shrink, 1f) * width * lastW * 2f,
142140
h = ((float)capRegion.height / capRegion.width) * w,
143141

144142
angle = -Mathf.radDeg * lastAngle - 90f,
145143
u = capRegion.u, v = capRegion.v2, u2 = capRegion.u2, v2 = capRegion.v, uh = Mathf.lerp(u, u2, 0.5f),
146144
cx = Mathf.cosDeg(angle) * w / 2f, cy = Mathf.sinDeg(angle) * w / 2f,
147145
x1 = lastX, y1 = lastY,
148-
//x2 = lastX + Mathf.cosDeg(angle + 90f) * h, y2 = lastY + Mathf.sinDeg(angle + 90f) * h,
149146
x2 = lastX + Mathf.cosDeg(angle + 90f) * h, y2 = lastY + Mathf.sinDeg(angle + 90f) * h,
150147

151148
col1 = tmp.set(Draw.getColor()).lerp(fadeColor, gradientInterp.apply(1f - rv)).a(fadeInterp.apply(alpha)).clamp().toFloatBits(),
@@ -249,15 +246,11 @@ public void draw(Color color, float widthMultiplier){
249246
x2 = lastX;
250247
y2 = lastY;
251248
w2 = lastW;
252-
//rv2 = points.items[psize - 1];
253249
rv2 = psize / 4f / length;
254250
}
255251

256252
float
257253
z2 = i == psize - 4 ? endAngle : -Angles.angleRad(x1, y1, x2, y2), z1 = i == 0 ? z2 : lastAngle,
258-
//fs1 = Mathf.map(i, 0f, psize, 1f - shrink, 1f) * width * w1,
259-
//fs2 = Mathf.map(Math.min(i + 4f, psize - 4f), 0f, psize, 1f - shrink, 1f) * width * w2,
260-
//fs2 = Mathf.map(i + 4f, 0f, psize, 1f - shrink, 1f) * width * w2,
261254
fs1 = Mathf.map(rv1, 1f - shrink, 1f) * width * w1,
262255
fs2 = Mathf.map(rv2, 1f - shrink, 1f) * width * w2,
263256

@@ -352,12 +345,7 @@ public void shorten(){
352345
public void update(float x, float y, float widthMultiplier){
353346
float dst = Mathf.dst(lastX, lastY, x, y) / Time.delta;
354347
float width = baseWidth * widthMultiplier;
355-
/*if((counter += Time.delta) >= 0.96f){
356-
if(points.size > length * 4) points.removeRange(0, 3);
357348

358-
counter = 0f;
359-
points.add(x, y, width, 0f);
360-
}*/
361349
if((counter += Time.delta) >= 0.96f){
362350
if(dst >= minDst){
363351
if(points.size > length * 4 - 4) points.removeRange(0, 3);
@@ -369,20 +357,17 @@ public void update(float x, float y, float widthMultiplier){
369357
counter = 0f;
370358
}
371359

372-
//lastAngle = Mathf.zero(dst, 0.4f) ? lastAngle : (-Angles.angleRad(x, y, lastX, lastY) + Mathf.pi);
373360
lastAngle = Mathf.zero(dst) ? lastAngle : -Angles.angleRad(lastX, lastY, x, y);
374361
lastX = x;
375362
lastY = y;
376363
lastW = width;
377364
calcProgress();
378365

379-
if(points.size > 0 && trailChance > 0f && Mathf.chanceDelta(trailChance * Mathf.clamp(dst / trailThreshold))){
366+
int psize = points.size;
367+
if(psize > 0 && trailChance > 0f && Mathf.chanceDelta(trailChance * Mathf.clamp(dst / trailThreshold))){
380368
trailEffect.at(
381369
x, y, width * trailWidth,
382-
tmp.set(trailColor).a(fadeInterp.apply(
383-
Mathf.clamp(points.items[points.size - 1]) *
384-
fadeAlpha + (1f - fadeAlpha)
385-
))
370+
tmp.set(trailColor).a(fadeInterp.apply(Mathf.clamp((psize / 4f / length) * fadeAlpha + (1f - fadeAlpha))))
386371
);
387372
}
388373
}
@@ -400,23 +385,12 @@ public void calcProgress(){
400385

401386
items[i + 3] = maxDst;
402387
maxDst += dst;
403-
//items[i + 3] = dst;
404388
}
405389

406390
float frac = psize / 4f / length;
407391
for(int i = 0; i < psize; i += 4){
408392
items[i + 3] = Mathf.clamp((items[i + 3] / maxDst) * frac);
409393
}
410-
411-
/*float
412-
frac = psize / 4f / length,
413-
first = items[3], last = 0f;
414-
for(int i = 0; i < psize; i += 4){
415-
float v = items[i + 3];
416-
417-
items[i + 3] = Mathf.clamp((v + last - first) / maxDst * frac);
418-
last += v;
419-
}*/
420394
}
421395
}
422396
}

0 commit comments

Comments
 (0)