Target FPS is 60 but I'm getting results returned 24 - 26 FPS instead, I've probably made a stupid mistake in measuring the time or something, but for the life of me I can't find the problem.
I've gone with an un-throttled Update and a throttled draw, most examples I saw used Thread.Sleep , but I've always been told its an unhealthy practice, so I've steered clear.
Here is the game loop. Update and Draw are currently empty.
@Override
public void run() {
Canvas canvas = null;
long updateCount = 0L;
long updateTime = 0L;
long tickCount = 0L;
long tickTime = 0L;
long tickLoopStart = 0L;
long updateLoopStart = 0L;
long elapsedNanoseconds = 0L;
double timeDelta = 0;
while (running)
{
canvas = null;
tickCount++;
tickLoopStart = System.nanoTime();
try
{
canvas = surfaceHolder.lockCanvas();
updateLoopStart = System.nanoTime();
elapsedNanoseconds = System.nanoTime() - tickLoopStart;
while (elapsedNanoseconds < NANOSECONDS_PER_DRAW)
{
updateCount++;
Update(timeDelta);
timeDelta = (System.nanoTime() - updateLoopStart) / 1000000000;
updateLoopStart = System.nanoTime();
elapsedNanoseconds = System.nanoTime() - tickLoopStart;
}
updateTime += System.nanoTime() - tickLoopStart;
updateLoopStart = System.nanoTime();
Draw(canvas);
}
finally
{
if (canvas != null)
{
surfaceHolder.unlockCanvasAndPost(canvas);
}
}
elapsedNanoseconds = System.nanoTime() - tickLoopStart;
tickTime += elapsedNanoseconds;
timeDelta = (System.nanoTime() - updateLoopStart) / 1000000000;
}
Log.d(TAG, "Game loop has run " + tickCount + " times. Averaging " + (tickTime / tickCount) + "ns per loop. with a target of " + NANOSECONDS_PER_DRAW + "ns.");
Log.d(TAG, "Update has run " + updateCount + " times. Averaging " + (updateTime / updateCount) + "ns per loop. taking up a total of " + updateTime + "ns.");
Log.d(TAG, "Draw has run " + tickCount + " times. Averaging " + ((tickTime - updateTime) / tickCount) + "ns per loop. taking up a total of " + (tickTime - updateTime) + "ns.");
}
Any and all help is greatly appreciated,
Thanks in advanced,
Bombshell






