diff --git a/panda/src/device/inputDevice.I b/panda/src/device/inputDevice.I index aa8e069955..fc5236594c 100644 --- a/panda/src/device/inputDevice.I +++ b/panda/src/device/inputDevice.I @@ -250,13 +250,8 @@ is_button_known(size_t index) const { */ INLINE InputDevice::ButtonState InputDevice:: get_button(size_t index) const { - if (index < _buttons.size()) { - return _buttons[index]; - } else { - device_cat.error() - << "Index " << index << " was not found in the axes list\n"; - return ButtonState(); - } + nassertr_always(index < _buttons.size(), ButtonState()); + return _buttons[index]; } /** @@ -270,8 +265,6 @@ find_button(ButtonHandle handle) const { return _buttons[i]; } } - device_cat.error() - << "Handle " << handle.get_name() << " was not found in the axes list\n"; return ButtonState(); } @@ -321,13 +314,8 @@ get_axis_value(size_t index) const { */ INLINE InputDevice::AxisState InputDevice:: get_axis(size_t index) const { - if (index < _axes.size()) { - return _axes[index]; - } else { - device_cat.error() - << "Index " << index << " was not found in the axes list\n"; - return AxisState(); - } + nassertr_always(index < _axes.size(), AxisState()); + return _axes[index]; } /** @@ -341,8 +329,6 @@ find_axis(InputDevice::Axis axis) const { return _axes[i]; } } - device_cat.error() - << "Axis " << axis << " was not found in the axes list\n"; return AxisState(); } diff --git a/panda/src/device/inputDevice.h b/panda/src/device/inputDevice.h index 0088ea8f86..25bcfea9c0 100644 --- a/panda/src/device/inputDevice.h +++ b/panda/src/device/inputDevice.h @@ -142,6 +142,8 @@ PUBLISHED: ALWAYS_INLINE bool is_pressed() const; PUBLISHED: + operator bool() { return _state != S_unknown; } + MAKE_PROPERTY(known, is_known); MAKE_PROPERTY(pressed, is_pressed); @@ -156,6 +158,8 @@ PUBLISHED: constexpr AxisState() = default; PUBLISHED: + operator bool() { return known && value != 0.0; } + Axis axis = Axis::none; double value = 0.0; bool known = false; @@ -268,6 +272,8 @@ PUBLISHED: PT(PointerEventList) get_pointer_events(); virtual void output(std::ostream &out) const; + +public: static std::string format_device_class(DeviceClass dc); static std::string format_axis(Axis axis);