input.cpp 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Copyright (c) 2012-2014 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 = sizeof(Keyboard) +
  15. sizeof(Mouse) + sizeof(Touch);
  16. char _buffer[BUFFER_SIZE];
  17. Keyboard* _keyboard = NULL;
  18. Mouse* _mouse = NULL;
  19. Touch* _touch = NULL;
  20. void init()
  21. {
  22. _keyboard = new (_buffer) Keyboard();
  23. _mouse = new (_buffer + sizeof(Keyboard)) Mouse();
  24. _touch = new (_buffer + sizeof(Keyboard) + sizeof(Mouse)) Touch();
  25. }
  26. void shutdown()
  27. {
  28. _keyboard->~Keyboard();
  29. _keyboard = NULL;
  30. _mouse->~Mouse();
  31. _mouse = NULL;
  32. _touch->~Touch();
  33. _touch = NULL;
  34. }
  35. void update()
  36. {
  37. _keyboard->update();
  38. _mouse->update();
  39. _touch->update();
  40. }
  41. Keyboard& keyboard()
  42. {
  43. return *_keyboard;
  44. }
  45. Mouse& mouse()
  46. {
  47. return *_mouse;
  48. }
  49. Touch& touch()
  50. {
  51. return *_touch;
  52. }
  53. } // namespace input_globals
  54. } // namespace crown