amerkoleci / alimer

Cross-platform .NET 8 C# 12 game engine.

Home Page:https://amerkoleci.github.io/alimer-docs/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Input

amerkoleci opened this issue · comments

  • Create a new project
  • Implement SDL support
  • Implement Windows support

I did some research for Windows. DirectInput seems to be deprecated. There are special APIs for the Xbox360/One controller but for high-dpi mice and keyboards listening to raw input window messages seems to be the way to go.

I've implemented this here: https://github.com/roy-t/MiniEngine3/blob/main/src/Backend/Mini.Engine.Windows/InputService.cs, Mouse.cs, MouseDecoder.cs, Keyboard.cs, KeyboardDecoder.cs. For keyboards it also handles both virtual key characters and scan codes, which is another important thing to consider. I haven't added controller support yet.

I also wanted to tackle another problem. I want every system in my engine to get all input events, so to never miss anything, even if a frame took multiple seconds to render.

What I did is give every system its own keyboard/mouse instance. When the system is updated it iterates through all the input events to model the state of the mouse/keyboard after each event. You can see that system in action in https://github.com/roy-t/MiniEngine3/blob/main/src/Mini.Engine/Controllers/CameraController.cs

This might be a bit overkill as you would not expect the same key/button to have multiple events in a single frame. But I kinda got carried away with it.

Feel free to use this as inspiration or to copy paste it :).