Minor optimization
This commit is contained in:
@@ -115,6 +115,10 @@ public class World extends Module{
|
||||
if(!Mathf.inBounds(x, y, tiles)) return null;
|
||||
return tiles[x][y];
|
||||
}
|
||||
|
||||
public Tile rawTile(int x, int y){
|
||||
return tiles[x][y];
|
||||
}
|
||||
|
||||
public Tile tileWorld(float x, float y){
|
||||
return tile(Mathf.scl2(x, tilesize), Mathf.scl2(y, tilesize));
|
||||
|
||||
@@ -59,19 +59,25 @@ public class BlockRenderer{
|
||||
|
||||
Graphics.surface(renderer.effectSurface);
|
||||
|
||||
for(int x = -rangex - expandr; x <= rangex + expandr; x++){
|
||||
for(int y = -rangey - expandr; y <= rangey + expandr; y++){
|
||||
int worldx = Mathf.scl(camera.position.x, tilesize) + x;
|
||||
int worldy = Mathf.scl(camera.position.y, tilesize) + y;
|
||||
boolean expanded = (x < -rangex || x > rangex || y < -rangey || y > rangey);
|
||||
int avgx = Mathf.scl(camera.position.x, tilesize);
|
||||
int avgy = Mathf.scl(camera.position.y, tilesize);
|
||||
|
||||
int minx = Math.max(avgx - rangex - expandr, 0);
|
||||
int miny = Math.max(avgy - rangey - expandr, 0);
|
||||
int maxx = Math.min(world.width() - 1, avgx + rangex + expandr);
|
||||
int maxy = Math.min(world.height() - 1, avgy+ rangey + expandr);
|
||||
|
||||
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);
|
||||
|
||||
synchronized (Tile.tileSetLock) {
|
||||
Tile tile = world.tile(worldx, worldy);
|
||||
Tile tile = world.rawTile(x, y);
|
||||
|
||||
if (tile != null) {
|
||||
Block block = tile.block();
|
||||
|
||||
if (!expanded && block != Blocks.air && world.isAccessible(worldx, worldy)) {
|
||||
if (!expanded && block != Blocks.air && world.isAccessible(x, y)) {
|
||||
tile.block().drawShadow(tile);
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,8 @@ public class Tile implements PosTrait, TargetTrait {
|
||||
public static final Object tileSetLock = new Object();
|
||||
|
||||
/**Block ID data.*/
|
||||
private byte floor, wall;
|
||||
private Block wall;
|
||||
private Floor floor;
|
||||
/**Rotation, 0-3. Also used to store offload location for routers, in which case it can be any number.*/
|
||||
private byte rotation;
|
||||
/**Team ordinal.*/
|
||||
@@ -52,15 +53,15 @@ public class Tile implements PosTrait, TargetTrait {
|
||||
|
||||
public Tile(int x, int y, byte floor, byte wall){
|
||||
this(x, y);
|
||||
this.floor = floor;
|
||||
this.wall = wall;
|
||||
this.floor = (Floor) Block.getByID(floor);
|
||||
this.wall = Block.getByID(wall);
|
||||
changed();
|
||||
}
|
||||
|
||||
public Tile(int x, int y, byte floor, byte wall, byte rotation, byte team, byte elevation){
|
||||
this(x, y);
|
||||
this.floor = floor;
|
||||
this.wall = wall;
|
||||
this.floor =(Floor) Block.getByID(floor);
|
||||
this.wall = Block.getByID(wall);
|
||||
this.rotation = rotation;
|
||||
this.elevation = elevation;
|
||||
changed();
|
||||
@@ -72,11 +73,11 @@ public class Tile implements PosTrait, TargetTrait {
|
||||
}
|
||||
|
||||
public byte getWallID(){
|
||||
return wall;
|
||||
return (byte)wall.id;
|
||||
}
|
||||
|
||||
public byte getFloorID(){
|
||||
return floor;
|
||||
return (byte)floor.id;
|
||||
}
|
||||
|
||||
/**Return relative rotation to a coordinate. Returns -1 if the coordinate is not near this tile.*/
|
||||
@@ -129,11 +130,11 @@ public class Tile implements PosTrait, TargetTrait {
|
||||
}
|
||||
|
||||
public Floor floor(){
|
||||
return (Floor)Block.getByID(getFloorID());
|
||||
return floor;
|
||||
}
|
||||
|
||||
public Block block(){
|
||||
return Block.getByID(getWallID());
|
||||
return wall;
|
||||
}
|
||||
|
||||
public Team getTeam(){
|
||||
@@ -161,7 +162,7 @@ public class Tile implements PosTrait, TargetTrait {
|
||||
public void setBlock(Block type, int rotation){
|
||||
synchronized (tileSetLock) {
|
||||
if(rotation < 0) rotation = (-rotation + 2);
|
||||
this.wall = (byte)type.id;
|
||||
this.wall = type;
|
||||
this.link = 0;
|
||||
setRotation((byte) (rotation % 4));
|
||||
changed();
|
||||
@@ -170,14 +171,14 @@ public class Tile implements PosTrait, TargetTrait {
|
||||
|
||||
public void setBlock(Block type){
|
||||
synchronized (tileSetLock) {
|
||||
this.wall = (byte)type.id;
|
||||
this.wall = type;
|
||||
this.link = 0;
|
||||
changed();
|
||||
}
|
||||
}
|
||||
|
||||
public void setFloor(Block type){
|
||||
this.floor = (byte)type.id;
|
||||
public void setFloor(Floor type){
|
||||
this.floor = type;
|
||||
}
|
||||
|
||||
public void setRotation(byte rotation){
|
||||
|
||||
@@ -15,6 +15,7 @@ import io.anuke.mindustry.io.MapTileData.TileDataMarker;
|
||||
import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.Floor;
|
||||
import io.anuke.ucore.noise.RidgedPerlin;
|
||||
import io.anuke.ucore.noise.Simplex;
|
||||
import io.anuke.ucore.util.Geometry;
|
||||
@@ -133,7 +134,7 @@ public class WorldGenerator {
|
||||
if(entry.noise.octaveNoise2D(2, 0.7, 1f / (2 + i*2), x, y)/2f +
|
||||
entry.ridge.getValue(x, y, 1f / (28 + i*4)) >= 2.0f - entry.frequency*4.0f
|
||||
&& entry.ridge.getValue(x+9999, y+9999, 1f/100f) > 0.4){
|
||||
tile.setFloor(OreBlocks.get(tile.floor(), entry.item));
|
||||
tile.setFloor((Floor) OreBlocks.get(tile.floor(), entry.item));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user