/// <summary> /// Create a new base instance of an input device. The device manager /// needs to be passed in for updates. /// </summary> /// <param name="deviceManager">The device manager that owns this device.</param> /// <param name="inputPoller">The poller to check input state from.</param> /// <param name="enabled">If the control should start enabled or not.</param> protected InputDevice(IInputDeviceManager deviceManager, IInputPoller inputPoller) { DeviceManager = deviceManager; InputPoller = inputPoller; DeviceManager.OnDeviceUpdate += DeviceManager_OnUpdate; Enabled = true; }
/// <summary> /// Process the input from the input poller. /// </summary> ///<param name="inputPoller">The currnet input state checker.</param> protected override void Update(IInputPoller inputPoller) { for (int i = 0, keyHandlerCount = keyHandlers.Count; i < keyHandlerCount; i++) { keyHandlers[i].Update(inputPoller); } }
/// <summary> /// Update this handler using the input state poller /// passed in. /// </summary> /// <param name="inputPoller">The poller to check input state.</param> public void Update(IInputPoller inputPoller) { float value = 0.0f; switch (Axis) { case MouseAxis.Horizontal: value = inputPoller.GetAxis("Mouse X"); break; case MouseAxis.Vertical: value = inputPoller.GetAxis("Mouse Y"); break; case MouseAxis.ScrollWheel: value = inputPoller.GetAxis("Mouse ScrollWheel"); break; } if (value > 0.0001f || value < -0.0001f) { if (!isActive) { isActive = true; } NotifyListeners(value); } else if (isActive) { isActive = false; NotifyListeners(0.0f); } }
/// <summary> /// Create a new instance of the keyboard device. Only /// one is permitted at any time. /// </summary> /// <param name="deviceManager">The manager that owns this device.</param> /// <param name="inputPoller">The poller to check input state from.</param> public Keyboard(IInputDeviceManager deviceManager, IInputPoller inputPoller) : base(deviceManager, inputPoller) { if (instance == null) { instance = this; } else { throw new Exception("There is already a keyboard instance present. Did you call InputModule.GetDevice<Keyboard>()?"); } }
/// <summary> /// Create a new instance of the mouse device. Only one /// is permitted at any time. /// </summary> /// <param name="deviceManager">The manager that owns this device.</param> /// <param name="inputPoller">The poller to check input state from.</param> public Mouse(IInputDeviceManager deviceManager, IInputPoller inputPoller) : base(deviceManager, inputPoller) { if (instance == null) { instance = this; } else { throw new Exception("There is already a mouse instance present. Did you call InputModule.GetDevice<Mouse>()?"); } Cursor = inputPoller.Cursor; }
/// <summary> /// Process the input from the input poller. /// </summary> /// <param name="inputPoller">Checks the current input state of the engine.</param> protected override void Update(IInputPoller inputPoller) { if (buttonHandlers != null) { for (int i = 0, buttonHandlerCount = buttonHandlers.Count; i < buttonHandlerCount; i++) { buttonHandlers[i].Update(inputPoller); } } if (axisHandlers != null) { for (int i = 0, axisHandlerCount = axisHandlers.Count; i < axisHandlerCount; i++) { axisHandlers[i].Update(inputPoller); } } }
/// <summary> /// Update this handler and propogate the input for any /// of it's listeners. /// </summary> /// <param name="inputPoller">The poller to get current input.</param> public void Update(IInputPoller inputPoller) { if (downListeners != null && inputPoller.IsMouseButtonDown((int)Button)) { for (int i = 0, downCount = downListeners.Count; i < downCount; i++) { downListeners[i](Button, MouseButtonAction.Down); } } if (pressedListeners != null && inputPoller.IsMouseButtonPressed((int)Button)) { for (int i = 0, pressedCount = pressedListeners.Count; i < pressedCount; i++) { pressedListeners[i](Button, MouseButtonAction.Pressed); } } if (upListeners != null && inputPoller.IsMouseButtonUp((int)Button)) { for (int i = 0, upCount = upListeners.Count; i < upCount; i++) { upListeners[i](Button, MouseButtonAction.Up); } } }
/// <summary> /// Update this handler and propogate the input for any /// of it's listeners. /// </summary> /// <param name="inputPoller">The poller to get current input.</param> public void Update(IInputPoller inputPoller) { if (downListeners != null && inputPoller.IsButtonDown(code)) { for (int i = 0, downCount = downListeners.Count; i < downCount; i++) { downListeners[i](Key, KeyboardKeyAction.Down); } } if (pressedListeners != null && inputPoller.IsButtonPressed(code)) { for (int i = 0, pressedCount = pressedListeners.Count; i < pressedCount; i++) { pressedListeners[i](Key, KeyboardKeyAction.Pressed); } } if (upListeners != null && inputPoller.IsButtonUp(code)) { for (int i = 0, upCount = upListeners.Count; i < upCount; i++) { upListeners[i](Key, KeyboardKeyAction.Up); } } }
/// <summary> /// Update the state of the controller. /// </summary> /// <param name="inputPoller">Check current input state from.</param> protected abstract void Update(IInputPoller inputPoller);
/// <summary> /// Create a new instance of the /// </summary> /// <param name="engine">The parent engine instance.</param> public InputModule(GameEngine engine) : base(engine) { this.inputPoller = engine.GetService <IInputPoller>(); }