@esengine/ecs-framework
Version:
用于Laya、Cocos Creator等JavaScript游戏引擎的高性能ECS框架
3 lines • 178 kB
JavaScript
"use strict";function t(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,i=Array(e);n<e;n++)i[n]=t[n];return i}function e(t,e,n,i,r,o,s){try{var a=t[o](s),c=a.value}catch(t){return void n(t)}a.done?e(c):Promise.resolve(c).then(i,r)}function n(t){return function(){var n=this,i=arguments;return new Promise((function(r,o){var s=t.apply(n,i);function a(t){e(s,r,o,a,c,"next",t)}function c(t){e(s,r,o,a,c,"throw",t)}a(void 0)}))}}function i(t,e,n){if(h())return Reflect.construct.apply(null,arguments);var i=[null];i.push.apply(i,e);var r=new(t.bind.apply(t,i));return n&&f(r,n.prototype),r}function r(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,p(i.key),i)}}function o(t,e,n){return e&&r(t.prototype,e),n&&r(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function s(e,n){var i="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(i)return(i=i.call(e)).next.bind(i);if(Array.isArray(e)||(i=function(e,n){if(e){if("string"==typeof e)return t(e,n);var i={}.toString.call(e).slice(8,-1);return"Object"===i&&e.constructor&&(i=e.constructor.name),"Map"===i||"Set"===i?Array.from(e):"Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i)?t(e,n):void 0}}(e))||n){i&&(e=i);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function a(){return a=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var i in n)({}).hasOwnProperty.call(n,i)&&(t[i]=n[i])}return t},a.apply(null,arguments)}function c(t){return c=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},c(t)}function u(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,f(t,e)}function h(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(h=function(){return!!t})()}function l(){
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
var t,e,n="function"==typeof Symbol?Symbol:{},i=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function o(n,i,r,o){var c=i&&i.prototype instanceof a?i:a,u=Object.create(c.prototype);return d(u,"_invoke",function(n,i,r){var o,a,c,u=0,h=r||[],l=!1,d={p:0,n:0,v:t,a:f,f:f.bind(t,4),d:function(e,n){return o=e,a=0,c=t,d.n=n,s}};function f(n,i){for(a=n,c=i,e=0;!l&&u&&!r&&e<h.length;e++){var r,o=h[e],f=d.p,p=o[2];n>3?(r=p===i)&&(c=o[(a=o[4])?5:(a=3,3)],o[4]=o[5]=t):o[0]<=f&&((r=n<2&&f<o[1])?(a=0,d.v=i,d.n=o[1]):f<p&&(r=n<3||o[0]>i||i>p)&&(o[4]=n,o[5]=i,d.n=p,a=0))}if(r||n>1)return s;throw l=!0,i}return function(r,h,p){if(u>1)throw TypeError("Generator is already running");for(l&&1===h&&f(h,p),a=h,c=p;(e=a<2?t:c)||!l;){o||(a?a<3?(a>1&&(d.n=-1),f(a,c)):d.n=c:d.v=c);try{if(u=2,o){if(a||(r="next"),e=o[r]){if(!(e=e.call(o,c)))throw TypeError("iterator result is not an object");if(!e.done)return e;c=e.value,a<2&&(a=0)}else 1===a&&(e=o.return)&&e.call(o),a<2&&(c=TypeError("The iterator does not provide a '"+r+"' method"),a=1);o=t}else if((e=(l=d.n<0)?c:n.call(i,d))!==s)break}catch(e){o=t,a=1,c=e}finally{u=1}}return{value:e,done:l}}}(n,r,o),!0),u}var s={};function a(){}function c(){}function u(){}e=Object.getPrototypeOf;var h=[][i]?e(e([][i]())):(d(e={},i,(function(){return this})),e),f=u.prototype=a.prototype=Object.create(h);function p(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,d(t,r,"GeneratorFunction")),t.prototype=Object.create(f),t}return c.prototype=u,d(f,"constructor",u),d(u,"constructor",c),c.displayName="GeneratorFunction",d(u,r,"GeneratorFunction"),d(f),d(f,r,"Generator"),d(f,i,(function(){return this})),d(f,"toString",(function(){return"[object Generator]"})),(l=function(){return{w:o,m:p}})()}function d(t,e,n,i){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}d=function(t,e,n,i){function o(e,n){d(t,e,(function(t){return this._invoke(e,n,t)}))}e?r?r(t,e,{value:n,enumerable:!i,configurable:!i,writable:!i}):t[e]=n:(o("next",0),o("throw",1),o("return",2))},d(t,e,n,i)}function f(t,e){return f=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},f(t,e)}function p(t){var e=function(t,e){if("object"!=typeof t||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var i=n.call(t,e);if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t,"string");return"symbol"==typeof e?e:e+""}function m(t){var e="function"==typeof Map?new Map:void 0;return m=function(t){if(null===t||!function(t){try{return-1!==Function.toString.call(t).indexOf("[native code]")}catch(e){return"function"==typeof t}}(t))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,n)}function n(){return i(t,arguments,c(this).constructor)}return n.prototype=Object.create(t.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),f(n,t)},m(t)}var y=function(){function t(){this._enabled=!1}var e=t.prototype;return e.setEnabled=function(t){this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled())},e.onEnabled=function(){},e.onDisabled=function(){},e.update=function(){},o(t,[{key:"enabled",get:function(){return this._enabled},set:function(t){this.setEnabled(t)}}])}(),g=function(){function t(){}return t.update=function(t){this.unscaledDeltaTime=t,this.deltaTime=t*this.timeScale,this.unscaledTotalTime+=this.unscaledDeltaTime,this.totalTime+=this.deltaTime,this.frameCount++},t.sceneChanged=function(){this.frameCount=0,this.totalTime=0,this.unscaledTotalTime=0,this.deltaTime=0,this.unscaledDeltaTime=0},t.checkEvery=function(t,e){return this.totalTime-e>=t},t}();g.deltaTime=0,g.unscaledDeltaTime=0,g.totalTime=0,g.unscaledTotalTime=0,g.timeScale=1,g.frameCount=0;var v,_=function(){function t(){this._timeInSeconds=0,this._repeats=!1,this._isDone=!1,this._elapsedTime=0}var e=t.prototype;return e.getContext=function(){return this.context},e.reset=function(){this._elapsedTime=0},e.stop=function(){this._isDone=!0},e.tick=function(){return!this._isDone&&this._elapsedTime>this._timeInSeconds&&(this._elapsedTime-=this._timeInSeconds,this._onTime(this),this._isDone||this._repeats||(this._isDone=!0)),this._elapsedTime+=g.deltaTime,this._isDone},e.initialize=function(t,e,n,i){this._timeInSeconds=t,this._repeats=e,this.context=n,this._onTime=i.bind(n)},e.unload=function(){this.context=null,this._onTime=null},o(t,[{key:"isDone",get:function(){return this._isDone}},{key:"elapsedTime",get:function(){return this._elapsedTime}}])}(),E=function(t){function e(){var e;return(e=t.apply(this,arguments)||this)._timers=[],e}u(e,t);var n=e.prototype;return n.update=function(){for(var t=this._timers.length-1;t>=0;t--)this._timers[t].tick()&&(this._timers[t].unload(),this._timers.splice(t,1))},n.schedule=function(t,e,n,i){var r=new _;return r.initialize(t,e,n,i),this._timers.push(r),r},e}(y);exports.PerformanceWarningType=void 0,(v=exports.PerformanceWarningType||(exports.PerformanceWarningType={})).HIGH_EXECUTION_TIME="high_execution_time",v.HIGH_MEMORY_USAGE="high_memory_usage",v.HIGH_CPU_USAGE="high_cpu_usage",v.FREQUENT_GC="frequent_gc",v.LOW_FPS="low_fps",v.HIGH_ENTITY_COUNT="high_entity_count";var S=function(){function t(){this._systemData=new Map,this._systemStats=new Map,this._warnings=[],this._isEnabled=!1,this._maxRecentSamples=60,this._maxWarnings=100,this._thresholds={executionTime:{warning:16.67,critical:33.33},memoryUsage:{warning:100,critical:200},cpuUsage:{warning:70,critical:90},fps:{warning:45,critical:30},entityCount:{warning:1e3,critical:5e3}},this._fpsHistory=[],this._lastFrameTime=0,this._frameCount=0,this._fpsUpdateInterval=1e3,this._lastFpsUpdate=0,this._currentFps=60,this._memoryCheckInterval=5e3,this._lastMemoryCheck=0,this._memoryHistory=[],this._gcCount=0,this._lastGcCheck=0,this._gcCheckInterval=1e3}var e=t.prototype;return e.enable=function(){this._isEnabled=!0},e.disable=function(){this._isEnabled=!1},e.startMonitoring=function(t){return this._isEnabled?performance.now():0},e.endMonitoring=function(t,e,n){if(void 0===n&&(n=0),this._isEnabled&&0!==e){var i=performance.now(),r=i-e,o={name:t,executionTime:r,entityCount:n,averageTimePerEntity:n>0?r/n:0,lastUpdateTime:i};this._systemData.set(t,o),this.updateStats(t,r)}},e.updateStats=function(t,e){var n=this._systemStats.get(t);n||(n={totalTime:0,averageTime:0,minTime:Number.MAX_VALUE,maxTime:0,executionCount:0,recentTimes:[],standardDeviation:0,percentile95:0,percentile99:0},this._systemStats.set(t,n)),n.totalTime+=e,n.executionCount++,n.averageTime=n.totalTime/n.executionCount,n.minTime=Math.min(n.minTime,e),n.maxTime=Math.max(n.maxTime,e),n.recentTimes.push(e),n.recentTimes.length>this._maxRecentSamples&&n.recentTimes.shift(),this.calculateAdvancedStats(n)},e.calculateAdvancedStats=function(t){if(0!==t.recentTimes.length){var e=t.recentTimes.reduce((function(t,e){return t+e}),0)/t.recentTimes.length,n=t.recentTimes.reduce((function(t,n){return t+Math.pow(n-e,2)}),0)/t.recentTimes.length;t.standardDeviation=Math.sqrt(n);var i=[].concat(t.recentTimes).sort((function(t,e){return t-e})),r=i.length;t.percentile95=i[Math.floor(.95*r)]||0,t.percentile99=i[Math.floor(.99*r)]||0}},e.getSystemData=function(t){return this._systemData.get(t)},e.getSystemStats=function(t){return this._systemStats.get(t)},e.getAllSystemData=function(){return new Map(this._systemData)},e.getAllSystemStats=function(){return new Map(this._systemStats)},e.getPerformanceReport=function(){if(!this._isEnabled)return"Performance monitoring is disabled.";var t=[];t.push("=== ECS Performance Report ==="),t.push("");for(var e,n=s(Array.from(this._systemStats.entries()).sort((function(t,e){return e[1].averageTime-t[1].averageTime})));!(e=n()).done;){var i=e.value,r=i[0],o=i[1],a=this._systemData.get(r);t.push("System: "+r),t.push(" Current: "+(null==a?void 0:a.executionTime.toFixed(2))+"ms ("+(null==a?void 0:a.entityCount)+" entities)"),t.push(" Average: "+o.averageTime.toFixed(2)+"ms"),t.push(" Min/Max: "+o.minTime.toFixed(2)+"ms / "+o.maxTime.toFixed(2)+"ms"),t.push(" Total: "+o.totalTime.toFixed(2)+"ms ("+o.executionCount+" calls)"),null!=a&&a.averageTimePerEntity&&a.averageTimePerEntity>0&&t.push(" Per Entity: "+a.averageTimePerEntity.toFixed(4)+"ms"),t.push("")}var c=Array.from(this._systemData.values()).reduce((function(t,e){return t+e.executionTime}),0);return t.push("Total Frame Time: "+c.toFixed(2)+"ms"),t.push("Systems Count: "+this._systemData.size),t.join("\n")},e.reset=function(){this._systemData.clear(),this._systemStats.clear()},e.resetSystem=function(t){this._systemData.delete(t),this._systemStats.delete(t)},e.getPerformanceWarnings=function(t){void 0===t&&(t=16.67);for(var e,n=[],i=s(this._systemData.entries());!(e=i()).done;){var r=e.value,o=r[0],a=r[1];a.executionTime>t&&n.push(o+": "+a.executionTime.toFixed(2)+"ms (>"+t+"ms)")}return n},e.setMaxRecentSamples=function(t){this._maxRecentSamples=t;for(var e,n=s(this._systemStats.values());!(e=n()).done;)for(var i=e.value;i.recentTimes.length>t;)i.recentTimes.shift()},o(t,[{key:"isEnabled",get:function(){return this._isEnabled}}],[{key:"instance",get:function(){return t._instance||(t._instance=new t),t._instance}}])}(),T=function(){function t(t,e,n){void 0===e&&(e=100),void 0===n&&(n=1024),this._objects=[],this._createFn=t,this._maxSize=e,this._objectSize=n,this._stats={size:0,maxSize:e,totalCreated:0,totalObtained:0,totalReleased:0,hitRate:0,estimatedMemoryUsage:0}}t.getPool=function(e,n,i){void 0===n&&(n=100),void 0===i&&(i=1024);var r=this._pools.get(e);return r||(r=new t((function(){return new e}),n,i),this._pools.set(e,r)),r};var e=t.prototype;return e.obtain=function(){if(this._stats.totalObtained++,this._objects.length>0){var t=this._objects.pop();return this._stats.size--,this._updateHitRate(),this._updateMemoryUsage(),t}return this._stats.totalCreated++,this._updateHitRate(),this._createFn()},e.release=function(t){t&&(this._stats.totalReleased++,this._stats.size<this._maxSize&&(t.reset(),this._objects.push(t),this._stats.size++,this._updateMemoryUsage()))},e.getStats=function(){return a({},this._stats)},e.clear=function(){for(var t,e=s(this._objects);!(t=e()).done;){t.value.reset()}this._objects.length=0,this._stats.size=0,this._updateMemoryUsage()},e.compact=function(t){for(var e=null!=t?t:Math.floor(this._objects.length/2);this._objects.length>e;){var n=this._objects.pop();n&&(n.reset(),this._stats.size--)}this._updateMemoryUsage()},e.prewarm=function(t){for(var e=Math.min(t,this._maxSize-this._objects.length),n=0;n<e;n++){var i=this._createFn();i.reset(),this._objects.push(i),this._stats.totalCreated++,this._stats.size++}this._updateMemoryUsage()},e.setMaxSize=function(t){this._maxSize=t,this._stats.maxSize=t,this._objects.length>t&&this.compact(t)},e.getAvailableCount=function(){return this._objects.length},e.isEmpty=function(){return 0===this._objects.length},e.isFull=function(){return this._objects.length>=this._maxSize},t.getAllPoolTypes=function(){return Array.from(this._pools.keys())},t.getAllPoolStats=function(){for(var t,e={},n=s(this._pools);!(t=n()).done;){var i=t.value,r=i[0],o=i[1];e[r.name||r.toString()]=o.getStats()}return e},t.compactAllPools=function(){for(var t,e=s(this._pools.values());!(t=e()).done;){t.value.compact()}},t.clearAllPools=function(){for(var t,e=s(this._pools.values());!(t=e()).done;){t.value.clear()}this._pools.clear()},t.getGlobalStatsString=function(){var t=this.getAllPoolStats(),e=["=== Object Pool Global Statistics ===",""];if(0===Object.keys(t).length)return e.push("No pools registered"),e.join("\n");for(var n=0,i=Object.entries(t);n<i.length;n++){var r=i[n],o=r[0],s=r[1];e.push(o+":"),e.push(" Size: "+s.size+"/"+s.maxSize),e.push(" Hit Rate: "+(100*s.hitRate).toFixed(1)+"%"),e.push(" Total Created: "+s.totalCreated),e.push(" Total Obtained: "+s.totalObtained),e.push(" Memory: "+(s.estimatedMemoryUsage/1024).toFixed(1)+" KB"),e.push("")}return e.join("\n")},e._updateHitRate=function(){if(0===this._stats.totalObtained)this._stats.hitRate=0;else{var t=this._stats.totalObtained-this._stats.totalCreated;this._stats.hitRate=t/this._stats.totalObtained}},e._updateMemoryUsage=function(){this._stats.estimatedMemoryUsage=this._stats.size*this._objectSize},t}();T._pools=new Map;var C,b=function(){function t(){this.pools=new Map,this.autoCompactInterval=6e4,this.lastCompactTime=0}t.getInstance=function(){return t.instance||(t.instance=new t),t.instance};var e=t.prototype;return e.registerPool=function(t,e){this.pools.set(t,e)},e.getPool=function(t){return this.pools.get(t)||null},e.update=function(){var t=Date.now();t-this.lastCompactTime>this.autoCompactInterval&&(this.compactAllPools(),this.lastCompactTime=t)},e.createPool=function(t,e,n,i){void 0===n&&(n=100),void 0===i&&(i=1024);var r=this.pools.get(t);return r||(r=new T(e,n,i),this.pools.set(t,r)),r},e.removePool=function(t){var e=this.pools.get(t);return!!e&&(e.clear(),this.pools.delete(t),!0)},e.getPoolNames=function(){return Array.from(this.pools.keys())},e.getPoolCount=function(){return this.pools.size},e.compactAllPools=function(){for(var t,e=s(this.pools.values());!(t=e()).done;){t.value.compact()}},e.clearAllPools=function(){for(var t,e=s(this.pools.values());!(t=e()).done;){t.value.clear()}},e.getAllStats=function(){for(var t,e=new Map,n=s(this.pools);!(t=n()).done;){var i=t.value,r=i[0],o=i[1];e.set(r,o.getStats())}return e},e.getGlobalStats=function(){for(var t,e=0,n=0,i=0,r=0,o=0,a=0,c=s(this.pools.values());!(t=c()).done;){var u=t.value.getStats();e+=u.size,n+=u.maxSize,i+=u.totalCreated,r+=u.totalObtained,o+=u.totalReleased,a+=u.estimatedMemoryUsage}return{size:e,maxSize:n,totalCreated:i,totalObtained:r,totalReleased:o,hitRate:0===r?0:(r-i)/r,estimatedMemoryUsage:a}},e.getStatsString=function(){var t=["=== Pool Manager Statistics ===",""];if(0===this.pools.size)return t.push("No pools registered"),t.join("\n");var e=this.getGlobalStats();t.push("Total Pools: "+this.pools.size),t.push("Global Hit Rate: "+(100*e.hitRate).toFixed(1)+"%"),t.push("Global Memory Usage: "+(e.estimatedMemoryUsage/1024).toFixed(1)+" KB"),t.push("");for(var n,i=s(this.pools);!(n=i()).done;){var r=n.value,o=r[0],a=r[1].getStats();t.push(o+":"),t.push(" Size: "+a.size+"/"+a.maxSize),t.push(" Hit Rate: "+(100*a.hitRate).toFixed(1)+"%"),t.push(" Memory: "+(a.estimatedMemoryUsage/1024).toFixed(1)+" KB"),t.push("")}return t.join("\n")},e.setAutoCompactInterval=function(t){this.autoCompactInterval=t},e.prewarmAllPools=function(){for(var t,e=s(this.pools.values());!(t=e()).done;){var n=t.value,i=n.getStats(),r=Math.floor(.2*i.maxSize);n.prewarm(r)}},e.reset=function(){this.clearAllPools(),this.pools.clear(),this.lastCompactTime=0},t}(),M=function(){function t(){}return t.create=function(t){if(t<0||t>=64)throw new Error("Bit index "+t+" out of range [0, 63]");return t<32?{lo:1<<t,hi:0}:{lo:0,hi:1<<t-32}},t.fromNumber=function(t){return{lo:t>>>0,hi:0}},t.hasAny=function(t,e){return 0!==(t.lo&e.lo)||0!==(t.hi&e.hi)},t.hasAll=function(t,e){return(t.lo&e.lo)===e.lo&&(t.hi&e.hi)===e.hi},t.hasNone=function(t,e){return 0===(t.lo&e.lo)&&0===(t.hi&e.hi)},t.isZero=function(t){return 0===t.lo&&0===t.hi},t.equals=function(t,e){return t.lo===e.lo&&t.hi===e.hi},t.setBit=function(t,e){if(e<0||e>=64)throw new Error("Bit index "+e+" out of range [0, 63]");e<32?t.lo|=1<<e:t.hi|=1<<e-32},t.clearBit=function(t,e){if(e<0||e>=64)throw new Error("Bit index "+e+" out of range [0, 63]");e<32?t.lo&=~(1<<e):t.hi&=~(1<<e-32)},t.orInPlace=function(t,e){t.lo|=e.lo,t.hi|=e.hi},t.andInPlace=function(t,e){t.lo&=e.lo,t.hi&=e.hi},t.xorInPlace=function(t,e){t.lo^=e.lo,t.hi^=e.hi},t.clear=function(t){t.lo=0,t.hi=0},t.copy=function(t,e){e.lo=t.lo,e.hi=t.hi},t.clone=function(t){return{lo:t.lo,hi:t.hi}},t.toString=function(t,e){if(void 0===e&&(e=2),2===e)return 0===t.hi?t.lo.toString(2):t.hi.toString(2)+t.lo.toString(2).padStart(32,"0");if(16===e)return 0===t.hi?"0x"+t.lo.toString(16).toUpperCase():"0x"+t.hi.toString(16).toUpperCase()+t.lo.toString(16).toUpperCase().padStart(8,"0");throw new Error("Only radix 2 and 16 are supported")},t.popCount=function(t){for(var e=0,n=t.lo,i=t.hi;n;)n&=n-1,e++;for(;i;)i&=i-1,e++;return e},t}();M.ZERO={lo:0,hi:0},exports.LogLevel=void 0,(C=exports.LogLevel||(exports.LogLevel={}))[C.Debug=0]="Debug",C[C.Info=1]="Info",C[C.Warn=2]="Warn",C[C.Error=3]="Error",C[C.Fatal=4]="Fatal",C[C.None=5]="None";var x={BLACK:"[30m",RED:"[31m",GREEN:"[32m",YELLOW:"[33m",BLUE:"[34m",MAGENTA:"[35m",CYAN:"[36m",WHITE:"[37m",BRIGHT_BLACK:"[90m",BRIGHT_RED:"[91m",BRIGHT_GREEN:"[92m",BRIGHT_YELLOW:"[93m",BRIGHT_BLUE:"[94m",BRIGHT_MAGENTA:"[95m",BRIGHT_CYAN:"[96m",BRIGHT_WHITE:"[97m",RESET:"[0m",BOLD:"[1m",UNDERLINE:"[4m"},w=function(){function t(t){void 0===t&&(t={}),this._config=a({level:exports.LogLevel.Info,enableTimestamp:!0,enableColors:"undefined"==typeof window},t)}var e=t.prototype;return e.debug=function(t){for(var e=arguments.length,n=new Array(e>1?e-1:0),i=1;i<e;i++)n[i-1]=arguments[i];this.log.apply(this,[exports.LogLevel.Debug,t].concat(n))},e.info=function(t){for(var e=arguments.length,n=new Array(e>1?e-1:0),i=1;i<e;i++)n[i-1]=arguments[i];this.log.apply(this,[exports.LogLevel.Info,t].concat(n))},e.warn=function(t){for(var e=arguments.length,n=new Array(e>1?e-1:0),i=1;i<e;i++)n[i-1]=arguments[i];this.log.apply(this,[exports.LogLevel.Warn,t].concat(n))},e.error=function(t){for(var e=arguments.length,n=new Array(e>1?e-1:0),i=1;i<e;i++)n[i-1]=arguments[i];this.log.apply(this,[exports.LogLevel.Error,t].concat(n))},e.fatal=function(t){for(var e=arguments.length,n=new Array(e>1?e-1:0),i=1;i<e;i++)n[i-1]=arguments[i];this.log.apply(this,[exports.LogLevel.Fatal,t].concat(n))},e.setLevel=function(t){this._config.level=t},e.setColors=function(t){0===Object.keys(t).length?delete this._config.colors:this._config.colors=a({},this._config.colors,t)},e.setPrefix=function(t){this._config.prefix=t},e.log=function(t,e){if(!(t<this._config.level)){var n=e;if(this._config.enableTimestamp)n="["+(new Date).toISOString()+"] "+n;if(this._config.prefix&&(n="["+this._config.prefix+"] "+n),n="["+exports.LogLevel[t].toUpperCase()+"] "+n,this._config.output)this._config.output(t,n);else{for(var i=arguments.length,r=new Array(i>2?i-2:0),o=2;o<i;o++)r[o-2]=arguments[o];this.outputToConsole.apply(this,[t,n].concat(r))}}},e.outputToConsole=function(t,e){for(var n=this._config.enableColors?this.getColors():null,i=arguments.length,r=new Array(i>2?i-2:0),o=2;o<i;o++)r[o-2]=arguments[o];switch(t){case exports.LogLevel.Debug:var s,a;if(n)(s=console).debug.apply(s,[""+n.debug+e+n.reset].concat(r));else(a=console).debug.apply(a,[e].concat(r));break;case exports.LogLevel.Info:var c,u;if(n)(c=console).info.apply(c,[""+n.info+e+n.reset].concat(r));else(u=console).info.apply(u,[e].concat(r));break;case exports.LogLevel.Warn:var h,l;if(n)(h=console).warn.apply(h,[""+n.warn+e+n.reset].concat(r));else(l=console).warn.apply(l,[e].concat(r));break;case exports.LogLevel.Error:var d,f;if(n)(d=console).error.apply(d,[""+n.error+e+n.reset].concat(r));else(f=console).error.apply(f,[e].concat(r));break;case exports.LogLevel.Fatal:var p,m;if(n)(p=console).error.apply(p,[""+n.fatal+e+n.reset].concat(r));else(m=console).error.apply(m,[e].concat(r))}},e.getColors=function(){return a({},{debug:x.BRIGHT_BLACK,info:x.GREEN,warn:x.YELLOW,error:x.RED,fatal:x.BRIGHT_RED,reset:x.RESET},this._config.colors)},t}(),I=function(){function t(){this._loggers=new Map,this._defaultLogger=new w}t.getInstance=function(){return t._instance||(t._instance=new t),t._instance};var e=t.prototype;return e.getLogger=function(t){if(!t)return this._defaultLogger;if(!this._loggers.has(t)){var e=new w({prefix:t,level:exports.LogLevel.Info});this._loggers.set(t,e)}return this._loggers.get(t)},e.setLogger=function(t,e){this._loggers.set(t,e)},e.setGlobalLevel=function(t){this._defaultLogger instanceof w&&this._defaultLogger.setLevel(t);for(var e,n=s(this._loggers.values());!(e=n()).done;){var i=e.value;i instanceof w&&i.setLevel(t)}},e.createChildLogger=function(t,e){var n=t+"."+e;return this.getLogger(n)},e.setGlobalColors=function(t){this._defaultLogger instanceof w&&this._defaultLogger.setColors(t);for(var e,n=s(this._loggers.values());!(e=n()).done;){var i=e.value;i instanceof w&&i.setColors(t)}},e.resetColors=function(){this._defaultLogger instanceof w&&this._defaultLogger.setColors({});for(var t,e=s(this._loggers.values());!(t=e()).done;){var n=t.value;n instanceof w&&n.setColors({})}},t}(),A=I.getInstance().getLogger();function D(t){return I.getInstance().getLogger(t)}var O=function(){function t(t){this.fields=new Map,this.stringFields=new Map,this.serializedFields=new Map,this.complexFields=new Map,this.entityToIndex=new Map,this.indexToEntity=[],this.freeIndices=[],this._size=0,this._capacity=1e3,this.type=t,this.initializeFields(t)}var e=t.prototype;return e.initializeFields=function(t){var e=new t,n=t.__highPrecisionFields||new Set,i=t.__float64Fields||new Set,r=t.__float32Fields||new Set,o=t.__int32Fields||new Set,s=t.__serializeMapFields||new Set,a=t.__serializeSetFields||new Set,c=t.__serializeArrayFields||new Set;for(var u in e)if(e.hasOwnProperty(u)&&"id"!==u){var h=e[u],l=typeof h;"number"===l?n.has(u)||(i.has(u)?this.fields.set(u,new Float64Array(this._capacity)):o.has(u)?this.fields.set(u,new Int32Array(this._capacity)):(r.has(u),this.fields.set(u,new Float32Array(this._capacity)))):"boolean"===l?this.fields.set(u,new Float32Array(this._capacity)):"string"===l?this.stringFields.set(u,new Array(this._capacity)):"object"===l&&null!==h&&(s.has(u)||a.has(u)||c.has(u))&&this.serializedFields.set(u,new Array(this._capacity))}},e.addComponent=function(t,e){if(this.entityToIndex.has(t)){var n=this.entityToIndex.get(t);this.updateComponentAtIndex(n,e)}else{var i;this.freeIndices.length>0?i=this.freeIndices.pop():(i=this._size)>=this._capacity&&this.resize(2*this._capacity),this.entityToIndex.set(t,i),this.indexToEntity[i]=t,this.updateComponentAtIndex(i,e),this._size++}},e.updateComponentAtIndex=function(t,e){var n=this.indexToEntity[t],i=new Map,r=this.type.__highPrecisionFields||new Set,o=this.type.__serializeMapFields||new Set,s=this.type.__serializeSetFields||new Set,a=this.type.__serializeArrayFields||new Set,c=this.type.__deepCopyFields||new Set;for(var u in e)if(e.hasOwnProperty(u)&&"id"!==u){var h=e[u],l=typeof h;if("number"===l)if(r.has(u)||!this.fields.has(u))i.set(u,h);else this.fields.get(u)[t]=h;else if("boolean"===l&&this.fields.has(u)){this.fields.get(u)[t]=h?1:0}else if(this.stringFields.has(u)){this.stringFields.get(u)[t]=String(h)}else if(this.serializedFields.has(u)){this.serializedFields.get(u)[t]=this.serializeValue(h,u,o,s,a)}else c.has(u)?i.set(u,this.deepClone(h)):i.set(u,h)}i.size>0&&this.complexFields.set(n,i)},e.serializeValue=function(e,n,i,r,o){try{return i.has(n)&&e instanceof Map?JSON.stringify(Array.from(e.entries())):r.has(n)&&e instanceof Set?JSON.stringify(Array.from(e)):(o.has(n)&&Array.isArray(e),JSON.stringify(e))}catch(e){return t._logger.warn("SoA序列化字段 "+n+" 失败:",e),"{}"}},e.deserializeValue=function(e,n,i,r,o){try{var s=JSON.parse(e);return i.has(n)?new Map(s):r.has(n)?new Set(s):(o.has(n),s)}catch(e){return t._logger.warn("SoA反序列化字段 "+n+" 失败:",e),null}},e.deepClone=function(t){var e=this;if(null===t||"object"!=typeof t)return t;if(t instanceof Date)return new Date(t.getTime());if(t instanceof Array)return t.map((function(t){return e.deepClone(t)}));if(t instanceof Map){for(var n,i=new Map,r=s(t.entries());!(n=r()).done;){var o=n.value,a=o[0],c=o[1];i.set(a,this.deepClone(c))}return i}if(t instanceof Set){for(var u,h=new Set,l=s(t.values());!(u=l()).done;){var d=u.value;h.add(this.deepClone(d))}return h}var f={};for(var p in t)t.hasOwnProperty(p)&&(f[p]=this.deepClone(t[p]));return f},e.getComponent=function(t){var e=this.entityToIndex.get(t);if(void 0===e)return null;for(var n,i=new this.type,r=this.type.__serializeMapFields||new Set,o=this.type.__serializeSetFields||new Set,a=this.type.__serializeArrayFields||new Set,c=s(this.fields.entries());!(n=c()).done;){var u=n.value,h=u[0],l=u[1][e],d=this.getFieldType(h);i[h]="boolean"===d?1===l:l}for(var f,p=s(this.stringFields.entries());!(f=p()).done;){var m=f.value,y=m[0],g=m[1];i[y]=g[e]}for(var v,_=s(this.serializedFields.entries());!(v=_()).done;){var E=v.value,S=E[0],T=E[1][e];T&&(i[S]=this.deserializeValue(T,S,r,o,a))}var C=this.complexFields.get(t);if(C)for(var b,M=s(C.entries());!(b=M()).done;){var x=b.value,w=x[0],I=x[1];i[w]=I}return i},e.getFieldType=function(t){return typeof(new this.type)[t]},e.hasComponent=function(t){return this.entityToIndex.has(t)},e.removeComponent=function(t){var e=this.entityToIndex.get(t);if(void 0===e)return null;var n=this.getComponent(t);return this.complexFields.delete(t),this.entityToIndex.delete(t),this.freeIndices.push(e),this._size--,n},e.resize=function(t){for(var e,n=s(this.fields.entries());!(e=n()).done;){var i=e.value,r=i[0],o=i[1],a=void 0;(a=o instanceof Float32Array?new Float32Array(t):o instanceof Float64Array?new Float64Array(t):new Int32Array(t)).set(o),this.fields.set(r,a)}for(var c,u=s(this.stringFields.entries());!(c=u()).done;){for(var h=c.value,l=h[0],d=h[1],f=new Array(t),p=0;p<d.length;p++)f[p]=d[p];this.stringFields.set(l,f)}for(var m,y=s(this.serializedFields.entries());!(m=y()).done;){for(var g=m.value,v=g[0],_=g[1],E=new Array(t),S=0;S<_.length;S++)E[S]=_[S];this.serializedFields.set(v,E)}this._capacity=t},e.getActiveIndices=function(){return Array.from(this.entityToIndex.values())},e.getFieldArray=function(t){return this.fields.get(t)||null},e.getTypedFieldArray=function(t){return this.fields.get(String(t))||null},e.getEntityIndex=function(t){return this.entityToIndex.get(t)},e.getEntityIdByIndex=function(t){return this.indexToEntity[t]},e.size=function(){return this._size},e.clear=function(){this.entityToIndex.clear(),this.indexToEntity=[],this.freeIndices=[],this.complexFields.clear(),this._size=0;for(var t,e=s(this.fields.values());!(t=e()).done;){t.value.fill(0)}for(var n,i=s(this.stringFields.values());!(n=i()).done;)for(var r=n.value,o=0;o<r.length;o++)r[o]=void 0;for(var a,c=s(this.serializedFields.values());!(a=c()).done;)for(var u=a.value,h=0;h<u.length;h++)u[h]=void 0},e.compact=function(){if(0!==this.freeIndices.length){for(var t=Array.from(this.entityToIndex.entries()).sort((function(t,e){return t[1]-e[1]})),e=new Map,n=[],i=0;i<t.length;i++){var r=t[i],o=r[0],a=r[1];if(e.set(o,i),n[i]=o,i!==a){for(var c,u=s(this.fields.entries());!(c=u()).done;){var h=c.value[1];h[i]=h[a]}for(var l,d=s(this.stringFields.entries());!(l=d()).done;){var f=l.value[1];f[i]=f[a]}for(var p,m=s(this.serializedFields.entries());!(p=m()).done;){var y=p.value[1];y[i]=y[a]}}}this.entityToIndex=e,this.indexToEntity=n,this.freeIndices=[],this._size=t.length}},e.getStats=function(){for(var t,e=0,n=new Map,i=s(this.fields.entries());!(t=i()).done;){var r=t.value,o=r[0],a=r[1],c=void 0,u=void 0;a instanceof Float32Array?(c=4,u="float32"):a instanceof Float64Array?(c=8,u="float64"):(c=4,u="int32");var h=a.length*c;e+=h,n.set(o,{size:this._size,capacity:a.length,type:u,memory:h})}return{size:this._size,capacity:this._capacity,usedSlots:this._size,fragmentation:this.freeIndices.length/this._capacity,memoryUsage:e,fieldStats:n}},e.performVectorizedOperation=function(t){var e=this.getActiveIndices();t(this.fields,e)},t}();O._logger=D("SoAStorage");var k=Symbol("ComponentTypeName"),N=Symbol("SystemTypeName");function P(t){var e=t[k];return e||(t.name||"UnknownComponent")}function R(t){var e=t[N];return e||(t.name||"UnknownSystem")}function z(t){return P(t.constructor)}function B(t){return R(t.constructor)}var F=function(){function t(){}return t.register=function(t){var e=P(t);if(this.componentTypes.has(t))return this.componentTypes.get(t);if(this.nextBitIndex>=this.maxComponents)throw new Error("Maximum number of component types ("+this.maxComponents+") exceeded");var n=this.nextBitIndex++;return this.componentTypes.set(t,n),this.componentNameToType.set(e,t),this.componentNameToId.set(e,n),n},t.getBitMask=function(t){var e=this.componentTypes.get(t);if(void 0===e){var n=P(t);throw new Error("Component type "+n+" is not registered")}return M.create(e)},t.getBitIndex=function(t){var e=this.componentTypes.get(t);if(void 0===e){var n=P(t);throw new Error("Component type "+n+" is not registered")}return e},t.isRegistered=function(t){return this.componentTypes.has(t)},t.getComponentType=function(t){return this.componentNameToType.get(t)||null},t.getAllRegisteredTypes=function(){return new Map(this.componentTypes)},t.getAllComponentNames=function(){return new Map(this.componentNameToType)},t.getComponentId=function(t){return this.componentNameToId.get(t)},t.registerComponentByName=function(t){if(this.componentNameToId.has(t))return this.componentNameToId.get(t);if(this.nextBitIndex>=this.maxComponents)throw new Error("Maximum number of component types ("+this.maxComponents+") exceeded");var e=this.nextBitIndex++;return this.componentNameToId.set(t,e),e},t.createSingleComponentMask=function(t){var e="single:"+t;if(this.maskCache.has(e))return this.maskCache.get(e);var n=this.getComponentId(t);if(void 0===n)throw new Error("Component type "+t+" is not registered");var i=M.create(n);return this.maskCache.set(e,i),i},t.createComponentMask=function(t){var e="multi:"+[].concat(t).sort().join(",");if(this.maskCache.has(e))return this.maskCache.get(e);for(var n,i=M.clone(M.ZERO),r=s(t);!(n=r()).done;){var o=n.value,a=this.getComponentId(o);if(void 0!==a){var c=M.create(a);M.orInPlace(i,c)}}return this.maskCache.set(e,i),i},t.clearMaskCache=function(){this.maskCache.clear()},t.reset=function(){this.componentTypes.clear(),this.componentNameToType.clear(),this.componentNameToId.clear(),this.maskCache.clear(),this.nextBitIndex=0},t}();F._logger=D("ComponentStorage"),F.componentTypes=new Map,F.componentNameToType=new Map,F.componentNameToId=new Map,F.maskCache=new Map,F.nextBitIndex=0,F.maxComponents=64;var L=function(){function t(t){this.dense=[],this.entityIds=[],this.entityToIndex=new Map,this.componentType=t,F.isRegistered(t)||F.register(t)}var e=t.prototype;return e.addComponent=function(t,e){if(this.entityToIndex.has(t))throw new Error("Entity "+t+" already has component "+P(this.componentType));var n=this.dense.length;this.dense.push(e),this.entityIds.push(t),this.entityToIndex.set(t,n)},e.getComponent=function(t){var e=this.entityToIndex.get(t);return void 0!==e?this.dense[e]:null},e.hasComponent=function(t){return this.entityToIndex.has(t)},e.removeComponent=function(t){var e=this.entityToIndex.get(t);if(void 0===e)return null;var n=this.dense[e],i=this.dense.length-1;if(e!==i){var r=this.dense[i],o=this.entityIds[i];this.dense[e]=r,this.entityIds[e]=o,this.entityToIndex.set(o,e)}return this.dense.pop(),this.entityIds.pop(),this.entityToIndex.delete(t),n},e.forEach=function(t){for(var e=0;e<this.dense.length;e++)t(this.dense[e],this.entityIds[e],e)},e.getDenseArray=function(){return{components:[].concat(this.dense),entityIds:[].concat(this.entityIds)}},e.clear=function(){this.dense.length=0,this.entityIds.length=0,this.entityToIndex.clear()},e.getStats=function(){return{totalSlots:this.dense.length,usedSlots:this.dense.length,freeSlots:0,fragmentation:0}},o(t,[{key:"size",get:function(){return this.dense.length}},{key:"type",get:function(){return this.componentType}}])}(),q=function(){function t(){this.storages=new Map}var e=t.prototype;return e.isSoAStorage=function(t){return this.storages.get(t)instanceof O},e.getSoAStorage=function(t){var e=this.getStorage(t);return e instanceof O?e:null},e.getFieldArray=function(t,e){var n=this.getSoAStorage(t);return n?n.getFieldArray(e):null},e.getTypedFieldArray=function(t,e){var n=this.getSoAStorage(t);return n?n.getTypedFieldArray(e):null},e.getActiveIndices=function(t){var e=this.getSoAStorage(t);return e?e.getActiveIndices():[]},e.getEntityIndex=function(t,e){var n=this.getSoAStorage(t);return n?n.getEntityIndex(e):void 0},e.getEntityIdByIndex=function(t,e){var n=this.getSoAStorage(t);return n?n.getEntityIdByIndex(e):void 0},e.getStorage=function(e){var n=this.storages.get(e);n||(e.__enableSoA?(n=new O(e),t._logger.info("为 "+P(e)+" 启用SoA优化(适用于大规模批量操作)")):n=new L(e),this.storages.set(e,n));return n},e.addComponent=function(t,e){var n=e.constructor;this.getStorage(n).addComponent(t,e)},e.getComponent=function(t,e){var n=this.storages.get(e);return n?n.getComponent(t):null},e.hasComponent=function(t,e){var n=this.storages.get(e);return!!n&&n.hasComponent(t)},e.removeComponent=function(t,e){var n=this.storages.get(e);return n?n.removeComponent(t):null},e.removeAllComponents=function(t){for(var e,n=s(this.storages.values());!(e=n()).done;){e.value.removeComponent(t)}},e.getComponentMask=function(t){for(var e,n=M.clone(M.ZERO),i=s(this.storages.entries());!(e=i()).done;){var r=e.value,o=r[0];if(r[1].hasComponent(t)){var a=F.getBitMask(o);M.orInPlace(n,a)}}return n},e.getAllStats=function(){for(var t,e=new Map,n=s(this.storages.entries());!(t=n()).done;){var i=t.value,r=i[0],o=i[1],a=P(r);e.set(a,o.getStats())}return e},e.clear=function(){for(var t,e=s(this.storages.values());!(t=e()).done;){t.value.clear()}this.storages.clear()},t}();q._logger=D("ComponentStorage");var W=function(){function t(){}return t.prototype.compare=function(t,e){var n=t.updateOrder-e.updateOrder;return 0==n&&(n=t.id-e.id),n},t}(),U=function(){function t(t,e){this.components=[],this.scene=null,this.updateInterval=1,this._isDestroyed=!1,this._parent=null,this._children=[],this._active=!0,this._tag=0,this._enabled=!0,this._updateOrder=0,this._componentMask=M.clone(M.ZERO),this._componentsByTypeId=[],this._componentDenseIndexByTypeId=[],this.name=t,this.id=e}var e=t.prototype;return e.createComponent=function(t){for(var e=arguments.length,n=new Array(e>1?e-1:0),r=1;r<e;r++)n[r-1]=arguments[r];var o=i(t,n);return this.addComponent(o)},e.addComponentInternal=function(t){var e=t.constructor;F.isRegistered(e)||F.register(e);var n=F.getBitIndex(e);t.entity=this,this._componentsByTypeId[n]=t;var i=this.components.length;this._componentDenseIndexByTypeId[n]=i,this.components.push(t);var r=F.getBitMask(e);return M.orInPlace(this._componentMask,r),t},e.addComponent=function(e){var n,i=e.constructor;if(this.hasComponent(i))throw new Error("Entity "+this.name+" already has component "+P(i));(this.addComponentInternal(e),this.scene&&this.scene.componentStorageManager&&this.scene.componentStorageManager.addComponent(this.id,e),e.onAddedToEntity(),t.eventBus)&&t.eventBus.emitComponentAdded({timestamp:Date.now(),source:"Entity",entityId:this.id,entityName:this.name,entityTag:null===(n=this.tag)||void 0===n?void 0:n.toString(),componentType:P(i),component:e});return this.scene&&this.scene.querySystem&&(this.scene.querySystem.removeEntity(this),this.scene.querySystem.addEntity(this)),e},e.getComponent=function(t){if(!F.isRegistered(t))return null;var e=F.getBitMask(t);if(M.hasNone(this._componentMask,e))return null;var n=F.getBitIndex(t),i=this._componentsByTypeId[n];if(i&&i.constructor===t)return i;if(this.scene&&this.scene.componentStorageManager){var r=this.scene.componentStorageManager.getComponent(this.id,t);if(r){if(this._componentsByTypeId[n]=r,!this.components.includes(r)){var o=this.components.length;this._componentDenseIndexByTypeId[n]=o,this.components.push(r)}return r}}for(var s=0;s<this.components.length;s++){var a=this.components[s];if(a instanceof t)return this._componentsByTypeId[n]=a,this._componentDenseIndexByTypeId[n]=s,a}return null},e.hasComponent=function(t){if(!F.isRegistered(t))return!1;var e=F.getBitMask(t);return M.hasAny(this._componentMask,e)},e.getOrCreateComponent=function(t){var e=this.getComponent(t);if(!e){for(var n=arguments.length,i=new Array(n>1?n-1:0),r=1;r<n;r++)i[r-1]=arguments[r];e=this.createComponent.apply(this,[t].concat(i))}return e},e.removeComponent=function(e){var n=e.constructor;if(F.isRegistered(n)){var i=F.getBitIndex(n);this._componentsByTypeId[i]=void 0,M.clearBit(this._componentMask,i);var r,o=this._componentDenseIndexByTypeId[i];if(void 0!==o&&o<this.components.length){var s=this.components.length-1;if(o!==s){var a=this.components[s];this.components[o]=a;var c=a.constructor,u=F.getBitIndex(c);this._componentDenseIndexByTypeId[u]=o}this.components.pop()}if(this._componentDenseIndexByTypeId[i]=-1,this.scene&&this.scene.componentStorageManager&&this.scene.componentStorageManager.removeComponent(this.id,n),e.onRemovedFromEntity&&e.onRemovedFromEntity(),t.eventBus)t.eventBus.emitComponentRemoved({timestamp:Date.now(),source:"Entity",entityId:this.id,entityName:this.name,entityTag:null===(r=this.tag)||void 0===r?void 0:r.toString(),componentType:P(n),component:e});e.entity=null,this.scene&&this.scene.querySystem&&(this.scene.querySystem.removeEntity(this),this.scene.querySystem.addEntity(this))}},e.removeComponentByType=function(t){var e=this.getComponent(t);return e?(this.removeComponent(e),e):null},e.removeAllComponents=function(){var t=[].concat(this.components);this._componentsByTypeId.length=0,this._componentDenseIndexByTypeId.length=0,M.clear(this._componentMask);for(var e,n=s(t);!(e=n()).done;){var i=e.value,r=i.constructor;this.scene&&this.scene.componentStorageManager&&this.scene.componentStorageManager.removeComponent(this.id,r),i.onRemovedFromEntity(),i.entity=null}this.components.length=0},e.addComponents=function(e){for(var n,i=[],r=s(e);!(n=r()).done;){var o=n.value;try{i.push(this.addComponent(o))}catch(e){t._logger.warn("添加组件失败 "+z(o)+":",e)}}return i},e.removeComponentsByTypes=function(t){for(var e,n=[],i=s(t);!(e=i()).done;){var r=e.value;n.push(this.removeComponentByType(r))}return n},e.getComponents=function(t){for(var e,n=[],i=s(this.components);!(e=i()).done;){var r=e.value;r instanceof t&&n.push(r)}return n},e.addChild=function(t){if(t===this)throw new Error("Entity cannot be its own child");return t._parent===this||(t._parent&&t._parent.removeChild(t),t._parent=this,this._children.push(t),!t.scene&&this.scene&&(t.scene=this.scene,this.scene.addEntity(t))),t},e.removeChild=function(t){var e=this._children.indexOf(t);return-1!==e&&(this._children.splice(e,1),t._parent=null,!0)},e.removeAllChildren=function(){for(var t,e=s([].concat(this._children));!(t=e()).done;){var n=t.value;this.removeChild(n)}},e.findChild=function(t,e){void 0===e&&(e=!1);for(var n,i=s(this._children);!(n=i()).done;){var r=n.value;if(r.name===t)return r}if(e)for(var o,a=s(this._children);!(o=a()).done;){var c=o.value.findChild(t,!0);if(c)return c}return null},e.findChildrenByTag=function(t,e){void 0===e&&(e=!1);for(var n,i=[],r=s(this._children);!(n=r()).done;){var o=n.value;o.tag===t&&i.push(o)}if(e)for(var a,c=s(this._children);!(a=c()).done;){var u=a.value;i.push.apply(i,u.findChildrenByTag(t,!0))}return i},e.getRoot=function(){for(var t=this;t._parent;)t=t._parent;return t},e.isAncestorOf=function(t){for(var e=t._parent;e;){if(e===this)return!0;e=e._parent}return!1},e.isDescendantOf=function(t){return t.isAncestorOf(this)},e.getDepth=function(){for(var t=0,e=this._parent;e;)t++,e=e._parent;return t},e.forEachChild=function(t,e){void 0===e&&(e=!1),this._children.forEach((function(n,i){t(n,i),e&&n.forEachChild(t,!0)}))},e.onActiveChanged=function(){for(var t,e=s(this.components);!(t=e()).done;){var n=t.value;"onActiveChanged"in n&&"function"==typeof n.onActiveChanged&&n.onActiveChanged()}this.scene&&this.scene.eventSystem&&this.scene.eventSystem.emitSync("entity:activeChanged",{entity:this,active:this._active,activeInHierarchy:this.activeInHierarchy})},e.update=function(){if(this.activeInHierarchy&&!this._isDestroyed){for(var t,e=s(this.components);!(t=e()).done;){var n=t.value;n.enabled&&n.update()}for(var i,r=s(this._children);!(i=r()).done;){i.value.update()}}},e.destroy=function(){if(!this._isDestroyed){this._isDestroyed=!0;for(var t,e=s([].concat(this._children));!(t=e()).done;){t.value.destroy()}this._parent&&this._parent.removeChild(this),this.removeAllComponents(),this.scene&&(this.scene.querySystem&&this.scene.querySystem.removeEntity(this),this.scene.entities&&this.scene.entities.remove(this))}},e.compareTo=function(t){return W.prototype.compare(this,t)},e.toString=function(){return"Entity["+this.name+":"+this.id+"]"},e.getDebugInfo=function(){var t;return{name:this.name,id:this.id,enabled:this._enabled,active:this._active,activeInHierarchy:this.activeInHierarchy,destroyed:this._isDestroyed,componentCount:this.components.length,componentTypes:this.components.map((function(t){return z(t)})),componentMask:M.toString(this._componentMask,2),parentId:(null===(t=this._parent)||void 0===t?void 0:t.id)||null,childCount:this._children.length,childIds:this._children.map((function(t){return t.id})),depth:this.getDepth(),indexMappingSize:this._componentsByTypeId.filter((function(t){return void 0!==t})).length,denseIndexMappingSize:this._componentDenseIndexByTypeId.filter((function(t){return-1!==t&&void 0!==t})).length}},o(t,[{key:"isDestroyed",get:function(){return this._isDestroyed}},{key:"parent",get:function(){return this._parent}},{key:"children",get:function(){return[].concat(this._children)}},{key:"childCount",get:function(){return this._children.length}},{key:"active",get:function(){return this._active},set:function(t){this._active!==t&&(this._active=t,this.onActiveChanged())}},{key:"activeInHierarchy",get:function(){return!!this._active&&(!this._parent||this._parent.activeInHierarchy)}},{key:"tag",get:function(){return this._tag},set:function(t){this._tag=t}},{key:"enabled",get:function(){return this._enabled},set:function(t){this._enabled=t}},{key:"updateOrder",get:function(){return this._updateOrder},set:function(t){this._updateOrder=t}},{key:"componentMask",get:function(){return this._componentMask}}])}();U._logger=D("Entity"),U.entityComparer=new W,U.eventBus=null;var j=function(){function t(t,e){this.scene=t,this.storageManager=e,this.entity=new U("",t.identifierPool.checkOut())}var e=t.prototype;return e.named=function(t){return this.entity.name=t,this},e.tagged=function(t){return this.entity.tag=t,this},e.with=function(t){return this.entity.addComponent(t),this},e.withComponents=function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];for(var i=0,r=e;i<r.length;i++){var o=r[i];this.entity.addComponent(o)}return this},e.withIf=function(t,e){return t&&this.entity.addComponent(e),this},e.withFactory=function(t){var e=t();return this.entity.addComponent(e),this},e.configure=function(t,e){var n=this.entity.getComponent(t);return n&&e(n),this},e.enabled=function(t){return void 0===t&&(t=!0),this.entity.enabled=t,this},e.active=function(t){return void 0===t&&(t=!0),this.entity.active=t,this},e.withChild=function(t){var e=t.build();return this.entity.addChild(e),this},e.withChildren=function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];for(var i=0,r=e;i<r.length;i++){var o=r[i].build();this.entity.addChild(o)}return this},e.withChildFactory=function(t){var e=t(this.entity).build();return this.entity.addChild(e),this},e.withChildIf=function(t,e){if(t){var n=e.build();this.entity.addChild(n)}return this},e.build=function(){return this.entity},e.spawn=function(){return this.scene.addEntity(this.entity),this.entity},e.clone=function(){var e=new t(this.scene,this.storageManager);return e.entity=this.entity,e},t}(),H=function(){function t(t){this.buffer=[],this._idToEntity=new Map,this._nameToEntities=new Map,this._entitiesToAdd=[],this._entitiesToRemove=[],this._isUpdating=!1,this._scene=t}var e=t.prototype;return e.add=function(t){this._isUpdating?this._entitiesToAdd.push(t):this.addImmediate(t)},e.addImmediate=function(t){this._idToEntity.has(t.id)||(this.buffer.push(t),this._idToEntity.set(t.id,t),this.updateNameIndex(t,!0))},e.remove=function(t){this._isUpdating?this._entitiesToRemove.push(t):this.removeImmediate(t)},e.removeImmediate=function(t){var e=this.buffer.indexOf(t);-1!==e&&(this.buffer.splice(e,1),this._idToEntity.delete(t.id),this.updateNameIndex(t,!1),this._scene&&this._scene.identifierPool&&this._scene.identifierPool.checkIn(t.id))},e.removeAllEntities=function(){for(var t=[],e=this.buffer.length-1;e>=0;e--)t.push(this.buffer[e].id),this.buffer[e].destroy();if(this._scene&&this._scene.identifierPool)for(var n,i=s(t);!(n=i()).done;){var r=n.value;this._scene.identifierPool.checkIn(r)}this.buffer.length=0,this._idToEntity.clear(),this._nameToEntities.clear(),this._entitiesToAdd.length=0,this._entitiesToRemove.length=0},e.updateLists=function(){if(this._entitiesToAdd.length>0){for(var t,e=s(this._entitiesToAdd);!(t=e()).done;){var n=t.value;this.addImmediate(n)}this._entitiesToAdd.length=0}if(this._entitiesToRemove.length>0){for(var i,r=s(this._entitiesToRemove);!(i=r()).done;){var o=i.value;this.removeImmediate(o)}this._entitiesToRemove.length=0}},e.update=function(){this._isUpdating=!0;try{for(var t=0;t<this.buffer.length;t++){var e=this.buffer[t];e.enabled&&!e.isDestroyed&&e.update()}}finally{this._isUpdating=!1}this.updateLists()},e.findEntity=function(t){var e=this._nameToEntities.get(t);return e&&e.length>0?e[0]:null},e.findEntitiesByName=function(t){return this._nameToEntities.get(t)||[]},e.findEntityById=function(t){return this._idToEntity.get(t)||null},e.findEntitiesByTag=function(t){for(var e,n=[],i=s(this.buffer);!(e=i()).done;){var r=e.value;r.tag===t&&n.push(r)}return n},e.findEntitiesWithComponent=function(t){for(var e,n=[],i=s(this.buffer);!(e=i()).done;){var r=e.value;r.hasComponent(t)&&n.push(r)}return n},e.forEach=function(t){for(var e,n=s(this.buffer);!(e=n()).done;){t(e.value)}},e.forEachWhere=function(t,e){for(var n,i=s(this.buffer);!(n=i()).done;){var r=n.value;t(r)&&e(r)}},e.updateNameIndex=function(t,e){if(t.name)if(e){var n=this._nameToEntities.get(t.name);n||(n=[],this._nameToEntities.set(t.name,n)),n.push(t)}else{var i=this._nameToEntities.get(t.name);if(i){var r=i.indexOf(t);-1!==r&&(i.splice(r,1),0===i.length&&this._nameToEntities.delete(t.name))}}},e.getStats=function(){for(var t,e=0,n=s(this.buffer);!(t=n()).done;){var i=t.value;i.enabled&&!i.isDestroyed&&e++}return{totalEntities:this.buffer.length,activeEntities:e,pendingAdd:this._entitiesToAdd.length,pendingRemove:this._entitiesToRemove.length,nameIndexSize:this._nameToEntities.size}},o(t,[{key:"count",get:function(){return this.buffer.length}}])}(),G=function(){function t(){this._processors=[],this._isDirty=!1}var e=t.prototype;return e.setDirty=function(){this._isDirty=!0},e.add=function(t){this._processors.push(t),this.setDirty()},e.remove=function(t){var e=this._processors.indexOf(t);-1!==e&&this._processors.splice(e,1)},e.getProcessor=function(t){for(var e,n=s(this._processors);!(e=n()).done;){var i=e.value;if(i instanceof t)return i}return null},e.begin=function(){this.sortProcessors()},e.end=function(){},e.update=function(){this.sortProcessors();for(var e,n=s(this._processors);!(e=n()).done;){var i=e.value;try{i.update()}catch(e){t._logger.error("Error in processor "+B(i)+":",e)}}},e.lateUpdate=function(){for(var t,e=s(this._processors);!(t=e()).done;){t.value.lateUpdate()}},e.sortProcessors=function(){this._isDirty&&(this._processors.sort((function(t,e){return t.updateOrder-e.updateOrder})),this._isDirty=!1)},o(t,[{key:"processors",get:function(){return this._processors}},{key:"count",get:function(){return this._processors.length}}])}();G._logger=D("EntityProcessorList");var Y=function(){function t(t,e){void 0===t&&(t=100),void 0===e&&(e=1024),this._nextAvailableIndex=0,this._freeIndices=[],this._generations=new Map,this._pendingRecycle=[],thi