From b2f9b2ef77bcb034143feeb4c3933efdb9673a2c Mon Sep 17 00:00:00 2001 From: Anuken Date: Sat, 18 Jan 2020 17:03:03 -0500 Subject: [PATCH] Planet cleanup --- core/src/mindustry/content/Planets.java | 4 +- core/src/mindustry/graphics/PlanetMesh.java | 7 ++-- .../maps/planet/PlanetGenerator.java | 34 ++-------------- .../maps/planet/TestPlanetGenerator.java | 40 +++++++++++++++++++ core/src/mindustry/type/Planet.java | 12 ++++-- gradle.properties | 2 +- 6 files changed, 59 insertions(+), 40 deletions(-) create mode 100644 core/src/mindustry/maps/planet/TestPlanetGenerator.java diff --git a/core/src/mindustry/content/Planets.java b/core/src/mindustry/content/Planets.java index 92208e67cf..c3812268d6 100644 --- a/core/src/mindustry/content/Planets.java +++ b/core/src/mindustry/content/Planets.java @@ -1,6 +1,7 @@ package mindustry.content; import mindustry.ctype.*; +import mindustry.maps.planet.*; import mindustry.type.*; public class Planets implements ContentList{ @@ -10,7 +11,8 @@ public class Planets implements ContentList{ @Override public void load(){ starter = new Planet("//TODO"){{ - + detail = 6; + generator = new TestPlanetGenerator(); }}; } } diff --git a/core/src/mindustry/graphics/PlanetMesh.java b/core/src/mindustry/graphics/PlanetMesh.java index cd851149a1..de98f4b88d 100644 --- a/core/src/mindustry/graphics/PlanetMesh.java +++ b/core/src/mindustry/graphics/PlanetMesh.java @@ -18,9 +18,10 @@ public class PlanetMesh{ private boolean lines = false; private float radius = 1f, intensity = 0.2f; - private PlanetGenerator gen = new PlanetGenerator(); + private final PlanetGenerator gen; - public PlanetMesh(int divisions){ + public PlanetMesh(int divisions, PlanetGenerator gen){ + this.gen = gen; this.grid = PlanetGrid.newGrid(divisions); int vertices = grid.tiles.length * 12 * (3 + 3 + 1); @@ -115,7 +116,7 @@ public class PlanetMesh{ } private Color color(Vec3 v){ - return gen.getColor(v, elevation(v)); + return gen.getColor(v); } private void verts(Vec3 a, Vec3 b, Vec3 c, Vec3 normal, Color color){ diff --git a/core/src/mindustry/maps/planet/PlanetGenerator.java b/core/src/mindustry/maps/planet/PlanetGenerator.java index e1f97f9df3..c1b5872fc0 100644 --- a/core/src/mindustry/maps/planet/PlanetGenerator.java +++ b/core/src/mindustry/maps/planet/PlanetGenerator.java @@ -1,37 +1,9 @@ package mindustry.maps.planet; import arc.graphics.*; -import arc.math.*; import arc.math.geom.*; -import arc.util.*; -import arc.util.noise.*; -public class PlanetGenerator{ - Pixmap pix = new Pixmap("planets/colors.png"); - Simplex noise = new Simplex(); - int waterLevel = 5; - float water = waterLevel / (float)(pix.getHeight()); - float scl = 5f; - - public float getHeight(Vec3 position){ - position = Tmp.v33.set(position).scl(scl); - - float height = Mathf.pow((float)noise.octaveNoise3D(7, 0.48f, 1f/3f, position.x, position.y, position.z), 2.4f); - if(height <= water){ - return water; - } - return height; - } - - public Color getColor(Vec3 position, float height){ - position = Tmp.v33.set(position).scl(scl); - float rad = scl; - float temp = Mathf.clamp(Math.abs(position.y * 2f) / (rad)); - float tnoise = (float)noise.octaveNoise3D(7, 0.48f, 1f/3f, position.x, position.y + 999f, position.z); - temp = Mathf.lerp(temp, tnoise, 0.5f); - height *= 1.2f; - height = Mathf.clamp(height); - - return Tmp.c1.set(pix.getPixel((int)(temp * (pix.getWidth()-1)), (int)((1f-height) * (pix.getHeight()-1)))); - } +public interface PlanetGenerator{ + float getHeight(Vec3 position); + Color getColor(Vec3 position); } diff --git a/core/src/mindustry/maps/planet/TestPlanetGenerator.java b/core/src/mindustry/maps/planet/TestPlanetGenerator.java new file mode 100644 index 0000000000..ea04eb17c6 --- /dev/null +++ b/core/src/mindustry/maps/planet/TestPlanetGenerator.java @@ -0,0 +1,40 @@ +package mindustry.maps.planet; + +import arc.graphics.*; +import arc.math.*; +import arc.math.geom.*; +import arc.util.*; +import arc.util.noise.*; + +public class TestPlanetGenerator implements PlanetGenerator{ + Pixmap pix = new Pixmap("planets/colors.png"); + Simplex noise = new Simplex(); + int waterLevel = 5; + float water = waterLevel / (float)(pix.getHeight()); + float scl = 5f; + + @Override + public float getHeight(Vec3 position){ + position = Tmp.v33.set(position).scl(scl); + + float height = Mathf.pow((float)noise.octaveNoise3D(7, 0.48f, 1f/3f, position.x, position.y, position.z), 2.4f); + if(height <= water){ + return water; + } + return height; + } + + @Override + public Color getColor(Vec3 position){ + float height = getHeight(position); + position = Tmp.v33.set(position).scl(scl); + float rad = scl; + float temp = Mathf.clamp(Math.abs(position.y * 2f) / (rad)); + float tnoise = (float)noise.octaveNoise3D(7, 0.48f, 1f/3f, position.x, position.y + 999f, position.z); + temp = Mathf.lerp(temp, tnoise, 0.5f); + height *= 1.2f; + height = Mathf.clamp(height); + + return Tmp.c1.set(pix.getPixel((int)(temp * (pix.getWidth()-1)), (int)((1f-height) * (pix.getHeight()-1)))); + } +} diff --git a/core/src/mindustry/type/Planet.java b/core/src/mindustry/type/Planet.java index a8cc63d491..959b621f52 100644 --- a/core/src/mindustry/type/Planet.java +++ b/core/src/mindustry/type/Planet.java @@ -2,15 +2,21 @@ package mindustry.type; import arc.scene.ui.layout.*; import arc.util.ArcAnnotate.*; -import arc.util.*; import mindustry.ctype.*; import mindustry.graphics.*; +import mindustry.maps.planet.*; public class Planet extends UnlockableContent{ /** Mesh used for rendering. Created on load(). */ public PlanetMesh mesh; /** Grid used for the sectors on the planet. */ public @NonNull PlanetGrid grid; + /** Generator that will make the planet. */ + public @NonNull PlanetGenerator generator; + /** Detail in divisions. Must be between 1 and 10. 6 is a good number.*/ + public int detail = 3; + /** Size in terms of divisions. This only controls the amount of sectors on the planet, not the visuals. */ + public int size = 3; public Planet(String name){ super(name); @@ -18,9 +24,7 @@ public class Planet extends UnlockableContent{ @Override public void load(){ - Time.mark(); - mesh = new PlanetMesh(6); - Log.info("Time to generate planet mesh: {0}", Time.elapsed()); + mesh = new PlanetMesh(detail, generator); } /** Planets cannot be viewed in the database dialog. */ diff --git a/gradle.properties b/gradle.properties index 06c53cec45..ac3d562c4a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ org.gradle.daemon=true org.gradle.jvmargs=-Xms256m -Xmx1024m -archash=ff62d39e0fa294117a885010b05b2b29412b4024 +archash=ec97ef07c9e241dbc26ef5b5a83ff87a2e40b11a