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

@@ -62,7 +62,7 @@ public class BaseRegistry{
//calculate averages
if(tile.block instanceof Drill || tile.block instanceof Pump){
Tmp.v1.add(tile.x*tilesize + tile.block.offset(), tile.y*tilesize + tile.block.offset());
Tmp.v1.add(tile.x*tilesize + tile.block.offset, tile.y*tilesize + tile.block.offset);
drills ++;
}
}

View File

@@ -112,14 +112,14 @@ public class MapRenderer implements Disposable{
if(wall.rotate){
mesh.draw(idxWall, region,
wx * tilesize + wall.offset(), wy * tilesize + wall.offset(),
wx * tilesize + wall.offset, wy * tilesize + wall.offset,
region.getWidth() * Draw.scl, region.getHeight() * Draw.scl, tile.rotdeg() - 90);
}else{
float width = region.getWidth() * Draw.scl, height = region.getHeight() * Draw.scl;
mesh.draw(idxWall, region,
wx * tilesize + wall.offset() + (tilesize - width) / 2f,
wy * tilesize + wall.offset() + (tilesize - height) / 2f,
wx * tilesize + wall.offset + (tilesize - width) / 2f,
wy * tilesize + wall.offset + (tilesize - height) / 2f,
width, height);
}
}else{

View File

@@ -87,7 +87,7 @@ abstract class PayloadComp implements Posc, Rotc, Hitboxc{
/** @return whether the tile has been successfully placed. */
boolean dropBlock(BlockPayload payload){
Building tile = payload.entity;
int tx = Vars.world.toTile(x - tile.block().offset()), ty = Vars.world.toTile(y - tile.block().offset());
int tx = Vars.world.toTile(x - tile.block().offset), ty = Vars.world.toTile(y - tile.block().offset);
Tile on = Vars.world.tile(tx, ty);
if(on != null && Build.validPlace(tile.block(), tile.team(), tx, ty, tile.rotation())){
int rot = (int)((rotation + 45f) / 90f) % 4;

View File

@@ -117,11 +117,11 @@ public class BuildPlan{
}
public float drawx(){
return x*tilesize + block.offset();
return x*tilesize + block.offset;
}
public float drawy(){
return y*tilesize + block.offset();
return y*tilesize + block.offset;
}
public BuildPlan configure(Object config){

View File

@@ -601,7 +601,7 @@ public class Schematics implements Loadable{
});
//rotate actual request, centered on its multiblock position
float wx = (req.x - ox) * tilesize + req.block.offset(), wy = (req.y - oy) * tilesize + req.block.offset();
float wx = (req.x - ox) * tilesize + req.block.offset, wy = (req.y - oy) * tilesize + req.block.offset;
float x = wx;
if(direction >= 0){
wx = -wy;
@@ -610,8 +610,8 @@ public class Schematics implements Loadable{
wx = wy;
wy = -x;
}
req.x = (short)(world.toTile(wx - req.block.offset()) + ox);
req.y = (short)(world.toTile(wy - req.block.offset()) + oy);
req.x = (short)(world.toTile(wx - req.block.offset) + ox);
req.y = (short)(world.toTile(wy - req.block.offset) + oy);
req.rotation = (byte)Mathf.mod(req.rotation + direction, 4);
});

View File

@@ -114,11 +114,11 @@ public class BlockRenderer implements Disposable{
if(brokenFade > 0.001f){
for(BlockPlan block : state.teams.get(player.team()).blocks){
Block b = content.block(block.block);
if(!camera.bounds(Tmp.r1).grow(tilesize * 2f).overlaps(Tmp.r2.setSize(b.size * tilesize).setCenter(block.x * tilesize + b.offset(), block.y * tilesize + b.offset()))) continue;
if(!camera.bounds(Tmp.r1).grow(tilesize * 2f).overlaps(Tmp.r2.setSize(b.size * tilesize).setCenter(block.x * tilesize + b.offset, block.y * tilesize + b.offset))) continue;
Draw.alpha(0.33f * brokenFade);
Draw.mixcol(Color.white, 0.2f + Mathf.absin(Time.globalTime(), 6f, 0.2f));
Draw.rect(b.icon(Cicon.full), block.x * tilesize + b.offset(), block.y * tilesize + b.offset(), b.rotate ? block.rotation * 90 : 0f);
Draw.rect(b.icon(Cicon.full), block.x * tilesize + b.offset, block.y * tilesize + b.offset, b.rotate ? block.rotation * 90 : 0f);
}
Draw.reset();
}

View File

@@ -68,8 +68,8 @@ public class Drawf{
Point2 p = Geometry.d8edge[i];
float offset = -Math.max(block.size - 1, 0) / 2f * tilesize;
Draw.rect("block-select",
x*tilesize + block.offset() + offset * p.x,
y*tilesize + block.offset() + offset * p.y, i * 90);
x*tilesize + block.offset + offset * p.x,
y*tilesize + block.offset + offset * p.y, i * 90);
}
Draw.reset();
}

View File

@@ -431,7 +431,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
});
//rotate actual request, centered on its multiblock position
float wx = (req.x - ox) * tilesize + req.block.offset(), wy = (req.y - oy) * tilesize + req.block.offset();
float wx = (req.x - ox) * tilesize + req.block.offset, wy = (req.y - oy) * tilesize + req.block.offset;
float x = wx;
if(direction >= 0){
wx = -wy;
@@ -440,8 +440,8 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
wx = wy;
wy = -x;
}
req.x = world.toTile(wx - req.block.offset()) + ox;
req.y = world.toTile(wy - req.block.offset()) + oy;
req.x = world.toTile(wx - req.block.offset) + ox;
req.y = world.toTile(wy - req.block.offset) + oy;
req.rotation = Mathf.mod(req.rotation + direction, 4);
});
}
@@ -450,12 +450,12 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
int origin = (x ? schemOriginX() : schemOriginY()) * tilesize;
requests.each(req -> {
float value = -((x ? req.x : req.y) * tilesize - origin + req.block.offset()) + origin;
float value = -((x ? req.x : req.y) * tilesize - origin + req.block.offset) + origin;
if(x){
req.x = (int)((value - req.block.offset()) / tilesize);
req.x = (int)((value - req.block.offset) / tilesize);
}else{
req.y = (int)((value - req.block.offset()) / tilesize);
req.y = (int)((value - req.block.offset) / tilesize);
}
req.pointConfig(p -> {
@@ -505,10 +505,10 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
if(!req.breaking){
r1.setSize(req.block.size * tilesize);
r1.setCenter(other.worldx() + req.block.offset(), other.worldy() + req.block.offset());
r1.setCenter(other.worldx() + req.block.offset, other.worldy() + req.block.offset);
}else{
r1.setSize(other.block().size * tilesize);
r1.setCenter(other.worldx() + other.block().offset(), other.worldy() + other.block().offset());
r1.setCenter(other.worldx() + other.block().offset, other.worldy() + other.block().offset);
}
return r2.overlaps(r1);
@@ -797,10 +797,6 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
&& tile.block() == Blocks.air && player.dst(tile.worldx(), tile.worldy()) <= miningRange;
}
Building entAt(float x, float y){
return world.build(tileX(x), tileY(y));
}
/** Returns the tile at the specified MOUSE coordinates. */
Tile tileAt(float x, float y){
return world.tile(tileX(x), tileY(y));
@@ -817,7 +813,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
int tileX(float cursorX){
Vec2 vec = Core.input.mouseWorld(cursorX, 0);
if(selectedBlock()){
vec.sub(block.offset(), block.offset());
vec.sub(block.offset, block.offset);
}
return world.toTile(vec.x);
}
@@ -825,7 +821,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
int tileY(float cursorY){
Vec2 vec = Core.input.mouseWorld(0, cursorY);
if(selectedBlock()){
vec.sub(block.offset(), block.offset());
vec.sub(block.offset, block.offset);
}
return world.toTile(vec.y);
}
@@ -989,15 +985,15 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
Draw.color(!valid ? Pal.removeBack : Pal.accentBack);
Draw.rect(Core.atlas.find("place-arrow"),
x * tilesize + block.offset() + dx*trns,
y * tilesize + block.offset() - 1 + dy*trns,
x * tilesize + block.offset + dx*trns,
y * tilesize + block.offset - 1 + dy*trns,
Core.atlas.find("place-arrow").getWidth() * Draw.scl,
Core.atlas.find("place-arrow").getHeight() * Draw.scl, rotation * 90 - 90);
Draw.color(!valid ? Pal.remove : Pal.accent);
Draw.rect(Core.atlas.find("place-arrow"),
x * tilesize + block.offset() + dx*trns,
y * tilesize + block.offset() + dy*trns,
x * tilesize + block.offset + dx*trns,
y * tilesize + block.offset + dy*trns,
Core.atlas.find("place-arrow").getWidth() * Draw.scl,
Core.atlas.find("place-arrow").getHeight() * Draw.scl, rotation * 90 - 90);
}
@@ -1054,7 +1050,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
for(int i = 0; i < points.size; i++){
Point2 point = points.get(i);
if(block != null && Tmp.r2.setSize(block.size * tilesize).setCenter(point.x * tilesize + block.offset(), point.y * tilesize + block.offset()).overlaps(Tmp.r3)){
if(block != null && Tmp.r2.setSize(block.size * tilesize).setCenter(point.x * tilesize + block.offset, point.y * tilesize + block.offset).overlaps(Tmp.r3)){
continue;
}
@@ -1069,7 +1065,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
line.last = next == null;
cons.get(line);
Tmp.r3.setSize(block.size * tilesize).setCenter(point.x * tilesize + block.offset(), point.y * tilesize + block.offset());
Tmp.r3.setSize(block.size * tilesize).setCenter(point.x * tilesize + block.offset, point.y * tilesize + block.offset);
}
}

View File

@@ -95,7 +95,7 @@ public class MobileInput extends InputHandler implements GestureListener{
/** Returns whether this block overlaps any selection requests. */
boolean checkOverlapPlacement(int x, int y, Block block){
r2.setSize(block.size * tilesize);
r2.setCenter(x * tilesize + block.offset(), y * tilesize + block.offset());
r2.setCenter(x * tilesize + block.offset, y * tilesize + block.offset);
for(BuildPlan req : selectRequests){
Tile other = req.tile();
@@ -103,7 +103,7 @@ public class MobileInput extends InputHandler implements GestureListener{
if(other == null || req.breaking) continue;
r1.setSize(req.block.size * tilesize);
r1.setCenter(other.worldx() + req.block.offset(), other.worldy() + req.block.offset());
r1.setCenter(other.worldx() + req.block.offset, other.worldy() + req.block.offset);
if(r2.overlaps(r1)){
return true;
@@ -116,7 +116,7 @@ public class MobileInput extends InputHandler implements GestureListener{
if(other == null || req.breaking) continue;
r1.setSize(req.block.size * tilesize);
r1.setCenter(other.worldx() + req.block.offset(), other.worldy() + req.block.offset());
r1.setCenter(other.worldx() + req.block.offset, other.worldy() + req.block.offset);
if(r2.overlaps(r1)){
return true;
@@ -137,11 +137,11 @@ public class MobileInput extends InputHandler implements GestureListener{
if(!req.breaking){
r1.setSize(req.block.size * tilesize);
r1.setCenter(other.worldx() + req.block.offset(), other.worldy() + req.block.offset());
r1.setCenter(other.worldx() + req.block.offset, other.worldy() + req.block.offset);
}else{
r1.setSize(other.block().size * tilesize);
r1.setCenter(other.worldx() + other.block().offset(), other.worldy() + other.block().offset());
r1.setCenter(other.worldx() + other.block().offset, other.worldy() + other.block().offset);
}
if(r2.overlaps(r1)) return req;
@@ -538,7 +538,7 @@ public class MobileInput extends InputHandler implements GestureListener{
Fx.tapBlock.at(cursor.worldx(), cursor.worldy(), 1f);
}else if(block != null){
updateLine(lineStartX, lineStartY, cursor.x, cursor.y);
Fx.tapBlock.at(cursor.worldx() + block.offset(), cursor.worldy() + block.offset(), block.size);
Fx.tapBlock.at(cursor.worldx() + block.offset, cursor.worldy() + block.offset, block.size);
}
}

View File

@@ -154,7 +154,7 @@ public class Placement{
public static NormalizeDrawResult normalizeDrawArea(Block block, int startx, int starty, int endx, int endy, boolean snap, int maxLength, float scaling){
normalizeArea(startx, starty, endx, endy, 0, snap, maxLength);
float offset = block.offset();
float offset = block.offset;
drawResult.x = result.x * tilesize;
drawResult.y = result.y * tilesize;

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{