diff --git a/core/assets/planets/colors.png b/core/assets/planets/colors.png new file mode 100644 index 0000000000..5efd5d38e0 Binary files /dev/null and b/core/assets/planets/colors.png differ diff --git a/core/src/mindustry/ClientLauncher.java b/core/src/mindustry/ClientLauncher.java index d1819b3a8f..6c5909a798 100644 --- a/core/src/mindustry/ClientLauncher.java +++ b/core/src/mindustry/ClientLauncher.java @@ -90,10 +90,7 @@ public abstract class ClientLauncher extends ApplicationCore implements Platform assets.load(mods); assets.load(schematics); - assets.loadRun("contentinit", ContentLoader.class, () -> { - content.init(); - content.load(); - }); + assets.loadRun("contentinit", ContentLoader.class, () -> content.init(), () -> content.load()); } @Override diff --git a/core/src/mindustry/graphics/PlanetMesh.java b/core/src/mindustry/graphics/PlanetMesh.java index fc2436c5a1..cd851149a1 100644 --- a/core/src/mindustry/graphics/PlanetMesh.java +++ b/core/src/mindustry/graphics/PlanetMesh.java @@ -3,12 +3,11 @@ package mindustry.graphics; import arc.graphics.*; import arc.graphics.VertexAttributes.*; import arc.graphics.gl.*; -import arc.math.*; import arc.math.geom.*; import arc.util.ArcAnnotate.*; import arc.util.*; -import arc.util.noise.*; import mindustry.graphics.PlanetGrid.*; +import mindustry.maps.planet.*; public class PlanetMesh{ private float[] floats = new float[3 + 3 + 1]; @@ -16,19 +15,12 @@ public class PlanetMesh{ private Mesh mesh; private PlanetGrid grid; - private float color; - private boolean lines; - private float radius; + private boolean lines = false; + private float radius = 1f, intensity = 0.2f; - private Simplex sim = new Simplex(); - private RidgedPerlin rid = new RidgedPerlin(2, 2); - private Color[] colors = {Color.royal, Color.royal, Color.royal, Color.tan, Color.valueOf("3f9a50"), Color.valueOf("3f9a50"), Color.gray, Color.white, Color.white}; - private Vec3 normal = new Vec3(); + private PlanetGenerator gen = new PlanetGenerator(); - public PlanetMesh(int divisions, float radius, boolean lines, Color color){ - this.radius = radius; - this.lines = lines; - this.color = color.toFloatBits(); + public PlanetMesh(int divisions){ this.grid = PlanetGrid.newGrid(divisions); int vertices = grid.tiles.length * 12 * (3 + 3 + 1); @@ -77,7 +69,7 @@ public class PlanetMesh{ } for(Corner corner : c){ - corner.v.setLength(radius + elevation(corner.bv)); + corner.v.setLength(radius + elevation(corner.bv)*intensity); } for(Corner corner : c){ @@ -115,20 +107,15 @@ public class PlanetMesh{ } private Vec3 normal(Vec3 v1, Vec3 v2, Vec3 v3){ - return normal.set(v2).sub(v1).crs(v3.x - v1.x, v3.y - v1.y, v3.z - v1.z).nor(); + return Tmp.v32.set(v2).sub(v1).crs(v3.x - v1.x, v3.y - v1.y, v3.z - v1.z).nor(); } private float elevation(Vec3 v){ - if(lines) return 0; - - Color c = color(v); - if(c == Color.royal) return 0.19f; - return ((float)sim.octaveNoise3D(8, 0.7, 1 / 2.0, v.x, v.y, v.z)) / 3f + (rid.getValue(v.x, v.y, v.z, 1f) + 1f) / 12f; + return gen.getHeight(v); } private Color color(Vec3 v){ - float f = ((float)sim.octaveNoise3D(6, 0.6, 1 / 2.0, v.x, v.y, v.z)) * 0.5f + 0.5f * ((rid.getValue(v.x, v.y, v.z, 1f) + 1f) / 2f); - return colors[Mathf.clamp((int)(f * colors.length), 0, colors.length - 1)]; + return gen.getColor(v, elevation(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 new file mode 100644 index 0000000000..e1f97f9df3 --- /dev/null +++ b/core/src/mindustry/maps/planet/PlanetGenerator.java @@ -0,0 +1,37 @@ +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)))); + } +} diff --git a/core/src/mindustry/type/Planet.java b/core/src/mindustry/type/Planet.java index eddcef84bb..a8cc63d491 100644 --- a/core/src/mindustry/type/Planet.java +++ b/core/src/mindustry/type/Planet.java @@ -2,23 +2,25 @@ package mindustry.type; import arc.scene.ui.layout.*; import arc.util.ArcAnnotate.*; +import arc.util.*; import mindustry.ctype.*; import mindustry.graphics.*; public class Planet extends UnlockableContent{ - /** Mesh used for rendering. */ - public @NonNull PlanetMesh mesh; + /** Mesh used for rendering. Created on load(). */ + public PlanetMesh mesh; /** Grid used for the sectors on the planet. */ public @NonNull PlanetGrid grid; - public Planet(String name, PlanetMesh mesh){ + public Planet(String name){ super(name); - this.mesh = mesh; } - //mods - Planet(String name){ - super(name); + @Override + public void load(){ + Time.mark(); + mesh = new PlanetMesh(6); + Log.info("Time to generate planet mesh: {0}", Time.elapsed()); } /** Planets cannot be viewed in the database dialog. */ diff --git a/core/src/mindustry/ui/dialogs/DeployDialog.java b/core/src/mindustry/ui/dialogs/DeployDialog.java index 812043d4d1..e2917b9798 100644 --- a/core/src/mindustry/ui/dialogs/DeployDialog.java +++ b/core/src/mindustry/ui/dialogs/DeployDialog.java @@ -123,7 +123,7 @@ public class DeployDialog extends FloatingDialog{ setFilter(TextureFilter.Linear); }}){{ float[] time = {0}; - setColor(Color.fromGray(0.3f)); + setColor(Color.gray(0.3f)); setScale(1.5f); update(() -> { setOrigin(Align.center); @@ -141,7 +141,7 @@ public class DeployDialog extends FloatingDialog{ Stack sub = new Stack(); if(slot.getZone() != null){ - sub.add(new Table(f -> f.margin(4f).add(new Image()).color(Color.fromGray(0.1f)).grow())); + sub.add(new Table(f -> f.margin(4f).add(new Image()).color(Color.gray(0.1f)).grow())); sub.add(new Table(f -> f.margin(4f).add(new Image(slot.getZone().preview).setScaling(Scaling.fit)).update(img -> { TextureRegionDrawable draw = (TextureRegionDrawable)img.getDrawable(); @@ -255,7 +255,7 @@ public class DeployDialog extends FloatingDialog{ } stack.setSize(Tmp.v1.x, Tmp.v1.y); - stack.add(new Table(t -> t.margin(4f).add(new Image(node.zone.preview).setScaling(Scaling.stretch)).color(node.zone.unlocked() ? Color.darkGray : Color.fromGray(0.2f)).grow())); + stack.add(new Table(t -> t.margin(4f).add(new Image(node.zone.preview).setScaling(Scaling.stretch)).color(node.zone.unlocked() ? Color.darkGray : Color.gray(0.2f)).grow())); stack.update(() -> stack.setPosition(node.x + panX + width / 2f, node.y + panY + height / 2f, Align.center)); Button button = new Button(Styles.squaret);