Parallax fixes

This commit is contained in:
Daniel Mills 2021-07-24 09:42:19 -04:00
parent a4ba07de99
commit 0d5e3a080c
4 changed files with 43 additions and 47 deletions

View File

@ -39,35 +39,35 @@ public abstract class EngineAssignedWorldManager extends EngineAssignedComponent
@EventHandler @EventHandler
public void on(WorldSaveEvent e) { public void on(WorldSaveEvent e) {
if (e.getWorld().equals(getTarget().getWorld())) { if (e.getWorld().equals(getTarget().getWorld().realWorld())) {
onSave(); onSave();
} }
} }
@EventHandler @EventHandler
public void on(WorldUnloadEvent e) { public void on(WorldUnloadEvent e) {
if (e.getWorld().equals(getTarget().getWorld())) { if (e.getWorld().equals(getTarget().getWorld().realWorld())) {
getEngine().close(); getEngine().close();
} }
} }
@EventHandler @EventHandler
public void on(EntitySpawnEvent e) { public void on(EntitySpawnEvent e) {
if (e.getEntity().getWorld().equals(getTarget().getWorld())) { if (e.getEntity().getWorld().equals(getTarget().getWorld().realWorld())) {
onEntitySpawn(e); onEntitySpawn(e);
} }
} }
@EventHandler @EventHandler
public void on(BlockBreakEvent e) { public void on(BlockBreakEvent e) {
if (e.getPlayer().getWorld().equals(getTarget().getWorld())) { if (e.getPlayer().getWorld().equals(getTarget().getWorld().realWorld())) {
onBlockBreak(e); onBlockBreak(e);
} }
} }
@EventHandler @EventHandler
public void on(BlockPlaceEvent e) { public void on(BlockPlaceEvent e) {
if (e.getPlayer().getWorld().equals(getTarget().getWorld())) { if (e.getPlayer().getWorld().equals(getTarget().getWorld().realWorld())) {
onBlockPlace(e); onBlockPlace(e);
} }
} }

View File

