/*: * @plugindesc (v1.2) Fixes various issues on high refresh rate monitors * @author Mac15001900 * * @help * This plugin fixes various issues on high refresh rate monitors. * No configuration is needed. * * ----------------------------------- Terms ------------------------------------ * * This plugin is available under the MIT Licence. You're free to use it in any * games, commercial or not, or use the code in your own plugins. Credit is * appreciated, but not required. If your credits include links, please link to * https://mac15001900.itch.io/ * */ var Imported = Imported || {}; Imported.MAC_High_Hz_Fixes = "1.2"; //Unfortunately, the above line was mistakenly missing in early versions of this plugin //If you need to detect the presence of those versions, try: SceneManager.updateMain.toString().includes("if (ranFrame)") //Removed FPS-related functions from SceneManager.update SceneManager.update = function () { try { // this.tickStart(); if (Utils.isMobileSafari()) { this.updateInputData(); } this.updateManagers(); this.updateMain(); // this.tickEnd(); } catch (e) { this.catchException(e); } }; //Added FPS-related functions here and changed renderScene to only be called when at least one logical frame happened SceneManager.updateMain = function () { let ranFrame = false; if (Utils.isMobileSafari()) { this.changeScene(); this.updateScene(); ranFrame = true; } else { var newTime = this._getTimeInMsWithoutMobileSafari(); var fTime = (newTime - this._currentTime) / 1000; if (fTime > 0.25) fTime = 0.25; this._currentTime = newTime; this._accumulator += fTime; while (this._accumulator >= this._deltaTime) { if (!ranFrame) this.tickStart(); ranFrame = true; this.updateInputData(); this.changeScene(); this.updateScene(); this._accumulator -= this._deltaTime; } if (ranFrame) this.tickEnd(); } if (ranFrame) this.renderScene(); this.requestUpdate(); }; //Fixed a rare graphics freeze that would happen when this._skipCount became negative, and removed frame counting Graphics.render = function (stage) { if (this._skipCount <= 0) { var startTime = Date.now(); if (stage) { this._renderer.render(stage); if (this._renderer.gl && this._renderer.gl.flush) { this._renderer.gl.flush(); } } var endTime = Date.now(); var elapsed = endTime - startTime; this._skipCount = Math.min(Math.floor(elapsed / 15), this._maxSkip); this._rendered = true; } else { this._skipCount--; this._rendered = false; } this.oldFrameCount = (this.oldFrameCount || 0) + 1; //This line replaces incrementing Graphics.frameCount }; //Moved framecounting here void ((alias) => { SceneManager.updateScene = function () { alias.call(this); Graphics.frameCount++; } })(SceneManager.updateScene); //Changing checkFreeze to use oldFrameCount Game_Interpreter.prototype.checkFreeze = function () { if (this._frameCount !== Graphics.oldFrameCount) { this._frameCount = Graphics.oldFrameCount; this._freezeChecker = 0; } if (this._freezeChecker++ >= 100000) { return true; } else { return false; } };