More work on integrating new input framework
This commit is contained in:
parent
d3008c56e0
commit
fa7f385bb8
|
|
@ -346,8 +346,16 @@ init_device() {
|
|||
int bi = 0;
|
||||
for (int i = 0; i < KEY_CNT; ++i) {
|
||||
if (test_bit(i, keys)) {
|
||||
set_button_map(bi, map_button(i));
|
||||
//cerr << "Button " << bi << " is mapped by the driver to " << i << "\n";
|
||||
ButtonHandle mapped = map_button(i);
|
||||
set_button_map(bi, mapped);
|
||||
|
||||
if (mapped == ButtonHandle::none()) {
|
||||
if (device_cat.is_debug()) {
|
||||
device_cat.debug() << "Unmapped /dev/input/event" << _index
|
||||
<< " button " << bi << ": 0x" << hex << i << dec << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
if (test_bit(i, states)) {
|
||||
_buttons[bi].state = S_down;
|
||||
all_values_zero = false;
|
||||
|
|
@ -735,6 +743,9 @@ map_button(int code) {
|
|||
}
|
||||
|
||||
switch (code) {
|
||||
case BTN_TRIGGER:
|
||||
return GamepadButton::trigger();
|
||||
|
||||
case BTN_A:
|
||||
return GamepadButton::action_a();
|
||||
|
||||
|
|
|
|||
|
|
@ -175,7 +175,7 @@ get_max_battery_level() const {
|
|||
* associated with a ButtonHandle even if their state is unknown. This number
|
||||
* may change as more buttons are discovered.
|
||||
*/
|
||||
INLINE int InputDevice::
|
||||
INLINE size_t InputDevice::
|
||||
get_num_buttons() const {
|
||||
LightMutexHolder holder(_lock);
|
||||
return _buttons.size();
|
||||
|
|
@ -192,10 +192,9 @@ get_num_buttons() const {
|
|||
* generate ButtonEvents when the buttons change state.
|
||||
*/
|
||||
INLINE void InputDevice::
|
||||
set_button_map(int index, ButtonHandle button) {
|
||||
set_button_map(size_t index, ButtonHandle button) {
|
||||
LightMutexHolder holder(_lock);
|
||||
nassertv(index >= 0);
|
||||
if (index >= (int)_buttons.size()) {
|
||||
if (index >= _buttons.size()) {
|
||||
_buttons.resize(index + 1, ButtonState());
|
||||
}
|
||||
|
||||
|
|
@ -208,8 +207,8 @@ set_button_map(int index, ButtonHandle button) {
|
|||
* was associated.
|
||||
*/
|
||||
INLINE ButtonHandle InputDevice::
|
||||
get_button_map(int index) const {
|
||||
if (index >= 0 && index < (int)_buttons.size()) {
|
||||
get_button_map(size_t index) const {
|
||||
if (index < _buttons.size()) {
|
||||
return _buttons[index].handle;
|
||||
} else {
|
||||
return ButtonHandle::none();
|
||||
|
|
@ -221,8 +220,8 @@ get_button_map(int index) const {
|
|||
* currently known to be down, or false if it is up or unknown.
|
||||
*/
|
||||
INLINE bool InputDevice::
|
||||
get_button_state(int index) const {
|
||||
if (index >= 0 && index < (int)_buttons.size()) {
|
||||
get_button_state(size_t index) const {
|
||||
if (index < _buttons.size()) {
|
||||
return (_buttons[index].state == S_down);
|
||||
} else {
|
||||
return false;
|
||||
|
|
@ -234,8 +233,8 @@ get_button_state(int index) const {
|
|||
* have never heard anything about this particular button.
|
||||
*/
|
||||
INLINE bool InputDevice::
|
||||
is_button_known(int index) const {
|
||||
if (index >= 0 && index < (int)_buttons.size()) {
|
||||
is_button_known(size_t index) const {
|
||||
if (index < _buttons.size()) {
|
||||
return _buttons[index].state != S_unknown;
|
||||
} else {
|
||||
return false;
|
||||
|
|
@ -248,12 +247,12 @@ is_button_known(int index) const {
|
|||
*/
|
||||
INLINE InputDevice::ButtonState InputDevice::
|
||||
get_button(size_t index) const {
|
||||
if (index >= 0 && index < (int)_buttons.size()) {
|
||||
if (index < _buttons.size()) {
|
||||
return _buttons[index];
|
||||
} else {
|
||||
device_cat.error()
|
||||
<< "Index " << index<< " was not found in the controls list\n";
|
||||
nassertr(false, ButtonState());
|
||||
<< "Index " << index << " was not found in the controls list\n";
|
||||
return ButtonState();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -263,21 +262,21 @@ get_button(size_t index) const {
|
|||
*/
|
||||
INLINE InputDevice::ButtonState InputDevice::
|
||||
find_button(ButtonHandle handle) const {
|
||||
for (int i; i < (int)_buttons.size(); i++) {
|
||||
for (size_t i = 0; i < _buttons.size(); ++i) {
|
||||
if (_buttons[i].handle == handle) {
|
||||
return _buttons[i];
|
||||
}
|
||||
}
|
||||
device_cat.error()
|
||||
<< "Handle " << handle.get_name() << " was not found in the controls list\n";
|
||||
nassertr(false, ButtonState());
|
||||
return ButtonState();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of analog controls known to the InputDevice. This number
|
||||
* may change as more controls are discovered.
|
||||
*/
|
||||
INLINE int InputDevice::
|
||||
INLINE size_t InputDevice::
|
||||
get_num_controls() const {
|
||||
return _controls.size();
|
||||
}
|
||||
|
|
@ -290,10 +289,9 @@ get_num_controls() const {
|
|||
* the various controls by index number.
|
||||
*/
|
||||
INLINE void InputDevice::
|
||||
set_control_map(int index, InputDevice::ControlAxis axis) {
|
||||
set_control_map(size_t index, InputDevice::ControlAxis axis) {
|
||||
LightMutexHolder holder(_lock);
|
||||
nassertv(index >= 0);
|
||||
if (index >= (int)_controls.size()) {
|
||||
if (index >= _controls.size()) {
|
||||
_controls.resize(index + 1, AnalogState());
|
||||
}
|
||||
|
||||
|
|
@ -306,8 +304,8 @@ set_control_map(int index, InputDevice::ControlAxis axis) {
|
|||
* associated.
|
||||
*/
|
||||
INLINE InputDevice::ControlAxis InputDevice::
|
||||
get_control_map(int index) const {
|
||||
if (index >= 0 && index < (int)_controls.size()) {
|
||||
get_control_map(size_t index) const {
|
||||
if (index < _controls.size()) {
|
||||
return _controls[index].axis;
|
||||
} else {
|
||||
return C_none;
|
||||
|
|
@ -320,8 +318,8 @@ get_control_map(int index) const {
|
|||
* single control is -1.0 to 1.0.
|
||||
*/
|
||||
INLINE double InputDevice::
|
||||
get_control_state(int index) const {
|
||||
if (index >= 0 && index < (int)_controls.size()) {
|
||||
get_control_state(size_t index) const {
|
||||
if (index < _controls.size()) {
|
||||
return _controls[index].state;
|
||||
} else {
|
||||
return 0.0;
|
||||
|
|
@ -334,12 +332,12 @@ get_control_state(int index) const {
|
|||
*/
|
||||
INLINE InputDevice::AnalogState InputDevice::
|
||||
get_control(size_t index) const {
|
||||
if (index >= 0 && index < (int)_controls.size()) {
|
||||
if (index < _controls.size()) {
|
||||
return _controls[index];
|
||||
} else {
|
||||
device_cat.error()
|
||||
<< "Index " << index<< " was not found in the controls list\n";
|
||||
nassertr(false, AnalogState());
|
||||
return AnalogState();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -349,14 +347,14 @@ get_control(size_t index) const {
|
|||
*/
|
||||
INLINE InputDevice::AnalogState InputDevice::
|
||||
find_control(InputDevice::ControlAxis axis) const {
|
||||
for (int i; i < (int)_controls.size(); i++) {
|
||||
for (size_t i = 0; i < _controls.size(); ++i) {
|
||||
if (_controls[i].axis == axis) {
|
||||
return _controls[i];
|
||||
}
|
||||
}
|
||||
device_cat.error()
|
||||
<< "Axis " << axis << " was not found in the controls list\n";
|
||||
nassertr(false, AnalogState());
|
||||
return AnalogState();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -364,8 +362,8 @@ find_control(InputDevice::ControlAxis axis) const {
|
|||
* if we have never heard anything about this particular control.
|
||||
*/
|
||||
INLINE bool InputDevice::
|
||||
is_control_known(int index) const {
|
||||
if (index >= 0 && index < (int)_controls.size()) {
|
||||
is_control_known(size_t index) const {
|
||||
if (index < _controls.size()) {
|
||||
return _controls[index].known;
|
||||
} else {
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -212,8 +212,8 @@ set_control_state(int index, double state) {
|
|||
device_cat.spam()
|
||||
<< "Changed control " << index;
|
||||
|
||||
if (_controls[index].known != C_none) {
|
||||
device_cat.spam(false) << " (" << _controls[index].known << ")";
|
||||
if (_controls[index].axis != C_none) {
|
||||
device_cat.spam(false) << " (" << _controls[index].axis << ")";
|
||||
}
|
||||
|
||||
device_cat.spam(false) << " to " << state << "\n";
|
||||
|
|
@ -438,6 +438,14 @@ operator << (ostream &out, InputDevice::DeviceClass dc) {
|
|||
case InputDevice::DC_steering_wheel:
|
||||
out << "steering_wheel";
|
||||
break;
|
||||
|
||||
case InputDevice::DC_dance_pad:
|
||||
out << "dance_pad";
|
||||
break;
|
||||
|
||||
case InputDevice::DC_hmd:
|
||||
out << "hmd";
|
||||
break;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
|
@ -488,6 +496,30 @@ operator << (ostream &out, InputDevice::ControlAxis axis) {
|
|||
case InputDevice::C_throttle:
|
||||
out << "throttle";
|
||||
break;
|
||||
|
||||
case InputDevice::C_rudder:
|
||||
out << "rudder";
|
||||
break;
|
||||
|
||||
case InputDevice::C_hat_x:
|
||||
out << "hat_x";
|
||||
break;
|
||||
|
||||
case InputDevice::C_hat_y:
|
||||
out << "hat_y";
|
||||
break;
|
||||
|
||||
case InputDevice::C_wheel:
|
||||
out << "wheel";
|
||||
break;
|
||||
|
||||
case InputDevice::C_accelerator:
|
||||
out << "accelerator";
|
||||
break;
|
||||
|
||||
case InputDevice::C_brake:
|
||||
out << "brake";
|
||||
break;
|
||||
}
|
||||
|
||||
return out;
|
||||
|
|
|
|||
|
|
@ -156,17 +156,17 @@ PUBLISHED:
|
|||
INLINE short get_battery_level() const;
|
||||
INLINE short get_max_battery_level() const;
|
||||
|
||||
INLINE int get_num_buttons() const;
|
||||
INLINE void set_button_map(int index, ButtonHandle button);
|
||||
INLINE ButtonHandle get_button_map(int index) const;
|
||||
INLINE bool get_button_state(int index) const;
|
||||
INLINE bool is_button_known(int index) const;
|
||||
INLINE size_t get_num_buttons() const;
|
||||
INLINE void set_button_map(size_t index, ButtonHandle button);
|
||||
INLINE ButtonHandle get_button_map(size_t index) const;
|
||||
INLINE bool get_button_state(size_t index) const;
|
||||
INLINE bool is_button_known(size_t index) const;
|
||||
|
||||
INLINE int get_num_controls() const;
|
||||
INLINE void set_control_map(int index, ControlAxis axis);
|
||||
INLINE ControlAxis get_control_map(int index) const;
|
||||
INLINE double get_control_state(int index) const;
|
||||
INLINE bool is_control_known(int index) const;
|
||||
INLINE size_t get_num_controls() const;
|
||||
INLINE void set_control_map(size_t index, ControlAxis axis);
|
||||
INLINE ControlAxis get_control_map(size_t index) const;
|
||||
INLINE double get_control_state(size_t index) const;
|
||||
INLINE bool is_control_known(size_t index) const;
|
||||
|
||||
INLINE void set_vibration(double strong, double weak);
|
||||
|
||||
|
|
|
|||
|
|
@ -690,11 +690,6 @@ add_input_device(InputDevice *device) {
|
|||
LightMutexHolder holder(_input_lock);
|
||||
int index = (int)_input_devices.size();
|
||||
_input_devices.push_back(device);
|
||||
|
||||
if (device->is_of_type(GraphicsWindowInputDevice::get_class_type())) {
|
||||
((GraphicsWindowInputDevice *)device)->set_device_index(index);
|
||||
}
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,17 +15,7 @@
|
|||
*
|
||||
*/
|
||||
INLINE GraphicsWindowInputDevice::
|
||||
GraphicsWindowInputDevice() : _host(NULL) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the device index. This is reported in pointer events. The device
|
||||
* index will be equal to the position of the GraphicsWindowInputDevice in the
|
||||
* window's list.
|
||||
*/
|
||||
INLINE void GraphicsWindowInputDevice::
|
||||
set_device_index(int index) {
|
||||
_device_index = index;
|
||||
GraphicsWindowInputDevice() {
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@ TypeHandle GraphicsWindowInputDevice::_type_handle;
|
|||
*/
|
||||
GraphicsWindowInputDevice::
|
||||
GraphicsWindowInputDevice(GraphicsWindow *host, const string &name, int flags) :
|
||||
InputDevice(name, DC_virtual, flags),
|
||||
_host(host)
|
||||
InputDevice(name, DC_virtual, flags)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -74,7 +73,6 @@ GraphicsWindowInputDevice(const GraphicsWindowInputDevice ©) {
|
|||
*/
|
||||
void GraphicsWindowInputDevice::
|
||||
operator = (const GraphicsWindowInputDevice ©) {
|
||||
_host = copy._host;
|
||||
InputDevice::operator = (copy);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -39,8 +39,6 @@ public:
|
|||
void operator = (const GraphicsWindowInputDevice ©);
|
||||
~GraphicsWindowInputDevice();
|
||||
|
||||
INLINE void set_device_index(int index);
|
||||
|
||||
PUBLISHED:
|
||||
// The following interface is for the various kinds of GraphicsWindows to
|
||||
// record the data incoming on the device.
|
||||
|
|
@ -61,9 +59,6 @@ PUBLISHED:
|
|||
INLINE void set_pointer_out_of_window(double time = ClockObject::get_global_clock()->get_frame_time());
|
||||
|
||||
private:
|
||||
GraphicsWindow *_host;
|
||||
int _device_index;
|
||||
|
||||
typedef pset<ButtonHandle> ButtonsHeld;
|
||||
ButtonsHeld _buttons_held;
|
||||
|
||||
|
|
|
|||
|
|
@ -55,44 +55,6 @@ eglGraphicsWindow::
|
|||
~eglGraphicsWindow() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Forces the pointer to the indicated position within the window, if
|
||||
* possible.
|
||||
*
|
||||
* Returns true if successful, false on failure. This may fail if the mouse
|
||||
* is not currently within the window, or if the API doesn't support this
|
||||
* operation.
|
||||
*/
|
||||
bool eglGraphicsWindow::
|
||||
move_pointer(int device, int x, int y) {
|
||||
// Note: this is not thread-safe; it should be called only from App.
|
||||
// Probably not an issue.
|
||||
if (device == 0) {
|
||||
// Move the system mouse pointer.
|
||||
if (!_properties.get_foreground() ||
|
||||
!_input_devices[0].get_pointer().get_in_window()) {
|
||||
// If the window doesn't have input focus, or the mouse isn't currently
|
||||
// within the window, forget it.
|
||||
return false;
|
||||
}
|
||||
|
||||
const MouseData &md = _input_devices[0].get_pointer();
|
||||
if (!md.get_in_window() || md.get_x() != x || md.get_y() != y) {
|
||||
XWarpPointer(_display, None, _xwindow, 0, 0, 0, 0, x, y);
|
||||
_input_devices[0].set_pointer_in_window(x, y);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
// Move a raw mouse.
|
||||
if ((device < 1)||(device >= _input_devices.size())) {
|
||||
return false;
|
||||
}
|
||||
_input_devices[device].set_pointer_in_window(x, y);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This function will be called within the draw thread before beginning
|
||||
* rendering for a given frame. It should do whatever setup is required, and
|
||||
|
|
|
|||
|
|
@ -33,7 +33,6 @@ public:
|
|||
GraphicsOutput *host);
|
||||
virtual ~eglGraphicsWindow();
|
||||
|
||||
virtual bool move_pointer(int device, int x, int y);
|
||||
virtual bool begin_frame(FrameMode mode, Thread *current_thread);
|
||||
virtual void end_frame(FrameMode mode, Thread *current_thread);
|
||||
virtual void end_flip();
|
||||
|
|
|
|||
|
|
@ -47,6 +47,8 @@ DEFINE_GAMEPAD_BUTTON_HANDLE(action_z)
|
|||
DEFINE_GAMEPAD_BUTTON_HANDLE(action_1)
|
||||
DEFINE_GAMEPAD_BUTTON_HANDLE(action_2)
|
||||
|
||||
DEFINE_GAMEPAD_BUTTON_HANDLE(trigger)
|
||||
|
||||
/**
|
||||
* This is intended to be called only once, by the static initialization
|
||||
* performed in config_util.cxx.
|
||||
|
|
@ -81,4 +83,6 @@ init_gamepad_buttons() {
|
|||
|
||||
ButtonRegistry::ptr()->register_button(_action_1, "action_1");
|
||||
ButtonRegistry::ptr()->register_button(_action_2, "action_2");
|
||||
|
||||
ButtonRegistry::ptr()->register_button(_trigger, "trigger");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,6 +53,8 @@ PUBLISHED:
|
|||
static ButtonHandle action_1();
|
||||
static ButtonHandle action_2();
|
||||
|
||||
static ButtonHandle trigger();
|
||||
|
||||
public:
|
||||
static void init_gamepad_buttons();
|
||||
};
|
||||
|
|
|
|||
|
|
@ -131,14 +131,13 @@ move_pointer(int device, int x, int y) {
|
|||
// Probably not an issue.
|
||||
if (device == 0) {
|
||||
// Move the system mouse pointer.
|
||||
if (!_properties.get_foreground() ||
|
||||
!_input->get_pointer().get_in_window()) {
|
||||
PointerData md = _input->get_pointer();
|
||||
if (!_properties.get_foreground() || !md.get_in_window()) {
|
||||
// If the window doesn't have input focus, or the mouse isn't currently
|
||||
// within the window, forget it.
|
||||
return false;
|
||||
}
|
||||
|
||||
const MouseData &md = _input->get_pointer();
|
||||
if (!md.get_in_window() || md.get_x() != x || md.get_y() != y) {
|
||||
if (!_dga_mouse_enabled) {
|
||||
XWarpPointer(_display, None, _xwindow, 0, 0, 0, 0, x, y);
|
||||
|
|
@ -147,12 +146,8 @@ move_pointer(int device, int x, int y) {
|
|||
}
|
||||
return true;
|
||||
} else {
|
||||
// Move a raw mouse.
|
||||
if (device < 1 || device >= _input_devices.size()) {
|
||||
return false;
|
||||
}
|
||||
//_input_devices[device]->set_pointer_in_window(x, y);
|
||||
return true;
|
||||
// Can't move a raw mouse.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1236,6 +1231,7 @@ setup_colormap(XVisualInfo *visual) {
|
|||
|
||||
/**
|
||||
* Adds raw mice to the _input_devices list.
|
||||
* @deprecated obtain raw devices via the device manager instead.
|
||||
*/
|
||||
void x11GraphicsWindow::
|
||||
open_raw_mice() {
|
||||
|
|
|
|||
|
|
@ -102,13 +102,6 @@ protected:
|
|||
Bool _override_redirect;
|
||||
Atom _wm_delete_window;
|
||||
|
||||
struct MouseDeviceInfo {
|
||||
int _fd;
|
||||
int _input_device_index;
|
||||
string _io_buffer;
|
||||
};
|
||||
pvector<MouseDeviceInfo> _mouse_device_info;
|
||||
|
||||
public:
|
||||
static TypeHandle get_class_type() {
|
||||
return _type_handle;
|
||||
|
|
|
|||
Loading…
Reference in New Issue