mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-20 03:04:08 +00:00
Jigsaw is faster
This commit is contained in:
parent
6620d2d023
commit
959f96dd74
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
package com.volmit.iris.engine.jigsaw;
|
package com.volmit.iris.engine.jigsaw;
|
||||||
|
|
||||||
|
import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap;
|
||||||
import com.volmit.iris.Iris;
|
import com.volmit.iris.Iris;
|
||||||
import com.volmit.iris.core.IrisDataManager;
|
import com.volmit.iris.core.IrisDataManager;
|
||||||
import com.volmit.iris.core.tools.IrisWorlds;
|
import com.volmit.iris.core.tools.IrisWorlds;
|
||||||
@ -29,6 +30,7 @@ import com.volmit.iris.engine.object.common.IObjectPlacer;
|
|||||||
import com.volmit.iris.engine.parallax.ParallaxChunkMeta;
|
import com.volmit.iris.engine.parallax.ParallaxChunkMeta;
|
||||||
import com.volmit.iris.util.collection.KList;
|
import com.volmit.iris.util.collection.KList;
|
||||||
import com.volmit.iris.util.collection.KMap;
|
import com.volmit.iris.util.collection.KMap;
|
||||||
|
import com.volmit.iris.util.format.Form;
|
||||||
import com.volmit.iris.util.math.RNG;
|
import com.volmit.iris.util.math.RNG;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.bukkit.Axis;
|
import org.bukkit.Axis;
|
||||||
@ -42,14 +44,20 @@ public class PlannedStructure {
|
|||||||
private IrisJigsawStructure structure;
|
private IrisJigsawStructure structure;
|
||||||
private IrisPosition position;
|
private IrisPosition position;
|
||||||
private IrisDataManager data;
|
private IrisDataManager data;
|
||||||
private static KMap<String, IrisObject> objectRotationCache;
|
private static transient ConcurrentLinkedHashMap<String, IrisObject> objectRotationCache
|
||||||
|
= new ConcurrentLinkedHashMap.Builder<String, IrisObject>()
|
||||||
|
.initialCapacity(64)
|
||||||
|
.maximumWeightedCapacity(1024)
|
||||||
|
.concurrencyLevel(32)
|
||||||
|
.build();
|
||||||
private RNG rng;
|
private RNG rng;
|
||||||
private boolean verbose;
|
private boolean verbose;
|
||||||
private boolean terminating;
|
private boolean terminating;
|
||||||
|
private static int hit = 0;
|
||||||
|
private static int miss = 0;
|
||||||
|
|
||||||
public PlannedStructure(IrisJigsawStructure structure, IrisPosition position, RNG rng) {
|
public PlannedStructure(IrisJigsawStructure structure, IrisPosition position, RNG rng) {
|
||||||
terminating = false;
|
terminating = false;
|
||||||
objectRotationCache = new KMap<>();
|
|
||||||
verbose = true;
|
verbose = true;
|
||||||
this.pieces = new KList<>();
|
this.pieces = new KList<>();
|
||||||
this.structure = structure;
|
this.structure = structure;
|
||||||
@ -393,16 +401,20 @@ public class PlannedStructure {
|
|||||||
public IrisObject rotated(IrisJigsawPiece piece, IrisObjectRotation rotation) {
|
public IrisObject rotated(IrisJigsawPiece piece, IrisObjectRotation rotation) {
|
||||||
String key = piece.getObject() + "-" + rotation.hashCode();
|
String key = piece.getObject() + "-" + rotation.hashCode();
|
||||||
|
|
||||||
if (objectRotationCache.containsKey(key)) {
|
return objectRotationCache.compute(key, (k, v) -> {
|
||||||
IrisObject o = objectRotationCache.get(key);
|
if(v == null)
|
||||||
|
{
|
||||||
if (o != null) {
|
miss++;
|
||||||
return o;
|
return rotation.rotateCopy(data.getObjectLoader().load(piece.getObject()));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
IrisObject o = rotation.rotateCopy(data.getObjectLoader().load(piece.getObject()));
|
hit++;
|
||||||
objectRotationCache.put(key, o);
|
printCacheHit();
|
||||||
return o;
|
return v;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void printCacheHit() {
|
||||||
|
System.out.println("Cache Hit " + Form.pc((double) hit / (double) (hit + miss), 2) + " Cache Hit: " + hit + " hits " + miss + " misses.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,10 +53,10 @@ public class IrisObjectScale {
|
|||||||
@Desc("If this object is scaled up beyond its origin size, specify a 3D interpolator")
|
@Desc("If this object is scaled up beyond its origin size, specify a 3D interpolator")
|
||||||
private IrisObjectPlacementScaleInterpolator interpolation = IrisObjectPlacementScaleInterpolator.NONE;
|
private IrisObjectPlacementScaleInterpolator interpolation = IrisObjectPlacementScaleInterpolator.NONE;
|
||||||
|
|
||||||
private transient ConcurrentLinkedHashMap<IrisObject, KList<IrisObject>> cache
|
private static transient ConcurrentLinkedHashMap<IrisObject, KList<IrisObject>> cache
|
||||||
= new ConcurrentLinkedHashMap.Builder<IrisObject, KList<IrisObject>>()
|
= new ConcurrentLinkedHashMap.Builder<IrisObject, KList<IrisObject>>()
|
||||||
.initialCapacity(64)
|
.initialCapacity(64)
|
||||||
.maximumWeightedCapacity(64)
|
.maximumWeightedCapacity(1024)
|
||||||
.concurrencyLevel(32)
|
.concurrencyLevel(32)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user