Results 1 to 10 of 30

Thread: Yet another segfault (a.k.a. Darkhog is a total noob)

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #28
    Delay(17) is NOT the way to go, since the game will wait the same amount after every frame. On one machine, calculations will take 3ms + 17ms delay = 20ms per frame = 50FPS, but a slower machine will take 8ms + 17ms delay = 25ms per frame = 40FPS, and the game will slow down. To have a steady FPS, what you need to do is:
    Code:
    Function GetMSecs():Comp;
       begin Exit(TimeStampToMSecs(DateTimeToTimeStamp(Now()))) end;
    This function uses standard functions from SysUtils and returns current time as 64bit int containing the amount of miliseconds since 30.12.1899.

    In the game loop:
    Code:
    Time := getMSecs();
    (* Do all the calculations, drawing, et cetera *)
    While (getMSecs() - Time < DELAY_BETWEEN_FRAMES) do Delay(1)
    This way, unless the machine REALLY slows down, to the point that calculating/rendering a frame takes longer than DELAY_BETWEEN_FRAMES, you're going to have a steady FPS.

    Edit:
    Oh, and also, SysUtils contains Sleep(), which does the same crt.Delay() does.
    Last edited by Super Vegeta; 08-08-2013 at 09:37 AM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •