Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 2 additions & 20 deletions src/engine/ecs/World.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ export class World {
/** Generational entity ID allocator - handles ID recycling with stale reference detection */
private entityIdAllocator: EntityIdAllocator = new EntityIdAllocator(MAX_ENTITIES);

// Component storage for faster queries (kept for backwards compatibility)
private componentIndex: Map<ComponentType, Set<EntityId>> = new Map();

// ARCHETYPE SYSTEM: Group entities by component signature
private archetypes: Map<string, Archetype> = new Map(); // signature → Archetype
private entityArchetype: Map<EntityId, string> = new Map(); // entityId → signature
Expand Down Expand Up @@ -103,11 +100,6 @@ export class World {
// Remove from archetype (uses full EntityId for archetype tracking)
this.removeEntityFromArchetype(entity.id);

// Remove from component indices (kept for backwards compatibility)
for (const [type, entityIds] of this.componentIndex) {
entityIds.delete(entity.id);
}

// Mark entity as destroyed
entity.destroy();
this.entities.delete(index);
Expand Down Expand Up @@ -367,13 +359,7 @@ export class World {
}

// Called by Entity when a component is added
public onComponentAdded(entityId: EntityId, type: ComponentType): void {
// Update component index (kept for backwards compatibility)
if (!this.componentIndex.has(type)) {
this.componentIndex.set(type, new Set());
}
this.componentIndex.get(type)!.add(entityId);

public onComponentAdded(entityId: EntityId, _type: ComponentType): void {
// Update archetype - entity's component signature has changed
const index = getEntityIndex(entityId);
const entity = this.entities.get(index);
Expand All @@ -386,10 +372,7 @@ export class World {
}

// Called by Entity when a component is removed
public onComponentRemoved(entityId: EntityId, type: ComponentType): void {
// Update component index (kept for backwards compatibility)
this.componentIndex.get(type)?.delete(entityId);

public onComponentRemoved(entityId: EntityId, _type: ComponentType): void {
// Update archetype - entity's component signature has changed
const entity = this.entities.get(getEntityIndex(entityId));
if (entity && !entity.isDestroyed()) {
Expand All @@ -399,7 +382,6 @@ export class World {

public clear(): void {
this.entities.clear();
this.componentIndex.clear();
this.archetypes.clear();
this.entityArchetype.clear();
this.queryCache.clear();
Expand Down