Is it possible to detect the game's actual framerate at runtime? I'm referring to the value shown on-screen with a Debug(4,1) call, except that I want to store it in a variable; I'm not referring to the target framerate found by GetGameSpeed().
My goal here is to automatically suspend a CPU-heavy routine if and when the game detects itself slowing down.
I can't find anything other than using the seconds of DateTime, that will give you a pretty low resolution, but should suffice to roughly detect the framerate.
As Khris states, AGS doesn't have a more precise timing mechanic than DateTime.RawTime, but you could track the exact FPS of the previous 1 second by simply updating a variable in rep_ex_always:
int fpsCounter = 0;
int lastFPS = 0;
DateTime *lastTime; // = null
function repeatedly_execute_always()
{
DateTime *now = DateTime.Now;
if (lastTime == null) lastTime = now;
if (lastTime.RawTime == now.RawTime) fpsCounter++;
else
{
lastFPS = fpsCounter;
lastTime = now;
fpsCounter = 1;
}
}
You could cache the results from this in a small array to get a blended average which may more accurately reflect minor changes, but the average itself would still only update once per second (as that's the only way to tell in-game that real-world time has actually passed).