{"action":"created","issue":{"url":"https://api.github.com/repos/SodiumFRP/sodium/issues/73","labels_url":"https://api.github.com/repos/SodiumFRP/sodium/issues/73/labels{/name}","comments_url":"https://api.github.com/repos/SodiumFRP/sodium/issues/73/comments","events_url":"https://api.github.com/repos/SodiumFRP/sodium/issues/73/events","html_url":"https://github.com/SodiumFRP/sodium/issues/73","id":100504656,"number":73,"title":"Behaviour propagation","user":{"login":"elaye","id":2633171,"avatar_url":"https://avatars.githubusercontent.com/u/2633171?v=3","gravatar_id":"","url":"https://api.github.com/users/elaye","html_url":"https://github.com/elaye","followers_url":"https://api.github.com/users/elaye/followers","following_url":"https://api.github.com/users/elaye/following{/other_user}","gists_url":"https://api.github.com/users/elaye/gists{/gist_id}","starred_url":"https://api.github.com/users/elaye/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elaye/subscriptions","organizations_url":"https://api.github.com/users/elaye/orgs","repos_url":"https://api.github.com/users/elaye/repos","events_url":"https://api.github.com/users/elaye/events{/privacy}","received_events_url":"https://api.github.com/users/elaye/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-08-12T09:37:22Z","updated_at":"2015-08-12T19:41:47Z","closed_at":null,"body":"Hello,\r\nI recently discovered Sodium and it's amazing what it's possible to do with it! However, I'm facing a problem at the moment that makes me think that I still don't quite understand how it really works. \r\n\r\nI'm trying to implement a \"reactive cube\" where for instance the width of the cube is controlled by a `Behaviour`. My cube is represented like this:\r\n\r\n    data RCube = RCube\r\n\t    { cubeSize :: Behaviour Float\r\n\t    , changeCubeSize :: Float -> Reactive ()\r\n\t    , mesh :: RMesh \r\n\t    }\r\n\r\nAnd I create one with this function:\r\n\r\n    newRCube :: Point -> Float -> App RCube\r\n    newRCube p s = do\r\n\t    (eSize, pushSize) <- io $ sync $ newBehaviour s\r\n\t    mesh <- io $ newRMesh LineStrip\r\n\t    io $ sync $ listenTrans (updates eSize) $ \\s ->\r\n\t\t    scaleMesh mesh $ scaleMatrix $ Vec3 s s s\r\n\r\n\t    --io $ sync $ listen (updates eSize) print\r\n\t    return $ RCube eSize pushSize mesh\r\n\r\nAnd for the `RMesh`:\r\n\r\n    data RMesh = RMesh\r\n        { mode :: GL.PrimitiveMode\r\n        , model :: Behaviour Mat4\r\n        , scaleMesh :: Mat4 -> Reactive ()\r\n        ...\r\n        }\r\n\r\n    newRMesh :: GL.PrimitiveMode -> IO RMesh\r\n    newRMesh mode = do\r\n        (eScale, pushScale) <- sync $ newBehaviour idMatrix\r\n        --idem eRotation, eTranslation\r\n        let eModel = (multmm) <$> ((multmm) <$> eScale <*> eRotation) <*> eTranslation\r\n        --sync $ listen (updates eScale) print\r\n        ...\r\n        return $ Mesh mode eModel pushScale ...\r\n\r\nNow with this I try to change the size of the cube with respect to time like this:\r\n\r\n    main :: IO ()\r\n    main = runApp app\r\n\r\n    app :: App ()\r\n    app = do\r\n\t    -- OpenGL stuff\r\n\t    cube <- newRCube (Point 0 0 0) 500\r\n\t\r\n\t    io $ sync $ changeCubeSize cube 300\r\n\t    io $ sync $ changeCubeSize cube 400\r\n\t    io $ sync $ changeCubeSize cube 200\r\n\r\n\t    forever $ do \r\n\t\t    t <- io $ getElapsedTime\r\n\t\t    let s = realToFrac $ t * 100\r\n\t\t    io $ sync $ changeCubeSize cube s\r\n\t\t    draw cube\r\n                    ...\r\n\r\nWhat I'm trying to do is to propagate the change of the cube size to the mesh scale. The behaviour of my program is inconsistent and I have absolutely no clue of where it can come from. If I call `changeCubeSize` before the `forever` in my app function, the cube size does change but not every time: if I call `changeCubeSize` mutliple times the last calls won't do anything. And the call in the `forever` doesn't do anything. I suppose there is a better way to do what I'm trying to do but I can't see it...\r\n"},"comment":{"url":"https://api.github.com/repos/SodiumFRP/sodium/issues/comments/130423191","html_url":"https://github.com/SodiumFRP/sodium/issues/73#issuecomment-130423191","issue_url":"https://api.github.com/repos/SodiumFRP/sodium/issues/73","id":130423191,"user":{"login":"the-real-blackh","id":738712,"avatar_url":"https://avatars.githubusercontent.com/u/738712?v=3","gravatar_id":"","url":"https://api.github.com/users/the-real-blackh","html_url":"https://github.com/the-real-blackh","followers_url":"https://api.github.com/users/the-real-blackh/followers","following_url":"https://api.github.com/users/the-real-blackh/following{/other_user}","gists_url":"https://api.github.com/users/the-real-blackh/gists{/gist_id}","starred_url":"https://api.github.com/users/the-real-blackh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/the-real-blackh/subscriptions","organizations_url":"https://api.github.com/users/the-real-blackh/orgs","repos_url":"https://api.github.com/users/the-real-blackh/repos","events_url":"https://api.github.com/users/the-real-blackh/events{/privacy}","received_events_url":"https://api.github.com/users/the-real-blackh/received_events","type":"User","site_admin":false},"created_at":"2015-08-12T19:41:47Z","updated_at":"2015-08-12T19:41:47Z","body":"That should work. I'll test your code out and get back to you shortly."}}