I registered for the wiki to post the hirestimer class from Snowmoon that we all know and love, but I gather I have to provide hosting for the file. I’ve searched the new forums with several word combinations but couldn’t find it. Can be no one has reposted it?!?! I don’t have a host besides geocities as of yet, so here it is;
public class HighResTimer implements Runnable
{
private int ticks, autoLength;
private Thread timerThread;
private boolean autoCorrection = true;
private boolean running = false;
private long timeDiff, startTime, endTime, msDelay, targetMs;
public HighResTimer() {
timerThread = new Thread(this);
timerThread.setPriority(Thread.MAX_PRIORITY);
timerThread.setDaemon(true);
}
public int getTickCount() {
return ticks;
}
public void resetTickCount() {
ticks = 0;
}
public void startTimer() {
running = true;
timerThread.start();
}
public void stopTimer() {
running = false;
try {
timerThread.join();
}
catch (Exception e) {}
}
public void setAutoCorrection(boolean on, int sampleLength) {
autoCorrection = on;
autoLength = sampleLength;
}
public void setDelay(int tmsDelay) {
msDelay = tmsDelay;
targetMs = msDelay;
}
public void run() {
startTime = System.currentTimeMillis();
try {
while (running) {
if (msDelay > 0)
Thread.sleep(msDelay);
ticks++;
synchronized (this) {
notifyAll();
}
if (autoCorrection && (ticks % autoLength == 0)) {
endTime = System.currentTimeMillis();
timeDiff = ((endTime - startTime) / autoLength) - targetMs;
startTime = endTime;
if (timeDiff > 0) {
msDelay--;
}
if (timeDiff < 0) {
msDelay++;
}
}
}
}
catch (Exception e) {}
}
}
(Ours or anyone elses
)