Android Open Source - fireflies_android Game Thread






From Project

Back to project page fireflies_android.

License

The source code is released under:

MIT License

If you think the Android project fireflies_android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package donothingbox.game.controller;
/*w ww. ja v  a  2  s.  c om*/
import donothingbox.game.view.GameSurfaceView;
import android.annotation.SuppressLint;
import android.graphics.Canvas;
import android.view.SurfaceHolder;

@SuppressLint("WrongCall")
public class GameThread extends Thread {

private SurfaceHolder mSurfaceHolder;
private GameSurfaceView mSurfaceView;
private Canvas canvas;
private boolean m_isRunning = false;

/*
 *   Game Thread that pushes drawing on GameSurfaceView
 *   TODO setup with throttled FPS mgmt based off of max (60FPS) and performance (downgrade FPS on slower devices)
 */

public GameThread(SurfaceHolder holder,GameSurfaceView surfaceView) {

  mSurfaceHolder = holder;
  mSurfaceView = surfaceView;
}

public void setRunnable(boolean run) {
  m_isRunning = run;
}

public void run() {
  //TODO this try is a "patch" to prevent a thrown error on exit. Thread not properly cleaned up, need to trace down real reason
  try{
      while(m_isRunning) {
          canvas = null;
          try {
              canvas = mSurfaceHolder.lockCanvas(null);
              synchronized(mSurfaceHolder) {
                mSurfaceView.onDraw(canvas);
              }
          } finally {
              if(canvas != null && mSurfaceHolder != null) {
                mSurfaceHolder.unlockCanvasAndPost(canvas);
              }
          }
      }
    } catch(RuntimeException e){
      System.out.println("This needs to be cleaned up better: " + e);
    }
}

public Canvas getCanvas() {

    if(canvas != null) {

        return canvas;

    } else {

        return null;
    }
}
}




Java Source Code List

com.donothingbox.fireflies_android.CoreApp.java
com.donothingbox.fireflies_android.DynamicActivity.java
com.donothingbox.fireflies_android.GameSurfaceActivity.java
com.donothingbox.fireflies_android.MainActivity.java
donothingbox.game.controller.AudioController.java
donothingbox.game.controller.GameThread.java
donothingbox.game.controller.HUDController.java
donothingbox.game.controller.StateController.java
donothingbox.game.model.DepthSortComparator.java
donothingbox.game.utils.BitmapUtils.java
donothingbox.game.utils.Utils.java
donothingbox.game.view.CustomDrawableView.java
donothingbox.game.view.FireflySprite.java
donothingbox.game.view.GameLayout.java
donothingbox.game.view.GameSurfaceView.java
donothingbox.game.view.Sprite.java