Skip to content

Instantly share code, notes, and snippets.

@tabularelf
Last active September 10, 2023 16:59
Show Gist options
  • Save tabularelf/7fe8c87e993bbc23a1c7665e626e65fb to your computer and use it in GitHub Desktop.
Save tabularelf/7fe8c87e993bbc23a1c7665e626e65fb to your computer and use it in GitHub Desktop.
An alternative FPS counter that even your shaders can now impact
/* TabularElf made this!
Use case:
Insert fpsClock().tick(); within the begin step event of your game management object. (And never in a loop)
You may retrieve the FPS value by calling fpsClock() anytime to return a string value of the FPS.
*/
function __getFPSClockSingleton() {
static _clockStruct = new (function() constructor {
static __FPSMain = game_get_speed(gamespeed_fps);
static __AFT = game_get_speed(gamespeed_microseconds);
static __Time = get_timer();
static __oldTime = 0;
static __nFrames = 0;
static __prevFPS = 0;
static __nextFrame = __Time;
static tick = function() {
var _currentTime = get_timer();
if (_currentTime > __nextFrame) {
__nextFrame = _currentTime+1000;
++__nFrames;
if (_currentTime - __Time > 1000000) {
var _oldTime = __Time;
__Time = _currentTime;
__prevFPS = min(__nFrames, __FPSMain);
__nFrames = 0;
}
}
return self;
}
static setFPS = function(_fps, _type) {
game_set_speed(_fps, _type);
static __FPSMain = game_get_speed(gamespeed_fps);
static __AFT = game_get_speed(gamespeed_microseconds);
}
static toString = function() {
return string(__prevFPS);
}
})();
return _clockStruct;
}
function fpsClock() {
return __getFPSClockSingleton();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment