mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 00:34:19 +00:00
Baseline IrisApi draft before stage-graph redesign
This commit is contained in:
commit
9043d93fbd
91 files changed
+4045
No files matched your search
@@ -0,0 +1,16 @@
|
||||
package com.volmit.placement;
|
||||
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.object.BlockEntityData;
|
||||
import com.volmit.world.BlockPosition;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
/** A proposed or buffered write in world coordinates, including its block entity payload. */
|
||||
public record PlacedBlock(BlockPosition position, BlockState state, Optional<BlockEntityData> blockEntity) {
|
||||
public PlacedBlock {
|
||||
Objects.requireNonNull(position, "position");
|
||||
Objects.requireNonNull(state, "state");
|
||||
Objects.requireNonNull(blockEntity, "blockEntity");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.volmit.placement;
|
||||
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.world.BlockPosition;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
/** Marker metadata in world coordinates. */
|
||||
public record PlacedMarker(BlockPosition position, ResourceId type, Map<String, String> attributes) {
|
||||
public PlacedMarker {
|
||||
Objects.requireNonNull(position, "position");
|
||||
Objects.requireNonNull(type, "type");
|
||||
attributes = Map.copyOf(attributes);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.volmit.placement;
|
||||
|
||||
import com.volmit.mantle.Mantle;
|
||||
import com.volmit.world.BlockView;
|
||||
|
||||
/** Buffered world-space access for placement hooks, without ownership of commit/close.
|
||||
* Reads include the overlay. Bounds cover the object's footprint plus declared horizontal reach
|
||||
* and host-authorized vertical area. Block/entity/marker/mantle writes share the host edit.
|
||||
* Out-of-area access throws; nested mantle edits are unsupported. Do not retain this view.
|
||||
*/
|
||||
public interface PlacementAccess extends BlockView {
|
||||
void set(PlacedBlock block);
|
||||
void marker(PlacedMarker marker);
|
||||
Mantle mantle();
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.volmit.placement;
|
||||
|
||||
import com.volmit.config.FeatureSettings;
|
||||
import com.volmit.generation.InvocationContext;
|
||||
import com.volmit.object.ObjectTransformer;
|
||||
import com.volmit.world.TerrainSampler;
|
||||
import com.volmit.world.BlockView;
|
||||
|
||||
/** Read-only inputs to placement hooks. Working state is carried by returned immutable requests
|
||||
* and blocks, never stored on a configured modifier. Context lifetime ends with placement.
|
||||
*/
|
||||
public interface PlacementContext extends InvocationContext {
|
||||
TerrainSampler terrain();
|
||||
FeatureSettings settings();
|
||||
ObjectTransformer objects();
|
||||
/** Prepared blocks before this placement. Use hook access for reads of buffered changes. */
|
||||
BlockView blocks();
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.volmit.placement;
|
||||
|
||||
/** Host-owned buffered placement writes, in world coordinates, including cross-chunk writes.
|
||||
* All reads see the overlay. Block/entity/marker/mantle mutations participate in one commit.
|
||||
* Out-of-bounds access fails, never clips. The host excludes competing writers and handles
|
||||
* block entity replacement/removal when states change. Nested mantle edits are unsupported.
|
||||
* Successful commit ends the edit; failure leaves the parent unchanged and permits only close.
|
||||
* Close is idempotent and discards uncommitted work. Views expire when this edit ends.
|
||||
* This is a generation-storage transaction, not live-world or disk/crash atomicity.
|
||||
*/
|
||||
public interface PlacementEdit extends PlacementAccess, AutoCloseable {
|
||||
void commit();
|
||||
@Override void close();
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.volmit.placement;
|
||||
|
||||
import com.volmit.generation.Dependencies;
|
||||
import java.util.Optional;
|
||||
|
||||
/** Configured placement behavior. IDs are namespaced; dependencies refer only to placement
|
||||
* modifier IDs, not chunk modifiers. Snapshot settings; calls may occur concurrently.
|
||||
* The host runs prepare for all modifiers, mapBlock for each candidate, then validate for all
|
||||
* modifiers before buffering any write. beforePlace runs after validation but before object
|
||||
* writes, for boring/preparation. afterPlace runs only after all accepted blocks and
|
||||
* markers are buffered, allowing vacuum/stilts to observe the final footprint and overlay.
|
||||
* Exceptions discard the attempt. Empty prepare rejects it; empty mapBlock skips one block.
|
||||
*/
|
||||
public abstract class PlacementModifier {
|
||||
public abstract String id();
|
||||
public Dependencies depends() { return Dependencies.none(); }
|
||||
/** Horizontal access beyond the resulting object footprint; nonnegative, read at pack load. */
|
||||
public int writeRadius() { return 0; }
|
||||
public Optional<PlacementRequest> prepare(PlacementContext context, PlacementRequest request) { return Optional.of(request); }
|
||||
public Optional<PlacedBlock> mapBlock(PlacementContext context, PlacedBlock block) { return Optional.of(block); }
|
||||
public boolean validate(PlacementContext context, PlacementPlan plan) { return true; }
|
||||
public void beforePlace(PlacementContext context, PlacementAccess access, PlacementPlan proposed) {}
|
||||
public void afterPlace(PlacementContext context, PlacementAccess access, PlacementPlan written) {}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.volmit.placement;
|
||||
|
||||
import com.volmit.IrisFeature;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface PlacementModifierFactory<F extends IrisFeature> {
|
||||
PlacementModifier create(F feature);
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.volmit.placement;
|
||||
|
||||
import com.volmit.mantle.BlockBox;
|
||||
import com.volmit.world.BlockPosition;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
/** Complete proposed writes, constructed before validation or mutation.
|
||||
* Block positions are unique and ordered x/y/z. writtenBounds describes block writes only;
|
||||
* markers and the original object's declared footprint are tracked separately.
|
||||
*/
|
||||
public record PlacementPlan(PlacementRequest request, List<PlacedBlock> blocks, List<PlacedMarker> markers) {
|
||||
public PlacementPlan {
|
||||
Objects.requireNonNull(request, "request");
|
||||
blocks = List.copyOf(blocks).stream().sorted(Comparator.comparing(PlacedBlock::position)).toList();
|
||||
markers = List.copyOf(markers).stream().sorted(Comparator.comparing(PlacedMarker::position)).toList();
|
||||
var positions = new HashSet<BlockPosition>();
|
||||
for (var block : blocks) {
|
||||
if (!positions.add(block.position())) throw new IllegalArgumentException("Duplicate placement write: " + block.position());
|
||||
}
|
||||
}
|
||||
|
||||
public Optional<BlockBox> writtenBounds() {
|
||||
if (blocks.isEmpty()) return Optional.empty();
|
||||
int minX = Integer.MAX_VALUE, minY = Integer.MAX_VALUE, minZ = Integer.MAX_VALUE;
|
||||
int maxX = Integer.MIN_VALUE, maxY = Integer.MIN_VALUE, maxZ = Integer.MIN_VALUE;
|
||||
for (var block : blocks) {
|
||||
var position = block.position();
|
||||
minX = Math.min(minX, position.x()); minY = Math.min(minY, position.y()); minZ = Math.min(minZ, position.z());
|
||||
maxX = Math.max(maxX, position.x()); maxY = Math.max(maxY, position.y()); maxZ = Math.max(maxZ, position.z());
|
||||
}
|
||||
return Optional.of(new BlockBox(minX, minY, minZ, Math.addExact(maxX, 1), Math.addExact(maxY, 1), Math.addExact(maxZ, 1)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.volmit.placement;
|
||||
|
||||
import com.volmit.mantle.BlockBox;
|
||||
import com.volmit.object.GeneratedObject;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.world.BlockPosition;
|
||||
import java.util.Objects;
|
||||
|
||||
/** One placement attempt. Geometry is already transformed; anchor is a world block position.
|
||||
* World position = local position - object anchor + request anchor. Arithmetic never wraps.
|
||||
* id identifies this attempt within the host's generation plan.
|
||||
*/
|
||||
public record PlacementRequest(ResourceId id, GeneratedObject object, BlockPosition anchor) {
|
||||
public PlacementRequest {
|
||||
Objects.requireNonNull(id, "id");
|
||||
Objects.requireNonNull(object, "object");
|
||||
Objects.requireNonNull(anchor, "anchor");
|
||||
}
|
||||
|
||||
public BlockPosition worldPosition(BlockPosition local) {
|
||||
return new BlockPosition(translate(local.x(), object.anchor().x(), anchor.x()),
|
||||
translate(local.y(), object.anchor().y(), anchor.y()),
|
||||
translate(local.z(), object.anchor().z(), anchor.z()));
|
||||
}
|
||||
|
||||
public BlockBox footprint() {
|
||||
var bounds = object.bounds();
|
||||
var min = worldPosition(new BlockPosition(bounds.minX(), bounds.minY(), bounds.minZ()));
|
||||
var max = worldPosition(new BlockPosition(bounds.maxX(), bounds.maxY(), bounds.maxZ()));
|
||||
return new BlockBox(min.x(), min.y(), min.z(), max.x(), max.y(), max.z());
|
||||
}
|
||||
|
||||
private static int translate(int local, int objectAnchor, int worldAnchor) {
|
||||
return Math.toIntExact((long) local - objectAnchor + worldAnchor);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user