Minor floor renderer optimization

This commit is contained in:
Anuken
2021-03-18 21:55:33 -04:00
parent 851fa09e0c
commit 49c099a03c
2 changed files with 12 additions and 13 deletions

View File

@@ -17,7 +17,7 @@ import java.util.*;
import static mindustry.Vars.*; import static mindustry.Vars.*;
public class FloorRenderer implements Disposable{ public class FloorRenderer implements Disposable{
private static final int chunksize = mobile ? 16 : 32; private static final int chunksize = mobile ? 16 : 32, chunkunits = chunksize * tilesize;
private int[][][] cache; private int[][][] cache;
private MultiCacheBatch cbatch; private MultiCacheBatch cbatch;
@@ -43,11 +43,13 @@ public class FloorRenderer implements Disposable{
Camera camera = Core.camera; Camera camera = Core.camera;
int crangex = (int)(camera.width / (chunksize * tilesize)) + 1; float pad = tilesize/2f;
int crangey = (int)(camera.height / (chunksize * tilesize)) + 1;
int camx = (int)(camera.position.x / (chunksize * tilesize)); int
int camy = (int)(camera.position.y / (chunksize * tilesize)); minx = (int)((camera.position.x - camera.width/2f - pad) / chunkunits),
miny = (int)((camera.position.y - camera.height/2f - pad) / chunkunits),
maxx = Mathf.ceil((camera.position.x + camera.width/2f + pad) / chunkunits),
maxy = Mathf.ceil((camera.position.y + camera.height/2f + pad) / chunkunits);
int layers = CacheLayer.all.length; int layers = CacheLayer.all.length;
@@ -55,15 +57,12 @@ public class FloorRenderer implements Disposable{
drawnLayerSet.clear(); drawnLayerSet.clear();
//preliminary layer check //preliminary layer check
for(int x = -crangex; x <= crangex; x++){ for(int x = minx; x <= maxx; x++){
for(int y = -crangey; y <= crangey; y++){ for(int y = miny; y <= maxy; y++){
int worldx = camx + x;
int worldy = camy + y;
if(!Structs.inBounds(worldx, worldy, cache)) if(!Structs.inBounds(x, y, cache)) continue;
continue;
int[] chunk = cache[worldx][worldy]; int[] chunk = cache[x][y];
//loop through all layers, and add layer index if it exists //loop through all layers, and add layer index if it exists
for(int i = 0; i < layers; i++){ for(int i = 0; i < layers; i++){

View File

@@ -1,3 +1,3 @@
org.gradle.daemon=true org.gradle.daemon=true
org.gradle.jvmargs=-Xms256m -Xmx1024m org.gradle.jvmargs=-Xms256m -Xmx1024m
archash=363054f79b8c38a279c261677bd008392926f286 archash=13b82d76b623e9c6492f3005adc17babad5cb9bf