mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-26 17:01:20 -08:00
fix(danmuku): [PKG-DANMUKU-12] keep frame sampling during async placement
This commit is contained in:
1 parent
df6a6fe82e
commit
4f559cb31d
20 files changed
+6192
-64
No files matched your search
@@ -0,0 +1,38 @@
|
||||
import type { DanmuItem } from './types'
|
||||
|
||||
// Sampling owns references only; the public state pools stay under Danmuku's control.
|
||||
export default class SchedulingBuffer {
|
||||
private pending = new Set<DanmuItem>()
|
||||
private reserved = new Set<DanmuItem>()
|
||||
|
||||
capture(items: DanmuItem[], failed: Set<DanmuItem>) {
|
||||
for (const item of items) {
|
||||
if (!this.reserved.has(item) && !failed.has(item))
|
||||
this.pending.add(item)
|
||||
}
|
||||
}
|
||||
|
||||
take() {
|
||||
const ready: DanmuItem[] = []
|
||||
const waiting: DanmuItem[] = []
|
||||
for (const item of this.pending) {
|
||||
if (item.$state === 'ready')
|
||||
ready.push(item)
|
||||
else if (item.$state === 'wait')
|
||||
waiting.push(item)
|
||||
}
|
||||
this.pending.clear()
|
||||
const batch = [...ready, ...waiting]
|
||||
this.reserved = new Set(batch)
|
||||
return batch
|
||||
}
|
||||
|
||||
complete() {
|
||||
this.reserved.clear()
|
||||
}
|
||||
|
||||
clear() {
|
||||
this.pending.clear()
|
||||
this.reserved.clear()
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user