Controls.pkg 975 B

123456789101112131415161718192021222324252627282930313233343536
  1. $#include "Controls.h"
  2. /// %Controls sent over the network.
  3. class Controls
  4. {
  5. public:
  6. /// Reset to initial state.
  7. void Reset();
  8. /// Set or release buttons.
  9. void Set(unsigned buttons, bool down = true)
  10. {
  11. if (down)
  12. buttons_ |= buttons;
  13. else
  14. buttons_ &= ~buttons;
  15. }
  16. /// Check if a button is held down.
  17. bool IsDown(unsigned button) const
  18. {
  19. return (buttons_ & button) != 0;
  20. }
  21. /// Check if a button was pressed on this frame. Requires previous frame's controls.
  22. bool IsPressed(unsigned button, const Controls& previousControls) const { return (buttons_ & button) != 0 && (previousControls.buttons_ & button) == 0; }
  23. /// Button state.
  24. unsigned buttons_ @ buttons;
  25. /// Mouse yaw.
  26. float yaw_ @ yaw;
  27. /// Mouse pitch.
  28. float pitch_ @ pitch;
  29. /// Extra control data.
  30. VariantMap extraData_ @ extraData;
  31. };