From de36f73df579cd071f57d79de1c85dd7106f4999 Mon Sep 17 00:00:00 2001 From: Eric McDaniel Date: Thu, 11 Jun 2020 12:49:43 -0400 Subject: [PATCH] fix: restore destroy op (#41) --- packages/ecs/src/world.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/ecs/src/world.ts b/packages/ecs/src/world.ts index 2d368b8c..5cf9e4fb 100644 --- a/packages/ecs/src/world.ts +++ b/packages/ecs/src/world.ts @@ -36,8 +36,9 @@ enum WorldOpType { type CreateOp = [WorldOpType.Create, number, ReadonlyArray, number?] type InsertOp = [WorldOpType.Insert, number, ReadonlyArray] +type DestroyOp = [WorldOpType.Destroy, number] -type WorldOp = CreateOp | InsertOp +type WorldOp = CreateOp | InsertOp | DestroyOp export const createWorld = (systems: System[]): World => { const ops: WorldOp[] = [] @@ -79,6 +80,9 @@ export const createWorld = (systems: System[]): World => { storage.insert(op[1], ...(op[2] as Component[])) break } + case WorldOpType.Destroy: + destroyed.add(op[1]) + break default: break } @@ -120,7 +124,12 @@ export const createWorld = (systems: System[]): World => { } function destroy(entity: number) { - destroyed.add(entity) + const op = opPool.retain() as DestroyOp + + op[0] = WorldOpType.Destroy + op[1] = entity + + ops.push(op) } function isEphemeral(entity: number) {