mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 08:44:50 +00:00
HintedLocator asks the ObjectsAt services which biomes and regions place an object
The object search plan no longer reads IrisObjectPlacement: it builds its coarse sampler from the layout entries the modules name and the biome tree it owns.
This commit is contained in:
1 parent
7a3f5961cc
commit
8137f6dba9
4 files changed
+55
-19
No files matched your search
@@ -49,6 +49,19 @@ public final class ModuleServices {
|
||||
return keys;
|
||||
}
|
||||
|
||||
/** The biomes and regions of the engine's layout that every module says place the object {@code objectKey}. */
|
||||
public static ObjectsAt.PlacedBy objectPlacers(Engine engine, String objectKey) {
|
||||
PackWorld world = engine.getGeneration().world();
|
||||
Set<String> biomes = new LinkedHashSet<>();
|
||||
Set<String> regions = new LinkedHashSet<>();
|
||||
for (ObjectsAt provider : catalog(engine.getData()).services(ObjectsAt.class)) {
|
||||
ObjectsAt.PlacedBy placedBy = provider.placedBy(world, objectKey);
|
||||
biomes.addAll(placedBy.biomes());
|
||||
regions.addAll(placedBy.regions());
|
||||
}
|
||||
return new ObjectsAt.PlacedBy(biomes, regions);
|
||||
}
|
||||
|
||||
/** Every structure key the pack's modules know, placed or not. */
|
||||
public static Set<String> structureKeys(IrisData data) {
|
||||
Set<String> keys = new LinkedHashSet<>();
|
||||
|
||||
@@ -18,14 +18,15 @@
|
||||
|
||||
package art.arcane.iris.engine.framework;
|
||||
|
||||
import art.arcane.iris.engine.object.placement.IrisObjectPlacement;
|
||||
import art.arcane.iris.core.IrisSettings;
|
||||
import art.arcane.iris.core.modules.ModuleServices;
|
||||
import art.arcane.iris.engine.IrisComplex;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.engine.object.world.region.IrisRegion;
|
||||
import art.arcane.iris.util.common.parallel.BurstExecutor;
|
||||
import art.arcane.iris.util.common.parallel.MultiBurst;
|
||||
import art.arcane.iris.util.project.context.IrisContext;
|
||||
import com.volmit.service.ObjectsAt;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.collection.KMap;
|
||||
import art.arcane.volmlib.util.collection.KSet;
|
||||
@@ -33,6 +34,7 @@ import art.arcane.volmlib.util.math.Position2;
|
||||
import art.arcane.volmlib.util.scheduling.PrecisionStopwatch;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
@@ -389,6 +391,7 @@ public final class HintedLocator<T> implements Locator<T> {
|
||||
}
|
||||
|
||||
IrisComplex complex = engine.getComplex();
|
||||
ObjectsAt.PlacedBy placers = ModuleServices.objectPlacers(engine, objectKey);
|
||||
BiomeSource source = new BiomeSource(engine);
|
||||
KSet<String> landHosts = new KSet<>();
|
||||
KSet<String> seaHosts = new KSet<>();
|
||||
@@ -401,28 +404,28 @@ public final class HintedLocator<T> implements Locator<T> {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (placesObject(region.getSurfaceObjects(), objectKey)) {
|
||||
if (placers.regions().contains(region.getLoadKey())) {
|
||||
directRegions.add(region.getLoadKey());
|
||||
}
|
||||
|
||||
boolean hosted = false;
|
||||
|
||||
for (String root : region.getLandBiomes()) {
|
||||
if (source.closurePlacesObject(root, objectKey)) {
|
||||
if (source.closureContainsAny(root, placers.biomes())) {
|
||||
landHosts.add(root);
|
||||
hosted = true;
|
||||
}
|
||||
}
|
||||
|
||||
for (String root : region.getSeaBiomes()) {
|
||||
if (source.closurePlacesObject(root, objectKey)) {
|
||||
if (source.closureContainsAny(root, placers.biomes())) {
|
||||
seaHosts.add(root);
|
||||
hosted = true;
|
||||
}
|
||||
}
|
||||
|
||||
for (String root : region.getShoreBiomes()) {
|
||||
if (source.closurePlacesObject(root, objectKey)) {
|
||||
if (source.closureContainsAny(root, placers.biomes())) {
|
||||
shoreHosts.add(root);
|
||||
hosted = true;
|
||||
}
|
||||
@@ -502,16 +505,6 @@ public final class HintedLocator<T> implements Locator<T> {
|
||||
};
|
||||
}
|
||||
|
||||
private static boolean placesObject(KList<IrisObjectPlacement> placements, String objectKey) {
|
||||
for (IrisObjectPlacement placement : placements) {
|
||||
if (placement != null && placement.getPlace().contains(objectKey)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static final class BiomeSource {
|
||||
private final Engine engine;
|
||||
private final KMap<String, IrisBiome> cache = new KMap<>();
|
||||
@@ -576,8 +569,8 @@ public final class HintedLocator<T> implements Locator<T> {
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean closurePlacesObject(String rootKey, String objectKey) {
|
||||
if (rootKey == null || objectKey == null) {
|
||||
private boolean closureContainsAny(String rootKey, Set<String> targetKeys) {
|
||||
if (rootKey == null || targetKeys.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -598,7 +591,7 @@ public final class HintedLocator<T> implements Locator<T> {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (placesObject(biome.getSurfaceObjects(), objectKey)) {
|
||||
if (targetKeys.contains(biome.getLoadKey())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -87,7 +87,17 @@ public class ModuleServicesTest {
|
||||
|
||||
@Override
|
||||
public void register(FeatureRegistry registry) {
|
||||
registry.registerService(ObjectsAt.class, (world, chunkX, chunkZ) -> Set.of(object + "@" + chunkX + "," + chunkZ));
|
||||
registry.registerService(ObjectsAt.class, new ObjectsAt() {
|
||||
@Override
|
||||
public Set<String> objectsAt(PackWorld world, int chunkX, int chunkZ) {
|
||||
return Set.of(object + "@" + chunkX + "," + chunkZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlacedBy placedBy(PackWorld world, String objectKey) {
|
||||
return new PlacedBy(Set.of(object + "-biome"), Set.of(id + "-region"));
|
||||
}
|
||||
});
|
||||
registry.registerService(StructureLocator.class, new StructureLocator() {
|
||||
@Override
|
||||
public Set<String> structures(PackResources resources) {
|
||||
@@ -141,6 +151,14 @@ public class ModuleServicesTest {
|
||||
assertEquals(List.of("tree@3,-4", "bush@3,-4", "rock@3,-4"), List.copyOf(ModuleServices.objectsAt(engine, 3, -4)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void objectPlacersCombineTheBiomesAndRegionsOfEveryModule() {
|
||||
ObjectsAt.PlacedBy placers = ModuleServices.objectPlacers(engine, "trees/oak");
|
||||
|
||||
assertEquals(Set.of("rock-biome", "tree-biome", "bush-biome"), placers.biomes());
|
||||
assertEquals(Set.of("test:zeta-region", "test:alpha-region", "test:beta-region"), placers.regions());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void structureListsCombineEveryModule() {
|
||||
assertEquals(Set.of("tower", "castle"), ModuleServices.locatableStructures(engine));
|
||||
|
||||
@@ -4,6 +4,8 @@ import art.arcane.iris.engine.object.placement.IrisObjectPlacement;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObject;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.loader.ResourceLoader;
|
||||
import art.arcane.iris.core.modules.ModuleResourceFixture;
|
||||
import art.arcane.iris.engine.mantle.components.ObjectModule;
|
||||
import art.arcane.iris.engine.IrisComplex;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
@@ -92,6 +94,9 @@ public class HintedLocatorTest {
|
||||
when(engine.isClosed()).thenReturn(false);
|
||||
when(engine.acquireGenerationLease(any(String.class))).thenReturn(GenerationSessionLease.noop());
|
||||
when(data.getBiomeLoader()).thenReturn(biomeLoader);
|
||||
ModuleResourceFixture.serveModules(data, new ObjectModule());
|
||||
when(engine.getGeneration()).thenReturn(new EngineGeneration(engine));
|
||||
stubReachableBiomes();
|
||||
}
|
||||
|
||||
private static IrisBiome biome(String key) {
|
||||
@@ -137,6 +142,10 @@ public class HintedLocatorTest {
|
||||
when(biomeLoader.load(biome.getLoadKey())).thenReturn(biome);
|
||||
}
|
||||
|
||||
private void stubReachableBiomes(IrisBiome... biomes) {
|
||||
when(dimension.getReachableBiomes(engine)).thenReturn(new KList<>(biomes));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void appendRingZeroAddsOnlyOrigin() {
|
||||
KList<Position2> batch = new KList<>();
|
||||
@@ -285,6 +294,7 @@ public class HintedLocatorTest {
|
||||
placements.add(placement);
|
||||
host.setObjects(placements);
|
||||
stubBiome(host);
|
||||
stubReachableBiomes(host);
|
||||
stubRegions(regionA);
|
||||
|
||||
when(complex.getRegionStream()).thenReturn(constantStream(regionA));
|
||||
@@ -326,6 +336,7 @@ public class HintedLocatorTest {
|
||||
IrisRegion regionA = region("reg_a");
|
||||
regionA.setLandBiomes(keys("plains"));
|
||||
stubBiome(biome("plains"));
|
||||
stubReachableBiomes(biome("plains"));
|
||||
stubRegions(regionA);
|
||||
|
||||
HintedLocator.SearchPlan plan = HintedLocator.objectPlan(engine, "missing/object");
|
||||
@@ -416,6 +427,7 @@ public class HintedLocatorTest {
|
||||
placements.add(placement);
|
||||
host.setObjects(placements);
|
||||
stubBiome(host);
|
||||
stubReachableBiomes(host);
|
||||
stubRegions(regionA);
|
||||
|
||||
when(complex.getRegionStream()).thenReturn(constantStream(regionA));
|
||||
|
||||
Reference in new issue
Block a user