public void Events_CanClearEventTrace() { using (var trace = new InputEventTrace()) { trace.Enable(); var device = InputSystem.AddDevice <Gamepad>(); InputSystem.QueueStateEvent(device, new GamepadState()); InputSystem.QueueStateEvent(device, new GamepadState()); InputSystem.Update(); Assert.That(trace.ToList(), Has.Count.EqualTo(2)); trace.Clear(); Assert.That(trace.ToList(), Has.Count.EqualTo(0)); } }
public unsafe void Events_CanTraceEventsOfDevice() { InputSystem.settings.timesliceEvents = false; var device = InputSystem.AddDevice <Gamepad>(); var noise = InputSystem.AddDevice <Gamepad>(); using (var trace = new InputEventTrace { deviceId = device.id }) { trace.Enable(); Assert.That(trace.enabled, Is.True); var firstState = new GamepadState { rightTrigger = 0.35f }; var secondState = new GamepadState { leftTrigger = 0.75f }; InputSystem.QueueStateEvent(device, firstState, 0.5); InputSystem.QueueStateEvent(device, secondState, 1.5); InputSystem.QueueStateEvent(noise, new GamepadState()); // This one just to make sure we don't get it. InputSystem.Update(); trace.Disable(); var events = trace.ToList(); Assert.That(events, Has.Count.EqualTo(2)); Assert.That(events[0].type, Is.EqualTo((FourCC)StateEvent.Type)); Assert.That(events[0].deviceId, Is.EqualTo(device.id)); Assert.That(events[0].time, Is.EqualTo(0.5).Within(0.000001)); Assert.That(events[0].sizeInBytes, Is.EqualTo(StateEvent.GetEventSizeWithPayload <GamepadState>())); Assert.That(UnsafeUtility.MemCmp(UnsafeUtility.AddressOf(ref firstState), StateEvent.From(events[0])->state, UnsafeUtility.SizeOf <GamepadState>()), Is.Zero); Assert.That(events[1].type, Is.EqualTo((FourCC)StateEvent.Type)); Assert.That(events[1].deviceId, Is.EqualTo(device.id)); Assert.That(events[1].time, Is.EqualTo(1.5).Within(0.000001)); Assert.That(events[1].sizeInBytes, Is.EqualTo(StateEvent.GetEventSizeWithPayload <GamepadState>())); Assert.That(UnsafeUtility.MemCmp(UnsafeUtility.AddressOf(ref secondState), StateEvent.From(events[1])->state, UnsafeUtility.SizeOf <GamepadState>()), Is.Zero); } }
public void Events_WhenTraceIsFull_WillStartOverwritingOldEvents() { InputSystem.settings.timesliceEvents = false; var device = InputSystem.AddDevice <Gamepad>(); using (var trace = new InputEventTrace(StateEvent.GetEventSizeWithPayload <GamepadState>() * 2) { deviceId = device.id }) { trace.Enable(); var firstState = new GamepadState { rightTrigger = 0.35f }; var secondState = new GamepadState { leftTrigger = 0.75f }; var thirdState = new GamepadState { leftTrigger = 0.95f }; InputSystem.QueueStateEvent(device, firstState, 0.5); InputSystem.QueueStateEvent(device, secondState, 1.5); InputSystem.QueueStateEvent(device, thirdState, 2.5); InputSystem.Update(); trace.Disable(); var events = trace.ToList(); Assert.That(events, Has.Count.EqualTo(2)); Assert.That(events, Has.Exactly(1).With.Property("time").EqualTo(1.5).Within(0.000001)); Assert.That(events, Has.Exactly(1).With.Property("time").EqualTo(2.5).Within(0.000001)); } }