Quote Originally Posted by jasonf
OK.. I just played with some numbers and I'm fairly sure it is..
fps = TicksPerSecond / ( CurrentTime - LastTime )
This is correct, the common function is: FPS = Slices/FrameTime whitch drops down to 1000 / (CurrentTime-LastTime) in most cases. Here is an implementation that we played with for our stuff:

[pascal]var
LastFrame : Cardinal;

function SystemGetTickCount() : Cardinal;
begin
result := -1;
{$IFDEF WIN32}
result := Windows.GetTickCount();
{$ENDIF}
{$IFDEF UNIX}
result := clock_gettime(CLOCK_MONOTONIC);
{$ENDIF}
end;

function GetFPS() : Cardinal;
var
CurrTime, FrameTime : Cardinal;
begin
CurrTime := SystemGetTickCount;
FrameTime := CurrTime-LastFrame;
if FrameTime < 0 then
FrameTime := (MaxCardinal-CurrTime)+LastFrame;
GetFPS := 1000 / FrameTime;
end;

// The render loop
begin
LastFrame := SystemGetTickCount;
// Setup stuff here
while GameRunning do
begin
// Rendering code goes here.
WriteLn('FPS: ', GetFPS);
LastFrame := SystemGetTickCount;
end;
end.[/pascal]

This seems to work fairly well, with the largest problem being that the first itteration is off, due to setup times and etc... Of course, I never left it up and running for the 49 days that it would take to find out if I screwed something up with the rollover stuff .