Add new more efficient block rendering system

This commit is contained in:
Anuken
2017-12-20 17:05:15 -05:00
parent 8cff097d1a
commit 19ae53ae6a
35 changed files with 397 additions and 235 deletions

View 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);
}
}

View File

@@ -0,0 +1,480 @@
package io.anuke.mindustry.graphics;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Colors;
import io.anuke.mindustry.Vars;
import io.anuke.ucore.core.Draw;
import io.anuke.ucore.core.Effects.Effect;
import io.anuke.ucore.graphics.Hue;
import io.anuke.ucore.util.Angles;
import io.anuke.ucore.util.Mathf;
public class Fx{
static Color lightRed = Hue.mix(Color.WHITE, Color.FIREBRICK, 0.1f);
static Color lightOrange = Color.valueOf("f68021");
static Color whiteOrange = Hue.mix(lightOrange, Color.WHITE, 0.6f);
static Color whiteYellow = Hue.mix(Color.YELLOW, Color.WHITE, 0.6f);
public static final Effect
generatorexplosion = new Effect(28, 40f, e -> {
Angles.randLenVectors(e.id, 16, 10f + e.ifract()*8f, (x, y)->{
float size = e.fract()*12f + 1f;
Draw.color(Color.WHITE, lightOrange, e.ifract());
Draw.rect("circle", e.x + x, e.y + y, size, size);
Draw.reset();
});
}),
reactorsmoke = new Effect(17, e -> {
Angles.randLenVectors(e.id, 4, e.ifract()*8f, (x, y)->{
float size = 1f+e.fract()*5f;
Draw.color(Color.LIGHT_GRAY, Color.GRAY, e.ifract());
Draw.rect("circle", e.x + x, e.y + y, size, size);
Draw.reset();
});
}),
nuclearsmoke = new Effect(40, e -> {
Angles.randLenVectors(e.id, 4, e.ifract()*13f, (x, y)->{
float size = e.sfract()*4f;
Draw.color(Color.LIGHT_GRAY, Color.GRAY, e.ifract());
Draw.rect("circle", e.x + x, e.y + y, size, size);
Draw.reset();
});
}),
nuclearcloud = new Effect(90, 200f, e -> {
Angles.randLenVectors(e.id, 10, e.powfract()*90f, (x, y)->{
float size = e.fract()*14f;
Draw.color(Color.LIME, Color.GRAY, e.ifract());
Draw.rect("circle", e.x + x, e.y + y, size, size);
Draw.reset();
});
}),
chainshot = new Effect(9f, e -> {
Draw.color(Color.WHITE, lightOrange, e.ifract());
Draw.thick(e.fract()*4f);
Draw.lineAngle(e.x, e.y, e.rotation, e.fract()*7f);
Draw.thick(e.fract()*2f);
Draw.lineAngle(e.x, e.y, e.rotation, e.fract()*10f);
Draw.reset();
}),
mortarshot = new Effect(10f, e -> {
Draw.color(Color.WHITE, Color.DARK_GRAY, e.ifract());
Draw.thick(e.fract()*6f);
Draw.lineAngle(e.x, e.y, e.rotation, e.fract()*10f);
Draw.thick(e.fract()*5f);
Draw.lineAngle(e.x, e.y, e.rotation, e.fract()*14f);
Draw.thick(e.fract()*1f);
Draw.lineAngle(e.x, e.y, e.rotation, e.fract()*16f);
Draw.reset();
}),
railshot = new Effect(9f, e -> {
Draw.color(Color.WHITE, Color.DARK_GRAY, e.ifract());
Draw.thick(e.fract()*5f);
Draw.lineAngle(e.x, e.y, e.rotation, e.fract()*8f);
Draw.thick(e.fract()*4f);
Draw.lineAngle(e.x, e.y, e.rotation, e.fract()*12f);
Draw.thick(e.fract()*1f);
Draw.lineAngle(e.x, e.y, e.rotation, e.fract()*14f);
Draw.reset();
}),
titanshot = new Effect(12f, e -> {
Draw.color(Color.WHITE, lightOrange, e.ifract());
Draw.thick(e.fract()*7f);
Draw.lineAngle(e.x, e.y, e.rotation, e.fract()*12f);
Draw.thick(e.fract()*4f);
Draw.lineAngle(e.x, e.y, e.rotation, e.fract()*16f);
Draw.thick(e.fract()*2f);
Draw.lineAngle(e.x, e.y, e.rotation, e.fract()*18f);
Draw.reset();
}),
largeCannonShot = new Effect(11f, e -> {
Draw.color(Color.WHITE, whiteYellow, e.ifract());
Draw.thick(e.fract()*6f);
Draw.lineAngle(e.x, e.y, e.rotation, e.fract()*12f);
Draw.thick(e.fract()*3f);
Draw.lineAngle(e.x, e.y, e.rotation, e.fract()*16f);
Draw.thick(e.fract()*1f);
Draw.lineAngle(e.x, e.y, e.rotation, e.fract()*18f);
Draw.reset();
}),
shockwave = new Effect(10f, 80f, e -> {
Draw.color(Color.WHITE, Color.LIGHT_GRAY, e.ifract());
Draw.thick(e.fract()*2f + 0.2f);
Draw.circle(e.x, e.y, e.ifract()*28f);
Draw.reset();
}),
nuclearShockwave = new Effect(10f, 200f, e -> {
Draw.color(Color.WHITE, Color.LIGHT_GRAY, e.ifract());
Draw.thick(e.fract()*3f + 0.2f);
Draw.polygon(40, e.x, e.y, e.ifract()*140f);
Draw.reset();
}),
shockwaveSmall = new Effect(10f, e -> {
Draw.color(Color.WHITE, Color.LIGHT_GRAY, e.ifract());
Draw.thick(e.fract()*2f + 0.1f);
Draw.circle(e.x, e.y, e.ifract()*15f);
Draw.reset();
}),
empshockwave = new Effect(7f, e -> {
Draw.color(Color.WHITE, Color.SKY, e.ifract());
Draw.thick(e.fract()*2f);
Draw.circle(e.x, e.y, e.ifract()*40f);
Draw.reset();
}),
empspark = new Effect(13, e -> {
Angles.randLenVectors(e.id, 7, 1f + e.ifract()*12f, (x, y)->{
float len = 1f+e.fract()*6f;
Draw.color(Color.SKY);
Draw.lineAngle(e.x + x, e.y + y, Mathf.atan2(x, y), len);
Draw.reset();
});
}),
redgeneratespark = new Effect(18, e -> {
Angles.randLenVectors(e.id, 5, e.ifract()*8f, (x, y)->{
float len = e.fract()*4f;
Draw.color(Color.valueOf("fbb97f"), Color.GRAY, e.ifract());
//Draw.alpha(e.fract());
Draw.rect("circle", e.x + x, e.y + y, len, len);
Draw.reset();
});
}),
generatespark = new Effect(18, e -> {
Angles.randLenVectors(e.id, 5, e.ifract()*8f, (x, y)->{
float len = e.fract()*4f;
Draw.color(Color.valueOf("d2b29c"), Color.GRAY, e.ifract());
//Draw.alpha(e.fract());
Draw.rect("circle", e.x + x, e.y + y, len, len);
Draw.reset();
});
}),
laserspark = new Effect(14, e -> {
Angles.randLenVectors(e.id, 8, 1f + e.ifract()*11f, (x, y)->{
float len = 1f+e.fract()*5f;
Draw.color(Color.WHITE, Color.CORAL, e.ifract());
Draw.alpha(e.ifract()/1.3f);
Draw.lineAngle(e.x + x, e.y + y, Mathf.atan2(x, y), len);
Draw.reset();
});
}),
shellsmoke = new Effect(20, e -> {
Angles.randLenVectors(e.id, 8, 3f + e.ifract()*17f, (x, y)->{
float size = 2f+e.fract()*5f;
Draw.color(Color.LIGHT_GRAY, Color.DARK_GRAY, e.ifract());
Draw.rect("circle", e.x + x, e.y + y, size, size);
Draw.reset();
});
}),
blastsmoke = new Effect(26, e -> {
Angles.randLenVectors(e.id, 12, 1f + e.ifract()*23f, (x, y)->{
float size = 2f+e.fract()*6f;
Draw.color(Color.LIGHT_GRAY, Color.DARK_GRAY, e.ifract());
Draw.rect("circle", e.x + x, e.y + y, size, size);
Draw.reset();
});
}),
lava = new Effect(18, e -> {
Angles.randLenVectors(e.id, 3, 1f + e.ifract()*10f, (x, y)->{
float size = e.sfract()*4f;
Draw.color(Color.ORANGE, Color.GRAY, e.ifract());
Draw.rect("circle", e.x + x, e.y + y, size, size);
Draw.reset();
});
}),
lavabubble = new Effect(45f, e -> {
Draw.color(Color.ORANGE);
float scl = 0.35f;
Draw.thick(1f - Mathf.clamp(e.ifract() - (1f-scl)) * (1f/scl));
Draw.circle(e.x, e.y, e.ifract()*4f);
Draw.reset();
}),
oilbubble = new Effect(64f, e -> {
Draw.color(Color.DARK_GRAY);
float scl = 0.25f;
Draw.thick(1f - Mathf.clamp(e.ifract() - (1f-scl)) * (1f/scl));
Draw.circle(e.x, e.y, e.ifract()*3f);
Draw.reset();
}),
shellexplosion = new Effect(9, e -> {
Draw.thickness(2f - e.ifract()*1.7f);
Draw.color(Color.WHITE, Color.LIGHT_GRAY, e.ifract());
Draw.circle(e.x, e.y, 3f + e.ifract() * 9f);
Draw.reset();
}),
blastexplosion = new Effect(16, e -> {
Draw.thickness(1.2f - e.ifract());
Draw.color(Color.WHITE, Color.SCARLET, e.ifract());
Draw.circle(e.x, e.y, 1.5f + e.ifract() * 9f);
Draw.reset();
}),
place = new Effect(16, e -> {
Draw.thickness(3f - e.ifract() * 2f);
Draw.square(e.x, e.y, Vars.tilesize / 2f + e.ifract() * 3f);
Draw.reset();
}),
dooropen = new Effect(10, e -> {
Draw.thickness(e.fract() * 1.6f);
Draw.square(e.x, e.y, Vars.tilesize / 2f + e.ifract() * 2f);
Draw.reset();
}),
doorclose= new Effect(10, e -> {
Draw.thickness(e.fract() * 1.6f);
Draw.square(e.x, e.y, Vars.tilesize / 2f + e.fract() * 2f);
Draw.reset();
}),
dooropenlarge = new Effect(10, e -> {
Draw.thickness(e.fract() * 1.6f);
Draw.square(e.x, e.y, Vars.tilesize + e.ifract() * 2f);
Draw.reset();
}),
doorcloselarge = new Effect(10, e -> {
Draw.thickness(e.fract() * 1.6f);
Draw.square(e.x, e.y, Vars.tilesize + e.fract() * 2f);
Draw.reset();
}),
purify = new Effect(10, e -> {
Draw.color(Color.ROYAL, Color.GRAY, e.ifract());
Draw.thickness(2f);
Draw.spikes(e.x, e.y, e.ifract() * 4f, 2, 6);
Draw.reset();
}),
purifyoil = new Effect(10, e -> {
Draw.color(Color.BLACK, Color.GRAY, e.ifract());
Draw.thickness(2f);
Draw.spikes(e.x, e.y, e.ifract() * 4f, 2, 6);
Draw.reset();
}),
purifystone = new Effect(10, e -> {
Draw.color(Color.ORANGE, Color.GRAY, e.ifract());
Draw.thickness(2f);
Draw.spikes(e.x, e.y, e.ifract() * 4f, 2, 6);
Draw.reset();
}),
generate = new Effect(11, e -> {
Draw.color(Color.ORANGE, Color.YELLOW, e.ifract());
Draw.thickness(1f);
Draw.spikes(e.x, e.y, e.ifract() * 5f, 2, 8);
Draw.reset();
}),
spark = new Effect(10, e -> {
Draw.thickness(1f);
Draw.color(Color.WHITE, Color.GRAY, e.ifract());
Draw.spikes(e.x, e.y, e.ifract() * 5f, 2, 8);
Draw.reset();
}),
sparkbig = new Effect(11, e -> {
Draw.thickness(1f);
Draw.color(lightRed, Color.GRAY, e.ifract());
Draw.spikes(e.x, e.y, e.ifract() * 5f, 2.3f, 8);
Draw.reset();
}),
smelt = new Effect(10, e -> {
Draw.thickness(1f);
Draw.color(Color.YELLOW, Color.RED, e.ifract());
Draw.spikes(e.x, e.y, e.ifract() * 5f, 2, 8);
Draw.reset();
}),
breakBlock = new Effect(12, e -> {
Draw.thickness(2f);
Draw.color(Color.WHITE, Colors.get("break"), e.ifract());
Draw.spikes(e.x, e.y, e.ifract() * 6f, 2, 5, 90);
Draw.reset();
}),
hit = new Effect(10, e -> {
Draw.thickness(1f);
Draw.color(Color.WHITE, Color.ORANGE, e.ifract());
Draw.spikes(e.x, e.y, e.ifract() * 3f, 2, 8);
Draw.reset();
}),
laserhit = new Effect(10, e -> {
Draw.thickness(1f);
Draw.color(Color.WHITE, Color.SKY, e.ifract());
Draw.spikes(e.x, e.y, e.ifract() * 2f, 2, 6);
Draw.reset();
}),
shieldhit = new Effect(9, e -> {
Draw.thickness(1f);
Draw.color(Color.WHITE, Color.SKY, e.ifract());
Draw.spikes(e.x, e.y, e.ifract() * 5f, 2, 6);
Draw.thickness(4f*e.fract());
Draw.circle(e.x, e.y, e.ifract()*14f);
Draw.reset();
}),
shoot = new Effect(8, e -> {
Draw.thickness(1f);
Draw.color(Color.WHITE, Color.GOLD, e.ifract());
Draw.spikes(e.x, e.y, e.ifract() * 2f, 2, 5);
Draw.reset();
}),
shoot2 = new Effect(8, e -> {
Draw.thickness(1f);
Draw.color(Color.WHITE, Color.SKY, e.ifract());
Draw.spikes(e.x, e.y, e.ifract() * 2f, 1, 5);
Draw.reset();
}),
shoot3 = new Effect(8, e -> {
Draw.thickness(1f);
Draw.color(Color.WHITE, Color.GOLD, e.ifract());
Draw.spikes(e.x, e.y, e.ifract() * 2f, 1, 5);
Draw.reset();
}),
railshoot = new Effect(8, e -> {
Draw.thickness(2f - e.ifract()*2f);
Draw.color(Color.WHITE, Color.LIGHT_GRAY, e.ifract());
Draw.spikes(e.x, e.y, 1f + e.ifract() * 4f, 1, 5);
Draw.reset();
}),
mortarshoot = new Effect(9, e -> {
Draw.thickness(1.3f - e.ifract());
Draw.color(Color.WHITE, Color.ORANGE, e.ifract());
Draw.spikes(e.x, e.y, e.ifract() * 4f, 2, 6);
Draw.circle(e.x, e.y, e.ifract() * 5f + 1f);
Draw.reset();
}),
titanExplosion = new Effect(11, 48f, e -> {
Draw.thickness(2f*e.fract()+0.5f);
Draw.color(Color.WHITE, Color.DARK_GRAY, e.powfract());
Draw.circle(e.x, e.y, 5f + e.powfract() * 8f);
Draw.color(e.ifract() < 0.5f ? whiteOrange : Color.DARK_GRAY);
float rad = e.fract()*10f + 5f;
Angles.randLenVectors(e.id, 5, 9f, (x, y)->{
Draw.rect("circle2", e.x + x, e.y + y, rad, rad);
});
Draw.reset();
}),
explosion = new Effect(11, e -> {
Draw.thickness(2f*e.fract()+0.5f);
Draw.color(Color.WHITE, Color.DARK_GRAY, e.powfract());
Draw.circle(e.x, e.y, 5f + e.powfract() * 6f);
Draw.color(e.ifract() < 0.5f ? Color.WHITE : Color.DARK_GRAY);
float rad = e.fract()*10f + 5f;
Angles.randLenVectors(e.id, 5, 8f, (x, y)->{
Draw.rect("circle2", e.x + x, e.y + y, rad, rad);
});
Draw.reset();
}),
blockexplosion = new Effect(13, e -> {
Angles.randLenVectors(e.id+1, 8, 5f + e.ifract()*11f, (x, y)->{
float size = 2f+e.fract()*8f;
Draw.color(Color.LIGHT_GRAY, Color.DARK_GRAY, e.ifract());
Draw.rect("circle", e.x + x, e.y + y, size, size);
Draw.reset();
});
Draw.thickness(2f*e.fract()+0.4f);
Draw.color(Color.WHITE, Color.ORANGE, e.powfract());
Draw.circle(e.x, e.y, 2f + e.powfract() * 9f);
Draw.color(e.ifract() < 0.5f ? Color.WHITE : Color.DARK_GRAY);
float rad = e.fract()*10f + 2f;
Angles.randLenVectors(e.id, 5, 8f, (x, y)->{
Draw.rect("circle2", e.x + x, e.y + y, rad, rad);
});
Draw.reset();
}),
coreexplosion = new Effect(13, e -> {
Draw.thickness(3f-e.ifract()*2f);
Draw.color(Color.ORANGE, Color.WHITE, e.ifract());
Draw.spikes(e.x, e.y, 5f + e.ifract() * 40f, 6, 6);
Draw.circle(e.x, e.y, 4f + e.ifract() * 40f);
Draw.reset();
}),
smoke = new Effect(100, e -> {
Draw.color(Color.GRAY, new Color(0.3f, 0.3f, 0.3f, 1f), e.ifract());
float size = 7f-e.ifract()*7f;
Draw.rect("circle", e.x, e.y, size, size);
Draw.reset();
}),
railsmoke = new Effect(30, e -> {
Draw.color(Color.LIGHT_GRAY, Color.WHITE, e.ifract());
float size = e.fract()*4f;
Draw.rect("circle", e.x, e.y, size, size);
Draw.reset();
}),
dashsmoke = new Effect(30, e -> {
Draw.color(Color.CORAL, Color.GRAY, e.ifract());
//Draw.alpha(e.fract());
float size = e.fract()*4f;
Draw.rect("circle", e.x, e.y, size, size);
Draw.reset();
}),
spawn = new Effect(23, e -> {
Draw.thickness(2f);
Draw.color(Color.DARK_GRAY, Color.SCARLET, e.ifract());
Draw.circle(e.x, e.y, 7f - e.ifract() * 6f);
Draw.reset();
}),
ind = new Effect(100, e -> {
Draw.thickness(3f);
Draw.color(Color.ROYAL);
Draw.circle(e.x, e.y, 3);
Draw.reset();
}),
respawn = new Effect(Vars.respawnduration, e -> {
Draw.tcolor(Color.SCARLET);
Draw.tscl(0.25f);
Draw.text("Respawning in " + (int)((e.lifetime-e.time)/60), e.x, e.y);
Draw.tscl(0.5f);
Draw.reset();
});
}

