GameApp.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Copyright (c) 2011 Nokia Corporation.
  3. */
  4. /**
  5. *
  6. * Interface for OpenGL game.
  7. * Does not contain any bindings to any api's
  8. *
  9. * Will be runned separately by platform dependent engine.
  10. *
  11. */
  12. #ifndef __NOKIAGAMEAPP__
  13. #define __NOKIAGAMEAPP__
  14. #include "GameEngine.h"
  15. #include "AudioInterfaces.h"
  16. namespace GF {
  17. enum MOUSE_EVENT_TYPE { MOUSE_DOWN, MOUSE_UP, MOUSE_MOVE };
  18. enum KEY_EVENT_TYPE { KEY_DOWN, KEY_UP, KEY_CHARACTER };
  19. enum NOTIFY_EVENT_TYPE { NE_ORIENTATION_CHANGED, NE_PAUSED, NE_RESUMED, NE_VOLUME_CHANGED };
  20. enum SENSOR_EVENT_TYPE { ACCELEROMETER, };
  21. enum BUTTONS { LEFT, RIGHT, UP, DOWN, FIRE, SOFTKEY1, SOFTKEY2 };
  22. class GameApp;
  23. /** implement this function to create your game */
  24. GF::GameApp *createGameApplication( GF::GameEngine *engine );
  25. class GameApp {
  26. public:
  27. GameApp( GameEngine *engine );
  28. virtual ~GameApp();
  29. /** Update game state according to given delta frame time in seconds (e.g. 1/60.0)
  30. */
  31. virtual void update( const float deltaFrameTime );
  32. /** Render screen using OpenGL
  33. */
  34. virtual void render();
  35. /** Renders sampleCount amount of audio samples into given buffer.
  36. * Calling starts when startAudio() is requested by the application.
  37. * Here, sampleCount == 2 means 1 sample for 2 channels.
  38. */
  39. virtual void readAudioStream(AUDIO_SAMPLE_TYPE * target, int sampleCount );
  40. /** Screen resize event, called at least once in application life cycle. In case OS
  41. * level application orientation is enabled, this is called for every orientation change. */
  42. virtual void resize( int w, int h );
  43. /** Allocate application resources. Invoked by the engine before the update loop starts */
  44. virtual bool prepare();
  45. /** Release application resources. Invoked by the engine when update loop ends,
  46. * either because of application is exiting or application lost its focus (e.g. incoming
  47. * phone call) */
  48. virtual void release();
  49. /** Handling mouse event */
  50. virtual void mouseEvent( MOUSE_EVENT_TYPE type, int x, int y, int button ) {};
  51. /** Handling key event */
  52. virtual void keyEvent( KEY_EVENT_TYPE type, int code ) {};
  53. /** Handling system event */
  54. virtual void notifyEvent( NOTIFY_EVENT_TYPE type, int flags ) {};
  55. /** Handling sensor event */
  56. virtual void sensorEvent( SENSOR_EVENT_TYPE type, int x, int y, int z) {};
  57. GameEngine *getGameEngine() { return engine; }
  58. protected:
  59. GameEngine *engine;
  60. };
  61. }
  62. #endif