Skip to content

Commit

Permalink
make unfreeze work properly and detect backwards leaps
Browse files Browse the repository at this point in the history
  • Loading branch information
valoeghese committed Nov 1, 2021
1 parent f5941d1 commit 45f34cb
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/main/java/valoeghese/scalpel/ScalpelApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,16 @@ public void run() {

this.postInit();

long lastUpdate = System.currentTimeMillis();

while (this.shouldRun()) {
long timeMillis = System.currentTimeMillis();

if (timeMillis >= this.nextUpdate) {
if (timeMillis < lastUpdate) {
System.out.println("Time Moved Backwards! Did the system timezone change?");
this.nextUpdate = timeMillis + this.tickDelta / 2;
} else if (timeMillis >= this.nextUpdate) {
lastUpdate = timeMillis;
this.nextUpdate = timeMillis + this.tickDelta;
if (this.freezeTime == null) this.tick();
}
Expand Down Expand Up @@ -106,6 +112,7 @@ protected void freeze() {
}

protected void unfreeze() {
this.nextUpdate = System.currentTimeMillis() + this.tickDelta - (int) (this.freezeTime * this.tickDelta);
this.freezeTime = null;
}

Expand Down

0 comments on commit 45f34cb

Please sign in to comment.