Created
November 5, 2014 00:38
-
-
Save arjankuijpers/be1589fe851cf9996b3b to your computer and use it in GitHub Desktop.
fps / tick counter with settable average, ported it from somebody (on the web) that wrote it in a typesafe language..
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//cant use const because of IE9, IE9 does not support const. | |
var MAXSAMPLES = 100; | |
var tickindex=0 | |
var ticksum=0; | |
var ticklist = []; | |
for(var i = 0; i < MAXSAMPLES; i++) | |
{ | |
ticklist[i] = 0; | |
} | |
var CalcAverageTick = function(newtick) | |
{ | |
ticksum-=ticklist[tickindex]; /* subtract value falling off */ | |
ticksum+=newtick; /* add new value */ | |
ticklist[tickindex]=newtick; /* save new value so it can be subtracted later */ | |
if(++tickindex==MAXSAMPLES) /* inc buffer index */ | |
tickindex=0; | |
/* return average */ | |
return(ticksum/MAXSAMPLES); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment