[Haskell-beginners] Netwire and event accumulator
Martín Villagra
mvillagra0 at gmail.com
Thu Dec 10 00:38:36 UTC 2015
Hi. I'm trying to do a simulation using Netwire 5 and SDL but as I've just
started with Netwire I'm not sure if I'm doing it correctly regarding the
input events. Suppose I have a game which consists in moving a single pixel
around the screen. To make this game, I created these simple wires:
readEvent :: Wire s e IO a SDL.Event
(SDL.Event can be SDL.NoEvent or an event just like Netwire's events, so I
guess they can be easily converted)
inputLogic :: Wire s m SDL.Event Position
(it keeps the position as an internal state and updates it according to the
event)
render :: Wire s e IO Position ( )
(just writes the pixel to the screen)
And finally the game can be expressed using Arrow notation as:
readEvent>>>inputLogic>>>render
It works. But the thing here is that events like mouse movement are
generated way faster than frames. To solve this, inputLogic should read all
the input events until there are none and only then render the frame. I'm
unable to do this using Wires. I've tried to make some kind of loop with
ArrowLoop but I failed. I did came up with this solution, creating
different wires:
readEvents :: Wire s e IO a [SDL.Event]
(it populates the list until there are no more events)
inputLogic' :: Wire s m [SDL.Event] Position
And the game is:
readEvents>>>inputLogic'>>>render
Which does the expected behaviour but it doesn't seem a good approach to
me. These new wires aren't as basic as the first ones. Is this the best way
to do it? Does anybody has a better idea?
Any advice will be considerably appreciated.
Martín
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20151209/92a39349/attachment.html>
More information about the Beginners
mailing list