Thread: Having only one function run at higher priority

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    yes it will...
    but I prefer to make one-shot settings to the next event based on timeprocessing for previous event, because in my code MM events do not occure with equal intervals...
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  2. #2
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Please tell me that neither MoveObjects, nor ProcessInput, nor anything else in that loop in AdvanceClock does any drawing, or other operation that might take so much as a millisecond?
    If either of those do, then that would be your problem. You need to decouple your fixed rate logic updating, from your frame rate. If your logic update rate is 60fps but your PC can't manage to draw as fast as 60fps (possibly due to other programs using CPU) then you will get the problem you mention.

    timeGetTime should really only be called ONCE at the start of that function, and everything else should simply be code that decides on how many logic steps to execute, or how long to sleep. The fact that you're calling it in a loop suggests you expect some things in that loop to take a little while, which as per the above, would be bad.

    Make (1000.0/60.0) a named constant instead of hard coding 16.666...

    I think another problem comes from the fact that you're asuming that AdvanceClock is called exactly 60 times per second. (Due to the Actual += 16.66666666666667; line near the start). However you then assume it isn't being called 60 times per second shown by that fact that you go on to compenstate for having slipped behind by adding Actual += 16.66666666666667; in the loop later on.
    You can't do both! You can either rely on AdvanceClock being called exactly 60 times per second in which case you wont need this code to contain loops, or you allow it to be variable, in which case you need to remove the first occurrence of Actual += 16.66666666666667;
    So, which is it?
    Last edited by iMalc; 02-23-2008 at 02:45 PM.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Change this program so it uses function??
    By stormfront in forum C Programming
    Replies: 8
    Last Post: 11-01-2005, 08:55 AM
  2. const at the end of a sub routine?
    By Kleid-0 in forum C++ Programming
    Replies: 14
    Last Post: 10-23-2005, 06:44 PM
  3. Run function from text file
    By hendraiskandar in forum C Programming
    Replies: 1
    Last Post: 06-20-2005, 01:36 AM
  4. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  5. Replies: 5
    Last Post: 02-08-2003, 07:42 PM