Update to use new SDF2D version
This commit is contained in:
parent
f0a9c1df68
commit
9062ae04a3
14 changed files with 160 additions and 209 deletions
41
src/index.ts
41
src/index.ts
|
|
@ -7,22 +7,18 @@ import '../static/logo-white.svg';
|
|||
import '../static/no-change/404.html';
|
||||
import '../static/no-change/robots.txt';
|
||||
import '../static/og-image.png';
|
||||
import { DeltaTimeCalculator } from './helper/delta-time-calculator';
|
||||
import { removeUnnecessaryOutlines } from './helper/remove-unnecessary-outlines';
|
||||
import { BlobScene } from './scenes/blob/blob-scene';
|
||||
import { MetaballScene } from './scenes/metaball/metaball-scene';
|
||||
import { RainScene } from './scenes/rain/rain-scene';
|
||||
import { Scene } from './scenes/scene';
|
||||
import { TunnelScene } from './scenes/tunnel-scene';
|
||||
import './styles/index.scss';
|
||||
|
||||
const scenes = [TunnelScene, MetaballScene, RainScene, BlobScene];
|
||||
const sceneIntervalInSeconds = 8;
|
||||
|
||||
glMatrix.setMatrixArrayType(Array);
|
||||
removeUnnecessaryOutlines();
|
||||
|
||||
const deltaTimeCalculator = new DeltaTimeCalculator();
|
||||
const canvas = document.querySelector('canvas') as HTMLCanvasElement;
|
||||
const errorText = document.querySelector('#error-text') as HTMLParamElement;
|
||||
const errorsContainer = document.querySelector('#errors-container') as HTMLDivElement;
|
||||
|
|
@ -43,44 +39,13 @@ const handleTextToggle = () => {
|
|||
toggleButton.addEventListener('click', handleTextToggle);
|
||||
handleTextToggle();
|
||||
|
||||
const handleScene = async (
|
||||
currentScene: Scene,
|
||||
NextSceneConstructor: new () => Scene
|
||||
): Promise<Scene> => {
|
||||
let triggerIsOver: () => void;
|
||||
const isOver = new Promise((resolve) => (triggerIsOver = resolve));
|
||||
let timeSinceStart = 0;
|
||||
|
||||
const handleFrame = (currentTime: DOMHighResTimeStamp) => {
|
||||
const deltaTime = deltaTimeCalculator.getNextDeltaTime(currentTime);
|
||||
|
||||
currentScene.drawNextFrame(currentTime, deltaTime);
|
||||
|
||||
if ((timeSinceStart += deltaTime) > sceneIntervalInSeconds * 1000) {
|
||||
triggerIsOver();
|
||||
} else {
|
||||
requestAnimationFrame(handleFrame);
|
||||
}
|
||||
};
|
||||
|
||||
requestAnimationFrame(handleFrame);
|
||||
|
||||
await isOver;
|
||||
currentScene.destroy();
|
||||
|
||||
const nextScene = new NextSceneConstructor();
|
||||
await nextScene.initialize(canvas, overlay);
|
||||
|
||||
return nextScene;
|
||||
};
|
||||
|
||||
const main = async () => {
|
||||
try {
|
||||
let i = 0;
|
||||
let currentScene: Scene = new scenes[i++]();
|
||||
await currentScene.initialize(canvas, overlay);
|
||||
for (;;) {
|
||||
currentScene = await handleScene(currentScene, scenes[i++ % scenes.length]);
|
||||
const currentScene = new scenes[i++ % scenes.length]();
|
||||
|
||||
await currentScene.run(canvas, overlay);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue