9
0
mirror of https://github.com/VolmitSoftware/Iris.git synced 2025-12-31 04:46:40 +00:00

Fixes & Mem improvements

This commit is contained in:
Daniel Mills
2020-07-31 01:02:00 -04:00
parent 9d326d240a
commit 121653a8f2
25 changed files with 42206 additions and 62 deletions

View File

@@ -91,7 +91,7 @@ public class IrisBiomeDecorator
if(!layerGenerators.containsKey(key))
{
layerGenerators.put(key, CNG.signature(rng.nextParallelRNG(getBlockData().size())).scale(1D / zoom));
layerGenerators.put(key, CNG.signature(rng.nextParallelRNG((int) (getBlockData().size() + key))).scale(1D / zoom));
}
return layerGenerators.get(key);
@@ -121,8 +121,8 @@ public class IrisBiomeDecorator
}
RNG nrng = rng.nextParallelRNG((int) (z - (int) ((x + 34856) * (int) (x + z + (int) (28835521 + (getChance() * 1000) + getStackMin() + getStackMax() + (getZoom() * 556))))));
double xx = dispersion.equals(Dispersion.SCATTER) ? nrng.i(-100000, 100000) : x;
double zz = dispersion.equals(Dispersion.SCATTER) ? nrng.i(-100000, 100000) : z;
double xx = dispersion.equals(Dispersion.SCATTER) ? nrng.i(-1000000, 1000000) : x;
double zz = dispersion.equals(Dispersion.SCATTER) ? nrng.i(-1000000, 1000000) : z;
if(getGenerator(rng).fitDoubleD(0D, 1D, xx, zz) <= chance)
{

View File

@@ -5,11 +5,14 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.zip.GZIPInputStream;
import org.bukkit.World;
import com.volmit.iris.IrisSettings;
import com.volmit.iris.util.ByteArrayTag;
import com.volmit.iris.util.CompoundTag;
import com.volmit.iris.util.CustomOutputStream;
import com.volmit.iris.util.KMap;
import com.volmit.iris.util.NBTInputStream;
import com.volmit.iris.util.NBTOutputStream;
@@ -18,42 +21,64 @@ import com.volmit.iris.util.Tag;
public class AtomicRegionData
{
private final World world;
private KMap<String, Tag> tag;
private Tag[] tag;
public AtomicRegionData(World world)
{
this.world = world;
tag = new KMap<>();
tag = new Tag[1024];
}
public int size()
{
return tag.size();
return tag.length;
}
public void read(InputStream in) throws IOException
{
NBTInputStream nin = new NBTInputStream(in);
tag = new KMap<>();
tag.putAll(((CompoundTag) nin.readTag()).getValue());
KMap<String, Tag> tags = new KMap<>();
tags.putAll(((CompoundTag) nin.readTag()).getValue());
for(String i : tags.keySet())
{
int x = Integer.valueOf(i.split("\\Q.\\E")[0]);
int z = Integer.valueOf(i.split("\\Q.\\E")[1]);
tag[(z << 5) | x] = tags.get(i);
}
nin.close();
}
public void write(OutputStream out) throws IOException
{
NBTOutputStream nos = new NBTOutputStream(out);
nos.writeTag(new CompoundTag("imca", tag));
KMap<String, Tag> tags = new KMap<>();
for(int i = 0; i < 32; i++)
{
for(int j = 0; j < 32; j++)
{
if(tag[(j << 5) | i] != null)
{
tags.put(i + "." + j, tag[(j << 5) | i]);
}
}
}
nos.writeTag(new CompoundTag("imca", tags));
nos.close();
}
public boolean contains(int rx, int rz)
{
return tag.containsKey(rx + "." + rz);
return tag[(rz << 5) | rx] != null;
}
public void delete(int rx, int rz)
{
tag.remove(rx + "." + rz);
tag[(rz << 5) | rx] = null;
}
public void set(int rx, int rz, AtomicSliverMap data) throws IOException
@@ -63,9 +88,19 @@ public class AtomicRegionData
return;
}
OutputStream out;
ByteArrayOutputStream boas = new ByteArrayOutputStream();
data.write(boas);
tag.put(rx + "." + rz, new ByteArrayTag(rx + "." + rz, boas.toByteArray()));
out = boas;
if(IrisSettings.get().parallaxCompression)
{
out = new CustomOutputStream(boas, IrisSettings.get().parallaxCompressionLevel);
}
data.write(out);
out.flush();
out.close();
tag[(rz << 5) | rx] = new ByteArrayTag(rx + "." + rz, boas.toByteArray());
}
public AtomicSliverMap get(int rx, int rz) throws IOException
@@ -79,8 +114,20 @@ public class AtomicRegionData
try
{
ByteArrayTag btag = (ByteArrayTag) tag.get(rx + "." + rz);
ByteArrayInputStream in = new ByteArrayInputStream(btag.getValue());
ByteArrayTag btag = (ByteArrayTag) tag[(rz << 5) | rx];
InputStream in;
if(IrisSettings.get().parallaxCompression)
{
in = new GZIPInputStream(new ByteArrayInputStream(btag.getValue()));
}
else
{
in = new ByteArrayInputStream(btag.getValue());
}
data.read(in);
}
@@ -96,4 +143,20 @@ public class AtomicRegionData
{
return world;
}
public long guessMemoryUsage()
{
long bytes = 0;
for(int i = 0; i < 1024; i++)
{
if(tag[i] != null && tag[i] instanceof ByteArrayTag)
{
bytes += 122;
bytes += ((ByteArrayTag) tag[i]).getValue().length;
}
}
return bytes;
}
}

