[Haskell-cafe] Improving event management in elerea
patai_gergely at fastmail.fm
Fri Aug 14 07:38:16 EDT 2009
> can you explain, please ? I can't feel it when I play.
Well, the paddle moves very fast that way, and its speed depends on the
refresh rate. While the refresh rate is set in this program, it's not a
good idea to depend on it in any way. Transfer functions provide access
to the frame time, so you can adjust the speed to be independent of it.
> or using some rounding as I did in my first implementation ?
It's good if that works. However, I wouldn't depend on that either,
since you might have to struggle with edge cases, and you also rely on
the sizes being related to each other in various ways instead of
choosing them freely. In my opinion, the best solution in this case
would be a clamped integral, which would also make it unnecessary to
check for the edge of the field in the condition (note that I make use
of the Num instances of signals to take care of the lifting):
integralClamped v0 vmin vmax s = transfer v0 accum s
where accum dt v v0 = max vmin $ min vmax $ v0+v*realToFrac dt
playerX <- integralClamped playerX0 (-fieldW) (fieldW-playerW)
(ifte lpress (-1) 0 + ifte rpress 1 0)
>From these, integralClamped and ifte might also be good candidates for
inclusion in the library.
http://www.fastmail.fm - Choose from over 50 domains or use your own
More information about the Haskell-Cafe