@ -37,13 +37,16 @@ import com.volmit.iris.engine.parallel.BurstExecutor;
import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.collection.KList;
import com.volmit.iris.util.collection.KMap; import com.volmit.iris.util.collection.KMap;
import com.volmit.iris.util.collection.KSet; import com.volmit.iris.util.collection.KSet;
import com.volmit.iris.util.documentation.BlockCoordinates;
import com.volmit.iris.util.documentation.ChunkCoordinates; import com.volmit.iris.util.documentation.ChunkCoordinates;
import com.volmit.iris.util.format.Form; import com.volmit.iris.util.format.Form;
import com.volmit.iris.util.function.Consumer4; import com.volmit.iris.util.function.Consumer4;
import com.volmit.iris.util.math.Position2;
import com.volmit.iris.util.math.RNG; import com.volmit.iris.util.math.RNG;
import com.volmit.iris.util.scheduling.IrisLock; import com.volmit.iris.util.scheduling.IrisLock;
import com.volmit.iris.util.scheduling.J; import com.volmit.iris.util.scheduling.J;
import com.volmit.iris.util.scheduling.PrecisionStopwatch; import com.volmit.iris.util.scheduling.PrecisionStopwatch;
import io.lumine.xikage.mythicmobs.utils.serialize.ChunkPosition;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.ChunkSnapshot; import org.bukkit.ChunkSnapshot;
import org.bukkit.block.TileState; import org.bukkit.block.TileState;
@ -203,55 +206,44 @@ public interface EngineParallaxManager extends DataProvider, IObjectPlacer {
IrisLock getFeatureLock(); IrisLock getFeatureLock();
@BlockCoordinates
default void forEachFeature(double x, double z, Consumer<IrisFeaturePositional> f) { default void forEachFeature(double x, double z, Consumer<IrisFeaturePositional> f) {
if (!getEngine().getDimension().hasFeatures(getEngine())) { if (!getEngine().getDimension().hasFeatures(getEngine())) {
return; return;
} }
long key = Cache.key(((int) x) >> 4, ((int) z) >> 4); KList<IrisFeaturePositional> pos = new KList<>();
for (IrisFeaturePositional ipf : getFeatureCache().compute(key, (ke, v) -> { for (IrisFeaturePositional i : getEngine().getDimension().getSpecificFeatures()) {
if (v != null) { if (i.shouldFilter(x, z)) {
return v; pos.add(i);
} }
}
getFeatureLock().lock(); int s = (int) Math.ceil(getParallaxSize() / 2D);
KList<IrisFeaturePositional> pos = new KList<>(); int i, j;
int cx = (int) x >> 4;
int cz = (int) z >> 4;
for (IrisFeaturePositional i : getEngine().getDimension().getSpecificFeatures()) { for (i = -s; i <= s; i++) {
if (i.shouldFilter(x, z)) { for (j = -s; j <= s; j++) {
pos.add(i); ParallaxChunkMeta m = getParallaxAccess().getMetaR(i + cx, j + cz);
}
}
int s = (int) Math.ceil(getParallaxSize() / 2D); try {
int i, j; for (IrisFeaturePositional k : m.getFeatures()) {
int cx = (int) x >> 4; if (k.shouldFilter(x, z)) {
int cz = (int) z >> 4; pos.add(k);
for (i = -s; i <= s; i++) {
for (j = -s; j <= s; j++) {
ParallaxChunkMeta m = getParallaxAccess().getMetaR(i + cx, j + cz);
synchronized (m) {
try {
for (IrisFeaturePositional k : m.getFeatures()) {
if (k.shouldFilter(x, z)) {
pos.add(k);
}
}
} catch (Throwable e) {
Iris.error("FILTER ERROR" + " AT " + (cx + i) + " " + (j + cz));
e.printStackTrace();
Iris.reportError(e);
} }
} }
} catch (Throwable e) {
Iris.error("FILTER ERROR" + " AT " + (cx + i) + " " + (j + cz));
e.printStackTrace();
Iris.reportError(e);
} }
} }
getFeatureLock().unlock(); }
return pos; for (IrisFeaturePositional ipf : pos) {
})) {
f.accept(ipf); f.accept(ipf);
} }
} }
@ -269,7 +261,7 @@ public interface EngineParallaxManager extends DataProvider, IObjectPlacer {
int i, j; int i, j;
KList<Runnable> after = new KList<>(); KList<Runnable> after = new KList<>();
int bs = (int) Math.pow((s * 2) + 1, 2); int bs = (int) Math.pow((s * 2) + 1, 2);
BurstExecutor burst = getEngine().getTarget().getBurster().burst(bs); BurstExecutor burst = getEngine().getTarget().getParallaxBurster().burst(bs);
for (i = -s; i <= s; i++) { for (i = -s; i <= s; i++) {
for (j = -s; j <= s; j++) { for (j = -s; j <= s; j++) {
int xx = i + x; int xx = i + x;
@ -277,8 +269,8 @@ public interface EngineParallaxManager extends DataProvider, IObjectPlacer {
int xxx = xx << 4; int xxx = xx << 4;
int zzz = zz << 4; int zzz = zz << 4;
if (!getParallaxAccess().isFeatureGenerated(xx, zz)) { if (!getParallaxAccess().isFeatureGenerated(xx, zz)) {
getParallaxAccess().setFeatureGenerated(xx, zz);
burst.queue(() -> { burst.queue(() -> {
getParallaxAccess().setFeatureGenerated(xx, zz);
RNG rng = new RNG(Cache.key(xx, zz)).nextParallelRNG(getEngine().getTarget().getWorld().seed()); RNG rng = new RNG(Cache.key(xx, zz)).nextParallelRNG(getEngine().getTarget().getWorld().seed());
IrisRegion region = getComplex().getRegionStream().get(xxx, zzz); IrisRegion region = getComplex().getRegionStream().get(xxx, zzz);
IrisBiome biome = getComplex().getTrueBiomeStream().get(xxx, zzz); IrisBiome biome = getComplex().getTrueBiomeStream().get(xxx, zzz);
@ -291,7 +283,7 @@ public interface EngineParallaxManager extends DataProvider, IObjectPlacer {
burst.complete(); burst.complete();
if (getEngine().getDimension().isPlaceObjects()) { if (getEngine().getDimension().isPlaceObjects()) {
burst = getEngine().getTarget().getBurster().burst(bs); burst = getEngine().getTarget().getParallaxBurster().burst(bs);
for (i = -s; i <= s; i++) { for (i = -s; i <= s; i++) {
int ii = i; int ii = i;
@ -307,7 +299,7 @@ public interface EngineParallaxManager extends DataProvider, IObjectPlacer {
} }
burst.complete(); burst.complete();
burst = getEngine().getTarget().getBurster().burst(bs); burst = getEngine().getTarget().getParallaxBurster().burst(bs);
for (i = -s; i <= s; i++) { for (i = -s; i <= s; i++) {
int ii = i; int ii = i;
@ -320,7 +312,7 @@ public interface EngineParallaxManager extends DataProvider, IObjectPlacer {
burst.complete(); burst.complete();
} }
getEngine().getTarget().getBurster().burst(after); getEngine().getTarget().getParallaxBurster().burst(after);
getParallaxAccess().setChunkGenerated(x, z); getParallaxAccess().setChunkGenerated(x, z);
p.end(); p.end();
getEngine().getMetrics().getParallax().put(p.getMilliseconds()); getEngine().getMetrics().getParallax().put(p.getMilliseconds());
@ -674,7 +666,7 @@ public interface EngineParallaxManager extends DataProvider, IObjectPlacer {
} }
Iris.verbose("Checking sizes for " + Form.f(objects.size()) + " referenced objects."); Iris.verbose("Checking sizes for " + Form.f(objects.size()) + " referenced objects.");
BurstExecutor e = getEngine().getTarget().getBurster().burst(objects.size()); BurstExecutor e = getEngine().getTarget().getParallaxBurster().burst(objects.size());
KMap<String, BlockVector> sizeCache = new KMap<>(); KMap<String, BlockVector> sizeCache = new KMap<>();
for (String i : objects) { for (String i : objects) {
e.queue(() -> { e.queue(() -> {

View File

@ -121,7 +121,7 @@ public class ParallaxRegion extends HunkRegion {
if ((t instanceof ByteArrayTag)) { if ((t instanceof ByteArrayTag)) {
try { try {
meta = metaAdapter.read((x, y, z) -> Hunk.newArrayHunk(32, 1, 32), (ByteArrayTag) t); meta = metaAdapter.read((x, y, z) -> Hunk.newAtomicHunk(32, 1, 32), (ByteArrayTag) t);
} catch (IOException e) { } catch (IOException e) {
Iris.reportError(e); Iris.reportError(e);
e.printStackTrace(); e.printStackTrace();
@ -129,7 +129,7 @@ public class ParallaxRegion extends HunkRegion {
} }
if (meta == null) { if (meta == null) {
meta = Hunk.newArrayHunk(32, 1, 32); meta = Hunk.newAtomicHunk(32, 1, 32);
} }
} }

View File

@ -83,4 +83,8 @@ public class Position2 {
public Position2 add(int x, int z) { public Position2 add(int x, int z) {
return new Position2(this.x + x, this.z + z); return new Position2(this.x + x, this.z + z);
} }
public Position2 blockToChunk() {
return new Position2(x >> 4, z >> 4);
}
} }