This commit is contained in:
Daniel Mills 2020-01-24 14:39:55 -05:00
parent 08159923d6
commit 31bf39d2e5
3 changed files with 61 additions and 4 deletions

View File

@ -60,7 +60,7 @@ public class Iris extends MortarPlugin
super.onEnable();
}
public File getCacheFolder()
public File getObjectCacheFolder()
{
return getDataFolder("cache", "object");
}

View File

@ -57,7 +57,7 @@ public class GenObject
@SuppressWarnings("deprecation")
public void perfectRead(File folder, String name) throws IOException
{
File file = new File(folder, IO.hash(name));
File file = new File(folder, IO.hash(name) + ".ioc");
FileInputStream fin = new FileInputStream(file);
DataInputStream din = new DataInputStream(fin);
centeredHeight = din.readBoolean();
@ -81,7 +81,7 @@ public class GenObject
@SuppressWarnings("deprecation")
public void perfectWrite(File folder) throws IOException
{
File file = new File(folder, IO.hash(name));
File file = new File(folder, IO.hash(name) + ".ioc");
FileOutputStream fos = new FileOutputStream(file);
DataOutputStream dos = new DataOutputStream(fos);
dos.writeBoolean(centeredHeight);

View File

@ -1,13 +1,70 @@
package ninja.bytecode.iris.generator.genobject;
import java.io.IOException;
import mortar.compute.math.M;
import mortar.util.text.C;
import ninja.bytecode.iris.Iris;
import ninja.bytecode.shuriken.logging.L;
public class PhantomGenObject
{
private GenObject object;
private String name;
private boolean loaded;
private long lastUse;
private long evictionNotice;
private int size;
public PhantomGenObject(GenObject object)
public PhantomGenObject(GenObject object) throws IOException
{
this.object = object;
this.name = object.getName();
object.perfectWrite(Iris.instance.getObjectCacheFolder());
lastUse = M.ms();
loaded = true;
size = object.getSchematic().size();
evictionNotice = 5000 + (size * 7);
}
public int getSize()
{
return size;
}
public boolean isLoaded()
{
return loaded;
}
public void attemptEviction()
{
if(loaded && M.ms() - lastUse > evictionNotice)
{
loaded = false;
object.dispose();
}
}
public GenObject get()
{
if(!loaded)
{
try
{
object.perfectRead(Iris.instance.getObjectCacheFolder(), name);
loaded = true;
}
catch(IOException e)
{
L.f(C.RED + "Cannot Read Cached Object: " + name);
L.ex(e);
}
}
lastUse = M.ms();
return object;
}
}