input.cpp 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * Copyright (c) 2012-2015 Daniele Bartolini and individual contributors.
  3. * License: https://github.com/taylor001/crown/blob/master/LICENSE
  4. */
  5. #include "input.h"
  6. #include "keyboard.h"
  7. #include "mouse.h"
  8. #include "touch.h"
  9. #include "memory.h"
  10. namespace crown
  11. {
  12. namespace input_globals
  13. {
  14. const size_t BUFFER_SIZE = 0 +
  15. + sizeof(Keyboard)
  16. + sizeof(Mouse)
  17. + sizeof(Touch);
  18. char _buffer[BUFFER_SIZE];
  19. Keyboard* _keyboard = NULL;
  20. Mouse* _mouse = NULL;
  21. Touch* _touch = NULL;
  22. void init()
  23. {
  24. _keyboard = new (_buffer) Keyboard();
  25. _mouse = new (_keyboard + 1) Mouse();
  26. _touch = new (_mouse + 1) Touch();
  27. }
  28. void shutdown()
  29. {
  30. _keyboard->~Keyboard();
  31. _keyboard = NULL;
  32. _mouse->~Mouse();
  33. _mouse = NULL;
  34. _touch->~Touch();
  35. _touch = NULL;
  36. }
  37. void update()
  38. {
  39. _keyboard->update();
  40. _mouse->update();
  41. _touch->update();
  42. }
  43. Keyboard& keyboard()
  44. {
  45. return *_keyboard;
  46. }
  47. Mouse& mouse()
  48. {
  49. return *_mouse;
  50. }
  51. Touch& touch()
  52. {
  53. return *_touch;
  54. }
  55. } // namespace input_globals
  56. } // namespace crown