diff --git a/source/bin/gs.d.ts b/source/bin/gs.d.ts index 6244a8d..dafc069 100644 --- a/source/bin/gs.d.ts +++ b/source/bin/gs.d.ts @@ -97,6 +97,9 @@ declare module gs { } } declare module gs { + /** + * 实体类,用于管理实体的组件和标签。 + */ class Entity { private id; private componentManagers; @@ -136,6 +139,10 @@ declare module gs { * @returns */ hasComponent(componentType: new (entityId: number) => T): boolean; + /** + * 清除组件缓存 + */ + clearComponentCache(): void; /** * 添加标签 * @param tag diff --git a/source/bin/gs.js b/source/bin/gs.js index a0ae8cd..e11bca2 100644 --- a/source/bin/gs.js +++ b/source/bin/gs.js @@ -289,6 +289,9 @@ var gs; })(gs || (gs = {})); var gs; (function (gs) { + /** + * 实体类,用于管理实体的组件和标签。 + */ var Entity = /** @class */ (function () { function Entity(id, entityManager, componentManagers) { // 缓存获取的组件 @@ -353,25 +356,10 @@ var gs; * @returns */ Entity.prototype.getAllComponents = function () { - var e_3, _a; - var components = []; - try { - for (var _b = __values(this.componentManagers), _c = _b.next(); !_c.done; _c = _b.next()) { - var _d = __read(_c.value, 2), manager = _d[1]; - var component = manager.get(this.id); - if (component) { - components.push(component); - } - } - } - catch (e_3_1) { e_3 = { error: e_3_1 }; } - finally { - try { - if (_c && !_c.done && (_a = _b.return)) _a.call(_b); - } - finally { if (e_3) throw e_3.error; } - } - return components; + var _this = this; + return Array.from(this.componentManagers.values()) + .map(function (manager) { return manager.get(_this.id); }) + .filter(function (component) { return component !== null; }); }; /** * 移除组件 @@ -404,6 +392,12 @@ var gs; var manager = this.componentManagers.get(componentType); return manager ? manager.has(this.id) : false; }; + /** + * 清除组件缓存 + */ + Entity.prototype.clearComponentCache = function () { + this.componentCache.clear(); + }; /** * 添加标签 * @param tag @@ -416,7 +410,7 @@ var gs; * @returns */ Entity.prototype.getTags = function () { - return this.tags; + return new Set(Array.from(this.tags)); }; /** * 移除标签 @@ -438,7 +432,7 @@ var gs; * @returns */ Entity.prototype.serialize = function () { - var e_4, _a; + var e_3, _a; var serializedEntity = { id: this.id, components: {}, @@ -452,12 +446,12 @@ var gs; } } } - catch (e_4_1) { e_4 = { error: e_4_1 }; } + catch (e_3_1) { e_3 = { error: e_3_1 }; } finally { try { if (_c && !_c.done && (_a = _b.return)) _a.call(_b); } - finally { if (e_4) throw e_4.error; } + finally { if (e_3) throw e_3.error; } } return serializedEntity; }; @@ -467,7 +461,7 @@ var gs; * @returns 返回增量序列化后的实体对象,如果没有更新的组件,则返回null */ Entity.prototype.serializeIncremental = function (lastSnapshotVersion) { - var e_5, _a; + var e_4, _a; var hasUpdatedComponents = false; var serializedEntity = { id: this.id, @@ -483,12 +477,12 @@ var gs; } } } - catch (e_5_1) { e_5 = { error: e_5_1 }; } + catch (e_4_1) { e_4 = { error: e_4_1 }; } finally { try { if (_c && !_c.done && (_a = _b.return)) _a.call(_b); } - finally { if (e_5) throw e_5.error; } + finally { if (e_4) throw e_4.error; } } return hasUpdatedComponents ? serializedEntity : null; }; @@ -497,7 +491,7 @@ var gs; * @param data */ Entity.prototype.deserialize = function (data) { - var e_6, _a; + var e_5, _a; for (var componentName in data.components) { try { for (var _b = __values(this.componentManagers), _c = _b.next(); !_c.done; _c = _b.next()) { @@ -511,12 +505,12 @@ var gs; } } } - catch (e_6_1) { e_6 = { error: e_6_1 }; } + catch (e_5_1) { e_5 = { error: e_5_1 }; } finally { try { if (_c && !_c.done && (_a = _b.return)) _a.call(_b); } - finally { if (e_6) throw e_6.error; } + finally { if (e_5) throw e_5.error; } } } }; @@ -833,7 +827,7 @@ var gs; (function (gs) { var EntityManager = /** @class */ (function () { function EntityManager(componentClasses, systemManager) { - var e_7, _a; + var e_6, _a; if (componentClasses === void 0) { componentClasses = null; } // 查询缓存,用于缓存组件查询结果 this.queryCache = new Map(); @@ -853,12 +847,12 @@ var gs; this.componentManagers.set(componentClass, componentManager); } } - catch (e_7_1) { e_7 = { error: e_7_1 }; } + catch (e_6_1) { e_6 = { error: e_6_1 }; } finally { try { if (componentClasses_1_1 && !componentClasses_1_1.done && (_a = componentClasses_1.return)) _a.call(componentClasses_1); } - finally { if (e_7) throw e_7.error; } + finally { if (e_6) throw e_6.error; } } } EntityManager.prototype.setSystemManager = function (systemManager) { @@ -890,7 +884,7 @@ var gs; */ EntityManager.prototype.createEntity = function (customEntityClass) { if (customEntityClass === void 0) { customEntityClass = gs.Entity; } - var e_8, _a; + var e_7, _a; var entityId = this.entityIdAllocator.allocate(); var entity = new customEntityClass(entityId, this, this.componentManagers); entity.onCreate(); @@ -904,12 +898,12 @@ var gs; this.tagCache.get(tag).push(entity); } } - catch (e_8_1) { e_8 = { error: e_8_1 }; } + catch (e_7_1) { e_7 = { error: e_7_1 }; } finally { try { if (_c && !_c.done && (_a = _b.return)) _a.call(_b); } - finally { if (e_8) throw e_8.error; } + finally { if (e_7) throw e_7.error; } } return entity; }; @@ -918,7 +912,7 @@ var gs; * @param entityId */ EntityManager.prototype.deleteEntity = function (entityId) { - var e_9, _a; + var e_8, _a; var entity = this.getEntity(entityId); if (entity) { entity.onDestroy(); @@ -935,12 +929,12 @@ var gs; } } } - catch (e_9_1) { e_9 = { error: e_9_1 }; } + catch (e_8_1) { e_8 = { error: e_8_1 }; } finally { try { if (_c && !_c.done && (_a = _b.return)) _a.call(_b); } - finally { if (e_9) throw e_9.error; } + finally { if (e_8) throw e_8.error; } } } }; @@ -981,7 +975,7 @@ var gs; * @returns 具有指定标签的实体数组 */ EntityManager.prototype.getEntitiesWithTag = function (tag) { - var e_10, _a; + var e_9, _a; if (!this.tagCache.has(tag)) { var entitiesWithTag = []; try { @@ -992,12 +986,12 @@ var gs; } } } - catch (e_10_1) { e_10 = { error: e_10_1 }; } + catch (e_9_1) { e_9 = { error: e_9_1 }; } finally { try { if (_c && !_c.done && (_a = _b.return)) _a.call(_b); } - finally { if (e_10) throw e_10.error; } + finally { if (e_9) throw e_9.error; } } this.tagCache.set(tag, entitiesWithTag); } @@ -1017,7 +1011,7 @@ var gs; return this.queryCache.get(key); }; EntityManager.prototype.performQuery = function (components) { - var e_11, _a; + var e_10, _a; var result = []; var _loop_1 = function (entity) { // 检查每个查询的组件是否存在于实体中 @@ -1036,12 +1030,12 @@ var gs; _loop_1(entity); } } - catch (e_11_1) { e_11 = { error: e_11_1 }; } + catch (e_10_1) { e_10 = { error: e_10_1 }; } finally { try { if (_c && !_c.done && (_a = _b.return)) _a.call(_b); } - finally { if (e_11) throw e_11.error; } + finally { if (e_10) throw e_10.error; } } return result; }; @@ -1050,7 +1044,7 @@ var gs; * @returns */ EntityManager.prototype.createStateSnapshot = function () { - var e_12, _a; + var e_11, _a; var snapshot = { entities: [], }; @@ -1060,12 +1054,12 @@ var gs; snapshot.entities.push(entity.serialize()); } } - catch (e_12_1) { e_12 = { error: e_12_1 }; } + catch (e_11_1) { e_11 = { error: e_11_1 }; } finally { try { if (_c && !_c.done && (_a = _b.return)) _a.call(_b); } - finally { if (e_12) throw e_12.error; } + finally { if (e_11) throw e_11.error; } } return snapshot; }; @@ -1075,7 +1069,7 @@ var gs; * @returns 返回一个包含实体增量数据的快照对象 */ EntityManager.prototype.createIncrementalStateSnapshot = function (lastSnapshotVersion) { - var e_13, _a; + var e_12, _a; var snapshot = { entities: [], }; @@ -1088,12 +1082,12 @@ var gs; } } } - catch (e_13_1) { e_13 = { error: e_13_1 }; } + catch (e_12_1) { e_12 = { error: e_12_1 }; } finally { try { if (_c && !_c.done && (_a = _b.return)) _a.call(_b); } - finally { if (e_13) throw e_13.error; } + finally { if (e_12) throw e_12.error; } } return snapshot; }; @@ -1102,7 +1096,7 @@ var gs; * @param stateSnapshot */ EntityManager.prototype.updateStateFromSnapshot = function (stateSnapshot) { - var e_14, _a; + var e_13, _a; var newEntityMap = new Map(); try { for (var _b = __values(stateSnapshot.entities), _c = _b.next(); !_c.done; _c = _b.next()) { @@ -1117,12 +1111,12 @@ var gs; newEntityMap.set(entityId, entity); } } - catch (e_14_1) { e_14 = { error: e_14_1 }; } + catch (e_13_1) { e_13 = { error: e_13_1 }; } finally { try { if (_c && !_c.done && (_a = _b.return)) _a.call(_b); } - finally { if (e_14) throw e_14.error; } + finally { if (e_13) throw e_13.error; } } this.entities = newEntityMap; }; @@ -1131,7 +1125,7 @@ var gs; * @param factor */ EntityManager.prototype.applyInterpolation = function (factor) { - var e_15, _a, e_16, _b; + var e_14, _a, e_15, _b; try { for (var _c = __values(this.getEntities()), _d = _c.next(); !_d.done; _d = _c.next()) { var entity = _d.value; @@ -1144,21 +1138,21 @@ var gs; } } } - catch (e_16_1) { e_16 = { error: e_16_1 }; } + catch (e_15_1) { e_15 = { error: e_15_1 }; } finally { try { if (_f && !_f.done && (_b = _e.return)) _b.call(_e); } - finally { if (e_16) throw e_16.error; } + finally { if (e_15) throw e_15.error; } } } } - catch (e_15_1) { e_15 = { error: e_15_1 }; } + catch (e_14_1) { e_14 = { error: e_14_1 }; } finally { try { if (_d && !_d.done && (_a = _c.return)) _a.call(_c); } - finally { if (e_15) throw e_15.error; } + finally { if (e_14) throw e_14.error; } } }; return EntityManager; @@ -1194,7 +1188,7 @@ var gs; else { var worker = new Worker(system.workerScript); worker.onmessage = function (event) { - var e_17, _a; + var e_16, _a; var updatedEntities = event.data.entities; try { for (var updatedEntities_1 = __values(updatedEntities), updatedEntities_1_1 = updatedEntities_1.next(); !updatedEntities_1_1.done; updatedEntities_1_1 = updatedEntities_1.next()) { @@ -1205,12 +1199,12 @@ var gs; } } } - catch (e_17_1) { e_17 = { error: e_17_1 }; } + catch (e_16_1) { e_16 = { error: e_16_1 }; } finally { try { if (updatedEntities_1_1 && !updatedEntities_1_1.done && (_a = updatedEntities_1.return)) _a.call(updatedEntities_1); } - finally { if (e_17) throw e_17.error; } + finally { if (e_16) throw e_16.error; } } }; this.systemWorkers.set(system, worker); @@ -1235,7 +1229,7 @@ var gs; * @param entity */ SystemManager.prototype.notifyComponentAdded = function (entity) { - var e_18, _a; + var e_17, _a; try { for (var _b = __values(this.systems), _c = _b.next(); !_c.done; _c = _b.next()) { var system = _c.value; @@ -1243,12 +1237,12 @@ var gs; this.entityCache.delete(system); } } - catch (e_18_1) { e_18 = { error: e_18_1 }; } + catch (e_17_1) { e_17 = { error: e_17_1 }; } finally { try { if (_c && !_c.done && (_a = _b.return)) _a.call(_b); } - finally { if (e_18) throw e_18.error; } + finally { if (e_17) throw e_17.error; } } }; /** @@ -1256,7 +1250,7 @@ var gs; * @param entity */ SystemManager.prototype.notifyComponentRemoved = function (entity) { - var e_19, _a; + var e_18, _a; try { for (var _b = __values(this.systems), _c = _b.next(); !_c.done; _c = _b.next()) { var system = _c.value; @@ -1264,12 +1258,12 @@ var gs; this.entityCache.delete(system); } } - catch (e_19_1) { e_19 = { error: e_19_1 }; } + catch (e_18_1) { e_18 = { error: e_18_1 }; } finally { try { if (_c && !_c.done && (_a = _b.return)) _a.call(_b); } - finally { if (e_19) throw e_19.error; } + finally { if (e_18) throw e_18.error; } } }; /** @@ -1283,7 +1277,7 @@ var gs; * 更新系统 */ SystemManager.prototype.update = function () { - var e_20, _a; + var e_19, _a; var entities = this.entityManager.getEntities(); try { for (var _b = __values(this.systems), _c = _b.next(); !_c.done; _c = _b.next()) { @@ -1308,12 +1302,12 @@ var gs; } } } - catch (e_20_1) { e_20 = { error: e_20_1 }; } + catch (e_19_1) { e_19 = { error: e_19_1 }; } finally { try { if (_c && !_c.done && (_a = _b.return)) _a.call(_b); } - finally { if (e_20) throw e_20.error; } + finally { if (e_19) throw e_19.error; } } }; return SystemManager; @@ -1563,7 +1557,7 @@ var gs; return entity.hasComponent(gs.StateMachineComponent); }; StateMachineSystem.prototype.update = function (entities) { - var e_21, _a; + var e_20, _a; try { for (var entities_1 = __values(entities), entities_1_1 = entities_1.next(); !entities_1_1.done; entities_1_1 = entities_1.next()) { var entity = entities_1_1.value; @@ -1571,12 +1565,12 @@ var gs; stateMachineComponent.stateMachine.update(); } } - catch (e_21_1) { e_21 = { error: e_21_1 }; } + catch (e_20_1) { e_20 = { error: e_20_1 }; } finally { try { if (entities_1_1 && !entities_1_1.done && (_a = entities_1.return)) _a.call(entities_1); } - finally { if (e_21) throw e_21.error; } + finally { if (e_20) throw e_20.error; } } }; return StateMachineSystem; @@ -1659,7 +1653,7 @@ var gs; return this.checkAllSet(components) && this.checkExclusionSet(components) && this.checkOneSet(components); }; Matcher.prototype.checkAllSet = function (components) { - var e_22, _a; + var e_21, _a; try { for (var _b = __values(this.allSet), _c = _b.next(); !_c.done; _c = _b.next()) { var type = _c.value; @@ -1668,17 +1662,17 @@ var gs; } } } - catch (e_22_1) { e_22 = { error: e_22_1 }; } + catch (e_21_1) { e_21 = { error: e_21_1 }; } finally { try { if (_c && !_c.done && (_a = _b.return)) _a.call(_b); } - finally { if (e_22) throw e_22.error; } + finally { if (e_21) throw e_21.error; } } return true; }; Matcher.prototype.checkExclusionSet = function (components) { - var e_23, _a; + var e_22, _a; try { for (var _b = __values(this.exclusionSet), _c = _b.next(); !_c.done; _c = _b.next()) { var type = _c.value; @@ -1687,17 +1681,17 @@ var gs; } } } - catch (e_23_1) { e_23 = { error: e_23_1 }; } + catch (e_22_1) { e_22 = { error: e_22_1 }; } finally { try { if (_c && !_c.done && (_a = _b.return)) _a.call(_b); } - finally { if (e_23) throw e_23.error; } + finally { if (e_22) throw e_22.error; } } return true; }; Matcher.prototype.checkOneSet = function (components) { - var e_24, _a; + var e_23, _a; if (this.oneSet.length === 0) { return true; } @@ -1709,12 +1703,12 @@ var gs; } } } - catch (e_24_1) { e_24 = { error: e_24_1 }; } + catch (e_23_1) { e_23 = { error: e_23_1 }; } finally { try { if (_c && !_c.done && (_a = _b.return)) _a.call(_b); } - finally { if (e_24) throw e_24.error; } + finally { if (e_23) throw e_23.error; } } return false; }; diff --git a/source/bin/gs.min.js b/source/bin/gs.min.js index 0e0c220..59daa45 100644 --- a/source/bin/gs.min.js +++ b/source/bin/gs.min.js @@ -1 +1 @@ -window.gs={},window.__extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}();var __values=this&&this.__values||function(t){var e="function"==typeof Symbol&&t[Symbol.iterator],n=0;return e?e.call(t):{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}}},__read=this&&this.__read||function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s},__spread=this&&this.__spread||function(){for(var t=[],e=0;e0){var t=this.pool.pop();return this.resetFn(t),t}return this.createFn()},t.prototype.release=function(t){this.pool.push(t)},t}();t.ObjectPool=e}(gs||(gs={})),function(t){var e=function(e){function n(){return e.call(this,function(){return new t.Event("",null)},function(t){t.type="",t.data=null})||this}return __extends(n,e),n}(t.ObjectPool);t.EventPool=e}(gs||(gs={})),function(t){var e=function(){function e(){this.listeners=new Map,this.eventPool=new t.EventPool}return e.prototype.on=function(t,e){this.listeners.has(t)||this.listeners.set(t,[]);var n=this.listeners.get(t);n&&n.push(e)},e.prototype.once=function(t,e){var n=this,r=function(o){n.off(t,r),e(o)};this.on(t,r)},e.prototype.off=function(t,e){var n=this.listeners.get(t);if(n){var r=n.indexOf(e);r>-1&&n.splice(r,1)}},e.prototype.emit=function(t,e){var n,r,o=this.eventPool.acquire();o.type=t,o.data=e;var i=this.listeners[t];if(i)try{for(var s=__values(i),a=s.next();!a.done;a=s.next()){(0,a.value)(o)}}catch(t){n={error:t}}finally{try{a&&!a.done&&(r=s.return)&&r.call(s)}finally{if(n)throw n.error}}this.eventPool.release(o)},e}();t.EventEmitter=e}(gs||(gs={})),function(t){t.GlobalEventEmitter=new t.EventEmitter}(gs||(gs={})),function(t){var e=function(){function t(){this._entityId=null,this._version=0}return t.prototype.setEntityId=function(t,e){this._entityId=t,this._entityManager=e},t.prototype.getEntityId=function(){return this._entityId},Object.defineProperty(t.prototype,"entityId",{get:function(){if(null===this._entityId)throw new Error("Entity ID 还未被设置");return this._entityId},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"entity",{get:function(){if(null===this._entityId)throw new Error("Entity ID 还未被设置");return this._entityManager.getEntity(this._entityId)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"version",{get:function(){return this._version},enumerable:!0,configurable:!0}),t.prototype.markUpdated=function(){this._version++},t.prototype.reinitialize=function(t,e){},t.prototype.onInitialize=function(){for(var t=[],e=0;et&&(o.components[u.name]=p.serialize(),r=!0)}}catch(t){e={error:t}}finally{try{s&&!s.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}return r?o:null},e.prototype.deserialize=function(t){var e,n;for(var r in t.components)try{for(var o=__values(this.componentManagers),i=o.next();!i.done;i=o.next()){var s=__read(i.value,2),a=s[0],u=s[1];if(a.name===r){var p=u.get(this.id);p&&p.deserialize(t.components[r]);break}}}catch(t){e={error:t}}finally{try{i&&!i.done&&(n=o.return)&&n.call(o)}finally{if(e)throw e.error}}},e.prototype.onCreate=function(){},e.prototype.onDestroy=function(){},e.prototype.on=function(t,e){this.eventEmitter.on(t,e)},e.prototype.once=function(t,e){this.eventEmitter.once(t,e)},e.prototype.off=function(t,e){this.eventEmitter.off(t,e)},e.prototype.emit=function(t,e){this.eventEmitter.emit(t,e)},e}();t.Entity=e}(gs||(gs={})),function(t){var e=function(){function e(e,n,r,o){this._paused=!1,this._enabled=!0,this.entityManager=e,this.priority=n,this.workerScript=o,this.matcher=r||t.Matcher.empty()}return Object.defineProperty(e.prototype,"paused",{get:function(){return this._paused},set:function(t){this._paused=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this._enabled=t},enumerable:!0,configurable:!0}),e.prototype.isPaused=function(){return this.paused},e.prototype.isEnabled=function(){return this.enabled},e.prototype.entityFilter=function(t){return!0},e.prototype.filterEntities=function(t){var e=this;return t.reduce(function(t,n){return e.matcher.isInterestedEntity(n)&&e.entityFilter(n)&&t.push(n),t},[])},e.prototype.handleComponentChange=function(t,e){this.matcher.isInterestedEntity(t)&&(e?this.onComponentAdded(t):this.onComponentRemoved(t))},e.prototype.onComponentAdded=function(t){},e.prototype.onComponentRemoved=function(t){},e.prototype.onRegister=function(){},e.prototype.onUnregister=function(){},e}();t.System=e}(gs||(gs={})),function(t){var e=function(){return function(t,e){this.type=t,this.data=e}}();t.Event=e}(gs||(gs={})),function(t){var e=function(){function t(t){this.inputManager=t}return t.prototype.sendInputToManager=function(t){this.inputManager.sendInput(t)},t}();t.InputAdapter=e}(gs||(gs={})),function(t){var e=function(){function t(){this.buffer=[]}return t.prototype.addEvent=function(t){this.buffer.push(t)},t.prototype.hasEvents=function(){return this.buffer.length>0},t.prototype.getEvents=function(){return this.buffer},t.prototype.consumeEvent=function(){if(0===this.buffer.length)return null;var t=this.buffer[0];return this.buffer.shift(),t},t.prototype.clear=function(){this.buffer=[]},t}();t.InputBuffer=e}(gs||(gs={})),function(t){var e=function(){function e(e){this.inputHistory=[],this.historySizeThreshold=1e3,this.eventListeners=[],this.entityManager=e,this.inputBuffer=new t.InputBuffer}return e.prototype.setHistorySizeThreshold=function(t){this.historySizeThreshold=t},e.prototype.addEventListener=function(t){this.eventListeners.push(t)},e.prototype.setAdapter=function(t){this.adapter=t},e.prototype.sendInput=function(t){this.handleInput(t)},e.prototype.handleInput=function(t){this.inputBuffer.addEvent(t),this.inputHistory.push({frameNumber:this.getCurrentFrameNumber(),input:t}),this.eventListeners.forEach(function(e){return e(t)}),this.inputHistory.length>this.historySizeThreshold&&this.inputHistory.splice(0,this.inputHistory.length-this.historySizeThreshold)},e.prototype.getCurrentFrameNumber=function(){return this.entityManager.getCurrentFrameNumber()},e.prototype.getInputBuffer=function(){return this.inputBuffer},e.prototype.getInputHistory=function(){return this.inputHistory},e}();t.InputManager=e}(gs||(gs={})),function(t){var e=function(){function e(e){this.componentPool=[],this.componentType=e,this.components=new t.SparseSet,this.preallocate(10)}return e.prototype.create=function(t,e){var n;return this.componentPool.length>0?(n=this.componentPool.pop()).reinitialize(t,e):n=new this.componentType,n.setEntityId(t,e),this.components.add(t,n),n},e.prototype.get=function(t){return this.components.get(t)},e.prototype.has=function(t){return this.components.has(t)},e.prototype.remove=function(t){var e=this.components.get(t);e&&(e.reset(),this.componentPool.push(e)),this.components.remove(t)},e.prototype.preallocate=function(t){for(var e=0;e-1&&a.splice(u,1)}}}catch(t){e={error:t}}finally{try{i&&!i.done&&(n=o.return)&&n.call(o)}finally{if(e)throw e.error}}}},e.prototype.getEntity=function(t){return this.entities.has(t)?this.entities.get(t):null},e.prototype.getEntitiesWithComponent=function(t){return this.queryComponents([t])},e.prototype.getEntitiesWithComponents=function(t){return this.queryComponents(t)},e.prototype.getEntities=function(){return Array.from(this.entities.values())},e.prototype.getEntitiesWithTag=function(t){var e,n;if(!this.tagCache.has(t)){var r=[];try{for(var o=__values(this.getEntities()),i=o.next();!i.done;i=o.next()){var s=i.value;s.hasTag(t)&&r.push(s)}}catch(t){e={error:t}}finally{try{i&&!i.done&&(n=o.return)&&n.call(o)}finally{if(e)throw e.error}}this.tagCache.set(t,r)}return this.tagCache.get(t)},e.prototype.queryComponents=function(t){var e=t.map(function(t){return t.name}).sort().join("|");if(!this.queryCache.has(e)){var n=this.performQuery(t);this.queryCache.set(e,n)}return this.queryCache.get(e)},e.prototype.performQuery=function(t){var e,n,r=[],o=function(e){t.every(function(t){return e.hasComponent(t)})&&r.push(e)};try{for(var i=__values(this.getEntities()),s=i.next();!s.done;s=i.next()){o(s.value)}}catch(t){e={error:t}}finally{try{s&&!s.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}return r},e.prototype.createStateSnapshot=function(){var t,e,n={entities:[]};try{for(var r=__values(this.getEntities()),o=r.next();!o.done;o=r.next()){var i=o.value;n.entities.push(i.serialize())}}catch(e){t={error:e}}finally{try{o&&!o.done&&(e=r.return)&&e.call(r)}finally{if(t)throw t.error}}return n},e.prototype.createIncrementalStateSnapshot=function(t){var e,n,r={entities:[]};try{for(var o=__values(this.getEntities()),i=o.next();!i.done;i=o.next()){var s=i.value.serializeIncremental(t);s&&r.entities.push(s)}}catch(t){e={error:t}}finally{try{i&&!i.done&&(n=o.return)&&n.call(o)}finally{if(e)throw e.error}}return r},e.prototype.updateStateFromSnapshot=function(e){var n,r,o=new Map;try{for(var i=__values(e.entities),s=i.next();!s.done;s=i.next()){var a=s.value,u=a.id,p=this.getEntity(u);p||(p=new t.Entity(u,this,this.componentManagers)).onCreate(),p.deserialize(a),o.set(u,p)}}catch(t){n={error:t}}finally{try{s&&!s.done&&(r=i.return)&&r.call(i)}finally{if(n)throw n.error}}this.entities=o},e.prototype.applyInterpolation=function(e){var n,r,o,i;try{for(var s=__values(this.getEntities()),a=s.next();!a.done;a=s.next()){var u=a.value;try{for(var p=__values(this.componentManagers),h=p.next();!h.done;h=p.next()){var c=__read(h.value,2),f=c[0],l=(c[1],u.getComponent(f));l instanceof t.Component&&"savePreviousState"in l&&"applyInterpolation"in l&&l.applyInterpolation(e)}}catch(t){o={error:t}}finally{try{h&&!h.done&&(i=p.return)&&i.call(p)}finally{if(o)throw o.error}}}}catch(t){n={error:t}}finally{try{a&&!a.done&&(r=s.return)&&r.call(s)}finally{if(n)throw n.error}}},e}();t.EntityManager=e}(gs||(gs={})),function(t){var e=function(){function t(t){this.systemWorkers=new Map,this.entityCache=new Map,this.systems=[],this.entityManager=t,t.setSystemManager(this)}return t.prototype.registerSystem=function(t){var e=this;if(t.onRegister(),this.systems.push(t),this.systems.sort(function(t,e){return t.priority-e.priority}),t.workerScript)if("undefined"==typeof Worker)console.warn("Web Workers 在当前环境中不受支持。系统将在主线程中运行");else{var n=new Worker(t.workerScript);n.onmessage=function(t){var n,r,o=t.data.entities;try{for(var i=__values(o),s=i.next();!s.done;s=i.next()){var a=s.value,u=e.entityManager.getEntity(a.id);u&&u.deserialize(a)}}catch(t){n={error:t}}finally{try{s&&!s.done&&(r=i.return)&&r.call(i)}finally{if(n)throw n.error}}},this.systemWorkers.set(t,n)}},t.prototype.unregisterSystem=function(t){t.onUnregister();var e=this.systems.indexOf(t);e>-1&&this.systems.splice(e,1),this.systemWorkers.delete(t),this.entityCache.delete(t)},t.prototype.notifyComponentAdded=function(t){var e,n;try{for(var r=__values(this.systems),o=r.next();!o.done;o=r.next()){var i=o.value;i.handleComponentChange(t,!0),this.entityCache.delete(i)}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(e)throw e.error}}},t.prototype.notifyComponentRemoved=function(t){var e,n;try{for(var r=__values(this.systems),o=r.next();!o.done;o=r.next()){var i=o.value;i.handleComponentChange(t,!1),this.entityCache.delete(i)}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(e)throw e.error}}},t.prototype.invalidateEntityCacheForSystem=function(t){this.entityCache.delete(t)},t.prototype.update=function(){var t,e,n=this.entityManager.getEntities();try{for(var r=__values(this.systems),o=r.next();!o.done;o=r.next()){var i=o.value;if(i.isEnabled()&&!i.isPaused()){var s=this.entityCache.get(i);s||(s=i.filterEntities(n),this.entityCache.set(i,s));var a=this.systemWorkers.get(i);if(a){var u={entities:s.map(function(t){return t.serialize()})};a.postMessage(u)}else i.update(s)}}}catch(e){t={error:e}}finally{try{o&&!o.done&&(e=r.return)&&e.call(r)}finally{if(t)throw t.error}}},t}();t.SystemManager=e}(gs||(gs={})),function(t){var e=function(){function t(){this.deltaTime=0,this.timeScale=1,this.totalTime=0}return t.getInstance=function(){return t.instance||(t.instance=new t),t.instance},t.prototype.update=function(t){this.deltaTime=t*this.timeScale,this.totalTime+=this.deltaTime},t}();t.TimeManager=e}(gs||(gs={})),function(t){var e=function(){function t(){this.networkAdapter=null}return t.prototype.setNetworkAdapter=function(t){this.networkAdapter=t},t.prototype.getNetworkAdpater=function(){return this.networkAdapter},t}();t.NetworkManager=e}(gs||(gs={})),function(t){var e=function(){function e(){this.snapshotQueue=[]}return e.prototype.sendState=function(t){},e.prototype.receiveState=function(t){this.snapshotQueue.push(t)},e.prototype.handleStateUpdate=function(e){if(!(this.snapshotQueue.length<2)){var n=this.snapshotQueue[0],r=this.snapshotQueue[1],o=t.TimeManager.getInstance().deltaTime,i=(o-n.timestamp)/(r.timestamp-n.timestamp);this.interpolateAndUpdateGameState(n,r,i),o>=r.timestamp&&this.snapshotQueue.shift()}},e.prototype.interpolateAndUpdateGameState=function(t,e,n){this.onInterpolation&&this.onInterpolation(t,e,n)},e}();t.SnapshotInterpolationStrategy=e}(gs||(gs={})),function(t){var e=function(){function t(){this.handleStateUpdate=function(){}}return t.prototype.sendState=function(t){var e=t;this.onCompressState&&(e=this.onCompressState(t)),this.onSendState&&this.onSendState(e)},t.prototype.receiveState=function(t){var e=t;this.onDecompressState&&(e=this.onDecompressState(t)),this.onReceiveState&&this.onReceiveState(e),this.handleStateUpdate(e)},t}();t.StateCompressionStrategy=e}(gs||(gs={})),function(t){var e=function(){function t(t){this.strategy=t}return t.prototype.sendState=function(t){this.strategy.sendState(t)},t.prototype.receiveState=function(t){this.strategy.receiveState(t)},t.prototype.handleStateUpdate=function(t){this.strategy.handleStateUpdate(t)},t.prototype.setStrategy=function(t){this.strategy=t},t}();t.SyncStrategyManager=e}(gs||(gs={})),function(t){var e=function(){function t(){this.currentState=null,this.states=new Map}return t.prototype.addState=function(t,e){this.states.set(t,e)},t.prototype.changeState=function(t){if(this.states.has(t)){var e=this.states.get(t);this.currentState&&this.currentState.exit&&this.currentState.exit(),this.currentState=e,this.currentState.enter&&this.currentState.enter()}else console.warn('状态 "'+t+'" 不存在.')},t.prototype.update=function(){this.currentState&&this.currentState.update&&this.currentState.update()},t}();t.StateMachine=e}(gs||(gs={})),function(t){var e=function(e){function n(){var n=e.call(this)||this;return n.stateMachine=new t.StateMachine,n}return __extends(n,e),n.prototype.reset=function(){this.stateMachine=new t.StateMachine},n}(t.Component);t.StateMachineComponent=e}(gs||(gs={})),function(t){var e=function(e){function n(t){return e.call(this,t,1)||this}return __extends(n,e),n.prototype.entityFilter=function(e){return e.hasComponent(t.StateMachineComponent)},n.prototype.update=function(e){var n,r;try{for(var o=__values(e),i=o.next();!i.done;i=o.next()){i.value.getComponent(t.StateMachineComponent).stateMachine.update()}}catch(t){n={error:t}}finally{try{i&&!i.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}},n}(t.System);t.StateMachineSystem=e}(gs||(gs={})),function(t){var e=function(){function t(t){void 0===t&&(t=32),this.data=new Uint32Array(Math.ceil(t/32))}return t.prototype.set=function(t){var e=Math.floor(t/32),n=t%32;this.data[e]|=1<=this.sparse.length&&(this.sparse.length=t+1),this.sparse[t]=this.count,this.dense[this.count]=t,this.items[this.count]=e,this.count++},t.prototype.remove=function(t){var e=this.sparse[t],n=this.count-1,r=this.dense[n],o=this.items[n];this.dense[e]=r,this.items[e]=o,this.sparse[r]=e,this.count--},t.prototype.has=function(t){return this.sparse[t]=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}}},__read=this&&this.__read||function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s},__spread=this&&this.__spread||function(){for(var t=[],e=0;e0){var t=this.pool.pop();return this.resetFn(t),t}return this.createFn()},t.prototype.release=function(t){this.pool.push(t)},t}();t.ObjectPool=e}(gs||(gs={})),function(t){var e=function(e){function n(){return e.call(this,function(){return new t.Event("",null)},function(t){t.type="",t.data=null})||this}return __extends(n,e),n}(t.ObjectPool);t.EventPool=e}(gs||(gs={})),function(t){var e=function(){function e(){this.listeners=new Map,this.eventPool=new t.EventPool}return e.prototype.on=function(t,e){this.listeners.has(t)||this.listeners.set(t,[]);var n=this.listeners.get(t);n&&n.push(e)},e.prototype.once=function(t,e){var n=this,r=function(o){n.off(t,r),e(o)};this.on(t,r)},e.prototype.off=function(t,e){var n=this.listeners.get(t);if(n){var r=n.indexOf(e);r>-1&&n.splice(r,1)}},e.prototype.emit=function(t,e){var n,r,o=this.eventPool.acquire();o.type=t,o.data=e;var i=this.listeners[t];if(i)try{for(var s=__values(i),a=s.next();!a.done;a=s.next()){(0,a.value)(o)}}catch(t){n={error:t}}finally{try{a&&!a.done&&(r=s.return)&&r.call(s)}finally{if(n)throw n.error}}this.eventPool.release(o)},e}();t.EventEmitter=e}(gs||(gs={})),function(t){t.GlobalEventEmitter=new t.EventEmitter}(gs||(gs={})),function(t){var e=function(){function t(){this._entityId=null,this._version=0}return t.prototype.setEntityId=function(t,e){this._entityId=t,this._entityManager=e},t.prototype.getEntityId=function(){return this._entityId},Object.defineProperty(t.prototype,"entityId",{get:function(){if(null===this._entityId)throw new Error("Entity ID 还未被设置");return this._entityId},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"entity",{get:function(){if(null===this._entityId)throw new Error("Entity ID 还未被设置");return this._entityManager.getEntity(this._entityId)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"version",{get:function(){return this._version},enumerable:!0,configurable:!0}),t.prototype.markUpdated=function(){this._version++},t.prototype.reinitialize=function(t,e){},t.prototype.onInitialize=function(){for(var t=[],e=0;et&&(o.components[u.name]=p.serialize(),r=!0)}}catch(t){e={error:t}}finally{try{s&&!s.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}return r?o:null},e.prototype.deserialize=function(t){var e,n;for(var r in t.components)try{for(var o=__values(this.componentManagers),i=o.next();!i.done;i=o.next()){var s=__read(i.value,2),a=s[0],u=s[1];if(a.name===r){var p=u.get(this.id);p&&p.deserialize(t.components[r]);break}}}catch(t){e={error:t}}finally{try{i&&!i.done&&(n=o.return)&&n.call(o)}finally{if(e)throw e.error}}},e.prototype.onCreate=function(){},e.prototype.onDestroy=function(){},e.prototype.on=function(t,e){this.eventEmitter.on(t,e)},e.prototype.once=function(t,e){this.eventEmitter.once(t,e)},e.prototype.off=function(t,e){this.eventEmitter.off(t,e)},e.prototype.emit=function(t,e){this.eventEmitter.emit(t,e)},e}();t.Entity=e}(gs||(gs={})),function(t){var e=function(){function e(e,n,r,o){this._paused=!1,this._enabled=!0,this.entityManager=e,this.priority=n,this.workerScript=o,this.matcher=r||t.Matcher.empty()}return Object.defineProperty(e.prototype,"paused",{get:function(){return this._paused},set:function(t){this._paused=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this._enabled=t},enumerable:!0,configurable:!0}),e.prototype.isPaused=function(){return this.paused},e.prototype.isEnabled=function(){return this.enabled},e.prototype.entityFilter=function(t){return!0},e.prototype.filterEntities=function(t){var e=this;return t.reduce(function(t,n){return e.matcher.isInterestedEntity(n)&&e.entityFilter(n)&&t.push(n),t},[])},e.prototype.handleComponentChange=function(t,e){this.matcher.isInterestedEntity(t)&&(e?this.onComponentAdded(t):this.onComponentRemoved(t))},e.prototype.onComponentAdded=function(t){},e.prototype.onComponentRemoved=function(t){},e.prototype.onRegister=function(){},e.prototype.onUnregister=function(){},e}();t.System=e}(gs||(gs={})),function(t){var e=function(){return function(t,e){this.type=t,this.data=e}}();t.Event=e}(gs||(gs={})),function(t){var e=function(){function t(t){this.inputManager=t}return t.prototype.sendInputToManager=function(t){this.inputManager.sendInput(t)},t}();t.InputAdapter=e}(gs||(gs={})),function(t){var e=function(){function t(){this.buffer=[]}return t.prototype.addEvent=function(t){this.buffer.push(t)},t.prototype.hasEvents=function(){return this.buffer.length>0},t.prototype.getEvents=function(){return this.buffer},t.prototype.consumeEvent=function(){if(0===this.buffer.length)return null;var t=this.buffer[0];return this.buffer.shift(),t},t.prototype.clear=function(){this.buffer=[]},t}();t.InputBuffer=e}(gs||(gs={})),function(t){var e=function(){function e(e){this.inputHistory=[],this.historySizeThreshold=1e3,this.eventListeners=[],this.entityManager=e,this.inputBuffer=new t.InputBuffer}return e.prototype.setHistorySizeThreshold=function(t){this.historySizeThreshold=t},e.prototype.addEventListener=function(t){this.eventListeners.push(t)},e.prototype.setAdapter=function(t){this.adapter=t},e.prototype.sendInput=function(t){this.handleInput(t)},e.prototype.handleInput=function(t){this.inputBuffer.addEvent(t),this.inputHistory.push({frameNumber:this.getCurrentFrameNumber(),input:t}),this.eventListeners.forEach(function(e){return e(t)}),this.inputHistory.length>this.historySizeThreshold&&this.inputHistory.splice(0,this.inputHistory.length-this.historySizeThreshold)},e.prototype.getCurrentFrameNumber=function(){return this.entityManager.getCurrentFrameNumber()},e.prototype.getInputBuffer=function(){return this.inputBuffer},e.prototype.getInputHistory=function(){return this.inputHistory},e}();t.InputManager=e}(gs||(gs={})),function(t){var e=function(){function e(e){this.componentPool=[],this.componentType=e,this.components=new t.SparseSet,this.preallocate(10)}return e.prototype.create=function(t,e){var n;return this.componentPool.length>0?(n=this.componentPool.pop()).reinitialize(t,e):n=new this.componentType,n.setEntityId(t,e),this.components.add(t,n),n},e.prototype.get=function(t){return this.components.get(t)},e.prototype.has=function(t){return this.components.has(t)},e.prototype.remove=function(t){var e=this.components.get(t);e&&(e.reset(),this.componentPool.push(e)),this.components.remove(t)},e.prototype.preallocate=function(t){for(var e=0;e-1&&a.splice(u,1)}}}catch(t){e={error:t}}finally{try{i&&!i.done&&(n=o.return)&&n.call(o)}finally{if(e)throw e.error}}}},e.prototype.getEntity=function(t){return this.entities.has(t)?this.entities.get(t):null},e.prototype.getEntitiesWithComponent=function(t){return this.queryComponents([t])},e.prototype.getEntitiesWithComponents=function(t){return this.queryComponents(t)},e.prototype.getEntities=function(){return Array.from(this.entities.values())},e.prototype.getEntitiesWithTag=function(t){var e,n;if(!this.tagCache.has(t)){var r=[];try{for(var o=__values(this.getEntities()),i=o.next();!i.done;i=o.next()){var s=i.value;s.hasTag(t)&&r.push(s)}}catch(t){e={error:t}}finally{try{i&&!i.done&&(n=o.return)&&n.call(o)}finally{if(e)throw e.error}}this.tagCache.set(t,r)}return this.tagCache.get(t)},e.prototype.queryComponents=function(t){var e=t.map(function(t){return t.name}).sort().join("|");if(!this.queryCache.has(e)){var n=this.performQuery(t);this.queryCache.set(e,n)}return this.queryCache.get(e)},e.prototype.performQuery=function(t){var e,n,r=[],o=function(e){t.every(function(t){return e.hasComponent(t)})&&r.push(e)};try{for(var i=__values(this.getEntities()),s=i.next();!s.done;s=i.next()){o(s.value)}}catch(t){e={error:t}}finally{try{s&&!s.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}return r},e.prototype.createStateSnapshot=function(){var t,e,n={entities:[]};try{for(var r=__values(this.getEntities()),o=r.next();!o.done;o=r.next()){var i=o.value;n.entities.push(i.serialize())}}catch(e){t={error:e}}finally{try{o&&!o.done&&(e=r.return)&&e.call(r)}finally{if(t)throw t.error}}return n},e.prototype.createIncrementalStateSnapshot=function(t){var e,n,r={entities:[]};try{for(var o=__values(this.getEntities()),i=o.next();!i.done;i=o.next()){var s=i.value.serializeIncremental(t);s&&r.entities.push(s)}}catch(t){e={error:t}}finally{try{i&&!i.done&&(n=o.return)&&n.call(o)}finally{if(e)throw e.error}}return r},e.prototype.updateStateFromSnapshot=function(e){var n,r,o=new Map;try{for(var i=__values(e.entities),s=i.next();!s.done;s=i.next()){var a=s.value,u=a.id,p=this.getEntity(u);p||(p=new t.Entity(u,this,this.componentManagers)).onCreate(),p.deserialize(a),o.set(u,p)}}catch(t){n={error:t}}finally{try{s&&!s.done&&(r=i.return)&&r.call(i)}finally{if(n)throw n.error}}this.entities=o},e.prototype.applyInterpolation=function(e){var n,r,o,i;try{for(var s=__values(this.getEntities()),a=s.next();!a.done;a=s.next()){var u=a.value;try{for(var p=__values(this.componentManagers),h=p.next();!h.done;h=p.next()){var c=__read(h.value,2),f=c[0],l=(c[1],u.getComponent(f));l instanceof t.Component&&"savePreviousState"in l&&"applyInterpolation"in l&&l.applyInterpolation(e)}}catch(t){o={error:t}}finally{try{h&&!h.done&&(i=p.return)&&i.call(p)}finally{if(o)throw o.error}}}}catch(t){n={error:t}}finally{try{a&&!a.done&&(r=s.return)&&r.call(s)}finally{if(n)throw n.error}}},e}();t.EntityManager=e}(gs||(gs={})),function(t){var e=function(){function t(t){this.systemWorkers=new Map,this.entityCache=new Map,this.systems=[],this.entityManager=t,t.setSystemManager(this)}return t.prototype.registerSystem=function(t){var e=this;if(t.onRegister(),this.systems.push(t),this.systems.sort(function(t,e){return t.priority-e.priority}),t.workerScript)if("undefined"==typeof Worker)console.warn("Web Workers 在当前环境中不受支持。系统将在主线程中运行");else{var n=new Worker(t.workerScript);n.onmessage=function(t){var n,r,o=t.data.entities;try{for(var i=__values(o),s=i.next();!s.done;s=i.next()){var a=s.value,u=e.entityManager.getEntity(a.id);u&&u.deserialize(a)}}catch(t){n={error:t}}finally{try{s&&!s.done&&(r=i.return)&&r.call(i)}finally{if(n)throw n.error}}},this.systemWorkers.set(t,n)}},t.prototype.unregisterSystem=function(t){t.onUnregister();var e=this.systems.indexOf(t);e>-1&&this.systems.splice(e,1),this.systemWorkers.delete(t),this.entityCache.delete(t)},t.prototype.notifyComponentAdded=function(t){var e,n;try{for(var r=__values(this.systems),o=r.next();!o.done;o=r.next()){var i=o.value;i.handleComponentChange(t,!0),this.entityCache.delete(i)}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(e)throw e.error}}},t.prototype.notifyComponentRemoved=function(t){var e,n;try{for(var r=__values(this.systems),o=r.next();!o.done;o=r.next()){var i=o.value;i.handleComponentChange(t,!1),this.entityCache.delete(i)}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(e)throw e.error}}},t.prototype.invalidateEntityCacheForSystem=function(t){this.entityCache.delete(t)},t.prototype.update=function(){var t,e,n=this.entityManager.getEntities();try{for(var r=__values(this.systems),o=r.next();!o.done;o=r.next()){var i=o.value;if(i.isEnabled()&&!i.isPaused()){var s=this.entityCache.get(i);s||(s=i.filterEntities(n),this.entityCache.set(i,s));var a=this.systemWorkers.get(i);if(a){var u={entities:s.map(function(t){return t.serialize()})};a.postMessage(u)}else i.update(s)}}}catch(e){t={error:e}}finally{try{o&&!o.done&&(e=r.return)&&e.call(r)}finally{if(t)throw t.error}}},t}();t.SystemManager=e}(gs||(gs={})),function(t){var e=function(){function t(){this.deltaTime=0,this.timeScale=1,this.totalTime=0}return t.getInstance=function(){return t.instance||(t.instance=new t),t.instance},t.prototype.update=function(t){this.deltaTime=t*this.timeScale,this.totalTime+=this.deltaTime},t}();t.TimeManager=e}(gs||(gs={})),function(t){var e=function(){function t(){this.networkAdapter=null}return t.prototype.setNetworkAdapter=function(t){this.networkAdapter=t},t.prototype.getNetworkAdpater=function(){return this.networkAdapter},t}();t.NetworkManager=e}(gs||(gs={})),function(t){var e=function(){function e(){this.snapshotQueue=[]}return e.prototype.sendState=function(t){},e.prototype.receiveState=function(t){this.snapshotQueue.push(t)},e.prototype.handleStateUpdate=function(e){if(!(this.snapshotQueue.length<2)){var n=this.snapshotQueue[0],r=this.snapshotQueue[1],o=t.TimeManager.getInstance().deltaTime,i=(o-n.timestamp)/(r.timestamp-n.timestamp);this.interpolateAndUpdateGameState(n,r,i),o>=r.timestamp&&this.snapshotQueue.shift()}},e.prototype.interpolateAndUpdateGameState=function(t,e,n){this.onInterpolation&&this.onInterpolation(t,e,n)},e}();t.SnapshotInterpolationStrategy=e}(gs||(gs={})),function(t){var e=function(){function t(){this.handleStateUpdate=function(){}}return t.prototype.sendState=function(t){var e=t;this.onCompressState&&(e=this.onCompressState(t)),this.onSendState&&this.onSendState(e)},t.prototype.receiveState=function(t){var e=t;this.onDecompressState&&(e=this.onDecompressState(t)),this.onReceiveState&&this.onReceiveState(e),this.handleStateUpdate(e)},t}();t.StateCompressionStrategy=e}(gs||(gs={})),function(t){var e=function(){function t(t){this.strategy=t}return t.prototype.sendState=function(t){this.strategy.sendState(t)},t.prototype.receiveState=function(t){this.strategy.receiveState(t)},t.prototype.handleStateUpdate=function(t){this.strategy.handleStateUpdate(t)},t.prototype.setStrategy=function(t){this.strategy=t},t}();t.SyncStrategyManager=e}(gs||(gs={})),function(t){var e=function(){function t(){this.currentState=null,this.states=new Map}return t.prototype.addState=function(t,e){this.states.set(t,e)},t.prototype.changeState=function(t){if(this.states.has(t)){var e=this.states.get(t);this.currentState&&this.currentState.exit&&this.currentState.exit(),this.currentState=e,this.currentState.enter&&this.currentState.enter()}else console.warn('状态 "'+t+'" 不存在.')},t.prototype.update=function(){this.currentState&&this.currentState.update&&this.currentState.update()},t}();t.StateMachine=e}(gs||(gs={})),function(t){var e=function(e){function n(){var n=e.call(this)||this;return n.stateMachine=new t.StateMachine,n}return __extends(n,e),n.prototype.reset=function(){this.stateMachine=new t.StateMachine},n}(t.Component);t.StateMachineComponent=e}(gs||(gs={})),function(t){var e=function(e){function n(t){return e.call(this,t,1)||this}return __extends(n,e),n.prototype.entityFilter=function(e){return e.hasComponent(t.StateMachineComponent)},n.prototype.update=function(e){var n,r;try{for(var o=__values(e),i=o.next();!i.done;i=o.next()){i.value.getComponent(t.StateMachineComponent).stateMachine.update()}}catch(t){n={error:t}}finally{try{i&&!i.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}},n}(t.System);t.StateMachineSystem=e}(gs||(gs={})),function(t){var e=function(){function t(t){void 0===t&&(t=32),this.data=new Uint32Array(Math.ceil(t/32))}return t.prototype.set=function(t){var e=Math.floor(t/32),n=t%32;this.data[e]|=1<=this.sparse.length&&(this.sparse.length=t+1),this.sparse[t]=this.count,this.dense[this.count]=t,this.items[this.count]=e,this.count++},t.prototype.remove=function(t){var e=this.sparse[t],n=this.count-1,r=this.dense[n],o=this.items[n];this.dense[e]=r,this.items[e]=o,this.sparse[r]=e,this.count--},t.prototype.has=function(t){return this.sparse[t]>; @@ -78,16 +81,9 @@ module gs { * @returns */ public getAllComponents(): Component[] { - const components: Component[] = []; - - for (const [, manager] of this.componentManagers) { - const component = manager.get(this.id); - if (component) { - components.push(component); - } - } - - return components; + return Array.from(this.componentManagers.values()) + .map(manager => manager.get(this.id)) + .filter(component => component !== null); } /** @@ -126,6 +122,13 @@ module gs { return manager ? manager.has(this.id) : false; } + /** + * 清除组件缓存 + */ + public clearComponentCache(): void { + this.componentCache.clear(); + } + /** * 添加标签 * @param tag @@ -139,7 +142,7 @@ module gs { * @returns */ getTags(): Set { - return this.tags; + return new Set(Array.from(this.tags)); } /**