Author Topic: How fast does a While loop run?  (Read 6486 times)

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
How fast does a While loop run?
« on: May 23, 2010, 08:00:46 PM »
How is the speed of a While GameRunning() loop governed?

Is it simply a function of how quickly the computer can repeat the commands within it?
Is there a fixed "tick" to it, say once per 0.1ms?


I have noticed that, without a rate limiter in place, gravity appears to happen at different speeds.  For example, while balancing orbits, I am finding that an asteroid will be 50% further round its orbit after 20 minutes than it is on most other occasions.

Alex

  • Administrator
  • Ent
  • *****
  • Thank You
  • -Given: 3
  • -Receive: 14
  • Posts: 1,035
Re: How fast does a While loop run?
« Reply #1 on: May 25, 2010, 07:36:53 PM »
Hmm, it should run at the same tick rate as the game logic... which does actually mean that while the game is time-dependent, the Lua is frame dependent. That's not so good for gravity stuff... hmm. One to think on.

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: How fast does a While loop run?
« Reply #2 on: May 25, 2010, 11:48:25 PM »
So if the Lua is frame-dependent, what governs the speed that the frames occur?  Is that just the speed of your computer?

On my pc the "frame rate" seems about 110hz, for the level I'm working on.

Alex

  • Administrator
  • Ent
  • *****
  • Thank You
  • -Given: 3
  • -Receive: 14
  • Posts: 1,035
Re: How fast does a While loop run?
« Reply #3 on: May 26, 2010, 11:41:51 PM »
Could be, yeah :( have to have a think.

I thought that 60 was the highest it would go though. hmmm

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: How fast does a While loop run?
« Reply #4 on: May 26, 2010, 11:59:00 PM »
You might be right actually.

Here's how I've been testing it:

Code: [Select]
-- ** RATE LIMITER **
If GetGameTime() > Timer + 0.01 then
   Timer = GetGameTime()

   <<run one pass (or frame) of the gravity engine>>

end

This code would mean it runs at up to 100 times per second.

If i change "0.01" to "0.02", ie 50 times per second, the gravity engine seems to run at half the speed - indeed if you look closely you can observe "juddering" as the game moves, pauses, moves, pauses.
However, using the value "0.001" doesnt seem any different to using "0.01".



By the way Alex, if I don't include a Rate Limiter then when I pause the game, the gravity engine keeps running - asteroids continue along their orbits, etc.  Using a rate limiter set to "0.00" has no effect on gameplay but fixes this problem.  Still, surely it should stop running Lua frames in that way when the game is paused..?  Not a huge problem, as I say there is a perfectly good workaround..just thought I'd mention it.
« Last Edit: May 27, 2010, 12:03:29 AM by annikk.exe »

Alex

  • Administrator
  • Ent
  • *****
  • Thank You
  • -Given: 3
  • -Receive: 14
  • Posts: 1,035
Re: How fast does a While loop run?
« Reply #5 on: May 27, 2010, 10:43:35 PM »
Lua should still run I think, there maybe ought to be different routines to call for when the game is paused though.

I will expose the update rate in Lua, but you'll have to work that into your calculations (probably most stuff will be solved by (update_rate/0.0166666) * (original_calculation) ).

AWS

  • Achiever
  • Arboreal Being
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 275
Re: How fast does a While loop run?
« Reply #6 on: June 01, 2010, 09:56:23 PM »
interesting Q annikk.

Pilchard123

  • Tester
  • Old Oak
  • ****
  • Thank You
  • -Given: 4
  • -Receive: 24
  • Posts: 932
  • Eufloria: Yes
Re: How fast does a While loop run?
« Reply #7 on: June 02, 2010, 10:24:38 PM »
Quote from: Imagamer
If you have AI variables that determine how soon the AI performs a specific action, like MINPLANTTIME and MAXPLANTTIME, what does MINTICK and MAXTICK do now? Does it start the timer of the other AI variables?

Would that have any effect? Like max/min lines of code/second?

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: How fast does a While loop run?
« Reply #8 on: June 03, 2010, 02:25:28 AM »
We're not sure what maxtick and mintick do.  Strange ones.. :>

Pilchard123

  • Tester
  • Old Oak
  • ****
  • Thank You
  • -Given: 4
  • -Receive: 24
  • Posts: 932
  • Eufloria: Yes
Re: How fast does a While loop run?
« Reply #9 on: June 03, 2010, 02:50:57 AM »
I know you're not sure. That's why I was suggesting them as a possible solution.

Unless you've already tried them as code speed controls, in which case just ignore me.

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: How fast does a While loop run?
« Reply #10 on: June 03, 2010, 03:03:18 AM »
I haven't tried them to be honest.  But I think Alex was implying that it's not currently possible to change the LUA framerate.

I might give it a try at some point anyway...but right now I'm about to move house :P  So it will have to wait, unless someone else wants to test it.  Can just plug them into one of my gravity maps and see if the orbits seem to go faster or slower.

Alex

  • Administrator
  • Ent
  • *****
  • Thank You
  • -Given: 3
  • -Receive: 14
  • Posts: 1,035
Re: How fast does a While loop run?
« Reply #11 on: June 09, 2010, 11:02:24 PM »
They used to be how fast the AI thinks, but it may have been deprecated such that they now do nothing at all.