device: a few InputDevice API tweaks

find_button() and find_axis() should not error since there is no way to find out whether a button/axis exists or not
This commit is contained in:
rdb 2018-11-30 19:52:26 +01:00
parent 2087d8ee84
commit 29170278e9
2 changed files with 10 additions and 18 deletions

View File

@ -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();
}

View File

@ -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);