about summary refs log tree commit diff
diff options
context:
space:
mode:
authorsternenseemann <git@lukasepple.de>2019-06-01 01:56:58 +0200
committersternenseemann <git@lukasepple.de>2019-06-01 01:56:58 +0200
commit9d81c6aa86a3ede94795f0aa33eb5990b3440390 (patch)
treee55055039cf4eb39eb92beb5acf2fcc7ba8ab311
parent2f2a1dae6f7e11624f13fa43b5ceb9ff08b5f70f (diff)
correct behavior of chainFun
add extraction of spawned objects
-rw-r--r--lib/Grav2ty/Control.hs7
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/Grav2ty/Control.hs b/lib/Grav2ty/Control.hs
index 0b39667..0fab401 100644
--- a/lib/Grav2ty/Control.hs
+++ b/lib/Grav2ty/Control.hs
@@ -104,8 +104,11 @@ updateState t extract state =
         updateAndExtract acc@(seq, f) x =
           if isDynamic x && (anyFrom _relColl x objectRel == Just True)
              then acc
-             else (updateObject' x >< seq, chainFun (extract x) f)
-        chainFun x f = if isJust f then (.) <$> x <*> f else x
+             else let updated = updateObject' x
+                   in (updated >< seq, foldl' chainFun f (fmap extract updated))
+        chainFun x@(Just _) f@(Just _) = (.) <$> x <*> f
+        chainFun Nothing f = f
+        chainFun x Nothing = x
         objectRel = objectRelGraph oldWorld
         getForce obj = foldlFrom' (\f r -> f + _relForce r) (V2 0 0) obj objectRel
         scaledT = state^.control^.ctrlTimeScale * t