[Haskell-beginners] firering event in netwire

Ertugrul Söylemez es at ertes.de
Tue Oct 30 04:39:17 CET 2012


Nathan Hüsken <nathan.huesken at posteo.de> wrote:

> >> 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 ...

First of all, Netwire 4 is now released on Hackage.  The interface has
changed slightly, so you may want to adapt your code.

Now to your problem:  If you need object_, chances are it's easier to do
using mkGen, but in this simple case I doubt that it's necessary.  Have
a look into the Control.Wire.Trans module tree, where you will find many
convenient switching combinators.  It should be possible to implement
this by using simple integrals and switching.

In the next version there will be more switching combinators to make
applications like yours easier to write.


Greets,
Ertugrul

-- 
Not to be or to be and (not to be or to be and (not to be or to be and
(not to be or to be and ... that is the list monad.
-------------- 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/beginners/attachments/20121030/a3fe5061/attachment.pgp>


More information about the Beginners mailing list