Skip to content

Commit

Permalink
fix: restore destroy op (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
3mcd authored Jun 11, 2020
1 parent c235ae3 commit de36f73
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions packages/ecs/src/world.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ enum WorldOpType {

type CreateOp = [WorldOpType.Create, number, ReadonlyArray<Component>, number?]
type InsertOp = [WorldOpType.Insert, number, ReadonlyArray<Component>]
type DestroyOp = [WorldOpType.Destroy, number]

type WorldOp = CreateOp | InsertOp
type WorldOp = CreateOp | InsertOp | DestroyOp

export const createWorld = <T>(systems: System<T>[]): World<T> => {
const ops: WorldOp[] = []
Expand Down Expand Up @@ -79,6 +80,9 @@ export const createWorld = <T>(systems: System<T>[]): World<T> => {
storage.insert(op[1], ...(op[2] as Component[]))
break
}
case WorldOpType.Destroy:
destroyed.add(op[1])
break
default:
break
}
Expand Down Expand Up @@ -120,7 +124,12 @@ export const createWorld = <T>(systems: System<T>[]): World<T> => {
}

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) {
Expand Down

0 comments on commit de36f73

Please sign in to comment.