Files
P42_godDaemons/GPS/collisionRegistry.js
2026-06-12 17:05:35 +00:00

40 lines
973 B
JavaScript

export class CollisionRegistry {
constructor() {
this.entries = []
}
purge(agentId) {
this.entries = this.entries.filter(
e => e.agentA !== agentId && e.agentB !== agentId
)
}
add(entry) {
const duplicate = this.entries.find(
e =>
(e.agentA === entry.agentA && e.agentB === entry.agentB) ||
(e.agentA === entry.agentB && e.agentB === entry.agentA)
)
if(duplicate) {
if(entry.time < duplicate.time) Object.assign(duplicate, entry)
return
}
this.entries.push(entry)
}
dueBefore(t) {
return(this.entries.filter(e => e.time <= t))
}
remove(entry) {
this.entries = this.entries.filter(
e =>
!((e.agentA === entry.agentA && e.agentB === entry.agentB) ||
(e.agentA === entry.agentB && e.agentB === entry.agentA))
)
}
}