1. tick_delay()

Okay, I got EUPHORIA 1.5a... And I noticed tick_rate().. Hey, this is too
good to be true! I made a routine, tick_delay() in QBasic accidentally
(Called it Delay()) while trying to make a regular 1 second type delay
thing. Anyway, it just so happens, my sloppy coding saved me (this time
;)... I converted it into Euphoria a couple days ago... before I knew
about tick_rate(). (Although there may be crash if the program is running
long enough for time() to roll over to 0 and the routine is running)
Anyway, here it is:

global procedure tick_delay(atom l)
    atom oldtime, c
    oldtime = time()
    c = 0
    while l > c do
        if time() > oldtime then
            c = c + 1
            oldtime = time()
        end if
    end while
end procedure

Explination:
After each tick time() increases. So, after each tick l will be more than
c. You can use tick_rate() to increase the resolution of tick_delay().
You cannot use fractional ticks. (18.2 will be considered 19)
This has one major advantage:
Most of us are used to a fixed delay. But what if there is more action
during one game loop than another one? Well, the gameplay could be jerky.
With this function, so long as each loop is less than 1 tick, the
gameplay will be as smooth as possible. Since time() hasn't been updated
yet and will be updated at a fixed point, the game will have the same
delay time each loop.
(I noticed that Language War sometimes isn't super smooth using it's
delay routines...)
This is a bit easier than needing to install a new ISR to take over the
clock interrupt for the delays.. :)
Comments?

new topic     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu