[Haskell-cafe] Netwire, keyboard events, and games

Ertugrul Söylemez es at ertes.de
Sun Feb 17 03:12:32 CET 2013


Kata Recurse <lightquake at amateurtopologist.com> wrote:

> This is the approach that I currently use; it was pointed out to me
> that polling the state of the keys on every input is considered bad
> practice since it means that key clicks that happen in between physics
> updates don't get registered at all, hence why I wanted to use a more
> event-driven approach.

The idea of this approach is that the set of currently pressed keys is
constructed by the application loop, not the wire itself.  Every event
triggers another step of the wire.

One problem with that approach is that the rendering may be much slower
than a wire step, so you get event congestion and thus delayed
responses.  This suggests that it would pay off to handle all events in
a single instant, but that is much more difficult than it sounds.  What
should a wire do, if in a single instant a key is pressed and released,
or if it is pressed multiple times?

A simple solution exists:  Wires can deal with a time delta of 0, so
step the wire with dt = 0 for all queued events before you render the
next frame.  There is nothing wrong with mixing this with sessions.  In,
say, SDL terms, if the event is NoEvent, use stepSession* and render.
If it's any other event, use stepWire* and don't render.


Greets,
Ertugrul

-- 
Key-ID: E5DD8D11 "Ertugrul Soeylemez <es at ertes.de>"
FPrint: BD28 3E3F BE63 BADD 4157  9134 D56A 37FA E5DD 8D11
Keysrv: hkp://subkeys.pgp.net/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20130217/1cd939ee/attachment.pgp>


More information about the Haskell-Cafe mailing list