mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-01-10 07:07:03 +07:00
Messed up rendering some more
This commit is contained in:
parent
622f0d9355
commit
bfcce4f7ab
BIN
core/assets-raw/sprites/blocks/environment/grass.png
Normal file
BIN
core/assets-raw/sprites/blocks/environment/grass.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 682 B |
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Before Width: | Height: | Size: 104 KiB After Width: | Height: | Size: 106 KiB |
@ -1,7 +1,7 @@
|
||||
#Autogenerated file. Do not modify.
|
||||
#Tue Apr 17 22:18:27 EDT 2018
|
||||
#Tue Apr 17 23:51:39 EDT 2018
|
||||
version=release
|
||||
androidBuildCode=962
|
||||
androidBuildCode=977
|
||||
name=Mindustry
|
||||
code=3.5
|
||||
build=custom build
|
||||
|
@ -105,7 +105,7 @@ public class BlockRenderer{
|
||||
Draw.color();
|
||||
|
||||
Graphics.end();
|
||||
floorRenderer.drawCache(DrawLayer.walls, crangex, crangey);
|
||||
//floorRenderer.drawCache(DrawLayer.walls, crangex, crangey);
|
||||
Graphics.begin();
|
||||
|
||||
Arrays.sort(requests.items, 0, requestidx);
|
||||
|
@ -1,92 +1,38 @@
|
||||
package io.anuke.mindustry.graphics;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.GL20;
|
||||
import com.badlogic.gdx.graphics.OrthographicCamera;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import com.badlogic.gdx.utils.NumberUtils;
|
||||
import com.badlogic.gdx.utils.async.AsyncExecutor;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.core.Core;
|
||||
import io.anuke.ucore.core.Graphics;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.graphics.CacheBatch;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
import io.anuke.ucore.graphics.Lines;
|
||||
import io.anuke.ucore.util.Log;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
import static io.anuke.ucore.core.Core.camera;
|
||||
import static io.anuke.mindustry.Vars.tilesize;
|
||||
import static io.anuke.mindustry.Vars.world;
|
||||
|
||||
public class FloorRenderer {
|
||||
private final static int vsize = 5;
|
||||
private final static int chunksize = 32;
|
||||
|
||||
private int[][][] cache;
|
||||
private CacheBatch cbatch;
|
||||
|
||||
public FloorRenderer(){
|
||||
|
||||
}
|
||||
private AsyncExecutor executor = new AsyncExecutor(4);
|
||||
private Chunk[][] cache;
|
||||
|
||||
public void drawFloor(){
|
||||
int chunksx = world.width() / chunksize, chunksy = world.height() / chunksize;
|
||||
|
||||
//render the entire map
|
||||
if(cache == null || cache.length != chunksx || cache[0].length != chunksy){
|
||||
cache = new int[chunksx][chunksy][DrawLayer.values().length];
|
||||
|
||||
Timers.markNs();
|
||||
|
||||
for(DrawLayer layer : DrawLayer.values()){
|
||||
for(int x = 0; x < chunksx; x++){
|
||||
for(int y = 0; y < chunksy; y++){
|
||||
cacheChunk(x, y, layer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Log.info("CACHING ELAPSED: {0}", Timers.elapsedNs());
|
||||
cache = new Chunk[chunksx][chunksy];
|
||||
}
|
||||
|
||||
OrthographicCamera camera = Core.camera;
|
||||
|
||||
if(Graphics.drawing()) Graphics.end();
|
||||
|
||||
int crangex = (int)(camera.viewportWidth * camera.zoom / (chunksize * tilesize))+1;
|
||||
int crangey = (int)(camera.viewportHeight * camera.zoom / (chunksize * tilesize))+1;
|
||||
|
||||
DrawLayer[] layers = DrawLayer.values();
|
||||
|
||||
for(int i = 0; i < layers.length - 1; i ++) {
|
||||
drawCache(layers[i], crangex, crangey);
|
||||
}
|
||||
|
||||
Graphics.begin();
|
||||
|
||||
Draw.reset();
|
||||
|
||||
if(debug && debugChunks){
|
||||
Draw.color(Color.YELLOW);
|
||||
Lines.stroke(1f);
|
||||
for(int x = -crangex; x <= crangex; x++){
|
||||
for(int y = -crangey; y <= crangey; y++){
|
||||
int worldx = Mathf.scl(camera.position.x, chunksize * tilesize) + x;
|
||||
int worldy = Mathf.scl(camera.position.y, chunksize * tilesize) + y;
|
||||
|
||||
if(!Mathf.inBounds(worldx, worldy, cache))
|
||||
continue;
|
||||
Lines.rect(worldx * chunksize * tilesize, worldy * chunksize * tilesize, chunksize * tilesize, chunksize * tilesize);
|
||||
}
|
||||
}
|
||||
Draw.reset();
|
||||
}
|
||||
}
|
||||
|
||||
void drawCache(DrawLayer layer, int crangex, int crangey){
|
||||
|
||||
Gdx.gl.glEnable(GL20.GL_BLEND);
|
||||
|
||||
layer.begin(cbatch);
|
||||
|
||||
for(int x = -crangex; x <= crangex; x++){
|
||||
for(int y = -crangey; y <= crangey; y++){
|
||||
int worldx = Mathf.scl(camera.position.x, chunksize * tilesize) + x;
|
||||
@ -95,50 +41,136 @@ public class FloorRenderer {
|
||||
if(!Mathf.inBounds(worldx, worldy, cache))
|
||||
continue;
|
||||
|
||||
cbatch.drawCache(cache[worldx][worldy][layer.ordinal()]);
|
||||
fillChunk(worldx * chunksize * tilesize, worldy * chunksize * tilesize);
|
||||
|
||||
if(cache[worldx][worldy] == null){
|
||||
cache[worldx][worldy] = new Chunk();
|
||||
executor.submit(() -> cacheChunk(worldx, worldy));
|
||||
continue;
|
||||
}
|
||||
|
||||
Chunk chunk = cache[worldx][worldy];
|
||||
|
||||
if(!chunk.rendered){
|
||||
continue;
|
||||
}
|
||||
|
||||
Core.batch.draw(Core.atlas.getTextures().first(), chunk.vertices, 0, chunk.length);
|
||||
}
|
||||
}
|
||||
|
||||
layer.end(cbatch);
|
||||
}
|
||||
|
||||
void cacheChunk(int cx, int cy, DrawLayer layer){
|
||||
if(cbatch == null){
|
||||
createBatch();
|
||||
}
|
||||
private void fillChunk(float x, float y){
|
||||
Draw.color(Color.GRAY);
|
||||
Draw.crect("white", x, y, chunksize * tilesize, chunksize * tilesize);
|
||||
Draw.color();
|
||||
}
|
||||
|
||||
cbatch.begin();
|
||||
Graphics.useBatch(cbatch);
|
||||
private Chunk cacheChunk(int cx, int cy){
|
||||
Chunk chunk = cache[cx][cy];
|
||||
chunk.vertices = new float[chunksize*chunksize*vsize * 4*6];
|
||||
|
||||
int idx = 0;
|
||||
float[] vertices = chunk.vertices;
|
||||
float color = NumberUtils.intToFloatColor(Color.WHITE.toIntBits());
|
||||
TextureRegion region = new TextureRegion(Core.atlas.getTextures().first());
|
||||
|
||||
for(int tilex = cx * chunksize; tilex < (cx + 1) * chunksize; tilex++){
|
||||
for(int tiley = cy * chunksize; tiley < (cy + 1) * chunksize; tiley++){
|
||||
Tile tile = world.tile(tilex, tiley);
|
||||
if(tile == null) continue;
|
||||
|
||||
if(tile.floor().drawLayer == layer && tile.block().drawLayer != DrawLayer.walls){
|
||||
tile.floor().draw(tile);
|
||||
}else if(tile.floor().drawLayer.ordinal() < layer.ordinal() && tile.block().drawLayer != DrawLayer.walls){
|
||||
tile.floor().drawNonLayer(tile);
|
||||
}
|
||||
Block floor = tile.floor();
|
||||
if(!Draw.hasRegion(floor.name())) continue;
|
||||
|
||||
if(tile.block().drawLayer == layer && layer == DrawLayer.walls){
|
||||
tile.block().draw(tile);
|
||||
TextureRegion base = Draw.region(floor.name());
|
||||
|
||||
set(base, region, 1 + Mathf.random(1), 1 + Mathf.random(1));
|
||||
|
||||
idx = draw(vertices, idx, region, tile.worldx(), tile.worldy(), color);
|
||||
|
||||
for(int dx = -1; dx <= 1; dx ++) {
|
||||
for (int dy = -1; dy <= 1; dy++) {
|
||||
|
||||
if (dx == 0 && dy == 0) continue;
|
||||
|
||||
Tile other = world.tile(tile.x + dx, tile.y + dy);
|
||||
|
||||
if (other == null) continue;
|
||||
|
||||
Block of = other.floor();
|
||||
|
||||
if(of.id < floor.id){
|
||||
float ox = (dx == 0 ? Mathf.range(0.5f) : 0);
|
||||
float oy = (dy == 0 ? Mathf.range(0.5f) : 0);
|
||||
set(base, region, (int)(1.5f + 2f*dx + ox), (int)(2f - 2f*dy + oy));
|
||||
|
||||
idx = draw(vertices, idx, region,
|
||||
tile.worldx() + dx * tilesize,
|
||||
tile.worldy() + dy * tilesize, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Graphics.popBatch();
|
||||
cbatch.end();
|
||||
cache[cx][cy][layer.ordinal()] = cbatch.getLastCache();
|
||||
|
||||
chunk.length = idx;
|
||||
chunk.rendered = true;
|
||||
return chunk;
|
||||
}
|
||||
|
||||
private void set(TextureRegion base, TextureRegion region, int x, int y){
|
||||
x = Mathf.clamp(x, 0, 3);
|
||||
y = Mathf.clamp(y, 0, 3);
|
||||
region.setRegion(base.getRegionX() + x *8, base.getRegionY() + y *8, 8, 8);
|
||||
}
|
||||
|
||||
private int draw(float[] vertices, int idx, TextureRegion region, float x, float y, float color){
|
||||
x -= tilesize/2f;
|
||||
y -= tilesize/2f;
|
||||
float width = tilesize, height = tilesize;
|
||||
|
||||
final float fx2 = x + width;
|
||||
final float fy2 = y + height;
|
||||
final float u = region.getU();
|
||||
final float v = region.getV2();
|
||||
final float u2 = region.getU2();
|
||||
final float v2 = region.getV();
|
||||
|
||||
vertices[idx ++] = x;
|
||||
vertices[idx ++] = y;
|
||||
vertices[idx ++] = color;
|
||||
vertices[idx ++] = u;
|
||||
vertices[idx ++] = v;
|
||||
|
||||
vertices[idx ++] = x;
|
||||
vertices[idx ++] = fy2;
|
||||
vertices[idx ++] = color;
|
||||
vertices[idx ++] = u;
|
||||
vertices[idx ++] = v2;
|
||||
|
||||
vertices[idx ++] = fx2;
|
||||
vertices[idx ++] = fy2;
|
||||
vertices[idx ++] = color;
|
||||
vertices[idx ++] = u2;
|
||||
vertices[idx ++] = v2;
|
||||
|
||||
vertices[idx ++] = fx2;
|
||||
vertices[idx ++] = y;
|
||||
vertices[idx ++] = color;
|
||||
vertices[idx ++] = u2;
|
||||
vertices[idx ++] = v;
|
||||
|
||||
return idx;
|
||||
}
|
||||
|
||||
private class Chunk{
|
||||
float[] vertices;
|
||||
boolean rendered;
|
||||
int length;
|
||||
}
|
||||
|
||||
public void clearTiles(){
|
||||
cache = null;
|
||||
createBatch();
|
||||
}
|
||||
|
||||
private void createBatch(){
|
||||
if(cbatch != null)
|
||||
cbatch.dispose();
|
||||
cbatch = new CacheBatch(world.width() * world.height() * 4);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user