Skip to content

Commit

Permalink
Extracted fps view into a separate class
Browse files Browse the repository at this point in the history
This should be temporary. I hope to move the FPS counter to a billboard
sprite
  • Loading branch information
bryanl committed Jan 28, 2012
1 parent e2c03d9 commit 44c0045
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/com/osesm/randy/framework/FPSCounter.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public FPSCounter(Simulation simulation) {
public void logFrame() { public void logFrame() {
frames++; frames++;
if (System.nanoTime() - startTime >= 1000000000) { if (System.nanoTime() - startTime >= 1000000000) {
simulation.setStatus("fps: " + frames); simulation.setStatus("frames per second: " + frames);
frames = 0; frames = 0;
startTime = System.nanoTime(); startTime = System.nanoTime();
} }
Expand Down
17 changes: 8 additions & 9 deletions src/com/osesm/randy/framework/Simulation.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
import javax.microedition.khronos.egl.EGLConfig; import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10; import javax.microedition.khronos.opengles.GL10;


import com.osesm.randy.framework.gl.ShaderCompiler;
import com.osesm.randy.lab.R;

import android.app.Activity; import android.app.Activity;
import android.opengl.GLSurfaceView; import android.opengl.GLSurfaceView;
import android.opengl.GLSurfaceView.Renderer; import android.opengl.GLSurfaceView.Renderer;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log; import android.util.Log;
import android.widget.RelativeLayout; import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams; import android.widget.RelativeLayout.LayoutParams;
import android.widget.TextView;
import com.osesm.randy.framework.gl.ShaderCompiler;
import com.osesm.randy.lab.FPSView;
import com.osesm.randy.lab.R;


public abstract class Simulation extends Activity implements Renderer { public abstract class Simulation extends Activity implements Renderer {


Expand All @@ -32,7 +32,7 @@ enum SimulationState {


long startTime = System.nanoTime(); long startTime = System.nanoTime();
private ShaderCompiler shaderCompiler; private ShaderCompiler shaderCompiler;
private TextView statusBar; private FPSView statusBar;


public void debug(String message) { public void debug(String message) {
Log.d(TAG, message); Log.d(TAG, message);
Expand All @@ -44,7 +44,6 @@ public void run() {
statusBar.setText(message); statusBar.setText(message);
} }
}); });

} }


@Override @Override
Expand All @@ -64,9 +63,9 @@ public void onCreate(Bundle savedInstanceState) {
private void addStatusBar(RelativeLayout view) { private void addStatusBar(RelativeLayout view) {
RelativeLayout.LayoutParams relativeParams = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams relativeParams = new RelativeLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
statusBar = new TextView(this);
statusBar.setText("frames per second: 999"); statusBar = new FPSView(this);

relativeParams.addRule(RelativeLayout.ALIGN_BOTTOM, glView.getId()); relativeParams.addRule(RelativeLayout.ALIGN_BOTTOM, glView.getId());
view.addView(statusBar, relativeParams); view.addView(statusBar, relativeParams);
} }
Expand Down
16 changes: 16 additions & 0 deletions src/com/osesm/randy/lab/FPSView.java
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.osesm.randy.lab;

import android.content.Context;
import android.widget.TextView;

public class FPSView extends TextView {

public FPSView(Context context) {
super(context);

setText("Status bar initialized...");
setTextColor(0xFFF06D2F);
setTextSize(25.0f);
}

}
22 changes: 11 additions & 11 deletions src/com/osesm/randy/lab/SimulationTest.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class SimulationScene extends Scene {


public SimulationScene(Simulation simulation) { public SimulationScene(Simulation simulation) {
super(simulation); super(simulation);

fpscounter = new FPSCounter(simulation); fpscounter = new FPSCounter(simulation);
} }


Expand All @@ -45,15 +45,15 @@ public void present(float deltaTime) {
long time = SystemClock.uptimeMillis() % 4000L; long time = SystemClock.uptimeMillis() % 4000L;
float angle = 0.090f * ((int) time); float angle = 0.090f * ((int) time);


camera.rotate(0.375f); // camera.rotate(angle);

for (Shape shape : shapes) { for (Shape shape : shapes) {
shape.setAngle(shape.getId() % 2 == 0 ? angle : -angle); shape.setAngle(shape.getId() % 2 == 0 ? angle : -angle);
shape.setProjectionMatrix(camera.getViewProjectionMatrix()); shape.setProjectionMatrix(camera.getViewProjectionMatrix());
shape.update(); shape.update();
shape.draw(); shape.draw();
} }

fpscounter.logFrame(); fpscounter.logFrame();
} }


Expand All @@ -77,24 +77,24 @@ public void dispose() {


@Override @Override
public void changed(int width, int height) { public void changed(int width, int height) {
GLES20.glViewport(0, 0, width, height); GLES20.glViewport(0, 0, width, height);
camera = new Camera(width, height); camera = new Camera(width, height);
} }


private void initShapes() { private void initShapes() {
short triangleIndices[] = { 0, 1, 2 }; short triangleIndices[] = { 0, 1, 2 };


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 }; 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 };
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 }; 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 };

Texture texture = new Texture(simulation, R.raw.basic_texture); Texture texture = new Texture(simulation, R.raw.basic_texture);


shapes = new ArrayList<Shape>(); shapes = new ArrayList<Shape>();
Mesh mesh; Mesh mesh;


// mesh = ObjLoader.load(simulation, "sphere.obj"); // mesh = ObjLoader.load(simulation, "sphere.obj");
// shapes.add(new Shape(mesh)); // shapes.add(new Shape(mesh));
// //
mesh = new Mesh(simulation, 15, 6, false, true, false); mesh = new Mesh(simulation, 15, 6, false, true, false);
mesh.setVertices(triangle1Coords, 0, triangle1Coords.length); mesh.setVertices(triangle1Coords, 0, triangle1Coords.length);
mesh.setIndices(triangleIndices, 0, triangleIndices.length); mesh.setIndices(triangleIndices, 0, triangleIndices.length);
Expand All @@ -109,7 +109,7 @@ private void initShapes() {
mesh = ObjLoader.load(simulation, "sphere.obj"); mesh = ObjLoader.load(simulation, "sphere.obj");
mesh.setTexture(texture); mesh.setTexture(texture);
shapes.add(new Shape(mesh)); shapes.add(new Shape(mesh));

} }
} }


Expand Down

0 comments on commit 44c0045

Please sign in to comment.