clientDialDevice.I 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // Filename: clientDialDevice.I
  2. // Created by: drose (26Jan01)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved
  8. //
  9. // All use of this software is subject to the terms of the Panda 3d
  10. // Software license. You should have received a copy of this license
  11. // along with this source code; you will also find a current copy of
  12. // the license at http://www.panda3d.org/license.txt .
  13. //
  14. // To contact the maintainers of this program write to
  15. // [email protected] .
  16. //
  17. ////////////////////////////////////////////////////////////////////
  18. ////////////////////////////////////////////////////////////////////
  19. // Function: ClientDialDevice::DialState::Constructor
  20. // Access: Public
  21. // Description:
  22. ////////////////////////////////////////////////////////////////////
  23. INLINE ClientDialDevice::DialState::
  24. DialState() :
  25. _offset(0.0),
  26. _known(false)
  27. {
  28. }
  29. ////////////////////////////////////////////////////////////////////
  30. // Function: ClientDialDevice::Constructor
  31. // Access: Protected
  32. // Description:
  33. ////////////////////////////////////////////////////////////////////
  34. INLINE ClientDialDevice::
  35. ClientDialDevice(ClientBase *client, const string &device_name):
  36. ClientDevice(client, get_class_type(), device_name)
  37. {
  38. }
  39. ////////////////////////////////////////////////////////////////////
  40. // Function: ClientDialDevice::get_num_dials
  41. // Access: Public
  42. // Description: Returns the number of dial dials known to the
  43. // ClientDialDevice. This number may change as
  44. // more dials are discovered.
  45. ////////////////////////////////////////////////////////////////////
  46. INLINE int ClientDialDevice::
  47. get_num_dials() const {
  48. return _dials.size();
  49. }
  50. ////////////////////////////////////////////////////////////////////
  51. // Function: ClientDialDevice::push_dial
  52. // Access: Public
  53. // Description: Marks that the dial has been offset by the indicated
  54. // amount. It is the user's responsibility to ensure
  55. // that this call is protected within lock().
  56. ////////////////////////////////////////////////////////////////////
  57. INLINE void ClientDialDevice::
  58. push_dial(int index, double offset) {
  59. ensure_dial_index(index);
  60. nassertv(index >= 0 && index < (int)_dials.size());
  61. _dials[index]._offset += offset;
  62. _dials[index]._known = true;
  63. }
  64. ////////////////////////////////////////////////////////////////////
  65. // Function: ClientDialDevice::read_dial
  66. // Access: Public
  67. // Description: Returns the number of complete revolutions of the
  68. // dial since the last time read_dial() was called.
  69. // This is a destructive operation; it is not possible
  70. // to read the dial without resetting the counter.
  71. //
  72. // It is the user's responsibility to ensure that this
  73. // call is protected within lock().
  74. ////////////////////////////////////////////////////////////////////
  75. INLINE double ClientDialDevice::
  76. read_dial(int index) {
  77. if (index >= 0 && index < (int)_dials.size()) {
  78. double result = _dials[index]._offset;
  79. _dials[index]._offset = 0.0;
  80. return result;
  81. } else {
  82. return 0.0;
  83. }
  84. }
  85. ////////////////////////////////////////////////////////////////////
  86. // Function: ClientDialDevice::is_dial_known
  87. // Access: Public
  88. // Description: Returns true if the state of the indicated dial
  89. // dial is known, or false if we have never heard
  90. // anything about this particular dial.
  91. ////////////////////////////////////////////////////////////////////
  92. INLINE bool ClientDialDevice::
  93. is_dial_known(int index) const {
  94. if (index >= 0 && index < (int)_dials.size()) {
  95. return _dials[index]._known;
  96. } else {
  97. return false;
  98. }
  99. }