From 6871db7155277e37ab86a9cb903e4c4954185653 Mon Sep 17 00:00:00 2001 From: Anuken Date: Fri, 21 Feb 2020 22:58:18 -0500 Subject: [PATCH] Visual tweaks --- core/assets/shaders/planet.vertex.glsl | 4 +- .../mindustry/graphics/PlanetRenderer.java | 7 +-- .../maps/generators/BasicGenerator.java | 48 ++++++++++++++++++- .../maps/planet/TestPlanetGenerator.java | 4 ++ gradle.properties | 2 +- 5 files changed, 57 insertions(+), 8 deletions(-) diff --git a/core/assets/shaders/planet.vertex.glsl b/core/assets/shaders/planet.vertex.glsl index 1c58d6169a..f78ad41b94 100755 --- a/core/assets/shaders/planet.vertex.glsl +++ b/core/assets/shaders/planet.vertex.glsl @@ -6,12 +6,12 @@ varying vec4 v_col; const vec3 ambientColor = vec3(1.0); const vec3 ambientDir = normalize(vec3(1.0, 1.0, 1.0)); -const vec3 diffuse = vec3(0); +const vec3 diffuse = vec3(0.3); const vec3 v1 = vec3(1.0, 0.0, 1.0); const vec3 v2 = vec3(1.0, 0.5, 0.0); void main(){ - vec3 norc = ambientColor * lerp(vec3(1.0), diffuse, 1.0 - clamp((dot(a_normal, ambientDir) + 1.0) / 2.0, 0.0, 1.0)); + vec3 norc = ambientColor * (diffuse + vec3(clamp((dot(a_normal, ambientDir) + 1.0) / 2.0, 0.0, 1.0))); v_col = a_color * vec4(norc, 1.0); gl_Position = u_projModelView * a_position; diff --git a/core/src/mindustry/graphics/PlanetRenderer.java b/core/src/mindustry/graphics/PlanetRenderer.java index 06fac12d65..c960b69dac 100644 --- a/core/src/mindustry/graphics/PlanetRenderer.java +++ b/core/src/mindustry/graphics/PlanetRenderer.java @@ -17,7 +17,7 @@ import mindustry.world.*; import static mindustry.Vars.*; public class PlanetRenderer implements PlanetGenerator{ - private static final Color outlineColor = Pal.accent.cpy().a(0.7f); + private static final Color outlineColor = Pal.accent.cpy().a(0.6f); private static final float camLength = 4f, outlineRad = 1.15f; private static final boolean drawRect = false; @@ -105,15 +105,16 @@ public class PlanetRenderer implements PlanetGenerator{ if(Core.input.keyDown(KeyCode.MOUSE_LEFT)){ float upV = cam.position.angle(Vec3.Y); + float xscale = 9f, yscale = 10f; float margin = 1; //scale X speed depending on polar coordinate float speed = 1f - Math.abs(upV - 90) / 90f; - cam.position.rotate(cam.up, (v.x - lastX) / 10 * speed); + cam.position.rotate(cam.up, (v.x - lastX) / xscale * speed); //prevent user from scrolling all the way up and glitching it out - float amount = (v.y - lastY) / 10; + float amount = (v.y - lastY) / yscale; amount = Mathf.clamp(upV + amount, margin, 180f - margin) - upV; cam.position.rotate(Tmp.v31.set(cam.up).rotate(cam.direction, 90), amount); diff --git a/core/src/mindustry/maps/generators/BasicGenerator.java b/core/src/mindustry/maps/generators/BasicGenerator.java index 22d8a4500a..daf522dc1d 100644 --- a/core/src/mindustry/maps/generators/BasicGenerator.java +++ b/core/src/mindustry/maps/generators/BasicGenerator.java @@ -12,10 +12,11 @@ import mindustry.world.*; import java.util.*; -import static mindustry.Vars.world; +import static mindustry.Vars.*; public abstract class BasicGenerator implements WorldGenerator{ protected static final DistanceHeuristic manhattan = (x1, y1, x2, y2) -> Math.abs(x1 - x2) + Math.abs(y1 - y2); + protected static final ShortArray ints1 = new ShortArray(), ints2 = new ShortArray(); protected Simplex sim = new Simplex(); protected Simplex sim2 = new Simplex(); @@ -44,8 +45,38 @@ public abstract class BasicGenerator implements WorldGenerator{ } + public void median(int radius){ + median(radius, 0.5); + } + + public void median(int radius, double percentile){ + short[] blocks = new short[tiles.width * tiles.height]; + short[] floors = new short[blocks.length]; + + tiles.each((x, y) -> { + ints1.clear(); + ints2.clear(); + Geometry.circle(x, y, width, height, radius, (cx, cy) -> { + ints1.add(tiles.getn(cx, cy).floorID()); + ints2.add(tiles.getn(cx, cy).blockID()); + }); + ints1.sort(); + ints2.sort(); + + floors[x + y*width] = ints1.get(Mathf.clamp((int)(ints1.size * percentile), 0, ints1.size - 1)); + blocks[x + y*width] = ints2.get(Mathf.clamp((int)(ints2.size * percentile), 0, ints2.size - 1)); + }); + + pass((x, y) -> { + block = content.block(blocks[x + y * width]); + floor = content.block(floors[x + y * width]); + }); + } + public void ores(Array ores){ pass((x, y) -> { + if(floor.asFloor().isLiquid) return; + int offsetX = x - 4, offsetY = y + 23; for(int i = ores.size - 1; i >= 0; i--){ Block entry = ores.get(i); @@ -234,6 +265,19 @@ public abstract class BasicGenerator implements WorldGenerator{ return out; } + public void trimDark(){ + for(Tile tile : tiles){ + boolean any = world.getDarkness(tile.x, tile.y) > 0; + for(int i = 0; i < 4 && !any; i++){ + any = world.getDarkness(tile.x + Geometry.d4[i].x, tile.y + Geometry.d4[i].y) > 0; + } + + if(any){ + tile.setBlock(tile.floor().wall); + } + } + } + public void inverseFloodFill(Tile start){ IntArray arr = new IntArray(); arr.add(start.pos()); @@ -254,7 +298,7 @@ public abstract class BasicGenerator implements WorldGenerator{ } for(Tile tile : tiles){ - if((tile.cost != 2 && tile.block() == Blocks.air) || world.getDarkness(tile.x, tile.y) != 0){ + if(tile.cost != 2 && tile.block() == Blocks.air){ tile.setBlock(tile.floor().wall); } } diff --git a/core/src/mindustry/maps/planet/TestPlanetGenerator.java b/core/src/mindustry/maps/planet/TestPlanetGenerator.java index 6203144ae1..0fa1814e9d 100644 --- a/core/src/mindustry/maps/planet/TestPlanetGenerator.java +++ b/core/src/mindustry/maps/planet/TestPlanetGenerator.java @@ -149,6 +149,10 @@ public class TestPlanetGenerator implements PlanetGenerator{ } } + trimDark(); + + median(2); + schematics.placeLoadout(Loadouts.advancedShard, spawn.x, spawn.y); } diff --git a/gradle.properties b/gradle.properties index 21c1a4ca33..c7c4123c06 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ org.gradle.daemon=true org.gradle.jvmargs=-Xms256m -Xmx1024m -archash=f1e9b0b63e8d99047324dea2d982a00ba6364497 +archash=e1a251eb2e98fb858e4132006fdc51da1a441586