animation and frame rate in C

Started by
5 comments, last by ca_priest 21 years, 4 months ago
Ive been developing an rpg written entirely from the ground up in C...and so far its come along nicely except theres no animation...the player can walk around skipping from tile to tile without taking steps...and the creatures and NPC''s just stand there. It''s too boring...so i now i need motion. I tried clock()...but it doesnt work...in most examples ive seen a macro ( CLOCKS_PER_SEC ) is used but not defined in the program. If i try this is gives an error and says it is undefined. I then hear its value is 1000000, but even if i define it as this...it still wont work. So what i need now is some sort of way to time my game so i can get at least 40 fps animation. I guess im looking for some kind of time function etc. Note: this is all done in old school C...not c++. Ive tried for weeks to get an answer for this i can find no where. Please for the love of god someone help me. Thanks. -Dave ca_priest@yahoo.com
...and that's where I saw the leprechaun...he told me to burn things.
Advertisement
#include <time.h> that''ll give u them macros and clock things.

note, in windows at least, the clock thing isnt that accurate so your timestep calculations should be sampled over several seconds in my opinion.

----------------------------
http://www.digitalsentience.pwp.blueyonder.co.uk
The whole problem is that when i compile the program ( in turbo c )...with time.h included, it still says that the macro is undefined...i wouldve though that it would be defined in time.h but apparently not...thanks anyway for the help
...and that's where I saw the leprechaun...he told me to burn things.
If you are using windows, you can use the function float timeGetTime(). I have found it extreely helpful and is the tier that i love. All of the other ones retun the time in soe goofy structure... something like t_time and stuff...

check out the function here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/multimed/mmfunc_2q3p.asp

hope that helps

btw, youll need to include windows.h and prolly want to #define WIN32_LEAN_AND_MEAN which excludes rarely used winows stuff...

tazzel3d ~ dwiel
Try CLK_TCK. You can also try a different compiler like mingw or borland''s free compiler if it doesn''t work.
Turbo C IDE has a quite useful help if you just want to look something up.
I scrounged this up from my one of my old DOS games. I think I gad a better one though, oh well.


        typedef unsigned short WORD;WORD *clock=(WORD *)0x0000046C;    /* this points to the 18.2hz system clock. */WORD Tick(){  WORD curClock;  curClock = *clock; /*get current clock value */  *clock = *clock;  /*update  value */  return curClock;}        


[edited by - Daerax on November 21, 2002 10:57:57 PM]

[edited by - Daerax on November 21, 2002 10:58:58 PM]

[edited by - Daerax on November 21, 2002 11:00:32 PM]
Im pretty sure i want to use timeGetTime(). However im sure how to structure the code. Id use the example from above but i dont know if that would provide smooth animation...i was thinking 40 to 60 fps. I read that timeGetTime returns a DWORD value. Does this mean i declare variables as follows:
DWORD start_time, end_time;.........? or do i declare them as float variables, etc.?


dave
ca_priest@yahoo.com
...and that's where I saw the leprechaun...he told me to burn things.

This topic is closed to new replies.

Advertisement