Fixed another potential mem leak

Added the base of smart320height
This commit is contained in:
RePixelatedMC
2024-04-09 17:04:32 +02:00
parent 206a4e9057
commit b898f73a05
8 changed files with 150 additions and 117 deletions
+1 -1
View File
@@ -37,7 +37,7 @@ registerCustomOutputTask('Coco', 'D://mcsm/plugins')
registerCustomOutputTask('Strange', 'D://Servers/1.17 Test Server/plugins') registerCustomOutputTask('Strange', 'D://Servers/1.17 Test Server/plugins')
registerCustomOutputTask('Vatuu', 'D://Minecraft/Servers/1.19.4/plugins') registerCustomOutputTask('Vatuu', 'D://Minecraft/Servers/1.19.4/plugins')
registerCustomOutputTask('CrazyDev22', 'C://Users/Julian/Desktop/server/plugins') registerCustomOutputTask('CrazyDev22', 'C://Users/Julian/Desktop/server/plugins')
registerCustomOutputTask('Pixel', 'C://Users/repix/Iris Dimension Engine/1.20.4 - Iris Development/plugins') registerCustomOutputTask('Pixel', 'C://Users/repix/Iris Dimension Engine/1.20.4 - Development/plugins')
// ========================== UNIX ============================== // ========================== UNIX ==============================
registerCustomOutputTaskUnix('CyberpwnLT', '/Users/danielmills/development/server/plugins') registerCustomOutputTaskUnix('CyberpwnLT', '/Users/danielmills/development/server/plugins')
registerCustomOutputTaskUnix('PsychoLT', '/Volumes/PRO-G40/Minecraft/MinecraftDevelopment/Server/plugins') registerCustomOutputTaskUnix('PsychoLT', '/Volumes/PRO-G40/Minecraft/MinecraftDevelopment/Server/plugins')
@@ -30,6 +30,7 @@ import com.volmit.iris.core.safeguard.UtilsSFG;
import com.volmit.iris.engine.object.IrisWorld; import com.volmit.iris.engine.object.IrisWorld;
import com.volmit.iris.engine.platform.BukkitChunkGenerator; import com.volmit.iris.engine.platform.BukkitChunkGenerator;
import com.volmit.iris.engine.platform.DummyChunkGenerator; import com.volmit.iris.engine.platform.DummyChunkGenerator;
import com.volmit.iris.util.collection.KList;
import com.volmit.iris.util.decree.DecreeExecutor; import com.volmit.iris.util.decree.DecreeExecutor;
import com.volmit.iris.util.decree.DecreeOrigin; import com.volmit.iris.util.decree.DecreeOrigin;
import com.volmit.iris.util.decree.annotations.Decree; import com.volmit.iris.util.decree.annotations.Decree;
@@ -216,41 +217,41 @@ public class CommandIris implements DecreeExecutor {
Iris.service(StudioSVC.class).open(sender(), 1337, "overworld"); Iris.service(StudioSVC.class).open(sender(), 1337, "overworld");
} }
@Decree(description = "Check if iris has access to that specific world") @Decree(description = "Check access of all worlds.", aliases = {"accesslist"})
public void hasAccess( public void worlds() {
@Param(description = "The world to access", aliases = {"world"}) KList<World> IrisWorlds = new KList<>();
World world KList<World> BukkitWorlds = new KList<>();
) {
Engine engine = IrisToolbelt.access(world).getEngine(); for (World w : Bukkit.getServer().getWorlds()) {
try {
Engine engine = IrisToolbelt.access(w).getEngine();
if (engine != null) { if (engine != null) {
sender().sendMessage("Access granted successfully."); IrisWorlds.add(w);
} else { }
sender().sendMessage(C.RED + "Failed to grant access."); } catch (Exception e) {
BukkitWorlds.add(w);
} }
} }
@Decree(description = "All Iris Worlds on the server.", aliases = {"worlds"})
public void irisworlds() {
List<World> IrisWorlds = new ArrayList<>();
for (World world : Bukkit.getWorlds()) {
try {
if (IrisToolbelt.access(world).getEngine() != null) {
IrisWorlds.add(world);
}
} catch (Exception e) {
// no
}
}
if (sender().isPlayer()) { if (sender().isPlayer()) {
sender.sendMessage(C.IRIS + "Iris Worlds:"); sender().sendMessage(C.BLUE + "Iris Worlds: ");
for (World world : IrisWorlds) { for (World IrisWorld : IrisWorlds.copy()) {
sender.sendMessage(C.GREEN + "- " + world.getName()); sender().sendMessage(C.IRIS + "- " +IrisWorld.getName());
}
sender().sendMessage(C.GOLD + "Bukkit Worlds: ");
for (World BukkitWorld : BukkitWorlds.copy()) {
sender().sendMessage(C.GRAY + "- " +BukkitWorld.getName());
} }
} else { } else {
Iris.info(C.IRIS + "Iris Worlds:"); Iris.info(C.BLUE + "Iris Worlds: ");
for (World world : IrisWorlds) { for (World IrisWorld : IrisWorlds.copy()) {
sender.sendMessage(C.GREEN + "- " + world.getName()); Iris.info(C.IRIS + "- " +IrisWorld.getName());
} }
Iris.info(C.GOLD + "Bukkit Worlds: ");
for (World BukkitWorld : BukkitWorlds.copy()) {
Iris.info(C.GRAY + "- " +BukkitWorld.getName());
}
} }
} }
@@ -85,7 +85,7 @@ import java.util.function.Supplier;
public class CommandStudio implements DecreeExecutor { public class CommandStudio implements DecreeExecutor {
private CommandFind find; private CommandFind find;
private CommandEdit edit; private CommandEdit edit;
private CommandDeepSearch deepSearch; //private CommandDeepSearch deepSearch;
public static String hrf(Duration duration) { public static String hrf(Duration duration) {
return duration.toString().substring(2).replaceAll("(\\d[HMS])(?!$)", "$1 ").toLowerCase(); return duration.toString().substring(2).replaceAll("(\\d[HMS])(?!$)", "$1 ").toLowerCase();
@@ -55,10 +55,10 @@ public class IrisRenderer {
IrisBiome b = renderer.getBiome((int) Math.round(x), renderer.getMaxHeight() - 1, (int) Math.round(z)); IrisBiome b = renderer.getBiome((int) Math.round(x), renderer.getMaxHeight() - 1, (int) Math.round(z));
IrisBiomeGeneratorLink g = b.getGenerators().get(0); IrisBiomeGeneratorLink g = b.getGenerators().get(0);
Color c; Color c;
if (g.getMax() <= 0) { if (g.getMax(renderer) <= 0) {
// Max is below water level, so it is most likely an ocean biome // Max is below water level, so it is most likely an ocean biome
c = Color.BLUE; c = Color.BLUE;
} else if (g.getMin() < 0) { } else if (g.getMin(renderer) < 0) {
// Min is below water level, but max is not, so it is most likely a shore biome // Min is below water level, but max is not, so it is most likely a shore biome
c = Color.YELLOW; c = Color.YELLOW;
} else { } else {
@@ -78,6 +78,9 @@ public class IrisEngineSVC implements IrisService {
t = t - 200; t = t - 200;
} }
this.setup(); this.setup();
this.TrimLogic();
this.UnloadLogic();
trimAlive.begin(); trimAlive.begin();
unloadAlive.begin(); unloadAlive.begin();
trimActiveAlive.begin(); trimActiveAlive.begin();
@@ -85,8 +88,8 @@ public class IrisEngineSVC implements IrisService {
updateTicker.start(); updateTicker.start();
cacheTicker.start(); cacheTicker.start();
trimTicker.start(); //trimTicker.start();
unloadTicker.start(); //unloadTicker.start();
instance = this; instance = this;
} }
@@ -104,10 +107,6 @@ public class IrisEngineSVC implements IrisService {
return tectonicLimit.get(); return tectonicLimit.get();
} }
public void EngineReport() {
Iris.info(C.RED + "CRITICAL ENGINE FAILURE! The Tectonic Trim subsystem has not responded for: " + Form.duration(trimAlive.getMillis()) + ".");
}
@EventHandler @EventHandler
public void onWorldUnload(WorldUnloadEvent event) { public void onWorldUnload(WorldUnloadEvent event) {
updateWorlds(); updateWorlds();
@@ -179,9 +178,9 @@ public class IrisEngineSVC implements IrisService {
} }
if (!isServerShuttingDown && isServerLoaded) { if (!isServerShuttingDown && isServerLoaded) {
if (!trimTicker.isAlive()) { if (!trimTicker.isAlive()) {
Iris.info(C.IRIS + "TrimTicker found dead! Booting it up!"); Iris.info(C.RED + "TrimTicker found dead! Booting it up!");
try { try {
trimTicker.start(); TrimLogic();
} catch (Exception e) { } catch (Exception e) {
Iris.error("What happened?"); Iris.error("What happened?");
e.printStackTrace(); e.printStackTrace();
@@ -189,9 +188,9 @@ public class IrisEngineSVC implements IrisService {
} }
if (!unloadTicker.isAlive()) { if (!unloadTicker.isAlive()) {
Iris.info(C.IRIS + "UnloadTicker found dead! Booting it up!"); Iris.info(C.RED + "UnloadTicker found dead! Booting it up!");
try { try {
unloadTicker.start(); UnloadLogic();
} catch (Exception e) { } catch (Exception e) {
Iris.error("What happened?"); Iris.error("What happened?");
e.printStackTrace(); e.printStackTrace();
@@ -205,9 +204,12 @@ public class IrisEngineSVC implements IrisService {
return 1000; return 1000;
} }
}; };
}
public void TrimLogic() {
if (trimTicker == null || !trimTicker.isAlive()) {
trimTicker = new Looper() { trimTicker = new Looper() {
private final Supplier<Engine> supplier = createSupplier(); private final Supplier<Engine> supplier = createSupplier();
@Override @Override
protected long loop() { protected long loop() {
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
@@ -219,19 +221,23 @@ public class IrisEngineSVC implements IrisService {
} }
} catch (Throwable e) { } catch (Throwable e) {
Iris.reportError(e); Iris.reportError(e);
Iris.info(C.RED + "EngineSVC: Failed to trim. Please contact support!"); Iris.info(C.RED + "EngineSVC: Failed to trim.");
e.printStackTrace(); e.printStackTrace();
return -1; return -1;
} }
int size = lastUse.size(); int size = lastUse.size();
long time = (size > 0 ? 1000/size : 1000) - (System.currentTimeMillis() - start); long time = (size > 0 ? 1000 / size : 1000) - (System.currentTimeMillis() - start);
if (time <= 0) if (time <= 0)
return 0; return 0;
return time; return time;
} }
}; };
trimTicker.start();
}
}
public void UnloadLogic() {
if (unloadTicker == null || !unloadTicker.isAlive()) {
unloadTicker = new Looper() { unloadTicker = new Looper() {
private final Supplier<Engine> supplier = createSupplier(); private final Supplier<Engine> supplier = createSupplier();
@@ -256,12 +262,14 @@ public class IrisEngineSVC implements IrisService {
} }
int size = lastUse.size(); int size = lastUse.size();
long time = (size > 0 ? 1000/size : 1000) - (System.currentTimeMillis() - start); long time = (size > 0 ? 1000 / size : 1000) - (System.currentTimeMillis() - start);
if (time <= 0) if (time <= 0)
return 0; return 0;
return time; return time;
} }
}; };
unloadTicker.start();
}
} }
private Supplier<Engine> createSupplier() { private Supplier<Engine> createSupplier() {
@@ -281,7 +289,8 @@ public class IrisEngineSVC implements IrisService {
if (generator != null) { if (generator != null) {
Engine engine = generator.getEngine(); Engine engine = generator.getEngine();
if (engine != null && !engine.isStudio()) { boolean closed = engine.getMantle().getData().isClosed();
if (engine != null && !engine.isStudio() && !closed) {
lastUseLock.lock(); lastUseLock.lock();
lastUse.put(world, System.currentTimeMillis()); lastUse.put(world, System.currentTimeMillis());
lastUseLock.unlock(); lastUseLock.unlock();
@@ -292,7 +292,7 @@ public class IrisComplex implements DataProvider {
double b = 0; double b = 0;
for (IrisGenerator gen : generators) { for (IrisGenerator gen : generators) {
b += bx.getGenLinkMax(gen.getLoadKey()); b += bx.getGenLinkMax(gen.getLoadKey(), engine);
} }
return b; return b;
@@ -311,7 +311,7 @@ public class IrisComplex implements DataProvider {
double b = 0; double b = 0;
for (IrisGenerator gen : generators) { for (IrisGenerator gen : generators) {
b += bx.getGenLinkMin(gen.getLoadKey()); b += bx.getGenLinkMin(gen.getLoadKey(), engine);
} }
return b; return b;
@@ -194,13 +194,14 @@ public class IrisBiome extends IrisRegistrant implements IRare {
return getCustomDerivitives() != null && getCustomDerivitives().isNotEmpty(); return getCustomDerivitives() != null && getCustomDerivitives().isNotEmpty();
} }
public double getGenLinkMax(String loadKey) { public double getGenLinkMax(String loadKey, Engine engine) {
Integer v = genCacheMax.aquire(() -> Integer v = genCacheMax.aquire(() ->
{ {
KMap<String, Integer> l = new KMap<>(); KMap<String, Integer> l = new KMap<>();
for (IrisBiomeGeneratorLink i : getGenerators()) { for (IrisBiomeGeneratorLink i : getGenerators()) {
l.put(i.getGenerator(), i.getMax()); l.put(i.getGenerator(), i.getMax(engine));
} }
return l; return l;
@@ -209,13 +210,13 @@ public class IrisBiome extends IrisRegistrant implements IRare {
return v == null ? 0 : v; return v == null ? 0 : v;
} }
public double getGenLinkMin(String loadKey) { public double getGenLinkMin(String loadKey, Engine engine) {
Integer v = genCacheMin.aquire(() -> Integer v = genCacheMin.aquire(() ->
{ {
KMap<String, Integer> l = new KMap<>(); KMap<String, Integer> l = new KMap<>();
for (IrisBiomeGeneratorLink i : getGenerators()) { for (IrisBiomeGeneratorLink i : getGenerators()) {
l.put(i.getGenerator(), i.getMin()); l.put(i.getGenerator(), i.getMin(engine));
} }
return l; return l;
@@ -450,26 +451,26 @@ public class IrisBiome extends IrisRegistrant implements IRare {
return real; return real;
} }
public int getMaxHeight() { public int getMaxHeight(Engine engine) {
return maxHeight.aquire(() -> return maxHeight.aquire(() ->
{ {
int maxHeight = 0; int maxHeight = 0;
for (IrisBiomeGeneratorLink i : getGenerators()) { for (IrisBiomeGeneratorLink i : getGenerators()) {
maxHeight += i.getMax(); maxHeight += i.getMax(engine);
} }
return maxHeight; return maxHeight;
}); });
} }
public int getMaxWithObjectHeight(IrisData data) { public int getMaxWithObjectHeight(IrisData data, Engine engine) {
return maxWithObjectHeight.aquire(() -> return maxWithObjectHeight.aquire(() ->
{ {
int maxHeight = 0; int maxHeight = 0;
for (IrisBiomeGeneratorLink i : getGenerators()) { for (IrisBiomeGeneratorLink i : getGenerators()) {
maxHeight += i.getMax(); maxHeight += i.getMax(engine);
} }
int gg = 0; int gg = 0;
@@ -18,14 +18,14 @@
package com.volmit.iris.engine.object; package com.volmit.iris.engine.object;
import com.volmit.iris.Iris;
import com.volmit.iris.core.IrisSettings; import com.volmit.iris.core.IrisSettings;
import com.volmit.iris.engine.data.cache.AtomicCache; import com.volmit.iris.engine.data.cache.AtomicCache;
import com.volmit.iris.engine.framework.Engine;
import com.volmit.iris.engine.object.annotations.*; import com.volmit.iris.engine.object.annotations.*;
import com.volmit.iris.util.data.DataProvider; import com.volmit.iris.util.data.DataProvider;
import com.volmit.iris.util.interpolation.IrisInterpolation; import com.volmit.iris.util.interpolation.IrisInterpolation;
import lombok.AllArgsConstructor; import lombok.*;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
@Snippet("generator-layer") @Snippet("generator-layer")
@@ -45,11 +45,13 @@ public class IrisBiomeGeneratorLink {
@MinNumber(-2032) // TODO: WARNING HEIGHT @MinNumber(-2032) // TODO: WARNING HEIGHT
@MaxNumber(2032) // TODO: WARNING HEIGHT @MaxNumber(2032) // TODO: WARNING HEIGHT
@Desc("The min block value (value + fluidHeight)") @Desc("The min block value (value + fluidHeight)")
@Getter(AccessLevel.NONE)
private int min = 0; private int min = 0;
@DependsOn({"min", "max"}) @DependsOn({"min", "max"})
@Required @Required
@MinNumber(-2032) // TODO: WARNING HEIGHT @MinNumber(-2032) // TODO: WARNING HEIGHT
@MaxNumber(2032) // TODO: WARNING HEIGHT @MaxNumber(2032) // TODO: WARNING HEIGHT
@Getter(AccessLevel.NONE)
@Desc("The max block value (value + fluidHeight)") @Desc("The max block value (value + fluidHeight)")
private int max = 0; private int max = 0;
@@ -66,21 +68,41 @@ public class IrisBiomeGeneratorLink {
}); });
} }
private int calculateHeight(Engine engine, int option) {
int dmx = engine.getDimension().getMaxHeight();
int dmn = engine.getDimension().getMinHeight();
int mx = max; // 500
int mn = min; // 160
if (true) { // todo after merge
if (mx > 0) mx = Math.min((int)(((float)mx / (float)dmx) * 300.0f), 300);
if (mx < 0) mx = Math.min((int)(((float)mx / (float)dmn) * 300.0f), 56);
if (mn > 0) mn = Math.min((int)(((float)mn / (float)dmx) * 300.0f), 300);
if (mn < 0) mn = Math.min((int)(((float)mn / (float)dmn) * 300.0f), 56);
}
if (option == 1) {
return mx;
}
if (option == 0) {
return mn;
}
Iris.error("Fatal Generator error!");
return 0;
}
public int getMax(Engine engine) {
return calculateHeight(engine, 1);
}
public int getMin(Engine engine) {
return calculateHeight(engine, 0);
}
public double getHeight(DataProvider xg, double x, double z, long seed) { public double getHeight(DataProvider xg, double x, double z, long seed) {
double g = getCachedGenerator(xg).getHeight(x, z, seed); double g = getCachedGenerator(xg).getHeight(x, z, seed);
g = g < 0 ? 0 : g; g = g < 0 ? 0 : g;
g = g > 1 ? 1 : g; g = g > 1 ? 1 : g;
// if (IrisSettings.get().getGenerator().forceConvertTo320Height) {
// if (max > 320 || min > 320) {
// double scaleFactor = 320.0 / Math.max(max, min);
// min *= (int) scaleFactor;
// max *= (int) scaleFactor;
// if (min < 0) {
//
// }
// }
// }
// todo This
return IrisInterpolation.lerp(min, max, g); return IrisInterpolation.lerp(min, max, g);
} }