public void RemoveStateChangeMonitor(InputControl control, IInputStateChangeMonitor monitor, long monitorIndex) { if (m_StateChangeMonitors == null) { return; } var device = control.device; var deviceIndex = device.m_DeviceIndex; // Ignore if device has already been removed. if (deviceIndex == InputDevice.kInvalidDeviceIndex) { return; } // Ignore if there are no state monitors set up for the device. if (deviceIndex >= m_StateChangeMonitors.Length) { return; } m_StateChangeMonitors[deviceIndex].Remove(monitor, monitorIndex, isProcessingEvents); // Remove pending timeouts on the monitor. for (var i = 0; i < m_StateChangeMonitorTimeouts.length; ++i) { if (m_StateChangeMonitorTimeouts[i].monitor == monitor && m_StateChangeMonitorTimeouts[i].monitorIndex == monitorIndex) { m_StateChangeMonitorTimeouts[i] = default; } } }
////TODO: support combining monitors for bitfields public void AddStateChangeMonitor(InputControl control, IInputStateChangeMonitor monitor, long monitorIndex, uint groupIndex) { Debug.Assert(m_DevicesCount > 0); var device = control.device; var deviceIndex = device.m_DeviceIndex; Debug.Assert(deviceIndex != InputDevice.kInvalidDeviceIndex); // Allocate/reallocate monitor arrays, if necessary. // We lazy-sync it to array of devices. if (m_StateChangeMonitors == null) { m_StateChangeMonitors = new StateChangeMonitorsForDevice[m_DevicesCount]; } else if (m_StateChangeMonitors.Length <= deviceIndex) { Array.Resize(ref m_StateChangeMonitors, m_DevicesCount); } // If we have removed monitors if (!isProcessingEvents && m_StateChangeMonitors[deviceIndex].needToCompactArrays) { m_StateChangeMonitors[deviceIndex].CompactArrays(); } // Add record. m_StateChangeMonitors[deviceIndex].Add(control, monitor, monitorIndex, groupIndex); }
public void AddStateChangeMonitorTimeout(InputControl control, IInputStateChangeMonitor monitor, double time, long monitorIndex, int timerIndex) { m_StateChangeMonitorTimeouts.Append( new StateChangeMonitorTimeout { control = control, time = time, monitor = monitor, monitorIndex = monitorIndex, timerIndex = timerIndex, }); }
public void RemoveStateChangeMonitorTimeout(IInputStateChangeMonitor monitor, long monitorIndex, int timerIndex) { var timeoutCount = m_StateChangeMonitorTimeouts.length; for (var i = 0; i < timeoutCount; ++i) { ////REVIEW: can we avoid the repeated array lookups without copying the struct out? if (ReferenceEquals(m_StateChangeMonitorTimeouts[i].monitor, monitor) && m_StateChangeMonitorTimeouts[i].monitorIndex == monitorIndex && m_StateChangeMonitorTimeouts[i].timerIndex == timerIndex) { m_StateChangeMonitorTimeouts[i] = default; break; } } }
public void State_StateChangeMonitorTimeout_CanBeAddedFromMonitorCallback() { var gamepad = InputSystem.AddDevice <Gamepad>(); var monitorFired = false; var timeoutFired = false; IInputStateChangeMonitor monitor = null; monitor = InputSystem.AddStateChangeMonitor(gamepad.leftStick, (control, time, eventPtr, monitorIndex) => { Assert.That(!monitorFired); monitorFired = true; InputSystem.AddStateChangeMonitorTimeout(gamepad.leftStick, monitor, runtime.currentTime + 1); }, timerExpiredCallback: (control, time, monitorIndex, timerIndex) => { Assert.That(!timeoutFired); timeoutFired = true; }); // Trigger monitor callback. InputSystem.QueueStateEvent(gamepad, new GamepadState { leftStick = Vector2.one }); InputSystem.Update(); Assert.That(monitorFired); // Expire timer. runtime.currentTime += 2; InputSystem.Update(); Assert.That(timeoutFired); }
public void SignalStateChangeMonitor(InputControl control, IInputStateChangeMonitor monitor) { var device = control.device; var deviceIndex = device.m_DeviceIndex; ref var monitorsForDevice = ref m_StateChangeMonitors[deviceIndex];