Daniel Díaz Casanueva | 28 Dec 01:21 2012
Picon

Gloss and relatively expensive computations

Hello cafe!

I'm having some performance issues trying to use gloss to make animations where each "model" step is relatively time expensive. I'm using the IO.Simulate module because my step function needs to do an IO operation which takes around 1 second (it may vary).

I will try to give some details.

I have the step function:

step :: Model -> IO Model
step m = do
 ...
 p <- slowOperation
 ...
 return newModel

The rest of the program is small and simple. The drawing function (Model -> IO Picture -- it is pure though) is as quick as simple. However, the program get stuck after the first iteration.

In the other hand, I am using the animateIO function which ask me for an Int value to set up "the number of simulation steps to take for each second of real time". But I'm more interested in the animation waiting for the simulation step to end. Does it make sense?

I would be really thankful with any pointer here.

Thanks in advance,
Daniel Díaz.
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
Artyom Kazak | 28 Dec 01:56 2012
Picon

Re: Gloss and relatively expensive computations

You could create a new thread which would be 'forever' executing your extensive computation and updating some IOVar accordingly. The drawing function would do nothing except reading that IOVar and displaying its contents. Since drawing is cheap, this can be done at any reasonable rate.

28.12.2012 3:22 пользователь "Daniel Díaz Casanueva" <dhelta.diaz <at> gmail.com> написал:
Hello cafe!

I'm having some performance issues trying to use gloss to make animations where each "model" step is relatively time expensive. I'm using the IO.Simulate module because my step function needs to do an IO operation which takes around 1 second (it may vary).

I will try to give some details.

I have the step function:

step :: Model -> IO Model
step m = do
 ...
 p <- slowOperation
 ...
 return newModel

The rest of the program is small and simple. The drawing function (Model -> IO Picture -- it is pure though) is as quick as simple. However, the program get stuck after the first iteration.

In the other hand, I am using the animateIO function which ask me for an Int value to set up "the number of simulation steps to take for each second of real time". But I'm more interested in the animation waiting for the simulation step to end. Does it make sense?

I would be really thankful with any pointer here.

Thanks in advance,
Daniel Díaz.

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
Daniel Díaz Casanueva | 30 Dec 20:22 2012
Picon

Re: Gloss and relatively expensive computations

Hi Artyom!

Thanks for your response. It seems your tactic has worked. I was so focused on programming "inside" the gloss parameter that I completely forgot about programming in the "outside". Here is what I did (I picked MVar's):

myprog s = do
 ...
 var <- newMVar w0
 let loop w = do
       w' <- step s w
       putMVar var w'
       loop w'
 forkIO $ loop w0
 simulateIO ...  (\_ _ w -> fmap (fromMaybe w) $ tryTakeMVar var)

And it's working just fine!

Best regards,
Daniel Díaz.
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Gmane