C function for RPG frame rate
I''m tryin to find a function i can use to control the frame rate in my RPG. Ive tried clock() but it wont work. In all the code ive seen the macro CLOCKS_PER_SEC isnt defined, but when i compile the code it says i need a definition (turbo C). Ive heard that its supposed to represent 1000000, but i tried this and still it didnt work. Keep in mind this is all written in REGULAR C...not C++. Anyone have any idea how i can accomplish a frame rate of between 40 and 60 fps? Any help with this is greatly appreciated.
-Dave
ca_priest@yahoo.com
I have written a good FPS and CPS counter routine, but it uses a millisecond timer from a third party api, which i dont know how to do.
Your first step is to find some timer code. I know in dos that requires the use of hooking some interrupt since the CPU clock only works on 18.6 tics a second (Not nearly fast enough for a game)
I have no freekin idea how to do anything with timers in windows. I am thinking the win32 api had some timer functions. If you are using OpenGL, i know it has a millisecond timer function.
- Twisted Matrix
Your first step is to find some timer code. I know in dos that requires the use of hooking some interrupt since the CPU clock only works on 18.6 tics a second (Not nearly fast enough for a game)
I have no freekin idea how to do anything with timers in windows. I am thinking the win32 api had some timer functions. If you are using OpenGL, i know it has a millisecond timer function.
- Twisted Matrix
OpenGL has no timer function. It''s only for graphical tasks.
The macro CLOCKS_PER_SEC should be defined in
The macro CLOCKS_PER_SEC should be defined in
time.h
, usually with the value 1000
because clock()
returns the number of milliseconds since application start.
In DOS, you can check port 0x3DA for the vertical retrace interval. It will give you a timer running synchronized with the display refresh (60Hz normally). You also avoid video-tearing if you do your drawing/flipping during this interval.
If I remember correctly it was like:
vret = inportb( 0x3DA ) & 8; // the flag is in bit3
Hope this is something you''re looking for.
If I remember correctly it was like:
vret = inportb( 0x3DA ) & 8; // the flag is in bit3
Hope this is something you''re looking for.
I tried and still for some reason...even with time.h included, the macro CLOCKS_PER_SEC isnt defined. I tried to define then as 1000, but still, no matter the length of time that passes, my output is always zero seconds. If i dont divide by CLOCKS_PER_SEC at all...then the output would be for example:
i count out 10 seconds in real time and when i check with the program it says .000194 microseconds passed. This is crazy. Im thinkin that when i divide the output by 1000 in hopes of getting actual seconds im making this number so small that its displayed as zero. Its like im getting a value returned as megaseconds instead of microseconds when use clock(). I checked my math and everything is fine. Get a starting time from any arbitrary period when you begin the loop, and wait as long as you like, then end the loop and get an ending time, subtract the starting time from the ending time and i should microseconds...but i get.000whatever...anyone know whats going wrong...like i said before this is regular old c and im using the turbo c compiler -Dave
ca_priest@yahoo.com
i count out 10 seconds in real time and when i check with the program it says .000194 microseconds passed. This is crazy. Im thinkin that when i divide the output by 1000 in hopes of getting actual seconds im making this number so small that its displayed as zero. Its like im getting a value returned as megaseconds instead of microseconds when use clock(). I checked my math and everything is fine. Get a starting time from any arbitrary period when you begin the loop, and wait as long as you like, then end the loop and get an ending time, subtract the starting time from the ending time and i should microseconds...but i get.000whatever...anyone know whats going wrong...like i said before this is regular old c and im using the turbo c compiler -Dave
ca_priest@yahoo.com
Please post your time-keeping code... (the rest won''t be needed).
[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions | Organising code files | My stuff ]
[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions | Organising code files | My stuff ]
What OS?
If you''re running in a DOS box, Windows ''lies'' about the time (long story).
You sure you''re not treating the output wrong? ((not)converting to float, etc.)
If you''re running in a DOS box, Windows ''lies'' about the time (long story).
You sure you''re not treating the output wrong? ((not)converting to float, etc.)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement