mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-18 18:23:06 +00:00
Fixes for plax
This commit is contained in:
parent
a9410d92a2
commit
5994cc66b4
@ -33,8 +33,9 @@ public class HunkRegionSlice<T>
|
||||
this.lastUse = new KMap<>();
|
||||
}
|
||||
|
||||
public void cleanup(long t)
|
||||
public int cleanup(long t)
|
||||
{
|
||||
int v = 0;
|
||||
if(loadedChunks.size() != lastUse.size())
|
||||
{
|
||||
Iris.warn("Incorrect chunk use counts in " + key);
|
||||
@ -50,11 +51,15 @@ public class HunkRegionSlice<T>
|
||||
|
||||
for(ChunkPosition i : lastUse.k())
|
||||
{
|
||||
if(M.ms() - lastUse.get(i) > t)
|
||||
Long l = lastUse.get(i);
|
||||
if(l == null || M.ms() - l > t)
|
||||
{
|
||||
v++;
|
||||
unload(i.getX(), i.getZ());
|
||||
}
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
public void clear()
|
||||
@ -109,16 +114,19 @@ public class HunkRegionSlice<T>
|
||||
compound.getValue().put(key(x, z), hunk.writeByteArrayTag(adapter, key(x, z)));
|
||||
}
|
||||
|
||||
public synchronized void unloadAll()
|
||||
public synchronized int unloadAll()
|
||||
{
|
||||
int v = 0;
|
||||
for(ChunkPosition i : loadedChunks.k())
|
||||
{
|
||||
unload(i.getX(), i.getZ());
|
||||
v++;
|
||||
}
|
||||
|
||||
save.clear();
|
||||
loadedChunks.clear();
|
||||
lastUse.clear();
|
||||
return v;
|
||||
}
|
||||
|
||||
public synchronized void save(Hunk<T> region, int x, int z)
|
||||
|
@ -147,12 +147,12 @@ public class ParallaxRegion extends HunkRegion
|
||||
super.save();
|
||||
}
|
||||
|
||||
public void unload()
|
||||
public int unload()
|
||||
{
|
||||
blockSlice.unloadAll();
|
||||
objectSlice.unloadAll();
|
||||
updateSlice.unloadAll();
|
||||
unloadMetaHunk();
|
||||
return blockSlice.unloadAll()+
|
||||
objectSlice.unloadAll()+
|
||||
updateSlice.unloadAll();
|
||||
}
|
||||
|
||||
public HunkRegionSlice<BlockData> getBlockSlice() {
|
||||
@ -170,9 +170,9 @@ public class ParallaxRegion extends HunkRegion
|
||||
return updateSlice;
|
||||
}
|
||||
|
||||
public void cleanup(long c) {
|
||||
blockSlice.cleanup(c);
|
||||
objectSlice.cleanup(c);
|
||||
public int cleanup(long c) {
|
||||
return blockSlice.cleanup(c) +
|
||||
objectSlice.cleanup(c) +
|
||||
updateSlice.cleanup(c);
|
||||
}
|
||||
|
||||
|
@ -89,10 +89,10 @@ public class ParallaxWorld implements ParallaxAccess
|
||||
}
|
||||
}
|
||||
|
||||
public void unload(int x, int z)
|
||||
public int unload(int x, int z)
|
||||
{
|
||||
long key = key(x, z);
|
||||
|
||||
int v = 0;
|
||||
if(isLoaded(x, z))
|
||||
{
|
||||
if(save.contains(key))
|
||||
@ -101,8 +101,15 @@ public class ParallaxWorld implements ParallaxAccess
|
||||
save.remove(key);
|
||||
}
|
||||
|
||||
loadedRegions.remove(key).unload();
|
||||
v += loadedRegions.remove(key).unload();
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
Iris.warn("Cant unload region " + x + " " + z + " because it's not loaded.");
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
public ParallaxRegion load(int x, int z)
|
||||
@ -203,21 +210,28 @@ public class ParallaxWorld implements ParallaxAccess
|
||||
|
||||
@Override
|
||||
public void cleanup(long r, long c) {
|
||||
Iris.info("P: c" + Form.f(getChunkCount()) + " / r" + getRegionCount());
|
||||
|
||||
J.a(() -> {
|
||||
int rr = 0;
|
||||
int cc = 0;
|
||||
|
||||
for(ParallaxRegion i : loadedRegions.v())
|
||||
{
|
||||
if(i.hasBeenIdleLongerThan(r))
|
||||
{
|
||||
rr++;
|
||||
unload(i.getX(), i.getZ());
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
i.cleanup(c);
|
||||
cc+= i.cleanup(c);
|
||||
}
|
||||
}
|
||||
|
||||
Iris.info("Unloaded " + rr + " Regions and " + cc + " Chunks");
|
||||
Iris.info("P: c" + Form.f(getChunkCount()) + " / r" + getRegionCount());
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1,18 +1,13 @@
|
||||
package com.volmit.iris.util;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import com.volmit.iris.Iris;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.util.concurrent.*;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
|
||||
public class J
|
||||
{
|
||||
private static int tid = 0;
|
||||
@ -56,7 +51,18 @@ public class J
|
||||
|
||||
public static void a(Runnable a)
|
||||
{
|
||||
e.submit(a);
|
||||
e.submit(() -> {
|
||||
try
|
||||
{
|
||||
a.run();
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
System.out.println("Failed to run async task");
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static <T> Future<T> a(Callable<T> a)
|
||||
|
Loading…
x
Reference in New Issue
Block a user