Oops. The list's spam-filter tossed this note. ---------- Forwarded message ---------- From: Alexander Foremny <alexanderforemny@googlemail.com> To: reactive@haskell.org Date: Tue, 24 Aug 2010 10:14:11 +0200 Subject: whenE uses much memory Hello, I am trying to write a simple 2D tower defense game using reactive and reactive-glut. I am spawning a wave of creeps that walk around the map and when there are no creeps on the map, I'd like to spawn the next wave. However, I cannot predict at which time there will be no creeps on the maps since each creature might move with different speed. To realize switching anyway I thought I could poll the number of creeps and switch when the number is zero. With that solution I am having serious performance problems. Here's the relevant code:
data World = World { ... }
wave1 :: Behavior World
wave2 :: Behavior World
worldB = wave1 `switcher` fmap (const wave2) (whenE (zeroCreeps wave1) pollE) where pollE = atTimes [1..]
zeroCreeps :: Behavior World -> Behavior Bool
When running worldB from main I can see the program's memory usage increasing and everything becomes very unresponsive. It seems as if whenE is accumalating all the occurences of the event. The problem seems to boil down to snapshot having the same behavior.
snapshot (pure False) (atTimes [1..])
This piece of code uses very much memory either. Is this due to reactive being broken (I read that somewhere) or is my solution just no solution at all? I am using ghc 6.12.1 with reactive 0.11.5 and reactive-glut 0.1.9. Regards Alexander Foremny
participants (1)
-
Conal Elliott