A 'Cycles' variable is added++ everytime "mainProcessHandler();" is called & the initial "Cycle" is completed:
So a cycle in this would be the "mainProcessHandler()" method.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| private void mainProcessHandler() { try { Player.process(); WalkingCheck.process(); WalkingHandler.process(); repaint(); updateFps(); } catch (Exception e1) { System.err.println("A Fatal Exception has occured while processing the mainHandler!"); e1.printStackTrace(System.err); System.exit(0); return; } } |
Sorry for posting so much code, it's just that i've never been good with System.currentTimeMillis() and getting results to return accurately.The Cycles variable i don't care about (I added that just for looks after all else failed to return accurate results).
I'd just like some fancy debugging/engine offload variables that when printed out give me accurate results of usage out of 100(percent). <(keyboard failure).
(The average time between debugs i've already handled via a SimpleTimer class).
This is what I was using before, and since
I can't comprehend on how to change those variables to
adjust to a much smaller sleepTime (3 to six) ms. I bring my question here asking for help D=
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| try { if (sleepTime > 0) Thread.sleep(sleepTime); engineTimer.reset();
if(cycleTime < 575) sleepTime = cycleRate - cycleTime; else sleepTime = 0; cycleTime = engineTimer.elapsed(); sleepTime = cycleRate - cycleTime; totalCycleTime += cycleTime; cycles++; debug(); } catch (Exception ex) { ex.printStackTrace(); System.out.println("A fatal exception has been thrown!"); System.exit(0); } |
Everytime that got printed out it would just say usage is = 0.0, simply because the hop between sleepTime was to great for anything to even build up/redraw intime for a smaller cycle (Sprite based game).
Here is that fancy methods debug() (math/results portion)
1 2 3 4 5 6 7 8 9 10 11
| private static void debug() { if (debugTimer.elapsed() > 360 * 1000) { long averageCycleTime = totalCycleTime / cycles; System.out.println("Average Cycle Time: " + averageCycleTime + "ms"); double engineLoad = ((double) averageCycleTime / (double) cycleRate); System.out.println("Engine load: "+ debugPercentFormat.format(engineLoad)); totalCycleTime = 0; cycles = 0; debugTimer.reset(); } } |