diff --git a/src/Affection/Particle.hs b/src/Affection/Particle.hs index 8743234..cafb298 100644 --- a/src/Affection/Particle.hs +++ b/src/Affection/Particle.hs @@ -36,61 +36,31 @@ updateParticle -- -> Affection us [Maybe Particle] -> Affection us (Maybe Particle) -- ^ resulting 'Particle' -updateParticle time funct pa = do - now <- elapsedTime <$> get - if particleCreation pa + particleTimeToLive pa < now - then do - mproducer <- liftIO $ G.gegl_node_get_producer - (particleStackCont pa) - "input" - case mproducer of - Just (producer, padname) -> do - consumers <- liftIO $ G.gegl_node_get_consumers - (particleStackCont pa) - "output" - liftIO $ mapM_ (\(node, inpad)-> G.gegl_node_connect_to - producer - padname - node - inpad - ) consumers - Nothing -> return () - liftIO $ G.gegl_node_drop $ particleRootNode pa - return $ Nothing - else do - np <- Just <$> funct time pa - return $ np --- updateParticle time funct acc@[p] pa = do --- now <- elapsedTime <$> get --- if particleCreation pa + particleTimeToLive pa > now --- then do --- liftIO $ G.gegl_node_drop $ particleRootNode pa --- return $ Nothing : acc --- else do --- when (not $ isNothing p) $ do --- -- liftIO $ traceIO "linking second node in list" --- liftIO $ G.gegl_node_link --- (particleStackCont pa) --- (particleStackCont $ fromJust p) --- np <- Just <$> funct time pa --- return $ np : acc --- updateParticle time funct acc@(p:ps) pa = do --- now <- elapsedTime <$> get --- if particleCreation pa + particleTimeToLive pa > now --- then do --- liftIO $ G.gegl_node_drop $ particleRootNode pa --- return $ Nothing : acc --- else do --- when (isNothing p) $ do --- let mnl = nextLiving ps --- maybe --- (return ()) --- (\nl -> do --- -- liftIO $ traceIO "linking nth node on list" --- liftIO $ G.gegl_node_link (particleStackCont pa) (particleStackCont nl)) --- mnl --- np <- Just <$> funct time pa --- return $ np : acc +updateParticle time funct pa = + do + now <- elapsedTime <$> get + if particleCreation pa + particleTimeToLive pa < now + then do + mproducer <- liftIO $ G.gegl_node_get_producer + (particleStackCont pa) + "input" + case mproducer of + Just (producer, padname) -> do + consumers <- liftIO $ G.gegl_node_get_consumers + (particleStackCont pa) + "output" + liftIO $ mapM_ (\(node, inpad)-> G.gegl_node_connect_to + producer + padname + node + inpad + ) consumers + Nothing -> return () + liftIO $ G.gegl_node_drop $ particleRootNode pa + return $ Nothing + else do + np <- Just <$> funct time pa + return $ np -- | Get the next living particle from a list nextLiving