00001 // Filename: clientDialDevice.I 00002 // Created by: drose (26Jan01) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved 00008 // 00009 // All use of this software is subject to the terms of the Panda 3d 00010 // Software license. You should have received a copy of this license 00011 // along with this source code; you will also find a current copy of 00012 // the license at http://www.panda3d.org/license.txt . 00013 // 00014 // To contact the maintainers of this program write to 00015 // panda3d@yahoogroups.com . 00016 // 00017 //////////////////////////////////////////////////////////////////// 00018 00019 //////////////////////////////////////////////////////////////////// 00020 // Function: ClientDialDevice::DialState::Constructor 00021 // Access: Public 00022 // Description: 00023 //////////////////////////////////////////////////////////////////// 00024 INLINE ClientDialDevice::DialState:: 00025 DialState() : 00026 _offset(0.0), 00027 _known(false) 00028 { 00029 } 00030 00031 //////////////////////////////////////////////////////////////////// 00032 // Function: ClientDialDevice::Constructor 00033 // Access: Protected 00034 // Description: 00035 //////////////////////////////////////////////////////////////////// 00036 INLINE ClientDialDevice:: 00037 ClientDialDevice(ClientBase *client, const string &device_name): 00038 ClientDevice(client, get_class_type(), device_name) 00039 { 00040 } 00041 00042 //////////////////////////////////////////////////////////////////// 00043 // Function: ClientDialDevice::get_num_dials 00044 // Access: Public 00045 // Description: Returns the number of dial dials known to the 00046 // ClientDialDevice. This number may change as 00047 // more dials are discovered. 00048 //////////////////////////////////////////////////////////////////// 00049 INLINE int ClientDialDevice:: 00050 get_num_dials() const { 00051 return _dials.size(); 00052 } 00053 00054 //////////////////////////////////////////////////////////////////// 00055 // Function: ClientDialDevice::push_dial 00056 // Access: Public 00057 // Description: Marks that the dial has been offset by the indicated 00058 // amount. It is the user's responsibility to ensure 00059 // that this call is protected within lock(). 00060 //////////////////////////////////////////////////////////////////// 00061 INLINE void ClientDialDevice:: 00062 push_dial(int index, double offset) { 00063 ensure_dial_index(index); 00064 nassertv(index >= 0 && index < (int)_dials.size()); 00065 _dials[index]._offset += offset; 00066 _dials[index]._known = true; 00067 } 00068 00069 //////////////////////////////////////////////////////////////////// 00070 // Function: ClientDialDevice::read_dial 00071 // Access: Public 00072 // Description: Returns the number of complete revolutions of the 00073 // dial since the last time read_dial() was called. 00074 // This is a destructive operation; it is not possible 00075 // to read the dial without resetting the counter. 00076 // 00077 // It is the user's responsibility to ensure that this 00078 // call is protected within lock(). 00079 //////////////////////////////////////////////////////////////////// 00080 INLINE double ClientDialDevice:: 00081 read_dial(int index) { 00082 if (index >= 0 && index < (int)_dials.size()) { 00083 double result = _dials[index]._offset; 00084 _dials[index]._offset = 0.0; 00085 return result; 00086 } else { 00087 return 0.0; 00088 } 00089 } 00090 00091 //////////////////////////////////////////////////////////////////// 00092 // Function: ClientDialDevice::is_dial_known 00093 // Access: Public 00094 // Description: Returns true if the state of the indicated dial 00095 // dial is known, or false if we have never heard 00096 // anything about this particular dial. 00097 //////////////////////////////////////////////////////////////////// 00098 INLINE bool ClientDialDevice:: 00099 is_dial_known(int index) const { 00100 if (index >= 0 && index < (int)_dials.size()) { 00101 return _dials[index]._known; 00102 } else { 00103 return false; 00104 } 00105 }