diff --git a/core/src/mindustry/entities/Damage.java b/core/src/mindustry/entities/Damage.java index 3ff230a0df..b1a0e4bf9c 100644 --- a/core/src/mindustry/entities/Damage.java +++ b/core/src/mindustry/entities/Damage.java @@ -6,6 +6,7 @@ import arc.math.*; import arc.math.geom.*; import arc.struct.*; import arc.util.*; +import arc.util.pooling.*; import mindustry.content.*; import mindustry.core.*; import mindustry.game.EventType.*; @@ -27,6 +28,7 @@ public class Damage{ private static final IntSet collidedBlocks = new IntSet(); private static final IntFloatMap damages = new IntFloatMap(); private static final Seq collided = new Seq<>(); + private static final Pool collidePool = Pools.get(Collided.class, Collided::new); private static final Seq builds = new Seq<>(); private static final FloatSeq distances = new FloatSeq(); @@ -227,8 +229,6 @@ public class Damage{ length = findPierceLength(hitter, pierceCap, length); } - collided.clear(); - collidedBlocks.clear(); vec.trnsExact(angle, length); @@ -239,14 +239,14 @@ public class Damage{ Building tile = world.build(cx, cy); boolean collide = tile != null && hitter.checkUnderBuild(tile, cx * tilesize, cy * tilesize) && collidedBlocks.add(tile.pos()); if(collide){ - collided.add(new Collided(cx * tilesize, cy * tilesize, tile)); + collided.add(collidePool.obtain().set(cx * tilesize, cy * tilesize, tile)); for(Point2 p : Geometry.d4){ Tile other = world.tile(p.x + cx, p.y + cy); if(other != null && (large || Intersector.intersectSegmentRectangle(seg1, seg2, other.getBounds(Tmp.r1)))){ Building build = other.build; if(build != null && hitter.checkUnderBuild(build, cx * tilesize, cy * tilesize) && collidedBlocks.add(build.pos())){ - collided.add(new Collided((p.x + cx * tilesize), (p.y + cy) * tilesize, build)); + collided.add(collidePool.obtain().set((p.x + cx * tilesize), (p.y + cy) * tilesize, build)); } } } @@ -267,7 +267,7 @@ public class Damage{ Vec2 vec = Geometry.raycastRect(x, y, x2, y2, hitrect.grow(expand * 2)); if(vec != null){ - collided.add(new Collided(vec.x, vec.y, u)); + collided.add(collidePool.obtain().set(vec.x, vec.y, u)); } } }); @@ -295,6 +295,9 @@ public class Damage{ } } }); + + collidePool.freeAll(collided); + collided.clear(); } /** @@ -616,10 +619,11 @@ public class Damage{ public float x, y; public Teamc target; - public Collided(float x, float y, Teamc target){ + public Collided set(float x, float y, Teamc target){ this.x = x; this.y = y; this.target = target; + return this; } } }