Removed unnecessary synchronized() blocks
This commit is contained in:
@@ -399,11 +399,11 @@ public class NetClient extends Module{
|
||||
quiet = true;
|
||||
}
|
||||
|
||||
public synchronized void addRemovedEntity(int id){
|
||||
public void addRemovedEntity(int id){
|
||||
removed.add(id);
|
||||
}
|
||||
|
||||
public synchronized boolean isEntityUsed(int id){
|
||||
public boolean isEntityUsed(int id){
|
||||
return removed.contains(id);
|
||||
}
|
||||
|
||||
@@ -414,11 +414,9 @@ public class NetClient extends Module{
|
||||
|
||||
BuildRequest[] requests;
|
||||
|
||||
synchronized(player.getPlaceQueue()){
|
||||
requests = new BuildRequest[player.getPlaceQueue().size];
|
||||
for(int i = 0; i < requests.length; i++){
|
||||
requests[i] = player.getPlaceQueue().get(i);
|
||||
}
|
||||
requests = new BuildRequest[player.getPlaceQueue().size];
|
||||
for(int i = 0; i < requests.length; i++){
|
||||
requests[i] = player.getPlaceQueue().get(i);
|
||||
}
|
||||
|
||||
Call.onClientShapshot(lastSent++, TimeUtils.millis(), player.x, player.y,
|
||||
|
||||
@@ -70,7 +70,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
|
||||
public TargetTrait moveTarget;
|
||||
|
||||
private float walktime;
|
||||
private Queue<BuildRequest> placeQueue = new ThreadQueue<>();
|
||||
private Queue<BuildRequest> placeQueue = new Queue<>();
|
||||
private Tile mining;
|
||||
private CarriableTrait carrying;
|
||||
private Trail trail = new Trail(12);
|
||||
@@ -421,55 +421,53 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
|
||||
|
||||
/**Draw all current build requests. Does not draw the beam effect, only the positions.*/
|
||||
public void drawBuildRequests(){
|
||||
synchronized(getPlaceQueue()){
|
||||
for(BuildRequest request : getPlaceQueue()){
|
||||
if(getCurrentRequest() == request) continue;
|
||||
for(BuildRequest request : getPlaceQueue()){
|
||||
if(getCurrentRequest() == request) continue;
|
||||
|
||||
if(request.breaking){
|
||||
Block block = world.tile(request.x, request.y).target().block();
|
||||
if(request.breaking){
|
||||
Block block = world.tile(request.x, request.y).target().block();
|
||||
|
||||
//draw removal request
|
||||
Lines.stroke(2f);
|
||||
//draw removal request
|
||||
Lines.stroke(2f);
|
||||
|
||||
Draw.color(Palette.removeBack);
|
||||
Draw.color(Palette.removeBack);
|
||||
|
||||
float rad = Mathf.absin(Timers.time(), 7f, 1f) + block.size * tilesize / 2f - 1;
|
||||
float rad = Mathf.absin(Timers.time(), 7f, 1f) + block.size * tilesize / 2f - 1;
|
||||
|
||||
Lines.square(
|
||||
request.x * tilesize + block.offset(),
|
||||
request.y * tilesize + block.offset() - 1,
|
||||
rad);
|
||||
Lines.square(
|
||||
request.x * tilesize + block.offset(),
|
||||
request.y * tilesize + block.offset() - 1,
|
||||
rad);
|
||||
|
||||
Draw.color(Palette.remove);
|
||||
Draw.color(Palette.remove);
|
||||
|
||||
Lines.square(
|
||||
request.x * tilesize + block.offset(),
|
||||
request.y * tilesize + block.offset(),
|
||||
rad);
|
||||
}else{
|
||||
//draw place request
|
||||
Lines.stroke(2f);
|
||||
Lines.square(
|
||||
request.x * tilesize + block.offset(),
|
||||
request.y * tilesize + block.offset(),
|
||||
rad);
|
||||
}else{
|
||||
//draw place request
|
||||
Lines.stroke(2f);
|
||||
|
||||
Draw.color(Palette.accentBack);
|
||||
Draw.color(Palette.accentBack);
|
||||
|
||||
float rad = Mathf.absin(Timers.time(), 7f, 1f) - 2f + request.recipe.result.size * tilesize / 2f;
|
||||
float rad = Mathf.absin(Timers.time(), 7f, 1f) - 2f + request.recipe.result.size * tilesize / 2f;
|
||||
|
||||
Lines.square(
|
||||
request.x * tilesize + request.recipe.result.offset(),
|
||||
request.y * tilesize + request.recipe.result.offset() - 1,
|
||||
rad);
|
||||
Lines.square(
|
||||
request.x * tilesize + request.recipe.result.offset(),
|
||||
request.y * tilesize + request.recipe.result.offset() - 1,
|
||||
rad);
|
||||
|
||||
Draw.color(Palette.accent);
|
||||
Draw.color(Palette.accent);
|
||||
|
||||
Lines.square(
|
||||
request.x * tilesize + request.recipe.result.offset(),
|
||||
request.y * tilesize + request.recipe.result.offset(),
|
||||
rad);
|
||||
}
|
||||
Lines.square(
|
||||
request.x * tilesize + request.recipe.result.offset(),
|
||||
request.y * tilesize + request.recipe.result.offset(),
|
||||
rad);
|
||||
}
|
||||
|
||||
Draw.reset();
|
||||
}
|
||||
|
||||
Draw.reset();
|
||||
}
|
||||
|
||||
//endregion
|
||||
|
||||
@@ -259,27 +259,25 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
|
||||
|
||||
@Override
|
||||
public void update(){
|
||||
synchronized(Tile.tileSetLock){
|
||||
//TODO better smoke effect, this one is awful
|
||||
if(health != 0 && health < tile.block().health && !(tile.block() instanceof Wall) &&
|
||||
Mathf.chance(0.009f * Timers.delta() * (1f - health / tile.block().health))){
|
||||
//TODO better smoke effect, this one is awful
|
||||
if(health != 0 && health < tile.block().health && !(tile.block() instanceof Wall) &&
|
||||
Mathf.chance(0.009f * Timers.delta() * (1f - health / tile.block().health))){
|
||||
|
||||
Effects.effect(Fx.smoke, x + Mathf.range(4), y + Mathf.range(4));
|
||||
}
|
||||
Effects.effect(Fx.smoke, x + Mathf.range(4), y + Mathf.range(4));
|
||||
}
|
||||
|
||||
timeScaleDuration -= Timers.delta();
|
||||
if(timeScaleDuration <= 0f || !tile.block().canOverdrive){
|
||||
timeScale = 1f;
|
||||
}
|
||||
timeScaleDuration -= Timers.delta();
|
||||
if(timeScaleDuration <= 0f || !tile.block().canOverdrive){
|
||||
timeScale = 1f;
|
||||
}
|
||||
|
||||
if(health <= 0){
|
||||
onDeath();
|
||||
}
|
||||
Block previous = tile.block();
|
||||
tile.block().update(tile);
|
||||
if(tile.block() == previous && cons != null){
|
||||
cons.update(this);
|
||||
}
|
||||
if(health <= 0){
|
||||
onDeath();
|
||||
}
|
||||
Block previous = tile.block();
|
||||
tile.block().update(tile);
|
||||
if(tile.block() == previous && cons != null){
|
||||
cons.update(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -84,30 +84,28 @@ public interface BuilderTrait extends Entity{
|
||||
}
|
||||
|
||||
default void readBuilding(DataInput input, boolean applyChanges) throws IOException{
|
||||
synchronized(getPlaceQueue()){
|
||||
if(applyChanges) getPlaceQueue().clear();
|
||||
if(applyChanges) getPlaceQueue().clear();
|
||||
|
||||
byte type = input.readByte();
|
||||
if(type != -1){
|
||||
int position = input.readInt();
|
||||
float progress = input.readFloat();
|
||||
BuildRequest request;
|
||||
byte type = input.readByte();
|
||||
if(type != -1){
|
||||
int position = input.readInt();
|
||||
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(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));
|
||||
}
|
||||
|
||||
request.progress = progress;
|
||||
request.progress = progress;
|
||||
|
||||
if(applyChanges){
|
||||
getPlaceQueue().addLast(request);
|
||||
}else if(isBuilding()){
|
||||
getCurrentRequest().progress = progress;
|
||||
}
|
||||
if(applyChanges){
|
||||
getPlaceQueue().addLast(request);
|
||||
}else if(isBuilding()){
|
||||
getCurrentRequest().progress = progress;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -122,13 +120,11 @@ public interface BuilderTrait extends Entity{
|
||||
* Otherwise, a new place request is added to the queue.
|
||||
*/
|
||||
default void replaceBuilding(int x, int y, int rotation, Recipe recipe){
|
||||
synchronized(getPlaceQueue()){
|
||||
for(BuildRequest request : getPlaceQueue()){
|
||||
if(request.x == x && request.y == y){
|
||||
clearBuilding();
|
||||
addBuildRequest(request);
|
||||
return;
|
||||
}
|
||||
for(BuildRequest request : getPlaceQueue()){
|
||||
if(request.x == x && request.y == y){
|
||||
clearBuilding();
|
||||
addBuildRequest(request);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,18 +138,16 @@ public interface BuilderTrait extends Entity{
|
||||
|
||||
/**Add another build requests to the tail of the queue, if it doesn't exist there yet.*/
|
||||
default void addBuildRequest(BuildRequest place){
|
||||
synchronized(getPlaceQueue()){
|
||||
for(BuildRequest request : getPlaceQueue()){
|
||||
if(request.x == place.x && request.y == place.y){
|
||||
return;
|
||||
}
|
||||
for(BuildRequest request : getPlaceQueue()){
|
||||
if(request.x == place.x && request.y == place.y){
|
||||
return;
|
||||
}
|
||||
Tile tile = world.tile(place.x, place.y);
|
||||
if(tile != null && tile.entity instanceof BuildEntity){
|
||||
place.progress = tile.<BuildEntity>entity().progress;
|
||||
}
|
||||
getPlaceQueue().addLast(place);
|
||||
}
|
||||
Tile tile = world.tile(place.x, place.y);
|
||||
if(tile != null && tile.entity instanceof BuildEntity){
|
||||
place.progress = tile.<BuildEntity>entity().progress;
|
||||
}
|
||||
getPlaceQueue().addLast(place);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -161,9 +155,7 @@ public interface BuilderTrait extends Entity{
|
||||
* May return null.
|
||||
*/
|
||||
default BuildRequest getCurrentRequest(){
|
||||
synchronized(getPlaceQueue()){
|
||||
return getPlaceQueue().size == 0 ? null : getPlaceQueue().first();
|
||||
}
|
||||
return getPlaceQueue().size == 0 ? null : getPlaceQueue().first();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -275,18 +267,15 @@ public interface BuilderTrait extends Entity{
|
||||
/**Draw placement effects for an entity. This includes mining*/
|
||||
default void drawBuilding(Unit unit){
|
||||
BuildRequest request;
|
||||
|
||||
synchronized(getPlaceQueue()){
|
||||
if(!isBuilding()){
|
||||
if(getMineTile() != null){
|
||||
drawMining(unit);
|
||||
}
|
||||
return;
|
||||
if(!isBuilding()){
|
||||
if(getMineTile() != null){
|
||||
drawMining(unit);
|
||||
}
|
||||
|
||||
request = getCurrentRequest();
|
||||
return;
|
||||
}
|
||||
|
||||
request = getCurrentRequest();
|
||||
|
||||
Tile tile = world.tile(request.x, request.y);
|
||||
|
||||
if(unit.distanceTo(tile) > placeDistance){
|
||||
|
||||
@@ -40,12 +40,11 @@ import static io.anuke.mindustry.Vars.unitGroups;
|
||||
import static io.anuke.mindustry.Vars.world;
|
||||
|
||||
public class Drone extends FlyingUnit implements BuilderTrait{
|
||||
protected static float discoverRange = 120f;
|
||||
protected static int timerRepairEffect = timerIndex++;
|
||||
|
||||
protected Item targetItem;
|
||||
protected Tile mineTile;
|
||||
protected Queue<BuildRequest> placeQueue = new ThreadQueue<>();
|
||||
protected Queue<BuildRequest> placeQueue = new Queue<>();
|
||||
protected boolean isBreaking;
|
||||
|
||||
public final UnitState
|
||||
@@ -250,14 +249,12 @@ public class Drone extends FlyingUnit implements BuilderTrait{
|
||||
for(BaseUnit unit : group.all()){
|
||||
if(unit instanceof Drone){
|
||||
Drone drone = (Drone)unit;
|
||||
synchronized(drone.getPlaceQueue()){
|
||||
if(drone.isBuilding()){
|
||||
//stop building if opposite building begins.
|
||||
BuildRequest req = drone.getCurrentRequest();
|
||||
if(req.breaking != event.breaking && req.x == event.tile.x && req.y == event.tile.y){
|
||||
drone.clearBuilding();
|
||||
drone.setState(drone.repair);
|
||||
}
|
||||
if(drone.isBuilding()){
|
||||
//stop building if opposite building begins.
|
||||
BuildRequest req = drone.getCurrentRequest();
|
||||
if(req.breaking != event.breaking && req.x == event.tile.x && req.y == event.tile.y){
|
||||
drone.clearBuilding();
|
||||
drone.setState(drone.repair);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -106,32 +106,29 @@ public class BlockRenderer{
|
||||
for(int x = minx; x <= maxx; x++){
|
||||
for(int y = miny; y <= maxy; y++){
|
||||
boolean expanded = (Math.abs(x - avgx) > rangex || Math.abs(y - avgy) > rangey);
|
||||
Tile tile = world.rawTile(x, y);
|
||||
|
||||
synchronized(Tile.tileSetLock){
|
||||
Tile tile = world.rawTile(x, y);
|
||||
if(tile != null){
|
||||
Block block = tile.block();
|
||||
Team team = tile.getTeam();
|
||||
|
||||
if(tile != null){
|
||||
Block block = tile.block();
|
||||
Team team = tile.getTeam();
|
||||
if(!expanded && block != Blocks.air && world.isAccessible(x, y)){
|
||||
tile.block().drawShadow(tile);
|
||||
}
|
||||
|
||||
if(!expanded && block != Blocks.air && world.isAccessible(x, y)){
|
||||
tile.block().drawShadow(tile);
|
||||
if(block != Blocks.air){
|
||||
if(!expanded){
|
||||
addRequest(tile, Layer.block);
|
||||
teamChecks.add(team.ordinal());
|
||||
}
|
||||
|
||||
if(block != Blocks.air){
|
||||
if(!expanded){
|
||||
addRequest(tile, Layer.block);
|
||||
teamChecks.add(team.ordinal());
|
||||
if(block.expanded || !expanded){
|
||||
if(block.layer != null && block.isLayer(tile)){
|
||||
addRequest(tile, block.layer);
|
||||
}
|
||||
|
||||
if(block.expanded || !expanded){
|
||||
if(block.layer != null && block.isLayer(tile)){
|
||||
addRequest(tile, block.layer);
|
||||
}
|
||||
|
||||
if(block.layer2 != null && block.isLayer2(tile)){
|
||||
addRequest(tile, block.layer2);
|
||||
}
|
||||
if(block.layer2 != null && block.isLayer2(tile)){
|
||||
addRequest(tile, block.layer2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -171,16 +168,14 @@ public class BlockRenderer{
|
||||
layerBegins(req.layer);
|
||||
}
|
||||
|
||||
synchronized(Tile.tileSetLock){
|
||||
Block block = req.tile.block();
|
||||
Block block = req.tile.block();
|
||||
|
||||
if(req.layer == Layer.block){
|
||||
block.draw(req.tile);
|
||||
}else if(req.layer == block.layer){
|
||||
block.drawLayer(req.tile);
|
||||
}else if(req.layer == block.layer2){
|
||||
block.drawLayer2(req.tile);
|
||||
}
|
||||
if(req.layer == Layer.block){
|
||||
block.draw(req.tile);
|
||||
}else if(req.layer == block.layer){
|
||||
block.drawLayer(req.tile);
|
||||
}else if(req.layer == block.layer2){
|
||||
block.drawLayer2(req.tile);
|
||||
}
|
||||
|
||||
lastLayer = req.layer;
|
||||
@@ -199,17 +194,16 @@ public class BlockRenderer{
|
||||
BlockRequest req = requests.get(index);
|
||||
if(req.tile.getTeam() != team) continue;
|
||||
|
||||
synchronized(Tile.tileSetLock){
|
||||
Block block = req.tile.block();
|
||||
Block block = req.tile.block();
|
||||
|
||||
if(req.layer == Layer.block){
|
||||
block.draw(req.tile);
|
||||
}else if(req.layer == block.layer){
|
||||
block.drawLayer(req.tile);
|
||||
}else if(req.layer == block.layer2){
|
||||
block.drawLayer2(req.tile);
|
||||
}
|
||||
if(req.layer == Layer.block){
|
||||
block.draw(req.tile);
|
||||
}else if(req.layer == block.layer){
|
||||
block.drawLayer(req.tile);
|
||||
}else if(req.layer == block.layer2){
|
||||
block.drawLayer2(req.tile);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -74,20 +74,18 @@ public class MinimapRenderer implements Disposable{
|
||||
dx = Mathf.clamp(dx, sz, world.width() - sz);
|
||||
dy = Mathf.clamp(dy, sz, world.height() - sz);
|
||||
|
||||
synchronized(units){
|
||||
rect.set((dx - sz) * tilesize, (dy - sz) * tilesize, sz * 2 * tilesize, sz * 2 * tilesize);
|
||||
Graphics.beginClip(x, y, w, h);
|
||||
rect.set((dx - sz) * tilesize, (dy - sz) * tilesize, sz * 2 * tilesize, sz * 2 * tilesize);
|
||||
Graphics.beginClip(x, y, w, h);
|
||||
|
||||
for(Unit unit : units){
|
||||
float rx = (unit.x - rect.x) / rect.width * w, ry = (unit.y - rect.y) / rect.width * h;
|
||||
Draw.color(unit.getTeam().color);
|
||||
Draw.rect("white", x + rx, y + ry, w / (sz * 2), h / (sz * 2));
|
||||
}
|
||||
|
||||
Draw.color();
|
||||
|
||||
Graphics.endClip();
|
||||
for(Unit unit : units){
|
||||
float rx = (unit.x - rect.x) / rect.width * w, ry = (unit.y - rect.y) / rect.width * h;
|
||||
Draw.color(unit.getTeam().color);
|
||||
Draw.rect("white", x + rx, y + ry, w / (sz * 2), h / (sz * 2));
|
||||
}
|
||||
|
||||
Draw.color();
|
||||
|
||||
Graphics.endClip();
|
||||
}
|
||||
|
||||
public TextureRegion getRegion(){
|
||||
@@ -128,11 +126,9 @@ public class MinimapRenderer implements Disposable{
|
||||
dx = Mathf.clamp(dx, sz, world.width() - sz);
|
||||
dy = Mathf.clamp(dy, sz, world.height() - sz);
|
||||
|
||||
synchronized(units){
|
||||
rect.set((dx - sz) * tilesize, (dy - sz) * tilesize, sz * 2 * tilesize, sz * 2 * tilesize);
|
||||
units.clear();
|
||||
Units.getNearby(rect, units::add);
|
||||
}
|
||||
rect.set((dx - sz) * tilesize, (dy - sz) * tilesize, sz * 2 * tilesize, sz * 2 * tilesize);
|
||||
units.clear();
|
||||
Units.getNearby(rect, units::add);
|
||||
}
|
||||
|
||||
private int colorFor(Tile tile){
|
||||
|
||||
@@ -53,10 +53,7 @@ public class OverlayRenderer{
|
||||
//draw config selected block
|
||||
if(input.frag.config.isShown()){
|
||||
Tile tile = input.frag.config.getSelectedTile();
|
||||
|
||||
synchronized(Tile.tileSetLock){
|
||||
tile.block().drawConfigure(tile);
|
||||
}
|
||||
tile.block().drawConfigure(tile);
|
||||
}
|
||||
|
||||
input.drawTop();
|
||||
@@ -113,53 +110,52 @@ public class OverlayRenderer{
|
||||
Draw.reset();
|
||||
}
|
||||
|
||||
synchronized(Tile.tileSetLock){
|
||||
Block block = target.block();
|
||||
TileEntity entity = target.entity;
|
||||
Block block = target.block();
|
||||
TileEntity entity = target.entity;
|
||||
|
||||
if(entity != null){
|
||||
int[] values = {0, 0};
|
||||
boolean[] doDraw = {false};
|
||||
if(entity != null){
|
||||
int[] values = {0, 0};
|
||||
boolean[] doDraw = {false};
|
||||
|
||||
Runnable drawbars = () -> {
|
||||
for(BlockBar bar : block.bars.list()){
|
||||
float offset = Mathf.sign(bar.top) * (block.size / 2f * tilesize + 2f + (bar.top ? values[0] : values[1]));
|
||||
Runnable drawbars = () -> {
|
||||
for(BlockBar bar : block.bars.list()){
|
||||
float offset = Mathf.sign(bar.top) * (block.size / 2f * tilesize + 2f + (bar.top ? values[0] : values[1]));
|
||||
|
||||
float value = bar.value.get(target);
|
||||
float value = bar.value.get(target);
|
||||
|
||||
if(MathUtils.isEqual(value, -1f)) continue;
|
||||
if(MathUtils.isEqual(value, -1f)) continue;
|
||||
|
||||
if(doDraw[0]){
|
||||
drawBar(bar.type.color, target.drawx(), target.drawy() + offset, value);
|
||||
}
|
||||
|
||||
if(bar.top)
|
||||
values[0]++;
|
||||
else
|
||||
values[1]++;
|
||||
if(doDraw[0]){
|
||||
drawBar(bar.type.color, target.drawx(), target.drawy() + offset, value);
|
||||
}
|
||||
};
|
||||
|
||||
drawbars.run();
|
||||
|
||||
if(values[0] > 0){
|
||||
drawEncloser(target.drawx(), target.drawy() + block.size * tilesize / 2f + 2f, values[0]);
|
||||
if(bar.top)
|
||||
values[0]++;
|
||||
else
|
||||
values[1]++;
|
||||
}
|
||||
};
|
||||
|
||||
if(values[1] > 0){
|
||||
drawEncloser(target.drawx(), target.drawy() - block.size * tilesize / 2f - 2f - values[1], values[1]);
|
||||
}
|
||||
drawbars.run();
|
||||
|
||||
doDraw[0] = true;
|
||||
values[0] = 0;
|
||||
values[1] = 1;
|
||||
|
||||
drawbars.run();
|
||||
if(values[0] > 0){
|
||||
drawEncloser(target.drawx(), target.drawy() + block.size * tilesize / 2f + 2f, values[0]);
|
||||
}
|
||||
|
||||
if(values[1] > 0){
|
||||
drawEncloser(target.drawx(), target.drawy() - block.size * tilesize / 2f - 2f - values[1], values[1]);
|
||||
}
|
||||
|
||||
target.block().drawSelect(target);
|
||||
doDraw[0] = true;
|
||||
values[0] = 0;
|
||||
values[1] = 1;
|
||||
|
||||
drawbars.run();
|
||||
}
|
||||
|
||||
|
||||
target.block().drawSelect(target);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ public class Trail{
|
||||
this.length = length;
|
||||
}
|
||||
|
||||
public synchronized void update(float curx, float cury){
|
||||
public void update(float curx, float cury){
|
||||
if(Vector2.dst(curx, cury, lastX, lastY) >= maxJump){
|
||||
points.clear();
|
||||
}
|
||||
@@ -39,11 +39,11 @@ public class Trail{
|
||||
lastY = cury;
|
||||
}
|
||||
|
||||
public synchronized void clear(){
|
||||
public void clear(){
|
||||
points.clear();
|
||||
}
|
||||
|
||||
public synchronized void draw(Color color, float stroke){
|
||||
public void draw(Color color, float stroke){
|
||||
Draw.color(color);
|
||||
|
||||
for(int i = 0; i < points.size - 2; i += 2){
|
||||
|
||||
@@ -22,7 +22,6 @@ import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
|
||||
public class Tile implements PosTrait, TargetTrait{
|
||||
public static final Object tileSetLock = new Object();
|
||||
/**
|
||||
* 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.
|
||||
@@ -147,33 +146,27 @@ public class Tile implements PosTrait, TargetTrait{
|
||||
}
|
||||
|
||||
public void setBlock(Block type, int rotation){
|
||||
synchronized(tileSetLock){
|
||||
preChanged();
|
||||
if(rotation < 0) rotation = (-rotation + 2);
|
||||
this.wall = type;
|
||||
this.link = 0;
|
||||
setRotation((byte) (rotation % 4));
|
||||
changed();
|
||||
}
|
||||
preChanged();
|
||||
if(rotation < 0) rotation = (-rotation + 2);
|
||||
this.wall = type;
|
||||
this.link = 0;
|
||||
setRotation((byte) (rotation % 4));
|
||||
changed();
|
||||
}
|
||||
|
||||
public void setBlock(Block type, Team team){
|
||||
synchronized(tileSetLock){
|
||||
preChanged();
|
||||
this.wall = type;
|
||||
this.team = (byte)team.ordinal();
|
||||
this.link = 0;
|
||||
changed();
|
||||
}
|
||||
preChanged();
|
||||
this.wall = type;
|
||||
this.team = (byte)team.ordinal();
|
||||
this.link = 0;
|
||||
changed();
|
||||
}
|
||||
|
||||
public void setBlock(Block type){
|
||||
synchronized(tileSetLock){
|
||||
preChanged();
|
||||
this.wall = type;
|
||||
this.link = 0;
|
||||
changed();
|
||||
}
|
||||
preChanged();
|
||||
this.wall = type;
|
||||
this.link = 0;
|
||||
changed();
|
||||
}
|
||||
|
||||
public void setFloor(Floor type){
|
||||
@@ -270,7 +263,7 @@ public class Tile implements PosTrait, TargetTrait{
|
||||
* Returns the list of all tiles linked to this multiblock, or an empty array if it's not a multiblock.
|
||||
* This array contains all linked tiles, including this tile itself.
|
||||
*/
|
||||
public synchronized Array<Tile> getLinkedTiles(Array<Tile> tmpArray){
|
||||
public Array<Tile> getLinkedTiles(Array<Tile> tmpArray){
|
||||
Block block = block();
|
||||
tmpArray.clear();
|
||||
if(block.isMultiblock()){
|
||||
@@ -292,7 +285,7 @@ public class Tile implements PosTrait, TargetTrait{
|
||||
* Returns the list of all tiles linked to this multiblock if it were this block, or an empty array if it's not a multiblock.
|
||||
* This array contains all linked tiles, including this tile itself.
|
||||
*/
|
||||
public synchronized Array<Tile> getLinkedTilesAs(Block block, Array<Tile> tmpArray){
|
||||
public Array<Tile> getLinkedTilesAs(Block block, Array<Tile> tmpArray){
|
||||
tmpArray.clear();
|
||||
if(block.isMultiblock()){
|
||||
int offsetx = -(block.size - 1) / 2;
|
||||
@@ -394,52 +387,47 @@ public class Tile implements PosTrait, TargetTrait{
|
||||
}
|
||||
|
||||
private void preChanged(){
|
||||
synchronized(tileSetLock){
|
||||
block().removed(this);
|
||||
if(entity != null){
|
||||
entity.removeFromProximity();
|
||||
}
|
||||
team = 0;
|
||||
block().removed(this);
|
||||
if(entity != null){
|
||||
entity.removeFromProximity();
|
||||
}
|
||||
team = 0;
|
||||
}
|
||||
|
||||
private void changed(){
|
||||
|
||||
synchronized(tileSetLock){
|
||||
if(entity != null){
|
||||
entity.remove();
|
||||
entity = null;
|
||||
}
|
||||
|
||||
Block block = block();
|
||||
|
||||
if(block.hasEntity()){
|
||||
entity = block.newEntity().init(this, block.update);
|
||||
entity.cons = new ConsumeModule();
|
||||
if(block.hasItems) entity.items = new ItemModule();
|
||||
if(block.hasLiquids) entity.liquids = new LiquidModule();
|
||||
if(block.hasPower){
|
||||
entity.power = new PowerModule();
|
||||
entity.power.graph.add(this);
|
||||
}
|
||||
|
||||
if(!world.isGenerating()){
|
||||
entity.updateProximity();
|
||||
}
|
||||
}else if(!(block instanceof BlockPart) && !world.isGenerating()){
|
||||
//since the entity won't update proximity for us, update proximity for all nearby tiles manually
|
||||
for(GridPoint2 p : Geometry.d4){
|
||||
Tile tile = world.tile(x + p.x, y + p.y);
|
||||
if(tile != null){
|
||||
tile = tile.target();
|
||||
tile.block().onProximityUpdate(tile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
updateOcclusion();
|
||||
if(entity != null){
|
||||
entity.remove();
|
||||
entity = null;
|
||||
}
|
||||
|
||||
Block block = block();
|
||||
|
||||
if(block.hasEntity()){
|
||||
entity = block.newEntity().init(this, block.update);
|
||||
entity.cons = new ConsumeModule();
|
||||
if(block.hasItems) entity.items = new ItemModule();
|
||||
if(block.hasLiquids) entity.liquids = new LiquidModule();
|
||||
if(block.hasPower){
|
||||
entity.power = new PowerModule();
|
||||
entity.power.graph.add(this);
|
||||
}
|
||||
|
||||
if(!world.isGenerating()){
|
||||
entity.updateProximity();
|
||||
}
|
||||
}else if(!(block instanceof BlockPart) && !world.isGenerating()){
|
||||
//since the entity won't update proximity for us, update proximity for all nearby tiles manually
|
||||
for(GridPoint2 p : Geometry.d4){
|
||||
Tile tile = world.tile(x + p.x, y + p.y);
|
||||
if(tile != null){
|
||||
tile = tile.target();
|
||||
tile.block().onProximityUpdate(tile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
updateOcclusion();
|
||||
|
||||
world.notifyChanged(this);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user