View File

@@ -32,6 +32,7 @@ public class AtomicSliver
private long last = M.ms();
private int x;
private int z;
boolean modified = false;
public AtomicSliver(int x, int z)
{
@@ -69,7 +70,8 @@ public class AtomicSliver
lock.lock();
block.put(h, d);
modified = true;
if(d.getMaterial().equals(Material.AIR) || d.getMaterial().equals(Material.CAVE_AIR))
{
lock.unlock();
@@ -88,6 +90,7 @@ public class AtomicSliver
}
lock.lock();
modified = true;
block.put(h, d);
lock.unlock();
}
@@ -113,6 +116,7 @@ public class AtomicSliver
{
lock.lock();
biome.put(h, d);
modified = true;
highestBiome = h > highestBiome ? h : highestBiome;
lock.unlock();
}
@@ -120,6 +124,7 @@ public class AtomicSliver
public void set(int h, IrisBiome d)
{
lock.lock();
modified = true;
truebiome.put(h, d);
lock.unlock();
}
@@ -173,6 +178,7 @@ public class AtomicSliver
{
block.put(i, BlockDataTools.getBlockData(din.readUTF()));
}
modified = false;
lock.unlock();
}

View File

@@ -93,4 +93,17 @@ public class AtomicSliverMap
i.inject(currentData);
}
}
public boolean isModified()
{
for(AtomicSliver i : slivers)
{
if(i.isModified())
{
return true;
}
}
return false;
}
}

View File

@@ -10,6 +10,7 @@ import org.bukkit.World;
import com.volmit.iris.Iris;
import com.volmit.iris.util.ChronoLatch;
import com.volmit.iris.util.ChunkPosition;
import com.volmit.iris.util.KList;
import com.volmit.iris.util.KMap;
import com.volmit.iris.util.M;
@@ -20,8 +21,10 @@ public class AtomicWorldData
private KMap<ChunkPosition, AtomicRegionData> loadedSections;
private KMap<ChunkPosition, Long> lastRegion;
private KMap<ChunkPosition, Long> lastChunk;
private KList<ChunkPosition> unloadRegions;
private KList<ChunkPosition> unloadChunks;
private String prefix;
private ChronoLatch cl = new ChronoLatch(3000);
private ChronoLatch cl = new ChronoLatch(333);
public AtomicWorldData(World world, String prefix)
{
@@ -30,6 +33,8 @@ public class AtomicWorldData
loadedChunks = new KMap<>();
lastRegion = new KMap<>();
lastChunk = new KMap<>();
unloadRegions = new KList<>();
unloadChunks = new KList<>();
this.prefix = prefix;
getSubregionFolder().mkdirs();
}
@@ -162,10 +167,16 @@ public class AtomicWorldData
public void saveChunk(ChunkPosition i) throws IOException
{
int x = i.getX();
int z = i.getZ();
AtomicRegionData dat = loadSection(x >> 5, z >> 5, true);
dat.set(x & 31, z & 31, loadedChunks.get(i));
AtomicSliverMap m = loadedChunks.get(i);
if(m.isModified())
{
int x = i.getX();
int z = i.getZ();
AtomicRegionData dat = loadSection(x >> 5, z >> 5, true);
dat.set(x & 31, z & 31, m);
}
loadedChunks.remove(i);
lastChunk.remove(i);
}
@@ -261,38 +272,68 @@ public class AtomicWorldData
return;
}
for(ChunkPosition i : lastRegion.k())
int m = 0;
for(ChunkPosition i : lastRegion.keySet())
{
if(m > 1)
{
break;
}
if(M.ms() - lastRegion.get(i) > 60000)
{
lastRegion.remove(i);
try
{
unloadSection(i, true);
}
catch(IOException e)
{
e.printStackTrace();
}
unloadRegions.add(i);
m++;
}
}
for(ChunkPosition i : lastChunk.k())
m = 0;
for(ChunkPosition i : unloadRegions)
{
if(M.ms() - lastChunk.get(i) > 60000)
{
try
{
saveChunk(i);
}
lastRegion.remove(i);
catch(IOException e)
{
Iris.warn("Failed to save chunk");
}
try
{
unloadSection(i, true);
}
catch(IOException e)
{
e.printStackTrace();
}
}
unloadRegions.clear();
for(ChunkPosition i : lastChunk.keySet())
{
if(m > 7)
{
break;
}
if(M.ms() - lastChunk.get(i) > 15000)
{
m++;
unloadChunks.add(i);
}
}
for(ChunkPosition i : unloadChunks)
{
try
{
saveChunk(i);
}
catch(IOException e)
{
Iris.warn("Failed to save chunk");
}
}
unloadChunks.clear();
}
}