Source reformat
This commit is contained in:
@@ -77,7 +77,7 @@ public class BlockRenderer{
|
||||
for(int y = 0; y < world.height(); y++){
|
||||
Tile tile = world.rawTile(x, y);
|
||||
if(tile.getRotation() > 0 && tile.block().solid && tile.block().fillsTile && !tile.block().synthetic()){
|
||||
Draw.color(0f, 0f, 0f, Math.min((tile.getRotation() + 0.5f)/4f, 1f));
|
||||
Draw.color(0f, 0f, 0f, Math.min((tile.getRotation() + 0.5f) / 4f, 1f));
|
||||
Fill.rect(tile.x + 0.5f, tile.y + 0.5f, 1, 1);
|
||||
}
|
||||
}
|
||||
@@ -92,9 +92,9 @@ public class BlockRenderer{
|
||||
shadowEvents.add(event.tile);
|
||||
|
||||
int avgx = (int)(camera.position.x / tilesize);
|
||||
int avgy = (int)(camera.position. y / tilesize);
|
||||
int rangex = (int) (camera.width / tilesize / 2) + 2;
|
||||
int rangey = (int) (camera.height / tilesize / 2) + 2;
|
||||
int avgy = (int)(camera.position.y / tilesize);
|
||||
int rangex = (int)(camera.width / tilesize / 2) + 2;
|
||||
int rangey = (int)(camera.height / tilesize / 2) + 2;
|
||||
|
||||
if(Math.abs(avgx - event.tile.x) <= rangex && Math.abs(avgy - event.tile.y) <= rangey){
|
||||
lastCamY = lastCamX = -99; //invalidate camera position so blocks get updated
|
||||
@@ -104,11 +104,11 @@ public class BlockRenderer{
|
||||
|
||||
public void drawFog(){
|
||||
float ww = world.width() * tilesize, wh = world.height() * tilesize;
|
||||
float x = camera.position.x + tilesize/2f, y = camera.position.y + tilesize/2f;
|
||||
float u = (x - camera.width/2f) / ww,
|
||||
v = (y - camera.height/2f) / wh,
|
||||
u2 = (x + camera.width/2f) / ww,
|
||||
v2 = (y + camera.height/2f) / wh;
|
||||
float x = camera.position.x + tilesize / 2f, y = camera.position.y + tilesize / 2f;
|
||||
float u = (x - camera.width / 2f) / ww,
|
||||
v = (y - camera.height / 2f) / wh,
|
||||
u2 = (x + camera.width / 2f) / ww,
|
||||
v2 = (y + camera.height / 2f) / wh;
|
||||
|
||||
Tmp.tr1.set(fog.getTexture());
|
||||
Tmp.tr1.set(u, v2, u2, v);
|
||||
@@ -144,11 +144,11 @@ public class BlockRenderer{
|
||||
}
|
||||
|
||||
float ww = world.width() * tilesize, wh = world.height() * tilesize;
|
||||
float x = camera.position.x + tilesize/2f, y = camera.position.y + tilesize/2f;
|
||||
float u = (x - camera.width/2f) / ww,
|
||||
v = (y - camera.height/2f) / wh,
|
||||
u2 = (x + camera.width/2f) / ww,
|
||||
v2 = (y + camera.height/2f) / wh;
|
||||
float x = camera.position.x + tilesize / 2f, y = camera.position.y + tilesize / 2f;
|
||||
float u = (x - camera.width / 2f) / ww,
|
||||
v = (y - camera.height / 2f) / wh,
|
||||
u2 = (x + camera.width / 2f) / ww,
|
||||
v2 = (y + camera.height / 2f) / wh;
|
||||
|
||||
Tmp.tr1.set(shadows.getTexture());
|
||||
Tmp.tr1.set(u, v2, u2, v);
|
||||
@@ -158,15 +158,15 @@ public class BlockRenderer{
|
||||
Draw.shader();
|
||||
}
|
||||
|
||||
/**Process all blocks to draw.*/
|
||||
/** Process all blocks to draw. */
|
||||
public void processBlocks(){
|
||||
iterateidx = 0;
|
||||
|
||||
int avgx = (int)(camera.position.x / tilesize);
|
||||
int avgy = (int)(camera.position.y / tilesize);
|
||||
|
||||
int rangex = (int) (camera.width / tilesize / 2) + 3;
|
||||
int rangey = (int) (camera.height / tilesize / 2) + 3;
|
||||
int rangex = (int)(camera.width / tilesize / 2) + 3;
|
||||
int rangey = (int)(camera.height / tilesize / 2) + 3;
|
||||
|
||||
if(avgx == lastCamX && avgy == lastCamY && lastRangeX == rangex && lastRangeY == rangey){
|
||||
return;
|
||||
|
||||
@@ -2,20 +2,13 @@ package io.anuke.mindustry.graphics;
|
||||
|
||||
import io.anuke.arc.Core;
|
||||
import io.anuke.arc.Events;
|
||||
import io.anuke.arc.collection.IntArray;
|
||||
import io.anuke.arc.collection.IntSet;
|
||||
import io.anuke.arc.collection.*;
|
||||
import io.anuke.arc.collection.IntSet.IntSetIterator;
|
||||
import io.anuke.arc.collection.ObjectSet;
|
||||
import io.anuke.arc.graphics.Camera;
|
||||
import io.anuke.arc.graphics.GL20;
|
||||
import io.anuke.arc.graphics.g2d.CacheBatch;
|
||||
import io.anuke.arc.graphics.g2d.Draw;
|
||||
import io.anuke.arc.graphics.g2d.SpriteBatch;
|
||||
import io.anuke.arc.graphics.g2d.SpriteCache;
|
||||
import io.anuke.arc.graphics.g2d.*;
|
||||
import io.anuke.arc.math.Mathf;
|
||||
import io.anuke.arc.util.Log;
|
||||
import io.anuke.arc.util.Structs;
|
||||
import io.anuke.arc.util.Time;
|
||||
import io.anuke.arc.util.*;
|
||||
import io.anuke.mindustry.game.EventType.WorldLoadEvent;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.Floor;
|
||||
@@ -45,8 +38,8 @@ public class FloorRenderer{
|
||||
|
||||
Camera camera = Core.camera;
|
||||
|
||||
int crangex = (int) (camera.width / (chunksize * tilesize)) + 1;
|
||||
int crangey = (int) (camera.height / (chunksize * tilesize)) + 1;
|
||||
int crangex = (int)(camera.width / (chunksize * tilesize)) + 1;
|
||||
int crangey = (int)(camera.height / (chunksize * tilesize)) + 1;
|
||||
|
||||
int camx = (int)(camera.position.x / (chunksize * tilesize));
|
||||
int camy = (int)(camera.position.y / (chunksize * tilesize));
|
||||
@@ -129,8 +122,8 @@ public class FloorRenderer{
|
||||
|
||||
Camera camera = Core.camera;
|
||||
|
||||
int crangex = (int) (camera.width / (chunksize * tilesize)) + 1;
|
||||
int crangey = (int) (camera.height / (chunksize * tilesize)) + 1;
|
||||
int crangex = (int)(camera.width / (chunksize * tilesize)) + 1;
|
||||
int crangey = (int)(camera.height / (chunksize * tilesize)) + 1;
|
||||
|
||||
layer.begin();
|
||||
|
||||
@@ -183,7 +176,7 @@ public class FloorRenderer{
|
||||
|
||||
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);
|
||||
Tile tile = world.tile(tilex, tiley);
|
||||
Floor floor;
|
||||
|
||||
if(tile == null){
|
||||
@@ -194,7 +187,7 @@ public class FloorRenderer{
|
||||
|
||||
if(tile.block().cacheLayer == layer && layer == CacheLayer.walls){
|
||||
tile.block().draw(tile);
|
||||
}else if(floor.cacheLayer == layer && (world.isAccessible(tile.x,tile.y) || tile.block().cacheLayer != CacheLayer.walls || !tile.block().fillsTile)){
|
||||
}else if(floor.cacheLayer == layer && (world.isAccessible(tile.x, tile.y) || tile.block().cacheLayer != CacheLayer.walls || !tile.block().fillsTile)){
|
||||
floor.draw(tile);
|
||||
}else if(floor.cacheLayer.ordinal() < layer.ordinal() && layer != CacheLayer.walls){
|
||||
floor.drawNonLayer(tile);
|
||||
@@ -208,8 +201,8 @@ public class FloorRenderer{
|
||||
public void clearTiles(){
|
||||
if(cbatch != null) cbatch.dispose();
|
||||
|
||||
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];
|
||||
SpriteCache sprites = new SpriteCache(world.width() * world.height() * 6, (world.width() / chunksize) * (world.height() / chunksize) * 2, false);
|
||||
cbatch = new CacheBatch(sprites);
|
||||
|
||||
@@ -16,35 +16,35 @@ public class IndexedRenderer implements Disposable{
|
||||
private final static int vsize = 5;
|
||||
|
||||
private Shader program = new Shader(
|
||||
Strings.join("\n",
|
||||
"attribute vec4 " + Shader.POSITION_ATTRIBUTE + ";",
|
||||
"attribute vec4 " + Shader.COLOR_ATTRIBUTE + ";",
|
||||
"attribute vec2 " + Shader.TEXCOORD_ATTRIBUTE + "0;",
|
||||
"uniform mat4 u_projTrans;",
|
||||
"varying vec4 v_color;",
|
||||
"varying vec2 v_texCoords;",
|
||||
"",
|
||||
"void main(){",
|
||||
" v_color = " + Shader.COLOR_ATTRIBUTE + ";",
|
||||
" v_color.a = v_color.a * (255.0/254.0);",
|
||||
" v_texCoords = " + Shader.TEXCOORD_ATTRIBUTE + "0;",
|
||||
" gl_Position = u_projTrans * " + Shader.POSITION_ATTRIBUTE + ";",
|
||||
"}"),
|
||||
Strings.join("\n",
|
||||
"#ifdef GL_ES",
|
||||
"#define LOWP lowp",
|
||||
"precision mediump float;",
|
||||
"#else",
|
||||
"#define LOWP ",
|
||||
"#endif",
|
||||
"",
|
||||
"varying LOWP vec4 v_color;",
|
||||
"varying vec2 v_texCoords;",
|
||||
"uniform sampler2D u_texture;",
|
||||
"",
|
||||
"void main(){",
|
||||
" gl_FragColor = v_color * texture2D(u_texture, v_texCoords);",
|
||||
"}"
|
||||
Strings.join("\n",
|
||||
"attribute vec4 " + Shader.POSITION_ATTRIBUTE + ";",
|
||||
"attribute vec4 " + Shader.COLOR_ATTRIBUTE + ";",
|
||||
"attribute vec2 " + Shader.TEXCOORD_ATTRIBUTE + "0;",
|
||||
"uniform mat4 u_projTrans;",
|
||||
"varying vec4 v_color;",
|
||||
"varying vec2 v_texCoords;",
|
||||
"",
|
||||
"void main(){",
|
||||
" v_color = " + Shader.COLOR_ATTRIBUTE + ";",
|
||||
" v_color.a = v_color.a * (255.0/254.0);",
|
||||
" v_texCoords = " + Shader.TEXCOORD_ATTRIBUTE + "0;",
|
||||
" gl_Position = u_projTrans * " + Shader.POSITION_ATTRIBUTE + ";",
|
||||
"}"),
|
||||
Strings.join("\n",
|
||||
"#ifdef GL_ES",
|
||||
"#define LOWP lowp",
|
||||
"precision mediump float;",
|
||||
"#else",
|
||||
"#define LOWP ",
|
||||
"#endif",
|
||||
"",
|
||||
"varying LOWP vec4 v_color;",
|
||||
"varying vec2 v_texCoords;",
|
||||
"uniform sampler2D u_texture;",
|
||||
"",
|
||||
"void main(){",
|
||||
" gl_FragColor = v_color * texture2D(u_texture, v_texCoords);",
|
||||
"}"
|
||||
));
|
||||
private Mesh mesh;
|
||||
private float[] tmpVerts = new float[vsize * 6];
|
||||
@@ -226,9 +226,9 @@ public class IndexedRenderer implements Disposable{
|
||||
if(mesh != null) mesh.dispose();
|
||||
|
||||
mesh = new Mesh(true, 6 * sprites, 0,
|
||||
new VertexAttribute(Usage.Position, 2, "a_position"),
|
||||
new VertexAttribute(Usage.ColorPacked, 4, "a_color"),
|
||||
new VertexAttribute(Usage.TextureCoordinates, 2, "a_texCoord0"));
|
||||
new VertexAttribute(Usage.Position, 2, "a_position"),
|
||||
new VertexAttribute(Usage.ColorPacked, 4, "a_color"),
|
||||
new VertexAttribute(Usage.TextureCoordinates, 2, "a_texCoord0"));
|
||||
vertices = new float[6 * sprites * vsize];
|
||||
mesh.setVertices(vertices);
|
||||
}
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
package io.anuke.mindustry.graphics;
|
||||
|
||||
public enum Layer{
|
||||
/**Base block layer.*/
|
||||
/** Base block layer. */
|
||||
block,
|
||||
/**for placement*/
|
||||
/** for placement */
|
||||
placement,
|
||||
/**First overlay. Stuff like conveyor items.*/
|
||||
/** First overlay. Stuff like conveyor items. */
|
||||
overlay,
|
||||
/**"High" blocks, like turrets.*/
|
||||
/** "High" blocks, like turrets. */
|
||||
turret,
|
||||
/**Power lasers.*/
|
||||
/** Power lasers. */
|
||||
power,
|
||||
/**Extra lasers, like healing turrets.*/
|
||||
/** Extra lasers, like healing turrets. */
|
||||
laser
|
||||
}
|
||||
|
||||
@@ -3,13 +3,9 @@ package io.anuke.mindustry.graphics;
|
||||
import io.anuke.arc.Core;
|
||||
import io.anuke.arc.Events;
|
||||
import io.anuke.arc.collection.Array;
|
||||
import io.anuke.arc.graphics.Pixmap;
|
||||
import io.anuke.arc.graphics.*;
|
||||
import io.anuke.arc.graphics.Pixmap.Format;
|
||||
import io.anuke.arc.graphics.Pixmaps;
|
||||
import io.anuke.arc.graphics.Texture;
|
||||
import io.anuke.arc.graphics.g2d.Draw;
|
||||
import io.anuke.arc.graphics.g2d.Fill;
|
||||
import io.anuke.arc.graphics.g2d.TextureRegion;
|
||||
import io.anuke.arc.graphics.g2d.*;
|
||||
import io.anuke.arc.math.Mathf;
|
||||
import io.anuke.arc.math.geom.Rectangle;
|
||||
import io.anuke.arc.util.Disposable;
|
||||
@@ -83,7 +79,7 @@ public class MinimapRenderer implements Disposable{
|
||||
for(Unit unit : units){
|
||||
float rx = (unit.x - rect.x) / rect.width * w, ry = (unit.y - rect.y) / rect.width * h;
|
||||
Draw.color(unit.getTeam().color);
|
||||
Fill.rect(x + rx, y + ry, baseSize/2f, baseSize/2f);
|
||||
Fill.rect(x + rx, y + ry, baseSize / 2f, baseSize / 2f);
|
||||
}
|
||||
|
||||
Draw.color();
|
||||
|
||||
@@ -76,7 +76,7 @@ public class OverlayRenderer{
|
||||
buildFadeTime = Mathf.lerpDelta(buildFadeTime, input.isPlacing() ? 1f : 0f, 0.06f);
|
||||
|
||||
Draw.reset();
|
||||
Lines.stroke(buildFadeTime*2f);
|
||||
Lines.stroke(buildFadeTime * 2f);
|
||||
|
||||
if(buildFadeTime > 0.005f){
|
||||
for(Team enemy : state.teams.enemiesOf(player.getTeam())){
|
||||
|
||||
@@ -120,10 +120,10 @@ public class Shaders{
|
||||
setUniformf("u_dp", Unit.dp.scl(1f));
|
||||
setUniformf("u_time", Time.time() / Unit.dp.scl(1f));
|
||||
setUniformf("u_offset",
|
||||
Core.camera.position.x - Core.camera.width / 2 ,
|
||||
Core.camera.position.y - Core.camera.height / 2 );
|
||||
setUniformf("u_texsize", Core.camera.width ,
|
||||
Core.camera.height );
|
||||
Core.camera.position.x - Core.camera.width / 2,
|
||||
Core.camera.position.y - Core.camera.height / 2);
|
||||
setUniformf("u_texsize", Core.camera.width,
|
||||
Core.camera.height);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,7 +140,7 @@ public class Shaders{
|
||||
setUniformf("time", Time.time());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class LoadShader extends Shader{
|
||||
public LoadShader(String frag, String vert){
|
||||
super(Core.files.internal("shaders/" + vert + ".vertex"), Core.files.internal("shaders/" + frag + ".fragment"));
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
package io.anuke.mindustry.graphics;
|
||||
|
||||
import io.anuke.arc.Core;
|
||||
import io.anuke.arc.graphics.g2d.CapStyle;
|
||||
import io.anuke.arc.graphics.g2d.Draw;
|
||||
import io.anuke.arc.graphics.g2d.Lines;
|
||||
import io.anuke.arc.graphics.g2d.TextureRegion;
|
||||
import io.anuke.arc.graphics.g2d.*;
|
||||
import io.anuke.arc.math.Mathf;
|
||||
import io.anuke.arc.util.Tmp;
|
||||
|
||||
@@ -34,6 +31,6 @@ public class Shapes{
|
||||
|
||||
public static void tri(float x, float y, float width, float length, float rotation){
|
||||
float oy = 17f / 63f * length;
|
||||
Draw.rect(Core.atlas.find("shape-3"), x, y - oy + length/2f, width, length, width / 2f, oy, rotation - 90);
|
||||
Draw.rect(Core.atlas.find("shape-3"), x, y - oy + length / 2f, width, length, width / 2f, oy, rotation - 90);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user