Implemented Async World-Data Loading

Uses Mutex to assure no concurrent loading and saving
Merges Loaded data in Main Thread
This commit is contained in:
Sn0wStorm
2020-04-07 12:45:55 +02:00
parent f4bfdfa595
commit cae2b9dfff
9 changed files with 251 additions and 86 deletions
+31 -7
View File
@@ -30,17 +30,17 @@ public class BarrelBody {
/**
* Loading from file
*/
public BarrelBody(Barrel barrel, byte signoffset, BoundingBox bounds) {
public BarrelBody(Barrel barrel, byte signoffset, BoundingBox bounds, boolean async) {
this(barrel, signoffset);
if (bounds == null || bounds.area() > 64 ) {
if (boundsSeemBad(bounds)) {
if (async) {
this.bounds = null;
return;
}
// If loading from old data, or block locations are missing, or other error, regenerate BoundingBox
// This will only be done in those extreme cases.
P.p.log("Regenerating Barrel BoundingBox: " + (bounds == null ? "was null" : "area=" + bounds.area()));
Block broken = getBrokenBlock(true);
if (broken != null) {
barrel.remove(broken, null, true);
}
regenerateBounds();
} else {
this.bounds = bounds;
}
@@ -79,6 +79,15 @@ public class BarrelBody {
signoffset = 0;
}
/**
* Quick check if the bounds are valid or seem corrupt
*/
public static boolean boundsSeemBad(BoundingBox bounds) {
if (bounds == null) return true;
long area = bounds.area();
return area > 64 || area < 4;
}
/**
* direction of the barrel from the spigot
*/
@@ -218,6 +227,21 @@ public class BarrelBody {
return block;
}
/**
* Regenerate the Barrel Bounds.
*
* @return true if successful, false if Barrel was broken and should be removed.
*/
public boolean regenerateBounds() {
P.p.log("Regenerating Barrel BoundingBox: " + (bounds == null ? "was null" : "area=" + bounds.area()));
Block broken = getBrokenBlock(true);
if (broken != null) {
barrel.remove(broken, null, true);
return false;
}
return true;
}
/**
* returns null if Barrel is correctly placed; the block that is missing when not.
* <p>the barrel needs to be formed correctly