View File

@@ -0,0 +1,57 @@
package io.anuke.mindustry.graphics;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.utils.FloatArray;
import io.anuke.ucore.core.Core;
import io.anuke.ucore.core.Settings;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.graphics.Shader;
import io.anuke.ucore.util.Tmp;
public class Shaders{
public static final Outline outline = new Outline();
public static final Shield shield = new Shield();
public static class Outline extends Shader{
public Color color = new Color();
public Outline(){
super("outline", "default");
}
@Override
public void apply(){
shader.setUniformf("u_color", color);
shader.setUniformf("u_texsize", Tmp.v1.set(region.getTexture().getWidth(), region.getTexture().getHeight()));
}
}
public static class Shield extends Shader{
public static final int MAX_HITS = 3*64;
public Color color = new Color();
public FloatArray hits;
public Shield(){
super("shield", "default");
}
@Override
public void apply(){
float scale = Settings.getBool("pixelate") ? 1 : Core.cameraScale / Core.camera.zoom;
float scaling = Core.cameraScale / 4f / Core.camera.zoom;
if(hits.size > 0){
shader.setUniform3fv("u_hits[0]", hits.items, 0, Math.min(hits.size, MAX_HITS));
shader.setUniformi("u_hitamount", Math.min(hits.size, MAX_HITS)/3);
}
shader.setUniformf("u_color", color);
shader.setUniformf("u_time", Timers.time());
shader.setUniformf("u_scaling", scaling);
shader.setUniformf("u_offset", Tmp.v1.set(Core.camera.position.x, Core.camera.position.y));
shader.setUniformf("u_texsize", Tmp.v1.set(region.getTexture().getWidth() / scale,
region.getTexture().getHeight() / scale));
}
}
}