PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Sync game speed using frame rate ratio ?

I want to sync my game speed using Warmi's formula. Am I doing it right?

Code:

//FLOAT nFrameRate = 0;
//m_timer.GetActualFrameRate(&nFrameRate;);

int GameSpeedX = 0;
int DEF_TARGET_FPS = 40;
FLOAT nActualFrameTime = 0;

m_timer.GetActualFrameTime(&nActualFrameTime;);

int FrameRateRatio = int( DEF_TARGET_FPS/nActualFrameTime);

GameSpeedX += (GameSpeedX*FrameRateRatio);




I cant find a good function to round off the value.
To round, add 0.5 then truncate (by casting to int).

This won't work for negative numbers, and doesn't do the "round 0.5 to even" behaviour that statisticians love, but it will work.
http://www.scalenesoftware.com/
First title coming soon!


Wow, too much action :-) Goodluck!


--- sync ---

I'm just confused with the int and float for my animation hehehe. Pls post any code if you have any using the technq above. Thanks.
denthorq wrote:
http://www.scalenesoftware.com/
First title coming soon!


Wow, too much action :-) Goodluck!


Thanks. It's coming along but a lot of work. :-)


I'm just confused with the int and float for my animation hehehe. Pls post any code if you have any using the technq above. Thanks.


To round, do this:

Code:

float f1 = 3.14;
float f2 = 4.87;
float f3 = 5.5;
int n1 = f1 + 0.5; // 3.64 -> 3
int n2 = f2 + 0.5; // 5.37 -> 5
int n3 = f3 + 0.5; // 6.0 -> 6


But do make it an inline function, don't just do it in place.

For negative numbers, you have to subtract instead of add because of the way truncation (when casting to int) works. To round 0.5 to even is even more complicated.

I don't know about the algorithm to vary the frame rate, my frame rate is currently fixed.