15
15
public class SlashRenderer {
16
16
private static int maxCount = 4 ;
17
17
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 ;
19
20
private static FrameBuffer buffer ;
20
21
21
22
private static void createShader (){
@@ -38,7 +39,13 @@ public static void init(){
38
39
39
40
public static void addSlash (float x , float y , float a , float off , float length , float width , float color ){
40
41
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 ++;
42
49
}
43
50
44
51
public static void draw (){
@@ -50,7 +57,7 @@ public static void draw(){
50
57
Draw .draw (BHLayer .end + 1f , () -> {
51
58
buffer .end ();
52
59
53
- if (slashes .size > maxCount ) createShader ();
60
+ while (slashes .size > maxCount ) createShader ();
54
61
55
62
float [] slashArray = new float [slashes .size * 4 ];
56
63
for (int i = 0 ; i < slashes .size ; i ++){
@@ -71,12 +78,13 @@ public static void draw(){
71
78
drawSlashes ();
72
79
}
73
80
74
- slashes . clear () ;
81
+ slashIndex = 0 ;
75
82
});
76
83
}
77
84
78
85
private static void drawSlashes (){
79
- for (SlashData slash : slashes ){
86
+ for (int i = 0 ; i < slashIndex ; i ++){
87
+ SlashData slash = slashes .items [i ];
80
88
float ang = slash .angle * Mathf .radDeg ;
81
89
Tmp .v1 .trns (ang , slash .length );
82
90
Tmp .v2 .trns (ang + 90f , slash .width );
@@ -112,7 +120,7 @@ private static class SlashData{
112
120
public float x , y , angle , offset ;
113
121
public float length , width , color ;
114
122
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 ){
116
124
this .x = x ;
117
125
this .y = y ;
118
126
this .angle = angle ;
0 commit comments