Merge branch 'remove-tile-pack' of https://github.com/Anuken/Mindustry
This commit is contained in:
@@ -58,7 +58,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
|
||||
public boolean achievedFlight;
|
||||
public Color color = new Color();
|
||||
public Mech mech;
|
||||
public int spawner = -1;
|
||||
public int spawner = noSpawner;
|
||||
|
||||
public NetConnection con;
|
||||
public int playerIndex = 0;
|
||||
@@ -498,7 +498,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
|
||||
updateRespawning();
|
||||
return;
|
||||
}else{
|
||||
spawner = -1;
|
||||
spawner = noSpawner;
|
||||
}
|
||||
|
||||
avoidOthers(1f);
|
||||
@@ -788,23 +788,23 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
|
||||
|
||||
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);
|
||||
}else{
|
||||
CoreEntity entity = (CoreEntity) getClosestCore();
|
||||
if(entity != null && !netServer.isWaitingForPlayers()){
|
||||
this.spawner = entity.tile.id();
|
||||
this.spawner = entity.tile.pos();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void beginRespawning(SpawnerTrait spawner){
|
||||
this.spawner = spawner.getTile().packedPosition();
|
||||
this.spawner = spawner.getTile().pos();
|
||||
this.dead = true;
|
||||
}
|
||||
|
||||
public void endRespawning(){
|
||||
spawner = -1;
|
||||
spawner = noSpawner;
|
||||
}
|
||||
|
||||
//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.writeInt(Color.rgba8888(color));
|
||||
buffer.writeByte(mech.id);
|
||||
buffer.writeInt(mining == null ? -1 : mining.packedPosition());
|
||||
buffer.writeInt(mining == null ? -1 : mining.pos());
|
||||
buffer.writeInt(spawner);
|
||||
buffer.writeShort((short) (baseRotation * 2));
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ import io.anuke.mindustry.net.Interpolator;
|
||||
import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.mindustry.type.StatusEffect;
|
||||
import io.anuke.mindustry.type.Weapon;
|
||||
import io.anuke.mindustry.world.Pos;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.Floor;
|
||||
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;
|
||||
/**Maximum absolute value of a velocity vector component.*/
|
||||
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 Vector2 moveVector = new Vector2();
|
||||
|
||||
@@ -48,7 +48,7 @@ public class Fire extends TimedEntity implements SaveTrait, SyncTrait, Poolable{
|
||||
public static void create(Tile tile){
|
||||
if(Net.client() || tile == null) return; //not clientside.
|
||||
|
||||
Fire fire = map.get(tile.packedPosition());
|
||||
Fire fire = map.get(tile.pos());
|
||||
|
||||
if(fire == null){
|
||||
fire = Pooling.obtain(Fire.class, Fire::new);
|
||||
@@ -56,7 +56,7 @@ public class Fire extends TimedEntity implements SaveTrait, SyncTrait, Poolable{
|
||||
fire.lifetime = baseLifetime;
|
||||
fire.set(tile.worldx(), tile.worldy());
|
||||
fire.add();
|
||||
map.put(tile.packedPosition(), fire);
|
||||
map.put(tile.pos(), fire);
|
||||
}else{
|
||||
fire.lifetime = baseLifetime;
|
||||
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.
|
||||
*/
|
||||
public static void extinguish(Tile tile, float intensity){
|
||||
if(tile != null && map.containsKey(tile.packedPosition())){
|
||||
map.get(tile.packedPosition()).time += intensity * Timers.delta();
|
||||
if(tile != null && map.containsKey(tile.pos())){
|
||||
map.get(tile.pos()).time += intensity * Timers.delta();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,7 +157,7 @@ public class Fire extends TimedEntity implements SaveTrait, SyncTrait, Poolable{
|
||||
|
||||
@Override
|
||||
public void writeSave(DataOutput stream) throws IOException{
|
||||
stream.writeInt(tile.packedPosition());
|
||||
stream.writeInt(tile.pos());
|
||||
stream.writeFloat(lifetime);
|
||||
stream.writeFloat(time);
|
||||
}
|
||||
@@ -202,7 +202,7 @@ public class Fire extends TimedEntity implements SaveTrait, SyncTrait, Poolable{
|
||||
@Override
|
||||
public void removed(){
|
||||
if(tile != null){
|
||||
map.remove(tile.packedPosition());
|
||||
map.remove(tile.pos());
|
||||
}
|
||||
reset();
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ public class Puddle extends SolidEntity implements SaveTrait, Poolable, DrawTrai
|
||||
|
||||
/**Returns the puddle on the specified tile. May return null.*/
|
||||
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){
|
||||
@@ -83,7 +83,7 @@ public class Puddle extends SolidEntity implements SaveTrait, Poolable, DrawTrai
|
||||
reactPuddle(tile.floor().liquidDrop, liquid, amount, tile,
|
||||
(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){
|
||||
Effects.effect(BlockFx.ripple, tile.floor().liquidDrop.color,
|
||||
@@ -93,7 +93,7 @@ public class Puddle extends SolidEntity implements SaveTrait, Poolable, DrawTrai
|
||||
return;
|
||||
}
|
||||
|
||||
Puddle p = map.get(tile.packedPosition());
|
||||
Puddle p = map.get(tile.pos());
|
||||
if(p == null){
|
||||
if(Net.client()) return; //not clientside.
|
||||
|
||||
@@ -104,7 +104,7 @@ public class Puddle extends SolidEntity implements SaveTrait, Poolable, DrawTrai
|
||||
puddle.generation = (byte) generation;
|
||||
puddle.set((tile.worldx() + source.worldx()) / 2f, (tile.worldy() + source.worldy()) / 2f);
|
||||
puddle.add();
|
||||
map.put(tile.packedPosition(), puddle);
|
||||
map.put(tile.pos(), puddle);
|
||||
}else if(p.liquid == liquid){
|
||||
p.accepting = Math.max(amount, p.accepting);
|
||||
|
||||
@@ -249,7 +249,7 @@ public class Puddle extends SolidEntity implements SaveTrait, Poolable, DrawTrai
|
||||
|
||||
@Override
|
||||
public void writeSave(DataOutput stream) throws IOException{
|
||||
stream.writeInt(tile.packedPosition());
|
||||
stream.writeInt(tile.pos());
|
||||
stream.writeFloat(x);
|
||||
stream.writeFloat(y);
|
||||
stream.writeByte(liquid.id);
|
||||
@@ -288,7 +288,7 @@ public class Puddle extends SolidEntity implements SaveTrait, Poolable, DrawTrai
|
||||
|
||||
@Override
|
||||
public void removed(){
|
||||
map.remove(tile.packedPosition());
|
||||
map.remove(tile.pos());
|
||||
reset();
|
||||
}
|
||||
|
||||
@@ -298,7 +298,7 @@ public class Puddle extends SolidEntity implements SaveTrait, Poolable, DrawTrai
|
||||
data.writeFloat(y);
|
||||
data.writeByte(liquid.id);
|
||||
data.writeShort((short) (amount * 4));
|
||||
data.writeInt(tile.packedPosition());
|
||||
data.writeInt(tile.pos());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -309,7 +309,7 @@ public class Puddle extends SolidEntity implements SaveTrait, Poolable, DrawTrai
|
||||
targetAmount = data.readShort() / 4f;
|
||||
tile = world.tile(data.readInt());
|
||||
|
||||
map.put(tile.packedPosition(), this);
|
||||
map.put(tile.pos(), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,6 +16,7 @@ import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.mindustry.type.Recipe;
|
||||
import io.anuke.mindustry.world.Build;
|
||||
import io.anuke.mindustry.world.Pos;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.BuildBlock;
|
||||
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.Lines;
|
||||
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.DataOutput;
|
||||
@@ -72,7 +76,7 @@ public interface BuilderTrait extends Entity{
|
||||
|
||||
if(request != null){
|
||||
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);
|
||||
if(!request.breaking){
|
||||
output.writeByte(request.recipe.id);
|
||||
@@ -96,13 +100,13 @@ public interface BuilderTrait extends Entity{
|
||||
float progress = input.readFloat();
|
||||
BuildRequest request;
|
||||
|
||||
if(type == 1){ //remove
|
||||
request = new BuildRequest(position % world.width(), position / world.width());
|
||||
}else{ //place
|
||||
byte recipe = input.readByte();
|
||||
byte rotation = input.readByte();
|
||||
request = new BuildRequest(position % world.width(), position / world.width(), rotation, content.recipe(recipe));
|
||||
}
|
||||
if(type == 1){ //remove
|
||||
request = new BuildRequest(Pos.x(position), Pos.y(position));
|
||||
}else{ //place
|
||||
byte recipe = input.readByte();
|
||||
byte rotation = input.readByte();
|
||||
request = new BuildRequest(Pos.x(position), Pos.y(position), rotation, content.recipe(recipe));
|
||||
}
|
||||
|
||||
request.progress = progress;
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
|
||||
|
||||
protected boolean isWave;
|
||||
protected Squad squad;
|
||||
protected int spawner = -1;
|
||||
protected int spawner = noSpawner;
|
||||
|
||||
/**internal constructor used for deserialization, DO NOT USE*/
|
||||
public BaseUnit(){
|
||||
@@ -111,16 +111,8 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
|
||||
return type;
|
||||
}
|
||||
|
||||
public Tile getSpawner(){
|
||||
return world.tile(spawner);
|
||||
}
|
||||
|
||||
public void setSpawner(Tile tile){
|
||||
this.spawner = tile.packedPosition();
|
||||
}
|
||||
|
||||
public void setIntSpawner(int pos){
|
||||
this.spawner = pos;
|
||||
this.spawner = tile.pos();
|
||||
}
|
||||
|
||||
/**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(){
|
||||
if(spawner == -1) return;
|
||||
if(spawner == noSpawner) return;
|
||||
|
||||
Tile tile = world.tile(spawner);
|
||||
if(tile != null && tile.entity != null){
|
||||
@@ -151,7 +143,7 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
|
||||
((SpawnerTrait) tile.entity).updateSpawning(this);
|
||||
}
|
||||
}else{
|
||||
spawner = -1;
|
||||
spawner = noSpawner;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -305,7 +297,7 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -336,7 +328,7 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
|
||||
|
||||
@Override
|
||||
public void removed(){
|
||||
spawner = -1;
|
||||
spawner = noSpawner;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -358,8 +358,8 @@ public class Drone extends FlyingUnit implements BuilderTrait{
|
||||
@Override
|
||||
public void write(DataOutput data) throws IOException{
|
||||
super.write(data);
|
||||
data.writeInt(mineTile == null || !state.is(mine) ? -1 : mineTile.packedPosition());
|
||||
data.writeInt(state.is(repair) && target instanceof TileEntity ? ((TileEntity)target).tile.packedPosition() : -1);
|
||||
data.writeInt(mineTile == null || !state.is(mine) ? -1 : mineTile.pos());
|
||||
data.writeInt(state.is(repair) && target instanceof TileEntity ? ((TileEntity)target).tile.pos() : -1);
|
||||
writeBuilding(data);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user