Sample.cpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. #include "Sample.h"
  2. #include "SamplesGame.h"
  3. const Game::State& Sample::UNINITIALIZED = Game::UNINITIALIZED;
  4. const Game::State& Sample::RUNNING = Game::RUNNING;
  5. const Game::State& Sample::PAUSED = Game::PAUSED;
  6. const Game::ClearFlags& Sample::CLEAR_COLOR = Game::CLEAR_COLOR;
  7. const Game::ClearFlags& Sample::CLEAR_DEPTH = Game::CLEAR_DEPTH;
  8. const Game::ClearFlags& Sample::CLEAR_STENCIL = Game::CLEAR_STENCIL;
  9. const Game::ClearFlags& Sample::CLEAR_COLOR_DEPTH = Game::CLEAR_COLOR_DEPTH;
  10. const Game::ClearFlags& Sample::CLEAR_COLOR_STENCIL = Game::CLEAR_COLOR_STENCIL;
  11. const Game::ClearFlags& Sample::CLEAR_DEPTH_STENCIL = Game::CLEAR_DEPTH_STENCIL;
  12. const Game::ClearFlags& Sample::CLEAR_COLOR_DEPTH_STENCIL = Game::CLEAR_COLOR_DEPTH_STENCIL;
  13. Sample::Sample()
  14. {
  15. }
  16. Sample::~Sample()
  17. {
  18. enableScriptCamera(false);
  19. }
  20. bool Sample::isVsync()
  21. {
  22. return Game::isVsync();
  23. }
  24. void Sample::setVsync(bool enable)
  25. {
  26. Game::setVsync(enable);
  27. }
  28. long Sample::getAbsoluteTime()
  29. {
  30. return Game::getAbsoluteTime();
  31. }
  32. long Sample::getGameTime()
  33. {
  34. return Game::getGameTime();
  35. }
  36. Game::State Sample::getState() const
  37. {
  38. return Game::getInstance()->getState();
  39. }
  40. int Sample::run()
  41. {
  42. return Game::getInstance()->run();
  43. }
  44. void Sample::pause()
  45. {
  46. Game::getInstance()->pause();
  47. }
  48. void Sample::resume()
  49. {
  50. Game::getInstance()->resume();
  51. }
  52. void Sample::exit()
  53. {
  54. Game::getInstance()->exit();
  55. }
  56. void Sample::frame()
  57. {
  58. Game::getInstance()->frame();
  59. }
  60. unsigned int Sample::getFrameRate() const
  61. {
  62. return Game::getInstance()->getFrameRate();
  63. }
  64. const Rectangle& Sample::getViewport() const
  65. {
  66. return Game::getInstance()->getViewport();
  67. }
  68. void Sample::setViewport(const Rectangle& viewport)
  69. {
  70. Game::getInstance()->setViewport(viewport);
  71. }
  72. unsigned int Sample::getWidth() const
  73. {
  74. return Game::getInstance()->getWidth();
  75. }
  76. unsigned int Sample::getHeight() const
  77. {
  78. return Game::getInstance()->getHeight();
  79. }
  80. float Sample::getAspectRatio() const
  81. {
  82. return Game::getInstance()->getAspectRatio();
  83. }
  84. void Sample::clear(Game::ClearFlags flags, const Vector4& clearColor, float clearDepth, int clearStencil)
  85. {
  86. Game::getInstance()->clear(flags, clearColor, clearDepth, clearStencil);
  87. }
  88. void Sample::clear(Game::ClearFlags flags, float red, float green, float blue, float alpha, float clearDepth, int clearStencil)
  89. {
  90. Game::getInstance()->clear(flags, red, green, blue, alpha, clearDepth, clearStencil);
  91. }
  92. AudioController* Sample::getAudioController() const
  93. {
  94. return Game::getInstance()->getAudioController();
  95. }
  96. AnimationController* Sample::getAnimationController() const
  97. {
  98. return Game::getInstance()->getAnimationController();
  99. }
  100. PhysicsController* Sample::getPhysicsController() const
  101. {
  102. return Game::getInstance()->getPhysicsController();
  103. }
  104. ScriptController* Sample::getScriptController() const
  105. {
  106. return Game::getInstance()->getScriptController();
  107. }
  108. void Sample::displayKeyboard(bool display)
  109. {
  110. Game::getInstance()->displayKeyboard(display);
  111. }
  112. void Sample::keyEvent(Keyboard::KeyEvent evt, int key)
  113. {
  114. }
  115. void Sample::touchEvent(Touch::TouchEvent evt, int x, int y, unsigned int contactIndex)
  116. {
  117. }
  118. bool Sample::mouseEvent(Mouse::MouseEvent evt, int x, int y, int wheelDelta)
  119. {
  120. return false;
  121. }
  122. bool Sample::hasMouse()
  123. {
  124. return Game::getInstance()->hasMouse();
  125. }
  126. bool Sample::isMouseCaptured()
  127. {
  128. return Game::getInstance()->isMouseCaptured();
  129. }
  130. void Sample::setMouseCaptured(bool captured)
  131. {
  132. Game::getInstance()->setMouseCaptured(captured);
  133. }
  134. void Sample::setMultiTouch(bool enabled)
  135. {
  136. Game::getInstance()->setMultiTouch(enabled);
  137. }
  138. bool Sample::isMultiTouch() const
  139. {
  140. return Game::getInstance()->isMultiTouch();
  141. }
  142. bool Sample::hasAccelerometer() const
  143. {
  144. return Game::getInstance()->hasAccelerometer();
  145. }
  146. void Sample::getAccelerometerValues(float* pitch, float* roll)
  147. {
  148. Game::getInstance()->getAccelerometerValues(pitch, roll);
  149. }
  150. void Sample::getSensorValues(float* accelX, float* accelY, float* accelZ, float* gyroX, float* gyroY, float* gyroZ)
  151. {
  152. Game::getInstance()->getSensorValues(accelX, accelY, accelZ, gyroX, gyroY, gyroZ);
  153. }
  154. void Sample::schedule(long timeOffset, TimeListener* timeListener, void* cookie)
  155. {
  156. Game::getInstance()->schedule(timeOffset, timeListener, cookie);
  157. }
  158. void Sample::enableScriptCamera(bool enable)
  159. {
  160. Game::getInstance()->getScriptController()->executeFunction<void>("camera_setActive", "b", enable);
  161. }
  162. void Sample::setScriptCameraSpeed(float normal, float fast)
  163. {
  164. Game::getInstance()->getScriptController()->executeFunction<void>("camera_setSpeed", "ff", normal, fast);
  165. }
  166. bool Sample::isGestureSupported(Gesture::GestureEvent evt)
  167. {
  168. return Game::getInstance()->isGestureSupported(evt);
  169. }
  170. void Sample::registerGesture(Gesture::GestureEvent evt)
  171. {
  172. Game::getInstance()->registerGesture(evt);
  173. }
  174. void Sample::unregisterGesture(Gesture::GestureEvent evt)
  175. {
  176. Game::getInstance()->unregisterGesture(evt);
  177. }
  178. bool Sample::isGestureRegistered(Gesture::GestureEvent evt)
  179. {
  180. return Game::getInstance()->isGestureRegistered(evt);
  181. }
  182. void Sample::gestureSwipeEvent(int x, int y, int direction)
  183. {
  184. }
  185. void Sample::gesturePinchEvent(int x, int y, float scale)
  186. {
  187. }
  188. void Sample::gestureTapEvent(int x, int y)
  189. {
  190. }
  191. void Sample::gestureLongTapEvent(int x, int y, float duration)
  192. {
  193. }
  194. void Sample::gestureDragEvent(int x, int y)
  195. {
  196. }
  197. void Sample::gestureDropEvent(int x, int y)
  198. {
  199. }
  200. void Sample::gamepadEvent(Gamepad::GamepadEvent evt, Gamepad* gamepad)
  201. {
  202. }
  203. unsigned int Sample::getGamepadCount() const
  204. {
  205. return Game::getInstance()->getGamepadCount();
  206. }
  207. Gamepad* Sample::getGamepad(unsigned int index, bool preferPhysical) const
  208. {
  209. return Game::getInstance()->getGamepad(index, preferPhysical);
  210. }
  211. void Sample::drawFrameRate(Font* font, const Vector4& color, unsigned int x, unsigned int y, unsigned int fps)
  212. {
  213. char buffer[10];
  214. sprintf(buffer, "%u", fps);
  215. font->start();
  216. font->drawText(buffer, x, y, color, 18);
  217. font->finish();
  218. }