mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-16 13:53:12 +00:00
Optimize mover rendering and segment plan pipeline
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
import FastPriorityQueue from "fastpriorityqueue";
|
||||
|
||||
export type UnitMotionRenderQueueEntry = {
|
||||
unitId: number;
|
||||
version: number;
|
||||
priority: number;
|
||||
onScreenHint: boolean;
|
||||
};
|
||||
|
||||
export class UnitMotionRenderQueue {
|
||||
private queue = new FastPriorityQueue<UnitMotionRenderQueueEntry>(
|
||||
(a, b) => a.priority > b.priority,
|
||||
);
|
||||
|
||||
enqueue(entry: UnitMotionRenderQueueEntry): void {
|
||||
this.queue.add(entry);
|
||||
}
|
||||
|
||||
pollValid(
|
||||
isValid: (entry: UnitMotionRenderQueueEntry) => boolean,
|
||||
): UnitMotionRenderQueueEntry | null {
|
||||
while (!this.queue.isEmpty()) {
|
||||
const entry = this.queue.poll();
|
||||
if (!entry) {
|
||||
break;
|
||||
}
|
||||
if (isValid(entry)) {
|
||||
return entry;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
size(): number {
|
||||
return this.queue.size;
|
||||
}
|
||||
|
||||
clear(): void {
|
||||
this.queue = new FastPriorityQueue<UnitMotionRenderQueueEntry>(
|
||||
(a, b) => a.priority > b.priority,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user