diff --git a/build.gradle b/build.gradle index 6d62477c27..da94f43d1a 100644 --- a/build.gradle +++ b/build.gradle @@ -25,7 +25,7 @@ allprojects { appName = 'Mindustry' gdxVersion = '1.9.8' aiVersion = '1.8.1' - uCoreVersion = '156dff2' + uCoreVersion = '36de2b4' getVersionString = { String buildVersion = getBuildVersion() diff --git a/core/assets/shaders/water.fragment b/core/assets/shaders/water.fragment new file mode 100644 index 0000000000..4005d580ac --- /dev/null +++ b/core/assets/shaders/water.fragment @@ -0,0 +1,90 @@ +#ifdef GL_ES +precision mediump float; +precision mediump int; +#endif + +uniform sampler2D u_texture; + +uniform vec2 camerapos; +uniform vec2 screensize; +uniform float time; + +varying vec4 v_color; +varying vec2 v_texCoord; + +float round(float num, float f){ + return float(int(num / f)) * f; +} + +vec3 permute(vec3 x) { return mod(((x*34.0)+1.0)*x, 289.0); } + +float snoise(vec2 v){ + const vec4 C = vec4(0.211324865405187, 0.366025403784439, + -0.577350269189626, 0.024390243902439); + vec2 i = floor(v + dot(v, C.yy) ); + vec2 x0 = v - i + dot(i, C.xx); + vec2 i1; + i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0); + vec4 x12 = x0.xyxy + C.xxzz; + x12.xy -= i1; + i = mod(i, 289.0); + vec3 p = permute( permute( i.y + vec3(0.0, i1.y, 1.0 )) + + i.x + vec3(0.0, i1.x, 1.0 )); + vec3 m = max(0.5 - vec3(dot(x0,x0), dot(x12.xy,x12.xy), + dot(x12.zw,x12.zw)), 0.0); + m = m*m ; + m = m*m ; + vec3 x = 2.0 * fract(p * C.www) - 1.0; + vec3 h = abs(x) - 0.5; + vec3 ox = floor(x + 0.5); + vec3 a0 = x - ox; + m *= 1.79284291400159 - 0.85373472095314 * ( a0*a0 + h*h ); + vec3 g; + g.x = a0.x * x0.x + h.x * x0.y; + g.yz = a0.yz * x12.xz + h.yz * x12.yw; + return 130.0 * dot(m, g); +} + +void main() { + + vec2 c = v_texCoord.xy; + vec4 color = texture2D(u_texture, c); + + vec2 v = vec2(1.0/screensize.x, 1.0/screensize.y); + ivec2 icoords = ivec2(int(c.x / v.x + camerapos.x), int(c.y / v.y + camerapos.y)); + vec2 coords = vec2(float(icoords.x), float(icoords.y)); + + float stime = time / 5.0; + + float mscl = 30.0; + float mth = 5.0; + + //if there's something actually there + if(color.r > 0.01){ + vec4 old = color; + color = texture2D(u_texture, c + vec2(sin(stime/3.0 + coords.y/0.75) * v.x, 0.0)) * vec4(0.9, 0.9, 1, 1.0); + color.a = 1.0; + + if(color.r < 0.01){ + color = old; + } + + float n1 = snoise(coords / 40.0 + vec2(time) / 200.0); + float n2 = snoise((coords + vec2(632.0)) / 25.0 + vec2(0.0, -time) / 190.0); + + float r = (n1 + n2) * 3.0; + + if(mod(float(int(coords.x + coords.y*1.1 + sin(stime / 8.0 + coords.x/5.0 - coords.y/100.0)*2.0)) + + sin(stime / 20.0 + coords.y/3.0) * 1.0 + + sin(stime / 10.0 + coords.y/2.0) * 2.0 + + sin(stime / 7.0 + coords.y/1.0) * 0.5 + + sin(coords.x + coords.y) + + sin(stime / 20.0 + coords.x/4.0) * 1.0, mscl) + r < mth){ + + color *= 1.2; + color.a = 1.0; + } + } + + gl_FragColor = color; +} diff --git a/core/assets/version.properties b/core/assets/version.properties index fa3f84764e..2d2ef6a8f9 100644 --- a/core/assets/version.properties +++ b/core/assets/version.properties @@ -1,7 +1,7 @@ #Autogenerated file. Do not modify. -#Tue Mar 13 18:52:30 EDT 2018 +#Tue Mar 13 22:34:33 EDT 2018 version=release -androidBuildCode=489 +androidBuildCode=491 name=Mindustry code=3.4 build=custom build diff --git a/core/src/io/anuke/mindustry/core/Renderer.java b/core/src/io/anuke/mindustry/core/Renderer.java index f1fe3a2856..5dea8438a6 100644 --- a/core/src/io/anuke/mindustry/core/Renderer.java +++ b/core/src/io/anuke/mindustry/core/Renderer.java @@ -44,7 +44,7 @@ import static io.anuke.ucore.core.Core.camera; public class Renderer extends RendererModule{ private final static float shieldHitDuration = 18f; - public Surface shadowSurface, shieldSurface, indicatorSurface; + public Surface shadowSurface, shieldSurface, indicatorSurface, waterSurface; private int targetscale = baseCameraScale; private Texture background = new Texture("sprites/background.png"); @@ -83,6 +83,7 @@ public class Renderer extends RendererModule{ shieldSurface = Graphics.createSurface(scale); indicatorSurface = Graphics.createSurface(scale); pixelSurface = Graphics.createSurface(scale); + waterSurface = Graphics.createSurface(scale); } public void setPixelate(boolean pixelate){ diff --git a/core/src/io/anuke/mindustry/graphics/BlockRenderer.java b/core/src/io/anuke/mindustry/graphics/BlockRenderer.java index e53ffacd1b..e5d04817f1 100644 --- a/core/src/io/anuke/mindustry/graphics/BlockRenderer.java +++ b/core/src/io/anuke/mindustry/graphics/BlockRenderer.java @@ -114,7 +114,7 @@ public class BlockRenderer{ Draw.color(); Graphics.end(); - drawCache(1, crangex, crangey); + drawCache(DrawLayer.walls, crangex, crangey); Graphics.begin(); Arrays.sort(requests.items, 0, requestidx); @@ -165,12 +165,13 @@ public class BlockRenderer{ //render the entire map if(cache == null || cache.length != chunksx || cache[0].length != chunksy){ - cache = new int[chunksx][chunksy][2]; + cache = new int[chunksx][chunksy][DrawLayer.values().length]; - for(int x = 0; x < chunksx; x++){ - for(int y = 0; y < chunksy; y++){ - cacheChunk(x, y, true); - cacheChunk(x, y, false); + for(DrawLayer layer : DrawLayer.values()){ + for(int x = 0; x < chunksx; x++){ + for(int y = 0; y < chunksy; y++){ + cacheChunk(x, y, layer); + } } } } @@ -182,7 +183,11 @@ public class BlockRenderer{ int crangex = (int)(camera.viewportWidth * camera.zoom / (chunksize * tilesize))+1; int crangey = (int)(camera.viewportHeight * camera.zoom / (chunksize * tilesize))+1; - drawCache(0, crangex, crangey); + DrawLayer[] layers = DrawLayer.values(); + + for(int i = 0; i < layers.length - 1; i ++) { + drawCache(layers[i], crangex, crangey); + } Graphics.begin(); @@ -224,11 +229,11 @@ public class BlockRenderer{ } - void drawCache(int layer, int crangex, int crangey){ + void drawCache(DrawLayer layer, int crangex, int crangey){ Gdx.gl.glEnable(GL20.GL_BLEND); - cbatch.setProjectionMatrix(Core.camera.combined); - cbatch.beginDraw(); + layer.begin(cbatch); + for(int x = -crangex; x <= crangex; x++){ for(int y = -crangey; y <= crangey; y++){ int worldx = Mathf.scl(camera.position.x, chunksize * tilesize) + x; @@ -237,14 +242,14 @@ public class BlockRenderer{ if(!Mathf.inBounds(worldx, worldy, cache)) continue; - cbatch.drawCache(cache[worldx][worldy][layer]); + cbatch.drawCache(cache[worldx][worldy][layer.ordinal()]); } } - cbatch.endDraw(); + layer.end(cbatch); } - void cacheChunk(int cx, int cy, boolean floor){ + void cacheChunk(int cx, int cy, DrawLayer layer){ if(cbatch == null){ createBatch(); } @@ -256,18 +261,21 @@ public class BlockRenderer{ for(int tiley = cy * chunksize; tiley < (cy + 1) * chunksize; tiley++){ Tile tile = world.tile(tilex, tiley); if(tile == null) continue; - if(floor){ - if(!(tile.block() instanceof StaticBlock)){ - tile.floor().draw(tile); - } - }else if(tile.block() instanceof StaticBlock){ + + if(tile.floor().drawLayer == layer && tile.block().drawLayer != DrawLayer.walls){ + tile.floor().draw(tile); + }else if(tile.floor().drawLayer.ordinal() < layer.ordinal() && tile.block().drawLayer != DrawLayer.walls){ + tile.floor().drawNonLayer(tile); + } + + if(tile.block().drawLayer == layer && layer == DrawLayer.walls){ tile.block().draw(tile); } } } Graphics.popBatch(); cbatch.end(); - cache[cx][cy][floor ? 0 : 1] = cbatch.getLastCache(); + cache[cx][cy][layer.ordinal()] = cbatch.getLastCache(); } public void clearTiles(){ diff --git a/core/src/io/anuke/mindustry/graphics/DrawLayer.java b/core/src/io/anuke/mindustry/graphics/DrawLayer.java new file mode 100644 index 0000000000..9ff1c03cdf --- /dev/null +++ b/core/src/io/anuke/mindustry/graphics/DrawLayer.java @@ -0,0 +1,51 @@ +package io.anuke.mindustry.graphics; + +import io.anuke.ucore.core.Core; +import io.anuke.ucore.core.Graphics; +import io.anuke.ucore.graphics.CacheBatch; +import io.anuke.ucore.graphics.Draw; + +import static io.anuke.mindustry.Vars.renderer; + +public enum DrawLayer { + water{ + @Override + public void begin(CacheBatch batch){ + batch.setProjectionMatrix(Core.camera.combined); + Graphics.useBatch(batch.drawBatch()); + + Graphics.begin(); + Graphics.surface(renderer.waterSurface); + } + + @Override + public void end(CacheBatch batch){ + Graphics.surface(); + Graphics.end(); + + Graphics.popBatch(); + + Graphics.shader(Shaders.water); + Graphics.begin(); + Draw.rect(renderer.waterSurface.texture(), Core.camera.position.x, Core.camera.position.y, + Core.camera.viewportWidth * Core.camera.zoom, -Core.camera.viewportHeight * Core.camera.zoom); + Graphics.end(); + Graphics.shader(); + } + }, + normal, + walls; + + public void begin(CacheBatch batch){ + batch.setProjectionMatrix(Core.camera.combined); + Graphics.useBatch(batch.drawBatch()); + + Graphics.begin(); + } + + public void end(CacheBatch batch){ + Graphics.end(); + + Graphics.popBatch(); + } +} diff --git a/core/src/io/anuke/mindustry/graphics/Shaders.java b/core/src/io/anuke/mindustry/graphics/Shaders.java index 61e04d8861..b4f146c79b 100644 --- a/core/src/io/anuke/mindustry/graphics/Shaders.java +++ b/core/src/io/anuke/mindustry/graphics/Shaders.java @@ -1,5 +1,6 @@ package io.anuke.mindustry.graphics; +import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.utils.FloatArray; @@ -12,9 +13,25 @@ import io.anuke.ucore.scene.ui.layout.Unit; public class Shaders{ public static final Outline outline = new Outline(); public static final Shield shield = new Shield(); + public static final Water water = new Water(); private static final Vector2 vec = new Vector2(); - + + public static class Water extends Shader{ + + public Water(){ + super("water", "default"); + } + + @Override + public void apply(){ + shader.setUniformf("camerapos", Core.camera.position.x + Core.camera.zoom, Core.camera.position.y); + shader.setUniformf("screensize", Gdx.graphics.getWidth() / Core.cameraScale * Core.camera.zoom, + Gdx.graphics.getHeight() / Core.cameraScale * Core.camera.zoom); + shader.setUniformf("time", Timers.time()); + } + } + public static class Outline extends Shader{ public Color color = new Color(); public float lighten = 0f; diff --git a/core/src/io/anuke/mindustry/world/Block.java b/core/src/io/anuke/mindustry/world/Block.java index a405b8a9e6..bd95f7d78e 100644 --- a/core/src/io/anuke/mindustry/world/Block.java +++ b/core/src/io/anuke/mindustry/world/Block.java @@ -7,6 +7,7 @@ import com.badlogic.gdx.utils.ObjectMap; import com.badlogic.gdx.utils.reflect.ClassReflection; import io.anuke.mindustry.core.GameState.State; import io.anuke.mindustry.entities.TileEntity; +import io.anuke.mindustry.graphics.DrawLayer; import io.anuke.mindustry.graphics.Fx; import io.anuke.mindustry.net.Net; import io.anuke.mindustry.net.NetEvents; @@ -79,6 +80,8 @@ public class Block extends BaseBlock { public boolean expanded = false; /**Max of timers used.*/ public int timers = 0; + /**Draw layer. Only used for 'cached' rendering.*/ + public DrawLayer drawLayer = DrawLayer.normal; /**Layer to draw extra stuff on.*/ public Layer layer = null; /**Extra layer to draw extra extra stuff on.*/ @@ -219,6 +222,8 @@ public class Block extends BaseBlock { tile.entity.update(); } } + + public void drawNonLayer(Tile tile){} public void drawShadow(Tile tile){ diff --git a/core/src/io/anuke/mindustry/world/blocks/Blocks.java b/core/src/io/anuke/mindustry/world/blocks/Blocks.java index a1214be359..45c458d462 100644 --- a/core/src/io/anuke/mindustry/world/blocks/Blocks.java +++ b/core/src/io/anuke/mindustry/world/blocks/Blocks.java @@ -1,5 +1,6 @@ package io.anuke.mindustry.world.blocks; +import io.anuke.mindustry.graphics.DrawLayer; import io.anuke.mindustry.graphics.Fx; import io.anuke.mindustry.resource.Item; import io.anuke.mindustry.resource.ItemStack; @@ -31,6 +32,7 @@ public class Blocks{ solid = true; liquidDrop = Liquid.water; liquid = true; + drawLayer = DrawLayer.water; }}, water = new Floor("water"){{ @@ -38,6 +40,7 @@ public class Blocks{ solid = true; liquidDrop = Liquid.water; liquid = true; + drawLayer = DrawLayer.water; }}, lava = new Floor("lava"){ diff --git a/core/src/io/anuke/mindustry/world/blocks/ProductionBlocks.java b/core/src/io/anuke/mindustry/world/blocks/ProductionBlocks.java index 552e09ed1f..3be7eb6b48 100644 --- a/core/src/io/anuke/mindustry/world/blocks/ProductionBlocks.java +++ b/core/src/io/anuke/mindustry/world/blocks/ProductionBlocks.java @@ -67,8 +67,8 @@ public class ProductionBlocks{ health = 200; inputLiquid = Liquid.water; outputLiquid = Liquid.cryofluid; - inputItem = Item.titanium; - liquidPerItem = 70f; + inputItem = Item.quartz; + liquidPerItem = 50f; itemCapacity = 50; powerUse = 0.1f; size = 2; diff --git a/core/src/io/anuke/mindustry/world/blocks/types/Floor.java b/core/src/io/anuke/mindustry/world/blocks/types/Floor.java index aa6cc5808a..5a75611207 100644 --- a/core/src/io/anuke/mindustry/world/blocks/types/Floor.java +++ b/core/src/io/anuke/mindustry/world/blocks/types/Floor.java @@ -19,41 +19,53 @@ public class Floor extends Block{ super(name); variants = 3; } + + @Override + public void drawNonLayer(Tile tile){ + MathUtils.random.setSeed(tile.id()); + + drawEdges(tile, true); + } @Override public void draw(Tile tile){ MathUtils.random.setSeed(tile.id()); - + Draw.rect(variants > 0 ? (name() + MathUtils.random(1, variants)) : name(), tile.worldx(), tile.worldy()); - - if(blend) + + drawEdges(tile, false); + } + + private void drawEdges(Tile tile, boolean sameLayer){ + if(!blend) return; for(int dx = -1; dx <= 1; dx ++){ for(int dy = -1; dy <= 1; dy ++){ - + if(dx == 0 && dy == 0) continue; - + Tile other = world.tile(tile.x+dx, tile.y+dy); - + if(other == null) continue; - + Block floor = other.floor(); - - if(floor.id <= this.id || !blends.test(floor)) continue; - + + if(floor.id <= this.id || !blends.test(floor) || (floor.drawLayer.ordinal() > this.drawLayer.ordinal() && !sameLayer) || + (sameLayer && floor.drawLayer == this.drawLayer)) continue; + TextureRegion region = Draw.hasRegion(floor.name() + "edge") ? Draw.region(floor.name() + "edge") : - Draw.region(floor.edge + "edge"); - + Draw.region(floor.edge + "edge"); + int sx = -dx*8+2, sy = -dy*8+2; int x = Mathf.clamp(sx, 0, 12); int y = Mathf.clamp(sy, 0, 12); int w = Mathf.clamp(sx+8, 0, 12) - x, h = Mathf.clamp(sy+8, 0, 12) - y; - + float rx = Mathf.clamp(dx*8, 0, 8-w); float ry = Mathf.clamp(dy*8, 0, 8-h); - + tempRegion.setTexture(region.getTexture()); tempRegion.setRegion(region.getRegionX()+x, region.getRegionY()+y+h, w, -h); - + Draw.crect(tempRegion, tile.worldx()-4 + rx, tile.worldy()-4 + ry, w, h); } } diff --git a/core/src/io/anuke/mindustry/world/blocks/types/StaticBlock.java b/core/src/io/anuke/mindustry/world/blocks/types/StaticBlock.java index 4d375f0464..ccc43cc0dc 100644 --- a/core/src/io/anuke/mindustry/world/blocks/types/StaticBlock.java +++ b/core/src/io/anuke/mindustry/world/blocks/types/StaticBlock.java @@ -1,11 +1,13 @@ package io.anuke.mindustry.world.blocks.types; +import io.anuke.mindustry.graphics.DrawLayer; import io.anuke.mindustry.world.Block; public class StaticBlock extends Block{ public StaticBlock(String name) { super(name); + drawLayer = DrawLayer.walls; } }