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.
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.
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();
static DWORD timer = GetTickCount();
if(GetTickCount() - timer > 30) // The number placed there will alter the speed of execution
timer = GetTickCount();
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.
Using lifedragons thing i get these errors
Compiler: Default compiler
Building Makefile: "C:\Dev-Cpp\Programs\Makefile.win"
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
Platform.cpp:135: error: `int destroy_bitmap' redeclared as different kind of
C:/Dev-Cpp/include/allegro/gfx.h:361: error: previous declaration of `void
Platform.cpp:135: error: invalid conversion from `BITMAP*' to `int'
Platform.cpp:136: error: ISO C++ forbids declaration of `allegro_exit' with no
Platform.cpp:136: error: new declaration `int allegro_exit()'
C:/Dev-Cpp/include/allegro/system.h:66: error: ambiguates old declaration `void
Platform.cpp:137: error: syntax error before `return'
make.exe: *** [Platform.o] Error 1
Whys that happening?
did you #include <windows.h> ?