Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Extracted fps view into a separate class

This should be temporary. I hope to move the FPS counter to a billboard
sprite
  • Loading branch information...
commit 44c00453725253cd89c1fd31f6a44eec6a5bd37d 1 parent e2c03d9
Bryan Liles authored
2  src/com/osesm/randy/framework/FPSCounter.java
@@ -12,7 +12,7 @@ public FPSCounter(Simulation simulation) {
12 12 public void logFrame() {
13 13 frames++;
14 14 if (System.nanoTime() - startTime >= 1000000000) {
15   - simulation.setStatus("fps: " + frames);
  15 + simulation.setStatus("frames per second: " + frames);
16 16 frames = 0;
17 17 startTime = System.nanoTime();
18 18 }
17 src/com/osesm/randy/framework/Simulation.java
@@ -3,9 +3,6 @@
3 3 import javax.microedition.khronos.egl.EGLConfig;
4 4 import javax.microedition.khronos.opengles.GL10;
5 5
6   -import com.osesm.randy.framework.gl.ShaderCompiler;
7   -import com.osesm.randy.lab.R;
8   -
9 6 import android.app.Activity;
10 7 import android.opengl.GLSurfaceView;
11 8 import android.opengl.GLSurfaceView.Renderer;
@@ -13,7 +10,10 @@
13 10 import android.util.Log;
14 11 import android.widget.RelativeLayout;
15 12 import android.widget.RelativeLayout.LayoutParams;
16   -import android.widget.TextView;
  13 +
  14 +import com.osesm.randy.framework.gl.ShaderCompiler;
  15 +import com.osesm.randy.lab.FPSView;
  16 +import com.osesm.randy.lab.R;
17 17
18 18 public abstract class Simulation extends Activity implements Renderer {
19 19
@@ -32,7 +32,7 @@
32 32
33 33 long startTime = System.nanoTime();
34 34 private ShaderCompiler shaderCompiler;
35   - private TextView statusBar;
  35 + private FPSView statusBar;
36 36
37 37 public void debug(String message) {
38 38 Log.d(TAG, message);
@@ -44,7 +44,6 @@ public void run() {
44 44 statusBar.setText(message);
45 45 }
46 46 });
47   -
48 47 }
49 48
50 49 @Override
@@ -64,9 +63,9 @@ public void onCreate(Bundle savedInstanceState) {
64 63 private void addStatusBar(RelativeLayout view) {
65 64 RelativeLayout.LayoutParams relativeParams = new RelativeLayout.LayoutParams(
66 65 LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
67   - statusBar = new TextView(this);
68   - statusBar.setText("frames per second: 999");
69   -
  66 +
  67 + statusBar = new FPSView(this);
  68 +
70 69 relativeParams.addRule(RelativeLayout.ALIGN_BOTTOM, glView.getId());
71 70 view.addView(statusBar, relativeParams);
72 71 }
16 src/com/osesm/randy/lab/FPSView.java
... ... @@ -0,0 +1,16 @@
  1 +package com.osesm.randy.lab;
  2 +
  3 +import android.content.Context;
  4 +import android.widget.TextView;
  5 +
  6 +public class FPSView extends TextView {
  7 +
  8 + public FPSView(Context context) {
  9 + super(context);
  10 +
  11 + setText("Status bar initialized...");
  12 + setTextColor(0xFFF06D2F);
  13 + setTextSize(25.0f);
  14 + }
  15 +
  16 +}
22 src/com/osesm/randy/lab/SimulationTest.java
@@ -29,7 +29,7 @@ public Scene getStartScene() {
29 29
30 30 public SimulationScene(Simulation simulation) {
31 31 super(simulation);
32   -
  32 +
33 33 fpscounter = new FPSCounter(simulation);
34 34 }
35 35
@@ -45,15 +45,15 @@ public void present(float deltaTime) {
45 45 long time = SystemClock.uptimeMillis() % 4000L;
46 46 float angle = 0.090f * ((int) time);
47 47
48   - camera.rotate(0.375f);
49   -
  48 + // camera.rotate(angle);
  49 +
50 50 for (Shape shape : shapes) {
51 51 shape.setAngle(shape.getId() % 2 == 0 ? angle : -angle);
52 52 shape.setProjectionMatrix(camera.getViewProjectionMatrix());
53 53 shape.update();
54 54 shape.draw();
55 55 }
56   -
  56 +
57 57 fpscounter.logFrame();
58 58 }
59 59
@@ -77,8 +77,8 @@ public void dispose() {
77 77
78 78 @Override
79 79 public void changed(int width, int height) {
80   - GLES20.glViewport(0, 0, width, height);
81   - camera = new Camera(width, height);
  80 + GLES20.glViewport(0, 0, width, height);
  81 + camera = new Camera(width, height);
82 82 }
83 83
84 84 private void initShapes() {
@@ -86,15 +86,15 @@ private void initShapes() {
86 86
87 87 float triangle1Coords[] = { -0.5f, -0.25f, 0.5f, 0f, 0f, 0.5f, -0.25f, 0.5f, 1f, 0f, 0.0f, 0.559016994f, 0.5f, 0.5f, 1f };
88 88 float triangle2Coords[] = { -0.7f, -0.25f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.3f, -0.25f, 0.25f, 0.0f, 0.0f, 1.0f, 1.0f, -0.2f, 0.559016994f, 0.2f, 1.0f, 0.0f, 0.0f, 1.0f };
89   -
  89 +
90 90 Texture texture = new Texture(simulation, R.raw.basic_texture);
91 91
92 92 shapes = new ArrayList<Shape>();
93 93 Mesh mesh;
94 94
95   -// mesh = ObjLoader.load(simulation, "sphere.obj");
96   -// shapes.add(new Shape(mesh));
97   -//
  95 + // mesh = ObjLoader.load(simulation, "sphere.obj");
  96 + // shapes.add(new Shape(mesh));
  97 + //
98 98 mesh = new Mesh(simulation, 15, 6, false, true, false);
99 99 mesh.setVertices(triangle1Coords, 0, triangle1Coords.length);
100 100 mesh.setIndices(triangleIndices, 0, triangleIndices.length);
@@ -109,7 +109,7 @@ private void initShapes() {
109 109 mesh = ObjLoader.load(simulation, "sphere.obj");
110 110 mesh.setTexture(texture);
111 111 shapes.add(new Shape(mesh));
112   -
  112 +
113 113 }
114 114 }
115 115

0 comments on commit 44c0045

Please sign in to comment.
Something went wrong with that request. Please try again.