mainDrawLoop = {
initializeState;
camera.taint();
const simulate = ~opts.indexOf('Simulate');
let frame = regl.frame(() => {
try {
if (simulate) {
integrate({
src: state,
dst: tmpStateColumn,
srcColumn: mutable currentColumn,
dt,
t: mutable t
});
mutable t += dt;
mutable currentColumn = (mutable currentColumn + 1) % stepCount;
copyStateColumn({
src: tmpStateColumn,
dst: state,
dstColumn: mutable currentColumn
});
}
camera(({ dirty }) => {
// Only render if we're currently simulating or if the camera is moved
if (!simulate && !dirty) return;
regl.clear({ color: [1, 1, 1, 1], depth: 1 });
drawLines({
...lineData,
src: state,
texOffset: (mutable currentColumn - stepCount + 1) / stepCount
});
});
} catch (e) {
console.error(e);
frame && frame.cancel();
frame = null;
}
});
invalidation.then(() => {
frame && frame.cancel();
frame = null;
});
}