• Popular Now

• 13
• 15
• 19
• 27
• 9

Archived

This topic is now archived and is closed to further replies.

C function for RPG frame rate

This topic is 5586 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

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

Share on other sites
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

Share on other sites
OpenGL has no timer function. It''s only for graphical tasks.
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.

Share on other sites
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.

Share on other sites
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

Share on other sites
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.)