platform game demo

Started by
12 comments, last by diskheadyXI 21 years, 9 months ago
so i take it no one anyware on gamedev.net has any clue if the above is correct or not
Advertisement
Your timer code is very wrong. You have to remember that you are dealing with 64-bit integers. Probably to maintain compatibility with future (and present) 64-bit CPUs that might run windows without the need to thunk. At the moment only the low 32-bits are utilised/needed. The book that you mentions only gives you a fluffy overview of what you need to do. I am not surprised that you are in difficulties.

Basically what you want to do is this:

1. Store the reciprocal of frequency. That is 1/frequency. Think of this as beats per second.

// Retrieve the frequency of the performance timer...
QueryPerformanceFrequency ( &Frequency );

// Store the reciprocal..
RecipFrequency = 1.0f / (float) ( Frequency.u.LowPart );


2. Once per frame query the time (measured in beats) and subtract this from the last time (measured in beats). Now you want to divide this result by the number of beats per second. You do this by multiplying by the reciprocal of frequency. [You could just divide by frequency but multiplication by the reciprocal is faster and gives the same result.] Now you have your frame time in seconds.

// What''s the time?
QueryPerformanceCounter ( &ThisFrameTime );

// Frame time is...
Frametime = ( ThisFrameTime.u.LowPart - LastFrameTime.u.LowPart ) * RecipFrequency;

// Store ThisFrameTime into LastFrameTime...
LastFrameTime = ThisFrameTime ;

I would advise you also to initialise LastFrameTime when you first calculate the reciprocal of frequency. This way when you first calculate frametime you will have a valid LastFrameTime to do the comparison with. Also remember that the frametime has a period and so every so often it will wrap around. You need to have a check for this to ensure that when this happens you handle it gracefully. The same goes for when you are using time GetTime.

Good luck
Kevin


thank you very much kevin (i thought you''d all abaondoned me )

I''ll get to work on that asap

all the best

Andy
Time for my bed. It''s very late here in the uk. Good luck.

Kevin

This topic is closed to new replies.

Advertisement