diff --git a/CONTRACTS.md b/CONTRACTS.md index ec0a742f9..880116d7c 100644 --- a/CONTRACTS.md +++ b/CONTRACTS.md @@ -217,8 +217,8 @@ running Iris is the pack publisher's responsibility. (`InvocationContext.world()`), to service calls and to hooks. Use `WorldStates` (or the same rules) for its store. A placement a tool makes outside those worlds (a studio paste) gets a `PackWorld` of its own: the pack's resources and settings, a seed the host picks, a store closed when the placement ends, and no hooks. `world()` never throws. -- Answer `PackWorld.seed(purpose)` with `WorldRandom.purposeSeed(seed(), purpose)`, except for ids of your own built-ins - whose existing worlds depend on other seeds; the same world and purpose always get the same seed. +- Don't override `PackWorld.seed(purpose)`: its default, `WorldRandom.purposeSeed(seed(), purpose)`, is the rule for + every purpose, the host's own built-ins included. - Answer `PackWorld.running()` for a world the host runs, empty for a tool's world. Its `layout()` covers every column of the world (not one chunk), with the same values chunk stages read; its `settings()` are the settings at a column and a biome's declarations as chunk stages see them; `highest` is the platform's highest block now; `caveFloors` are @@ -259,8 +259,8 @@ running Iris is the pack publisher's responsibility. (`EXPRESSIONS`, `IMAGE_MAPS` among them); rendering a value type with the host's own description of the same JSON is allowed. - Serve `PackResources.noise()`: build each style's noise from the host's generators, expressions and image maps, - the same values for the same style and seed, cached per pack snapshot; an unknown style name is flat, a missing - expression falls back to the base style, and a missing image map fails. + the same values for the same style and seed, cached per pack snapshot; an unknown style name, a missing expression and a + missing image map fail. Answer `NoiseSampler.signed(...)` with the generator's own signed read (and its per-thread coordinate memo) when it has one; the default is `sample * 2 - 1`. Answer `NoiseSampler.scaled(factor)` by building the generator again with the factor folded into its scale, leaving the sampler it diff --git a/DESIGN.md b/DESIGN.md index 2e301dfd0..618fa26c5 100644 --- a/DESIGN.md +++ b/DESIGN.md @@ -938,7 +938,8 @@ Why these lines: of one field again and again, so the memo is the difference between caves that cost what they always did and caves that do not. A default method (`sample * 2 - 1`) keeps every other sampler valid. - **Style names are text with `@Ref(NOISE_STYLE)`**, not an enum: the host owns the list, and an API enum would - pin it. An unknown name samples flat, as Iris has always read one. + pin it. An unknown name fails when the noise is built, as a missing expression or image map does: a silent + flat noise hides the pack's typo. - **`isFlat()` is stricter than Iris's**: a flat base style with an expression or image map is not flat. - **Block properties are text.** `{"waterlogged": true}` decodes to `"true"`, which is what the platform's state key holds; the host's studio description may accept the JSON types it accepted before. diff --git a/README.md b/README.md index a6a955059..714519aa9 100644 --- a/README.md +++ b/README.md @@ -148,9 +148,8 @@ stage uses its own stream within one invocation and must not share or keep it. A module's own world-wide randoms and noise take `world.seed(purpose)`, the seed the world gives a purpose id such as `example:moss/patches`: the same for the same world and purpose, independent across purposes, so two modules never -mix the world seed into the same value by hand. Hosts answer `WorldRandom.purposeSeed(world.seed(), purpose)`, pinned -like every other `WorldRandom` value; Iris answers its built-ins' `iris:seed/*` purposes with the seeds its worlds -always had. +mix the world seed into the same value by hand. It is `WorldRandom.purposeSeed(world.seed(), purpose)` for every +purpose and host (a default method of `PackWorld`), pinned like every other `WorldRandom` value. ## The mantle pipeline and reach diff --git a/api/src/main/java/com/volmit/noise/NoiseFactory.java b/api/src/main/java/com/volmit/noise/NoiseFactory.java index 8dc0baeb6..195dcf93c 100644 --- a/api/src/main/java/com/volmit/noise/NoiseFactory.java +++ b/api/src/main/java/com/volmit/noise/NoiseFactory.java @@ -13,9 +13,8 @@ public interface NoiseFactory { *
A style with its own seed ({@link NoiseStyle#seed()}) ignores {@code seed}: the host rolls it from that number * and the seed of the world the pack generates, so every reader of the same seeded style gets the same noise. * - *
A style name the host does not know samples as {@link NoiseStyle#FLAT}, and an expression the pack does not - * have falls back to the base style, as packs have always been read. An image map the pack does not have, or cannot - * use as noise, throws {@link IllegalArgumentException}. + *
A style name the host does not know, an expression the pack does not have, and an image map the pack does not + * have or cannot use as noise throw {@link IllegalArgumentException}. */ NoiseSampler sampler(NoiseStyle style, long seed); } diff --git a/api/src/main/java/com/volmit/noise/NoiseStyle.java b/api/src/main/java/com/volmit/noise/NoiseStyle.java index 7de7e0ccc..03c251dcb 100644 --- a/api/src/main/java/com/volmit/noise/NoiseStyle.java +++ b/api/src/main/java/com/volmit/noise/NoiseStyle.java @@ -28,7 +28,7 @@ public final class NoiseStyle { public static final String FLAT = "FLAT"; @Ref(Reference.NOISE_STYLE) - @Desc("The noise generator. Used when neither expression nor imageMap is set, and when an expression fails.") + @Desc("The noise generator. Used when neither expression nor imageMap is set.") private String style = FLAT; @Desc("Above 0, the noise is turned into cells of this frequency.") diff --git a/api/src/main/java/com/volmit/world/PackWorld.java b/api/src/main/java/com/volmit/world/PackWorld.java index 419fd2b2e..9d583db44 100644 --- a/api/src/main/java/com/volmit/world/PackWorld.java +++ b/api/src/main/java/com/volmit/world/PackWorld.java @@ -3,6 +3,7 @@ package com.volmit.world; import com.volmit.ModuleLog; import com.volmit.config.PackSettings; import com.volmit.placement.Placements; +import com.volmit.random.WorldRandom; import com.volmit.resource.PackResources; import com.volmit.resource.ResourceId; import java.util.Optional; @@ -30,11 +31,12 @@ public interface PackWorld { /** * The seed this world gives {@code purpose}, such as {@code example:moss/patches}: the same for the same world and * purpose, independent across purposes. Seed a module's own randoms and noise with it instead of mixing - * {@link #seed()} by hand. A host answers {@link com.volmit.random.WorldRandom#purposeSeed} of the world's seed, - * except for purposes of its own modules whose worlds already depend on other seeds: Iris answers the ids of - * {@code iris:} purposes its built-in modules use with the seeds its worlds always had. + * {@link #seed()} by hand. It is {@link com.volmit.random.WorldRandom#purposeSeed} of the world's seed, for every + * purpose and every host. */ - long seed(ResourceId purpose); + default long seed(ResourceId purpose) { + return WorldRandom.purposeSeed(seed(), purpose); + } /** The pack snapshot this world generates with. */ PackResources resources(); diff --git a/host/src/main/java/com/volmit/host/ModuleWorld.java b/host/src/main/java/com/volmit/host/ModuleWorld.java index 988ecc6c4..4a8b0fc56 100644 --- a/host/src/main/java/com/volmit/host/ModuleWorld.java +++ b/host/src/main/java/com/volmit/host/ModuleWorld.java @@ -4,7 +4,6 @@ import com.volmit.ModuleLog; import com.volmit.config.PackSettings; import com.volmit.placement.Placements; import com.volmit.resource.PackResources; -import com.volmit.resource.ResourceId; import com.volmit.world.PackWorld; import com.volmit.world.RunningWorld; import java.util.Objects; @@ -37,11 +36,6 @@ final class ModuleWorld implements PackWorld { return world.seed(); } - @Override - public long seed(ResourceId purpose) { - return world.seed(purpose); - } - @Override public PackResources resources() { return world.resources(); diff --git a/host/src/test/java/com/volmit/host/ExtensionsTest.java b/host/src/test/java/com/volmit/host/ExtensionsTest.java index df350507a..e9b0a50ec 100644 --- a/host/src/test/java/com/volmit/host/ExtensionsTest.java +++ b/host/src/test/java/com/volmit/host/ExtensionsTest.java @@ -11,9 +11,7 @@ import com.volmit.generation.GenerationContext; import com.volmit.hunk.Hunk; import com.volmit.mantle.Mantle; import com.volmit.placement.Placements; -import com.volmit.random.WorldRandom; import com.volmit.resource.PackResources; -import com.volmit.resource.ResourceId; import com.volmit.stage.Pipeline; import com.volmit.stage.Stage; import com.volmit.support.TestContexts; @@ -84,7 +82,6 @@ class ExtensionsTest { } public long seed() { return TestContexts.SEED; } - public long seed(ResourceId purpose) { return WorldRandom.purposeSeed(seed(), purpose); } public PackResources resources() { throw new AssertionError("Unused resources"); } public PackSettings settings() { throw new AssertionError("Unused settings"); } public int minWorldY() { return 0; } diff --git a/host/src/test/java/com/volmit/support/TestWorld.java b/host/src/test/java/com/volmit/support/TestWorld.java index 7fe31d0ed..4b33fde34 100644 --- a/host/src/test/java/com/volmit/support/TestWorld.java +++ b/host/src/test/java/com/volmit/support/TestWorld.java @@ -6,10 +6,8 @@ import com.volmit.config.PackSettings; import com.volmit.config.SettingsStack; import com.volmit.host.ModuleLogs; import com.volmit.host.WorldStates; -import com.volmit.random.WorldRandom; import com.volmit.placement.Placements; import com.volmit.resource.PackResources; -import com.volmit.resource.ResourceId; import com.volmit.world.PackWorld; import com.volmit.world.RunningWorld; import java.util.Optional; @@ -34,11 +32,6 @@ public final class TestWorld implements PackWorld, AutoCloseable { return TestContexts.SEED; } - @Override - public long seed(ResourceId purpose) { - return WorldRandom.purposeSeed(seed(), purpose); - } - @Override public PackResources resources() { throw new AssertionError("Unused resources");