Thread: Time delay

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    3

    Time delay

    I want my games to go at a maximum speed that doesnt depend on the speed of the computer, so i want to put some sort of time delay in the main game loops.

    Does anyone know of any way to make a very small time delay?
    I only know of functions that can delay the program for a minimum of 1 milisecond, and thats too long.

    I really need something that delays the program for less than 1 milisecond.

    Thanks

  2. #2
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Posts
    2,572
    hmm, I'm not sure that such function exists, you could however maybe have a dummy operation that has a constant time - like maybe taking a square root or something similar.

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  3. #3
    Registered User
    Join Date
    Sep 2004
    Posts
    27
    Simply making delays won't work. Because the delay will stack. If you are using a windows system, try this.

    The best way I know, within having to write specialized stuff yourself, is to framelock it with GetTickCount();

    Code:
    static DWORD timer = GetTickCount();
    
    if(GetTickCount() - timer > 30) // The number placed there will alter the speed of execution
    {
          timer = GetTickCount();
          RunGameLoop();
    }
    Last edited by Lifedragn; 09-28-2004 at 11:54 PM.

  4. #4
    Registered User
    Join Date
    Sep 2004
    Posts
    27
    There's also a function called QueryPerformanceCounter() which I am told is more accurate, and allows higher frame rates than GetTickCount(). You may wish to look into that function as well. I've used Query all of twice, so I can't remember exactly how I applied it to locking my game execution speed.

    Also, on a sidenote... Doom III is framelocked at 60 frames per second. If you can squeeze that much performance out of the game, 60 fps will work well.

    When I say FPS, I am including execution cycles as well as drawing cycles.

  5. #5
    Registered User
    Join Date
    Sep 2004
    Posts
    3
    Using lifedragons thing i get these errors

    Compiler: Default compiler
    Building Makefile: "C:\Dev-Cpp\Programs\Makefile.win"
    Executing make...
    make.exe -f "C:\Dev-Cpp\Programs\Makefile.win" all
    g++.exe -c Platform.cpp -o Platform.o -I"C:/Dev-Cpp/include/c++" -I"C:/Dev-Cpp/include/c++/mingw32" -I"C:/Dev-Cpp/include/c++/backward" -I"C:/Dev-Cpp/include"

    Platform.cpp: In function `void _mangled_main()':
    Platform.cpp:102: error: ISO C++ forbids declaration of `DWORD' with no type
    Platform.cpp:102: error: syntax error before `=' token
    Platform.cpp:104: error: `GetTickCount' undeclared (first use this function)
    Platform.cpp:104: error: (Each undeclared identifier is reported only once for
    each function it appears in.)
    Platform.cpp:104: error: `timer' undeclared (first use this function)
    Platform.cpp:113: error: syntax error before `;' token

    Platform.cpp: At global scope:

    Platform.cpp:135: error: ISO C++ forbids declaration of `destroy_bitmap' with

    no type
    Platform.cpp:135: error: `int destroy_bitmap' redeclared as different kind of
    symbol
    C:/Dev-Cpp/include/allegro/gfx.h:361: error: previous declaration of `void
    destroy_bitmap(BITMAP*)'
    Platform.cpp:135: error: invalid conversion from `BITMAP*' to `int'
    Platform.cpp:136: error: ISO C++ forbids declaration of `allegro_exit' with no
    type

    Platform.cpp:136: error: new declaration `int allegro_exit()'
    C:/Dev-Cpp/include/allegro/system.h:66: error: ambiguates old declaration `void
    allegro_exit()'
    Platform.cpp:137: error: syntax error before `return'
    make.exe: *** [Platform.o] Error 1

    Execution terminated


    Whys that happening?
    Last edited by Superfrog; 09-29-2004 at 08:40 AM.

  6. #6
    Registered User
    Join Date
    Jul 2003
    Posts
    85
    did you #include <windows.h> ?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Execution Time - Rijandael encryption
    By gamer4life687 in forum C++ Programming
    Replies: 5
    Last Post: 09-20-2008, 09:25 PM
  2. Killing someones grandparents
    By nickname_changed in forum A Brief History of Cprogramming.com
    Replies: 37
    Last Post: 09-07-2003, 07:56 AM
  3. The Timing is incorret
    By Drew in forum C++ Programming
    Replies: 5
    Last Post: 08-28-2003, 04:57 PM
  4. Time delay function
    By sundeeptuteja in forum C++ Programming
    Replies: 4
    Last Post: 02-10-2003, 05:17 AM
  5. time class
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 12-11-2001, 10:12 PM