import {System} from '@/ecs/index.js'; export default class Colliders extends System { static get priority() { return { after: 'MaintainColliderHash', }; } tick() { const checked = new Map(); for (const entity of this.ecs.changed(['Position'])) { if (!entity.Collider) { continue; } if (!checked.has(entity)) { checked.set(entity, new Set()); } const within = this.ecs.system('MaintainColliderHash').within(entity.Collider.aabb); for (const other of within) { if (entity === other || !other.Collider) { continue; } if (!checked.has(other)) { checked.set(other, new Set()); } if (checked.get(entity).has(other)) { continue; } checked.get(other).add(entity); entity.Collider.checkCollision(other.Collider); } for (const [other, intersections] of entity.Collider.$$intersections) { if (!within.has(this.ecs.get(other.entity))) { entity.Collider.endIntersections(other, intersections); } } } } }