[prev in list] [next in list] [prev in thread] [next in thread] 

List:       haskell-cafe
Subject:    Re: [Haskell-cafe] Correct way to record state in OpenGL?
From:       Mark Spezzano <valheru () chariot ! net ! au>
Date:       2010-04-08 16:55:23
Message-ID: A74E6670-346D-4675-B397-B04EEECAD537 () chariot ! net ! au
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Maybe I should ask: If I have many state variables encapsulated in one IO (StateVar \
DemoState) how do I go about referencing and updating _one_ without having to \
enumerate all of them?

What is the syntax?

Mark

On 09/04/2010, at 12:13 AM, Mark Spezzano wrote:

> I sort of understand what people are getting at.
> 
> My basic question is now, given that I have a bunch of parameters that represent \
> state should I bundle up ALL of these parameters in one data type (DemoState, say) \
> and have ONE IORef variable that references the lot, or have an IORef for each \
> piece of state, separately. 
> What are the disadvantages of each approach?
> 
> Also, is reading and writing to an IORef expensive computationally?
> 
> Thanks,
> 
> Mark 
> 
> On 05/04/2010, at 2:25 AM, Tobias Brandt wrote:
> 
> > HOpenGL uses Data.StateVar. One can define the following function:
> > 
> > newStateVar :: a -> IO (StateVar a)
> > newStateVar val = do
> > ref <- newIORef val
> > let readAction = readIORef ref
> > let writeAction = \newVal -> writeIORef ref newVal
> > return (makeStateVar readAction writeAction)
> > 
> > Now one can use StateVar consistent with HOpenGL:
> > 
> > create:  foo <- newStateVar bar
> > read:     get foo
> > write      foo $= baz
> > 
> > On 4 April 2010 11:03, Mark Spezzano <mark.spezzano@chariot.net.au> wrote:
> > Hi
> > 
> > What is the correct way to record "custom" state when using OpenGL?
> > 
> > By this, I refer to, say, properties of a square--say it's x,y coordinates as it \
> > moves across the screen. This requires that the program keep track of the \
> > object's state as it moves. These coordinates are _not_ part of the OpenGL state \
> > machine, so is the correct way to use the State monad? 
> > If so--or if not so--how would I proceed to keep track of the state of my objects \
> > as they move about the screen? Maybe the HOpenGL implementation comes with such \
> > state-tracking devices? 
> > Please post code snippets if necessary.
> > 
> > Thanks in advance,
> > 
> > Mark Spezzano
> > _______________________________________________
> > Haskell-Cafe mailing list
> > Haskell-Cafe@haskell.org
> > http://www.haskell.org/mailman/listinfo/haskell-cafe
> > 
> 
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe


[Attachment #5 (unknown)]

<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; \
-webkit-line-break: after-white-space; ">Maybe I should ask: If I have many state \
variables encapsulated in one IO (StateVar DemoState) how do I go about referencing \
and updating _one_ without having to enumerate all of them?<div><br></div><div>What \
is the syntax?</div><div><br></div><div>Mark</div><div><br><div><div>On 09/04/2010, \
at 12:13 AM, Mark Spezzano wrote:</div><br \
class="Apple-interchange-newline"><blockquote type="cite"><div style="word-wrap: \
break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">I sort \
of understand what people are getting at.<div><br></div><div>My basic question is \
now, given that I have a bunch of parameters that represent state should I bundle up \
ALL of these parameters in one data type (DemoState, say) and have ONE IORef variable \
that references the lot, or have an IORef for each piece of state, \
separately.</div><div><br></div><div>What are the disadvantages of each \
approach?</div><div><br></div><div>Also, is reading and writing to an IORef expensive \
computationally?</div><div><br></div><div>Thanks,</div><div><br></div><div>Mark&nbsp;</div><div><br><div><div>On \
05/04/2010, at 2:25 AM, Tobias Brandt wrote:</div><br \
class="Apple-interchange-newline"><blockquote type="cite">HOpenGL uses Data.StateVar. \
One can define the following function:<br><br>newStateVar :: a -&gt; IO (StateVar \
a)<br>newStateVar val = do<br>&nbsp;&nbsp;&nbsp; ref &lt;- newIORef \
val<br>&nbsp;&nbsp;&nbsp; let readAction = readIORef ref<br>&nbsp;&nbsp;&nbsp; let \
writeAction = \newVal -&gt; writeIORef ref newVal<br> &nbsp;&nbsp;&nbsp; return \
(makeStateVar readAction writeAction)<br><br>Now one can use StateVar consistent with \
HOpenGL:<br><br>create:&nbsp; foo &lt;- newStateVar \
bar<br>read:&nbsp;&nbsp;&nbsp;&nbsp; get foo<br>write&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
foo $= baz<br><br><div class="gmail_quote"> On 4 April 2010 11:03, Mark Spezzano \
<span dir="ltr">&lt;<a \
href="mailto:mark.spezzano@chariot.net.au">mark.spezzano@chariot.net.au</a>&gt;</span> \
wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; \
border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"> Hi<br>
<br>
What is the correct way to record "custom" state when using OpenGL?<br>
<br>
By this, I refer to, say, properties of a square--say it's x,y coordinates as it \
moves across the screen. This requires that the program keep track of the object's \
state as it moves. These coordinates are _not_ part of the OpenGL state machine, so \
is the correct way to use the State monad?<br>

<br>
If so--or if not so--how would I proceed to keep track of the state of my objects as \
they move about the screen? Maybe the HOpenGL implementation comes with such \
state-tracking devices?<br> <br>
Please post code snippets if necessary.<br>
<br>
Thanks in advance,<br>
<font color="#888888"><br>
Mark Spezzano<br>
&nbsp;_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" \
target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br> \
</font></blockquote></div><br> \
</blockquote></div><br></div></div>_______________________________________________<br>Haskell-Cafe \
mailing list<br><a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a> \
<br>http://www.haskell.org/mailman/listinfo/haskell-cafe<br></blockquote></div><br></div></body></html>




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


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic