|
| 1 | +// Filename: clientDialDevice.I |
| 2 | +// Created by: drose (26Jan01) |
| 3 | +// |
| 4 | +//////////////////////////////////////////////////////////////////// |
| 5 | + |
| 6 | +//////////////////////////////////////////////////////////////////// |
| 7 | +// Function: ClientDialDevice::DialState::Constructor |
| 8 | +// Access: Public |
| 9 | +// Description: |
| 10 | +//////////////////////////////////////////////////////////////////// |
| 11 | +INLINE ClientDialDevice::DialState:: |
| 12 | +DialState() : |
| 13 | + _offset(0.0), |
| 14 | + _known(false) |
| 15 | +{ |
| 16 | +} |
| 17 | + |
| 18 | +//////////////////////////////////////////////////////////////////// |
| 19 | +// Function: ClientDialDevice::Constructor |
| 20 | +// Access: Protected |
| 21 | +// Description: |
| 22 | +//////////////////////////////////////////////////////////////////// |
| 23 | +INLINE ClientDialDevice:: |
| 24 | +ClientDialDevice(ClientBase *client, const string &device_name): |
| 25 | + ClientDevice(client, get_class_type(), device_name) |
| 26 | +{ |
| 27 | +} |
| 28 | + |
| 29 | +//////////////////////////////////////////////////////////////////// |
| 30 | +// Function: ClientDialDevice::get_num_dials |
| 31 | +// Access: Public |
| 32 | +// Description: Returns the number of dial dials known to the |
| 33 | +// ClientDialDevice. This number may change as |
| 34 | +// more dials are discovered. |
| 35 | +//////////////////////////////////////////////////////////////////// |
| 36 | +INLINE int ClientDialDevice:: |
| 37 | +get_num_dials() const { |
| 38 | + return _dials.size(); |
| 39 | +} |
| 40 | + |
| 41 | +//////////////////////////////////////////////////////////////////// |
| 42 | +// Function: ClientDialDevice::push_dial |
| 43 | +// Access: Public |
| 44 | +// Description: Marks that the dial has been offset by the indicated |
| 45 | +// amount. It is the user's responsibility to ensure |
| 46 | +// that this call is protected within lock(). |
| 47 | +//////////////////////////////////////////////////////////////////// |
| 48 | +INLINE void ClientDialDevice:: |
| 49 | +push_dial(int index, double offset) { |
| 50 | + ensure_dial_index(index); |
| 51 | + nassertv(index >= 0 && index < (int)_dials.size()); |
| 52 | + _dials[index]._offset += offset; |
| 53 | + _dials[index]._known = true; |
| 54 | +} |
| 55 | + |
| 56 | +//////////////////////////////////////////////////////////////////// |
| 57 | +// Function: ClientDialDevice::read_dial |
| 58 | +// Access: Public |
| 59 | +// Description: Returns the number of complete revolutions of the |
| 60 | +// dial since the last time read_dial() was called. |
| 61 | +// This is a destructive operation; it is not possible |
| 62 | +// to read the dial without resetting the counter. |
| 63 | +// |
| 64 | +// It is the user's responsibility to ensure that this |
| 65 | +// call is protected within lock(). |
| 66 | +//////////////////////////////////////////////////////////////////// |
| 67 | +INLINE double ClientDialDevice:: |
| 68 | +read_dial(int index) { |
| 69 | + if (index >= 0 && index < (int)_dials.size()) { |
| 70 | + double result = _dials[index]._offset; |
| 71 | + _dials[index]._offset = 0.0; |
| 72 | + return result; |
| 73 | + } else { |
| 74 | + return 0.0; |
| 75 | + } |
| 76 | +} |
| 77 | + |
| 78 | +//////////////////////////////////////////////////////////////////// |
| 79 | +// Function: ClientDialDevice::is_dial_known |
| 80 | +// Access: Public |
| 81 | +// Description: Returns true if the state of the indicated dial |
| 82 | +// dial is known, or false if we have never heard |
| 83 | +// anything about this particular dial. |
| 84 | +//////////////////////////////////////////////////////////////////// |
| 85 | +INLINE bool ClientDialDevice:: |
| 86 | +is_dial_known(int index) const { |
| 87 | + if (index >= 0 && index < (int)_dials.size()) { |
| 88 | + return _dials[index]._known; |
| 89 | + } else { |
| 90 | + return false; |
| 91 | + } |
| 92 | +} |
0 commit comments