Re: Controlling Speed

new topic     » goto parent     » topic index » view thread      » older message » newer message

On Tue, 3 Nov 1998 12:54:08 -0500, John DeHope <jwap at TAMPABAY.RR.COM> wrote:

>I'd like to throw my two cents in on the question of controlling a
>program's speed. I'm using this method for a game, so that no matter how
>fast the computer is the game executes at the same speed. The code is
>shown below...
>
        <SNIP>
>
>This code has some shortcomings, I know...
>1) What happens when the internal Euphoria time() function has to reset
>to 0. This would seem to kill my delay() procedure immediately. RDS: How
>big a number can time() return?

My understanding for quite sometime was that the time() reset after 24
hours.  I originally believed it to be at midnight.  Midnight or not
it appears 24 hours is your limit.  My most secure method and most
accurate method of time delay follows only as description of how to
build it.  I have done this a few times and prefer it when worried
about reliablilty and accuracy.  Sometimes you want a delay much less
than .05 or sometimes less than .01.  This can be accomplished assuming
the speed of your computer.

First you must sample the computers speed.  This is done only once.
It is done when the program first starts.  To do this you time a loop.
Two methods of timing a loop exist.
Method 1:
    t = time()
    for A = 1 to large_number do
    end for
    t = time() - t
result is "t" seconds per "large_number" counts

    Pro: This method is personally believed to be very accurate.
    Con: This method can tie up a slow computer for what appears
         as an eternity.
Method 2:
    counts = 0
    t = time() + 30-- 30 second delay  Could be less.
    while t > time() do
      counts = counts + 1
    end while
result is "counts" per "t" 30 seconds or whatever your delay was.
    Pro: Guaranteed not to tie up the computer more than 30 seconds.
    Con: Assumed to be SLIGHTLY less accurate.

What you do with this timing is quite simple.
If you used method 1 then you now know that.
  for a = 1 to large_number
  end for
will pause for "t" seconds.
If you used method 2 you now know that.
  for a = 1 to counts do
  end for
will pause for 30 seconds.
In method to if you want to pause for one second you simply use
  for a = 1 to counts/30 do
  end for

I hope this is now Clear as mud.  You can use seperate time sampling
to determine how long you want to delay so as to achieve a consistent
frame rate.

>2) This only works if the delay() procedure is imbedded into a main loop
>that is executing constantly. It does not slow down a program unless it
>is called relatively constantly.

This is common and understood.

        <SNIP>
>
>John.

_________________________

Lucius L. Hilley III    lhilley at cdc.net
http://www.cdc.net/~lhilley
http://www.americanantiques.com
http://www.dragonvet.com
_________________________

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu