Large world size optimizations
This commit is contained in:
@@ -109,7 +109,7 @@ public class Pathfinder{
|
|||||||
//add all targets to the frontier
|
//add all targets to the frontier
|
||||||
for(Tile other : world.indexer.getEnemy(team, BlockFlag.target)){
|
for(Tile other : world.indexer.getEnemy(team, BlockFlag.target)){
|
||||||
path.weights[other.x][other.y] = 0;
|
path.weights[other.x][other.y] = 0;
|
||||||
path.searches[other.x][other.y] = path.search;
|
path.searches[other.x][other.y] = (short)path.search;
|
||||||
path.frontier.addFirst(other);
|
path.frontier.addFirst(other);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -117,6 +117,8 @@ public class Pathfinder{
|
|||||||
|
|
||||||
private void createFor(Team team){
|
private void createFor(Team team){
|
||||||
PathData path = new PathData();
|
PathData path = new PathData();
|
||||||
|
path.weights = new float[world.width()][world.height()];
|
||||||
|
path.searches = new short[world.width()][world.height()];
|
||||||
path.search++;
|
path.search++;
|
||||||
path.frontier.ensureCapacity((world.width() + world.height()) * 3);
|
path.frontier.ensureCapacity((world.width() + world.height()) * 3);
|
||||||
|
|
||||||
@@ -130,7 +132,7 @@ public class Pathfinder{
|
|||||||
&& tile.block().flags.contains(BlockFlag.target)){
|
&& tile.block().flags.contains(BlockFlag.target)){
|
||||||
path.frontier.addFirst(tile);
|
path.frontier.addFirst(tile);
|
||||||
path.weights[x][y] = 0;
|
path.weights[x][y] = 0;
|
||||||
path.searches[x][y] = path.search;
|
path.searches[x][y] = (short)path.search;
|
||||||
}else{
|
}else{
|
||||||
path.weights[x][y] = Float.MAX_VALUE;
|
path.weights[x][y] = Float.MAX_VALUE;
|
||||||
}
|
}
|
||||||
@@ -159,7 +161,7 @@ public class Pathfinder{
|
|||||||
&& passable(other, team)){
|
&& passable(other, team)){
|
||||||
path.frontier.addFirst(world.tile(dx, dy));
|
path.frontier.addFirst(world.tile(dx, dy));
|
||||||
path.weights[dx][dy] = cost + other.cost;
|
path.weights[dx][dy] = cost + other.cost;
|
||||||
path.searches[dx][dy] = path.search;
|
path.searches[dx][dy] = (short)path.search;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -186,14 +188,9 @@ public class Pathfinder{
|
|||||||
|
|
||||||
class PathData{
|
class PathData{
|
||||||
float[][] weights;
|
float[][] weights;
|
||||||
int[][] searches;
|
short[][] searches;
|
||||||
int search = 0;
|
int search = 0;
|
||||||
long lastSearchTime;
|
long lastSearchTime;
|
||||||
Queue<Tile> frontier = new Queue<>();
|
Queue<Tile> frontier = new Queue<>();
|
||||||
|
|
||||||
PathData(){
|
|
||||||
weights = new float[world.width()][world.height()];
|
|
||||||
searches = new int[world.width()][world.height()];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import static io.anuke.mindustry.Vars.*;
|
|||||||
public class BlockRenderer{
|
public class BlockRenderer{
|
||||||
private final static int initialRequests = 32 * 32;
|
private final static int initialRequests = 32 * 32;
|
||||||
private final static int expandr = 6;
|
private final static int expandr = 6;
|
||||||
|
private final static boolean disableShadows = true;
|
||||||
|
|
||||||
public final FloorRenderer floor = new FloorRenderer();
|
public final FloorRenderer floor = new FloorRenderer();
|
||||||
|
|
||||||
@@ -53,6 +54,8 @@ public class BlockRenderer{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void drawShadows(){
|
public void drawShadows(){
|
||||||
|
if(disableShadows) return;
|
||||||
|
|
||||||
if(shadows.getWidth() != Core.graphics.getWidth() || shadows.getHeight() != Core.graphics.getHeight()){
|
if(shadows.getWidth() != Core.graphics.getWidth() || shadows.getHeight() != Core.graphics.getHeight()){
|
||||||
shadows.resize(Core.graphics.getWidth(), Core.graphics.getHeight());
|
shadows.resize(Core.graphics.getWidth(), Core.graphics.getHeight());
|
||||||
}
|
}
|
||||||
@@ -107,7 +110,6 @@ public class BlockRenderer{
|
|||||||
|
|
||||||
if(tile != null){
|
if(tile != null){
|
||||||
Block block = tile.block();
|
Block block = tile.block();
|
||||||
Team team = tile.getTeam();
|
|
||||||
|
|
||||||
if(!expanded && block != Blocks.air && world.isAccessible(x, y)){
|
if(!expanded && block != Blocks.air && world.isAccessible(x, y)){
|
||||||
tile.block().drawShadow(tile);
|
tile.block().drawShadow(tile);
|
||||||
@@ -133,8 +135,6 @@ public class BlockRenderer{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Draw.proj(camera.projection());
|
|
||||||
|
|
||||||
Sort.instance().sort(requests.items, 0, requestidx);
|
Sort.instance().sort(requests.items, 0, requestidx);
|
||||||
|
|
||||||
lastCamX = avgx;
|
lastCamX = avgx;
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import io.anuke.arc.graphics.GL20;
|
|||||||
import io.anuke.arc.graphics.g2d.CacheBatch;
|
import io.anuke.arc.graphics.g2d.CacheBatch;
|
||||||
import io.anuke.arc.graphics.g2d.Draw;
|
import io.anuke.arc.graphics.g2d.Draw;
|
||||||
import io.anuke.arc.graphics.g2d.SpriteBatch;
|
import io.anuke.arc.graphics.g2d.SpriteBatch;
|
||||||
|
import io.anuke.arc.graphics.g2d.SpriteCache;
|
||||||
import io.anuke.arc.math.Mathf;
|
import io.anuke.arc.math.Mathf;
|
||||||
import io.anuke.arc.util.Log;
|
import io.anuke.arc.util.Log;
|
||||||
import io.anuke.arc.util.Structs;
|
import io.anuke.arc.util.Structs;
|
||||||
@@ -30,6 +31,7 @@ public class FloorRenderer{
|
|||||||
private CacheBatch cbatch;
|
private CacheBatch cbatch;
|
||||||
private IntSet drawnLayerSet = new IntSet();
|
private IntSet drawnLayerSet = new IntSet();
|
||||||
private IntArray drawnLayers = new IntArray();
|
private IntArray drawnLayers = new IntArray();
|
||||||
|
private ObjectSet<CacheLayer> used = new ObjectSet<>();
|
||||||
|
|
||||||
public FloorRenderer(){
|
public FloorRenderer(){
|
||||||
Events.on(WorldLoadEvent.class, event -> clearTiles());
|
Events.on(WorldLoadEvent.class, event -> clearTiles());
|
||||||
@@ -142,10 +144,9 @@ public class FloorRenderer{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void cacheChunk(int cx, int cy){
|
private void cacheChunk(int cx, int cy){
|
||||||
|
used.clear();
|
||||||
Chunk chunk = cache[cx][cy];
|
Chunk chunk = cache[cx][cy];
|
||||||
|
|
||||||
ObjectSet<CacheLayer> used = new ObjectSet<>();
|
|
||||||
|
|
||||||
for(int tilex = cx * chunksize; tilex < (cx + 1) * chunksize; tilex++){
|
for(int tilex = cx * chunksize; tilex < (cx + 1) * chunksize; tilex++){
|
||||||
for(int tiley = cy * chunksize; tiley < (cy + 1) * chunksize; tiley++){
|
for(int tiley = cy * chunksize; tiley < (cy + 1) * chunksize; tiley++){
|
||||||
Tile tile = world.tile(tilex, tiley);
|
Tile tile = world.tile(tilex, tiley);
|
||||||
@@ -195,7 +196,8 @@ public class FloorRenderer{
|
|||||||
int chunksx = Mathf.ceil((float) (world.width()) / chunksize),
|
int chunksx = Mathf.ceil((float) (world.width()) / chunksize),
|
||||||
chunksy = Mathf.ceil((float) (world.height()) / chunksize) ;
|
chunksy = Mathf.ceil((float) (world.height()) / chunksize) ;
|
||||||
cache = new Chunk[chunksx][chunksy];
|
cache = new Chunk[chunksx][chunksy];
|
||||||
cbatch = new CacheBatch(world.width() * world.height());
|
SpriteCache sprites = new SpriteCache(world.width() * world.height(), (world.width() / chunksize) * (world.height() / chunksize) * 2, false);
|
||||||
|
cbatch = new CacheBatch(sprites);
|
||||||
|
|
||||||
Time.mark();
|
Time.mark();
|
||||||
|
|
||||||
|
|||||||
@@ -141,8 +141,8 @@ public class WorldGenerator{
|
|||||||
|
|
||||||
int sx = (short)Mathf.range(Short.MAX_VALUE/2);
|
int sx = (short)Mathf.range(Short.MAX_VALUE/2);
|
||||||
int sy = (short)Mathf.range(Short.MAX_VALUE/2);
|
int sy = (short)Mathf.range(Short.MAX_VALUE/2);
|
||||||
int width = 380;
|
int width = 512;
|
||||||
int height = 380;
|
int height = 512;
|
||||||
Array<Point2> spawns = new Array<>();
|
Array<Point2> spawns = new Array<>();
|
||||||
Array<Item> ores = Item.getAllOres();
|
Array<Item> ores = Item.getAllOres();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user