Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1307,7 +1307,7 @@ public void pause() {
final boolean canPause = isRunning() && !f_stopping && f_pauseBeginTimeNanos == 0;
if (canPause) {
f_timingSource.removeTickListener(this);
f_pauseBeginTimeNanos = System.nanoTime();
f_pauseBeginTimeNanos = f_timingSource.getNanoTime();
}
}
}
Expand All @@ -1333,7 +1333,7 @@ public void resume() {
synchronized (this) {
final boolean paused = isPaused();
if (paused) {
long pauseDeltaNanos = System.nanoTime() - f_pauseBeginTimeNanos;
long pauseDeltaNanos = f_timingSource.getNanoTime() - f_pauseBeginTimeNanos;
f_startTimeNanos += pauseDeltaNanos;
f_cycleStartTimeNanos += pauseDeltaNanos;
f_pauseBeginTimeNanos = 0;
Expand Down Expand Up @@ -1411,7 +1411,7 @@ public void await() throws InterruptedException {
* time.
*/
public long getCycleElapsedTime() {
return getCycleElapsedTime(System.nanoTime());
return getCycleElapsedTime(f_timingSource.getNanoTime());
}

/**
Expand Down Expand Up @@ -1440,7 +1440,7 @@ public long getCycleElapsedTime(long currentTimeNanos) {
* @return the total time elapsed in nanoseconds between the time this animation started and the current time.
*/
public long getTotalElapsedTime() {
return getTotalElapsedTime(System.nanoTime());
return getTotalElapsedTime(f_timingSource.getNanoTime());
}

/**
Expand Down Expand Up @@ -1493,7 +1493,7 @@ void startHelper(Direction direction, String methodName) {
throw new IllegalStateException(I18N.err(12, methodName));
}

final long nanoTime = System.nanoTime();
final long nanoTime = f_timingSource.getNanoTime();
f_startTimeNanos = nanoTime;
f_cycleStartTimeNanos = nanoTime + f_startDelayNanos;
f_currentDirection = direction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public void runPerTick() {
}
task.run();
}
final long nanoTime = System.nanoTime();
final long nanoTime = getNanoTime();
if (!f_tickListeners.isEmpty()) {
for (TickListener listener : f_tickListeners) {
listener.timingSourceTick(TimingSource.this, nanoTime);
Expand All @@ -210,4 +210,16 @@ public void runPerTick() {
}
}
}

/**
* Returns the reference time of this TimingSource in nanoseconds.
* By default, this method delegates to {@link System#nanoTime()}.
* Subclasses may override this method to provide their own reference time,
* such as a frame counter or an alternative high-precision timing source.
*
* @return the reference time in nanoseconds
*/
public long getNanoTime() {
return System.nanoTime();
}
}