Merge branch 'remove-link-byte' of https://github.com/Anuken/Mindustry

This commit is contained in:
Anuken
2019-04-13 11:04:43 -04:00
9 changed files with 64 additions and 47 deletions

View File

@@ -305,7 +305,11 @@ public class World implements ApplicationListener{
} }
public void setBlock(Tile tile, Block block, Team team){ public void setBlock(Tile tile, Block block, Team team){
tile.setBlock(block, team); setBlock(tile, block, team, 0);
}
public void setBlock(Tile tile, Block block, Team team, int rotation){
tile.setBlock(block, team, rotation);
if(block.isMultiblock()){ if(block.isMultiblock()){
int offsetx = -(block.size - 1) / 2; int offsetx = -(block.size - 1) / 2;
int offsety = -(block.size - 1) / 2; int offsety = -(block.size - 1) / 2;

View File

@@ -45,7 +45,7 @@ public class EditorTile extends Tile{
@Override @Override
public void setBlock(Block type){ public void setBlock(Block type){
Block previous = wall; Block previous = block;
if(previous == type) return; if(previous == type) return;
super.setBlock(type); super.setBlock(type);
op(TileOp.get(x, y, (byte)OpType.block.ordinal(), previous.id, type.id)); op(TileOp.get(x, y, (byte)OpType.block.ordinal(), previous.id, type.id));
@@ -84,8 +84,8 @@ public class EditorTile extends Tile{
protected void changed(){ protected void changed(){
entity = null; entity = null;
if(wall == null){ if(block == null){
wall = Blocks.air; block = Blocks.air;
} }
if(floor == null){ if(floor == null){

View File

@@ -19,7 +19,7 @@ public enum EditorTool{
byte link = tile.getLinkByte(); byte link = tile.getLinkByte();
if(tile.block() instanceof BlockPart && link != 0){ if(tile.isLinked()){
x -= (Pack.leftByte(link) - 8); x -= (Pack.leftByte(link) - 8);
y -= (Pack.rightByte(link) - 8); y -= (Pack.rightByte(link) - 8);
@@ -27,7 +27,7 @@ public enum EditorTool{
} }
//do not. //do not.
if(tile.block() instanceof BlockPart){ if(tile.isLinked()){
return; return;
} }

View File

@@ -167,7 +167,7 @@ public class MapIO{
stream.writeByte(tile.getBlockID()); stream.writeByte(tile.getBlockID());
if(tile.block() instanceof BlockPart){ if(tile.block() instanceof BlockPart){
stream.writeByte(tile.link); stream.writeByte(tile.getLinkByte());
}else if(tile.entity != null){ }else if(tile.entity != null){
stream.writeByte(Pack.byteByte(tile.getTeamID(), tile.getRotation())); //team + rotation stream.writeByte(Pack.byteByte(tile.getTeamID(), tile.getRotation())); //team + rotation
stream.writeShort(/*(short)tile.entity.health*/tile.block().health); //health stream.writeShort(/*(short)tile.entity.health*/tile.block().health); //health
@@ -293,7 +293,7 @@ public class MapIO{
tile.setBlock(block); tile.setBlock(block);
if(block == Blocks.part){ if(block == Blocks.part){
tile.link = stream.readByte(); tile.setLinkByte(stream.readByte());
}else if(tile.entity != null){ }else if(tile.entity != null){
byte tr = stream.readByte(); byte tr = stream.readByte();
short health = stream.readShort(); short health = stream.readShort();

View File

@@ -67,7 +67,7 @@ public abstract class SaveFileVersion{
stream.writeByte(tile.getBlockID()); stream.writeByte(tile.getBlockID());
if(tile.block() == Blocks.part){ if(tile.block() == Blocks.part){
stream.writeByte(tile.link); stream.writeByte(tile.getLinkByte());
}else if(tile.entity != null){ }else if(tile.entity != null){
stream.writeByte(Pack.byteByte(tile.getTeamID(), tile.getRotation())); //team + rotation stream.writeByte(Pack.byteByte(tile.getTeamID(), tile.getRotation())); //team + rotation
stream.writeShort((short)tile.entity.health); //health stream.writeShort((short)tile.entity.health); //health
@@ -136,7 +136,7 @@ public abstract class SaveFileVersion{
tile.setBlock(block); tile.setBlock(block);
if(block == Blocks.part){ if(block == Blocks.part){
tile.link = stream.readByte(); tile.setLinkByte(stream.readByte());
}else if(tile.entity != null){ }else if(tile.entity != null){
byte tr = stream.readByte(); byte tr = stream.readByte();
short health = stream.readShort(); short health = stream.readShort();

View File

@@ -16,13 +16,7 @@ import io.anuke.mindustry.world.modules.*;
import static io.anuke.mindustry.Vars.*; import static io.anuke.mindustry.Vars.*;
public class Tile implements Position, TargetTrait{ public class Tile implements Position, TargetTrait{
/**
* The coordinates of the core tile this is linked to, in the form of two bytes packed into one.
* This is relative to the block it is linked to; negate coords to find the link.
*/
public byte link = 0;
/** Tile traversal cost. */ /** Tile traversal cost. */
public byte cost = 1; public byte cost = 1;
/** Weight of [ground] units on this tile. */ /** Weight of [ground] units on this tile. */
@@ -30,7 +24,7 @@ public class Tile implements Position, TargetTrait{
/** Tile entity, usually null. */ /** Tile entity, usually null. */
public TileEntity entity; public TileEntity entity;
public short x, y; public short x, y;
protected Block wall; protected Block block;
protected Floor floor; protected Floor floor;
/** Rotation, 0-3. Also used to store offload location, in which case it can be any number. */ /** Rotation, 0-3. Also used to store offload location, in which case it can be any number. */
private byte rotation; private byte rotation;
@@ -42,20 +36,20 @@ public class Tile implements Position, TargetTrait{
public Tile(int x, int y){ public Tile(int x, int y){
this.x = (short)x; this.x = (short)x;
this.y = (short)y; this.y = (short)y;
wall = floor = (Floor)Blocks.air; block = floor = (Floor)Blocks.air;
} }
public Tile(int x, int y, byte floor, byte wall){ public Tile(int x, int y, byte floor, byte block){
this(x, y); this(x, y);
this.floor = (Floor)content.block(floor); this.floor = (Floor)content.block(floor);
this.wall = content.block(wall); this.block = content.block(block);
changed(); changed();
} }
public Tile(int x, int y, byte floor, byte wall, byte rotation, byte team){ public Tile(int x, int y, byte floor, byte block, byte rotation, byte team){
this(x, y); this(x, y);
this.floor = (Floor)content.block(floor); this.floor = (Floor)content.block(floor);
this.wall = content.block(wall); this.block = content.block(block);
this.rotation = rotation; this.rotation = rotation;
changed(); changed();
this.team = team; this.team = team;
@@ -67,7 +61,7 @@ public class Tile implements Position, TargetTrait{
} }
public byte getBlockID(){ public byte getBlockID(){
return wall.id; return block.id;
} }
public byte getFloorID(){ public byte getFloorID(){
@@ -133,7 +127,7 @@ public class Tile implements Position, TargetTrait{
} }
public Block block(){ public Block block(){
return wall; return block;
} }
public Floor overlay(){ public Floor overlay(){
@@ -142,7 +136,7 @@ public class Tile implements Position, TargetTrait{
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public <T extends Block> T cblock(){ public <T extends Block> T cblock(){
return (T)wall; return (T)block;
} }
@Override @Override
@@ -158,27 +152,35 @@ public class Tile implements Position, TargetTrait{
return team; return team;
} }
public void setBlock(Block type, Team team, int rotation){
preChanged();
this.block = type;
this.team = (byte)team.ordinal();
this.rotation = 0;
this.rotation = (byte)Mathf.mod(rotation, 4);
changed();
}
public void setBlock(Block type, int rotation){ public void setBlock(Block type, int rotation){
preChanged(); preChanged();
if(rotation < 0) rotation = (-rotation + 2); this.block = type;
this.wall = type; this.rotation = 0;
this.link = 0; this.rotation = (byte)Mathf.mod(rotation, 4);
setRotation((byte)(rotation % 4));
changed(); changed();
} }
public void setBlock(Block type, Team team){ public void setBlock(Block type, Team team){
preChanged(); preChanged();
this.wall = type; this.block = type;
this.team = (byte)team.ordinal(); this.team = (byte)team.ordinal();
this.link = 0; this.rotation = 0;
changed(); changed();
} }
public void setBlock(Block type){ public void setBlock(Block type){
preChanged(); preChanged();
this.wall = type; this.block = type;
this.link = 0; this.rotation = 0;
changed(); changed();
} }
@@ -241,7 +243,7 @@ public class Tile implements Position, TargetTrait{
public boolean breakable(){ public boolean breakable(){
Block block = block(); Block block = block();
if(link == 0){ if(!isLinked()){
return (block.destructible || block.breakable || block.update); return (block.destructible || block.breakable || block.update);
}else{ }else{
return getLinked() != this && getLinked().getLinked() == null && getLinked().breakable(); return getLinked() != this && getLinked().getLinked() == null && getLinked().breakable();
@@ -253,21 +255,21 @@ public class Tile implements Position, TargetTrait{
} }
public boolean isLinked(){ public boolean isLinked(){
return link != 0; return block == Blocks.part;
} }
public byte getLinkByte(){ public byte getLinkByte(){
return link; return rotation;
} }
public void setLinkByte(byte b){ public void setLinkByte(byte b){
this.link = b; this.rotation = b;
} }
/** Sets this to a linked tile, which sets the block to a part. dx and dy can only be -8-7. */ /** Sets this to a linked tile, which sets the block to a part. dx and dy can only be -8-7. */
public void setLinked(byte dx, byte dy){ public void setLinked(byte dx, byte dy){
setBlock(Blocks.part); setBlock(Blocks.part);
link = Pack.byteByte((byte)(dx + 8), (byte)(dy + 8)); rotation = Pack.byteByte((byte)(dx + 8), (byte)(dy + 8));
} }
/** /**
@@ -315,12 +317,10 @@ public class Tile implements Position, TargetTrait{
/** Returns the block the multiblock is linked to, or null if it is not linked to any block. */ /** Returns the block the multiblock is linked to, or null if it is not linked to any block. */
public Tile getLinked(){ public Tile getLinked(){
if(link == 0){ if(!isLinked()){
return null; return null;
}else{ }else{
byte dx = Pack.leftByte(link); return world.tile(x + linkX(rotation), y + linkY(rotation));
byte dy = Pack.rightByte(link);
return world.tile(x - (dx - 8), y - (dy - 8));
} }
} }
@@ -452,7 +452,7 @@ public class Tile implements Position, TargetTrait{
@Override @Override
public boolean isDead(){ public boolean isDead(){
return false; //tiles never die return entity == null;
} }
@Override @Override
@@ -486,6 +486,16 @@ public class Tile implements Position, TargetTrait{
Block floor = floor(); Block floor = floor();
return floor.name + ":" + block.name + ":" + content.block(overlay) + "[" + x + "," + y + "] " + "entity=" + (entity == null ? "null" : (entity.getClass())) + return floor.name + ":" + block.name + ":" + content.block(overlay) + "[" + x + "," + y + "] " + "entity=" + (entity == null ? "null" : (entity.getClass())) +
(link != 0 ? " link=[" + (Pack.leftByte(link) - 8) + ", " + (Pack.rightByte(link) - 8) + "]" : ""); (isLinked() ? " link=[" + linkX(rotation) + ", " + linkY(rotation) + "]" : "");
}
/**Returns the relative X from a link byte.*/
public static int linkX(byte value){
return -((byte)((value >> 4) & (byte)0x0F) - 8);
}
/**Returns the relative Y from a link byte.*/
public static int linkY(byte value){
return -((byte)(value & 0x0F) - 8);
} }
} }

View File

@@ -51,8 +51,7 @@ public class BuildBlock extends Block{
public static void onConstructFinish(Tile tile, Block block, int builderID, byte rotation, Team team){ public static void onConstructFinish(Tile tile, Block block, int builderID, byte rotation, Team team){
if(tile == null) return; if(tile == null) return;
float healthf = tile.entity == null ? 1f : tile.entity.healthf(); float healthf = tile.entity == null ? 1f : tile.entity.healthf();
tile.setRotation(rotation); world.setBlock(tile, block, team, rotation);
world.setBlock(tile, block, team);
if(tile.entity != null){ if(tile.entity != null){
tile.entity.health = block.health * healthf; tile.entity.health = block.health * healthf;
} }

View File

@@ -167,6 +167,10 @@ public class Conveyor extends Block{
public void unitOn(Tile tile, Unit unit){ public void unitOn(Tile tile, Unit unit){
ConveyorEntity entity = tile.entity(); ConveyorEntity entity = tile.entity();
if(entity.clogHeat > 0.5f){
return;
}
entity.noSleep(); entity.noSleep();
float speed = this.speed * tilesize / 2.4f; float speed = this.speed * tilesize / 2.4f;

View File

@@ -81,7 +81,7 @@ public class PowerTestFixture{
// Since this part shall not be part of the test and would require more work anyway, we manually set the block and floor // Since this part shall not be part of the test and would require more work anyway, we manually set the block and floor
// through reflections and then simulate part of what the changed() method does. // through reflections and then simulate part of what the changed() method does.
Field field = Tile.class.getDeclaredField("wall"); Field field = Tile.class.getDeclaredField("block");
field.setAccessible(true); field.setAccessible(true);
field.set(tile, block); field.set(tile, block);