I haven't run any benchmarks or anything yet, so I am kind of just asking this out of my ass, but here goes.
I am working on the Input module for
Rpg.NET, so keep in mind this is not being performed in Ruby, so there are some things that can be done that are not possible with a script. Here is my debate, which of these two directions to take it:
Direction 1 : GetKeyboardStateThis was my original thought. Every time Input.update is called, invoke GetKeyboardState, enumerate the buffer the key states were copied to, and internally calculate and set flags in arrays to store which keys are triggered, released, repeated, etc. This is more or less just the same formula as Custom Controls in ToA, but written in C#.
After thinking about it, I really don't care for this approach. It is perfectly acceptable as a Ruby script, since the options there are more limited, but I am not a fan of the the need to enumerate 256 keys every time the update method is called, and perform a bunch of checks on each key to determine what to do about each.
Direction 2 : WindowProcI already have a WndProc function in place that receives any message posted to the window, including key presses, key releases, mouse buttons, mouse wheel, mouse move, and just about anything else you could imagine that has an effect on the window.
My theory is, instead of checking the state of the keyboard every frame, I can simply update the states of the keys as the messages arrive, and do nothing in the meantime. That means no enumerating 256 every frame, and it has the obvious advantage of being an "all-in-one" method that can allow me to seamlessly integrate mouse input, as well as other anything else I want to implement.
My question is, are there any disadvantages of the second approach over the first?