[Haskell-beginners] FRP and a set of pairwise interacting (colliding) objects

Nathan Hüsken nathan.huesken at posteo.de
Fri Jun 29 14:07:13 CEST 2012


Hi,

I want to simulate as set of 2D objects, which can collide pairs wise
with each other.
In an OOP language, I would do this:

  for (o1 in objects) {
    for (o2 in objets) {
      if (testCollision(o1, o2)) {
        CollData cd = getCollisionData(o1,o2);
        o1.reactToCollision(cd);
        o2.reactToCollision(cd):
      }
    }
  }

Now I want to do the same thing in Haskell with FRP.
Normally in FRP (correct me if I am wrong) I have for my objects a
Signal (or whatever it is called in the specific library), which gets as
input the collision events for this object (and probably more data, but
let's assume collision events are enough):

  object :: Signal (Event CollData) ObjectState

The CollData events themself are generated at another place:

  collisions :: Signal [ObjectState] (Event CollData)

But now the collisions are generated at one place, and processed at
another. This means that CollData must be somehow tagged to the objects
it belongs to (an ID for example). This again means that some function
must take the pool of all collision datas and distribute them to the
"object" Signals.

When I have a lot of objects, this means a significant overhead!

Now I am wondering if there is a nicer approach which avoids this overhead.

Thanks!
Nathan



More information about the Beginners mailing list