/** * Execute a frame. <br> * <br> * This method will update game logic and update the graphics. */ @Override public void onDrawFrame(GL10 gl) { Room current = myOwner.getCurrentRoom(); gl.glClear(GL10.GL_COLOR_BUFFER_BIT); // Get rid of the previous frame gl.glClearColor(red, green, blue, alpha); // BG color myOwner.getGraphicsHelper().handleGraphics((GL11) gl); if (current != null) { current.update(averageDelta / OPTIMAL_TIME); // Update game logic current.draw(gl); // Draw graphics } now = SystemClock.uptimeMillis(); if (lastTime > 0) timeElapsed = now - lastTime; // The amount of time the last frame took else timeElapsed = (long) averageDelta; // Only happens the first frame if (frames < FPS) { frames++; averageDelta = (timeElapsed + averageDelta * (frames - 1)) / frames; // Update the average amount of time a frame takes } else { averageDelta = (timeElapsed + averageDelta * (FPS - 1)) / FPS; // Update the average amount of time a frame takes } lastTime = now; if (averageDelta / OPTIMAL_TIME > 1.2) { averageDelta = OPTIMAL_TIME; } if (averageDelta / OPTIMAL_TIME < .8) { averageDelta = OPTIMAL_TIME; } if (OUTPUT_FPS) { double fps = (double) 1000 / (double) averageDelta; if (1000.0 / timeElapsed < low || low == -1) low = 1000.0 / timeElapsed; if (1000.0 / timeElapsed > high || high == -1) high = 1000.0 / timeElapsed; if (1000.0 / timeElapsed < 30) Log.d("fps", "FRAME DROPPED. FPS: " + Double.toString(1000.0 / timeElapsed)); if (SystemClock.uptimeMillis() % 100 == 0) { Log.d( "fps", "FPS: " + Double.toString(fps) + " LOW: " + Double.toString(low) + " HIGH: " + Double.toString(high)); // Show FPS in logcat } } }
/** * Set up the surface. <br> * <br> * This method will load the textures, enable effects we need, disable effects we don't need, set * up the client state for drawing the quads. */ @Override public void onSurfaceCreated(GL10 gl, EGLConfig config) { myOwner.getGraphicsHelper().handleGraphics((GL11) gl); // Load textures for the view red = green = blue = alpha = 1; low = high = -1; gl.glBlendFunc(GL10.GL_ONE, GL10.GL_ONE_MINUS_SRC_ALPHA); // How to interpret transparency gl.glAlphaFunc(GL10.GL_GREATER, 0); gl.glEnable(GL10.GL_BLEND); // Enable transparency gl.glEnable(GL10.GL_TEXTURE_2D); // Enable Texture Mapping // Disable all the things we don't need. gl.glDisable(GL10.GL_DEPTH_TEST); gl.glDisable(GL10.GL_FOG); gl.glDisable(GL10.GL_LIGHTING); gl.glDisable(GL10.GL_STENCIL_TEST); gl.glDisable(GL10.GL_SCISSOR_TEST); gl.glDisable(GL10.GL_DITHER); gl.glDisable(GL10.GL_CULL_FACE); gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); // We will use vertex arrays for quad vertices gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY); // We will need to use portions of textures }
/** * Returns the width of the room. This is the same as the width of the room's containing BobView. * * @return Width of the room, in pixels. */ public int getWidth() { return view.getWidth(); }
/** * Returns the height of the room. This is the same as the height of the room's containing * BobView. * * @return Height of the room, in pixels. */ public int getHeight() { return view.getHeight(); }
/** Get the controller helper for this Room's containing BobView. */ public Controller getController() { return view.getController(); }
/** Get the Touch touch listener for this Room's containing BobView. */ public Touch getTouch() { return view.getTouch(); }
/** Returns the activity containing the BobView that contains this Room. */ public Activity getActivity() { return view.getActivity(); }