mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 00:04:42 +00:00
Batch 6 part 4a: purpose seeds and the running world
Finding 40, first step. PackWorld.seed(purpose) gives each purpose id an independent world seed, specified as WorldRandom.purposeSeed and pinned against the reference script; a host may answer its own built-ins' ids with the seeds existing worlds depend on. PackWorld.running() is the world as services and hooks see it (layout over every column, settings, highest block, cave floors, sky, platform loot tables, debug), reusing TerrainSampler and FeatureSettings instead of a facade vocabulary.
This commit is contained in:
1 parent
1bc91df048
commit
364d735a95
11 files changed
+167
-8
No files matched your search
@@ -1,5 +1,7 @@
|
||||
package com.volmit.random;
|
||||
|
||||
import com.volmit.resource.ResourceId;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
@@ -46,6 +48,8 @@ import java.util.RandomAccess;
|
||||
*/
|
||||
public final class WorldRandom {
|
||||
private static final long GOLDEN_GAMMA = 0x9e3779b97f4a7c15L;
|
||||
private static final long FNV_OFFSET_BASIS = 0xcbf29ce484222325L;
|
||||
private static final long FNV_PRIME = 0x100000001b3L;
|
||||
private static final int INT_BITS = 32;
|
||||
private static final long UNSIGNED_INT_MASK = 0xffff_ffffL;
|
||||
private static final long INT_RANGE = 1L << INT_BITS;
|
||||
@@ -60,6 +64,20 @@ public final class WorldRandom {
|
||||
state = seed;
|
||||
}
|
||||
|
||||
/**
|
||||
* The seed for {@code purpose} of a world whose seed is {@code worldSeed}: {@code mix(worldSeed ^ mix(h))}, where
|
||||
* {@code mix} is the finalizer above and {@code h} the 64-bit FNV-1a hash (offset basis {@code 0xcbf29ce484222325},
|
||||
* prime {@code 0x100000001b3}) of the UTF-8 bytes of {@code purpose.toString()}. Different purposes give independent
|
||||
* seeds; see {@link com.volmit.world.PackWorld#seed(ResourceId)}.
|
||||
*/
|
||||
public static long purposeSeed(long worldSeed, ResourceId purpose) {
|
||||
long hash = FNV_OFFSET_BASIS;
|
||||
for (byte octet : purpose.toString().getBytes(StandardCharsets.UTF_8)) {
|
||||
hash = (hash ^ (octet & 0xff)) * FNV_PRIME;
|
||||
}
|
||||
return mix(worldSeed ^ mix(hash));
|
||||
}
|
||||
|
||||
/** A uniformly distributed {@code long}: the next SplitMix64 output. */
|
||||
public long nextLong() {
|
||||
state += GOLDEN_GAMMA;
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.volmit.world;
|
||||
import com.volmit.ModuleLog;
|
||||
import com.volmit.config.PackSettings;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
|
||||
@@ -25,6 +26,15 @@ import java.util.function.Function;
|
||||
public interface PackWorld {
|
||||
long seed();
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
long seed(ResourceId purpose);
|
||||
|
||||
/** The pack snapshot this world generates with. */
|
||||
PackResources resources();
|
||||
|
||||
@@ -38,6 +48,9 @@ public interface PackWorld {
|
||||
*/
|
||||
int minWorldY();
|
||||
|
||||
/** The world as it runs now, for services and lifecycle hooks; empty for a tool's world, which nothing runs. */
|
||||
Optional<RunningWorld> running();
|
||||
|
||||
/**
|
||||
* The world's one {@code type} instance, created by {@code create} the first time anyone asks for it. Modules keep
|
||||
* their caches and per-world workers here instead of in fields, since stage bodies and services are shared by every
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
package com.volmit.world;
|
||||
|
||||
import com.volmit.config.FeatureSettings;
|
||||
import com.volmit.geometry.BlockPosition;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
/** A world the host is running, as it is now, for services and lifecycle hooks: they have no chunk, so they ask the
|
||||
* world's layout, settings and platform state here instead of through an invocation. A chunk stage uses its
|
||||
* invocation's views, which may differ while the chunk generates.
|
||||
*
|
||||
* <p>X and Z are world coordinates; Y is the height above the dimension's bottom, as everywhere in the API. The views
|
||||
* live as long as the world and are safe to use from any thread.
|
||||
*/
|
||||
public interface RunningWorld {
|
||||
/** The world's terrain and biomes as generation lays them out, before anything was placed: its bounds are every
|
||||
* column of the world at full height. The same answers a chunk stage's {@link TerrainSampler} gives for its columns.
|
||||
*/
|
||||
TerrainSampler layout();
|
||||
|
||||
/** The settings at a world column, as a chunk stage's {@link FeatureSettings} gives them: the dimension's, the
|
||||
* column's region's and its surface biome's; a cave biome's through {@link FeatureSettings#declaredBy}.
|
||||
*/
|
||||
FeatureSettings settings();
|
||||
|
||||
/** The height of the highest block in the column now: the terrain with what objects and structures added.
|
||||
* {@code ignoreFluid} skips fluid blocks, so it answers the ground under a sea.
|
||||
*/
|
||||
int highestBlock(int worldX, int worldZ, boolean ignoreFluid);
|
||||
|
||||
/** The floors of the caves generation marked in the chunk, as positions of the floor blocks; none on a platform that
|
||||
* cannot read them.
|
||||
*/
|
||||
List<BlockPosition> caveFloors(int chunkX, int chunkZ);
|
||||
|
||||
/** The time and weather of the world; empty while the platform has not loaded the world. */
|
||||
Optional<Sky> sky();
|
||||
|
||||
/** The ids of the loot tables the platform has, such as {@code minecraft:chests/simple_dungeon}. They do not change
|
||||
* while the world runs.
|
||||
*/
|
||||
Set<ResourceId> platformLootTables();
|
||||
|
||||
/** Whether the world is one a pack author is working on (Iris: a studio world): the host then shows where generated
|
||||
* things came from, such as the sources of items ({@link com.volmit.item.ItemDrop#source()}).
|
||||
*/
|
||||
boolean debug();
|
||||
|
||||
/** The world's time of day in ticks, whether it storms and whether it thunders. */
|
||||
record Sky(long time, boolean storming, boolean thundering) {
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user