新增identifierPool用于实体id复用
This commit is contained in:
Vendored
+11
-2
@@ -234,7 +234,6 @@ declare module es {
|
||||
compare(self: Entity, other: Entity): number;
|
||||
}
|
||||
class Entity implements IEqualityComparable {
|
||||
static _idGenerator: number;
|
||||
static entityComparer: IComparer<Entity>;
|
||||
/**
|
||||
* 当前实体所属的场景
|
||||
@@ -261,7 +260,7 @@ declare module es {
|
||||
*/
|
||||
updateInterval: number;
|
||||
componentBits: Bits;
|
||||
constructor(name: string);
|
||||
constructor(name: string, id: number);
|
||||
_isDestroyed: boolean;
|
||||
/**
|
||||
* 如果调用了destroy,那么在下一次处理实体之前这将一直为true
|
||||
@@ -651,6 +650,7 @@ declare module es {
|
||||
*/
|
||||
readonly entityProcessors: EntityProcessorList;
|
||||
readonly _sceneComponents: SceneComponent[];
|
||||
readonly identifierPool: IdentifierPool;
|
||||
private _didSceneBegin;
|
||||
constructor();
|
||||
/**
|
||||
@@ -1863,6 +1863,15 @@ declare module es {
|
||||
static getHashCode(str: any): number;
|
||||
}
|
||||
}
|
||||
declare module es {
|
||||
class IdentifierPool {
|
||||
private ids;
|
||||
private nextAvailableId_;
|
||||
constructor();
|
||||
checkOut(): number;
|
||||
checkIn(id: number): void;
|
||||
}
|
||||
}
|
||||
declare module es {
|
||||
class Matcher {
|
||||
protected allSet: (new (...args: any[]) => Component)[];
|
||||
|
||||
+25
-4
@@ -600,7 +600,7 @@ var es;
|
||||
}());
|
||||
es.EntityComparer = EntityComparer;
|
||||
var Entity = /** @class */ (function () {
|
||||
function Entity(name) {
|
||||
function Entity(name, id) {
|
||||
/**
|
||||
* 指定应该调用这个entity update方法的频率。1表示每一帧,2表示每一帧,以此类推
|
||||
*/
|
||||
@@ -612,7 +612,7 @@ var es;
|
||||
this.transform = new es.Transform(this);
|
||||
this.componentBits = new es.Bits();
|
||||
this.name = name;
|
||||
this.id = Entity._idGenerator++;
|
||||
this.id = id;
|
||||
}
|
||||
Object.defineProperty(Entity.prototype, "isDestroyed", {
|
||||
/**
|
||||
@@ -896,6 +896,7 @@ var es;
|
||||
*/
|
||||
Entity.prototype.destroy = function () {
|
||||
this._isDestroyed = true;
|
||||
this.scene.identifierPool.checkIn(this.id);
|
||||
this.scene.entities.remove(this);
|
||||
this.transform.parent = null;
|
||||
// 销毁所有子项
|
||||
@@ -1056,7 +1057,6 @@ var es;
|
||||
Entity.prototype.toString = function () {
|
||||
return "[Entity: name: " + this.name + ", tag: " + this.tag + ", enabled: " + this.enabled + ", depth: " + this.updateOrder + "]";
|
||||
};
|
||||
Entity._idGenerator = 0;
|
||||
Entity.entityComparer = new EntityComparer();
|
||||
return Entity;
|
||||
}());
|
||||
@@ -1431,6 +1431,7 @@ var es;
|
||||
this._sceneComponents = [];
|
||||
this.entities = new es.EntityList(this);
|
||||
this.entityProcessors = new es.EntityProcessorList();
|
||||
this.identifierPool = new es.IdentifierPool();
|
||||
this.initialize();
|
||||
}
|
||||
/**
|
||||
@@ -1532,7 +1533,7 @@ var es;
|
||||
* @param name
|
||||
*/
|
||||
Scene.prototype.createEntity = function (name) {
|
||||
var entity = new es.Entity(name);
|
||||
var entity = new es.Entity(name, this.identifierPool.checkOut());
|
||||
return this.addEntity(entity);
|
||||
};
|
||||
/**
|
||||
@@ -4448,6 +4449,26 @@ var es;
|
||||
es.HashHelpers = HashHelpers;
|
||||
})(es || (es = {}));
|
||||
var es;
|
||||
(function (es) {
|
||||
var IdentifierPool = /** @class */ (function () {
|
||||
function IdentifierPool() {
|
||||
this.nextAvailableId_ = 0;
|
||||
this.ids = new es.Bag();
|
||||
}
|
||||
IdentifierPool.prototype.checkOut = function () {
|
||||
if (this.ids.size() > 0) {
|
||||
return this.ids.removeLast();
|
||||
}
|
||||
return this.nextAvailableId_++;
|
||||
};
|
||||
IdentifierPool.prototype.checkIn = function (id) {
|
||||
this.ids.add(id);
|
||||
};
|
||||
return IdentifierPool;
|
||||
}());
|
||||
es.IdentifierPool = IdentifierPool;
|
||||
})(es || (es = {}));
|
||||
var es;
|
||||
(function (es) {
|
||||
var Matcher = /** @class */ (function () {
|
||||
function Matcher() {
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user