[Haskell-beginners] firering event in netwire

Nathan Hüsken nathan.huesken at posteo.de
Mon Oct 29 12:24:51 CET 2012


Hey,
I am posting on this old topic because I did not have time in the mean
time to concentrate on this in the past weeks and now I resume.

On 10/01/2012 02:22 PM, Ertugrul Söylemez wrote:
> Nathan Hüsken <nathan.huesken at posteo.de> wrote:
> 
>>>> But this does not do the accumulation every frame, but whenever an
>>>> event happens.
>>>
>>> That wire by itself does the accumulation at every frame, so you
>>> probably have an inhibiting wire earlier in the chain.
>>
>> Let me restate my problem. My wire is this:
>>
>> pos = accum (+) 0.0 . speed
>>
>> and all I do is putStrLn the output at every frame.
> 
> As a side note, see testWire and testWireM in Control.Wire.Session. =)
> 
> 
>> If withing one frame where speed has the value (1) several events are
>> sent over the wire (for example several keyup and keydown events for
>> an unrelated key), then pos gets incremented for one for each of this
>> events. So I have to prevent the accumulation if the event is not
>> NoEvent.
> 
> That's because you're using constant time deltas.  Even if your time
> frame has a constant rate you should still make use of your time deltas.
> In particular notice that Netwire can deal with time deltas of 0.  Then
> instead of accum you would use integral_.

Yes, ok. But now I want to do something with collision detection and
response. So I am trying the stanard FRP Pong example. For the ball I am
using

ballWire :: PaddleState BallState
ballWire = proc ps -> do
  object_ collDet startState -< (Accelerate (0.0, 0.0), ps)
  where
    collDet paddle ball = doCollisionResponseWithPaddleAndWalls paddle ball

now I do not want the doCollisionResponseWithPaddleAndWalls to be
applied every time an input event is send over the wire but only when
the Update event is fired.
Now I could add the event type (or the time delta) to the "paddle"
argument and test for it

collDet (paddle, eventType) ball = if eventType = Update then
doCollisionResponseWithPaddleAndWalls paddle ball else ball

But this feels like an unnecessary effort ...

Thanks!
nathan



More information about the Beginners mailing list