mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-04-07 08:16:31 +00:00
More robust and some debugging
This commit is contained in:
@@ -33,6 +33,8 @@ import com.volmit.iris.util.mantle.Mantle;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
@Decree(name = "Developer", origin = DecreeOrigin.BOTH, description = "Iris World Manager", aliases = {"dev"})
|
||||
public class CommandDeveloper implements DecreeExecutor {
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package com.volmit.iris.engine.jigsaw;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.loader.IrisData;
|
||||
import com.volmit.iris.core.tools.IrisToolbelt;
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
@@ -38,6 +39,9 @@ import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.util.BlockVector;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@SuppressWarnings("ALL")
|
||||
@Data
|
||||
public class PlannedPiece {
|
||||
@@ -72,6 +76,7 @@ public class PlannedPiece {
|
||||
this.object.setLoadKey(piece.getObject());
|
||||
this.ogObject.setLoadKey(piece.getObject());
|
||||
this.connected = new KList<>();
|
||||
|
||||
}
|
||||
|
||||
public void setPosition(IrisPosition p) {
|
||||
@@ -133,10 +138,29 @@ public class PlannedPiece {
|
||||
return getWorldPosition(c.getPosition());
|
||||
}
|
||||
|
||||
public List<IrisPosition> getConnectorWorldPositions() {
|
||||
List<IrisPosition> worldPositions = new ArrayList<>();
|
||||
|
||||
for (IrisJigsawPieceConnector connector : this.piece.getConnectors()) {
|
||||
IrisPosition worldPosition = getWorldPosition(connector.getPosition());
|
||||
worldPositions.add(worldPosition);
|
||||
}
|
||||
|
||||
return worldPositions;
|
||||
}
|
||||
|
||||
public IrisPosition getWorldPosition(IrisPosition position) {
|
||||
return this.position.add(position).add(new IrisPosition(object.getCenter()));
|
||||
}
|
||||
|
||||
public void debugPrintConnectorPositions() {
|
||||
Iris.debug("Connector World Positions for PlannedPiece at " + position + ":");
|
||||
List<IrisPosition> connectorPositions = getConnectorWorldPositions();
|
||||
for (IrisPosition pos : connectorPositions) {
|
||||
Iris.debug(" - Connector at: " + pos);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isFull() {
|
||||
return connected.size() >= piece.getConnectors().size() || isDead();
|
||||
}
|
||||
|
||||
@@ -208,6 +208,7 @@ public class PlannedStructure {
|
||||
for (IrisJigsawPieceConnector i : piece.getAvailableConnectors().shuffleCopy(rng)) {
|
||||
if (generateConnectorOutwards(piece, i)) {
|
||||
b = true;
|
||||
piece.debugPrintConnectorPositions();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -293,12 +293,12 @@ public interface EngineMantle extends IObjectPlacer {
|
||||
}
|
||||
|
||||
default long getToUnload(){
|
||||
return getMantle().ToUnloadTectonic();
|
||||
return getMantle().FakeToUnload.get();
|
||||
}
|
||||
default double getTectonicLimit(){
|
||||
return getMantle().getTectonicLimit();
|
||||
return getMantle().tectonicLimit.get();
|
||||
}
|
||||
default double getTectonicDuration(){
|
||||
return getMantle().getTectonicUnloadDuration();
|
||||
return getMantle().adjustedIdleDuration.get();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,8 +41,10 @@ import com.volmit.iris.util.misc.getHardware;
|
||||
import com.volmit.iris.util.parallel.BurstExecutor;
|
||||
import com.volmit.iris.util.parallel.HyperLock;
|
||||
import com.volmit.iris.util.parallel.MultiBurst;
|
||||
import com.volmit.iris.util.scheduling.Looper;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Chunk;
|
||||
import org.checkerframework.checker.units.qual.A;
|
||||
|
||||
import java.io.EOFException;
|
||||
import java.io.File;
|
||||
@@ -53,6 +55,7 @@ import java.util.Set;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
/**
|
||||
* The mantle can store any type of data slice anywhere and manage regions & IO on it's own.
|
||||
@@ -400,11 +403,10 @@ public class Mantle {
|
||||
*
|
||||
* @param baseIdleDuration the duration
|
||||
*/
|
||||
@Getter
|
||||
AtomicInteger FakeToUnload = new AtomicInteger(0);
|
||||
AtomicDouble adjustedIdleDuration = new AtomicDouble(0);
|
||||
@Getter
|
||||
double tectonicLimit = 30;
|
||||
|
||||
public AtomicInteger FakeToUnload = new AtomicInteger(0);
|
||||
public AtomicDouble adjustedIdleDuration = new AtomicDouble(0);
|
||||
public AtomicInteger tectonicLimit = new AtomicInteger(30);
|
||||
|
||||
|
||||
public synchronized void trim(long baseIdleDuration) {
|
||||
@@ -413,21 +415,21 @@ public class Mantle {
|
||||
}
|
||||
|
||||
if (IrisSettings.get().getPerformance().dynamicPerformanceMode){
|
||||
tectonicLimit = 2;
|
||||
tectonicLimit.set(2);
|
||||
long t = getHardware.getProcessMemory();
|
||||
for (; t > 250;){
|
||||
tectonicLimit++;
|
||||
tectonicLimit.getAndAdd(1);
|
||||
t = t - 250;
|
||||
}
|
||||
}
|
||||
|
||||
adjustedIdleDuration.set(baseIdleDuration);
|
||||
|
||||
if (loadedRegions.size() > tectonicLimit) {
|
||||
if (getHardware.getProcessMemory() < 5000 && IrisSettings.get().getPerformance().dynamicPerformanceMode) {
|
||||
adjustedIdleDuration.set(Math.max(adjustedIdleDuration.get() - (1000 * (loadedRegions.size() - tectonicLimit) * 2.65), 4000));
|
||||
} else {
|
||||
adjustedIdleDuration.set(Math.max(adjustedIdleDuration.get() - (1000 * (loadedRegions.size() - tectonicLimit) * 1.45), 4000));
|
||||
if (loadedRegions.size() > tectonicLimit.get()) {
|
||||
// todo update this correctly and maybe do something when its above a 100%
|
||||
if (IrisSettings.get().getPerformance().dynamicPerformanceMode) {
|
||||
int tectonicLimitValue = tectonicLimit.get();
|
||||
adjustedIdleDuration.set(Math.max(adjustedIdleDuration.get() - (1000 * (((loadedRegions.size() - tectonicLimitValue) / (double) tectonicLimitValue) * 100) * 0.4), 4000));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -476,13 +478,6 @@ public class Mantle {
|
||||
}
|
||||
}
|
||||
|
||||
public long ToUnloadTectonic(){
|
||||
return FakeToUnload.get();
|
||||
}
|
||||
public double getTectonicUnloadDuration(){
|
||||
return adjustedIdleDuration.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* This retreives a future of the Tectonic Plate at the given coordinates.
|
||||
* All methods accessing tectonic plates should go through this method
|
||||
|
||||
168
core/src/main/java/com/volmit/iris/util/math/RNGV2.java
Normal file
168
core/src/main/java/com/volmit/iris/util/math/RNGV2.java
Normal file
@@ -0,0 +1,168 @@
|
||||
package com.volmit.iris.util.math;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class RNGV2 extends SecureRandom {
|
||||
private static final long serialVersionUID = 5222938581174415179L;
|
||||
private static final char[] CHARGEN = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-=!@#$%^&*()_+`~[];',./<>?:\\\"{}|\\\\".toCharArray();
|
||||
private final long sx;
|
||||
|
||||
// Constructor with no seed
|
||||
public RNGV2() {
|
||||
super();
|
||||
sx = 0;
|
||||
}
|
||||
|
||||
public RNGV2(long seed) {
|
||||
super();
|
||||
this.setSeed(seed);
|
||||
this.sx = seed;
|
||||
}
|
||||
|
||||
// Constructor with a string seed
|
||||
public RNGV2(String seed) {
|
||||
this(UUID.nameUUIDFromBytes(seed.getBytes(StandardCharsets.UTF_8)).getLeastSignificantBits() +
|
||||
UUID.nameUUIDFromBytes(seed.getBytes(StandardCharsets.UTF_8)).getMostSignificantBits() +
|
||||
(seed.length() * 32564L));
|
||||
}
|
||||
|
||||
public RNGV2 nextParallelRNG(int signature) {
|
||||
return new RNGV2(sx + signature);
|
||||
}
|
||||
|
||||
public RNGV2 nextParallelRNG(long signature) {
|
||||
return new RNGV2(sx + signature);
|
||||
}
|
||||
|
||||
public String s(int length) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
sb.append(c());
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public char c() {
|
||||
return CHARGEN[i(CHARGEN.length - 1)];
|
||||
}
|
||||
|
||||
// Pick a random enum
|
||||
public <T> T e(Class<T> t) {
|
||||
T[] c = t.getEnumConstants();
|
||||
return c[i(c.length)];
|
||||
}
|
||||
|
||||
public boolean b() {
|
||||
return nextBoolean();
|
||||
}
|
||||
|
||||
public boolean b(double percent) {
|
||||
return d() > percent;
|
||||
}
|
||||
|
||||
public short si(int lowerBound, int upperBound) {
|
||||
return (short) (lowerBound + (nextFloat() * ((upperBound - lowerBound) + 1)));
|
||||
}
|
||||
|
||||
public short si(int upperBound) {
|
||||
return si(0, upperBound);
|
||||
}
|
||||
|
||||
public short si() {
|
||||
return si(1);
|
||||
}
|
||||
|
||||
public float f(float lowerBound, float upperBound) {
|
||||
return lowerBound + (nextFloat() * ((upperBound - lowerBound)));
|
||||
}
|
||||
|
||||
public float f(float upperBound) {
|
||||
return f(0, upperBound);
|
||||
}
|
||||
|
||||
public float f() {
|
||||
return f(1);
|
||||
}
|
||||
|
||||
public double d(double lowerBound, double upperBound) {
|
||||
return lowerBound + (nextDouble() * (upperBound - lowerBound));
|
||||
}
|
||||
|
||||
public double d(double upperBound) {
|
||||
return d(0, upperBound);
|
||||
}
|
||||
|
||||
public double d() {
|
||||
return nextDouble();
|
||||
}
|
||||
|
||||
public int i(int lowerBound, int upperBound) {
|
||||
if (lowerBound >= upperBound) {
|
||||
throw new IllegalArgumentException("Upper bound must be greater than lower bound");
|
||||
}
|
||||
return lowerBound + this.nextInt(upperBound - lowerBound + 1);
|
||||
}
|
||||
|
||||
public int i(int upperBound) {
|
||||
return i(0, upperBound);
|
||||
}
|
||||
|
||||
public long l(long lowerBound, long upperBound) {
|
||||
return Math.round(d(lowerBound, upperBound));
|
||||
}
|
||||
|
||||
public long l(long upperBound) {
|
||||
return l(0, upperBound);
|
||||
}
|
||||
|
||||
public int imax() {
|
||||
return i(Integer.MIN_VALUE, Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
public long lmax() {
|
||||
return l(Long.MIN_VALUE, Long.MAX_VALUE);
|
||||
}
|
||||
|
||||
public float fmax() {
|
||||
return f(Float.MIN_VALUE, Float.MAX_VALUE);
|
||||
}
|
||||
|
||||
public double dmax() {
|
||||
return d(Double.MIN_VALUE, Double.MAX_VALUE);
|
||||
}
|
||||
|
||||
public short simax() {
|
||||
return si(Short.MIN_VALUE, Short.MAX_VALUE);
|
||||
}
|
||||
|
||||
public boolean chance(double chance) {
|
||||
return nextDouble() <= chance;
|
||||
}
|
||||
|
||||
public <T> T pick(List<T> pieces) {
|
||||
if (pieces.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (pieces.size() == 1) {
|
||||
return pieces.get(0);
|
||||
}
|
||||
|
||||
return pieces.get(this.nextInt(pieces.size()));
|
||||
}
|
||||
|
||||
public long getSeed() {
|
||||
return sx;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user