Keep running in background

This commit is contained in:
u3shit 2024-03-16 18:57:33 +01:00
parent 71a607698a
commit 213d8b3ee9
2 changed files with 30 additions and 5 deletions
BondageClub/Scripts

View file

@ -5,6 +5,8 @@ var GameVersion = "R102";
const GameVersionFormat = /^R([0-9]+)(?:(Alpha|Beta)([0-9]+)?)?$/;
var GameWorker = null;
var CommonVersionUpdated = false;
/** @type {TouchList | null} */
@ -45,12 +47,36 @@ function GameStart() {
canvas.addEventListener("touchmove", GameTouchMove);
canvas.addEventListener("touchend", GameTouchEnd);
requestAnimationFrame(GameRun);
requestAnimationFrame(GameAnimationFrame);
// Can't use setInterval, chrome throttles it to 1 minute on inactive pages, but not in workers...
GameWorker = new Worker("Scripts/GameWorker.js");
GameWorker.onmessage = GameFallbackTimer;
}
// When the code is loaded, we start the game engine
window.addEventListener("load", GameStart);
/**
* Callback to requestAnimationFrame.
* @param {number} Timestamp
* @returns {void}
*/
function GameAnimationFrame(Timestamp) {
GameRun(Timestamp);
requestAnimationFrame(GameAnimationFrame);
}
/**
* Periodically called in the background with low frequency, so the game doesn't freeze, even if the user switches to a different tab.
* @returns {void}
*/
function GameFallbackTimer() {
let Timestamp = performance.now();
if (Timestamp - TimerLastTime > 500) {
GameRun(Timestamp);
}
}
/**
* Main game running state, runs the drawing
* @param {number} Timestamp
@ -67,8 +93,6 @@ function GameRun(Timestamp) {
TimerProcess();
ServerSendQueueProcess();
requestAnimationFrame(MainRun);
}
/**
@ -207,8 +231,6 @@ function GameMouseLeave(event) {
/** @deprecated */
function KeyDown(event) { GameKeyDown(event); }
/** @deprecated */
function MainRun(Timestamp) { GameRun(Timestamp); }
/** @deprecated */
function Click(event) { if (!CommonIsMobile) { CommonClick(event); } }
/** @deprecated */
function LoseFocus(event) { GameMouseLeave(event); }

View file

@ -0,0 +1,3 @@
"use strict";
setInterval(() => postMessage(null), 1000);