Rev 167 |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
package com.gebauz.Bauzoid.app;
import android.os.SystemClock;
public class GameThread
implements Runnable
{
private GameRenderer mRenderer =
null;
private long mLastTime
;
private boolean mFinished
;
public GameThread
(GameRenderer renderer
)
{
mRenderer = renderer
;
mLastTime = SystemClock.
uptimeMillis();
mFinished =
false;
}
public void run
()
{
mLastTime = SystemClock.
uptimeMillis();
mFinished =
false;
while (!mFinished
)
{
}
/*
mLastTime = SystemClock.uptimeMillis();
mFinished = false;
while (!mFinished) {
if (mGameRoot != null) {
mRenderer.waitDrawingComplete();
final long time = SystemClock.uptimeMillis();
final long timeDelta = time - mLastTime;
long finalDelta = timeDelta;
if (timeDelta > 12) {
float secondsDelta = (time - mLastTime) * 0.001f;
if (secondsDelta > 0.1f) {
secondsDelta = 0.1f;
}
mLastTime = time;
mGameRoot.update(secondsDelta, null);
CameraSystem camera = mGameRoot.sSystemRegistry.cameraSystem;
float x = 0.0f;
float y = 0.0f;
if (camera != null) {
x = camera.getFocusPositionX();
y = camera.getFocusPositionY();
}
BaseObject.sSystemRegistry.renderSystem.swap(mRenderer, x, y);
final long endTime = SystemClock.uptimeMillis();
finalDelta = endTime - time;
mProfileTime += finalDelta;
mProfileFrames++;
if (mProfileTime > PROFILE_REPORT_DELAY * 1000) {
final long averageFrameTime = mProfileTime / mProfileFrames;
DebugLog.d("Game Profile", "Average: " + averageFrameTime);
mProfileTime = 0;
mProfileFrames = 0;
mGameRoot.sSystemRegistry.hudSystem.setFPS(1000 / (int)averageFrameTime);
}
}
// If the game logic completed in less than 16ms, that means it's running
// faster than 60fps, which is our target frame rate. In that case we should
// yield to the rendering thread, at least for the remaining frame.
if (finalDelta < 16) {
try {
Thread.sleep(16 - finalDelta);
} catch (InterruptedException e) {
// Interruptions here are no big deal.
}
}
synchronized(mPauseLock) {
if (mPaused) {
SoundSystem sound = BaseObject.sSystemRegistry.soundSystem;
if (sound != null) {
sound.pauseAll();
BaseObject.sSystemRegistry.inputSystem.releaseAllKeys();
}
while (mPaused) {
try {
mPauseLock.wait();
} catch (InterruptedException e) {
// No big deal if this wait is interrupted.
}
}
}
}
}
}
// Make sure our dependence on the render system is cleaned up.
BaseObject.sSystemRegistry.renderSystem.emptyQueues(mRenderer);
*/
}
}