1 / 17

Android Game Framework

Android Game Framework. CGDD4203. The Overview. AndroidGame Extends Activity class Implements Game (abstract) interface AndroidGame consists of FastRenderView , Graphics Audio, Input, FileIO Screen. OnCreate. Linking Input Handling. getStartScreen. OnPause and OnResume.

royce
Download Presentation

Android Game Framework

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Android Game Framework CGDD4203

  2. The Overview • AndroidGame • Extends Activity class • Implements Game (abstract) interface • AndroidGame consists of • FastRenderView, Graphics • Audio, Input, FileIO • Screen

  3. OnCreate

  4. Linking Input Handling

  5. getStartScreen

  6. OnPause and OnResume OK to dim/turn-off screen Stop the render thread Active/current screen should stop Don’t dim/turn-off screen hereafter Active/current screen should commence Begin the render thread

  7. setScreen – Getting Things Going Stop previously active screen Commence new active screen (with time/update delta of 0)

  8. Rendering

  9. AndroidFastRenderView • Threaded (implements Runnable) • Maintains • Reference to AndroidGame • Bitmap framebuffer (to draw) • SurfaceHolder (to lock/unlock canvas) • Responsible for calling update/present on game’s current screen

  10. The Thread’s Work Tell current screen toupdate/present itself Draw the frame bufferfullscreen (scaled)

  11. Input Handling

  12. AndroidInput • Provides ability to handle various inputs • Accelerometer • Keyboard • Touch • Clean interface to low-level ‘guts’ • Also allows for multiple APIs and compatibility • SDK < 5 (SingleTouchHanlder) • SDK >= 5 (MultiTouchHandler)

  13. Garbage Collection and Pools • In real-time systems, auto-memory handling (GC) can kill performance • Memory pools can avoid this problem • Allocate at the beginning and “self-manage” thereafter gcviz (on NetFlix data) http://techblog.netflix.com/2013/05/garbage-collection-visualization.html

  14. KeyboardHandler • Allocate pool (smart list) of KeyEvent • Maintain input buffer • Maintain events collection • Poll buffer periodically • Move from buffer to events collection • Shuffle memory from events collection to pool as needed • Don’t neglect to handle events or events collection will fill up (i.e., pool will empty)

  15. Pool Fixed Size (! GC) No allocation(! GC) Pool<KeyEvent> keyEventPool (capacity = 100 in this case) List<KeyEvent> keyEventsBuffer 1. Key is pressed 2. Key info copied (obj moved from pool into buffer) List<KeyEvent> keyEvents 3.This (#1 & #2)continues… No allocation(! GC) 4. Periodically (don’t wait too long) we call getKeyEvents 5. KeyEvent objects are “freed” back into the pool & moved into keyEvents

  16. Other Odds and Ends • AndroidFileIO • Audio • AndroidAudio • AndroidSound • AndroidMusic • Other Input • AccelerometerInput • AccelerometerHandler • CompassHandler All of this is ‘cake’ (no lie!) if you’ve followedeverything else.

  17. The Overall Picture

More Related