新增identifierPool用于实体id复用
This commit is contained in:
22
source/src/ECS/Utils/IdentifierPool.ts
Normal file
22
source/src/ECS/Utils/IdentifierPool.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
module es {
|
||||
export class IdentifierPool {
|
||||
private ids: Bag<number>;
|
||||
private nextAvailableId_ = 0;
|
||||
|
||||
constructor() {
|
||||
this.ids = new Bag<number>();
|
||||
}
|
||||
|
||||
public checkOut(): number {
|
||||
if (this.ids.size() > 0) {
|
||||
return this.ids.removeLast();
|
||||
}
|
||||
|
||||
return this.nextAvailableId_++;
|
||||
}
|
||||
|
||||
public checkIn(id: number): void {
|
||||
this.ids.add(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user