Skip to content

Commit 17c9c5f

Browse files
committed
Slash pooling
1 parent c8f8d93 commit 17c9c5f

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

src/progressed/graphics/renders/SlashRenderer.java

+14-6
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
public class SlashRenderer{
1616
private static int maxCount = 4;
1717
private static SlashShader slashShader;
18-
private static final Seq<SlashData> slashes = new Seq<>();
18+
private static final Seq<SlashData> slashes = new Seq<>(SlashData.class);
19+
private static int slashIndex = 0;
1920
private static FrameBuffer buffer;
2021

2122
private static void createShader(){
@@ -38,7 +39,13 @@ public static void init(){
3839

3940
public static void addSlash(float x, float y, float a, float off, float length, float width, float color){
4041
if(off <= 0.001f) return;
41-
slashes.add(new SlashData(x, y, a, off, length, width, color));
42+
if(slashes.size <= slashIndex) slashes.add(new SlashData());
43+
44+
//Pool slashes
45+
var slash = slashes.items[slashIndex];
46+
slash.set(x, y, a, off, length, width, color);
47+
48+
slashIndex++;
4249
}
4350

4451
public static void draw(){
@@ -50,7 +57,7 @@ public static void draw(){
5057
Draw.draw(BHLayer.end + 1f, () -> {
5158
buffer.end();
5259

53-
if(slashes.size > maxCount) createShader();
60+
while(slashes.size > maxCount) createShader();
5461

5562
float[] slashArray = new float[slashes.size * 4];
5663
for(int i = 0; i < slashes.size; i++){
@@ -71,12 +78,13 @@ public static void draw(){
7178
drawSlashes();
7279
}
7380

74-
slashes.clear();
81+
slashIndex = 0;
7582
});
7683
}
7784

7885
private static void drawSlashes(){
79-
for(SlashData slash : slashes){
86+
for(int i = 0; i < slashIndex; i++){
87+
SlashData slash = slashes.items[i];
8088
float ang = slash.angle * Mathf.radDeg;
8189
Tmp.v1.trns(ang, slash.length);
8290
Tmp.v2.trns(ang + 90f, slash.width);
@@ -112,7 +120,7 @@ private static class SlashData{
112120
public float x, y, angle, offset;
113121
public float length, width, color;
114122

115-
public SlashData(float x, float y, float angle, float offset, float length, float width, float color){
123+
public void set(float x, float y, float angle, float offset, float length, float width, float color){
116124
this.x = x;
117125
this.y = y;
118126
this.angle = angle;

src/progressed/world/blocks/defence/turret/testing/ArcBulletScatterTestTurret.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@
1111
import static mindustry.Vars.*;
1212

1313
public class ArcBulletScatterTestTurret extends ArcBulletTestTurret{
14-
public float bAccel = 0.3f;
14+
public float bAccel = 0f;
1515

1616
public ArcBulletScatterTestTurret(String name){
1717
super(name);
1818

19-
2019
shootType = new ArcBoltBulletType(15f, 30f){{
2120
trailLength = 40;
2221
}};

0 commit comments

Comments
 (0)