Android Open Source - TreeFrogEngine Game Renderer






From Project

Back to project page TreeFrogEngine.

License

The source code is released under:

MIT License

If you think the Android project TreeFrogEngine 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.discretesoftworks.framework;
/*from   w  w  w .  j a  v a2 s  .  co  m*/
import java.util.ArrayList;


public abstract class GameRenderer {
  
  public ArrayList<GameObject> destructibleObjects, toAdd, toRemove;
  public ArrayList<GriddedObject> solidObjects;
  
  public RaggedDictionary<Integer, GameObject> renderObjects;
  
  public static GameRenderer s_instance;
  
  private int screenWidth = 1920, screenHeight = 1080;
  
  private boolean toClean = false, toClear = false;
  
  private AndroidGame game;
  
  public GameRenderer(){
    renderObjects = new RaggedDictionary<Integer, GameObject>(RaggedDictionary.RIGHT_TO_LEFT);
    toAdd = new ArrayList<GameObject>();
    toRemove = new ArrayList<GameObject>();
    solidObjects = new ArrayList<GriddedObject>();
    destructibleObjects = new ArrayList<GameObject>();
  }
  
  public void update(float deltaTime){
    // Adding MUST come before removing!
    if (toClear) {
      toClear = false;
      for (GameObject o :renderObjects.getCompiledData())
        remove(o);
      renderObjects.clear();
      solidObjects.clear();
    }
    synchronized (renderObjects) {
      synchronized (toAdd) {
        for (int a = 0; a < toAdd.size(); a++){
          renderObjects.add(toAdd.get(a).getDepth(),toAdd.get(a));
        }
        toAdd.clear();
      }
      synchronized (toRemove) {
        for (int r = 0; r < toRemove.size(); r++){
          renderObjects.removeAll(toRemove.get(r).clear());
        }
        toRemove.clear();
      }
    
    
      if (toClean){
        toClean = false;
        System.gc();
      }
  
      int i = 0;
      ArrayList<GameObject> objects = renderObjects.getCompiledData();
      for (i = 0; i < objects.size(); i++){
        objects.get(i).update(deltaTime);
        if (objects.get(i).getLife() < 1)
          toRemove.add(objects.get(i));
        else if (objects.get(i).getDepthChanged())
          renderObjects.move(objects.get(i), objects.get(i).getDepth());
      }
    }
  }
  
  public void add(GameObject o){
    toAdd.add(o);
  }
  
  public ArrayList<GriddedObject> getSolidObjects(){
    return solidObjects;
  }
  
  public void addSolid(GameObject s){
    solidObjects.add(s);
  }
  
  public void removeSolid(GameObject s){
    solidObjects.remove(s);
  }
  
  public void setGame(AndroidGame game){
    this.game = game;
  }
  
  public AndroidGame getGame(){
    return game;
  }
  
  public void clean(){
    toClean = true;
  }
  
  public void clear(){
    toClear = true;
  }
  
  public void remove(GameObject o){
    toRemove.add(o);
  }
  
  public void setScreenWidth(int screenWidth){
    this.screenWidth = screenWidth;
  }
  
  public void setScreenHeight(int screenHeight){
    this.screenHeight = screenHeight;
  }
  
  public int getScreenWidth(){
      return screenWidth;
    }
    
    public int getScreenHeight(){
      return screenHeight;
    }
    
    public abstract int getViewWidth();
    public abstract int getViewHeight();
    public abstract float getViewScale();
  
    public abstract float[] getVPMatrix();
    public abstract float getRatio();
  public abstract RenderModel getNewModel(float x, float y, float width, float height, String filename);
  public abstract void freeModel(RenderModel model);
  public abstract void setBGColor(float r, float g, float b, float a);
  public abstract boolean getSurfaceCreated();
  public abstract void setSurfaceCreated(boolean s);
}




Java Source Code List

com.discretesoftworks.OUYAframework.OuyaGameController.java
com.discretesoftworks.OUYAframework.OuyaGame.java
com.discretesoftworks.TestGame.Floor.java
com.discretesoftworks.TestGame.Player.java
com.discretesoftworks.TestGame.Pointer.java
com.discretesoftworks.TestGame.TestController.java
com.discretesoftworks.TestGame.TestGame.java
com.discretesoftworks.framework.AndroidGame.java
com.discretesoftworks.framework.Assets.java
com.discretesoftworks.framework.Directional.java
com.discretesoftworks.framework.GameController.java
com.discretesoftworks.framework.GameFont.java
com.discretesoftworks.framework.GameObject.java
com.discretesoftworks.framework.GameRenderer.java
com.discretesoftworks.framework.GriddedObject.java
com.discretesoftworks.framework.ModelLoader.java
com.discretesoftworks.framework.MovingObject.java
com.discretesoftworks.framework.MyGLRenderer.java
com.discretesoftworks.framework.MyGLSurfaceView.java
com.discretesoftworks.framework.NumericalMatrix.java
com.discretesoftworks.framework.Pair.java
com.discretesoftworks.framework.Path.java
com.discretesoftworks.framework.Pool.java
com.discretesoftworks.framework.RaggedDictionary.java
com.discretesoftworks.framework.RenderModel.java
com.discretesoftworks.framework.Sprite.java
com.discretesoftworks.framework.Terrain.java
com.discretesoftworks.framework.TextDisplay.java
com.discretesoftworks.framework.TextHolder.java
com.discretesoftworks.framework.View.java
com.discretesoftworks.networking.NetworkGameController.java
com.discretesoftworks.networking.Writer.java