I'm trying to write a loop that will only run a certain number of times
per second. For instance, in Ruby-Processing, you would use
"frame_rate(30)" to make the main loop execute no more than 30 evenly
spaced frames per second. How might I go about doing something like
that?
I could try calling sleep with a float that represents the difference
between the next time I want the loop to run and the current time. That
seems clunky, though.
I also thought about using the Observer pattern to have a timer alert
the simulation each time it should update. That also seems wrong.
I feel like I must be overlooking something simple. Any ideas?
I think your first method is the one I've seen the most in game loops.
You calculate how long you should sleep based on what time it is now
and what time you want to wake up, being careful that your last frame
could have taken over 1/30th of a second.
You also use the elapsed time in your physics, so the physics engine
is not tied to your frame rate.
···
On Tue, Sep 8, 2009 at 5:38 PM, Michael Tomer<michael.tomer@fnis.com> wrote:
I'm trying to write a loop that will only run a certain number of times
per second. For instance, in Ruby-Processing, you would use
"frame_rate(30)" to make the main loop execute no more than 30 evenly
spaced frames per second. How might I go about doing something like
that?
I could try calling sleep with a float that represents the difference
between the next time I want the loop to run and the current time. That
seems clunky, though.
I also thought about using the Observer pattern to have a timer alert
the simulation each time it should update. That also seems wrong.
I'm trying to write a loop that will only run a certain number of times
per second.
The proper way to do this is to call the setitimer(2) function
that will send SIGALRM periodically to the process. It has been
discussed a long time ago:
Thanks, Paul. I feel better knowing that my first guess was right, even
though it initially struck me as wrong. I guess that'll teach me to
second guess myself.
On Tue, Sep 8, 2009 at 6:14 PM, Bertram Scharpf<lists@bertram-scharpf.de> wrote:
Am Mittwoch, 09. Sep 2009, 01:38:33 +0900 schrieb Michael Tomer:
I'm trying to write a loop that will only run a certain number of times
per second.
The proper way to do this is to call the setitimer(2) function
that will send SIGALRM periodically to the process. It has been
discussed a long time ago:
On Sep 8, 2:14 pm, Bertram Scharpf <li...@bertram-scharpf.de> wrote:
Hi,
Am Mittwoch, 09. Sep 2009, 01:38:33 +0900 schrieb Michael Tomer:
> I'm trying to write a loop that will only run a certain number of times
> per second.
The proper way to do this is to call the setitimer(2) function
that will send SIGALRM periodically to the process. It has been
discussed a long time ago: