diff --git a/core/assets-raw/sprites/blocks/environment/dark-panel-1.png b/core/assets-raw/sprites/blocks/environment/dark-panel-1.png index 3f02f3706f..4eebdd9f44 100644 Binary files a/core/assets-raw/sprites/blocks/environment/dark-panel-1.png and b/core/assets-raw/sprites/blocks/environment/dark-panel-1.png differ diff --git a/core/src/mindustry/content/Planets.java b/core/src/mindustry/content/Planets.java index ce71c8a849..dc3b48c621 100644 --- a/core/src/mindustry/content/Planets.java +++ b/core/src/mindustry/content/Planets.java @@ -1,8 +1,10 @@ package mindustry.content; import arc.graphics.*; +import arc.math.*; import arc.math.geom.*; -import arc.util.noise.*; +import arc.struct.*; +import arc.util.*; import mindustry.ctype.*; import mindustry.game.*; import mindustry.graphics.*; @@ -85,18 +87,18 @@ public class Planets implements ContentList{ } }; - meshLoader = () -> new HexMesh(this, new HexMesher(){ - Simplex sim = new Simplex(id); - @Override - public float getHeight(Vec3 position){ - return (float)sim.octaveNoise3D(2, 0.55, 0.45f, 5f + position.x, 5f + position.y, 5f + position.z) * 14f; + meshLoader = () -> { + Seq meshes = new Seq<>(); + + meshes.add(new NoiseMesh(this, 0, 2, Pal.gray, radius, 2, 0.55f, 0.45f, 14f)); + int am = Mathf.random(3, 6); + + for(int j = 0; j < am; j++){ + meshes.add(new MatMesh(new NoiseMesh(this, j + 1, 1, Pal.gray, 0.025f + Mathf.random(0.046f), 2, 0.6f, 0.38f, 20f), new Mat3D().setToTranslation(Tmp.v31.setToRandomDirection().setLength(Mathf.random(0.3f, 1.3f))))); } - @Override - public Color getColor(Vec3 position){ - return Pal.gray; - } - }, 2, Shaders.planet); + return new MultiMesh(meshes.toArray(GenericMesh.class)); + }; }}; } diff --git a/core/src/mindustry/core/ContentLoader.java b/core/src/mindustry/core/ContentLoader.java index e00fec3061..6022f7bc9a 100644 --- a/core/src/mindustry/core/ContentLoader.java +++ b/core/src/mindustry/core/ContentLoader.java @@ -151,11 +151,6 @@ public class ContentLoader{ ColorMapper.load(); } - public void dispose(){ - initialize(Content::dispose); - clear(); - } - /** Get last piece of content created for error-handling purposes. */ public @Nullable Content getLastAdded(){ return lastAdded; diff --git a/core/src/mindustry/ctype/Content.java b/core/src/mindustry/ctype/Content.java index 4103f4899e..fb0679bf9b 100644 --- a/core/src/mindustry/ctype/Content.java +++ b/core/src/mindustry/ctype/Content.java @@ -6,7 +6,7 @@ import mindustry.*; import mindustry.mod.Mods.*; /** Base class for a content type that is loaded in {@link mindustry.core.ContentLoader}. */ -public abstract class Content implements Comparable, Disposable{ +public abstract class Content implements Comparable{ public short id; /** Info on which mod this content was loaded from. */ public ModContentInfo minfo = new ModContentInfo(); @@ -39,11 +39,6 @@ public abstract class Content implements Comparable, Disposable{ return minfo.error != null; } - @Override - public void dispose(){ - //does nothing by default - } - @Override public int compareTo(Content c){ return Integer.compare(id, c.id); diff --git a/core/src/mindustry/graphics/g3d/GenericMesh.java b/core/src/mindustry/graphics/g3d/GenericMesh.java new file mode 100644 index 0000000000..30aa5b85fa --- /dev/null +++ b/core/src/mindustry/graphics/g3d/GenericMesh.java @@ -0,0 +1,7 @@ +package mindustry.graphics.g3d; + +import arc.math.geom.*; + +public interface GenericMesh{ + void render(Mat3D projection, Mat3D transform); +} diff --git a/core/src/mindustry/graphics/g3d/HexMesh.java b/core/src/mindustry/graphics/g3d/HexMesh.java index e3ba7b9f27..ebe7deae8d 100644 --- a/core/src/mindustry/graphics/g3d/HexMesh.java +++ b/core/src/mindustry/graphics/g3d/HexMesh.java @@ -15,6 +15,9 @@ public class HexMesh extends PlanetMesh{ super(planet, MeshBuilder.buildHex(mesher, divisions, false, planet.radius, 0.2f), shader); } + public HexMesh(){ + } + @Override public void preRender(){ Shaders.planet.lightDir.set(planet.solarSystem.position).sub(planet.position).rotate(Vec3.Y, planet.getRotation()).nor(); diff --git a/core/src/mindustry/graphics/g3d/MatMesh.java b/core/src/mindustry/graphics/g3d/MatMesh.java new file mode 100644 index 0000000000..8a0473f1f1 --- /dev/null +++ b/core/src/mindustry/graphics/g3d/MatMesh.java @@ -0,0 +1,22 @@ +package mindustry.graphics.g3d; + +import arc.math.geom.*; + +//TODO maybe this is a bad idea +/** A GenericMesh that wraps and applies an additional transform to a generic mesh. */ +public class MatMesh implements GenericMesh{ + private static final Mat3D tmp = new Mat3D(); + + GenericMesh mesh; + Mat3D mat; + + public MatMesh(GenericMesh mesh, Mat3D mat){ + this.mesh = mesh; + this.mat = mat; + } + + @Override + public void render(Mat3D projection, Mat3D transform){ + mesh.render(projection, tmp.set(transform).mul(mat)); + } +} diff --git a/core/src/mindustry/graphics/g3d/MultiMesh.java b/core/src/mindustry/graphics/g3d/MultiMesh.java new file mode 100644 index 0000000000..8f0c60563b --- /dev/null +++ b/core/src/mindustry/graphics/g3d/MultiMesh.java @@ -0,0 +1,18 @@ +package mindustry.graphics.g3d; + +import arc.math.geom.*; + +public class MultiMesh implements GenericMesh{ + GenericMesh[] meshes; + + public MultiMesh(GenericMesh... meshes){ + this.meshes = meshes; + } + + @Override + public void render(Mat3D projection, Mat3D transform){ + for(var v : meshes){ + v.render(projection, transform); + } + } +} diff --git a/core/src/mindustry/graphics/g3d/NoiseMesh.java b/core/src/mindustry/graphics/g3d/NoiseMesh.java new file mode 100644 index 0000000000..b796d7b67c --- /dev/null +++ b/core/src/mindustry/graphics/g3d/NoiseMesh.java @@ -0,0 +1,28 @@ +package mindustry.graphics.g3d; + +import arc.graphics.*; +import arc.math.geom.*; +import arc.util.noise.*; +import mindustry.graphics.*; +import mindustry.type.*; + +public class NoiseMesh extends HexMesh{ + Simplex sim; + + public NoiseMesh(Planet planet, int seed, int divisions, Color color, float radius, int octaves, float persistence, float scale, float mag){ + this.planet = planet; + this.sim = new Simplex(planet.id + seed); + this.shader = Shaders.planet; + this.mesh = MeshBuilder.buildHex(new HexMesher(){ + @Override + public float getHeight(Vec3 position){ + return (float)sim.octaveNoise3D(octaves, persistence, scale, 5f + position.x, 5f + position.y, 5f + position.z) * mag; + } + + @Override + public Color getColor(Vec3 position){ + return color; + } + }, divisions, false, radius, 0.2f); + } +} diff --git a/core/src/mindustry/graphics/g3d/PlanetMesh.java b/core/src/mindustry/graphics/g3d/PlanetMesh.java index 23e7966d33..8fe1547a5b 100644 --- a/core/src/mindustry/graphics/g3d/PlanetMesh.java +++ b/core/src/mindustry/graphics/g3d/PlanetMesh.java @@ -3,14 +3,13 @@ package mindustry.graphics.g3d; import arc.graphics.*; import arc.graphics.gl.*; import arc.math.geom.*; -import arc.util.*; import mindustry.type.*; /** Defines a mesh that is rendered for a planet. Subclasses provide a mesh and a shader. */ -public abstract class PlanetMesh implements Disposable{ - protected final Mesh mesh; - protected final Planet planet; - protected final Shader shader; +public abstract class PlanetMesh implements GenericMesh{ + protected Mesh mesh; + protected Planet planet; + protected Shader shader; public PlanetMesh(Planet planet, Mesh mesh, Shader shader){ this.planet = planet; @@ -18,9 +17,12 @@ public abstract class PlanetMesh implements Disposable{ this.shader = shader; } + public PlanetMesh(){} + /** Should be overridden to set up any shader parameters such as planet position, normals, etc. */ public abstract void preRender(); + @Override public void render(Mat3D projection, Mat3D transform){ preRender(); shader.bind(); @@ -29,9 +31,4 @@ public abstract class PlanetMesh implements Disposable{ shader.apply(); mesh.render(shader, Gl.triangles); } - - @Override - public void dispose(){ - mesh.dispose(); - } } diff --git a/core/src/mindustry/graphics/g3d/PlanetRenderer.java b/core/src/mindustry/graphics/g3d/PlanetRenderer.java index ed526d17a6..1523a57e0d 100644 --- a/core/src/mindustry/graphics/g3d/PlanetRenderer.java +++ b/core/src/mindustry/graphics/g3d/PlanetRenderer.java @@ -173,8 +173,8 @@ public class PlanetRenderer implements Disposable{ } batch.proj(cam.combined); - renderOrbit(planet); + renderOrbit(planet); } public void renderOrbit(Planet planet){ diff --git a/core/src/mindustry/type/Planet.java b/core/src/mindustry/type/Planet.java index c044198113..31932d51e3 100644 --- a/core/src/mindustry/type/Planet.java +++ b/core/src/mindustry/type/Planet.java @@ -20,7 +20,7 @@ public class Planet extends UnlockableContent{ /** intersect() temp var. */ private static final Vec3 intersectResult = new Vec3(); /** Mesh used for rendering. Created on load() - will be null on the server! */ - public @Nullable PlanetMesh mesh; + public @Nullable GenericMesh mesh; /** Position in global coordinates. Will be 0,0,0 until the Universe updates it. */ public Vec3 position = new Vec3(); /** Grid used for the sectors on the planet. Null if this planet can't be landed on. */ @@ -76,7 +76,7 @@ public class Planet extends UnlockableContent{ /** Satellites orbiting this planet. */ public Seq satellites = new Seq<>(); /** Loads the mesh. Clientside only. Defaults to a boring sphere mesh. */ - protected Prov meshLoader = () -> new ShaderSphereMesh(this, Shaders.unlit, 2); + protected Prov meshLoader = () -> new ShaderSphereMesh(this, Shaders.unlit, 2); public Planet(String name, Planet parent, float radius){ super(name); @@ -217,9 +217,6 @@ public class Planet extends UnlockableContent{ /** Regenerates the planet mesh. For debugging only. */ public void reloadMesh(){ - if(mesh != null){ - mesh.dispose(); - } mesh = meshLoader.get(); } @@ -249,14 +246,6 @@ public class Planet extends UnlockableContent{ } - @Override - public void dispose(){ - if(mesh != null){ - mesh.dispose(); - mesh = null; - } - } - /** Gets a sector a tile position. */ public Sector getSector(Ptile tile){ return sectors.get(tile.id);