fix: 全局灯条颜色发布协程未能等待下一个截图完成,导致性能缺陷。

This commit is contained in:
2023-04-01 18:39:51 +08:00
parent 56137b52a5
commit 47e30ec94a
4 changed files with 176 additions and 125 deletions

View File

@ -18,34 +18,16 @@ const SorterItem: Component<{ mapper: LedStripPixelMapper; strip: LedStripConfig
const [fullLeds, setFullLeds] = createSignal<string[]>([]);
createEffect(() => {
let stopped = false;
const frame = () => {
untrack(() => {
const strips = ledStripStore.strips;
const totalLedCount = strips.reduce((acc, strip) => acc + strip.len, 0);
const fullLeds = new Array(totalLedCount).fill('rgba(255,255,255,0.5)');
const strips = ledStripStore.strips;
const totalLedCount = strips.reduce((acc, strip) => acc + strip.len, 0);
const fullLeds = new Array(totalLedCount).fill('rgba(255,255,255,0.5)');
for (let i = props.mapper.start, j = 0; i < props.mapper.end; i++, j++) {
fullLeds[i] = `rgb(${ledStripStore.colors[i * 3]}, ${
ledStripStore.colors[i * 3 + 1]
}, ${ledStripStore.colors[i * 3 + 2]})`;
}
setFullLeds(fullLeds);
});
if (!stopped) {
setTimeout(() => {
frame();
}, 1000);
}
};
frame();
onCleanup(() => {
console.log('cleanup');
stopped = true;
});
for (let i = props.mapper.start, j = 0; i < props.mapper.end; i++, j++) {
fullLeds[i] = `rgb(${ledStripStore.colors[i * 3]}, ${
ledStripStore.colors[i * 3 + 1]
}, ${ledStripStore.colors[i * 3 + 2]})`;
}
setFullLeds(fullLeds);
});
return (