Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Game.registerMod('dethrottler', {
- init: function() {
- this.setup();
- window.dethrottlerModObj = this;
- Game.registerHook('logic', this.update);
- eval('Game.Loop='+Game.Loop.toString()
- .replace('setTimeout(Game.Loop,1000/Game.fps);', 'setTimeout(Game.Loop,Game.currentAvgFps / Game.fps * 1000 / Game.fps);')
- .replace('setTimeout(Game.Loop,Math.max(1000/Game.fps-(Date.now()-startTimestamp),0));', 'setTimeout(Game.Loop,Game.currentAvgFps / Game.fps * Math.max(1000/Game.fps-(Date.now()-startTimestamp),0));') //FPSTweaker support
- );
- },
- deltaTimeList: [],
- deltaTimeListMaxLength: 20 * Game.fps,
- setup: function() {
- for (let i = 0; i < this.deltaTimeListMaxLength; i++) {
- this.deltaTimeList.push(Game.fps);
- }
- },
- loop: function(t) {
- t.deltaTimeList.shift();
- t.deltaTimeList.push(t.getFps());
- //setTimeout(t.loop, 1 / Game.fps, t);
- },
- getAverage: function() {
- let a = 0;
- for (let i in this.deltaTimeList) {
- a += this.deltaTimeList[i];
- }
- a /= this.deltaTimeList.length;
- return a;
- },
- getFps: function() {
- return (Game.frameNumber/((Date.now()-Game.fpsStartTime)/1000)) + 3; //+3 is to mitigate overcorrecting
- },
- currentAvgFps: Game.fps,
- update: function() {
- dethrottlerModObj.loop(dethrottlerModObj);
- dethrottlerModObj.currentAvgFps = dethrottlerModObj.getAverage();
- Game.currentAvgFps = dethrottlerModObj.currentAvgFps;
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment