Merge branch 'remove-tile-pack' of https://github.com/Anuken/Mindustry

This commit is contained in:
Anuken
2018-12-01 17:36:16 -05:00
37 changed files with 158 additions and 142 deletions

View File

@@ -51,8 +51,8 @@ public class BlockIndexer{
public BlockIndexer(){ public BlockIndexer(){
Events.on(TileChangeEvent.class, event -> { Events.on(TileChangeEvent.class, event -> {
if(typeMap.get(event.tile.packedPosition()) != null){ if(typeMap.get(event.tile.pos()) != null){
TileIndex index = typeMap.get(event.tile.packedPosition()); TileIndex index = typeMap.get(event.tile.pos());
for(BlockFlag flag : index.flags){ for(BlockFlag flag : index.flags){
getFlagged(index.team)[flag.ordinal()].remove(event.tile); getFlagged(index.team)[flag.ordinal()].remove(event.tile);
} }
@@ -230,7 +230,7 @@ public class BlockIndexer{
map[flag.ordinal()] = arr; map[flag.ordinal()] = arr;
} }
typeMap.put(tile.packedPosition(), new TileIndex(tile.block().flags, tile.getTeam())); typeMap.put(tile.pos(), new TileIndex(tile.block().flags, tile.getTeam()));
} }
if(ores == null) return; if(ores == null) return;

View File

@@ -23,6 +23,7 @@ import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.type.ItemStack; import io.anuke.mindustry.type.ItemStack;
import io.anuke.mindustry.type.Recipe; import io.anuke.mindustry.type.Recipe;
import io.anuke.mindustry.ui.dialogs.FloatingDialog; import io.anuke.mindustry.ui.dialogs.FloatingDialog;
import io.anuke.mindustry.world.Pos;
import io.anuke.ucore.core.*; import io.anuke.ucore.core.*;
import io.anuke.ucore.entities.EntityQuery; import io.anuke.ucore.entities.EntityQuery;
import io.anuke.ucore.modules.Module; import io.anuke.ucore.modules.Module;

View File

@@ -492,7 +492,7 @@ public class NetServer extends Module{
//write all core inventory data //write all core inventory data
for(Tile tile : cores){ for(Tile tile : cores){
dataStream.writeInt(tile.packedPosition()); dataStream.writeInt(tile.pos());
tile.entity.items.write(dataStream); tile.entity.items.write(dataStream);
} }

View File

@@ -152,7 +152,7 @@ public class Renderer extends RendererModule{
if(players[0].isDead()){ if(players[0].isDead()){
TileEntity core = players[0].getClosestCore(); TileEntity core = players[0].getClosestCore();
if(core != null && players[0].spawner == -1){ if(core != null && players[0].spawner == Unit.noSpawner){
smoothCamera(core.x, core.y, 0.08f); smoothCamera(core.x, core.y, 0.08f);
}else{ }else{
smoothCamera(position.x + 0.0001f, position.y + 0.0001f, 0.08f); smoothCamera(position.x + 0.0001f, position.y + 0.0001f, 0.08f);

View File

@@ -15,6 +15,7 @@ import io.anuke.mindustry.io.MapIO;
import io.anuke.mindustry.maps.*; import io.anuke.mindustry.maps.*;
import io.anuke.mindustry.maps.generation.WorldGenerator; import io.anuke.mindustry.maps.generation.WorldGenerator;
import io.anuke.mindustry.world.Block; import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Pos;
import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.OreBlock; import io.anuke.mindustry.world.blocks.OreBlock;
import io.anuke.ucore.core.Events; import io.anuke.ucore.core.Events;
@@ -103,12 +104,8 @@ public class World extends Module{
return tiles == null ? 0 : tiles[0].length; return tiles == null ? 0 : tiles[0].length;
} }
public int toPacked(int x, int y){ public Tile tile(int pos){
return x + y * width(); return tiles == null ? null : tile(Pos.x(pos), Pos.y(pos));
}
public Tile tile(int packed){
return tiles == null ? null : tile(packed % width(), packed / width());
} }
public Tile tile(int x, int y){ public Tile tile(int x, int y){

View File

@@ -58,7 +58,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
public boolean achievedFlight; public boolean achievedFlight;
public Color color = new Color(); public Color color = new Color();
public Mech mech; public Mech mech;
public int spawner = -1; public int spawner = noSpawner;
public NetConnection con; public NetConnection con;
public int playerIndex = 0; public int playerIndex = 0;
@@ -498,7 +498,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
updateRespawning(); updateRespawning();
return; return;
}else{ }else{
spawner = -1; spawner = noSpawner;
} }
avoidOthers(1f); avoidOthers(1f);
@@ -788,23 +788,23 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
public void updateRespawning(){ public void updateRespawning(){
if(spawner != -1 && world.tile(spawner) != null && world.tile(spawner).entity instanceof SpawnerTrait){ if(spawner != noSpawner && world.tile(spawner) != null && world.tile(spawner).entity instanceof SpawnerTrait){
((SpawnerTrait) world.tile(spawner).entity).updateSpawning(this); ((SpawnerTrait) world.tile(spawner).entity).updateSpawning(this);
}else{ }else{
CoreEntity entity = (CoreEntity) getClosestCore(); CoreEntity entity = (CoreEntity) getClosestCore();
if(entity != null && !netServer.isWaitingForPlayers()){ if(entity != null && !netServer.isWaitingForPlayers()){
this.spawner = entity.tile.id(); this.spawner = entity.tile.pos();
} }
} }
} }
public void beginRespawning(SpawnerTrait spawner){ public void beginRespawning(SpawnerTrait spawner){
this.spawner = spawner.getTile().packedPosition(); this.spawner = spawner.getTile().pos();
this.dead = true; this.dead = true;
} }
public void endRespawning(){ public void endRespawning(){
spawner = -1; spawner = noSpawner;
} }
//endregion //endregion
@@ -860,7 +860,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
buffer.writeByte(Bits.toByte(isAdmin) | (Bits.toByte(dead) << 1) | (Bits.toByte(isBoosting) << 2)); buffer.writeByte(Bits.toByte(isAdmin) | (Bits.toByte(dead) << 1) | (Bits.toByte(isBoosting) << 2));
buffer.writeInt(Color.rgba8888(color)); buffer.writeInt(Color.rgba8888(color));
buffer.writeByte(mech.id); buffer.writeByte(mech.id);
buffer.writeInt(mining == null ? -1 : mining.packedPosition()); buffer.writeInt(mining == null ? -1 : mining.pos());
buffer.writeInt(spawner); buffer.writeInt(spawner);
buffer.writeShort((short) (baseRotation * 2)); buffer.writeShort((short) (baseRotation * 2));

View File

@@ -12,6 +12,7 @@ import io.anuke.mindustry.net.Interpolator;
import io.anuke.mindustry.net.Net; import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.type.StatusEffect; import io.anuke.mindustry.type.StatusEffect;
import io.anuke.mindustry.type.Weapon; import io.anuke.mindustry.type.Weapon;
import io.anuke.mindustry.world.Pos;
import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.Floor; import io.anuke.mindustry.world.blocks.Floor;
import io.anuke.ucore.core.Effects; import io.anuke.ucore.core.Effects;
@@ -39,6 +40,7 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
public static final float velocityPercision = 8f; public static final float velocityPercision = 8f;
/**Maximum absolute value of a velocity vector component.*/ /**Maximum absolute value of a velocity vector component.*/
public static final float maxAbsVelocity = 127f / velocityPercision; public static final float maxAbsVelocity = 127f / velocityPercision;
public static final int noSpawner = Pos.get(-1, 1);
private static final Rectangle queryRect = new Rectangle(); private static final Rectangle queryRect = new Rectangle();
private static final Vector2 moveVector = new Vector2(); private static final Vector2 moveVector = new Vector2();

View File

@@ -48,7 +48,7 @@ public class Fire extends TimedEntity implements SaveTrait, SyncTrait, Poolable{
public static void create(Tile tile){ public static void create(Tile tile){
if(Net.client() || tile == null) return; //not clientside. if(Net.client() || tile == null) return; //not clientside.
Fire fire = map.get(tile.packedPosition()); Fire fire = map.get(tile.pos());
if(fire == null){ if(fire == null){
fire = Pooling.obtain(Fire.class, Fire::new); fire = Pooling.obtain(Fire.class, Fire::new);
@@ -56,7 +56,7 @@ public class Fire extends TimedEntity implements SaveTrait, SyncTrait, Poolable{
fire.lifetime = baseLifetime; fire.lifetime = baseLifetime;
fire.set(tile.worldx(), tile.worldy()); fire.set(tile.worldx(), tile.worldy());
fire.add(); fire.add();
map.put(tile.packedPosition(), fire); map.put(tile.pos(), fire);
}else{ }else{
fire.lifetime = baseLifetime; fire.lifetime = baseLifetime;
fire.time = 0f; fire.time = 0f;
@@ -75,8 +75,8 @@ public class Fire extends TimedEntity implements SaveTrait, SyncTrait, Poolable{
* Attempts to extinguish a fire by shortening its life. If there is no fire here, does nothing. * Attempts to extinguish a fire by shortening its life. If there is no fire here, does nothing.
*/ */
public static void extinguish(Tile tile, float intensity){ public static void extinguish(Tile tile, float intensity){
if(tile != null && map.containsKey(tile.packedPosition())){ if(tile != null && map.containsKey(tile.pos())){
map.get(tile.packedPosition()).time += intensity * Timers.delta(); map.get(tile.pos()).time += intensity * Timers.delta();
} }
} }
@@ -157,7 +157,7 @@ public class Fire extends TimedEntity implements SaveTrait, SyncTrait, Poolable{
@Override @Override
public void writeSave(DataOutput stream) throws IOException{ public void writeSave(DataOutput stream) throws IOException{
stream.writeInt(tile.packedPosition()); stream.writeInt(tile.pos());
stream.writeFloat(lifetime); stream.writeFloat(lifetime);
stream.writeFloat(time); stream.writeFloat(time);
} }
@@ -202,7 +202,7 @@ public class Fire extends TimedEntity implements SaveTrait, SyncTrait, Poolable{
@Override @Override
public void removed(){ public void removed(){
if(tile != null){ if(tile != null){
map.remove(tile.packedPosition()); map.remove(tile.pos());
} }
reset(); reset();
} }

View File

@@ -73,7 +73,7 @@ public class Puddle extends SolidEntity implements SaveTrait, Poolable, DrawTrai
/**Returns the puddle on the specified tile. May return null.*/ /**Returns the puddle on the specified tile. May return null.*/
public static Puddle getPuddle(Tile tile){ public static Puddle getPuddle(Tile tile){
return map.get(tile.packedPosition()); return map.get(tile.pos());
} }
private static void deposit(Tile tile, Tile source, Liquid liquid, float amount, int generation){ private static void deposit(Tile tile, Tile source, Liquid liquid, float amount, int generation){
@@ -83,7 +83,7 @@ public class Puddle extends SolidEntity implements SaveTrait, Poolable, DrawTrai
reactPuddle(tile.floor().liquidDrop, liquid, amount, tile, reactPuddle(tile.floor().liquidDrop, liquid, amount, tile,
(tile.worldx() + source.worldx()) / 2f, (tile.worldy() + source.worldy()) / 2f); (tile.worldx() + source.worldx()) / 2f, (tile.worldy() + source.worldy()) / 2f);
Puddle p = map.get(tile.packedPosition()); Puddle p = map.get(tile.pos());
if(generation == 0 && p != null && p.lastRipple <= Timers.time() - 40f){ if(generation == 0 && p != null && p.lastRipple <= Timers.time() - 40f){
Effects.effect(BlockFx.ripple, tile.floor().liquidDrop.color, Effects.effect(BlockFx.ripple, tile.floor().liquidDrop.color,
@@ -93,7 +93,7 @@ public class Puddle extends SolidEntity implements SaveTrait, Poolable, DrawTrai
return; return;
} }
Puddle p = map.get(tile.packedPosition()); Puddle p = map.get(tile.pos());
if(p == null){ if(p == null){
if(Net.client()) return; //not clientside. if(Net.client()) return; //not clientside.
@@ -104,7 +104,7 @@ public class Puddle extends SolidEntity implements SaveTrait, Poolable, DrawTrai
puddle.generation = (byte) generation; puddle.generation = (byte) generation;
puddle.set((tile.worldx() + source.worldx()) / 2f, (tile.worldy() + source.worldy()) / 2f); puddle.set((tile.worldx() + source.worldx()) / 2f, (tile.worldy() + source.worldy()) / 2f);
puddle.add(); puddle.add();
map.put(tile.packedPosition(), puddle); map.put(tile.pos(), puddle);
}else if(p.liquid == liquid){ }else if(p.liquid == liquid){
p.accepting = Math.max(amount, p.accepting); p.accepting = Math.max(amount, p.accepting);
@@ -249,7 +249,7 @@ public class Puddle extends SolidEntity implements SaveTrait, Poolable, DrawTrai
@Override @Override
public void writeSave(DataOutput stream) throws IOException{ public void writeSave(DataOutput stream) throws IOException{
stream.writeInt(tile.packedPosition()); stream.writeInt(tile.pos());
stream.writeFloat(x); stream.writeFloat(x);
stream.writeFloat(y); stream.writeFloat(y);
stream.writeByte(liquid.id); stream.writeByte(liquid.id);
@@ -288,7 +288,7 @@ public class Puddle extends SolidEntity implements SaveTrait, Poolable, DrawTrai
@Override @Override
public void removed(){ public void removed(){
map.remove(tile.packedPosition()); map.remove(tile.pos());
reset(); reset();
} }
@@ -298,7 +298,7 @@ public class Puddle extends SolidEntity implements SaveTrait, Poolable, DrawTrai
data.writeFloat(y); data.writeFloat(y);
data.writeByte(liquid.id); data.writeByte(liquid.id);
data.writeShort((short) (amount * 4)); data.writeShort((short) (amount * 4));
data.writeInt(tile.packedPosition()); data.writeInt(tile.pos());
} }
@Override @Override
@@ -309,7 +309,7 @@ public class Puddle extends SolidEntity implements SaveTrait, Poolable, DrawTrai
targetAmount = data.readShort() / 4f; targetAmount = data.readShort() / 4f;
tile = world.tile(data.readInt()); tile = world.tile(data.readInt());
map.put(tile.packedPosition(), this); map.put(tile.pos(), this);
} }
@Override @Override

View File

@@ -16,6 +16,7 @@ import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.type.Item; import io.anuke.mindustry.type.Item;
import io.anuke.mindustry.type.Recipe; import io.anuke.mindustry.type.Recipe;
import io.anuke.mindustry.world.Build; import io.anuke.mindustry.world.Build;
import io.anuke.mindustry.world.Pos;
import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.BuildBlock; import io.anuke.mindustry.world.blocks.BuildBlock;
import io.anuke.mindustry.world.blocks.BuildBlock.BuildEntity; import io.anuke.mindustry.world.blocks.BuildBlock.BuildEntity;
@@ -27,7 +28,10 @@ import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.graphics.Fill; import io.anuke.ucore.graphics.Fill;
import io.anuke.ucore.graphics.Lines; import io.anuke.ucore.graphics.Lines;
import io.anuke.ucore.graphics.Shapes; import io.anuke.ucore.graphics.Shapes;
import io.anuke.ucore.util.*; import io.anuke.ucore.util.Angles;
import io.anuke.ucore.util.Geometry;
import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Translator;
import java.io.DataInput; import java.io.DataInput;
import java.io.DataOutput; import java.io.DataOutput;
@@ -72,7 +76,7 @@ public interface BuilderTrait extends Entity{
if(request != null){ if(request != null){
output.writeByte(request.breaking ? 1 : 0); output.writeByte(request.breaking ? 1 : 0);
output.writeInt(world.toPacked(request.x, request.y)); output.writeInt(Pos.get(request.x, request.y));
output.writeFloat(request.progress); output.writeFloat(request.progress);
if(!request.breaking){ if(!request.breaking){
output.writeByte(request.recipe.id); output.writeByte(request.recipe.id);
@@ -96,13 +100,13 @@ public interface BuilderTrait extends Entity{
float progress = input.readFloat(); float progress = input.readFloat();
BuildRequest request; BuildRequest request;
if(type == 1){ //remove if(type == 1){ //remove
request = new BuildRequest(position % world.width(), position / world.width()); request = new BuildRequest(Pos.x(position), Pos.y(position));
}else{ //place }else{ //place
byte recipe = input.readByte(); byte recipe = input.readByte();
byte rotation = input.readByte(); byte rotation = input.readByte();
request = new BuildRequest(position % world.width(), position / world.width(), rotation, content.recipe(recipe)); request = new BuildRequest(Pos.x(position), Pos.y(position), rotation, content.recipe(recipe));
} }
request.progress = progress; request.progress = progress;

View File

@@ -52,7 +52,7 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
protected boolean isWave; protected boolean isWave;
protected Squad squad; protected Squad squad;
protected int spawner = -1; protected int spawner = noSpawner;
/**internal constructor used for deserialization, DO NOT USE*/ /**internal constructor used for deserialization, DO NOT USE*/
public BaseUnit(){ public BaseUnit(){
@@ -111,16 +111,8 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
return type; return type;
} }
public Tile getSpawner(){
return world.tile(spawner);
}
public void setSpawner(Tile tile){ public void setSpawner(Tile tile){
this.spawner = tile.packedPosition(); this.spawner = tile.pos();
}
public void setIntSpawner(int pos){
this.spawner = pos;
} }
/**Sets this to a 'wave' unit, which means it has slightly different AI and will not run out of ammo.*/ /**Sets this to a 'wave' unit, which means it has slightly different AI and will not run out of ammo.*/
@@ -143,7 +135,7 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
} }
public void updateRespawning(){ public void updateRespawning(){
if(spawner == -1) return; if(spawner == noSpawner) return;
Tile tile = world.tile(spawner); Tile tile = world.tile(spawner);
if(tile != null && tile.entity != null){ if(tile != null && tile.entity != null){
@@ -151,7 +143,7 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
((SpawnerTrait) tile.entity).updateSpawning(this); ((SpawnerTrait) tile.entity).updateSpawning(this);
} }
}else{ }else{
spawner = -1; spawner = noSpawner;
} }
} }
@@ -305,7 +297,7 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
avoidOthers(1.25f); avoidOthers(1.25f);
if(spawner != -1 && (world.tile(spawner) == null || world.tile(spawner).entity == null)){ if(spawner != noSpawner && (world.tile(spawner) == null || world.tile(spawner).entity == null)){
damage(health); damage(health);
} }
@@ -336,7 +328,7 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
@Override @Override
public void removed(){ public void removed(){
spawner = -1; spawner = noSpawner;
} }
@Override @Override

View File

@@ -358,8 +358,8 @@ public class Drone extends FlyingUnit implements BuilderTrait{
@Override @Override
public void write(DataOutput data) throws IOException{ public void write(DataOutput data) throws IOException{
super.write(data); super.write(data);
data.writeInt(mineTile == null || !state.is(mine) ? -1 : mineTile.packedPosition()); data.writeInt(mineTile == null || !state.is(mine) ? -1 : mineTile.pos());
data.writeInt(state.is(repair) && target instanceof TileEntity ? ((TileEntity)target).tile.packedPosition() : -1); data.writeInt(state.is(repair) && target instanceof TileEntity ? ((TileEntity)target).tile.pos() : -1);
writeBuilding(data); writeBuilding(data);
} }

View File

@@ -77,9 +77,11 @@ public class FogRenderer implements Disposable{
pixelBuffer.position(0); pixelBuffer.position(0);
for(int i = 0; i < world.width() * world.height(); i++){ for(int i = 0; i < world.width() * world.height(); i++){
int x = i % world.width();
int y = i / world.width();
byte r = pixelBuffer.get(); byte r = pixelBuffer.get();
if(r != 0){ if(r != 0){
world.tile(i).setVisibility((byte)1); world.tile(x, y).setVisibility((byte)1);
} }
pixelBuffer.position(pixelBuffer.position() + 3); pixelBuffer.position(pixelBuffer.position() + 3);
} }
@@ -128,10 +130,12 @@ public class FogRenderer implements Disposable{
changeQueue.clear(); changeQueue.clear();
if(dirty){ if(dirty){
for(int i = 0; i < world.width() * world.height(); i++){ for(int x = 0; x < world.width(); x++){
Tile tile = world.tile(i); for(int y = 0; y < world.height(); y++){
if(tile.discovered()){ Tile tile = world.tile(x, y);
Fill.rect(tile.worldx(), tile.worldy(), tilesize, tilesize); if(tile.discovered()){
Fill.rect(tile.worldx(), tile.worldy(), tilesize, tilesize);
}
} }
} }
dirty = false; dirty = false;

View File

@@ -50,7 +50,7 @@ public abstract class SaveFileVersion{
stream.writeShort(world.height()); stream.writeShort(world.height());
for(int i = 0; i < world.width() * world.height(); i++){ for(int i = 0; i < world.width() * world.height(); i++){
Tile tile = world.tile(i); Tile tile = world.tile(i % world.width(), i / world.width());
stream.writeByte(tile.getFloorID()); stream.writeByte(tile.getFloorID());
stream.writeByte(tile.getBlockID()); stream.writeByte(tile.getBlockID());
@@ -73,7 +73,7 @@ public abstract class SaveFileVersion{
int consecutives = 0; int consecutives = 0;
for(int j = i + 1; j < world.width() * world.height() && consecutives < 255; j++){ for(int j = i + 1; j < world.width() * world.height() && consecutives < 255; j++){
Tile nextTile = world.tile(j); Tile nextTile = world.tile(j % world.width(), j / world.width());
if(nextTile.getFloorID() != tile.getFloorID() || nextTile.block() != Blocks.air || nextTile.getElevation() != tile.getElevation()){ if(nextTile.getFloorID() != tile.getFloorID() || nextTile.block() != Blocks.air || nextTile.getElevation() != tile.getElevation()){
break; break;
@@ -89,13 +89,13 @@ public abstract class SaveFileVersion{
//write visibility, length-run encoded //write visibility, length-run encoded
for(int i = 0; i < world.width() * world.height(); i++){ for(int i = 0; i < world.width() * world.height(); i++){
Tile tile = world.tile(i); Tile tile = world.tile(i % world.width(), i / world.width());
boolean discovered = tile.discovered(); boolean discovered = tile.discovered();
int consecutives = 0; int consecutives = 0;
for(int j = i + 1; j < world.width() * world.height() && consecutives < 32767*2-1; j++){ for(int j = i + 1; j < world.width() * world.height() && consecutives < 32767*2-1; j++){
Tile nextTile = world.tile(j); Tile nextTile = world.tile(j % world.width(), j / world.width());
if(nextTile.discovered() != discovered){ if(nextTile.discovered() != discovered){
break; break;

View File

@@ -14,7 +14,7 @@ import java.util.zip.InflaterInputStream;
import static io.anuke.mindustry.Vars.*; import static io.anuke.mindustry.Vars.*;
public class SaveIO{ public class SaveIO{
public static final IntArray breakingVersions = IntArray.with(47, 48, 49, 50, 51, 52, 53, 54, 55, 56); public static final IntArray breakingVersions = IntArray.with(47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58);
public static final IntMap<SaveFileVersion> versions = new IntMap<>(); public static final IntMap<SaveFileVersion> versions = new IntMap<>();
public static final Array<SaveFileVersion> versionArray = Array.with( public static final Array<SaveFileVersion> versionArray = Array.with(
new Save16() new Save16()

View File

@@ -18,6 +18,7 @@ import io.anuke.mindustry.net.Packets.AdminAction;
import io.anuke.mindustry.net.Packets.KickReason; import io.anuke.mindustry.net.Packets.KickReason;
import io.anuke.mindustry.type.*; import io.anuke.mindustry.type.*;
import io.anuke.mindustry.world.Block; import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Pos;
import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.core.Effects; import io.anuke.ucore.core.Effects;
import io.anuke.ucore.core.Effects.Effect; import io.anuke.ucore.core.Effects.Effect;
@@ -142,13 +143,12 @@ public class TypeIO{
@WriteClass(Tile.class) @WriteClass(Tile.class)
public static void writeTile(ByteBuffer buffer, Tile tile){ public static void writeTile(ByteBuffer buffer, Tile tile){
buffer.putInt(tile == null ? -1 : tile.packedPosition()); buffer.putInt(tile == null ? Pos.get(-1, -1) : tile.pos());
} }
@ReadClass(Tile.class) @ReadClass(Tile.class)
public static Tile readTile(ByteBuffer buffer){ public static Tile readTile(ByteBuffer buffer){
int position = buffer.getInt(); return world.tile(buffer.getInt());
return position == -1 ? null : world.tile(position);
} }
@WriteClass(Block.class) @WriteClass(Block.class)
@@ -166,7 +166,7 @@ public class TypeIO{
buffer.putShort((short)requests.length); buffer.putShort((short)requests.length);
for(BuildRequest request : requests){ for(BuildRequest request : requests){
buffer.put(request.breaking ? (byte) 1 : 0); buffer.put(request.breaking ? (byte) 1 : 0);
buffer.putInt(world.toPacked(request.x, request.y)); buffer.putInt(Pos.get(request.x, request.y));
if(!request.breaking){ if(!request.breaking){
buffer.put(request.recipe.id); buffer.put(request.recipe.id);
buffer.put((byte) request.rotation); buffer.put((byte) request.rotation);
@@ -184,11 +184,11 @@ public class TypeIO{
BuildRequest currentRequest; BuildRequest currentRequest;
if(type == 1){ //remove if(type == 1){ //remove
currentRequest = new BuildRequest(position % world.width(), position / world.width()); currentRequest = new BuildRequest(Pos.x(position), Pos.y(position));
}else{ //place }else{ //place
byte recipe = buffer.get(); byte recipe = buffer.get();
byte rotation = buffer.get(); byte rotation = buffer.get();
currentRequest = new BuildRequest(position % world.width(), position / world.width(), rotation, content.recipe(recipe)); currentRequest = new BuildRequest(Pos.x(position), Pos.y(position), rotation, content.recipe(recipe));
} }
reqs[i] = (currentRequest); reqs[i] = (currentRequest);

View File

@@ -59,7 +59,7 @@ public class Save16 extends SaveFileVersion{
stream.writeLong(TimeUtils.millis()); //last saved stream.writeLong(TimeUtils.millis()); //last saved
stream.writeLong(headless ? 0 : control.saves.getTotalPlaytime()); //playtime stream.writeLong(headless ? 0 : control.saves.getTotalPlaytime()); //playtime
stream.writeInt(Version.build); //build stream.writeInt(Version.build); //build
stream.writeInt(world.getSector() == null ? invalidSector : world.getSector().packedPosition()); //sector ID stream.writeInt(world.getSector() == null ? invalidSector : world.getSector().pos()); //sector ID
//--GENERAL STATE-- //--GENERAL STATE--
stream.writeByte(state.mode.ordinal()); //gamemode stream.writeByte(state.mode.ordinal()); //gamemode

View File

@@ -67,7 +67,7 @@ public class Sector{
return !headless && control.saves.getByID(saveID) != null; return !headless && control.saves.getByID(saveID) != null;
} }
public int packedPosition(){ public int pos(){
return Bits.packInt(x, y); return Bits.packInt(x, y);
} }
} }

View File

@@ -53,7 +53,7 @@ public class Sectors{
world.loadSector(sector); world.loadSector(sector);
logic.play(); logic.play();
if(!headless){ if(!headless){
sector.saveID = control.saves.addSave("sector-" + sector.packedPosition()).index; sector.saveID = control.saves.addSave("sector-" + sector.pos()).index;
} }
world.sectors.save(); world.sectors.save();
world.setSector(sector); world.setSector(sector);

View File

@@ -17,6 +17,7 @@ import io.anuke.mindustry.maps.Sector;
import io.anuke.mindustry.maps.missions.Mission; import io.anuke.mindustry.maps.missions.Mission;
import io.anuke.mindustry.type.Item; import io.anuke.mindustry.type.Item;
import io.anuke.mindustry.world.Block; import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Pos;
import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.Floor; import io.anuke.mindustry.world.blocks.Floor;
import io.anuke.mindustry.world.blocks.OreBlock; import io.anuke.mindustry.world.blocks.OreBlock;
@@ -86,7 +87,7 @@ public class WorldGenerator{
Tile tile = tiles[x][y]; Tile tile = tiles[x][y];
if(tile.block().isMultiblock()){ if(tile.block().isMultiblock()){
multiblocks.add(tile.packedPosition()); multiblocks.add(tile.pos());
} }
} }
} }
@@ -95,8 +96,8 @@ public class WorldGenerator{
for(int i = 0; i < multiblocks.size; i++){ for(int i = 0; i < multiblocks.size; i++){
int pos = multiblocks.get(i); int pos = multiblocks.get(i);
int x = pos % tiles.length; int x = Pos.x(pos);
int y = pos / tiles.length; int y = Pos.y(pos);
Block result = tiles[x][y].block(); Block result = tiles[x][y].block();
Team team = tiles[x][y].getTeam(); Team team = tiles[x][y].getTeam();

View File

@@ -32,7 +32,7 @@ public class NetworkIO{
//--GENERAL STATE-- //--GENERAL STATE--
stream.writeByte(state.mode.ordinal()); //gamemode stream.writeByte(state.mode.ordinal()); //gamemode
stream.writeUTF(world.getMap().name); //map name stream.writeUTF(world.getMap().name); //map name
stream.writeInt(world.getSector() == null ? invalidSector : world.getSector().packedPosition()); //sector ID stream.writeInt(world.getSector() == null ? invalidSector : world.getSector().pos()); //sector ID
stream.writeInt(world.getSector() == null ? 0 : world.getSector().completedMissions); stream.writeInt(world.getSector() == null ? 0 : world.getSector().completedMissions);
//write tags //write tags
@@ -56,7 +56,7 @@ public class NetworkIO{
stream.writeShort(world.height()); stream.writeShort(world.height());
for(int i = 0; i < world.width() * world.height(); i++){ for(int i = 0; i < world.width() * world.height(); i++){
Tile tile = world.tile(i); Tile tile = world.tile(i % world.width(), i / world.width());
stream.writeByte(tile.getFloorID()); stream.writeByte(tile.getFloorID());
stream.writeByte(tile.getBlockID()); stream.writeByte(tile.getBlockID());
@@ -79,7 +79,7 @@ public class NetworkIO{
int consecutives = 0; int consecutives = 0;
for(int j = i + 1; j < world.width() * world.height() && consecutives < 255; j++){ for(int j = i + 1; j < world.width() * world.height() && consecutives < 255; j++){
Tile nextTile = world.tile(j); Tile nextTile = world.tile(j % world.width(), j / world.width());
if(nextTile.getFloorID() != tile.getFloorID() || nextTile.block() != Blocks.air || nextTile.getElevation() != tile.getElevation()){ if(nextTile.getFloorID() != tile.getFloorID() || nextTile.block() != Blocks.air || nextTile.getElevation() != tile.getElevation()){
break; break;
@@ -95,13 +95,13 @@ public class NetworkIO{
//write visibility, length-run encoded //write visibility, length-run encoded
for(int i = 0; i < world.width() * world.height(); i++){ for(int i = 0; i < world.width() * world.height(); i++){
Tile tile = world.tile(i); Tile tile = world.tile(i % world.width(), i / world.width());;
boolean discovered = tile.discovered(); boolean discovered = tile.discovered();
int consecutives = 0; int consecutives = 0;
for(int j = i + 1; j < world.width() * world.height() && consecutives < 32767*2-1; j++){ for(int j = i + 1; j < world.width() * world.height() && consecutives < 32767*2-1; j++){
Tile nextTile = world.tile(j); Tile nextTile = world.tile(j % world.width(), j / world.width());;
if(nextTile.discovered() != discovered){ if(nextTile.discovered() != discovered){
break; break;
@@ -129,7 +129,7 @@ public class NetworkIO{
stream.writeByte(data.cores.size); stream.writeByte(data.cores.size);
for(Tile tile : data.cores){ for(Tile tile : data.cores){
stream.writeInt(tile.packedPosition()); stream.writeInt(tile.pos());
} }
} }

View File

@@ -164,7 +164,7 @@ public class Block extends BaseBlock {
for(int i = 0; i < tile.entity.power.links.size; i++){ for(int i = 0; i < tile.entity.power.links.size; i++){
Tile other = world.tile(tile.entity.power.links.get(i)); Tile other = world.tile(tile.entity.power.links.get(i));
if(other != null && other.entity != null && other.entity.power != null){ if(other != null && other.entity != null && other.entity.power != null){
other.entity.power.links.removeValue(tile.packedPosition()); other.entity.power.links.removeValue(tile.pos());
} }
} }
} }
@@ -173,7 +173,7 @@ public class Block extends BaseBlock {
out.clear(); out.clear();
for(Tile other : tile.entity.proximity()){ for(Tile other : tile.entity.proximity()){
if(other.entity.power != null && !(consumesPower && other.block().consumesPower && !outputsPower && !other.block().outputsPower) if(other.entity.power != null && !(consumesPower && other.block().consumesPower && !outputsPower && !other.block().outputsPower)
&& !tile.entity.power.links.contains(other.packedPosition())){ && !tile.entity.power.links.contains(other.pos())){
out.add(other); out.add(other);
} }
} }

View File

@@ -0,0 +1,20 @@
package io.anuke.mindustry.world;
/**Methods for a packed position 'struct', contained in an int.*/
public class Pos{
/**Returns packed position from an x/y position. The values must be within short limits.*/
public static int get(int x, int y){
return (((short)x) << 16) | (((short)y) & 0xFFFF);
}
/**Returns the x component of a position.*/
public static short x(int pos){
return (short) (pos >>> 16);
}
/**Returns the y component of a position.*/
public static short y(int pos){
return (short) (pos & 0xFFFF);
}
}

View File

@@ -71,8 +71,9 @@ public class Tile implements PosTrait, TargetTrait{
return visibility > 0; return visibility > 0;
} }
public int packedPosition(){ /**Returns this tile's position as a {@link Pos}.*/
return x + y * world.width(); public int pos(){
return Pos.get(x, y);
} }
public byte getBlockID(){ public byte getBlockID(){
@@ -104,10 +105,6 @@ public class Tile implements PosTrait, TargetTrait{
return (T) entity; return (T) entity;
} }
public int id(){
return x + y * world.width();
}
public float worldx(){ public float worldx(){
return x * tilesize; return x * tilesize;
} }

View File

@@ -130,16 +130,16 @@ public class Floor extends Block{
@Override @Override
public void drawNonLayer(Tile tile){ public void drawNonLayer(Tile tile){
MathUtils.random.setSeed(tile.id()); MathUtils.random.setSeed(tile.pos());
drawEdges(tile, true); drawEdges(tile, true);
} }
@Override @Override
public void draw(Tile tile){ public void draw(Tile tile){
MathUtils.random.setSeed(tile.id()); MathUtils.random.setSeed(tile.pos());
Draw.rect(variantRegions[Mathf.randomSeed(tile.id(), 0, Math.max(0, variantRegions.length - 1))], tile.worldx(), tile.worldy()); Draw.rect(variantRegions[Mathf.randomSeed(tile.pos(), 0, Math.max(0, variantRegions.length - 1))], tile.worldx(), tile.worldy());
if(tile.hasCliffs() && cliffRegions != null){ if(tile.hasCliffs() && cliffRegions != null){
for(int i = 0; i < 4; i++){ for(int i = 0; i < 4; i++){

View File

@@ -39,14 +39,14 @@ public class OreBlock extends Floor{
@Override @Override
public void draw(Tile tile){ public void draw(Tile tile){
Draw.rect(variantRegions[Mathf.randomSeed(tile.id(), 0, Math.max(0, variantRegions.length - 1))], tile.worldx(), tile.worldy()); Draw.rect(variantRegions[Mathf.randomSeed(tile.pos(), 0, Math.max(0, variantRegions.length - 1))], tile.worldx(), tile.worldy());
drawEdges(tile, false); drawEdges(tile, false);
} }
@Override @Override
public void drawNonLayer(Tile tile){ public void drawNonLayer(Tile tile){
MathUtils.random.setSeed(tile.id()); MathUtils.random.setSeed(tile.pos());
base.drawEdges(tile, true); base.drawEdges(tile, true);
} }

View File

@@ -19,7 +19,7 @@ public class Rock extends Block{
@Override @Override
public void draw(Tile tile){ public void draw(Tile tile){
if(variants > 0){ if(variants > 0){
Draw.rect(regions[Mathf.randomSeed(tile.id(), 0, Math.max(0, regions.length - 1))], tile.worldx(), tile.worldy()); Draw.rect(regions[Mathf.randomSeed(tile.pos(), 0, Math.max(0, regions.length - 1))], tile.worldx(), tile.worldy());
}else{ }else{
Draw.rect(region, tile.worldx(), tile.worldy()); Draw.rect(region, tile.worldx(), tile.worldy());
} }
@@ -28,7 +28,7 @@ public class Rock extends Block{
@Override @Override
public void drawShadow(Tile tile){ public void drawShadow(Tile tile){
if(shadowRegions != null){ if(shadowRegions != null){
Draw.rect(shadowRegions[(Mathf.randomSeed(tile.id(), 0, variants - 1))], tile.worldx(), tile.worldy()); Draw.rect(shadowRegions[(Mathf.randomSeed(tile.pos(), 0, variants - 1))], tile.worldx(), tile.worldy());
}else if(shadowRegion != null){ }else if(shadowRegion != null){
Draw.rect(shadowRegion, tile.drawx(), tile.drawy()); Draw.rect(shadowRegion, tile.drawx(), tile.drawy());
} }

View File

@@ -83,10 +83,10 @@ public class MendProjector extends Block{
if(other == null) continue; if(other == null) continue;
other = other.target(); other = other.target();
if(other.getTeamID() == tile.getTeamID() && !healed.contains(other.packedPosition()) && other.entity != null && other.entity.health < other.entity.maxHealth()){ if(other.getTeamID() == tile.getTeamID() && !healed.contains(other.pos()) && other.entity != null && other.entity.health < other.entity.maxHealth()){
other.entity.healBy(other.entity.maxHealth() * (healPercent + entity.phaseHeat*phaseBoost)/100f); other.entity.healBy(other.entity.maxHealth() * (healPercent + entity.phaseHeat*phaseBoost)/100f);
Effects.effect(BlockFx.healBlockFull, Hue.mix(color, phase, entity.phaseHeat), other.drawx(), other.drawy(), other.block().size); Effects.effect(BlockFx.healBlockFull, Hue.mix(color, phase, entity.phaseHeat), other.drawx(), other.drawy(), other.block().size);
healed.add(other.packedPosition()); healed.add(other.pos());
} }
} }
} }

View File

@@ -85,11 +85,11 @@ public class OverdriveProjector extends Block{
if(other == null) continue; if(other == null) continue;
other = other.target(); other = other.target();
if(other.getTeamID() == tile.getTeamID() && !healed.contains(other.packedPosition()) && other.entity != null){ if(other.getTeamID() == tile.getTeamID() && !healed.contains(other.pos()) && other.entity != null){
other.entity.timeScaleDuration = Math.max(other.entity.timeScaleDuration, reload + 1f); other.entity.timeScaleDuration = Math.max(other.entity.timeScaleDuration, reload + 1f);
other.entity.timeScale = Math.max(other.entity.timeScale, realBoost); other.entity.timeScale = Math.max(other.entity.timeScale, realBoost);
Effects.effect(BlockFx.overdriveBlockFull, Hue.mix(color, phase, entity.phaseHeat), other.drawx(), other.drawy(), other.block().size); Effects.effect(BlockFx.overdriveBlockFull, Hue.mix(color, phase, entity.phaseHeat), other.drawx(), other.drawy(), other.block().size);
healed.add(other.packedPosition()); healed.add(other.pos());
} }
} }
} }

View File

@@ -15,6 +15,7 @@ import io.anuke.mindustry.graphics.Palette;
import io.anuke.mindustry.type.Item; import io.anuke.mindustry.type.Item;
import io.anuke.mindustry.world.Block; import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Edges; import io.anuke.mindustry.world.Edges;
import io.anuke.mindustry.world.Pos;
import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.meta.BlockGroup; import io.anuke.mindustry.world.meta.BlockGroup;
import io.anuke.ucore.core.Timers; import io.anuke.ucore.core.Timers;
@@ -58,8 +59,8 @@ public class ItemBridge extends Block{
public static void linkItemBridge(Player player, Tile tile, Tile other){ public static void linkItemBridge(Player player, Tile tile, Tile other){
ItemBridgeEntity entity = tile.entity(); ItemBridgeEntity entity = tile.entity();
ItemBridgeEntity oe = other.entity(); ItemBridgeEntity oe = other.entity();
entity.link = other.packedPosition(); entity.link = other.pos();
oe.incoming.add(tile.packedPosition()); oe.incoming.add(tile.pos());
} }
@Remote(targets = Loc.both, called = Loc.server, forward = true) @Remote(targets = Loc.both, called = Loc.server, forward = true)
@@ -68,7 +69,7 @@ public class ItemBridge extends Block{
entity.link = -1; entity.link = -1;
if(other != null){ if(other != null){
ItemBridgeEntity oe = other.entity(); ItemBridgeEntity oe = other.entity();
oe.incoming.remove(tile.packedPosition()); oe.incoming.remove(tile.pos());
} }
} }
@@ -90,7 +91,7 @@ public class ItemBridge extends Block{
Call.linkItemBridge(null, last, tile); Call.linkItemBridge(null, last, tile);
} }
} }
lastPlaced = tile.packedPosition(); lastPlaced = tile.pos();
} }
@Override @Override
@@ -122,7 +123,7 @@ public class ItemBridge extends Block{
for(int j = 0; j < 4; j++){ for(int j = 0; j < 4; j++){
Tile other = tile.getNearby(Geometry.d4[j].x * i, Geometry.d4[j].y * i); Tile other = tile.getNearby(Geometry.d4[j].x * i, Geometry.d4[j].y * i);
if(linkValid(tile, other)){ if(linkValid(tile, other)){
boolean linked = other.packedPosition() == entity.link; boolean linked = other.pos() == entity.link;
Draw.color(linked ? Palette.place : Palette.breakInvalid); Draw.color(linked ? Palette.place : Palette.breakInvalid);
Lines.square(other.drawx(), other.drawy(), Lines.square(other.drawx(), other.drawy(),
@@ -139,7 +140,7 @@ public class ItemBridge extends Block{
ItemBridgeEntity entity = tile.entity(); ItemBridgeEntity entity = tile.entity();
if(linkValid(tile, other)){ if(linkValid(tile, other)){
if(entity.link == other.packedPosition()){ if(entity.link == other.pos()){
Call.unlinkItemBridge(null, tile, other); Call.unlinkItemBridge(null, tile, other);
}else{ }else{
Call.linkItemBridge(null, tile, other); Call.linkItemBridge(null, tile, other);
@@ -254,7 +255,7 @@ public class ItemBridge extends Block{
if(rel == rel2) return false; if(rel == rel2) return false;
}else{ }else{
return source.block() instanceof ItemBridge && source.<ItemBridgeEntity>entity().link == tile.packedPosition() && tile.entity.items.total() < itemCapacity; return source.block() instanceof ItemBridge && source.<ItemBridgeEntity>entity().link == tile.pos() && tile.entity.items.total() < itemCapacity;
} }
return tile.entity.items.total() < itemCapacity; return tile.entity.items.total() < itemCapacity;
@@ -273,9 +274,7 @@ public class ItemBridge extends Block{
while(it.hasNext){ while(it.hasNext){
int v = it.next(); int v = it.next();
int x = v % world.width(); if(tile.absoluteRelativeTo(Pos.x(v), Pos.y(v)) == i){
int y = v / world.width();
if(tile.absoluteRelativeTo(x, y) == i){
return false; return false;
} }
} }
@@ -315,7 +314,7 @@ public class ItemBridge extends Block{
return false; return false;
} }
return other.block() == this && (!checkDouble || other.<ItemBridgeEntity>entity().link != tile.packedPosition()); return other.block() == this && (!checkDouble || other.<ItemBridgeEntity>entity().link != tile.pos());
} }
public static class ItemBridgeEntity extends TileEntity{ public static class ItemBridgeEntity extends TileEntity{

View File

@@ -3,6 +3,7 @@ package io.anuke.mindustry.world.blocks.distribution;
import com.badlogic.gdx.utils.IntSet.IntSetIterator; import com.badlogic.gdx.utils.IntSet.IntSetIterator;
import io.anuke.mindustry.type.Item; import io.anuke.mindustry.type.Item;
import io.anuke.mindustry.type.Liquid; import io.anuke.mindustry.type.Liquid;
import io.anuke.mindustry.world.Pos;
import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.meta.BlockGroup; import io.anuke.mindustry.world.meta.BlockGroup;
import io.anuke.ucore.core.Timers; import io.anuke.ucore.core.Timers;
@@ -65,9 +66,7 @@ public class LiquidExtendingBridge extends ExtendingItemBridge{
while(it.hasNext){ while(it.hasNext){
int v = it.next(); int v = it.next();
int x = v % world.width(); if(tile.absoluteRelativeTo(Pos.x(v), Pos.y(v)) == i){
int y = v / world.width();
if(tile.absoluteRelativeTo(x, y) == i){
return false; return false;
} }
} }

View File

@@ -225,11 +225,11 @@ public class MassDriver extends Block{
MassDriverEntity entity = tile.entity(); MassDriverEntity entity = tile.entity();
if(entity.link == other.packedPosition()){ if(entity.link == other.pos()){
Call.linkMassDriver(null, tile, -1); Call.linkMassDriver(null, tile, -1);
return false; return false;
}else if(other.block() instanceof MassDriver && other.distanceTo(tile) <= range){ }else if(other.block() instanceof MassDriver && other.distanceTo(tile) <= range){
Call.linkMassDriver(null, tile, other.packedPosition()); Call.linkMassDriver(null, tile, other.pos());
return false; return false;
} }

View File

@@ -134,9 +134,9 @@ public class PowerGraph{
child.entity.power.graph = this; child.entity.power.graph = this;
add(child); add(child);
for(Tile next : child.block().getPowerConnections(child, outArray2)){ for(Tile next : child.block().getPowerConnections(child, outArray2)){
if(next.entity.power != null && next.entity.power.graph == null && !closedSet.contains(next.packedPosition())){ if(next.entity.power != null && next.entity.power.graph == null && !closedSet.contains(next.pos())){
queue.addLast(next); queue.addLast(next);
closedSet.add(next.packedPosition()); closedSet.add(next.pos());
} }
} }
} }
@@ -156,9 +156,9 @@ public class PowerGraph{
child.entity.power.graph = graph; child.entity.power.graph = graph;
graph.add(child); graph.add(child);
for(Tile next : child.block().getPowerConnections(child, outArray2)){ for(Tile next : child.block().getPowerConnections(child, outArray2)){
if(next != tile && next.entity.power != null && next.entity.power.graph == null && !closedSet.contains(next.packedPosition())){ if(next != tile && next.entity.power != null && next.entity.power.graph == null && !closedSet.contains(next.pos())){
queue.addLast(next); queue.addLast(next);
closedSet.add(next.packedPosition()); closedSet.add(next.pos());
} }
} }
} }

View File

@@ -51,14 +51,14 @@ public class PowerNode extends PowerBlock{
TileEntity entity = tile.entity(); TileEntity entity = tile.entity();
if(!entity.power.links.contains(other.packedPosition())){ if(!entity.power.links.contains(other.pos())){
entity.power.links.add(other.packedPosition()); entity.power.links.add(other.pos());
} }
if(other.getTeamID() == tile.getTeamID()){ if(other.getTeamID() == tile.getTeamID()){
if(!other.entity.power.links.contains(tile.packedPosition())){ if(!other.entity.power.links.contains(tile.pos())){
other.entity.power.links.add(tile.packedPosition()); other.entity.power.links.add(tile.pos());
} }
} }
@@ -75,8 +75,8 @@ public class PowerNode extends PowerBlock{
PowerGraph tg = entity.power.graph; PowerGraph tg = entity.power.graph;
tg.clear(); tg.clear();
entity.power.links.removeValue(other.packedPosition()); entity.power.links.removeValue(other.pos());
other.entity.power.links.removeValue(tile.packedPosition()); other.entity.power.links.removeValue(tile.pos());
//reflow from this point, covering all tiles on this side //reflow from this point, covering all tiles on this side
tg.reflow(tile); tg.reflow(tile);
@@ -99,14 +99,14 @@ public class PowerNode extends PowerBlock{
if(linkValid(tile, before) && before.block() instanceof PowerNode){ if(linkValid(tile, before) && before.block() instanceof PowerNode){
for(Tile near : before.entity.proximity()){ for(Tile near : before.entity.proximity()){
if(near.target() == tile){ if(near.target() == tile){
lastPlaced = tile.packedPosition(); lastPlaced = tile.pos();
return; return;
} }
} }
Call.linkPowerNodes(null, tile, before); Call.linkPowerNodes(null, tile, before);
} }
lastPlaced = tile.packedPosition(); lastPlaced = tile.pos();
} }
@Override @Override
@@ -202,7 +202,7 @@ public class PowerNode extends PowerBlock{
for(int i = 0; i < entity.power.links.size; i++){ for(int i = 0; i < entity.power.links.size; i++){
Tile link = world.tile(entity.power.links.get(i)); Tile link = world.tile(entity.power.links.get(i));
if(linkValid(tile, link) && (!(link.block() instanceof PowerNode) if(linkValid(tile, link) && (!(link.block() instanceof PowerNode)
|| ((tile.block().size > link.block().size) || (tile.block().size == link.block().size && tile.id() < link.id())))){ || ((tile.block().size > link.block().size) || (tile.block().size == link.block().size && tile.pos() < link.pos())))){
drawLaser(tile, link); drawLaser(tile, link);
} }
} }
@@ -211,7 +211,7 @@ public class PowerNode extends PowerBlock{
} }
protected boolean linked(Tile tile, Tile other){ protected boolean linked(Tile tile, Tile other){
return tile.entity.power.links.contains(other.packedPosition()); return tile.entity.power.links.contains(other.pos());
} }
protected boolean linkValid(Tile tile, Tile link){ protected boolean linkValid(Tile tile, Tile link){
@@ -227,7 +227,7 @@ public class PowerNode extends PowerBlock{
return Vector2.dst(tile.drawx(), tile.drawy(), link.drawx(), link.drawy()) <= Math.max(laserRange * tilesize, return Vector2.dst(tile.drawx(), tile.drawy(), link.drawx(), link.drawy()) <= Math.max(laserRange * tilesize,
((PowerNode) link.block()).laserRange * tilesize) ((PowerNode) link.block()).laserRange * tilesize)
+ (link.block().size - 1) * tilesize / 2f + (tile.block().size - 1) * tilesize / 2f && + (link.block().size - 1) * tilesize / 2f + (tile.block().size - 1) * tilesize / 2f &&
(!checkMaxNodes || (oe.power.links.size < ((PowerNode) link.block()).maxNodes || oe.power.links.contains(tile.packedPosition()))); (!checkMaxNodes || (oe.power.links.size < ((PowerNode) link.block()).maxNodes || oe.power.links.contains(tile.pos())));
}else{ }else{
return Vector2.dst(tile.drawx(), tile.drawy(), link.drawx(), link.drawy()) return Vector2.dst(tile.drawx(), tile.drawy(), link.drawx(), link.drawy())
<= laserRange * tilesize + (link.block().size - 1) * tilesize; <= laserRange * tilesize + (link.block().size - 1) * tilesize;

View File

@@ -74,7 +74,7 @@ public class Cultivator extends Drill{
Draw.color(bottomColor, plantColorLight, entity.warmup); Draw.color(bottomColor, plantColorLight, entity.warmup);
random.setSeed(tile.packedPosition()); random.setSeed(tile.pos());
for(int i = 0; i < 12; i++){ for(int i = 0; i < 12; i++){
float offset = random.nextFloat() * 999999f; float offset = random.nextFloat() * 999999f;
float x = random.range(4f), y = random.range(4f); float x = random.range(4f), y = random.range(4f);

View File

@@ -101,9 +101,9 @@ public class StorageGraph{
add(child); add(child);
for(Tile next : child.entity.proximity()){ for(Tile next : child.entity.proximity()){
if(next != base && next.block() instanceof StorageBlock && next.<StorageEntity>entity().graph == null && !closedSet.contains(next.packedPosition())){ if(next != base && next.block() instanceof StorageBlock && next.<StorageEntity>entity().graph == null && !closedSet.contains(next.pos())){
queue.addLast(next); queue.addLast(next);
closedSet.add(next.packedPosition()); closedSet.add(next.pos());
} }
} }
} }

View File

@@ -62,7 +62,7 @@ public class Reconstructor extends Block{
if(other != null && other.block() instanceof Reconstructor){ if(other != null && other.block() instanceof Reconstructor){
ReconstructorEntity oe = other.entity(); ReconstructorEntity oe = other.entity();
if(oe.link == entity.tile.packedPosition()){ if(oe.link == entity.tile.pos()){
oe.link = -1; oe.link = -1;
} }
} }
@@ -103,8 +103,8 @@ public class Reconstructor extends Block{
unlink(entity); unlink(entity);
unlink(oe); unlink(oe);
entity.link = other.packedPosition(); entity.link = other.pos();
oe.link = tile.packedPosition(); oe.link = tile.pos();
}); });
} }
@@ -161,7 +161,7 @@ public class Reconstructor extends Block{
ReconstructorEntity entity = tile.entity(); ReconstructorEntity entity = tile.entity();
if(entity.link == other.packedPosition()){ if(entity.link == other.pos()){
Call.unlinkReconstructor(null, tile, other); Call.unlinkReconstructor(null, tile, other);
return false; return false;
}else if(other.block() instanceof Reconstructor){ }else if(other.block() instanceof Reconstructor){