Cached Block#offset()

This commit is contained in:
Anuken
2020-07-19 16:34:06 -04:00
parent c398b89284
commit 6547a38567
24 changed files with 60 additions and 65 deletions

View File

@@ -96,6 +96,8 @@ public class Block extends UnlockableContent{
public boolean floating = false;
/** multiblock size */
public int size = 1;
/** multiblock offset */
public float offset = 0f;
/** Whether to draw this block in the expanded draw range. */
public boolean expanded = false;
/** Max of timers used. */
@@ -242,7 +244,7 @@ public class Block extends UnlockableContent{
float width = layout.width;
font.setColor(color);
float dx = x * tilesize + offset(), dy = y * tilesize + offset() + size * tilesize / 2f + 3;
float dx = x * tilesize + offset, dy = y * tilesize + offset + size * tilesize / 2f + 3;
font.draw(text, dx, dy + layout.height + 1, Align.center);
dy -= 1f;
Lines.stroke(2f, Color.darkGray);
@@ -470,13 +472,8 @@ public class Block extends UnlockableContent{
return entityType.get();
}
/** Offset for placing and drawing multiblocks. */
public float offset(){
return ((size + 1) % 2) * tilesize / 2f;
}
public Rect bounds(int x, int y, Rect rect){
return rect.setSize(size * tilesize).setCenter(x * tilesize + offset(), y * tilesize + offset());
return rect.setSize(size * tilesize).setCenter(x * tilesize + offset, y * tilesize + offset);
}
public boolean isMultiblock(){
@@ -604,6 +601,8 @@ public class Block extends UnlockableContent{
health = size * size * 40;
}
offset = ((size + 1) % 2) * tilesize / 2f;
buildCost = 0f;
for(ItemStack stack : requirements){
buildCost += stack.amount * stack.item.cost;

View File

@@ -73,11 +73,11 @@ public class Build{
return false;
}
if((type.solid || type.solidifes) && Units.anyEntities(x * tilesize + type.offset() - type.size*tilesize/2f, y * tilesize + type.offset() - type.size*tilesize/2f, type.size * tilesize, type.size*tilesize)){
if((type.solid || type.solidifes) && Units.anyEntities(x * tilesize + type.offset - type.size*tilesize/2f, y * tilesize + type.offset - type.size*tilesize/2f, type.size * tilesize, type.size*tilesize)){
return false;
}
if(state.teams.eachEnemyCore(team, core -> Mathf.dst(x * tilesize + type.offset(), y * tilesize + type.offset(), core.x, core.y) < state.rules.enemyCoreBuildRadius + type.size * tilesize / 2f)){
if(state.teams.eachEnemyCore(team, core -> Mathf.dst(x * tilesize + type.offset, y * tilesize + type.offset, core.x, core.y) < state.rules.enemyCoreBuildRadius + type.size * tilesize / 2f)){
return false;
}

View File

@@ -121,11 +121,11 @@ public class Tile implements Position, QuadTreeObject, Displayable{
}
public float drawx(){
return block().offset() + worldx();
return block().offset + worldx();
}
public float drawy(){
return block().offset() + worldy();
return block().offset + worldy();
}
public boolean isDarkened(){

View File

@@ -52,7 +52,7 @@ public class MendProjector extends Block{
@Override
public void drawPlace(int x, int y, int rotation, boolean valid){
Drawf.dashCircle(x * tilesize + offset(), y * tilesize + offset(), range, Pal.accent);
Drawf.dashCircle(x * tilesize + offset, y * tilesize + offset, range, Pal.accent);
}
public class MendEntity extends Building{

View File

@@ -43,7 +43,7 @@ public class OverdriveProjector extends Block{
@Override
public void drawPlace(int x, int y, int rotation, boolean valid){
Drawf.dashCircle(x * tilesize + offset(), y * tilesize + offset(), range, Pal.accent);
Drawf.dashCircle(x * tilesize + offset, y * tilesize + offset, range, Pal.accent);
}
@Override

View File

@@ -44,7 +44,7 @@ public class PointDefenseTurret extends Block{
@Override
public void drawPlace(int x, int y, int rotation, boolean valid){
Drawf.dashCircle(x * tilesize + offset(), y * tilesize + offset(), range, Pal.accent);
Drawf.dashCircle(x * tilesize + offset, y * tilesize + offset, range, Pal.accent);
}
@Override

View File

@@ -42,7 +42,7 @@ public class TractorBeamTurret extends Block{
@Override
public void drawPlace(int x, int y, int rotation, boolean valid){
Drawf.dashCircle(x * tilesize + offset(), y * tilesize + offset(), range, Pal.accent);
Drawf.dashCircle(x * tilesize + offset, y * tilesize + offset, range, Pal.accent);
}
@Override

View File

@@ -128,7 +128,7 @@ public abstract class Turret extends Block{
@Override
public void drawPlace(int x, int y, int rotation, boolean valid){
Drawf.dashCircle(x * tilesize + offset(), y * tilesize + offset(), range, Pal.placing);
Drawf.dashCircle(x * tilesize + offset, y * tilesize + offset, range, Pal.placing);
}
public static abstract class AmmoEntry{

View File

@@ -62,7 +62,7 @@ public class MassDriver extends Block{
//if so, draw a dotted line towards it while it is in range
float sin = Mathf.absin(Time.time(), 6f, 1f);
Tmp.v1.set(x * tilesize + offset(), y * tilesize + offset()).sub(selected.x, selected.y).limit((size / 2f + 1) * tilesize + sin + 0.5f);
Tmp.v1.set(x * tilesize + offset, y * tilesize + offset).sub(selected.x, selected.y).limit((size / 2f + 1) * tilesize + sin + 0.5f);
float x2 = x * tilesize - Tmp.v1.x, y2 = y * tilesize - Tmp.v1.y,
x1 = selected.x + Tmp.v1.x, y1 = selected.y + Tmp.v1.y;
int segs = (int)(selected.dst(x * tilesize, y * tilesize) / tilesize);

View File

@@ -119,7 +119,7 @@ public class PowerNode extends PowerBlock{
Lines.stroke(1f);
Draw.color(Pal.placing);
Drawf.circles(x * tilesize + offset(), y * tilesize + offset(), laserRange * tilesize);
Drawf.circles(x * tilesize + offset, y * tilesize + offset, laserRange * tilesize);
getPotentialLinks(tile, other -> {
Drawf.square(other.x, other.y, other.block().size * tilesize / 2f + 2f, Pal.place);
@@ -167,13 +167,13 @@ public class PowerNode extends PowerBlock{
public boolean overlaps(@Nullable Tile src, @Nullable Tile other){
if(src == null || other == null) return true;
return Intersector.overlaps(Tmp.cr1.set(src.worldx() + offset(), src.worldy() + offset(), laserRange * tilesize), Tmp.r1.setSize(size * tilesize).setCenter(other.worldx() + offset(), other.worldy() + offset()));
return Intersector.overlaps(Tmp.cr1.set(src.worldx() + offset, src.worldy() + offset, laserRange * tilesize), Tmp.r1.setSize(size * tilesize).setCenter(other.worldx() + offset, other.worldy() + offset));
}
protected void getPotentialLinks(Tile tile, Cons<Building> others){
Boolf<Building> valid = other -> other != null && other.tile() != tile && other.power() != null &&
((!other.block().outputsPower && other.block().consumesPower) || (other.block().outputsPower && !other.block().consumesPower) || other.block() instanceof PowerNode) &&
overlaps(tile.x * tilesize + offset(), tile.y * tilesize + offset(), other.tile(), laserRange * tilesize) && other.team() == player.team()
overlaps(tile.x * tilesize + offset, tile.y * tilesize + offset, other.tile(), laserRange * tilesize) && other.team() == player.team()
&& !other.proximity().contains(e -> e.tile() == tile) && !graphs.contains(other.power().graph);
tempTileEnts.clear();

View File

@@ -117,7 +117,7 @@ public class Drill extends Block{
if(returnItem != null){
float width = drawPlaceText(Core.bundle.formatFloat("bar.drillspeed", 60f / (drillTime + hardnessDrillMultiplier * returnItem.hardness) * returnCount, 2), x, y, valid);
float dx = x * tilesize + offset() - width/2f - 4f, dy = y * tilesize + offset() + size * tilesize / 2f + 5;
float dx = x * tilesize + offset - width/2f - 4f, dy = y * tilesize + offset + size * tilesize / 2f + 5;
Draw.mixcol(Color.darkGray, 1f);
Draw.rect(returnItem.icon(Cicon.small), dx, dy - 1);
Draw.reset();

View File

@@ -45,7 +45,7 @@ public class Pump extends LiquidBlock{
if(liquidDrop != null){
float width = drawPlaceText(Core.bundle.formatFloat("bar.pumpspeed", tiles * pumpAmount / size / size * 60f, 0), x, y, valid);
float dx = x * tilesize + offset() - width/2f - 4f, dy = y * tilesize + offset() + size * tilesize / 2f + 5;
float dx = x * tilesize + offset - width/2f - 4f, dy = y * tilesize + offset + size * tilesize / 2f + 5;
Draw.mixcol(Color.darkGray, 1f);
Draw.rect(liquidDrop.icon(Cicon.small), dx, dy - 1);
Draw.reset();

View File

@@ -53,7 +53,7 @@ public class RepairPoint extends Block{
@Override
public void drawPlace(int x, int y, int rotation, boolean valid){
Drawf.dashCircle(x * tilesize + offset(), y * tilesize + offset(), repairRadius, Pal.accent);
Drawf.dashCircle(x * tilesize + offset, y * tilesize + offset, repairRadius, Pal.accent);
}
@Override

View File

@@ -30,7 +30,7 @@ public class ResupplyPoint extends Block{
@Override
public void drawPlace(int x, int y, int rotation, boolean valid){
Drawf.dashCircle(x * tilesize + offset(), y * tilesize + offset(), range, Pal.placing);
Drawf.dashCircle(x * tilesize + offset, y * tilesize + offset, range, Pal.placing);
}
public class ResupplyPointEntity extends Building{