mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-30 09:44:24 +00:00
Document module jars, entry points and pack loading
This commit is contained in:
1 parent
6388173f19
commit
4fa6ddcd7a
4 files changed
+92
-14
No files matched your search
@@ -8,6 +8,7 @@ types that carry them and lists what the Iris adapter still owes.
|
|||||||
| Requirement | Contract |
|
| Requirement | Contract |
|
||||||
| --- | --- |
|
| --- | --- |
|
||||||
| Module identity and composition | `IrisModule`, `ModuleInfo`, `StageGraph` |
|
| Module identity and composition | `IrisModule`, `ModuleInfo`, `StageGraph` |
|
||||||
|
| Module jars in a pack | `META-INF/services/com.volmit.IrisModule`, host `PackModules`, `DiscoveredModule` |
|
||||||
| Module-owned work and ordering | `Stage`, `StageRef`, stage definitions, `requires`/`softAfter`/`softBefore` |
|
| Module-owned work and ordering | `Stage`, `StageRef`, stage definitions, `requires`/`softAfter`/`softBefore` |
|
||||||
| Activation by configuration | `when(settingsType)`, host `ConfiguredSettings` |
|
| Activation by configuration | `when(settingsType)`, host `ConfiguredSettings` |
|
||||||
| Typed results between modules | stage outputs, `StageContext.output` |
|
| Typed results between modules | stage outputs, `StageContext.output` |
|
||||||
@@ -39,9 +40,15 @@ context, outputs and accumulators.
|
|||||||
- 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.
|
||||||
|
- Load each pack's jars with `PackModules`, pass them with the built-in modules to
|
||||||
|
`LoadedModules.load`, and close `PackModules` only after nothing built from it is in use.
|
||||||
|
- Make built-in modules visible to the loader that defines the API, or pack jars cannot require
|
||||||
|
their stages.
|
||||||
|
|
||||||
## Open
|
## Open
|
||||||
|
|
||||||
- Per-stage reach declarations, replacing the removed modifier radii.
|
- Per-stage reach declarations, replacing the removed modifier radii.
|
||||||
- Per-stage RNG streams, so adding a module does not shift other modules' random draws.
|
- Per-stage RNG streams, so adding a module does not shift other modules' random draws.
|
||||||
- Terrain/biome providers, pack transformations, structure assembly and the runtime family.
|
- Terrain/biome providers, pack transformations, structure assembly and the runtime family.
|
||||||
|
- Version gating: modules do not declare which API version they target, so an incompatible jar
|
||||||
|
fails with a linkage error at load or later at install or run time.
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
# Iris API design
|
# Iris API design
|
||||||
|
|
||||||
Status: the stage graph, both pipelines' reference executors, settings catalog, geometry,
|
Status: pack module loading, the stage graph, both pipelines' reference executors, settings
|
||||||
resources and typed storage contracts exist and are tested without the Iris engine. Provider and
|
catalog, geometry, resources and typed storage contracts exist and are tested without the Iris
|
||||||
runtime families at the end are design notes, not Java interfaces.
|
engine. Provider and runtime families at the end are design notes, not Java interfaces.
|
||||||
|
|
||||||
## Model
|
## Model
|
||||||
|
|
||||||
@@ -31,6 +31,46 @@ flowchart TD
|
|||||||
Hunk --> Publish
|
Hunk --> Publish
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Module loading
|
||||||
|
|
||||||
|
The `IrisModule` implementation is the module's entry point. `info()` returns its id and
|
||||||
|
version; there is no separate descriptor. A pack keeps its modules in `<pack>/modules/*.jar`,
|
||||||
|
one module per jar.
|
||||||
|
|
||||||
|
A jar names its entry class in `META-INF/services/com.volmit.IrisModule`, the provider format of
|
||||||
|
`ServiceLoader`. The host reads that file from the jar itself rather than calling
|
||||||
|
`ServiceLoader`, which would also return providers of parent class loaders and could not say
|
||||||
|
which jar a broken provider came from. The rejected alternatives:
|
||||||
|
|
||||||
|
- A manifest attribute such as `Iris-Module: com.example.MossModule`. It needs the same reading
|
||||||
|
code but is not a Java convention, IDEs do not check it, and fat-jar tools tend to rewrite
|
||||||
|
manifests.
|
||||||
|
- A descriptor file with id and version. It duplicates `info()`, so the two can disagree, and
|
||||||
|
parsing it needs a format the JDK does not ship.
|
||||||
|
|
||||||
|
`PackModules.load(packRoot)`:
|
||||||
|
|
||||||
|
1. Lists regular files ending in `.jar` in `<pack>/modules`, sorted by file name. A missing
|
||||||
|
directory means no modules.
|
||||||
|
2. Reads each jar's entry point file. Comments (`#`) and blank lines are ignored; zero or more
|
||||||
|
than one class name fails.
|
||||||
|
3. Creates one `URLClassLoader` for all jars of the pack, parent = the loader of `IrisModule`.
|
||||||
|
4. Loads each entry class, checks that it implements `IrisModule` and comes from its own jar,
|
||||||
|
instantiates it with the public no-argument constructor and calls `info()`.
|
||||||
|
|
||||||
|
One loader per pack, not per jar, because `requires(...)` takes another module's stage constant.
|
||||||
|
A pack jar that requires a stage of another pack jar must see its classes. Packs stay isolated
|
||||||
|
from each other, and built-in modules visible to the API's loader are visible to every pack. The
|
||||||
|
cost: two jars of one pack that contain the same class name share the first one in file name
|
||||||
|
order. The entry-class check catches this for entry classes only.
|
||||||
|
|
||||||
|
Closing `PackModules` closes the loader. Classes loaded before that keep working, so the host
|
||||||
|
must drop `LoadedModules` and everything else built from the pack first.
|
||||||
|
|
||||||
|
Each module reaches `LoadedModules.load` as a `DiscoveredModule`: the module and its origin, the
|
||||||
|
jar path relative to the pack or "host classpath" for built-ins. Duplicate module ids and foreign
|
||||||
|
stage namespaces name the origin. Every jar error names the jar.
|
||||||
|
|
||||||
## Stages
|
## Stages
|
||||||
|
|
||||||
A stage is a constant created by `Stage.placement`, `Stage.placementBlock` or `Stage.chunk`. Its
|
A stage is a constant created by `Stage.placement`, `Stage.placementBlock` or `Stage.chunk`. Its
|
||||||
@@ -157,8 +197,8 @@ Unknown persisted layers must be preserved or fail explicitly.
|
|||||||
|
|
||||||
## Not implemented
|
## Not implemented
|
||||||
|
|
||||||
- Iris host wiring: module discovery and version gating, JSON decoding and validation, schema
|
- Iris host wiring: version gating, JSON decoding and validation, schema generation, resource
|
||||||
generation, resource loaders, platform block adapters, storage and codecs.
|
loaders, platform block adapters, storage and codecs.
|
||||||
- Reach. The old per-modifier `writeRadius` and `mantleRadius` are gone with the modifiers. The
|
- Reach. The old per-modifier `writeRadius` and `mantleRadius` are gone with the modifiers. The
|
||||||
host must prepare the whole area a pipeline may touch. Per-stage reach is an open question.
|
host must prepare the whole area a pipeline may touch. Per-stage reach is an open question.
|
||||||
- Legacy random compatibility. Seed offsets and draw order must be matched by the adapter where
|
- Legacy random compatibility. Seed offsets and draw order must be matched by the adapter where
|
||||||
|
|||||||
@@ -43,23 +43,48 @@ public final class MossModule implements IrisModule {
|
|||||||
`IrisModule.register(FeatureRegistry)` stays for non-stage contributions: geometry generators
|
`IrisModule.register(FeatureRegistry)` stays for non-stage contributions: geometry generators
|
||||||
and mantle layers.
|
and mantle layers.
|
||||||
|
|
||||||
|
## Module jars
|
||||||
|
|
||||||
|
A pack loads its modules from `<pack>/modules/*.jar`. One jar holds one module. Its entry point
|
||||||
|
is the `IrisModule` class, named in the jar's `META-INF/services/com.volmit.IrisModule`:
|
||||||
|
|
||||||
|
```
|
||||||
|
modules/moss.jar
|
||||||
|
META-INF/services/com.volmit.IrisModule contains: com.example.moss.MossModule
|
||||||
|
com/example/moss/MossModule.class public, public no-argument constructor
|
||||||
|
com/example/moss/MossSettings.class
|
||||||
|
```
|
||||||
|
|
||||||
|
`info()` gives the module id and version. The id's namespace is the namespace of every stage the
|
||||||
|
module defines.
|
||||||
|
|
||||||
## Host side
|
## Host side
|
||||||
|
|
||||||
```java
|
```java
|
||||||
var loaded = LoadedModules.load(acceptedModules, reservedHostFields);
|
try (var pack = PackModules.load(packRoot)) {
|
||||||
System.out.println(loaded.placement().describe());
|
var modules = new ArrayList<>(builtIns); // DiscoveredModule.builtIn(...)
|
||||||
|
modules.addAll(pack.modules());
|
||||||
|
var loaded = LoadedModules.load(modules, reservedHostFields);
|
||||||
|
System.out.println(loaded.placement().describe());
|
||||||
|
|
||||||
var placer = new PlacementRunner(loaded.placement());
|
var placer = new PlacementRunner(loaded.placement());
|
||||||
PlacementOutcome outcome = placer.place(request, edit, inputs, ConfiguredSettings.of(stilt, snow));
|
PlacementOutcome outcome = placer.place(request, edit, inputs, ConfiguredSettings.of(stilt, snow));
|
||||||
|
|
||||||
new ChunkRunner(loaded.chunk()).generate(generationContext, chunkSettings);
|
new ChunkRunner(loaded.chunk()).generate(generationContext, chunkSettings);
|
||||||
|
} // drop everything built from the pack before it closes
|
||||||
```
|
```
|
||||||
|
|
||||||
|
`PackModules.load` reads one entry point per jar, in jar file name order, and loads every jar
|
||||||
|
of the pack through one class loader. Closing it closes that loader. A pack without a `modules`
|
||||||
|
directory has no modules. Errors name the jar: no entry point, several entry points, or an entry
|
||||||
|
class that cannot be loaded, is not an `IrisModule`, is not in that jar, or fails to construct.
|
||||||
|
|
||||||
`LoadedModules.load` installs every module, catalogs the settings types named in `when(...)`
|
`LoadedModules.load` installs every module, catalogs the settings types named in `when(...)`
|
||||||
together with geometry and mantle registrations, and resolves both pipelines. Graph errors
|
together with geometry and mantle registrations, and resolves both pipelines. Graph errors
|
||||||
(missing requirement, cycle, foreign namespace, duplicate, cross-pipeline edge) fail here, at
|
(missing requirement, cycle, foreign namespace, duplicate, cross-pipeline edge) fail here, at
|
||||||
pack load. `describe()` prints the order, owners, edge kinds, fused block passes and the stage
|
pack load. Duplicate module ids and foreign namespaces also name the jar or "host classpath".
|
||||||
pairs that have no path between them.
|
`describe()` prints the order, owners, edge kinds, fused block passes and the stage pairs that
|
||||||
|
have no path between them.
|
||||||
|
|
||||||
`PlacementRunner` owns the edit for one attempt. It commits once if no stage rejects or throws
|
`PlacementRunner` owns the edit for one attempt. It commits once if no stage rejects or throws
|
||||||
and closes the edit in every case. Stages get buffered `PlacementAccess` without commit rights.
|
and closes the edit in every case. Stages get buffered `PlacementAccess` without commit rights.
|
||||||
@@ -86,7 +111,8 @@ invocations and must not keep views or mutable state.
|
|||||||
```
|
```
|
||||||
|
|
||||||
The tests cover graph resolution and every error path, fusion, activation cascade, outputs,
|
The tests cover graph resolution and every error path, fusion, activation cascade, outputs,
|
||||||
rejection and rollback, and install-order determinism. The example ports in
|
rejection and rollback, and install-order determinism. `PackModulesTest` compiles real module
|
||||||
|
jars into a temporary pack and loads them, including every jar error. The example ports in
|
||||||
`src/test/java/com/volmit/example` rebuild preparation, anchoring, block writes, stilt and snow
|
`src/test/java/com/volmit/example` rebuild preparation, anchoring, block writes, stilt and snow
|
||||||
as separate modules, add a third-party moss module, and add a two-module chunk pipeline. There is
|
as separate modules, add a third-party moss module, and add a two-module chunk pipeline. There is
|
||||||
no Minecraft integration or production storage in these tests.
|
no Minecraft integration or production storage in these tests.
|
||||||
@@ -2,7 +2,12 @@ package com.volmit;
|
|||||||
|
|
||||||
import com.volmit.stage.StageGraph;
|
import com.volmit.stage.StageGraph;
|
||||||
|
|
||||||
/** A unit of world-generation behavior. The core engine is an ordinary module too. */
|
/** A unit of world-generation behavior. The core engine is an ordinary module too.
|
||||||
|
*
|
||||||
|
* <p>In a pack's module jar this class is the entry point. The jar names it in
|
||||||
|
* {@code META-INF/services/com.volmit.IrisModule}, and it needs a public no-argument constructor.
|
||||||
|
* One jar holds exactly one module.
|
||||||
|
*/
|
||||||
public interface IrisModule {
|
public interface IrisModule {
|
||||||
ModuleInfo info();
|
ModuleInfo info();
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user