@esengine/ecs-framework 2.1.47 → 2.1.48

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "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(){
1
+ "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,s,o){try{var a=t[s](o),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,s){var o=t.apply(n,i);function a(t){e(o,r,s,a,c,"next",t)}function c(t){e(o,r,s,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 s(t,e,n){return e&&r(t.prototype,e),n&&r(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function o(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(){
2
2
  /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
3
- 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:"",RED:"",GREEN:"",YELLOW:"",BLUE:"",MAGENTA:"",CYAN:"",WHITE:"",BRIGHT_BLACK:"",BRIGHT_RED:"",BRIGHT_GREEN:"",BRIGHT_YELLOW:"",BRIGHT_BLUE:"",BRIGHT_MAGENTA:"",BRIGHT_CYAN:"",BRIGHT_WHITE:"",RESET:"",BOLD:"",UNDERLINE:""},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=[],this._recycleDelay=100,this._stats={totalAllocated:0,totalRecycled:0,currentActive:0,memoryExpansions:0},this._recycleDelay=t,this._expansionBlockSize=e,this._preAllocateGenerations(0,this._expansionBlockSize)}var e=t.prototype;return e.checkOut=function(){var e;if(this._processDelayedRecycle(),this._freeIndices.length>0)e=this._freeIndices.pop();else{if(this._nextAvailableIndex>t.MAX_INDEX)throw new Error("实体索引已达到框架设计限制 ("+t.MAX_INDEX+")。这意味着您已经分配了超过65535个不同的实体索引。这是16位索引设计的限制,考虑优化实体回收策略或升级到64位ID设计。");e=this._nextAvailableIndex++,this._ensureGenerationCapacity(e)}var n=this._generations.get(e)||1;return this._stats.totalAllocated++,this._stats.currentActive++,this._packId(e,n)},e.checkIn=function(t){var e=this._unpackIndex(t),n=this._unpackGeneration(t);return!!this._isValidId(e,n)&&(!this._pendingRecycle.some((function(t){return t.index===e&&t.generation===n}))&&(this._pendingRecycle.push({index:e,generation:n,timestamp:Date.now()}),this._stats.currentActive--,this._stats.totalRecycled++,!0))},e.isValid=function(t){var e=this._unpackIndex(t),n=this._unpackGeneration(t);return this._isValidId(e,n)},e.getStats=function(){for(var e,n=0,i=0,r=s(this._generations);!(e=r()).done;){var o=e.value,a=o[0],c=o[1];a<this._nextAvailableIndex&&(n+=c,i++)}var u=i>0?n/i:1;return{totalAllocated:this._stats.totalAllocated,totalRecycled:this._stats.totalRecycled,currentActive:this._stats.currentActive,currentlyFree:this._freeIndices.length,pendingRecycle:this._pendingRecycle.length,maxPossibleEntities:t.MAX_INDEX+1,maxUsedIndex:this._nextAvailableIndex-1,memoryUsage:this._calculateMemoryUsage(),memoryExpansions:this._stats.memoryExpansions,averageGeneration:Math.round(100*u)/100,generationStorageSize:this._generations.size}},e.forceProcessDelayedRecycle=function(){this._processDelayedRecycle(!0)},e._processDelayedRecycle=function(e){if(void 0===e&&(e=!1),0!==this._pendingRecycle.length){for(var n,i=Date.now(),r=[],o=[],a=s(this._pendingRecycle);!(n=a()).done;){var c=n.value;e||i-c.timestamp>=this._recycleDelay?r.push(c):o.push(c)}for(var u=0,h=r;u<h.length;u++){var l=h[u];if(this._isValidId(l.index,l.generation)){var d=l.generation+1;d>t.MAX_GENERATION&&(d=1),this._generations.set(l.index,d),this._freeIndices.push(l.index)}}this._pendingRecycle=o}},e._preAllocateGenerations=function(e,n){for(var i=0;i<n;i++){var r=e+i;r<=t.MAX_INDEX&&this._generations.set(r,1)}this._stats.memoryExpansions++},e._ensureGenerationCapacity=function(t){if(!this._generations.has(t)){var e=Math.floor(t/this._expansionBlockSize)*this._expansionBlockSize;this._preAllocateGenerations(e,this._expansionBlockSize)}},e._calculateMemoryUsage=function(){return 16*this._generations.size+8*this._freeIndices.length+32*this._pendingRecycle.length},e._packId=function(t,e){return e<<16|t},e._unpackIndex=function(t){return 65535&t},e._unpackGeneration=function(t){return t>>>16&65535},e._isValidId=function(t,e){if(t<0||t>=this._nextAvailableIndex)return!1;var n=this._generations.get(t);return void 0!==n&&n===e},t}();Y.MAX_INDEX=65535,Y.MAX_GENERATION=65535;var Q=function(){function t(t,e,n){void 0===n&&(n=1e3),this.pool=[],this.createFn=t,this.resetFn=e,this.maxSize=n}var e=t.prototype;return e.acquire=function(){return this.pool.length>0?this.pool.pop():this.createFn()},e.release=function(t){this.pool.length<this.maxSize&&(this.resetFn&&this.resetFn(t),this.pool.push(t))},e.prewarm=function(t){for(var e=0;e<t&&this.pool.length<this.maxSize;e++)this.pool.push(this.createFn())},e.clear=function(){this.pool.length=0},e.getAvailableCount=function(){return this.pool.length},e.getMaxSize=function(){return this.maxSize},t}(),V=function(){function t(){this.pools=new Map}t.getInstance=function(){return t.instance||(t.instance=new t),t.instance};var e=t.prototype;return e.registerPool=function(t,e,n,i){this.pools.set(t,new Q(e,n,i))},e.acquireComponent=function(t){var e=this.pools.get(t);return e?e.acquire():null},e.releaseComponent=function(t,e){var n=this.pools.get(t);n&&n.release(e)},e.prewarmAll=function(t){void 0===t&&(t=100);for(var e,n=s(this.pools.values());!(e=n()).done;){e.value.prewarm(t)}},e.clearAll=function(){for(var t,e=s(this.pools.values());!(t=e()).done;){t.value.clear()}},e.reset=function(){this.pools.clear()},e.getPoolStats=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,{available:o.getAvailableCount(),maxSize:o.getMaxSize()})}return e},e.getPoolUtilization=function(){for(var t,e=new Map,n=s(this.pools);!(t=n()).done;){var i=t.value,r=i[0],o=i[1],a=o.getAvailableCount(),c=o.getMaxSize(),u=c-a,h=c>0?u/c*100:0;e.set(r,{used:u,total:c,utilization:h})}return e},e.getComponentUtilization=function(t){var e=this.pools.get(t);if(!e)return 0;var n=e.getAvailableCount(),i=e.getMaxSize();return i>0?(i-n)/i*100:0},t}(),X=function(){function t(){this._dense=[],this._sparse=new Map}var e=t.prototype;return e.add=function(t){if(this._sparse.has(t))return!1;var e=this._dense.length;return this._dense.push(t),this._sparse.set(t,e),!0},e.remove=function(t){var e=this._sparse.get(t);if(void 0===e)return!1;var n=this._dense.length-1;if(e!==n){var i=this._dense[n];this._dense[e]=i,this._sparse.set(i,e)}return this._dense.pop(),this._sparse.delete(t),!0},e.has=function(t){return this._sparse.has(t)},e.getIndex=function(t){return this._sparse.get(t)},e.getByIndex=function(t){return this._dense[t]},e.forEach=function(t){for(var e=0;e<this._dense.length;e++)t(this._dense[e],e)},e.map=function(t){for(var e=[],n=0;n<this._dense.length;n++)e.push(t(this._dense[n],n));return e},e.filter=function(t){for(var e=[],n=0;n<this._dense.length;n++)t(this._dense[n],n)&&e.push(this._dense[n]);return e},e.find=function(t){for(var e=0;e<this._dense.length;e++)if(t(this._dense[e],e))return this._dense[e]},e.some=function(t){for(var e=0;e<this._dense.length;e++)if(t(this._dense[e],e))return!0;return!1},e.every=function(t){for(var e=0;e<this._dense.length;e++)if(!t(this._dense[e],e))return!1;return!0},e.getDenseArray=function(){return[].concat(this._dense)},e.getDenseArrayUnsafe=function(){return this._dense},e.clear=function(){this._dense.length=0,this._sparse.clear()},e.toArray=function(){return[].concat(this._dense)},e.toSet=function(){return new Set(this._dense)},e.getMemoryStats=function(){var t=8*this._dense.length,e=16*this._sparse.size;return{denseArraySize:t,sparseMapSize:e,totalMemory:t+e}},e.validate=function(){if(this._dense.length!==this._sparse.size)return!1;for(var t=0;t<this._dense.length;t++){var e=this._dense[t];if(this._sparse.get(e)!==t)return!1}for(var n,i=s(this._sparse);!(n=i()).done;){var r=n.value,o=r[0],a=r[1];if(a>=this._dense.length||this._dense[a]!==o)return!1}return!0},o(t,[{key:"size",get:function(){return this._dense.length}},{key:"isEmpty",get:function(){return 0===this._dense.length}}])}(),Z=function(t){function e(){return t.call(this)||this}return u(e,t),e.prototype.reset=function(){this.clear()},e}(m(Set)),J=function(){function t(){this._componentMasks=[],this._componentToEntities=new Map,this._entities=new X}var e=t.prototype;return e.addEntity=function(t){this._entities.has(t)&&this.removeEntity(t);for(var e,n=M.clone(M.ZERO),i=new Set,r=s(t.components);!(e=r()).done;){var o=e.value.constructor;i.add(o),F.isRegistered(o)||F.register(o);var a=F.getBitMask(o);M.orInPlace(n,a)}this._entities.add(t);for(var c=this._entities.getIndex(t);this._componentMasks.length<=c;)this._componentMasks.push(M.clone(M.ZERO));this._componentMasks[c]=n,this.updateComponentMappings(t,i,!0)},e.removeEntity=function(t){var e=this._entities.getIndex(t);if(void 0!==e){var n=this.getEntityComponentTypes(t);this.updateComponentMappings(t,n,!1),this._entities.remove(t);var i=this._componentMasks.length-1;e!==i&&(this._componentMasks[e]=this._componentMasks[i]),this._componentMasks.pop()}},e.queryByComponent=function(t){var e=this._componentToEntities.get(t);return e?new Set(e):new Set},e.queryMultipleAnd=function(e){var n=this;if(0===e.length)return new Set;if(1===e.length)return this.queryByComponent(e[0]);for(var i,r=M.clone(M.ZERO),o=s(e);!(i=o()).done;){var a=i.value;if(!F.isRegistered(a))return new Set;var c=F.getBitMask(a);M.orInPlace(r,c)}var u=t._entitySetPool.obtain();return this._entities.forEach((function(t,e){var i=n._componentMasks[e];M.hasAll(i,r)&&u.add(t)})),u},e.queryMultipleOr=function(e){var n=this;if(0===e.length)return new Set;if(1===e.length)return this.queryByComponent(e[0]);for(var i,r=M.clone(M.ZERO),o=s(e);!(i=o()).done;){var a=i.value;if(F.isRegistered(a)){var c=F.getBitMask(a);M.orInPlace(r,c)}}if(M.equals(r,M.ZERO))return new Set;var u=t._entitySetPool.obtain();return this._entities.forEach((function(t,e){var i=n._componentMasks[e];M.hasAny(i,r)&&u.add(t)})),u},e.hasComponent=function(t,e){var n=this._entities.getIndex(t);if(void 0===n)return!1;if(!F.isRegistered(e))return!1;var i=this._componentMasks[n],r=F.getBitMask(e);return M.hasAny(i,r)},e.getEntityMask=function(t){var e=this._entities.getIndex(t);if(void 0!==e)return this._componentMasks[e]},e.getAllEntities=function(){return this._entities.toArray()},e.forEach=function(t){var e=this;this._entities.forEach((function(n,i){t(n,e._componentMasks[i],i)}))},e.clear=function(){this._entities.clear(),this._componentMasks.length=0;for(var e,n=s(this._componentToEntities.values());!(e=n()).done;){var i=e.value;t._entitySetPool.release(i)}this._componentToEntities.clear()},e.getMemoryStats=function(){for(var t,e=this._entities.getMemoryStats(),n=16*this._componentMasks.length,i=16*this._componentToEntities.size,r=s(this._componentToEntities.values());!(t=r()).done;){i+=8*t.value.size}return{entitiesMemory:e.totalMemory,masksMemory:n,mappingsMemory:i,totalMemory:e.totalMemory+n+i}},e.validate=function(){if(!this._entities.validate())return!1;if(this._componentMasks.length!==this._entities.size)return!1;for(var t,e=new Set,n=s(this._componentToEntities.values());!(t=n()).done;)for(var i,r=s(t.value);!(i=r()).done;){var o=i.value;e.add(o)}for(var a,c=s(e);!(a=c()).done;){var u=a.value;if(!this._entities.has(u))return!1}return!0},e.getEntityComponentTypes=function(t){for(var e,n=new Set,i=s(t.components);!(e=i()).done;){var r=e.value;n.add(r.constructor)}return n},e.updateComponentMappings=function(e,n,i){for(var r,o=s(n);!(r=o()).done;){var a=r.value,c=this._componentToEntities.get(a);i?(c||(c=t._entitySetPool.obtain(),this._componentToEntities.set(a,c)),c.add(e)):c&&(c.delete(e),0===c.size&&(this._componentToEntities.delete(a),t._entitySetPool.release(c)))}},o(t,[{key:"size",get:function(){return this._entities.size}},{key:"isEmpty",get:function(){return this._entities.isEmpty}}])}();J._entitySetPool=T.getPool(Z,50,512);var K,$=function(){function t(){this._queryCount=0,this._totalQueryTime=0,this._lastUpdated=Date.now(),this._sparseSet=new J}var e=t.prototype;return e.addEntity=function(t){this._sparseSet.addEntity(t),this._lastUpdated=Date.now()},e.removeEntity=function(t){this._sparseSet.removeEntity(t),this._lastUpdated=Date.now()},e.query=function(t){var e=performance.now(),n=this._sparseSet.queryByComponent(t);return this._queryCount++,this._totalQueryTime+=performance.now()-e,n},e.queryMultiple=function(t,e){var n,i=performance.now();return n=0===t.length?new Set:1===t.length?this.query(t[0]):"AND"===e?this._sparseSet.queryMultipleAnd(t):this._sparseSet.queryMultipleOr(t),this._queryCount++,this._totalQueryTime+=performance.now()-i,n},e.clear=function(){this._sparseSet.clear(),this._lastUpdated=Date.now()},e.getStats=function(){var t=this._sparseSet.getMemoryStats();return{size:this._sparseSet.size,memoryUsage:t.totalMemory,queryCount:this._queryCount,avgQueryTime:this._queryCount>0?this._totalQueryTime/this._queryCount:0,lastUpdated:this._lastUpdated}},t}(),tt=function(){function t(){this._index=new $}var e=t.prototype;return e.addEntity=function(t){this._index.addEntity(t)},e.removeEntity=function(t){this._index.removeEntity(t)},e.query=function(t){return this._index.query(t)},e.queryMultiple=function(t,e){return this._index.queryMultiple(t,e)},e.getStats=function(){return this._index.getStats()},e.clear=function(){this._index.clear()},t}(),et=function(){function t(){this._archetypes=new Map,this._entityToArchetype=new Map,this._componentToArchetypes=new Map,this._queryCache=new Map,this._cacheTimeout=5e3,this._maxCacheSize=100}var e=t.prototype;return e.addEntity=function(t){var e=this.getEntityComponentTypes(t),n=this.generateArchetypeId(e),i=this._archetypes.get(n);i||(i=this.createArchetype(e)),i.entities.push(t),i.updatedAt=Date.now(),this._entityToArchetype.set(t,i),this.updateComponentIndexes(i,e,!0),this.invalidateQueryCache()},e.removeEntity=function(t){var e=this._entityToArchetype.get(t);if(e){var n=e.entities.indexOf(t);-1!==n&&(e.entities.splice(n,1),e.updatedAt=Date.now()),this._entityToArchetype.delete(t),this.invalidateQueryCache()}},e.queryArchetypes=function(t,e){void 0===e&&(e="AND");var n=performance.now(),i=e+":"+t.map((function(t){return P(t)})).sort().join(","),r=this._queryCache.get(i);if(r&&Date.now()-r.timestamp<this._cacheTimeout)return a({},r.result,{executionTime:performance.now()-n,fromCache:!0});var o=[],c=0;if("AND"===e)for(var u,h=s(this._archetypes.values());!(u=h()).done;){var l=u.value;this.archetypeContainsAllComponents(l,t)&&(o.push(l),c+=l.entities.length)}else{for(var d,f=new Set,p=s(t);!(d=p()).done;){var m=d.value,y=this._componentToArchetypes.get(m);if(y)for(var g,v=s(y);!(g=v()).done;){var _=g.value;f.add(_)}}for(var E,S=s(f);!(E=S()).done;){var T=E.value;o.push(T),c+=T.entities.length}}var C={archetypes:o,totalEntities:c,executionTime:performance.now()-n,fromCache:!1};return this._queryCache.set(i,{result:C,timestamp:Date.now()}),C},e.getEntityArchetype=function(t){return this._entityToArchetype.get(t)},e.getAllArchetypes=function(){return Array.from(this._archetypes.values())},e.clear=function(){this._archetypes.clear(),this._entityToArchetype.clear(),this._componentToArchetypes.clear(),this._queryCache.clear()},e.getEntityComponentTypes=function(t){return t.components.map((function(t){return t.constructor}))},e.generateArchetypeId=function(t){return t.map((function(t){return P(t)})).sort().join("|")},e.createArchetype=function(t){var e=this.generateArchetypeId(t),n={id:e,componentTypes:[].concat(t),entities:[],createdAt:Date.now(),updatedAt:Date.now()};return this._archetypes.set(e,n),n},e.archetypeContainsAllComponents=function(t,e){for(var n,i=s(e);!(n=i()).done;){var r=n.value;if(!t.componentTypes.includes(r))return!1}return!0},e.updateComponentIndexes=function(t,e,n){for(var i,r=s(e);!(i=r()).done;){var o=i.value,a=this._componentToArchetypes.get(o);a||(a=new Set,this._componentToArchetypes.set(o,a)),n?a.add(t):(a.delete(t),0===a.size&&this._componentToArchetypes.delete(o))}},e.invalidateQueryCache=function(){this._queryCache.clear()},t}();exports.DirtyFlag=void 0,(K=exports.DirtyFlag||(exports.DirtyFlag={}))[K.COMPONENT_MODIFIED=1]="COMPONENT_MODIFIED",K[K.COMPONENT_ADDED=2]="COMPONENT_ADDED",K[K.COMPONENT_REMOVED=4]="COMPONENT_REMOVED",K[K.TRANSFORM_CHANGED=8]="TRANSFORM_CHANGED",K[K.STATE_CHANGED=16]="STATE_CHANGED",K[K.CUSTOM_1=256]="CUSTOM_1",K[K.CUSTOM_2=512]="CUSTOM_2",K[K.CUSTOM_3=1024]="CUSTOM_3",K[K.ALL=4294967295]="ALL";var nt,it=function(){function t(){this._dirtyEntities=new Map,this._listeners=[],this._stats={totalMarkings:0,totalCleanups:0,frameCount:0,totalDirtyPerFrame:0},this._currentFrame=0,this._batchSize=100,this._maxProcessingTime=16,this._processingQueue=[],this._isProcessing=!1}var e=t.prototype;return e.markDirty=function(t,e,n){void 0===n&&(n=[]),this._stats.totalMarkings++;var i=this._dirtyEntities.get(t);i||(i={entity:t,flags:0,modifiedComponents:new Set,timestamp:performance.now(),frameNumber:this._currentFrame},this._dirtyEntities.set(t,i)),i.flags|=e,i.timestamp=performance.now(),i.frameNumber=this._currentFrame;for(var r,o=s(n);!(r=o()).done;){var a=r.value;i.modifiedComponents.add(a)}this.notifyListeners(i,e)},e.isDirty=function(t,e){void 0===e&&(e=exports.DirtyFlag.ALL);var n=this._dirtyEntities.get(t);return!!n&&0!==(n.flags&e)},e.clearDirty=function(t,e){void 0===e&&(e=exports.DirtyFlag.ALL);var n=this._dirtyEntities.get(t);n&&(e===exports.DirtyFlag.ALL?this._dirtyEntities.delete(t):(n.flags&=~e,0===n.flags&&this._dirtyEntities.delete(t)),this._stats.totalCleanups++)},e.getDirtyEntities=function(t){void 0===t&&(t=exports.DirtyFlag.ALL);for(var e,n=[],i=s(this._dirtyEntities.values());!(e=i()).done;){var r=e.value;0!==(r.flags&t)&&n.push(r)}return n},e.processDirtyEntities=function(){if(!this._isProcessing){this._isProcessing=!0;var t,e=performance.now();if(0===this._processingQueue.length)(t=this._processingQueue).push.apply(t,this._dirtyEntities.values());for(var n=0;this._processingQueue.length>0&&n<this._batchSize;){if(performance.now()-e>this._maxProcessingTime)break;var i=this._processingQueue.shift();this.processEntity(i),n++}0===this._processingQueue.length&&(this._isProcessing=!1,this.onFrameEnd())}},e.addListener=function(t){this._listeners.push(t),this._listeners.sort((function(t,e){return(t.priority||100)-(e.priority||100)}))},e.removeListener=function(t){var e=this._listeners.findIndex((function(e){return e.callback===t}));-1!==e&&this._listeners.splice(e,1)},e.beginFrame=function(){this._currentFrame++},e.endFrame=function(){this._isProcessing||this.processDirtyEntities()},e.getStats=function(){return{dirtyEntityCount:this._dirtyEntities.size,totalMarkings:this._stats.totalMarkings,totalCleanups:this._stats.totalCleanups,listenerCount:this._listeners.length,avgDirtyPerFrame:this._stats.frameCount>0?this._stats.totalDirtyPerFrame/this._stats.frameCount:0,estimatedMemoryUsage:this.estimateMemoryUsage()}},e.clear=function(){this._dirtyEntities.clear(),this._processingQueue.length=0,this._isProcessing=!1,this._stats={totalMarkings:0,totalCleanups:0,frameCount:0,totalDirtyPerFrame:0}},e.configureBatchProcessing=function(t,e){this._batchSize=t,this._maxProcessingTime=e},e.processEntity=function(e){for(var n,i=s(this._listeners);!(n=i()).done;){var r=n.value;if(0!==(e.flags&r.flags))try{r.callback(e)}catch(e){t._logger.error("脏数据监听器错误:",e)}}this.clearDirty(e.entity)},e.notifyListeners=function(e,n){for(var i,r=s(this._listeners);!(i=r()).done;){var o=i.value;if(0!==(n&o.flags))try{o.callback(e)}catch(e){t._logger.error("脏数据监听器通知错误:",e)}}},e.onFrameEnd=function(){this._stats.frameCount++,this._stats.totalDirtyPerFrame+=this._dirtyEntities.size},e.estimateMemoryUsage=function(){var t=0;return t+=100*this._dirtyEntities.size,t+=50*this._listeners.length,t+=8*this._processingQueue.length},t}();it._logger=D("DirtyTrackingSystem"),function(t){t.ALL="all",t.ANY="any",t.NONE="none"}(nt||(nt={}));var rt,ot,st=function(){function t(){this._logger=D("QuerySystem"),this.entities=[],this.indexDirty=!0,this._version=0,this.queryCache=new Map,this.cacheMaxSize=1e3,this.cacheTimeout=5e3,this.queryStats={totalQueries:0,cacheHits:0,indexHits:0,linearScans:0,archetypeHits:0,dirtyChecks:0},this.entityIndex={byMask:new Map,byComponentType:new Map,byTag:new Map,byName:new Map},this.componentPoolManager=V.getInstance(),this.componentIndexManager=new tt,this.archetypeSystem=new et,this.dirtyTrackingSystem=new it}var e=t.prototype;return e.setEntities=function(t){this.entities=t,this.clearQueryCache(),this.rebuildIndexes()},e.addEntity=function(t,e){void 0===e&&(e=!1),this.entities.includes(t)||(this.entities.push(t),this.addEntityToIndexes(t),this.componentIndexManager.addEntity(t),this.archetypeSystem.addEntity(t),this.dirtyTrackingSystem.markDirty(t,exports.DirtyFlag.COMPONENT_ADDED),e||this.clearQueryCache(),this._version++)},e.addEntities=function(t){if(0!==t.length){for(var e,n=new Set(this.entities.map((function(t){return t.id}))),i=0,r=s(t);!(e=r()).done;){var o=e.value;n.has(o.id)||(this.entities.push(o),this.addEntityToIndexes(o),n.add(o.id),i++)}i>0&&this.clearQueryCache()}},e.addEntitiesUnchecked=function(t){if(0!==t.length){for(var e,n=s(t);!(e=n()).done;){var i=e.value;this.entities.push(i)}for(var r,o=s(t);!(r=o()).done;){var a=r.value;this.addEntityToIndexes(a)}this.clearQueryCache()}},e.removeEntity=function(t){var e=this.entities.indexOf(t);-1!==e&&(this.entities.splice(e,1),this.removeEntityFromIndexes(t),this.componentIndexManager.removeEntity(t),this.archetypeSystem.removeEntity(t),this.dirtyTrackingSystem.markDirty(t,exports.DirtyFlag.COMPONENT_REMOVED),this.clearQueryCache(),this._version++)},e.addEntityToIndexes=function(t){var e=t.componentMask.toString(),n=this.entityIndex.byMask.get(e);n||(n=new Set,this.entityIndex.byMask.set(e,n)),n.add(t);for(var i=t.components,r=0;r<i.length;r++){var o=i[r].constructor,s=this.entityIndex.byComponentType.get(o);s||(s=new Set,this.entityIndex.byComponentType.set(o,s)),s.add(t)}var a=t.tag;if(void 0!==a){var c=this.entityIndex.byTag.get(a);c||(c=new Set,this.entityIndex.byTag.set(a,c)),c.add(t)}var u=t.name;if(u){var h=this.entityIndex.byName.get(u);h||(h=new Set,this.entityIndex.byName.set(u,h)),h.add(t)}},e.removeEntityFromIndexes=function(t){var e=t.componentMask.toString(),n=this.entityIndex.byMask.get(e);n&&(n.delete(t),0===n.size&&this.entityIndex.byMask.delete(e));for(var i,r=s(t.components);!(i=r()).done;){var o=i.value.constructor,a=this.entityIndex.byComponentType.get(o);a&&(a.delete(t),0===a.size&&this.entityIndex.byComponentType.delete(o))}if(void 0!==t.tag){var c=this.entityIndex.byTag.get(t.tag);c&&(c.delete(t),0===c.size&&this.entityIndex.byTag.delete(t.tag))}if(t.name){var u=this.entityIndex.byName.get(t.name);u&&(u.delete(t),0===u.size&&this.entityIndex.byName.delete(t.name))}},e.rebuildIndexes=function(){this.entityIndex.byMask.clear(),this.entityIndex.byComponentType.clear(),this.entityIndex.byTag.clear(),this.entityIndex.byName.clear(),this.archetypeSystem.clear(),this.componentIndexManager.clear();for(var t,e=s(this.entities);!(t=e()).done;){var n=t.value;this.addEntityToIndexes(n),this.componentIndexManager.addEntity(n),this.archetypeSystem.addEntity(n)}this.indexDirty=!1},e.queryAll=function(){var t=performance.now();this.queryStats.totalQueries++;for(var e=arguments.length,n=new Array(e),i=0;i<e;i++)n[i]=arguments[i];var r="all:"+n.map((function(t){return P(t)})).sort().join(","),o=this.getFromCache(r);if(o)return this.queryStats.cacheHits++,{entities:o,count:o.length,executionTime:performance.now()-t,fromCache:!0};var a=[],c=this.archetypeSystem.queryArchetypes(n,"AND");if(c.archetypes.length>0){this.queryStats.archetypeHits++;for(var u,h=s(c.archetypes);!(u=h()).done;){var l,d=u.value;(l=a).push.apply(l,d.entities)}}else try{if(1===n.length){this.queryStats.indexHits++;var f=this.componentIndexManager.query(n[0]);a=Array.from(f)}else{var p=this.componentIndexManager.queryMultiple(n,"AND");a=Array.from(p)}}catch(t){a=[]}return this.addToCache(r,a),{entities:a,count:a.length,executionTime:performance.now()-t,fromCache:!1}},e.queryMultipleComponents=function(t){for(var e,n=null,i=1/0,r=s(t);!(e=r()).done;){var o=e.value,a=this.entityIndex.byComponentType.get(o);if(!a||0===a.size)return[];a.size<i&&(i=a.size,n=a)}if(!n)return[];for(var c,u=this.createComponentMask(t),h=[],l=s(n);!(c=l()).done;){var d=c.value;M.hasAll(d.componentMask,u)&&h.push(d)}return h},e.queryAny=function(){var t=performance.now();this.queryStats.totalQueries++;for(var e=arguments.length,n=new Array(e),i=0;i<e;i++)n[i]=arguments[i];var r="any:"+n.map((function(t){return P(t)})).sort().join(","),o=this.getFromCache(r);if(o)return this.queryStats.cacheHits++,{entities:o,count:o.length,executionTime:performance.now()-t,fromCache:!0};var a,c=this.archetypeSystem.queryArchetypes(n,"OR");if(c.archetypes.length>0){this.queryStats.archetypeHits++,a=[];for(var u,h=s(c.archetypes);!(u=h()).done;){var l,d=u.value;(l=a).push.apply(l,d.entities)}}else{var f=this.componentIndexManager.queryMultiple(n,"OR");a=Array.from(f)}return this.addToCache(r,a),{entities:a,count:a.length,executionTime:performance.now()-t,fromCache:!1}},e.queryNone=function(){var t=performance.now();this.queryStats.totalQueries++;for(var e=arguments.length,n=new Array(e),i=0;i<e;i++)n[i]=arguments[i];var r="none:"+n.map((function(t){return P(t)})).sort().join(","),o=this.getFromCache(r);if(o)return this.queryStats.cacheHits++,{entities:o,count:o.length,executionTime:performance.now()-t,fromCache:!0};var s=this.createComponentMask(n),a=this.entities.filter((function(t){return M.hasNone(t.componentMask,s)}));return this.addToCache(r,a),{entities:a,count:a.length,executionTime:performance.now()-t,fromCache:!1}},e.queryByTag=function(t){var e=performance.now();this.queryStats.totalQueries++;var n="tag:"+t,i=this.getFromCache(n);if(i)return this.queryStats.cacheHits++,{entities:i,count:i.length,executionTime:performance.now()-e,fromCache:!0};this.queryStats.indexHits++;var r=Array.from(this.entityIndex.byTag.get(t)||[]);return this.addToCache(n,r),{entities:r,count:r.length,executionTime:performance.now()-e,fromCache:!1}},e.queryByName=function(t){var e=performance.now();this.queryStats.totalQueries++;var n="name:"+t,i=this.getFromCache(n);if(i)return this.queryStats.cacheHits++,{entities:i,count:i.length,executionTime:performance.now()-e,fromCache:!0};this.queryStats.indexHits++;var r=Array.from(this.entityIndex.byName.get(t)||[]);return this.addToCache(n,r),{entities:r,count:r.length,executionTime:performance.now()-e,fromCache:!1}},e.queryByComponent=function(t){var e=performance.now();this.queryStats.totalQueries++;var n="component:"+P(t),i=this.getFromCache(n);if(i)return this.queryStats.cacheHits++,{entities:i,count:i.length,executionTime:performance.now()-e,fromCache:!0};this.queryStats.indexHits++;var r=Array.from(this.entityIndex.byComponentType.get(t)||[]);return this.addToCache(n,r),{entities:r,count:r.length,executionTime:performance.now()-e,fromCache:!1}},e.getFromCache=function(t){var e=this.queryCache.get(t);return e?Date.now()-e.timestamp>this.cacheTimeout?(this.queryCache.delete(t),null):(e.hitCount++,e.entities):null},e.addToCache=function(t,e){this.queryCache.size>=this.cacheMaxSize&&this.cleanupCache(),this.queryCache.set(t,{entities:[].concat(e),timestamp:Date.now(),hitCount:0})},e.cleanupCache=function(){for(var t,e=Date.now(),n=s(this.queryCache.entries());!(t=n()).done;){var i=t.value,r=i[0];e-i[1].timestamp>this.cacheTimeout&&this.queryCache.delete(r)}if(this.queryCache.size>=this.cacheMaxSize){var o=Array.from(this.queryCache.entries());o.sort((function(t,e){return t[1].hitCount-e[1].hitCount}));for(var a=Math.floor(.2*this.cacheMaxSize),c=0;c<a&&c<o.length;c++)this.queryCache.delete(o[c][0])}},e.clearQueryCache=function(){this.queryCache.clear()},e.clearCache=function(){this.clearQueryCache()},e.batchUpdateComponents=function(t){for(var e,n=this,i=[],r=function(){var t=e.value,r=n.entities.find((function(e){return e.id===t.entityId}));r&&(n.removeEntityFromIndexes(r),i.push(r))},o=s(t);!(e=o()).done;)r();for(var a=0,c=i;a<c.length;a++){var u=c[a];this.addEntityToIndexes(u)}for(var h=0,l=i;h<l.length;h++){var d=l[h];this.dirtyTrackingSystem.markDirty(d,exports.DirtyFlag.COMPONENT_MODIFIED,[])}this.clearQueryCache()},e.createComponentMask=function(t){for(var e,n=M.clone(M.ZERO),i=!1,r=s(t);!(e=r()).done;){var o=e.value;try{var a=F.getBitMask(o);M.orInPlace(n,a),i=!0}catch(t){this._logger.warn("组件类型 "+P(o)+" 未注册,跳过")}}return i?n:{lo:4294967295,hi:4294967295}},e.getAllEntities=function(){return[].concat(this.entities)},e.getStats=function(){return{entityCount:this.entities.length,indexStats:{maskIndexSize:this.entityIndex.byMask.size,componentIndexSize:this.entityIndex.byComponentType.size,tagIndexSize:this.entityIndex.byTag.size,nameIndexSize:this.entityIndex.byName.size},queryStats:a({},this.queryStats,{cacheHitRate:this.queryStats.totalQueries>0?(this.queryStats.cacheHits/this.queryStats.totalQueries*100).toFixed(2)+"%":"0%"}),optimizationStats:{componentIndex:this.componentIndexManager.getStats(),archetypeSystem:this.archetypeSystem.getAllArchetypes().map((function(t){return{id:t.id,componentTypes:t.componentTypes.map((function(t){return P(t)})),entityCount:t.entities.length}})),dirtyTracking:this.dirtyTrackingSystem.getStats()},cacheStats:{size:this.queryCache.size,hitRate:this.queryStats.totalQueries>0?(this.queryStats.cacheHits/this.queryStats.totalQueries*100).toFixed(2)+"%":"0%"}}},e.configureDirtyTracking=function(t,e){this.dirtyTrackingSystem.configureBatchProcessing(t,e)},e.optimizePerformance=function(){this.dirtyTrackingSystem.processDirtyEntities(),this.cleanupCache(),this.componentIndexManager.getStats()},e.beginFrame=function(){this.dirtyTrackingSystem.beginFrame()},e.endFrame=function(){this.dirtyTrackingSystem.endFrame()},e.markEntityDirty=function(t,e){this.queryStats.dirtyChecks++,this.dirtyTrackingSystem.markDirty(t,exports.DirtyFlag.COMPONENT_MODIFIED,e),this.clearQueryCache()},e.getEntityArchetype=function(t){return this.archetypeSystem.getEntityArchetype(t)},o(t,[{key:"version",get:function(){return this._version}}])}(),at=function(){function t(t){this._logger=D("QueryBuilder"),this.conditions=[],this.querySystem=t}var e=t.prototype;return e.withAll=function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];return this.conditions.push({type:nt.ALL,componentTypes:e,mask:this.createComponentMask(e)}),this},e.withAny=function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];return this.conditions.push({type:nt.ANY,componentTypes:e,mask:this.createComponentMask(e)}),this},e.without=function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];return this.conditions.push({type:nt.NONE,componentTypes:e,mask:this.createComponentMask(e)}),this},e.execute=function(){var t,e,n,i=performance.now();if(1===this.conditions.length){var r=this.conditions[0];switch(r.type){case nt.ALL:return(t=this.querySystem).queryAll.apply(t,r.componentTypes);case nt.ANY:return(e=this.querySystem).queryAny.apply(e,r.componentTypes);case nt.NONE:return(n=this.querySystem).queryNone.apply(n,r.componentTypes)}}return{entities:[],count:0,executionTime:performance.now()-i,fromCache:!1}},e.createComponentMask=function(t){for(var e,n=M.clone(M.ZERO),i=s(t);!(e=i()).done;){var r=e.value;try{var o=F.getBitMask(r);M.orInPlace(n,o)}catch(t){this._logger.warn("组件类型 "+P(r)+" 未注册,跳过")}}return n},e.reset=function(){return this.conditions=[],this},t}(),ct=function(){function t(){this.listeners=new Map,this.stats=new Map,this.batchQueue=new Map,this.batchTimers=new Map,this.batchConfigs=new Map,this.nextListenerId=0,this.isEnabled=!0,this.maxListeners=100}var e=t.prototype;return e.on=function(t,e,n){return void 0===n&&(n={}),this.addListener(t,e,n)},e.once=function(t,e,n){return void 0===n&&(n={}),this.addListener(t,e,a({},n,{once:!0}))},e.onAsync=function(t,e,n){return void 0===n&&(n={}),this.addListener(t,e,a({},n,{async:!0}))},e.off=function(t,e){var n=this.listeners.get(t);if(!n)return!1;var i=n.findIndex((function(t){return t.id===e}));return-1!==i&&(n.splice(i,1),0===n.length&&(this.listeners.delete(t),this.stats.delete(t)),!0)},e.offAll=function(t){this.listeners.delete(t),this.stats.delete(t),this.clearBatch(t)},e.emit=function(){var t=n(l().m((function t(e,n){var i;return l().w((function(t){for(;;)switch(t.n){case 0:if(this.isEnabled){t.n=1;break}return t.a(2);case 1:if(null==(i=this.batchConfigs.get(e))||!i.enabled){t.n=2;break}return this.addToBatch(e,n),t.a(2);case 2:return t.n=3,this.executeEvent(e,n);case 3:return t.a(2)}}),t,this)})));return function(e,n){return t.apply(this,arguments)}}(),e.emitSync=function(e,n){if(this.isEnabled){var i=this.listeners.get(e);if(i&&0!==i.length){for(var r,o=performance.now(),a=[],c=s(this.sortListenersByPriority(i));!(r=c()).done;){var u=r.value;if(!u.config.async)try{u.config.context?u.handler.call(u.config.context,n):u.handler(n),u.config.once&&a.push(u.id)}catch(n){t._logger.error("事件处理器执行错误 "+e+":",n)}}this.removeListeners(e,a),this.updateStats(e,performance.now()-o)}}},e.setBatchConfig=function(t,e){this.batchConfigs.set(t,e)},e.flushBatch=function(t){var e=this.batchQueue.get(t);if(e&&0!==e.length){var n=this.batchTimers.get(t);n&&(clearTimeout(n),this.batchTimers.delete(t)),this.processBatch(t,e),this.batchQueue.delete(t)}},e.getStats=function(t){return t?this.stats.get(t)||this.createEmptyStats(t):new Map(this.stats)},e.resetStats=function(t){t?this.stats.delete(t):this.stats.clear()},e.setEnabled=function(t){this.isEnabled=t},e.hasListeners=function(t){var e=this.listeners.get(t);return!!e&&e.length>0},e.getListenerCount=function(t){var e=this.listeners.get(t);return e?e.length:0},e.clear=function(){this.listeners.clear(),this.stats.clear(),this.clearAllBatches()},e.setMaxListeners=function(t){this.maxListeners=t},e.addListener=function(e,n,i){var r=this.listeners.get(e);if(r||(r=[],this.listeners.set(e,r)),r.length>=this.maxListeners)return t._logger.warn("事件类型 "+e+" 的监听器数量超过最大限制 ("+this.maxListeners+")"),"";var o="listener_"+this.nextListenerId++,s={handler:n,config:a({priority:0},i),id:o};return r.push(s),this.stats.has(e)||this.stats.set(e,this.createEmptyStats(e)),o},e.executeEvent=function(){var e=n(l().m((function e(i,r){var o,a,c,u,h,d,f,p,m,y;return l().w((function(e){for(;;)switch(e.n){case 0:if((o=this.listeners.get(i))&&0!==o.length){e.n=1;break}return e.a(2);case 1:for(a=performance.now(),c=[],u=this.sortListenersByPriority(o),h=u.filter((function(t){return!t.config.async})),d=u.filter((function(t){return t.config.async})),f=s(h);!(p=f()).done;){m=p.value;try{m.config.context?m.handler.call(m.config.context,r):m.handler(r),m.config.once&&c.push(m.id)}catch(e){t._logger.error("同步事件处理器执行错误 "+i+":",e)}}return y=d.map(function(){var e=n(l().m((function e(n){var o;return l().w((function(e){for(;;)switch(e.p=e.n){case 0:if(e.p=0,!n.config.context){e.n=2;break}return e.n=1,n.handler.call(n.config.context,r);case 1:e.n=3;break;case 2:return e.n=3,n.handler(r);case 3:n.config.once&&c.push(n.id),e.n=5;break;case 4:e.p=4,o=e.v,t._logger.error("异步事件处理器执行错误 "+i+":",o);case 5:return e.a(2)}}),e,null,[[0,4]])})));return function(t){return e.apply(this,arguments)}}()),e.n=2,Promise.all(y);case 2:this.removeListeners(i,c),this.updateStats(i,performance.now()-a);case 3:return e.a(2)}}),e,this)})));return function(t,n){return e.apply(this,arguments)}}(),e.sortListenersByPriority=function(t){return t.slice().sort((function(t,e){return(e.config.priority||0)-(t.config.priority||0)}))},e.removeListeners=function(t,e){if(0!==e.length){var n=this.listeners.get(t);if(n){for(var i,r=function(){var t=i.value,e=n.findIndex((function(e){return e.id===t}));-1!==e&&n.splice(e,1)},o=s(e);!(i=o()).done;)r();0===n.length&&(this.listeners.delete(t),this.stats.delete(t))}}},e.addToBatch=function(t,e){var n=this,i=this.batchQueue.get(t);i||(i=[],this.batchQueue.set(t,i)),i.push(e);var r=this.batchConfigs.get(t);if(i.length>=r.batchSize)this.flushBatch(t);else if(!this.batchTimers.has(t)){var o=setTimeout((function(){n.flushBatch(t)}),r.delay);this.batchTimers.set(t,o)}},e.processBatch=function(){var t=n(l().m((function t(e,n){var i;return l().w((function(t){for(;;)switch(t.n){case 0:return i={type:e,events:n,count:n.length,timestamp:Date.now()},t.n=1,this.executeEvent(e+":batch",i);case 1:return t.a(2)}}),t,this)})));return function(e,n){return t.apply(this,arguments)}}(),e.clearBatch=function(t){this.batchQueue.delete(t);var e=this.batchTimers.get(t);e&&(clearTimeout(e),this.batchTimers.delete(t))},e.clearAllBatches=function(){this.batchQueue.clear();for(var t,e=s(this.batchTimers.values());!(t=e()).done;){var n=t.value;clearTimeout(n)}this.batchTimers.clear(),this.batchConfigs.clear()},e.updateStats=function(t,e){var n=this.stats.get(t);n||(n=this.createEmptyStats(t),this.stats.set(t,n)),n.triggerCount++,n.totalExecutionTime+=e,n.averageExecutionTime=n.totalExecutionTime/n.triggerCount,n.lastTriggerTime=Date.now(),n.listenerCount=this.getListenerCount(t)},e.createEmptyStats=function(t){return{eventType:t,listenerCount:0,triggerCount:0,totalExecutionTime:0,averageExecutionTime:0,lastTriggerTime:0}},t}();ct._logger=D("EventSystem"),exports.ECSEventType=void 0,(rt=exports.ECSEventType||(exports.ECSEventType={})).ENTITY_CREATED="entity:created",rt.ENTITY_DESTROYED="entity:destroyed",rt.ENTITY_ENABLED="entity:enabled",rt.ENTITY_DISABLED="entity:disabled",rt.ENTITY_TAG_ADDED="entity:tag:added",rt.ENTITY_TAG_REMOVED="entity:tag:removed",rt.ENTITY_NAME_CHANGED="entity:name:changed",rt.COMPONENT_ADDED="component:added",rt.COMPONENT_REMOVED="component:removed",rt.COMPONENT_MODIFIED="component:modified",rt.COMPONENT_ENABLED="component:enabled",rt.COMPONENT_DISABLED="component:disabled",rt.SYSTEM_ADDED="system:added",rt.SYSTEM_REMOVED="system:removed",rt.SYSTEM_ENABLED="system:enabled",rt.SYSTEM_DISABLED="system:disabled",rt.SYSTEM_PROCESSING_START="system:processing:start",rt.SYSTEM_PROCESSING_END="system:processing:end",rt.SYSTEM_ERROR="system:error",rt.SCENE_CREATED="scene:created",rt.SCENE_DESTROYED="scene:destroyed",rt.SCENE_ACTIVATED="scene:activated",rt.SCENE_DEACTIVATED="scene:deactivated",rt.SCENE_PAUSED="scene:paused",rt.SCENE_RESUMED="scene:resumed",rt.QUERY_EXECUTED="query:executed",rt.QUERY_CACHE_HIT="query:cache:hit",rt.QUERY_CACHE_MISS="query:cache:miss",rt.QUERY_OPTIMIZED="query:optimized",rt.PERFORMANCE_WARNING="performance:warning",rt.PERFORMANCE_CRITICAL="performance:critical",rt.MEMORY_USAGE_HIGH="memory:usage:high",rt.FRAME_RATE_DROP="frame:rate:drop",rt.INDEX_CREATED="index:created",rt.INDEX_UPDATED="index:updated",rt.INDEX_OPTIMIZED="index:optimized",rt.ARCHETYPE_CREATED="archetype:created",rt.ARCHETYPE_ENTITY_ADDED="archetype:entity:added",rt.ARCHETYPE_ENTITY_REMOVED="archetype:entity:removed",rt.DIRTY_MARK_ADDED="dirty:mark:added",rt.DIRTY_BATCH_PROCESSED="dirty:batch:processed",rt.ERROR_OCCURRED="error:occurred",rt.WARNING_ISSUED="warning:issued",rt.FRAMEWORK_INITIALIZED="framework:initialized",rt.FRAMEWORK_SHUTDOWN="framework:shutdown",rt.DEBUG_INFO="debug:info",rt.DEBUG_STATS_UPDATED="debug:stats:updated",exports.EventPriority=void 0,(ot=exports.EventPriority||(exports.EventPriority={}))[ot.LOWEST=0]="LOWEST",ot[ot.LOW=25]="LOW",ot[ot.NORMAL=50]="NORMAL",ot[ot.HIGH=75]="HIGH",ot[ot.HIGHEST=100]="HIGHEST",ot[ot.CRITICAL=200]="CRITICAL";var ut={ENTITY:{CREATED:exports.ECSEventType.ENTITY_CREATED,DESTROYED:exports.ECSEventType.ENTITY_DESTROYED,ENABLED:exports.ECSEventType.ENTITY_ENABLED,DISABLED:exports.ECSEventType.ENTITY_DISABLED,TAG_ADDED:exports.ECSEventType.ENTITY_TAG_ADDED,TAG_REMOVED:exports.ECSEventType.ENTITY_TAG_REMOVED,NAME_CHANGED:exports.ECSEventType.ENTITY_NAME_CHANGED},COMPONENT:{ADDED:exports.ECSEventType.COMPONENT_ADDED,REMOVED:exports.ECSEventType.COMPONENT_REMOVED,MODIFIED:exports.ECSEventType.COMPONENT_MODIFIED,ENABLED:exports.ECSEventType.COMPONENT_ENABLED,DISABLED:exports.ECSEventType.COMPONENT_DISABLED},SYSTEM:{ADDED:exports.ECSEventType.SYSTEM_ADDED,REMOVED:exports.ECSEventType.SYSTEM_REMOVED,ENABLED:exports.ECSEventType.SYSTEM_ENABLED,DISABLED:exports.ECSEventType.SYSTEM_DISABLED,PROCESSING_START:exports.ECSEventType.SYSTEM_PROCESSING_START,PROCESSING_END:exports.ECSEventType.SYSTEM_PROCESSING_END,ERROR:exports.ECSEventType.SYSTEM_ERROR},PERFORMANCE:{WARNING:exports.ECSEventType.PERFORMANCE_WARNING,CRITICAL:exports.ECSEventType.PERFORMANCE_CRITICAL,MEMORY_HIGH:exports.ECSEventType.MEMORY_USAGE_HIGH,FRAME_DROP:exports.ECSEventType.FRAME_RATE_DROP}},ht=function(){function t(){}return t.isValid=function(t){return this.validTypes.has(t)},t.getAllValidTypes=function(){return Array.from(this.validTypes)},t.addCustomType=function(t){this.validTypes.add(t)},t.removeCustomType=function(t){this.validTypes.delete(t)},t}();ht.validTypes=new Set([].concat(Object.values(exports.ECSEventType),Object.values(ut.ENTITY),Object.values(ut.COMPONENT),Object.values(ut.SYSTEM),Object.values(ut.PERFORMANCE)));var lt=function(){function t(t){void 0===t&&(t=!1),this.eventIdCounter=0,this.isDebugMode=!1,this.eventSystem=new ct,this.isDebugMode=t}var e=t.prototype;return e.emit=function(e,n){this.validateEventType(e);var i=this.enhanceEventData(e,n);this.isDebugMode&&t._logger.info("发射事件: "+e,i),this.eventSystem.emitSync(e,i)},e.emitAsync=function(){var e=n(l().m((function e(n,i){var r;return l().w((function(e){for(;;)switch(e.n){case 0:return this.validateEventType(n),r=this.enhanceEventData(n,i),this.isDebugMode&&t._logger.info("发射异步事件: "+n,r),e.n=1,this.eventSystem.emit(n,r);case 1:return e.a(2)}}),e,this)})));return function(t,n){return e.apply(this,arguments)}}(),e.on=function(e,n,i){void 0===i&&(i={}),this.validateEventType(e);var r={once:i.once||!1,priority:i.priority||exports.EventPriority.NORMAL,async:i.async||!1,context:i.context};return this.isDebugMode&&t._logger.info("添加监听器: "+e,r),this.eventSystem.on(e,n,r)},e.once=function(t,e,n){return void 0===n&&(n={}),this.on(t,e,a({},n,{once:!0}))},e.onAsync=function(t,e,n){return void 0===n&&(n={}),this.on(t,e,a({},n,{async:!0}))},e.off=function(e,n){return this.isDebugMode&&t._logger.info("移除监听器: "+n+" 事件: "+e),this.eventSystem.off(e,n)},e.offAll=function(e){this.isDebugMode&&t._logger.info("移除所有监听器: "+e),this.eventSystem.offAll(e)},e.hasListeners=function(t){return this.eventSystem.hasListeners(t)},e.getStats=function(t){var e=this,n=this.eventSystem.getStats(t);if(n instanceof Map){var i=new Map;return n.forEach((function(t,n){i.set(n,e.convertEventStats(t))})),i}return this.convertEventStats(n)},e.clear=function(){this.isDebugMode&&t._logger.info("清空所有监听器"),this.eventSystem.clear()},e.setEnabled=function(t){this.eventSystem.setEnabled(t)},e.setDebugMode=function(t){this.isDebugMode=t},e.setMaxListeners=function(t){this.eventSystem.setMaxListeners(t)},e.getListenerCount=function(t){return this.eventSystem.getListenerCount(t)},e.setBatchConfig=function(t,e,n){this.eventSystem.setBatchConfig(t,{batchSize:e,delay:n,enabled:!0})},e.flushBatch=function(t){this.eventSystem.flushBatch(t)},e.resetStats=function(t){this.eventSystem.resetStats(t)},e.emitEntityCreated=function(t){this.emit(exports.ECSEventType.ENTITY_CREATED,t)},e.emitEntityDestroyed=function(t){this.emit(exports.ECSEventType.ENTITY_DESTROYED,t)},e.emitComponentAdded=function(t){this.emit(exports.ECSEventType.COMPONENT_ADDED,t)},e.emitComponentRemoved=function(t){this.emit(exports.ECSEventType.COMPONENT_REMOVED,t)},e.emitSystemAdded=function(t){this.emit(exports.ECSEventType.SYSTEM_ADDED,t)},e.emitSystemRemoved=function(t){this.emit(exports.ECSEventType.SYSTEM_REMOVED,t)},e.emitSceneChanged=function(t){this.emit(exports.ECSEventType.SCENE_ACTIVATED,t)},e.emitPerformanceWarning=function(t){this.emit(exports.ECSEventType.PERFORMANCE_WARNING,t)},e.onEntityCreated=function(t,e){return this.on(exports.ECSEventType.ENTITY_CREATED,t,e)},e.onComponentAdded=function(t,e){return this.on(exports.ECSEventType.COMPONENT_ADDED,t,e)},e.onSystemError=function(t,e){return this.on(exports.ECSEventType.SYSTEM_ERROR,t,e)},e.onPerformanceWarning=function(t,e){return this.on(exports.ECSEventType.PERFORMANCE_WARNING,t,e)},e.validateEventType=function(e){ht.isValid(e)||(this.isDebugMode&&t._logger.warn("未知事件类型: "+e),this.isDebugMode&&ht.addCustomType(e))},e.enhanceEventData=function(t,e){if(null==e)return{timestamp:Date.now(),eventId:t+"_"+ ++this.eventIdCounter,source:"EventBus"};var n=e;return n.timestamp||(n.timestamp=Date.now()),n.eventId||(n.eventId=t+"_"+ ++this.eventIdCounter),n.source||(n.source="EventBus"),n},e.convertEventStats=function(t){return{eventType:t.eventType,listenerCount:t.listenerCount,triggerCount:t.triggerCount,totalExecutionTime:t.totalExecutionTime,averageExecutionTime:t.averageExecutionTime,lastTriggerTime:t.lastTriggerTime}},t}();lt._logger=D("EventBus");var dt=function(){function t(){}return t.getInstance=function(t){return void 0===t&&(t=!1),this.instance||(this.instance=new lt(t)),this.instance},t.reset=function(t){return void 0===t&&(t=!1),this.instance&&this.instance.clear(),this.instance=new lt(t),this.instance},t}();var ft=function(){function t(t){var e=this;this.name="",this._didSceneBegin=!1,this.entities=new H(this),this.entityProcessors=new G,this.identifierPool=new Y,this.componentStorageManager=new q,this.querySystem=new st,this.eventSystem=new ct,null!=t&&t.name&&(this.name=t.name),U.eventBus||(U.eventBus=new lt(!1)),U.eventBus&&U.eventBus.onComponentAdded((function(t){e.eventSystem.emitSync("component:added",t)}))}var e=t.prototype;return e.initialize=function(){},e.onStart=function(){},e.unload=function(){},e.begin=function(){null!=this.entityProcessors&&this.entityProcessors.begin(),this._didSceneBegin=!0,this.onStart()},e.end=function(){this._didSceneBegin=!1,this.entities.removeAllEntities(),this.querySystem.setEntities([]),this.componentStorageManager.clear(),this.entityProcessors&&this.entityProcessors.end(),this.unload()},e.update=function(){this.entities.updateLists(),null!=this.entityProcessors&&this.entityProcessors.update(),this.entities.update(),null!=this.entityProcessors&&this.entityProcessors.lateUpdate()},e.createEntity=function(t){var e=new U(t,this.identifierPool.checkOut());return this.eventSystem.emitSync("entity:created",{entityName:t,entity:e,scene:this}),this.addEntity(e)},e.addEntity=function(t,e){return void 0===e&&(e=!1),this.entities.add(t),t.scene=this,this.querySystem.addEntity(t,e),this.eventSystem.emitSync("entity:added",{entity:t,scene:this}),t},e.createEntities=function(t,e){void 0===e&&(e="Entity");for(var n=[],i=0;i<t;i++){var r=new U(e+"_"+i,this.identifierPool.checkOut());r.scene=this,n.push(r)}for(var o=0,s=n;o<s.length;o++){var a=s[o];this.entities.add(a)}return this.querySystem.addEntitiesUnchecked(n),this.eventSystem.emitSync("entities:batch_added",{entities:n,scene:this,count:t}),n},e.destroyAllEntities=function(){this.entities.removeAllEntities(),this.querySystem.setEntities([])},e.findEntity=function(t){return this.entities.findEntity(t)},e.findEntityById=function(t){return this.entities.findEntityById(t)},e.findEntitiesByTag=function(t){for(var e,n=[],i=s(this.entities.buffer);!(e=i()).done;){var r=e.value;r.tag===t&&n.push(r)}return n},e.getEntityByName=function(t){return this.findEntity(t)},e.getEntitiesByTag=function(t){return this.findEntitiesByTag(t)},e.addEntityProcessor=function(t){return this.entityProcessors.processors.includes(t)||(t.scene=this,this.entityProcessors.add(t),t.initialize(),t.setUpdateOrder(this.entityProcessors.count-1)),t},e.addSystem=function(t){return this.addEntityProcessor(t)},e.removeEntityProcessor=function(t){this.entityProcessors.remove(t),t.reset(),t.scene=null},e.getEntityProcessor=function(t){return this.entityProcessors.getProcessor(t)},e.getStats=function(){return{entityCount:this.entities.count,processorCount:this.entityProcessors.count,componentStorageStats:this.componentStorageManager.getAllStats()}},e.getDebugInfo=function(){return{name:this.name||this.constructor.name,entityCount:this.entities.count,processorCount:this.entityProcessors.count,isRunning:this._didSceneBegin,entities:this.entities.buffer.map((function(t){return{name:t.name,id:t.id,componentCount:t.components.length,componentTypes:t.components.map((function(t){return z(t)}))}})),processors:this.entityProcessors.processors.map((function(t){var e;return{name:B(t),updateOrder:t.updateOrder,entityCount:(null===(e=t._entities)||void 0===e?void 0:e.length)||0}})),componentStats:this.componentStorageManager.getAllStats()}},o(t,[{key:"systems",get:function(){return this.entityProcessors.processors}}])}(),pt=function(){function t(){this.scene=new ft}var e=t.prototype;return e.named=function(t){return this.scene.name=t,this},e.withEntity=function(t){return this.scene.addEntity(t),this},e.withEntityBuilder=function(t){var e=t(new j(this.scene,this.scene.componentStorageManager)).build();return this.scene.addEntity(e),this},e.withEntities=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.scene.addEntity(o)}return this},e.withSystem=function(t){return this.scene.addSystem(t),this},e.withSystems=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.scene.addSystem(o)}return this},e.build=function(){return this.scene},t}(),mt=function(){function t(t){for(var e=arguments.length,n=new Array(e>1?e-1:0),r=1;r<e;r++)n[r-1]=arguments[r];this.component=i(t,n)}var e=t.prototype;return e.set=function(t,e){return this.component[t]=e,this},e.configure=function(t){return t(this.component),this},e.setIf=function(t,e,n){return t&&(this.component[e]=n),this},e.build=function(){return this.component},t}(),yt=function(){function t(t){this.entities=t}var e=t.prototype;return e.addComponent=function(t){for(var e,n=s(this.entities);!(e=n()).done;){e.value.addComponent(t)}return this},e.removeComponent=function(t){for(var e,n=s(this.entities);!(e=n()).done;){e.value.removeComponentByType(t)}return this},e.setActive=function(t){for(var e,n=s(this.entities);!(e=n()).done;){e.value.active=t}return this},e.setTag=function(t){for(var e,n=s(this.entities);!(e=n()).done;){e.value.tag=t}return this},e.forEach=function(t){return this.entities.forEach(t),this},e.filter=function(e){return new t(this.entities.filter(e))},e.toArray=function(){return this.entities.slice()},e.count=function(){return this.entities.length},t}(),gt=function(){function t(t,e,n){this.scene=t,this.querySystem=e,this.eventSystem=n}var e=t.prototype;return e.createEntity=function(){return new j(this.scene,this.scene.componentStorageManager)},e.createScene=function(){return new pt},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];return i(mt,[t].concat(n))},e.query=function(){return new at(this.querySystem)},e.find=function(){var t;return(t=this.querySystem).queryAll.apply(t,arguments).entities},e.findFirst=function(){var t,e=(t=this.querySystem).queryAll.apply(t,arguments);return e.entities.length>0?e.entities[0]:null},e.findByName=function(t){return this.scene.findEntity(t)},e.findByTag=function(t){return this.scene.findEntitiesByTag(t)},e.emit=function(t,e){this.eventSystem.emitSync(t,e)},e.emitAsync=function(){var t=n(l().m((function t(e,n){return l().w((function(t){for(;;)switch(t.n){case 0:return t.n=1,this.eventSystem.emit(e,n);case 1:return t.a(2)}}),t,this)})));return function(e,n){return t.apply(this,arguments)}}(),e.on=function(t,e){return this.eventSystem.on(t,e)},e.once=function(t,e){return this.eventSystem.once(t,e)},e.off=function(t,e){this.eventSystem.off(t,e)},e.batch=function(t){return new yt(t)},e.getStats=function(){return{entityCount:this.scene.entities.count,systemCount:this.scene.systems.length,componentStats:this.scene.componentStorageManager.getAllStats(),queryStats:this.querySystem.getStats(),eventStats:this.eventSystem.getStats()}},t}();function vt(t,e,n){return new gt(t,e,n)}var _t=D("World"),Et=function(){function t(t){void 0===t&&(t={}),this._scenes=new Map,this._activeScenes=new Set,this._globalSystems=[],this._isActive=!1,this._config=a({name:"World",debug:!1,maxScenes:10,autoCleanup:!0},t),this.name=this._config.name,this._createdAt=Date.now(),_t.info("创建World: "+this.name)}var e=t.prototype;return e.createScene=function(t,e){if(this._scenes.has(t))throw new Error("Scene ID '"+t+"' 已存在于World '"+this.name+"' 中");if(this._scenes.size>=this._config.maxScenes)throw new Error("World '"+this.name+"' 已达到最大Scene数量限制: "+this._config.maxScenes);var n=e||new ft;return"id"in n&&(n.id=t),"name"in n&&!n.name&&(n.name=t),this._scenes.set(t,n),n.initialize(),_t.info("在World '"+this.name+"' 中创建Scene: "+t),n},e.removeScene=function(t){var e=this._scenes.get(t);return!!e&&(this._activeScenes.has(t)&&this.setSceneActive(t,!1),e.end(),this._scenes.delete(t),_t.info("从World '"+this.name+"' 中移除Scene: "+t),!0)},e.getScene=function(t){return this._scenes.get(t)||null},e.getSceneIds=function(){return Array.from(this._scenes.keys())},e.getAllScenes=function(){return Array.from(this._scenes.values())},e.setSceneActive=function(t,e){var n=this._scenes.get(t);n?e?(this._activeScenes.add(t),n.begin&&n.begin(),_t.debug("在World '"+this.name+"' 中激活Scene: "+t)):(this._activeScenes.delete(t),_t.debug("在World '"+this.name+"' 中停用Scene: "+t)):_t.warn("Scene '"+t+"' 不存在于World '"+this.name+"' 中")},e.isSceneActive=function(t){return this._activeScenes.has(t)},e.getActiveSceneCount=function(){return this._activeScenes.size},e.addGlobalSystem=function(t){return this._globalSystems.includes(t)||(this._globalSystems.push(t),t.initialize&&t.initialize(),_t.debug("在World '"+this.name+"' 中添加全局System: "+t.name)),t},e.removeGlobalSystem=function(t){var e=this._globalSystems.indexOf(t);return-1!==e&&(this._globalSystems.splice(e,1),t.reset&&t.reset(),_t.debug("从World '"+this.name+"' 中移除全局System: "+t.name),!0)},e.getGlobalSystem=function(t){for(var e,n=s(this._globalSystems);!(e=n()).done;){var i=e.value;if(i instanceof t)return i}return null},e.start=function(){if(!this._isActive){this._isActive=!0;for(var t,e=s(this._globalSystems);!(t=e()).done;){var n=t.value;n.initialize&&n.initialize()}_t.info("启动World: "+this.name)}},e.stop=function(){if(this._isActive){for(var t,e=s(this._activeScenes);!(t=e()).done;){var n=t.value;this.setSceneActive(n,!1)}for(var i,r=s(this._globalSystems);!(i=r()).done;){var o=i.value;o.reset&&o.reset()}this._isActive=!1,_t.info("停止World: "+this.name)}},e.updateGlobalSystems=function(){if(this._isActive)for(var t,e=s(this._globalSystems);!(t=e()).done;){var n=t.value;n.update&&n.update()}},e.updateScenes=function(){if(this._isActive){for(var t,e=s(this._activeScenes);!(t=e()).done;){var n=t.value,i=this._scenes.get(n);i&&i.update&&i.update()}this._config.autoCleanup&&this.shouldAutoCleanup()&&this.cleanup()}},e.destroy=function(){_t.info("销毁World: "+this.name),this.stop();for(var t=0,e=Array.from(this._scenes.keys());t<e.length;t++){var n=e[t];this.removeScene(n)}for(var i,r=s(this._globalSystems);!(i=r()).done;){var o=i.value;o.destroy?o.destroy():o.reset&&o.reset()}this._globalSystems.length=0,this._scenes.clear(),this._activeScenes.clear()},e.getStatus=function(){var t=this;return{name:this.name,isActive:this._isActive,sceneCount:this._scenes.size,activeSceneCount:this._activeScenes.size,globalSystemCount:this._globalSystems.length,createdAt:this._createdAt,config:a({},this._config),scenes:Array.from(this._scenes.keys()).map((function(e){var n;return{id:e,isActive:t._activeScenes.has(e),name:(null===(n=t._scenes.get(e))||void 0===n?void 0:n.name)||e}}))}},e.getStats=function(){for(var t,e={totalEntities:0,totalSystems:this._globalSystems.length,memoryUsage:0,performance:{averageUpdateTime:0,maxUpdateTime:0}},n=s(this._scenes.values());!(t=n()).done;){var i=t.value;i.entities&&(e.totalEntities+=i.entities.count),i.systems&&(e.totalSystems+=i.systems.length)}return e},e.shouldAutoCleanup=function(){for(var t,e=Date.now(),n=s(this._scenes);!(t=n()).done;){var i=t.value,r=i[0],o=i[1];if(!this._activeScenes.has(r)&&o.entities&&0===o.entities.count&&e-this._createdAt>3e5)return!0}return!1},e.cleanup=function(){for(var t=Array.from(this._scenes.keys()),e=Date.now(),n=0,i=t;n<i.length;n++){var r=i[n],o=this._scenes.get(r);o&&!this._activeScenes.has(r)&&o.entities&&0===o.entities.count&&e-this._createdAt>3e5&&(this.removeScene(r),_t.debug("自动清理空Scene: "+r+" from World "+this.name))}},o(t,[{key:"isActive",get:function(){return this._isActive}},{key:"sceneCount",get:function(){return this._scenes.size}},{key:"createdAt",get:function(){return this._createdAt}}])}(),St=D("WorldManager"),Tt=function(){function t(t){void 0===t&&(t={}),this._worlds=new Map,this._activeWorlds=new Set,this._cleanupTimer=null,this._isRunning=!1,this._config=a({maxWorlds:50,autoCleanup:!0,cleanupInterval:3e4,debug:!1},t),St.info("WorldManager已初始化",{maxWorlds:this._config.maxWorlds,autoCleanup:this._config.autoCleanup,cleanupInterval:this._config.cleanupInterval}),this.startCleanupTimer()}t.getInstance=function(e){return this._instance||(this._instance=new t(e)),this._instance},t.reset=function(){this._instance&&(this._instance.destroy(),this._instance=null)};var e=t.prototype;return e.createWorld=function(t,e){if(!t||"string"!=typeof t||""===t.trim())throw new Error("World ID不能为空");if(this._worlds.has(t))throw new Error("World ID '"+t+"' 已存在");if(this._worlds.size>=this._config.maxWorlds)throw new Error("已达到最大World数量限制: "+this._config.maxWorlds);var n=a({name:t,debug:this._config.debug},e),i=new Et(n);return this._worlds.set(t,i),St.info("创建World: "+t,{config:n}),i},e.removeWorld=function(t){var e=this._worlds.get(t);return!!e&&(this._activeWorlds.has(t)&&this.setWorldActive(t,!1),e.destroy(),this._worlds.delete(t),St.info("移除World: "+t),!0)},e.getWorld=function(t){return this._worlds.get(t)||null},e.getWorldIds=function(){return Array.from(this._worlds.keys())},e.getAllWorlds=function(){return Array.from(this._worlds.values())},e.setWorldActive=function(t,e){var n=this._worlds.get(t);n?e?(this._activeWorlds.add(t),n.start(),St.debug("激活World: "+t)):(this._activeWorlds.delete(t),n.stop(),St.debug("停用World: "+t)):St.warn("World '"+t+"' 不存在")},e.isWorldActive=function(t){return this._activeWorlds.has(t)},e.getActiveWorlds=function(){for(var t,e=[],n=s(this._activeWorlds);!(t=n()).done;){var i=t.value,r=this._worlds.get(i);r&&e.push(r)}return e},e.startAll=function(){this._isRunning=!0;for(var t,e=s(this._worlds.keys());!(t=e()).done;){var n=t.value;this.setWorldActive(n,!0)}St.info("启动所有World")},e.stopAll=function(){this._isRunning=!1;for(var t,e=s(this._activeWorlds);!(t=e()).done;){var n=t.value;this.setWorldActive(n,!1)}St.info("停止所有World")},e.findWorlds=function(t){for(var e,n=[],i=s(this._worlds.values());!(e=i()).done;){var r=e.value;t(r)&&n.push(r)}return n},e.findWorldByName=function(t){for(var e,n=s(this._worlds.values());!(e=n()).done;){var i=e.value;if(i.name===t)return i}return null},e.getStats=function(){for(var t,e={totalWorlds:this._worlds.size,activeWorlds:this._activeWorlds.size,totalScenes:0,totalEntities:0,totalSystems:0,memoryUsage:0,isRunning:this._isRunning,config:a({},this._config),worlds:[]},n=s(this._worlds);!(t=n()).done;){var i=t.value,r=i[0],o=i[1],c=o.getStats();e.totalScenes+=c.totalSystems,e.totalEntities+=c.totalEntities,e.totalSystems+=c.totalSystems,e.worlds.push(a({id:r,name:o.name,isActive:this._activeWorlds.has(r),sceneCount:o.sceneCount},c))}return e},e.getDetailedStatus=function(){var t=this;return a({},this.getStats(),{worlds:Array.from(this._worlds.entries()).map((function(e){var n=e[0],i=e[1];return{id:n,isActive:t._activeWorlds.has(n),status:i.getStatus()}}))})},e.cleanup=function(){for(var t,e=[],n=s(this._worlds);!(t=n()).done;){var i=t.value,r=i[0],o=i[1];this.shouldCleanupWorld(o)&&e.push(r)}for(var a=0,c=e;a<c.length;a++){var u=c[a];this.removeWorld(u)}return e.length>0&&St.debug("清理了 "+e.length+" 个World"),e.length},e.destroy=function(){St.info("正在销毁WorldManager..."),this.stopCleanupTimer(),this.stopAll();for(var t=0,e=Array.from(this._worlds.keys());t<e.length;t++){var n=e[t];this.removeWorld(n)}this._worlds.clear(),this._activeWorlds.clear(),this._isRunning=!1,St.info("WorldManager已销毁")},e.startCleanupTimer=function(){var t=this;this._config.autoCleanup&&!this._cleanupTimer&&(this._cleanupTimer=setInterval((function(){t.cleanup()}),this._config.cleanupInterval),St.debug("启动World清理定时器,间隔: "+this._config.cleanupInterval+"ms"))},e.stopCleanupTimer=function(){this._cleanupTimer&&(clearInterval(this._cleanupTimer),this._cleanupTimer=null,St.debug("停止World清理定时器"))},e.shouldCleanupWorld=function(t){return!t.isActive&&((0===t.sceneCount||!t.getAllScenes().some((function(t){return t.entities&&t.entities.count>0})))&&Date.now()-t.createdAt>6e5)},o(t,[{key:"worldCount",get:function(){return this._worlds.size}},{key:"activeWorldCount",get:function(){return this._activeWorlds.size}},{key:"isRunning",get:function(){return this._isRunning}},{key:"config",get:function(){return a({},this._config)}}])}();Tt._instance=null;var Ct=function(){function t(t){if(t&&"object"==typeof t)this._value=M.clone(t);else if("number"==typeof t)this._value=M.fromNumber(t);else if("string"==typeof t){var e=parseInt(t,10);this._value=M.fromNumber(e)}else this._value=M.clone(M.ZERO)}var e=t.prototype;return e.set=function(t){if(t<0)throw new Error("Bit index cannot be negative");if(t>=64)throw new Error("Bit index exceeds 64-bit limit. ECS framework supports max 64 component types.");M.setBit(this._value,t)},e.clear=function(t){if(t<0)throw new Error("Bit index cannot be negative");t>=64||M.clearBit(this._value,t)},e.get=function(t){if(t<0||t>=64)return!1;var e=M.create(t);return M.hasAny(this._value,e)},e.containsAll=function(t){return M.hasAll(this._value,t._value)},e.intersects=function(t){return M.hasAny(this._value,t._value)},e.excludes=function(t){return M.hasNone(this._value,t._value)},e.clearAll=function(){M.clear(this._value)},e.isEmpty=function(){return M.isZero(this._value)},e.cardinality=function(){return M.popCount(this._value)},e.and=function(e){var n=new t;return M.copy(this._value,n._value),M.andInPlace(n._value,e._value),n},e.or=function(e){var n=new t;return M.copy(this._value,n._value),M.orInPlace(n._value,e._value),n},e.xor=function(e){var n=new t;return M.copy(this._value,n._value),M.xorInPlace(n._value,e._value),n},e.not=function(e){void 0===e&&(e=64),e>64&&(e=64);var n=new t;if(M.copy(this._value,n._value),e<=32){var i=(1<<e)-1;n._value.lo=~n._value.lo&i,n._value.hi=0}else if(n._value.lo=~n._value.lo,e<64){var r=(1<<e-32)-1;n._value.hi=~n._value.hi&r}else n._value.hi=~n._value.hi;return n},e.copyFrom=function(t){M.copy(t._value,this._value)},e.clone=function(){return new t(this._value)},e.getValue=function(){return this._value},e.setValue=function(t){if("object"==typeof t)M.copy(t,this._value);else if("number"==typeof t)this._value=M.fromNumber(t);else{var e=parseInt(t,10);this._value=M.fromNumber(e)}},e.toString=function(){for(var t=[],e=0;e<64;e++)this.get(e)&&t.push(e.toString());return"Bits["+t.join(", ")+"]"},e.toBinaryString=function(t){void 0===t&&(t=64),t>64&&(t=64);for(var e="",n=t-1;n>=0;n--)e+=this.get(n)?"1":"0",n%8==0&&n>0&&(e+=" ");return e},e.toHexString=function(){return M.toString(this._value,16)},t.fromBinaryString=function(e){var n,i=e.replace(/\s/g,"");if(i.length<=32){n={lo:parseInt(i,2)>>>0,hi:0}}else{var r=i.substring(i.length-32),o=i.substring(0,i.length-32);n={lo:parseInt(r,2)>>>0,hi:parseInt(o,2)>>>0}}return new t(n)},t.fromHexString=function(e){var n,i=e.replace(/^0x/i,"");if(i.length<=8){n={lo:parseInt(i,16)>>>0,hi:0}}else{var r=i.substring(i.length-8),o=i.substring(0,i.length-8);n={lo:parseInt(r,16)>>>0,hi:parseInt(o,16)>>>0}}return new t(n)},e.equals=function(t){return M.equals(this._value,t._value)},e.getHighestBitIndex=function(){if(M.isZero(this._value))return-1;if(0!==this._value.hi)for(var t=31;t>=0;t--)if(this._value.hi&1<<t)return t+32;for(var e=31;e>=0;e--)if(this._value.lo&1<<e)return e;return-1},e.getLowestBitIndex=function(){if(M.isZero(this._value))return-1;for(var t=0;t<32;t++)if(this._value.lo&1<<t)return t;for(var e=0;e<32;e++)if(this._value.hi&1<<e)return e+32;return-1},t}(),bt=function(){function t(){this._componentTypes=new Map,this._typeNames=new Map,this._nextTypeId=0}var e=t.prototype;return e.getTypeId=function(t){var e=this._componentTypes.get(t);return void 0===e&&(e=this._nextTypeId++,this._componentTypes.set(t,e),this._typeNames.set(e,P(t))),e},e.getTypeName=function(t){return this._typeNames.get(t)||"Unknown"},e.createBits=function(){for(var t=new Ct,e=arguments.length,n=new Array(e),i=0;i<e;i++)n[i]=arguments[i];for(var r=0,o=n;r<o.length;r++){var s=o[r],a=this.getTypeId(s);t.set(a)}return t},e.getEntityBits=function(t){for(var e,n=new Ct,i=s(t);!(e=i()).done;){var r=e.value,o=this.getTypeId(r.constructor);n.set(o)}return n},e.reset=function(){this._componentTypes.clear(),this._typeNames.clear(),this._nextTypeId=0},o(t,[{key:"registeredTypeCount",get:function(){return this._componentTypes.size}}],[{key:"instance",get:function(){return t._instance||(t._instance=new t),t._instance}}])}(),Mt=function(){function t(){}var e=t.prototype;return e.collectEntityData=function(){var t=kt.scene;if(!t)return this.getEmptyEntityDebugData();var e,n=t.entities;if(!n)return this.getEmptyEntityDebugData();try{e=n.getStats?n.getStats():this.calculateFallbackEntityStats(n)}catch(t){return{totalEntities:0,activeEntities:0,pendingAdd:0,pendingRemove:0,entitiesPerArchetype:[],topEntitiesByComponents:[],entityHierarchy:[],entityDetailsMap:{}}}var i=this.collectArchetypeData(t);return{totalEntities:e.totalEntities,activeEntities:e.activeEntities,pendingAdd:e.pendingAdd||0,pendingRemove:e.pendingRemove||0,entitiesPerArchetype:i.distribution,topEntitiesByComponents:i.topEntities,entityHierarchy:[],entityDetailsMap:{}}},e.getRawEntityList=function(){var t=kt.scene;if(!t)return[];var e=t.entities;return null!=e&&e.buffer?e.buffer.map((function(t){var e,n;return{id:t.id,name:t.name||"Entity_"+t.id,active:!1!==t.active,enabled:!1!==t.enabled,activeInHierarchy:!1!==t.activeInHierarchy,componentCount:t.components.length,componentTypes:t.components.map((function(t){return z(t)})),parentId:(null===(e=t.parent)||void 0===e?void 0:e.id)||null,childIds:(null===(n=t.children)||void 0===n?void 0:n.map((function(t){return t.id})))||[],depth:t.getDepth?t.getDepth():0,tag:t.tag||0,updateOrder:t.updateOrder||0}})):[]},e.getEntityDetails=function(t){try{var e,n,i,r=kt.scene;if(!r)return null;var o=r.entities;if(null==o||!o.buffer)return null;var s=o.buffer.find((function(e){return e.id===t}));if(!s)return null;var c=s.getDebugInfo?s.getDebugInfo():this.buildFallbackEntityInfo(s),u=this.extractComponentDetails(s.components),h=this.getSceneInfo(r);return a({},c,{scene:h.name,sceneName:h.name,sceneType:h.type,parentName:(null===(e=s.parent)||void 0===e?void 0:e.name)||null,components:u||[],componentCount:(null===(n=s.components)||void 0===n?void 0:n.length)||0,componentTypes:(null===(i=s.components)||void 0===i?void 0:i.map((function(t){return z(t)})))||[]})}catch(t){return{error:"获取实体详情失败: "+(t instanceof Error?t.message:String(t)),scene:"获取失败",components:[],componentCount:0,componentTypes:[]}}},e.getSceneInfo=function(t){var e="当前场景",n="Scene";try{if(t.name&&"string"==typeof t.name&&t.name.trim())e=t.name.trim();else if(t.constructor&&t.constructor.name)e=t.constructor.name,n=t.constructor.name;else if(t._name&&"string"==typeof t._name&&t._name.trim())e=t._name.trim();else{var i,r=null===(i=Object.getPrototypeOf(t))||void 0===i||null===(i=i.constructor)||void 0===i?void 0:i.name;r&&"Object"!==r&&(e=r,n=r)}}catch(t){e="场景名获取失败"}return{name:e,type:n}},e.collectEntityDataWithMemory=function(){var t=kt.scene;if(!t)return this.getEmptyEntityDebugData();var e,n=t.entities;if(!n)return this.getEmptyEntityDebugData();try{e=n.getStats?n.getStats():this.calculateFallbackEntityStats(n)}catch(t){return{totalEntities:0,activeEntities:0,pendingAdd:0,pendingRemove:0,entitiesPerArchetype:[],topEntitiesByComponents:[],entityHierarchy:[],entityDetailsMap:{}}}var i=this.collectArchetypeDataWithMemory(t);return{totalEntities:e.totalEntities,activeEntities:e.activeEntities,pendingAdd:e.pendingAdd||0,pendingRemove:e.pendingRemove||0,entitiesPerArchetype:i.distribution,topEntitiesByComponents:i.topEntities,entityHierarchy:this.buildEntityHierarchyTree(n),entityDetailsMap:this.buildEntityDetailsMap(n)}},e.collectArchetypeData=function(t){var e;if(t&&t.archetypeSystem&&"function"==typeof t.archetypeSystem.getAllArchetypes)return this.extractArchetypeStatistics(t.archetypeSystem);var n={entities:(null===(e=t.entities)||void 0===e?void 0:e.buffer)||[]};return{distribution:this.getArchetypeDistributionFast(n),topEntities:this.getTopEntitiesByComponentsFast(n)}},e.getArchetypeDistributionFast=function(t){var e=new Map;return t&&t.entities&&t.entities.forEach((function(t){var n,i=(null===(n=t.components)||void 0===n?void 0:n.map((function(t){return z(t)})))||[],r=i.length>0?i.sort().join(", "):"无组件",o=e.get(r);o?o.count++:e.set(r,{count:1,componentTypes:i})})),Array.from(e.entries()).map((function(t){return{signature:t[0],count:t[1].count,memory:0}})).sort((function(t,e){return e.count-t.count})).slice(0,20)},e.getTopEntitiesByComponentsFast=function(t){return t&&t.entities?t.entities.map((function(t){var e;return{id:t.id.toString(),name:t.name||"Entity_"+t.id,componentCount:(null===(e=t.components)||void 0===e?void 0:e.length)||0,memory:0}})).sort((function(t,e){return e.componentCount-t.componentCount})).slice(0,10):[]},e.collectArchetypeDataWithMemory=function(t){var e;if(t&&t.archetypeSystem&&"function"==typeof t.archetypeSystem.getAllArchetypes)return this.extractArchetypeStatisticsWithMemory(t.archetypeSystem);var n={entities:(null===(e=t.entities)||void 0===e?void 0:e.buffer)||[]};return{distribution:this.getArchetypeDistributionWithMemory(n),topEntities:this.getTopEntitiesByComponentsWithMemory(n)}},e.extractArchetypeStatistics=function(t){var e=t.getAllArchetypes(),n=[],i=[];return e.forEach((function(t){var e,r,o=(null===(e=t.componentTypes)||void 0===e?void 0:e.map((function(t){return t.name})).join(","))||"Unknown",s=(null===(r=t.entities)||void 0===r?void 0:r.length)||0;n.push({signature:o,count:s,memory:0}),t.entities&&t.entities.slice(0,5).forEach((function(t){var e;i.push({id:t.id.toString(),name:t.name||"Entity_"+t.id,componentCount:(null===(e=t.components)||void 0===e?void 0:e.length)||0,memory:0})}))})),n.sort((function(t,e){return e.count-t.count})),i.sort((function(t,e){return e.componentCount-t.componentCount})),{distribution:n,topEntities:i}},e.extractArchetypeStatisticsWithMemory=function(t){var e=this,n=t.getAllArchetypes(),i=[],r=[];return n.forEach((function(t){var n,o,s=(null===(n=t.componentTypes)||void 0===n?void 0:n.map((function(t){return t.name})).join(","))||"Unknown",a=(null===(o=t.entities)||void 0===o?void 0:o.length)||0,c=0;if(t.entities&&t.entities.length>0){for(var u=Math.min(5,t.entities.length),h=0,l=0;l<u;l++)h+=e.estimateEntityMemoryUsage(t.entities[l]);c=h/u*a}i.push({signature:s,count:a,memory:c}),t.entities&&t.entities.slice(0,5).forEach((function(t){var n;r.push({id:t.id.toString(),name:t.name||"Entity_"+t.id,componentCount:(null===(n=t.components)||void 0===n?void 0:n.length)||0,memory:e.estimateEntityMemoryUsage(t)})}))})),i.sort((function(t,e){return e.count-t.count})),r.sort((function(t,e){return e.componentCount-t.componentCount})),{distribution:i,topEntities:r}},e.getArchetypeDistribution=function(t){var e=new Map;return t&&t.entities&&t.entities.forEach((function(t){var n,i=(null===(n=t.componentMask)||void 0===n?void 0:n.toString())||"0",r=e.get(i);e.set(i,(r||0)+1)})),Array.from(e.entries()).map((function(t){return{signature:t[0],count:t[1],memory:0}})).sort((function(t,e){return e.count-t.count}))},e.getArchetypeDistributionWithMemory=function(t){var e=this,n=new Map;return t&&t.entities&&t.entities.forEach((function(t){var i,r=(null===(i=t.components)||void 0===i?void 0:i.map((function(t){return z(t)})))||[],o=r.length>0?r.sort().join(", "):"无组件",s=n.get(o),a=e.estimateEntityMemoryUsage(t);(isNaN(a)||a<0)&&(a=0),s?(s.count++,s.memory+=a):n.set(o,{count:1,memory:a,componentTypes:r})})),Array.from(n.entries()).map((function(t){var e=t[0],n=t[1];return{signature:e,count:n.count,memory:isNaN(n.memory)?0:n.memory}})).sort((function(t,e){return e.count-t.count}))},e.getTopEntitiesByComponents=function(t){return t&&t.entities?t.entities.map((function(t){var e;return{id:t.id.toString(),name:t.name||"Entity_"+t.id,componentCount:(null===(e=t.components)||void 0===e?void 0:e.length)||0,memory:0}})).sort((function(t,e){return e.componentCount-t.componentCount})):[]},e.getTopEntitiesByComponentsWithMemory=function(t){var e=this;return t&&t.entities?t.entities.map((function(t){var n;return{id:t.id.toString(),name:t.name||"Entity_"+t.id,componentCount:(null===(n=t.components)||void 0===n?void 0:n.length)||0,memory:e.estimateEntityMemoryUsage(t)}})).sort((function(t,e){return e.componentCount-t.componentCount})):[]},e.getEmptyEntityDebugData=function(){return{totalEntities:0,activeEntities:0,pendingAdd:0,pendingRemove:0,entitiesPerArchetype:[],topEntitiesByComponents:[],entityHierarchy:[],entityDetailsMap:{}}},e.calculateFallbackEntityStats=function(t){var e=t.buffer||[],n=e.filter((function(t){return t.enabled&&!t._isDestroyed}));return{totalEntities:e.length,activeEntities:n.length,pendingAdd:0,pendingRemove:0,averageComponentsPerEntity:n.length>0?e.reduce((function(t,e){var n;return t+((null===(n=e.components)||void 0===n?void 0:n.length)||0)}),0)/n.length:0}},e.estimateEntityMemoryUsage=function(t){var e=this;try{var n=0,i=this.calculateObjectSize(t,["components","children","parent"]);return!isNaN(i)&&i>0&&(n+=i),t.components&&Array.isArray(t.components)&&t.components.forEach((function(t){var i=e.calculateObjectSize(t,["entity"]);!isNaN(i)&&i>0&&(n+=i)})),isNaN(n)||n<0?0:n}catch(t){return 0}},e.calculateObjectSize=function(t,e){if(void 0===e&&(e=[]),!t||"object"!=typeof t)return 0;var n=new WeakSet,i=function(t,r){if(void 0===r&&(r=0),!t||"object"!=typeof t||r>=2)return 0;if(n.has(t))return 0;n.add(t);var o=32;try{for(var s=Object.keys(t),a=Math.min(s.length,20),c=0;c<a;c++){var u=s[c];if(!(e.includes(u)||"constructor"===u||"__proto__"===u||u.startsWith("_cc_")||u.startsWith("__"))){var h=t[u];o+=2*u.length,"string"==typeof h?o+=Math.min(2*h.length,200):"number"==typeof h?o+=8:"boolean"==typeof h?o+=4:Array.isArray(h)?o+=40+Math.min(8*h.length,160):"object"==typeof h&&null!==h&&(o+=i(h,r+1))}}}catch(t){return 64}return o};try{var r=i(t);return Math.max(r,32)}catch(t){return 64}},e.buildEntityHierarchyTree=function(t){var e=this;if(null==t||!t.buffer)return[];var n=[];return t.buffer.forEach((function(t){if(!t.parent){var i=e.buildEntityHierarchyNode(t);n.push(i)}})),n.sort((function(t,e){return t.name<e.name?-1:t.name>e.name?1:t.id-e.id})),n},e.buildEntityHierarchyNode=function(t){var e,n=this,i={id:t.id,name:t.name||"Entity_"+t.id,active:!1!==t.active,enabled:!1!==t.enabled,activeInHierarchy:!1!==t.activeInHierarchy,componentCount:t.components.length,componentTypes:t.components.map((function(t){return z(t)})),parentId:(null===(e=t.parent)||void 0===e?void 0:e.id)||null,children:[],depth:t.getDepth?t.getDepth():0,tag:t.tag||0,updateOrder:t.updateOrder||0};(t.children&&t.children.length>0&&(i.children=t.children.map((function(t){return n.buildEntityHierarchyNode(t)}))),"function"==typeof t.getDebugInfo)&&(i=a({},i,t.getDebugInfo()));return t.components&&t.components.length>0&&(i.componentDetails=this.extractComponentDetails(t.components)),i},e.buildEntityDetailsMap=function(t){var e=this;if(null==t||!t.buffer)return{};for(var n={},i=t.buffer,r=0;r<i.length;r+=100){i.slice(r,r+100).forEach((function(t){var i,r=t.getDebugInfo?t.getDebugInfo():e.buildFallbackEntityInfo(t),o=t.getComponentCacheStats?t.getComponentCacheStats():null,s=e.extractComponentDetails(t.components);n[t.id]=a({},r,{parentName:(null===(i=t.parent)||void 0===i?void 0:i.name)||null,components:s,componentTypes:r.componentTypes||s.map((function(t){return t.typeName})),cachePerformance:o?{hitRate:o.cacheStats.hitRate,size:o.cacheStats.size,maxSize:o.cacheStats.maxSize}:null})}))}return n},e.buildFallbackEntityInfo=function(t){var e,n,i,r=kt.scene,o=this.getSceneInfo(r);return{name:t.name||"Entity_"+t.id,id:t.id,enabled:!1!==t.enabled,active:!1!==t.active,activeInHierarchy:!1!==t.activeInHierarchy,destroyed:t.isDestroyed||!1,scene:o.name,sceneName:o.name,sceneType:o.type,componentCount:t.components.length,componentTypes:t.components.map((function(t){return z(t)})),componentMask:(null===(e=t.componentMask)||void 0===e?void 0:e.toString())||"0",parentId:(null===(n=t.parent)||void 0===n?void 0:n.id)||null,childCount:(null===(i=t.children)||void 0===i?void 0:i.length)||0,childIds:t.children.map((function(t){return t.id}))||[],depth:t.getDepth?t.getDepth():0,tag:t.tag||0,updateOrder:t.updateOrder||0}},e.extractComponentDetails=function(t){var e=this;return t.map((function(t){var n=z(t);if(!n||"Object"===n||"Function"===n)try{var i=bt.instance,r=t.constructor,o=i.getTypeId(r);n=i.getTypeName(o)}catch(t){n="UnknownComponent"}var s={};try{Object.keys(t).forEach((function(n){if(!n.startsWith("_")&&"entity"!==n&&"constructor"!==n){var i=t[n];null!=i&&(s[n]=e.formatPropertyValue(i))}})),0===Object.keys(s).length&&(s._info="该组件没有公开属性",s._componentId=z(t))}catch(e){s._error="属性提取失败",s._componentId=z(t)}return{typeName:n,properties:s}}))},e.getComponentProperties=function(t,e){var n=this;try{var i=kt.scene;if(!i)return{};var r=i.entities;if(null==r||!r.buffer)return{};var o=r.buffer.find((function(e){return e.id===t}));if(!o||e>=o.components.length)return{};var s=o.components[e],a={};return Object.keys(s).forEach((function(t){if(!t.startsWith("_")&&"entity"!==t){var e=s[t];null!=e&&(a[t]=n.formatPropertyValue(e))}})),a}catch(t){return{_error:"属性提取失败"}}},e.formatPropertyValue=function(t,e){return void 0===e&&(e=0),null==t?t:"object"!=typeof t?"string"==typeof t&&t.length>200?"[长字符串: "+t.length+"字符] "+t.substring(0,100)+"...":t:0===e?this.formatObjectFirstLevel(t):this.createLazyLoadPlaceholder(t)},e.formatObjectFirstLevel=function(t){var e=this;try{if(Array.isArray(t)){if(0===t.length)return[];if(t.length>10){var n=t.slice(0,3).map((function(t){return e.formatPropertyValue(t,1)}));return{_isLazyArray:!0,_arrayLength:t.length,_sample:n,_summary:"数组["+t.length+"个元素]"}}return t.map((function(t){return e.formatPropertyValue(t,1)}))}var i=Object.keys(t);if(0===i.length)return{};for(var r={},o=0,s=0,a=i;s<a.length;s++){var c=a[s];if(o>=15){r._hasMoreProperties=!0,r._totalProperties=i.length,r._hiddenCount=i.length-o;break}if(!c.startsWith("_")&&!c.startsWith("$")&&"function"!=typeof t[c])try{var u=t[c];null!=u&&(r[c]=this.formatPropertyValue(u,1),o++)}catch(t){r[c]="[访问失败: "+(t instanceof Error?t.message:String(t))+"]",o++}}return r}catch(t){return"[对象解析失败: "+(t instanceof Error?t.message:String(t))+"]"}},e.createLazyLoadPlaceholder=function(t){try{var e,n=(null===(e=t.constructor)||void 0===e?void 0:e.name)||"Object";return{_isLazyObject:!0,_typeName:n,_summary:this.getObjectSummary(t,n),_objectId:this.generateObjectId(t)}}catch(t){return{_isLazyObject:!0,_typeName:"Unknown",_summary:"无法分析的对象: "+(t instanceof Error?t.message:String(t)),_objectId:Math.random().toString(36).substr(2,9)}}},e.getObjectSummary=function(t,e){try{if((e.toLowerCase().includes("vec")||e.toLowerCase().includes("vector"))&&void 0!==t.x&&void 0!==t.y){var n=void 0!==t.z?t.z:"";return e+"("+t.x+", "+t.y+(n?", "+n:"")+")"}if(e.toLowerCase().includes("color")&&void 0!==t.r&&void 0!==t.g&&void 0!==t.b){var i=void 0!==t.a?t.a:1;return e+"("+t.r+", "+t.g+", "+t.b+", "+i+")"}if(e.toLowerCase().includes("node"))return e+": "+(t.name||t._name||"未命名");if(e.toLowerCase().includes("component")){var r,o,s=(null===(r=t.node)||void 0===r?void 0:r.name)||(null===(o=t.node)||void 0===o?void 0:o._name)||"";return e+(s?" on "+s:"")}var a=Object.keys(t);return 0===a.length?e+" (空对象)":e+" ("+a.length+"个属性)"}catch(t){return e+" (无法分析)"}},e.generateObjectId=function(t){try{return void 0!==t.id?"obj_"+t.id:void 0!==t._id?"obj_"+t._id:void 0!==t.uuid?"obj_"+t.uuid:void 0!==t._uuid?"obj_"+t._uuid:"obj_"+Math.random().toString(36).substr(2,9)}catch(t){return"obj_"+Math.random().toString(36).substr(2,9)}},e.expandLazyObject=function(t,e,n){try{var i=kt.scene;if(!i)return null;var r=i.entities;if(null==r||!r.buffer)return null;var o=r.buffer.find((function(e){return e.id===t}));if(!o)return null;if(e>=o.components.length)return null;var s=o.components[e],a=this.getObjectByPath(s,n);return a?this.formatObjectFirstLevel(a):null}catch(t){return{error:"展开失败: "+(t instanceof Error?t.message:String(t))}}},e.getObjectByPath=function(t,e){if(!e)return t;for(var n,i=t,r=s(e.split("."));!(n=r()).done;){var o=n.value;if(null==i)return null;if(o.includes("[")&&o.includes("]")){var a=o.substring(0,o.indexOf("[")),c=parseInt(o.substring(o.indexOf("[")+1,o.indexOf("]")));if(a&&(i=i[a]),!(Array.isArray(i)&&c>=0&&c<i.length))return null;i=i[c]}else i=i[o]}return i},t}(),xt=function(){function t(){}return t.prototype.collectSystemData=function(t){var e=kt.scene;if(!e)return{totalSystems:0,systemsInfo:[]};var n=e.entityProcessors;if(!n)return{totalSystems:0,systemsInfo:[]};var i=n.processors||[],r=new Map,o=new Map;if(t)try{r=t.getAllSystemStats(),o=t.getAllSystemData()}catch(t){}return{totalSystems:i.length,systemsInfo:i.map((function(t){var e,n=t.systemName||B(t),i=r.get(n),s=o.get(n);return{name:n,type:B(t),entityCount:(null===(e=t.entities)||void 0===e?void 0:e.length)||0,executionTime:(null==i?void 0:i.averageTime)||(null==s?void 0:s.executionTime)||0,minExecutionTime:(null==i?void 0:i.minTime)===Number.MAX_VALUE?0:(null==i?void 0:i.minTime)||0,maxExecutionTime:(null==i?void 0:i.maxTime)||0,executionTimeHistory:(null==i?void 0:i.recentTimes)||[],updateOrder:t.updateOrder||0,enabled:!1!==t.enabled,lastUpdateTime:(null==s?void 0:s.lastUpdateTime)||0}}))}},t}(),wt=function(){function t(){this.frameTimeHistory=[],this.maxHistoryLength=60,this.lastGCCount=0,this.gcCollections=0,this.lastMemoryCheck=0}var e=t.prototype;return e.collectPerformanceData=function(t){var e=g.deltaTime,n=1e3*e,i=e>0?Math.round(1/e):0,r=this.getECSPerformanceData(t),o=r.totalExecutionTime,s=n>0?o/n*100:0,a=0;performance.memory&&(a=performance.memory.usedJSHeapSize/1024/1024),this.frameTimeHistory.push(o),this.frameTimeHistory.length>this.maxHistoryLength&&this.frameTimeHistory.shift();var c=this.frameTimeHistory.filter((function(t){return t>=0}));return{frameTime:o,engineFrameTime:n,ecsPercentage:s,memoryUsage:a,fps:i,averageFrameTime:c.length>0?c.reduce((function(t,e){return t+e}),0)/c.length:o,minFrameTime:c.length>0?Math.min.apply(Math,c):o,maxFrameTime:c.length>0?Math.max.apply(Math,c):o,frameTimeHistory:[].concat(this.frameTimeHistory),systemPerformance:this.getSystemPerformance(t),systemBreakdown:r.systemBreakdown,memoryDetails:this.getMemoryDetails()}},e.getECSPerformanceData=function(t){if(!t)try{var e=kt.Instance;if(!e||!e._performanceMonitor)return{totalExecutionTime:0,systemBreakdown:[]};t=e._performanceMonitor}catch(t){return{totalExecutionTime:0,systemBreakdown:[]}}if(!t.enabled){try{t.enabled=!0}catch(t){}return{totalExecutionTime:0,systemBreakdown:[]}}try{var n=0,i=[],r=t.getAllSystemStats();if(0===r.size)return{totalExecutionTime:0,systemBreakdown:[]};for(var o,a=s(r.entries());!(o=a()).done;){var c=o.value,u=c[0],h=c[1],l=h.recentTimes&&h.recentTimes.length>0?h.recentTimes[h.recentTimes.length-1]:h.averageTime||0;n+=l,i.push({systemName:u,executionTime:l,percentage:0})}return i.forEach((function(t){t.percentage=n>0?t.executionTime/n*100:0})),i.sort((function(t,e){return e.executionTime-t.executionTime})),{totalExecutionTime:n,systemBreakdown:i}}catch(t){return{totalExecutionTime:0,systemBreakdown:[]}}},e.getSystemPerformance=function(t){if(!t)return[];try{var e=t.getAllSystemStats(),n=t.getAllSystemData();return Array.from(e.entries()).map((function(t){var e=t[0],i=t[1],r=n.get(e);return{systemName:e,averageTime:i.averageTime||0,maxTime:i.maxTime||0,minTime:i.minTime===Number.MAX_VALUE?0:i.minTime||0,samples:i.executionCount||0,percentage:0,entityCount:(null==r?void 0:r.entityCount)||0,lastExecutionTime:(null==r?void 0:r.executionTime)||0}}))}catch(t){return[]}},e.getMemoryDetails=function(){var t={entities:0,components:0,systems:0,pooled:0,totalMemory:0,usedMemory:0,freeMemory:0,gcCollections:this.updateGCCount()};try{if(performance.memory){var e=performance.memory;if(t.totalMemory=e.jsHeapSizeLimit||536870912,t.usedMemory=e.usedJSHeapSize||0,t.freeMemory=t.totalMemory-t.usedMemory,this.lastMemoryCheck>0)this.lastMemoryCheck-t.usedMemory>1048576&&this.gcCollections++;this.lastMemoryCheck=t.usedMemory}else t.totalMemory=536870912,t.freeMemory=536870912}catch(t){return{totalMemory:0,usedMemory:0,freeMemory:0,entityMemory:0,componentMemory:0,systemMemory:0,pooledMemory:0,gcCollections:this.gcCollections}}return t},e.updateGCCount=function(){try{return"undefined"!=typeof PerformanceObserver||performance.measureUserAgentSpecificMemory,this.gcCollections}catch(t){return this.gcCollections}},t}(),It=function(){function t(){}var e=t.prototype;return e.collectComponentData=function(){var t=this,e=kt.scene;if(!e)return{componentTypes:0,componentInstances:0,componentStats:[]};var n=e.entities;if(null==n||!n.buffer)return{componentTypes:0,componentInstances:0,componentStats:[]};var i=new Map,r=0;n.buffer.forEach((function(t){t.components&&t.components.forEach((function(t){var e=z(t),n=i.get(e)||{count:0,entities:0};n.count++,r++,i.set(e,n)}))}));var o=new Map,a=new Map;try{for(var c,u=V.getInstance(),h=u.getPoolStats(),l=u.getPoolUtilization(),d=s(h.entries());!(c=d()).done;){var f=c.value,p=f[0],m=f[1];a.set(p,m.maxSize)}for(var y,g=s(l.entries());!(y=g()).done;){var v=y.value,_=v[0],E=v[1];o.set(_,E.utilization)}}catch(t){}return{componentTypes:i.size,componentInstances:r,componentStats:Array.from(i.entries()).map((function(e){var i=e[0],r=e[1],s=a.get(i)||0,c=o.get(i)||0,u=t.getEstimatedComponentSize(i);return{typeName:i,instanceCount:r.count,memoryPerInstance:u,totalMemory:r.count*u,poolSize:s,poolUtilization:c,averagePerEntity:r.count/n.buffer.length}}))}},e.getEstimatedComponentSize=function(e){if(t.componentSizeCache.has(e))return t.componentSizeCache.get(e);var n=kt.scene;if(!n)return 64;var i=n.entities;if(null==i||!i.buffer)return 64;var r=64;try{for(var o,a=s(i.buffer);!(o=a()).done;){var c=o.value;if(c.components){var u=c.components.find((function(t){return z(t)===e}));if(u){r=this.calculateQuickObjectSize(u);break}}}}catch(t){r=64}return t.componentSizeCache.set(e,r),r},e.calculateQuickObjectSize=function(t){if(!t||"object"!=typeof t)return 8;var e=32,n=new WeakSet,i=function(t,e){if(void 0===e&&(e=0),!t||"object"!=typeof t||n.has(t)||e>3)return 0;n.add(t);var r=0;try{for(var o=Object.keys(t),s=0;s<Math.min(o.length,20);s++){var a=o[s];if("entity"!==a&&"_entity"!==a&&"constructor"!==a){var c=t[a];r+=2*a.length,"string"==typeof c?r+=Math.min(2*c.length,200):"number"==typeof c?r+=8:"boolean"==typeof c?r+=4:"object"==typeof c&&null!==c&&(r+=i(c,e+1))}}}catch(t){return 32}return r};return e+=i(t),Math.max(e,32)},e.calculateDetailedComponentMemory=function(t){var e=kt.scene;if(!e)return this.getEstimatedComponentSize(t);var n=e.entities;if(null==n||!n.buffer)return this.getEstimatedComponentSize(t);try{for(var i,r=s(n.buffer);!(i=r()).done;){var o=i.value;if(o.components){var a=o.components.find((function(e){return z(e)===t}));if(a)return this.estimateObjectSize(a)}}}catch(t){}return this.getEstimatedComponentSize(t)},e.estimateObjectSize=function(t,e,n){if(void 0===e&&(e=new WeakSet),void 0===n&&(n=0),null==t||n>10)return 0;if(e.has(t))return 0;var i=0;switch(typeof t){case"boolean":i=4;break;case"number":default:i=8;break;case"string":i=24+Math.min(2*t.length,1e3);break;case"object":if(e.add(t),Array.isArray(t)){i=40+8*t.length;for(var r=Math.min(t.length,50),o=0;o<r;o++)i+=this.estimateObjectSize(t[o],e,n+1)}else{i=32;try{for(var s=Object.getOwnPropertyNames(t),a=Math.min(s.length,30),c=0;c<a;c++){var u=s[c];if("constructor"!==u&&"__proto__"!==u&&"entity"!==u&&"_entity"!==u&&!u.startsWith("_cc_")&&!u.startsWith("__"))try{i+=16+2*u.length;var h=t[u];null!=h&&(i+=this.estimateObjectSize(h,e,n+1))}catch(t){continue}}}catch(t){i=128}}}return 8*Math.ceil(i/8)},t.clearCache=function(){t.componentSizeCache.clear()},t}();It.componentSizeCache=new Map;var At=function(){function t(){this.sceneStartTime=Date.now()}var e=t.prototype;return e.collectSceneData=function(){var t,e,n=kt.scene;if(!n)return{currentSceneName:"No Scene",isInitialized:!1,sceneRunTime:0,sceneEntityCount:0,sceneSystemCount:0,sceneMemory:0,sceneUptime:0};var i=(Date.now()-this.sceneStartTime)/1e3,r=n.entities,o=n.entityProcessors;return{currentSceneName:n.name||"Unnamed Scene",isInitialized:n._didSceneBegin||!1,sceneRunTime:i,sceneEntityCount:(null==r||null===(t=r.buffer)||void 0===t?void 0:t.length)||0,sceneSystemCount:(null==o||null===(e=o.processors)||void 0===e?void 0:e.length)||0,sceneMemory:0,sceneUptime:i}},e.setSceneStartTime=function(t){this.sceneStartTime=t},t}(),Dt=function(){function t(t,e){void 0===e&&(e=!0),this.isConnected=!1,this.reconnectAttempts=0,this.maxReconnectAttempts=5,this.reconnectInterval=2e3,this.url=t,this.autoReconnect=e}var e=t.prototype;return e.setMessageHandler=function(t){this.messageHandler=t},e.connect=function(){var t=this;return new Promise((function(e,n){try{t.ws=new WebSocket(t.url),t.ws.onopen=function(n){t.handleOpen(n),e()},t.ws.onclose=function(e){t.handleClose(e)},t.ws.onerror=function(e){t.handleError(e),n(e)},t.ws.onmessage=function(e){t.handleMessage(e)}}catch(e){t.handleConnectionFailure(e),n(e)}}))},e.disconnect=function(){this.ws&&(this.autoReconnect=!1,this.ws.close(),this.ws=void 0),this.isConnected=!1},e.send=function(t){if(this.isConnected&&this.ws)try{var e="string"==typeof t?t:JSON.stringify(t);this.ws.send(e)}catch(t){}},e.getConnectionStatus=function(){return this.isConnected},e.setMaxReconnectAttempts=function(t){this.maxReconnectAttempts=t},e.setReconnectInterval=function(t){this.reconnectInterval=t},e.scheduleReconnect=function(){var t=this;this.reconnectTimer&&clearTimeout(this.reconnectTimer);var e=Math.min(1e3*Math.pow(2,this.reconnectAttempts),3e4);this.reconnectAttempts++,this.reconnectTimer=setTimeout((function(){t.connect().catch((function(e){t.reconnectAttempts<t.maxReconnectAttempts&&t.scheduleReconnect()}))}),e)},e.handleMessage=function(t){try{var e=JSON.parse(t.data);this.messageHandler&&this.messageHandler(e)}catch(t){}},e.handleOpen=function(t){this.isConnected=!0,this.reconnectAttempts=0,this.onOpen&&this.onOpen(t)},e.handleClose=function(t){this.isConnected=!1,this.onClose&&this.onClose(t),this.autoReconnect&&this.reconnectAttempts<this.maxReconnectAttempts&&this.scheduleReconnect()},e.handleError=function(t){this.onError&&this.onError(t)},e.handleConnectionFailure=function(t){this.onError&&this.onError(t)},t}(),Ot=function(){function t(t,e){this.frameCounter=0,this.lastSendTime=0,this.isRunning=!1,this.config=e,this.entityCollector=new Mt,this.systemCollector=new xt,this.performanceCollector=new wt,this.componentCollector=new It,this.sceneCollector=new At,this.webSocketManager=new Dt(e.websocketUrl,!1!==e.autoReconnect),this.webSocketManager.setMessageHandler(this.handleMessage.bind(this));var n=e.debugFrameRate||30;this.sendInterval=1e3/n,this.start()}var e=t.prototype;return e.start=function(){this.isRunning||(this.isRunning=!0,this.connectWebSocket())},e.stop=function(){this.isRunning&&(this.isRunning=!1,this.webSocketManager.disconnect())},e.updateConfig=function(t){this.config=t;var e=t.debugFrameRate||30;this.sendInterval=1e3/e,this.webSocketManager&&t.websocketUrl&&(this.webSocketManager.disconnect(),this.webSocketManager=new Dt(t.websocketUrl,!1!==t.autoReconnect),this.webSocketManager.setMessageHandler(this.handleMessage.bind(this)),this.connectWebSocket())},e.onFrameUpdate=function(t){if(this.isRunning&&this.config.enabled){this.frameCounter++;var e=Date.now();e-this.lastSendTime>=this.sendInterval&&(this.sendDebugData(),this.lastSendTime=e)}},e.onSceneChanged=function(){this.isRunning&&this.config.enabled&&this.sendDebugData()},e.handleMessage=function(t){try{switch(t.type){case"capture_memory_snapshot":this.handleMemorySnapshotRequest();break;case"config_update":t.config&&this.updateConfig(a({},this.config,t.config));break;case"expand_lazy_object":this.handleExpandLazyObjectRequest(t);break;case"get_component_properties":this.handleGetComponentPropertiesRequest(t);break;case"get_raw_entity_list":this.handleGetRawEntityListRequest(t);break;case"get_entity_details":this.handleGetEntityDetailsRequest(t);break;case"ping":this.webSocketManager.send({type:"pong",timestamp:Date.now()})}}catch(e){t.requestId&&this.webSocketManager.send({type:"error_response",requestId:t.requestId,error:e instanceof Error?e.message:String(e)})}},e.handleExpandLazyObjectRequest=function(t){try{var e=t.entityId,n=t.componentIndex,i=t.propertyPath,r=t.requestId;if(void 0===e||void 0===n||!i)return void this.webSocketManager.send({type:"expand_lazy_object_response",requestId:r,error:"缺少必要参数"});var o=this.entityCollector.expandLazyObject(e,n,i);this.webSocketManager.send({type:"expand_lazy_object_response",requestId:r,data:o})}catch(e){this.webSocketManager.send({type:"expand_lazy_object_response",requestId:t.requestId,error:e instanceof Error?e.message:String(e)})}},e.handleGetComponentPropertiesRequest=function(t){try{var e=t.entityId,n=t.componentIndex,i=t.requestId;if(void 0===e||void 0===n)return void this.webSocketManager.send({type:"get_component_properties_response",requestId:i,error:"缺少必要参数"});var r=this.entityCollector.getComponentProperties(e,n);this.webSocketManager.send({type:"get_component_properties_response",requestId:i,data:r})}catch(e){this.webSocketManager.send({type:"get_component_properties_response",requestId:t.requestId,error:e instanceof Error?e.message:String(e)})}},e.handleGetRawEntityListRequest=function(t){try{var e=t.requestId,n=this.entityCollector.getRawEntityList();this.webSocketManager.send({type:"get_raw_entity_list_response",requestId:e,data:n})}catch(e){this.webSocketManager.send({type:"get_raw_entity_list_response",requestId:t.requestId,error:e instanceof Error?e.message:String(e)})}},e.handleGetEntityDetailsRequest=function(t){try{var e=t.entityId,n=t.requestId;if(void 0===e)return void this.webSocketManager.send({type:"get_entity_details_response",requestId:n,error:"缺少实体ID参数"});var i=this.entityCollector.getEntityDetails(e);this.webSocketManager.send({type:"get_entity_details_response",requestId:n,data:i})}catch(e){this.webSocketManager.send({type:"get_entity_details_response",requestId:t.requestId,error:e instanceof Error?e.message:String(e)})}},e.handleMemorySnapshotRequest=function(){try{var t=this.captureMemorySnapshot();this.webSocketManager.send({type:"memory_snapshot_response",data:t})}catch(t){this.webSocketManager.send({type:"memory_snapshot_error",error:t instanceof Error?t.message:"内存快照捕获失败"})}},e.captureMemorySnapshot=function(){var t=Date.now(),e=this.entityCollector.collectEntityDataWithMemory(),n=this.collectBaseMemoryInfo(),i=kt.scene,r=null!=i&&i.entities?this.collectComponentMemoryStats(i.entities):{totalMemory:0,componentTypes:0,totalInstances:0,breakdown:[]},o=this.collectSystemMemoryStats(),s=this.collectPoolMemoryStats(),a=this.collectPerformanceStats(),c=e.entitiesPerArchetype.reduce((function(t,e){return t+e.memory}),0);return{timestamp:t,version:"2.0",summary:{totalEntities:e.totalEntities,totalMemoryUsage:n.usedMemory,totalMemoryLimit:n.totalMemory,memoryUtilization:n.usedMemory/n.totalMemory*100,gcCollections:n.gcCollections,entityMemory:c,componentMemory:r.totalMemory,systemMemory:o.totalMemory,poolMemory:s.totalMemory},baseMemory:n,entities:{totalMemory:c,entityCount:e.totalEntities,archetypes:e.entitiesPerArchetype,largestEntities:e.topEntitiesByComponents},components:r,systems:o,pools:s,performance:a}},e.collectBaseMemoryInfo=function(){var t={totalMemory:0,usedMemory:0,freeMemory:0,gcCollections:0,heapInfo:null,detailedMemory:void 0};try{var e=performance;if(e.memory){var n=e.memory;t.totalMemory=n.jsHeapSizeLimit||536870912,t.usedMemory=n.usedJSHeapSize||0,t.freeMemory=t.totalMemory-t.usedMemory,t.heapInfo={totalJSHeapSize:n.totalJSHeapSize||0,usedJSHeapSize:n.usedJSHeapSize||0,jsHeapSizeLimit:n.jsHeapSizeLimit||0}}else t.totalMemory=536870912,t.freeMemory=536870912;e.measureUserAgentSpecificMemory&&e.measureUserAgentSpecificMemory().then((function(e){t.detailedMemory=e})).catch((function(){}))}catch(t){}return t},e.collectComponentMemoryStats=function(t){for(var e,n=new Map,i=0,r=new Map,o=s(t.buffer);!(e=o()).done;){var a=e.value;if(a&&!a.destroyed&&a.components)for(var c,u=s(a.components);!(c=u()).done;){var h=z(c.value);r.set(h,(r.get(h)||0)+1)}}for(var l,d=s(r.entries());!(l=d()).done;){var f=l.value,p=f[0],m=f[1],y=this.componentCollector.calculateDetailedComponentMemory(p),g=y*m;i+=g;for(var v,_=[],E=0,S=s(t.buffer);!(v=S()).done;){var T=v.value;if(T&&!T.destroyed&&T.components){for(var C,b=s(T.components);!(C=b()).done;){if(z(C.value)===p&&(_.push({entityId:T.id,entityName:T.name||"Entity_"+T.id,memory:y}),++E>=100))break}if(E>=100)break}}n.set(p,{count:m,totalMemory:g,instances:_.slice(0,10)})}var M=Array.from(n.entries()).map((function(t){var e=t[0],n=t[1];return{typeName:e,instanceCount:n.count,totalMemory:n.totalMemory,averageMemory:n.totalMemory/n.count,percentage:i>0?n.totalMemory/i*100:0,largestInstances:n.instances.sort((function(t,e){return e.memory-t.memory})).slice(0,3)}})).sort((function(t,e){return e.totalMemory-t.totalMemory}));return{totalMemory:i,componentTypes:n.size,totalInstances:Array.from(n.values()).reduce((function(t,e){return t+e.count}),0),breakdown:M}},e.collectSystemMemoryStats=function(){var t=kt.scene,e=0,n=[];try{var i=null==t?void 0:t.entityProcessors;if(i&&i.processors)for(var r,o=new Map,a=s(i.processors);!(r=a()).done;){var c=r.value,u=B(c),h=void 0;o.has(u)?h=o.get(u):(h=this.calculateQuickSystemSize(c),o.set(u,h)),e+=h,n.push({name:u,memory:h,enabled:!1!==c.enabled,updateOrder:c.updateOrder||0})}}catch(t){}return{totalMemory:e,systemCount:n.length,breakdown:n.sort((function(t,e){return e.memory-t.memory}))}},e.calculateQuickSystemSize=function(t){if(!t||"object"!=typeof t)return 64;var e=128;try{for(var n=Object.keys(t),i=0;i<Math.min(n.length,15);i++){var r=n[i];if("entities"!==r&&"scene"!==r&&"constructor"!==r){var o=t[r];e+=2*r.length,"string"==typeof o?e+=Math.min(2*o.length,100):"number"==typeof o?e+=8:"boolean"==typeof o?e+=4:Array.isArray(o)?e+=40+Math.min(8*o.length,200):"object"==typeof o&&null!==o&&(e+=64)}}}catch(t){return 128}return Math.max(e,64)},e.collectPoolMemoryStats=function(){var t=0,e=[];try{for(var n,i=s(V.getInstance().getPoolStats().entries());!(n=i()).done;){var r=n.value,o=r[0],a=r[1],c=32*a.maxSize;t+=c,e.push({typeName:o,maxSize:a.maxSize,currentSize:a.currentSize||0,estimatedMemory:c,utilization:a.currentSize?a.currentSize/a.maxSize*100:0})}}catch(t){}try{for(var u=T.getAllPoolStats(),h=0,l=Object.entries(u);h<l.length;h++){var d=l[h],f=d[0],p=d[1];t+=p.estimatedMemoryUsage,e.push({typeName:"Pool_"+f,maxSize:p.maxSize,currentSize:p.size,estimatedMemory:p.estimatedMemoryUsage,utilization:p.size/p.maxSize*100,hitRate:100*p.hitRate})}}catch(t){}return{totalMemory:t,poolCount:e.length,breakdown:e.sort((function(t,e){return e.estimatedMemory-t.estimatedMemory}))}},e.collectPerformanceStats=function(){try{var t,e=kt.Instance._performanceMonitor;if(!e)return{enabled:!1};var n=e.getAllSystemStats(),i=e.getPerformanceWarnings();return{enabled:null!==(t=e.enabled)&&void 0!==t&&t,systemCount:n.size,warnings:i.slice(0,10),topSystems:Array.from(n.entries()).map((function(t){var e=t[0],n=t[1];return{name:e,averageTime:n.averageTime,maxTime:n.maxTime,samples:n.executionCount}})).sort((function(t,e){return e.averageTime-t.averageTime})).slice(0,5)}}catch(t){return{enabled:!1,error:t instanceof Error?t.message:String(t)}}},e.getDebugData=function(){var t=Date.now(),e=kt.scene,n={timestamp:t,frameworkVersion:"1.0.0",isRunning:this.isRunning,frameworkLoaded:!0,currentScene:(null==e?void 0:e.name)||"Unknown"};if(this.config.channels.entities&&(n.entities=this.entityCollector.collectEntityData()),this.config.channels.systems){var i=kt.Instance._performanceMonitor;n.systems=this.systemCollector.collectSystemData(i)}if(this.config.channels.performance){var r=kt.Instance._performanceMonitor;n.performance=this.performanceCollector.collectPerformanceData(r)}return this.config.channels.components&&(n.components=this.componentCollector.collectComponentData()),this.config.channels.scenes&&(n.scenes=this.sceneCollector.collectSceneData()),n},e.connectWebSocket=function(){var t=n(l().m((function t(){return l().w((function(t){for(;;)switch(t.p=t.n){case 0:return t.p=0,t.n=1,this.webSocketManager.connect();case 1:t.n=3;break;case 2:t.p=2,t.v;case 3:return t.a(2)}}),t,this,[[0,2]])})));return function(){return t.apply(this,arguments)}}(),e.sendDebugData=function(){if(this.webSocketManager.getConnectionStatus())try{var t={type:"debug_data",data:this.getDebugData()};this.webSocketManager.send(t)}catch(t){}},t}(),kt=function(){function t(e){var n,i,r;void 0===e&&(e={}),this._globalManagers=[],t._instance=this,this._config=a({debug:!0,enableEntitySystems:!0},e),this._timerManager=new E,t.registerGlobalManager(this._timerManager),this._performanceMonitor=S.instance,this._config.debug&&this._performanceMonitor.enable(),this._poolManager=b.getInstance(),t.entitySystemsEnabled=null===(n=this._config.enableEntitySystems)||void 0===n||n,this.debug=null===(i=this._config.debug)||void 0===i||i,null!==(r=this._config.debugConfig)&&void 0!==r&&r.enabled&&(this._debugManager=new Ot(this,this._config.debugConfig)),this.initialize()}t.getScene=function(){if(!this._instance)return null;this._instance.ensureDefaultWorld();var t=this._instance._worldManager.getWorld(this.DEFAULT_WORLD_ID);return(null==t?void 0:t.getScene(this.DEFAULT_SCENE_ID))||null},t.setScene=function(t){if(!this._instance)throw new Error("Core实例未创建,请先调用Core.create()");this._instance.ensureDefaultWorld();var e=this._instance._worldManager.getWorld(this.DEFAULT_WORLD_ID);return e.getScene(this.DEFAULT_SCENE_ID)&&e.removeScene(this.DEFAULT_SCENE_ID),e.createScene(this.DEFAULT_SCENE_ID,t),e.setSceneActive(this.DEFAULT_SCENE_ID,!0),this._instance.onSceneChanged(),t},t.create=function(e){if(void 0===e&&(e=!0),null==this._instance){var n="boolean"==typeof e?{debug:e,enableEntitySystems:!0}:e;this._instance=new t(n)}return this._instance},t.update=function(e){this._instance?this._instance.updateInternal(e):t._logger.warn("Core实例未创建,请先调用Core.create()")},t.registerGlobalManager=function(t){this._instance._globalManagers.push(t),t.enabled=!0},t.unregisterGlobalManager=function(t){this._instance._globalManagers.splice(this._instance._globalManagers.indexOf(t),1),t.enabled=!1},t.getGlobalManager=function(t){for(var e,n=s(this._instance._globalManagers);!(e=n()).done;){var i=e.value;if(i instanceof t)return i}return null},t.schedule=function(t,e,n,i){if(void 0===e&&(e=!1),!i)throw new Error("onTime callback is required");return this._instance._timerManager.schedule(t,e,n,i)},t.enableDebug=function(e){this._instance?(this._instance._debugManager?this._instance._debugManager.updateConfig(e):this._instance._debugManager=new Ot(this._instance,e),this._instance._config.debugConfig=e):t._logger.warn("Core实例未创建,请先调用Core.create()")},t.disableDebug=function(){this._instance&&(this._instance._debugManager&&(this._instance._debugManager.stop(),this._instance._debugManager=void 0),this._instance._config.debugConfig&&(this._instance._config.debugConfig.enabled=!1))},t.getDebugData=function(){var t;return null!==(t=this._instance)&&void 0!==t&&t._debugManager?this._instance._debugManager.getDebugData():null},t.getWorldManager=function(){if(!this._instance)throw new Error("Core实例未创建,请先调用Core.create()");return this._instance._worldManager||(this._instance._worldManager=Tt.getInstance({maxWorlds:50,autoCleanup:!0,cleanupInterval:6e4,debug:this._instance._config.debug})),this._instance._worldManager},t.enableWorldManager=function(){return this.getWorldManager()};var e=t.prototype;return e.ensureDefaultWorld=function(){this._worldManager||(this._worldManager=Tt.getInstance({maxWorlds:1,autoCleanup:!1,cleanupInterval:0,debug:this._config.debug})),this._worldManager.getWorld(t.DEFAULT_WORLD_ID)||(this._worldManager.createWorld(t.DEFAULT_WORLD_ID,{name:"DefaultWorld",maxScenes:1,autoCleanup:!1}),this._worldManager.setWorldActive(t.DEFAULT_WORLD_ID,!0))},e.onSceneChanged=function(){var e=this;g.sceneChanged();var n=t.getScene();n&&n.querySystem&&n.eventSystem&&(this._ecsAPI=vt(n,n.querySystem,n.eventSystem)),this._debugManager&&queueMicrotask((function(){var t;null===(t=e._debugManager)||void 0===t||t.onSceneChanged()}))},e.initialize=function(){},e.updateInternal=function(e){if(!t.paused){var n=this._performanceMonitor.startMonitoring("Core.update");g.update(e),"updateFPS"in this._performanceMonitor&&"function"==typeof this._performanceMonitor.updateFPS&&this._performanceMonitor.updateFPS(g.deltaTime);for(var i,r=this._performanceMonitor.startMonitoring("GlobalManagers.update"),o=s(this._globalManagers);!(i=o()).done;){var a=i.value;a.enabled&&a.update()}if(this._performanceMonitor.endMonitoring("GlobalManagers.update",r,this._globalManagers.length),this._poolManager.update(),this._worldManager){for(var c,u=this._performanceMonitor.startMonitoring("Worlds.update"),h=0,l=s(this._worldManager.getActiveWorlds());!(c=l()).done;){var d=c.value;d.updateGlobalSystems(),d.updateScenes(),h+=d.getStats().totalEntities}this._performanceMonitor.endMonitoring("Worlds.update",u,h)}this._debugManager&&this._debugManager.onFrameUpdate(e),this._performanceMonitor.endMonitoring("Core.update",n)}},o(t,null,[{key:"Instance",get:function(){return this._instance}},{key:"scene",get:function(){return this.getScene()}},{key:"ecsAPI",get:function(){var t;return(null===(t=this._instance)||void 0===t?void 0:t._ecsAPI)||null}},{key:"isDebugEnabled",get:function(){var t;return(null===(t=this._instance)||void 0===t||null===(t=t._config.debugConfig)||void 0===t?void 0:t.enabled)||!1}}])}();kt.paused=!1,kt.DEFAULT_WORLD_ID="__default__",kt.DEFAULT_SCENE_ID="__main__",kt._logger=D("Core");var Nt=function(t,e){this.func=t,this.context=e},Pt=function(){function t(){this._messageTable=new Map}var e=t.prototype;return e.addObserver=function(t,e,n){var i=this._messageTable.get(t);i||(i=[],this._messageTable.set(t,i)),this.hasObserver(t,e)||i.push(new Nt(e,n))},e.removeObserver=function(t,e){var n=this._messageTable.get(t);if(n){var i=n.findIndex((function(t){return t.func==e}));-1!=i&&n.splice(i,1)}},e.emit=function(t){var e=this._messageTable.get(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];for(var o,a=s(e);!(o=a()).done;){var c,u=o.value;(c=u.func).call.apply(c,[u.context].concat(i))}}},e.hasObserver=function(t,e){var n=this._messageTable.get(t);return!!n&&n.some((function(t){return t.func===e}))},e.removeAllObservers=function(t){void 0!==t?this._messageTable.delete(t):this._messageTable.clear()},e.dispose=function(){this._messageTable.clear()},e.getEventTypeCount=function(){return this._messageTable.size},e.getObserverCount=function(t){var e=this._messageTable.get(t);return e?e.length:0},t}(),Rt=function(){function t(){this._enabled=!0,this._updateOrder=0,this.id=t._idGenerator++}var e=t.prototype;return e.onAddedToEntity=function(){},e.onRemovedFromEntity=function(){},e.onEnabled=function(){},e.onDisabled=function(){},e.update=function(){},o(t,[{key:"enabled",get:function(){return this.entity?this.entity.enabled&&this._enabled:this._enabled},set:function(t){this._enabled!==t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled())}},{key:"updateOrder",get:function(){return this._updateOrder},set:function(t){this._updateOrder=t}}])}();Rt._idGenerator=0;var zt=function(){function t(){this.condition={all:[],any:[],none:[]}}t.all=function(){var e=new t;return e.all.apply(e,arguments)},t.any=function(){var e=new t;return e.any.apply(e,arguments)},t.none=function(){var e=new t;return e.none.apply(e,arguments)},t.byTag=function(e){return(new t).withTag(e)},t.byName=function(e){return(new t).withName(e)},t.byComponent=function(e){return(new t).withComponent(e)},t.complex=function(){return new t},t.empty=function(){return new t};var e=t.prototype;return e.all=function(){var t;return(t=this.condition.all).push.apply(t,arguments),this},e.any=function(){var t;return(t=this.condition.any).push.apply(t,arguments),this},e.none=function(){var t;return(t=this.condition.none).push.apply(t,arguments),this},e.exclude=function(){return this.none.apply(this,arguments)},e.one=function(){return this.any.apply(this,arguments)},e.withTag=function(t){return this.condition.tag=t,this},e.withName=function(t){return this.condition.name=t,this},e.withComponent=function(t){return this.condition.component=t,this},e.withoutTag=function(){return delete this.condition.tag,this},e.withoutName=function(){return delete this.condition.name,this},e.withoutComponent=function(){return delete this.condition.component,this},e.getCondition=function(){return{all:[].concat(this.condition.all),any:[].concat(this.condition.any),none:[].concat(this.condition.none),tag:this.condition.tag,name:this.condition.name,component:this.condition.component}},e.isEmpty=function(){return 0===this.condition.all.length&&0===this.condition.any.length&&0===this.condition.none.length&&void 0===this.condition.tag&&void 0===this.condition.name&&void 0===this.condition.component},e.reset=function(){return this.condition.all.length=0,this.condition.any.length=0,this.condition.none.length=0,delete this.condition.tag,delete this.condition.name,delete this.condition.component,this},e.clone=function(){var e,n,i,r=new t;return(e=r.condition.all).push.apply(e,this.condition.all),(n=r.condition.any).push.apply(n,this.condition.any),(i=r.condition.none).push.apply(i,this.condition.none),void 0!==this.condition.tag&&(r.condition.tag=this.condition.tag),void 0!==this.condition.name&&(r.condition.name=this.condition.name),void 0!==this.condition.component&&(r.condition.component=this.condition.component),r},e.toString=function(){var t=[];return this.condition.all.length>0&&t.push("all("+this.condition.all.map((function(t){return P(t)})).join(", ")+")"),this.condition.any.length>0&&t.push("any("+this.condition.any.map((function(t){return P(t)})).join(", ")+")"),this.condition.none.length>0&&t.push("none("+this.condition.none.map((function(t){return P(t)})).join(", ")+")"),void 0!==this.condition.tag&&t.push("tag("+this.condition.tag+")"),void 0!==this.condition.name&&t.push("name("+this.condition.name+")"),void 0!==this.condition.component&&t.push("component("+P(this.condition.component)+")"),"Matcher["+t.join(" & ")+"]"},t}(),Bt=function(){function t(t){this._updateOrder=0,this._enabled=!0,this._performanceMonitor=S.instance,this._initialized=!1,this._trackedEntities=new Set,this._scene=null,this._matcher=t||zt.empty(),this._systemName=B(this)}var e=t.prototype;return e.setUpdateOrder=function(t){this._updateOrder=t,this.scene&&this.scene.entityProcessors&&this.scene.entityProcessors.setDirty()},e.initialize=function(){this._initialized||(this._initialized=!0,this.scene&&this.queryEntities(),this.onInitialize())},e.onInitialize=function(){},e.reset=function(){this._initialized=!1,this._trackedEntities.clear()},e.queryEntities=function(){var t;if(null===(t=this.scene)||void 0===t||!t.querySystem||!this._matcher)return[];var e=this._matcher.getCondition(),n=this.scene.querySystem,i=[];return i=this._matcher.isEmpty()?n.getAllEntities():this.isSingleCondition(e)?this.executeSingleConditionQuery(e,n):this.executeComplexQuery(e,n),this.updateEntityTracking(i),i},e.isSingleCondition=function(t){return 1===(t.all.length>0?1:0)+(t.any.length>0?1:0)+(t.none.length>0?1:0)+(void 0!==t.tag?1:0)+(void 0!==t.name?1:0)+(void 0!==t.component?1:0)},e.executeSingleConditionQuery=function(t,e){return void 0!==t.tag?e.queryByTag(t.tag).entities:void 0!==t.name?e.queryByName(t.name).entities:void 0!==t.component?e.queryByComponent(t.component).entities:t.all.length>0&&0===t.any.length&&0===t.none.length?e.queryAll.apply(e,t.all).entities:0===t.all.length&&t.any.length>0&&0===t.none.length?e.queryAny.apply(e,t.any).entities:0===t.all.length&&0===t.any.length&&t.none.length>0?e.queryNone.apply(e,t.none).entities:[]},e.executeComplexQueryWithIdSets=function(t,e){var n=null;if(void 0!==t.tag){var i=e.queryByTag(t.tag);n=this.extractEntityIds(i.entities)}if(void 0!==t.name){var r=this.extractEntityIds(e.queryByName(t.name).entities);n=n?this.intersectIdSets(n,r):r}if(void 0!==t.component){var o=this.extractEntityIds(e.queryByComponent(t.component).entities);n=n?this.intersectIdSets(n,o):o}if(t.all.length>0){var s=this.extractEntityIds(e.queryAll.apply(e,t.all).entities);n=n?this.intersectIdSets(n,s):s}if(t.any.length>0){var a=this.extractEntityIds(e.queryAny.apply(e,t.any).entities);n=n?this.intersectIdSets(n,a):a}if(t.none.length>0){n||(n=this.extractEntityIds(e.getAllEntities()));var c=e.queryAny.apply(e,t.none),u=this.extractEntityIds(c.entities);n=this.differenceIdSets(n,u)}return n?this.idSetToEntityArray(n,e.getAllEntities()):[]},e.extractEntityIds=function(t){for(var e=new Set,n=0;n<t.length;n++)e.add(t[n].id);return e},e.intersectIdSets=function(t,e){for(var n,i=t.size<=e.size?[t,e]:[e,t],r=i[0],o=i[1],a=new Set,c=s(r);!(n=c()).done;){var u=n.value;o.has(u)&&a.add(u)}return a},e.differenceIdSets=function(t,e){for(var n,i=new Set,r=s(t);!(n=r()).done;){var o=n.value;e.has(o)||i.add(o)}return i},e.idSetToEntityArray=function(t,e){for(var n,i=new Map,r=s(e);!(n=r()).done;){var o=n.value;i.set(o.id,o)}for(var a,c=[],u=s(t);!(a=u()).done;){var h=a.value,l=i.get(h);l&&c.push(l)}return c},e.executeComplexQuery=function(t,e){return this.executeComplexQueryWithIdSets(t,e)},e.update=function(){if(this._enabled&&this.onCheckProcessing()){var t=this._performanceMonitor.startMonitoring(this._systemName),e=0;try{this.onBegin();var n=this.queryEntities();e=n.length,this.process(n)}finally{this._performanceMonitor.endMonitoring(this._systemName,t,e)}}},e.lateUpdate=function(){if(this._enabled&&this.onCheckProcessing()){var t=this._performanceMonitor.startMonitoring(this._systemName+"_Late"),e=0;try{var n=this.queryEntities();e=n.length,this.lateProcess(n),this.onEnd()}finally{this._performanceMonitor.endMonitoring(this._systemName+"_Late",t,e)}}},e.onBegin=function(){},e.process=function(t){},e.lateProcess=function(t){},e.onEnd=function(){},e.onCheckProcessing=function(){return!0},e.getPerformanceData=function(){return this._performanceMonitor.getSystemData(this._systemName)},e.getPerformanceStats=function(){return this._performanceMonitor.getSystemStats(this._systemName)},e.resetPerformanceData=function(){this._performanceMonitor.resetSystem(this._systemName)},e.toString=function(){var t=this.entities.length,e=this.getPerformanceData(),n=e?" ("+e.executionTime.toFixed(2)+"ms)":"";return this._systemName+"["+t+" entities]"+n},e.updateEntityTracking=function(t){for(var e,n=new Set(t),i=s(t);!(e=i()).done;){var r=e.value;this._trackedEntities.has(r)||(this._trackedEntities.add(r),this.onAdded(r))}for(var o,a=s(this._trackedEntities);!(o=a()).done;){var c=o.value;n.has(c)||(this._trackedEntities.delete(c),this.onRemoved(c))}},e.onAdded=function(t){},e.onRemoved=function(t){},o(t,[{key:"entities",get:function(){return this.queryEntities()}},{key:"updateOrder",get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)}},{key:"enabled",get:function(){return this._enabled},set:function(t){this._enabled=t}},{key:"systemName",get:function(){return this._systemName}},{key:"scene",get:function(){return this._scene},set:function(t){this._scene=t}},{key:"matcher",get:function(){return this._matcher}}])}(),Ft=function(t){function e(e){return t.call(this,e)||this}return u(e,t),e.prototype.process=function(t){this.processSystem()},e}(Bt),Lt=function(t){function e(e){return t.call(this,e)||this}return u(e,t),e.prototype.process=function(t){},e}(Bt),qt=function(t){function e(e,n){var i;return(i=t.call(this,n)||this).acc=0,i.intervalRemainder=0,i.interval=e,i}u(e,t);var n=e.prototype;return n.onCheckProcessing=function(){return this.acc+=g.deltaTime,this.acc>=this.interval&&(this.intervalRemainder=this.acc-this.interval,this.acc=0,!0)},n.getIntervalDelta=function(){return this.interval+this.intervalRemainder},e}(Bt),Wt=function(){function t(t){this.entityManager=t,this._allComponents=[],this._anyComponents=[],this._withoutComponents=[],this._withTags=[],this._withoutTags=[],this._activeOnly=!1,this._enabledOnly=!1,this._customPredicates=[]}var e=t.prototype;return e.withAll=function(){var t;return(t=this._allComponents).push.apply(t,arguments),this},e.withAny=function(){var t;return(t=this._anyComponents).push.apply(t,arguments),this},e.without=function(){var t;return(t=this._withoutComponents).push.apply(t,arguments),this},e.withTag=function(t){return this._withTags.push(t),this},e.withoutTag=function(t){return this._withoutTags.push(t),this},e.active=function(){return this._activeOnly=!0,this},e.enabled=function(){return this._enabledOnly=!0,this},e.where=function(t){return this._customPredicates.push(t),this},e.execute=function(){var t=this,e=[];if(this._allComponents.length>0){var n=this.entityManager.queryWithComponentIndex(this._allComponents,"AND");e=Array.from(n)}else if(this._anyComponents.length>0){var i=this.entityManager.queryWithComponentIndex(this._anyComponents,"OR");e=Array.from(i)}else e=this.entityManager.getAllEntities();return e.filter((function(e){return t.matchesEntity(e)}))},e.first=function(){var t=this;return this.entityManager.getAllEntities().find((function(e){return t.matchesEntity(e)}))||null},e.count=function(){var t=this;return this.entityManager.getAllEntities().filter((function(e){return t.matchesEntity(e)})).length},e.forEach=function(t){var e=this;this.entityManager.getAllEntities().forEach((function(n){e.matchesEntity(n)&&t(n)}))},e.matchesEntity=function(t){if(this._activeOnly&&!t.active)return!1;if(this._enabledOnly&&!t.enabled)return!1;if(this._allComponents.length>0)for(var e,n=s(this._allComponents);!(e=n()).done;){var i=e.value;if(!t.hasComponent(i))return!1}if(this._anyComponents.length>0){for(var r,o=!1,a=s(this._anyComponents);!(r=a()).done;){var c=r.value;if(t.hasComponent(c)){o=!0;break}}if(!o)return!1}if(this._withoutComponents.length>0)for(var u,h=s(this._withoutComponents);!(u=h()).done;){var l=u.value;if(t.hasComponent(l))return!1}if(this._withTags.length>0&&!this._withTags.includes(t.tag))return!1;if(this._withoutTags.length>0&&this._withoutTags.includes(t.tag))return!1;if(this._customPredicates.length>0)for(var d,f=s(this._customPredicates);!(d=f()).done;){if(!(0,d.value)(t))return!1}return!0},t}(),Ut=function(){function t(){var t=this;this._entities=new Map,this._entitiesByName=new Map,this._entitiesByTag=new Map,this._destroyedEntities=new Set,this._identifierPool=new Y,this._componentIndexManager=new tt,this._archetypeSystem=new et,this._dirtyTrackingSystem=new it,this._eventBus=new lt(!1),U.eventBus=this._eventBus,this._eventBus.on("component:added",(function(e){var n=t._entities.get(e.entityId);n&&(t._componentIndexManager.addEntity(n),t._archetypeSystem.addEntity(n))})),this._eventBus.on("component:removed",(function(e){var n=t._entities.get(e.entityId);n&&(t._componentIndexManager.removeEntity(n),t._archetypeSystem.removeEntity(n))}))}var e=t.prototype;return e.createEntity=function(t){var e,n=this._identifierPool.checkOut();t||(t="Entity_"+n);var i=new U(t,n);return this._entities.set(n,i),this.updateNameIndex(i,!0),this.updateTagIndex(i,!0),i.components.length>0&&(this._componentIndexManager.addEntity(i),this._archetypeSystem.addEntity(i),this._dirtyTrackingSystem.markDirty(i,exports.DirtyFlag.COMPONENT_ADDED)),this._eventBus.emitEntityCreated({timestamp:Date.now(),source:"EntityManager",entityId:i.id,entityName:i.name,entityTag:null===(e=i.tag)||void 0===e?void 0:e.toString()}),i},e.createEntitiesBatch=function(t,e,n){if(void 0===e&&(e="Entity"),void 0===n&&(n=!1),t<=0)return[];for(var i=[],r=0;r<t;r++){var o=this._identifierPool.checkOut(),a=new U(e+"_"+o,o);i.push(a),this._entities.set(o,a)}for(var c=0,u=i;c<u.length;c++){var h=u[c];this.updateNameIndex(h,!0),this.updateTagIndex(h,!0),h.components.length>0&&(this._componentIndexManager.addEntity(h),this._archetypeSystem.addEntity(h),this._dirtyTrackingSystem.markDirty(h,exports.DirtyFlag.COMPONENT_ADDED))}if(!n)for(var l,d=Date.now(),f=s(i);!(l=f()).done;){var p,m=l.value;this._eventBus.emitEntityCreated({timestamp:d,source:"EntityManager",entityId:m.id,entityName:m.name,entityTag:null===(p=m.tag)||void 0===p?void 0:p.toString()})}return i},e.destroyEntity=function(t){var e,n=null;return!!(n="string"==typeof t?this.getEntityByName(t):"number"==typeof t?this._entities.get(t)||null:this._entities.get(t.id)||null)&&(this._destroyedEntities.add(n.id),this.updateNameIndex(n,!1),this.updateTagIndex(n,!1),this._componentIndexManager.removeEntity(n),this._archetypeSystem.removeEntity(n),this._dirtyTrackingSystem.markDirty(n,exports.DirtyFlag.COMPONENT_REMOVED),this._eventBus.emitEntityDestroyed({timestamp:Date.now(),source:"EntityManager",entityId:n.id,entityName:n.name,entityTag:null===(e=n.tag)||void 0===e?void 0:e.toString()}),n.destroy(),this._entities.delete(n.id),this._identifierPool.checkIn(n.id),!0)},e.getAllEntities=function(){return Array.from(this._entities.values())},e.getEntity=function(t){var e="string"==typeof t?parseInt(t):t;return this._entities.get(e)||null},e.getEntityByName=function(t){var e=this._entitiesByName.get(t);return e&&e.length>0?e[0]:null},e.getEntitiesByTag=function(t){return Array.from(this._entities.values()).filter((function(e){return e.tag===t}))},e.getEntitiesWithComponent=function(t){var e=this._componentIndexManager.query(t);return Array.from(e)},e.query=function(){return new Wt(this)},e.queryWithComponentIndex=function(t,e){return this._componentIndexManager.queryMultiple(t,e)},e.markEntityDirty=function(t,e){this._dirtyTrackingSystem.markDirty(t,exports.DirtyFlag.COMPONENT_MODIFIED,e)},e.getOptimizationStats=function(){return{componentIndex:this._componentIndexManager.getStats(),archetypeSystem:this._archetypeSystem.getAllArchetypes().map((function(t){return{id:t.id,componentTypes:t.componentTypes.map((function(t){return t.name})),entityCount:t.entities.length}})),dirtyTracking:this._dirtyTrackingSystem.getStats()}},e.updateNameIndex=function(t,e){if(t.name)if(e){var n=this._entitiesByName.get(t.name);n||(n=[],this._entitiesByName.set(t.name,n)),n.push(t)}else{var i=this._entitiesByName.get(t.name);if(i){var r=i.indexOf(t);-1!==r&&(i.splice(r,1),0===i.length&&this._entitiesByName.delete(t.name))}}},e.updateTagIndex=function(t,e){if(e){var n=this._entitiesByTag.get(t.tag);n||(n=[],this._entitiesByTag.set(t.tag,n)),n.push(t)}else{var i=this._entitiesByTag.get(t.tag);if(i){var r=i.indexOf(t);-1!==r&&(i.splice(r,1),0===i.length&&this._entitiesByTag.delete(t.tag))}}},o(t,[{key:"entityCount",get:function(){return this._entities.size}},{key:"activeEntityCount",get:function(){for(var t,e=0,n=s(this._entities.values());!(t=n()).done;){var i=t.value;i.active&&!i.isDestroyed&&e++}return e}},{key:"eventBus",get:function(){return this._eventBus}}])}(),jt=function(){function t(){}return t.getType=function(t){return t.constructor},t}(),Ht=function(){function t(){}return t.toNumber=function(t){return null==t?0:Number(t)},t}();exports.ArchetypeSystem=et,exports.AsyncEventHandler=function(t,e){return void 0===e&&(e={}),function(n,i,r){var o=r.value,s=n.constructor.prototype.initEventListeners||function(){};return n.constructor.prototype.initEventListeners=function(){s.call(this),dt.getInstance().onAsync(t,o.bind(this),e)},r}},exports.BitMask64Utils=M,exports.Bits=Ct,exports.COMPONENT_TYPE_NAME=k,exports.Colors=x,exports.Component=Rt,exports.ComponentDataCollector=It,exports.ComponentIndex=$,exports.ComponentIndexManager=tt,exports.ComponentPool=Q,exports.ComponentPoolManager=V,exports.ComponentRegistry=F,exports.ComponentSparseSet=J,exports.ComponentStorage=L,exports.ComponentTypeManager=bt,exports.ConsoleLogger=w,exports.Core=kt,exports.DebugManager=Ot,exports.DirtyTrackingSystem=it,exports.ECSComponent=function(t){return function(e){if(!t||"string"!=typeof t)throw new Error("ECSComponent装饰器必须提供有效的类型名称");return e[k]=t,e}},exports.ECSFluentAPI=gt,exports.ECSSystem=function(t){return function(e){if(!t||"string"!=typeof t)throw new Error("ECSSystem装饰器必须提供有效的类型名称");return e[N]=t,e}},exports.EVENT_TYPES=ut,exports.Emitter=Pt,exports.EnableSoA=function(t){return t.__enableSoA=!0,t},exports.Entity=U,exports.EntityDataCollector=Mt,exports.EntityList=H,exports.EntityManager=Ut,exports.EntityProcessorList=G,exports.EntityQueryBuilder=Wt,exports.EntitySystem=Bt,exports.EventBus=lt,exports.EventHandler=function(t,e){return void 0===e&&(e={}),function(n,i,r){var o=r.value,s=n.constructor.prototype.initEventListeners||function(){};return n.constructor.prototype.initEventListeners=function(){s.call(this),dt.getInstance().on(t,o.bind(this),e)},r}},exports.EventTypeValidator=ht,exports.Float32=function(t,e){var n=String(e);t.constructor.__float32Fields||(t.constructor.__float32Fields=new Set),t.constructor.__float32Fields.add(n)},exports.Float64=function(t,e){var n=String(e);t.constructor.__float64Fields||(t.constructor.__float64Fields=new Set),t.constructor.__float64Fields.add(n)},exports.FuncPack=Nt,exports.GlobalEventBus=dt,exports.GlobalManager=y,exports.HighPrecision=function(t,e){var n=String(e);t.constructor.__highPrecisionFields||(t.constructor.__highPrecisionFields=new Set),t.constructor.__highPrecisionFields.add(n)},exports.IdentifierPool=Y,exports.Int32=function(t,e){var n=String(e);t.constructor.__int32Fields||(t.constructor.__int32Fields=new Set),t.constructor.__int32Fields.add(n)},exports.IntervalSystem=qt,exports.Logger=A,exports.LoggerManager=I,exports.Matcher=zt,exports.NumberExtension=Ht,exports.PassiveSystem=Lt,exports.PerformanceDataCollector=wt,exports.PerformanceMonitor=S,exports.Pool=T,exports.PoolManager=b,exports.ProcessingSystem=Ft,exports.QuerySystem=st,exports.SYSTEM_TYPE_NAME=N,exports.Scene=ft,exports.SceneDataCollector=At,exports.SerializeMap=function(t,e){var n=String(e);t.constructor.__serializeMapFields||(t.constructor.__serializeMapFields=new Set),t.constructor.__serializeMapFields.add(n)},exports.SoAStorage=O,exports.SparseSet=X,exports.SystemDataCollector=xt,exports.Time=g,exports.Timer=_,exports.TimerManager=E,exports.TypeSafeEventSystem=ct,exports.TypeUtils=jt,exports.WebSocketManager=Dt,exports.World=Et,exports.WorldManager=Tt,exports.createECSAPI=vt,exports.createLogger=D,exports.getComponentInstanceTypeName=z,exports.getComponentTypeName=P,exports.getSystemInstanceTypeName=B,exports.getSystemTypeName=R,exports.resetLoggerColors=function(){I.getInstance().resetColors()},exports.setGlobalLogLevel=function(t){I.getInstance().setGlobalLevel(t)},exports.setLoggerColors=function(t){I.getInstance().setGlobalColors(t)};
3
+ var t,e,n="function"==typeof Symbol?Symbol:{},i=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function s(n,i,r,s){var c=i&&i.prototype instanceof a?i:a,u=Object.create(c.prototype);return d(u,"_invoke",function(n,i,r){var s,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 s=e,a=0,c=t,d.n=n,o}};function f(n,i){for(a=n,c=i,e=0;!l&&u&&!r&&e<h.length;e++){var r,s=h[e],f=d.p,p=s[2];n>3?(r=p===i)&&(c=s[(a=s[4])?5:(a=3,3)],s[4]=s[5]=t):s[0]<=f&&((r=n<2&&f<s[1])?(a=0,d.v=i,d.n=s[1]):f<p&&(r=n<3||s[0]>i||i>p)&&(s[4]=n,s[5]=i,d.n=p,a=0))}if(r||n>1)return o;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;){s||(a?a<3?(a>1&&(d.n=-1),f(a,c)):d.n=c:d.v=c);try{if(u=2,s){if(a||(r="next"),e=s[r]){if(!(e=e.call(s,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=s.return)&&e.call(s),a<2&&(c=TypeError("The iterator does not provide a '"+r+"' method"),a=1);s=t}else if((e=(l=d.n<0)?c:n.call(i,d))!==o)break}catch(e){s=t,a=1,c=e}finally{u=1}}return{value:e,done:l}}}(n,r,s),!0),u}var o={};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:s,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 s(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:(s("next",0),s("throw",1),s("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(){},s(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},s(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,s={name:t,executionTime:r,entityCount:n,averageTimePerEntity:n>0?r/n:0,lastUpdateTime:i};this._systemData.set(t,s),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=o(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],s=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: "+s.averageTime.toFixed(2)+"ms"),t.push(" Min/Max: "+s.minTime.toFixed(2)+"ms / "+s.maxTime.toFixed(2)+"ms"),t.push(" Total: "+s.totalTime.toFixed(2)+"ms ("+s.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=o(this._systemData.entries());!(e=i()).done;){var r=e.value,s=r[0],a=r[1];a.executionTime>t&&n.push(s+": "+a.executionTime.toFixed(2)+"ms (>"+t+"ms)")}return n},e.setMaxRecentSamples=function(t){this._maxRecentSamples=t;for(var e,n=o(this._systemStats.values());!(e=n()).done;)for(var i=e.value;i.recentTimes.length>t;)i.recentTimes.shift()},s(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=o(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=o(this._pools);!(t=n()).done;){var i=t.value,r=i[0],s=i[1];e[r.name||r.toString()]=s.getStats()}return e},t.compactAllPools=function(){for(var t,e=o(this._pools.values());!(t=e()).done;){t.value.compact()}},t.clearAllPools=function(){for(var t,e=o(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],s=r[0],o=r[1];e.push(s+":"),e.push(" Size: "+o.size+"/"+o.maxSize),e.push(" Hit Rate: "+(100*o.hitRate).toFixed(1)+"%"),e.push(" Total Created: "+o.totalCreated),e.push(" Total Obtained: "+o.totalObtained),e.push(" Memory: "+(o.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=o(this.pools.values());!(t=e()).done;){t.value.compact()}},e.clearAllPools=function(){for(var t,e=o(this.pools.values());!(t=e()).done;){t.value.clear()}},e.getAllStats=function(){for(var t,e=new Map,n=o(this.pools);!(t=n()).done;){var i=t.value,r=i[0],s=i[1];e.set(r,s.getStats())}return e},e.getGlobalStats=function(){for(var t,e=0,n=0,i=0,r=0,s=0,a=0,c=o(this.pools.values());!(t=c()).done;){var u=t.value.getStats();e+=u.size,n+=u.maxSize,i+=u.totalCreated,r+=u.totalObtained,s+=u.totalReleased,a+=u.estimatedMemoryUsage}return{size:e,maxSize:n,totalCreated:i,totalObtained:r,totalReleased:s,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=o(this.pools);!(n=i()).done;){var r=n.value,s=r[0],a=r[1].getStats();t.push(s+":"),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=o(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:"",RED:"",GREEN:"",YELLOW:"",BLUE:"",MAGENTA:"",CYAN:"",WHITE:"",BRIGHT_BLACK:"",BRIGHT_RED:"",BRIGHT_GREEN:"",BRIGHT_YELLOW:"",BRIGHT_BLUE:"",BRIGHT_MAGENTA:"",BRIGHT_CYAN:"",BRIGHT_WHITE:"",RESET:"",BOLD:"",UNDERLINE:""},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),s=2;s<i;s++)r[s-2]=arguments[s];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),s=2;s<i;s++)r[s-2]=arguments[s];switch(t){case exports.LogLevel.Debug:var o,a;if(n)(o=console).debug.apply(o,[""+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._defaultLevel=exports.LogLevel.Info,this._defaultLogger=new w({level:this._defaultLevel})}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:this._defaultLevel});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._defaultLevel=t,this._defaultLogger instanceof w&&this._defaultLogger.setLevel(t);for(var e,n=o(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=o(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=o(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,s=t.__int32Fields||new Set,o=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)):s.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&&(o.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,s=this.type.__serializeMapFields||new Set,o=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,s,o,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,s){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)):(s.has(n)&&Array.isArray(e),JSON.stringify(e))}catch(e){return t._logger.warn("SoA序列化字段 "+n+" 失败:",e),"{}"}},e.deserializeValue=function(e,n,i,r,s){try{var o=JSON.parse(e);return i.has(n)?new Map(o):r.has(n)?new Set(o):(s.has(n),o)}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=o(t.entries());!(n=r()).done;){var s=n.value,a=s[0],c=s[1];i.set(a,this.deepClone(c))}return i}if(t instanceof Set){for(var u,h=new Set,l=o(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,s=this.type.__serializeSetFields||new Set,a=this.type.__serializeArrayFields||new Set,c=o(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=o(this.stringFields.entries());!(f=p()).done;){var m=f.value,y=m[0],g=m[1];i[y]=g[e]}for(var v,_=o(this.serializedFields.entries());!(v=_()).done;){var E=v.value,S=E[0],T=E[1][e];T&&(i[S]=this.deserializeValue(T,S,r,s,a))}var C=this.complexFields.get(t);if(C)for(var b,M=o(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=o(this.fields.entries());!(e=n()).done;){var i=e.value,r=i[0],s=i[1],a=void 0;(a=s instanceof Float32Array?new Float32Array(t):s instanceof Float64Array?new Float64Array(t):new Int32Array(t)).set(s),this.fields.set(r,a)}for(var c,u=o(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=o(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=o(this.fields.values());!(t=e()).done;){t.value.fill(0)}for(var n,i=o(this.stringFields.values());!(n=i()).done;)for(var r=n.value,s=0;s<r.length;s++)r[s]=void 0;for(var a,c=o(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],s=r[0],a=r[1];if(e.set(s,i),n[i]=s,i!==a){for(var c,u=o(this.fields.entries());!(c=u()).done;){var h=c.value[1];h[i]=h[a]}for(var l,d=o(this.stringFields.entries());!(l=d()).done;){var f=l.value[1];f[i]=f[a]}for(var p,m=o(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=o(this.fields.entries());!(t=i()).done;){var r=t.value,s=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(s,{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 L=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=o(t);!(n=r()).done;){var s=n.value,a=this.getComponentId(s);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}();L._logger=D("ComponentStorage"),L.componentTypes=new Map,L.componentNameToType=new Map,L.componentNameToId=new Map,L.maskCache=new Map,L.nextBitIndex=0,L.maxComponents=64;var F=function(){function t(t){this.dense=[],this.entityIds=[],this.entityToIndex=new Map,this.componentType=t,L.isRegistered(t)||L.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],s=this.entityIds[i];this.dense[e]=r,this.entityIds[e]=s,this.entityToIndex.set(s,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}},s(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 F(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=o(this.storages.values());!(e=n()).done;){e.value.removeComponent(t)}},e.getComponentMask=function(t){for(var e,n=M.clone(M.ZERO),i=o(this.storages.entries());!(e=i()).done;){var r=e.value,s=r[0];if(r[1].hasComponent(t)){var a=L.getBitMask(s);M.orInPlace(n,a)}}return n},e.getAllStats=function(){for(var t,e=new Map,n=o(this.storages.entries());!(t=n()).done;){var i=t.value,r=i[0],s=i[1],a=P(r);e.set(a,s.getStats())}return e},e.clear=function(){for(var t,e=o(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 s=i(t,n);return this.addComponent(s)},e.addComponentInternal=function(t){var e=t.constructor;L.isRegistered(e)||L.register(e);var n=L.getBitIndex(e);t.entity=this,this._componentsByTypeId[n]=t;var i=this.components.length;this._componentDenseIndexByTypeId[n]=i,this.components.push(t);var r=L.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(!L.isRegistered(t))return null;var e=L.getBitMask(t);if(M.hasNone(this._componentMask,e))return null;var n=L.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 s=this.components.length;this._componentDenseIndexByTypeId[n]=s,this.components.push(r)}return r}}for(var o=0;o<this.components.length;o++){var a=this.components[o];if(a instanceof t)return this._componentsByTypeId[n]=a,this._componentDenseIndexByTypeId[n]=o,a}return null},e.hasComponent=function(t){if(!L.isRegistered(t))return!1;var e=L.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(L.isRegistered(n)){var i=L.getBitIndex(n);this._componentsByTypeId[i]=void 0,M.clearBit(this._componentMask,i);var r,s=this._componentDenseIndexByTypeId[i];if(void 0!==s&&s<this.components.length){var o=this.components.length-1;if(s!==o){var a=this.components[o];this.components[s]=a;var c=a.constructor,u=L.getBitIndex(c);this._componentDenseIndexByTypeId[u]=s}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=o(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=o(e);!(n=r()).done;){var s=n.value;try{i.push(this.addComponent(s))}catch(e){t._logger.warn("添加组件失败 "+z(s)+":",e)}}return i},e.removeComponentsByTypes=function(t){for(var e,n=[],i=o(t);!(e=i()).done;){var r=e.value;n.push(this.removeComponentByType(r))}return n},e.getComponents=function(t){for(var e,n=[],i=o(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=o([].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=o(this._children);!(n=i()).done;){var r=n.value;if(r.name===t)return r}if(e)for(var s,a=o(this._children);!(s=a()).done;){var c=s.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=o(this._children);!(n=r()).done;){var s=n.value;s.tag===t&&i.push(s)}if(e)for(var a,c=o(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=o(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=o(this.components);!(t=e()).done;){var n=t.value;n.enabled&&n.update()}for(var i,r=o(this._children);!(i=r()).done;){i.value.update()}}},e.destroy=function(){if(!this._isDestroyed){this._isDestroyed=!0;for(var t,e=o([].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}},s(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 s=r[i];this.entity.addComponent(s)}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 s=r[i].build();this.entity.addChild(s)}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=o(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=o(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=o(this._entitiesToRemove);!(i=r()).done;){var s=i.value;this.removeImmediate(s)}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=o(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=o(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=o(this.buffer);!(e=n()).done;){t(e.value)}},e.forEachWhere=function(t,e){for(var n,i=o(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=o(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}},s(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=o(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=o(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=o(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)},s(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=[],this._recycleDelay=100,this._stats={totalAllocated:0,totalRecycled:0,currentActive:0,memoryExpansions:0},this._recycleDelay=t,this._expansionBlockSize=e,this._preAllocateGenerations(0,this._expansionBlockSize)}var e=t.prototype;return e.checkOut=function(){var e;if(this._processDelayedRecycle(),this._freeIndices.length>0)e=this._freeIndices.pop();else{if(this._nextAvailableIndex>t.MAX_INDEX)throw new Error("实体索引已达到框架设计限制 ("+t.MAX_INDEX+")。这意味着您已经分配了超过65535个不同的实体索引。这是16位索引设计的限制,考虑优化实体回收策略或升级到64位ID设计。");e=this._nextAvailableIndex++,this._ensureGenerationCapacity(e)}var n=this._generations.get(e)||1;return this._stats.totalAllocated++,this._stats.currentActive++,this._packId(e,n)},e.checkIn=function(t){var e=this._unpackIndex(t),n=this._unpackGeneration(t);return!!this._isValidId(e,n)&&(!this._pendingRecycle.some((function(t){return t.index===e&&t.generation===n}))&&(this._pendingRecycle.push({index:e,generation:n,timestamp:Date.now()}),this._stats.currentActive--,this._stats.totalRecycled++,!0))},e.isValid=function(t){var e=this._unpackIndex(t),n=this._unpackGeneration(t);return this._isValidId(e,n)},e.getStats=function(){for(var e,n=0,i=0,r=o(this._generations);!(e=r()).done;){var s=e.value,a=s[0],c=s[1];a<this._nextAvailableIndex&&(n+=c,i++)}var u=i>0?n/i:1;return{totalAllocated:this._stats.totalAllocated,totalRecycled:this._stats.totalRecycled,currentActive:this._stats.currentActive,currentlyFree:this._freeIndices.length,pendingRecycle:this._pendingRecycle.length,maxPossibleEntities:t.MAX_INDEX+1,maxUsedIndex:this._nextAvailableIndex-1,memoryUsage:this._calculateMemoryUsage(),memoryExpansions:this._stats.memoryExpansions,averageGeneration:Math.round(100*u)/100,generationStorageSize:this._generations.size}},e.forceProcessDelayedRecycle=function(){this._processDelayedRecycle(!0)},e._processDelayedRecycle=function(e){if(void 0===e&&(e=!1),0!==this._pendingRecycle.length){for(var n,i=Date.now(),r=[],s=[],a=o(this._pendingRecycle);!(n=a()).done;){var c=n.value;e||i-c.timestamp>=this._recycleDelay?r.push(c):s.push(c)}for(var u=0,h=r;u<h.length;u++){var l=h[u];if(this._isValidId(l.index,l.generation)){var d=l.generation+1;d>t.MAX_GENERATION&&(d=1),this._generations.set(l.index,d),this._freeIndices.push(l.index)}}this._pendingRecycle=s}},e._preAllocateGenerations=function(e,n){for(var i=0;i<n;i++){var r=e+i;r<=t.MAX_INDEX&&this._generations.set(r,1)}this._stats.memoryExpansions++},e._ensureGenerationCapacity=function(t){if(!this._generations.has(t)){var e=Math.floor(t/this._expansionBlockSize)*this._expansionBlockSize;this._preAllocateGenerations(e,this._expansionBlockSize)}},e._calculateMemoryUsage=function(){return 16*this._generations.size+8*this._freeIndices.length+32*this._pendingRecycle.length},e._packId=function(t,e){return e<<16|t},e._unpackIndex=function(t){return 65535&t},e._unpackGeneration=function(t){return t>>>16&65535},e._isValidId=function(t,e){if(t<0||t>=this._nextAvailableIndex)return!1;var n=this._generations.get(t);return void 0!==n&&n===e},t}();Y.MAX_INDEX=65535,Y.MAX_GENERATION=65535;var Q=function(){function t(t,e,n){void 0===n&&(n=1e3),this.pool=[],this.createFn=t,this.resetFn=e,this.maxSize=n}var e=t.prototype;return e.acquire=function(){return this.pool.length>0?this.pool.pop():this.createFn()},e.release=function(t){this.pool.length<this.maxSize&&(this.resetFn&&this.resetFn(t),this.pool.push(t))},e.prewarm=function(t){for(var e=0;e<t&&this.pool.length<this.maxSize;e++)this.pool.push(this.createFn())},e.clear=function(){this.pool.length=0},e.getAvailableCount=function(){return this.pool.length},e.getMaxSize=function(){return this.maxSize},t}(),V=function(){function t(){this.pools=new Map}t.getInstance=function(){return t.instance||(t.instance=new t),t.instance};var e=t.prototype;return e.registerPool=function(t,e,n,i){this.pools.set(t,new Q(e,n,i))},e.acquireComponent=function(t){var e=this.pools.get(t);return e?e.acquire():null},e.releaseComponent=function(t,e){var n=this.pools.get(t);n&&n.release(e)},e.prewarmAll=function(t){void 0===t&&(t=100);for(var e,n=o(this.pools.values());!(e=n()).done;){e.value.prewarm(t)}},e.clearAll=function(){for(var t,e=o(this.pools.values());!(t=e()).done;){t.value.clear()}},e.reset=function(){this.pools.clear()},e.getPoolStats=function(){for(var t,e=new Map,n=o(this.pools);!(t=n()).done;){var i=t.value,r=i[0],s=i[1];e.set(r,{available:s.getAvailableCount(),maxSize:s.getMaxSize()})}return e},e.getPoolUtilization=function(){for(var t,e=new Map,n=o(this.pools);!(t=n()).done;){var i=t.value,r=i[0],s=i[1],a=s.getAvailableCount(),c=s.getMaxSize(),u=c-a,h=c>0?u/c*100:0;e.set(r,{used:u,total:c,utilization:h})}return e},e.getComponentUtilization=function(t){var e=this.pools.get(t);if(!e)return 0;var n=e.getAvailableCount(),i=e.getMaxSize();return i>0?(i-n)/i*100:0},t}(),X=function(){function t(){this._dense=[],this._sparse=new Map}var e=t.prototype;return e.add=function(t){if(this._sparse.has(t))return!1;var e=this._dense.length;return this._dense.push(t),this._sparse.set(t,e),!0},e.remove=function(t){var e=this._sparse.get(t);if(void 0===e)return!1;var n=this._dense.length-1;if(e!==n){var i=this._dense[n];this._dense[e]=i,this._sparse.set(i,e)}return this._dense.pop(),this._sparse.delete(t),!0},e.has=function(t){return this._sparse.has(t)},e.getIndex=function(t){return this._sparse.get(t)},e.getByIndex=function(t){return this._dense[t]},e.forEach=function(t){for(var e=0;e<this._dense.length;e++)t(this._dense[e],e)},e.map=function(t){for(var e=[],n=0;n<this._dense.length;n++)e.push(t(this._dense[n],n));return e},e.filter=function(t){for(var e=[],n=0;n<this._dense.length;n++)t(this._dense[n],n)&&e.push(this._dense[n]);return e},e.find=function(t){for(var e=0;e<this._dense.length;e++)if(t(this._dense[e],e))return this._dense[e]},e.some=function(t){for(var e=0;e<this._dense.length;e++)if(t(this._dense[e],e))return!0;return!1},e.every=function(t){for(var e=0;e<this._dense.length;e++)if(!t(this._dense[e],e))return!1;return!0},e.getDenseArray=function(){return[].concat(this._dense)},e.getDenseArrayUnsafe=function(){return this._dense},e.clear=function(){this._dense.length=0,this._sparse.clear()},e.toArray=function(){return[].concat(this._dense)},e.toSet=function(){return new Set(this._dense)},e.getMemoryStats=function(){var t=8*this._dense.length,e=16*this._sparse.size;return{denseArraySize:t,sparseMapSize:e,totalMemory:t+e}},e.validate=function(){if(this._dense.length!==this._sparse.size)return!1;for(var t=0;t<this._dense.length;t++){var e=this._dense[t];if(this._sparse.get(e)!==t)return!1}for(var n,i=o(this._sparse);!(n=i()).done;){var r=n.value,s=r[0],a=r[1];if(a>=this._dense.length||this._dense[a]!==s)return!1}return!0},s(t,[{key:"size",get:function(){return this._dense.length}},{key:"isEmpty",get:function(){return 0===this._dense.length}}])}(),Z=function(t){function e(){return t.call(this)||this}return u(e,t),e.prototype.reset=function(){this.clear()},e}(m(Set)),J=function(){function t(){this._componentMasks=[],this._componentToEntities=new Map,this._entities=new X}var e=t.prototype;return e.addEntity=function(t){this._entities.has(t)&&this.removeEntity(t);for(var e,n=M.clone(M.ZERO),i=new Set,r=o(t.components);!(e=r()).done;){var s=e.value.constructor;i.add(s),L.isRegistered(s)||L.register(s);var a=L.getBitMask(s);M.orInPlace(n,a)}this._entities.add(t);for(var c=this._entities.getIndex(t);this._componentMasks.length<=c;)this._componentMasks.push(M.clone(M.ZERO));this._componentMasks[c]=n,this.updateComponentMappings(t,i,!0)},e.removeEntity=function(t){var e=this._entities.getIndex(t);if(void 0!==e){var n=this.getEntityComponentTypes(t);this.updateComponentMappings(t,n,!1),this._entities.remove(t);var i=this._componentMasks.length-1;e!==i&&(this._componentMasks[e]=this._componentMasks[i]),this._componentMasks.pop()}},e.queryByComponent=function(t){var e=this._componentToEntities.get(t);return e?new Set(e):new Set},e.queryMultipleAnd=function(e){var n=this;if(0===e.length)return new Set;if(1===e.length)return this.queryByComponent(e[0]);for(var i,r=M.clone(M.ZERO),s=o(e);!(i=s()).done;){var a=i.value;if(!L.isRegistered(a))return new Set;var c=L.getBitMask(a);M.orInPlace(r,c)}var u=t._entitySetPool.obtain();return this._entities.forEach((function(t,e){var i=n._componentMasks[e];M.hasAll(i,r)&&u.add(t)})),u},e.queryMultipleOr=function(e){var n=this;if(0===e.length)return new Set;if(1===e.length)return this.queryByComponent(e[0]);for(var i,r=M.clone(M.ZERO),s=o(e);!(i=s()).done;){var a=i.value;if(L.isRegistered(a)){var c=L.getBitMask(a);M.orInPlace(r,c)}}if(M.equals(r,M.ZERO))return new Set;var u=t._entitySetPool.obtain();return this._entities.forEach((function(t,e){var i=n._componentMasks[e];M.hasAny(i,r)&&u.add(t)})),u},e.hasComponent=function(t,e){var n=this._entities.getIndex(t);if(void 0===n)return!1;if(!L.isRegistered(e))return!1;var i=this._componentMasks[n],r=L.getBitMask(e);return M.hasAny(i,r)},e.getEntityMask=function(t){var e=this._entities.getIndex(t);if(void 0!==e)return this._componentMasks[e]},e.getAllEntities=function(){return this._entities.toArray()},e.forEach=function(t){var e=this;this._entities.forEach((function(n,i){t(n,e._componentMasks[i],i)}))},e.clear=function(){this._entities.clear(),this._componentMasks.length=0;for(var e,n=o(this._componentToEntities.values());!(e=n()).done;){var i=e.value;t._entitySetPool.release(i)}this._componentToEntities.clear()},e.getMemoryStats=function(){for(var t,e=this._entities.getMemoryStats(),n=16*this._componentMasks.length,i=16*this._componentToEntities.size,r=o(this._componentToEntities.values());!(t=r()).done;){i+=8*t.value.size}return{entitiesMemory:e.totalMemory,masksMemory:n,mappingsMemory:i,totalMemory:e.totalMemory+n+i}},e.validate=function(){if(!this._entities.validate())return!1;if(this._componentMasks.length!==this._entities.size)return!1;for(var t,e=new Set,n=o(this._componentToEntities.values());!(t=n()).done;)for(var i,r=o(t.value);!(i=r()).done;){var s=i.value;e.add(s)}for(var a,c=o(e);!(a=c()).done;){var u=a.value;if(!this._entities.has(u))return!1}return!0},e.getEntityComponentTypes=function(t){for(var e,n=new Set,i=o(t.components);!(e=i()).done;){var r=e.value;n.add(r.constructor)}return n},e.updateComponentMappings=function(e,n,i){for(var r,s=o(n);!(r=s()).done;){var a=r.value,c=this._componentToEntities.get(a);i?(c||(c=t._entitySetPool.obtain(),this._componentToEntities.set(a,c)),c.add(e)):c&&(c.delete(e),0===c.size&&(this._componentToEntities.delete(a),t._entitySetPool.release(c)))}},s(t,[{key:"size",get:function(){return this._entities.size}},{key:"isEmpty",get:function(){return this._entities.isEmpty}}])}();J._entitySetPool=T.getPool(Z,50,512);var K,$=function(){function t(){this._queryCount=0,this._totalQueryTime=0,this._lastUpdated=Date.now(),this._sparseSet=new J}var e=t.prototype;return e.addEntity=function(t){this._sparseSet.addEntity(t),this._lastUpdated=Date.now()},e.removeEntity=function(t){this._sparseSet.removeEntity(t),this._lastUpdated=Date.now()},e.query=function(t){var e=performance.now(),n=this._sparseSet.queryByComponent(t);return this._queryCount++,this._totalQueryTime+=performance.now()-e,n},e.queryMultiple=function(t,e){var n,i=performance.now();return n=0===t.length?new Set:1===t.length?this.query(t[0]):"AND"===e?this._sparseSet.queryMultipleAnd(t):this._sparseSet.queryMultipleOr(t),this._queryCount++,this._totalQueryTime+=performance.now()-i,n},e.clear=function(){this._sparseSet.clear(),this._lastUpdated=Date.now()},e.getStats=function(){var t=this._sparseSet.getMemoryStats();return{size:this._sparseSet.size,memoryUsage:t.totalMemory,queryCount:this._queryCount,avgQueryTime:this._queryCount>0?this._totalQueryTime/this._queryCount:0,lastUpdated:this._lastUpdated}},t}(),tt=function(){function t(){this._index=new $}var e=t.prototype;return e.addEntity=function(t){this._index.addEntity(t)},e.removeEntity=function(t){this._index.removeEntity(t)},e.query=function(t){return this._index.query(t)},e.queryMultiple=function(t,e){return this._index.queryMultiple(t,e)},e.getStats=function(){return this._index.getStats()},e.clear=function(){this._index.clear()},t}(),et=function(){function t(){this._archetypes=new Map,this._entityToArchetype=new Map,this._componentToArchetypes=new Map,this._queryCache=new Map,this._cacheTimeout=5e3,this._maxCacheSize=100}var e=t.prototype;return e.addEntity=function(t){var e=this.getEntityComponentTypes(t),n=this.generateArchetypeId(e),i=this._archetypes.get(n);i||(i=this.createArchetype(e)),i.entities.push(t),i.updatedAt=Date.now(),this._entityToArchetype.set(t,i),this.updateComponentIndexes(i,e,!0),this.invalidateQueryCache()},e.removeEntity=function(t){var e=this._entityToArchetype.get(t);if(e){var n=e.entities.indexOf(t);-1!==n&&(e.entities.splice(n,1),e.updatedAt=Date.now()),this._entityToArchetype.delete(t),this.invalidateQueryCache()}},e.queryArchetypes=function(t,e){void 0===e&&(e="AND");var n=performance.now(),i=e+":"+t.map((function(t){return P(t)})).sort().join(","),r=this._queryCache.get(i);if(r&&Date.now()-r.timestamp<this._cacheTimeout)return a({},r.result,{executionTime:performance.now()-n,fromCache:!0});var s=[],c=0;if("AND"===e)for(var u,h=o(this._archetypes.values());!(u=h()).done;){var l=u.value;this.archetypeContainsAllComponents(l,t)&&(s.push(l),c+=l.entities.length)}else{for(var d,f=new Set,p=o(t);!(d=p()).done;){var m=d.value,y=this._componentToArchetypes.get(m);if(y)for(var g,v=o(y);!(g=v()).done;){var _=g.value;f.add(_)}}for(var E,S=o(f);!(E=S()).done;){var T=E.value;s.push(T),c+=T.entities.length}}var C={archetypes:s,totalEntities:c,executionTime:performance.now()-n,fromCache:!1};return this._queryCache.set(i,{result:C,timestamp:Date.now()}),C},e.getEntityArchetype=function(t){return this._entityToArchetype.get(t)},e.getAllArchetypes=function(){return Array.from(this._archetypes.values())},e.clear=function(){this._archetypes.clear(),this._entityToArchetype.clear(),this._componentToArchetypes.clear(),this._queryCache.clear()},e.getEntityComponentTypes=function(t){return t.components.map((function(t){return t.constructor}))},e.generateArchetypeId=function(t){return t.map((function(t){return P(t)})).sort().join("|")},e.createArchetype=function(t){var e=this.generateArchetypeId(t),n={id:e,componentTypes:[].concat(t),entities:[],createdAt:Date.now(),updatedAt:Date.now()};return this._archetypes.set(e,n),n},e.archetypeContainsAllComponents=function(t,e){for(var n,i=o(e);!(n=i()).done;){var r=n.value;if(!t.componentTypes.includes(r))return!1}return!0},e.updateComponentIndexes=function(t,e,n){for(var i,r=o(e);!(i=r()).done;){var s=i.value,a=this._componentToArchetypes.get(s);a||(a=new Set,this._componentToArchetypes.set(s,a)),n?a.add(t):(a.delete(t),0===a.size&&this._componentToArchetypes.delete(s))}},e.invalidateQueryCache=function(){this._queryCache.clear()},t}();exports.DirtyFlag=void 0,(K=exports.DirtyFlag||(exports.DirtyFlag={}))[K.COMPONENT_MODIFIED=1]="COMPONENT_MODIFIED",K[K.COMPONENT_ADDED=2]="COMPONENT_ADDED",K[K.COMPONENT_REMOVED=4]="COMPONENT_REMOVED",K[K.TRANSFORM_CHANGED=8]="TRANSFORM_CHANGED",K[K.STATE_CHANGED=16]="STATE_CHANGED",K[K.CUSTOM_1=256]="CUSTOM_1",K[K.CUSTOM_2=512]="CUSTOM_2",K[K.CUSTOM_3=1024]="CUSTOM_3",K[K.ALL=4294967295]="ALL";var nt,it=function(){function t(){this._dirtyEntities=new Map,this._listeners=[],this._stats={totalMarkings:0,totalCleanups:0,frameCount:0,totalDirtyPerFrame:0},this._currentFrame=0,this._batchSize=100,this._maxProcessingTime=16,this._processingQueue=[],this._isProcessing=!1}var e=t.prototype;return e.markDirty=function(t,e,n){void 0===n&&(n=[]),this._stats.totalMarkings++;var i=this._dirtyEntities.get(t);i||(i={entity:t,flags:0,modifiedComponents:new Set,timestamp:performance.now(),frameNumber:this._currentFrame},this._dirtyEntities.set(t,i)),i.flags|=e,i.timestamp=performance.now(),i.frameNumber=this._currentFrame;for(var r,s=o(n);!(r=s()).done;){var a=r.value;i.modifiedComponents.add(a)}this.notifyListeners(i,e)},e.isDirty=function(t,e){void 0===e&&(e=exports.DirtyFlag.ALL);var n=this._dirtyEntities.get(t);return!!n&&0!==(n.flags&e)},e.clearDirty=function(t,e){void 0===e&&(e=exports.DirtyFlag.ALL);var n=this._dirtyEntities.get(t);n&&(e===exports.DirtyFlag.ALL?this._dirtyEntities.delete(t):(n.flags&=~e,0===n.flags&&this._dirtyEntities.delete(t)),this._stats.totalCleanups++)},e.getDirtyEntities=function(t){void 0===t&&(t=exports.DirtyFlag.ALL);for(var e,n=[],i=o(this._dirtyEntities.values());!(e=i()).done;){var r=e.value;0!==(r.flags&t)&&n.push(r)}return n},e.processDirtyEntities=function(){if(!this._isProcessing){this._isProcessing=!0;var t,e=performance.now();if(0===this._processingQueue.length)(t=this._processingQueue).push.apply(t,this._dirtyEntities.values());for(var n=0;this._processingQueue.length>0&&n<this._batchSize;){if(performance.now()-e>this._maxProcessingTime)break;var i=this._processingQueue.shift();this.processEntity(i),n++}0===this._processingQueue.length&&(this._isProcessing=!1,this.onFrameEnd())}},e.addListener=function(t){this._listeners.push(t),this._listeners.sort((function(t,e){return(t.priority||100)-(e.priority||100)}))},e.removeListener=function(t){var e=this._listeners.findIndex((function(e){return e.callback===t}));-1!==e&&this._listeners.splice(e,1)},e.beginFrame=function(){this._currentFrame++},e.endFrame=function(){this._isProcessing||this.processDirtyEntities()},e.getStats=function(){return{dirtyEntityCount:this._dirtyEntities.size,totalMarkings:this._stats.totalMarkings,totalCleanups:this._stats.totalCleanups,listenerCount:this._listeners.length,avgDirtyPerFrame:this._stats.frameCount>0?this._stats.totalDirtyPerFrame/this._stats.frameCount:0,estimatedMemoryUsage:this.estimateMemoryUsage()}},e.clear=function(){this._dirtyEntities.clear(),this._processingQueue.length=0,this._isProcessing=!1,this._stats={totalMarkings:0,totalCleanups:0,frameCount:0,totalDirtyPerFrame:0}},e.configureBatchProcessing=function(t,e){this._batchSize=t,this._maxProcessingTime=e},e.processEntity=function(e){for(var n,i=o(this._listeners);!(n=i()).done;){var r=n.value;if(0!==(e.flags&r.flags))try{r.callback(e)}catch(e){t._logger.error("脏数据监听器错误:",e)}}this.clearDirty(e.entity)},e.notifyListeners=function(e,n){for(var i,r=o(this._listeners);!(i=r()).done;){var s=i.value;if(0!==(n&s.flags))try{s.callback(e)}catch(e){t._logger.error("脏数据监听器通知错误:",e)}}},e.onFrameEnd=function(){this._stats.frameCount++,this._stats.totalDirtyPerFrame+=this._dirtyEntities.size},e.estimateMemoryUsage=function(){var t=0;return t+=100*this._dirtyEntities.size,t+=50*this._listeners.length,t+=8*this._processingQueue.length},t}();it._logger=D("DirtyTrackingSystem"),function(t){t.ALL="all",t.ANY="any",t.NONE="none"}(nt||(nt={}));var rt,st,ot=function(){function t(){this._logger=D("QuerySystem"),this.entities=[],this.indexDirty=!0,this._version=0,this.queryCache=new Map,this.cacheMaxSize=1e3,this.cacheTimeout=5e3,this.queryStats={totalQueries:0,cacheHits:0,indexHits:0,linearScans:0,archetypeHits:0,dirtyChecks:0},this.entityIndex={byMask:new Map,byComponentType:new Map,byTag:new Map,byName:new Map},this.componentPoolManager=V.getInstance(),this.componentIndexManager=new tt,this.archetypeSystem=new et,this.dirtyTrackingSystem=new it}var e=t.prototype;return e.setEntities=function(t){this.entities=t,this.clearQueryCache(),this.rebuildIndexes()},e.addEntity=function(t,e){void 0===e&&(e=!1),this.entities.includes(t)||(this.entities.push(t),this.addEntityToIndexes(t),this.componentIndexManager.addEntity(t),this.archetypeSystem.addEntity(t),this.dirtyTrackingSystem.markDirty(t,exports.DirtyFlag.COMPONENT_ADDED),e||this.clearQueryCache(),this._version++)},e.addEntities=function(t){if(0!==t.length){for(var e,n=new Set(this.entities.map((function(t){return t.id}))),i=0,r=o(t);!(e=r()).done;){var s=e.value;n.has(s.id)||(this.entities.push(s),this.addEntityToIndexes(s),n.add(s.id),i++)}i>0&&this.clearQueryCache()}},e.addEntitiesUnchecked=function(t){if(0!==t.length){for(var e,n=o(t);!(e=n()).done;){var i=e.value;this.entities.push(i)}for(var r,s=o(t);!(r=s()).done;){var a=r.value;this.addEntityToIndexes(a)}this.clearQueryCache()}},e.removeEntity=function(t){var e=this.entities.indexOf(t);-1!==e&&(this.entities.splice(e,1),this.removeEntityFromIndexes(t),this.componentIndexManager.removeEntity(t),this.archetypeSystem.removeEntity(t),this.dirtyTrackingSystem.markDirty(t,exports.DirtyFlag.COMPONENT_REMOVED),this.clearQueryCache(),this._version++)},e.addEntityToIndexes=function(t){var e=t.componentMask.toString(),n=this.entityIndex.byMask.get(e);n||(n=new Set,this.entityIndex.byMask.set(e,n)),n.add(t);for(var i=t.components,r=0;r<i.length;r++){var s=i[r].constructor,o=this.entityIndex.byComponentType.get(s);o||(o=new Set,this.entityIndex.byComponentType.set(s,o)),o.add(t)}var a=t.tag;if(void 0!==a){var c=this.entityIndex.byTag.get(a);c||(c=new Set,this.entityIndex.byTag.set(a,c)),c.add(t)}var u=t.name;if(u){var h=this.entityIndex.byName.get(u);h||(h=new Set,this.entityIndex.byName.set(u,h)),h.add(t)}},e.removeEntityFromIndexes=function(t){var e=t.componentMask.toString(),n=this.entityIndex.byMask.get(e);n&&(n.delete(t),0===n.size&&this.entityIndex.byMask.delete(e));for(var i,r=o(t.components);!(i=r()).done;){var s=i.value.constructor,a=this.entityIndex.byComponentType.get(s);a&&(a.delete(t),0===a.size&&this.entityIndex.byComponentType.delete(s))}if(void 0!==t.tag){var c=this.entityIndex.byTag.get(t.tag);c&&(c.delete(t),0===c.size&&this.entityIndex.byTag.delete(t.tag))}if(t.name){var u=this.entityIndex.byName.get(t.name);u&&(u.delete(t),0===u.size&&this.entityIndex.byName.delete(t.name))}},e.rebuildIndexes=function(){this.entityIndex.byMask.clear(),this.entityIndex.byComponentType.clear(),this.entityIndex.byTag.clear(),this.entityIndex.byName.clear(),this.archetypeSystem.clear(),this.componentIndexManager.clear();for(var t,e=o(this.entities);!(t=e()).done;){var n=t.value;this.addEntityToIndexes(n),this.componentIndexManager.addEntity(n),this.archetypeSystem.addEntity(n)}this.indexDirty=!1},e.queryAll=function(){var t=performance.now();this.queryStats.totalQueries++;for(var e=arguments.length,n=new Array(e),i=0;i<e;i++)n[i]=arguments[i];var r="all:"+n.map((function(t){return P(t)})).sort().join(","),s=this.getFromCache(r);if(s)return this.queryStats.cacheHits++,{entities:s,count:s.length,executionTime:performance.now()-t,fromCache:!0};var a=[],c=this.archetypeSystem.queryArchetypes(n,"AND");if(c.archetypes.length>0){this.queryStats.archetypeHits++;for(var u,h=o(c.archetypes);!(u=h()).done;){var l,d=u.value;(l=a).push.apply(l,d.entities)}}else try{if(1===n.length){this.queryStats.indexHits++;var f=this.componentIndexManager.query(n[0]);a=Array.from(f)}else{var p=this.componentIndexManager.queryMultiple(n,"AND");a=Array.from(p)}}catch(t){a=[]}return this.addToCache(r,a),{entities:a,count:a.length,executionTime:performance.now()-t,fromCache:!1}},e.queryMultipleComponents=function(t){for(var e,n=null,i=1/0,r=o(t);!(e=r()).done;){var s=e.value,a=this.entityIndex.byComponentType.get(s);if(!a||0===a.size)return[];a.size<i&&(i=a.size,n=a)}if(!n)return[];for(var c,u=this.createComponentMask(t),h=[],l=o(n);!(c=l()).done;){var d=c.value;M.hasAll(d.componentMask,u)&&h.push(d)}return h},e.queryAny=function(){var t=performance.now();this.queryStats.totalQueries++;for(var e=arguments.length,n=new Array(e),i=0;i<e;i++)n[i]=arguments[i];var r="any:"+n.map((function(t){return P(t)})).sort().join(","),s=this.getFromCache(r);if(s)return this.queryStats.cacheHits++,{entities:s,count:s.length,executionTime:performance.now()-t,fromCache:!0};var a,c=this.archetypeSystem.queryArchetypes(n,"OR");if(c.archetypes.length>0){this.queryStats.archetypeHits++,a=[];for(var u,h=o(c.archetypes);!(u=h()).done;){var l,d=u.value;(l=a).push.apply(l,d.entities)}}else{var f=this.componentIndexManager.queryMultiple(n,"OR");a=Array.from(f)}return this.addToCache(r,a),{entities:a,count:a.length,executionTime:performance.now()-t,fromCache:!1}},e.queryNone=function(){var t=performance.now();this.queryStats.totalQueries++;for(var e=arguments.length,n=new Array(e),i=0;i<e;i++)n[i]=arguments[i];var r="none:"+n.map((function(t){return P(t)})).sort().join(","),s=this.getFromCache(r);if(s)return this.queryStats.cacheHits++,{entities:s,count:s.length,executionTime:performance.now()-t,fromCache:!0};var o=this.createComponentMask(n),a=this.entities.filter((function(t){return M.hasNone(t.componentMask,o)}));return this.addToCache(r,a),{entities:a,count:a.length,executionTime:performance.now()-t,fromCache:!1}},e.queryByTag=function(t){var e=performance.now();this.queryStats.totalQueries++;var n="tag:"+t,i=this.getFromCache(n);if(i)return this.queryStats.cacheHits++,{entities:i,count:i.length,executionTime:performance.now()-e,fromCache:!0};this.queryStats.indexHits++;var r=Array.from(this.entityIndex.byTag.get(t)||[]);return this.addToCache(n,r),{entities:r,count:r.length,executionTime:performance.now()-e,fromCache:!1}},e.queryByName=function(t){var e=performance.now();this.queryStats.totalQueries++;var n="name:"+t,i=this.getFromCache(n);if(i)return this.queryStats.cacheHits++,{entities:i,count:i.length,executionTime:performance.now()-e,fromCache:!0};this.queryStats.indexHits++;var r=Array.from(this.entityIndex.byName.get(t)||[]);return this.addToCache(n,r),{entities:r,count:r.length,executionTime:performance.now()-e,fromCache:!1}},e.queryByComponent=function(t){var e=performance.now();this.queryStats.totalQueries++;var n="component:"+P(t),i=this.getFromCache(n);if(i)return this.queryStats.cacheHits++,{entities:i,count:i.length,executionTime:performance.now()-e,fromCache:!0};this.queryStats.indexHits++;var r=Array.from(this.entityIndex.byComponentType.get(t)||[]);return this.addToCache(n,r),{entities:r,count:r.length,executionTime:performance.now()-e,fromCache:!1}},e.getFromCache=function(t){var e=this.queryCache.get(t);return e?Date.now()-e.timestamp>this.cacheTimeout?(this.queryCache.delete(t),null):(e.hitCount++,e.entities):null},e.addToCache=function(t,e){this.queryCache.size>=this.cacheMaxSize&&this.cleanupCache(),this.queryCache.set(t,{entities:[].concat(e),timestamp:Date.now(),hitCount:0})},e.cleanupCache=function(){for(var t,e=Date.now(),n=o(this.queryCache.entries());!(t=n()).done;){var i=t.value,r=i[0];e-i[1].timestamp>this.cacheTimeout&&this.queryCache.delete(r)}if(this.queryCache.size>=this.cacheMaxSize){var s=Array.from(this.queryCache.entries());s.sort((function(t,e){return t[1].hitCount-e[1].hitCount}));for(var a=Math.floor(.2*this.cacheMaxSize),c=0;c<a&&c<s.length;c++)this.queryCache.delete(s[c][0])}},e.clearQueryCache=function(){this.queryCache.clear()},e.clearCache=function(){this.clearQueryCache()},e.batchUpdateComponents=function(t){for(var e,n=this,i=[],r=function(){var t=e.value,r=n.entities.find((function(e){return e.id===t.entityId}));r&&(n.removeEntityFromIndexes(r),i.push(r))},s=o(t);!(e=s()).done;)r();for(var a=0,c=i;a<c.length;a++){var u=c[a];this.addEntityToIndexes(u)}for(var h=0,l=i;h<l.length;h++){var d=l[h];this.dirtyTrackingSystem.markDirty(d,exports.DirtyFlag.COMPONENT_MODIFIED,[])}this.clearQueryCache()},e.createComponentMask=function(t){for(var e,n=M.clone(M.ZERO),i=!1,r=o(t);!(e=r()).done;){var s=e.value;try{var a=L.getBitMask(s);M.orInPlace(n,a),i=!0}catch(t){this._logger.warn("组件类型 "+P(s)+" 未注册,跳过")}}return i?n:{lo:4294967295,hi:4294967295}},e.getAllEntities=function(){return[].concat(this.entities)},e.getStats=function(){return{entityCount:this.entities.length,indexStats:{maskIndexSize:this.entityIndex.byMask.size,componentIndexSize:this.entityIndex.byComponentType.size,tagIndexSize:this.entityIndex.byTag.size,nameIndexSize:this.entityIndex.byName.size},queryStats:a({},this.queryStats,{cacheHitRate:this.queryStats.totalQueries>0?(this.queryStats.cacheHits/this.queryStats.totalQueries*100).toFixed(2)+"%":"0%"}),optimizationStats:{componentIndex:this.componentIndexManager.getStats(),archetypeSystem:this.archetypeSystem.getAllArchetypes().map((function(t){return{id:t.id,componentTypes:t.componentTypes.map((function(t){return P(t)})),entityCount:t.entities.length}})),dirtyTracking:this.dirtyTrackingSystem.getStats()},cacheStats:{size:this.queryCache.size,hitRate:this.queryStats.totalQueries>0?(this.queryStats.cacheHits/this.queryStats.totalQueries*100).toFixed(2)+"%":"0%"}}},e.configureDirtyTracking=function(t,e){this.dirtyTrackingSystem.configureBatchProcessing(t,e)},e.optimizePerformance=function(){this.dirtyTrackingSystem.processDirtyEntities(),this.cleanupCache(),this.componentIndexManager.getStats()},e.beginFrame=function(){this.dirtyTrackingSystem.beginFrame()},e.endFrame=function(){this.dirtyTrackingSystem.endFrame()},e.markEntityDirty=function(t,e){this.queryStats.dirtyChecks++,this.dirtyTrackingSystem.markDirty(t,exports.DirtyFlag.COMPONENT_MODIFIED,e),this.clearQueryCache()},e.getEntityArchetype=function(t){return this.archetypeSystem.getEntityArchetype(t)},s(t,[{key:"version",get:function(){return this._version}}])}(),at=function(){function t(t){this._logger=D("QueryBuilder"),this.conditions=[],this.querySystem=t}var e=t.prototype;return e.withAll=function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];return this.conditions.push({type:nt.ALL,componentTypes:e,mask:this.createComponentMask(e)}),this},e.withAny=function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];return this.conditions.push({type:nt.ANY,componentTypes:e,mask:this.createComponentMask(e)}),this},e.without=function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];return this.conditions.push({type:nt.NONE,componentTypes:e,mask:this.createComponentMask(e)}),this},e.execute=function(){var t,e,n,i=performance.now();if(1===this.conditions.length){var r=this.conditions[0];switch(r.type){case nt.ALL:return(t=this.querySystem).queryAll.apply(t,r.componentTypes);case nt.ANY:return(e=this.querySystem).queryAny.apply(e,r.componentTypes);case nt.NONE:return(n=this.querySystem).queryNone.apply(n,r.componentTypes)}}return{entities:[],count:0,executionTime:performance.now()-i,fromCache:!1}},e.createComponentMask=function(t){for(var e,n=M.clone(M.ZERO),i=o(t);!(e=i()).done;){var r=e.value;try{var s=L.getBitMask(r);M.orInPlace(n,s)}catch(t){this._logger.warn("组件类型 "+P(r)+" 未注册,跳过")}}return n},e.reset=function(){return this.conditions=[],this},t}(),ct=function(){function t(){this.listeners=new Map,this.stats=new Map,this.batchQueue=new Map,this.batchTimers=new Map,this.batchConfigs=new Map,this.nextListenerId=0,this.isEnabled=!0,this.maxListeners=100}var e=t.prototype;return e.on=function(t,e,n){return void 0===n&&(n={}),this.addListener(t,e,n)},e.once=function(t,e,n){return void 0===n&&(n={}),this.addListener(t,e,a({},n,{once:!0}))},e.onAsync=function(t,e,n){return void 0===n&&(n={}),this.addListener(t,e,a({},n,{async:!0}))},e.off=function(t,e){var n=this.listeners.get(t);if(!n)return!1;var i=n.findIndex((function(t){return t.id===e}));return-1!==i&&(n.splice(i,1),0===n.length&&(this.listeners.delete(t),this.stats.delete(t)),!0)},e.offAll=function(t){this.listeners.delete(t),this.stats.delete(t),this.clearBatch(t)},e.emit=function(){var t=n(l().m((function t(e,n){var i;return l().w((function(t){for(;;)switch(t.n){case 0:if(this.isEnabled){t.n=1;break}return t.a(2);case 1:if(null==(i=this.batchConfigs.get(e))||!i.enabled){t.n=2;break}return this.addToBatch(e,n),t.a(2);case 2:return t.n=3,this.executeEvent(e,n);case 3:return t.a(2)}}),t,this)})));return function(e,n){return t.apply(this,arguments)}}(),e.emitSync=function(e,n){if(this.isEnabled){var i=this.listeners.get(e);if(i&&0!==i.length){for(var r,s=performance.now(),a=[],c=o(this.sortListenersByPriority(i));!(r=c()).done;){var u=r.value;if(!u.config.async)try{u.config.context?u.handler.call(u.config.context,n):u.handler(n),u.config.once&&a.push(u.id)}catch(n){t._logger.error("事件处理器执行错误 "+e+":",n)}}this.removeListeners(e,a),this.updateStats(e,performance.now()-s)}}},e.setBatchConfig=function(t,e){this.batchConfigs.set(t,e)},e.flushBatch=function(t){var e=this.batchQueue.get(t);if(e&&0!==e.length){var n=this.batchTimers.get(t);n&&(clearTimeout(n),this.batchTimers.delete(t)),this.processBatch(t,e),this.batchQueue.delete(t)}},e.getStats=function(t){return t?this.stats.get(t)||this.createEmptyStats(t):new Map(this.stats)},e.resetStats=function(t){t?this.stats.delete(t):this.stats.clear()},e.setEnabled=function(t){this.isEnabled=t},e.hasListeners=function(t){var e=this.listeners.get(t);return!!e&&e.length>0},e.getListenerCount=function(t){var e=this.listeners.get(t);return e?e.length:0},e.clear=function(){this.listeners.clear(),this.stats.clear(),this.clearAllBatches()},e.setMaxListeners=function(t){this.maxListeners=t},e.addListener=function(e,n,i){var r=this.listeners.get(e);if(r||(r=[],this.listeners.set(e,r)),r.length>=this.maxListeners)return t._logger.warn("事件类型 "+e+" 的监听器数量超过最大限制 ("+this.maxListeners+")"),"";var s="listener_"+this.nextListenerId++,o={handler:n,config:a({priority:0},i),id:s};return r.push(o),this.stats.has(e)||this.stats.set(e,this.createEmptyStats(e)),s},e.executeEvent=function(){var e=n(l().m((function e(i,r){var s,a,c,u,h,d,f,p,m,y;return l().w((function(e){for(;;)switch(e.n){case 0:if((s=this.listeners.get(i))&&0!==s.length){e.n=1;break}return e.a(2);case 1:for(a=performance.now(),c=[],u=this.sortListenersByPriority(s),h=u.filter((function(t){return!t.config.async})),d=u.filter((function(t){return t.config.async})),f=o(h);!(p=f()).done;){m=p.value;try{m.config.context?m.handler.call(m.config.context,r):m.handler(r),m.config.once&&c.push(m.id)}catch(e){t._logger.error("同步事件处理器执行错误 "+i+":",e)}}return y=d.map(function(){var e=n(l().m((function e(n){var s;return l().w((function(e){for(;;)switch(e.p=e.n){case 0:if(e.p=0,!n.config.context){e.n=2;break}return e.n=1,n.handler.call(n.config.context,r);case 1:e.n=3;break;case 2:return e.n=3,n.handler(r);case 3:n.config.once&&c.push(n.id),e.n=5;break;case 4:e.p=4,s=e.v,t._logger.error("异步事件处理器执行错误 "+i+":",s);case 5:return e.a(2)}}),e,null,[[0,4]])})));return function(t){return e.apply(this,arguments)}}()),e.n=2,Promise.all(y);case 2:this.removeListeners(i,c),this.updateStats(i,performance.now()-a);case 3:return e.a(2)}}),e,this)})));return function(t,n){return e.apply(this,arguments)}}(),e.sortListenersByPriority=function(t){return t.slice().sort((function(t,e){return(e.config.priority||0)-(t.config.priority||0)}))},e.removeListeners=function(t,e){if(0!==e.length){var n=this.listeners.get(t);if(n){for(var i,r=function(){var t=i.value,e=n.findIndex((function(e){return e.id===t}));-1!==e&&n.splice(e,1)},s=o(e);!(i=s()).done;)r();0===n.length&&(this.listeners.delete(t),this.stats.delete(t))}}},e.addToBatch=function(t,e){var n=this,i=this.batchQueue.get(t);i||(i=[],this.batchQueue.set(t,i)),i.push(e);var r=this.batchConfigs.get(t);if(i.length>=r.batchSize)this.flushBatch(t);else if(!this.batchTimers.has(t)){var s=setTimeout((function(){n.flushBatch(t)}),r.delay);this.batchTimers.set(t,s)}},e.processBatch=function(){var t=n(l().m((function t(e,n){var i;return l().w((function(t){for(;;)switch(t.n){case 0:return i={type:e,events:n,count:n.length,timestamp:Date.now()},t.n=1,this.executeEvent(e+":batch",i);case 1:return t.a(2)}}),t,this)})));return function(e,n){return t.apply(this,arguments)}}(),e.clearBatch=function(t){this.batchQueue.delete(t);var e=this.batchTimers.get(t);e&&(clearTimeout(e),this.batchTimers.delete(t))},e.clearAllBatches=function(){this.batchQueue.clear();for(var t,e=o(this.batchTimers.values());!(t=e()).done;){var n=t.value;clearTimeout(n)}this.batchTimers.clear(),this.batchConfigs.clear()},e.updateStats=function(t,e){var n=this.stats.get(t);n||(n=this.createEmptyStats(t),this.stats.set(t,n)),n.triggerCount++,n.totalExecutionTime+=e,n.averageExecutionTime=n.totalExecutionTime/n.triggerCount,n.lastTriggerTime=Date.now(),n.listenerCount=this.getListenerCount(t)},e.createEmptyStats=function(t){return{eventType:t,listenerCount:0,triggerCount:0,totalExecutionTime:0,averageExecutionTime:0,lastTriggerTime:0}},t}();ct._logger=D("EventSystem"),exports.ECSEventType=void 0,(rt=exports.ECSEventType||(exports.ECSEventType={})).ENTITY_CREATED="entity:created",rt.ENTITY_DESTROYED="entity:destroyed",rt.ENTITY_ENABLED="entity:enabled",rt.ENTITY_DISABLED="entity:disabled",rt.ENTITY_TAG_ADDED="entity:tag:added",rt.ENTITY_TAG_REMOVED="entity:tag:removed",rt.ENTITY_NAME_CHANGED="entity:name:changed",rt.COMPONENT_ADDED="component:added",rt.COMPONENT_REMOVED="component:removed",rt.COMPONENT_MODIFIED="component:modified",rt.COMPONENT_ENABLED="component:enabled",rt.COMPONENT_DISABLED="component:disabled",rt.SYSTEM_ADDED="system:added",rt.SYSTEM_REMOVED="system:removed",rt.SYSTEM_ENABLED="system:enabled",rt.SYSTEM_DISABLED="system:disabled",rt.SYSTEM_PROCESSING_START="system:processing:start",rt.SYSTEM_PROCESSING_END="system:processing:end",rt.SYSTEM_ERROR="system:error",rt.SCENE_CREATED="scene:created",rt.SCENE_DESTROYED="scene:destroyed",rt.SCENE_ACTIVATED="scene:activated",rt.SCENE_DEACTIVATED="scene:deactivated",rt.SCENE_PAUSED="scene:paused",rt.SCENE_RESUMED="scene:resumed",rt.QUERY_EXECUTED="query:executed",rt.QUERY_CACHE_HIT="query:cache:hit",rt.QUERY_CACHE_MISS="query:cache:miss",rt.QUERY_OPTIMIZED="query:optimized",rt.PERFORMANCE_WARNING="performance:warning",rt.PERFORMANCE_CRITICAL="performance:critical",rt.MEMORY_USAGE_HIGH="memory:usage:high",rt.FRAME_RATE_DROP="frame:rate:drop",rt.INDEX_CREATED="index:created",rt.INDEX_UPDATED="index:updated",rt.INDEX_OPTIMIZED="index:optimized",rt.ARCHETYPE_CREATED="archetype:created",rt.ARCHETYPE_ENTITY_ADDED="archetype:entity:added",rt.ARCHETYPE_ENTITY_REMOVED="archetype:entity:removed",rt.DIRTY_MARK_ADDED="dirty:mark:added",rt.DIRTY_BATCH_PROCESSED="dirty:batch:processed",rt.ERROR_OCCURRED="error:occurred",rt.WARNING_ISSUED="warning:issued",rt.FRAMEWORK_INITIALIZED="framework:initialized",rt.FRAMEWORK_SHUTDOWN="framework:shutdown",rt.DEBUG_INFO="debug:info",rt.DEBUG_STATS_UPDATED="debug:stats:updated",exports.EventPriority=void 0,(st=exports.EventPriority||(exports.EventPriority={}))[st.LOWEST=0]="LOWEST",st[st.LOW=25]="LOW",st[st.NORMAL=50]="NORMAL",st[st.HIGH=75]="HIGH",st[st.HIGHEST=100]="HIGHEST",st[st.CRITICAL=200]="CRITICAL";var ut={ENTITY:{CREATED:exports.ECSEventType.ENTITY_CREATED,DESTROYED:exports.ECSEventType.ENTITY_DESTROYED,ENABLED:exports.ECSEventType.ENTITY_ENABLED,DISABLED:exports.ECSEventType.ENTITY_DISABLED,TAG_ADDED:exports.ECSEventType.ENTITY_TAG_ADDED,TAG_REMOVED:exports.ECSEventType.ENTITY_TAG_REMOVED,NAME_CHANGED:exports.ECSEventType.ENTITY_NAME_CHANGED},COMPONENT:{ADDED:exports.ECSEventType.COMPONENT_ADDED,REMOVED:exports.ECSEventType.COMPONENT_REMOVED,MODIFIED:exports.ECSEventType.COMPONENT_MODIFIED,ENABLED:exports.ECSEventType.COMPONENT_ENABLED,DISABLED:exports.ECSEventType.COMPONENT_DISABLED},SYSTEM:{ADDED:exports.ECSEventType.SYSTEM_ADDED,REMOVED:exports.ECSEventType.SYSTEM_REMOVED,ENABLED:exports.ECSEventType.SYSTEM_ENABLED,DISABLED:exports.ECSEventType.SYSTEM_DISABLED,PROCESSING_START:exports.ECSEventType.SYSTEM_PROCESSING_START,PROCESSING_END:exports.ECSEventType.SYSTEM_PROCESSING_END,ERROR:exports.ECSEventType.SYSTEM_ERROR},PERFORMANCE:{WARNING:exports.ECSEventType.PERFORMANCE_WARNING,CRITICAL:exports.ECSEventType.PERFORMANCE_CRITICAL,MEMORY_HIGH:exports.ECSEventType.MEMORY_USAGE_HIGH,FRAME_DROP:exports.ECSEventType.FRAME_RATE_DROP}},ht=function(){function t(){}return t.isValid=function(t){return this.validTypes.has(t)},t.getAllValidTypes=function(){return Array.from(this.validTypes)},t.addCustomType=function(t){this.validTypes.add(t)},t.removeCustomType=function(t){this.validTypes.delete(t)},t}();ht.validTypes=new Set([].concat(Object.values(exports.ECSEventType),Object.values(ut.ENTITY),Object.values(ut.COMPONENT),Object.values(ut.SYSTEM),Object.values(ut.PERFORMANCE)));var lt=function(){function t(t){void 0===t&&(t=!1),this.eventIdCounter=0,this.isDebugMode=!1,this.eventSystem=new ct,this.isDebugMode=t}var e=t.prototype;return e.emit=function(e,n){this.validateEventType(e);var i=this.enhanceEventData(e,n);this.isDebugMode&&t._logger.info("发射事件: "+e,i),this.eventSystem.emitSync(e,i)},e.emitAsync=function(){var e=n(l().m((function e(n,i){var r;return l().w((function(e){for(;;)switch(e.n){case 0:return this.validateEventType(n),r=this.enhanceEventData(n,i),this.isDebugMode&&t._logger.info("发射异步事件: "+n,r),e.n=1,this.eventSystem.emit(n,r);case 1:return e.a(2)}}),e,this)})));return function(t,n){return e.apply(this,arguments)}}(),e.on=function(e,n,i){void 0===i&&(i={}),this.validateEventType(e);var r={once:i.once||!1,priority:i.priority||exports.EventPriority.NORMAL,async:i.async||!1,context:i.context};return this.isDebugMode&&t._logger.info("添加监听器: "+e,r),this.eventSystem.on(e,n,r)},e.once=function(t,e,n){return void 0===n&&(n={}),this.on(t,e,a({},n,{once:!0}))},e.onAsync=function(t,e,n){return void 0===n&&(n={}),this.on(t,e,a({},n,{async:!0}))},e.off=function(e,n){return this.isDebugMode&&t._logger.info("移除监听器: "+n+" 事件: "+e),this.eventSystem.off(e,n)},e.offAll=function(e){this.isDebugMode&&t._logger.info("移除所有监听器: "+e),this.eventSystem.offAll(e)},e.hasListeners=function(t){return this.eventSystem.hasListeners(t)},e.getStats=function(t){var e=this,n=this.eventSystem.getStats(t);if(n instanceof Map){var i=new Map;return n.forEach((function(t,n){i.set(n,e.convertEventStats(t))})),i}return this.convertEventStats(n)},e.clear=function(){this.isDebugMode&&t._logger.info("清空所有监听器"),this.eventSystem.clear()},e.setEnabled=function(t){this.eventSystem.setEnabled(t)},e.setDebugMode=function(t){this.isDebugMode=t},e.setMaxListeners=function(t){this.eventSystem.setMaxListeners(t)},e.getListenerCount=function(t){return this.eventSystem.getListenerCount(t)},e.setBatchConfig=function(t,e,n){this.eventSystem.setBatchConfig(t,{batchSize:e,delay:n,enabled:!0})},e.flushBatch=function(t){this.eventSystem.flushBatch(t)},e.resetStats=function(t){this.eventSystem.resetStats(t)},e.emitEntityCreated=function(t){this.emit(exports.ECSEventType.ENTITY_CREATED,t)},e.emitEntityDestroyed=function(t){this.emit(exports.ECSEventType.ENTITY_DESTROYED,t)},e.emitComponentAdded=function(t){this.emit(exports.ECSEventType.COMPONENT_ADDED,t)},e.emitComponentRemoved=function(t){this.emit(exports.ECSEventType.COMPONENT_REMOVED,t)},e.emitSystemAdded=function(t){this.emit(exports.ECSEventType.SYSTEM_ADDED,t)},e.emitSystemRemoved=function(t){this.emit(exports.ECSEventType.SYSTEM_REMOVED,t)},e.emitSceneChanged=function(t){this.emit(exports.ECSEventType.SCENE_ACTIVATED,t)},e.emitPerformanceWarning=function(t){this.emit(exports.ECSEventType.PERFORMANCE_WARNING,t)},e.onEntityCreated=function(t,e){return this.on(exports.ECSEventType.ENTITY_CREATED,t,e)},e.onComponentAdded=function(t,e){return this.on(exports.ECSEventType.COMPONENT_ADDED,t,e)},e.onSystemError=function(t,e){return this.on(exports.ECSEventType.SYSTEM_ERROR,t,e)},e.onPerformanceWarning=function(t,e){return this.on(exports.ECSEventType.PERFORMANCE_WARNING,t,e)},e.validateEventType=function(e){ht.isValid(e)||(this.isDebugMode&&t._logger.warn("未知事件类型: "+e),this.isDebugMode&&ht.addCustomType(e))},e.enhanceEventData=function(t,e){if(null==e)return{timestamp:Date.now(),eventId:t+"_"+ ++this.eventIdCounter,source:"EventBus"};var n=e;return n.timestamp||(n.timestamp=Date.now()),n.eventId||(n.eventId=t+"_"+ ++this.eventIdCounter),n.source||(n.source="EventBus"),n},e.convertEventStats=function(t){return{eventType:t.eventType,listenerCount:t.listenerCount,triggerCount:t.triggerCount,totalExecutionTime:t.totalExecutionTime,averageExecutionTime:t.averageExecutionTime,lastTriggerTime:t.lastTriggerTime}},t}();lt._logger=D("EventBus");var dt=function(){function t(){}return t.getInstance=function(t){return void 0===t&&(t=!1),this.instance||(this.instance=new lt(t)),this.instance},t.reset=function(t){return void 0===t&&(t=!1),this.instance&&this.instance.clear(),this.instance=new lt(t),this.instance},t}();var ft=function(){function t(t){var e=this;this.name="",this._didSceneBegin=!1,this.entities=new H(this),this.entityProcessors=new G,this.identifierPool=new Y,this.componentStorageManager=new q,this.querySystem=new ot,this.eventSystem=new ct,null!=t&&t.name&&(this.name=t.name),U.eventBus||(U.eventBus=new lt(!1)),U.eventBus&&U.eventBus.onComponentAdded((function(t){e.eventSystem.emitSync("component:added",t)}))}var e=t.prototype;return e.initialize=function(){},e.onStart=function(){},e.unload=function(){},e.begin=function(){null!=this.entityProcessors&&this.entityProcessors.begin(),this._didSceneBegin=!0,this.onStart()},e.end=function(){this._didSceneBegin=!1,this.entities.removeAllEntities(),this.querySystem.setEntities([]),this.componentStorageManager.clear(),this.entityProcessors&&this.entityProcessors.end(),this.unload()},e.update=function(){this.entities.updateLists(),null!=this.entityProcessors&&this.entityProcessors.update(),this.entities.update(),null!=this.entityProcessors&&this.entityProcessors.lateUpdate()},e.createEntity=function(t){var e=new U(t,this.identifierPool.checkOut());return this.eventSystem.emitSync("entity:created",{entityName:t,entity:e,scene:this}),this.addEntity(e)},e.addEntity=function(t,e){return void 0===e&&(e=!1),this.entities.add(t),t.scene=this,this.querySystem.addEntity(t,e),this.eventSystem.emitSync("entity:added",{entity:t,scene:this}),t},e.createEntities=function(t,e){void 0===e&&(e="Entity");for(var n=[],i=0;i<t;i++){var r=new U(e+"_"+i,this.identifierPool.checkOut());r.scene=this,n.push(r)}for(var s=0,o=n;s<o.length;s++){var a=o[s];this.entities.add(a)}return this.querySystem.addEntitiesUnchecked(n),this.eventSystem.emitSync("entities:batch_added",{entities:n,scene:this,count:t}),n},e.destroyAllEntities=function(){this.entities.removeAllEntities(),this.querySystem.setEntities([])},e.findEntity=function(t){return this.entities.findEntity(t)},e.findEntityById=function(t){return this.entities.findEntityById(t)},e.findEntitiesByTag=function(t){for(var e,n=[],i=o(this.entities.buffer);!(e=i()).done;){var r=e.value;r.tag===t&&n.push(r)}return n},e.getEntityByName=function(t){return this.findEntity(t)},e.getEntitiesByTag=function(t){return this.findEntitiesByTag(t)},e.addEntityProcessor=function(t){return this.entityProcessors.processors.includes(t)||(t.scene=this,this.entityProcessors.add(t),t.initialize(),t.setUpdateOrder(this.entityProcessors.count-1)),t},e.addSystem=function(t){return this.addEntityProcessor(t)},e.removeEntityProcessor=function(t){this.entityProcessors.remove(t),t.reset(),t.scene=null},e.getEntityProcessor=function(t){return this.entityProcessors.getProcessor(t)},e.getStats=function(){return{entityCount:this.entities.count,processorCount:this.entityProcessors.count,componentStorageStats:this.componentStorageManager.getAllStats()}},e.getDebugInfo=function(){return{name:this.name||this.constructor.name,entityCount:this.entities.count,processorCount:this.entityProcessors.count,isRunning:this._didSceneBegin,entities:this.entities.buffer.map((function(t){return{name:t.name,id:t.id,componentCount:t.components.length,componentTypes:t.components.map((function(t){return z(t)}))}})),processors:this.entityProcessors.processors.map((function(t){var e;return{name:B(t),updateOrder:t.updateOrder,entityCount:(null===(e=t._entities)||void 0===e?void 0:e.length)||0}})),componentStats:this.componentStorageManager.getAllStats()}},s(t,[{key:"systems",get:function(){return this.entityProcessors.processors}}])}(),pt=function(){function t(){this.scene=new ft}var e=t.prototype;return e.named=function(t){return this.scene.name=t,this},e.withEntity=function(t){return this.scene.addEntity(t),this},e.withEntityBuilder=function(t){var e=t(new j(this.scene,this.scene.componentStorageManager)).build();return this.scene.addEntity(e),this},e.withEntities=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 s=r[i];this.scene.addEntity(s)}return this},e.withSystem=function(t){return this.scene.addSystem(t),this},e.withSystems=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 s=r[i];this.scene.addSystem(s)}return this},e.build=function(){return this.scene},t}(),mt=function(){function t(t){for(var e=arguments.length,n=new Array(e>1?e-1:0),r=1;r<e;r++)n[r-1]=arguments[r];this.component=i(t,n)}var e=t.prototype;return e.set=function(t,e){return this.component[t]=e,this},e.configure=function(t){return t(this.component),this},e.setIf=function(t,e,n){return t&&(this.component[e]=n),this},e.build=function(){return this.component},t}(),yt=function(){function t(t){this.entities=t}var e=t.prototype;return e.addComponent=function(t){for(var e,n=o(this.entities);!(e=n()).done;){e.value.addComponent(t)}return this},e.removeComponent=function(t){for(var e,n=o(this.entities);!(e=n()).done;){e.value.removeComponentByType(t)}return this},e.setActive=function(t){for(var e,n=o(this.entities);!(e=n()).done;){e.value.active=t}return this},e.setTag=function(t){for(var e,n=o(this.entities);!(e=n()).done;){e.value.tag=t}return this},e.forEach=function(t){return this.entities.forEach(t),this},e.filter=function(e){return new t(this.entities.filter(e))},e.toArray=function(){return this.entities.slice()},e.count=function(){return this.entities.length},t}(),gt=function(){function t(t,e,n){this.scene=t,this.querySystem=e,this.eventSystem=n}var e=t.prototype;return e.createEntity=function(){return new j(this.scene,this.scene.componentStorageManager)},e.createScene=function(){return new pt},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];return i(mt,[t].concat(n))},e.query=function(){return new at(this.querySystem)},e.find=function(){var t;return(t=this.querySystem).queryAll.apply(t,arguments).entities},e.findFirst=function(){var t,e=(t=this.querySystem).queryAll.apply(t,arguments);return e.entities.length>0?e.entities[0]:null},e.findByName=function(t){return this.scene.findEntity(t)},e.findByTag=function(t){return this.scene.findEntitiesByTag(t)},e.emit=function(t,e){this.eventSystem.emitSync(t,e)},e.emitAsync=function(){var t=n(l().m((function t(e,n){return l().w((function(t){for(;;)switch(t.n){case 0:return t.n=1,this.eventSystem.emit(e,n);case 1:return t.a(2)}}),t,this)})));return function(e,n){return t.apply(this,arguments)}}(),e.on=function(t,e){return this.eventSystem.on(t,e)},e.once=function(t,e){return this.eventSystem.once(t,e)},e.off=function(t,e){this.eventSystem.off(t,e)},e.batch=function(t){return new yt(t)},e.getStats=function(){return{entityCount:this.scene.entities.count,systemCount:this.scene.systems.length,componentStats:this.scene.componentStorageManager.getAllStats(),queryStats:this.querySystem.getStats(),eventStats:this.eventSystem.getStats()}},t}();function vt(t,e,n){return new gt(t,e,n)}var _t=D("World"),Et=function(){function t(t){void 0===t&&(t={}),this._scenes=new Map,this._activeScenes=new Set,this._globalSystems=[],this._isActive=!1,this._config=a({name:"World",debug:!1,maxScenes:10,autoCleanup:!0},t),this.name=this._config.name,this._createdAt=Date.now(),_t.info("创建World: "+this.name)}var e=t.prototype;return e.createScene=function(t,e){if(this._scenes.has(t))throw new Error("Scene ID '"+t+"' 已存在于World '"+this.name+"' 中");if(this._scenes.size>=this._config.maxScenes)throw new Error("World '"+this.name+"' 已达到最大Scene数量限制: "+this._config.maxScenes);var n=e||new ft;return"id"in n&&(n.id=t),"name"in n&&!n.name&&(n.name=t),this._scenes.set(t,n),n.initialize(),_t.info("在World '"+this.name+"' 中创建Scene: "+t),n},e.removeScene=function(t){var e=this._scenes.get(t);return!!e&&(this._activeScenes.has(t)&&this.setSceneActive(t,!1),e.end(),this._scenes.delete(t),_t.info("从World '"+this.name+"' 中移除Scene: "+t),!0)},e.getScene=function(t){return this._scenes.get(t)||null},e.getSceneIds=function(){return Array.from(this._scenes.keys())},e.getAllScenes=function(){return Array.from(this._scenes.values())},e.setSceneActive=function(t,e){var n=this._scenes.get(t);n?e?(this._activeScenes.add(t),n.begin&&n.begin(),_t.debug("在World '"+this.name+"' 中激活Scene: "+t)):(this._activeScenes.delete(t),_t.debug("在World '"+this.name+"' 中停用Scene: "+t)):_t.warn("Scene '"+t+"' 不存在于World '"+this.name+"' 中")},e.isSceneActive=function(t){return this._activeScenes.has(t)},e.getActiveSceneCount=function(){return this._activeScenes.size},e.addGlobalSystem=function(t){return this._globalSystems.includes(t)||(this._globalSystems.push(t),t.initialize&&t.initialize(),_t.debug("在World '"+this.name+"' 中添加全局System: "+t.name)),t},e.removeGlobalSystem=function(t){var e=this._globalSystems.indexOf(t);return-1!==e&&(this._globalSystems.splice(e,1),t.reset&&t.reset(),_t.debug("从World '"+this.name+"' 中移除全局System: "+t.name),!0)},e.getGlobalSystem=function(t){for(var e,n=o(this._globalSystems);!(e=n()).done;){var i=e.value;if(i instanceof t)return i}return null},e.start=function(){if(!this._isActive){this._isActive=!0;for(var t,e=o(this._globalSystems);!(t=e()).done;){var n=t.value;n.initialize&&n.initialize()}_t.info("启动World: "+this.name)}},e.stop=function(){if(this._isActive){for(var t,e=o(this._activeScenes);!(t=e()).done;){var n=t.value;this.setSceneActive(n,!1)}for(var i,r=o(this._globalSystems);!(i=r()).done;){var s=i.value;s.reset&&s.reset()}this._isActive=!1,_t.info("停止World: "+this.name)}},e.updateGlobalSystems=function(){if(this._isActive)for(var t,e=o(this._globalSystems);!(t=e()).done;){var n=t.value;n.update&&n.update()}},e.updateScenes=function(){if(this._isActive){for(var t,e=o(this._activeScenes);!(t=e()).done;){var n=t.value,i=this._scenes.get(n);i&&i.update&&i.update()}this._config.autoCleanup&&this.shouldAutoCleanup()&&this.cleanup()}},e.destroy=function(){_t.info("销毁World: "+this.name),this.stop();for(var t=0,e=Array.from(this._scenes.keys());t<e.length;t++){var n=e[t];this.removeScene(n)}for(var i,r=o(this._globalSystems);!(i=r()).done;){var s=i.value;s.destroy?s.destroy():s.reset&&s.reset()}this._globalSystems.length=0,this._scenes.clear(),this._activeScenes.clear()},e.getStatus=function(){var t=this;return{name:this.name,isActive:this._isActive,sceneCount:this._scenes.size,activeSceneCount:this._activeScenes.size,globalSystemCount:this._globalSystems.length,createdAt:this._createdAt,config:a({},this._config),scenes:Array.from(this._scenes.keys()).map((function(e){var n;return{id:e,isActive:t._activeScenes.has(e),name:(null===(n=t._scenes.get(e))||void 0===n?void 0:n.name)||e}}))}},e.getStats=function(){for(var t,e={totalEntities:0,totalSystems:this._globalSystems.length,memoryUsage:0,performance:{averageUpdateTime:0,maxUpdateTime:0}},n=o(this._scenes.values());!(t=n()).done;){var i=t.value;i.entities&&(e.totalEntities+=i.entities.count),i.systems&&(e.totalSystems+=i.systems.length)}return e},e.shouldAutoCleanup=function(){for(var t,e=Date.now(),n=o(this._scenes);!(t=n()).done;){var i=t.value,r=i[0],s=i[1];if(!this._activeScenes.has(r)&&s.entities&&0===s.entities.count&&e-this._createdAt>3e5)return!0}return!1},e.cleanup=function(){for(var t=Array.from(this._scenes.keys()),e=Date.now(),n=0,i=t;n<i.length;n++){var r=i[n],s=this._scenes.get(r);s&&!this._activeScenes.has(r)&&s.entities&&0===s.entities.count&&e-this._createdAt>3e5&&(this.removeScene(r),_t.debug("自动清理空Scene: "+r+" from World "+this.name))}},s(t,[{key:"isActive",get:function(){return this._isActive}},{key:"sceneCount",get:function(){return this._scenes.size}},{key:"createdAt",get:function(){return this._createdAt}}])}(),St=D("WorldManager"),Tt=function(){function t(t){void 0===t&&(t={}),this._worlds=new Map,this._activeWorlds=new Set,this._cleanupTimer=null,this._isRunning=!1,this._config=a({maxWorlds:50,autoCleanup:!0,cleanupInterval:3e4,debug:!1},t),St.info("WorldManager已初始化",{maxWorlds:this._config.maxWorlds,autoCleanup:this._config.autoCleanup,cleanupInterval:this._config.cleanupInterval}),this.startCleanupTimer()}t.getInstance=function(e){return this._instance||(this._instance=new t(e)),this._instance},t.reset=function(){this._instance&&(this._instance.destroy(),this._instance=null)};var e=t.prototype;return e.createWorld=function(t,e){if(!t||"string"!=typeof t||""===t.trim())throw new Error("World ID不能为空");if(this._worlds.has(t))throw new Error("World ID '"+t+"' 已存在");if(this._worlds.size>=this._config.maxWorlds)throw new Error("已达到最大World数量限制: "+this._config.maxWorlds);var n=a({name:t,debug:this._config.debug},e),i=new Et(n);return this._worlds.set(t,i),St.info("创建World: "+t,{config:n}),i},e.removeWorld=function(t){var e=this._worlds.get(t);return!!e&&(this._activeWorlds.has(t)&&this.setWorldActive(t,!1),e.destroy(),this._worlds.delete(t),St.info("移除World: "+t),!0)},e.getWorld=function(t){return this._worlds.get(t)||null},e.getWorldIds=function(){return Array.from(this._worlds.keys())},e.getAllWorlds=function(){return Array.from(this._worlds.values())},e.setWorldActive=function(t,e){var n=this._worlds.get(t);n?e?(this._activeWorlds.add(t),n.start(),St.debug("激活World: "+t)):(this._activeWorlds.delete(t),n.stop(),St.debug("停用World: "+t)):St.warn("World '"+t+"' 不存在")},e.isWorldActive=function(t){return this._activeWorlds.has(t)},e.getActiveWorlds=function(){for(var t,e=[],n=o(this._activeWorlds);!(t=n()).done;){var i=t.value,r=this._worlds.get(i);r&&e.push(r)}return e},e.startAll=function(){this._isRunning=!0;for(var t,e=o(this._worlds.keys());!(t=e()).done;){var n=t.value;this.setWorldActive(n,!0)}St.info("启动所有World")},e.stopAll=function(){this._isRunning=!1;for(var t,e=o(this._activeWorlds);!(t=e()).done;){var n=t.value;this.setWorldActive(n,!1)}St.info("停止所有World")},e.findWorlds=function(t){for(var e,n=[],i=o(this._worlds.values());!(e=i()).done;){var r=e.value;t(r)&&n.push(r)}return n},e.findWorldByName=function(t){for(var e,n=o(this._worlds.values());!(e=n()).done;){var i=e.value;if(i.name===t)return i}return null},e.getStats=function(){for(var t,e={totalWorlds:this._worlds.size,activeWorlds:this._activeWorlds.size,totalScenes:0,totalEntities:0,totalSystems:0,memoryUsage:0,isRunning:this._isRunning,config:a({},this._config),worlds:[]},n=o(this._worlds);!(t=n()).done;){var i=t.value,r=i[0],s=i[1],c=s.getStats();e.totalScenes+=c.totalSystems,e.totalEntities+=c.totalEntities,e.totalSystems+=c.totalSystems,e.worlds.push(a({id:r,name:s.name,isActive:this._activeWorlds.has(r),sceneCount:s.sceneCount},c))}return e},e.getDetailedStatus=function(){var t=this;return a({},this.getStats(),{worlds:Array.from(this._worlds.entries()).map((function(e){var n=e[0],i=e[1];return{id:n,isActive:t._activeWorlds.has(n),status:i.getStatus()}}))})},e.cleanup=function(){for(var t,e=[],n=o(this._worlds);!(t=n()).done;){var i=t.value,r=i[0],s=i[1];this.shouldCleanupWorld(s)&&e.push(r)}for(var a=0,c=e;a<c.length;a++){var u=c[a];this.removeWorld(u)}return e.length>0&&St.debug("清理了 "+e.length+" 个World"),e.length},e.destroy=function(){St.info("正在销毁WorldManager..."),this.stopCleanupTimer(),this.stopAll();for(var t=0,e=Array.from(this._worlds.keys());t<e.length;t++){var n=e[t];this.removeWorld(n)}this._worlds.clear(),this._activeWorlds.clear(),this._isRunning=!1,St.info("WorldManager已销毁")},e.startCleanupTimer=function(){var t=this;this._config.autoCleanup&&!this._cleanupTimer&&(this._cleanupTimer=setInterval((function(){t.cleanup()}),this._config.cleanupInterval),St.debug("启动World清理定时器,间隔: "+this._config.cleanupInterval+"ms"))},e.stopCleanupTimer=function(){this._cleanupTimer&&(clearInterval(this._cleanupTimer),this._cleanupTimer=null,St.debug("停止World清理定时器"))},e.shouldCleanupWorld=function(t){return!t.isActive&&((0===t.sceneCount||!t.getAllScenes().some((function(t){return t.entities&&t.entities.count>0})))&&Date.now()-t.createdAt>6e5)},s(t,[{key:"worldCount",get:function(){return this._worlds.size}},{key:"activeWorldCount",get:function(){return this._activeWorlds.size}},{key:"isRunning",get:function(){return this._isRunning}},{key:"config",get:function(){return a({},this._config)}}])}();Tt._instance=null;var Ct=function(){function t(t){if(t&&"object"==typeof t)this._value=M.clone(t);else if("number"==typeof t)this._value=M.fromNumber(t);else if("string"==typeof t){var e=parseInt(t,10);this._value=M.fromNumber(e)}else this._value=M.clone(M.ZERO)}var e=t.prototype;return e.set=function(t){if(t<0)throw new Error("Bit index cannot be negative");if(t>=64)throw new Error("Bit index exceeds 64-bit limit. ECS framework supports max 64 component types.");M.setBit(this._value,t)},e.clear=function(t){if(t<0)throw new Error("Bit index cannot be negative");t>=64||M.clearBit(this._value,t)},e.get=function(t){if(t<0||t>=64)return!1;var e=M.create(t);return M.hasAny(this._value,e)},e.containsAll=function(t){return M.hasAll(this._value,t._value)},e.intersects=function(t){return M.hasAny(this._value,t._value)},e.excludes=function(t){return M.hasNone(this._value,t._value)},e.clearAll=function(){M.clear(this._value)},e.isEmpty=function(){return M.isZero(this._value)},e.cardinality=function(){return M.popCount(this._value)},e.and=function(e){var n=new t;return M.copy(this._value,n._value),M.andInPlace(n._value,e._value),n},e.or=function(e){var n=new t;return M.copy(this._value,n._value),M.orInPlace(n._value,e._value),n},e.xor=function(e){var n=new t;return M.copy(this._value,n._value),M.xorInPlace(n._value,e._value),n},e.not=function(e){void 0===e&&(e=64),e>64&&(e=64);var n=new t;if(M.copy(this._value,n._value),e<=32){var i=(1<<e)-1;n._value.lo=~n._value.lo&i,n._value.hi=0}else if(n._value.lo=~n._value.lo,e<64){var r=(1<<e-32)-1;n._value.hi=~n._value.hi&r}else n._value.hi=~n._value.hi;return n},e.copyFrom=function(t){M.copy(t._value,this._value)},e.clone=function(){return new t(this._value)},e.getValue=function(){return this._value},e.setValue=function(t){if("object"==typeof t)M.copy(t,this._value);else if("number"==typeof t)this._value=M.fromNumber(t);else{var e=parseInt(t,10);this._value=M.fromNumber(e)}},e.toString=function(){for(var t=[],e=0;e<64;e++)this.get(e)&&t.push(e.toString());return"Bits["+t.join(", ")+"]"},e.toBinaryString=function(t){void 0===t&&(t=64),t>64&&(t=64);for(var e="",n=t-1;n>=0;n--)e+=this.get(n)?"1":"0",n%8==0&&n>0&&(e+=" ");return e},e.toHexString=function(){return M.toString(this._value,16)},t.fromBinaryString=function(e){var n,i=e.replace(/\s/g,"");if(i.length<=32){n={lo:parseInt(i,2)>>>0,hi:0}}else{var r=i.substring(i.length-32),s=i.substring(0,i.length-32);n={lo:parseInt(r,2)>>>0,hi:parseInt(s,2)>>>0}}return new t(n)},t.fromHexString=function(e){var n,i=e.replace(/^0x/i,"");if(i.length<=8){n={lo:parseInt(i,16)>>>0,hi:0}}else{var r=i.substring(i.length-8),s=i.substring(0,i.length-8);n={lo:parseInt(r,16)>>>0,hi:parseInt(s,16)>>>0}}return new t(n)},e.equals=function(t){return M.equals(this._value,t._value)},e.getHighestBitIndex=function(){if(M.isZero(this._value))return-1;if(0!==this._value.hi)for(var t=31;t>=0;t--)if(this._value.hi&1<<t)return t+32;for(var e=31;e>=0;e--)if(this._value.lo&1<<e)return e;return-1},e.getLowestBitIndex=function(){if(M.isZero(this._value))return-1;for(var t=0;t<32;t++)if(this._value.lo&1<<t)return t;for(var e=0;e<32;e++)if(this._value.hi&1<<e)return e+32;return-1},t}(),bt=function(){function t(){this._componentTypes=new Map,this._typeNames=new Map,this._nextTypeId=0}var e=t.prototype;return e.getTypeId=function(t){var e=this._componentTypes.get(t);return void 0===e&&(e=this._nextTypeId++,this._componentTypes.set(t,e),this._typeNames.set(e,P(t))),e},e.getTypeName=function(t){return this._typeNames.get(t)||"Unknown"},e.createBits=function(){for(var t=new Ct,e=arguments.length,n=new Array(e),i=0;i<e;i++)n[i]=arguments[i];for(var r=0,s=n;r<s.length;r++){var o=s[r],a=this.getTypeId(o);t.set(a)}return t},e.getEntityBits=function(t){for(var e,n=new Ct,i=o(t);!(e=i()).done;){var r=e.value,s=this.getTypeId(r.constructor);n.set(s)}return n},e.reset=function(){this._componentTypes.clear(),this._typeNames.clear(),this._nextTypeId=0},s(t,[{key:"registeredTypeCount",get:function(){return this._componentTypes.size}}],[{key:"instance",get:function(){return t._instance||(t._instance=new t),t._instance}}])}(),Mt=function(){function t(){}var e=t.prototype;return e.collectEntityData=function(t){if(!t)return this.getEmptyEntityDebugData();var e,n=t.entities;if(!n)return this.getEmptyEntityDebugData();try{e=n.getStats?n.getStats():this.calculateFallbackEntityStats(n)}catch(t){return{totalEntities:0,activeEntities:0,pendingAdd:0,pendingRemove:0,entitiesPerArchetype:[],topEntitiesByComponents:[],entityHierarchy:[],entityDetailsMap:{}}}var i=this.collectArchetypeData(t);return{totalEntities:e.totalEntities,activeEntities:e.activeEntities,pendingAdd:e.pendingAdd||0,pendingRemove:e.pendingRemove||0,entitiesPerArchetype:i.distribution,topEntitiesByComponents:i.topEntities,entityHierarchy:[],entityDetailsMap:{}}},e.getRawEntityList=function(t){if(!t)return[];var e=t.entities;return null!=e&&e.buffer?e.buffer.map((function(t){var e,n;return{id:t.id,name:t.name||"Entity_"+t.id,active:!1!==t.active,enabled:!1!==t.enabled,activeInHierarchy:!1!==t.activeInHierarchy,componentCount:t.components.length,componentTypes:t.components.map((function(t){return z(t)})),parentId:(null===(e=t.parent)||void 0===e?void 0:e.id)||null,childIds:(null===(n=t.children)||void 0===n?void 0:n.map((function(t){return t.id})))||[],depth:t.getDepth?t.getDepth():0,tag:t.tag||0,updateOrder:t.updateOrder||0}})):[]},e.getEntityDetails=function(t,e){try{var n,i,r;if(!e)return null;var s=e.entities;if(null==s||!s.buffer)return null;var o=s.buffer.find((function(e){return e.id===t}));if(!o)return null;var c=o.getDebugInfo?o.getDebugInfo():this.buildFallbackEntityInfo(o,e),u=this.extractComponentDetails(o.components),h=this.getSceneInfo(e);return a({},c,{scene:h.name,sceneName:h.name,sceneType:h.type,parentName:(null===(n=o.parent)||void 0===n?void 0:n.name)||null,components:u||[],componentCount:(null===(i=o.components)||void 0===i?void 0:i.length)||0,componentTypes:(null===(r=o.components)||void 0===r?void 0:r.map((function(t){return z(t)})))||[]})}catch(t){return{error:"获取实体详情失败: "+(t instanceof Error?t.message:String(t)),scene:"获取失败",components:[],componentCount:0,componentTypes:[]}}},e.getSceneInfo=function(t){var e="当前场景",n="Scene";try{if(t.name&&"string"==typeof t.name&&t.name.trim())e=t.name.trim();else if(t.constructor&&t.constructor.name)e=t.constructor.name,n=t.constructor.name;else if(t._name&&"string"==typeof t._name&&t._name.trim())e=t._name.trim();else{var i,r=null===(i=Object.getPrototypeOf(t))||void 0===i||null===(i=i.constructor)||void 0===i?void 0:i.name;r&&"Object"!==r&&(e=r,n=r)}}catch(t){e="场景名获取失败"}return{name:e,type:n}},e.collectEntityDataWithMemory=function(t){if(!t)return this.getEmptyEntityDebugData();var e,n=t.entities;if(!n)return this.getEmptyEntityDebugData();try{e=n.getStats?n.getStats():this.calculateFallbackEntityStats(n)}catch(t){return{totalEntities:0,activeEntities:0,pendingAdd:0,pendingRemove:0,entitiesPerArchetype:[],topEntitiesByComponents:[],entityHierarchy:[],entityDetailsMap:{}}}var i=this.collectArchetypeDataWithMemory(t);return{totalEntities:e.totalEntities,activeEntities:e.activeEntities,pendingAdd:e.pendingAdd||0,pendingRemove:e.pendingRemove||0,entitiesPerArchetype:i.distribution,topEntitiesByComponents:i.topEntities,entityHierarchy:this.buildEntityHierarchyTree(n),entityDetailsMap:this.buildEntityDetailsMap(n,t)}},e.collectArchetypeData=function(t){var e;if(t&&t.archetypeSystem&&"function"==typeof t.archetypeSystem.getAllArchetypes)return this.extractArchetypeStatistics(t.archetypeSystem);var n={entities:(null===(e=t.entities)||void 0===e?void 0:e.buffer)||[]};return{distribution:this.getArchetypeDistributionFast(n),topEntities:this.getTopEntitiesByComponentsFast(n)}},e.getArchetypeDistributionFast=function(t){var e=new Map;return t&&t.entities&&t.entities.forEach((function(t){var n,i=(null===(n=t.components)||void 0===n?void 0:n.map((function(t){return z(t)})))||[],r=i.length>0?i.sort().join(", "):"无组件",s=e.get(r);s?s.count++:e.set(r,{count:1,componentTypes:i})})),Array.from(e.entries()).map((function(t){return{signature:t[0],count:t[1].count,memory:0}})).sort((function(t,e){return e.count-t.count})).slice(0,20)},e.getTopEntitiesByComponentsFast=function(t){return t&&t.entities?t.entities.map((function(t){var e;return{id:t.id.toString(),name:t.name||"Entity_"+t.id,componentCount:(null===(e=t.components)||void 0===e?void 0:e.length)||0,memory:0}})).sort((function(t,e){return e.componentCount-t.componentCount})).slice(0,10):[]},e.collectArchetypeDataWithMemory=function(t){var e;if(t&&t.archetypeSystem&&"function"==typeof t.archetypeSystem.getAllArchetypes)return this.extractArchetypeStatisticsWithMemory(t.archetypeSystem);var n={entities:(null===(e=t.entities)||void 0===e?void 0:e.buffer)||[]};return{distribution:this.getArchetypeDistributionWithMemory(n),topEntities:this.getTopEntitiesByComponentsWithMemory(n)}},e.extractArchetypeStatistics=function(t){var e=t.getAllArchetypes(),n=[],i=[];return e.forEach((function(t){var e,r,s=(null===(e=t.componentTypes)||void 0===e?void 0:e.map((function(t){return t.name})).join(","))||"Unknown",o=(null===(r=t.entities)||void 0===r?void 0:r.length)||0;n.push({signature:s,count:o,memory:0}),t.entities&&t.entities.slice(0,5).forEach((function(t){var e;i.push({id:t.id.toString(),name:t.name||"Entity_"+t.id,componentCount:(null===(e=t.components)||void 0===e?void 0:e.length)||0,memory:0})}))})),n.sort((function(t,e){return e.count-t.count})),i.sort((function(t,e){return e.componentCount-t.componentCount})),{distribution:n,topEntities:i}},e.extractArchetypeStatisticsWithMemory=function(t){var e=this,n=t.getAllArchetypes(),i=[],r=[];return n.forEach((function(t){var n,s,o=(null===(n=t.componentTypes)||void 0===n?void 0:n.map((function(t){return t.name})).join(","))||"Unknown",a=(null===(s=t.entities)||void 0===s?void 0:s.length)||0,c=0;if(t.entities&&t.entities.length>0){for(var u=Math.min(5,t.entities.length),h=0,l=0;l<u;l++)h+=e.estimateEntityMemoryUsage(t.entities[l]);c=h/u*a}i.push({signature:o,count:a,memory:c}),t.entities&&t.entities.slice(0,5).forEach((function(t){var n;r.push({id:t.id.toString(),name:t.name||"Entity_"+t.id,componentCount:(null===(n=t.components)||void 0===n?void 0:n.length)||0,memory:e.estimateEntityMemoryUsage(t)})}))})),i.sort((function(t,e){return e.count-t.count})),r.sort((function(t,e){return e.componentCount-t.componentCount})),{distribution:i,topEntities:r}},e.getArchetypeDistribution=function(t){var e=new Map;return t&&t.entities&&t.entities.forEach((function(t){var n,i=(null===(n=t.componentMask)||void 0===n?void 0:n.toString())||"0",r=e.get(i);e.set(i,(r||0)+1)})),Array.from(e.entries()).map((function(t){return{signature:t[0],count:t[1],memory:0}})).sort((function(t,e){return e.count-t.count}))},e.getArchetypeDistributionWithMemory=function(t){var e=this,n=new Map;return t&&t.entities&&t.entities.forEach((function(t){var i,r=(null===(i=t.components)||void 0===i?void 0:i.map((function(t){return z(t)})))||[],s=r.length>0?r.sort().join(", "):"无组件",o=n.get(s),a=e.estimateEntityMemoryUsage(t);(isNaN(a)||a<0)&&(a=0),o?(o.count++,o.memory+=a):n.set(s,{count:1,memory:a,componentTypes:r})})),Array.from(n.entries()).map((function(t){var e=t[0],n=t[1];return{signature:e,count:n.count,memory:isNaN(n.memory)?0:n.memory}})).sort((function(t,e){return e.count-t.count}))},e.getTopEntitiesByComponents=function(t){return t&&t.entities?t.entities.map((function(t){var e;return{id:t.id.toString(),name:t.name||"Entity_"+t.id,componentCount:(null===(e=t.components)||void 0===e?void 0:e.length)||0,memory:0}})).sort((function(t,e){return e.componentCount-t.componentCount})):[]},e.getTopEntitiesByComponentsWithMemory=function(t){var e=this;return t&&t.entities?t.entities.map((function(t){var n;return{id:t.id.toString(),name:t.name||"Entity_"+t.id,componentCount:(null===(n=t.components)||void 0===n?void 0:n.length)||0,memory:e.estimateEntityMemoryUsage(t)}})).sort((function(t,e){return e.componentCount-t.componentCount})):[]},e.getEmptyEntityDebugData=function(){return{totalEntities:0,activeEntities:0,pendingAdd:0,pendingRemove:0,entitiesPerArchetype:[],topEntitiesByComponents:[],entityHierarchy:[],entityDetailsMap:{}}},e.calculateFallbackEntityStats=function(t){var e=t.buffer||[],n=e.filter((function(t){return t.enabled&&!t._isDestroyed}));return{totalEntities:e.length,activeEntities:n.length,pendingAdd:0,pendingRemove:0,averageComponentsPerEntity:n.length>0?e.reduce((function(t,e){var n;return t+((null===(n=e.components)||void 0===n?void 0:n.length)||0)}),0)/n.length:0}},e.estimateEntityMemoryUsage=function(t){var e=this;try{var n=0,i=this.calculateObjectSize(t,["components","children","parent"]);return!isNaN(i)&&i>0&&(n+=i),t.components&&Array.isArray(t.components)&&t.components.forEach((function(t){var i=e.calculateObjectSize(t,["entity"]);!isNaN(i)&&i>0&&(n+=i)})),isNaN(n)||n<0?0:n}catch(t){return 0}},e.calculateObjectSize=function(t,e){if(void 0===e&&(e=[]),!t||"object"!=typeof t)return 0;var n=new WeakSet,i=function(t,r){if(void 0===r&&(r=0),!t||"object"!=typeof t||r>=2)return 0;if(n.has(t))return 0;n.add(t);var s=32;try{for(var o=Object.keys(t),a=Math.min(o.length,20),c=0;c<a;c++){var u=o[c];if(!(e.includes(u)||"constructor"===u||"__proto__"===u||u.startsWith("_cc_")||u.startsWith("__"))){var h=t[u];s+=2*u.length,"string"==typeof h?s+=Math.min(2*h.length,200):"number"==typeof h?s+=8:"boolean"==typeof h?s+=4:Array.isArray(h)?s+=40+Math.min(8*h.length,160):"object"==typeof h&&null!==h&&(s+=i(h,r+1))}}}catch(t){return 64}return s};try{var r=i(t);return Math.max(r,32)}catch(t){return 64}},e.buildEntityHierarchyTree=function(t){var e=this;if(null==t||!t.buffer)return[];var n=[];return t.buffer.forEach((function(t){if(!t.parent){var i=e.buildEntityHierarchyNode(t);n.push(i)}})),n.sort((function(t,e){return t.name<e.name?-1:t.name>e.name?1:t.id-e.id})),n},e.buildEntityHierarchyNode=function(t){var e,n=this,i={id:t.id,name:t.name||"Entity_"+t.id,active:!1!==t.active,enabled:!1!==t.enabled,activeInHierarchy:!1!==t.activeInHierarchy,componentCount:t.components.length,componentTypes:t.components.map((function(t){return z(t)})),parentId:(null===(e=t.parent)||void 0===e?void 0:e.id)||null,children:[],depth:t.getDepth?t.getDepth():0,tag:t.tag||0,updateOrder:t.updateOrder||0};(t.children&&t.children.length>0&&(i.children=t.children.map((function(t){return n.buildEntityHierarchyNode(t)}))),"function"==typeof t.getDebugInfo)&&(i=a({},i,t.getDebugInfo()));return t.components&&t.components.length>0&&(i.componentDetails=this.extractComponentDetails(t.components)),i},e.buildEntityDetailsMap=function(t,e){var n=this;if(null==t||!t.buffer)return{};for(var i={},r=t.buffer,s=0;s<r.length;s+=100){r.slice(s,s+100).forEach((function(t){var r,s=t.getDebugInfo?t.getDebugInfo():n.buildFallbackEntityInfo(t,e),o=t.getComponentCacheStats?t.getComponentCacheStats():null,c=n.extractComponentDetails(t.components);i[t.id]=a({},s,{parentName:(null===(r=t.parent)||void 0===r?void 0:r.name)||null,components:c,componentTypes:s.componentTypes||c.map((function(t){return t.typeName})),cachePerformance:o?{hitRate:o.cacheStats.hitRate,size:o.cacheStats.size,maxSize:o.cacheStats.maxSize}:null})}))}return i},e.buildFallbackEntityInfo=function(t,e){var n,i,r,s=this.getSceneInfo(e);return{name:t.name||"Entity_"+t.id,id:t.id,enabled:!1!==t.enabled,active:!1!==t.active,activeInHierarchy:!1!==t.activeInHierarchy,destroyed:t.isDestroyed||!1,scene:s.name,sceneName:s.name,sceneType:s.type,componentCount:t.components.length,componentTypes:t.components.map((function(t){return z(t)})),componentMask:(null===(n=t.componentMask)||void 0===n?void 0:n.toString())||"0",parentId:(null===(i=t.parent)||void 0===i?void 0:i.id)||null,childCount:(null===(r=t.children)||void 0===r?void 0:r.length)||0,childIds:t.children.map((function(t){return t.id}))||[],depth:t.getDepth?t.getDepth():0,tag:t.tag||0,updateOrder:t.updateOrder||0}},e.extractComponentDetails=function(t){var e=this;return t.map((function(t){var n=z(t);if(!n||"Object"===n||"Function"===n)try{var i=bt.instance,r=t.constructor,s=i.getTypeId(r);n=i.getTypeName(s)}catch(t){n="UnknownComponent"}var o={};try{Object.keys(t).forEach((function(n){if(!n.startsWith("_")&&"entity"!==n&&"constructor"!==n){var i=t[n];null!=i&&(o[n]=e.formatPropertyValue(i))}})),0===Object.keys(o).length&&(o._info="该组件没有公开属性",o._componentId=z(t))}catch(e){o._error="属性提取失败",o._componentId=z(t)}return{typeName:n,properties:o}}))},e.getComponentProperties=function(t,e,n){var i=this;try{if(!n)return{};var r=n.entities;if(null==r||!r.buffer)return{};var s=r.buffer.find((function(e){return e.id===t}));if(!s||e>=s.components.length)return{};var o=s.components[e],a={};return Object.keys(o).forEach((function(t){if(!t.startsWith("_")&&"entity"!==t){var e=o[t];null!=e&&(a[t]=i.formatPropertyValue(e))}})),a}catch(t){return{_error:"属性提取失败"}}},e.formatPropertyValue=function(t,e){return void 0===e&&(e=0),null==t?t:"object"!=typeof t?"string"==typeof t&&t.length>200?"[长字符串: "+t.length+"字符] "+t.substring(0,100)+"...":t:0===e?this.formatObjectFirstLevel(t):this.createLazyLoadPlaceholder(t)},e.formatObjectFirstLevel=function(t){var e=this;try{if(Array.isArray(t)){if(0===t.length)return[];if(t.length>10){var n=t.slice(0,3).map((function(t){return e.formatPropertyValue(t,1)}));return{_isLazyArray:!0,_arrayLength:t.length,_sample:n,_summary:"数组["+t.length+"个元素]"}}return t.map((function(t){return e.formatPropertyValue(t,1)}))}var i=Object.keys(t);if(0===i.length)return{};for(var r={},s=0,o=0,a=i;o<a.length;o++){var c=a[o];if(s>=15){r._hasMoreProperties=!0,r._totalProperties=i.length,r._hiddenCount=i.length-s;break}if(!c.startsWith("_")&&!c.startsWith("$")&&"function"!=typeof t[c])try{var u=t[c];null!=u&&(r[c]=this.formatPropertyValue(u,1),s++)}catch(t){r[c]="[访问失败: "+(t instanceof Error?t.message:String(t))+"]",s++}}return r}catch(t){return"[对象解析失败: "+(t instanceof Error?t.message:String(t))+"]"}},e.createLazyLoadPlaceholder=function(t){try{var e,n=(null===(e=t.constructor)||void 0===e?void 0:e.name)||"Object";return{_isLazyObject:!0,_typeName:n,_summary:this.getObjectSummary(t,n),_objectId:this.generateObjectId(t)}}catch(t){return{_isLazyObject:!0,_typeName:"Unknown",_summary:"无法分析的对象: "+(t instanceof Error?t.message:String(t)),_objectId:Math.random().toString(36).substr(2,9)}}},e.getObjectSummary=function(t,e){try{if((e.toLowerCase().includes("vec")||e.toLowerCase().includes("vector"))&&void 0!==t.x&&void 0!==t.y){var n=void 0!==t.z?t.z:"";return e+"("+t.x+", "+t.y+(n?", "+n:"")+")"}if(e.toLowerCase().includes("color")&&void 0!==t.r&&void 0!==t.g&&void 0!==t.b){var i=void 0!==t.a?t.a:1;return e+"("+t.r+", "+t.g+", "+t.b+", "+i+")"}if(e.toLowerCase().includes("node"))return e+": "+(t.name||t._name||"未命名");if(e.toLowerCase().includes("component")){var r,s,o=(null===(r=t.node)||void 0===r?void 0:r.name)||(null===(s=t.node)||void 0===s?void 0:s._name)||"";return e+(o?" on "+o:"")}var a=Object.keys(t);return 0===a.length?e+" (空对象)":e+" ("+a.length+"个属性)"}catch(t){return e+" (无法分析)"}},e.generateObjectId=function(t){try{return void 0!==t.id?"obj_"+t.id:void 0!==t._id?"obj_"+t._id:void 0!==t.uuid?"obj_"+t.uuid:void 0!==t._uuid?"obj_"+t._uuid:"obj_"+Math.random().toString(36).substr(2,9)}catch(t){return"obj_"+Math.random().toString(36).substr(2,9)}},e.expandLazyObject=function(t,e,n,i){try{if(!i)return null;var r=i.entities;if(null==r||!r.buffer)return null;var s=r.buffer.find((function(e){return e.id===t}));if(!s)return null;if(e>=s.components.length)return null;var o=s.components[e],a=this.getObjectByPath(o,n);return a?this.formatObjectFirstLevel(a):null}catch(t){return{error:"展开失败: "+(t instanceof Error?t.message:String(t))}}},e.getObjectByPath=function(t,e){if(!e)return t;for(var n,i=t,r=o(e.split("."));!(n=r()).done;){var s=n.value;if(null==i)return null;if(s.includes("[")&&s.includes("]")){var a=s.substring(0,s.indexOf("[")),c=parseInt(s.substring(s.indexOf("[")+1,s.indexOf("]")));if(a&&(i=i[a]),!(Array.isArray(i)&&c>=0&&c<i.length))return null;i=i[c]}else i=i[s]}return i},t}(),xt=function(){function t(){}return t.prototype.collectSystemData=function(t,e){if(!e)return{totalSystems:0,systemsInfo:[]};var n=e.entityProcessors;if(!n)return{totalSystems:0,systemsInfo:[]};var i=n.processors||[],r=new Map,s=new Map;if(t)try{r=t.getAllSystemStats(),s=t.getAllSystemData()}catch(t){}return{totalSystems:i.length,systemsInfo:i.map((function(t){var e,n=t.systemName||B(t),i=r.get(n),o=s.get(n);return{name:n,type:B(t),entityCount:(null===(e=t.entities)||void 0===e?void 0:e.length)||0,executionTime:(null==i?void 0:i.averageTime)||(null==o?void 0:o.executionTime)||0,minExecutionTime:(null==i?void 0:i.minTime)===Number.MAX_VALUE?0:(null==i?void 0:i.minTime)||0,maxExecutionTime:(null==i?void 0:i.maxTime)||0,executionTimeHistory:(null==i?void 0:i.recentTimes)||[],updateOrder:t.updateOrder||0,enabled:!1!==t.enabled,lastUpdateTime:(null==o?void 0:o.lastUpdateTime)||0}}))}},t}(),wt=function(){function t(){this.frameTimeHistory=[],this.maxHistoryLength=60,this.lastGCCount=0,this.gcCollections=0,this.lastMemoryCheck=0}var e=t.prototype;return e.collectPerformanceData=function(t){var e=g.deltaTime,n=1e3*e,i=e>0?Math.round(1/e):0,r=this.getECSPerformanceData(t),s=r.totalExecutionTime,o=n>0?s/n*100:0,a=0;performance.memory&&(a=performance.memory.usedJSHeapSize/1024/1024),this.frameTimeHistory.push(s),this.frameTimeHistory.length>this.maxHistoryLength&&this.frameTimeHistory.shift();var c=this.frameTimeHistory.filter((function(t){return t>=0}));return{frameTime:s,engineFrameTime:n,ecsPercentage:o,memoryUsage:a,fps:i,averageFrameTime:c.length>0?c.reduce((function(t,e){return t+e}),0)/c.length:s,minFrameTime:c.length>0?Math.min.apply(Math,c):s,maxFrameTime:c.length>0?Math.max.apply(Math,c):s,frameTimeHistory:[].concat(this.frameTimeHistory),systemPerformance:this.getSystemPerformance(t),systemBreakdown:r.systemBreakdown,memoryDetails:this.getMemoryDetails()}},e.getECSPerformanceData=function(t){if(!t)return{totalExecutionTime:0,systemBreakdown:[]};if(!t.enabled){try{t.enabled=!0}catch(t){}return{totalExecutionTime:0,systemBreakdown:[]}}try{var e=0,n=[],i=t.getAllSystemStats();if(0===i.size)return{totalExecutionTime:0,systemBreakdown:[]};for(var r,s=o(i.entries());!(r=s()).done;){var a=r.value,c=a[0],u=a[1],h=u.recentTimes&&u.recentTimes.length>0?u.recentTimes[u.recentTimes.length-1]:u.averageTime||0;e+=h,n.push({systemName:c,executionTime:h,percentage:0})}return n.forEach((function(t){t.percentage=e>0?t.executionTime/e*100:0})),n.sort((function(t,e){return e.executionTime-t.executionTime})),{totalExecutionTime:e,systemBreakdown:n}}catch(t){return{totalExecutionTime:0,systemBreakdown:[]}}},e.getSystemPerformance=function(t){if(!t)return[];try{var e=t.getAllSystemStats(),n=t.getAllSystemData();return Array.from(e.entries()).map((function(t){var e=t[0],i=t[1],r=n.get(e);return{systemName:e,averageTime:i.averageTime||0,maxTime:i.maxTime||0,minTime:i.minTime===Number.MAX_VALUE?0:i.minTime||0,samples:i.executionCount||0,percentage:0,entityCount:(null==r?void 0:r.entityCount)||0,lastExecutionTime:(null==r?void 0:r.executionTime)||0}}))}catch(t){return[]}},e.getMemoryDetails=function(){var t={entities:0,components:0,systems:0,pooled:0,totalMemory:0,usedMemory:0,freeMemory:0,gcCollections:this.updateGCCount()};try{if(performance.memory){var e=performance.memory;if(t.totalMemory=e.jsHeapSizeLimit||536870912,t.usedMemory=e.usedJSHeapSize||0,t.freeMemory=t.totalMemory-t.usedMemory,this.lastMemoryCheck>0)this.lastMemoryCheck-t.usedMemory>1048576&&this.gcCollections++;this.lastMemoryCheck=t.usedMemory}else t.totalMemory=536870912,t.freeMemory=536870912}catch(t){return{totalMemory:0,usedMemory:0,freeMemory:0,entityMemory:0,componentMemory:0,systemMemory:0,pooledMemory:0,gcCollections:this.gcCollections}}return t},e.updateGCCount=function(){try{return"undefined"!=typeof PerformanceObserver||performance.measureUserAgentSpecificMemory,this.gcCollections}catch(t){return this.gcCollections}},t}(),It=function(){function t(){}var e=t.prototype;return e.collectComponentData=function(t){var e=this;if(!t)return{componentTypes:0,componentInstances:0,componentStats:[]};var n=t.entities;if(null==n||!n.buffer)return{componentTypes:0,componentInstances:0,componentStats:[]};var i=new Map,r=0;n.buffer.forEach((function(t){t.components&&t.components.forEach((function(t){var e=z(t),n=i.get(e)||{count:0,entities:0};n.count++,r++,i.set(e,n)}))}));var s=new Map,a=new Map;try{for(var c,u=V.getInstance(),h=u.getPoolStats(),l=u.getPoolUtilization(),d=o(h.entries());!(c=d()).done;){var f=c.value,p=f[0],m=f[1];a.set(p,m.maxSize)}for(var y,g=o(l.entries());!(y=g()).done;){var v=y.value,_=v[0],E=v[1];s.set(_,E.utilization)}}catch(t){}return{componentTypes:i.size,componentInstances:r,componentStats:Array.from(i.entries()).map((function(i){var r=i[0],o=i[1],c=a.get(r)||0,u=s.get(r)||0,h=e.getEstimatedComponentSize(r,t);return{typeName:r,instanceCount:o.count,memoryPerInstance:h,totalMemory:o.count*h,poolSize:c,poolUtilization:u,averagePerEntity:o.count/n.buffer.length}}))}},e.getEstimatedComponentSize=function(e,n){if(t.componentSizeCache.has(e))return t.componentSizeCache.get(e);if(!n)return 64;var i=n.entities;if(null==i||!i.buffer)return 64;var r=64;try{for(var s,a=o(i.buffer);!(s=a()).done;){var c=s.value;if(c.components){var u=c.components.find((function(t){return z(t)===e}));if(u){r=this.calculateQuickObjectSize(u);break}}}}catch(t){r=64}return t.componentSizeCache.set(e,r),r},e.calculateQuickObjectSize=function(t){if(!t||"object"!=typeof t)return 8;var e=32,n=new WeakSet,i=function(t,e){if(void 0===e&&(e=0),!t||"object"!=typeof t||n.has(t)||e>3)return 0;n.add(t);var r=0;try{for(var s=Object.keys(t),o=0;o<Math.min(s.length,20);o++){var a=s[o];if("entity"!==a&&"_entity"!==a&&"constructor"!==a){var c=t[a];r+=2*a.length,"string"==typeof c?r+=Math.min(2*c.length,200):"number"==typeof c?r+=8:"boolean"==typeof c?r+=4:"object"==typeof c&&null!==c&&(r+=i(c,e+1))}}}catch(t){return 32}return r};return e+=i(t),Math.max(e,32)},e.calculateDetailedComponentMemory=function(t,e){if(!e)return this.getEstimatedComponentSize(t,e);var n=e.entities;if(null==n||!n.buffer)return this.getEstimatedComponentSize(t,e);try{for(var i,r=o(n.buffer);!(i=r()).done;){var s=i.value;if(s.components){var a=s.components.find((function(e){return z(e)===t}));if(a)return this.estimateObjectSize(a)}}}catch(t){}return this.getEstimatedComponentSize(t,e)},e.estimateObjectSize=function(t,e,n){if(void 0===e&&(e=new WeakSet),void 0===n&&(n=0),null==t||n>10)return 0;if(e.has(t))return 0;var i=0;switch(typeof t){case"boolean":i=4;break;case"number":default:i=8;break;case"string":i=24+Math.min(2*t.length,1e3);break;case"object":if(e.add(t),Array.isArray(t)){i=40+8*t.length;for(var r=Math.min(t.length,50),s=0;s<r;s++)i+=this.estimateObjectSize(t[s],e,n+1)}else{i=32;try{for(var o=Object.getOwnPropertyNames(t),a=Math.min(o.length,30),c=0;c<a;c++){var u=o[c];if("constructor"!==u&&"__proto__"!==u&&"entity"!==u&&"_entity"!==u&&!u.startsWith("_cc_")&&!u.startsWith("__"))try{i+=16+2*u.length;var h=t[u];null!=h&&(i+=this.estimateObjectSize(h,e,n+1))}catch(t){continue}}}catch(t){i=128}}}return 8*Math.ceil(i/8)},t.clearCache=function(){t.componentSizeCache.clear()},t}();It.componentSizeCache=new Map;var At=function(){function t(){this.sceneStartTime=Date.now()}var e=t.prototype;return e.collectSceneData=function(t){var e,n;if(!t)return{currentSceneName:"No Scene",isInitialized:!1,sceneRunTime:0,sceneEntityCount:0,sceneSystemCount:0,sceneMemory:0,sceneUptime:0};var i=(Date.now()-this.sceneStartTime)/1e3,r=t.entities,s=t.entityProcessors;return{currentSceneName:t.name||"Unnamed Scene",isInitialized:t._didSceneBegin||!1,sceneRunTime:i,sceneEntityCount:(null==r||null===(e=r.buffer)||void 0===e?void 0:e.length)||0,sceneSystemCount:(null==s||null===(n=s.processors)||void 0===n?void 0:n.length)||0,sceneMemory:0,sceneUptime:i}},e.setSceneStartTime=function(t){this.sceneStartTime=t},t}(),Dt=function(){function t(t,e){void 0===e&&(e=!0),this.isConnected=!1,this.reconnectAttempts=0,this.maxReconnectAttempts=5,this.reconnectInterval=2e3,this.url=t,this.autoReconnect=e}var e=t.prototype;return e.setMessageHandler=function(t){this.messageHandler=t},e.connect=function(){var t=this;return new Promise((function(e,n){try{t.ws=new WebSocket(t.url),t.ws.onopen=function(n){t.handleOpen(n),e()},t.ws.onclose=function(e){t.handleClose(e)},t.ws.onerror=function(e){t.handleError(e),n(e)},t.ws.onmessage=function(e){t.handleMessage(e)}}catch(e){t.handleConnectionFailure(e),n(e)}}))},e.disconnect=function(){this.ws&&(this.autoReconnect=!1,this.ws.close(),this.ws=void 0),this.isConnected=!1},e.send=function(t){if(this.isConnected&&this.ws)try{var e="string"==typeof t?t:JSON.stringify(t);this.ws.send(e)}catch(t){}},e.getConnectionStatus=function(){return this.isConnected},e.setMaxReconnectAttempts=function(t){this.maxReconnectAttempts=t},e.setReconnectInterval=function(t){this.reconnectInterval=t},e.scheduleReconnect=function(){var t=this;this.reconnectTimer&&clearTimeout(this.reconnectTimer);var e=Math.min(1e3*Math.pow(2,this.reconnectAttempts),3e4);this.reconnectAttempts++,this.reconnectTimer=setTimeout((function(){t.connect().catch((function(e){t.reconnectAttempts<t.maxReconnectAttempts&&t.scheduleReconnect()}))}),e)},e.handleMessage=function(t){try{var e=JSON.parse(t.data);this.messageHandler&&this.messageHandler(e)}catch(t){}},e.handleOpen=function(t){this.isConnected=!0,this.reconnectAttempts=0,this.onOpen&&this.onOpen(t)},e.handleClose=function(t){this.isConnected=!1,this.onClose&&this.onClose(t),this.autoReconnect&&this.reconnectAttempts<this.maxReconnectAttempts&&this.scheduleReconnect()},e.handleError=function(t){this.onError&&this.onError(t)},e.handleConnectionFailure=function(t){this.onError&&this.onError(t)},t}(),Ot=function(){function t(t,e){this.frameCounter=0,this.lastSendTime=0,this.isRunning=!1,this.config=e,this.sceneProvider=function(){return t.scene||t.constructor.scene},this.performanceMonitorProvider=function(){return t._performanceMonitor},this.entityCollector=new Mt,this.systemCollector=new xt,this.performanceCollector=new wt,this.componentCollector=new It,this.sceneCollector=new At,this.webSocketManager=new Dt(e.websocketUrl,!1!==e.autoReconnect),this.webSocketManager.setMessageHandler(this.handleMessage.bind(this));var n=e.debugFrameRate||30;this.sendInterval=1e3/n,this.start()}var e=t.prototype;return e.start=function(){this.isRunning||(this.isRunning=!0,this.connectWebSocket())},e.stop=function(){this.isRunning&&(this.isRunning=!1,this.webSocketManager.disconnect())},e.updateConfig=function(t){this.config=t;var e=t.debugFrameRate||30;this.sendInterval=1e3/e,this.webSocketManager&&t.websocketUrl&&(this.webSocketManager.disconnect(),this.webSocketManager=new Dt(t.websocketUrl,!1!==t.autoReconnect),this.webSocketManager.setMessageHandler(this.handleMessage.bind(this)),this.connectWebSocket())},e.onFrameUpdate=function(t){if(this.isRunning&&this.config.enabled){this.frameCounter++;var e=Date.now();e-this.lastSendTime>=this.sendInterval&&(this.sendDebugData(),this.lastSendTime=e)}},e.onSceneChanged=function(){this.isRunning&&this.config.enabled&&this.sendDebugData()},e.handleMessage=function(t){try{switch(t.type){case"capture_memory_snapshot":this.handleMemorySnapshotRequest();break;case"config_update":t.config&&this.updateConfig(a({},this.config,t.config));break;case"expand_lazy_object":this.handleExpandLazyObjectRequest(t);break;case"get_component_properties":this.handleGetComponentPropertiesRequest(t);break;case"get_raw_entity_list":this.handleGetRawEntityListRequest(t);break;case"get_entity_details":this.handleGetEntityDetailsRequest(t);break;case"ping":this.webSocketManager.send({type:"pong",timestamp:Date.now()})}}catch(e){t.requestId&&this.webSocketManager.send({type:"error_response",requestId:t.requestId,error:e instanceof Error?e.message:String(e)})}},e.handleExpandLazyObjectRequest=function(t){try{var e=t.entityId,n=t.componentIndex,i=t.propertyPath,r=t.requestId;if(void 0===e||void 0===n||!i)return void this.webSocketManager.send({type:"expand_lazy_object_response",requestId:r,error:"缺少必要参数"});var s=this.entityCollector.expandLazyObject(e,n,i);this.webSocketManager.send({type:"expand_lazy_object_response",requestId:r,data:s})}catch(e){this.webSocketManager.send({type:"expand_lazy_object_response",requestId:t.requestId,error:e instanceof Error?e.message:String(e)})}},e.handleGetComponentPropertiesRequest=function(t){try{var e=t.entityId,n=t.componentIndex,i=t.requestId;if(void 0===e||void 0===n)return void this.webSocketManager.send({type:"get_component_properties_response",requestId:i,error:"缺少必要参数"});var r=this.entityCollector.getComponentProperties(e,n);this.webSocketManager.send({type:"get_component_properties_response",requestId:i,data:r})}catch(e){this.webSocketManager.send({type:"get_component_properties_response",requestId:t.requestId,error:e instanceof Error?e.message:String(e)})}},e.handleGetRawEntityListRequest=function(t){try{var e=t.requestId,n=this.entityCollector.getRawEntityList();this.webSocketManager.send({type:"get_raw_entity_list_response",requestId:e,data:n})}catch(e){this.webSocketManager.send({type:"get_raw_entity_list_response",requestId:t.requestId,error:e instanceof Error?e.message:String(e)})}},e.handleGetEntityDetailsRequest=function(t){try{var e=t.entityId,n=t.requestId;if(void 0===e)return void this.webSocketManager.send({type:"get_entity_details_response",requestId:n,error:"缺少实体ID参数"});var i=this.entityCollector.getEntityDetails(e);this.webSocketManager.send({type:"get_entity_details_response",requestId:n,data:i})}catch(e){this.webSocketManager.send({type:"get_entity_details_response",requestId:t.requestId,error:e instanceof Error?e.message:String(e)})}},e.handleMemorySnapshotRequest=function(){try{var t=this.captureMemorySnapshot();this.webSocketManager.send({type:"memory_snapshot_response",data:t})}catch(t){this.webSocketManager.send({type:"memory_snapshot_error",error:t instanceof Error?t.message:"内存快照捕获失败"})}},e.captureMemorySnapshot=function(){var t=Date.now(),e=this.collectBaseMemoryInfo(),n=this.sceneProvider(),i=this.entityCollector.collectEntityDataWithMemory(n),r=null!=n&&n.entities?this.collectComponentMemoryStats(n.entities):{totalMemory:0,componentTypes:0,totalInstances:0,breakdown:[]},s=this.collectSystemMemoryStats(),o=this.collectPoolMemoryStats(),a=this.collectPerformanceStats(),c=i.entitiesPerArchetype.reduce((function(t,e){return t+e.memory}),0);return{timestamp:t,version:"2.0",summary:{totalEntities:i.totalEntities,totalMemoryUsage:e.usedMemory,totalMemoryLimit:e.totalMemory,memoryUtilization:e.usedMemory/e.totalMemory*100,gcCollections:e.gcCollections,entityMemory:c,componentMemory:r.totalMemory,systemMemory:s.totalMemory,poolMemory:o.totalMemory},baseMemory:e,entities:{totalMemory:c,entityCount:i.totalEntities,archetypes:i.entitiesPerArchetype,largestEntities:i.topEntitiesByComponents},components:r,systems:s,pools:o,performance:a}},e.collectBaseMemoryInfo=function(){var t={totalMemory:0,usedMemory:0,freeMemory:0,gcCollections:0,heapInfo:null,detailedMemory:void 0};try{var e=performance;if(e.memory){var n=e.memory;t.totalMemory=n.jsHeapSizeLimit||536870912,t.usedMemory=n.usedJSHeapSize||0,t.freeMemory=t.totalMemory-t.usedMemory,t.heapInfo={totalJSHeapSize:n.totalJSHeapSize||0,usedJSHeapSize:n.usedJSHeapSize||0,jsHeapSizeLimit:n.jsHeapSizeLimit||0}}else t.totalMemory=536870912,t.freeMemory=536870912;e.measureUserAgentSpecificMemory&&e.measureUserAgentSpecificMemory().then((function(e){t.detailedMemory=e})).catch((function(){}))}catch(t){}return t},e.collectComponentMemoryStats=function(t){for(var e,n=new Map,i=0,r=new Map,s=o(t.buffer);!(e=s()).done;){var a=e.value;if(a&&!a.destroyed&&a.components)for(var c,u=o(a.components);!(c=u()).done;){var h=z(c.value);r.set(h,(r.get(h)||0)+1)}}for(var l,d=o(r.entries());!(l=d()).done;){var f=l.value,p=f[0],m=f[1],y=this.componentCollector.calculateDetailedComponentMemory(p),g=y*m;i+=g;for(var v,_=[],E=0,S=o(t.buffer);!(v=S()).done;){var T=v.value;if(T&&!T.destroyed&&T.components){for(var C,b=o(T.components);!(C=b()).done;){if(z(C.value)===p&&(_.push({entityId:T.id,entityName:T.name||"Entity_"+T.id,memory:y}),++E>=100))break}if(E>=100)break}}n.set(p,{count:m,totalMemory:g,instances:_.slice(0,10)})}var M=Array.from(n.entries()).map((function(t){var e=t[0],n=t[1];return{typeName:e,instanceCount:n.count,totalMemory:n.totalMemory,averageMemory:n.totalMemory/n.count,percentage:i>0?n.totalMemory/i*100:0,largestInstances:n.instances.sort((function(t,e){return e.memory-t.memory})).slice(0,3)}})).sort((function(t,e){return e.totalMemory-t.totalMemory}));return{totalMemory:i,componentTypes:n.size,totalInstances:Array.from(n.values()).reduce((function(t,e){return t+e.count}),0),breakdown:M}},e.collectSystemMemoryStats=function(){var t=this.sceneProvider(),e=0,n=[];try{var i=null==t?void 0:t.entityProcessors;if(i&&i.processors)for(var r,s=new Map,a=o(i.processors);!(r=a()).done;){var c=r.value,u=B(c),h=void 0;s.has(u)?h=s.get(u):(h=this.calculateQuickSystemSize(c),s.set(u,h)),e+=h,n.push({name:u,memory:h,enabled:!1!==c.enabled,updateOrder:c.updateOrder||0})}}catch(t){}return{totalMemory:e,systemCount:n.length,breakdown:n.sort((function(t,e){return e.memory-t.memory}))}},e.calculateQuickSystemSize=function(t){if(!t||"object"!=typeof t)return 64;var e=128;try{for(var n=Object.keys(t),i=0;i<Math.min(n.length,15);i++){var r=n[i];if("entities"!==r&&"scene"!==r&&"constructor"!==r){var s=t[r];e+=2*r.length,"string"==typeof s?e+=Math.min(2*s.length,100):"number"==typeof s?e+=8:"boolean"==typeof s?e+=4:Array.isArray(s)?e+=40+Math.min(8*s.length,200):"object"==typeof s&&null!==s&&(e+=64)}}}catch(t){return 128}return Math.max(e,64)},e.collectPoolMemoryStats=function(){var t=0,e=[];try{for(var n,i=o(V.getInstance().getPoolStats().entries());!(n=i()).done;){var r=n.value,s=r[0],a=r[1],c=32*a.maxSize;t+=c,e.push({typeName:s,maxSize:a.maxSize,currentSize:a.currentSize||0,estimatedMemory:c,utilization:a.currentSize?a.currentSize/a.maxSize*100:0})}}catch(t){}try{for(var u=T.getAllPoolStats(),h=0,l=Object.entries(u);h<l.length;h++){var d=l[h],f=d[0],p=d[1];t+=p.estimatedMemoryUsage,e.push({typeName:"Pool_"+f,maxSize:p.maxSize,currentSize:p.size,estimatedMemory:p.estimatedMemoryUsage,utilization:p.size/p.maxSize*100,hitRate:100*p.hitRate})}}catch(t){}return{totalMemory:t,poolCount:e.length,breakdown:e.sort((function(t,e){return e.estimatedMemory-t.estimatedMemory}))}},e.collectPerformanceStats=function(){try{var t,e=this.performanceMonitorProvider();if(!e)return{enabled:!1};var n=e.getAllSystemStats(),i=e.getPerformanceWarnings();return{enabled:null!==(t=e.enabled)&&void 0!==t&&t,systemCount:n.size,warnings:i.slice(0,10),topSystems:Array.from(n.entries()).map((function(t){var e=t[0],n=t[1];return{name:e,averageTime:n.averageTime,maxTime:n.maxTime,samples:n.executionCount}})).sort((function(t,e){return e.averageTime-t.averageTime})).slice(0,5)}}catch(t){return{enabled:!1,error:t instanceof Error?t.message:String(t)}}},e.getDebugData=function(){var t=Date.now(),e=this.sceneProvider(),n={timestamp:t,frameworkVersion:"1.0.0",isRunning:this.isRunning,frameworkLoaded:!0,currentScene:(null==e?void 0:e.name)||"Unknown"};if(this.config.channels.entities&&(n.entities=this.entityCollector.collectEntityData(e)),this.config.channels.systems){var i=this.performanceMonitorProvider();n.systems=this.systemCollector.collectSystemData(i,e)}if(this.config.channels.performance){var r=this.performanceMonitorProvider();n.performance=this.performanceCollector.collectPerformanceData(r)}return this.config.channels.components&&(n.components=this.componentCollector.collectComponentData(e)),this.config.channels.scenes&&(n.scenes=this.sceneCollector.collectSceneData(e)),n},e.connectWebSocket=function(){var t=n(l().m((function t(){return l().w((function(t){for(;;)switch(t.p=t.n){case 0:return t.p=0,t.n=1,this.webSocketManager.connect();case 1:t.n=3;break;case 2:t.p=2,t.v;case 3:return t.a(2)}}),t,this,[[0,2]])})));return function(){return t.apply(this,arguments)}}(),e.sendDebugData=function(){if(this.webSocketManager.getConnectionStatus())try{var t={type:"debug_data",data:this.getDebugData()};this.webSocketManager.send(t)}catch(t){}},t}(),kt=function(){function t(e){var n,i,r;void 0===e&&(e={}),this._globalManagers=[],t._instance=this,this._config=a({debug:!0,enableEntitySystems:!0},e),this._timerManager=new E,t.registerGlobalManager(this._timerManager),this._performanceMonitor=S.instance,this._config.debug&&this._performanceMonitor.enable(),this._poolManager=b.getInstance(),t.entitySystemsEnabled=null===(n=this._config.enableEntitySystems)||void 0===n||n,this.debug=null===(i=this._config.debug)||void 0===i||i,null!==(r=this._config.debugConfig)&&void 0!==r&&r.enabled&&(this._debugManager=new Ot(this,this._config.debugConfig)),this.initialize()}t.getScene=function(){if(!this._instance)return null;this._instance.ensureDefaultWorld();var t=this._instance._worldManager.getWorld(this.DEFAULT_WORLD_ID);return(null==t?void 0:t.getScene(this.DEFAULT_SCENE_ID))||null},t.setScene=function(t){if(!this._instance)throw new Error("Core实例未创建,请先调用Core.create()");this._instance.ensureDefaultWorld();var e=this._instance._worldManager.getWorld(this.DEFAULT_WORLD_ID);return e.getScene(this.DEFAULT_SCENE_ID)&&e.removeScene(this.DEFAULT_SCENE_ID),e.createScene(this.DEFAULT_SCENE_ID,t),e.setSceneActive(this.DEFAULT_SCENE_ID,!0),this._instance.onSceneChanged(),t},t.create=function(e){if(void 0===e&&(e=!0),null==this._instance){var n="boolean"==typeof e?{debug:e,enableEntitySystems:!0}:e;this._instance=new t(n)}return this._instance},t.update=function(e){this._instance?this._instance.updateInternal(e):t._logger.warn("Core实例未创建,请先调用Core.create()")},t.registerGlobalManager=function(t){this._instance._globalManagers.push(t),t.enabled=!0},t.unregisterGlobalManager=function(t){this._instance._globalManagers.splice(this._instance._globalManagers.indexOf(t),1),t.enabled=!1},t.getGlobalManager=function(t){for(var e,n=o(this._instance._globalManagers);!(e=n()).done;){var i=e.value;if(i instanceof t)return i}return null},t.schedule=function(t,e,n,i){if(void 0===e&&(e=!1),!i)throw new Error("onTime callback is required");return this._instance._timerManager.schedule(t,e,n,i)},t.enableDebug=function(e){this._instance?(this._instance._debugManager?this._instance._debugManager.updateConfig(e):this._instance._debugManager=new Ot(this._instance,e),this._instance._config.debugConfig=e):t._logger.warn("Core实例未创建,请先调用Core.create()")},t.disableDebug=function(){this._instance&&(this._instance._debugManager&&(this._instance._debugManager.stop(),this._instance._debugManager=void 0),this._instance._config.debugConfig&&(this._instance._config.debugConfig.enabled=!1))},t.getDebugData=function(){var t;return null!==(t=this._instance)&&void 0!==t&&t._debugManager?this._instance._debugManager.getDebugData():null},t.getWorldManager=function(){if(!this._instance)throw new Error("Core实例未创建,请先调用Core.create()");return this._instance._worldManager||(this._instance._worldManager=Tt.getInstance({maxWorlds:50,autoCleanup:!0,cleanupInterval:6e4,debug:this._instance._config.debug})),this._instance._worldManager},t.enableWorldManager=function(){return this.getWorldManager()};var e=t.prototype;return e.ensureDefaultWorld=function(){this._worldManager||(this._worldManager=Tt.getInstance({maxWorlds:1,autoCleanup:!1,cleanupInterval:0,debug:this._config.debug})),this._worldManager.getWorld(t.DEFAULT_WORLD_ID)||(this._worldManager.createWorld(t.DEFAULT_WORLD_ID,{name:"DefaultWorld",maxScenes:1,autoCleanup:!1}),this._worldManager.setWorldActive(t.DEFAULT_WORLD_ID,!0))},e.onSceneChanged=function(){var e=this;g.sceneChanged();var n=t.getScene();n&&n.querySystem&&n.eventSystem&&(this._ecsAPI=vt(n,n.querySystem,n.eventSystem)),this._debugManager&&queueMicrotask((function(){var t;null===(t=e._debugManager)||void 0===t||t.onSceneChanged()}))},e.initialize=function(){},e.updateInternal=function(e){if(!t.paused){var n=this._performanceMonitor.startMonitoring("Core.update");g.update(e),"updateFPS"in this._performanceMonitor&&"function"==typeof this._performanceMonitor.updateFPS&&this._performanceMonitor.updateFPS(g.deltaTime);for(var i,r=this._performanceMonitor.startMonitoring("GlobalManagers.update"),s=o(this._globalManagers);!(i=s()).done;){var a=i.value;a.enabled&&a.update()}if(this._performanceMonitor.endMonitoring("GlobalManagers.update",r,this._globalManagers.length),this._poolManager.update(),this._worldManager){for(var c,u=this._performanceMonitor.startMonitoring("Worlds.update"),h=0,l=o(this._worldManager.getActiveWorlds());!(c=l()).done;){var d=c.value;d.updateGlobalSystems(),d.updateScenes(),h+=d.getStats().totalEntities}this._performanceMonitor.endMonitoring("Worlds.update",u,h)}this._debugManager&&this._debugManager.onFrameUpdate(e),this._performanceMonitor.endMonitoring("Core.update",n)}},s(t,null,[{key:"Instance",get:function(){return this._instance}},{key:"scene",get:function(){return this.getScene()}},{key:"ecsAPI",get:function(){var t;return(null===(t=this._instance)||void 0===t?void 0:t._ecsAPI)||null}},{key:"isDebugEnabled",get:function(){var t;return(null===(t=this._instance)||void 0===t||null===(t=t._config.debugConfig)||void 0===t?void 0:t.enabled)||!1}}])}();kt.paused=!1,kt.DEFAULT_WORLD_ID="__default__",kt.DEFAULT_SCENE_ID="__main__",kt._logger=D("Core");var Nt=function(t,e){this.func=t,this.context=e},Pt=function(){function t(){this._messageTable=new Map}var e=t.prototype;return e.addObserver=function(t,e,n){var i=this._messageTable.get(t);i||(i=[],this._messageTable.set(t,i)),this.hasObserver(t,e)||i.push(new Nt(e,n))},e.removeObserver=function(t,e){var n=this._messageTable.get(t);if(n){var i=n.findIndex((function(t){return t.func==e}));-1!=i&&n.splice(i,1)}},e.emit=function(t){var e=this._messageTable.get(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];for(var s,a=o(e);!(s=a()).done;){var c,u=s.value;(c=u.func).call.apply(c,[u.context].concat(i))}}},e.hasObserver=function(t,e){var n=this._messageTable.get(t);return!!n&&n.some((function(t){return t.func===e}))},e.removeAllObservers=function(t){void 0!==t?this._messageTable.delete(t):this._messageTable.clear()},e.dispose=function(){this._messageTable.clear()},e.getEventTypeCount=function(){return this._messageTable.size},e.getObserverCount=function(t){var e=this._messageTable.get(t);return e?e.length:0},t}(),Rt=function(){function t(){this._enabled=!0,this._updateOrder=0,this.id=t._idGenerator++}var e=t.prototype;return e.onAddedToEntity=function(){},e.onRemovedFromEntity=function(){},e.onEnabled=function(){},e.onDisabled=function(){},e.update=function(){},s(t,[{key:"enabled",get:function(){return this.entity?this.entity.enabled&&this._enabled:this._enabled},set:function(t){this._enabled!==t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled())}},{key:"updateOrder",get:function(){return this._updateOrder},set:function(t){this._updateOrder=t}}])}();Rt._idGenerator=0;var zt=function(){function t(){this.condition={all:[],any:[],none:[]}}t.all=function(){var e=new t;return e.all.apply(e,arguments)},t.any=function(){var e=new t;return e.any.apply(e,arguments)},t.none=function(){var e=new t;return e.none.apply(e,arguments)},t.byTag=function(e){return(new t).withTag(e)},t.byName=function(e){return(new t).withName(e)},t.byComponent=function(e){return(new t).withComponent(e)},t.complex=function(){return new t},t.empty=function(){return new t};var e=t.prototype;return e.all=function(){var t;return(t=this.condition.all).push.apply(t,arguments),this},e.any=function(){var t;return(t=this.condition.any).push.apply(t,arguments),this},e.none=function(){var t;return(t=this.condition.none).push.apply(t,arguments),this},e.exclude=function(){return this.none.apply(this,arguments)},e.one=function(){return this.any.apply(this,arguments)},e.withTag=function(t){return this.condition.tag=t,this},e.withName=function(t){return this.condition.name=t,this},e.withComponent=function(t){return this.condition.component=t,this},e.withoutTag=function(){return delete this.condition.tag,this},e.withoutName=function(){return delete this.condition.name,this},e.withoutComponent=function(){return delete this.condition.component,this},e.getCondition=function(){return{all:[].concat(this.condition.all),any:[].concat(this.condition.any),none:[].concat(this.condition.none),tag:this.condition.tag,name:this.condition.name,component:this.condition.component}},e.isEmpty=function(){return 0===this.condition.all.length&&0===this.condition.any.length&&0===this.condition.none.length&&void 0===this.condition.tag&&void 0===this.condition.name&&void 0===this.condition.component},e.reset=function(){return this.condition.all.length=0,this.condition.any.length=0,this.condition.none.length=0,delete this.condition.tag,delete this.condition.name,delete this.condition.component,this},e.clone=function(){var e,n,i,r=new t;return(e=r.condition.all).push.apply(e,this.condition.all),(n=r.condition.any).push.apply(n,this.condition.any),(i=r.condition.none).push.apply(i,this.condition.none),void 0!==this.condition.tag&&(r.condition.tag=this.condition.tag),void 0!==this.condition.name&&(r.condition.name=this.condition.name),void 0!==this.condition.component&&(r.condition.component=this.condition.component),r},e.toString=function(){var t=[];return this.condition.all.length>0&&t.push("all("+this.condition.all.map((function(t){return P(t)})).join(", ")+")"),this.condition.any.length>0&&t.push("any("+this.condition.any.map((function(t){return P(t)})).join(", ")+")"),this.condition.none.length>0&&t.push("none("+this.condition.none.map((function(t){return P(t)})).join(", ")+")"),void 0!==this.condition.tag&&t.push("tag("+this.condition.tag+")"),void 0!==this.condition.name&&t.push("name("+this.condition.name+")"),void 0!==this.condition.component&&t.push("component("+P(this.condition.component)+")"),"Matcher["+t.join(" & ")+"]"},t}(),Bt=function(){function t(t){this._updateOrder=0,this._enabled=!0,this._performanceMonitor=S.instance,this._initialized=!1,this._trackedEntities=new Set,this._eventListeners=[],this._scene=null,this._matcher=t||zt.empty(),this._systemName=B(this)}var e=t.prototype;return e.setUpdateOrder=function(t){this._updateOrder=t,this.scene&&this.scene.entityProcessors&&this.scene.entityProcessors.setDirty()},e.initialize=function(){this._initialized||(this._initialized=!0,this.scene&&this.queryEntities(),this.onInitialize())},e.onInitialize=function(){},e.reset=function(){this._initialized=!1,this._trackedEntities.clear(),this.cleanupEventListeners(),this.onDestroy()},e.queryEntities=function(){var t;if(null===(t=this.scene)||void 0===t||!t.querySystem||!this._matcher)return[];var e=this._matcher.getCondition(),n=this.scene.querySystem,i=[];return i=this._matcher.isEmpty()?n.getAllEntities():this.isSingleCondition(e)?this.executeSingleConditionQuery(e,n):this.executeComplexQuery(e,n),this.updateEntityTracking(i),i},e.isSingleCondition=function(t){return 1===(t.all.length>0?1:0)+(t.any.length>0?1:0)+(t.none.length>0?1:0)+(void 0!==t.tag?1:0)+(void 0!==t.name?1:0)+(void 0!==t.component?1:0)},e.executeSingleConditionQuery=function(t,e){return void 0!==t.tag?e.queryByTag(t.tag).entities:void 0!==t.name?e.queryByName(t.name).entities:void 0!==t.component?e.queryByComponent(t.component).entities:t.all.length>0&&0===t.any.length&&0===t.none.length?e.queryAll.apply(e,t.all).entities:0===t.all.length&&t.any.length>0&&0===t.none.length?e.queryAny.apply(e,t.any).entities:0===t.all.length&&0===t.any.length&&t.none.length>0?e.queryNone.apply(e,t.none).entities:[]},e.executeComplexQueryWithIdSets=function(t,e){var n=null;if(void 0!==t.tag){var i=e.queryByTag(t.tag);n=this.extractEntityIds(i.entities)}if(void 0!==t.name){var r=this.extractEntityIds(e.queryByName(t.name).entities);n=n?this.intersectIdSets(n,r):r}if(void 0!==t.component){var s=this.extractEntityIds(e.queryByComponent(t.component).entities);n=n?this.intersectIdSets(n,s):s}if(t.all.length>0){var o=this.extractEntityIds(e.queryAll.apply(e,t.all).entities);n=n?this.intersectIdSets(n,o):o}if(t.any.length>0){var a=this.extractEntityIds(e.queryAny.apply(e,t.any).entities);n=n?this.intersectIdSets(n,a):a}if(t.none.length>0){n||(n=this.extractEntityIds(e.getAllEntities()));var c=e.queryAny.apply(e,t.none),u=this.extractEntityIds(c.entities);n=this.differenceIdSets(n,u)}return n?this.idSetToEntityArray(n,e.getAllEntities()):[]},e.extractEntityIds=function(t){for(var e=new Set,n=0;n<t.length;n++)e.add(t[n].id);return e},e.intersectIdSets=function(t,e){for(var n,i=t.size<=e.size?[t,e]:[e,t],r=i[0],s=i[1],a=new Set,c=o(r);!(n=c()).done;){var u=n.value;s.has(u)&&a.add(u)}return a},e.differenceIdSets=function(t,e){for(var n,i=new Set,r=o(t);!(n=r()).done;){var s=n.value;e.has(s)||i.add(s)}return i},e.idSetToEntityArray=function(t,e){for(var n,i=new Map,r=o(e);!(n=r()).done;){var s=n.value;i.set(s.id,s)}for(var a,c=[],u=o(t);!(a=u()).done;){var h=a.value,l=i.get(h);l&&c.push(l)}return c},e.executeComplexQuery=function(t,e){return this.executeComplexQueryWithIdSets(t,e)},e.update=function(){if(this._enabled&&this.onCheckProcessing()){var t=this._performanceMonitor.startMonitoring(this._systemName),e=0;try{this.onBegin();var n=this.queryEntities();e=n.length,this.process(n)}finally{this._performanceMonitor.endMonitoring(this._systemName,t,e)}}},e.lateUpdate=function(){if(this._enabled&&this.onCheckProcessing()){var t=this._performanceMonitor.startMonitoring(this._systemName+"_Late"),e=0;try{var n=this.queryEntities();e=n.length,this.lateProcess(n),this.onEnd()}finally{this._performanceMonitor.endMonitoring(this._systemName+"_Late",t,e)}}},e.onBegin=function(){},e.process=function(t){},e.lateProcess=function(t){},e.onEnd=function(){},e.onCheckProcessing=function(){return!0},e.getPerformanceData=function(){return this._performanceMonitor.getSystemData(this._systemName)},e.getPerformanceStats=function(){return this._performanceMonitor.getSystemStats(this._systemName)},e.resetPerformanceData=function(){this._performanceMonitor.resetSystem(this._systemName)},e.toString=function(){var t=this.entities.length,e=this.getPerformanceData(),n=e?" ("+e.executionTime.toFixed(2)+"ms)":"";return this._systemName+"["+t+" entities]"+n},e.updateEntityTracking=function(t){for(var e,n=new Set(t),i=o(t);!(e=i()).done;){var r=e.value;this._trackedEntities.has(r)||(this._trackedEntities.add(r),this.onAdded(r))}for(var s,a=o(this._trackedEntities);!(s=a()).done;){var c=s.value;n.has(c)||(this._trackedEntities.delete(c),this.onRemoved(c))}},e.onAdded=function(t){},e.onRemoved=function(t){},e.addEventListener=function(t,e,n){var i;if(null!==(i=this.scene)&&void 0!==i&&i.eventSystem){var r=this.scene.eventSystem.on(t,e,n);r&&this._eventListeners.push({eventSystem:this.scene.eventSystem,eventType:t,handler:e,listenerRef:r})}else console.warn("["+this.systemName+"] Cannot add event listener: scene.eventSystem not available")},e.removeEventListener=function(t,e){var n=this._eventListeners.findIndex((function(n){return n.eventType===t&&n.handler===e}));if(n>=0){var i=this._eventListeners[n];i.eventSystem.off(t,i.listenerRef),this._eventListeners.splice(n,1)}},e.cleanupEventListeners=function(){for(var t,e=o(this._eventListeners);!(t=e()).done;){var n=t.value;try{n.eventSystem.off(n.eventType,n.listenerRef)}catch(t){console.warn("["+this.systemName+'] Failed to remove event listener for "'+n.eventType+'":',t)}}this._eventListeners.length=0},e.onDestroy=function(){},s(t,[{key:"entities",get:function(){return this.queryEntities()}},{key:"updateOrder",get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)}},{key:"enabled",get:function(){return this._enabled},set:function(t){this._enabled=t}},{key:"systemName",get:function(){return this._systemName}},{key:"scene",get:function(){return this._scene},set:function(t){this._scene=t}},{key:"matcher",get:function(){return this._matcher}}])}(),Lt=function(t){function e(e){return t.call(this,e)||this}return u(e,t),e.prototype.process=function(t){this.processSystem()},e}(Bt),Ft=function(t){function e(e){return t.call(this,e)||this}return u(e,t),e.prototype.process=function(t){},e}(Bt),qt=function(t){function e(e,n){var i;return(i=t.call(this,n)||this).acc=0,i.intervalRemainder=0,i.interval=e,i}u(e,t);var n=e.prototype;return n.onCheckProcessing=function(){return this.acc+=g.deltaTime,this.acc>=this.interval&&(this.intervalRemainder=this.acc-this.interval,this.acc=0,!0)},n.getIntervalDelta=function(){return this.interval+this.intervalRemainder},e}(Bt),Wt=function(){function t(t){this.entityManager=t,this._allComponents=[],this._anyComponents=[],this._withoutComponents=[],this._withTags=[],this._withoutTags=[],this._activeOnly=!1,this._enabledOnly=!1,this._customPredicates=[]}var e=t.prototype;return e.withAll=function(){var t;return(t=this._allComponents).push.apply(t,arguments),this},e.withAny=function(){var t;return(t=this._anyComponents).push.apply(t,arguments),this},e.without=function(){var t;return(t=this._withoutComponents).push.apply(t,arguments),this},e.withTag=function(t){return this._withTags.push(t),this},e.withoutTag=function(t){return this._withoutTags.push(t),this},e.active=function(){return this._activeOnly=!0,this},e.enabled=function(){return this._enabledOnly=!0,this},e.where=function(t){return this._customPredicates.push(t),this},e.execute=function(){var t=this,e=[];if(this._allComponents.length>0){var n=this.entityManager.queryWithComponentIndex(this._allComponents,"AND");e=Array.from(n)}else if(this._anyComponents.length>0){var i=this.entityManager.queryWithComponentIndex(this._anyComponents,"OR");e=Array.from(i)}else e=this.entityManager.getAllEntities();return e.filter((function(e){return t.matchesEntity(e)}))},e.first=function(){var t=this;return this.entityManager.getAllEntities().find((function(e){return t.matchesEntity(e)}))||null},e.count=function(){var t=this;return this.entityManager.getAllEntities().filter((function(e){return t.matchesEntity(e)})).length},e.forEach=function(t){var e=this;this.entityManager.getAllEntities().forEach((function(n){e.matchesEntity(n)&&t(n)}))},e.matchesEntity=function(t){if(this._activeOnly&&!t.active)return!1;if(this._enabledOnly&&!t.enabled)return!1;if(this._allComponents.length>0)for(var e,n=o(this._allComponents);!(e=n()).done;){var i=e.value;if(!t.hasComponent(i))return!1}if(this._anyComponents.length>0){for(var r,s=!1,a=o(this._anyComponents);!(r=a()).done;){var c=r.value;if(t.hasComponent(c)){s=!0;break}}if(!s)return!1}if(this._withoutComponents.length>0)for(var u,h=o(this._withoutComponents);!(u=h()).done;){var l=u.value;if(t.hasComponent(l))return!1}if(this._withTags.length>0&&!this._withTags.includes(t.tag))return!1;if(this._withoutTags.length>0&&this._withoutTags.includes(t.tag))return!1;if(this._customPredicates.length>0)for(var d,f=o(this._customPredicates);!(d=f()).done;){if(!(0,d.value)(t))return!1}return!0},t}(),Ut=function(){function t(){var t=this;this._entities=new Map,this._entitiesByName=new Map,this._entitiesByTag=new Map,this._destroyedEntities=new Set,this._identifierPool=new Y,this._componentIndexManager=new tt,this._archetypeSystem=new et,this._dirtyTrackingSystem=new it,this._eventBus=new lt(!1),U.eventBus=this._eventBus,this._eventBus.on("component:added",(function(e){var n=t._entities.get(e.entityId);n&&(t._componentIndexManager.addEntity(n),t._archetypeSystem.addEntity(n))})),this._eventBus.on("component:removed",(function(e){var n=t._entities.get(e.entityId);n&&(t._componentIndexManager.removeEntity(n),t._archetypeSystem.removeEntity(n))}))}var e=t.prototype;return e.createEntity=function(t){var e,n=this._identifierPool.checkOut();t||(t="Entity_"+n);var i=new U(t,n);return this._entities.set(n,i),this.updateNameIndex(i,!0),this.updateTagIndex(i,!0),i.components.length>0&&(this._componentIndexManager.addEntity(i),this._archetypeSystem.addEntity(i),this._dirtyTrackingSystem.markDirty(i,exports.DirtyFlag.COMPONENT_ADDED)),this._eventBus.emitEntityCreated({timestamp:Date.now(),source:"EntityManager",entityId:i.id,entityName:i.name,entityTag:null===(e=i.tag)||void 0===e?void 0:e.toString()}),i},e.createEntitiesBatch=function(t,e,n){if(void 0===e&&(e="Entity"),void 0===n&&(n=!1),t<=0)return[];for(var i=[],r=0;r<t;r++){var s=this._identifierPool.checkOut(),a=new U(e+"_"+s,s);i.push(a),this._entities.set(s,a)}for(var c=0,u=i;c<u.length;c++){var h=u[c];this.updateNameIndex(h,!0),this.updateTagIndex(h,!0),h.components.length>0&&(this._componentIndexManager.addEntity(h),this._archetypeSystem.addEntity(h),this._dirtyTrackingSystem.markDirty(h,exports.DirtyFlag.COMPONENT_ADDED))}if(!n)for(var l,d=Date.now(),f=o(i);!(l=f()).done;){var p,m=l.value;this._eventBus.emitEntityCreated({timestamp:d,source:"EntityManager",entityId:m.id,entityName:m.name,entityTag:null===(p=m.tag)||void 0===p?void 0:p.toString()})}return i},e.destroyEntity=function(t){var e,n=null;return!!(n="string"==typeof t?this.getEntityByName(t):"number"==typeof t?this._entities.get(t)||null:this._entities.get(t.id)||null)&&(this._destroyedEntities.add(n.id),this.updateNameIndex(n,!1),this.updateTagIndex(n,!1),this._componentIndexManager.removeEntity(n),this._archetypeSystem.removeEntity(n),this._dirtyTrackingSystem.markDirty(n,exports.DirtyFlag.COMPONENT_REMOVED),this._eventBus.emitEntityDestroyed({timestamp:Date.now(),source:"EntityManager",entityId:n.id,entityName:n.name,entityTag:null===(e=n.tag)||void 0===e?void 0:e.toString()}),n.destroy(),this._entities.delete(n.id),this._identifierPool.checkIn(n.id),!0)},e.getAllEntities=function(){return Array.from(this._entities.values())},e.getEntity=function(t){var e="string"==typeof t?parseInt(t):t;return this._entities.get(e)||null},e.getEntityByName=function(t){var e=this._entitiesByName.get(t);return e&&e.length>0?e[0]:null},e.getEntitiesByTag=function(t){return Array.from(this._entities.values()).filter((function(e){return e.tag===t}))},e.getEntitiesWithComponent=function(t){var e=this._componentIndexManager.query(t);return Array.from(e)},e.query=function(){return new Wt(this)},e.queryWithComponentIndex=function(t,e){return this._componentIndexManager.queryMultiple(t,e)},e.markEntityDirty=function(t,e){this._dirtyTrackingSystem.markDirty(t,exports.DirtyFlag.COMPONENT_MODIFIED,e)},e.getOptimizationStats=function(){return{componentIndex:this._componentIndexManager.getStats(),archetypeSystem:this._archetypeSystem.getAllArchetypes().map((function(t){return{id:t.id,componentTypes:t.componentTypes.map((function(t){return t.name})),entityCount:t.entities.length}})),dirtyTracking:this._dirtyTrackingSystem.getStats()}},e.updateNameIndex=function(t,e){if(t.name)if(e){var n=this._entitiesByName.get(t.name);n||(n=[],this._entitiesByName.set(t.name,n)),n.push(t)}else{var i=this._entitiesByName.get(t.name);if(i){var r=i.indexOf(t);-1!==r&&(i.splice(r,1),0===i.length&&this._entitiesByName.delete(t.name))}}},e.updateTagIndex=function(t,e){if(e){var n=this._entitiesByTag.get(t.tag);n||(n=[],this._entitiesByTag.set(t.tag,n)),n.push(t)}else{var i=this._entitiesByTag.get(t.tag);if(i){var r=i.indexOf(t);-1!==r&&(i.splice(r,1),0===i.length&&this._entitiesByTag.delete(t.tag))}}},s(t,[{key:"entityCount",get:function(){return this._entities.size}},{key:"activeEntityCount",get:function(){for(var t,e=0,n=o(this._entities.values());!(t=n()).done;){var i=t.value;i.active&&!i.isDestroyed&&e++}return e}},{key:"eventBus",get:function(){return this._eventBus}}])}(),jt=function(){function t(){}return t.getType=function(t){return t.constructor},t}(),Ht=function(){function t(){}return t.toNumber=function(t){return null==t?0:Number(t)},t}();exports.ArchetypeSystem=et,exports.AsyncEventHandler=function(t,e){return void 0===e&&(e={}),function(n,i,r){var s=r.value,o=n.constructor.prototype.initEventListeners||function(){};return n.constructor.prototype.initEventListeners=function(){o.call(this),dt.getInstance().onAsync(t,s.bind(this),e)},r}},exports.BitMask64Utils=M,exports.Bits=Ct,exports.COMPONENT_TYPE_NAME=k,exports.Colors=x,exports.Component=Rt,exports.ComponentDataCollector=It,exports.ComponentIndex=$,exports.ComponentIndexManager=tt,exports.ComponentPool=Q,exports.ComponentPoolManager=V,exports.ComponentRegistry=L,exports.ComponentSparseSet=J,exports.ComponentStorage=F,exports.ComponentTypeManager=bt,exports.ConsoleLogger=w,exports.Core=kt,exports.DebugManager=Ot,exports.DirtyTrackingSystem=it,exports.ECSComponent=function(t){return function(e){if(!t||"string"!=typeof t)throw new Error("ECSComponent装饰器必须提供有效的类型名称");return e[k]=t,e}},exports.ECSFluentAPI=gt,exports.ECSSystem=function(t){return function(e){if(!t||"string"!=typeof t)throw new Error("ECSSystem装饰器必须提供有效的类型名称");return e[N]=t,e}},exports.EVENT_TYPES=ut,exports.Emitter=Pt,exports.EnableSoA=function(t){return t.__enableSoA=!0,t},exports.Entity=U,exports.EntityDataCollector=Mt,exports.EntityList=H,exports.EntityManager=Ut,exports.EntityProcessorList=G,exports.EntityQueryBuilder=Wt,exports.EntitySystem=Bt,exports.EventBus=lt,exports.EventHandler=function(t,e){return void 0===e&&(e={}),function(n,i,r){var s=r.value,o=n.constructor.prototype.initEventListeners||function(){};return n.constructor.prototype.initEventListeners=function(){o.call(this),dt.getInstance().on(t,s.bind(this),e)},r}},exports.EventTypeValidator=ht,exports.Float32=function(t,e){var n=String(e);t.constructor.__float32Fields||(t.constructor.__float32Fields=new Set),t.constructor.__float32Fields.add(n)},exports.Float64=function(t,e){var n=String(e);t.constructor.__float64Fields||(t.constructor.__float64Fields=new Set),t.constructor.__float64Fields.add(n)},exports.FuncPack=Nt,exports.GlobalEventBus=dt,exports.GlobalManager=y,exports.HighPrecision=function(t,e){var n=String(e);t.constructor.__highPrecisionFields||(t.constructor.__highPrecisionFields=new Set),t.constructor.__highPrecisionFields.add(n)},exports.IdentifierPool=Y,exports.Int32=function(t,e){var n=String(e);t.constructor.__int32Fields||(t.constructor.__int32Fields=new Set),t.constructor.__int32Fields.add(n)},exports.IntervalSystem=qt,exports.Logger=A,exports.LoggerManager=I,exports.Matcher=zt,exports.NumberExtension=Ht,exports.PassiveSystem=Ft,exports.PerformanceDataCollector=wt,exports.PerformanceMonitor=S,exports.Pool=T,exports.PoolManager=b,exports.ProcessingSystem=Lt,exports.QuerySystem=ot,exports.SYSTEM_TYPE_NAME=N,exports.Scene=ft,exports.SceneDataCollector=At,exports.SerializeMap=function(t,e){var n=String(e);t.constructor.__serializeMapFields||(t.constructor.__serializeMapFields=new Set),t.constructor.__serializeMapFields.add(n)},exports.SoAStorage=O,exports.SparseSet=X,exports.SystemDataCollector=xt,exports.Time=g,exports.Timer=_,exports.TimerManager=E,exports.TypeSafeEventSystem=ct,exports.TypeUtils=jt,exports.WebSocketManager=Dt,exports.World=Et,exports.WorldManager=Tt,exports.createECSAPI=vt,exports.createLogger=D,exports.getComponentInstanceTypeName=z,exports.getComponentTypeName=P,exports.getSystemInstanceTypeName=B,exports.getSystemTypeName=R,exports.resetLoggerColors=function(){I.getInstance().resetColors()},exports.setGlobalLogLevel=function(t){I.getInstance().setGlobalLevel(t)},exports.setLoggerColors=function(t){I.getInstance().setGlobalColors(t)};
4
4
  //# sourceMappingURL=index.cjs.map