Skip to content

v2.0 : Hinput 2.0

Compare
Choose a tag to compare
@henriforshort henriforshort released this 12 May 14:41
· 8 commits to master since this release

This version consists of a significant amount of breaking changes to the API. Hopefully, they will make it more consistent, efficient and easy to use for you. Have a look at this guide if you need help adapting your code to the new API.

Breaking - Changes

  • Rename hinput to Hinput
    I added a capital H to better comply with C# best practices.

  • Remove the “h” prefix before the name of all classes
    hGamepad is now Gamepad, hButton is now Button and so on.

  • Add dedicated namespaces to prevent collision in class names
    This is meant to prevent collisions between user classes and Hinput classes, since they have much more common names without the "h" prefix.

    • "HinputClasses" for Gamepad, Stick, Pressable, Button, Trigger, StickDirection, StickPressedZone, Press, VibrationPreset and Settings
    • "HinputClasses.Internal" for the rest
    • The Hinput class is not part of a namespace, and can still be accessed from anywhere.
  • Change AnyGamepad and AnyInput paradigm
    I reduced consistency a bit, in favor of a much simpler and intuitive system.

    • Remove "internal" properties
    • Remove exclusive AnyGamepad, AnyInput and AnyGamepadStick properties
    • index, leftVibration and rightVibration are always -1
    • name, fullName and type are always “AnyGamepad” or “AnyInput”
    • On AnyGamepad, isEnabled, Enable and Disable only impact AnyGamepad. Same for AnyInput.
    • On AnyGamepad, isConnected returns true if at least one gamepad is connected
    • On AnyGamepad, Vibrate vibrates all gamepads
  • Rename Direction to StickDirection

  • Rename parameters from Settings for clarity

    • directionAngle is now stickType. It is an enum which values are Four Directions (previously directionAngle = 90) and Eight Directions (previously directionangle = 45)
    • rename vibrationDuration to vibrationDefaultDuration, leftVibrationIntensity to vibrationDefaultLeftIntensity and rightVibrationIntensity to vibrationDefaultRightIntensity
    • Default vibration is now VibrationPreset.Impact (left 20%, right 80% for 0.2 seconds).

Breaking - Removed features

  • Remove "internal" properties
    These properties were not clear at all, and provided very little use.

    • Gamepad: remove internalName, internalFullName, and internalIndex
    • Pressable: remove internalName, internalFullName, internalGamepad, internalGamepadFullName, internalGamepadIndex
    • Button, AnyInput and Trigger: remove internalIndex
    • StickDirection, StickPressedZone: remove internalStickFullName, internalStick, stickIndex, stickFullName (the latter two can still be accessed through stick.index and stick.fullName)
    • Stick: remove internalFullName, internalGamepad, internalGamepadIndex, internalGamepadFullName, gamepadIndex, gamepadFullName (the latter two can still be accessed through gamepad.index and gamepad.fullName)
  • Remove exclusive properties from AnyGamepad and AnyInput

    • AnyGamepad: remove gamepads, gamepad, indices
    • AnyInput: remove pressedInputs, pressedInput, index
    • AnyGamepadStick: remove pressedSticks, pressedStick
  • Remove buildAllOnStartup from Settings

    • I reworked the whole performance system, and this feature was not needed anymore.
  • Remove "raw" properties and inDeadZone
    Because no one needs that stuff when you can change the size of dead zones (you can even do it through code)

    • Pressable: remove inDeadZone, positionRaw
    • Stick: remove inDeadZone, positionRaw, horizontalRaw, verticalRaw, angleRaw, distanceRaw, worldPositionCameraRaw, worldPositionFlatRaw
  • Remove redundant directions from Stick

    • Remove leftUp, rightUp, leftDown, rightDown from stick (upLeft, upRight, downLeft, and downRight still exist and do exactly the same thing)
  • Remove position from Pressable
    Position is not a relevant information on buttons that can only be pressed or released. This property is still present on Trigger.

  • Remove lastPress properties from Pressable
    These properties are not very useful, and easy to reproduce if needed by the user.

    • Remove lastPressWasDouble, lastPressWasLong, lastPressed, lastPressStart and lastReleased from Pressable
  • Remove doublePress and longPress properties from Pressable
    I changed how Pressable works and added Press properties instead.

    • Remove doublePress, doublePressJustPressed, doublePressJustReleased, longPress, longPressJustPressed and longPressJustReleased from Pressable
  • Remove angle from StickDirection

  • Remove Stick => Pressable implicit conversion (through inPressedZone)

Features

  • Add Press class to represent a specific way of pressing a Pressable (for instance a simple, double or long press)

    • The Press class has the following properties: pressed, justPressed, released, justReleased, pressDuration, releaseDuration.
    • Add simplePress, doublePress and longPress properties to Pressable
  • Add implicit conversions

    • Pressable => Press through simplePress by default
    • Press => bool through pressed by default
    • Pressable => bool through simplePress.pressed by default
  • Add settings to choose default conversions

    • Pressable => Press can use either simplePress, doublePress or longPress (default is simplePress).
    • Press => bool can use either pressed, justPressed, released or justReleased (default is pressed).
  • Rework performance management
    In most cases, Update time is about 20% of what it used to be.

    • Add Enable and Disable methods to Gamepads, Pressables and Stick, as well as isEnabled property.
    • Add settings to start the game with any Gamepad, Pressable or Stick already disabled.
    • Skip update in disabled Gamepads, Pressables and Sticks.
    • Skip update in Gamepads that have never been connected.
    • Make D-pads much more efficient.
    • Make Axes much more efficient.
    • Make Buttons a bit more efficient.
    • Remove 1 frame latency on AnyGamepad
  • Improve OS detection to support XBoxOne and non-Windows WebGL builds

Fixes

  • Buttons on AnyGamepad now behave like normal buttons
    They're considered pressed if they are pressed on at least one gamepad, and released if they are released on all gamepads. If a given button is pressed on a gamepad, releasing it on a different gamepad no longer triggers a justReleased event on AnyGamepad.

  • Move the Updater script earlier in execution order
    This fixes various minor bugs caused by Hinput not being updated consistently

  • Add a few checks at potential divisions by 0
    For instance if dead zone = 1

General

  • Add internal classes StickPressable, GamepadPressable and AnyGamepadButton

  • Countless code refactorings, project improvements, comment rephrasing and document edits