mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-18 18:23:06 +00:00
v2 parallax fixes!
This commit is contained in:
parent
b74a00de22
commit
f2339f26ca
@ -320,22 +320,14 @@ public class IrisObject extends IrisRegistrant
|
||||
}
|
||||
}
|
||||
|
||||
public void place(int x, int z, IObjectPlacer placer, IrisObjectPlacement config, RNG rng, IrisDataManager rdata)
|
||||
public int place(int x, int z, IObjectPlacer placer, IrisObjectPlacement config, RNG rng, IrisDataManager rdata)
|
||||
{
|
||||
if(shitty)
|
||||
{
|
||||
return;
|
||||
}
|
||||
place(x, -1, z, placer, config, rng, rdata);
|
||||
return place(x, -1, z, placer, config, rng, rdata);
|
||||
}
|
||||
|
||||
public void place(int x, int z, IObjectPlacer placer, IrisObjectPlacement config, RNG rng, CarveResult c, IrisDataManager rdata)
|
||||
public int place(int x, int z, IObjectPlacer placer, IrisObjectPlacement config, RNG rng, CarveResult c, IrisDataManager rdata)
|
||||
{
|
||||
if(shitty)
|
||||
{
|
||||
return;
|
||||
}
|
||||
place(x, -1, z, placer, config, rng, null, c, rdata);
|
||||
return place(x, -1, z, placer, config, rng, null, c, rdata);
|
||||
}
|
||||
|
||||
public int place(int x, int yv, int z, IObjectPlacer placer, IrisObjectPlacement config, RNG rng, IrisDataManager rdata)
|
||||
|
@ -16,6 +16,23 @@ public class BlockPosition
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
if(o == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(o instanceof BlockPosition)
|
||||
{
|
||||
BlockPosition ot = (BlockPosition) o;
|
||||
|
||||
return ot.x == x && ot.y == y && ot.z == z;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public int getChunkX()
|
||||
{
|
||||
return x >> 4;
|
||||
|
@ -176,4 +176,8 @@ public class EngineCompositeGenerator extends ChunkGenerator implements Hotloada
|
||||
public static EngineCompositeGenerator newProductionWorld() {
|
||||
return new EngineCompositeGenerator(null, true);
|
||||
}
|
||||
|
||||
public EngineCompound getComposite() {
|
||||
return compound;
|
||||
}
|
||||
}
|
@ -24,6 +24,29 @@ public interface EngineCompound extends Listener
|
||||
|
||||
public void saveEngineMetadata();
|
||||
|
||||
default Engine getEngineForHeight(int height)
|
||||
{
|
||||
if(getSize() == 1)
|
||||
{
|
||||
return getEngine(0);
|
||||
}
|
||||
|
||||
int buf = 0;
|
||||
|
||||
for(int i = 0; i < getSize(); i++)
|
||||
{
|
||||
Engine e = getEngine(i);
|
||||
buf += e.getHeight();
|
||||
|
||||
if(buf >= height)
|
||||
{
|
||||
return e;
|
||||
}
|
||||
}
|
||||
|
||||
return getEngine(getSize() - 1);
|
||||
}
|
||||
|
||||
public default void save()
|
||||
{
|
||||
saveEngineMetadata();
|
||||
|
@ -1,7 +1,11 @@
|
||||
package com.volmit.iris.v2.scaffold.engine;
|
||||
|
||||
import java.lang.reflect.Parameter;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import com.volmit.iris.util.*;
|
||||
import com.volmit.iris.v2.scaffold.parallax.ParallaxChunkMeta;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.util.BlockVector;
|
||||
|
||||
@ -13,12 +17,6 @@ import com.volmit.iris.object.IrisObject;
|
||||
import com.volmit.iris.object.IrisObjectPlacement;
|
||||
import com.volmit.iris.object.IrisRegion;
|
||||
import com.volmit.iris.object.IrisTextPlacement;
|
||||
import com.volmit.iris.util.B;
|
||||
import com.volmit.iris.util.Form;
|
||||
import com.volmit.iris.util.IObjectPlacer;
|
||||
import com.volmit.iris.util.KList;
|
||||
import com.volmit.iris.util.KSet;
|
||||
import com.volmit.iris.util.RNG;
|
||||
import com.volmit.iris.v2.generator.IrisComplex;
|
||||
import com.volmit.iris.v2.scaffold.cache.Cache;
|
||||
import com.volmit.iris.v2.scaffold.data.DataProvider;
|
||||
@ -81,7 +79,13 @@ public interface EngineParallax extends DataProvider, IObjectPlacer
|
||||
|
||||
default void insertParallax(int x, int z, Hunk<BlockData> data)
|
||||
{
|
||||
data.compute3D(getEngine().getParallelism(), (xx,yy,zz,h)->{
|
||||
ParallaxChunkMeta meta = getParallaxAccess().getMetaR(x>>4, z>>4);
|
||||
|
||||
if(!meta.isObjects()) {
|
||||
return;
|
||||
}
|
||||
|
||||
data.compute2DYRange(getEngine().getParallelism(), meta.getMinObject(), meta.getMaxObject(), (xx,yy,zz,h)->{
|
||||
for(int i = x+xx; i < x+xx+ h.getWidth(); i++)
|
||||
{
|
||||
for(int j= z+zz; j < z+zz + h.getDepth(); j++)
|
||||
@ -93,6 +97,8 @@ public interface EngineParallax extends DataProvider, IObjectPlacer
|
||||
if(d != null)
|
||||
{
|
||||
h.set(i - (x-xx), k-yy, j - (z+zz), d);
|
||||
// DONT TRUST INTELIJ ^^^^
|
||||
// ITS A FUCKING LIE
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -139,13 +145,36 @@ public interface EngineParallax extends DataProvider, IObjectPlacer
|
||||
}
|
||||
|
||||
default void place(RNG rng, int x, int z, IrisObjectPlacement objectPlacement)
|
||||
{
|
||||
place(rng, x,-1, z, objectPlacement);
|
||||
}
|
||||
|
||||
default void place(RNG rng, int x, int forceY, int z, IrisObjectPlacement objectPlacement)
|
||||
{
|
||||
for(int i = 0; i < objectPlacement.getDensity(); i++)
|
||||
{
|
||||
objectPlacement.getSchematic(getComplex(), rng).place(rng.i(x, x+16), rng.i(z, z+16), this, objectPlacement, rng, getData());
|
||||
IrisObject v = objectPlacement.getSchematic(getComplex(), rng);
|
||||
int xx = rng.i(x, x+16);
|
||||
int zz = rng.i(z, z+16);
|
||||
int id = rng.i(0, Integer.MAX_VALUE);
|
||||
v.place(xx, forceY, zz, this, objectPlacement, rng, (b) -> {
|
||||
getParallaxAccess().setObject(b.getX(), b.getY(), b.getZ(), v.getLoadKey() + "@" + id);
|
||||
ParallaxChunkMeta meta = getParallaxAccess().getMetaRW(b.getX() >> 4, b.getZ() >> 4);
|
||||
meta.setObjects(true);
|
||||
meta.setMaxObject(Math.max(b.getY(), meta.getMaxObject()));
|
||||
meta.setMinObject(Math.min(b.getY(), Math.max(meta.getMinObject(), 0)));
|
||||
}, null, getData());
|
||||
}
|
||||
}
|
||||
|
||||
default void updateParallaxChunkObjectData(int minY, int maxY, int x, int z, IrisObject v)
|
||||
{
|
||||
ParallaxChunkMeta meta = getParallaxAccess().getMetaRW(x >> 4, z >> 4);
|
||||
meta.setObjects(true);
|
||||
meta.setMaxObject(Math.max(maxY, meta.getMaxObject()));
|
||||
meta.setMinObject(Math.min(minY, Math.max(meta.getMinObject(), 0)));
|
||||
}
|
||||
|
||||
default int computeParallaxSize()
|
||||
{
|
||||
Iris.verbose("Calculating the Parallax Size in Parallel");
|
||||
|
@ -622,7 +622,31 @@ public interface Hunk<T>
|
||||
{
|
||||
rq.add(r);
|
||||
}
|
||||
}), (xx, yy, zz, c) -> insert(xx, yy, zz, c));
|
||||
}), this::insert);
|
||||
e.complete();
|
||||
rq.forEach(Runnable::run);
|
||||
return this;
|
||||
}
|
||||
|
||||
default Hunk<T> compute2DYRange(int parallelism, int ymin, int ymax, Consumer4<Integer, Integer, Integer, Hunk<T>> v)
|
||||
{
|
||||
if(get2DDimension(parallelism) == 1)
|
||||
{
|
||||
v.accept(0, 0, 0, this);
|
||||
return this;
|
||||
}
|
||||
|
||||
BurstExecutor e = MultiBurst.burst.burst(parallelism);
|
||||
KList<Runnable> rq = new KList<Runnable>(parallelism);
|
||||
getSections2DYLimit(parallelism, ymin, ymax, (xx, yy, zz, h, r) -> e.queue(() ->
|
||||
{
|
||||
v.accept(xx, yy, zz, h);
|
||||
|
||||
synchronized(rq)
|
||||
{
|
||||
rq.add(r);
|
||||
}
|
||||
}), this::insert);
|
||||
e.complete();
|
||||
rq.forEach(Runnable::run);
|
||||
return this;
|
||||
@ -650,7 +674,7 @@ public interface Hunk<T>
|
||||
{
|
||||
rq.add(r);
|
||||
}
|
||||
}), (xx, yy, zz, c) -> insert(xx, yy, zz, c));
|
||||
}), this::insert);
|
||||
e.complete();
|
||||
rq.forEach(Runnable::run);
|
||||
return this;
|
||||
@ -658,7 +682,7 @@ public interface Hunk<T>
|
||||
|
||||
default Hunk<T> getSections2D(int sections, Consumer5<Integer, Integer, Integer, Hunk<T>, Runnable> v)
|
||||
{
|
||||
return getSections2D(sections, v, (xx, yy, zz, c) -> insert(xx, yy, zz, c));
|
||||
return getSections2D(sections, v, this::insert);
|
||||
}
|
||||
|
||||
default Hunk<T> getSections2D(int sections, Consumer5<Integer, Integer, Integer, Hunk<T>, Runnable> v, Consumer4<Integer, Integer, Integer, Hunk<T>> inserter)
|
||||
@ -693,6 +717,38 @@ public interface Hunk<T>
|
||||
return this;
|
||||
}
|
||||
|
||||
default Hunk<T> getSections2DYLimit(int sections, int ymin, int ymax, Consumer5<Integer, Integer, Integer, Hunk<T>, Runnable> v, Consumer4<Integer, Integer, Integer, Hunk<T>> inserter)
|
||||
{
|
||||
int dim = (int) get2DDimension(sections);
|
||||
|
||||
if(sections <= 1)
|
||||
{
|
||||
getSection(0, 0, 0, getWidth(), getHeight(), getDepth(), (hh, r) -> v.accept(0, 0, 0, hh, r), inserter);
|
||||
return this;
|
||||
}
|
||||
|
||||
int w = getWidth() / dim;
|
||||
int wr = getWidth() - (w * dim);
|
||||
int d = getDepth() / dim;
|
||||
int dr = getDepth() - (d * dim);
|
||||
int i, j;
|
||||
|
||||
for(i = 0; i < getWidth(); i += w)
|
||||
{
|
||||
int ii = i;
|
||||
|
||||
for(j = 0; j < getDepth(); j += d)
|
||||
{
|
||||
int jj = j;
|
||||
getSection(i, ymin, j, i + w + (i == 0 ? wr : 0), ymax, j + d + (j == 0 ? dr : 0), (h, r) -> v.accept(ii, ymin, jj, h, r), inserter);
|
||||
i = i == 0 ? i + wr : i;
|
||||
j = j == 0 ? j + dr : j;
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
default Hunk<T> getSections3D(int sections, Consumer5<Integer, Integer, Integer, Hunk<T>, Runnable> v)
|
||||
{
|
||||
return getSections3D(sections, v, (xx, yy, zz, c) -> insert(xx, yy, zz, c));
|
||||
|
@ -43,7 +43,7 @@ public class HunkRegion
|
||||
in.close();
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
catch(Throwable ignored)
|
||||
{
|
||||
|
||||
}
|
||||
@ -80,7 +80,6 @@ public class HunkRegion
|
||||
NBTOutputStream out = new NBTOutputStream(fos);
|
||||
out.writeTag(compound);
|
||||
out.close();
|
||||
Iris.verbose("Saved Region: " + getX() + " " + getZ());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,17 +2,10 @@ package com.volmit.iris.v2.scaffold.hunk.io;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.volmit.iris.util.*;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.util.ByteArrayTag;
|
||||
import com.volmit.iris.util.CompoundTag;
|
||||
import com.volmit.iris.util.Function2;
|
||||
import com.volmit.iris.util.Function3;
|
||||
import com.volmit.iris.util.KList;
|
||||
import com.volmit.iris.util.KMap;
|
||||
import com.volmit.iris.util.M;
|
||||
import com.volmit.iris.util.Tag;
|
||||
import com.volmit.iris.v2.scaffold.hunk.Hunk;
|
||||
|
||||
public class HunkRegionSlice<T>
|
||||
@ -24,9 +17,9 @@ public class HunkRegionSlice<T>
|
||||
private final HunkIOAdapter<T> adapter;
|
||||
private final CompoundTag compound;
|
||||
private final String key;
|
||||
private final KMap<Long, Hunk<T>> loadedChunks;
|
||||
private final KMap<Long, Long> lastUse;
|
||||
private final KList<Long> save;
|
||||
private final KMap<ChunkPosition, Hunk<T>> loadedChunks;
|
||||
private final KMap<ChunkPosition, Long> lastUse;
|
||||
private final KList<ChunkPosition> save;
|
||||
private final int height;
|
||||
|
||||
public HunkRegionSlice(int height, Function3<Integer, Integer, Integer, Hunk<T>> factory, HunkIOAdapter<T> adapter, CompoundTag compound, String key)
|
||||
@ -46,14 +39,21 @@ public class HunkRegionSlice<T>
|
||||
if(loadedChunks.size() != lastUse.size())
|
||||
{
|
||||
Iris.warn("Incorrect chunk use counts in " + key);
|
||||
|
||||
for(ChunkPosition i : lastUse.k())
|
||||
{
|
||||
if(!loadedChunks.containsKey(i))
|
||||
{
|
||||
Iris.warn(" Missing LoadChunkKey " + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(Long i : lastUse.k())
|
||||
for(ChunkPosition i : lastUse.k())
|
||||
{
|
||||
if(M.ms() - lastUse.get(i) > t)
|
||||
{
|
||||
System.out.println("Trying to unload " + i);
|
||||
unload((int)(i >> 32), (int) i.longValue());
|
||||
unload(i.getX(), i.getZ());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -74,9 +74,9 @@ public class HunkRegionSlice<T>
|
||||
|
||||
public void save()
|
||||
{
|
||||
for(Long i : save)
|
||||
for(ChunkPosition i : save)
|
||||
{
|
||||
save((int)(i >> 32), (int) i.longValue());
|
||||
save(i.getX(), i.getZ());
|
||||
}
|
||||
|
||||
save.clear();
|
||||
@ -112,9 +112,9 @@ public class HunkRegionSlice<T>
|
||||
|
||||
public synchronized void unloadAll()
|
||||
{
|
||||
for(Long i : loadedChunks.k())
|
||||
for(ChunkPosition i : loadedChunks.k())
|
||||
{
|
||||
unload((int)(i >> 32), (int) i.longValue());
|
||||
unload(i.getX(), i.getZ());
|
||||
}
|
||||
|
||||
save.clear();
|
||||
@ -136,7 +136,7 @@ public class HunkRegionSlice<T>
|
||||
|
||||
public boolean isLoaded(int x, int z)
|
||||
{
|
||||
return loadedChunks.containsKey(ikey(x, z));
|
||||
return loadedChunks.containsKey(new ChunkPosition(x, z));
|
||||
}
|
||||
|
||||
public synchronized void save(int x, int z)
|
||||
@ -149,11 +149,9 @@ public class HunkRegionSlice<T>
|
||||
|
||||
public synchronized void unload(int x, int z)
|
||||
{
|
||||
long key = ikey(x, z);
|
||||
System.out.println(x + "," + z + " = " + key);
|
||||
ChunkPosition key = new ChunkPosition(x, z);
|
||||
if(isLoaded(x, z))
|
||||
{
|
||||
System.out.println("HOT IT");
|
||||
if(save.contains(key))
|
||||
{
|
||||
save(x, z);
|
||||
@ -163,18 +161,13 @@ public class HunkRegionSlice<T>
|
||||
lastUse.remove(key);
|
||||
loadedChunks.remove(key);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
System.out.println("IDK WHERE " + key + " IS");
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized Hunk<T> load(int x, int z)
|
||||
{
|
||||
if(isLoaded(x, z))
|
||||
{
|
||||
return loadedChunks.get(ikey(x, z));
|
||||
return loadedChunks.get(new ChunkPosition(x, z));
|
||||
}
|
||||
|
||||
Hunk<T> v = null;
|
||||
@ -197,14 +190,14 @@ public class HunkRegionSlice<T>
|
||||
v = factory.apply(16, height, 16);
|
||||
}
|
||||
|
||||
loadedChunks.put(ikey(x, z), v);
|
||||
loadedChunks.put(new ChunkPosition(x, z), v);
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
public Hunk<T> get(int x, int z)
|
||||
{
|
||||
long key = ikey(x, z);
|
||||
ChunkPosition key = new ChunkPosition(x, z);
|
||||
|
||||
Hunk<T> c = loadedChunks.get(key);
|
||||
|
||||
@ -213,7 +206,7 @@ public class HunkRegionSlice<T>
|
||||
c = load(x, z);
|
||||
}
|
||||
|
||||
lastUse.put(ikey(x, z), M.ms());
|
||||
lastUse.put(new ChunkPosition(x, z), M.ms());
|
||||
|
||||
return c;
|
||||
}
|
||||
@ -225,15 +218,10 @@ public class HunkRegionSlice<T>
|
||||
|
||||
public Hunk<T> getRW(int x, int z)
|
||||
{
|
||||
save.addIfMissing(ikey(x, z));
|
||||
save.addIfMissing(new ChunkPosition(x, z));
|
||||
return get(x, z);
|
||||
}
|
||||
|
||||
private long ikey(int x, int z)
|
||||
{
|
||||
return (((long) x) << 32) | (((long) z) & 0xffffffffL);
|
||||
}
|
||||
|
||||
private String key(int x, int z)
|
||||
{
|
||||
if(x < 0 || x >= 32 || z < 0 || z >= 32)
|
||||
@ -241,7 +229,7 @@ public class HunkRegionSlice<T>
|
||||
throw new IndexOutOfBoundsException("The chunk " + x + " " + z + " is out of bounds max is 31x31");
|
||||
}
|
||||
|
||||
return key + "." + Long.toString(ikey(x,z), 36);
|
||||
return key + "." + x + "." + z;
|
||||
}
|
||||
|
||||
public int getLoadCount()
|
||||
|
@ -19,18 +19,34 @@ public class ParallaxChunkMeta {
|
||||
public void write(ParallaxChunkMeta parallaxChunkMeta, DataOutputStream dos) throws IOException {
|
||||
dos.writeBoolean(parallaxChunkMeta.isGenerated());
|
||||
dos.writeBoolean(parallaxChunkMeta.isParallaxGenerated());
|
||||
dos.writeBoolean(parallaxChunkMeta.isObjects());
|
||||
|
||||
if(parallaxChunkMeta.isObjects())
|
||||
{
|
||||
dos.writeByte(parallaxChunkMeta.getMinObject() + Byte.MIN_VALUE);
|
||||
dos.writeByte(parallaxChunkMeta.getMaxObject() + Byte.MIN_VALUE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParallaxChunkMeta read(DataInputStream din) throws IOException {
|
||||
return new ParallaxChunkMeta(din.readBoolean(), din.readBoolean());
|
||||
boolean g = din.readBoolean();
|
||||
boolean p = din.readBoolean();
|
||||
boolean o = din.readBoolean();
|
||||
int min = o ? din.readByte() - Byte.MIN_VALUE : -1;
|
||||
int max = o ? din.readByte() - Byte.MIN_VALUE : -1;
|
||||
return new ParallaxChunkMeta(g, p, o, min, max);
|
||||
}
|
||||
};
|
||||
|
||||
private boolean generated;
|
||||
private boolean parallaxGenerated;
|
||||
private boolean objects;
|
||||
private int maxObject = -1;
|
||||
private int minObject = -1;
|
||||
|
||||
public ParallaxChunkMeta()
|
||||
{
|
||||
this(false, false);
|
||||
this(false, false, false, -1, -1);
|
||||
}
|
||||
}
|
||||
|
@ -192,7 +192,7 @@ public class ParallaxWorld implements ParallaxAccess
|
||||
|
||||
public void cleanup()
|
||||
{
|
||||
cleanup(10000, 3000);
|
||||
cleanup(10000, 5000);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
x
Reference in New Issue
Block a user