Looking for a nice way to keep my games cycle under 6 seconds, and every 45 seconds outprint the following: (If it can be calculated)
Average Cycle Time: 0.0ms. (Under control =D)
Engine Offload: 0.0%. (Possibly out of 100%?)
Right now how my game’s loop looks is like the following:
public void run() {
try {
if (sleepTime > 0) {
Thread.sleep(getCycle());
mainProcessHandler();
cycles++;
debug();
}
} catch (InterruptedException e) {
System.out.println("A Fatal Exception has occured during Runtime!");
e.printStackTrace(System.err);
System.exit(0);
return;
}
}
And at the end it calls the debugging method (where i’d like this to outprint every 45 seconds).
private void debug() {
try {
if ((debugTimer.elapsed() > averageDebugTime) && (debugging())) {
cycleTime = cycleTimer.elapsed();
System.out.println("Average Cycle Time: "+cycleTime+"ms.");
System.out.println("Total Cycles: "+getCycles());
cycles = 0;
sleepTime = getCycle();
cycleTimer.reset();
debugTimer.reset();
System.gc();
System.runFinalization();
}
} catch (Exception e1) {
System.err.println("A Fatal Exception has occured while processing debug!");
e1.printStackTrace(System.err);
System.exit(0);
return;
}
}
I really don’t like what i’ve came up with before this, or the example above.
Right now it just outprints:
[2/5/12 6:05 PM]: Average Cycle Time: 30007ms.
[2/5/12 6:05 PM]: Total Cycles: 1938
So i’m asking if anyone could come up or share some nice way of keeping track of these variables, and adjusting them through out my main game class.