Fix feature placements

This commit is contained in:
Daniel Mills 2021-08-03 23:02:46 -04:00
parent 412c67b47a
commit ee78249c2f
3 changed files with 21 additions and 25 deletions

View File

@ -19,6 +19,7 @@
package com.volmit.iris.engine; package com.volmit.iris.engine;
import com.volmit.iris.core.IrisSettings; import com.volmit.iris.core.IrisSettings;
import com.volmit.iris.engine.cache.Cache;
import com.volmit.iris.engine.framework.Engine; import com.volmit.iris.engine.framework.Engine;
import com.volmit.iris.engine.framework.EngineAssignedWorldManager; import com.volmit.iris.engine.framework.EngineAssignedWorldManager;
import com.volmit.iris.engine.object.*; import com.volmit.iris.engine.object.*;
@ -44,7 +45,7 @@ import java.util.stream.Stream;
public class IrisWorldManager extends EngineAssignedWorldManager { public class IrisWorldManager extends EngineAssignedWorldManager {
private final int art; private final int art;
private final KMap<UUID, Long> spawnCooldowns; private final KMap<Long, Long> chunkCooldowns;
private int entityCount = 0; private int entityCount = 0;
private final ChronoLatch cl; private final ChronoLatch cl;
private int actuallySpawned = 0; private int actuallySpawned = 0;
@ -52,7 +53,7 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
public IrisWorldManager(Engine engine) { public IrisWorldManager(Engine engine) {
super(engine); super(engine);
cl = new ChronoLatch(5000); cl = new ChronoLatch(5000);
spawnCooldowns = new KMap<>(); chunkCooldowns = new KMap<>();
art = J.ar(this::onAsyncTick, 7); art = J.ar(this::onAsyncTick, 7);
} }
@ -71,33 +72,26 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
} }
int maxGroups = 3; int maxGroups = 3;
int biomeBaseCooldownSeconds = IrisSettings.get().getGeneral().isDebug() ? 0 : 15; int chunkCooldownSeconds = 60;
for (UUID i : spawnCooldowns.k()) { for (Long i : chunkCooldowns.k()) {
if (M.ms() - spawnCooldowns.get(i) > TimeUnit.SECONDS.toMillis(biomeBaseCooldownSeconds)) { if (M.ms() - chunkCooldowns.get(i) > TimeUnit.SECONDS.toMillis(chunkCooldownSeconds)) {
spawnCooldowns.remove(i); chunkCooldowns.remove(i);
} }
} }
KMap<UUID, KList<Chunk>> data = mapChunkBiomes();
int spawnBuffer = 32; int spawnBuffer = 32;
for (UUID i : data.k().shuffleCopy(RNG.r)) { for (Chunk c : getEngine().getWorld().realWorld().getLoadedChunks()) {
if (spawnCooldowns.containsKey(i)) {
continue;
}
if (spawnBuffer-- < 0) { if (spawnBuffer-- < 0) {
break; break;
} }
for (int ig = 0; ig < data.get(i).size() / 8; ig++) { IrisBiome biome = getEngine().getSurfaceBiome(c);
Chunk c = data.get(i).getRandom(); IrisRegion region = getEngine().getRegion(c);
IrisBiome biome = getEngine().getSurfaceBiome(c); spawnIn(c, biome, region, maxGroups);
IrisRegion region = getEngine().getRegion(c); chunkCooldowns.put(Cache.key(c), M.ms());
spawnIn(c, biome, region, i, maxGroups);
spawnCooldowns.put(i, M.ms());
}
} }
if (actuallySpawned <= 0) { if (actuallySpawned <= 0) {
@ -105,7 +99,7 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
} }
} }
private void spawnIn(Chunk c, IrisBiome biome, IrisRegion region, UUID id, int max) { private void spawnIn(Chunk c, IrisBiome biome, IrisRegion region, int max) {
if (c.getEntities().length > 2) { if (c.getEntities().length > 2) {
return; return;
} }
@ -130,11 +124,11 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
.shuffleCopy(RNG.r).stream().filter(this::canSpawn) .shuffleCopy(RNG.r).stream().filter(this::canSpawn)
.flatMap(this::stream))) .flatMap(this::stream)))
.collect(Collectors.toList())) .collect(Collectors.toList()))
.popRandom(RNG.r, max).forEach((i) -> spawn(c, id, i)); .popRandom(RNG.r, max).forEach((i) -> spawn(c, i));
//@done //@done
} }
private void spawn(Chunk c, UUID id, IrisEntitySpawn i) { private void spawn(Chunk c, IrisEntitySpawn i) {
if (i.spawn(getEngine(), c, RNG.r)) { if (i.spawn(getEngine(), c, RNG.r)) {
actuallySpawned++; actuallySpawned++;
getCooldown(i.getReferenceSpawner()).spawn(getEngine()); getCooldown(i.getReferenceSpawner()).spawn(getEngine());

View File

@ -597,12 +597,12 @@ public interface EngineParallaxManager extends DataProvider, IObjectPlacer {
double a = Math.max(v.getW(), v.getD()); double a = Math.max(v.getW(), v.getD());
for (IrisFeaturePositional k : rw.getFeatures()) { for (IrisFeaturePositional k : rw.getFeatures()) {
if (k.getX() == xx && k.getZ() == zz) { if (k.getX() == xx+1 && k.getZ() == zz-1) {
break; break;
} }
} }
rw.getFeatures().add(new IrisFeaturePositional(xx, zz, j.getZone())); rw.getFeatures().add(new IrisFeaturePositional(xx+1, zz-1, j.getZone()));
} }
} }
} }
@ -660,12 +660,12 @@ public interface EngineParallaxManager extends DataProvider, IObjectPlacer {
double a = Math.max(v.getW(), v.getD()); double a = Math.max(v.getW(), v.getD());
for (IrisFeaturePositional k : rw.getFeatures()) { for (IrisFeaturePositional k : rw.getFeatures()) {
if (k.getX() == xx && k.getZ() == zz) { if (k.getX() == xx+1 && k.getZ() == zz-1) {
continue placing; continue placing;
} }
} }
rw.getFeatures().add(new IrisFeaturePositional(xx, zz, j.getZone())); rw.getFeatures().add(new IrisFeaturePositional(xx+1, zz-1, j.getZone()));
} }
} }
} }

View File

@ -21,6 +21,7 @@ package com.volmit.iris.engine.object;
import com.volmit.iris.engine.object.annotations.Desc; import com.volmit.iris.engine.object.annotations.Desc;
import com.volmit.iris.engine.object.annotations.MinNumber; import com.volmit.iris.engine.object.annotations.MinNumber;
import com.volmit.iris.engine.object.annotations.Required; import com.volmit.iris.engine.object.annotations.Required;
import com.volmit.iris.util.documentation.ChunkCoordinates;
import com.volmit.iris.util.math.RNG; import com.volmit.iris.util.math.RNG;
import lombok.Data; import lombok.Data;
@ -37,6 +38,7 @@ public class IrisFeaturePotential {
@Desc("") @Desc("")
private IrisFeature zone = new IrisFeature(); private IrisFeature zone = new IrisFeature();
@ChunkCoordinates
public boolean hasZone(RNG rng, int cx, int cz) { public boolean hasZone(RNG rng, int cx, int cz) {
return rng.nextInt(rarity) == 0; return rng.nextInt(rarity) == 0;
} }