private void ProcessAnEvent(ref SDL_Event ev) { int id; switch (ev.type) { case SDL_EventType.ControllerDeviceAdded: UpdateGamepadRegister(); _applicationMessenger.QueueMessage(FrameworkMessage.GamepadAdded); break; case SDL_EventType.ControllerDeviceRemoved: UpdateGamepadRegister(); _applicationMessenger.QueueMessage(FrameworkMessage.GamepadRemoved); break; case SDL_EventType.ControllerDeviceRemapped: //Unsure if am required to process this event. For future investigation break; case SDL_EventType.ControllerButtonUp: case SDL_EventType.ControllerButtonDown: SDL_ControllerButtonEvent buttonEvent = Unsafe.As <SDL_Event, SDL_ControllerButtonEvent>(ref ev); id = buttonEvent.which; if (_controllers.ContainsKey(id)) { var controller = _controllers[id]; var button = ToGamepadButton(buttonEvent.button); var pressed = buttonEvent.state == 1; //SDL_PRESSED and SDL_RELEASED don't appear to exist controller.ProcessButtonEvent(button, pressed); } break; case SDL_EventType.ControllerAxisMotion: SDL_ControllerAxisEvent axisEvent = Unsafe.As <SDL_Event, SDL_ControllerAxisEvent>(ref ev); id = axisEvent.which; if (_controllers.ContainsKey(id)) { var controller = _controllers[id]; var axis = ToGamepadAxis(axisEvent.axis); var value = NormalizeAxis(axisEvent.value); controller.ProcessAxisEvent(axis, value); } break; } }
private void ProcessEvent(ref SDL_Event ev) { switch (ev.type) { case SDL_EventType.ControllerDeviceAdded: case SDL_EventType.ControllerDeviceRemoved: case SDL_EventType.ControllerDeviceRemapped: case SDL_EventType.ControllerButtonUp: case SDL_EventType.ControllerButtonDown: case SDL_EventType.ControllerAxisMotion: _inputGameController.CacheEvent(ref ev); break; //Currently Veldrid Snapshot is used for all events. //However here is an attempt to faster sample mouse position case SDL_EventType.MouseMotion: _inputMouseAndKeyboard.CacheEvent(ref ev); break; case SDL_EventType.Quit: case SDL_EventType.Terminating: _coreMessenger.QueueMessage(CoreMessage.Shutdown); break; case SDL_EventType.LowMemory: _applicationMessenger.QueueMessage(FrameworkMessage.LowMemoryReported); break; case SDL_EventType.RenderDeviceReset: case SDL_EventType.RenderTargetsReset: _coreMessenger.QueueMessage(CoreMessage.DeviceOrRenderTargetsReset); break; } }