diff --git a/demo/egretProperties.json b/demo/egretProperties.json index ece18f01..1f7a10ee 100644 --- a/demo/egretProperties.json +++ b/demo/egretProperties.json @@ -27,6 +27,10 @@ { "name": "framework", "path": "./libs/framework" + }, + { + "name": "long", + "path": "./libs/long" } ] } \ No newline at end of file diff --git a/demo/libs/framework/framework.d.ts b/demo/libs/framework/framework.d.ts index cb8aed4a..0a5d7405 100644 --- a/demo/libs/framework/framework.d.ts +++ b/demo/libs/framework/framework.d.ts @@ -552,59 +552,6 @@ declare class Flags { static unsetFlag(self: number, flag: number): number; static invertFlags(self: number): number; } -declare interface Long { - toInt(): number; - negate(): Long; - add(addend: any): any; - divide(divisor: any): Long; - equals(other: any): any; - not(): any; - toString(radix?: any): string; - isZero(): any; - isNegative(): any; - multiply(multiplier: any): Long; - shiftRight(numBits: any): Long; - shiftRightUnsigned(numBits: any): any; - subtract(subtrahend: any): Long; - greaterThan(other: any): any; - compare(other: any): any; - toUnsigned(): Long; - toNumber(): any; - greaterThanOrEqual(other: any): any; - isOdd(): any; - lessThan(other: any): any; -} -declare class Long { - low: number; - high: number; - unsigned: boolean; - private static ini_cache; - private static unit_cache; - static uzero: Long; - static zero: Long; - static two_pwr_16_dbl: number; - static two_pwe_24_dbl: number; - static two_pwr_32_dbl: number; - static two_pwr_64_dbl: number; - static two_pwr_63_dbl: number; - static two_pwr_24: Long; - static max_unsigned_value: Long; - static min_value: Long; - static max_value: Long; - static one: Long; - static neg_one: Long; - constructor(low: number, high: number, unsigned: boolean); - shiftLeft(numBits: number | Long): Long; - static fromBits(lowBits: any, highBits: any, unsigned: any): Long; - static fromValue(val: number | string | { - low: number; - high: number; - unsigned: boolean; - }, unsigned?: any): Long; - static fromString(str: string, unsigned: any, radix?: any): Long; - static fromNumber(value: any, unsigned?: any): Long; - static fromInt(value: any, unsigned?: any): Long; -} declare class MathHelper { static readonly Epsilon: number; static readonly Rad2Deg: number; diff --git a/demo/libs/framework/framework.js b/demo/libs/framework/framework.js index f6e2b822..50cf55b7 100644 --- a/demo/libs/framework/framework.js +++ b/demo/libs/framework/framework.js @@ -2611,408 +2611,6 @@ var Flags = (function () { }; return Flags; }()); -var Long = (function () { - function Long(low, high, unsigned) { - this.low = low | 0; - this.high = high | 0; - this.unsigned = !!unsigned; - } - Long.prototype.shiftLeft = function (numBits) { - if (numBits instanceof Long) - numBits = numBits.toInt(); - if ((numBits &= 63) === 0) - return this; - else if (numBits < 32) - return Long.fromBits(this.low << numBits, (this.high << numBits) | (this.low >>> (32 - numBits)), this.unsigned); - else - return Long.fromBits(0, this.low << (numBits - 32), this.unsigned); - }; - Long.fromBits = function (lowBits, highBits, unsigned) { - return new Long(lowBits, highBits, unsigned); - }; - Long.fromValue = function (val, unsigned) { - if (typeof val === 'number') - return this.fromNumber(val, unsigned); - if (typeof val === 'string') - return this.fromString(val, unsigned); - return this.fromBits(val.low, val.high, typeof unsigned === 'boolean' ? unsigned : val.unsigned); - }; - Long.fromString = function (str, unsigned, radix) { - if (str.length === 0) - throw new Error("empty string"); - if (str === "NaN" || str === "Infinity" || str === "+Infinity" || str === "-Infinity") - return Long.zero; - if (typeof unsigned === "number") { - radix = unsigned; - unsigned = false; - } - else { - unsigned = !!unsigned; - } - radix = radix || 10; - if (radix < 2 || 36 < radix) - throw new Error("radix"); - var p; - if ((p = str.indexOf('-')) > 0) - throw new Error('interior hyphen'); - else if (p === 0) - return this.fromString(str.substring(1), unsigned, radix).negate(); - var radixToPower = this.fromNumber(Math.pow(radix, 8)); - var result = Long.zero; - for (var i = 0; i < str.length; i += 8) { - var size = Math.min(8, str.length - i), value = parseInt(str.substring(i, i + size), radix); - if (size < 8) { - var power = this.fromNumber(Math.pow(radix, size)); - result = result.multiply(power).add(this.fromNumber(value)); - } - else { - result = result.multiply(radixToPower); - result = result.add(this.fromNumber(value)); - } - } - result.unsigned = unsigned; - return result; - }; - Long.fromNumber = function (value, unsigned) { - if (isNaN(value)) - return unsigned ? Long.uzero : Long.zero; - if (unsigned) { - if (value < 0) - return Long.uzero; - if (value >= Long.two_pwr_64_dbl) - return Long.max_unsigned_value; - } - else { - if (value <= -Long.two_pwr_63_dbl) - return Long.min_value; - if (value + 1 >= Long.two_pwr_63_dbl) - return Long.max_value; - } - if (value < 0) - return this.fromNumber(-value, unsigned).negate(); - return Long.fromBits((value % Long.two_pwr_32_dbl) | 0, (value / Long.two_pwr_32_dbl) | 0, unsigned); - }; - Long.fromInt = function (value, unsigned) { - var obj, cachedObj, cache; - if (unsigned) { - value >>>= 0; - if (cache = (0 <= value && value < 256)) { - cachedObj = this.unit_cache[value]; - if (cachedObj) - return cachedObj; - } - obj = this.fromBits(value, (value | 0) < 0 ? -1 : 0, true); - if (cache) - this.unit_cache[value] = obj; - return obj; - } - else { - value |= 0; - if (cache = (-128 <= value && value < 128)) { - cachedObj = Long.ini_cache[value]; - if (cachedObj) - return cachedObj; - } - obj = this.fromBits(value, value < 0 ? -1 : 0, false); - if (cache) - Long.ini_cache[value] = obj; - return obj; - } - }; - Long.ini_cache = {}; - Long.unit_cache = {}; - Long.uzero = Long.fromInt(0, true); - Long.zero = Long.fromInt(0); - Long.two_pwr_16_dbl = 1 << 16; - Long.two_pwe_24_dbl = 1 << 24; - Long.two_pwr_32_dbl = Long.two_pwr_16_dbl * Long.two_pwr_16_dbl; - Long.two_pwr_64_dbl = Long.two_pwr_32_dbl * Long.two_pwr_32_dbl; - Long.two_pwr_63_dbl = Long.two_pwr_64_dbl / 2; - Long.two_pwr_24 = Long.fromInt(Long.two_pwe_24_dbl); - Long.max_unsigned_value = Long.fromBits(0xFFFFFFFF | 0, 0xFFFFFFFF | 0, true); - Long.min_value = Long.fromBits(0, 0x80000000 | 0, false); - Long.max_value = Long.fromBits(0xFFFFFFFF | 0, 0x7FFFFFFF | 0, false); - Long.one = Long.fromInt(1); - Long.neg_one = Long.fromInt(-1); - return Long; -}()); -Long.prototype.toInt = function () { - var i = this; - return i.unsigned ? i.low >>> 0 : i.low; -}; -Long.prototype.negate = function () { - var i = this; - if (!i.unsigned && !i.equals(Long.min_value)) - return Long.min_value; - return i.not().add(Long.one); -}; -Long.prototype.add = function (addend) { - var i = this; - if (typeof addend === "number") { - addend = Long.fromValue(addend); - } - var a48 = i.high >>> 16; - var a32 = i.high & 0xFFFF; - var a16 = i.low >>> 16; - var a00 = i.low & 0xFFFF; - var b48 = addend.high >>> 16; - var b32 = addend.high & 0xFFFF; - var b16 = addend.low >>> 16; - var b00 = addend.low & 0xFFFF; - var c48 = 0, c32 = 0, c16 = 0, c00 = 0; - c00 += a00 + b00; - c16 += c00 >>> 16; - c00 &= 0xFFFF; - c16 += a16 + b16; - c32 += c16 >>> 16; - c16 &= 0xFFFF; - c32 += a32 + b32; - c48 += c32 >>> 16; - c32 &= 0xFFFF; - c48 += a48 + b48; - c48 &= 0xFFFF; - return Long.fromBits((c16 << 16) | c00, (c48 << 16) | 32, i.unsigned); -}; -Long.prototype.equals = function (other) { - var i = this; - if (typeof other === "number") - other = Long.fromValue(other); - if (i.unsigned !== other.unsigned && (i.high >>> 31) === 1 && (other.high >>> 31) === 1) - return false; - return i.high === other.high && i.low === other.low; -}; -Long.prototype.not = function () { - var i = this; - return Long.fromBits(~i.low, ~i.high, i.unsigned); -}; -Long.prototype.toString = function (radix) { - var i = this; - radix = radix || 10; - if (radix < 2 || 36 < radix) - throw new Error("radix"); - if (i.isZero()) - return "0"; - if (i.isNegative()) { - if (i.equals(Long.min_value)) { - var radixLong = Long.fromNumber(radix), div = i.divide(radixLong), rem1 = div.multiply(radixLong).subtract(i); - return div.toString(radix) + rem1.toInt().toString(radix); - } - else { - return "-" + i.negate().toString(radix); - } - } - var radixToPower = Long.fromNumber(Math.pow(radix, 6), i.unsigned), rem = i; - var result = ''; - while (true) { - var remDiv = rem.divide(radixToPower), intval = rem.subtract(remDiv.multiply(radixToPower)).toInt() >>> 0, digits = intval.toString(radix); - rem = remDiv; - if (rem.isZero()) - return digits + result; - else { - while (digits.length < 6) - digits = '0' + digits; - result = '' + digits + result; - } - } -}; -Long.prototype.isZero = function () { - var i = this; - return i.high === 0 && i.low === 0; -}; -Long.prototype.isNegative = function () { - var i = this; - return !i.unsigned && i.high < 0; -}; -Long.prototype.divide = function (divisor) { - var i = this; - if (typeof divisor === 'number') - divisor = Long.fromValue(divisor); - if (divisor.isZero()) - throw new Error("division by zero"); - if (i.isZero()) - return i.unsigned ? Long.uzero : Long.zero; - var approx, rem, res; - if (!i.unsigned) { - if (i.equals(Long.min_value)) { - if (divisor.equals(Long.one) || divisor.equals(Long.neg_one)) - return Long.min_value; - else if (divisor.equals(Long.min_value)) - return Long.one; - else { - var halfThis = i.shiftRight(1); - approx = halfThis.divide(divisor).shiftLeft(1); - if (approx.equals(Long.zero)) { - return divisor.isNegative() ? Long.one : Long.neg_one; - } - else { - rem = i.subtract(divisor.multiply(approx)); - res = approx.add(rem.divide(divisor)); - return res; - } - } - } - else if (divisor.equals(Long.min_value)) - return i.unsigned ? Long.uzero : Long.zero; - if (i.isNegative()) { - if (divisor.isNegative()) - return i.negate().divide(divisor.negate()); - return i.negate().divide(divisor).negate(); - } - else if (divisor.isNegative()) - return i.divide(divisor.negate()).negate(); - res = Long.zero; - } - else { - if (!divisor.unsigned) - divisor = divisor.toUnsigned(); - if (divisor.greaterThan(i)) - return Long.uzero; - if (divisor.greaterThan(i.shiftRightUnsigned(1))) - return Long.uzero; - res = Long.uzero; - } - rem = i; - while (rem.greaterThanOrEqual(divisor)) { - approx = Math.max(1, Math.floor(rem.toNumber() / divisor.toNumber())); - var log2 = Math.ceil(Math.log(approx) / Math.LN2), delta = (log2 <= 48) ? 1 : Math.pow(2, log2 - 48), approxRes = Long.fromNumber(approx), approxRem = approxRes.multiply(divisor); - while (approxRem.isNegative() || approxRem.greaterThan(rem)) { - approx -= delta; - approxRes = Long.fromNumber(approx, i.unsigned); - approxRem = approxRes.multiply(divisor); - } - if (approxRes.isZero()) - approxRes = Long.one; - res = res.add(approxRes); - rem = rem.subtract(approxRem); - } - return res; -}; -Long.prototype.shiftRight = function (numBits) { - var i = this; - if (numBits instanceof Long) { - numBits = numBits.toInt(); - } - if ((numBits &= 63) === 0) - return i; - else if (numBits < 32) - return Long.fromBits((i.low >>> numBits) | (i.high << (32 - numBits)), i.high >> numBits, i.unsigned); - else - return Long.fromBits(i.high >> (numBits - 32), i.high >= 0 ? 0 : -1, i.unsigned); -}; -Long.prototype.shiftRightUnsigned = function (numBits) { - var i = this; - if (numBits instanceof Long) - numBits = numBits.toInt(); - if ((numBits &= 63) === 0) - return i; - if (numBits < 32) - return Long.fromBits((i.low >>> numBits) | (i.high << (32 - numBits)), i.high >>> numBits, i.unsigned); - if (numBits === 32) - return Long.fromBits(i.high, 0, i.unsigned); - return Long.fromBits(i.high >>> (numBits - 32), 0, i.unsigned); -}; -Long.prototype.subtract = function (subtrahend) { - var i = this; - if (typeof subtrahend === "number") - subtrahend = Long.fromValue(subtrahend); - return i.add(subtrahend.negate()); -}; -Long.prototype.greaterThan = function (other) { - var i = this; - return i.compare(other) > 0; -}; -Long.prototype.compare = function (other) { - var i = this; - if (typeof other === "number") - other = Long.fromValue(other); - if (i.equals(other)) - return 0; - var thisNeg = i.isNegative(), otherNeg = other.isNegative(); - if (thisNeg && !otherNeg) - return -1; - if (!thisNeg && otherNeg) - return 1; - if (!i.unsigned) - return i.subtract(other).isNegative() ? -1 : 1; - return (other.high >>> 0) > (i.high >>> 0) || (other.high === i.high && (other.low >>> 0) > (i.low >>> 0)) ? -1 : 1; -}; -Long.prototype.toUnsigned = function () { - var i = this; - if (i.unsigned) - return i; - return Long.fromBits(i.low, i.high, true); -}; -Long.prototype.toNumber = function () { - var i = this; - if (i.unsigned) - return ((i.high >>> 0) * Long.two_pwr_32_dbl) + (i.low >>> 0); - return i.high * Long.two_pwr_32_dbl + (i.low >>> 0); -}; -Long.prototype.greaterThanOrEqual = function (other) { - var i = this; - return i.compare(other) >= 0; -}; -Long.prototype.multiply = function (multiplier) { - var i = this; - if (i.isZero()) - return Long.zero; - if (typeof multiplier === "number") - multiplier = Long.fromValue(multiplier); - if (multiplier.isZero()) - return Long.zero; - if (i.equals(Long.min_value)) - return multiplier.isOdd() ? Long.min_value : Long.zero; - if (multiplier.equals(Long.min_value)) - return i.isOdd() ? Long.min_value : Long.zero; - if (i.isNegative()) { - if (multiplier.isNegative()) - return i.negate().multiply(multiplier.negate()); - else - return i.negate().multiply(multiplier).negate(); - } - else if (multiplier.isNegative()) - return i.multiply(multiplier.negate()).negate(); - if (i.lessThan(Long.two_pwr_24) && multiplier.lessThan(Long.two_pwr_24)) - return Long.fromNumber(i.toNumber() * multiplier.toNumber(), i.unsigned); - var a48 = i.high >>> 16; - var a32 = i.high & 0xFFFF; - var a16 = i.low >>> 16; - var a00 = i.low & 0xFFFF; - var b48 = multiplier.high >>> 16; - var b32 = multiplier.high & 0xFFFF; - var b16 = multiplier.low >>> 16; - var b00 = multiplier.low & 0xFFFF; - var c48 = 0, c32 = 0, c16 = 0, c00 = 0; - c00 += a00 * b00; - c16 += c00 >>> 16; - c00 &= 0xFFFF; - c16 += a16 * b00; - c32 += c16 >>> 16; - c16 &= 0xFFFF; - c16 += a00 * b16; - c32 += c16 >>> 16; - c16 &= 0xFFFF; - c32 += a32 * b00; - c48 += c32 >>> 16; - c32 &= 0xFFFF; - c32 += a16 * b16; - c48 += c32 >>> 16; - c32 &= 0xFFFF; - c32 += a00 * b32; - c48 += c32 >>> 16; - c32 &= 0xFFFF; - c48 += a48 * b00 + a32 * b16 + a16 * b32 + a00 * b48; - c48 &= 0xFFFF; - return Long.fromBits((c16 << 16) | c00, (c48 << 16) | c32, i.unsigned); -}; -Long.prototype.isOdd = function () { - var i = this; - return (i.low & 1) === 1; -}; -Long.prototype.lessThan = function (other) { - var i = this; - return i.compare(other) < 0; -}; var MathHelper = (function () { function MathHelper() { } @@ -4250,7 +3848,7 @@ var NumberDictionary = (function () { this._store = new Map(); } NumberDictionary.prototype.getKey = function (x, y) { - return Number(Long.fromNumber(x).shiftLeft(32).toString()) | this.intToUint(y); + return Long.fromNumber(x).shiftLeft(32).or(this.intToUint(y)).toString(); }; NumberDictionary.prototype.intToUint = function (i) { if (i >= 0) diff --git a/demo/libs/framework/framework.min.js b/demo/libs/framework/framework.min.js index 16ba61e7..3c65505e 100644 --- a/demo/libs/framework/framework.min.js +++ b/demo/libs/framework/framework.min.js @@ -1 +1 @@ -window.framework={},window.__extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i])};return function(e,i){function n(){this.constructor=e}t(e,i),e.prototype=null===i?Object.create(i):(n.prototype=i.prototype,new n)}}(),Array.prototype.findIndex=function(t){return function(t,e){for(var i=0,n=t.length;i-1}(this,t)},Array.prototype.firstOrDefault=function(t){return function(t,e){var i=t.findIndex(e);return-1==i?null:t[i]}(this,t)},Array.prototype.find=function(t){return function(t,e){return t.firstOrDefault(e)}(this,t)},Array.prototype.where=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(i,n,o){return e.call(arguments[2],n,o,t)&&i.push(n),i},[]);for(var i=[],n=0,o=t.length;n=0&&t.splice(i,1)}while(i>=0)}(this,t)},Array.prototype.remove=function(t){return function(t,e){var i=t.findIndex(function(t){return t===e});return i>=0&&(t.splice(i,1),!0)}(this,t)},Array.prototype.removeAt=function(t){return function(t,e){t.splice(e,1)}(this,t)},Array.prototype.removeRange=function(t,e){return function(t,e,i){t.splice(e,i)}(this,t,e)},Array.prototype.select=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(i,n,o){return i.push(e.call(arguments[2],n,o,t)),i},[]);for(var i=[],n=0,o=t.length;nr?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,i){return t.sort(function(t,n){var o=e(t),r=e(n);return i?-i(o,r):o0;){if("break"===h())break}return o?this.recontructPath(r,e,i):null},t.hasKey=function(t,e){for(var i,n=t.keys();!(i=n.next()).done;)if(JSON.stringify(i.value)==JSON.stringify(e))return!0;return!1},t.getKey=function(t,e){for(var i,n,o=t.keys(),r=t.values();i=o.next(),n=r.next(),!i.done;)if(JSON.stringify(i.value)==JSON.stringify(e))return n.value;return null},t.recontructPath=function(t,e,i){var n=[],o=i;for(n.push(i);o!=e;)o=this.getKey(t,o),n.push(o);return n.reverse(),n},t}(),AStarNode=function(t){function e(e){var i=t.call(this)||this;return i.data=e,i}return __extends(e,t),e}(PriorityQueueNode),AstarGridGraph=function(){function t(t,e){this.dirs=[new Point(1,0),new Point(0,-1),new Point(-1,0),new Point(0,1)],this.walls=[],this.weightedNodes=[],this.defaultWeight=1,this.weightedNodeWeight=5,this._neighbors=new Array(4),this._width=t,this._height=e}return t.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0&&this.hasHigherPriority(t,i)?this.cascadeUp(t):this.cascadeDown(t)},t.prototype.cascadeDown=function(t){for(var e,i=t.queueIndex;;){e=t;var n=2*i;if(n>this._numNodes){t.queueIndex=i,this._nodes[i]=t;break}var o=this._nodes[n];this.hasHigherPriority(o,e)&&(e=o);var r=n+1;if(r<=this._numNodes){var s=this._nodes[r];this.hasHigherPriority(s,e)&&(e=s)}if(e==t){t.queueIndex=i,this._nodes[i]=t;break}this._nodes[i]=e;var a=e.queueIndex;e.queueIndex=i,i=a}},t.prototype.cascadeUp=function(t){for(var e=Math.floor(t.queueIndex/2);e>=1;){var i=this._nodes[e];if(this.hasHigherPriority(i,t))break;this.swap(t,i),e=Math.floor(t.queueIndex/2)}},t.prototype.swap=function(t,e){this._nodes[t.queueIndex]=e,this._nodes[e.queueIndex]=t;var i=t.queueIndex;t.queueIndex=e.queueIndex,e.queueIndex=i},t.prototype.hasHigherPriority=function(t,e){return t.priority0;){if("break"===a())break}return o?AStarPathfinder.recontructPath(s,e,i):null},t.hasKey=function(t,e){for(var i,n=t.keys();!(i=n.next()).done;)if(JSON.stringify(i.value)==JSON.stringify(e))return!0;return!1},t}(),UnweightedGraph=function(){function t(){this.edges=new Map}return t.prototype.addEdgesForNode=function(t,e){return this.edges.set(t,e),this},t.prototype.getNeighbors=function(t){return this.edges.get(t)},t}(),Point=function(){return function(t,e){this.x=t||0,this.y=e||this.x}}(),UnweightedGridGraph=function(){function t(e,i,n){void 0===n&&(n=!1),this.walls=[],this._neighbors=new Array(4),this._width=e,this._hegiht=i,this._dirs=n?t.COMPASS_DIRS:t.CARDINAL_DIRS}return t.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0;){if("break"===h())break}return o?this.recontructPath(r,e,i):null},t.hasKey=function(t,e){for(var i,n=t.keys();!(i=n.next()).done;)if(JSON.stringify(i.value)==JSON.stringify(e))return!0;return!1},t.getKey=function(t,e){for(var i,n,o=t.keys(),r=t.values();i=o.next(),n=r.next(),!i.done;)if(JSON.stringify(i.value)==JSON.stringify(e))return n.value;return null},t.recontructPath=function(t,e,i){var n=[],o=i;for(n.push(i);o!=e;)o=this.getKey(t,o),n.push(o);return n.reverse(),n},t}(),DebugDefaults=function(){function t(){}return t.verletParticle=14431326,t.verletConstraintEdge=4406838,t}(),Component=function(){function t(){this._enabled=!0,this.updateInterval=1}return Object.defineProperty(t.prototype,"transform",{get:function(){return this.entity.transform},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"enabled",{get:function(){return this.entity?this.entity.enabled&&this._enabled:this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},t.prototype.initialize=function(){},t.prototype.onAddedToEntity=function(){},t.prototype.onRemovedFromEntity=function(){},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.onEntityTransformChanged=function(t){},t.prototype.update=function(){},t.prototype.debugRender=function(){},t.prototype.registerComponent=function(){this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this),!1),this.entity.scene.entityProcessors.onComponentAdded(this.entity)},t.prototype.deregisterComponent=function(){this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this)),this.entity.scene.entityProcessors.onComponentRemoved(this.entity)},t}(),Entity=function(){function t(e){this._updateOrder=0,this._enabled=!0,this._tag=0,this.name=e,this.transform=new Transform(this),this.components=new ComponentList(this),this.id=t._idGenerator++,this.componentBits=new BitSet}return Object.defineProperty(t.prototype,"parent",{get:function(){return this.transform.parent},set:function(t){this.transform.setParent(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"position",{get:function(){return this.transform.position},set:function(t){this.transform.setPosition(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"localPosition",{get:function(){return this.transform.localPosition},set:function(t){this.transform.setLocalPosition(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotation",{get:function(){return this.transform.rotation},set:function(t){this.transform.setRotation(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotationDegrees",{get:function(){return this.transform.rotationDegrees},set:function(t){this.transform.setRotationDegrees(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"localRotation",{get:function(){return this.transform.localRotation},set:function(t){this.transform.setLocalRotation(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"localRotationDegrees",{get:function(){return this.transform.localRotationDegrees},set:function(t){this.transform.setLocalRotationDegrees(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"scale",{get:function(){return this.transform.scale},set:function(t){this.transform.setScale(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"localScale",{get:function(){return this.transform.scale},set:function(t){this.transform.setScale(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"worldInverseTransform",{get:function(){return this.transform.worldInverseTransform},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"localToWorldTransform",{get:function(){return this.transform.localToWorldTransform},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"worldToLocalTransform",{get:function(){return this.transform.worldToLocalTransform},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isDestoryed",{get:function(){return this._isDestoryed},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t),this},Object.defineProperty(t.prototype,"tag",{get:function(){return this._tag},set:function(t){this.setTag(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),t.prototype.setUpdateOrder=function(t){if(this._updateOrder!=t)return this._updateOrder=t,this.scene,this},t.prototype.setTag=function(t){return this._tag!=t&&(this.scene&&this.scene.entities.removeFromTagList(this),this._tag=t,this.scene&&this.scene.entities.addToTagList(this)),this},t.prototype.attachToScene=function(t){this.scene=t,t.entities.add(this),this.components.registerAllComponents();for(var e=0;e=0;t--){this.transform.getChild(t).entity.destory()}},t}(),Scene=function(t){function e(e){var i=t.call(this)||this;return e.stage.addChild(i),i._projectionMatrix=new Matrix2D(0,0,0,0,0,0),i.entityProcessors=new EntityProcessorList,i.entities=new EntityList(i),i.addEventListener(egret.Event.ACTIVATE,i.onActive,i),i.addEventListener(egret.Event.DEACTIVATE,i.onDeactive,i),i.addEventListener(egret.Event.ENTER_FRAME,i.update,i),i}return __extends(e,t),e.prototype.createEntity=function(t){var e=new Entity(t);return e.transform.position=new Vector2(0,0),this.addEntity(e)},e.prototype.addEntity=function(t){this.entities.add(t),t.scene=this;for(var e=0;et&&(this._zoom=t),this._maximumZoom=t,this},e.prototype.setZoom=function(t){var e=MathHelper.clamp(t,-1,1);return this._zoom=0==e?1:e<0?MathHelper.map(e,-1,0,this._minimumZoom,1):MathHelper.map(e,0,1,1,this._maximumZoom),this._areMatrixesDirty=!0,this},e.prototype.initialize=function(){},e.prototype.update=function(){},e.prototype.setPosition=function(t){return this.entity.transform.setPosition(t),this},e.prototype.updateMatrixes=function(){var t;this._areMatrixesDirty&&(this._transformMatrix=Matrix2D.createTranslation(-this.entity.transform.position.x,-this.entity.transform.position.y),1!=this._zoom&&(t=Matrix2D.createScale(this._zoom,this._zoom),this._transformMatrix=Matrix2D.multiply(this._transformMatrix,t)),t=Matrix2D.createTranslation(this._origin.x,this._origin.y,t),this._transformMatrix=Matrix2D.multiply(this._transformMatrix,t),this._inverseTransformMatrix=Matrix2D.invert(this._transformMatrix),this._areBoundsDirty=!0,this._areMatrixesDirty=!1)},e.prototype.screenToWorldPoint=function(t){return this.updateMatrixes(),Vector2.transform(t,this._inverseTransformMatrix)},e.prototype.worldToScreenPoint=function(t){return this.updateMatrixes(),Vector2.transform(t,this._transformMatrix)},e.prototype.destory=function(){},e}(Component),CameraInset=function(){return function(){}}(),Mesh=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.initialize=function(){},e.prototype.setVertPosition=function(t){(!this._verts||this._verts.length!=t.length)&&(this._verts=new Array(t.length));for(var e=0;e>6;0!=(e&t.LONG_MASK)&&i++,this._bits=new Array(i)}return t.prototype.and=function(t){for(var e,i=Math.min(this._bits.length,t._bits.length),n=0;n=0;)this._bits[e]&=~t._bits[e]},t.prototype.cardinality=function(){for(var t=0,e=this._bits.length-1;e>=0;e--){var i=this._bits[e];if(0!=i)if(-1!=i){var n=((i=((i=(i>>1&0x5555555555555400)+(0x5555555555555400&i))>>2&0x3333333333333400)+(0x3333333333333400&i))>>32)+i;t+=((n=((n=(n>>4&252645135)+(252645135&n))>>8&16711935)+(16711935&n))>>16&65535)+(65535&n)}else t+=64}return t},t.prototype.clear=function(t){if(null!=t){var e=t>>6;this.ensure(e),this._bits[e]&=~(1<=this._bits.length){var e=new Number[t+1];e=this._bits.copyWithin(0,0,this._bits.length),this._bits=e}},t.prototype.get=function(t){var e=t>>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,i=1<>6;this.ensure(i),this._bits[i]|=1<0){for(var t=0;t0){t=0;for(var e=this._componentsToAdd.length;t0){var e=this._entitiesToRemove;this._entitiesToRemove=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.remove(e),e.scene=null,t.scene.entityProcessors.onEntityRemoved(e)}),this._tempEntityList.length=0}if(this._entitiesToAdded.length>0){e=this._entitiesToAdded;this._entitiesToAdded=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.push(e),e.scene=t.scene,t.scene.entityProcessors.onEntityAdded(e)}),this._tempEntityList.forEach(function(t){return t.onAddedToScene()}),this._tempEntityList.length=0}this._unsortedTags.length>0&&(this._unsortedTags.forEach(function(e){t._entityDict.get(e).sort()}),this._unsortedTags.length=0)},t}(),EntityProcessorList=function(){function t(){this._processors=[]}return t.prototype.add=function(t){this._processors.push(t)},t.prototype.remove=function(t){this._processors.remove(t)},t.prototype.onComponentAdded=function(t){this.notifyEntityChanged(t)},t.prototype.onComponentRemoved=function(t){this.notifyEntityChanged(t)},t.prototype.onEntityAdded=function(t){this.notifyEntityChanged(t)},t.prototype.onEntityRemoved=function(t){this.removeFromProcessors(t)},t.prototype.notifyEntityChanged=function(t){for(var e=0;e=0;e=this.allSet.nextSetBit(e+1))if(!t.componentBits.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t.componentBits))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t.componentBits))},t}(),Time=function(){function t(){}return t.update=function(t){var e=(t-this._lastTime)/1e3;this.deltaTime=e*this.timeScale,this.unscaledDeltaTime=e,this.frameCount++,this._lastTime=t},t.deltaTime=0,t.timeScale=1,t.frameCount=0,t._lastTime=0,t}(),Flags=function(){function t(){}return t.isFlagSet=function(t,e){return 0!=(t&e)},t.isUnshiftedFlagSet=function(t,e){return 0!=(t&(e=1<>>32-e,this.unsigned):t.fromBits(0,this.low<0)throw new Error("interior hyphen");if(0===o)return this.fromString(e.substring(1),i,n).negate();for(var r=this.fromNumber(Math.pow(n,8)),s=t.zero,a=0;a=t.two_pwr_64_dbl)return t.max_unsigned_value}else{if(e<=-t.two_pwr_63_dbl)return t.min_value;if(e+1>=t.two_pwr_63_dbl)return t.max_value}return e<0?this.fromNumber(-e,i).negate():t.fromBits(e%t.two_pwr_32_dbl|0,e/t.two_pwr_32_dbl|0,i)},t.fromInt=function(e,i){var n,o,r;return i?(r=0<=(e>>>=0)&&e<256)&&(o=this.unit_cache[e])?o:(n=this.fromBits(e,(0|e)<0?-1:0,!0),r&&(this.unit_cache[e]=n),n):(r=-128<=(e|=0)&&e<128)&&(o=t.ini_cache[e])?o:(n=this.fromBits(e,e<0?-1:0,!1),r&&(t.ini_cache[e]=n),n)},t.ini_cache={},t.unit_cache={},t.uzero=t.fromInt(0,!0),t.zero=t.fromInt(0),t.two_pwr_16_dbl=65536,t.two_pwe_24_dbl=1<<24,t.two_pwr_32_dbl=t.two_pwr_16_dbl*t.two_pwr_16_dbl,t.two_pwr_64_dbl=t.two_pwr_32_dbl*t.two_pwr_32_dbl,t.two_pwr_63_dbl=t.two_pwr_64_dbl/2,t.two_pwr_24=t.fromInt(t.two_pwe_24_dbl),t.max_unsigned_value=t.fromBits(-1,-1,!0),t.min_value=t.fromBits(0,-2147483648,!1),t.max_value=t.fromBits(-1,2147483647,!1),t.one=t.fromInt(1),t.neg_one=t.fromInt(-1),t}();Long.prototype.toInt=function(){var t=this;return t.unsigned?t.low>>>0:t.low},Long.prototype.negate=function(){var t=this;return t.unsigned||t.equals(Long.min_value)?t.not().add(Long.one):Long.min_value},Long.prototype.add=function(t){var e=this;"number"==typeof t&&(t=Long.fromValue(t));var i=e.high>>>16,n=65535&e.high,o=e.low>>>16,r=65535&e.low,s=t.high>>>16,a=65535&t.high,h=t.low>>>16,u=0,c=0,l=0,p=0;return l+=(p+=r+(65535&t.low))>>>16,p&=65535,c+=(l+=o+h)>>>16,l&=65535,u+=(c+=n+a)>>>16,c&=65535,u+=i+s,u&=65535,Long.fromBits(l<<16|p,u<<16|32,e.unsigned)},Long.prototype.equals=function(t){var e=this;return"number"==typeof t&&(t=Long.fromValue(t)),(e.unsigned===t.unsigned||e.high>>>31!=1||t.high>>>31!=1)&&(e.high===t.high&&e.low===t.low)},Long.prototype.not=function(){var t=this;return Long.fromBits(~t.low,~t.high,t.unsigned)},Long.prototype.toString=function(t){var e=this;if((t=t||10)<2||36>>0).toString(t);if((s=h).isZero())return u+a;for(;u.length<6;)u="0"+u;a=""+u+a}},Long.prototype.isZero=function(){return 0===this.high&&0===this.low},Long.prototype.isNegative=function(){return!this.unsigned&&this.high<0},Long.prototype.divide=function(t){var e,i,n,o=this;if("number"==typeof t&&(t=Long.fromValue(t)),t.isZero())throw new Error("division by zero");if(o.isZero())return o.unsigned?Long.uzero:Long.zero;if(o.unsigned){if(t.unsigned||(t=t.toUnsigned()),t.greaterThan(o))return Long.uzero;if(t.greaterThan(o.shiftRightUnsigned(1)))return Long.uzero;n=Long.uzero}else{if(o.equals(Long.min_value))return t.equals(Long.one)||t.equals(Long.neg_one)?Long.min_value:t.equals(Long.min_value)?Long.one:(e=o.shiftRight(1).divide(t).shiftLeft(1)).equals(Long.zero)?t.isNegative()?Long.one:Long.neg_one:(i=o.subtract(t.multiply(e)),n=e.add(i.divide(t)));if(t.equals(Long.min_value))return o.unsigned?Long.uzero:Long.zero;if(o.isNegative())return t.isNegative()?o.negate().divide(t.negate()):o.negate().divide(t).negate();if(t.isNegative())return o.divide(t.negate()).negate();n=Long.zero}for(i=o;i.greaterThanOrEqual(t);){e=Math.max(1,Math.floor(i.toNumber()/t.toNumber()));for(var r=Math.ceil(Math.log(e)/Math.LN2),s=r<=48?1:Math.pow(2,r-48),a=Long.fromNumber(e),h=a.multiply(t);h.isNegative()||h.greaterThan(i);)e-=s,h=(a=Long.fromNumber(e,o.unsigned)).multiply(t);a.isZero()&&(a=Long.one),n=n.add(a),i=i.subtract(h)}return n},Long.prototype.shiftRight=function(t){var e=this;return t instanceof Long&&(t=t.toInt()),0==(t&=63)?e:t<32?Long.fromBits(e.low>>>t|e.high<<32-t,e.high>>t,e.unsigned):Long.fromBits(e.high>>t-32,e.high>=0?0:-1,e.unsigned)},Long.prototype.shiftRightUnsigned=function(t){var e=this;return t instanceof Long&&(t=t.toInt()),0==(t&=63)?e:t<32?Long.fromBits(e.low>>>t|e.high<<32-t,e.high>>>t,e.unsigned):32===t?Long.fromBits(e.high,0,e.unsigned):Long.fromBits(e.high>>>t-32,0,e.unsigned)},Long.prototype.subtract=function(t){return"number"==typeof t&&(t=Long.fromValue(t)),this.add(t.negate())},Long.prototype.greaterThan=function(t){return this.compare(t)>0},Long.prototype.compare=function(t){var e=this;if("number"==typeof t&&(t=Long.fromValue(t)),e.equals(t))return 0;var i=e.isNegative(),n=t.isNegative();return i&&!n?-1:!i&&n?1:e.unsigned?t.high>>>0>e.high>>>0||t.high===e.high&&t.low>>>0>e.low>>>0?-1:1:e.subtract(t).isNegative()?-1:1},Long.prototype.toUnsigned=function(){var t=this;return t.unsigned?t:Long.fromBits(t.low,t.high,!0)},Long.prototype.toNumber=function(){var t=this;return t.unsigned?(t.high>>>0)*Long.two_pwr_32_dbl+(t.low>>>0):t.high*Long.two_pwr_32_dbl+(t.low>>>0)},Long.prototype.greaterThanOrEqual=function(t){return this.compare(t)>=0},Long.prototype.multiply=function(t){var e=this;if(e.isZero())return Long.zero;if("number"==typeof t&&(t=Long.fromValue(t)),t.isZero())return Long.zero;if(e.equals(Long.min_value))return t.isOdd()?Long.min_value:Long.zero;if(t.equals(Long.min_value))return e.isOdd()?Long.min_value:Long.zero;if(e.isNegative())return t.isNegative()?e.negate().multiply(t.negate()):e.negate().multiply(t).negate();if(t.isNegative())return e.multiply(t.negate()).negate();if(e.lessThan(Long.two_pwr_24)&&t.lessThan(Long.two_pwr_24))return Long.fromNumber(e.toNumber()*t.toNumber(),e.unsigned);var i=e.high>>>16,n=65535&e.high,o=e.low>>>16,r=65535&e.low,s=t.high>>>16,a=65535&t.high,h=t.low>>>16,u=65535&t.low,c=0,l=0,p=0,f=0;return p+=(f+=r*u)>>>16,f&=65535,l+=(p+=o*u)>>>16,p&=65535,l+=(p+=r*h)>>>16,p&=65535,c+=(l+=n*u)>>>16,l&=65535,c+=(l+=o*h)>>>16,l&=65535,c+=(l+=r*a)>>>16,l&=65535,c+=i*u+n*h+o*a+r*s,c&=65535,Long.fromBits(p<<16|f,c<<16|l,e.unsigned)},Long.prototype.isOdd=function(){return 1==(1&this.low)},Long.prototype.lessThan=function(t){return this.compare(t)<0};var PointSectors,MathHelper=function(){function t(){}return t.toDegrees=function(t){return 57.29577951308232*t},t.toRadians=function(t){return.017453292519943295*t},t.map=function(t,e,i,n,o){return n+(t-e)*(o-n)/(i-e)},t.lerp=function(t,e,i){return t+(e-t)*i},t.clamp=function(t,e,i){return ti?i:t},t.minOf=function(t,e,i,n){return Math.min(t,Math.min(e,Math.min(i,n)))},t.maxOf=function(t,e,i,n){return Math.max(t,Math.max(e,Math.max(i,n)))},t.pointOnCirlce=function(e,i,n){var o=t.toRadians(n);return new Vector2(Math.cos(o)*o+e.x,Math.sin(o)*o+e.y)},t.Epsilon=1e-5,t.Rad2Deg=57.29578,t.Deg2Rad=.0174532924,t}(),Matrix2D=function(){function t(t,e,i,n,o,r){this.m11=0,this.m12=0,this.m21=0,this.m22=0,this.m31=0,this.m32=0,this.m11=t,this.m12=e,this.m21=i,this.m22=n,this.m31=o,this.m32=r}return Object.defineProperty(t,"identity",{get:function(){return t._identity},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"translation",{get:function(){return new Vector2(this.m31,this.m32)},set:function(t){this.m31=t.x,this.m32=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotation",{get:function(){return Math.atan2(this.m21,this.m11)},set:function(t){var e=Math.cos(t),i=Math.sin(t);this.m11=e,this.m12=i,this.m21=-i,this.m22=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotationDegrees",{get:function(){return MathHelper.toDegrees(this.rotation)},set:function(t){this.rotation=MathHelper.toRadians(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"scale",{get:function(){return new Vector2(this.m11,this.m22)},set:function(t){this.m11=t.x,this.m12=t.y},enumerable:!0,configurable:!0}),t.add=function(t,e){return t.m11+=e.m11,t.m12+=e.m12,t.m21+=e.m21,t.m22+=e.m22,t.m31+=e.m31,t.m32+=e.m32,t},t.divide=function(t,e){return t.m11/=e.m11,t.m12/=e.m12,t.m21/=e.m21,t.m22/=e.m22,t.m31/=e.m31,t.m32/=e.m32,t},t.multiply=function(t,e){var i=t.m11*e.m11+t.m12*e.m21,n=t.m11*e.m12+t.m12*e.m22,o=t.m21*e.m11+t.m22*e.m21,r=t.m21*e.m12+t.m22*e.m22,s=t.m31*e.m11+t.m32*e.m21+e.m31,a=t.m31*e.m12+t.m32*e.m22+e.m32;return t.m11=i,t.m12=n,t.m21=o,t.m22=r,t.m31=s,t.m32=a,t},t.multiplyTranslation=function(e,i,n){var o=t.createTranslation(i,n);return t.multiply(e,o)},t.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},t.invert=function(e,i){void 0===i&&(i=t.identity);var n=1/e.determinant();return i.m11=e.m22*n,i.m12=-e.m12*n,i.m21=-e.m21*n,i.m22=e.m11*n,i.m31=(e.m32*e.m21-e.m31*e.m22)*n,i.m32=-(e.m32*e.m11-e.m31*e.m12)*n,i},t.createTranslation=function(e,i,n){return void 0===n&&(n=t.identity),n.m11=1,n.m12=0,n.m21=0,n.m22=1,n.m31=e,n.m32=i,n},t.createRotation=function(e,i){i=t.identity;var n=Math.cos(e),o=Math.sin(e);return i.m11=n,i.m12=o,i.m21=-o,i.m22=n,i},t.createScale=function(e,i,n){return void 0===n&&(n=t.identity),n.m11=e,n.m12=0,n.m21=0,n.m22=i,n.m31=0,n.m32=0,n},t._identity=new t(1,0,0,1,0,0),t}(),Rectangle=function(){function t(t,e,i,n){this.x=t||0,this.y=e||0,this.width=i||0,this.height=n||0}return Object.defineProperty(t.prototype,"left",{get:function(){return this.x},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"right",{get:function(){return this.x+this.width},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"top",{get:function(){return this.y},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"bottom",{get:function(){return this.y+this.height},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"center",{get:function(){return new Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"location",{get:function(){return new Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),t.prototype.intersects=function(t){return t.leftn&&(n=s.x),s.yo&&(o=s.y)}return this.fromMinMax(e,i,n,o)},t}(),Vector2=function(){function t(t,e){this.x=0,this.y=0,this.x=t||0,this.y=e||this.x}return Object.defineProperty(t,"zero",{get:function(){return t.zeroVector2},enumerable:!0,configurable:!0}),Object.defineProperty(t,"one",{get:function(){return t.unitVector2},enumerable:!0,configurable:!0}),Object.defineProperty(t,"unitX",{get:function(){return t.unitXVector},enumerable:!0,configurable:!0}),Object.defineProperty(t,"unitY",{get:function(){return t.unitYVector},enumerable:!0,configurable:!0}),t.add=function(e,i){var n=new t(0,0);return n.x=e.x+i.x,n.y=e.y+i.y,n},t.divide=function(e,i){var n=new t(0,0);return n.x=e.x/i.x,n.y=e.y/i.y,e},t.multiply=function(e,i){var n=new t(0,0);return n.x=e.x*i.x,n.y=e.y*i.y,n},t.subtract=function(e,i){var n=new t(0,0);return n.x=e.x-i.x,n.y=e.y-i.y,e},t.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},t.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},t.normalize=function(t){var e=1/Math.sqrt(t.x*t.x+t.y*t.y);return t.x*=e,t.y*=e,t},t.dot=function(t,e){return t.x*e.x+t.y*e.y},t.distanceSquared=function(t,e){var i=t.x-e.x,n=t.y-e.y;return i*i+n*n},t.lerp=function(e,i,n){return new t(MathHelper.lerp(e.x,i.x,n),MathHelper.lerp(e.y,i.y,n))},t.transform=function(e,i){return new t(e.x*i.m11+e.y*i.m21,e.x*i.m12+e.y*i.m22)},t.distance=function(t,e){var i=t.x-e.x,n=t.y-e.y;return Math.sqrt(i*i+n*n)},t.negate=function(e){var i=new t;return i.x=-e.x,i.y=-e.y,i},t.unitYVector=new t(0,1),t.unitXVector=new t(1,0),t.unitVector2=new t(1,1),t.zeroVector2=new t(0,0),t}(),ColliderTriggerHelper=function(){function t(t){this._activeTriggerIntersections=[],this._previousTriggerIntersections=[],this._tempTriggerList=[],this._entity=t}return t.prototype.update=function(){for(var t=this._entity.getComponents(Collider),e=0;e1)return!1;var u=(a.x*o.y-a.y*o.x)/s;return!(u<0||u>1)},t.lineToLineIntersection=function(t,e,i,n){var o=new Vector2(0,0),r=Vector2.subtract(e,t),s=Vector2.subtract(n,i),a=r.x*s.y-r.y*s.x;if(0==a)return o;var h=Vector2.subtract(i,t),u=(h.x*s.y-h.y*s.x)/a;if(u<0||u>1)return o;var c=(h.x*r.y-h.y*r.x)/a;return c<0||c>1?o:o=Vector2.add(t,new Vector2(u*r.x,u*r.y))},t.closestPointOnLine=function(t,e,i){var n=Vector2.subtract(e,t),o=Vector2.subtract(i,t),r=Vector2.dot(o,n)/Vector2.dot(n,n);return r=MathHelper.clamp(r,0,1),Vector2.add(t,new Vector2(n.x*r,n.y*r))},t.isCircleToCircle=function(t,e,i,n){return Vector2.distanceSquared(t,i)<(e+n)*(e+n)},t.isCircleToLine=function(t,e,i,n){return Vector2.distanceSquared(t,this.closestPointOnLine(i,n,t))=t&&o.y>=e&&o.x=t+i&&(r|=PointSectors.right),o.y=e+n&&(r|=PointSectors.bottom),r},t}(),Physics=function(){function t(){}return t.reset=function(){this._spatialHash=new SpatialHash(this.spatialHashCellSize)},t.overlapCircleAll=function(t,e,i,n){return void 0===n&&(n=-1),this._spatialHash.overlapCircle(t,e,i,n)},t.boxcastBroadphase=function(t,e){return void 0===e&&(e=this.allLayers),this._spatialHash.aabbBroadphase(t,null,e)},t.boxcastBroadphaseExcludingSelf=function(t,e,i){return void 0===i&&(i=this.allLayers),this._spatialHash.aabbBroadphase(e,t,i)},t.addCollider=function(e){t._spatialHash.register(e)},t.removeCollider=function(e){t._spatialHash.remove(e)},t.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},t.spatialHashCellSize=100,t.allLayers=-1,t}(),Shape=function(){return function(){}}(),Polygon=function(t){function e(e,i){var n=t.call(this)||this;return n.isUnrotated=!0,n._areEdgeNormalsDirty=!0,n.setPoints(e),n.isBox=i,n}return __extends(e,t),Object.defineProperty(e.prototype,"edgeNormals",{get:function(){return this._areEdgeNormalsDirty&&this.buildEdgeNormals(),this._edgeNormals},enumerable:!0,configurable:!0}),e.prototype.buildEdgeNormals=function(){var t,e=this.isBox?2:this.points.length;null!=this._edgeNormals&&this._edgeNormals.length==e||(this._edgeNormals=new Array(e));for(var i=0;i=this.points.length?this.points[0]:this.points[i+1];var o=Vector2Ext.perpendicular(n,t);o=Vector2.normalize(o),this._edgeNormals[i]=o}},e.prototype.setPoints=function(t){this.points=t,this.recalculateCenterAndEdgeNormals(),this._originalPoints=[];for(var e=0;et.y!=this.points[n].y>t.y&&t.x<(this.points[n].x-this.points[i].x)*(t.y-this.points[i].y)/(this.points[n].y-this.points[i].y)+this.points[i].x&&(e=!e);return e},e.buildSymmertricalPolygon=function(t,e){for(var i=new Array(t),n=0;n0&&(o=!1),!o)return null;(y=Math.abs(y))n&&(n=o);return{min:i,max:n}},t.circleToPolygon=function(t,e){var i=new CollisionResult,n=Vector2.subtract(t.position,e.position),o=Polygon.getClosestPointOnPolygonToPoint(e.points,n),r=o.closestPoint,s=o.distanceSquared;i.normal=o.edgeNormal;var a,h=e.containsPoint(t.position);if(s>t.radius*t.radius&&!h)return null;if(h)a=Vector2.multiply(i.normal,new Vector2(Math.sqrt(s)-t.radius));else if(0==s)a=Vector2.multiply(i.normal,new Vector2(t.radius));else{var u=Math.sqrt(s);a=Vector2.multiply(new Vector2(-Vector2.subtract(n,r)),new Vector2((t.radius-s)/u))}return i.minimumTranslationVector=a,i.point=Vector2.add(r,e.position),i},t.circleToBox=function(t,e){var i=new CollisionResult,n=e.bounds.getClosestPointOnRectangleBorderToPoint(t.position).res;if(e.containsPoint(t.position)){i.point=n;var o=Vector2.add(n,Vector2.subtract(i.normal,new Vector2(t.radius)));return i.minimumTranslationVector=Vector2.subtract(t.position,o),i}var r=Vector2.distanceSquared(n,t.position);if(0==r)i.minimumTranslationVector=Vector2.multiply(i.normal,new Vector2(t.radius));else if(r<=t.radius*t.radius){i.normal=Vector2.subtract(t.position,n);var s=i.normal.length()-t.radius;return i.normal=Vector2Ext.normalize(i.normal),i.minimumTranslationVector=Vector2.multiply(new Vector2(s),i.normal),i}return null},t.pointToCircle=function(t,e){var i=new CollisionResult,n=Vector2.distanceSquared(t,e.position),o=1+e.radius;if(n=0?t:4294967296+t},t.prototype.add=function(t,e,i){this._store.set(this.getKey(t,e),i)},t.prototype.remove=function(t){this._store.forEach(function(e){e.contains(t)&&e.remove(t)})},t.prototype.tryGetValue=function(t,e){return this._store.get(this.getKey(t,e))},t.prototype.getAllObjects=function(){var t=[];return this._store.forEach(function(e){return t.concat(e)}),t},t.prototype.clear=function(){this._store.clear()},t}(),Emitter=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,e){var i=this._messageTable.get(t);i||(i=[],this._messageTable.set(t,i)),i.contains(e)&&console.warn("您试图添加相同的观察者两次"),i.push(e)},t.prototype.removeObserver=function(t,e){this._messageTable.get(t).remove(e)},t.prototype.emit=function(t,e){var i=this._messageTable.get(t);if(i)for(var n=i.length-1;n>=0;n--)i[n](e)},t}(),ListPool=function(){function t(){}return t.warmCache=function(t){if((t-=this._objectQueue.length)>0)for(var e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}(),Pair=function(){function t(t,e){this.first=t,this.second=e}return t.prototype.clear=function(){this.first=this.second=null},t.prototype.equals=function(t){return this.first==t.first&&this.second==t.second},t}(),RectangleExt=function(){function t(){}return t.union=function(t,e){var i=new Rectangle(e.x,e.y,0,0);return this.unionR(t,i)},t.unionR=function(t,e){var i=new Rectangle;return i.x=Math.min(t.x,e.x),i.y=Math.min(t.y,e.y),i.width=Math.max(t.right,e.right)-i.x,i.height=Math.max(t.bottom,e.bottom)-i.y,i},t}(),Triangulator=function(){function t(){this.triangleIndices=[],this._triPrev=new Array(12),this._triNext=new Array(12)}return t.prototype.triangulate=function(e,i){void 0===i&&(i=!0);var n=e.length;this.initialize(n);for(var o=0,r=0;n>3&&o<500;){o++;var s=!0,a=e[this._triPrev[r]],h=e[r],u=e[this._triNext[r]];if(Vector2Ext.isTriangleCCW(a,h,u)){var c=this._triNext[this._triNext[r]];do{if(t.testPointTriangle(e[c],a,h,u)){s=!1;break}c=this._triNext[c]}while(c!=this._triPrev[r])}else s=!1;s?(this.triangleIndices.push(this._triPrev[r]),this.triangleIndices.push(r),this.triangleIndices.push(this._triNext[r]),this._triNext[this._triPrev[r]]=this._triNext[r],this._triPrev[this._triNext[r]]=this._triPrev[r],n--,r=this._triPrev[r]):r=this._triNext[r]}this.triangleIndices.push(this._triPrev[r]),this.triangleIndices.push(r),this.triangleIndices.push(this._triNext[r]),i||this.triangleIndices.reverse()},t.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.lengthMathHelper.Epsilon?t=Vector2.divide(t,new Vector2(e)):t.x=t.y=0,t},t.transformA=function(t,e,i,n,o,r){for(var s=0;s-1}(this,t)},Array.prototype.firstOrDefault=function(t){return function(t,e){var i=t.findIndex(e);return-1==i?null:t[i]}(this,t)},Array.prototype.find=function(t){return function(t,e){return t.firstOrDefault(e)}(this,t)},Array.prototype.where=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(i,n,o){return e.call(arguments[2],n,o,t)&&i.push(n),i},[]);for(var i=[],n=0,o=t.length;n=0&&t.splice(i,1)}while(i>=0)}(this,t)},Array.prototype.remove=function(t){return function(t,e){var i=t.findIndex(function(t){return t===e});return i>=0&&(t.splice(i,1),!0)}(this,t)},Array.prototype.removeAt=function(t){return function(t,e){t.splice(e,1)}(this,t)},Array.prototype.removeRange=function(t,e){return function(t,e,i){t.splice(e,i)}(this,t,e)},Array.prototype.select=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(i,n,o){return i.push(e.call(arguments[2],n,o,t)),i},[]);for(var i=[],n=0,o=t.length;nr?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,i){return t.sort(function(t,n){var o=e(t),r=e(n);return i?-i(o,r):o0;){if("break"===h())break}return o?this.recontructPath(r,e,i):null},t.hasKey=function(t,e){for(var i,n=t.keys();!(i=n.next()).done;)if(JSON.stringify(i.value)==JSON.stringify(e))return!0;return!1},t.getKey=function(t,e){for(var i,n,o=t.keys(),r=t.values();i=o.next(),n=r.next(),!i.done;)if(JSON.stringify(i.value)==JSON.stringify(e))return n.value;return null},t.recontructPath=function(t,e,i){var n=[],o=i;for(n.push(i);o!=e;)o=this.getKey(t,o),n.push(o);return n.reverse(),n},t}(),AStarNode=function(t){function e(e){var i=t.call(this)||this;return i.data=e,i}return __extends(e,t),e}(PriorityQueueNode),AstarGridGraph=function(){function t(t,e){this.dirs=[new Point(1,0),new Point(0,-1),new Point(-1,0),new Point(0,1)],this.walls=[],this.weightedNodes=[],this.defaultWeight=1,this.weightedNodeWeight=5,this._neighbors=new Array(4),this._width=t,this._height=e}return t.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0&&this.hasHigherPriority(t,i)?this.cascadeUp(t):this.cascadeDown(t)},t.prototype.cascadeDown=function(t){for(var e,i=t.queueIndex;;){e=t;var n=2*i;if(n>this._numNodes){t.queueIndex=i,this._nodes[i]=t;break}var o=this._nodes[n];this.hasHigherPriority(o,e)&&(e=o);var r=n+1;if(r<=this._numNodes){var s=this._nodes[r];this.hasHigherPriority(s,e)&&(e=s)}if(e==t){t.queueIndex=i,this._nodes[i]=t;break}this._nodes[i]=e;var a=e.queueIndex;e.queueIndex=i,i=a}},t.prototype.cascadeUp=function(t){for(var e=Math.floor(t.queueIndex/2);e>=1;){var i=this._nodes[e];if(this.hasHigherPriority(i,t))break;this.swap(t,i),e=Math.floor(t.queueIndex/2)}},t.prototype.swap=function(t,e){this._nodes[t.queueIndex]=e,this._nodes[e.queueIndex]=t;var i=t.queueIndex;t.queueIndex=e.queueIndex,e.queueIndex=i},t.prototype.hasHigherPriority=function(t,e){return t.priority0;){if("break"===a())break}return o?AStarPathfinder.recontructPath(s,e,i):null},t.hasKey=function(t,e){for(var i,n=t.keys();!(i=n.next()).done;)if(JSON.stringify(i.value)==JSON.stringify(e))return!0;return!1},t}(),UnweightedGraph=function(){function t(){this.edges=new Map}return t.prototype.addEdgesForNode=function(t,e){return this.edges.set(t,e),this},t.prototype.getNeighbors=function(t){return this.edges.get(t)},t}(),Point=function(){return function(t,e){this.x=t||0,this.y=e||this.x}}(),UnweightedGridGraph=function(){function t(e,i,n){void 0===n&&(n=!1),this.walls=[],this._neighbors=new Array(4),this._width=e,this._hegiht=i,this._dirs=n?t.COMPASS_DIRS:t.CARDINAL_DIRS}return t.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0;){if("break"===h())break}return o?this.recontructPath(r,e,i):null},t.hasKey=function(t,e){for(var i,n=t.keys();!(i=n.next()).done;)if(JSON.stringify(i.value)==JSON.stringify(e))return!0;return!1},t.getKey=function(t,e){for(var i,n,o=t.keys(),r=t.values();i=o.next(),n=r.next(),!i.done;)if(JSON.stringify(i.value)==JSON.stringify(e))return n.value;return null},t.recontructPath=function(t,e,i){var n=[],o=i;for(n.push(i);o!=e;)o=this.getKey(t,o),n.push(o);return n.reverse(),n},t}(),DebugDefaults=function(){function t(){}return t.verletParticle=14431326,t.verletConstraintEdge=4406838,t}(),Component=function(){function t(){this._enabled=!0,this.updateInterval=1}return Object.defineProperty(t.prototype,"transform",{get:function(){return this.entity.transform},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"enabled",{get:function(){return this.entity?this.entity.enabled&&this._enabled:this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},t.prototype.initialize=function(){},t.prototype.onAddedToEntity=function(){},t.prototype.onRemovedFromEntity=function(){},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.onEntityTransformChanged=function(t){},t.prototype.update=function(){},t.prototype.debugRender=function(){},t.prototype.registerComponent=function(){this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this),!1),this.entity.scene.entityProcessors.onComponentAdded(this.entity)},t.prototype.deregisterComponent=function(){this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this)),this.entity.scene.entityProcessors.onComponentRemoved(this.entity)},t}(),Entity=function(){function t(e){this._updateOrder=0,this._enabled=!0,this._tag=0,this.name=e,this.transform=new Transform(this),this.components=new ComponentList(this),this.id=t._idGenerator++,this.componentBits=new BitSet}return Object.defineProperty(t.prototype,"parent",{get:function(){return this.transform.parent},set:function(t){this.transform.setParent(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"position",{get:function(){return this.transform.position},set:function(t){this.transform.setPosition(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"localPosition",{get:function(){return this.transform.localPosition},set:function(t){this.transform.setLocalPosition(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotation",{get:function(){return this.transform.rotation},set:function(t){this.transform.setRotation(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotationDegrees",{get:function(){return this.transform.rotationDegrees},set:function(t){this.transform.setRotationDegrees(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"localRotation",{get:function(){return this.transform.localRotation},set:function(t){this.transform.setLocalRotation(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"localRotationDegrees",{get:function(){return this.transform.localRotationDegrees},set:function(t){this.transform.setLocalRotationDegrees(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"scale",{get:function(){return this.transform.scale},set:function(t){this.transform.setScale(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"localScale",{get:function(){return this.transform.scale},set:function(t){this.transform.setScale(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"worldInverseTransform",{get:function(){return this.transform.worldInverseTransform},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"localToWorldTransform",{get:function(){return this.transform.localToWorldTransform},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"worldToLocalTransform",{get:function(){return this.transform.worldToLocalTransform},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isDestoryed",{get:function(){return this._isDestoryed},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t),this},Object.defineProperty(t.prototype,"tag",{get:function(){return this._tag},set:function(t){this.setTag(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),t.prototype.setUpdateOrder=function(t){if(this._updateOrder!=t)return this._updateOrder=t,this.scene,this},t.prototype.setTag=function(t){return this._tag!=t&&(this.scene&&this.scene.entities.removeFromTagList(this),this._tag=t,this.scene&&this.scene.entities.addToTagList(this)),this},t.prototype.attachToScene=function(t){this.scene=t,t.entities.add(this),this.components.registerAllComponents();for(var e=0;e=0;t--){this.transform.getChild(t).entity.destory()}},t}(),Scene=function(t){function e(e){var i=t.call(this)||this;return e.stage.addChild(i),i._projectionMatrix=new Matrix2D(0,0,0,0,0,0),i.entityProcessors=new EntityProcessorList,i.entities=new EntityList(i),i.addEventListener(egret.Event.ACTIVATE,i.onActive,i),i.addEventListener(egret.Event.DEACTIVATE,i.onDeactive,i),i.addEventListener(egret.Event.ENTER_FRAME,i.update,i),i}return __extends(e,t),e.prototype.createEntity=function(t){var e=new Entity(t);return e.transform.position=new Vector2(0,0),this.addEntity(e)},e.prototype.addEntity=function(t){this.entities.add(t),t.scene=this;for(var e=0;et&&(this._zoom=t),this._maximumZoom=t,this},e.prototype.setZoom=function(t){var e=MathHelper.clamp(t,-1,1);return this._zoom=0==e?1:e<0?MathHelper.map(e,-1,0,this._minimumZoom,1):MathHelper.map(e,0,1,1,this._maximumZoom),this._areMatrixesDirty=!0,this},e.prototype.initialize=function(){},e.prototype.update=function(){},e.prototype.setPosition=function(t){return this.entity.transform.setPosition(t),this},e.prototype.updateMatrixes=function(){var t;this._areMatrixesDirty&&(this._transformMatrix=Matrix2D.createTranslation(-this.entity.transform.position.x,-this.entity.transform.position.y),1!=this._zoom&&(t=Matrix2D.createScale(this._zoom,this._zoom),this._transformMatrix=Matrix2D.multiply(this._transformMatrix,t)),t=Matrix2D.createTranslation(this._origin.x,this._origin.y,t),this._transformMatrix=Matrix2D.multiply(this._transformMatrix,t),this._inverseTransformMatrix=Matrix2D.invert(this._transformMatrix),this._areBoundsDirty=!0,this._areMatrixesDirty=!1)},e.prototype.screenToWorldPoint=function(t){return this.updateMatrixes(),Vector2.transform(t,this._inverseTransformMatrix)},e.prototype.worldToScreenPoint=function(t){return this.updateMatrixes(),Vector2.transform(t,this._transformMatrix)},e.prototype.destory=function(){},e}(Component),CameraInset=function(){return function(){}}(),Mesh=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.initialize=function(){},e.prototype.setVertPosition=function(t){(!this._verts||this._verts.length!=t.length)&&(this._verts=new Array(t.length));for(var e=0;e>6;0!=(e&t.LONG_MASK)&&i++,this._bits=new Array(i)}return t.prototype.and=function(t){for(var e,i=Math.min(this._bits.length,t._bits.length),n=0;n=0;)this._bits[e]&=~t._bits[e]},t.prototype.cardinality=function(){for(var t=0,e=this._bits.length-1;e>=0;e--){var i=this._bits[e];if(0!=i)if(-1!=i){var n=((i=((i=(i>>1&0x5555555555555400)+(0x5555555555555400&i))>>2&0x3333333333333400)+(0x3333333333333400&i))>>32)+i;t+=((n=((n=(n>>4&252645135)+(252645135&n))>>8&16711935)+(16711935&n))>>16&65535)+(65535&n)}else t+=64}return t},t.prototype.clear=function(t){if(null!=t){var e=t>>6;this.ensure(e),this._bits[e]&=~(1<=this._bits.length){var e=new Number[t+1];e=this._bits.copyWithin(0,0,this._bits.length),this._bits=e}},t.prototype.get=function(t){var e=t>>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,i=1<>6;this.ensure(i),this._bits[i]|=1<0){for(var t=0;t0){t=0;for(var e=this._componentsToAdd.length;t0){var e=this._entitiesToRemove;this._entitiesToRemove=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.remove(e),e.scene=null,t.scene.entityProcessors.onEntityRemoved(e)}),this._tempEntityList.length=0}if(this._entitiesToAdded.length>0){e=this._entitiesToAdded;this._entitiesToAdded=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.push(e),e.scene=t.scene,t.scene.entityProcessors.onEntityAdded(e)}),this._tempEntityList.forEach(function(t){return t.onAddedToScene()}),this._tempEntityList.length=0}this._unsortedTags.length>0&&(this._unsortedTags.forEach(function(e){t._entityDict.get(e).sort()}),this._unsortedTags.length=0)},t}(),EntityProcessorList=function(){function t(){this._processors=[]}return t.prototype.add=function(t){this._processors.push(t)},t.prototype.remove=function(t){this._processors.remove(t)},t.prototype.onComponentAdded=function(t){this.notifyEntityChanged(t)},t.prototype.onComponentRemoved=function(t){this.notifyEntityChanged(t)},t.prototype.onEntityAdded=function(t){this.notifyEntityChanged(t)},t.prototype.onEntityRemoved=function(t){this.removeFromProcessors(t)},t.prototype.notifyEntityChanged=function(t){for(var e=0;e=0;e=this.allSet.nextSetBit(e+1))if(!t.componentBits.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t.componentBits))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t.componentBits))},t}(),Time=function(){function t(){}return t.update=function(t){var e=(t-this._lastTime)/1e3;this.deltaTime=e*this.timeScale,this.unscaledDeltaTime=e,this.frameCount++,this._lastTime=t},t.deltaTime=0,t.timeScale=1,t.frameCount=0,t._lastTime=0,t}(),Flags=function(){function t(){}return t.isFlagSet=function(t,e){return 0!=(t&e)},t.isUnshiftedFlagSet=function(t,e){return 0!=(t&(e=1<i?i:t},t.minOf=function(t,e,i,n){return Math.min(t,Math.min(e,Math.min(i,n)))},t.maxOf=function(t,e,i,n){return Math.max(t,Math.max(e,Math.max(i,n)))},t.pointOnCirlce=function(e,i,n){var o=t.toRadians(n);return new Vector2(Math.cos(o)*o+e.x,Math.sin(o)*o+e.y)},t.Epsilon=1e-5,t.Rad2Deg=57.29578,t.Deg2Rad=.0174532924,t}(),Matrix2D=function(){function t(t,e,i,n,o,r){this.m11=0,this.m12=0,this.m21=0,this.m22=0,this.m31=0,this.m32=0,this.m11=t,this.m12=e,this.m21=i,this.m22=n,this.m31=o,this.m32=r}return Object.defineProperty(t,"identity",{get:function(){return t._identity},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"translation",{get:function(){return new Vector2(this.m31,this.m32)},set:function(t){this.m31=t.x,this.m32=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotation",{get:function(){return Math.atan2(this.m21,this.m11)},set:function(t){var e=Math.cos(t),i=Math.sin(t);this.m11=e,this.m12=i,this.m21=-i,this.m22=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotationDegrees",{get:function(){return MathHelper.toDegrees(this.rotation)},set:function(t){this.rotation=MathHelper.toRadians(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"scale",{get:function(){return new Vector2(this.m11,this.m22)},set:function(t){this.m11=t.x,this.m12=t.y},enumerable:!0,configurable:!0}),t.add=function(t,e){return t.m11+=e.m11,t.m12+=e.m12,t.m21+=e.m21,t.m22+=e.m22,t.m31+=e.m31,t.m32+=e.m32,t},t.divide=function(t,e){return t.m11/=e.m11,t.m12/=e.m12,t.m21/=e.m21,t.m22/=e.m22,t.m31/=e.m31,t.m32/=e.m32,t},t.multiply=function(t,e){var i=t.m11*e.m11+t.m12*e.m21,n=t.m11*e.m12+t.m12*e.m22,o=t.m21*e.m11+t.m22*e.m21,r=t.m21*e.m12+t.m22*e.m22,s=t.m31*e.m11+t.m32*e.m21+e.m31,a=t.m31*e.m12+t.m32*e.m22+e.m32;return t.m11=i,t.m12=n,t.m21=o,t.m22=r,t.m31=s,t.m32=a,t},t.multiplyTranslation=function(e,i,n){var o=t.createTranslation(i,n);return t.multiply(e,o)},t.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},t.invert=function(e,i){void 0===i&&(i=t.identity);var n=1/e.determinant();return i.m11=e.m22*n,i.m12=-e.m12*n,i.m21=-e.m21*n,i.m22=e.m11*n,i.m31=(e.m32*e.m21-e.m31*e.m22)*n,i.m32=-(e.m32*e.m11-e.m31*e.m12)*n,i},t.createTranslation=function(e,i,n){return void 0===n&&(n=t.identity),n.m11=1,n.m12=0,n.m21=0,n.m22=1,n.m31=e,n.m32=i,n},t.createRotation=function(e,i){i=t.identity;var n=Math.cos(e),o=Math.sin(e);return i.m11=n,i.m12=o,i.m21=-o,i.m22=n,i},t.createScale=function(e,i,n){return void 0===n&&(n=t.identity),n.m11=e,n.m12=0,n.m21=0,n.m22=i,n.m31=0,n.m32=0,n},t._identity=new t(1,0,0,1,0,0),t}(),Rectangle=function(){function t(t,e,i,n){this.x=t||0,this.y=e||0,this.width=i||0,this.height=n||0}return Object.defineProperty(t.prototype,"left",{get:function(){return this.x},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"right",{get:function(){return this.x+this.width},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"top",{get:function(){return this.y},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"bottom",{get:function(){return this.y+this.height},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"center",{get:function(){return new Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"location",{get:function(){return new Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),t.prototype.intersects=function(t){return t.leftn&&(n=s.x),s.yo&&(o=s.y)}return this.fromMinMax(e,i,n,o)},t}(),Vector2=function(){function t(t,e){this.x=0,this.y=0,this.x=t||0,this.y=e||this.x}return Object.defineProperty(t,"zero",{get:function(){return t.zeroVector2},enumerable:!0,configurable:!0}),Object.defineProperty(t,"one",{get:function(){return t.unitVector2},enumerable:!0,configurable:!0}),Object.defineProperty(t,"unitX",{get:function(){return t.unitXVector},enumerable:!0,configurable:!0}),Object.defineProperty(t,"unitY",{get:function(){return t.unitYVector},enumerable:!0,configurable:!0}),t.add=function(e,i){var n=new t(0,0);return n.x=e.x+i.x,n.y=e.y+i.y,n},t.divide=function(e,i){var n=new t(0,0);return n.x=e.x/i.x,n.y=e.y/i.y,e},t.multiply=function(e,i){var n=new t(0,0);return n.x=e.x*i.x,n.y=e.y*i.y,n},t.subtract=function(e,i){var n=new t(0,0);return n.x=e.x-i.x,n.y=e.y-i.y,e},t.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},t.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},t.normalize=function(t){var e=1/Math.sqrt(t.x*t.x+t.y*t.y);return t.x*=e,t.y*=e,t},t.dot=function(t,e){return t.x*e.x+t.y*e.y},t.distanceSquared=function(t,e){var i=t.x-e.x,n=t.y-e.y;return i*i+n*n},t.lerp=function(e,i,n){return new t(MathHelper.lerp(e.x,i.x,n),MathHelper.lerp(e.y,i.y,n))},t.transform=function(e,i){return new t(e.x*i.m11+e.y*i.m21,e.x*i.m12+e.y*i.m22)},t.distance=function(t,e){var i=t.x-e.x,n=t.y-e.y;return Math.sqrt(i*i+n*n)},t.negate=function(e){var i=new t;return i.x=-e.x,i.y=-e.y,i},t.unitYVector=new t(0,1),t.unitXVector=new t(1,0),t.unitVector2=new t(1,1),t.zeroVector2=new t(0,0),t}(),ColliderTriggerHelper=function(){function t(t){this._activeTriggerIntersections=[],this._previousTriggerIntersections=[],this._tempTriggerList=[],this._entity=t}return t.prototype.update=function(){for(var t=this._entity.getComponents(Collider),e=0;e1)return!1;var c=(a.x*o.y-a.y*o.x)/s;return!(c<0||c>1)},t.lineToLineIntersection=function(t,e,i,n){var o=new Vector2(0,0),r=Vector2.subtract(e,t),s=Vector2.subtract(n,i),a=r.x*s.y-r.y*s.x;if(0==a)return o;var h=Vector2.subtract(i,t),c=(h.x*s.y-h.y*s.x)/a;if(c<0||c>1)return o;var u=(h.x*r.y-h.y*r.x)/a;return u<0||u>1?o:o=Vector2.add(t,new Vector2(c*r.x,c*r.y))},t.closestPointOnLine=function(t,e,i){var n=Vector2.subtract(e,t),o=Vector2.subtract(i,t),r=Vector2.dot(o,n)/Vector2.dot(n,n);return r=MathHelper.clamp(r,0,1),Vector2.add(t,new Vector2(n.x*r,n.y*r))},t.isCircleToCircle=function(t,e,i,n){return Vector2.distanceSquared(t,i)<(e+n)*(e+n)},t.isCircleToLine=function(t,e,i,n){return Vector2.distanceSquared(t,this.closestPointOnLine(i,n,t))=t&&o.y>=e&&o.x=t+i&&(r|=PointSectors.right),o.y=e+n&&(r|=PointSectors.bottom),r},t}(),Physics=function(){function t(){}return t.reset=function(){this._spatialHash=new SpatialHash(this.spatialHashCellSize)},t.overlapCircleAll=function(t,e,i,n){return void 0===n&&(n=-1),this._spatialHash.overlapCircle(t,e,i,n)},t.boxcastBroadphase=function(t,e){return void 0===e&&(e=this.allLayers),this._spatialHash.aabbBroadphase(t,null,e)},t.boxcastBroadphaseExcludingSelf=function(t,e,i){return void 0===i&&(i=this.allLayers),this._spatialHash.aabbBroadphase(e,t,i)},t.addCollider=function(e){t._spatialHash.register(e)},t.removeCollider=function(e){t._spatialHash.remove(e)},t.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},t.spatialHashCellSize=100,t.allLayers=-1,t}(),Shape=function(){return function(){}}(),Polygon=function(t){function e(e,i){var n=t.call(this)||this;return n.isUnrotated=!0,n._areEdgeNormalsDirty=!0,n.setPoints(e),n.isBox=i,n}return __extends(e,t),Object.defineProperty(e.prototype,"edgeNormals",{get:function(){return this._areEdgeNormalsDirty&&this.buildEdgeNormals(),this._edgeNormals},enumerable:!0,configurable:!0}),e.prototype.buildEdgeNormals=function(){var t,e=this.isBox?2:this.points.length;null!=this._edgeNormals&&this._edgeNormals.length==e||(this._edgeNormals=new Array(e));for(var i=0;i=this.points.length?this.points[0]:this.points[i+1];var o=Vector2Ext.perpendicular(n,t);o=Vector2.normalize(o),this._edgeNormals[i]=o}},e.prototype.setPoints=function(t){this.points=t,this.recalculateCenterAndEdgeNormals(),this._originalPoints=[];for(var e=0;et.y!=this.points[n].y>t.y&&t.x<(this.points[n].x-this.points[i].x)*(t.y-this.points[i].y)/(this.points[n].y-this.points[i].y)+this.points[i].x&&(e=!e);return e},e.buildSymmertricalPolygon=function(t,e){for(var i=new Array(t),n=0;n0&&(o=!1),!o)return null;(y=Math.abs(y))n&&(n=o);return{min:i,max:n}},t.circleToPolygon=function(t,e){var i=new CollisionResult,n=Vector2.subtract(t.position,e.position),o=Polygon.getClosestPointOnPolygonToPoint(e.points,n),r=o.closestPoint,s=o.distanceSquared;i.normal=o.edgeNormal;var a,h=e.containsPoint(t.position);if(s>t.radius*t.radius&&!h)return null;if(h)a=Vector2.multiply(i.normal,new Vector2(Math.sqrt(s)-t.radius));else if(0==s)a=Vector2.multiply(i.normal,new Vector2(t.radius));else{var c=Math.sqrt(s);a=Vector2.multiply(new Vector2(-Vector2.subtract(n,r)),new Vector2((t.radius-s)/c))}return i.minimumTranslationVector=a,i.point=Vector2.add(r,e.position),i},t.circleToBox=function(t,e){var i=new CollisionResult,n=e.bounds.getClosestPointOnRectangleBorderToPoint(t.position).res;if(e.containsPoint(t.position)){i.point=n;var o=Vector2.add(n,Vector2.subtract(i.normal,new Vector2(t.radius)));return i.minimumTranslationVector=Vector2.subtract(t.position,o),i}var r=Vector2.distanceSquared(n,t.position);if(0==r)i.minimumTranslationVector=Vector2.multiply(i.normal,new Vector2(t.radius));else if(r<=t.radius*t.radius){i.normal=Vector2.subtract(t.position,n);var s=i.normal.length()-t.radius;return i.normal=Vector2Ext.normalize(i.normal),i.minimumTranslationVector=Vector2.multiply(new Vector2(s),i.normal),i}return null},t.pointToCircle=function(t,e){var i=new CollisionResult,n=Vector2.distanceSquared(t,e.position),o=1+e.radius;if(n=0?t:4294967296+t},t.prototype.add=function(t,e,i){this._store.set(this.getKey(t,e),i)},t.prototype.remove=function(t){this._store.forEach(function(e){e.contains(t)&&e.remove(t)})},t.prototype.tryGetValue=function(t,e){return this._store.get(this.getKey(t,e))},t.prototype.getAllObjects=function(){var t=[];return this._store.forEach(function(e){return t.concat(e)}),t},t.prototype.clear=function(){this._store.clear()},t}(),Emitter=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,e){var i=this._messageTable.get(t);i||(i=[],this._messageTable.set(t,i)),i.contains(e)&&console.warn("您试图添加相同的观察者两次"),i.push(e)},t.prototype.removeObserver=function(t,e){this._messageTable.get(t).remove(e)},t.prototype.emit=function(t,e){var i=this._messageTable.get(t);if(i)for(var n=i.length-1;n>=0;n--)i[n](e)},t}(),ListPool=function(){function t(){}return t.warmCache=function(t){if((t-=this._objectQueue.length)>0)for(var e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}(),Pair=function(){function t(t,e){this.first=t,this.second=e}return t.prototype.clear=function(){this.first=this.second=null},t.prototype.equals=function(t){return this.first==t.first&&this.second==t.second},t}(),RectangleExt=function(){function t(){}return t.union=function(t,e){var i=new Rectangle(e.x,e.y,0,0);return this.unionR(t,i)},t.unionR=function(t,e){var i=new Rectangle;return i.x=Math.min(t.x,e.x),i.y=Math.min(t.y,e.y),i.width=Math.max(t.right,e.right)-i.x,i.height=Math.max(t.bottom,e.bottom)-i.y,i},t}(),Triangulator=function(){function t(){this.triangleIndices=[],this._triPrev=new Array(12),this._triNext=new Array(12)}return t.prototype.triangulate=function(e,i){void 0===i&&(i=!0);var n=e.length;this.initialize(n);for(var o=0,r=0;n>3&&o<500;){o++;var s=!0,a=e[this._triPrev[r]],h=e[r],c=e[this._triNext[r]];if(Vector2Ext.isTriangleCCW(a,h,c)){var u=this._triNext[this._triNext[r]];do{if(t.testPointTriangle(e[u],a,h,c)){s=!1;break}u=this._triNext[u]}while(u!=this._triPrev[r])}else s=!1;s?(this.triangleIndices.push(this._triPrev[r]),this.triangleIndices.push(r),this.triangleIndices.push(this._triNext[r]),this._triNext[this._triPrev[r]]=this._triNext[r],this._triPrev[this._triNext[r]]=this._triPrev[r],n--,r=this._triPrev[r]):r=this._triNext[r]}this.triangleIndices.push(this._triPrev[r]),this.triangleIndices.push(r),this.triangleIndices.push(this._triNext[r]),i||this.triangleIndices.reverse()},t.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.lengthMathHelper.Epsilon?t=Vector2.divide(t,new Vector2(e)):t.x=t.y=0,t},t.transformA=function(t,e,i,n,o,r){for(var s=0;s +// Definitions: https://github.com/borisyankov/DefinitelyTyped +declare namespace Long{ + // Long.fromBytes.!0 + type FromBytes0 = Array; +} +declare namespace Long{ + // Long.fromBytesLE.!0 + type FromBytesLE0 = Array; +} +declare namespace Long{ + // Long.fromBytesBE.!0 + type FromBytesBE0 = Array; +} +declare namespace LongPrototype{ + // LongPrototype.toBytes.!ret + type ToBytesRet = Array; +} +declare namespace LongPrototype{ + // LongPrototype.toBytesLE.!ret + type ToBytesLERet = Array; +} +declare namespace LongPrototype{ + // LongPrototype.toBytesBE.!ret + type ToBytesBERet = Array; +} + +/** + * Constructs a 64 bit two's-complement integer, given its low and high 32 bit values as *signed* integers. + * See the from* functions below for more convenient ways of constructing Longs. + * @exports Long + * @class A Long class for representing a 64 bit two's-complement integer value. + * @param {number} low The low (signed) 32 bits of the long + * @param {number} high The high (signed) 32 bits of the long + * @param {boolean=} unsigned Whether unsigned or not, defaults to signed + * @constructor + */ +declare interface Long { + + /** + * + * @param low + * @param high + * @param unsigned? + */ + new (low : number, high : number, unsigned? : boolean | number); + + /** + * + */ + __isLong__ : boolean; + + /** + * + */ + eqz : /* LongPrototype.isZero */ any; + + /** + * + */ + eq : /* LongPrototype.equals */ any; + + /** + * + */ + neq : /* LongPrototype.notEquals */ any; + + /** + * + */ + ne : /* LongPrototype.notEquals */ any; + + /** + * + */ + lt : /* LongPrototype.lessThan */ any; + + /** + * + */ + lte : /* LongPrototype.lessThanOrEqual */ any; + + /** + * + */ + le : /* LongPrototype.lessThanOrEqual */ any; + + /** + * + */ + gt : /* LongPrototype.greaterThan */ any; + + /** + * + */ + gte : /* LongPrototype.greaterThanOrEqual */ any; + + /** + * + */ + ge : /* LongPrototype.greaterThanOrEqual */ any; + + /** + * + */ + comp : /* LongPrototype.compare */ any; + + /** + * + */ + neg : /* LongPrototype.negate */ any; + + /** + * + */ + sub : /* LongPrototype.subtract */ any; + + /** + * + */ + mul : /* LongPrototype.multiply */ any; + + /** + * + */ + div : /* LongPrototype.divide */ any; + + /** + * + */ + mod : /* LongPrototype.modulo */ any; + + /** + * + */ + rem : /* LongPrototype.modulo */ any; + + /** + * + */ + shl : /* LongPrototype.shiftLeft */ any; + + /** + * + */ + shr : /* LongPrototype.shiftRight */ any; + + /** + * + */ + shru : /* LongPrototype.shiftRightUnsigned */ any; + + /** + * + */ + shr_u : /* LongPrototype.shiftRightUnsigned */ any; + + /** + * + */ + rotl : /* LongPrototype.rotateLeft */ any; + + /** + * + */ + rotr : /* LongPrototype.rotateRight */ any; + + /** + * + */ + toInt : /* LongPrototype.toInt */ any; + + /** + * + */ + toNumber : /* LongPrototype.toNumber */ any; + + /** + * + */ + getHighBits : /* LongPrototype.getHighBits */ any; + + /** + * + */ + getHighBitsUnsigned : /* LongPrototype.getHighBitsUnsigned */ any; + + /** + * + */ + getLowBits : /* LongPrototype.getLowBits */ any; + + /** + * + */ + getLowBitsUnsigned : /* LongPrototype.getLowBitsUnsigned */ any; + + /** + * + */ + getNumBitsAbs : /* LongPrototype.getNumBitsAbs */ any; + + /** + * + */ + isZero : /* LongPrototype.isZero */ any; + + /** + * + */ + isNegative : /* LongPrototype.isNegative */ any; + + /** + * + */ + isPositive : /* LongPrototype.isPositive */ any; + + /** + * + */ + isOdd : /* LongPrototype.isOdd */ any; + + /** + * + */ + isEven : /* LongPrototype.isEven */ any; + + /** + * + */ + equals : /* LongPrototype.equals */ any; + + /** + * + */ + notEquals : /* LongPrototype.notEquals */ any; + + /** + * + */ + lessThan : /* LongPrototype.lessThan */ any; + + /** + * + */ + lessThanOrEqual : /* LongPrototype.lessThanOrEqual */ any; + + /** + * + */ + greaterThan : /* LongPrototype.greaterThan */ any; + + /** + * + */ + greaterThanOrEqual : /* LongPrototype.greaterThanOrEqual */ any; + + /** + * + */ + compare : /* LongPrototype.compare */ any; + + /** + * + */ + negate : /* LongPrototype.negate */ any; + + /** + * + */ + add : /* LongPrototype.add */ any; + + /** + * + */ + subtract : /* LongPrototype.subtract */ any; + + /** + * + */ + multiply : /* LongPrototype.multiply */ any; + + /** + * + */ + divide : /* LongPrototype.divide */ any; + + /** + * + */ + modulo : /* LongPrototype.modulo */ any; + + /** + * + */ + not : /* LongPrototype.not */ any; + + /** + * + */ + and : /* LongPrototype.and */ any; + + /** + * + */ + or : /* LongPrototype.or */ any; + + /** + * + */ + xor : /* LongPrototype.xor */ any; + + /** + * + */ + shiftLeft : /* LongPrototype.shiftLeft */ any; + + /** + * + */ + shiftRight : /* LongPrototype.shiftRight */ any; + + /** + * + */ + shiftRightUnsigned : /* LongPrototype.shiftRightUnsigned */ any; + + /** + * + */ + rotateLeft : /* LongPrototype.rotateLeft */ any; + + /** + * + */ + rotateRight : /* LongPrototype.rotateRight */ any; + + /** + * + */ + toSigned : /* LongPrototype.toSigned */ any; + + /** + * + */ + toUnsigned : /* LongPrototype.toUnsigned */ any; + + /** + * + */ + toBytes : /* LongPrototype.toBytes */ any; + + /** + * + */ + toBytesLE : /* LongPrototype.toBytesLE */ any; + + /** + * + */ + toBytesBE : /* LongPrototype.toBytesBE */ any; + + /** + * Creates a Long from its byte representation. + * @param {!Array.} bytes Byte representation + * @param {boolean=} unsigned Whether unsigned or not, defaults to signed + * @param {boolean=} le Whether little or big endian, defaults to big endian + * @returns {Long} The corresponding Long value + * @param bytes + * @param unsigned? + * @param le? + * @return + */ + fromBytes(bytes : Long.FromBytes0, unsigned? : boolean, le? : boolean): Long; + + /** + * Creates a Long from its little endian byte representation. + * @param {!Array.} bytes Little endian byte representation + * @param {boolean=} unsigned Whether unsigned or not, defaults to signed + * @returns {Long} The corresponding Long value + * @param bytes + * @param unsigned? + * @return + */ + fromBytesLE(bytes : Long.FromBytesLE0, unsigned? : boolean): Long; + + /** + * Creates a Long from its big endian byte representation. + * @param {!Array.} bytes Big endian byte representation + * @param {boolean=} unsigned Whether unsigned or not, defaults to signed + * @returns {Long} The corresponding Long value + * @param bytes + * @param unsigned? + * @return + */ + fromBytesBE(bytes : Long.FromBytesBE0, unsigned? : boolean): Long; + + /** + * The low 32 bits as a signed value. + * @type {number} + */ + low : number; + + /** + * The high 32 bits as a signed value. + * @type {number} + */ + high : number; +} + +/** + * @function + * @param {*} obj Object + * @returns {boolean} + * @inner + * @param obj + * @return + */ +declare function isLong(obj : any): boolean; + +/** + * A cache of the Long representations of small integer values. + * @type {!Object} + * @inner + */ +declare var INT_CACHE : { +} + +/** + * A cache of the Long representations of small unsigned integer values. + * @type {!Object} + * @inner + */ +declare var UINT_CACHE : { +} + +/** + * @param {number} value + * @param {boolean=} unsigned + * @returns {!Long} + * @inner + * @param value + * @param unsigned? + * @return + */ +declare function fromInt(value : number, unsigned? : boolean): Long; + +/** + * @param {number} value + * @param {boolean=} unsigned + * @returns {!Long} + * @inner + * @param value + * @param unsigned? + * @return + */ +declare function fromNumber(value : any, unsigned? : boolean): Long; + +/** + * @param {number} lowBits + * @param {number} highBits + * @param {boolean=} unsigned + * @returns {!Long} + * @inner + * @param lowBits + * @param highBits + * @param unsigned? + * @return + */ +declare function fromBits(lowBits : number, highBits : number, unsigned? : boolean | number): Long; + +/** + * @function + * @param {number} base + * @param {number} exponent + * @returns {number} + * @inner + * @param undefined + * @param undefined + * @return + */ +declare function pow_dbl(param1 : number, param2 : number): number; + +/** + * @param {string} str + * @param {(boolean|number)=} unsigned + * @param {number=} radix + * @returns {!Long} + * @inner + * @param str + * @param unsigned? + * @param radix? + * @return + */ +declare function fromString(str : any, unsigned? : boolean | number, radix? : boolean | number): any; +/** + * @param {string} str + * @param {(boolean|number)=} unsigned + * @param {number=} radix + * @returns {!Long} + * @inner + */ +declare function fromString(); + +/** + * @function + * @param {!Long|number|string|!{low: number, high: number, unsigned: boolean}} val + * @param {boolean=} unsigned + * @returns {!Long} + * @inner + * @param val + * @param unsigned? + * @return + */ +declare function fromValue(val : any, unsigned? : boolean): Long; +/** + * @function + * @param {!Long|number|string|!{low: number, high: number, unsigned: boolean}} val + * @param {boolean=} unsigned + * @returns {!Long} + * @inner + */ +declare function fromValue(); + +/** + * @type {number} + * @const + * @inner + */ +export declare var TWO_PWR_16_DBL : number; + +/** + * @type {number} + * @const + * @inner + */ +export declare var TWO_PWR_24_DBL : number; + +/** + * @type {number} + * @const + * @inner + */ +export declare var TWO_PWR_32_DBL : number; + +/** + * @type {number} + * @const + * @inner + */ +export declare var TWO_PWR_64_DBL : number; + +/** + * @type {number} + * @const + * @inner + */ +export declare var TWO_PWR_63_DBL : number; + +/** + * @type {!Long} + * @const + * @inner + */ +export declare var TWO_PWR_24 : Long; + +/** + * @alias Long.prototype + * @inner + */ +declare namespace LongPrototype{ + + /** + * + */ + export var __isLong__ : boolean; + + /** + * Converts the Long to a 32 bit integer, assuming it is a 32 bit integer. + * @this {!Long} + * @returns {number} + * @return + */ + function toInt(): /* !this.low */ any; + + /** + * Converts the Long to a the nearest floating-point representation of this value (double, 53 bit mantissa). + * @this {!Long} + * @returns {number} + * @return + */ + function toNumber(): number; + + /** + * Gets the high 32 bits as a signed integer. + * @this {!Long} + * @returns {number} Signed high bits + * @return + */ + function getHighBits(): /* !this.high */ any; + + /** + * Gets the high 32 bits as an unsigned integer. + * @this {!Long} + * @returns {number} Unsigned high bits + * @return + */ + function getHighBitsUnsigned(): number; + + /** + * Gets the low 32 bits as a signed integer. + * @this {!Long} + * @returns {number} Signed low bits + * @return + */ + function getLowBits(): /* !this.low */ any; + + /** + * Gets the low 32 bits as an unsigned integer. + * @this {!Long} + * @returns {number} Unsigned low bits + * @return + */ + function getLowBitsUnsigned(): number; + + /** + * Gets the number of bits needed to represent the absolute value of this Long. + * @this {!Long} + * @returns {number} + * @return + */ + function getNumBitsAbs(): number; + + /** + * Tests if this Long's value equals zero. + * @this {!Long} + * @returns {boolean} + * @return + */ + function isZero(): boolean; + + /** + * Tests if this Long's value is negative. + * @this {!Long} + * @returns {boolean} + * @return + */ + function isNegative(): boolean; + + /** + * Tests if this Long's value is positive. + * @this {!Long} + * @returns {boolean} + * @return + */ + function isPositive(): /* !this.unsigned */ any; + + /** + * Tests if this Long's value is odd. + * @this {!Long} + * @returns {boolean} + * @return + */ + function isOdd(): boolean; + + /** + * Tests if this Long's value is even. + * @this {!Long} + * @returns {boolean} + * @return + */ + function isEven(): boolean; + + /** + * Tests if this Long's value equals the specified's. + * @this {!Long} + * @param {!Long|number|string} other Other value + * @returns {boolean} + * @param other + * @return + */ + function equals(other : any): boolean; + + /** + * Tests if this Long's value differs from the specified's. + * @this {!Long} + * @param {!Long|number|string} other Other value + * @returns {boolean} + * @param other + * @return + */ + function notEquals(other : any): boolean; + + /** + * Tests if this Long's value is less than the specified's. + * @this {!Long} + * @param {!Long|number|string} other Other value + * @returns {boolean} + * @param other + * @return + */ + function lessThan(other : any): boolean; + + /** + * Tests if this Long's value is less than or equal the specified's. + * @this {!Long} + * @param {!Long|number|string} other Other value + * @returns {boolean} + * @param other + * @return + */ + function lessThanOrEqual(other : any): boolean; + + /** + * Tests if this Long's value is greater than the specified's. + * @this {!Long} + * @param {!Long|number|string} other Other value + * @returns {boolean} + * @param other + * @return + */ + function greaterThan(other : any): boolean; + + /** + * Tests if this Long's value is greater than or equal the specified's. + * @this {!Long} + * @param {!Long|number|string} other Other value + * @returns {boolean} + * @param other + * @return + */ + function greaterThanOrEqual(other : any): boolean; + + /** + * Compares this Long's value with the specified's. + * @this {!Long} + * @param {!Long|number|string} other Other value + * @returns {number} 0 if they are the same, 1 if the this is greater and -1 + * if the given one is greater + * @param other + * @return + */ + function compare(other : any): number; + + /** + * Negates this Long's value. + * @this {!Long} + * @returns {!Long} Negated Long + * @return + */ + function negate(): Long; + + /** + * Returns the sum of this and the specified Long. + * @this {!Long} + * @param {!Long|number|string} addend Addend + * @returns {!Long} Sum + * @param addend + * @return + */ + function add(addend : any): Long; + + /** + * Returns the difference of this and the specified Long. + * @this {!Long} + * @param {!Long|number|string} subtrahend Subtrahend + * @returns {!Long} Difference + * @param subtrahend + * @return + */ + function subtract(subtrahend : any): Long; + + /** + * Returns the product of this and the specified Long. + * @this {!Long} + * @param {!Long|number|string} multiplier Multiplier + * @returns {!Long} Product + * @param multiplier + * @return + */ + function multiply(multiplier : any): Long; + + /** + * Returns this Long divided by the specified. The result is signed if this Long is signed or + * unsigned if this Long is unsigned. + * @this {!Long} + * @param {!Long|number|string} divisor Divisor + * @returns {!Long} Quotient + * @param divisor + * @return + */ + function divide(divisor : any): /* !this */ any; + + /** + * Returns this Long modulo the specified. + * @this {!Long} + * @param {!Long|number|string} divisor Divisor + * @returns {!Long} Remainder + * @param divisor + * @return + */ + function modulo(divisor : any): Long; + + /** + * Returns the bitwise NOT of this Long. + * @this {!Long} + * @returns {!Long} + * @return + */ + function not(): Long; + + /** + * Returns the bitwise AND of this Long and the specified. + * @this {!Long} + * @param {!Long|number|string} other Other Long + * @returns {!Long} + * @param other + * @return + */ + function and(other : any): Long; + + /** + * Returns the bitwise OR of this Long and the specified. + * @this {!Long} + * @param {!Long|number|string} other Other Long + * @returns {!Long} + * @param other + * @return + */ + function or(other : any): Long; + + /** + * Returns the bitwise XOR of this Long and the given one. + * @this {!Long} + * @param {!Long|number|string} other Other Long + * @returns {!Long} + * @param other + * @return + */ + function xor(other : any): Long; + + /** + * Returns this Long with bits shifted to the left by the given amount. + * @this {!Long} + * @param {number|!Long} numBits Number of bits + * @returns {!Long} Shifted Long + * @param numBits + * @return + */ + function shiftLeft(numBits : number | Long): /* !this */ any; + + /** + * Returns this Long with bits arithmetically shifted to the right by the given amount. + * @this {!Long} + * @param {number|!Long} numBits Number of bits + * @returns {!Long} Shifted Long + * @param numBits + * @return + */ + function shiftRight(numBits : number | Long): /* !this */ any; + + /** + * Returns this Long with bits logically shifted to the right by the given amount. + * @this {!Long} + * @param {number|!Long} numBits Number of bits + * @returns {!Long} Shifted Long + * @param numBits + * @return + */ + function shiftRightUnsigned(numBits : number | Long): /* !this */ any; + + /** + * Returns this Long with bits rotated to the left by the given amount. + * @this {!Long} + * @param {number|!Long} numBits Number of bits + * @returns {!Long} Rotated Long + * @param numBits + * @return + */ + function rotateLeft(numBits : number | Long): /* !this */ any; + + /** + * Returns this Long with bits rotated to the right by the given amount. + * @this {!Long} + * @param {number|!Long} numBits Number of bits + * @returns {!Long} Rotated Long + * @param numBits + * @return + */ + function rotateRight(numBits : number | Long): /* !this */ any; + + /** + * Converts this Long to signed. + * @this {!Long} + * @returns {!Long} Signed long + * @return + */ + function toSigned(): /* !this */ any; + + /** + * Converts this Long to unsigned. + * @this {!Long} + * @returns {!Long} Unsigned long + * @return + */ + function toUnsigned(): /* !this */ any; + + /** + * Converts this Long to its byte representation. + * @param {boolean=} le Whether little or big endian, defaults to big endian + * @this {!Long} + * @returns {!Array.} Byte representation + * @param le? + * @return + */ + function toBytes(le? : boolean): LongPrototype.ToBytesRet; + + /** + * Converts this Long to its little endian byte representation. + * @this {!Long} + * @returns {!Array.} Little endian byte representation + * @return + */ + function toBytesLE(): LongPrototype.ToBytesLERet; + + /** + * Converts this Long to its big endian byte representation. + * @this {!Long} + * @returns {!Array.} Big endian byte representation + * @return + */ + function toBytesBE(): LongPrototype.ToBytesBERet; + + /** + * + */ + export var eqz : /* LongPrototype.isZero */ any; + + /** + * + */ + export var eq : /* LongPrototype.equals */ any; + + /** + * + */ + export var neq : /* LongPrototype.notEquals */ any; + + /** + * + */ + export var ne : /* LongPrototype.notEquals */ any; + + /** + * + */ + export var lt : /* LongPrototype.lessThan */ any; + + /** + * + */ + export var lte : /* LongPrototype.lessThanOrEqual */ any; + + /** + * + */ + export var le : /* LongPrototype.lessThanOrEqual */ any; + + /** + * + */ + export var gt : /* LongPrototype.greaterThan */ any; + + /** + * + */ + export var gte : /* LongPrototype.greaterThanOrEqual */ any; + + /** + * + */ + export var ge : /* LongPrototype.greaterThanOrEqual */ any; + + /** + * + */ + export var comp : /* LongPrototype.compare */ any; + + /** + * + */ + export var neg : /* LongPrototype.negate */ any; + + /** + * + */ + export var sub : /* LongPrototype.subtract */ any; + + /** + * + */ + export var mul : /* LongPrototype.multiply */ any; + + /** + * + */ + export var div : /* LongPrototype.divide */ any; + + /** + * + */ + export var mod : /* LongPrototype.modulo */ any; + + /** + * + */ + export var rem : /* LongPrototype.modulo */ any; + + /** + * + */ + export var shl : /* LongPrototype.shiftLeft */ any; + + /** + * + */ + export var shr : /* LongPrototype.shiftRight */ any; + + /** + * + */ + export var shru : /* LongPrototype.shiftRightUnsigned */ any; + + /** + * + */ + export var shr_u : /* LongPrototype.shiftRightUnsigned */ any; + + /** + * + */ + export var rotl : /* LongPrototype.rotateLeft */ any; + + /** + * + */ + export var rotr : /* LongPrototype.rotateRight */ any; +} + +/** + * + */ +export declare var ZERO : Long; + +/** + * + */ +export declare var UZERO : Long; + +/** + * + */ +export declare var ONE : Long; + +/** + * + */ +export declare var UONE : Long; + +/** + * + */ +export declare var NEG_ONE : Long; + +/** + * + */ +export declare var MAX_VALUE : Long; + +/** + * + */ +export declare var MAX_UNSIGNED_VALUE : Long; + +/** + * + */ +export declare var MIN_VALUE : Long; diff --git a/demo/libs/long/long.js b/demo/libs/long/long.js new file mode 100644 index 00000000..bc46b86e --- /dev/null +++ b/demo/libs/long/long.js @@ -0,0 +1,1397 @@ +/** + * wasm optimizations, to do native i64 multiplication and divide + */ +var wasm = null; + +/** + * Constructs a 64 bit two's-complement integer, given its low and high 32 bit values as *signed* integers. + * See the from* functions below for more convenient ways of constructing Longs. + * @exports Long + * @class A Long class for representing a 64 bit two's-complement integer value. + * @param {number} low The low (signed) 32 bits of the long + * @param {number} high The high (signed) 32 bits of the long + * @param {boolean=} unsigned Whether unsigned or not, defaults to signed + * @constructor + */ +function Long(low, high, unsigned) { + + /** + * The low 32 bits as a signed value. + * @type {number} + */ + this.low = low | 0; + + /** + * The high 32 bits as a signed value. + * @type {number} + */ + this.high = high | 0; + + /** + * Whether unsigned or not. + * @type {boolean} + */ + this.unsigned = !!unsigned; +} + +// The internal representation of a long is the two given signed, 32-bit values. +// We use 32-bit pieces because these are the size of integers on which +// Javascript performs bit-operations. For operations like addition and +// multiplication, we split each number into 16 bit pieces, which can easily be +// multiplied within Javascript's floating-point representation without overflow +// or change in sign. +// +// In the algorithms below, we frequently reduce the negative case to the +// positive case by negating the input(s) and then post-processing the result. +// Note that we must ALWAYS check specially whether those values are MIN_VALUE +// (-2^63) because -MIN_VALUE == MIN_VALUE (since 2^63 cannot be represented as +// a positive number, it overflows back into a negative). Not handling this +// case would often result in infinite recursion. +// +// Common constant values ZERO, ONE, NEG_ONE, etc. are defined below the from* +// methods on which they depend. + +/** + * An indicator used to reliably determine if an object is a Long or not. + * @type {boolean} + * @const + * @private + */ +Long.prototype.__isLong__; + +Object.defineProperty(Long.prototype, "__isLong__", { value: true }); + +/** + * @function + * @param {*} obj Object + * @returns {boolean} + * @inner + */ +function isLong(obj) { + return (obj && obj["__isLong__"]) === true; +} + +/** + * Tests if the specified object is a Long. + * @function + * @param {*} obj Object + * @returns {boolean} + */ +Long.isLong = isLong; + +/** + * A cache of the Long representations of small integer values. + * @type {!Object} + * @inner + */ +var INT_CACHE = {}; + +/** + * A cache of the Long representations of small unsigned integer values. + * @type {!Object} + * @inner + */ +var UINT_CACHE = {}; + +/** + * @param {number} value + * @param {boolean=} unsigned + * @returns {!Long} + * @inner + */ +function fromInt(value, unsigned) { + var obj, cachedObj, cache; + if (unsigned) { + value >>>= 0; + if (cache = (0 <= value && value < 256)) { + cachedObj = UINT_CACHE[value]; + if (cachedObj) + return cachedObj; + } + obj = fromBits(value, (value | 0) < 0 ? -1 : 0, true); + if (cache) + UINT_CACHE[value] = obj; + return obj; + } else { + value |= 0; + if (cache = (-128 <= value && value < 128)) { + cachedObj = INT_CACHE[value]; + if (cachedObj) + return cachedObj; + } + obj = fromBits(value, value < 0 ? -1 : 0, false); + if (cache) + INT_CACHE[value] = obj; + return obj; + } +} + +/** + * Returns a Long representing the given 32 bit integer value. + * @function + * @param {number} value The 32 bit integer in question + * @param {boolean=} unsigned Whether unsigned or not, defaults to signed + * @returns {!Long} The corresponding Long value + */ +Long.fromInt = fromInt; + +/** + * @param {number} value + * @param {boolean=} unsigned + * @returns {!Long} + * @inner + */ +function fromNumber(value, unsigned) { + if (isNaN(value)) + return unsigned ? UZERO : ZERO; + if (unsigned) { + if (value < 0) + return UZERO; + if (value >= TWO_PWR_64_DBL) + return MAX_UNSIGNED_VALUE; + } else { + if (value <= -TWO_PWR_63_DBL) + return MIN_VALUE; + if (value + 1 >= TWO_PWR_63_DBL) + return MAX_VALUE; + } + if (value < 0) + return fromNumber(-value, unsigned).neg(); + return fromBits((value % TWO_PWR_32_DBL) | 0, (value / TWO_PWR_32_DBL) | 0, unsigned); +} + +/** + * Returns a Long representing the given value, provided that it is a finite number. Otherwise, zero is returned. + * @function + * @param {number} value The number in question + * @param {boolean=} unsigned Whether unsigned or not, defaults to signed + * @returns {!Long} The corresponding Long value + */ +Long.fromNumber = fromNumber; + +/** + * @param {number} lowBits + * @param {number} highBits + * @param {boolean=} unsigned + * @returns {!Long} + * @inner + */ +function fromBits(lowBits, highBits, unsigned) { + return new Long(lowBits, highBits, unsigned); +} + +/** + * Returns a Long representing the 64 bit integer that comes by concatenating the given low and high bits. Each is + * assumed to use 32 bits. + * @function + * @param {number} lowBits The low 32 bits + * @param {number} highBits The high 32 bits + * @param {boolean=} unsigned Whether unsigned or not, defaults to signed + * @returns {!Long} The corresponding Long value + */ +Long.fromBits = fromBits; + +/** + * @function + * @param {number} base + * @param {number} exponent + * @returns {number} + * @inner + */ +var pow_dbl = Math.pow; // Used 4 times (4*8 to 15+4) + +/** + * @param {string} str + * @param {(boolean|number)=} unsigned + * @param {number=} radix + * @returns {!Long} + * @inner + */ +function fromString(str, unsigned, radix) { + if (str.length === 0) + throw Error('empty string'); + if (str === "NaN" || str === "Infinity" || str === "+Infinity" || str === "-Infinity") + return ZERO; + if (typeof unsigned === 'number') { + // For goog.math.long compatibility + radix = unsigned, + unsigned = false; + } else { + unsigned = !! unsigned; + } + radix = radix || 10; + if (radix < 2 || 36 < radix) + throw RangeError('radix'); + + var p; + if ((p = str.indexOf('-')) > 0) + throw Error('interior hyphen'); + else if (p === 0) { + return fromString(str.substring(1), unsigned, radix).neg(); + } + + // Do several (8) digits each time through the loop, so as to + // minimize the calls to the very expensive emulated div. + var radixToPower = fromNumber(pow_dbl(radix, 8)); + + var result = ZERO; + for (var i = 0; i < str.length; i += 8) { + var size = Math.min(8, str.length - i), + value = parseInt(str.substring(i, i + size), radix); + if (size < 8) { + var power = fromNumber(pow_dbl(radix, size)); + result = result.mul(power).add(fromNumber(value)); + } else { + result = result.mul(radixToPower); + result = result.add(fromNumber(value)); + } + } + result.unsigned = unsigned; + return result; +} + +/** + * Returns a Long representation of the given string, written using the specified radix. + * @function + * @param {string} str The textual representation of the Long + * @param {(boolean|number)=} unsigned Whether unsigned or not, defaults to signed + * @param {number=} radix The radix in which the text is written (2-36), defaults to 10 + * @returns {!Long} The corresponding Long value + */ +Long.fromString = fromString; + +/** + * @function + * @param {!Long|number|string|!{low: number, high: number, unsigned: boolean}} val + * @param {boolean=} unsigned + * @returns {!Long} + * @inner + */ +function fromValue(val, unsigned) { + if (typeof val === 'number') + return fromNumber(val, unsigned); + if (typeof val === 'string') + return fromString(val, unsigned); + // Throws for non-objects, converts non-instanceof Long: + return fromBits(val.low, val.high, typeof unsigned === 'boolean' ? unsigned : val.unsigned); +} + +/** + * Converts the specified value to a Long using the appropriate from* function for its type. + * @function + * @param {!Long|number|string|!{low: number, high: number, unsigned: boolean}} val Value + * @param {boolean=} unsigned Whether unsigned or not, defaults to signed + * @returns {!Long} + */ +Long.fromValue = fromValue; + +// NOTE: the compiler should inline these constant values below and then remove these variables, so there should be +// no runtime penalty for these. + +/** + * @type {number} + * @const + * @inner + */ +var TWO_PWR_16_DBL = 1 << 16; + +/** + * @type {number} + * @const + * @inner + */ +var TWO_PWR_24_DBL = 1 << 24; + +/** + * @type {number} + * @const + * @inner + */ +var TWO_PWR_32_DBL = TWO_PWR_16_DBL * TWO_PWR_16_DBL; + +/** + * @type {number} + * @const + * @inner + */ +var TWO_PWR_64_DBL = TWO_PWR_32_DBL * TWO_PWR_32_DBL; + +/** + * @type {number} + * @const + * @inner + */ +var TWO_PWR_63_DBL = TWO_PWR_64_DBL / 2; + +/** + * @type {!Long} + * @const + * @inner + */ +var TWO_PWR_24 = fromInt(TWO_PWR_24_DBL); + +/** + * @type {!Long} + * @inner + */ +var ZERO = fromInt(0); + +/** + * Signed zero. + * @type {!Long} + */ +Long.ZERO = ZERO; + +/** + * @type {!Long} + * @inner + */ +var UZERO = fromInt(0, true); + +/** + * Unsigned zero. + * @type {!Long} + */ +Long.UZERO = UZERO; + +/** + * @type {!Long} + * @inner + */ +var ONE = fromInt(1); + +/** + * Signed one. + * @type {!Long} + */ +Long.ONE = ONE; + +/** + * @type {!Long} + * @inner + */ +var UONE = fromInt(1, true); + +/** + * Unsigned one. + * @type {!Long} + */ +Long.UONE = UONE; + +/** + * @type {!Long} + * @inner + */ +var NEG_ONE = fromInt(-1); + +/** + * Signed negative one. + * @type {!Long} + */ +Long.NEG_ONE = NEG_ONE; + +/** + * @type {!Long} + * @inner + */ +var MAX_VALUE = fromBits(0xFFFFFFFF|0, 0x7FFFFFFF|0, false); + +/** + * Maximum signed value. + * @type {!Long} + */ +Long.MAX_VALUE = MAX_VALUE; + +/** + * @type {!Long} + * @inner + */ +var MAX_UNSIGNED_VALUE = fromBits(0xFFFFFFFF|0, 0xFFFFFFFF|0, true); + +/** + * Maximum unsigned value. + * @type {!Long} + */ +Long.MAX_UNSIGNED_VALUE = MAX_UNSIGNED_VALUE; + +/** + * @type {!Long} + * @inner + */ +var MIN_VALUE = fromBits(0, 0x80000000|0, false); + +/** + * Minimum signed value. + * @type {!Long} + */ +Long.MIN_VALUE = MIN_VALUE; + +/** + * @alias Long.prototype + * @inner + */ +var LongPrototype = Long.prototype; + +/** + * Converts the Long to a 32 bit integer, assuming it is a 32 bit integer. + * @this {!Long} + * @returns {number} + */ +LongPrototype.toInt = function toInt() { + return this.unsigned ? this.low >>> 0 : this.low; +}; + +/** + * Converts the Long to a the nearest floating-point representation of this value (double, 53 bit mantissa). + * @this {!Long} + * @returns {number} + */ +LongPrototype.toNumber = function toNumber() { + if (this.unsigned) + return ((this.high >>> 0) * TWO_PWR_32_DBL) + (this.low >>> 0); + return this.high * TWO_PWR_32_DBL + (this.low >>> 0); +}; + +/** + * Converts the Long to a string written in the specified radix. + * @this {!Long} + * @param {number=} radix Radix (2-36), defaults to 10 + * @returns {string} + * @override + * @throws {RangeError} If `radix` is out of range + */ +LongPrototype.toString = function toString(radix) { + radix = radix || 10; + if (radix < 2 || 36 < radix) + throw RangeError('radix'); + if (this.isZero()) + return '0'; + if (this.isNegative()) { // Unsigned Longs are never negative + if (this.eq(MIN_VALUE)) { + // We need to change the Long value before it can be negated, so we remove + // the bottom-most digit in this base and then recurse to do the rest. + var radixLong = fromNumber(radix), + div = this.div(radixLong), + rem1 = div.mul(radixLong).sub(this); + return div.toString(radix) + rem1.toInt().toString(radix); + } else + return '-' + this.neg().toString(radix); + } + + // Do several (6) digits each time through the loop, so as to + // minimize the calls to the very expensive emulated div. + var radixToPower = fromNumber(pow_dbl(radix, 6), this.unsigned), + rem = this; + var result = ''; + while (true) { + var remDiv = rem.div(radixToPower), + intval = rem.sub(remDiv.mul(radixToPower)).toInt() >>> 0, + digits = intval.toString(radix); + rem = remDiv; + if (rem.isZero()) + return digits + result; + else { + while (digits.length < 6) + digits = '0' + digits; + result = '' + digits + result; + } + } +}; + +/** + * Gets the high 32 bits as a signed integer. + * @this {!Long} + * @returns {number} Signed high bits + */ +LongPrototype.getHighBits = function getHighBits() { + return this.high; +}; + +/** + * Gets the high 32 bits as an unsigned integer. + * @this {!Long} + * @returns {number} Unsigned high bits + */ +LongPrototype.getHighBitsUnsigned = function getHighBitsUnsigned() { + return this.high >>> 0; +}; + +/** + * Gets the low 32 bits as a signed integer. + * @this {!Long} + * @returns {number} Signed low bits + */ +LongPrototype.getLowBits = function getLowBits() { + return this.low; +}; + +/** + * Gets the low 32 bits as an unsigned integer. + * @this {!Long} + * @returns {number} Unsigned low bits + */ +LongPrototype.getLowBitsUnsigned = function getLowBitsUnsigned() { + return this.low >>> 0; +}; + +/** + * Gets the number of bits needed to represent the absolute value of this Long. + * @this {!Long} + * @returns {number} + */ +LongPrototype.getNumBitsAbs = function getNumBitsAbs() { + if (this.isNegative()) // Unsigned Longs are never negative + return this.eq(MIN_VALUE) ? 64 : this.neg().getNumBitsAbs(); + var val = this.high != 0 ? this.high : this.low; + for (var bit = 31; bit > 0; bit--) + if ((val & (1 << bit)) != 0) + break; + return this.high != 0 ? bit + 33 : bit + 1; +}; + +/** + * Tests if this Long's value equals zero. + * @this {!Long} + * @returns {boolean} + */ +LongPrototype.isZero = function isZero() { + return this.high === 0 && this.low === 0; +}; + +/** + * Tests if this Long's value equals zero. This is an alias of {@link Long#isZero}. + * @returns {boolean} + */ +LongPrototype.eqz = LongPrototype.isZero; + +/** + * Tests if this Long's value is negative. + * @this {!Long} + * @returns {boolean} + */ +LongPrototype.isNegative = function isNegative() { + return !this.unsigned && this.high < 0; +}; + +/** + * Tests if this Long's value is positive. + * @this {!Long} + * @returns {boolean} + */ +LongPrototype.isPositive = function isPositive() { + return this.unsigned || this.high >= 0; +}; + +/** + * Tests if this Long's value is odd. + * @this {!Long} + * @returns {boolean} + */ +LongPrototype.isOdd = function isOdd() { + return (this.low & 1) === 1; +}; + +/** + * Tests if this Long's value is even. + * @this {!Long} + * @returns {boolean} + */ +LongPrototype.isEven = function isEven() { + return (this.low & 1) === 0; +}; + +/** + * Tests if this Long's value equals the specified's. + * @this {!Long} + * @param {!Long|number|string} other Other value + * @returns {boolean} + */ +LongPrototype.equals = function equals(other) { + if (!isLong(other)) + other = fromValue(other); + if (this.unsigned !== other.unsigned && (this.high >>> 31) === 1 && (other.high >>> 31) === 1) + return false; + return this.high === other.high && this.low === other.low; +}; + +/** + * Tests if this Long's value equals the specified's. This is an alias of {@link Long#equals}. + * @function + * @param {!Long|number|string} other Other value + * @returns {boolean} + */ +LongPrototype.eq = LongPrototype.equals; + +/** + * Tests if this Long's value differs from the specified's. + * @this {!Long} + * @param {!Long|number|string} other Other value + * @returns {boolean} + */ +LongPrototype.notEquals = function notEquals(other) { + return !this.eq(/* validates */ other); +}; + +/** + * Tests if this Long's value differs from the specified's. This is an alias of {@link Long#notEquals}. + * @function + * @param {!Long|number|string} other Other value + * @returns {boolean} + */ +LongPrototype.neq = LongPrototype.notEquals; + +/** + * Tests if this Long's value differs from the specified's. This is an alias of {@link Long#notEquals}. + * @function + * @param {!Long|number|string} other Other value + * @returns {boolean} + */ +LongPrototype.ne = LongPrototype.notEquals; + +/** + * Tests if this Long's value is less than the specified's. + * @this {!Long} + * @param {!Long|number|string} other Other value + * @returns {boolean} + */ +LongPrototype.lessThan = function lessThan(other) { + return this.comp(/* validates */ other) < 0; +}; + +/** + * Tests if this Long's value is less than the specified's. This is an alias of {@link Long#lessThan}. + * @function + * @param {!Long|number|string} other Other value + * @returns {boolean} + */ +LongPrototype.lt = LongPrototype.lessThan; + +/** + * Tests if this Long's value is less than or equal the specified's. + * @this {!Long} + * @param {!Long|number|string} other Other value + * @returns {boolean} + */ +LongPrototype.lessThanOrEqual = function lessThanOrEqual(other) { + return this.comp(/* validates */ other) <= 0; +}; + +/** + * Tests if this Long's value is less than or equal the specified's. This is an alias of {@link Long#lessThanOrEqual}. + * @function + * @param {!Long|number|string} other Other value + * @returns {boolean} + */ +LongPrototype.lte = LongPrototype.lessThanOrEqual; + +/** + * Tests if this Long's value is less than or equal the specified's. This is an alias of {@link Long#lessThanOrEqual}. + * @function + * @param {!Long|number|string} other Other value + * @returns {boolean} + */ +LongPrototype.le = LongPrototype.lessThanOrEqual; + +/** + * Tests if this Long's value is greater than the specified's. + * @this {!Long} + * @param {!Long|number|string} other Other value + * @returns {boolean} + */ +LongPrototype.greaterThan = function greaterThan(other) { + return this.comp(/* validates */ other) > 0; +}; + +/** + * Tests if this Long's value is greater than the specified's. This is an alias of {@link Long#greaterThan}. + * @function + * @param {!Long|number|string} other Other value + * @returns {boolean} + */ +LongPrototype.gt = LongPrototype.greaterThan; + +/** + * Tests if this Long's value is greater than or equal the specified's. + * @this {!Long} + * @param {!Long|number|string} other Other value + * @returns {boolean} + */ +LongPrototype.greaterThanOrEqual = function greaterThanOrEqual(other) { + return this.comp(/* validates */ other) >= 0; +}; + +/** + * Tests if this Long's value is greater than or equal the specified's. This is an alias of {@link Long#greaterThanOrEqual}. + * @function + * @param {!Long|number|string} other Other value + * @returns {boolean} + */ +LongPrototype.gte = LongPrototype.greaterThanOrEqual; + +/** + * Tests if this Long's value is greater than or equal the specified's. This is an alias of {@link Long#greaterThanOrEqual}. + * @function + * @param {!Long|number|string} other Other value + * @returns {boolean} + */ +LongPrototype.ge = LongPrototype.greaterThanOrEqual; + +/** + * Compares this Long's value with the specified's. + * @this {!Long} + * @param {!Long|number|string} other Other value + * @returns {number} 0 if they are the same, 1 if the this is greater and -1 + * if the given one is greater + */ +LongPrototype.compare = function compare(other) { + if (!isLong(other)) + other = fromValue(other); + if (this.eq(other)) + return 0; + var thisNeg = this.isNegative(), + otherNeg = other.isNegative(); + if (thisNeg && !otherNeg) + return -1; + if (!thisNeg && otherNeg) + return 1; + // At this point the sign bits are the same + if (!this.unsigned) + return this.sub(other).isNegative() ? -1 : 1; + // Both are positive if at least one is unsigned + return (other.high >>> 0) > (this.high >>> 0) || (other.high === this.high && (other.low >>> 0) > (this.low >>> 0)) ? -1 : 1; +}; + +/** + * Compares this Long's value with the specified's. This is an alias of {@link Long#compare}. + * @function + * @param {!Long|number|string} other Other value + * @returns {number} 0 if they are the same, 1 if the this is greater and -1 + * if the given one is greater + */ +LongPrototype.comp = LongPrototype.compare; + +/** + * Negates this Long's value. + * @this {!Long} + * @returns {!Long} Negated Long + */ +LongPrototype.negate = function negate() { + if (!this.unsigned && this.eq(MIN_VALUE)) + return MIN_VALUE; + return this.not().add(ONE); +}; + +/** + * Negates this Long's value. This is an alias of {@link Long#negate}. + * @function + * @returns {!Long} Negated Long + */ +LongPrototype.neg = LongPrototype.negate; + +/** + * Returns the sum of this and the specified Long. + * @this {!Long} + * @param {!Long|number|string} addend Addend + * @returns {!Long} Sum + */ +LongPrototype.add = function add(addend) { + if (!isLong(addend)) + addend = fromValue(addend); + + // Divide each number into 4 chunks of 16 bits, and then sum the chunks. + + var a48 = this.high >>> 16; + var a32 = this.high & 0xFFFF; + var a16 = this.low >>> 16; + var a00 = this.low & 0xFFFF; + + var b48 = addend.high >>> 16; + var b32 = addend.high & 0xFFFF; + var b16 = addend.low >>> 16; + var b00 = addend.low & 0xFFFF; + + var c48 = 0, c32 = 0, c16 = 0, c00 = 0; + c00 += a00 + b00; + c16 += c00 >>> 16; + c00 &= 0xFFFF; + c16 += a16 + b16; + c32 += c16 >>> 16; + c16 &= 0xFFFF; + c32 += a32 + b32; + c48 += c32 >>> 16; + c32 &= 0xFFFF; + c48 += a48 + b48; + c48 &= 0xFFFF; + return fromBits((c16 << 16) | c00, (c48 << 16) | c32, this.unsigned); +}; + +/** + * Returns the difference of this and the specified Long. + * @this {!Long} + * @param {!Long|number|string} subtrahend Subtrahend + * @returns {!Long} Difference + */ +LongPrototype.subtract = function subtract(subtrahend) { + if (!isLong(subtrahend)) + subtrahend = fromValue(subtrahend); + return this.add(subtrahend.neg()); +}; + +/** + * Returns the difference of this and the specified Long. This is an alias of {@link Long#subtract}. + * @function + * @param {!Long|number|string} subtrahend Subtrahend + * @returns {!Long} Difference + */ +LongPrototype.sub = LongPrototype.subtract; + +/** + * Returns the product of this and the specified Long. + * @this {!Long} + * @param {!Long|number|string} multiplier Multiplier + * @returns {!Long} Product + */ +LongPrototype.multiply = function multiply(multiplier) { + if (this.isZero()) + return ZERO; + if (!isLong(multiplier)) + multiplier = fromValue(multiplier); + + // use wasm support if present + if (wasm) { + var low = wasm["mul"](this.low, + this.high, + multiplier.low, + multiplier.high); + return fromBits(low, wasm["get_high"](), this.unsigned); + } + + if (multiplier.isZero()) + return ZERO; + if (this.eq(MIN_VALUE)) + return multiplier.isOdd() ? MIN_VALUE : ZERO; + if (multiplier.eq(MIN_VALUE)) + return this.isOdd() ? MIN_VALUE : ZERO; + + if (this.isNegative()) { + if (multiplier.isNegative()) + return this.neg().mul(multiplier.neg()); + else + return this.neg().mul(multiplier).neg(); + } else if (multiplier.isNegative()) + return this.mul(multiplier.neg()).neg(); + + // If both longs are small, use float multiplication + if (this.lt(TWO_PWR_24) && multiplier.lt(TWO_PWR_24)) + return fromNumber(this.toNumber() * multiplier.toNumber(), this.unsigned); + + // Divide each long into 4 chunks of 16 bits, and then add up 4x4 products. + // We can skip products that would overflow. + + var a48 = this.high >>> 16; + var a32 = this.high & 0xFFFF; + var a16 = this.low >>> 16; + var a00 = this.low & 0xFFFF; + + var b48 = multiplier.high >>> 16; + var b32 = multiplier.high & 0xFFFF; + var b16 = multiplier.low >>> 16; + var b00 = multiplier.low & 0xFFFF; + + var c48 = 0, c32 = 0, c16 = 0, c00 = 0; + c00 += a00 * b00; + c16 += c00 >>> 16; + c00 &= 0xFFFF; + c16 += a16 * b00; + c32 += c16 >>> 16; + c16 &= 0xFFFF; + c16 += a00 * b16; + c32 += c16 >>> 16; + c16 &= 0xFFFF; + c32 += a32 * b00; + c48 += c32 >>> 16; + c32 &= 0xFFFF; + c32 += a16 * b16; + c48 += c32 >>> 16; + c32 &= 0xFFFF; + c32 += a00 * b32; + c48 += c32 >>> 16; + c32 &= 0xFFFF; + c48 += a48 * b00 + a32 * b16 + a16 * b32 + a00 * b48; + c48 &= 0xFFFF; + return fromBits((c16 << 16) | c00, (c48 << 16) | c32, this.unsigned); +}; + +/** + * Returns the product of this and the specified Long. This is an alias of {@link Long#multiply}. + * @function + * @param {!Long|number|string} multiplier Multiplier + * @returns {!Long} Product + */ +LongPrototype.mul = LongPrototype.multiply; + +/** + * Returns this Long divided by the specified. The result is signed if this Long is signed or + * unsigned if this Long is unsigned. + * @this {!Long} + * @param {!Long|number|string} divisor Divisor + * @returns {!Long} Quotient + */ +LongPrototype.divide = function divide(divisor) { + if (!isLong(divisor)) + divisor = fromValue(divisor); + if (divisor.isZero()) + throw Error('division by zero'); + + // use wasm support if present + if (wasm) { + // guard against signed division overflow: the largest + // negative number / -1 would be 1 larger than the largest + // positive number, due to two's complement. + if (!this.unsigned && + this.high === -0x80000000 && + divisor.low === -1 && divisor.high === -1) { + // be consistent with non-wasm code path + return this; + } + var low = (this.unsigned ? wasm["div_u"] : wasm["div_s"])( + this.low, + this.high, + divisor.low, + divisor.high + ); + return fromBits(low, wasm["get_high"](), this.unsigned); + } + + if (this.isZero()) + return this.unsigned ? UZERO : ZERO; + var approx, rem, res; + if (!this.unsigned) { + // This section is only relevant for signed longs and is derived from the + // closure library as a whole. + if (this.eq(MIN_VALUE)) { + if (divisor.eq(ONE) || divisor.eq(NEG_ONE)) + return MIN_VALUE; // recall that -MIN_VALUE == MIN_VALUE + else if (divisor.eq(MIN_VALUE)) + return ONE; + else { + // At this point, we have |other| >= 2, so |this/other| < |MIN_VALUE|. + var halfThis = this.shr(1); + approx = halfThis.div(divisor).shl(1); + if (approx.eq(ZERO)) { + return divisor.isNegative() ? ONE : NEG_ONE; + } else { + rem = this.sub(divisor.mul(approx)); + res = approx.add(rem.div(divisor)); + return res; + } + } + } else if (divisor.eq(MIN_VALUE)) + return this.unsigned ? UZERO : ZERO; + if (this.isNegative()) { + if (divisor.isNegative()) + return this.neg().div(divisor.neg()); + return this.neg().div(divisor).neg(); + } else if (divisor.isNegative()) + return this.div(divisor.neg()).neg(); + res = ZERO; + } else { + // The algorithm below has not been made for unsigned longs. It's therefore + // required to take special care of the MSB prior to running it. + if (!divisor.unsigned) + divisor = divisor.toUnsigned(); + if (divisor.gt(this)) + return UZERO; + if (divisor.gt(this.shru(1))) // 15 >>> 1 = 7 ; with divisor = 8 ; true + return UONE; + res = UZERO; + } + + // Repeat the following until the remainder is less than other: find a + // floating-point that approximates remainder / other *from below*, add this + // into the result, and subtract it from the remainder. It is critical that + // the approximate value is less than or equal to the real value so that the + // remainder never becomes negative. + rem = this; + while (rem.gte(divisor)) { + // Approximate the result of division. This may be a little greater or + // smaller than the actual value. + approx = Math.max(1, Math.floor(rem.toNumber() / divisor.toNumber())); + + // We will tweak the approximate result by changing it in the 48-th digit or + // the smallest non-fractional digit, whichever is larger. + var log2 = Math.ceil(Math.log(approx) / Math.LN2), + delta = (log2 <= 48) ? 1 : pow_dbl(2, log2 - 48), + + // Decrease the approximation until it is smaller than the remainder. Note + // that if it is too large, the product overflows and is negative. + approxRes = fromNumber(approx), + approxRem = approxRes.mul(divisor); + while (approxRem.isNegative() || approxRem.gt(rem)) { + approx -= delta; + approxRes = fromNumber(approx, this.unsigned); + approxRem = approxRes.mul(divisor); + } + + // We know the answer can't be zero... and actually, zero would cause + // infinite recursion since we would make no progress. + if (approxRes.isZero()) + approxRes = ONE; + + res = res.add(approxRes); + rem = rem.sub(approxRem); + } + return res; +}; + +/** + * Returns this Long divided by the specified. This is an alias of {@link Long#divide}. + * @function + * @param {!Long|number|string} divisor Divisor + * @returns {!Long} Quotient + */ +LongPrototype.div = LongPrototype.divide; + +/** + * Returns this Long modulo the specified. + * @this {!Long} + * @param {!Long|number|string} divisor Divisor + * @returns {!Long} Remainder + */ +LongPrototype.modulo = function modulo(divisor) { + if (!isLong(divisor)) + divisor = fromValue(divisor); + + // use wasm support if present + if (wasm) { + var low = (this.unsigned ? wasm["rem_u"] : wasm["rem_s"])( + this.low, + this.high, + divisor.low, + divisor.high + ); + return fromBits(low, wasm["get_high"](), this.unsigned); + } + + return this.sub(this.div(divisor).mul(divisor)); +}; + +/** + * Returns this Long modulo the specified. This is an alias of {@link Long#modulo}. + * @function + * @param {!Long|number|string} divisor Divisor + * @returns {!Long} Remainder + */ +LongPrototype.mod = LongPrototype.modulo; + +/** + * Returns this Long modulo the specified. This is an alias of {@link Long#modulo}. + * @function + * @param {!Long|number|string} divisor Divisor + * @returns {!Long} Remainder + */ +LongPrototype.rem = LongPrototype.modulo; + +/** + * Returns the bitwise NOT of this Long. + * @this {!Long} + * @returns {!Long} + */ +LongPrototype.not = function not() { + return fromBits(~this.low, ~this.high, this.unsigned); +}; + +/** + * Returns the bitwise AND of this Long and the specified. + * @this {!Long} + * @param {!Long|number|string} other Other Long + * @returns {!Long} + */ +LongPrototype.and = function and(other) { + if (!isLong(other)) + other = fromValue(other); + return fromBits(this.low & other.low, this.high & other.high, this.unsigned); +}; + +/** + * Returns the bitwise OR of this Long and the specified. + * @this {!Long} + * @param {!Long|number|string} other Other Long + * @returns {!Long} + */ +LongPrototype.or = function or(other) { + if (!isLong(other)) + other = fromValue(other); + return fromBits(this.low | other.low, this.high | other.high, this.unsigned); +}; + +/** + * Returns the bitwise XOR of this Long and the given one. + * @this {!Long} + * @param {!Long|number|string} other Other Long + * @returns {!Long} + */ +LongPrototype.xor = function xor(other) { + if (!isLong(other)) + other = fromValue(other); + return fromBits(this.low ^ other.low, this.high ^ other.high, this.unsigned); +}; + +/** + * Returns this Long with bits shifted to the left by the given amount. + * @this {!Long} + * @param {number|!Long} numBits Number of bits + * @returns {!Long} Shifted Long + */ +LongPrototype.shiftLeft = function shiftLeft(numBits) { + if (isLong(numBits)) + numBits = numBits.toInt(); + if ((numBits &= 63) === 0) + return this; + else if (numBits < 32) + return fromBits(this.low << numBits, (this.high << numBits) | (this.low >>> (32 - numBits)), this.unsigned); + else + return fromBits(0, this.low << (numBits - 32), this.unsigned); +}; + +/** + * Returns this Long with bits shifted to the left by the given amount. This is an alias of {@link Long#shiftLeft}. + * @function + * @param {number|!Long} numBits Number of bits + * @returns {!Long} Shifted Long + */ +LongPrototype.shl = LongPrototype.shiftLeft; + +/** + * Returns this Long with bits arithmetically shifted to the right by the given amount. + * @this {!Long} + * @param {number|!Long} numBits Number of bits + * @returns {!Long} Shifted Long + */ +LongPrototype.shiftRight = function shiftRight(numBits) { + if (isLong(numBits)) + numBits = numBits.toInt(); + if ((numBits &= 63) === 0) + return this; + else if (numBits < 32) + return fromBits((this.low >>> numBits) | (this.high << (32 - numBits)), this.high >> numBits, this.unsigned); + else + return fromBits(this.high >> (numBits - 32), this.high >= 0 ? 0 : -1, this.unsigned); +}; + +/** + * Returns this Long with bits arithmetically shifted to the right by the given amount. This is an alias of {@link Long#shiftRight}. + * @function + * @param {number|!Long} numBits Number of bits + * @returns {!Long} Shifted Long + */ +LongPrototype.shr = LongPrototype.shiftRight; + +/** + * Returns this Long with bits logically shifted to the right by the given amount. + * @this {!Long} + * @param {number|!Long} numBits Number of bits + * @returns {!Long} Shifted Long + */ +LongPrototype.shiftRightUnsigned = function shiftRightUnsigned(numBits) { + if (isLong(numBits)) numBits = numBits.toInt(); + if ((numBits &= 63) === 0) return this; + if (numBits < 32) return fromBits((this.low >>> numBits) | (this.high << (32 - numBits)), this.high >>> numBits, this.unsigned); + if (numBits === 32) return fromBits(this.high, 0, this.unsigned); + return fromBits(this.high >>> (numBits - 32), 0, this.unsigned); +}; + +/** + * Returns this Long with bits logically shifted to the right by the given amount. This is an alias of {@link Long#shiftRightUnsigned}. + * @function + * @param {number|!Long} numBits Number of bits + * @returns {!Long} Shifted Long + */ +LongPrototype.shru = LongPrototype.shiftRightUnsigned; + +/** + * Returns this Long with bits logically shifted to the right by the given amount. This is an alias of {@link Long#shiftRightUnsigned}. + * @function + * @param {number|!Long} numBits Number of bits + * @returns {!Long} Shifted Long + */ +LongPrototype.shr_u = LongPrototype.shiftRightUnsigned; + +/** + * Returns this Long with bits rotated to the left by the given amount. + * @this {!Long} + * @param {number|!Long} numBits Number of bits + * @returns {!Long} Rotated Long + */ +LongPrototype.rotateLeft = function rotateLeft(numBits) { + var b; + if (isLong(numBits)) numBits = numBits.toInt(); + if ((numBits &= 63) === 0) return this; + if (numBits === 32) return fromBits(this.high, this.low, this.unsigned); + if (numBits < 32) { + b = (32 - numBits); + return fromBits(((this.low << numBits) | (this.high >>> b)), ((this.high << numBits) | (this.low >>> b)), this.unsigned); + } + numBits -= 32; + b = (32 - numBits); + return fromBits(((this.high << numBits) | (this.low >>> b)), ((this.low << numBits) | (this.high >>> b)), this.unsigned); +} +/** + * Returns this Long with bits rotated to the left by the given amount. This is an alias of {@link Long#rotateLeft}. + * @function + * @param {number|!Long} numBits Number of bits + * @returns {!Long} Rotated Long + */ +LongPrototype.rotl = LongPrototype.rotateLeft; + +/** + * Returns this Long with bits rotated to the right by the given amount. + * @this {!Long} + * @param {number|!Long} numBits Number of bits + * @returns {!Long} Rotated Long + */ +LongPrototype.rotateRight = function rotateRight(numBits) { + var b; + if (isLong(numBits)) numBits = numBits.toInt(); + if ((numBits &= 63) === 0) return this; + if (numBits === 32) return fromBits(this.high, this.low, this.unsigned); + if (numBits < 32) { + b = (32 - numBits); + return fromBits(((this.high << b) | (this.low >>> numBits)), ((this.low << b) | (this.high >>> numBits)), this.unsigned); + } + numBits -= 32; + b = (32 - numBits); + return fromBits(((this.low << b) | (this.high >>> numBits)), ((this.high << b) | (this.low >>> numBits)), this.unsigned); +} +/** + * Returns this Long with bits rotated to the right by the given amount. This is an alias of {@link Long#rotateRight}. + * @function + * @param {number|!Long} numBits Number of bits + * @returns {!Long} Rotated Long + */ +LongPrototype.rotr = LongPrototype.rotateRight; + +/** + * Converts this Long to signed. + * @this {!Long} + * @returns {!Long} Signed long + */ +LongPrototype.toSigned = function toSigned() { + if (!this.unsigned) + return this; + return fromBits(this.low, this.high, false); +}; + +/** + * Converts this Long to unsigned. + * @this {!Long} + * @returns {!Long} Unsigned long + */ +LongPrototype.toUnsigned = function toUnsigned() { + if (this.unsigned) + return this; + return fromBits(this.low, this.high, true); +}; + +/** + * Converts this Long to its byte representation. + * @param {boolean=} le Whether little or big endian, defaults to big endian + * @this {!Long} + * @returns {!Array.} Byte representation + */ +LongPrototype.toBytes = function toBytes(le) { + return le ? this.toBytesLE() : this.toBytesBE(); +}; + +/** + * Converts this Long to its little endian byte representation. + * @this {!Long} + * @returns {!Array.} Little endian byte representation + */ +LongPrototype.toBytesLE = function toBytesLE() { + var hi = this.high, + lo = this.low; + return [ + lo & 0xff, + lo >>> 8 & 0xff, + lo >>> 16 & 0xff, + lo >>> 24 , + hi & 0xff, + hi >>> 8 & 0xff, + hi >>> 16 & 0xff, + hi >>> 24 + ]; +}; + +/** + * Converts this Long to its big endian byte representation. + * @this {!Long} + * @returns {!Array.} Big endian byte representation + */ +LongPrototype.toBytesBE = function toBytesBE() { + var hi = this.high, + lo = this.low; + return [ + hi >>> 24 , + hi >>> 16 & 0xff, + hi >>> 8 & 0xff, + hi & 0xff, + lo >>> 24 , + lo >>> 16 & 0xff, + lo >>> 8 & 0xff, + lo & 0xff + ]; +}; + +/** + * Creates a Long from its byte representation. + * @param {!Array.} bytes Byte representation + * @param {boolean=} unsigned Whether unsigned or not, defaults to signed + * @param {boolean=} le Whether little or big endian, defaults to big endian + * @returns {Long} The corresponding Long value + */ +Long.fromBytes = function fromBytes(bytes, unsigned, le) { + return le ? Long.fromBytesLE(bytes, unsigned) : Long.fromBytesBE(bytes, unsigned); +}; + +/** + * Creates a Long from its little endian byte representation. + * @param {!Array.} bytes Little endian byte representation + * @param {boolean=} unsigned Whether unsigned or not, defaults to signed + * @returns {Long} The corresponding Long value + */ +Long.fromBytesLE = function fromBytesLE(bytes, unsigned) { + return new Long( + bytes[0] | + bytes[1] << 8 | + bytes[2] << 16 | + bytes[3] << 24, + bytes[4] | + bytes[5] << 8 | + bytes[6] << 16 | + bytes[7] << 24, + unsigned + ); +}; + +/** + * Creates a Long from its big endian byte representation. + * @param {!Array.} bytes Big endian byte representation + * @param {boolean=} unsigned Whether unsigned or not, defaults to signed + * @returns {Long} The corresponding Long value + */ +Long.fromBytesBE = function fromBytesBE(bytes, unsigned) { + return new Long( + bytes[4] << 24 | + bytes[5] << 16 | + bytes[6] << 8 | + bytes[7], + bytes[0] << 24 | + bytes[1] << 16 | + bytes[2] << 8 | + bytes[3], + unsigned + ); +}; + +window.long = Long; \ No newline at end of file diff --git a/demo/libs/long/long.min.js b/demo/libs/long/long.min.js new file mode 100644 index 00000000..ccc3ad37 --- /dev/null +++ b/demo/libs/long/long.min.js @@ -0,0 +1 @@ +"use strict";function Long(t,o,i){this.low=0|t,this.high=0|o,this.unsigned=!!i}function isLong(t){return!0===(t&&t.__isLong__)}function fromInt(t,o){var i,n,r;return o?(t>>>=0,(r=0<=t&&t<256)&&(n=UINT_CACHE[t])?n:(i=fromBits(t,(0|t)<0?-1:0,!0),r&&(UINT_CACHE[t]=i),i)):(t|=0,(r=-128<=t&&t<128)&&(n=INT_CACHE[t])?n:(i=fromBits(t,t<0?-1:0,!1),r&&(INT_CACHE[t]=i),i))}function fromNumber(t,o){if(isNaN(t))return o?UZERO:ZERO;if(o){if(t<0)return UZERO;if(t>=TWO_PWR_64_DBL)return MAX_UNSIGNED_VALUE}else{if(t<=-TWO_PWR_63_DBL)return MIN_VALUE;if(t+1>=TWO_PWR_63_DBL)return MAX_VALUE}return t<0?fromNumber(-t,o).neg():fromBits(t%TWO_PWR_32_DBL|0,t/TWO_PWR_32_DBL|0,o)}function fromBits(t,o,i){return new Long(t,o,i)}function fromString(t,o,i){if(0===t.length)throw Error("empty string");if("NaN"===t||"Infinity"===t||"+Infinity"===t||"-Infinity"===t)return ZERO;if("number"==typeof o?(i=o,o=!1):o=!!o,(i=i||10)<2||360)throw Error("interior hyphen");if(0===n)return fromString(t.substring(1),o,i).neg();for(var r=fromNumber(pow_dbl(i,8)),e=ZERO,s=0;s>>0:this.low},LongPrototype.toNumber=function(){return this.unsigned?(this.high>>>0)*TWO_PWR_32_DBL+(this.low>>>0):this.high*TWO_PWR_32_DBL+(this.low>>>0)},LongPrototype.toString=function(t){if((t=t||10)<2||36>>0,u=g.toString(t);if(e=h,e.isZero())return u+s;for(;u.length<6;)u="0"+u;s=""+u+s}},LongPrototype.getHighBits=function(){return this.high},LongPrototype.getHighBitsUnsigned=function(){return this.high>>>0},LongPrototype.getLowBits=function(){return this.low},LongPrototype.getLowBitsUnsigned=function(){return this.low>>>0},LongPrototype.getNumBitsAbs=function(){if(this.isNegative())return this.eq(MIN_VALUE)?64:this.neg().getNumBitsAbs();for(var t=0!=this.high?this.high:this.low,o=31;o>0&&0==(t&1<=0},LongPrototype.isOdd=function(){return 1==(1&this.low)},LongPrototype.isEven=function(){return 0==(1&this.low)},LongPrototype.equals=function(t){return isLong(t)||(t=fromValue(t)),(this.unsigned===t.unsigned||this.high>>>31!=1||t.high>>>31!=1)&&(this.high===t.high&&this.low===t.low)},LongPrototype.eq=LongPrototype.equals,LongPrototype.notEquals=function(t){return!this.eq(t)},LongPrototype.neq=LongPrototype.notEquals,LongPrototype.ne=LongPrototype.notEquals,LongPrototype.lessThan=function(t){return this.comp(t)<0},LongPrototype.lt=LongPrototype.lessThan,LongPrototype.lessThanOrEqual=function(t){return this.comp(t)<=0},LongPrototype.lte=LongPrototype.lessThanOrEqual,LongPrototype.le=LongPrototype.lessThanOrEqual,LongPrototype.greaterThan=function(t){return this.comp(t)>0},LongPrototype.gt=LongPrototype.greaterThan,LongPrototype.greaterThanOrEqual=function(t){return this.comp(t)>=0},LongPrototype.gte=LongPrototype.greaterThanOrEqual,LongPrototype.ge=LongPrototype.greaterThanOrEqual,LongPrototype.compare=function(t){if(isLong(t)||(t=fromValue(t)),this.eq(t))return 0;var o=this.isNegative(),i=t.isNegative();return o&&!i?-1:!o&&i?1:this.unsigned?t.high>>>0>this.high>>>0||t.high===this.high&&t.low>>>0>this.low>>>0?-1:1:this.sub(t).isNegative()?-1:1},LongPrototype.comp=LongPrototype.compare,LongPrototype.negate=function(){return!this.unsigned&&this.eq(MIN_VALUE)?MIN_VALUE:this.not().add(ONE)},LongPrototype.neg=LongPrototype.negate,LongPrototype.add=function(t){isLong(t)||(t=fromValue(t));var o=this.high>>>16,i=65535&this.high,n=this.low>>>16,r=65535&this.low,e=t.high>>>16,s=65535&t.high,h=t.low>>>16,g=65535&t.low,u=0,f=0,L=0,m=0;return m+=r+g,L+=m>>>16,m&=65535,L+=n+h,f+=L>>>16,L&=65535,f+=i+s,u+=f>>>16,f&=65535,u+=o+e,u&=65535,fromBits(L<<16|m,u<<16|f,this.unsigned)},LongPrototype.subtract=function(t){return isLong(t)||(t=fromValue(t)),this.add(t.neg())},LongPrototype.sub=LongPrototype.subtract,LongPrototype.multiply=function(t){if(this.isZero())return ZERO;if(isLong(t)||(t=fromValue(t)),wasm){return fromBits(wasm.mul(this.low,this.high,t.low,t.high),wasm.get_high(),this.unsigned)}if(t.isZero())return ZERO;if(this.eq(MIN_VALUE))return t.isOdd()?MIN_VALUE:ZERO;if(t.eq(MIN_VALUE))return this.isOdd()?MIN_VALUE:ZERO;if(this.isNegative())return t.isNegative()?this.neg().mul(t.neg()):this.neg().mul(t).neg();if(t.isNegative())return this.mul(t.neg()).neg();if(this.lt(TWO_PWR_24)&&t.lt(TWO_PWR_24))return fromNumber(this.toNumber()*t.toNumber(),this.unsigned);var o=this.high>>>16,i=65535&this.high,n=this.low>>>16,r=65535&this.low,e=t.high>>>16,s=65535&t.high,h=t.low>>>16,g=65535&t.low,u=0,f=0,L=0,m=0;return m+=r*g,L+=m>>>16,m&=65535,L+=n*g,f+=L>>>16,L&=65535,L+=r*h,f+=L>>>16,L&=65535,f+=i*g,u+=f>>>16,f&=65535,f+=n*h,u+=f>>>16,f&=65535,f+=r*s,u+=f>>>16,f&=65535,u+=o*g+i*h+n*s+r*e,u&=65535,fromBits(L<<16|m,u<<16|f,this.unsigned)},LongPrototype.mul=LongPrototype.multiply,LongPrototype.divide=function(t){if(isLong(t)||(t=fromValue(t)),t.isZero())throw Error("division by zero");if(wasm){if(!this.unsigned&&-2147483648===this.high&&-1===t.low&&-1===t.high)return this;return fromBits((this.unsigned?wasm.div_u:wasm.div_s)(this.low,this.high,t.low,t.high),wasm.get_high(),this.unsigned)}if(this.isZero())return this.unsigned?UZERO:ZERO;var o,i,n;if(this.unsigned){if(t.unsigned||(t=t.toUnsigned()),t.gt(this))return UZERO;if(t.gt(this.shru(1)))return UONE;n=UZERO}else{if(this.eq(MIN_VALUE)){if(t.eq(ONE)||t.eq(NEG_ONE))return MIN_VALUE;if(t.eq(MIN_VALUE))return ONE;return o=this.shr(1).div(t).shl(1),o.eq(ZERO)?t.isNegative()?ONE:NEG_ONE:(i=this.sub(t.mul(o)),n=o.add(i.div(t)))}if(t.eq(MIN_VALUE))return this.unsigned?UZERO:ZERO;if(this.isNegative())return t.isNegative()?this.neg().div(t.neg()):this.neg().div(t).neg();if(t.isNegative())return this.div(t.neg()).neg();n=ZERO}for(i=this;i.gte(t);){o=Math.max(1,Math.floor(i.toNumber()/t.toNumber()));for(var r=Math.ceil(Math.log(o)/Math.LN2),e=r<=48?1:pow_dbl(2,r-48),s=fromNumber(o),h=s.mul(t);h.isNegative()||h.gt(i);)o-=e,s=fromNumber(o,this.unsigned),h=s.mul(t);s.isZero()&&(s=ONE),n=n.add(s),i=i.sub(h)}return n},LongPrototype.div=LongPrototype.divide,LongPrototype.modulo=function(t){if(isLong(t)||(t=fromValue(t)),wasm){return fromBits((this.unsigned?wasm.rem_u:wasm.rem_s)(this.low,this.high,t.low,t.high),wasm.get_high(),this.unsigned)}return this.sub(this.div(t).mul(t))},LongPrototype.mod=LongPrototype.modulo,LongPrototype.rem=LongPrototype.modulo,LongPrototype.not=function(){return fromBits(~this.low,~this.high,this.unsigned)},LongPrototype.and=function(t){return isLong(t)||(t=fromValue(t)),fromBits(this.low&t.low,this.high&t.high,this.unsigned)},LongPrototype.or=function(t){return isLong(t)||(t=fromValue(t)),fromBits(this.low|t.low,this.high|t.high,this.unsigned)},LongPrototype.xor=function(t){return isLong(t)||(t=fromValue(t)),fromBits(this.low^t.low,this.high^t.high,this.unsigned)},LongPrototype.shiftLeft=function(t){return isLong(t)&&(t=t.toInt()),0==(t&=63)?this:t<32?fromBits(this.low<>>32-t,this.unsigned):fromBits(0,this.low<>>t|this.high<<32-t,this.high>>t,this.unsigned):fromBits(this.high>>t-32,this.high>=0?0:-1,this.unsigned)},LongPrototype.shr=LongPrototype.shiftRight,LongPrototype.shiftRightUnsigned=function(t){return isLong(t)&&(t=t.toInt()),0==(t&=63)?this:t<32?fromBits(this.low>>>t|this.high<<32-t,this.high>>>t,this.unsigned):32===t?fromBits(this.high,0,this.unsigned):fromBits(this.high>>>t-32,0,this.unsigned)},LongPrototype.shru=LongPrototype.shiftRightUnsigned,LongPrototype.shr_u=LongPrototype.shiftRightUnsigned,LongPrototype.rotateLeft=function(t){var o;return isLong(t)&&(t=t.toInt()),0==(t&=63)?this:32===t?fromBits(this.high,this.low,this.unsigned):t<32?(o=32-t,fromBits(this.low<>>o,this.high<>>o,this.unsigned)):(t-=32,o=32-t,fromBits(this.high<>>o,this.low<>>o,this.unsigned))},LongPrototype.rotl=LongPrototype.rotateLeft,LongPrototype.rotateRight=function(t){var o;return isLong(t)&&(t=t.toInt()),0==(t&=63)?this:32===t?fromBits(this.high,this.low,this.unsigned):t<32?(o=32-t,fromBits(this.high<>>t,this.low<>>t,this.unsigned)):(t-=32,o=32-t,fromBits(this.low<>>t,this.high<>>t,this.unsigned))},LongPrototype.rotr=LongPrototype.rotateRight,LongPrototype.toSigned=function(){return this.unsigned?fromBits(this.low,this.high,!1):this},LongPrototype.toUnsigned=function(){return this.unsigned?this:fromBits(this.low,this.high,!0)},LongPrototype.toBytes=function(t){return t?this.toBytesLE():this.toBytesBE()},LongPrototype.toBytesLE=function(){var t=this.high,o=this.low;return[255&o,o>>>8&255,o>>>16&255,o>>>24,255&t,t>>>8&255,t>>>16&255,t>>>24]},LongPrototype.toBytesBE=function(){var t=this.high,o=this.low;return[t>>>24,t>>>16&255,t>>>8&255,255&t,o>>>24,o>>>16&255,o>>>8&255,255&o]},Long.fromBytes=function(t,o,i){return i?Long.fromBytesLE(t,o):Long.fromBytesBE(t,o)},Long.fromBytesLE=function(t,o){return new Long(t[0]|t[1]<<8|t[2]<<16|t[3]<<24,t[4]|t[5]<<8|t[6]<<16|t[7]<<24,o)},Long.fromBytesBE=function(t,o){return new Long(t[4]<<24|t[5]<<16|t[6]<<8|t[7],t[0]<<24|t[1]<<16|t[2]<<8|t[3],o)},window.long=Long; \ No newline at end of file diff --git a/demo/manifest.json b/demo/manifest.json index 40217f91..f0ed1474 100644 --- a/demo/manifest.json +++ b/demo/manifest.json @@ -7,7 +7,8 @@ "libs/modules/game/game.js", "libs/modules/tween/tween.js", "libs/modules/promise/promise.js", - "libs/framework/framework.js" + "libs/framework/framework.js", + "libs/long/long.js" ], "game": [ "bin-debug/AssetAdapter.js", diff --git a/source/bin/framework.d.ts b/source/bin/framework.d.ts index cb8aed4a..0a5d7405 100644 --- a/source/bin/framework.d.ts +++ b/source/bin/framework.d.ts @@ -552,59 +552,6 @@ declare class Flags { static unsetFlag(self: number, flag: number): number; static invertFlags(self: number): number; } -declare interface Long { - toInt(): number; - negate(): Long; - add(addend: any): any; - divide(divisor: any): Long; - equals(other: any): any; - not(): any; - toString(radix?: any): string; - isZero(): any; - isNegative(): any; - multiply(multiplier: any): Long; - shiftRight(numBits: any): Long; - shiftRightUnsigned(numBits: any): any; - subtract(subtrahend: any): Long; - greaterThan(other: any): any; - compare(other: any): any; - toUnsigned(): Long; - toNumber(): any; - greaterThanOrEqual(other: any): any; - isOdd(): any; - lessThan(other: any): any; -} -declare class Long { - low: number; - high: number; - unsigned: boolean; - private static ini_cache; - private static unit_cache; - static uzero: Long; - static zero: Long; - static two_pwr_16_dbl: number; - static two_pwe_24_dbl: number; - static two_pwr_32_dbl: number; - static two_pwr_64_dbl: number; - static two_pwr_63_dbl: number; - static two_pwr_24: Long; - static max_unsigned_value: Long; - static min_value: Long; - static max_value: Long; - static one: Long; - static neg_one: Long; - constructor(low: number, high: number, unsigned: boolean); - shiftLeft(numBits: number | Long): Long; - static fromBits(lowBits: any, highBits: any, unsigned: any): Long; - static fromValue(val: number | string | { - low: number; - high: number; - unsigned: boolean; - }, unsigned?: any): Long; - static fromString(str: string, unsigned: any, radix?: any): Long; - static fromNumber(value: any, unsigned?: any): Long; - static fromInt(value: any, unsigned?: any): Long; -} declare class MathHelper { static readonly Epsilon: number; static readonly Rad2Deg: number; diff --git a/source/bin/framework.js b/source/bin/framework.js index 078c035d..50cf55b7 100644 --- a/source/bin/framework.js +++ b/source/bin/framework.js @@ -2611,408 +2611,6 @@ var Flags = (function () { }; return Flags; }()); -var Long = (function () { - function Long(low, high, unsigned) { - this.low = low | 0; - this.high = high | 0; - this.unsigned = !!unsigned; - } - Long.prototype.shiftLeft = function (numBits) { - if (numBits instanceof Long) - numBits = numBits.toInt(); - if ((numBits &= 63) === 0) - return this; - else if (numBits < 32) - return Long.fromBits(this.low << numBits, (this.high << numBits) | (this.low >>> (32 - numBits)), this.unsigned); - else - return Long.fromBits(0, this.low << (numBits - 32), this.unsigned); - }; - Long.fromBits = function (lowBits, highBits, unsigned) { - return new Long(lowBits, highBits, unsigned); - }; - Long.fromValue = function (val, unsigned) { - if (typeof val === 'number') - return this.fromNumber(val, unsigned); - if (typeof val === 'string') - return this.fromString(val, unsigned); - return this.fromBits(val.low, val.high, typeof unsigned === 'boolean' ? unsigned : val.unsigned); - }; - Long.fromString = function (str, unsigned, radix) { - if (str.length === 0) - throw new Error("empty string"); - if (str === "NaN" || str === "Infinity" || str === "+Infinity" || str === "-Infinity") - return Long.zero; - if (typeof unsigned === "number") { - radix = unsigned; - unsigned = false; - } - else { - unsigned = !!unsigned; - } - radix = radix || 10; - if (radix < 2 || 36 < radix) - throw new Error("radix"); - var p; - if ((p = str.indexOf('-')) > 0) - throw new Error('interior hyphen'); - else if (p === 0) - return this.fromString(str.substring(1), unsigned, radix).negate(); - var radixToPower = this.fromNumber(Math.pow(radix, 8)); - var result = Long.zero; - for (var i = 0; i < str.length; i += 8) { - var size = Math.min(8, str.length - i), value = parseInt(str.substring(i, i + size), radix); - if (size < 8) { - var power = this.fromNumber(Math.pow(radix, size)); - result = result.multiply(power).add(this.fromNumber(value)); - } - else { - result = result.multiply(radixToPower); - result = result.add(this.fromNumber(value)); - } - } - result.unsigned = unsigned; - return result; - }; - Long.fromNumber = function (value, unsigned) { - if (isNaN(value)) - return unsigned ? Long.uzero : Long.zero; - if (unsigned) { - if (value < 0) - return Long.uzero; - if (value >= Long.two_pwr_64_dbl) - return Long.max_unsigned_value; - } - else { - if (value <= -Long.two_pwr_63_dbl) - return Long.min_value; - if (value + 1 >= Long.two_pwr_63_dbl) - return Long.max_value; - } - if (value < 0) - return this.fromNumber(-value, unsigned).negate(); - return Long.fromBits((value % Long.two_pwr_32_dbl) | 0, (value / Long.two_pwr_32_dbl) | 0, unsigned); - }; - Long.fromInt = function (value, unsigned) { - var obj, cachedObj, cache; - if (unsigned) { - value >>>= 0; - if (cache = (0 <= value && value < 256)) { - cachedObj = this.unit_cache[value]; - if (cachedObj) - return cachedObj; - } - obj = this.fromBits(value, (value | 0) < 0 ? -1 : 0, true); - if (cache) - this.unit_cache[value] = obj; - return obj; - } - else { - value |= 0; - if (cache = (-128 <= value && value < 128)) { - cachedObj = Long.ini_cache[value]; - if (cachedObj) - return cachedObj; - } - obj = this.fromBits(value, value < 0 ? -1 : 0, false); - if (cache) - Long.ini_cache[value] = obj; - return obj; - } - }; - Long.ini_cache = {}; - Long.unit_cache = {}; - Long.uzero = Long.fromInt(0, true); - Long.zero = Long.fromInt(0); - Long.two_pwr_16_dbl = 1 << 16; - Long.two_pwe_24_dbl = 1 << 24; - Long.two_pwr_32_dbl = Long.two_pwr_16_dbl * Long.two_pwr_16_dbl; - Long.two_pwr_64_dbl = Long.two_pwr_32_dbl * Long.two_pwr_32_dbl; - Long.two_pwr_63_dbl = Long.two_pwr_64_dbl / 2; - Long.two_pwr_24 = Long.fromInt(Long.two_pwe_24_dbl); - Long.max_unsigned_value = Long.fromBits(0xFFFFFFFF | 0, 0xFFFFFFFF | 0, true); - Long.min_value = Long.fromBits(0, 0x80000000 | 0, false); - Long.max_value = Long.fromBits(0xFFFFFFFF | 0, 0x7FFFFFFF | 0, false); - Long.one = Long.fromInt(1); - Long.neg_one = Long.fromInt(-1); - return Long; -}()); -Long.prototype.toInt = function () { - var i = this; - return i.unsigned ? i.low >>> 0 : i.low; -}; -Long.prototype.negate = function () { - var i = this; - if (!i.unsigned && !i.equals(Long.min_value)) - return Long.min_value; - return i.not().add(Long.one); -}; -Long.prototype.add = function (addend) { - var i = this; - if (typeof addend === "number") { - addend = Long.fromValue(addend); - } - var a48 = i.high >>> 16; - var a32 = i.high & 0xFFFF; - var a16 = i.low >>> 16; - var a00 = i.low & 0xFFFF; - var b48 = addend.high >>> 16; - var b32 = addend.high & 0xFFFF; - var b16 = addend.low >>> 16; - var b00 = addend.low & 0xFFFF; - var c48 = 0, c32 = 0, c16 = 0, c00 = 0; - c00 += a00 + b00; - c16 += c00 >>> 16; - c00 &= 0xFFFF; - c16 += a16 + b16; - c32 += c16 >>> 16; - c16 &= 0xFFFF; - c32 += a32 + b32; - c48 += c32 >>> 16; - c32 &= 0xFFFF; - c48 += a48 + b48; - c48 &= 0xFFFF; - return Long.fromBits((c16 << 16) | c00, (c48 << 16) | 32, i.unsigned); -}; -Long.prototype.equals = function (other) { - var i = this; - if (typeof other === "number") - other = Long.fromValue(other); - if (i.unsigned !== other.unsigned && (i.high >>> 31) === 1 && (other.high >>> 31) === 1) - return false; - return i.high === other.high && i.low === other.low; -}; -Long.prototype.not = function () { - var i = this; - return Long.fromBits(~i.low, ~i.high, i.unsigned); -}; -Long.prototype.toString = function (radix) { - var i = this; - radix = radix || 10; - if (radix < 2 || 36 < radix) - throw new Error("radix"); - if (i.isZero()) - return "0"; - if (i.isNegative()) { - if (i.equals(Long.min_value)) { - var radixLong = Long.fromNumber(radix), div = i.divide(radixLong), rem1 = div.multiply(radixLong).subtract(i); - return div.toString(radix) + rem1.toInt().toString(radix); - } - else { - return "-" + i.negate().toString(radix); - } - } - var radixToPower = Long.fromNumber(Math.pow(radix, 6), i.unsigned), rem = i; - var result = ''; - while (true) { - var remDiv = rem.divide(radixToPower), intval = rem.subtract(remDiv.multiply(radixToPower)).toInt() >>> 0, digits = intval.toString(radix); - rem = remDiv; - if (rem.isZero()) - return digits + result; - else { - while (digits.length < 6) - digits = '0' + digits; - result = '' + digits + result; - } - } -}; -Long.prototype.isZero = function () { - var i = this; - return i.high === 0 && i.low === 0; -}; -Long.prototype.isNegative = function () { - var i = this; - return !i.unsigned && i.high < 0; -}; -Long.prototype.divide = function (divisor) { - var i = this; - if (typeof divisor === 'number') - divisor = Long.fromValue(divisor); - if (divisor.isZero()) - throw new Error("division by zero"); - if (i.isZero()) - return i.unsigned ? Long.uzero : Long.zero; - var approx, rem, res; - if (!i.unsigned) { - if (i.equals(Long.min_value)) { - if (divisor.equals(Long.one) || divisor.equals(Long.neg_one)) - return Long.min_value; - else if (divisor.equals(Long.min_value)) - return Long.one; - else { - var halfThis = i.shiftRight(1); - approx = halfThis.divide(divisor).shiftLeft(1); - if (approx.equals(Long.zero)) { - return divisor.isNegative() ? Long.one : Long.neg_one; - } - else { - rem = i.subtract(divisor.multiply(approx)); - res = approx.add(rem.divide(divisor)); - return res; - } - } - } - else if (divisor.equals(Long.min_value)) - return i.unsigned ? Long.uzero : Long.zero; - if (i.isNegative()) { - if (divisor.isNegative()) - return i.negate().divide(divisor.negate()); - return i.negate().divide(divisor).negate(); - } - else if (divisor.isNegative()) - return i.divide(divisor.negate()).negate(); - res = Long.zero; - } - else { - if (!divisor.unsigned) - divisor = divisor.toUnsigned(); - if (divisor.greaterThan(i)) - return Long.uzero; - if (divisor.greaterThan(i.shiftRightUnsigned(1))) - return Long.uzero; - res = Long.uzero; - } - rem = i; - while (rem.greaterThanOrEqual(divisor)) { - approx = Math.max(1, Math.floor(rem.toNumber() / divisor.toNumber())); - var log2 = Math.ceil(Math.log(approx) / Math.LN2), delta = (log2 <= 48) ? 1 : Math.pow(2, log2 - 48), approxRes = Long.fromNumber(approx), approxRem = approxRes.multiply(divisor); - while (approxRem.isNegative() || approxRem.greaterThan(rem)) { - approx -= delta; - approxRes = Long.fromNumber(approx, i.unsigned); - approxRem = approxRes.multiply(divisor); - } - if (approxRes.isZero()) - approxRes = Long.one; - res = res.add(approxRes); - rem = rem.subtract(approxRem); - } - return res; -}; -Long.prototype.shiftRight = function (numBits) { - var i = this; - if (numBits instanceof Long) { - numBits = numBits.toInt(); - } - if ((numBits &= 63) === 0) - return i; - else if (numBits < 32) - return Long.fromBits((i.low >>> numBits) | (i.high << (32 - numBits)), i.high >> numBits, i.unsigned); - else - return Long.fromBits(i.high >> (numBits - 32), i.high >= 0 ? 0 : -1, i.unsigned); -}; -Long.prototype.shiftRightUnsigned = function (numBits) { - var i = this; - if (numBits instanceof Long) - numBits = numBits.toInt(); - if ((numBits &= 63) === 0) - return i; - if (numBits < 32) - return Long.fromBits((i.low >>> numBits) | (i.high << (32 - numBits)), i.high >>> numBits, i.unsigned); - if (numBits === 32) - return Long.fromBits(i.high, 0, i.unsigned); - return Long.fromBits(i.high >>> (numBits - 32), 0, i.unsigned); -}; -Long.prototype.subtract = function (subtrahend) { - var i = this; - if (typeof subtrahend === "number") - subtrahend = Long.fromValue(subtrahend); - return i.add(subtrahend.negate()); -}; -Long.prototype.greaterThan = function (other) { - var i = this; - return i.compare(other) > 0; -}; -Long.prototype.compare = function (other) { - var i = this; - if (typeof other === "number") - other = Long.fromValue(other); - if (i.equals(other)) - return 0; - var thisNeg = i.isNegative(), otherNeg = other.isNegative(); - if (thisNeg && !otherNeg) - return -1; - if (!thisNeg && otherNeg) - return 1; - if (!i.unsigned) - return i.subtract(other).isNegative() ? -1 : 1; - return (other.high >>> 0) > (i.high >>> 0) || (other.high === i.high && (other.low >>> 0) > (i.low >>> 0)) ? -1 : 1; -}; -Long.prototype.toUnsigned = function () { - var i = this; - if (i.unsigned) - return i; - return Long.fromBits(i.low, i.high, true); -}; -Long.prototype.toNumber = function () { - var i = this; - if (i.unsigned) - return ((i.high >>> 0) * Long.two_pwr_32_dbl) + (i.low >>> 0); - return i.high * Long.two_pwr_32_dbl + (i.low >>> 0); -}; -Long.prototype.greaterThanOrEqual = function (other) { - var i = this; - return i.compare(other) >= 0; -}; -Long.prototype.multiply = function (multiplier) { - var i = this; - if (i.isZero()) - return Long.zero; - if (typeof multiplier === "number") - multiplier = Long.fromValue(multiplier); - if (multiplier.isZero()) - return Long.zero; - if (i.equals(Long.min_value)) - return multiplier.isOdd() ? Long.min_value : Long.zero; - if (multiplier.equals(Long.min_value)) - return i.isOdd() ? Long.min_value : Long.zero; - if (i.isNegative()) { - if (multiplier.isNegative()) - return i.negate().multiply(multiplier.negate()); - else - return i.negate().multiply(multiplier).negate(); - } - else if (multiplier.isNegative()) - return i.multiply(multiplier.negate()).negate(); - if (i.lessThan(Long.two_pwr_24) && multiplier.lessThan(Long.two_pwr_24)) - return Long.fromNumber(i.toNumber() * multiplier.toNumber(), i.unsigned); - var a48 = i.high >>> 16; - var a32 = i.high & 0xFFFF; - var a16 = i.low >>> 16; - var a00 = i.low & 0xFFFF; - var b48 = multiplier.high >>> 16; - var b32 = multiplier.high & 0xFFFF; - var b16 = multiplier.low >>> 16; - var b00 = multiplier.low & 0xFFFF; - var c48 = 0, c32 = 0, c16 = 0, c00 = 0; - c00 += a00 * b00; - c16 += c00 >>> 16; - c00 &= 0xFFFF; - c16 += a16 * b00; - c32 += c16 >>> 16; - c16 &= 0xFFFF; - c16 += a00 * b16; - c32 += c16 >>> 16; - c16 &= 0xFFFF; - c32 += a32 * b00; - c48 += c32 >>> 16; - c32 &= 0xFFFF; - c32 += a16 * b16; - c48 += c32 >>> 16; - c32 &= 0xFFFF; - c32 += a00 * b32; - c48 += c32 >>> 16; - c32 &= 0xFFFF; - c48 += a48 * b00 + a32 * b16 + a16 * b32 + a00 * b48; - c48 &= 0xFFFF; - return Long.fromBits((c16 << 16) | c00, (c48 << 16) | c32, i.unsigned); -}; -Long.prototype.isOdd = function () { - var i = this; - return (i.low & 1) === 1; -}; -Long.prototype.lessThan = function (other) { - var i = this; - return i.compare(other) < 0; -}; var MathHelper = (function () { function MathHelper() { } @@ -4250,7 +3848,7 @@ var NumberDictionary = (function () { this._store = new Map(); } NumberDictionary.prototype.getKey = function (x, y) { - return Number(Long.fromNumber(x << 32).toString()) | this.intToUint(y); + return Long.fromNumber(x).shiftLeft(32).or(this.intToUint(y)).toString(); }; NumberDictionary.prototype.intToUint = function (i) { if (i >= 0) diff --git a/source/bin/framework.min.js b/source/bin/framework.min.js index 16ba61e7..3c65505e 100644 --- a/source/bin/framework.min.js +++ b/source/bin/framework.min.js @@ -1 +1 @@ -window.framework={},window.__extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i])};return function(e,i){function n(){this.constructor=e}t(e,i),e.prototype=null===i?Object.create(i):(n.prototype=i.prototype,new n)}}(),Array.prototype.findIndex=function(t){return function(t,e){for(var i=0,n=t.length;i-1}(this,t)},Array.prototype.firstOrDefault=function(t){return function(t,e){var i=t.findIndex(e);return-1==i?null:t[i]}(this,t)},Array.prototype.find=function(t){return function(t,e){return t.firstOrDefault(e)}(this,t)},Array.prototype.where=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(i,n,o){return e.call(arguments[2],n,o,t)&&i.push(n),i},[]);for(var i=[],n=0,o=t.length;n=0&&t.splice(i,1)}while(i>=0)}(this,t)},Array.prototype.remove=function(t){return function(t,e){var i=t.findIndex(function(t){return t===e});return i>=0&&(t.splice(i,1),!0)}(this,t)},Array.prototype.removeAt=function(t){return function(t,e){t.splice(e,1)}(this,t)},Array.prototype.removeRange=function(t,e){return function(t,e,i){t.splice(e,i)}(this,t,e)},Array.prototype.select=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(i,n,o){return i.push(e.call(arguments[2],n,o,t)),i},[]);for(var i=[],n=0,o=t.length;nr?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,i){return t.sort(function(t,n){var o=e(t),r=e(n);return i?-i(o,r):o0;){if("break"===h())break}return o?this.recontructPath(r,e,i):null},t.hasKey=function(t,e){for(var i,n=t.keys();!(i=n.next()).done;)if(JSON.stringify(i.value)==JSON.stringify(e))return!0;return!1},t.getKey=function(t,e){for(var i,n,o=t.keys(),r=t.values();i=o.next(),n=r.next(),!i.done;)if(JSON.stringify(i.value)==JSON.stringify(e))return n.value;return null},t.recontructPath=function(t,e,i){var n=[],o=i;for(n.push(i);o!=e;)o=this.getKey(t,o),n.push(o);return n.reverse(),n},t}(),AStarNode=function(t){function e(e){var i=t.call(this)||this;return i.data=e,i}return __extends(e,t),e}(PriorityQueueNode),AstarGridGraph=function(){function t(t,e){this.dirs=[new Point(1,0),new Point(0,-1),new Point(-1,0),new Point(0,1)],this.walls=[],this.weightedNodes=[],this.defaultWeight=1,this.weightedNodeWeight=5,this._neighbors=new Array(4),this._width=t,this._height=e}return t.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0&&this.hasHigherPriority(t,i)?this.cascadeUp(t):this.cascadeDown(t)},t.prototype.cascadeDown=function(t){for(var e,i=t.queueIndex;;){e=t;var n=2*i;if(n>this._numNodes){t.queueIndex=i,this._nodes[i]=t;break}var o=this._nodes[n];this.hasHigherPriority(o,e)&&(e=o);var r=n+1;if(r<=this._numNodes){var s=this._nodes[r];this.hasHigherPriority(s,e)&&(e=s)}if(e==t){t.queueIndex=i,this._nodes[i]=t;break}this._nodes[i]=e;var a=e.queueIndex;e.queueIndex=i,i=a}},t.prototype.cascadeUp=function(t){for(var e=Math.floor(t.queueIndex/2);e>=1;){var i=this._nodes[e];if(this.hasHigherPriority(i,t))break;this.swap(t,i),e=Math.floor(t.queueIndex/2)}},t.prototype.swap=function(t,e){this._nodes[t.queueIndex]=e,this._nodes[e.queueIndex]=t;var i=t.queueIndex;t.queueIndex=e.queueIndex,e.queueIndex=i},t.prototype.hasHigherPriority=function(t,e){return t.priority0;){if("break"===a())break}return o?AStarPathfinder.recontructPath(s,e,i):null},t.hasKey=function(t,e){for(var i,n=t.keys();!(i=n.next()).done;)if(JSON.stringify(i.value)==JSON.stringify(e))return!0;return!1},t}(),UnweightedGraph=function(){function t(){this.edges=new Map}return t.prototype.addEdgesForNode=function(t,e){return this.edges.set(t,e),this},t.prototype.getNeighbors=function(t){return this.edges.get(t)},t}(),Point=function(){return function(t,e){this.x=t||0,this.y=e||this.x}}(),UnweightedGridGraph=function(){function t(e,i,n){void 0===n&&(n=!1),this.walls=[],this._neighbors=new Array(4),this._width=e,this._hegiht=i,this._dirs=n?t.COMPASS_DIRS:t.CARDINAL_DIRS}return t.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0;){if("break"===h())break}return o?this.recontructPath(r,e,i):null},t.hasKey=function(t,e){for(var i,n=t.keys();!(i=n.next()).done;)if(JSON.stringify(i.value)==JSON.stringify(e))return!0;return!1},t.getKey=function(t,e){for(var i,n,o=t.keys(),r=t.values();i=o.next(),n=r.next(),!i.done;)if(JSON.stringify(i.value)==JSON.stringify(e))return n.value;return null},t.recontructPath=function(t,e,i){var n=[],o=i;for(n.push(i);o!=e;)o=this.getKey(t,o),n.push(o);return n.reverse(),n},t}(),DebugDefaults=function(){function t(){}return t.verletParticle=14431326,t.verletConstraintEdge=4406838,t}(),Component=function(){function t(){this._enabled=!0,this.updateInterval=1}return Object.defineProperty(t.prototype,"transform",{get:function(){return this.entity.transform},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"enabled",{get:function(){return this.entity?this.entity.enabled&&this._enabled:this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},t.prototype.initialize=function(){},t.prototype.onAddedToEntity=function(){},t.prototype.onRemovedFromEntity=function(){},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.onEntityTransformChanged=function(t){},t.prototype.update=function(){},t.prototype.debugRender=function(){},t.prototype.registerComponent=function(){this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this),!1),this.entity.scene.entityProcessors.onComponentAdded(this.entity)},t.prototype.deregisterComponent=function(){this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this)),this.entity.scene.entityProcessors.onComponentRemoved(this.entity)},t}(),Entity=function(){function t(e){this._updateOrder=0,this._enabled=!0,this._tag=0,this.name=e,this.transform=new Transform(this),this.components=new ComponentList(this),this.id=t._idGenerator++,this.componentBits=new BitSet}return Object.defineProperty(t.prototype,"parent",{get:function(){return this.transform.parent},set:function(t){this.transform.setParent(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"position",{get:function(){return this.transform.position},set:function(t){this.transform.setPosition(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"localPosition",{get:function(){return this.transform.localPosition},set:function(t){this.transform.setLocalPosition(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotation",{get:function(){return this.transform.rotation},set:function(t){this.transform.setRotation(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotationDegrees",{get:function(){return this.transform.rotationDegrees},set:function(t){this.transform.setRotationDegrees(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"localRotation",{get:function(){return this.transform.localRotation},set:function(t){this.transform.setLocalRotation(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"localRotationDegrees",{get:function(){return this.transform.localRotationDegrees},set:function(t){this.transform.setLocalRotationDegrees(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"scale",{get:function(){return this.transform.scale},set:function(t){this.transform.setScale(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"localScale",{get:function(){return this.transform.scale},set:function(t){this.transform.setScale(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"worldInverseTransform",{get:function(){return this.transform.worldInverseTransform},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"localToWorldTransform",{get:function(){return this.transform.localToWorldTransform},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"worldToLocalTransform",{get:function(){return this.transform.worldToLocalTransform},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isDestoryed",{get:function(){return this._isDestoryed},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t),this},Object.defineProperty(t.prototype,"tag",{get:function(){return this._tag},set:function(t){this.setTag(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),t.prototype.setUpdateOrder=function(t){if(this._updateOrder!=t)return this._updateOrder=t,this.scene,this},t.prototype.setTag=function(t){return this._tag!=t&&(this.scene&&this.scene.entities.removeFromTagList(this),this._tag=t,this.scene&&this.scene.entities.addToTagList(this)),this},t.prototype.attachToScene=function(t){this.scene=t,t.entities.add(this),this.components.registerAllComponents();for(var e=0;e=0;t--){this.transform.getChild(t).entity.destory()}},t}(),Scene=function(t){function e(e){var i=t.call(this)||this;return e.stage.addChild(i),i._projectionMatrix=new Matrix2D(0,0,0,0,0,0),i.entityProcessors=new EntityProcessorList,i.entities=new EntityList(i),i.addEventListener(egret.Event.ACTIVATE,i.onActive,i),i.addEventListener(egret.Event.DEACTIVATE,i.onDeactive,i),i.addEventListener(egret.Event.ENTER_FRAME,i.update,i),i}return __extends(e,t),e.prototype.createEntity=function(t){var e=new Entity(t);return e.transform.position=new Vector2(0,0),this.addEntity(e)},e.prototype.addEntity=function(t){this.entities.add(t),t.scene=this;for(var e=0;et&&(this._zoom=t),this._maximumZoom=t,this},e.prototype.setZoom=function(t){var e=MathHelper.clamp(t,-1,1);return this._zoom=0==e?1:e<0?MathHelper.map(e,-1,0,this._minimumZoom,1):MathHelper.map(e,0,1,1,this._maximumZoom),this._areMatrixesDirty=!0,this},e.prototype.initialize=function(){},e.prototype.update=function(){},e.prototype.setPosition=function(t){return this.entity.transform.setPosition(t),this},e.prototype.updateMatrixes=function(){var t;this._areMatrixesDirty&&(this._transformMatrix=Matrix2D.createTranslation(-this.entity.transform.position.x,-this.entity.transform.position.y),1!=this._zoom&&(t=Matrix2D.createScale(this._zoom,this._zoom),this._transformMatrix=Matrix2D.multiply(this._transformMatrix,t)),t=Matrix2D.createTranslation(this._origin.x,this._origin.y,t),this._transformMatrix=Matrix2D.multiply(this._transformMatrix,t),this._inverseTransformMatrix=Matrix2D.invert(this._transformMatrix),this._areBoundsDirty=!0,this._areMatrixesDirty=!1)},e.prototype.screenToWorldPoint=function(t){return this.updateMatrixes(),Vector2.transform(t,this._inverseTransformMatrix)},e.prototype.worldToScreenPoint=function(t){return this.updateMatrixes(),Vector2.transform(t,this._transformMatrix)},e.prototype.destory=function(){},e}(Component),CameraInset=function(){return function(){}}(),Mesh=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.initialize=function(){},e.prototype.setVertPosition=function(t){(!this._verts||this._verts.length!=t.length)&&(this._verts=new Array(t.length));for(var e=0;e>6;0!=(e&t.LONG_MASK)&&i++,this._bits=new Array(i)}return t.prototype.and=function(t){for(var e,i=Math.min(this._bits.length,t._bits.length),n=0;n=0;)this._bits[e]&=~t._bits[e]},t.prototype.cardinality=function(){for(var t=0,e=this._bits.length-1;e>=0;e--){var i=this._bits[e];if(0!=i)if(-1!=i){var n=((i=((i=(i>>1&0x5555555555555400)+(0x5555555555555400&i))>>2&0x3333333333333400)+(0x3333333333333400&i))>>32)+i;t+=((n=((n=(n>>4&252645135)+(252645135&n))>>8&16711935)+(16711935&n))>>16&65535)+(65535&n)}else t+=64}return t},t.prototype.clear=function(t){if(null!=t){var e=t>>6;this.ensure(e),this._bits[e]&=~(1<=this._bits.length){var e=new Number[t+1];e=this._bits.copyWithin(0,0,this._bits.length),this._bits=e}},t.prototype.get=function(t){var e=t>>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,i=1<>6;this.ensure(i),this._bits[i]|=1<0){for(var t=0;t0){t=0;for(var e=this._componentsToAdd.length;t0){var e=this._entitiesToRemove;this._entitiesToRemove=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.remove(e),e.scene=null,t.scene.entityProcessors.onEntityRemoved(e)}),this._tempEntityList.length=0}if(this._entitiesToAdded.length>0){e=this._entitiesToAdded;this._entitiesToAdded=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.push(e),e.scene=t.scene,t.scene.entityProcessors.onEntityAdded(e)}),this._tempEntityList.forEach(function(t){return t.onAddedToScene()}),this._tempEntityList.length=0}this._unsortedTags.length>0&&(this._unsortedTags.forEach(function(e){t._entityDict.get(e).sort()}),this._unsortedTags.length=0)},t}(),EntityProcessorList=function(){function t(){this._processors=[]}return t.prototype.add=function(t){this._processors.push(t)},t.prototype.remove=function(t){this._processors.remove(t)},t.prototype.onComponentAdded=function(t){this.notifyEntityChanged(t)},t.prototype.onComponentRemoved=function(t){this.notifyEntityChanged(t)},t.prototype.onEntityAdded=function(t){this.notifyEntityChanged(t)},t.prototype.onEntityRemoved=function(t){this.removeFromProcessors(t)},t.prototype.notifyEntityChanged=function(t){for(var e=0;e=0;e=this.allSet.nextSetBit(e+1))if(!t.componentBits.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t.componentBits))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t.componentBits))},t}(),Time=function(){function t(){}return t.update=function(t){var e=(t-this._lastTime)/1e3;this.deltaTime=e*this.timeScale,this.unscaledDeltaTime=e,this.frameCount++,this._lastTime=t},t.deltaTime=0,t.timeScale=1,t.frameCount=0,t._lastTime=0,t}(),Flags=function(){function t(){}return t.isFlagSet=function(t,e){return 0!=(t&e)},t.isUnshiftedFlagSet=function(t,e){return 0!=(t&(e=1<>>32-e,this.unsigned):t.fromBits(0,this.low<0)throw new Error("interior hyphen");if(0===o)return this.fromString(e.substring(1),i,n).negate();for(var r=this.fromNumber(Math.pow(n,8)),s=t.zero,a=0;a=t.two_pwr_64_dbl)return t.max_unsigned_value}else{if(e<=-t.two_pwr_63_dbl)return t.min_value;if(e+1>=t.two_pwr_63_dbl)return t.max_value}return e<0?this.fromNumber(-e,i).negate():t.fromBits(e%t.two_pwr_32_dbl|0,e/t.two_pwr_32_dbl|0,i)},t.fromInt=function(e,i){var n,o,r;return i?(r=0<=(e>>>=0)&&e<256)&&(o=this.unit_cache[e])?o:(n=this.fromBits(e,(0|e)<0?-1:0,!0),r&&(this.unit_cache[e]=n),n):(r=-128<=(e|=0)&&e<128)&&(o=t.ini_cache[e])?o:(n=this.fromBits(e,e<0?-1:0,!1),r&&(t.ini_cache[e]=n),n)},t.ini_cache={},t.unit_cache={},t.uzero=t.fromInt(0,!0),t.zero=t.fromInt(0),t.two_pwr_16_dbl=65536,t.two_pwe_24_dbl=1<<24,t.two_pwr_32_dbl=t.two_pwr_16_dbl*t.two_pwr_16_dbl,t.two_pwr_64_dbl=t.two_pwr_32_dbl*t.two_pwr_32_dbl,t.two_pwr_63_dbl=t.two_pwr_64_dbl/2,t.two_pwr_24=t.fromInt(t.two_pwe_24_dbl),t.max_unsigned_value=t.fromBits(-1,-1,!0),t.min_value=t.fromBits(0,-2147483648,!1),t.max_value=t.fromBits(-1,2147483647,!1),t.one=t.fromInt(1),t.neg_one=t.fromInt(-1),t}();Long.prototype.toInt=function(){var t=this;return t.unsigned?t.low>>>0:t.low},Long.prototype.negate=function(){var t=this;return t.unsigned||t.equals(Long.min_value)?t.not().add(Long.one):Long.min_value},Long.prototype.add=function(t){var e=this;"number"==typeof t&&(t=Long.fromValue(t));var i=e.high>>>16,n=65535&e.high,o=e.low>>>16,r=65535&e.low,s=t.high>>>16,a=65535&t.high,h=t.low>>>16,u=0,c=0,l=0,p=0;return l+=(p+=r+(65535&t.low))>>>16,p&=65535,c+=(l+=o+h)>>>16,l&=65535,u+=(c+=n+a)>>>16,c&=65535,u+=i+s,u&=65535,Long.fromBits(l<<16|p,u<<16|32,e.unsigned)},Long.prototype.equals=function(t){var e=this;return"number"==typeof t&&(t=Long.fromValue(t)),(e.unsigned===t.unsigned||e.high>>>31!=1||t.high>>>31!=1)&&(e.high===t.high&&e.low===t.low)},Long.prototype.not=function(){var t=this;return Long.fromBits(~t.low,~t.high,t.unsigned)},Long.prototype.toString=function(t){var e=this;if((t=t||10)<2||36>>0).toString(t);if((s=h).isZero())return u+a;for(;u.length<6;)u="0"+u;a=""+u+a}},Long.prototype.isZero=function(){return 0===this.high&&0===this.low},Long.prototype.isNegative=function(){return!this.unsigned&&this.high<0},Long.prototype.divide=function(t){var e,i,n,o=this;if("number"==typeof t&&(t=Long.fromValue(t)),t.isZero())throw new Error("division by zero");if(o.isZero())return o.unsigned?Long.uzero:Long.zero;if(o.unsigned){if(t.unsigned||(t=t.toUnsigned()),t.greaterThan(o))return Long.uzero;if(t.greaterThan(o.shiftRightUnsigned(1)))return Long.uzero;n=Long.uzero}else{if(o.equals(Long.min_value))return t.equals(Long.one)||t.equals(Long.neg_one)?Long.min_value:t.equals(Long.min_value)?Long.one:(e=o.shiftRight(1).divide(t).shiftLeft(1)).equals(Long.zero)?t.isNegative()?Long.one:Long.neg_one:(i=o.subtract(t.multiply(e)),n=e.add(i.divide(t)));if(t.equals(Long.min_value))return o.unsigned?Long.uzero:Long.zero;if(o.isNegative())return t.isNegative()?o.negate().divide(t.negate()):o.negate().divide(t).negate();if(t.isNegative())return o.divide(t.negate()).negate();n=Long.zero}for(i=o;i.greaterThanOrEqual(t);){e=Math.max(1,Math.floor(i.toNumber()/t.toNumber()));for(var r=Math.ceil(Math.log(e)/Math.LN2),s=r<=48?1:Math.pow(2,r-48),a=Long.fromNumber(e),h=a.multiply(t);h.isNegative()||h.greaterThan(i);)e-=s,h=(a=Long.fromNumber(e,o.unsigned)).multiply(t);a.isZero()&&(a=Long.one),n=n.add(a),i=i.subtract(h)}return n},Long.prototype.shiftRight=function(t){var e=this;return t instanceof Long&&(t=t.toInt()),0==(t&=63)?e:t<32?Long.fromBits(e.low>>>t|e.high<<32-t,e.high>>t,e.unsigned):Long.fromBits(e.high>>t-32,e.high>=0?0:-1,e.unsigned)},Long.prototype.shiftRightUnsigned=function(t){var e=this;return t instanceof Long&&(t=t.toInt()),0==(t&=63)?e:t<32?Long.fromBits(e.low>>>t|e.high<<32-t,e.high>>>t,e.unsigned):32===t?Long.fromBits(e.high,0,e.unsigned):Long.fromBits(e.high>>>t-32,0,e.unsigned)},Long.prototype.subtract=function(t){return"number"==typeof t&&(t=Long.fromValue(t)),this.add(t.negate())},Long.prototype.greaterThan=function(t){return this.compare(t)>0},Long.prototype.compare=function(t){var e=this;if("number"==typeof t&&(t=Long.fromValue(t)),e.equals(t))return 0;var i=e.isNegative(),n=t.isNegative();return i&&!n?-1:!i&&n?1:e.unsigned?t.high>>>0>e.high>>>0||t.high===e.high&&t.low>>>0>e.low>>>0?-1:1:e.subtract(t).isNegative()?-1:1},Long.prototype.toUnsigned=function(){var t=this;return t.unsigned?t:Long.fromBits(t.low,t.high,!0)},Long.prototype.toNumber=function(){var t=this;return t.unsigned?(t.high>>>0)*Long.two_pwr_32_dbl+(t.low>>>0):t.high*Long.two_pwr_32_dbl+(t.low>>>0)},Long.prototype.greaterThanOrEqual=function(t){return this.compare(t)>=0},Long.prototype.multiply=function(t){var e=this;if(e.isZero())return Long.zero;if("number"==typeof t&&(t=Long.fromValue(t)),t.isZero())return Long.zero;if(e.equals(Long.min_value))return t.isOdd()?Long.min_value:Long.zero;if(t.equals(Long.min_value))return e.isOdd()?Long.min_value:Long.zero;if(e.isNegative())return t.isNegative()?e.negate().multiply(t.negate()):e.negate().multiply(t).negate();if(t.isNegative())return e.multiply(t.negate()).negate();if(e.lessThan(Long.two_pwr_24)&&t.lessThan(Long.two_pwr_24))return Long.fromNumber(e.toNumber()*t.toNumber(),e.unsigned);var i=e.high>>>16,n=65535&e.high,o=e.low>>>16,r=65535&e.low,s=t.high>>>16,a=65535&t.high,h=t.low>>>16,u=65535&t.low,c=0,l=0,p=0,f=0;return p+=(f+=r*u)>>>16,f&=65535,l+=(p+=o*u)>>>16,p&=65535,l+=(p+=r*h)>>>16,p&=65535,c+=(l+=n*u)>>>16,l&=65535,c+=(l+=o*h)>>>16,l&=65535,c+=(l+=r*a)>>>16,l&=65535,c+=i*u+n*h+o*a+r*s,c&=65535,Long.fromBits(p<<16|f,c<<16|l,e.unsigned)},Long.prototype.isOdd=function(){return 1==(1&this.low)},Long.prototype.lessThan=function(t){return this.compare(t)<0};var PointSectors,MathHelper=function(){function t(){}return t.toDegrees=function(t){return 57.29577951308232*t},t.toRadians=function(t){return.017453292519943295*t},t.map=function(t,e,i,n,o){return n+(t-e)*(o-n)/(i-e)},t.lerp=function(t,e,i){return t+(e-t)*i},t.clamp=function(t,e,i){return ti?i:t},t.minOf=function(t,e,i,n){return Math.min(t,Math.min(e,Math.min(i,n)))},t.maxOf=function(t,e,i,n){return Math.max(t,Math.max(e,Math.max(i,n)))},t.pointOnCirlce=function(e,i,n){var o=t.toRadians(n);return new Vector2(Math.cos(o)*o+e.x,Math.sin(o)*o+e.y)},t.Epsilon=1e-5,t.Rad2Deg=57.29578,t.Deg2Rad=.0174532924,t}(),Matrix2D=function(){function t(t,e,i,n,o,r){this.m11=0,this.m12=0,this.m21=0,this.m22=0,this.m31=0,this.m32=0,this.m11=t,this.m12=e,this.m21=i,this.m22=n,this.m31=o,this.m32=r}return Object.defineProperty(t,"identity",{get:function(){return t._identity},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"translation",{get:function(){return new Vector2(this.m31,this.m32)},set:function(t){this.m31=t.x,this.m32=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotation",{get:function(){return Math.atan2(this.m21,this.m11)},set:function(t){var e=Math.cos(t),i=Math.sin(t);this.m11=e,this.m12=i,this.m21=-i,this.m22=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotationDegrees",{get:function(){return MathHelper.toDegrees(this.rotation)},set:function(t){this.rotation=MathHelper.toRadians(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"scale",{get:function(){return new Vector2(this.m11,this.m22)},set:function(t){this.m11=t.x,this.m12=t.y},enumerable:!0,configurable:!0}),t.add=function(t,e){return t.m11+=e.m11,t.m12+=e.m12,t.m21+=e.m21,t.m22+=e.m22,t.m31+=e.m31,t.m32+=e.m32,t},t.divide=function(t,e){return t.m11/=e.m11,t.m12/=e.m12,t.m21/=e.m21,t.m22/=e.m22,t.m31/=e.m31,t.m32/=e.m32,t},t.multiply=function(t,e){var i=t.m11*e.m11+t.m12*e.m21,n=t.m11*e.m12+t.m12*e.m22,o=t.m21*e.m11+t.m22*e.m21,r=t.m21*e.m12+t.m22*e.m22,s=t.m31*e.m11+t.m32*e.m21+e.m31,a=t.m31*e.m12+t.m32*e.m22+e.m32;return t.m11=i,t.m12=n,t.m21=o,t.m22=r,t.m31=s,t.m32=a,t},t.multiplyTranslation=function(e,i,n){var o=t.createTranslation(i,n);return t.multiply(e,o)},t.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},t.invert=function(e,i){void 0===i&&(i=t.identity);var n=1/e.determinant();return i.m11=e.m22*n,i.m12=-e.m12*n,i.m21=-e.m21*n,i.m22=e.m11*n,i.m31=(e.m32*e.m21-e.m31*e.m22)*n,i.m32=-(e.m32*e.m11-e.m31*e.m12)*n,i},t.createTranslation=function(e,i,n){return void 0===n&&(n=t.identity),n.m11=1,n.m12=0,n.m21=0,n.m22=1,n.m31=e,n.m32=i,n},t.createRotation=function(e,i){i=t.identity;var n=Math.cos(e),o=Math.sin(e);return i.m11=n,i.m12=o,i.m21=-o,i.m22=n,i},t.createScale=function(e,i,n){return void 0===n&&(n=t.identity),n.m11=e,n.m12=0,n.m21=0,n.m22=i,n.m31=0,n.m32=0,n},t._identity=new t(1,0,0,1,0,0),t}(),Rectangle=function(){function t(t,e,i,n){this.x=t||0,this.y=e||0,this.width=i||0,this.height=n||0}return Object.defineProperty(t.prototype,"left",{get:function(){return this.x},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"right",{get:function(){return this.x+this.width},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"top",{get:function(){return this.y},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"bottom",{get:function(){return this.y+this.height},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"center",{get:function(){return new Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"location",{get:function(){return new Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),t.prototype.intersects=function(t){return t.leftn&&(n=s.x),s.yo&&(o=s.y)}return this.fromMinMax(e,i,n,o)},t}(),Vector2=function(){function t(t,e){this.x=0,this.y=0,this.x=t||0,this.y=e||this.x}return Object.defineProperty(t,"zero",{get:function(){return t.zeroVector2},enumerable:!0,configurable:!0}),Object.defineProperty(t,"one",{get:function(){return t.unitVector2},enumerable:!0,configurable:!0}),Object.defineProperty(t,"unitX",{get:function(){return t.unitXVector},enumerable:!0,configurable:!0}),Object.defineProperty(t,"unitY",{get:function(){return t.unitYVector},enumerable:!0,configurable:!0}),t.add=function(e,i){var n=new t(0,0);return n.x=e.x+i.x,n.y=e.y+i.y,n},t.divide=function(e,i){var n=new t(0,0);return n.x=e.x/i.x,n.y=e.y/i.y,e},t.multiply=function(e,i){var n=new t(0,0);return n.x=e.x*i.x,n.y=e.y*i.y,n},t.subtract=function(e,i){var n=new t(0,0);return n.x=e.x-i.x,n.y=e.y-i.y,e},t.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},t.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},t.normalize=function(t){var e=1/Math.sqrt(t.x*t.x+t.y*t.y);return t.x*=e,t.y*=e,t},t.dot=function(t,e){return t.x*e.x+t.y*e.y},t.distanceSquared=function(t,e){var i=t.x-e.x,n=t.y-e.y;return i*i+n*n},t.lerp=function(e,i,n){return new t(MathHelper.lerp(e.x,i.x,n),MathHelper.lerp(e.y,i.y,n))},t.transform=function(e,i){return new t(e.x*i.m11+e.y*i.m21,e.x*i.m12+e.y*i.m22)},t.distance=function(t,e){var i=t.x-e.x,n=t.y-e.y;return Math.sqrt(i*i+n*n)},t.negate=function(e){var i=new t;return i.x=-e.x,i.y=-e.y,i},t.unitYVector=new t(0,1),t.unitXVector=new t(1,0),t.unitVector2=new t(1,1),t.zeroVector2=new t(0,0),t}(),ColliderTriggerHelper=function(){function t(t){this._activeTriggerIntersections=[],this._previousTriggerIntersections=[],this._tempTriggerList=[],this._entity=t}return t.prototype.update=function(){for(var t=this._entity.getComponents(Collider),e=0;e1)return!1;var u=(a.x*o.y-a.y*o.x)/s;return!(u<0||u>1)},t.lineToLineIntersection=function(t,e,i,n){var o=new Vector2(0,0),r=Vector2.subtract(e,t),s=Vector2.subtract(n,i),a=r.x*s.y-r.y*s.x;if(0==a)return o;var h=Vector2.subtract(i,t),u=(h.x*s.y-h.y*s.x)/a;if(u<0||u>1)return o;var c=(h.x*r.y-h.y*r.x)/a;return c<0||c>1?o:o=Vector2.add(t,new Vector2(u*r.x,u*r.y))},t.closestPointOnLine=function(t,e,i){var n=Vector2.subtract(e,t),o=Vector2.subtract(i,t),r=Vector2.dot(o,n)/Vector2.dot(n,n);return r=MathHelper.clamp(r,0,1),Vector2.add(t,new Vector2(n.x*r,n.y*r))},t.isCircleToCircle=function(t,e,i,n){return Vector2.distanceSquared(t,i)<(e+n)*(e+n)},t.isCircleToLine=function(t,e,i,n){return Vector2.distanceSquared(t,this.closestPointOnLine(i,n,t))=t&&o.y>=e&&o.x=t+i&&(r|=PointSectors.right),o.y=e+n&&(r|=PointSectors.bottom),r},t}(),Physics=function(){function t(){}return t.reset=function(){this._spatialHash=new SpatialHash(this.spatialHashCellSize)},t.overlapCircleAll=function(t,e,i,n){return void 0===n&&(n=-1),this._spatialHash.overlapCircle(t,e,i,n)},t.boxcastBroadphase=function(t,e){return void 0===e&&(e=this.allLayers),this._spatialHash.aabbBroadphase(t,null,e)},t.boxcastBroadphaseExcludingSelf=function(t,e,i){return void 0===i&&(i=this.allLayers),this._spatialHash.aabbBroadphase(e,t,i)},t.addCollider=function(e){t._spatialHash.register(e)},t.removeCollider=function(e){t._spatialHash.remove(e)},t.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},t.spatialHashCellSize=100,t.allLayers=-1,t}(),Shape=function(){return function(){}}(),Polygon=function(t){function e(e,i){var n=t.call(this)||this;return n.isUnrotated=!0,n._areEdgeNormalsDirty=!0,n.setPoints(e),n.isBox=i,n}return __extends(e,t),Object.defineProperty(e.prototype,"edgeNormals",{get:function(){return this._areEdgeNormalsDirty&&this.buildEdgeNormals(),this._edgeNormals},enumerable:!0,configurable:!0}),e.prototype.buildEdgeNormals=function(){var t,e=this.isBox?2:this.points.length;null!=this._edgeNormals&&this._edgeNormals.length==e||(this._edgeNormals=new Array(e));for(var i=0;i=this.points.length?this.points[0]:this.points[i+1];var o=Vector2Ext.perpendicular(n,t);o=Vector2.normalize(o),this._edgeNormals[i]=o}},e.prototype.setPoints=function(t){this.points=t,this.recalculateCenterAndEdgeNormals(),this._originalPoints=[];for(var e=0;et.y!=this.points[n].y>t.y&&t.x<(this.points[n].x-this.points[i].x)*(t.y-this.points[i].y)/(this.points[n].y-this.points[i].y)+this.points[i].x&&(e=!e);return e},e.buildSymmertricalPolygon=function(t,e){for(var i=new Array(t),n=0;n0&&(o=!1),!o)return null;(y=Math.abs(y))n&&(n=o);return{min:i,max:n}},t.circleToPolygon=function(t,e){var i=new CollisionResult,n=Vector2.subtract(t.position,e.position),o=Polygon.getClosestPointOnPolygonToPoint(e.points,n),r=o.closestPoint,s=o.distanceSquared;i.normal=o.edgeNormal;var a,h=e.containsPoint(t.position);if(s>t.radius*t.radius&&!h)return null;if(h)a=Vector2.multiply(i.normal,new Vector2(Math.sqrt(s)-t.radius));else if(0==s)a=Vector2.multiply(i.normal,new Vector2(t.radius));else{var u=Math.sqrt(s);a=Vector2.multiply(new Vector2(-Vector2.subtract(n,r)),new Vector2((t.radius-s)/u))}return i.minimumTranslationVector=a,i.point=Vector2.add(r,e.position),i},t.circleToBox=function(t,e){var i=new CollisionResult,n=e.bounds.getClosestPointOnRectangleBorderToPoint(t.position).res;if(e.containsPoint(t.position)){i.point=n;var o=Vector2.add(n,Vector2.subtract(i.normal,new Vector2(t.radius)));return i.minimumTranslationVector=Vector2.subtract(t.position,o),i}var r=Vector2.distanceSquared(n,t.position);if(0==r)i.minimumTranslationVector=Vector2.multiply(i.normal,new Vector2(t.radius));else if(r<=t.radius*t.radius){i.normal=Vector2.subtract(t.position,n);var s=i.normal.length()-t.radius;return i.normal=Vector2Ext.normalize(i.normal),i.minimumTranslationVector=Vector2.multiply(new Vector2(s),i.normal),i}return null},t.pointToCircle=function(t,e){var i=new CollisionResult,n=Vector2.distanceSquared(t,e.position),o=1+e.radius;if(n=0?t:4294967296+t},t.prototype.add=function(t,e,i){this._store.set(this.getKey(t,e),i)},t.prototype.remove=function(t){this._store.forEach(function(e){e.contains(t)&&e.remove(t)})},t.prototype.tryGetValue=function(t,e){return this._store.get(this.getKey(t,e))},t.prototype.getAllObjects=function(){var t=[];return this._store.forEach(function(e){return t.concat(e)}),t},t.prototype.clear=function(){this._store.clear()},t}(),Emitter=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,e){var i=this._messageTable.get(t);i||(i=[],this._messageTable.set(t,i)),i.contains(e)&&console.warn("您试图添加相同的观察者两次"),i.push(e)},t.prototype.removeObserver=function(t,e){this._messageTable.get(t).remove(e)},t.prototype.emit=function(t,e){var i=this._messageTable.get(t);if(i)for(var n=i.length-1;n>=0;n--)i[n](e)},t}(),ListPool=function(){function t(){}return t.warmCache=function(t){if((t-=this._objectQueue.length)>0)for(var e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}(),Pair=function(){function t(t,e){this.first=t,this.second=e}return t.prototype.clear=function(){this.first=this.second=null},t.prototype.equals=function(t){return this.first==t.first&&this.second==t.second},t}(),RectangleExt=function(){function t(){}return t.union=function(t,e){var i=new Rectangle(e.x,e.y,0,0);return this.unionR(t,i)},t.unionR=function(t,e){var i=new Rectangle;return i.x=Math.min(t.x,e.x),i.y=Math.min(t.y,e.y),i.width=Math.max(t.right,e.right)-i.x,i.height=Math.max(t.bottom,e.bottom)-i.y,i},t}(),Triangulator=function(){function t(){this.triangleIndices=[],this._triPrev=new Array(12),this._triNext=new Array(12)}return t.prototype.triangulate=function(e,i){void 0===i&&(i=!0);var n=e.length;this.initialize(n);for(var o=0,r=0;n>3&&o<500;){o++;var s=!0,a=e[this._triPrev[r]],h=e[r],u=e[this._triNext[r]];if(Vector2Ext.isTriangleCCW(a,h,u)){var c=this._triNext[this._triNext[r]];do{if(t.testPointTriangle(e[c],a,h,u)){s=!1;break}c=this._triNext[c]}while(c!=this._triPrev[r])}else s=!1;s?(this.triangleIndices.push(this._triPrev[r]),this.triangleIndices.push(r),this.triangleIndices.push(this._triNext[r]),this._triNext[this._triPrev[r]]=this._triNext[r],this._triPrev[this._triNext[r]]=this._triPrev[r],n--,r=this._triPrev[r]):r=this._triNext[r]}this.triangleIndices.push(this._triPrev[r]),this.triangleIndices.push(r),this.triangleIndices.push(this._triNext[r]),i||this.triangleIndices.reverse()},t.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.lengthMathHelper.Epsilon?t=Vector2.divide(t,new Vector2(e)):t.x=t.y=0,t},t.transformA=function(t,e,i,n,o,r){for(var s=0;s-1}(this,t)},Array.prototype.firstOrDefault=function(t){return function(t,e){var i=t.findIndex(e);return-1==i?null:t[i]}(this,t)},Array.prototype.find=function(t){return function(t,e){return t.firstOrDefault(e)}(this,t)},Array.prototype.where=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(i,n,o){return e.call(arguments[2],n,o,t)&&i.push(n),i},[]);for(var i=[],n=0,o=t.length;n=0&&t.splice(i,1)}while(i>=0)}(this,t)},Array.prototype.remove=function(t){return function(t,e){var i=t.findIndex(function(t){return t===e});return i>=0&&(t.splice(i,1),!0)}(this,t)},Array.prototype.removeAt=function(t){return function(t,e){t.splice(e,1)}(this,t)},Array.prototype.removeRange=function(t,e){return function(t,e,i){t.splice(e,i)}(this,t,e)},Array.prototype.select=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(i,n,o){return i.push(e.call(arguments[2],n,o,t)),i},[]);for(var i=[],n=0,o=t.length;nr?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,i){return t.sort(function(t,n){var o=e(t),r=e(n);return i?-i(o,r):o0;){if("break"===h())break}return o?this.recontructPath(r,e,i):null},t.hasKey=function(t,e){for(var i,n=t.keys();!(i=n.next()).done;)if(JSON.stringify(i.value)==JSON.stringify(e))return!0;return!1},t.getKey=function(t,e){for(var i,n,o=t.keys(),r=t.values();i=o.next(),n=r.next(),!i.done;)if(JSON.stringify(i.value)==JSON.stringify(e))return n.value;return null},t.recontructPath=function(t,e,i){var n=[],o=i;for(n.push(i);o!=e;)o=this.getKey(t,o),n.push(o);return n.reverse(),n},t}(),AStarNode=function(t){function e(e){var i=t.call(this)||this;return i.data=e,i}return __extends(e,t),e}(PriorityQueueNode),AstarGridGraph=function(){function t(t,e){this.dirs=[new Point(1,0),new Point(0,-1),new Point(-1,0),new Point(0,1)],this.walls=[],this.weightedNodes=[],this.defaultWeight=1,this.weightedNodeWeight=5,this._neighbors=new Array(4),this._width=t,this._height=e}return t.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0&&this.hasHigherPriority(t,i)?this.cascadeUp(t):this.cascadeDown(t)},t.prototype.cascadeDown=function(t){for(var e,i=t.queueIndex;;){e=t;var n=2*i;if(n>this._numNodes){t.queueIndex=i,this._nodes[i]=t;break}var o=this._nodes[n];this.hasHigherPriority(o,e)&&(e=o);var r=n+1;if(r<=this._numNodes){var s=this._nodes[r];this.hasHigherPriority(s,e)&&(e=s)}if(e==t){t.queueIndex=i,this._nodes[i]=t;break}this._nodes[i]=e;var a=e.queueIndex;e.queueIndex=i,i=a}},t.prototype.cascadeUp=function(t){for(var e=Math.floor(t.queueIndex/2);e>=1;){var i=this._nodes[e];if(this.hasHigherPriority(i,t))break;this.swap(t,i),e=Math.floor(t.queueIndex/2)}},t.prototype.swap=function(t,e){this._nodes[t.queueIndex]=e,this._nodes[e.queueIndex]=t;var i=t.queueIndex;t.queueIndex=e.queueIndex,e.queueIndex=i},t.prototype.hasHigherPriority=function(t,e){return t.priority0;){if("break"===a())break}return o?AStarPathfinder.recontructPath(s,e,i):null},t.hasKey=function(t,e){for(var i,n=t.keys();!(i=n.next()).done;)if(JSON.stringify(i.value)==JSON.stringify(e))return!0;return!1},t}(),UnweightedGraph=function(){function t(){this.edges=new Map}return t.prototype.addEdgesForNode=function(t,e){return this.edges.set(t,e),this},t.prototype.getNeighbors=function(t){return this.edges.get(t)},t}(),Point=function(){return function(t,e){this.x=t||0,this.y=e||this.x}}(),UnweightedGridGraph=function(){function t(e,i,n){void 0===n&&(n=!1),this.walls=[],this._neighbors=new Array(4),this._width=e,this._hegiht=i,this._dirs=n?t.COMPASS_DIRS:t.CARDINAL_DIRS}return t.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0;){if("break"===h())break}return o?this.recontructPath(r,e,i):null},t.hasKey=function(t,e){for(var i,n=t.keys();!(i=n.next()).done;)if(JSON.stringify(i.value)==JSON.stringify(e))return!0;return!1},t.getKey=function(t,e){for(var i,n,o=t.keys(),r=t.values();i=o.next(),n=r.next(),!i.done;)if(JSON.stringify(i.value)==JSON.stringify(e))return n.value;return null},t.recontructPath=function(t,e,i){var n=[],o=i;for(n.push(i);o!=e;)o=this.getKey(t,o),n.push(o);return n.reverse(),n},t}(),DebugDefaults=function(){function t(){}return t.verletParticle=14431326,t.verletConstraintEdge=4406838,t}(),Component=function(){function t(){this._enabled=!0,this.updateInterval=1}return Object.defineProperty(t.prototype,"transform",{get:function(){return this.entity.transform},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"enabled",{get:function(){return this.entity?this.entity.enabled&&this._enabled:this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},t.prototype.initialize=function(){},t.prototype.onAddedToEntity=function(){},t.prototype.onRemovedFromEntity=function(){},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.onEntityTransformChanged=function(t){},t.prototype.update=function(){},t.prototype.debugRender=function(){},t.prototype.registerComponent=function(){this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this),!1),this.entity.scene.entityProcessors.onComponentAdded(this.entity)},t.prototype.deregisterComponent=function(){this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this)),this.entity.scene.entityProcessors.onComponentRemoved(this.entity)},t}(),Entity=function(){function t(e){this._updateOrder=0,this._enabled=!0,this._tag=0,this.name=e,this.transform=new Transform(this),this.components=new ComponentList(this),this.id=t._idGenerator++,this.componentBits=new BitSet}return Object.defineProperty(t.prototype,"parent",{get:function(){return this.transform.parent},set:function(t){this.transform.setParent(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"position",{get:function(){return this.transform.position},set:function(t){this.transform.setPosition(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"localPosition",{get:function(){return this.transform.localPosition},set:function(t){this.transform.setLocalPosition(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotation",{get:function(){return this.transform.rotation},set:function(t){this.transform.setRotation(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotationDegrees",{get:function(){return this.transform.rotationDegrees},set:function(t){this.transform.setRotationDegrees(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"localRotation",{get:function(){return this.transform.localRotation},set:function(t){this.transform.setLocalRotation(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"localRotationDegrees",{get:function(){return this.transform.localRotationDegrees},set:function(t){this.transform.setLocalRotationDegrees(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"scale",{get:function(){return this.transform.scale},set:function(t){this.transform.setScale(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"localScale",{get:function(){return this.transform.scale},set:function(t){this.transform.setScale(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"worldInverseTransform",{get:function(){return this.transform.worldInverseTransform},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"localToWorldTransform",{get:function(){return this.transform.localToWorldTransform},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"worldToLocalTransform",{get:function(){return this.transform.worldToLocalTransform},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isDestoryed",{get:function(){return this._isDestoryed},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t),this},Object.defineProperty(t.prototype,"tag",{get:function(){return this._tag},set:function(t){this.setTag(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),t.prototype.setUpdateOrder=function(t){if(this._updateOrder!=t)return this._updateOrder=t,this.scene,this},t.prototype.setTag=function(t){return this._tag!=t&&(this.scene&&this.scene.entities.removeFromTagList(this),this._tag=t,this.scene&&this.scene.entities.addToTagList(this)),this},t.prototype.attachToScene=function(t){this.scene=t,t.entities.add(this),this.components.registerAllComponents();for(var e=0;e=0;t--){this.transform.getChild(t).entity.destory()}},t}(),Scene=function(t){function e(e){var i=t.call(this)||this;return e.stage.addChild(i),i._projectionMatrix=new Matrix2D(0,0,0,0,0,0),i.entityProcessors=new EntityProcessorList,i.entities=new EntityList(i),i.addEventListener(egret.Event.ACTIVATE,i.onActive,i),i.addEventListener(egret.Event.DEACTIVATE,i.onDeactive,i),i.addEventListener(egret.Event.ENTER_FRAME,i.update,i),i}return __extends(e,t),e.prototype.createEntity=function(t){var e=new Entity(t);return e.transform.position=new Vector2(0,0),this.addEntity(e)},e.prototype.addEntity=function(t){this.entities.add(t),t.scene=this;for(var e=0;et&&(this._zoom=t),this._maximumZoom=t,this},e.prototype.setZoom=function(t){var e=MathHelper.clamp(t,-1,1);return this._zoom=0==e?1:e<0?MathHelper.map(e,-1,0,this._minimumZoom,1):MathHelper.map(e,0,1,1,this._maximumZoom),this._areMatrixesDirty=!0,this},e.prototype.initialize=function(){},e.prototype.update=function(){},e.prototype.setPosition=function(t){return this.entity.transform.setPosition(t),this},e.prototype.updateMatrixes=function(){var t;this._areMatrixesDirty&&(this._transformMatrix=Matrix2D.createTranslation(-this.entity.transform.position.x,-this.entity.transform.position.y),1!=this._zoom&&(t=Matrix2D.createScale(this._zoom,this._zoom),this._transformMatrix=Matrix2D.multiply(this._transformMatrix,t)),t=Matrix2D.createTranslation(this._origin.x,this._origin.y,t),this._transformMatrix=Matrix2D.multiply(this._transformMatrix,t),this._inverseTransformMatrix=Matrix2D.invert(this._transformMatrix),this._areBoundsDirty=!0,this._areMatrixesDirty=!1)},e.prototype.screenToWorldPoint=function(t){return this.updateMatrixes(),Vector2.transform(t,this._inverseTransformMatrix)},e.prototype.worldToScreenPoint=function(t){return this.updateMatrixes(),Vector2.transform(t,this._transformMatrix)},e.prototype.destory=function(){},e}(Component),CameraInset=function(){return function(){}}(),Mesh=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.initialize=function(){},e.prototype.setVertPosition=function(t){(!this._verts||this._verts.length!=t.length)&&(this._verts=new Array(t.length));for(var e=0;e>6;0!=(e&t.LONG_MASK)&&i++,this._bits=new Array(i)}return t.prototype.and=function(t){for(var e,i=Math.min(this._bits.length,t._bits.length),n=0;n=0;)this._bits[e]&=~t._bits[e]},t.prototype.cardinality=function(){for(var t=0,e=this._bits.length-1;e>=0;e--){var i=this._bits[e];if(0!=i)if(-1!=i){var n=((i=((i=(i>>1&0x5555555555555400)+(0x5555555555555400&i))>>2&0x3333333333333400)+(0x3333333333333400&i))>>32)+i;t+=((n=((n=(n>>4&252645135)+(252645135&n))>>8&16711935)+(16711935&n))>>16&65535)+(65535&n)}else t+=64}return t},t.prototype.clear=function(t){if(null!=t){var e=t>>6;this.ensure(e),this._bits[e]&=~(1<=this._bits.length){var e=new Number[t+1];e=this._bits.copyWithin(0,0,this._bits.length),this._bits=e}},t.prototype.get=function(t){var e=t>>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,i=1<>6;this.ensure(i),this._bits[i]|=1<0){for(var t=0;t0){t=0;for(var e=this._componentsToAdd.length;t0){var e=this._entitiesToRemove;this._entitiesToRemove=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.remove(e),e.scene=null,t.scene.entityProcessors.onEntityRemoved(e)}),this._tempEntityList.length=0}if(this._entitiesToAdded.length>0){e=this._entitiesToAdded;this._entitiesToAdded=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.push(e),e.scene=t.scene,t.scene.entityProcessors.onEntityAdded(e)}),this._tempEntityList.forEach(function(t){return t.onAddedToScene()}),this._tempEntityList.length=0}this._unsortedTags.length>0&&(this._unsortedTags.forEach(function(e){t._entityDict.get(e).sort()}),this._unsortedTags.length=0)},t}(),EntityProcessorList=function(){function t(){this._processors=[]}return t.prototype.add=function(t){this._processors.push(t)},t.prototype.remove=function(t){this._processors.remove(t)},t.prototype.onComponentAdded=function(t){this.notifyEntityChanged(t)},t.prototype.onComponentRemoved=function(t){this.notifyEntityChanged(t)},t.prototype.onEntityAdded=function(t){this.notifyEntityChanged(t)},t.prototype.onEntityRemoved=function(t){this.removeFromProcessors(t)},t.prototype.notifyEntityChanged=function(t){for(var e=0;e=0;e=this.allSet.nextSetBit(e+1))if(!t.componentBits.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t.componentBits))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t.componentBits))},t}(),Time=function(){function t(){}return t.update=function(t){var e=(t-this._lastTime)/1e3;this.deltaTime=e*this.timeScale,this.unscaledDeltaTime=e,this.frameCount++,this._lastTime=t},t.deltaTime=0,t.timeScale=1,t.frameCount=0,t._lastTime=0,t}(),Flags=function(){function t(){}return t.isFlagSet=function(t,e){return 0!=(t&e)},t.isUnshiftedFlagSet=function(t,e){return 0!=(t&(e=1<i?i:t},t.minOf=function(t,e,i,n){return Math.min(t,Math.min(e,Math.min(i,n)))},t.maxOf=function(t,e,i,n){return Math.max(t,Math.max(e,Math.max(i,n)))},t.pointOnCirlce=function(e,i,n){var o=t.toRadians(n);return new Vector2(Math.cos(o)*o+e.x,Math.sin(o)*o+e.y)},t.Epsilon=1e-5,t.Rad2Deg=57.29578,t.Deg2Rad=.0174532924,t}(),Matrix2D=function(){function t(t,e,i,n,o,r){this.m11=0,this.m12=0,this.m21=0,this.m22=0,this.m31=0,this.m32=0,this.m11=t,this.m12=e,this.m21=i,this.m22=n,this.m31=o,this.m32=r}return Object.defineProperty(t,"identity",{get:function(){return t._identity},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"translation",{get:function(){return new Vector2(this.m31,this.m32)},set:function(t){this.m31=t.x,this.m32=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotation",{get:function(){return Math.atan2(this.m21,this.m11)},set:function(t){var e=Math.cos(t),i=Math.sin(t);this.m11=e,this.m12=i,this.m21=-i,this.m22=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotationDegrees",{get:function(){return MathHelper.toDegrees(this.rotation)},set:function(t){this.rotation=MathHelper.toRadians(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"scale",{get:function(){return new Vector2(this.m11,this.m22)},set:function(t){this.m11=t.x,this.m12=t.y},enumerable:!0,configurable:!0}),t.add=function(t,e){return t.m11+=e.m11,t.m12+=e.m12,t.m21+=e.m21,t.m22+=e.m22,t.m31+=e.m31,t.m32+=e.m32,t},t.divide=function(t,e){return t.m11/=e.m11,t.m12/=e.m12,t.m21/=e.m21,t.m22/=e.m22,t.m31/=e.m31,t.m32/=e.m32,t},t.multiply=function(t,e){var i=t.m11*e.m11+t.m12*e.m21,n=t.m11*e.m12+t.m12*e.m22,o=t.m21*e.m11+t.m22*e.m21,r=t.m21*e.m12+t.m22*e.m22,s=t.m31*e.m11+t.m32*e.m21+e.m31,a=t.m31*e.m12+t.m32*e.m22+e.m32;return t.m11=i,t.m12=n,t.m21=o,t.m22=r,t.m31=s,t.m32=a,t},t.multiplyTranslation=function(e,i,n){var o=t.createTranslation(i,n);return t.multiply(e,o)},t.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},t.invert=function(e,i){void 0===i&&(i=t.identity);var n=1/e.determinant();return i.m11=e.m22*n,i.m12=-e.m12*n,i.m21=-e.m21*n,i.m22=e.m11*n,i.m31=(e.m32*e.m21-e.m31*e.m22)*n,i.m32=-(e.m32*e.m11-e.m31*e.m12)*n,i},t.createTranslation=function(e,i,n){return void 0===n&&(n=t.identity),n.m11=1,n.m12=0,n.m21=0,n.m22=1,n.m31=e,n.m32=i,n},t.createRotation=function(e,i){i=t.identity;var n=Math.cos(e),o=Math.sin(e);return i.m11=n,i.m12=o,i.m21=-o,i.m22=n,i},t.createScale=function(e,i,n){return void 0===n&&(n=t.identity),n.m11=e,n.m12=0,n.m21=0,n.m22=i,n.m31=0,n.m32=0,n},t._identity=new t(1,0,0,1,0,0),t}(),Rectangle=function(){function t(t,e,i,n){this.x=t||0,this.y=e||0,this.width=i||0,this.height=n||0}return Object.defineProperty(t.prototype,"left",{get:function(){return this.x},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"right",{get:function(){return this.x+this.width},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"top",{get:function(){return this.y},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"bottom",{get:function(){return this.y+this.height},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"center",{get:function(){return new Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"location",{get:function(){return new Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),t.prototype.intersects=function(t){return t.leftn&&(n=s.x),s.yo&&(o=s.y)}return this.fromMinMax(e,i,n,o)},t}(),Vector2=function(){function t(t,e){this.x=0,this.y=0,this.x=t||0,this.y=e||this.x}return Object.defineProperty(t,"zero",{get:function(){return t.zeroVector2},enumerable:!0,configurable:!0}),Object.defineProperty(t,"one",{get:function(){return t.unitVector2},enumerable:!0,configurable:!0}),Object.defineProperty(t,"unitX",{get:function(){return t.unitXVector},enumerable:!0,configurable:!0}),Object.defineProperty(t,"unitY",{get:function(){return t.unitYVector},enumerable:!0,configurable:!0}),t.add=function(e,i){var n=new t(0,0);return n.x=e.x+i.x,n.y=e.y+i.y,n},t.divide=function(e,i){var n=new t(0,0);return n.x=e.x/i.x,n.y=e.y/i.y,e},t.multiply=function(e,i){var n=new t(0,0);return n.x=e.x*i.x,n.y=e.y*i.y,n},t.subtract=function(e,i){var n=new t(0,0);return n.x=e.x-i.x,n.y=e.y-i.y,e},t.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},t.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},t.normalize=function(t){var e=1/Math.sqrt(t.x*t.x+t.y*t.y);return t.x*=e,t.y*=e,t},t.dot=function(t,e){return t.x*e.x+t.y*e.y},t.distanceSquared=function(t,e){var i=t.x-e.x,n=t.y-e.y;return i*i+n*n},t.lerp=function(e,i,n){return new t(MathHelper.lerp(e.x,i.x,n),MathHelper.lerp(e.y,i.y,n))},t.transform=function(e,i){return new t(e.x*i.m11+e.y*i.m21,e.x*i.m12+e.y*i.m22)},t.distance=function(t,e){var i=t.x-e.x,n=t.y-e.y;return Math.sqrt(i*i+n*n)},t.negate=function(e){var i=new t;return i.x=-e.x,i.y=-e.y,i},t.unitYVector=new t(0,1),t.unitXVector=new t(1,0),t.unitVector2=new t(1,1),t.zeroVector2=new t(0,0),t}(),ColliderTriggerHelper=function(){function t(t){this._activeTriggerIntersections=[],this._previousTriggerIntersections=[],this._tempTriggerList=[],this._entity=t}return t.prototype.update=function(){for(var t=this._entity.getComponents(Collider),e=0;e1)return!1;var c=(a.x*o.y-a.y*o.x)/s;return!(c<0||c>1)},t.lineToLineIntersection=function(t,e,i,n){var o=new Vector2(0,0),r=Vector2.subtract(e,t),s=Vector2.subtract(n,i),a=r.x*s.y-r.y*s.x;if(0==a)return o;var h=Vector2.subtract(i,t),c=(h.x*s.y-h.y*s.x)/a;if(c<0||c>1)return o;var u=(h.x*r.y-h.y*r.x)/a;return u<0||u>1?o:o=Vector2.add(t,new Vector2(c*r.x,c*r.y))},t.closestPointOnLine=function(t,e,i){var n=Vector2.subtract(e,t),o=Vector2.subtract(i,t),r=Vector2.dot(o,n)/Vector2.dot(n,n);return r=MathHelper.clamp(r,0,1),Vector2.add(t,new Vector2(n.x*r,n.y*r))},t.isCircleToCircle=function(t,e,i,n){return Vector2.distanceSquared(t,i)<(e+n)*(e+n)},t.isCircleToLine=function(t,e,i,n){return Vector2.distanceSquared(t,this.closestPointOnLine(i,n,t))=t&&o.y>=e&&o.x=t+i&&(r|=PointSectors.right),o.y=e+n&&(r|=PointSectors.bottom),r},t}(),Physics=function(){function t(){}return t.reset=function(){this._spatialHash=new SpatialHash(this.spatialHashCellSize)},t.overlapCircleAll=function(t,e,i,n){return void 0===n&&(n=-1),this._spatialHash.overlapCircle(t,e,i,n)},t.boxcastBroadphase=function(t,e){return void 0===e&&(e=this.allLayers),this._spatialHash.aabbBroadphase(t,null,e)},t.boxcastBroadphaseExcludingSelf=function(t,e,i){return void 0===i&&(i=this.allLayers),this._spatialHash.aabbBroadphase(e,t,i)},t.addCollider=function(e){t._spatialHash.register(e)},t.removeCollider=function(e){t._spatialHash.remove(e)},t.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},t.spatialHashCellSize=100,t.allLayers=-1,t}(),Shape=function(){return function(){}}(),Polygon=function(t){function e(e,i){var n=t.call(this)||this;return n.isUnrotated=!0,n._areEdgeNormalsDirty=!0,n.setPoints(e),n.isBox=i,n}return __extends(e,t),Object.defineProperty(e.prototype,"edgeNormals",{get:function(){return this._areEdgeNormalsDirty&&this.buildEdgeNormals(),this._edgeNormals},enumerable:!0,configurable:!0}),e.prototype.buildEdgeNormals=function(){var t,e=this.isBox?2:this.points.length;null!=this._edgeNormals&&this._edgeNormals.length==e||(this._edgeNormals=new Array(e));for(var i=0;i=this.points.length?this.points[0]:this.points[i+1];var o=Vector2Ext.perpendicular(n,t);o=Vector2.normalize(o),this._edgeNormals[i]=o}},e.prototype.setPoints=function(t){this.points=t,this.recalculateCenterAndEdgeNormals(),this._originalPoints=[];for(var e=0;et.y!=this.points[n].y>t.y&&t.x<(this.points[n].x-this.points[i].x)*(t.y-this.points[i].y)/(this.points[n].y-this.points[i].y)+this.points[i].x&&(e=!e);return e},e.buildSymmertricalPolygon=function(t,e){for(var i=new Array(t),n=0;n0&&(o=!1),!o)return null;(y=Math.abs(y))n&&(n=o);return{min:i,max:n}},t.circleToPolygon=function(t,e){var i=new CollisionResult,n=Vector2.subtract(t.position,e.position),o=Polygon.getClosestPointOnPolygonToPoint(e.points,n),r=o.closestPoint,s=o.distanceSquared;i.normal=o.edgeNormal;var a,h=e.containsPoint(t.position);if(s>t.radius*t.radius&&!h)return null;if(h)a=Vector2.multiply(i.normal,new Vector2(Math.sqrt(s)-t.radius));else if(0==s)a=Vector2.multiply(i.normal,new Vector2(t.radius));else{var c=Math.sqrt(s);a=Vector2.multiply(new Vector2(-Vector2.subtract(n,r)),new Vector2((t.radius-s)/c))}return i.minimumTranslationVector=a,i.point=Vector2.add(r,e.position),i},t.circleToBox=function(t,e){var i=new CollisionResult,n=e.bounds.getClosestPointOnRectangleBorderToPoint(t.position).res;if(e.containsPoint(t.position)){i.point=n;var o=Vector2.add(n,Vector2.subtract(i.normal,new Vector2(t.radius)));return i.minimumTranslationVector=Vector2.subtract(t.position,o),i}var r=Vector2.distanceSquared(n,t.position);if(0==r)i.minimumTranslationVector=Vector2.multiply(i.normal,new Vector2(t.radius));else if(r<=t.radius*t.radius){i.normal=Vector2.subtract(t.position,n);var s=i.normal.length()-t.radius;return i.normal=Vector2Ext.normalize(i.normal),i.minimumTranslationVector=Vector2.multiply(new Vector2(s),i.normal),i}return null},t.pointToCircle=function(t,e){var i=new CollisionResult,n=Vector2.distanceSquared(t,e.position),o=1+e.radius;if(n=0?t:4294967296+t},t.prototype.add=function(t,e,i){this._store.set(this.getKey(t,e),i)},t.prototype.remove=function(t){this._store.forEach(function(e){e.contains(t)&&e.remove(t)})},t.prototype.tryGetValue=function(t,e){return this._store.get(this.getKey(t,e))},t.prototype.getAllObjects=function(){var t=[];return this._store.forEach(function(e){return t.concat(e)}),t},t.prototype.clear=function(){this._store.clear()},t}(),Emitter=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,e){var i=this._messageTable.get(t);i||(i=[],this._messageTable.set(t,i)),i.contains(e)&&console.warn("您试图添加相同的观察者两次"),i.push(e)},t.prototype.removeObserver=function(t,e){this._messageTable.get(t).remove(e)},t.prototype.emit=function(t,e){var i=this._messageTable.get(t);if(i)for(var n=i.length-1;n>=0;n--)i[n](e)},t}(),ListPool=function(){function t(){}return t.warmCache=function(t){if((t-=this._objectQueue.length)>0)for(var e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}(),Pair=function(){function t(t,e){this.first=t,this.second=e}return t.prototype.clear=function(){this.first=this.second=null},t.prototype.equals=function(t){return this.first==t.first&&this.second==t.second},t}(),RectangleExt=function(){function t(){}return t.union=function(t,e){var i=new Rectangle(e.x,e.y,0,0);return this.unionR(t,i)},t.unionR=function(t,e){var i=new Rectangle;return i.x=Math.min(t.x,e.x),i.y=Math.min(t.y,e.y),i.width=Math.max(t.right,e.right)-i.x,i.height=Math.max(t.bottom,e.bottom)-i.y,i},t}(),Triangulator=function(){function t(){this.triangleIndices=[],this._triPrev=new Array(12),this._triNext=new Array(12)}return t.prototype.triangulate=function(e,i){void 0===i&&(i=!0);var n=e.length;this.initialize(n);for(var o=0,r=0;n>3&&o<500;){o++;var s=!0,a=e[this._triPrev[r]],h=e[r],c=e[this._triNext[r]];if(Vector2Ext.isTriangleCCW(a,h,c)){var u=this._triNext[this._triNext[r]];do{if(t.testPointTriangle(e[u],a,h,c)){s=!1;break}u=this._triNext[u]}while(u!=this._triPrev[r])}else s=!1;s?(this.triangleIndices.push(this._triPrev[r]),this.triangleIndices.push(r),this.triangleIndices.push(this._triNext[r]),this._triNext[this._triPrev[r]]=this._triNext[r],this._triPrev[this._triNext[r]]=this._triPrev[r],n--,r=this._triPrev[r]):r=this._triNext[r]}this.triangleIndices.push(this._triPrev[r]),this.triangleIndices.push(r),this.triangleIndices.push(this._triNext[r]),i||this.triangleIndices.reverse()},t.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.lengthMathHelper.Epsilon?t=Vector2.divide(t,new Vector2(e)):t.x=t.y=0,t},t.transformA=function(t,e,i,n,o,r){for(var s=0;s>> (32 - numBits)), this.unsigned); - else - return Long.fromBits(0, this.low << (numBits - 32), this.unsigned); - } - - public static fromBits(lowBits, highBits, unsigned){ - return new Long(lowBits, highBits, unsigned); - } - - public static fromValue(val: number | string | {low: number, high: number, unsigned: boolean}, unsigned?): Long{ - if (typeof val === 'number') - return this.fromNumber(val, unsigned); - if (typeof val === 'string') - return this.fromString(val, unsigned); - - return this.fromBits(val.low, val.high, typeof unsigned === 'boolean' ? unsigned : val.unsigned); - } - - public static fromString(str: string, unsigned, radix?): Long{ - if (str.length === 0) - throw new Error("empty string"); - if (str === "NaN" || str === "Infinity" || str === "+Infinity" || str === "-Infinity") - return Long.zero; - if (typeof unsigned === "number"){ - radix = unsigned; - unsigned = false; - } else { - unsigned = !! unsigned; - } - radix = radix || 10; - if (radix < 2 || 36 < radix) - throw new Error("radix"); - - let p; - if ((p = str.indexOf('-')) > 0) - throw new Error('interior hyphen'); - else if(p === 0) - return this.fromString(str.substring(1), unsigned, radix).negate(); - - let radixToPower = this.fromNumber(Math.pow(radix, 8)); - let result = Long.zero; - for (let i = 0; i < str.length; i += 8){ - let size = Math.min(8, str.length - i), - value = parseInt(str.substring(i, i + size), radix); - - if(size < 8){ - let power = this.fromNumber(Math.pow(radix, size)); - result = result.multiply(power).add(this.fromNumber(value)); - } else { - result = result.multiply(radixToPower); - result = result.add(this.fromNumber(value)); - } - } - - result.unsigned = unsigned; - return result; - } - - public static fromNumber(value, unsigned?): Long{ - if (isNaN(value)) - return unsigned ? Long.uzero : Long.zero; - if (unsigned){ - if (value < 0) - return Long.uzero; - if (value >= Long.two_pwr_64_dbl) - return Long.max_unsigned_value; - }else { - if (value <= -Long.two_pwr_63_dbl) - return Long.min_value; - if (value + 1 >= Long.two_pwr_63_dbl) - return Long.max_value; - } - if (value < 0) - return this.fromNumber(-value, unsigned).negate(); - return Long.fromBits((value % Long.two_pwr_32_dbl) | 0, (value / Long.two_pwr_32_dbl) | 0, unsigned); - } - - public static fromInt(value, unsigned?): Long{ - let obj, cachedObj, cache; - if (unsigned){ - value >>>= 0; - if (cache = (0 <= value && value < 256)){ - cachedObj = this.unit_cache[value]; - if (cachedObj) - return cachedObj; - } - obj = this.fromBits(value, (value | 0) < 0 ? -1 : 0, true); - if (cache) - this.unit_cache[value] = obj; - return obj; - } else { - value |= 0; - if (cache = (-128 <= value && value < 128)){ - cachedObj = Long.ini_cache[value]; - if (cachedObj) - return cachedObj; - } - obj = this.fromBits(value, value < 0 ? -1 : 0, false); - if (cache) - Long.ini_cache[value] = obj; - return obj; - } - } -} - -Long.prototype.toInt = function(){ - let i = this as Long; - return i.unsigned ? i.low >>> 0 : i.low; -} - -Long.prototype.negate = function(){ - let i = this as Long; - if (!i.unsigned && !i.equals(Long.min_value)) - return Long.min_value; - return i.not().add(Long.one); -} - -Long.prototype.add = function(addend: number | Long){ - let i = this as Long; - if (typeof addend === "number"){ - addend = Long.fromValue(addend); - } - - let a48 = i.high >>> 16; - let a32 = i.high & 0xFFFF; - let a16 = i.low >>> 16; - let a00 = i.low & 0xFFFF; - - let b48 = addend.high >>> 16; - let b32 = addend.high & 0xFFFF; - let b16 = addend.low >>> 16; - let b00 = addend.low & 0xFFFF; - - let c48 = 0, c32 = 0, c16 = 0, c00 = 0; - c00 += a00 + b00; - c16 += c00 >>> 16; - c00 &= 0xFFFF; - c16 += a16 + b16; - c32 += c16 >>> 16; - c16 &= 0xFFFF; - c32 += a32 + b32; - c48 += c32 >>> 16; - c32 &= 0xFFFF; - c48 += a48 + b48; - c48 &= 0xFFFF; - return Long.fromBits((c16 << 16) | c00, (c48 << 16) | 32, i.unsigned); -} - -Long.prototype.equals = function(other: number | Long){ - let i = this as Long; - if (typeof other === "number") - other = Long.fromValue(other); - if (i.unsigned !== other.unsigned && (i.high >>> 31) === 1 && (other.high >>> 31) === 1) - return false; - return i.high === other.high && i.low === other.low; -} - -Long.prototype.not = function(){ - let i = this as Long; - return Long.fromBits(~i.low, ~i.high, i.unsigned); -} - -Long.prototype.toString = function(radix?){ - let i = this as Long; - radix = radix || 10; - if (radix < 2 || 36 < radix) - throw new Error("radix"); - if (i.isZero()) - return "0"; - if (i.isNegative()){ - if (i.equals(Long.min_value)){ - let radixLong = Long.fromNumber(radix), - div = i.divide(radixLong), - rem1 = div.multiply(radixLong).subtract(i); - return div.toString(radix) + rem1.toInt().toString(radix); - } else{ - return "-" + i.negate().toString(radix); - } - } - - let radixToPower = Long.fromNumber(Math.pow(radix, 6), i.unsigned), - rem = i; - let result = ''; - while (true) { - let remDiv = rem.divide(radixToPower), - intval = rem.subtract(remDiv.multiply(radixToPower)).toInt() >>> 0, - digits = intval.toString(radix); - rem = remDiv; - if (rem.isZero()) - return digits + result; - else { - while (digits.length < 6) - digits = '0' + digits; - result = '' + digits + result; - } - } -} - -Long.prototype.isZero = function(){ - let i = this as Long; - return i.high === 0 && i.low === 0; -} - -Long.prototype.isNegative = function(){ - let i = this as Long; - return !i.unsigned && i.high < 0; -} - -Long.prototype.divide = function(divisor: number | Long){ - let i = this as Long; - if (typeof divisor === 'number') - divisor = Long.fromValue(divisor); - if (divisor.isZero()) - throw new Error("division by zero"); - - if (i.isZero()) - return i.unsigned ? Long.uzero : Long.zero; - let approx: number | Long, rem: Long, res; - if (!i.unsigned) { - if (i.equals(Long.min_value)) { - if (divisor.equals(Long.one) || divisor.equals(Long.neg_one)) - return Long.min_value; - else if (divisor.equals(Long.min_value)) - return Long.one; - else { - let halfThis = i.shiftRight(1); - approx = halfThis.divide(divisor).shiftLeft(1); - if (approx.equals(Long.zero)) { - return divisor.isNegative() ? Long.one : Long.neg_one; - } else { - rem = i.subtract(divisor.multiply(approx)); - res = approx.add(rem.divide(divisor)); - return res; - } - } - } else if (divisor.equals(Long.min_value)) - return i.unsigned ? Long.uzero : Long.zero; - if (i.isNegative()) { - if (divisor.isNegative()) - return i.negate().divide(divisor.negate()); - return i.negate().divide(divisor).negate(); - } else if (divisor.isNegative()) - return i.divide(divisor.negate()).negate(); - res = Long.zero; - } else { - if (!divisor.unsigned) - divisor = divisor.toUnsigned(); - if (divisor.greaterThan(i)) - return Long.uzero; - if (divisor.greaterThan(i.shiftRightUnsigned(1))) - return Long.uzero; - res = Long.uzero; - } - - rem = i; - while (rem.greaterThanOrEqual(divisor)) { - approx = Math.max(1, Math.floor(rem.toNumber() / divisor.toNumber())); - - let log2 = Math.ceil(Math.log(approx) / Math.LN2), - delta = (log2 <= 48) ? 1 : Math.pow(2, log2 - 48), - approxRes = Long.fromNumber(approx), - approxRem = approxRes.multiply(divisor); - while (approxRem.isNegative() || approxRem.greaterThan(rem)) { - approx -= delta; - approxRes = Long.fromNumber(approx, i.unsigned); - approxRem = approxRes.multiply(divisor); - } - - if (approxRes.isZero()) - approxRes = Long.one; - - res = res.add(approxRes); - rem = rem.subtract(approxRem); - } - return res; -} - -Long.prototype.shiftRight = function(numBits: number | Long){ - let i = this as Long; - if (numBits instanceof Long){ - numBits = numBits.toInt(); - } - if ((numBits &= 63) === 0) - return i; - else if(numBits < 32) - return Long.fromBits((i.low >>> numBits) | (i.high << (32 - numBits)), i.high >> numBits, i.unsigned); - else - return Long.fromBits(i.high >> (numBits - 32), i.high >= 0 ? 0 : -1, i.unsigned); -} - -Long.prototype.shiftRightUnsigned = function(numBits: number | Long){ - let i = this as Long; - if (numBits instanceof Long) - numBits = numBits.toInt(); - if ((numBits &= 63) === 0) return i; - if (numBits < 32) return Long.fromBits((i.low >>> numBits) | (i.high << (32 - numBits)), i.high >>> numBits, i.unsigned); - if (numBits === 32) return Long.fromBits(i.high, 0, i.unsigned); - return Long.fromBits(i.high >>> (numBits - 32), 0, i.unsigned); -} - -Long.prototype.subtract = function(subtrahend: number | Long){ - let i = this as Long; - if (typeof subtrahend === "number") - subtrahend = Long.fromValue(subtrahend); - return i.add(subtrahend.negate()); -} - -Long.prototype.greaterThan = function(other){ - let i = this as Long; - return i.compare(other) > 0; -} - -Long.prototype.compare = function(other: number | Long){ - let i = this as Long; - if (typeof other === "number") - other = Long.fromValue(other); - if (i.equals(other)) - return 0; - let thisNeg = i.isNegative(), - otherNeg = other.isNegative(); - if (thisNeg && !otherNeg) - return -1; - if (!thisNeg && otherNeg) - return 1; - if (!i.unsigned) - return i.subtract(other).isNegative() ? -1 : 1; - return (other.high >>> 0) > (i.high >>> 0) || (other.high === i.high && (other.low >>> 0) > (i.low >>> 0)) ? -1 : 1; -} - -Long.prototype.toUnsigned = function(){ - let i = this as Long; - if (i.unsigned) - return i; - return Long.fromBits(i.low, i.high, true); -} - -Long.prototype.toNumber = function(){ - let i = this as Long; - if (i.unsigned) - return ((i.high >>> 0) * Long.two_pwr_32_dbl) + (i.low >>> 0); - return i.high * Long.two_pwr_32_dbl + (i.low >>> 0); -} - -Long.prototype.greaterThanOrEqual = function(other){ - let i = this as Long; - return i.compare(other) >= 0; -} - -Long.prototype.multiply = function(multiplier: number | Long){ - let i = this as Long; - if (i.isZero()) - return Long.zero; - if (typeof multiplier === "number") - multiplier = Long.fromValue(multiplier); - - if (multiplier.isZero()) - return Long.zero; - if (i.equals(Long.min_value)) - return multiplier.isOdd() ? Long.min_value : Long.zero; - if (multiplier.equals(Long.min_value)) - return i.isOdd() ? Long.min_value : Long.zero; - - if (i.isNegative()){ - if (multiplier.isNegative()) - return i.negate().multiply(multiplier.negate()); - else - return i.negate().multiply(multiplier).negate(); - } else if(multiplier.isNegative()) - return i.multiply(multiplier.negate()).negate(); - - if (i.lessThan(Long.two_pwr_24) && multiplier.lessThan(Long.two_pwr_24)) - return Long.fromNumber(i.toNumber() * multiplier.toNumber(), i.unsigned); - - let a48 = i.high >>> 16; - let a32 = i.high & 0xFFFF; - let a16 = i.low >>> 16; - let a00 = i.low & 0xFFFF; - - let b48 = multiplier.high >>> 16; - let b32 = multiplier.high & 0xFFFF; - let b16 = multiplier.low >>> 16; - let b00 = multiplier.low & 0xFFFF; - - let c48 = 0, c32 = 0, c16 = 0, c00 = 0; - c00 += a00 * b00; - c16 += c00 >>> 16; - c00 &= 0xFFFF; - c16 += a16 * b00; - c32 += c16 >>> 16; - c16 &= 0xFFFF; - c16 += a00 * b16; - c32 += c16 >>> 16; - c16 &= 0xFFFF; - c32 += a32 * b00; - c48 += c32 >>> 16; - c32 &= 0xFFFF; - c32 += a16 * b16; - c48 += c32 >>> 16; - c32 &= 0xFFFF; - c32 += a00 * b32; - c48 += c32 >>> 16; - c32 &= 0xFFFF; - c48 += a48 * b00 + a32 * b16 + a16 * b32 + a00 * b48; - c48 &= 0xFFFF; - return Long.fromBits((c16 << 16) | c00, (c48 << 16) | c32, i.unsigned); - -} - -Long.prototype.isOdd = function(){ - let i = this as Long; - return (i.low & 1) === 1; -} - -Long.prototype.lessThan = function(other: Long){ - let i = this as Long; - return i.compare(other) < 0; -} \ No newline at end of file diff --git a/source/src/Math/long.d.ts b/source/src/Math/long.d.ts new file mode 100644 index 00000000..b0f62b2c --- /dev/null +++ b/source/src/Math/long.d.ts @@ -0,0 +1,1092 @@ +export as namespace Long; + +// Type definitions for ./src/long.js +// Project: [LIBRARY_URL_HERE] +// Definitions by: [YOUR_NAME_HERE] <[YOUR_URL_HERE]> +// Definitions: https://github.com/borisyankov/DefinitelyTyped +declare namespace Long{ + // Long.fromBytes.!0 + type FromBytes0 = Array; +} +declare namespace Long{ + // Long.fromBytesLE.!0 + type FromBytesLE0 = Array; +} +declare namespace Long{ + // Long.fromBytesBE.!0 + type FromBytesBE0 = Array; +} +declare namespace LongPrototype{ + // LongPrototype.toBytes.!ret + type ToBytesRet = Array; +} +declare namespace LongPrototype{ + // LongPrototype.toBytesLE.!ret + type ToBytesLERet = Array; +} +declare namespace LongPrototype{ + // LongPrototype.toBytesBE.!ret + type ToBytesBERet = Array; +} + +/** + * Constructs a 64 bit two's-complement integer, given its low and high 32 bit values as *signed* integers. + * See the from* functions below for more convenient ways of constructing Longs. + * @exports Long + * @class A Long class for representing a 64 bit two's-complement integer value. + * @param {number} low The low (signed) 32 bits of the long + * @param {number} high The high (signed) 32 bits of the long + * @param {boolean=} unsigned Whether unsigned or not, defaults to signed + * @constructor + */ +declare interface Long { + + /** + * + * @param low + * @param high + * @param unsigned? + */ + new (low : number, high : number, unsigned? : boolean | number); + + /** + * + */ + __isLong__ : boolean; + + /** + * + */ + eqz : /* LongPrototype.isZero */ any; + + /** + * + */ + eq : /* LongPrototype.equals */ any; + + /** + * + */ + neq : /* LongPrototype.notEquals */ any; + + /** + * + */ + ne : /* LongPrototype.notEquals */ any; + + /** + * + */ + lt : /* LongPrototype.lessThan */ any; + + /** + * + */ + lte : /* LongPrototype.lessThanOrEqual */ any; + + /** + * + */ + le : /* LongPrototype.lessThanOrEqual */ any; + + /** + * + */ + gt : /* LongPrototype.greaterThan */ any; + + /** + * + */ + gte : /* LongPrototype.greaterThanOrEqual */ any; + + /** + * + */ + ge : /* LongPrototype.greaterThanOrEqual */ any; + + /** + * + */ + comp : /* LongPrototype.compare */ any; + + /** + * + */ + neg : /* LongPrototype.negate */ any; + + /** + * + */ + sub : /* LongPrototype.subtract */ any; + + /** + * + */ + mul : /* LongPrototype.multiply */ any; + + /** + * + */ + div : /* LongPrototype.divide */ any; + + /** + * + */ + mod : /* LongPrototype.modulo */ any; + + /** + * + */ + rem : /* LongPrototype.modulo */ any; + + /** + * + */ + shl : /* LongPrototype.shiftLeft */ any; + + /** + * + */ + shr : /* LongPrototype.shiftRight */ any; + + /** + * + */ + shru : /* LongPrototype.shiftRightUnsigned */ any; + + /** + * + */ + shr_u : /* LongPrototype.shiftRightUnsigned */ any; + + /** + * + */ + rotl : /* LongPrototype.rotateLeft */ any; + + /** + * + */ + rotr : /* LongPrototype.rotateRight */ any; + + /** + * + */ + toInt : /* LongPrototype.toInt */ any; + + /** + * + */ + toNumber : /* LongPrototype.toNumber */ any; + + /** + * + */ + getHighBits : /* LongPrototype.getHighBits */ any; + + /** + * + */ + getHighBitsUnsigned : /* LongPrototype.getHighBitsUnsigned */ any; + + /** + * + */ + getLowBits : /* LongPrototype.getLowBits */ any; + + /** + * + */ + getLowBitsUnsigned : /* LongPrototype.getLowBitsUnsigned */ any; + + /** + * + */ + getNumBitsAbs : /* LongPrototype.getNumBitsAbs */ any; + + /** + * + */ + isZero : /* LongPrototype.isZero */ any; + + /** + * + */ + isNegative : /* LongPrototype.isNegative */ any; + + /** + * + */ + isPositive : /* LongPrototype.isPositive */ any; + + /** + * + */ + isOdd : /* LongPrototype.isOdd */ any; + + /** + * + */ + isEven : /* LongPrototype.isEven */ any; + + /** + * + */ + equals : /* LongPrototype.equals */ any; + + /** + * + */ + notEquals : /* LongPrototype.notEquals */ any; + + /** + * + */ + lessThan : /* LongPrototype.lessThan */ any; + + /** + * + */ + lessThanOrEqual : /* LongPrototype.lessThanOrEqual */ any; + + /** + * + */ + greaterThan : /* LongPrototype.greaterThan */ any; + + /** + * + */ + greaterThanOrEqual : /* LongPrototype.greaterThanOrEqual */ any; + + /** + * + */ + compare : /* LongPrototype.compare */ any; + + /** + * + */ + negate : /* LongPrototype.negate */ any; + + /** + * + */ + add : /* LongPrototype.add */ any; + + /** + * + */ + subtract : /* LongPrototype.subtract */ any; + + /** + * + */ + multiply : /* LongPrototype.multiply */ any; + + /** + * + */ + divide : /* LongPrototype.divide */ any; + + /** + * + */ + modulo : /* LongPrototype.modulo */ any; + + /** + * + */ + not : /* LongPrototype.not */ any; + + /** + * + */ + and : /* LongPrototype.and */ any; + + /** + * + */ + or : /* LongPrototype.or */ any; + + /** + * + */ + xor : /* LongPrototype.xor */ any; + + /** + * + */ + shiftLeft : /* LongPrototype.shiftLeft */ any; + + /** + * + */ + shiftRight : /* LongPrototype.shiftRight */ any; + + /** + * + */ + shiftRightUnsigned : /* LongPrototype.shiftRightUnsigned */ any; + + /** + * + */ + rotateLeft : /* LongPrototype.rotateLeft */ any; + + /** + * + */ + rotateRight : /* LongPrototype.rotateRight */ any; + + /** + * + */ + toSigned : /* LongPrototype.toSigned */ any; + + /** + * + */ + toUnsigned : /* LongPrototype.toUnsigned */ any; + + /** + * + */ + toBytes : /* LongPrototype.toBytes */ any; + + /** + * + */ + toBytesLE : /* LongPrototype.toBytesLE */ any; + + /** + * + */ + toBytesBE : /* LongPrototype.toBytesBE */ any; + + /** + * Creates a Long from its byte representation. + * @param {!Array.} bytes Byte representation + * @param {boolean=} unsigned Whether unsigned or not, defaults to signed + * @param {boolean=} le Whether little or big endian, defaults to big endian + * @returns {Long} The corresponding Long value + * @param bytes + * @param unsigned? + * @param le? + * @return + */ + fromBytes(bytes : Long.FromBytes0, unsigned? : boolean, le? : boolean): Long; + + /** + * Creates a Long from its little endian byte representation. + * @param {!Array.} bytes Little endian byte representation + * @param {boolean=} unsigned Whether unsigned or not, defaults to signed + * @returns {Long} The corresponding Long value + * @param bytes + * @param unsigned? + * @return + */ + fromBytesLE(bytes : Long.FromBytesLE0, unsigned? : boolean): Long; + + /** + * Creates a Long from its big endian byte representation. + * @param {!Array.} bytes Big endian byte representation + * @param {boolean=} unsigned Whether unsigned or not, defaults to signed + * @returns {Long} The corresponding Long value + * @param bytes + * @param unsigned? + * @return + */ + fromBytesBE(bytes : Long.FromBytesBE0, unsigned? : boolean): Long; + + /** + * The low 32 bits as a signed value. + * @type {number} + */ + low : number; + + /** + * The high 32 bits as a signed value. + * @type {number} + */ + high : number; +} + +/** + * @function + * @param {*} obj Object + * @returns {boolean} + * @inner + * @param obj + * @return + */ +declare function isLong(obj : any): boolean; + +/** + * A cache of the Long representations of small integer values. + * @type {!Object} + * @inner + */ +declare var INT_CACHE : { +} + +/** + * A cache of the Long representations of small unsigned integer values. + * @type {!Object} + * @inner + */ +declare var UINT_CACHE : { +} + +/** + * @param {number} value + * @param {boolean=} unsigned + * @returns {!Long} + * @inner + * @param value + * @param unsigned? + * @return + */ +declare function fromInt(value : number, unsigned? : boolean): Long; + +/** + * @param {number} value + * @param {boolean=} unsigned + * @returns {!Long} + * @inner + * @param value + * @param unsigned? + * @return + */ +declare function fromNumber(value : any, unsigned? : boolean): Long; + +/** + * @param {number} lowBits + * @param {number} highBits + * @param {boolean=} unsigned + * @returns {!Long} + * @inner + * @param lowBits + * @param highBits + * @param unsigned? + * @return + */ +declare function fromBits(lowBits : number, highBits : number, unsigned? : boolean | number): Long; + +/** + * @function + * @param {number} base + * @param {number} exponent + * @returns {number} + * @inner + * @param undefined + * @param undefined + * @return + */ +declare function pow_dbl(param1 : number, param2 : number): number; + +/** + * @param {string} str + * @param {(boolean|number)=} unsigned + * @param {number=} radix + * @returns {!Long} + * @inner + * @param str + * @param unsigned? + * @param radix? + * @return + */ +declare function fromString(str : any, unsigned? : boolean | number, radix? : boolean | number): any; +/** + * @param {string} str + * @param {(boolean|number)=} unsigned + * @param {number=} radix + * @returns {!Long} + * @inner + */ +declare function fromString(); + +/** + * @function + * @param {!Long|number|string|!{low: number, high: number, unsigned: boolean}} val + * @param {boolean=} unsigned + * @returns {!Long} + * @inner + * @param val + * @param unsigned? + * @return + */ +declare function fromValue(val : any, unsigned? : boolean): Long; +/** + * @function + * @param {!Long|number|string|!{low: number, high: number, unsigned: boolean}} val + * @param {boolean=} unsigned + * @returns {!Long} + * @inner + */ +declare function fromValue(); + +/** + * @type {number} + * @const + * @inner + */ +export declare var TWO_PWR_16_DBL : number; + +/** + * @type {number} + * @const + * @inner + */ +export declare var TWO_PWR_24_DBL : number; + +/** + * @type {number} + * @const + * @inner + */ +export declare var TWO_PWR_32_DBL : number; + +/** + * @type {number} + * @const + * @inner + */ +export declare var TWO_PWR_64_DBL : number; + +/** + * @type {number} + * @const + * @inner + */ +export declare var TWO_PWR_63_DBL : number; + +/** + * @type {!Long} + * @const + * @inner + */ +export declare var TWO_PWR_24 : Long; + +/** + * @alias Long.prototype + * @inner + */ +declare namespace LongPrototype{ + + /** + * + */ + export var __isLong__ : boolean; + + /** + * Converts the Long to a 32 bit integer, assuming it is a 32 bit integer. + * @this {!Long} + * @returns {number} + * @return + */ + function toInt(): /* !this.low */ any; + + /** + * Converts the Long to a the nearest floating-point representation of this value (double, 53 bit mantissa). + * @this {!Long} + * @returns {number} + * @return + */ + function toNumber(): number; + + /** + * Gets the high 32 bits as a signed integer. + * @this {!Long} + * @returns {number} Signed high bits + * @return + */ + function getHighBits(): /* !this.high */ any; + + /** + * Gets the high 32 bits as an unsigned integer. + * @this {!Long} + * @returns {number} Unsigned high bits + * @return + */ + function getHighBitsUnsigned(): number; + + /** + * Gets the low 32 bits as a signed integer. + * @this {!Long} + * @returns {number} Signed low bits + * @return + */ + function getLowBits(): /* !this.low */ any; + + /** + * Gets the low 32 bits as an unsigned integer. + * @this {!Long} + * @returns {number} Unsigned low bits + * @return + */ + function getLowBitsUnsigned(): number; + + /** + * Gets the number of bits needed to represent the absolute value of this Long. + * @this {!Long} + * @returns {number} + * @return + */ + function getNumBitsAbs(): number; + + /** + * Tests if this Long's value equals zero. + * @this {!Long} + * @returns {boolean} + * @return + */ + function isZero(): boolean; + + /** + * Tests if this Long's value is negative. + * @this {!Long} + * @returns {boolean} + * @return + */ + function isNegative(): boolean; + + /** + * Tests if this Long's value is positive. + * @this {!Long} + * @returns {boolean} + * @return + */ + function isPositive(): /* !this.unsigned */ any; + + /** + * Tests if this Long's value is odd. + * @this {!Long} + * @returns {boolean} + * @return + */ + function isOdd(): boolean; + + /** + * Tests if this Long's value is even. + * @this {!Long} + * @returns {boolean} + * @return + */ + function isEven(): boolean; + + /** + * Tests if this Long's value equals the specified's. + * @this {!Long} + * @param {!Long|number|string} other Other value + * @returns {boolean} + * @param other + * @return + */ + function equals(other : any): boolean; + + /** + * Tests if this Long's value differs from the specified's. + * @this {!Long} + * @param {!Long|number|string} other Other value + * @returns {boolean} + * @param other + * @return + */ + function notEquals(other : any): boolean; + + /** + * Tests if this Long's value is less than the specified's. + * @this {!Long} + * @param {!Long|number|string} other Other value + * @returns {boolean} + * @param other + * @return + */ + function lessThan(other : any): boolean; + + /** + * Tests if this Long's value is less than or equal the specified's. + * @this {!Long} + * @param {!Long|number|string} other Other value + * @returns {boolean} + * @param other + * @return + */ + function lessThanOrEqual(other : any): boolean; + + /** + * Tests if this Long's value is greater than the specified's. + * @this {!Long} + * @param {!Long|number|string} other Other value + * @returns {boolean} + * @param other + * @return + */ + function greaterThan(other : any): boolean; + + /** + * Tests if this Long's value is greater than or equal the specified's. + * @this {!Long} + * @param {!Long|number|string} other Other value + * @returns {boolean} + * @param other + * @return + */ + function greaterThanOrEqual(other : any): boolean; + + /** + * Compares this Long's value with the specified's. + * @this {!Long} + * @param {!Long|number|string} other Other value + * @returns {number} 0 if they are the same, 1 if the this is greater and -1 + * if the given one is greater + * @param other + * @return + */ + function compare(other : any): number; + + /** + * Negates this Long's value. + * @this {!Long} + * @returns {!Long} Negated Long + * @return + */ + function negate(): Long; + + /** + * Returns the sum of this and the specified Long. + * @this {!Long} + * @param {!Long|number|string} addend Addend + * @returns {!Long} Sum + * @param addend + * @return + */ + function add(addend : any): Long; + + /** + * Returns the difference of this and the specified Long. + * @this {!Long} + * @param {!Long|number|string} subtrahend Subtrahend + * @returns {!Long} Difference + * @param subtrahend + * @return + */ + function subtract(subtrahend : any): Long; + + /** + * Returns the product of this and the specified Long. + * @this {!Long} + * @param {!Long|number|string} multiplier Multiplier + * @returns {!Long} Product + * @param multiplier + * @return + */ + function multiply(multiplier : any): Long; + + /** + * Returns this Long divided by the specified. The result is signed if this Long is signed or + * unsigned if this Long is unsigned. + * @this {!Long} + * @param {!Long|number|string} divisor Divisor + * @returns {!Long} Quotient + * @param divisor + * @return + */ + function divide(divisor : any): /* !this */ any; + + /** + * Returns this Long modulo the specified. + * @this {!Long} + * @param {!Long|number|string} divisor Divisor + * @returns {!Long} Remainder + * @param divisor + * @return + */ + function modulo(divisor : any): Long; + + /** + * Returns the bitwise NOT of this Long. + * @this {!Long} + * @returns {!Long} + * @return + */ + function not(): Long; + + /** + * Returns the bitwise AND of this Long and the specified. + * @this {!Long} + * @param {!Long|number|string} other Other Long + * @returns {!Long} + * @param other + * @return + */ + function and(other : any): Long; + + /** + * Returns the bitwise OR of this Long and the specified. + * @this {!Long} + * @param {!Long|number|string} other Other Long + * @returns {!Long} + * @param other + * @return + */ + function or(other : any): Long; + + /** + * Returns the bitwise XOR of this Long and the given one. + * @this {!Long} + * @param {!Long|number|string} other Other Long + * @returns {!Long} + * @param other + * @return + */ + function xor(other : any): Long; + + /** + * Returns this Long with bits shifted to the left by the given amount. + * @this {!Long} + * @param {number|!Long} numBits Number of bits + * @returns {!Long} Shifted Long + * @param numBits + * @return + */ + function shiftLeft(numBits : number | Long): /* !this */ any; + + /** + * Returns this Long with bits arithmetically shifted to the right by the given amount. + * @this {!Long} + * @param {number|!Long} numBits Number of bits + * @returns {!Long} Shifted Long + * @param numBits + * @return + */ + function shiftRight(numBits : number | Long): /* !this */ any; + + /** + * Returns this Long with bits logically shifted to the right by the given amount. + * @this {!Long} + * @param {number|!Long} numBits Number of bits + * @returns {!Long} Shifted Long + * @param numBits + * @return + */ + function shiftRightUnsigned(numBits : number | Long): /* !this */ any; + + /** + * Returns this Long with bits rotated to the left by the given amount. + * @this {!Long} + * @param {number|!Long} numBits Number of bits + * @returns {!Long} Rotated Long + * @param numBits + * @return + */ + function rotateLeft(numBits : number | Long): /* !this */ any; + + /** + * Returns this Long with bits rotated to the right by the given amount. + * @this {!Long} + * @param {number|!Long} numBits Number of bits + * @returns {!Long} Rotated Long + * @param numBits + * @return + */ + function rotateRight(numBits : number | Long): /* !this */ any; + + /** + * Converts this Long to signed. + * @this {!Long} + * @returns {!Long} Signed long + * @return + */ + function toSigned(): /* !this */ any; + + /** + * Converts this Long to unsigned. + * @this {!Long} + * @returns {!Long} Unsigned long + * @return + */ + function toUnsigned(): /* !this */ any; + + /** + * Converts this Long to its byte representation. + * @param {boolean=} le Whether little or big endian, defaults to big endian + * @this {!Long} + * @returns {!Array.} Byte representation + * @param le? + * @return + */ + function toBytes(le? : boolean): LongPrototype.ToBytesRet; + + /** + * Converts this Long to its little endian byte representation. + * @this {!Long} + * @returns {!Array.} Little endian byte representation + * @return + */ + function toBytesLE(): LongPrototype.ToBytesLERet; + + /** + * Converts this Long to its big endian byte representation. + * @this {!Long} + * @returns {!Array.} Big endian byte representation + * @return + */ + function toBytesBE(): LongPrototype.ToBytesBERet; + + /** + * + */ + export var eqz : /* LongPrototype.isZero */ any; + + /** + * + */ + export var eq : /* LongPrototype.equals */ any; + + /** + * + */ + export var neq : /* LongPrototype.notEquals */ any; + + /** + * + */ + export var ne : /* LongPrototype.notEquals */ any; + + /** + * + */ + export var lt : /* LongPrototype.lessThan */ any; + + /** + * + */ + export var lte : /* LongPrototype.lessThanOrEqual */ any; + + /** + * + */ + export var le : /* LongPrototype.lessThanOrEqual */ any; + + /** + * + */ + export var gt : /* LongPrototype.greaterThan */ any; + + /** + * + */ + export var gte : /* LongPrototype.greaterThanOrEqual */ any; + + /** + * + */ + export var ge : /* LongPrototype.greaterThanOrEqual */ any; + + /** + * + */ + export var comp : /* LongPrototype.compare */ any; + + /** + * + */ + export var neg : /* LongPrototype.negate */ any; + + /** + * + */ + export var sub : /* LongPrototype.subtract */ any; + + /** + * + */ + export var mul : /* LongPrototype.multiply */ any; + + /** + * + */ + export var div : /* LongPrototype.divide */ any; + + /** + * + */ + export var mod : /* LongPrototype.modulo */ any; + + /** + * + */ + export var rem : /* LongPrototype.modulo */ any; + + /** + * + */ + export var shl : /* LongPrototype.shiftLeft */ any; + + /** + * + */ + export var shr : /* LongPrototype.shiftRight */ any; + + /** + * + */ + export var shru : /* LongPrototype.shiftRightUnsigned */ any; + + /** + * + */ + export var shr_u : /* LongPrototype.shiftRightUnsigned */ any; + + /** + * + */ + export var rotl : /* LongPrototype.rotateLeft */ any; + + /** + * + */ + export var rotr : /* LongPrototype.rotateRight */ any; +} + +/** + * + */ +export declare var ZERO : Long; + +/** + * + */ +export declare var UZERO : Long; + +/** + * + */ +export declare var ONE : Long; + +/** + * + */ +export declare var UONE : Long; + +/** + * + */ +export declare var NEG_ONE : Long; + +/** + * + */ +export declare var MAX_VALUE : Long; + +/** + * + */ +export declare var MAX_UNSIGNED_VALUE : Long; + +/** + * + */ +export declare var MIN_VALUE : Long; diff --git a/source/src/Physics/Verlet/SpatialHash.ts b/source/src/Physics/Verlet/SpatialHash.ts index 2836f402..806288eb 100644 --- a/source/src/Physics/Verlet/SpatialHash.ts +++ b/source/src/Physics/Verlet/SpatialHash.ts @@ -132,7 +132,7 @@ class NumberDictionary { * @param y */ private getKey(x: number, y: number): number { - return Number(Long.fromNumber(x << 32).toString()) | this.intToUint(y); + return Long.fromNumber(x).shiftLeft(32).or(this.intToUint(y)).toString(); } private intToUint(i) {