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
public void on(WorldSaveEvent e) {
if (e.getWorld().equals(getTarget().getWorld())) {
if (e.getWorld().equals(getTarget().getWorld().realWorld())) {
onSave();
}
}
@EventHandler
public void on(WorldUnloadEvent e) {
if (e.getWorld().equals(getTarget().getWorld())) {
if (e.getWorld().equals(getTarget().getWorld().realWorld())) {
getEngine().close();
}
}
@EventHandler
public void on(EntitySpawnEvent e) {
if (e.getEntity().getWorld().equals(getTarget().getWorld())) {
if (e.getEntity().getWorld().equals(getTarget().getWorld().realWorld())) {
onEntitySpawn(e);
}
}
@EventHandler
public void on(BlockBreakEvent e) {
if (e.getPlayer().getWorld().equals(getTarget().getWorld())) {
if (e.getPlayer().getWorld().equals(getTarget().getWorld().realWorld())) {
onBlockBreak(e);
}
}
@EventHandler
public void on(BlockPlaceEvent e) {
if (e.getPlayer().getWorld().equals(getTarget().getWorld())) {
if (e.getPlayer().getWorld().equals(getTarget().getWorld().realWorld())) {
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.KMap;
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.format.Form;
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.scheduling.IrisLock;
import com.volmit.iris.util.scheduling.J;
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
import io.lumine.xikage.mythicmobs.utils.serialize.ChunkPosition;
import org.bukkit.Chunk;
import org.bukkit.ChunkSnapshot;
import org.bukkit.block.TileState;
@ -203,55 +206,44 @@ public interface EngineParallaxManager extends DataProvider, IObjectPlacer {
IrisLock getFeatureLock();
@BlockCoordinates
default void forEachFeature(double x, double z, Consumer<IrisFeaturePositional> f) {
if (!getEngine().getDimension().hasFeatures(getEngine())) {
return;
}
long key = Cache.key(((int) x) >> 4, ((int) z) >> 4);
KList<IrisFeaturePositional> pos = new KList<>();
for (IrisFeaturePositional ipf : getFeatureCache().compute(key, (ke, v) -> {
if (v != null) {
return v;
for (IrisFeaturePositional i : getEngine().getDimension().getSpecificFeatures()) {
if (i.shouldFilter(x, z)) {
pos.add(i);
}
}
getFeatureLock().lock();
KList<IrisFeaturePositional> pos = new KList<>();
int s = (int) Math.ceil(getParallaxSize() / 2D);
int i, j;
int cx = (int) x >> 4;
int cz = (int) z >> 4;
for (IrisFeaturePositional i : getEngine().getDimension().getSpecificFeatures()) {
if (i.shouldFilter(x, z)) {
pos.add(i);
}
}
for (i = -s; i <= s; i++) {
for (j = -s; j <= s; j++) {
ParallaxChunkMeta m = getParallaxAccess().getMetaR(i + cx, j + cz);
int s = (int) Math.ceil(getParallaxSize() / 2D);
int i, j;
int cx = (int) x >> 4;
int cz = (int) z >> 4;
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);
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);
}
}
getFeatureLock().unlock();
}
return pos;
})) {
for (IrisFeaturePositional ipf : pos) {
f.accept(ipf);
}
}
@ -269,7 +261,7 @@ public interface EngineParallaxManager extends DataProvider, IObjectPlacer {
int i, j;
KList<Runnable> after = new KList<>();
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 (j = -s; j <= s; j++) {
int xx = i + x;
@ -277,8 +269,8 @@ public interface EngineParallaxManager extends DataProvider, IObjectPlacer {
int xxx = xx << 4;
int zzz = zz << 4;
if (!getParallaxAccess().isFeatureGenerated(xx, zz)) {
getParallaxAccess().setFeatureGenerated(xx, zz);
burst.queue(() -> {
getParallaxAccess().setFeatureGenerated(xx, zz);
RNG rng = new RNG(Cache.key(xx, zz)).nextParallelRNG(getEngine().getTarget().getWorld().seed());
IrisRegion region = getComplex().getRegionStream().get(xxx, zzz);
IrisBiome biome = getComplex().getTrueBiomeStream().get(xxx, zzz);
@ -291,7 +283,7 @@ public interface EngineParallaxManager extends DataProvider, IObjectPlacer {
burst.complete();
if (getEngine().getDimension().isPlaceObjects()) {
burst = getEngine().getTarget().getBurster().burst(bs);
burst = getEngine().getTarget().getParallaxBurster().burst(bs);
for (i = -s; i <= s; i++) {
int ii = i;
@ -307,7 +299,7 @@ public interface EngineParallaxManager extends DataProvider, IObjectPlacer {
}
burst.complete();
burst = getEngine().getTarget().getBurster().burst(bs);
burst = getEngine().getTarget().getParallaxBurster().burst(bs);
for (i = -s; i <= s; i++) {
int ii = i;
@ -320,7 +312,7 @@ public interface EngineParallaxManager extends DataProvider, IObjectPlacer {
burst.complete();
}
getEngine().getTarget().getBurster().burst(after);
getEngine().getTarget().getParallaxBurster().burst(after);
getParallaxAccess().setChunkGenerated(x, z);
p.end();
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.");
BurstExecutor e = getEngine().getTarget().getBurster().burst(objects.size());
BurstExecutor e = getEngine().getTarget().getParallaxBurster().burst(objects.size());
KMap<String, BlockVector> sizeCache = new KMap<>();
for (String i : objects) {
e.queue(() -> {

View File

@ -121,7 +121,7 @@ public class ParallaxRegion extends HunkRegion {
if ((t instanceof ByteArrayTag)) {
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) {
Iris.reportError(e);
e.printStackTrace();
@ -129,7 +129,7 @@ public class ParallaxRegion extends HunkRegion {
}
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) {
return new Position2(this.x + x, this.z + z);
}
public Position2 blockToChunk() {
return new Position2(x >> 4, z >> 4);
}
}