Fix non-monotonic elapsed time checks, fixes #108
This commit is contained in:
parent
be303f2e57
commit
b073d591fb
@ -59,7 +59,7 @@ public class MemoryBehavior extends Behavior {
|
||||
TileEntityLockable lockable = (TileEntityLockable) tileEntity;
|
||||
int size = lockable.getSizeInventory();
|
||||
|
||||
this.futureInventories.add(new FutureInventory(System.currentTimeMillis(), size, lockable.getGuiID(), tileEntity.getPos()));
|
||||
this.futureInventories.add(new FutureInventory(System.nanoTime() / 1000000L, size, lockable.getGuiID(), tileEntity.getPos()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -81,7 +81,7 @@ public class MemoryBehavior extends Behavior {
|
||||
SPacketOpenWindow packet = event.cast();
|
||||
|
||||
// Remove any entries that were created over a second ago, this should make up for INSANE latency
|
||||
this.futureInventories.removeIf(i -> System.currentTimeMillis() - i.time > 1000);
|
||||
this.futureInventories.removeIf(i -> System.nanoTime() / 1000000L - i.time > 1000);
|
||||
|
||||
this.futureInventories.stream()
|
||||
.filter(i -> i.type.equals(packet.getGuiId()) && i.slots == packet.getSlotCount())
|
||||
|
@ -183,7 +183,7 @@ public final class CachedRegion implements IBlockTypeAccess {
|
||||
return;
|
||||
|
||||
System.out.println("Loading region " + x + "," + z + " from disk " + path);
|
||||
long start = System.currentTimeMillis();
|
||||
long start = System.nanoTime() / 1000000L;
|
||||
|
||||
try (
|
||||
FileInputStream fileIn = new FileInputStream(regionFile.toFile());
|
||||
@ -266,7 +266,7 @@ public final class CachedRegion implements IBlockTypeAccess {
|
||||
}
|
||||
}
|
||||
hasUnsavedChanges = false;
|
||||
long end = System.currentTimeMillis();
|
||||
long end = System.nanoTime() / 1000000L;
|
||||
System.out.println("Loaded region successfully in " + (end - start) + "ms");
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
|
@ -153,22 +153,22 @@ public final class CachedWorld implements IBlockTypeAccess {
|
||||
System.out.println("Not saving to disk; chunk caching is disabled.");
|
||||
return;
|
||||
}
|
||||
long start = System.currentTimeMillis();
|
||||
long start = System.nanoTime() / 1000000L;
|
||||
this.cachedRegions.values().parallelStream().forEach(region -> {
|
||||
if (region != null)
|
||||
region.save(this.directory);
|
||||
});
|
||||
long now = System.currentTimeMillis();
|
||||
long now = System.nanoTime() / 1000000L;
|
||||
System.out.println("World save took " + (now - start) + "ms");
|
||||
}
|
||||
|
||||
public final void reloadAllFromDisk() {
|
||||
long start = System.currentTimeMillis();
|
||||
long start = System.nanoTime() / 1000000L;
|
||||
this.cachedRegions.values().forEach(region -> {
|
||||
if (region != null)
|
||||
region.load(this.directory);
|
||||
});
|
||||
long now = System.currentTimeMillis();
|
||||
long now = System.nanoTime() / 1000000L;
|
||||
System.out.println("World load took " + (now - start) + "ms");
|
||||
}
|
||||
|
||||
|
@ -39,7 +39,7 @@ public final class ChunkPacker implements Helper {
|
||||
private ChunkPacker() {}
|
||||
|
||||
public static CachedChunk pack(Chunk chunk) {
|
||||
long start = System.currentTimeMillis();
|
||||
long start = System.nanoTime() / 1000000L;
|
||||
|
||||
Map<String, List<BlockPos>> specialBlocks = new HashMap<>();
|
||||
BitSet bitSet = new BitSet(CachedChunk.SIZE);
|
||||
@ -63,7 +63,7 @@ public final class ChunkPacker implements Helper {
|
||||
e.printStackTrace();
|
||||
}
|
||||
//System.out.println("Packed special blocks: " + specialBlocks);
|
||||
long end = System.currentTimeMillis();
|
||||
long end = System.nanoTime() / 1000000L;
|
||||
//System.out.println("Chunk packing took " + (end - start) + "ms for " + chunk.x + "," + chunk.z);
|
||||
String[] blockNames = new String[256];
|
||||
for (int z = 0; z < 16; z++) {
|
||||
|
@ -72,7 +72,7 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
|
||||
currentlyRunning = this;
|
||||
CachedWorld cachedWorld = Optional.ofNullable(WorldProvider.INSTANCE.getCurrentWorld()).map(w -> w.cache).orElse(null);
|
||||
ChunkProviderClient chunkProvider = Minecraft.getMinecraft().world.getChunkProvider();
|
||||
long startTime = System.currentTimeMillis();
|
||||
long startTime = System.nanoTime() / 1000000L;
|
||||
boolean slowPath = Baritone.settings().slowPath.get();
|
||||
long timeoutTime = startTime + (slowPath ? Baritone.settings().slowPathTimeoutMS : Baritone.settings().pathTimeoutMS).<Long>get();
|
||||
//long lastPrintout = 0;
|
||||
@ -83,7 +83,7 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
|
||||
int pathingMaxChunkBorderFetch = Baritone.settings().pathingMaxChunkBorderFetch.get(); // grab all settings beforehand so that changing settings during pathing doesn't cause a crash or unpredictable behavior
|
||||
double favorCoeff = Baritone.settings().backtrackCostFavoringCoefficient.get();
|
||||
boolean minimumImprovementRepropagation = Baritone.settings().minimumImprovementRepropagation.get();
|
||||
while (!openSet.isEmpty() && numEmptyChunk < pathingMaxChunkBorderFetch && System.currentTimeMillis() < timeoutTime && !cancelRequested) {
|
||||
while (!openSet.isEmpty() && numEmptyChunk < pathingMaxChunkBorderFetch && System.nanoTime() / 1000000L - timeoutTime < 0 && !cancelRequested) {
|
||||
if (slowPath) {
|
||||
try {
|
||||
Thread.sleep(Baritone.settings().slowPathTimeDelayMS.<Long>get());
|
||||
@ -95,13 +95,13 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
|
||||
mostRecentConsidered = currentNode;
|
||||
BetterBlockPos currentNodePos = currentNode.pos;
|
||||
numNodes++;
|
||||
/*if (System.currentTimeMillis() > lastPrintout + 1000) {//print once a second
|
||||
/*if ((lastPrintout + 1000) - System.nanoTime() / 1000000L < 0) {//print once a second
|
||||
System.out.println("searching... at " + currentNodePos + ", considered " + numNodes + " nodes so far");
|
||||
lastPrintout = System.currentTimeMillis();
|
||||
lastPrintout = System.nanoTime() / 1000000L;
|
||||
}*/
|
||||
if (goal.isInGoal(currentNodePos)) {
|
||||
currentlyRunning = null;
|
||||
displayChatMessageRaw("Took " + (System.currentTimeMillis() - startTime) + "ms, " + numMovementsConsidered + " movements considered");
|
||||
displayChatMessageRaw("Took " + (System.nanoTime() / 1000000L - startTime) + "ms, " + numMovementsConsidered + " movements considered");
|
||||
return Optional.of(new Path(startNode, currentNode, numNodes));
|
||||
}
|
||||
//long constructStart = System.nanoTime();
|
||||
@ -182,7 +182,7 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
|
||||
}
|
||||
System.out.println(numMovementsConsidered + " movements considered");
|
||||
System.out.println("Open set size: " + openSet.size());
|
||||
System.out.println((int) (numNodes * 1.0 / ((System.currentTimeMillis() - startTime) / 1000F)) + " nodes per second");
|
||||
System.out.println((int) (numNodes * 1.0 / ((System.nanoTime() / 1000000L - startTime) / 1000F)) + " nodes per second");
|
||||
double bestDist = 0;
|
||||
for (int i = 0; i < bestSoFar.length; i++) {
|
||||
if (bestSoFar[i] == null) {
|
||||
@ -193,7 +193,7 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
|
||||
bestDist = dist;
|
||||
}
|
||||
if (dist > MIN_DIST_PATH * MIN_DIST_PATH) { // square the comparison since distFromStartSq is squared
|
||||
displayChatMessageRaw("Took " + (System.currentTimeMillis() - startTime) + "ms, A* cost coefficient " + COEFFICIENTS[i] + ", " + numMovementsConsidered + " movements considered");
|
||||
displayChatMessageRaw("Took " + (System.nanoTime() / 1000000L - startTime) + "ms, A* cost coefficient " + COEFFICIENTS[i] + ", " + numMovementsConsidered + " movements considered");
|
||||
if (COEFFICIENTS[i] >= 3) {
|
||||
System.out.println("Warning: cost coefficient is greater than three! Probably means that");
|
||||
System.out.println("the path I found is pretty terrible (like sneak-bridging for dozens of blocks)");
|
||||
|
@ -163,7 +163,7 @@ public class PathExecutor implements Helper {
|
||||
}
|
||||
}
|
||||
}*/
|
||||
long start = System.currentTimeMillis();
|
||||
long start = System.nanoTime() / 1000000L;
|
||||
for (int i = pathPosition - 10; i < pathPosition + 10; i++) {
|
||||
if (i >= 0 && i < path.movements().size()) {
|
||||
Movement m = path.movements().get(i);
|
||||
@ -198,7 +198,7 @@ public class PathExecutor implements Helper {
|
||||
toWalkInto = newWalkInto;
|
||||
recalcBP = false;
|
||||
}
|
||||
long end = System.currentTimeMillis();
|
||||
long end = System.nanoTime() / 1000000L;
|
||||
if (end - start > 0) {
|
||||
//displayChatMessageRaw("Recalculating break and place took " + (end - start) + "ms");
|
||||
}
|
||||
|
@ -188,7 +188,7 @@ public final class PathRenderer implements Helper {
|
||||
maxX = goalPos.getX() + 1 - 0.002 - renderPosX;
|
||||
minZ = goalPos.getZ() + 0.002 - renderPosZ;
|
||||
maxZ = goalPos.getZ() + 1 - 0.002 - renderPosZ;
|
||||
double y = Math.sin((System.currentTimeMillis() % 2000L) / 2000F * Math.PI * 2);
|
||||
double y = Math.sin(((float) (System.nanoTime() / 1000000L) % 2000L) / 2000F * Math.PI * 2);
|
||||
y1 = 1 + y + goalPos.getY() - renderPosY;
|
||||
y2 = 1 - y + goalPos.getY() - renderPosY;
|
||||
minY = goalPos.getY() - renderPosY;
|
||||
|
@ -42,7 +42,7 @@ public class OpenSetsTest {
|
||||
public void removeAndTest(int amount, IOpenSet[] test, Optional<Collection<PathNode>> mustContain) {
|
||||
double[][] results = new double[test.length][amount];
|
||||
for (int i = 0; i < test.length; i++) {
|
||||
long before = System.currentTimeMillis();
|
||||
long before = System.nanoTime() / 1000000L;
|
||||
for (int j = 0; j < amount; j++) {
|
||||
PathNode pn = test[i].removeLowest();
|
||||
if (mustContain.isPresent() && !mustContain.get().contains(pn)) {
|
||||
@ -50,7 +50,7 @@ public class OpenSetsTest {
|
||||
}
|
||||
results[i][j] = pn.combinedCost;
|
||||
}
|
||||
System.out.println(test[i].getClass() + " " + (System.currentTimeMillis() - before));
|
||||
System.out.println(test[i].getClass() + " " + (System.nanoTime() / 1000000L - before));
|
||||
}
|
||||
for (int j = 0; j < amount; j++) {
|
||||
for (int i = 1; i < test.length; i++) {
|
||||
@ -104,10 +104,10 @@ public class OpenSetsTest {
|
||||
|
||||
System.out.println("Insertion");
|
||||
for (IOpenSet set : test) {
|
||||
long before = System.currentTimeMillis();
|
||||
long before = System.nanoTime() / 1000000L;
|
||||
for (int i = 0; i < size; i++)
|
||||
set.insert(toInsert[i]);
|
||||
System.out.println(set.getClass() + " " + (System.currentTimeMillis() - before));
|
||||
System.out.println(set.getClass() + " " + (System.nanoTime() / 1000000L - before));
|
||||
//all three take either 0 or 1ms to insert up to 10,000 nodes
|
||||
//linkedlist takes 0ms most often (because there's no array resizing or allocation there, just pointer shuffling)
|
||||
}
|
||||
|
@ -44,21 +44,21 @@ public class BetterBlockPosTest {
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
long before1 = System.currentTimeMillis();
|
||||
long before1 = System.nanoTime() / 1000000L;
|
||||
for (int i = 0; i < 1000000; i++) {
|
||||
pos.up();
|
||||
}
|
||||
long after1 = System.currentTimeMillis();
|
||||
long after1 = System.nanoTime() / 1000000L;
|
||||
try {
|
||||
Thread.sleep(1000); // give GC some time
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
long before2 = System.currentTimeMillis();
|
||||
long before2 = System.nanoTime() / 1000000L;
|
||||
for (int i = 0; i < 1000000; i++) {
|
||||
pos2.up();
|
||||
}
|
||||
long after2 = System.currentTimeMillis();
|
||||
long after2 = System.nanoTime() / 1000000L;
|
||||
System.out.println((after1 - before1) + " " + (after2 - before2));
|
||||
}
|
||||
|
||||
@ -70,7 +70,7 @@ public class BetterBlockPosTest {
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
long before1 = System.currentTimeMillis();
|
||||
long before1 = System.nanoTime() / 1000000L;
|
||||
for (int i = 0; i < 1000000; i++) {
|
||||
pos.up(0);
|
||||
pos.up(1);
|
||||
@ -78,13 +78,13 @@ public class BetterBlockPosTest {
|
||||
pos.up(3);
|
||||
pos.up(4);
|
||||
}
|
||||
long after1 = System.currentTimeMillis();
|
||||
long after1 = System.nanoTime() / 1000000L;
|
||||
try {
|
||||
Thread.sleep(1000); // give GC some time
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
long before2 = System.currentTimeMillis();
|
||||
long before2 = System.nanoTime() / 1000000L;
|
||||
for (int i = 0; i < 1000000; i++) {
|
||||
pos2.up(0);
|
||||
pos2.up(1);
|
||||
@ -92,7 +92,7 @@ public class BetterBlockPosTest {
|
||||
pos2.up(3);
|
||||
pos2.up(4);
|
||||
}
|
||||
long after2 = System.currentTimeMillis();
|
||||
long after2 = System.nanoTime() / 1000000L;
|
||||
System.out.println((after1 - before1) + " " + (after2 - before2));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user