first GodDaemons group commit
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
|
||||
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))
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user