Lambda memory allocation optimizations
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package mindustry.entities;
|
||||
|
||||
import arc.func.*;
|
||||
import arc.math.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.struct.*;
|
||||
@@ -23,7 +24,9 @@ public class EntityCollisions{
|
||||
private Rect r2 = new Rect();
|
||||
|
||||
//entity collisions
|
||||
private Seq<Hitboxc> arrOut = new Seq<>();
|
||||
private Seq<Hitboxc> arrOut = new Seq<>(Hitboxc.class);
|
||||
private Cons<Hitboxc> hitCons = this::updateCollision;
|
||||
private Cons<QuadTree> treeCons = tree -> tree.intersect(r2, arrOut);
|
||||
|
||||
public void moveCheck(Hitboxc entity, float deltax, float deltay, SolidPred solidCheck){
|
||||
if(!solidCheck.solid(entity.tileX(), entity.tileY())){
|
||||
@@ -36,7 +39,7 @@ public class EntityCollisions{
|
||||
}
|
||||
|
||||
public void move(Hitboxc entity, float deltax, float deltay, SolidPred solidCheck){
|
||||
if(Math.abs(deltax) < 0.0001f & Math.abs(deltay) < 0.0001f) return;
|
||||
if(Math.abs(deltax) < 0.0001f & Math.abs(deltay) < 0.0001f) return;
|
||||
|
||||
boolean movedx = false;
|
||||
|
||||
@@ -213,28 +216,34 @@ public class EntityCollisions{
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends Hitboxc> void collide(EntityGroup<T> groupa){
|
||||
groupa.each(solid -> {
|
||||
solid.hitbox(r1);
|
||||
r1.x += (solid.lastX() - solid.getX());
|
||||
r1.y += (solid.lastY() - solid.getY());
|
||||
groupa.each((Cons<T>)hitCons);
|
||||
}
|
||||
|
||||
solid.hitbox(r2);
|
||||
r2.merge(r1);
|
||||
private void updateCollision(Hitboxc solid){
|
||||
solid.hitbox(r1);
|
||||
r1.x += (solid.lastX() - solid.getX());
|
||||
r1.y += (solid.lastY() - solid.getY());
|
||||
|
||||
arrOut.clear();
|
||||
solid.hitbox(r2);
|
||||
r2.merge(r1);
|
||||
|
||||
//get all targets based on what entity wants to collide with
|
||||
solid.getCollisions(tree -> tree.intersect(r2, arrOut));
|
||||
arrOut.clear();
|
||||
|
||||
for(Hitboxc sc : arrOut){
|
||||
sc.hitbox(r1);
|
||||
if(r2.overlaps(r1)){
|
||||
checkCollide(solid, sc);
|
||||
//break out of loop when this object hits something
|
||||
if(!solid.isAdded()) return;
|
||||
}
|
||||
//get all targets based on what entity wants to collide with
|
||||
solid.getCollisions(treeCons);
|
||||
|
||||
var items = arrOut.items;
|
||||
int size = arrOut.size;
|
||||
|
||||
for(int i = 0; i < size; i++){
|
||||
Hitboxc sc = items[i];
|
||||
sc.hitbox(r1);
|
||||
if(r2.overlaps(r1)){
|
||||
checkCollide(solid, sc);
|
||||
//break out of loop when this object hits something
|
||||
if(!solid.isAdded()) return;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public interface SolidPred{
|
||||
|
||||
Reference in New Issue
Block a user