mirror of
https://codeberg.org/ashley/poke.git
synced 2024-11-26 10:18:12 +01:00
test 4
This commit is contained in:
parent
cb67431323
commit
9e3eeb277e
1 changed files with 7 additions and 22 deletions
|
@ -2116,39 +2116,24 @@ const baseFrameIntervalMs = 500;
|
||||||
let intervalId;
|
let intervalId;
|
||||||
let oddFrame = true;
|
let oddFrame = true;
|
||||||
|
|
||||||
const getCoreCount = () => navigator.hardwareConcurrency || 2;
|
const getFrameInterval = () => {
|
||||||
|
const coreCount = navigator.hardwareConcurrency || 2;
|
||||||
const getOptimizedInterval = () => {
|
|
||||||
const coreCount = getCoreCount();
|
|
||||||
return Math.max(baseFrameIntervalMs / coreCount, 33);
|
return Math.max(baseFrameIntervalMs / coreCount, 33);
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateCanvasSize = () => {
|
|
||||||
const coreCount = getCoreCount();
|
|
||||||
const size = Math.min(1000, 800 / coreCount);
|
|
||||||
oddCanvas.style.width = evenCanvas.style.width = `${size}px`;
|
|
||||||
oddCanvas.style.height = evenCanvas.style.height = `${size * 0.75}px`;
|
|
||||||
};
|
|
||||||
|
|
||||||
const drawFrame = () => {
|
const drawFrame = () => {
|
||||||
const ctx = oddFrame ? oddCtx : evenCtx;
|
const ctx = oddFrame ? oddCtx : evenCtx;
|
||||||
const canvas = oddFrame ? oddCanvas : evenCanvas;
|
const canvas = oddFrame ? oddCanvas : evenCanvas;
|
||||||
|
|
||||||
ctx.drawImage(AMvideo, 0, 0, canvas.width, canvas.height);
|
ctx.drawImage(AMvideo, 0, 0, canvas.width, canvas.height);
|
||||||
|
oddCanvas.style.opacity = oddFrame ? canvasOpacity : "0";
|
||||||
if (oddFrame) {
|
evenCanvas.style.opacity = oddFrame ? "0" : canvasOpacity;
|
||||||
oddCanvas.style.opacity = canvasOpacity;
|
|
||||||
evenCanvas.style.opacity = "0";
|
|
||||||
} else {
|
|
||||||
evenCanvas.style.opacity = canvasOpacity;
|
|
||||||
oddCanvas.style.opacity = "0";
|
|
||||||
}
|
|
||||||
|
|
||||||
oddFrame = !oddFrame;
|
oddFrame = !oddFrame;
|
||||||
};
|
};
|
||||||
|
|
||||||
const drawStart = () => {
|
const drawStart = () => {
|
||||||
const frameIntervalMs = getOptimizedInterval();
|
const frameIntervalMs = getFrameInterval();
|
||||||
intervalId = setInterval(drawFrame, frameIntervalMs);
|
intervalId = setInterval(drawFrame, frameIntervalMs);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -2159,12 +2144,11 @@ const drawPause = () => {
|
||||||
const init = () => {
|
const init = () => {
|
||||||
AMvideo.pause();
|
AMvideo.pause();
|
||||||
AMvideo.play();
|
AMvideo.play();
|
||||||
updateCanvasSize();
|
|
||||||
AMvideo.addEventListener("play", drawStart, false);
|
AMvideo.addEventListener("play", drawStart, false);
|
||||||
AMvideo.addEventListener("pause", drawPause, false);
|
AMvideo.addEventListener("pause", drawPause, false);
|
||||||
AMvideo.addEventListener("ended", drawPause, false);
|
AMvideo.addEventListener("ended", drawPause, false);
|
||||||
|
|
||||||
const frameIntervalMs = getOptimizedInterval();
|
const frameIntervalMs = getFrameInterval();
|
||||||
oddCanvas.style.transition = evenCanvas.style.transition = `opacity ${frameIntervalMs}ms`;
|
oddCanvas.style.transition = evenCanvas.style.transition = `opacity ${frameIntervalMs}ms`;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -2178,6 +2162,7 @@ const cleanup = () => {
|
||||||
window.addEventListener("load", init);
|
window.addEventListener("load", init);
|
||||||
window.addEventListener("unload", cleanup);
|
window.addEventListener("unload", cleanup);
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
<style>
|
<style>
|
||||||
.video-player-container, #video {
|
.video-player-container, #video {
|
||||||
|
|
Loading…
Reference in a new issue