@lightningjs/renderer
Version:
Lightning 3 Renderer
58 lines • 1.93 kB
JavaScript
import { Platform } from '../Platform.js';
export class WebPlatform extends Platform {
////////////////////////
// Platform-specific methods
////////////////////////
createCanvas() {
const canvas = document.createElement('canvas');
return canvas;
}
getElementById(id) {
return document.getElementById(id);
}
////////////////////////
// Update loop
////////////////////////
startLoop(stage) {
let isIdle = false;
const runLoop = () => {
stage.updateFrameTime();
stage.updateAnimations();
if (!stage.hasSceneUpdates()) {
// We still need to calculate the fps else it looks like the app is frozen
stage.calculateFps();
setTimeout(runLoop, 16.666666666666668);
if (!isIdle) {
stage.shManager.cleanup();
stage.eventBus.emit('idle');
isIdle = true;
}
if (stage.txMemManager.checkCleanup() === true) {
stage.txMemManager.cleanup(false);
}
stage.flushFrameEvents();
return;
}
isIdle = false;
stage.drawFrame();
stage.flushFrameEvents();
requestAnimationFrame(runLoop);
};
requestAnimationFrame(runLoop);
}
////////////////////////
// ImageBitmap
////////////////////////
createImageBitmap(blob, sxOrOptions, sy, sw, sh, options) {
if (typeof sxOrOptions === 'number') {
return createImageBitmap(blob, sxOrOptions, sy ?? 0, sw ?? 0, sh ?? 0, options);
}
else {
return createImageBitmap(blob, sxOrOptions);
}
}
getTimeStamp() {
return performance ? performance.now() : Date.now();
}
}
//# sourceMappingURL=WebPlatform.js.map