progress on scrubbers. pending tick boundary handling fix

This commit is contained in:
2026-07-05 22:53:42 -04:00
parent 5a201f0cfd
commit 71e29b92b2
3 changed files with 269 additions and 116 deletions

View File

@@ -15,7 +15,6 @@ export class World {
this.labels = new Map();
this.initialState = new Map();
this.initialIndex = 0;
this.eventCount = 0;
if (script) {
this.#compile(script);
@@ -123,8 +122,6 @@ export class World {
}
if (!capturedInitialState) captureInitial();
this.eventCount = this.events.length - this.initialIndex;
}
}
@@ -170,13 +167,13 @@ export class WorldFrame {
if (typeof target === 'string') {
const absoluteIdx = this.world.labels.get(target);
if (absoluteIdx === undefined) throw new Error(`Label not found: ${target}`);
this.seekIndex(absoluteIdx - this.world.initialIndex);
this.seekIndex(absoluteIdx);
return;
}
let changed = false;
while (this.currentIndex < this.world.events.length && this.world.events[this.currentIndex].time <= targetTime) {
while (this.currentIndex < this.world.events.length && this.world.events[this.currentIndex].time < targetTime) {
const batch = this.world.events[this.currentIndex];
for (const action of batch.actions) {
this.#apply(action.next, action.x, action.y, action.z);
@@ -185,7 +182,7 @@ export class WorldFrame {
changed = true;
}
while (this.currentIndex > 0 && this.world.events[this.currentIndex - 1].time > targetTime) {
while (this.currentIndex > this.world.initialIndex && this.world.events[this.currentIndex - 1].time >= targetTime) {
this.currentIndex--;
const batch = this.world.events[this.currentIndex];
for (let i = batch.actions.length - 1; i >= 0; i--) {
@@ -199,8 +196,8 @@ export class WorldFrame {
if (changed) this.notify();
}
seekIndex(targetIndex) {
targetIndex = targetIndex + this.world.initialIndex;
seekIndex(absoluteIndex) {
let targetIndex = Math.max(this.world.initialIndex, Math.min(this.world.events.length, absoluteIndex));
let changed = false;
while (this.currentIndex < this.world.events.length && this.currentIndex < targetIndex) {