Android Open Source - ShootEmOff Android Fast Render View






From Project

Back to project page ShootEmOff.

License

The source code is released under:

Copyright (c) 2011 Andrey Moiseev, http://o2genum.ru Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),...

If you think the Android project ShootEmOff 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 com.shootemoff.framework.impl;
/*from w  w w .j  a v  a  2s. c o m*/
import android.graphics.*;
import android.view.SurfaceHolder;
import android.view.SurfaceView;

public class AndroidFastRenderView extends SurfaceView implements Runnable
{
  AndroidGame game;
  Bitmap frameBuffer;
  Thread renderThread = null;
  SurfaceHolder holder;
  volatile boolean running = false;

  public AndroidFastRenderView(AndroidGame game, Bitmap frameBuffer)
  {
    super(game);
    this.game = game;
    this.frameBuffer = frameBuffer;
    this.holder = getHolder();
    /*
     * From email by Fivos Asimakop:
     *
     * Remove the wake lock. It's a buggy thing that can cause troubles on
     * devices like Motorola, ZTE and potentially others. Also it will allow
     * you to remove that permission. The best way to prevent device from
     * going to sleep while playing is setting a "keepscreenon" attribute to
     * ON with the "setKeepScreenOn(true)" method. You may be able to do 
     * this in the SurfaceView that holds the canvas ( Not 100% sure about
     * that, I haven't worked with a Canvas yet ).
     */
    setKeepScreenOn(true);
  }
  
  public void resume()
  {
    running = true;
    renderThread = new Thread(this);
    renderThread.start();
  }

  public void run()
  {
    long startTime = System.nanoTime();
    while(running)
    {
      if(!holder.getSurface().isValid())
        continue;

      float deltaTime = (System.nanoTime() - startTime) / 1000000000.0F;
      startTime = System.nanoTime();
      
      game.getCurrentScreen().update(deltaTime);
      game.getCurrentScreen().present(deltaTime);

      Canvas canvas = holder.lockCanvas();
      canvas.drawBitmap(frameBuffer, 0, 0, null);
      holder.unlockCanvasAndPost(canvas);
    }
  }

  public void pause()
  {
    running = false;
    while(true)
    {
      try
      {
        renderThread.join();
        break;
      }
      catch (InterruptedException ex)
      {
        // Failed to stop thread, try again
      }
    }
  }
}




Java Source Code List

com.shootemoff.framework.Audio.java
com.shootemoff.framework.FileIO.java
com.shootemoff.framework.Game.java
com.shootemoff.framework.Graphics.java
com.shootemoff.framework.Input.java
com.shootemoff.framework.Pool.java
com.shootemoff.framework.Screen.java
com.shootemoff.framework.Sound.java
com.shootemoff.framework.Vibration.java
com.shootemoff.framework.impl.AndroidAudio.java
com.shootemoff.framework.impl.AndroidFastRenderView.java
com.shootemoff.framework.impl.AndroidFileIO.java
com.shootemoff.framework.impl.AndroidGame.java
com.shootemoff.framework.impl.AndroidGraphics.java
com.shootemoff.framework.impl.AndroidInput.java
com.shootemoff.framework.impl.AndroidOrientationHandler.java
com.shootemoff.framework.impl.AndroidSound.java
com.shootemoff.framework.impl.AndroidVibration.java
com.shootemoff.framework.impl.KeyboardHandler.java
com.shootemoff.framework.impl.MultiTouchHandler.java
com.shootemoff.framework.impl.OrientationHandler.java
com.shootemoff.framework.impl.SingleTouchHandler.java
com.shootemoff.framework.impl.TouchHandler.java
com.shootemoff.game.ControlPad.java
com.shootemoff.game.Core.java
com.shootemoff.game.Dot.java
com.shootemoff.game.GameActivity.java
com.shootemoff.game.GameOverActivity.java
com.shootemoff.game.GameScreen.java
com.shootemoff.game.OptionsObject.java
com.shootemoff.game.Point.java
com.shootemoff.game.ScoreBoardActivity.java
com.shootemoff.game.ScoreObject.java
com.shootemoff.game.SettingsActivity.java
com.shootemoff.game.StartScreenActivity.java
com.shootemoff.game.StorageHandler.java
com.shootemoff.game.VectorF.java
com.shootemoff.game.World.java