Sample.h 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #ifndef SAMPLE_H_
  2. #define SAMPLE_H_
  3. #include "gameplay.h"
  4. using namespace gameplay;
  5. /**
  6. * Base class for all of the samples.
  7. *
  8. * The goal is to provide an interface that matches the Game class.
  9. * This way you can easily copy the code from your sample into a game.
  10. */
  11. class Sample
  12. {
  13. friend class SamplesGame;
  14. public:
  15. static const Game::State& UNINITIALIZED;
  16. static const Game::State& RUNNING;
  17. static const Game::State& PAUSED;
  18. static const Game::ClearFlags& CLEAR_COLOR;
  19. static const Game::ClearFlags& CLEAR_DEPTH;
  20. static const Game::ClearFlags& CLEAR_STENCIL;
  21. static const Game::ClearFlags& CLEAR_COLOR_DEPTH;
  22. static const Game::ClearFlags& CLEAR_COLOR_STENCIL;
  23. static const Game::ClearFlags& CLEAR_DEPTH_STENCIL;
  24. static const Game::ClearFlags& CLEAR_COLOR_DEPTH_STENCIL;
  25. static bool isVsync();
  26. static void setVsync(bool enable);
  27. static long getAbsoluteTime();
  28. static long getGameTime();
  29. Game::State getState() const;
  30. int run();
  31. void pause();
  32. void resume();
  33. void exit();
  34. void frame();
  35. unsigned int getFrameRate() const;
  36. const Rectangle& getViewport() const;
  37. void setViewport(const Rectangle& viewport);
  38. unsigned int getWidth() const;
  39. unsigned int getHeight() const;
  40. float getAspectRatio() const;
  41. void clear(Game::ClearFlags flags, const Vector4& clearColor, float clearDepth, int clearStencil);
  42. void clear(Game::ClearFlags flags, float red, float green, float blue, float alpha, float clearDepth, int clearStencil);
  43. AudioController* getAudioController() const;
  44. AnimationController* getAnimationController() const;
  45. PhysicsController* getPhysicsController() const;
  46. ScriptController* getScriptController() const;
  47. void displayKeyboard(bool display);
  48. virtual void keyEvent(Keyboard::KeyEvent evt, int key);
  49. virtual void touchEvent(Touch::TouchEvent evt, int x, int y, unsigned int contactIndex);
  50. virtual bool mouseEvent(Mouse::MouseEvent evt, int x, int y, int wheelDelta);
  51. bool hasMouse();
  52. bool isMouseCaptured();
  53. void setMouseCaptured(bool captured);
  54. void setMultiTouch(bool enabled);
  55. bool isMultiTouch() const;
  56. bool hasAccelerometer() const;
  57. void getAccelerometerValues(float* pitch, float* roll);
  58. void getSensorValues(float* accelX, float* accelY, float* accelZ, float* gyroX, float* gyroY, float* gyroZ);
  59. void schedule(long timeOffset, TimeListener* timeListener, void* cookie = 0);
  60. void enableScriptCamera(bool enable);
  61. void setScriptCameraSpeed(float normal, float fast);
  62. bool isGestureSupported(Gesture::GestureEvent evt);
  63. void registerGesture(Gesture::GestureEvent evt);
  64. void unregisterGesture(Gesture::GestureEvent evt);
  65. bool isGestureRegistered(Gesture::GestureEvent evt);
  66. virtual void gestureSwipeEvent(int x, int y, int direction);
  67. virtual void gesturePinchEvent(int x, int y, float scale);
  68. virtual void gestureTapEvent(int x, int y);
  69. virtual void gestureLongTapEvent(int x, int y, float duration);
  70. virtual void gestureDragEvent(int x, int y);
  71. virtual void gestureDropEvent(int x, int y);
  72. virtual void gamepadEvent(Gamepad::GamepadEvent evt, Gamepad* gamepad);
  73. unsigned int getGamepadCount() const;
  74. Gamepad* getGamepad(unsigned int index, bool preferPhysical = true) const;
  75. protected:
  76. Sample();
  77. virtual ~Sample();
  78. virtual void initialize() = 0;
  79. virtual void finalize() = 0;
  80. virtual void update(float elapsedTime) = 0;
  81. virtual void render(float elapsedTime) = 0;
  82. static void drawFrameRate(Font* font, const Vector4& color, unsigned int x, unsigned int y, unsigned int fps);
  83. private:
  84. Sample(const Sample&);
  85. Sample& operator=(const Sample&);
  86. };
  87. #endif