I'm using reactive-banana
and sdl2
(using this glue library) for a game-like project. A Behavior
is created for the "absolute mouse location", as well as a Behavior
for the "relative mouse location" (a.k.a. the mouse movement). When not using FRP this works well, but with FRP the "relative mouse location" becomes a problem: it seems only a small amount of the data comes through. I suspect this happens because the underlying "SDL events" (that we represent with a Behavior
) do not line up nicely with the tick Event
s.
So I want to calculate my own mouse movement, by simply comparing the mouse location at the current tick with the location at the previous tick. I'm not sure if this will solve my problems, but I have good hope :)
First of all I'm lost on how to approach it: the State
monad, or an IORef
, or does reactive-banana
provide another means?
I'll give a small excerpt of the code I currently have:
makeNetwork :: GraphicsData -> SDLEventSource -> MomentIO ()
makeNetwork gd sdlEventSource = mdo
tickE <- tickEvent sdlEventSource
mouseMovementB <- fromPoll SDL.getRelativeMouseLocation
mousePositionB <- fromPoll SDL.getAbsoluteMouseLocation
let mousePositionE = mousePositionB <@ tickE
mouseMovementE = mouseMovementB <@ tickE -- this yields flaky data
-- ... the rest of the network description left out ...
As explained above I'd like to express mouseMovementE
in terms of the mousePositionB
at current tickE
(known as mousePositionE
) and the mousePositionE
value at the previous tickE
.
Any help is greatly appreciated!