Formatting
This commit is contained in:
@@ -15,203 +15,207 @@ import static io.anuke.mindustry.Vars.*;
|
||||
import static io.anuke.ucore.core.Core.camera;
|
||||
|
||||
public class BlockRenderer{
|
||||
private final static int initialRequests = 32*32;
|
||||
private final static int initialRequests = 32 * 32;
|
||||
|
||||
private FloorRenderer floorRenderer;
|
||||
|
||||
private Array<BlockRequest> requests = new Array<>(initialRequests);
|
||||
private Layer lastLayer;
|
||||
private int requestidx = 0;
|
||||
private int iterateidx = 0;
|
||||
private FloorRenderer floorRenderer;
|
||||
|
||||
public BlockRenderer(){
|
||||
floorRenderer = new FloorRenderer();
|
||||
private Array<BlockRequest> requests = new Array<>(initialRequests);
|
||||
private Layer lastLayer;
|
||||
private int requestidx = 0;
|
||||
private int iterateidx = 0;
|
||||
|
||||
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);
|
||||
}
|
||||
public BlockRenderer(){
|
||||
floorRenderer = new FloorRenderer();
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return tile.block().name + ":" + layer.toString();
|
||||
}
|
||||
}
|
||||
|
||||
/**Process all blocks to draw, simultaneously drawing block shadows and static blocks.*/
|
||||
public void processBlocks(){
|
||||
requestidx = 0;
|
||||
lastLayer = null;
|
||||
|
||||
int rangex = (int) (camera.viewportWidth * camera.zoom / tilesize / 2)+2;
|
||||
int rangey = (int) (camera.viewportHeight * camera.zoom / tilesize / 2)+2;
|
||||
for(int i = 0; i < requests.size; i++){
|
||||
requests.set(i, new BlockRequest());
|
||||
}
|
||||
}
|
||||
|
||||
int expandr = 4;
|
||||
|
||||
Graphics.surface(renderer.effectSurface, true, false);
|
||||
/**
|
||||
* Process all blocks to draw, simultaneously drawing block shadows and static blocks.
|
||||
*/
|
||||
public void processBlocks(){
|
||||
requestidx = 0;
|
||||
lastLayer = null;
|
||||
|
||||
int avgx = Mathf.scl(camera.position.x, tilesize);
|
||||
int avgy = Mathf.scl(camera.position.y, tilesize);
|
||||
int rangex = (int) (camera.viewportWidth * camera.zoom / tilesize / 2) + 2;
|
||||
int rangey = (int) (camera.viewportHeight * camera.zoom / tilesize / 2) + 2;
|
||||
|
||||
int minx = Math.max(avgx - rangex - expandr, 0);
|
||||
int miny = Math.max(avgy - rangey - expandr, 0);
|
||||
int maxx = Math.min(world.width() - 1, avgx + rangex + expandr);
|
||||
int maxy = Math.min(world.height() - 1, avgy+ rangey + expandr);
|
||||
int expandr = 4;
|
||||
|
||||
for(int x = minx; x <= maxx; x++){
|
||||
for(int y = miny; y <= maxy; y++){
|
||||
boolean expanded = (Math.abs(x - avgx) > rangex || Math.abs(y - avgy) > rangey);
|
||||
Graphics.surface(renderer.effectSurface, true, false);
|
||||
|
||||
synchronized (Tile.tileSetLock) {
|
||||
Tile tile = world.rawTile(x, y);
|
||||
int avgx = Mathf.scl(camera.position.x, tilesize);
|
||||
int avgy = Mathf.scl(camera.position.y, tilesize);
|
||||
|
||||
if (tile != null) {
|
||||
Block block = tile.block();
|
||||
int minx = Math.max(avgx - rangex - expandr, 0);
|
||||
int miny = Math.max(avgy - rangey - expandr, 0);
|
||||
int maxx = Math.min(world.width() - 1, avgx + rangex + expandr);
|
||||
int maxy = Math.min(world.height() - 1, avgy + rangey + expandr);
|
||||
|
||||
if (!expanded && block != Blocks.air && world.isAccessible(x, y)) {
|
||||
tile.block().drawShadow(tile);
|
||||
}
|
||||
for(int x = minx; x <= maxx; x++){
|
||||
for(int y = miny; y <= maxy; y++){
|
||||
boolean expanded = (Math.abs(x - avgx) > rangex || Math.abs(y - avgy) > rangey);
|
||||
|
||||
if (!(block instanceof StaticBlock)) {
|
||||
if (block != Blocks.air) {
|
||||
if (!expanded) {
|
||||
addRequest(tile, Layer.block);
|
||||
}
|
||||
synchronized(Tile.tileSetLock){
|
||||
Tile tile = world.rawTile(x, y);
|
||||
|
||||
if (block.expanded || !expanded) {
|
||||
if (block.layer != null && block.isLayer(tile)) {
|
||||
addRequest(tile, block.layer);
|
||||
}
|
||||
if(tile != null){
|
||||
Block block = tile.block();
|
||||
|
||||
if (block.layer2 != null && block.isLayer2(tile)) {
|
||||
addRequest(tile, block.layer2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!expanded && block != Blocks.air && world.isAccessible(x, y)){
|
||||
tile.block().drawShadow(tile);
|
||||
}
|
||||
|
||||
//TODO this actually isn't necessary
|
||||
Draw.color(0, 0, 0, 0.15f);
|
||||
Graphics.flushSurface();
|
||||
Draw.color();
|
||||
if(!(block instanceof StaticBlock)){
|
||||
if(block != Blocks.air){
|
||||
if(!expanded){
|
||||
addRequest(tile, Layer.block);
|
||||
}
|
||||
|
||||
Graphics.end();
|
||||
floorRenderer.beginDraw();
|
||||
floorRenderer.drawLayer(CacheLayer.walls);
|
||||
floorRenderer.endDraw();
|
||||
Graphics.begin();
|
||||
if(block.expanded || !expanded){
|
||||
if(block.layer != null && block.isLayer(tile)){
|
||||
addRequest(tile, block.layer);
|
||||
}
|
||||
|
||||
Sort.instance().sort(requests.items, 0, requestidx);
|
||||
iterateidx = 0;
|
||||
}
|
||||
if(block.layer2 != null && block.isLayer2(tile)){
|
||||
addRequest(tile, block.layer2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getRequests(){
|
||||
return requestidx;
|
||||
}
|
||||
|
||||
public void drawBlocks(Layer stopAt){
|
||||
|
||||
for(; iterateidx < requestidx; iterateidx ++){
|
||||
//TODO this actually isn't necessary
|
||||
Draw.color(0, 0, 0, 0.15f);
|
||||
Graphics.flushSurface();
|
||||
Draw.color();
|
||||
|
||||
if(iterateidx < requests.size && requests.get(iterateidx).layer.ordinal() > stopAt.ordinal()){
|
||||
break;
|
||||
}
|
||||
|
||||
BlockRequest req = requests.get(iterateidx);
|
||||
Graphics.end();
|
||||
floorRenderer.beginDraw();
|
||||
floorRenderer.drawLayer(CacheLayer.walls);
|
||||
floorRenderer.endDraw();
|
||||
Graphics.begin();
|
||||
|
||||
if(req.layer != lastLayer){
|
||||
if(lastLayer != null) layerEnds(lastLayer);
|
||||
layerBegins(req.layer);
|
||||
}
|
||||
Sort.instance().sort(requests.items, 0, requestidx);
|
||||
iterateidx = 0;
|
||||
}
|
||||
|
||||
synchronized (Tile.tileSetLock) {
|
||||
Block block = req.tile.block();
|
||||
public int getRequests(){
|
||||
return requestidx;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
public void drawBlocks(Layer stopAt){
|
||||
|
||||
lastLayer = req.layer;
|
||||
}
|
||||
}
|
||||
for(; iterateidx < requestidx; iterateidx++){
|
||||
|
||||
public void drawTeamBlocks(Layer layer, Team team){
|
||||
int index = this.iterateidx;
|
||||
if(iterateidx < requests.size && requests.get(iterateidx).layer.ordinal() > stopAt.ordinal()){
|
||||
break;
|
||||
}
|
||||
|
||||
for(; index < requestidx; index ++){
|
||||
BlockRequest req = requests.get(iterateidx);
|
||||
|
||||
if(index < requests.size && requests.get(index).layer.ordinal() > layer.ordinal()){
|
||||
break;
|
||||
}
|
||||
if(req.layer != lastLayer){
|
||||
if(lastLayer != null) layerEnds(lastLayer);
|
||||
layerBegins(req.layer);
|
||||
}
|
||||
|
||||
BlockRequest req = requests.get(index);
|
||||
if(req.tile.getTeam() != team) continue;
|
||||
synchronized(Tile.tileSetLock){
|
||||
Block block = req.tile.block();
|
||||
|
||||
synchronized (Tile.tileSetLock) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
if (req.layer == block.layer) {
|
||||
block.drawLayer(req.tile);
|
||||
} else if (req.layer == block.layer2) {
|
||||
block.drawLayer2(req.tile);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
lastLayer = req.layer;
|
||||
}
|
||||
}
|
||||
|
||||
public void skipLayer(Layer stopAt){
|
||||
public void drawTeamBlocks(Layer layer, Team team){
|
||||
int index = this.iterateidx;
|
||||
|
||||
for(; iterateidx < requestidx; iterateidx ++){
|
||||
if(iterateidx < requests.size && requests.get(iterateidx).layer.ordinal() > stopAt.ordinal()){
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
for(; index < requestidx; index++){
|
||||
|
||||
public void beginFloor(){
|
||||
floorRenderer.beginDraw();
|
||||
}
|
||||
if(index < requests.size && requests.get(index).layer.ordinal() > layer.ordinal()){
|
||||
break;
|
||||
}
|
||||
|
||||
public void endFloor(){
|
||||
floorRenderer.endDraw();
|
||||
}
|
||||
BlockRequest req = requests.get(index);
|
||||
if(req.tile.getTeam() != team) continue;
|
||||
|
||||
public void drawFloor(){
|
||||
floorRenderer.drawFloor();
|
||||
}
|
||||
synchronized(Tile.tileSetLock){
|
||||
Block block = req.tile.block();
|
||||
|
||||
private void layerBegins(Layer layer){}
|
||||
if(req.layer == block.layer){
|
||||
block.drawLayer(req.tile);
|
||||
}else if(req.layer == block.layer2){
|
||||
block.drawLayer2(req.tile);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void layerEnds(Layer layer){}
|
||||
public void skipLayer(Layer stopAt){
|
||||
|
||||
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 ++;
|
||||
}
|
||||
for(; iterateidx < requestidx; iterateidx++){
|
||||
if(iterateidx < requests.size && requests.get(iterateidx).layer.ordinal() > stopAt.ordinal()){
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void beginFloor(){
|
||||
floorRenderer.beginDraw();
|
||||
}
|
||||
|
||||
public void endFloor(){
|
||||
floorRenderer.endDraw();
|
||||
}
|
||||
|
||||
public void drawFloor(){
|
||||
floorRenderer.drawFloor();
|
||||
}
|
||||
|
||||
private void layerBegins(Layer layer){
|
||||
}
|
||||
|
||||
private void layerEnds(Layer layer){
|
||||
}
|
||||
|
||||
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++;
|
||||
}
|
||||
|
||||
private class BlockRequest implements Comparable<BlockRequest>{
|
||||
Tile tile;
|
||||
Layer layer;
|
||||
|
||||
@Override
|
||||
public int compareTo(BlockRequest other){
|
||||
return layer.compareTo(other.layer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return tile.block().name + ":" + layer.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import io.anuke.ucore.graphics.Shader;
|
||||
|
||||
import static io.anuke.mindustry.Vars.renderer;
|
||||
|
||||
public enum CacheLayer {
|
||||
public enum CacheLayer{
|
||||
water{
|
||||
@Override
|
||||
public void begin(){
|
||||
@@ -57,11 +57,11 @@ public enum CacheLayer {
|
||||
walls;
|
||||
|
||||
public void begin(){
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void end(){
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected void beginShader(){
|
||||
|
||||
@@ -26,7 +26,7 @@ import java.util.Arrays;
|
||||
import static io.anuke.mindustry.Vars.tilesize;
|
||||
import static io.anuke.mindustry.Vars.world;
|
||||
|
||||
public class FloorRenderer {
|
||||
public class FloorRenderer{
|
||||
private final static int chunksize = 64;
|
||||
|
||||
private Chunk[][] cache;
|
||||
@@ -38,6 +38,35 @@ public class FloorRenderer {
|
||||
Events.on(WorldLoadGraphicsEvent.class, this::clearTiles);
|
||||
}
|
||||
|
||||
static ShaderProgram createDefaultShader(){
|
||||
String vertexShader = "attribute vec4 " + ShaderProgram.POSITION_ATTRIBUTE + ";\n" //
|
||||
+ "attribute vec2 " + ShaderProgram.TEXCOORD_ATTRIBUTE + "0;\n" //
|
||||
+ "uniform mat4 u_projTrans;\n" //
|
||||
+ "varying vec2 v_texCoords;\n" //
|
||||
+ "\n" //
|
||||
+ "void main()\n" //
|
||||
+ "{\n" //
|
||||
+ " v_texCoords = " + ShaderProgram.TEXCOORD_ATTRIBUTE + "0;\n" //
|
||||
+ " gl_Position = u_projTrans * " + ShaderProgram.POSITION_ATTRIBUTE + ";\n" //
|
||||
+ "}\n";
|
||||
String fragmentShader = "#ifdef GL_ES\n" //
|
||||
+ "#define LOWP lowp\n" //
|
||||
+ "precision mediump float;\n" //
|
||||
+ "#else\n" //
|
||||
+ "#define LOWP \n" //
|
||||
+ "#endif\n" //
|
||||
+ "varying vec2 v_texCoords;\n" //
|
||||
+ "uniform sampler2D u_texture;\n" //
|
||||
+ "void main()\n"//
|
||||
+ "{\n" //
|
||||
+ " gl_FragColor = texture2D(u_texture, v_texCoords);\n" //
|
||||
+ "}";
|
||||
|
||||
ShaderProgram shader = new ShaderProgram(vertexShader, fragmentShader);
|
||||
if(!shader.isCompiled()) throw new IllegalArgumentException("Error compiling shader: " + shader.getLog());
|
||||
return shader;
|
||||
}
|
||||
|
||||
public void drawFloor(){
|
||||
if(cache == null){
|
||||
return;
|
||||
@@ -45,11 +74,11 @@ public class FloorRenderer {
|
||||
|
||||
OrthographicCamera camera = Core.camera;
|
||||
|
||||
int crangex = (int)(camera.viewportWidth * camera.zoom / (chunksize * tilesize))+1;
|
||||
int crangey = (int)(camera.viewportHeight * camera.zoom / (chunksize * tilesize))+1;
|
||||
int crangex = (int) (camera.viewportWidth * camera.zoom / (chunksize * tilesize)) + 1;
|
||||
int crangey = (int) (camera.viewportHeight * camera.zoom / (chunksize * tilesize)) + 1;
|
||||
|
||||
for(int x = -crangex; x <= crangex; x++) {
|
||||
for (int y = -crangey; y <= crangey; y++) {
|
||||
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;
|
||||
|
||||
@@ -71,13 +100,13 @@ public class FloorRenderer {
|
||||
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))
|
||||
if(!Mathf.inBounds(worldx, worldy, cache))
|
||||
continue;
|
||||
|
||||
Chunk chunk = cache[worldx][worldy];
|
||||
|
||||
//loop through all layers, and add layer index if it exists
|
||||
for(int i = 0; i < layers - 1; i ++){
|
||||
for(int i = 0; i < layers - 1; i++){
|
||||
if(chunk.caches[i] != -1){
|
||||
drawnLayerSet.add(i);
|
||||
}
|
||||
@@ -95,7 +124,7 @@ public class FloorRenderer {
|
||||
Graphics.end();
|
||||
beginDraw();
|
||||
|
||||
for(int i = 0; i < drawnLayers.size; i ++) {
|
||||
for(int i = 0; i < drawnLayers.size; i++){
|
||||
CacheLayer layer = CacheLayer.values()[drawnLayers.get(i)];
|
||||
|
||||
drawLayer(layer);
|
||||
@@ -131,13 +160,13 @@ public class FloorRenderer {
|
||||
|
||||
OrthographicCamera camera = Core.camera;
|
||||
|
||||
int crangex = (int)(camera.viewportWidth * camera.zoom / (chunksize * tilesize))+1;
|
||||
int crangey = (int)(camera.viewportHeight * camera.zoom / (chunksize * tilesize))+1;
|
||||
int crangex = (int) (camera.viewportWidth * camera.zoom / (chunksize * tilesize)) + 1;
|
||||
int crangey = (int) (camera.viewportHeight * camera.zoom / (chunksize * tilesize)) + 1;
|
||||
|
||||
layer.begin();
|
||||
|
||||
for (int x = -crangex; x <= crangex; x++) {
|
||||
for (int y = -crangey; y <= crangey; y++) {
|
||||
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;
|
||||
|
||||
@@ -166,12 +195,12 @@ public class FloorRenderer {
|
||||
|
||||
ObjectSet<CacheLayer> used = new ObjectSet<>();
|
||||
|
||||
for(int tilex = cx * chunksize; tilex < (cx + 1) * chunksize; tilex++) {
|
||||
for (int tiley = cy * chunksize; tiley < (cy + 1) * chunksize; tiley++) {
|
||||
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){
|
||||
if(tile != null){
|
||||
used.add(tile.block().cacheLayer == CacheLayer.walls ?
|
||||
CacheLayer.walls : tile.floor().cacheLayer);
|
||||
CacheLayer.walls : tile.floor().cacheLayer);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -180,7 +209,7 @@ public class FloorRenderer {
|
||||
cacheChunkLayer(cx, cy, chunk, layer);
|
||||
}
|
||||
|
||||
// Log.info("Time to cache a chunk: {0}", TimeUtils.timeSinceNanos(time) / 1000000f);
|
||||
// Log.info("Time to cache a chunk: {0}", TimeUtils.timeSinceNanos(time) / 1000000f);
|
||||
}
|
||||
|
||||
private void cacheChunkLayer(int cx, int cy, Chunk chunk, CacheLayer layer){
|
||||
@@ -211,25 +240,21 @@ public class FloorRenderer {
|
||||
chunk.caches[layer.ordinal()] = cbatch.getLastCache();
|
||||
}
|
||||
|
||||
private class Chunk{
|
||||
int[] caches = new int[CacheLayer.values().length];
|
||||
}
|
||||
|
||||
public void clearTiles(){
|
||||
if(cbatch != null) cbatch.dispose();
|
||||
|
||||
Timers.mark();
|
||||
|
||||
int chunksx = Mathf.ceil((float)world.width() / chunksize), chunksy = Mathf.ceil((float)world.height() / chunksize);
|
||||
int chunksx = Mathf.ceil((float) world.width() / chunksize), chunksy = Mathf.ceil((float) world.height() / chunksize);
|
||||
cache = new Chunk[chunksx][chunksy];
|
||||
cbatch = new CacheBatch(world.width()*world.height()*4*4);
|
||||
cbatch = new CacheBatch(world.width() * world.height() * 4 * 4);
|
||||
|
||||
Log.info("Time to create: {0}", Timers.elapsed());
|
||||
|
||||
Timers.mark();
|
||||
|
||||
for (int x = 0; x < chunksx; x++) {
|
||||
for (int y = 0; y < chunksy; y++) {
|
||||
for(int x = 0; x < chunksx; x++){
|
||||
for(int y = 0; y < chunksy; y++){
|
||||
cache[x][y] = new Chunk();
|
||||
Arrays.fill(cache[x][y].caches, -1);
|
||||
|
||||
@@ -240,32 +265,7 @@ public class FloorRenderer {
|
||||
Log.info("Time to cache: {0}", Timers.elapsed());
|
||||
}
|
||||
|
||||
static ShaderProgram createDefaultShader () {
|
||||
String vertexShader = "attribute vec4 " + ShaderProgram.POSITION_ATTRIBUTE + ";\n" //
|
||||
+ "attribute vec2 " + ShaderProgram.TEXCOORD_ATTRIBUTE + "0;\n" //
|
||||
+ "uniform mat4 u_projTrans;\n" //
|
||||
+ "varying vec2 v_texCoords;\n" //
|
||||
+ "\n" //
|
||||
+ "void main()\n" //
|
||||
+ "{\n" //
|
||||
+ " v_texCoords = " + ShaderProgram.TEXCOORD_ATTRIBUTE + "0;\n" //
|
||||
+ " gl_Position = u_projTrans * " + ShaderProgram.POSITION_ATTRIBUTE + ";\n" //
|
||||
+ "}\n";
|
||||
String fragmentShader = "#ifdef GL_ES\n" //
|
||||
+ "#define LOWP lowp\n" //
|
||||
+ "precision mediump float;\n" //
|
||||
+ "#else\n" //
|
||||
+ "#define LOWP \n" //
|
||||
+ "#endif\n" //
|
||||
+ "varying vec2 v_texCoords;\n" //
|
||||
+ "uniform sampler2D u_texture;\n" //
|
||||
+ "void main()\n"//
|
||||
+ "{\n" //
|
||||
+ " gl_FragColor = texture2D(u_texture, v_texCoords);\n" //
|
||||
+ "}";
|
||||
|
||||
ShaderProgram shader = new ShaderProgram(vertexShader, fragmentShader);
|
||||
if (!shader.isCompiled()) throw new IllegalArgumentException("Error compiling shader: " + shader.getLog());
|
||||
return shader;
|
||||
private class Chunk{
|
||||
int[] caches = new int[CacheLayer.values().length];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,9 @@ import java.nio.ByteBuffer;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
/**Used for rendering fog of war. A framebuffer is used for this.*/
|
||||
/**
|
||||
* Used for rendering fog of war. A framebuffer is used for this.
|
||||
*/
|
||||
public class FogRenderer implements Disposable{
|
||||
private TextureRegion region = new TextureRegion();
|
||||
private FrameBuffer buffer;
|
||||
@@ -42,8 +44,8 @@ public class FogRenderer implements Disposable{
|
||||
Graphics.clear(0, 0, 0, 1f);
|
||||
buffer.end();
|
||||
|
||||
for (int x = 0; x < world.width(); x++) {
|
||||
for (int y = 0; y < world.height(); y++) {
|
||||
for(int x = 0; x < world.width(); x++){
|
||||
for(int y = 0; y < world.height(); y++){
|
||||
Tile tile = world.tile(x, y);
|
||||
|
||||
if(tile.getTeam() == players[0].getTeam() && tile.block().synthetic() && tile.block().viewRange > 0){
|
||||
@@ -66,14 +68,14 @@ public class FogRenderer implements Disposable{
|
||||
float vw = Core.camera.viewportWidth * Core.camera.zoom;
|
||||
float vh = Core.camera.viewportHeight * Core.camera.zoom;
|
||||
|
||||
float px = Core.camera.position.x -= vw/2f;
|
||||
float py = Core.camera.position.y -= vh/2f;
|
||||
float px = Core.camera.position.x -= vw / 2f;
|
||||
float py = Core.camera.position.y -= vh / 2f;
|
||||
|
||||
float u = px / tilesize / world.width();
|
||||
float v = py / tilesize / world.height();
|
||||
|
||||
float u2 = (px + vw)/ tilesize / world.width();
|
||||
float v2 = (py + vh)/ tilesize / world.height();
|
||||
float u2 = (px + vw) / tilesize / world.width();
|
||||
float v2 = (py + vh) / tilesize / world.height();
|
||||
|
||||
if(Core.batch instanceof ClipSpriteBatch){
|
||||
((ClipSpriteBatch) Core.batch).enableClip(false);
|
||||
@@ -137,7 +139,7 @@ public class FogRenderer implements Disposable{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
public void dispose(){
|
||||
if(buffer != null) buffer.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,28 @@
|
||||
package io.anuke.mindustry.graphics;
|
||||
|
||||
public enum Layer{
|
||||
/**Base block layer.*/
|
||||
block,
|
||||
/**for placement*/
|
||||
/**
|
||||
* Base block layer.
|
||||
*/
|
||||
block,
|
||||
/**
|
||||
* for placement
|
||||
*/
|
||||
placement,
|
||||
/**First overlay. Stuff like conveyor items.*/
|
||||
overlay,
|
||||
/**"High" blocks, like turrets.*/
|
||||
turret,
|
||||
/**Power lasers.*/
|
||||
power,
|
||||
/**Extra lasers, like healing turrets.*/
|
||||
laser
|
||||
/**
|
||||
* First overlay. Stuff like conveyor items.
|
||||
*/
|
||||
overlay,
|
||||
/**
|
||||
* "High" blocks, like turrets.
|
||||
*/
|
||||
turret,
|
||||
/**
|
||||
* Power lasers.
|
||||
*/
|
||||
power,
|
||||
/**
|
||||
* Extra lasers, like healing turrets.
|
||||
*/
|
||||
laser
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ public class MinimapRenderer implements Disposable{
|
||||
|
||||
public void zoomBy(int amount){
|
||||
zoom += amount;
|
||||
zoom = Mathf.clamp(zoom, 1, Math.min(world.width(), world.height())/baseSize/2);
|
||||
zoom = Mathf.clamp(zoom, 1, Math.min(world.width(), world.height()) / baseSize / 2);
|
||||
}
|
||||
|
||||
public void reset(){
|
||||
@@ -71,10 +71,10 @@ public class MinimapRenderer implements Disposable{
|
||||
int sz = baseSize * zoom;
|
||||
float dx = (Core.camera.position.x / tilesize);
|
||||
float dy = (Core.camera.position.y / tilesize);
|
||||
dx = Mathf.clamp(dx, sz, world.width()-sz);
|
||||
dy = Mathf.clamp(dy, sz, world.height()-sz);
|
||||
dx = Mathf.clamp(dx, sz, world.width() - sz);
|
||||
dy = Mathf.clamp(dy, sz, world.height() - sz);
|
||||
|
||||
synchronized (units){
|
||||
synchronized(units){
|
||||
rect.set((dx - sz) * tilesize, (dy - sz) * tilesize, sz * 2 * tilesize, sz * 2 * tilesize);
|
||||
Graphics.flush();
|
||||
|
||||
@@ -93,24 +93,24 @@ public class MinimapRenderer implements Disposable{
|
||||
}
|
||||
}
|
||||
|
||||
public TextureRegion getRegion() {
|
||||
public TextureRegion getRegion(){
|
||||
if(texture == null) return null;
|
||||
|
||||
int sz = Mathf.clamp(baseSize * zoom, baseSize, Math.min(world.width(), world.height()));
|
||||
float dx = (Core.camera.position.x / tilesize);
|
||||
float dy = (Core.camera.position.y / tilesize);
|
||||
dx = Mathf.clamp(dx, sz, world.width()-sz);
|
||||
dy = Mathf.clamp(dy, sz, world.height()-sz);
|
||||
dx = Mathf.clamp(dx, sz, world.width() - sz);
|
||||
dy = Mathf.clamp(dy, sz, world.height() - sz);
|
||||
float invTexWidth = 1f / texture.getWidth();
|
||||
float invTexHeight = 1f / texture.getHeight();
|
||||
float x = dx - sz, y = world.height()-dy - sz, width = sz*2, height = sz*2;
|
||||
float x = dx - sz, y = world.height() - dy - sz, width = sz * 2, height = sz * 2;
|
||||
region.setRegion(x * invTexWidth, y * invTexHeight, (x + width) * invTexWidth, (y + height) * invTexHeight);
|
||||
return region;
|
||||
}
|
||||
|
||||
public void updateAll(){
|
||||
for(int x = 0; x < world.width(); x ++){
|
||||
for(int y = 0; y < world.height(); y ++){
|
||||
for(int x = 0; x < world.width(); x++){
|
||||
for(int y = 0; y < world.height(); y++){
|
||||
pixmap.drawPixel(x, pixmap.getHeight() - 1 - y, colorFor(world.tile(x, y)));
|
||||
}
|
||||
}
|
||||
@@ -128,10 +128,10 @@ public class MinimapRenderer implements Disposable{
|
||||
int sz = baseSize * zoom;
|
||||
float dx = (Core.camera.position.x / tilesize);
|
||||
float dy = (Core.camera.position.y / tilesize);
|
||||
dx = Mathf.clamp(dx, sz, world.width()-sz);
|
||||
dy = Mathf.clamp(dy, sz, world.height()-sz);
|
||||
dx = Mathf.clamp(dx, sz, world.width() - sz);
|
||||
dy = Mathf.clamp(dy, sz, world.height() - sz);
|
||||
|
||||
synchronized (units) {
|
||||
synchronized(units){
|
||||
rect.set((dx - sz) * tilesize, (dy - sz) * tilesize, sz * 2 * tilesize, sz * 2 * tilesize);
|
||||
units.clear();
|
||||
Units.getNearby(rect, units::add);
|
||||
@@ -142,7 +142,7 @@ public class MinimapRenderer implements Disposable{
|
||||
int color = tile.breakable() ? tile.target().getTeam().intColor : ColorMapper.getBlockColor(tile.block());
|
||||
if(color == 0) color = ColorMapper.getBlockColor(tile.floor());
|
||||
if(tile.elevation > 0){
|
||||
float mul = 1.1f+tile.elevation/4f;
|
||||
float mul = 1.1f + tile.elevation / 4f;
|
||||
tmpColor.set(color);
|
||||
tmpColor.mul(mul, mul, mul, 1f);
|
||||
color = Color.rgba8888(tmpColor);
|
||||
@@ -151,7 +151,7 @@ public class MinimapRenderer implements Disposable{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
public void dispose(){
|
||||
pixmap.dispose();
|
||||
texture.dispose();
|
||||
texture = null;
|
||||
|
||||
@@ -12,7 +12,6 @@ import io.anuke.mindustry.game.TeamInfo.TeamData;
|
||||
import io.anuke.mindustry.input.InputHandler;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.consumers.Consume;
|
||||
import io.anuke.mindustry.world.meta.BlockBar;
|
||||
import io.anuke.ucore.core.Graphics;
|
||||
import io.anuke.ucore.core.Settings;
|
||||
@@ -25,10 +24,10 @@ import io.anuke.ucore.util.Mathf;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class OverlayRenderer {
|
||||
public class OverlayRenderer{
|
||||
|
||||
public void drawBottom(){
|
||||
for(Player player : players) {
|
||||
for(Player player : players){
|
||||
InputHandler input = control.input(player.playerIndex);
|
||||
|
||||
if(!input.isDrawing() || player.isDead()) continue;
|
||||
@@ -44,7 +43,7 @@ public class OverlayRenderer {
|
||||
|
||||
public void drawTop(){
|
||||
|
||||
for(Player player : players) {
|
||||
for(Player player : players){
|
||||
if(player.isDead()) continue; //dead player don't draw
|
||||
|
||||
InputHandler input = control.input(player.playerIndex);
|
||||
@@ -53,7 +52,7 @@ public class OverlayRenderer {
|
||||
if(input.frag.config.isShown()){
|
||||
Tile tile = input.frag.config.getSelectedTile();
|
||||
|
||||
synchronized (Tile.tileSetLock) {
|
||||
synchronized(Tile.tileSetLock){
|
||||
tile.block().drawConfigure(tile);
|
||||
}
|
||||
}
|
||||
@@ -63,14 +62,14 @@ public class OverlayRenderer {
|
||||
Draw.reset();
|
||||
|
||||
//draw selected block bars and info
|
||||
if (input.recipe == null && !ui.hasMouse() && !input.frag.config.isShown()) {
|
||||
if(input.recipe == null && !ui.hasMouse() && !input.frag.config.isShown()){
|
||||
Vector2 vec = Graphics.world(input.getMouseX(), input.getMouseY());
|
||||
Tile tile = world.tileWorld(vec.x, vec.y);
|
||||
|
||||
if (tile != null && tile.block() != Blocks.air) {
|
||||
if(tile != null && tile.block() != Blocks.air){
|
||||
Tile target = tile.target();
|
||||
|
||||
if (showBlockDebug && target.entity != null) {
|
||||
if(showBlockDebug && target.entity != null){
|
||||
Draw.color(Color.RED);
|
||||
Lines.crect(target.drawx(), target.drawy(), target.block().size * tilesize, target.block().size * tilesize);
|
||||
Vector2 v = new Vector2();
|
||||
@@ -79,7 +78,7 @@ public class OverlayRenderer {
|
||||
Draw.tscl(0.25f);
|
||||
Array<Object> arr = target.block().getDebugInfo(target);
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (int i = 0; i < arr.size / 2; i++) {
|
||||
for(int i = 0; i < arr.size / 2; i++){
|
||||
result.append(arr.get(i * 2));
|
||||
result.append(": ");
|
||||
result.append(arr.get(i * 2 + 1));
|
||||
@@ -93,27 +92,27 @@ public class OverlayRenderer {
|
||||
Draw.reset();
|
||||
}
|
||||
|
||||
synchronized (Tile.tileSetLock) {
|
||||
synchronized(Tile.tileSetLock){
|
||||
Block block = target.block();
|
||||
TileEntity entity = target.entity;
|
||||
|
||||
if (entity != null) {
|
||||
if(entity != null){
|
||||
int[] values = {0, 0};
|
||||
boolean[] doDraw = {false};
|
||||
|
||||
Callable drawbars = () -> {
|
||||
for (BlockBar bar : block.bars.list()) {
|
||||
for(BlockBar bar : block.bars.list()){
|
||||
float offset = Mathf.sign(bar.top) * (block.size / 2f * tilesize + 2f + (bar.top ? values[0] : values[1]));
|
||||
|
||||
float value = bar.value.get(target);
|
||||
|
||||
if (MathUtils.isEqual(value, -1f)) continue;
|
||||
if(MathUtils.isEqual(value, -1f)) continue;
|
||||
|
||||
if(doDraw[0]){
|
||||
drawBar(bar.type.color, target.drawx(), target.drawy() + offset, value);
|
||||
}
|
||||
|
||||
if (bar.top)
|
||||
if(bar.top)
|
||||
values[0]++;
|
||||
else
|
||||
values[1]++;
|
||||
@@ -123,11 +122,11 @@ public class OverlayRenderer {
|
||||
drawbars.run();
|
||||
|
||||
if(values[0] > 0){
|
||||
drawEncloser(target.drawx(), target.drawy() + block.size * tilesize/2f + 2f, values[0]);
|
||||
drawEncloser(target.drawx(), target.drawy() + block.size * tilesize / 2f + 2f, values[0]);
|
||||
}
|
||||
|
||||
if(values[1] > 0){
|
||||
drawEncloser(target.drawx(), target.drawy() - block.size * tilesize/2f - 2f - values[1], values[1]);
|
||||
drawEncloser(target.drawx(), target.drawy() - block.size * tilesize / 2f - 2f - values[1], values[1]);
|
||||
}
|
||||
|
||||
doDraw[0] = true;
|
||||
@@ -143,7 +142,7 @@ public class OverlayRenderer {
|
||||
}
|
||||
}
|
||||
|
||||
if (input.isDroppingItem()) {
|
||||
if(input.isDroppingItem()){
|
||||
Vector2 v = Graphics.world(input.getMouseX(), input.getMouseY());
|
||||
float size = 8;
|
||||
Draw.rect(player.inventory.getItem().item.region, v.x, v.y, size, size);
|
||||
@@ -152,8 +151,8 @@ public class OverlayRenderer {
|
||||
Draw.reset();
|
||||
|
||||
Tile tile = world.tileWorld(v.x, v.y);
|
||||
if (tile != null) tile = tile.target();
|
||||
if (tile != null && tile.block().acceptStack(player.inventory.getItem().item, player.inventory.getItem().amount, tile, player) > 0) {
|
||||
if(tile != null) tile = tile.target();
|
||||
if(tile != null && tile.block().acceptStack(player.inventory.getItem().item, player.inventory.getItem().amount, tile, player) > 0){
|
||||
Draw.color(Palette.place);
|
||||
Lines.square(tile.drawx(), tile.drawy(), tile.block().size * tilesize / 2f + 1 + Mathf.absin(Timers.time(), 5f, 1f));
|
||||
Draw.color();
|
||||
@@ -177,9 +176,9 @@ public class OverlayRenderer {
|
||||
float x = unit.x;
|
||||
float y = unit.y;
|
||||
|
||||
if(unit == players[0] && players.length == 1 && snapCamera) {
|
||||
x = (int)(x + 0.0001f);
|
||||
y = (int)(y + 0.0001f);
|
||||
if(unit == players[0] && players.length == 1 && snapCamera){
|
||||
x = (int) (x + 0.0001f);
|
||||
y = (int) (y + 0.0001f);
|
||||
}
|
||||
|
||||
drawEncloser(x, y - 9f, 2f);
|
||||
@@ -197,7 +196,7 @@ public class OverlayRenderer {
|
||||
float w = (int) (len * 2 * finion);
|
||||
|
||||
Draw.color(Color.BLACK);
|
||||
Fill.crect(x - len, y, len*2f, 1);
|
||||
Fill.crect(x - len, y, len * 2f, 1);
|
||||
if(finion > 0){
|
||||
Draw.color(color);
|
||||
Fill.crect(x - len, y, Math.max(1, w), 1);
|
||||
@@ -210,7 +209,7 @@ public class OverlayRenderer {
|
||||
float len = 4;
|
||||
|
||||
Draw.color(Palette.bar);
|
||||
Fill.crect(x - len, y - 1, len*2f, height + 2f);
|
||||
Fill.crect(x - len, y - 1, len * 2f, height + 2f);
|
||||
Draw.color();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package io.anuke.mindustry.graphics;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
|
||||
public class Palette {
|
||||
public class Palette{
|
||||
public static final Color bulletYellow = Color.valueOf("ffeec9");
|
||||
public static final Color bulletYellowBack = Color.valueOf("f9c87a");
|
||||
|
||||
|
||||
@@ -13,100 +13,100 @@ import static io.anuke.mindustry.Vars.tilesize;
|
||||
import static io.anuke.mindustry.Vars.world;
|
||||
|
||||
public class Shaders{
|
||||
public static Outline outline;
|
||||
public static Outline outline;
|
||||
public static BlockBuild blockbuild;
|
||||
public static BlockPreview blockpreview;
|
||||
public static Shield shield;
|
||||
public static SurfaceShader water;
|
||||
public static SurfaceShader lava;
|
||||
public static SurfaceShader oil;
|
||||
public static Space space;
|
||||
public static UnitBuild build;
|
||||
public static MixShader mix;
|
||||
public static Shader fullMix;
|
||||
public static FogShader fog;
|
||||
public static Shield shield;
|
||||
public static SurfaceShader water;
|
||||
public static SurfaceShader lava;
|
||||
public static SurfaceShader oil;
|
||||
public static Space space;
|
||||
public static UnitBuild build;
|
||||
public static MixShader mix;
|
||||
public static Shader fullMix;
|
||||
public static FogShader fog;
|
||||
|
||||
public static void init(){
|
||||
outline = new Outline();
|
||||
blockbuild = new BlockBuild();
|
||||
blockpreview = new BlockPreview();
|
||||
shield = new Shield();
|
||||
water = new SurfaceShader("water");
|
||||
lava = new SurfaceShader("lava");
|
||||
oil = new SurfaceShader("oil");
|
||||
space = new Space();
|
||||
build = new UnitBuild();
|
||||
mix = new MixShader();
|
||||
fog = new FogShader();
|
||||
fullMix = new Shader("fullmix", "default");
|
||||
}
|
||||
public static void init(){
|
||||
outline = new Outline();
|
||||
blockbuild = new BlockBuild();
|
||||
blockpreview = new BlockPreview();
|
||||
shield = new Shield();
|
||||
water = new SurfaceShader("water");
|
||||
lava = new SurfaceShader("lava");
|
||||
oil = new SurfaceShader("oil");
|
||||
space = new Space();
|
||||
build = new UnitBuild();
|
||||
mix = new MixShader();
|
||||
fog = new FogShader();
|
||||
fullMix = new Shader("fullmix", "default");
|
||||
}
|
||||
|
||||
public static class FogShader extends Shader{
|
||||
public FogShader(){
|
||||
super("fog", "default");
|
||||
}
|
||||
}
|
||||
public static class FogShader extends Shader{
|
||||
public FogShader(){
|
||||
super("fog", "default");
|
||||
}
|
||||
}
|
||||
|
||||
public static class MixShader extends Shader{
|
||||
public Color color = new Color(Color.WHITE);
|
||||
public static class MixShader extends Shader{
|
||||
public Color color = new Color(Color.WHITE);
|
||||
|
||||
public MixShader(){
|
||||
super("mix", "default");
|
||||
}
|
||||
public MixShader(){
|
||||
super("mix", "default");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
super.apply();
|
||||
shader.setUniformf("u_color", color);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void apply(){
|
||||
super.apply();
|
||||
shader.setUniformf("u_color", color);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Space extends SurfaceShader{
|
||||
public static class Space extends SurfaceShader{
|
||||
|
||||
public Space(){
|
||||
super("space2");
|
||||
}
|
||||
public Space(){
|
||||
super("space2");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(){
|
||||
super.apply();
|
||||
shader.setUniformf("u_center", world.width() * tilesize/2f, world.height() * tilesize/2f);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void apply(){
|
||||
super.apply();
|
||||
shader.setUniformf("u_center", world.width() * tilesize / 2f, world.height() * tilesize / 2f);
|
||||
}
|
||||
}
|
||||
|
||||
public static class UnitBuild extends Shader{
|
||||
public float progress, time;
|
||||
public Color color = new Color();
|
||||
public TextureRegion region;
|
||||
public static class UnitBuild extends Shader{
|
||||
public float progress, time;
|
||||
public Color color = new Color();
|
||||
public TextureRegion region;
|
||||
|
||||
public UnitBuild() {
|
||||
super("build", "default");
|
||||
}
|
||||
public UnitBuild(){
|
||||
super("build", "default");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(){
|
||||
shader.setUniformf("u_time", time);
|
||||
shader.setUniformf("u_color", color);
|
||||
shader.setUniformf("u_progress", progress);
|
||||
shader.setUniformf("u_uv", region.getU(), region.getV());
|
||||
shader.setUniformf("u_uv2", region.getU2(), region.getV2());
|
||||
shader.setUniformf("u_texsize", region.getTexture().getWidth(), region.getTexture().getHeight());
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void apply(){
|
||||
shader.setUniformf("u_time", time);
|
||||
shader.setUniformf("u_color", color);
|
||||
shader.setUniformf("u_progress", progress);
|
||||
shader.setUniformf("u_uv", region.getU(), region.getV());
|
||||
shader.setUniformf("u_uv2", region.getU2(), region.getV2());
|
||||
shader.setUniformf("u_texsize", region.getTexture().getWidth(), region.getTexture().getHeight());
|
||||
}
|
||||
}
|
||||
|
||||
public static class Outline extends Shader{
|
||||
public Color color = new Color();
|
||||
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", region.getTexture().getWidth(), region.getTexture().getHeight());
|
||||
}
|
||||
}
|
||||
public Outline(){
|
||||
super("outline", "default");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(){
|
||||
shader.setUniformf("u_color", color);
|
||||
shader.setUniformf("u_texsize", region.getTexture().getWidth(), region.getTexture().getHeight());
|
||||
}
|
||||
}
|
||||
|
||||
public static class BlockBuild extends Shader{
|
||||
public Color color = new Color();
|
||||
@@ -136,7 +136,7 @@ public class Shaders{
|
||||
|
||||
@Override
|
||||
public void apply(){
|
||||
// shader.setUniformf("u_progress", progress);
|
||||
// shader.setUniformf("u_progress", progress);
|
||||
shader.setUniformf("u_color", color);
|
||||
shader.setUniformf("u_uv", region.getU(), region.getV());
|
||||
shader.setUniformf("u_uv2", region.getU2(), region.getV2());
|
||||
@@ -144,49 +144,49 @@ public class Shaders{
|
||||
shader.setUniformf("u_texsize", 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 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_dp", Unit.dp.scl(1f));
|
||||
shader.setUniformf("u_color", color);
|
||||
shader.setUniformf("u_time", Timers.time() / Unit.dp.scl(1f));
|
||||
shader.setUniformf("u_scaling", scaling);
|
||||
shader.setUniformf("u_offset",
|
||||
Core.camera.position.x - Core.camera.viewportWidth/2 * Core.camera.zoom,
|
||||
Core.camera.position.y - Core.camera.viewportHeight/2 * Core.camera.zoom);
|
||||
shader.setUniformf("u_texsize", Gdx.graphics.getWidth() / Core.cameraScale * Core.camera.zoom,
|
||||
Gdx.graphics.getHeight() / Core.cameraScale * Core.camera.zoom);
|
||||
}
|
||||
}
|
||||
|
||||
public static class SurfaceShader extends Shader{
|
||||
public static class Shield extends Shader{
|
||||
public static final int MAX_HITS = 3 * 64;
|
||||
public Color color = new Color();
|
||||
public FloatArray hits;
|
||||
|
||||
public SurfaceShader(String frag){
|
||||
super(frag, "default");
|
||||
}
|
||||
public Shield(){
|
||||
super("shield", "default");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(){
|
||||
shader.setUniformf("camerapos",
|
||||
Core.camera.position.x - Core.camera.viewportWidth/2 * Core.camera.zoom,
|
||||
Core.camera.position.y - Core.camera.viewportHeight/2 * Core.camera.zoom);
|
||||
shader.setUniformf("screensize", Gdx.graphics.getWidth() / Core.cameraScale * Core.camera.zoom,
|
||||
Gdx.graphics.getHeight() / Core.cameraScale * Core.camera.zoom);
|
||||
shader.setUniformf("time", Timers.time());
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void apply(){
|
||||
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_dp", Unit.dp.scl(1f));
|
||||
shader.setUniformf("u_color", color);
|
||||
shader.setUniformf("u_time", Timers.time() / Unit.dp.scl(1f));
|
||||
shader.setUniformf("u_scaling", scaling);
|
||||
shader.setUniformf("u_offset",
|
||||
Core.camera.position.x - Core.camera.viewportWidth / 2 * Core.camera.zoom,
|
||||
Core.camera.position.y - Core.camera.viewportHeight / 2 * Core.camera.zoom);
|
||||
shader.setUniformf("u_texsize", Gdx.graphics.getWidth() / Core.cameraScale * Core.camera.zoom,
|
||||
Gdx.graphics.getHeight() / Core.cameraScale * Core.camera.zoom);
|
||||
}
|
||||
}
|
||||
|
||||
public static class SurfaceShader extends Shader{
|
||||
|
||||
public SurfaceShader(String frag){
|
||||
super(frag, "default");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(){
|
||||
shader.setUniformf("camerapos",
|
||||
Core.camera.position.x - Core.camera.viewportWidth / 2 * Core.camera.zoom,
|
||||
Core.camera.position.y - Core.camera.viewportHeight / 2 * Core.camera.zoom);
|
||||
shader.setUniformf("screensize", Gdx.graphics.getWidth() / Core.cameraScale * Core.camera.zoom,
|
||||
Gdx.graphics.getHeight() / Core.cameraScale * Core.camera.zoom);
|
||||
shader.setUniformf("time", Timers.time());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,8 +8,10 @@ import io.anuke.ucore.graphics.Fill;
|
||||
import io.anuke.ucore.graphics.Lines;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
/**Class that renders a trail.*/
|
||||
public class Trail {
|
||||
/**
|
||||
* Class that renders a trail.
|
||||
*/
|
||||
public class Trail{
|
||||
private final static float maxJump = 15f;
|
||||
private final int length;
|
||||
private final FloatArray points = new FloatArray();
|
||||
@@ -26,7 +28,7 @@ public class Trail {
|
||||
|
||||
points.add(curx, cury);
|
||||
|
||||
if(points.size > length*2) {
|
||||
if(points.size > length * 2){
|
||||
float[] items = points.items;
|
||||
System.arraycopy(items, 2, items, 0, points.size - 2);
|
||||
points.size -= 2;
|
||||
@@ -48,14 +50,14 @@ public class Trail {
|
||||
float y = points.get(i + 1);
|
||||
float x2 = points.get(i + 2);
|
||||
float y2 = points.get(i + 3);
|
||||
float s = Mathf.clamp((float)(i) / points.size);
|
||||
float s = Mathf.clamp((float) (i) / points.size);
|
||||
|
||||
Lines.stroke(s * stroke);
|
||||
Lines.line(x, y, x2, y2);
|
||||
}
|
||||
|
||||
if(points.size >= 2){
|
||||
Fill.circle(points.get(points.size-2), points.get(points.size-1), stroke/2f);
|
||||
Fill.circle(points.get(points.size - 2), points.get(points.size - 1), stroke / 2f);
|
||||
}
|
||||
|
||||
Draw.reset();
|
||||
|
||||
Reference in New Issue
Block a user