Tile field encapsulation

This commit is contained in:
Anuken
2018-07-27 10:52:14 -04:00
parent 23bd9a989b
commit 01f6904f82
7 changed files with 27 additions and 18 deletions
@@ -89,7 +89,7 @@ public class Pathfinder{
} }
private boolean passable(Tile tile, Team team){ private boolean passable(Tile tile, Team team){
return (tile.block() == Blocks.air && !tile.floor().isLiquid && tile.cliffs == 0 && !tile.floor().solid && !(tile.floor().isLiquid && (tile.floor().damageTaken > 0 || tile.floor().drownTime > 0))) return (tile.block() == Blocks.air && !tile.floor().isLiquid && !tile.hasCliffs() && !tile.floor().solid && !(tile.floor().isLiquid && (tile.floor().damageTaken > 0 || tile.floor().drownTime > 0)))
|| (tile.breakable() && (tile.getTeam() != team)) || !tile.solid(); || (tile.breakable() && (tile.getTeam() != team)) || !tile.solid();
} }
@@ -179,7 +179,7 @@ public class Puddle extends BaseEntity implements SaveTrait, Poolable, DrawTrait
float deposited = Math.min((amount - maxLiquid / 1.5f) / 4f, 0.3f) * Timers.delta(); float deposited = Math.min((amount - maxLiquid / 1.5f) / 4f, 0.3f) * Timers.delta();
for(GridPoint2 point : Geometry.d4){ for(GridPoint2 point : Geometry.d4){
Tile other = world.tile(tile.x + point.x, tile.y + point.y); Tile other = world.tile(tile.x + point.x, tile.y + point.y);
if(other.block() == Blocks.air && other.cliffs == 0){ if(other.block() == Blocks.air && !other.hasCliffs()){
deposit(other, tile, liquid, deposited, generation + 1); deposit(other, tile, liquid, deposited, generation + 1);
amount -= deposited / 2f; //tweak to speed up/slow down puddle propagation amount -= deposited / 2f; //tweak to speed up/slow down puddle propagation
} }
@@ -25,9 +25,7 @@ import java.nio.ByteBuffer;
import static io.anuke.mindustry.Vars.*; import static io.anuke.mindustry.Vars.*;
/** /**Used for rendering fog of war. A framebuffer is used for this.*/
* Used for rendering fog of war. A framebuffer is used for this.
*/
public class FogRenderer implements Disposable{ public class FogRenderer implements Disposable{
private static final int extraPadding = 3; private static final int extraPadding = 3;
private static final int shadowPadding = 1; private static final int shadowPadding = 1;
@@ -127,7 +127,7 @@ public class WorldGenerator{
tile.updateOcclusion(); tile.updateOcclusion();
//fix things on cliffs that shouldn't be //fix things on cliffs that shouldn't be
if(tile.block() != Blocks.air && tile.cliffs != 0){ if(tile.block() != Blocks.air && tile.hasCliffs()){
tile.setBlock(Blocks.air); tile.setBlock(Blocks.air);
} }
} }
@@ -158,7 +158,7 @@ public class WorldGenerator{
Tile tile = tiles[x][y]; Tile tile = tiles[x][y];
if(!tile.floor().hasOres || tile.cliffs != 0 || tile.block() != Blocks.air){ if(!tile.floor().hasOres || tile.hasCliffs() || tile.block() != Blocks.air){
continue; continue;
} }
+2 -2
View File
@@ -154,7 +154,7 @@ public class Build{
for(int dy = 0; dy < type.size; dy++){ for(int dy = 0; dy < type.size; dy++){
Tile other = world.tile(x + dx + offsetx, y + dy + offsety); Tile other = world.tile(x + dx + offsetx, y + dy + offsety);
if(other == null || (other.block() != Blocks.air && !other.block().alwaysReplace) if(other == null || (other.block() != Blocks.air && !other.block().alwaysReplace)
|| other.cliffs != 0 || !other.floor().placeableOn || || other.hasCliffs() || !other.floor().placeableOn ||
(tile.floor().liquidDrop != null && !type.floating)){ (tile.floor().liquidDrop != null && !type.floating)){
return false; return false;
} }
@@ -164,7 +164,7 @@ public class Build{
}else{ }else{
return (tile.getTeam() == Team.none || tile.getTeam() == team) return (tile.getTeam() == Team.none || tile.getTeam() == team)
&& (tile.floor().liquidDrop == null || type.floating) && (tile.floor().liquidDrop == null || type.floating)
&& tile.floor().placeableOn && tile.cliffs == 0 && tile.floor().placeableOn && !tile.hasCliffs()
&& ((type.canReplace(tile.block()) && ((type.canReplace(tile.block())
&& !(type == tile.block() && rotation == tile.getRotation() && type.rotate)) || tile.block().alwaysReplace || tile.block() == Blocks.air) && !(type == tile.block() && rotation == tile.getRotation() && type.rotate)) || tile.block().alwaysReplace || tile.block() == Blocks.air)
&& tile.block().isMultiblock() == type.isMultiblock() && type.canPlaceOn(tile); && tile.block().isMultiblock() == type.isMultiblock() && type.canPlaceOn(tile);
+16 -5
View File
@@ -29,14 +29,13 @@ public class Tile implements PosTrait, TargetTrait{
* This is relative to the block it is linked to; negate coords to find the link. * This is relative to the block it is linked to; negate coords to find the link.
*/ */
public byte link = 0; public byte link = 0;
public short x, y;
/** Tile traversal cost. */ /** Tile traversal cost. */
public byte cost = 1; public byte cost = 1;
/** Position of cliffs around the tile, packed into bits 0-8. */
public byte cliffs;
/** Tile entity, usually null. */ /** Tile entity, usually null. */
public TileEntity entity; public TileEntity entity;
/** Block ID data. */ public short x, y;
/** Position of cliffs around the tile, packed into bits 0-8. */
private byte cliffs;
private Block wall; private Block wall;
private Floor floor; private Floor floor;
/** Rotation, 0-3. Also used to store offload location for routers, in which case it can be any number. */ /** Rotation, 0-3. Also used to store offload location for routers, in which case it can be any number. */
@@ -197,6 +196,18 @@ public class Tile implements PosTrait, TargetTrait{
this.elevation = (byte)elevation; this.elevation = (byte)elevation;
} }
public byte getCliffs(){
return cliffs;
}
public void setCliffs(byte cliffs){
this.cliffs = cliffs;
}
public boolean hasCliffs(){
return getCliffs() != 0;
}
public boolean passable(){ public boolean passable(){
Block block = block(); Block block = block();
Block floor = floor(); Block floor = floor();
@@ -212,7 +223,7 @@ public class Tile implements PosTrait, TargetTrait{
public boolean solid(){ public boolean solid(){
Block block = block(); Block block = block();
Block floor = floor(); Block floor = floor();
return block.solid || cliffs != 0 || (floor.solid && (block == Blocks.air || block.solidifes)) || block.isSolidFor(this) return block.solid || getCliffs() != 0 || (floor.solid && (block == Blocks.air || block.solidifes)) || block.isSolidFor(this)
|| (isLinked() && getLinked().block().isSolidFor(getLinked())); || (isLinked() && getLinked().block().isSolidFor(getLinked()));
} }
@@ -140,12 +140,12 @@ public class Floor extends Block{
Draw.rect(variantRegions[Mathf.randomSeed(tile.id(), 0, Math.max(0, variantRegions.length - 1))], tile.worldx(), tile.worldy()); Draw.rect(variantRegions[Mathf.randomSeed(tile.id(), 0, Math.max(0, variantRegions.length - 1))], tile.worldx(), tile.worldy());
if(tile.cliffs != 0 && cliffRegions != null){ if(tile.hasCliffs() && cliffRegions != null){
for(int i = 0; i < 4; i++){ for(int i = 0; i < 4; i++){
if((tile.cliffs & (1 << i * 2)) != 0){ if((tile.getCliffs() & (1 << i * 2)) != 0){
Draw.colorl(i > 1 ? 0.6f : 1f); Draw.colorl(i > 1 ? 0.6f : 1f);
boolean above = (tile.cliffs & (1 << ((i + 1) % 4) * 2)) != 0, below = (tile.cliffs & (1 << (Mathf.mod(i - 1, 4)) * 2)) != 0; boolean above = (tile.getCliffs() & (1 << ((i + 1) % 4) * 2)) != 0, below = (tile.getCliffs() & (1 << (Mathf.mod(i - 1, 4)) * 2)) != 0;
if(above && below){ if(above && below){
Draw.rect(cliffRegions[0], tile.worldx(), tile.worldy(), i * 90); Draw.rect(cliffRegions[0], tile.worldx(), tile.worldy(), i * 90);
@@ -169,7 +169,7 @@ public class Floor extends Block{
} }
protected void drawEdges(Tile tile, boolean sameLayer){ protected void drawEdges(Tile tile, boolean sameLayer){
if(!blend || tile.cliffs > 0) return; if(!blend || tile.getCliffs() > 0) return;
for(int i = 0; i < 8; i++){ for(int i = 0; i < 8; i++){
int dx = Geometry.d8[i].x, dy = Geometry.d8[i].y; int dx = Geometry.d8[i].x, dy = Geometry.d8[i].y;