Add new more efficient block rendering system
This commit is contained in:
@@ -14,11 +14,11 @@ import io.anuke.mindustry.Mindustry;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.entities.*;
|
||||
import io.anuke.mindustry.entities.effect.Fx;
|
||||
import io.anuke.mindustry.entities.effect.Shield;
|
||||
import io.anuke.mindustry.entities.enemies.Enemy;
|
||||
import io.anuke.mindustry.entities.enemies.FortressEnemy;
|
||||
import io.anuke.mindustry.entities.enemies.HealerEnemy;
|
||||
import io.anuke.mindustry.graphics.Fx;
|
||||
import io.anuke.mindustry.input.AndroidInput;
|
||||
import io.anuke.mindustry.input.DesktopInput;
|
||||
import io.anuke.mindustry.input.InputHandler;
|
||||
|
||||
@@ -4,8 +4,9 @@ import static io.anuke.mindustry.Vars.*;
|
||||
import static io.anuke.ucore.core.Core.*;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.*;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.Pixmap.Format;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.glutils.FrameBuffer;
|
||||
import com.badlogic.gdx.math.Rectangle;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
@@ -14,20 +15,18 @@ import com.badlogic.gdx.utils.FloatArray;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.entities.effect.Shaders;
|
||||
import io.anuke.mindustry.entities.enemies.Enemy;
|
||||
import io.anuke.mindustry.graphics.BlockRenderer;
|
||||
import io.anuke.mindustry.graphics.Shaders;
|
||||
import io.anuke.mindustry.input.PlaceMode;
|
||||
import io.anuke.mindustry.world.Layer;
|
||||
import io.anuke.mindustry.world.SpawnPoint;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.Blocks;
|
||||
import io.anuke.mindustry.world.blocks.ProductionBlocks;
|
||||
import io.anuke.mindustry.world.blocks.types.StaticBlock;
|
||||
import io.anuke.ucore.core.*;
|
||||
import io.anuke.ucore.entities.DestructibleEntity;
|
||||
import io.anuke.ucore.entities.EffectEntity;
|
||||
import io.anuke.ucore.entities.Entities;
|
||||
import io.anuke.ucore.graphics.CacheBatch;
|
||||
import io.anuke.ucore.graphics.Hue;
|
||||
import io.anuke.ucore.graphics.Surface;
|
||||
import io.anuke.ucore.modules.RendererModule;
|
||||
@@ -43,9 +42,8 @@ public class Renderer extends RendererModule{
|
||||
public Surface shadowSurface, shieldSurface, indicatorSurface;
|
||||
|
||||
private int targetscale = baseCameraScale;
|
||||
private int[][][] cache;
|
||||
private FloatArray shieldHits = new FloatArray();
|
||||
private CacheBatch cbatch;
|
||||
private BlockRenderer blocks = new BlockRenderer();
|
||||
|
||||
public Renderer() {
|
||||
Core.cameraScale = baseCameraScale;
|
||||
@@ -210,8 +208,9 @@ public class Renderer extends RendererModule{
|
||||
Graphics.surface(shieldSurface);
|
||||
Graphics.surface();
|
||||
|
||||
drawFloor();
|
||||
drawBlocks(false);
|
||||
blocks.drawFloor();
|
||||
blocks.processBlocks();
|
||||
blocks.drawBlocks(false);
|
||||
|
||||
Graphics.shader(Shaders.outline, false);
|
||||
Entities.draw(control.enemyGroup);
|
||||
@@ -219,6 +218,8 @@ public class Renderer extends RendererModule{
|
||||
|
||||
Entities.draw(Entities.defaultGroup());
|
||||
|
||||
blocks.drawBlocks(true);
|
||||
|
||||
Entities.draw(control.bulletGroup);
|
||||
|
||||
drawShield();
|
||||
@@ -228,7 +229,6 @@ public class Renderer extends RendererModule{
|
||||
if(Settings.getBool("indicators") && Vars.showUI){
|
||||
drawEnemyMarkers();
|
||||
}
|
||||
|
||||
|
||||
if(pixelate)
|
||||
Graphics.flushSurface();
|
||||
@@ -242,6 +242,10 @@ public class Renderer extends RendererModule{
|
||||
control.input.resetCursor();
|
||||
camera.position.set(player.x, player.y, 0);
|
||||
}
|
||||
|
||||
public void clearTiles(){
|
||||
blocks.clearTiles();
|
||||
}
|
||||
|
||||
void drawEnemyMarkers(){
|
||||
Graphics.surface(indicatorSurface);
|
||||
@@ -316,188 +320,6 @@ public class Renderer extends RendererModule{
|
||||
shieldHits.addAll(x, y, 0f);
|
||||
}
|
||||
|
||||
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][2];
|
||||
|
||||
for(int x = 0; x < chunksx; x++){
|
||||
for(int y = 0; y < chunksy; y++){
|
||||
cacheChunk(x, y, true);
|
||||
cacheChunk(x, y, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
OrthographicCamera camera = Core.camera;
|
||||
|
||||
Graphics.end();
|
||||
|
||||
int crangex = (int)(camera.viewportWidth * camera.zoom / (chunksize * tilesize))+1;
|
||||
int crangey = (int)(camera.viewportHeight * camera.zoom / (chunksize * tilesize))+1;
|
||||
|
||||
drawCache(0, crangex, crangey);
|
||||
|
||||
Graphics.begin();
|
||||
|
||||
Draw.reset();
|
||||
|
||||
if(Vars.showPaths && Vars.debug){
|
||||
drawPaths();
|
||||
}
|
||||
|
||||
if(Vars.debug && Vars.debugChunks){
|
||||
Draw.color(Color.YELLOW);
|
||||
Draw.thick(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;
|
||||
Draw.linerect(worldx * chunksize * tilesize, worldy * chunksize * tilesize, chunksize * tilesize, chunksize * tilesize);
|
||||
}
|
||||
}
|
||||
Draw.reset();
|
||||
}
|
||||
}
|
||||
|
||||
void drawBlocks(boolean top){
|
||||
int crangex = (int) (camera.viewportWidth / (chunksize * tilesize)) + 1;
|
||||
int crangey = (int) (camera.viewportHeight / (chunksize * tilesize)) + 1;
|
||||
|
||||
int rangex = (int) (camera.viewportWidth * camera.zoom / tilesize / 2)+2;
|
||||
int rangey = (int) (camera.viewportHeight * camera.zoom / tilesize / 2)+2;
|
||||
|
||||
boolean noshadows = Settings.getBool("noshadows");
|
||||
|
||||
boolean drawTiles = Settings.getBool("drawblocks");
|
||||
|
||||
if(!drawTiles) return;
|
||||
|
||||
Layer[] layers = Layer.values();
|
||||
|
||||
int start = (top ? 4 : (noshadows ? 1 : 0));
|
||||
int end = (top ? 4 + layers.length-1 : 4);
|
||||
|
||||
//0 = shadows
|
||||
//1 = cache blocks
|
||||
//2 = normal blocks
|
||||
//3+ = layers
|
||||
for(int l = start; l < end; l++){
|
||||
if(l == 0){
|
||||
Graphics.surface(shadowSurface);
|
||||
}
|
||||
|
||||
Layer layer = l >= 3 ? layers[l - 3] : null;
|
||||
|
||||
boolean expand = layer == Layer.power;
|
||||
int expandr = (expand ? 3 : 0);
|
||||
|
||||
if(l == 1){
|
||||
Graphics.end();
|
||||
drawCache(1, crangex, crangey);
|
||||
Graphics.begin();
|
||||
}else{
|
||||
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);
|
||||
|
||||
if(world.tile(worldx, worldy) != null){
|
||||
Tile tile = world.tile(worldx, worldy);
|
||||
if(l == 0 && !expanded){
|
||||
if(tile.block() != Blocks.air && world.isAccessible(worldx, worldy)){
|
||||
tile.block().drawShadow(tile);
|
||||
}
|
||||
}else if(!(tile.block() instanceof StaticBlock) &&
|
||||
(!expanded || tile.block().expanded)){
|
||||
if(l == 2){
|
||||
tile.block().draw(tile);
|
||||
}else{
|
||||
if(tile.block().layer == layer)
|
||||
tile.block().drawLayer(tile);
|
||||
|
||||
if(tile.block().layer2 == layer)
|
||||
tile.block().drawLayer2(tile);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(l == 0){
|
||||
Draw.color(0, 0, 0, 0.15f);
|
||||
Graphics.flushSurface();
|
||||
Draw.color();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void drawCache(int layer, int crangex, int crangey){
|
||||
Gdx.gl.glEnable(GL20.GL_BLEND);
|
||||
|
||||
cbatch.setProjectionMatrix(Core.camera.combined);
|
||||
cbatch.beginDraw();
|
||||
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;
|
||||
|
||||
cbatch.drawCache(cache[worldx][worldy][layer]);
|
||||
}
|
||||
}
|
||||
|
||||
cbatch.endDraw();
|
||||
}
|
||||
|
||||
void cacheChunk(int cx, int cy, boolean floor){
|
||||
cbatch.begin();
|
||||
Graphics.useBatch(cbatch);
|
||||
|
||||
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(floor){
|
||||
tile.floor().draw(tile);
|
||||
}else if(tile.block() instanceof StaticBlock){
|
||||
tile.block().draw(tile);
|
||||
}
|
||||
}
|
||||
}
|
||||
Graphics.popBatch();
|
||||
cbatch.end();
|
||||
cache[cx][cy][floor ? 0 : 1] = cbatch.getLastCache();
|
||||
}
|
||||
|
||||
public void clearTiles(){
|
||||
cache = null;
|
||||
if(cbatch != null)
|
||||
cbatch.dispose();
|
||||
cbatch = new CacheBatch(Vars.world.width() * Vars.world.height() * 3);
|
||||
}
|
||||
|
||||
void drawPaths(){
|
||||
Draw.color(Color.RED);
|
||||
for(SpawnPoint point : control.spawnpoints){
|
||||
if(point.pathTiles != null){
|
||||
for(int i = 1; i < point.pathTiles.length; i ++){
|
||||
Draw.line(point.pathTiles[i-1].worldx(), point.pathTiles[i-1].worldy(),
|
||||
point.pathTiles[i].worldx(), point.pathTiles[i].worldy());
|
||||
Draw.circle(point.pathTiles[i-1].worldx(), point.pathTiles[i-1].worldy(), 6f);
|
||||
}
|
||||
}
|
||||
}
|
||||
Draw.reset();
|
||||
}
|
||||
|
||||
void drawOverlay(){
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@ import com.badlogic.gdx.graphics.Color;
|
||||
|
||||
import io.anuke.mindustry.entities.effect.DamageArea;
|
||||
import io.anuke.mindustry.entities.effect.EMP;
|
||||
import io.anuke.mindustry.entities.effect.Fx;
|
||||
import io.anuke.mindustry.entities.enemies.Enemy;
|
||||
import io.anuke.mindustry.graphics.Fx;
|
||||
import io.anuke.ucore.core.Draw;
|
||||
import io.anuke.ucore.core.Effects;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
|
||||
@@ -5,7 +5,7 @@ import static io.anuke.mindustry.Vars.*;
|
||||
import com.badlogic.gdx.Input.Buttons;
|
||||
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.entities.effect.Fx;
|
||||
import io.anuke.mindustry.graphics.Fx;
|
||||
import io.anuke.mindustry.input.PlaceMode;
|
||||
import io.anuke.mindustry.resource.Mech;
|
||||
import io.anuke.mindustry.resource.Recipe;
|
||||
|
||||
@@ -5,8 +5,8 @@ import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.entities.effect.Fx;
|
||||
import io.anuke.mindustry.entities.enemies.Enemy;
|
||||
import io.anuke.mindustry.graphics.Fx;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.graphics.Fx;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.types.PowerAcceptor;
|
||||
import io.anuke.ucore.core.Draw;
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.badlogic.gdx.utils.ObjectSet;
|
||||
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.entities.enemies.Enemy;
|
||||
import io.anuke.mindustry.graphics.Fx;
|
||||
import io.anuke.ucore.core.Draw;
|
||||
import io.anuke.ucore.core.Effects;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
|
||||
@@ -6,8 +6,8 @@ import com.badlogic.gdx.utils.reflect.ClassReflection;
|
||||
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.entities.*;
|
||||
import io.anuke.mindustry.entities.effect.Fx;
|
||||
import io.anuke.mindustry.entities.effect.Shaders;
|
||||
import io.anuke.mindustry.graphics.Fx;
|
||||
import io.anuke.mindustry.graphics.Shaders;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.core.*;
|
||||
import io.anuke.ucore.entities.*;
|
||||
@@ -238,7 +238,7 @@ public class Enemy extends DestructibleEntity{
|
||||
xvelocity = (x - lastx) / Timers.delta();
|
||||
yvelocity = (y - lasty) / Timers.delta();
|
||||
|
||||
float minv = 0.09f;
|
||||
float minv = 0.07f;
|
||||
|
||||
if(xvelocity < minv && yvelocity < minv && node > 0 && target == null){
|
||||
idletime += Timers.delta();
|
||||
|
||||
@@ -2,7 +2,7 @@ package io.anuke.mindustry.entities.enemies;
|
||||
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.entities.BulletType;
|
||||
import io.anuke.mindustry.entities.effect.Fx;
|
||||
import io.anuke.mindustry.graphics.Fx;
|
||||
import io.anuke.ucore.core.Effects;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.util.Angles;
|
||||
|
||||
@@ -5,8 +5,8 @@ import com.badlogic.gdx.math.MathUtils;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.entities.Bullet;
|
||||
import io.anuke.mindustry.entities.BulletType;
|
||||
import io.anuke.mindustry.entities.effect.Fx;
|
||||
import io.anuke.mindustry.entities.effect.Shaders;
|
||||
import io.anuke.mindustry.graphics.Fx;
|
||||
import io.anuke.mindustry.graphics.Shaders;
|
||||
import io.anuke.ucore.core.*;
|
||||
import io.anuke.ucore.entities.Entities;
|
||||
import io.anuke.ucore.graphics.Hue;
|
||||
|
||||
335
core/src/io/anuke/mindustry/graphics/BlockRenderer.java
Normal file
335
core/src/io/anuke/mindustry/graphics/BlockRenderer.java
Normal file
@@ -0,0 +1,335 @@
|
||||
package io.anuke.mindustry.graphics;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
import static io.anuke.ucore.core.Core.camera;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
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.utils.Array;
|
||||
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.core.GameState;
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.world.*;
|
||||
import io.anuke.mindustry.world.blocks.Blocks;
|
||||
import io.anuke.mindustry.world.blocks.types.StaticBlock;
|
||||
import io.anuke.ucore.core.Core;
|
||||
import io.anuke.ucore.core.Draw;
|
||||
import io.anuke.ucore.core.Graphics;
|
||||
import io.anuke.ucore.graphics.CacheBatch;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
public class BlockRenderer{
|
||||
private final static int chunksize = 32;
|
||||
private final static int initialRequests = 32*32;
|
||||
|
||||
private int[][][] cache;
|
||||
private CacheBatch cbatch;
|
||||
|
||||
private Array<BlockRequest> requests = new Array<BlockRequest>(initialRequests);
|
||||
private int requestidx = 0;
|
||||
private int iterateidx = 0;
|
||||
|
||||
public BlockRenderer(){
|
||||
for(int i = 0; i < requests.size; i ++){
|
||||
requests.set(i, new BlockRequest());
|
||||
}
|
||||
}
|
||||
|
||||
private class BlockRequest implements Comparable<BlockRequest>{
|
||||
Tile tile;
|
||||
Layer layer;
|
||||
|
||||
@Override
|
||||
public int compareTo(BlockRequest other){
|
||||
return layer.compareTo(other.layer);
|
||||
}
|
||||
}
|
||||
|
||||
/**Process all blocks to draw, simultaneously drawing block shadows and static blocks.*/
|
||||
public void processBlocks(){
|
||||
requestidx = 0;
|
||||
|
||||
int crangex = (int) (camera.viewportWidth / (chunksize * tilesize)) + 1;
|
||||
int crangey = (int) (camera.viewportHeight / (chunksize * tilesize)) + 1;
|
||||
|
||||
int rangex = (int) (camera.viewportWidth * camera.zoom / tilesize / 2)+2;
|
||||
int rangey = (int) (camera.viewportHeight * camera.zoom / tilesize / 2)+2;
|
||||
|
||||
int expandr = 3;
|
||||
|
||||
Graphics.surface(renderer.shadowSurface);
|
||||
|
||||
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);
|
||||
|
||||
Tile tile = world.tile(worldx, worldy);
|
||||
|
||||
if(tile != null){
|
||||
Block block = tile.block();
|
||||
|
||||
if(!expanded && block != Blocks.air && world.isAccessible(worldx, worldy)){
|
||||
block.drawShadow(tile);
|
||||
}
|
||||
|
||||
if(!(block instanceof StaticBlock)){
|
||||
if(block == Blocks.air){
|
||||
if(!GameState.is(State.paused)) tile.floor().update(tile);
|
||||
}else{
|
||||
|
||||
if(!expanded){
|
||||
addRequest(tile, Layer.block);
|
||||
}
|
||||
|
||||
if(block.expanded || !expanded){
|
||||
if(block.layer != null){
|
||||
addRequest(tile, block.layer);
|
||||
}
|
||||
|
||||
if(block.layer2 != null){
|
||||
addRequest(tile, block.layer2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Draw.color(0, 0, 0, 0.15f);
|
||||
Graphics.flushSurface();
|
||||
Draw.color();
|
||||
|
||||
Graphics.end();
|
||||
drawCache(1, crangex, crangey);
|
||||
Graphics.begin();
|
||||
|
||||
Arrays.sort(requests.items, 0, requestidx);
|
||||
iterateidx = 0;
|
||||
}
|
||||
|
||||
public void drawBlocks(boolean top){
|
||||
Layer stopAt = top ? Layer.laser : Layer.overlay;
|
||||
|
||||
for(; iterateidx < requests.size; iterateidx ++){
|
||||
if(iterateidx < requests.size - 1 && requests.get(iterateidx).layer.ordinal() > stopAt.ordinal()){
|
||||
break;
|
||||
}
|
||||
|
||||
BlockRequest req = requests.get(iterateidx);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addRequest(Tile tile, Layer layer){
|
||||
if(requestidx >= requests.size){
|
||||
requests.add(new BlockRequest());
|
||||
}
|
||||
BlockRequest r = requests.get(requestidx);
|
||||
if(r == null){
|
||||
requests.set(requestidx, r = new BlockRequest());
|
||||
}
|
||||
r.tile = tile;
|
||||
r.layer = layer;
|
||||
requestidx ++;
|
||||
}
|
||||
|
||||
/*
|
||||
public void drawBlocks(boolean top){
|
||||
int crangex = (int) (camera.viewportWidth / (chunksize * tilesize)) + 1;
|
||||
int crangey = (int) (camera.viewportHeight / (chunksize * tilesize)) + 1;
|
||||
|
||||
int rangex = (int) (camera.viewportWidth * camera.zoom / tilesize / 2)+2;
|
||||
int rangey = (int) (camera.viewportHeight * camera.zoom / tilesize / 2)+2;
|
||||
|
||||
boolean noshadows = Settings.getBool("noshadows");
|
||||
|
||||
boolean drawTiles = Settings.getBool("drawblocks");
|
||||
|
||||
if(!drawTiles) return;
|
||||
|
||||
Layer[] layers = Layer.values();
|
||||
|
||||
int start = (top ? 4 : (noshadows ? 1 : 0));
|
||||
int end = (top ? 4 + layers.length-1 : 4);
|
||||
|
||||
//0 = shadows
|
||||
//1 = cache blocks
|
||||
//2 = normal blocks
|
||||
//3+ = layers
|
||||
for(int l = start; l < end; l++){
|
||||
if(l == 0){
|
||||
Graphics.surface(renderer.shadowSurface);
|
||||
}
|
||||
|
||||
Layer layer = l >= 3 ? layers[l - 3] : null;
|
||||
|
||||
boolean expand = layer == Layer.power;
|
||||
int expandr = (expand ? 3 : 0);
|
||||
|
||||
if(l == 1){
|
||||
Graphics.end();
|
||||
drawCache(1, crangex, crangey);
|
||||
Graphics.begin();
|
||||
}else{
|
||||
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);
|
||||
|
||||
if(world.tile(worldx, worldy) != null){
|
||||
Tile tile = world.tile(worldx, worldy);
|
||||
if(l == 0 && !expanded){
|
||||
if(tile.block() != Blocks.air && world.isAccessible(worldx, worldy)){
|
||||
tile.block().drawShadow(tile);
|
||||
}
|
||||
}else if(!(tile.block() instanceof StaticBlock) &&
|
||||
(!expanded || tile.block().expanded)){
|
||||
if(l == 2){
|
||||
tile.block().draw(tile);
|
||||
}else{
|
||||
if(tile.block().layer == layer)
|
||||
tile.block().drawLayer(tile);
|
||||
|
||||
if(tile.block().layer2 == layer)
|
||||
tile.block().drawLayer2(tile);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(l == 0){
|
||||
Draw.color(0, 0, 0, 0.15f);
|
||||
Graphics.flushSurface();
|
||||
Draw.color();
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
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][2];
|
||||
|
||||
for(int x = 0; x < chunksx; x++){
|
||||
for(int y = 0; y < chunksy; y++){
|
||||
cacheChunk(x, y, true);
|
||||
cacheChunk(x, y, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
OrthographicCamera camera = Core.camera;
|
||||
|
||||
Graphics.end();
|
||||
|
||||
int crangex = (int)(camera.viewportWidth * camera.zoom / (chunksize * tilesize))+1;
|
||||
int crangey = (int)(camera.viewportHeight * camera.zoom / (chunksize * tilesize))+1;
|
||||
|
||||
drawCache(0, crangex, crangey);
|
||||
|
||||
Graphics.begin();
|
||||
|
||||
Draw.reset();
|
||||
|
||||
if(Vars.showPaths && Vars.debug){
|
||||
drawPaths();
|
||||
}
|
||||
|
||||
if(Vars.debug && Vars.debugChunks){
|
||||
Draw.color(Color.YELLOW);
|
||||
Draw.thick(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;
|
||||
Draw.linerect(worldx * chunksize * tilesize, worldy * chunksize * tilesize, chunksize * tilesize, chunksize * tilesize);
|
||||
}
|
||||
}
|
||||
Draw.reset();
|
||||
}
|
||||
}
|
||||
|
||||
void drawPaths(){
|
||||
Draw.color(Color.RED);
|
||||
for(SpawnPoint point : control.getSpawnPoints()){
|
||||
if(point.pathTiles != null){
|
||||
for(int i = 1; i < point.pathTiles.length; i ++){
|
||||
Draw.line(point.pathTiles[i-1].worldx(), point.pathTiles[i-1].worldy(),
|
||||
point.pathTiles[i].worldx(), point.pathTiles[i].worldy());
|
||||
Draw.circle(point.pathTiles[i-1].worldx(), point.pathTiles[i-1].worldy(), 6f);
|
||||
}
|
||||
}
|
||||
}
|
||||
Draw.reset();
|
||||
}
|
||||
|
||||
|
||||
void drawCache(int layer, int crangex, int crangey){
|
||||
Gdx.gl.glEnable(GL20.GL_BLEND);
|
||||
|
||||
cbatch.setProjectionMatrix(Core.camera.combined);
|
||||
cbatch.beginDraw();
|
||||
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;
|
||||
|
||||
cbatch.drawCache(cache[worldx][worldy][layer]);
|
||||
}
|
||||
}
|
||||
|
||||
cbatch.endDraw();
|
||||
}
|
||||
|
||||
void cacheChunk(int cx, int cy, boolean floor){
|
||||
cbatch.begin();
|
||||
Graphics.useBatch(cbatch);
|
||||
|
||||
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(floor){
|
||||
tile.floor().draw(tile);
|
||||
}else if(tile.block() instanceof StaticBlock){
|
||||
tile.block().draw(tile);
|
||||
}
|
||||
}
|
||||
}
|
||||
Graphics.popBatch();
|
||||
cbatch.end();
|
||||
cache[cx][cy][floor ? 0 : 1] = cbatch.getLastCache();
|
||||
}
|
||||
|
||||
public void clearTiles(){
|
||||
cache = null;
|
||||
if(cbatch != null)
|
||||
cbatch.dispose();
|
||||
cbatch = new CacheBatch(Vars.world.width() * Vars.world.height() * 3);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package io.anuke.mindustry.entities.effect;
|
||||
package io.anuke.mindustry.graphics;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.Colors;
|
||||
@@ -1,4 +1,4 @@
|
||||
package io.anuke.mindustry.entities.effect;
|
||||
package io.anuke.mindustry.graphics;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.utils.FloatArray;
|
||||
@@ -9,7 +9,7 @@ import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.entities.effect.Fx;
|
||||
import io.anuke.mindustry.graphics.Fx;
|
||||
import io.anuke.mindustry.resource.ItemStack;
|
||||
import io.anuke.mindustry.resource.Recipe;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.badlogic.gdx.utils.IntSet;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.ColorMapper;
|
||||
import io.anuke.mindustry.world.ColorMapper.BlockPair;
|
||||
|
||||
public enum EditorTool{
|
||||
pencil{
|
||||
@@ -65,7 +66,9 @@ public enum EditorTool{
|
||||
},
|
||||
pick{
|
||||
public void touched(MapEditor editor, int x, int y){
|
||||
Block block = ColorMapper.get(editor.pixmap().getPixel(x, y)).dominant();
|
||||
BlockPair pair = ColorMapper.get(editor.pixmap().getPixel(x, y));
|
||||
if(pair == null) return;
|
||||
Block block = pair.dominant();
|
||||
editor.setDrawBlock(block);
|
||||
Vars.ui.getEditorDialog().updateSelectedBlock();
|
||||
}
|
||||
|
||||
@@ -43,6 +43,9 @@ public class MapView extends Element implements GestureListener{
|
||||
|
||||
@Override
|
||||
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
|
||||
if(pointer != 0){
|
||||
return false;
|
||||
}
|
||||
GridPoint2 p = project(x, y);
|
||||
lastx = p.x;
|
||||
lasty = p.y;
|
||||
|
||||
@@ -8,7 +8,7 @@ import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.entities.Bullet;
|
||||
import io.anuke.mindustry.entities.BulletType;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.entities.effect.Fx;
|
||||
import io.anuke.mindustry.graphics.Fx;
|
||||
import io.anuke.ucore.core.Effects;
|
||||
import io.anuke.ucore.entities.Entity;
|
||||
import io.anuke.ucore.util.Angles;
|
||||
|
||||
@@ -8,7 +8,7 @@ import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.core.GameState;
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.entities.effect.Fx;
|
||||
import io.anuke.mindustry.graphics.Fx;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.resource.ItemStack;
|
||||
import io.anuke.mindustry.resource.Liquid;
|
||||
@@ -72,9 +72,9 @@ public class Block{
|
||||
/**Max of timers used.*/
|
||||
public int timers = 0;
|
||||
/**Layer to draw extra stuff on.*/
|
||||
public Layer layer = Layer.overlay;
|
||||
public Layer layer = null;
|
||||
/**Extra layer to draw extra extra stuff on.*/
|
||||
public Layer layer2 = Layer.overlay;
|
||||
public Layer layer2 = null;
|
||||
|
||||
public Block(String name) {
|
||||
blocks.add(this);
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package io.anuke.mindustry.world;
|
||||
|
||||
public enum Layer{
|
||||
/**Base block layer.*/
|
||||
block,
|
||||
/**First overlay. Stuff like conveyor items.*/
|
||||
overlay,
|
||||
/**"High" blocks, like turrets.*/
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package io.anuke.mindustry.world.blocks;
|
||||
|
||||
import io.anuke.mindustry.core.GameState;
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.entities.effect.Fx;
|
||||
import io.anuke.mindustry.graphics.Fx;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.resource.ItemStack;
|
||||
import io.anuke.mindustry.resource.Liquid;
|
||||
@@ -21,10 +19,7 @@ public class Blocks{
|
||||
public void drawCache(Tile tile){}
|
||||
|
||||
//update floor blocks for effects, if needed
|
||||
public void draw(Tile tile){
|
||||
if(!GameState.is(State.paused))
|
||||
tile.floor().update(tile);
|
||||
}
|
||||
public void draw(Tile tile){}
|
||||
},
|
||||
|
||||
blockpart = new BlockPart(),
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package io.anuke.mindustry.world.blocks;
|
||||
|
||||
import io.anuke.mindustry.entities.effect.Fx;
|
||||
import io.anuke.mindustry.graphics.Fx;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.blocks.types.Wall;
|
||||
import io.anuke.mindustry.world.blocks.types.defense.*;
|
||||
|
||||
@@ -2,7 +2,7 @@ package io.anuke.mindustry.world.blocks;
|
||||
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.entities.effect.Fx;
|
||||
import io.anuke.mindustry.graphics.Fx;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.resource.Liquid;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
|
||||
@@ -5,8 +5,8 @@ import com.badlogic.gdx.math.Vector2;
|
||||
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.entities.BulletType;
|
||||
import io.anuke.mindustry.entities.effect.Fx;
|
||||
import io.anuke.mindustry.entities.effect.TeslaOrb;
|
||||
import io.anuke.mindustry.graphics.Fx;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
|
||||
@@ -11,7 +11,7 @@ import com.badlogic.gdx.math.Vector2;
|
||||
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.entities.effect.Fx;
|
||||
import io.anuke.mindustry.graphics.Fx;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.types.Configurable;
|
||||
|
||||
@@ -3,8 +3,8 @@ package io.anuke.mindustry.world.blocks.types.defense;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.math.MathUtils;
|
||||
|
||||
import io.anuke.mindustry.entities.effect.Fx;
|
||||
import io.anuke.mindustry.entities.enemies.Enemy;
|
||||
import io.anuke.mindustry.graphics.Fx;
|
||||
import io.anuke.mindustry.world.Layer;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.core.Draw;
|
||||
|
||||
@@ -4,8 +4,8 @@ import com.badlogic.gdx.utils.Array;
|
||||
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.entities.effect.Fx;
|
||||
import io.anuke.mindustry.entities.effect.Shield;
|
||||
import io.anuke.mindustry.graphics.Fx;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.types.PowerBlock;
|
||||
import io.anuke.ucore.core.Effects;
|
||||
|
||||
@@ -12,8 +12,8 @@ import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.entities.Bullet;
|
||||
import io.anuke.mindustry.entities.BulletType;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.entities.effect.Fx;
|
||||
import io.anuke.mindustry.entities.enemies.Enemy;
|
||||
import io.anuke.mindustry.graphics.Fx;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Layer;
|
||||
|
||||
@@ -4,7 +4,7 @@ import java.util.Arrays;
|
||||
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
|
||||
import io.anuke.mindustry.entities.effect.Fx;
|
||||
import io.anuke.mindustry.graphics.Fx;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
|
||||
@@ -3,7 +3,7 @@ package io.anuke.mindustry.world.blocks.types.production;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.entities.effect.Fx;
|
||||
import io.anuke.mindustry.graphics.Fx;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Layer;
|
||||
|
||||
@@ -8,7 +8,7 @@ import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.core.GameState;
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.entities.effect.Fx;
|
||||
import io.anuke.mindustry.graphics.Fx;
|
||||
import io.anuke.mindustry.world.Layer;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.types.PowerAcceptor;
|
||||
|
||||
@@ -5,7 +5,7 @@ import com.badlogic.gdx.utils.Array;
|
||||
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.entities.effect.Fx;
|
||||
import io.anuke.mindustry.graphics.Fx;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.core.Draw;
|
||||
|
||||
@@ -5,7 +5,7 @@ import com.badlogic.gdx.utils.Array;
|
||||
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.entities.effect.Fx;
|
||||
import io.anuke.mindustry.graphics.Fx;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.resource.Liquid;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
|
||||
@@ -8,7 +8,7 @@ import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.entities.effect.Fx;
|
||||
import io.anuke.mindustry.graphics.Fx;
|
||||
import io.anuke.mindustry.resource.Liquid;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.types.LiquidAcceptor;
|
||||
|
||||
@@ -10,7 +10,7 @@ import com.badlogic.gdx.math.Vector2;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.entities.effect.DamageArea;
|
||||
import io.anuke.mindustry.entities.effect.Fx;
|
||||
import io.anuke.mindustry.graphics.Fx;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.resource.Liquid;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
|
||||
Reference in New Issue
Block a user