Various request rendering optimizations
This commit is contained in:
@@ -24,6 +24,20 @@ public class Units{
|
||||
private static int intResult;
|
||||
private static Building buildResult;
|
||||
|
||||
//prevents allocations in anyEntities
|
||||
private static boolean anyEntityGround;
|
||||
private static float aeX, aeY, aeW, aeH;
|
||||
private static final Cons<Unit> anyEntityLambda = unit -> {
|
||||
if(boolResult) return;
|
||||
if((unit.isGrounded() && !unit.hovering) == anyEntityGround){
|
||||
unit.hitboxTile(hitrect);
|
||||
|
||||
if(hitrect.overlaps(aeX, aeY, aeW, aeH)){
|
||||
boolResult = true;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Remote(called = Loc.server)
|
||||
public static void unitCapDeath(Unit unit){
|
||||
if(unit != null){
|
||||
@@ -145,18 +159,13 @@ public class Units{
|
||||
|
||||
public static boolean anyEntities(float x, float y, float width, float height, boolean ground){
|
||||
boolResult = false;
|
||||
anyEntityGround = ground;
|
||||
aeX = x;
|
||||
aeY = y;
|
||||
aeW = width;
|
||||
aeH = height;
|
||||
|
||||
nearby(x, y, width, height, unit -> {
|
||||
if(boolResult) return;
|
||||
if((unit.isGrounded() && !unit.hovering) == ground){
|
||||
unit.hitboxTile(hitrect);
|
||||
|
||||
if(hitrect.overlaps(x, y, width, height)){
|
||||
boolResult = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
nearby(x, y, width, height, anyEntityLambda);
|
||||
return boolResult;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package mindustry.entities.units;
|
||||
|
||||
import arc.func.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.math.geom.QuadTree.*;
|
||||
import arc.util.*;
|
||||
import mindustry.game.*;
|
||||
import mindustry.gen.*;
|
||||
@@ -10,7 +11,7 @@ import mindustry.world.*;
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
/** Class for storing build requests. Can be either a place or remove request. */
|
||||
public class BuildPlan implements Position{
|
||||
public class BuildPlan implements Position, QuadTreeObject{
|
||||
/** Position and rotation of this request. */
|
||||
public int x, y, rotation;
|
||||
/** Block being placed. If null, this is a breaking request.*/
|
||||
@@ -157,6 +158,15 @@ public class BuildPlan implements Position{
|
||||
return world.build(x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hitbox(Rect out){
|
||||
if(block != null){
|
||||
out.setCentered(x * tilesize + block.offset, y * tilesize + block.offset, block.size * tilesize);
|
||||
}else{
|
||||
out.setCentered(x * tilesize, y * tilesize, tilesize);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getX(){
|
||||
return drawx();
|
||||
|
||||
Reference in New Issue
Block a user