Permalink
Browse files

Fix tabs -> spaces

  • Loading branch information...
1 parent 36f02f5 commit 4b4cc55a74d6d4602bc02484cff1dbe763b5ff9e @sfraim sfraim committed Oct 23, 2011
View
50 app/src/frontend/ui/main/MainActivity.java
@@ -12,7 +12,7 @@
/**
* http://developer.android.com/reference/android/app/Activity.html
- *
+ *
* @author sfraim
*/
public class MainActivity extends Activity {
@@ -25,46 +25,46 @@ public void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.game);
gameView = (GameView) findViewById(R.id.gameView);
- // Use Immutable collections everywhere!
+ // Use Immutable collections everywhere!
ImmutableSet environmentSet = ImmutableSet.of(testEnvironment("Test that you have guava setup correctly"));
// Use AppLogger it is better than {@link Log}
AppLogger.log(android.util.Log.INFO, environmentSet.toString());
}
@Override
- public void onStart() {
- super.onStart();
+ public void onStart() {
+ super.onStart();
logMethod();
- }
+ }
- @Override
- public void onResume() {
- super.onResume();
+ @Override
+ public void onResume() {
+ super.onResume();
logMethod();
- gameView.getGameThread().resume();
- }
+ gameView.getGameThread().resume();
+ }
- @Override
- public void onPause() {
- super.onResume();
+ @Override
+ public void onPause() {
+ super.onResume();
logMethod();
- gameView.getGameThread().pause();
+ gameView.getGameThread().pause();
- // TODO This is where we need to save any state (save it to the thread).
- }
+ // TODO This is where we need to save any state (save it to the thread).
+ }
- @Override
- public void onStop() {
- super.onStop();
+ @Override
+ public void onStop() {
+ super.onStop();
logMethod();
gameView.getGameThread().stop();
- }
+ }
- @Override
- public void onDestroy() {
- super.onDestroy();
- logMethod();
- }
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+ logMethod();
+ }
/**
* Use {@link Nullable} whenever a value can be null.
View
44 app/src/frontend/ui/run/GameThread.java
@@ -33,20 +33,20 @@
private static final int FRAMES_PER_SECOND = 25;
private static final int SKIP_TICKS = 1000 / FRAMES_PER_SECOND;
- private ThreadState threadState;
+ private ThreadState threadState;
private SurfaceHolder surfaceHolder;
private GameView gameView;
private ExecutorService executorService;
private Future<?> gameLoopFuture;
- private boolean runApp;
+ private boolean runApp;
- protected GameThread(SurfaceHolder surfaceHolder, GameView gameView) {
+ protected GameThread(SurfaceHolder surfaceHolder, GameView gameView) {
logMethod();
- this.surfaceHolder = checkNotNull(surfaceHolder, "surfaceHolder");
- this.gameView = checkNotNull(gameView, "gameView");
+ this.surfaceHolder = checkNotNull(surfaceHolder, "surfaceHolder");
+ this.gameView = checkNotNull(gameView, "gameView");
executorService = Executors.newSingleThreadExecutor();
this.runApp = false;
- threadState = STATE_READY;
+ threadState = STATE_READY;
}
public void startGameThread() {
@@ -86,23 +86,23 @@ public void terminateGameThread() {
checkState(runApp && gameLoopFuture != null, "App has already been shutdown.");
runApp = false;
boolean retry = true;
- while (retry) {
- try {
+ while (retry) {
+ try {
gameLoopFuture.get();
setGameThreadState(STATE_TERMINATED);
- retry = false;
- } catch (CancellationException e) {
+ retry = false;
+ } catch (CancellationException e) {
retry = false;
} catch (Exception e) {
- log(Log.ERROR, e.toString());
- }
+ log(Log.ERROR, e.toString());
+ }
}
}
- public ThreadState getGameThreadState() {
+ public ThreadState getGameThreadState() {
logMethod();
- return threadState;
- }
+ return threadState;
+ }
/**
* Analogous to Thread.isAlive(). Returns true if the thread has called run and has not currently executed.
@@ -117,19 +117,19 @@ private void setGameThreadState(ThreadState threadState) {
}
}
- private void doGameLoop() {
+ private void doGameLoop() {
logMethod();
while (runApp) {
- Canvas canvas = null;
- try {
+ Canvas canvas = null;
+ try {
long frameStart = System.currentTimeMillis();
doGameLogic(canvas);
applyBrakes(frameStart);
- } catch (Exception e) {
+ } catch (Exception e) {
log(INFO, Log.getStackTraceString(e));
- }
- }
- }
+ }
+ }
+ }
private void applyBrakes(long frameStart) throws InterruptedException {
long frameEnd = System.currentTimeMillis();
View
27 app/src/frontend/ui/run/GameView.java
@@ -10,41 +10,44 @@
import android.view.SurfaceHolder;
import android.view.SurfaceView;
+/**
+ * @author sfraim
+ */
public class GameView extends SurfaceView implements SurfaceHolder.Callback {
- private GameThread gameThread;
-
- public GameView(Context context, AttributeSet attrs) {
+ private GameThread gameThread;
+
+ public GameView(Context context, AttributeSet attrs) {
super(context, attrs);
logMethod();
SurfaceHolder holder = getHolder();
holder.addCallback(this);
this.gameThread = new GameThread(holder, this);
- }
+ }
public GameThread getGameThread() {
return gameThread;
}
@Override
- public void surfaceCreated(SurfaceHolder holder) {
- logMethod();
- checkState(!gameThread.isAlive(), "The GameThread should not be alive when the surface is called."
+ public void surfaceCreated(SurfaceHolder holder) {
+ logMethod();
+ checkState(!gameThread.isAlive(), "The GameThread should not be alive when the surface is called."
+ "is created. State was " + gameThread.getGameThreadState());
if (gameThread.getGameThreadState() == STATE_TERMINATED) {
gameThread = new GameThread(getHolder(), this);
}
gameThread.startGameThread();
- }
+ }
@Override
public void surfaceChanged(SurfaceHolder surfaceHolder, int i, int i1, int i2) {
logMethod();
}
@Override
- public void surfaceDestroyed(SurfaceHolder holder) {
- logMethod();
- gameThread.terminateGameThread();
- }
+ public void surfaceDestroyed(SurfaceHolder holder) {
+ logMethod();
+ gameThread.terminateGameThread();
+ }
}

0 comments on commit 4b4cc55

Please sign in to comment.