Merge branch 'wave3b/p'

This commit is contained in:
piexel committed 2026-10-10 15:07:18 +02:00
commit 1a319d842b
8 files changed
+72 -25

No files matched your search

+2 -1
View File
@@ -132,7 +132,8 @@ running Iris is the pack publisher's responsibility.
dimension keeps no mantle or the chunk generates without it. A block a stage reads and writes back unchanged keeps dimension keeps no mantle or the chunk generates without it. A block a stage reads and writes back unchanged keeps
the host's own identity of it (a custom block of a content plugin stays one). the host's own identity of it (a custom block of a content plugin stays one).
- Answer `TerrainSampler.fluidHeight()` (the height the host fills with fluid below) and `upperDimensionY(x, z)` (where a - Answer `TerrainSampler.fluidHeight()` (the height the host fills with fluid below) and `upperDimensionY(x, z)` (where a
dimension stacked above begins; empty when none does). dimension stacked above begins; empty when none does). `surfaceY(x, z)` equals `column(x, z).surfaceY()`; a host
overrides it when the height costs less than the whole column.
- Make placement edits atomic across blocks, block entities, markers and mantle in generation - Make placement edits atomic across blocks, block entities, markers and mantle in generation
storage. Abort chunk publication when any stage fails. storage. Abort chunk publication when any stage fails.
- Preserve unknown persisted mantle layers or fail explicitly. - Preserve unknown persisted mantle layers or fail explicitly.
+3 -2
View File
@@ -496,7 +496,8 @@ whose writes throw. The runner does no neighbor scheduling or rollback. A failed
the host from publishing the chunk. the host from publishing the chunk.
A chunk stage writes only its chunk but may look around it: its `TerrainSampler` covers the chunk and the 16 blocks A chunk stage writes only its chunk but may look around it: its `TerrainSampler` covers the chunk and the 16 blocks
around it, so a stage that smooths a surface reads its neighbors' heights. The sampler also gives the dimension's around it, so a stage that smooths a surface reads its neighbors' heights (`surfaceY`, which spares the host the slope
that `column` works out). The sampler also gives the dimension's
`fluidHeight()` and, per column, `upperDimensionY` where a dimension stacked above begins; a stage writes nothing at or `fluidHeight()` and, per column, `upperDimensionY` where a dimension stacked above begins; a stage writes nothing at or
above it. The mantle's `blocks()` are the blocks placements wrote into the mantle for chunks to take over (objects, above it. The mantle's `blocks()` are the blocks placements wrote into the mantle for chunks to take over (objects,
structures): a chunk stage copies them into its chunk, as Iris's `iris:matter` does. They are the host's layer, so they structures): a chunk stage copies them into its chunk, as Iris's `iris:matter` does. They are the host's layer, so they
@@ -1024,7 +1025,7 @@ from a sapling, which drops a block has. A module answers such questions through
switch over every outcome). Keys are pack keys as packs write them and match without regard to case. switch over every outcome). Keys are pack keys as packs write them and match without regard to case.
`CaveBiomes` (`ONE`): the pack biome a module puts at a position whatever the regions say (a band of the deep dark, `CaveBiomes` (`ONE`): the pack biome a module puts at a position whatever the regions say (a band of the deep dark,
`overriddenBiome`, the height counted above the dimension's bottom) and how deep below the surface a biome's caves begin `overriddenBiome`, the height counted above the dimension's bottom) and how deep below the surface a biome's caves begin
(`minDepthBelowSurface`). The host owns the 3D biome of a position (its regions, terrain height and the cave biome stream) (`minDepthBelowSurface`, asked once per biome and kept while the world runs). The host owns the 3D biome of a position (its regions, terrain height and the cave biome stream)
and asks this only where a module decides; one provider, since two modules could not both decide the biome of one cave. and asks this only where a module decides; one provider, since two modules could not both decide the biome of one cave.
- **Settings that name biomes.** The host owns the biome tree (a region's biomes and their children) and the set of - **Settings that name biomes.** The host owns the biome tree (a region's biomes and their children) and the set of
biomes a dimension reaches, and both must include biomes that module settings name: a cave band's biome, the target of a biomes a dimension reaches, and both must include biomes that module settings name: a cave band's biome, the target of a
+2 -1
View File
@@ -122,7 +122,8 @@ graph.define(APPLY).run(CaveModule::apply); // reads its own chunk's CAVES and
A chunk stage writes only its own chunk but may look around it: `ctx.terrain()` covers the chunk and the 16 blocks A chunk stage writes only its own chunk but may look around it: `ctx.terrain()` covers the chunk and the 16 blocks
around it, gives the dimension's `fluidHeight()` and, per column, `upperDimensionY(x, z)` where a dimension stacked above around it, gives the dimension's `fluidHeight()` and, per column, `upperDimensionY(x, z)` where a dimension stacked above
begins (write nothing there). `ctx.mantle().blocks()` holds the blocks placements wrote into the mantle for the chunks to begins (write nothing there). `surfaceY(x, z)` is a column's height alone, cheaper than `column(x, z)` when a stage needs
no slope. `ctx.mantle().blocks()` holds the blocks placements wrote into the mantle for the chunks to
take over, such as objects and structures; a chunk stage copies them in (Iris's `iris:matter`). Stages only read them. take over, such as objects and structures; a chunk stage copies them in (Iris's `iris:matter`). Stages only read them.
```java ```java
@@ -5,11 +5,13 @@ import com.volmit.service.Providers;
import com.volmit.service.Service; import com.volmit.service.Service;
import java.util.Collection; import java.util.Collection;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.util.Optional; import java.util.Optional;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors;
/** Frozen registrations. Lists use lexical feature/layer/kind ID order, and validators, lifecycle hooks, service /** Frozen registrations. Lists use lexical feature/layer/kind ID order, and validators, lifecycle hooks, service
* providers are in module id order, each module's in the order it registered them, so * providers are in module id order, each module's in the order it registered them, so
@@ -17,6 +19,19 @@ import java.util.function.Function;
* concurrency contracts. * concurrency contracts.
*/ */
public final class FeatureCatalog { public final class FeatureCatalog {
/** Services are asked for on the generation hot path, so each type's annotation is read once. */
private static final ClassValue<Providers> SERVICE_PROVIDERS = new ClassValue<>() {
@Override
protected Providers computeValue(Class<?> type) {
var service = type.isInterface() ? type.getAnnotation(Service.class) : null;
if (service == null) {
throw new IllegalArgumentException(type.getName() + " is not a service: services are interfaces marked @"
+ Service.class.getName());
}
return service.value();
}
};
private final Map<Class<?>, FeatureDescriptor<?>> settings; private final Map<Class<?>, FeatureDescriptor<?>> settings;
private final Map<Class<?>, ObjectRegistration<?>> objects; private final Map<Class<?>, ObjectRegistration<?>> objects;
private final Map<String, MantleRegistration<?>> mantle; private final Map<String, MantleRegistration<?>> mantle;
@@ -24,7 +39,8 @@ public final class FeatureCatalog {
private final List<HeldTypeRegistration> heldTypes; private final List<HeldTypeRegistration> heldTypes;
private final List<ValidatorRegistration> validators; private final List<ValidatorRegistration> validators;
private final List<LifecycleRegistration> lifecycles; private final List<LifecycleRegistration> lifecycles;
private final List<ServiceRegistration> services; private final Map<Class<?>, List<ServiceRegistration>> registrationsByService;
private final Map<Class<?>, List<?>> providersByService;
FeatureCatalog( FeatureCatalog(
Map<Class<?>, FeatureDescriptor<?>> settings, Map<Class<?>, FeatureDescriptor<?>> settings,
@@ -42,7 +58,8 @@ public final class FeatureCatalog {
this.heldTypes = sorted(heldTypes, registration -> registration.type().getName()); this.heldTypes = sorted(heldTypes, registration -> registration.type().getName());
this.validators = inModuleOrder(validators, ValidatorRegistration::module); this.validators = inModuleOrder(validators, ValidatorRegistration::module);
this.lifecycles = inModuleOrder(lifecycles, LifecycleRegistration::module); this.lifecycles = inModuleOrder(lifecycles, LifecycleRegistration::module);
this.services = inModuleOrder(services, ServiceRegistration::module); this.registrationsByService = byService(inModuleOrder(services, ServiceRegistration::module));
this.providersByService = providersByService(registrationsByService);
} }
/** Settings types that activate stages; the host decodes them from pack JSON. */ /** Settings types that activate stages; the host decodes them from pack JSON. */
@@ -81,39 +98,53 @@ public final class FeatureCatalog {
/** Every provider of {@code service}, an interface marked {@link Service}, in module id order and each module's in the /** Every provider of {@code service}, an interface marked {@link Service}, in module id order and each module's in the
* order it registered them; empty when no module provides it. * order it registered them; empty when no module provides it.
*/ */
@SuppressWarnings("unchecked") // ModuleRegistry.registerService checked that every provider implements its service.
public <S> List<S> services(Class<S> service) { public <S> List<S> services(Class<S> service) {
requireService(service); var providers = providersByService.get(service);
return services.stream() if (providers == null) {
.filter(registration -> registration.service() == service) providersOf(service);
.map(registration -> service.cast(registration.provider())) return List.of();
.toList(); }
return (List<S>) providers;
} }
/** Every provider of {@code service} with the module that registered it, in the order of {@link #services}, so the host /** Every provider of {@code service} with the module that registered it, in the order of {@link #services}, so the host
* can name the module whose provider failed. * can name the module whose provider failed.
*/ */
public List<ServiceRegistration> registrations(Class<?> service) { public List<ServiceRegistration> registrations(Class<?> service) {
requireService(service); var registrations = registrationsByService.get(service);
return services.stream().filter(registration -> registration.service() == service).toList(); if (registrations == null) {
providersOf(service);
return List.of();
}
return registrations;
} }
/** The one provider of {@code service}, a service whose providers are {@link Providers#ONE}, if a module provides it. */ /** The one provider of {@code service}, a service whose providers are {@link Providers#ONE}, if a module provides it. */
public <S> Optional<S> service(Class<S> service) { public <S> Optional<S> service(Class<S> service) {
if (requireService(service).value() != Providers.ONE) { if (providersOf(service) != Providers.ONE) {
throw new IllegalArgumentException("Service " + service.getName() + " may have several providers; ask for all of" throw new IllegalArgumentException("Service " + service.getName() + " may have several providers; ask for all of"
+ " them with services(...)"); + " them with services(...)");
} }
return services(service).stream().findFirst(); var providers = services(service);
return providers.isEmpty() ? Optional.empty() : Optional.of(providers.getFirst());
} }
/** The {@link Service} annotation of {@code type}, which must be an interface carrying one. */ /** How many modules may provide {@code service}, which must be an interface marked {@link Service}. */
static Service requireService(Class<?> type) { static Providers providersOf(Class<?> service) {
var service = type.isInterface() ? type.getAnnotation(Service.class) : null; return SERVICE_PROVIDERS.get(service);
if (service == null) { }
throw new IllegalArgumentException(type.getName() + " is not a service: services are interfaces marked @"
+ Service.class.getName()); private static Map<Class<?>, List<ServiceRegistration>> byService(List<ServiceRegistration> inModuleOrder) {
} return Map.copyOf(inModuleOrder.stream()
return service; .collect(Collectors.groupingBy(ServiceRegistration::service, Collectors.toUnmodifiableList())));
}
private static Map<Class<?>, List<?>> providersByService(Map<Class<?>, List<ServiceRegistration>> registrationsByService) {
var providers = new HashMap<Class<?>, List<?>>();
registrationsByService.forEach((service, registrations) ->
providers.put(service, registrations.stream().map(ServiceRegistration::provider).toList()));
return Map.copyOf(providers);
} }
private static <T> List<T> inModuleOrder(List<T> registrations, Function<? super T, DiscoveredModule> module) { private static <T> List<T> inModuleOrder(List<T> registrations, Function<? super T, DiscoveredModule> module) {
@@ -170,7 +170,7 @@ public final class ModuleRegistry implements FeatureRegistry {
Objects.requireNonNull(service, "service"); Objects.requireNonNull(service, "service");
Objects.requireNonNull(provider, "provider"); Objects.requireNonNull(provider, "provider");
requireRegistering("Provider of " + service.getName()); requireRegistering("Provider of " + service.getName());
var providers = FeatureCatalog.requireService(service).value(); var providers = FeatureCatalog.providersOf(service);
if (!service.isInstance(provider)) { if (!service.isInstance(provider)) {
throw new IllegalArgumentException("Provider " + provider + " of module " + registering + " does not implement " throw new IllegalArgumentException("Provider " + provider + " of module " + registering + " does not implement "
+ service.getName()); + service.getName());
@@ -21,7 +21,8 @@ public interface CaveBiomes {
/** /**
* How many blocks below the surface a position must lie for the pack biome {@code biomeKey} to be the cave biome there; * How many blocks below the surface a position must lie for the pack biome {@code biomeKey} to be the cave biome there;
* nearer the surface the surface's biome is. 0 for a biome that has no such limit. * nearer the surface the surface's biome is. 0 for a biome that has no such limit. The answer depends on the world and the
* biome only: the host asks once per biome and keeps it while the world runs.
*/ */
int minDepthBelowSurface(PackWorld world, String biomeKey); int minDepthBelowSurface(PackWorld world, String biomeKey);
} }
@@ -11,6 +11,13 @@ import java.util.OptionalInt;
public interface TerrainSampler { public interface TerrainSampler {
BlockBox bounds(); BlockBox bounds();
TerrainSample column(int worldX, int worldZ); TerrainSample column(int worldX, int worldZ);
/** The column's {@link TerrainSample#surfaceY()} alone, for a module that needs neither slope nor fluid: the host
* may answer it without working out the rest of {@link #column}. Outside the bounds it throws like {@link #column}.
*/
default double surfaceY(int worldX, int worldZ) {
return column(worldX, worldZ).surfaceY();
}
BiomeSample biome(int worldX, int y, int worldZ); BiomeSample biome(int worldX, int y, int worldZ);
/** The height up to which the host fills the world with fluid wherever the terrain lies lower, the sea level of the /** The height up to which the host fills the world with fluid wherever the terrain lies lower, the sea level of the
@@ -395,6 +395,11 @@ class ModuleRegistryTest {
var several = assertThrows(IllegalArgumentException.class, () -> catalog.service(Greeting.class)); var several = assertThrows(IllegalArgumentException.class, () -> catalog.service(Greeting.class));
assertTrue(several.getMessage().contains("services(...)"), several.getMessage()); assertTrue(several.getMessage().contains("services(...)"), several.getMessage());
assertThrows(IllegalArgumentException.class, () -> catalog.services(NotAService.class)); assertThrows(IllegalArgumentException.class, () -> catalog.services(NotAService.class));
assertThrows(IllegalArgumentException.class, () -> catalog.registrations(NotAService.class), "asking again still refuses it");
assertEquals(List.of(alphaFirst, alphaSecond, zeta),
catalog.registrations(Greeting.class).stream().map(ServiceRegistration::provider).toList());
assertEquals(List.of(), catalog.registrations(Clock.class));
assertThrows(UnsupportedOperationException.class, () -> catalog.services(Greeting.class).clear(), "the catalog is frozen");
} }
@Test @Test